0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(core): add api quota guard for bring your ui feature (#6273)

This commit is contained in:
Charles Zhao 2024-07-19 13:17:40 +08:00 committed by GitHub
parent 216859a906
commit 64b022bdea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 107 deletions

View file

@ -93,7 +93,7 @@
"zod": "^3.23.8" "zod": "^3.23.8"
}, },
"devDependencies": { "devDependencies": {
"@logto/cloud": "0.2.5-3046fa6", "@logto/cloud": "0.2.5-3b703da",
"@silverhand/eslint-config": "6.0.1", "@silverhand/eslint-config": "6.0.1",
"@silverhand/ts-config": "6.0.0", "@silverhand/ts-config": "6.0.0",
"@types/adm-zip": "^0.5.5", "@types/adm-zip": "^0.5.5",

View file

@ -74,6 +74,7 @@ export const createQuotaLibrary = (
builtInEmailConnectorEnabled: notNumber, // No limit for now builtInEmailConnectorEnabled: notNumber, // No limit for now
customJwtEnabled: notNumber, // No limit for now customJwtEnabled: notNumber, // No limit for now
subjectTokenEnabled: notNumber, // No limit for now subjectTokenEnabled: notNumber, // No limit for now
bringYourUiEnabled: notNumber,
}; };
const getTenantUsage = async (key: keyof FeatureQuota, queryKey?: string): Promise<number> => { const getTenantUsage = async (key: keyof FeatureQuota, queryKey?: string): Promise<number> => {

View file

@ -8,6 +8,7 @@ import { object, z } from 'zod';
import { EnvSet } from '#src/env-set/index.js'; import { EnvSet } from '#src/env-set/index.js';
import RequestError from '#src/errors/RequestError/index.js'; import RequestError from '#src/errors/RequestError/index.js';
import koaGuard from '#src/middleware/koa-guard.js'; import koaGuard from '#src/middleware/koa-guard.js';
import koaQuotaGuard from '#src/middleware/koa-quota-guard.js';
import SystemContext from '#src/tenants/SystemContext.js'; import SystemContext from '#src/tenants/SystemContext.js';
import assertThat from '#src/utils/assert-that.js'; import assertThat from '#src/utils/assert-that.js';
import { getConsoleLogFromContext } from '#src/utils/console.js'; import { getConsoleLogFromContext } from '#src/utils/console.js';
@ -20,7 +21,12 @@ import { type ManagementApiRouter, type RouterInitArgs } from '../../types.js';
const maxRetryCount = 5; const maxRetryCount = 5;
export default function customUiAssetsRoutes<T extends ManagementApiRouter>( export default function customUiAssetsRoutes<T extends ManagementApiRouter>(
...[router]: RouterInitArgs<T> ...[
router,
{
libraries: { quota },
},
]: RouterInitArgs<T>
) { ) {
// TODO: Remove // TODO: Remove
if (!EnvSet.values.isDevFeaturesEnabled) { if (!EnvSet.values.isDevFeaturesEnabled) {
@ -29,6 +35,7 @@ export default function customUiAssetsRoutes<T extends ManagementApiRouter>(
router.post( router.post(
'/sign-in-exp/default/custom-ui-assets', '/sign-in-exp/default/custom-ui-assets',
koaQuotaGuard({ key: 'bringYourUiEnabled', quota }),
koaGuard({ koaGuard({
files: object({ files: object({
file: uploadFileGuard.array().min(1).max(1), file: uploadFileGuard.array().min(1).max(1),

View file

@ -3357,8 +3357,8 @@ importers:
version: 3.23.8 version: 3.23.8
devDependencies: devDependencies:
'@logto/cloud': '@logto/cloud':
specifier: 0.2.5-3046fa6 specifier: 0.2.5-3b703da
version: 0.2.5-3046fa6(zod@3.23.8) version: 0.2.5-3b703da(zod@3.23.8)
'@silverhand/eslint-config': '@silverhand/eslint-config':
specifier: 6.0.1 specifier: 6.0.1
version: 6.0.1(eslint@8.57.0)(prettier@3.0.0)(typescript@5.3.3) version: 6.0.1(eslint@8.57.0)(prettier@3.0.0)(typescript@5.3.3)
@ -3427,7 +3427,7 @@ importers:
version: 8.57.0 version: 8.57.0
jest: jest:
specifier: ^29.7.0 specifier: ^29.7.0
version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) version: 29.7.0(@types/node@20.10.4)
jest-matcher-specific-error: jest-matcher-specific-error:
specifier: ^1.0.0 specifier: ^1.0.0
version: 1.0.0 version: 1.0.0
@ -3682,7 +3682,7 @@ importers:
version: 3.0.0 version: 3.0.0
jest: jest:
specifier: ^29.7.0 specifier: ^29.7.0
version: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3)) version: 29.7.0(@types/node@20.12.7)
jest-environment-jsdom: jest-environment-jsdom:
specifier: ^29.7.0 specifier: ^29.7.0
version: 29.7.0 version: 29.7.0
@ -3691,7 +3691,7 @@ importers:
version: 2.0.0 version: 2.0.0
jest-transformer-svg: jest-transformer-svg:
specifier: ^2.0.0 specifier: ^2.0.0
version: 2.0.0(jest@29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3)))(react@18.2.0) version: 2.0.0(jest@29.7.0(@types/node@20.12.7))(react@18.2.0)
js-base64: js-base64:
specifier: ^3.7.5 specifier: ^3.7.5
version: 3.7.5 version: 3.7.5
@ -3830,7 +3830,7 @@ importers:
version: 10.0.0 version: 10.0.0
jest: jest:
specifier: ^29.7.0 specifier: ^29.7.0
version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) version: 29.7.0(@types/node@20.10.4)
jest-matcher-specific-error: jest-matcher-specific-error:
specifier: ^1.0.0 specifier: ^1.0.0
version: 1.0.0 version: 1.0.0
@ -5223,8 +5223,8 @@ packages:
'@logto/client@2.7.2': '@logto/client@2.7.2':
resolution: {integrity: sha512-jsmuDl9QpXfR3uLEMPE67tvYoL5XcjJi+4yGqucYPjd4GH6SUHp3N9skk8C/OyygnKDPLY+ttwD0LaIbpGvn+Q==} resolution: {integrity: sha512-jsmuDl9QpXfR3uLEMPE67tvYoL5XcjJi+4yGqucYPjd4GH6SUHp3N9skk8C/OyygnKDPLY+ttwD0LaIbpGvn+Q==}
'@logto/cloud@0.2.5-3046fa6': '@logto/cloud@0.2.5-3b703da':
resolution: {integrity: sha512-Q/UrDDUOIq3fIogArVLdWkaKVcalLrDyLF2UDEjr1WZ5+9GqyV3MVmG3KljxnRujamKK0bnQF+QAFAJTQJJUMg==} resolution: {integrity: sha512-VCevQnxP5910s/cDYAxoJRim9iH1yN/La0HAlOP6FhVGtZofYwTTfT9AQXC+dZScgydpcFWo4k/6MYOFRtZCLg==}
engines: {node: ^20.9.0} engines: {node: ^20.9.0}
'@logto/cloud@0.2.5-a7eedce': '@logto/cloud@0.2.5-a7eedce':
@ -14594,41 +14594,6 @@ snapshots:
- supports-color - supports-color
- ts-node - ts-node
'@jest/core@29.7.0(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3))':
dependencies:
'@jest/console': 29.7.0
'@jest/reporters': 29.7.0
'@jest/test-result': 29.7.0
'@jest/transform': 29.7.0
'@jest/types': 29.6.3
'@types/node': 20.12.7
ansi-escapes: 4.3.2
chalk: 4.1.2
ci-info: 3.8.0
exit: 0.1.2
graceful-fs: 4.2.11
jest-changed-files: 29.7.0
jest-config: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3))
jest-haste-map: 29.7.0
jest-message-util: 29.7.0
jest-regex-util: 29.6.3
jest-resolve: 29.7.0
jest-resolve-dependencies: 29.7.0
jest-runner: 29.7.0
jest-runtime: 29.7.0
jest-snapshot: 29.7.0
jest-util: 29.7.0
jest-validate: 29.7.0
jest-watcher: 29.7.0
micromatch: 4.0.5
pretty-format: 29.7.0
slash: 3.0.0
strip-ansi: 6.0.1
transitivePeerDependencies:
- babel-plugin-macros
- supports-color
- ts-node
'@jest/create-cache-key-function@27.5.1': '@jest/create-cache-key-function@27.5.1':
dependencies: dependencies:
'@jest/types': 27.5.1 '@jest/types': 27.5.1
@ -14881,7 +14846,7 @@ snapshots:
camelcase-keys: 7.0.2 camelcase-keys: 7.0.2
jose: 5.6.3 jose: 5.6.3
'@logto/cloud@0.2.5-3046fa6(zod@3.23.8)': '@logto/cloud@0.2.5-3b703da(zod@3.23.8)':
dependencies: dependencies:
'@silverhand/essentials': 2.9.1 '@silverhand/essentials': 2.9.1
'@withtyped/server': 0.13.6(zod@3.23.8) '@withtyped/server': 0.13.6(zod@3.23.8)
@ -17967,13 +17932,13 @@ snapshots:
dependencies: dependencies:
lodash.get: 4.4.2 lodash.get: 4.4.2
create-jest@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)): create-jest@29.7.0(@types/node@20.10.4):
dependencies: dependencies:
'@jest/types': 29.6.3 '@jest/types': 29.6.3
chalk: 4.1.2 chalk: 4.1.2
exit: 0.1.2 exit: 0.1.2
graceful-fs: 4.2.11 graceful-fs: 4.2.11
jest-config: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) jest-config: 29.7.0(@types/node@20.10.4)
jest-util: 29.7.0 jest-util: 29.7.0
prompts: 2.4.2 prompts: 2.4.2
transitivePeerDependencies: transitivePeerDependencies:
@ -20298,16 +20263,35 @@ snapshots:
- babel-plugin-macros - babel-plugin-macros
- supports-color - supports-color
jest-cli@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)): jest-cli@29.7.0(@types/node@20.10.4):
dependencies: dependencies:
'@jest/core': 29.7.0(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
'@jest/test-result': 29.7.0 '@jest/test-result': 29.7.0
'@jest/types': 29.6.3 '@jest/types': 29.6.3
chalk: 4.1.2 chalk: 4.1.2
create-jest: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) create-jest: 29.7.0(@types/node@20.10.4)
exit: 0.1.2 exit: 0.1.2
import-local: 3.1.0 import-local: 3.1.0
jest-config: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) jest-config: 29.7.0(@types/node@20.10.4)
jest-util: 29.7.0
jest-validate: 29.7.0
yargs: 17.7.2
transitivePeerDependencies:
- '@types/node'
- babel-plugin-macros
- supports-color
- ts-node
jest-cli@29.7.0(@types/node@20.12.7):
dependencies:
'@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
'@jest/test-result': 29.7.0
'@jest/types': 29.6.3
chalk: 4.1.2
create-jest: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
exit: 0.1.2
import-local: 3.1.0
jest-config: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
jest-util: 29.7.0 jest-util: 29.7.0
jest-validate: 29.7.0 jest-validate: 29.7.0
yargs: 17.7.2 yargs: 17.7.2
@ -20336,7 +20320,7 @@ snapshots:
- supports-color - supports-color
- ts-node - ts-node
jest-config@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)): jest-config@29.7.0(@types/node@20.10.4):
dependencies: dependencies:
'@babel/core': 7.24.4 '@babel/core': 7.24.4
'@jest/test-sequencer': 29.7.0 '@jest/test-sequencer': 29.7.0
@ -20362,7 +20346,6 @@ snapshots:
strip-json-comments: 3.1.1 strip-json-comments: 3.1.1
optionalDependencies: optionalDependencies:
'@types/node': 20.10.4 '@types/node': 20.10.4
ts-node: 10.9.2(@types/node@20.10.4)(typescript@5.3.3)
transitivePeerDependencies: transitivePeerDependencies:
- babel-plugin-macros - babel-plugin-macros
- supports-color - supports-color
@ -20398,37 +20381,6 @@ snapshots:
- babel-plugin-macros - babel-plugin-macros
- supports-color - supports-color
jest-config@29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)):
dependencies:
'@babel/core': 7.24.4
'@jest/test-sequencer': 29.7.0
'@jest/types': 29.6.3
babel-jest: 29.7.0(@babel/core@7.24.4)
chalk: 4.1.2
ci-info: 3.8.0
deepmerge: 4.3.1
glob: 7.2.3
graceful-fs: 4.2.11
jest-circus: 29.7.0
jest-environment-node: 29.7.0
jest-get-type: 29.6.3
jest-regex-util: 29.6.3
jest-resolve: 29.7.0
jest-runner: 29.7.0
jest-util: 29.7.0
jest-validate: 29.7.0
micromatch: 4.0.5
parse-json: 5.2.0
pretty-format: 29.7.0
slash: 3.0.0
strip-json-comments: 3.1.1
optionalDependencies:
'@types/node': 20.12.7
ts-node: 10.9.2(@types/node@20.10.4)(typescript@5.3.3)
transitivePeerDependencies:
- babel-plugin-macros
- supports-color
jest-dev-server@10.0.0: jest-dev-server@10.0.0:
dependencies: dependencies:
chalk: 4.1.2 chalk: 4.1.2
@ -20685,6 +20637,11 @@ snapshots:
jest: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3)) jest: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
react: 18.2.0 react: 18.2.0
jest-transformer-svg@2.0.0(jest@29.7.0(@types/node@20.12.7))(react@18.2.0):
dependencies:
jest: 29.7.0(@types/node@20.12.7)
react: 18.2.0
jest-util@29.5.0: jest-util@29.5.0:
dependencies: dependencies:
'@jest/types': 29.6.3 '@jest/types': 29.6.3
@ -20737,12 +20694,24 @@ snapshots:
merge-stream: 2.0.0 merge-stream: 2.0.0
supports-color: 8.1.1 supports-color: 8.1.1
jest@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)): jest@29.7.0(@types/node@20.10.4):
dependencies: dependencies:
'@jest/core': 29.7.0(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
'@jest/types': 29.6.3 '@jest/types': 29.6.3
import-local: 3.1.0 import-local: 3.1.0
jest-cli: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3)) jest-cli: 29.7.0(@types/node@20.10.4)
transitivePeerDependencies:
- '@types/node'
- babel-plugin-macros
- supports-color
- ts-node
jest@29.7.0(@types/node@20.12.7):
dependencies:
'@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.3.52(@swc/helpers@0.5.1))(@types/node@20.12.7)(typescript@5.3.3))
'@jest/types': 29.6.3
import-local: 3.1.0
jest-cli: 29.7.0(@types/node@20.12.7)
transitivePeerDependencies: transitivePeerDependencies:
- '@types/node' - '@types/node'
- babel-plugin-macros - babel-plugin-macros
@ -24236,25 +24205,6 @@ snapshots:
optionalDependencies: optionalDependencies:
'@swc/core': 1.3.52(@swc/helpers@0.5.1) '@swc/core': 1.3.52(@swc/helpers@0.5.1)
ts-node@10.9.2(@types/node@20.10.4)(typescript@5.3.3):
dependencies:
'@cspotcode/source-map-support': 0.8.1
'@tsconfig/node10': 1.0.9
'@tsconfig/node12': 1.0.11
'@tsconfig/node14': 1.0.3
'@tsconfig/node16': 1.0.4
'@types/node': 20.10.4
acorn: 8.10.0
acorn-walk: 8.2.0
arg: 4.1.3
create-require: 1.1.1
diff: 4.0.2
make-error: 1.3.6
typescript: 5.3.3
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
optional: true
tsconfig-paths@3.15.0: tsconfig-paths@3.15.0:
dependencies: dependencies:
'@types/json5': 0.0.29 '@types/json5': 0.0.29