@venizia/ignis 0.4.8-12 → 0.4.8-14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/components/mail/common/constants.d.ts +24 -14
- package/dist/esm/components/mail/common/constants.js +19 -32
- package/dist/esm/components/mail/common/constants.js.map +1 -1
- package/dist/esm/components/mail/common/errors.d.ts +10 -1
- package/dist/esm/components/mail/common/errors.js +7 -1
- package/dist/esm/components/mail/common/errors.js.map +1 -1
- package/dist/esm/components/mail/common/types/queue.d.ts +15 -8
- package/dist/esm/components/mail/common/types/queue.js.map +1 -1
- package/dist/esm/components/mail/common/types/template.d.ts +3 -2
- package/dist/esm/components/mail/common/types/template.js.map +1 -1
- package/dist/esm/components/mail/component.js +11 -2
- package/dist/esm/components/mail/component.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +9 -8
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +4 -4
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
- package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
- package/dist/esm/components/mail/services/mail.service.js +21 -19
- package/dist/esm/components/mail/services/mail.service.js.map +1 -1
- package/dist/esm/components/mail/services/template.service.d.ts +4 -1
- package/dist/esm/components/mail/services/template.service.js +24 -16
- package/dist/esm/components/mail/services/template.service.js.map +1 -1
- package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
- package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
- package/dist/esm/components/mail/utilities/header.utility.js +44 -0
- package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
- package/dist/esm/components/mail/utilities/index.d.ts +1 -0
- package/dist/esm/components/mail/utilities/index.js +1 -0
- package/dist/esm/components/mail/utilities/index.js.map +1 -1
- package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
- package/dist/esm/components/mail/utilities/mime.utility.js +9 -55
- package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
- package/dist/esm/components/static-asset/common/constants.d.ts +13 -5
- package/dist/esm/components/static-asset/common/constants.js +11 -10
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/errors.d.ts +36 -9
- package/dist/esm/components/static-asset/common/errors.js +36 -9
- package/dist/esm/components/static-asset/common/errors.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +66 -23
- package/dist/esm/components/static-asset/common/types.js.map +1 -1
- package/dist/esm/components/static-asset/component.js +1 -1
- package/dist/esm/components/static-asset/component.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +2 -166
- package/dist/esm/components/static-asset/controller/factory.js +7 -20
- package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
- package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
- package/dist/esm/components/static-asset/controller/index.js +1 -0
- package/dist/esm/components/static-asset/controller/index.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.d.ts +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/definition.js +15 -6
- package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js +32 -4
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/serve.d.ts +14 -2
- package/dist/esm/components/static-asset/controller/routes/serve.js +40 -15
- package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/upload.js +11 -10
- package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -1
- package/dist/esm/components/static-asset/services/commitment.service.d.ts +48 -18
- package/dist/esm/components/static-asset/services/commitment.service.js +155 -44
- package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -1
- package/dist/esm/components/static-asset/services/policy.service.d.ts +7 -3
- package/dist/esm/components/static-asset/services/policy.service.js +22 -2
- package/dist/esm/components/static-asset/services/policy.service.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +3 -1
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js +39 -5
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/entry.utility.js +9 -2
- package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/index.d.ts +1 -0
- package/dist/esm/components/static-asset/utilities/index.js +1 -0
- package/dist/esm/components/static-asset/utilities/index.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +6 -7
- package/dist/esm/components/static-asset/utilities/route-options.utility.js +9 -23
- package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -1
- package/dist/presets/app/preset.json +4 -4
- package/dist/presets/lib/preset.json +3 -3
- package/dist/presets/shared/preset.json +1 -1
- package/package.json +6 -6
|
@@ -47,6 +47,11 @@ export class StaticAssetEntryUtility {
|
|
|
47
47
|
message: `[${name}] directUpload needs keyPrefix | the pending prefix stays out of what the routes serve only when the entry has a scope of its own`,
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
+
if (directUpload && typeof directUpload.resolvers?.owner !== 'function') {
|
|
51
|
+
throw getError({
|
|
52
|
+
message: `[${name}] directUpload needs resolvers.owner | a token is signed for one owner, and the commit refuses any other`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
50
55
|
if (directUpload && directUpload.authorize === undefined) {
|
|
51
56
|
if (!StaticAssetEntryUtility.isGuarded({ auth })) {
|
|
52
57
|
throw getError({
|
|
@@ -88,8 +93,8 @@ export class StaticAssetEntryUtility {
|
|
|
88
93
|
bucket,
|
|
89
94
|
keyPrefix: scope?.keyPrefix,
|
|
90
95
|
maxFolderDepth,
|
|
91
|
-
// `maxFolderDepth` counts the caller's folders; the scope's own are
|
|
92
|
-
objectKeyMaxDepth: maxFolderDepth + (scope?.depth ?? 0),
|
|
96
|
+
// `maxFolderDepth` counts the caller's folders; the scope's own and the framework's uuid folder are not input.
|
|
97
|
+
objectKeyMaxDepth: maxFolderDepth + (scope?.depth ?? 0) + 1,
|
|
93
98
|
auth: auth && {
|
|
94
99
|
authenticate: auth.authenticate,
|
|
95
100
|
authorize: auth.authorize,
|
|
@@ -141,7 +146,9 @@ export class StaticAssetEntryUtility {
|
|
|
141
146
|
commitService: new StaticAssetUploadCommitService({
|
|
142
147
|
scope: resolved.name,
|
|
143
148
|
helper: resolved.helper,
|
|
149
|
+
bucket: resolved.bucket,
|
|
144
150
|
keyPrefix,
|
|
151
|
+
objectKeyMaxDepth: resolved.objectKeyMaxDepth,
|
|
145
152
|
directUpload,
|
|
146
153
|
storage: resolved.storage,
|
|
147
154
|
metaLink: resolved.metaLink,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/entry.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AActE,OAAO,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAoC5D,MAAM,OAAO,uBAAuB;IAClC,4HAA4H;IACpH,MAAM,CAAC,UAAU,CAAC,IAAqB;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAChF,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAExF,OAAO,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,YAAY,CAAC;IACxE,CAAC;IAED,sIAAsI;IAC9H,MAAM,CAAC,SAAS,CAAC,IAAiC;QACxD,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,IAA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AmB,CAAC,gBAAgB;gBACvE,SAAS,EAAE,YAAY,CAAC,SAAS;aAClC;YACD,YAAY,EAAE,YAAY,IAAI;gBAC5B,GAAG,YAAY;gBACf,UAAU;gBACV,SAAS,EAAE,YAAY,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;aAClD;YACD,QAAQ;YACR,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,yBAAyB,CAA2C,IAE1E;QAMC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;QAE7C,IAAI,CAAC,YAAY,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO;YACL,aAAa,EAAE,IAAI,8BAA8B,CAAC;gBAChD,KAAK,EAAE,QAAQ,CAAC,IAAI;gBACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,SAAS;gBACT,YAAY;aACb,CAAC;YACF,aAAa,EAAE,IAAI,8BAA8B,CAAS;gBACxD,KAAK,EAAE,QAAQ,CAAC,IAAI;gBACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,SAAS;gBACT,YAAY;gBACZ,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,IAAI,EAAE,QAAQ,CAAC,IAAI;aACpB,CAAC;SACH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseStorageHelper, StorageTypes } from '@venizia/ignis-helpers';\nimport type { IObjectLocation, IStorageHelper } from '@venizia/ignis-helpers';\nimport type { TValueOrAsyncResolver } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetDefaults, StaticAssetRouteKeys } from '../common';\nimport type {\n IStaticAssetValidation,\n TMetaLinkConfig,\n TStaticAssetAuth,\n TStaticAssetDefineExtraRoutes,\n TStaticAssetDirectUploadOptions,\n TStaticAssetEntry,\n TStaticAssetObjectKeyResolver,\n TStaticAssetRouteConfig,\n TStaticAssetRouteKey,\n TStaticAssetStorageType,\n} from '../common';\nimport type { TMetaLinkCompatibleSchema } from '../models';\nimport { StaticAssetUploadCommitService, StaticAssetUploadPolicyService } from '../services';\nimport { StaticAssetKeyScopeUtility } from './key-scope.utility';\nimport { StaticAssetObjectLinkUtility } from './object-link.utility';\nimport { StaticAssetToggleUtility } from './toggle.utility';\nimport type { z } from '@hono/zod-openapi';\n\n/** One route after its toggle is read: whether it is registered, and what the application overrides. */\nexport interface IStaticAssetResolvedRoute {\n isEnabled: boolean;\n override: TStaticAssetRouteConfig;\n}\n\n/** An entry with every toggle read, every default applied and every cross-check made, so the component, the controller and the services read one thing. */\nexport interface IStaticAssetResolvedEntry<Schema extends TMetaLinkCompatibleSchema> {\n name: string;\n /** The mount path with exactly one leading slash. */\n basePath: string;\n rawObjectPath: boolean;\n bucket: TValueOrAsyncResolver<string>;\n /** Normalized: no leading slash, one trailing slash. */\n keyPrefix?: string;\n /** Folders allowed in an object key: the caller's `maxFolderDepth` plus the scope's own. */\n objectKeyMaxDepth: number;\n maxFolderDepth: number;\n auth?: Pick<TStaticAssetAuth, 'authenticate' | 'authorize'> & { isPublicRead: boolean };\n routes: Partial<Record<TStaticAssetRouteKey, IStaticAssetResolvedRoute>>;\n helper: IStorageHelper;\n storage: TStaticAssetStorageType;\n link: (opts: IObjectLocation) => string;\n serverUpload?: { maxBytes?: number; maxFiles: number; objectKey?: TStaticAssetObjectKeyResolver };\n /** `authorize` is always present here: the entry's own, or the pass-through that `auth` makes safe. `validation` is present only when it is on. */\n directUpload?: Omit<TStaticAssetDirectUploadOptions, 'authorize' | 'validation'> & {\n authorize: NonNullable<TStaticAssetDirectUploadOptions['authorize']>;\n validation?: IStaticAssetValidation<z.ZodType>;\n };\n metaLink?: TMetaLinkConfig<Schema>;\n extend?: { before?: TStaticAssetDefineExtraRoutes; after?: TStaticAssetDefineExtraRoutes };\n}\n\nexport class StaticAssetEntryUtility {\n /** `staticAsset` and `static-asset` both become `StaticAssetController`; a name already ending in `Controller` keeps it. */\n private static deriveName(opts: { key: string }): string {\n const words = opts.key.split(/[^A-Za-z0-9]+/).filter((word) => word.length > 0);\n const pascal = words.map((word) => `${word[0].toUpperCase()}${word.slice(1)}`).join('');\n\n return pascal.endsWith('Controller') ? pascal : `${pascal}Controller`;\n }\n\n /** True when the entry's `auth` already decides who may call a route, which is what makes a missing `directUpload.authorize` safe. */\n private static isGuarded(opts: { auth?: TStaticAssetAuth }): boolean {\n const { authenticate, authorize } = opts.auth ?? {};\n const isAuthenticated =\n authenticate != null &&\n authenticate.skip !== true &&\n (authenticate.strategies?.length ?? 0) > 0;\n const isAuthorized = authorize != null && !('skip' in authorize);\n\n return isAuthenticated || isAuthorized;\n }\n\n /** Reads every toggle, applies every default and refuses what the types cannot (an entry written in plain JavaScript, or cast). */\n static resolve<Schema extends TMetaLinkCompatibleSchema>(opts: {\n key: string;\n entry: TStaticAssetEntry<Schema>;\n }): IStaticAssetResolvedEntry<Schema> {\n const { key, entry } = opts;\n const { helper, bucket, auth } = entry;\n const name = entry.name ?? StaticAssetEntryUtility.deriveName({ key });\n const { storageType } = helper;\n\n if (storageType !== StorageTypes.BUN_S3 && storageType !== StorageTypes.DISK) {\n throw getError({\n message: `[${name}] helper must be a BunS3Helper or a DiskHelper | storageType: ${storageType}`,\n });\n }\n\n const directUpload = StaticAssetToggleUtility.isUsed(entry.directUpload)\n ? entry.directUpload\n : undefined;\n\n // A policy is a POST policy, which only S3 can sign.\n if (directUpload && storageType !== StorageTypes.BUN_S3) {\n throw getError({\n message: `[${name}] directUpload needs a BunS3Helper | a POST policy is an S3 feature, and this helper is ${storageType}`,\n });\n }\n\n // Its pending objects live in the same bucket: the scope is what keeps them out of the routes.\n if (directUpload && entry.keyPrefix === undefined) {\n throw getError({\n message: `[${name}] directUpload needs keyPrefix | the pending prefix stays out of what the routes serve only when the entry has a scope of its own`,\n });\n }\n\n if (directUpload && directUpload.authorize === undefined) {\n if (!StaticAssetEntryUtility.isGuarded({ auth })) {\n throw getError({\n message: `[${name}] directUpload needs authorize or auth | a route that hands out a write credential has no safe default for who may call it`,\n });\n }\n }\n\n const scope =\n entry.keyPrefix === undefined\n ? undefined\n : StaticAssetKeyScopeUtility.normalizePrefix({\n keyPrefix: entry.keyPrefix,\n helper,\n scope: name,\n });\n const serverUpload = StaticAssetToggleUtility.isUsed(entry.serverUpload)\n ? entry.serverUpload\n : undefined;\n const maxFolderDepth = entry.maxFolderDepth ?? BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH;\n const basePath = StaticAssetObjectLinkUtility.normalizeBasePath({ basePath: entry.basePath });\n const rawObjectPath = entry.rawObjectPath ?? false;\n\n const routes: IStaticAssetResolvedEntry<Schema>['routes'] = {};\n\n for (const routeKey of StaticAssetRouteKeys.ALL) {\n const toggle = entry.routes?.[routeKey];\n\n if (toggle) {\n routes[routeKey] = {\n isEnabled: StaticAssetToggleUtility.isUsed(toggle),\n override: StaticAssetToggleUtility.pick(toggle) ?? {},\n };\n }\n }\n\n const metaLink = StaticAssetToggleUtility.isUsed(entry.metaLink) ? entry.metaLink : undefined;\n const validation =\n directUpload && StaticAssetToggleUtility.isUsed(directUpload.validation)\n ? directUpload.validation\n : undefined;\n\n return {\n name,\n basePath,\n rawObjectPath,\n bucket,\n keyPrefix: scope?.keyPrefix,\n maxFolderDepth,\n // `maxFolderDepth` counts the caller's folders; the scope's own are configuration, not input.\n objectKeyMaxDepth: maxFolderDepth + (scope?.depth ?? 0),\n auth: auth && {\n authenticate: auth.authenticate,\n authorize: auth.authorize,\n isPublicRead: StaticAssetToggleUtility.isUsed(auth.publicRead),\n },\n routes,\n helper,\n storage: storageType,\n link:\n entry.link ??\n ((location) =>\n StaticAssetObjectLinkUtility.build({\n basePath,\n bucket: location.bucket,\n object: location.object,\n rawObjectPath,\n })),\n serverUpload: serverUpload && {\n maxBytes: serverUpload.maxBytes,\n maxFiles: serverUpload.maxFiles ?? StaticAssetDefaults.MAX_UPLOAD_FILES,\n objectKey: serverUpload.objectKey,\n },\n directUpload: directUpload && {\n ...directUpload,\n validation,\n authorize: directUpload.authorize ?? (() => true),\n },\n metaLink,\n extend: entry.extend,\n };\n }\n\n /**\n * The pair of services an entry's direct-upload routes run, or `undefined` when the entry has no\n * direct upload. The one place they are constructed: the component binds what this returns and\n * hands the same instances to the controller.\n */\n static buildDirectUploadServices<Schema extends TMetaLinkCompatibleSchema>(opts: {\n resolved: IStaticAssetResolvedEntry<Schema>;\n }):\n | {\n policyService: StaticAssetUploadPolicyService;\n commitService: StaticAssetUploadCommitService<Schema>;\n }\n | undefined {\n const { resolved } = opts;\n const { keyPrefix, directUpload } = resolved;\n\n if (!directUpload || keyPrefix === undefined) {\n return undefined;\n }\n\n return {\n policyService: new StaticAssetUploadPolicyService({\n scope: resolved.name,\n helper: resolved.helper,\n bucket: resolved.bucket,\n keyPrefix,\n directUpload,\n }),\n commitService: new StaticAssetUploadCommitService<Schema>({\n scope: resolved.name,\n helper: resolved.helper,\n keyPrefix,\n directUpload,\n storage: resolved.storage,\n metaLink: resolved.metaLink,\n link: resolved.link,\n }),\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entry.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/entry.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AActE,OAAO,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE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YACD,QAAQ;YACR,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,yBAAyB,CAA2C,IAE1E;QAMC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;QAE7C,IAAI,CAAC,YAAY,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO;YACL,aAAa,EAAE,IAAI,8BAA8B,CAAC;gBAChD,KAAK,EAAE,QAAQ,CAAC,IAAI;gBACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,SAAS;gBACT,YAAY;aACb,CAAC;YACF,aAAa,EAAE,IAAI,8BAA8B,CAAS;gBACxD,KAAK,EAAE,QAAQ,CAAC,IAAI;gBACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,SAAS;gBACT,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;gBAC7C,YAAY;gBACZ,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,IAAI,EAAE,QAAQ,CAAC,IAAI;aACpB,CAAC;SACH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseStorageHelper, StorageTypes } from '@venizia/ignis-helpers';\nimport type { IObjectLocation, IStorageHelper } from '@venizia/ignis-helpers';\nimport type { TValueOrAsyncResolver } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetDefaults, StaticAssetRouteKeys } from '../common';\nimport type {\n IStaticAssetValidation,\n TMetaLinkConfig,\n TStaticAssetAuth,\n TStaticAssetDefineExtraRoutes,\n TStaticAssetDirectUploadOptions,\n TStaticAssetEntry,\n TStaticAssetObjectKeyResolver,\n TStaticAssetRouteConfig,\n TStaticAssetRouteKey,\n TStaticAssetStorageType,\n} from '../common';\nimport type { TMetaLinkCompatibleSchema } from '../models';\nimport { StaticAssetUploadCommitService, StaticAssetUploadPolicyService } from '../services';\nimport { StaticAssetKeyScopeUtility } from './key-scope.utility';\nimport { StaticAssetObjectLinkUtility } from './object-link.utility';\nimport { StaticAssetToggleUtility } from './toggle.utility';\nimport type { z } from '@hono/zod-openapi';\n\n/** One route after its toggle is read: whether it is registered, and what the application overrides. */\nexport interface IStaticAssetResolvedRoute {\n isEnabled: boolean;\n override: TStaticAssetRouteConfig;\n}\n\n/** An entry with every toggle read, every default applied and every cross-check made, so the component, the controller and the services read one thing. */\nexport interface IStaticAssetResolvedEntry<Schema extends TMetaLinkCompatibleSchema> {\n name: string;\n /** The mount path with exactly one leading slash. */\n basePath: string;\n rawObjectPath: boolean;\n bucket: TValueOrAsyncResolver<string>;\n /** Normalized: no leading slash, one trailing slash. */\n keyPrefix?: string;\n /** Folders allowed in an object key: the caller's `maxFolderDepth` plus the scope's own. */\n objectKeyMaxDepth: number;\n maxFolderDepth: number;\n auth?: Pick<TStaticAssetAuth, 'authenticate' | 'authorize'> & { isPublicRead: boolean };\n routes: Partial<Record<TStaticAssetRouteKey, IStaticAssetResolvedRoute>>;\n helper: IStorageHelper;\n storage: TStaticAssetStorageType;\n link: (opts: IObjectLocation) => string;\n serverUpload?: { maxBytes?: number; maxFiles: number; objectKey?: TStaticAssetObjectKeyResolver };\n /** `authorize` is always present here: the entry's own, or the pass-through that `auth` makes safe. `validation` is present only when it is on. */\n directUpload?: Omit<TStaticAssetDirectUploadOptions, 'authorize' | 'validation'> & {\n authorize: NonNullable<TStaticAssetDirectUploadOptions['authorize']>;\n validation?: IStaticAssetValidation<z.ZodType>;\n };\n metaLink?: TMetaLinkConfig<Schema>;\n extend?: { before?: TStaticAssetDefineExtraRoutes; after?: TStaticAssetDefineExtraRoutes };\n}\n\nexport class StaticAssetEntryUtility {\n /** `staticAsset` and `static-asset` both become `StaticAssetController`; a name already ending in `Controller` keeps it. */\n private static deriveName(opts: { key: string }): string {\n const words = opts.key.split(/[^A-Za-z0-9]+/).filter((word) => word.length > 0);\n const pascal = words.map((word) => `${word[0].toUpperCase()}${word.slice(1)}`).join('');\n\n return pascal.endsWith('Controller') ? pascal : `${pascal}Controller`;\n }\n\n /** True when the entry's `auth` already decides who may call a route, which is what makes a missing `directUpload.authorize` safe. */\n private static isGuarded(opts: { auth?: TStaticAssetAuth }): boolean {\n const { authenticate, authorize } = opts.auth ?? {};\n const isAuthenticated =\n authenticate != null &&\n authenticate.skip !== true &&\n (authenticate.strategies?.length ?? 0) > 0;\n const isAuthorized = authorize != null && !('skip' in authorize);\n\n return isAuthenticated || isAuthorized;\n }\n\n /** Reads every toggle, applies every default and refuses what the types cannot (an entry written in plain JavaScript, or cast). */\n static resolve<Schema extends TMetaLinkCompatibleSchema>(opts: {\n key: string;\n entry: TStaticAssetEntry<Schema>;\n }): IStaticAssetResolvedEntry<Schema> {\n const { key, entry } = opts;\n const { helper, bucket, auth } = entry;\n const name = entry.name ?? StaticAssetEntryUtility.deriveName({ key });\n const { storageType } = helper;\n\n if (storageType !== StorageTypes.BUN_S3 && storageType !== StorageTypes.DISK) {\n throw getError({\n message: `[${name}] helper must be a BunS3Helper or a DiskHelper | storageType: ${storageType}`,\n });\n }\n\n const directUpload = StaticAssetToggleUtility.isUsed(entry.directUpload)\n ? entry.directUpload\n : undefined;\n\n // A policy is a POST policy, which only S3 can sign.\n if (directUpload && storageType !== StorageTypes.BUN_S3) {\n throw getError({\n message: `[${name}] directUpload needs a BunS3Helper | a POST policy is an S3 feature, and this helper is ${storageType}`,\n });\n }\n\n // Its pending objects live in the same bucket: the scope is what keeps them out of the routes.\n if (directUpload && entry.keyPrefix === undefined) {\n throw getError({\n message: `[${name}] directUpload needs keyPrefix | the pending prefix stays out of what the routes serve only when the entry has a scope of its own`,\n });\n }\n\n if (directUpload && typeof directUpload.resolvers?.owner !== 'function') {\n throw getError({\n message: `[${name}] directUpload needs resolvers.owner | a token is signed for one owner, and the commit refuses any other`,\n });\n }\n\n if (directUpload && directUpload.authorize === undefined) {\n if (!StaticAssetEntryUtility.isGuarded({ auth })) {\n throw getError({\n message: `[${name}] directUpload needs authorize or auth | a route that hands out a write credential has no safe default for who may call it`,\n });\n }\n }\n\n const scope =\n entry.keyPrefix === undefined\n ? undefined\n : StaticAssetKeyScopeUtility.normalizePrefix({\n keyPrefix: entry.keyPrefix,\n helper,\n scope: name,\n });\n const serverUpload = StaticAssetToggleUtility.isUsed(entry.serverUpload)\n ? entry.serverUpload\n : undefined;\n const maxFolderDepth = entry.maxFolderDepth ?? BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH;\n const basePath = StaticAssetObjectLinkUtility.normalizeBasePath({ basePath: entry.basePath });\n const rawObjectPath = entry.rawObjectPath ?? false;\n\n const routes: IStaticAssetResolvedEntry<Schema>['routes'] = {};\n\n for (const routeKey of StaticAssetRouteKeys.ALL) {\n const toggle = entry.routes?.[routeKey];\n\n if (toggle) {\n routes[routeKey] = {\n isEnabled: StaticAssetToggleUtility.isUsed(toggle),\n override: StaticAssetToggleUtility.pick(toggle) ?? {},\n };\n }\n }\n\n const metaLink = StaticAssetToggleUtility.isUsed(entry.metaLink) ? entry.metaLink : undefined;\n const validation =\n directUpload && StaticAssetToggleUtility.isUsed(directUpload.validation)\n ? directUpload.validation\n : undefined;\n\n return {\n name,\n basePath,\n rawObjectPath,\n bucket,\n keyPrefix: scope?.keyPrefix,\n maxFolderDepth,\n // `maxFolderDepth` counts the caller's folders; the scope's own and the framework's uuid folder are not input.\n objectKeyMaxDepth: maxFolderDepth + (scope?.depth ?? 0) + 1,\n auth: auth && {\n authenticate: auth.authenticate,\n authorize: auth.authorize,\n isPublicRead: StaticAssetToggleUtility.isUsed(auth.publicRead),\n },\n routes,\n helper,\n storage: storageType,\n link:\n entry.link ??\n ((location) =>\n StaticAssetObjectLinkUtility.build({\n basePath,\n bucket: location.bucket,\n object: location.object,\n rawObjectPath,\n })),\n serverUpload: serverUpload && {\n maxBytes: serverUpload.maxBytes,\n maxFiles: serverUpload.maxFiles ?? StaticAssetDefaults.MAX_UPLOAD_FILES,\n objectKey: serverUpload.objectKey,\n },\n directUpload: directUpload && {\n ...directUpload,\n validation,\n authorize: directUpload.authorize ?? (() => true),\n },\n metaLink,\n extend: entry.extend,\n };\n }\n\n /**\n * The pair of services an entry's direct-upload routes run, or `undefined` when the entry has no\n * direct upload. The one place they are constructed: the component binds what this returns and\n * hands the same instances to the controller.\n */\n static buildDirectUploadServices<Schema extends TMetaLinkCompatibleSchema>(opts: {\n resolved: IStaticAssetResolvedEntry<Schema>;\n }):\n | {\n policyService: StaticAssetUploadPolicyService;\n commitService: StaticAssetUploadCommitService<Schema>;\n }\n | undefined {\n const { resolved } = opts;\n const { keyPrefix, directUpload } = resolved;\n\n if (!directUpload || keyPrefix === undefined) {\n return undefined;\n }\n\n return {\n policyService: new StaticAssetUploadPolicyService({\n scope: resolved.name,\n helper: resolved.helper,\n bucket: resolved.bucket,\n keyPrefix,\n directUpload,\n }),\n commitService: new StaticAssetUploadCommitService<Schema>({\n scope: resolved.name,\n helper: resolved.helper,\n bucket: resolved.bucket,\n keyPrefix,\n objectKeyMaxDepth: resolved.objectKeyMaxDepth,\n directUpload,\n storage: resolved.storage,\n metaLink: resolved.metaLink,\n link: resolved.link,\n }),\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './commit-token.utility';\nexport * from './ingest.utility';\nexport * from './object-link.utility';\nexport * from './toggle.utility';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './commit-token.utility';\nexport * from './ingest.utility';\nexport * from './object-link.utility';\nexport * from './pinned-file.utility';\nexport * from './toggle.utility';\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type IFileStat, type IObjectLocation, type IStorageHelper } from '@venizia/ignis-helpers';
|
|
2
|
+
import { type IStaticAssetPin } from '../common/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The pending file as `validation.handler` sees it. Every read asks the storage for exactly the
|
|
5
|
+
* content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:
|
|
6
|
+
* a read that finds other content or no object throws `UPLOAD_CHANGED`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class StaticAssetPinnedFile {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly size: number;
|
|
11
|
+
private readonly helper;
|
|
12
|
+
private readonly location;
|
|
13
|
+
private readonly pin;
|
|
14
|
+
constructor(opts: {
|
|
15
|
+
helper: IStorageHelper;
|
|
16
|
+
location: IObjectLocation;
|
|
17
|
+
pin: IStaticAssetPin;
|
|
18
|
+
size: number;
|
|
19
|
+
});
|
|
20
|
+
/** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */
|
|
21
|
+
static conditionOf(opts: {
|
|
22
|
+
pin: IStaticAssetPin;
|
|
23
|
+
}): {
|
|
24
|
+
ifMatch?: string;
|
|
25
|
+
versionId?: string;
|
|
26
|
+
};
|
|
27
|
+
/** The pin of what the storage holds now. An object with no ETag cannot be pinned. */
|
|
28
|
+
static pinOf(opts: {
|
|
29
|
+
stat: IFileStat;
|
|
30
|
+
scope: string;
|
|
31
|
+
}): IStaticAssetPin;
|
|
32
|
+
stream(opts?: {
|
|
33
|
+
range?: {
|
|
34
|
+
start: number;
|
|
35
|
+
end?: number;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=pinned-file.utility.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StorageUtility, } from '@venizia/ignis-helpers';
|
|
2
|
+
import { getError } from '@venizia/ignis-helpers/core';
|
|
3
|
+
import { StaticAssetErrors } from '../common/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* The pending file as `validation.handler` sees it. Every read asks the storage for exactly the
|
|
6
|
+
* content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:
|
|
7
|
+
* a read that finds other content or no object throws `UPLOAD_CHANGED`.
|
|
8
|
+
*/
|
|
9
|
+
export class StaticAssetPinnedFile {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.helper = opts.helper;
|
|
12
|
+
this.location = opts.location;
|
|
13
|
+
this.pin = opts.pin;
|
|
14
|
+
this.key = opts.location.object.key;
|
|
15
|
+
this.size = opts.size;
|
|
16
|
+
}
|
|
17
|
+
/** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */
|
|
18
|
+
static conditionOf(opts) {
|
|
19
|
+
const { pin } = opts;
|
|
20
|
+
return pin.versionId === undefined ? { ifMatch: pin.etag } : { versionId: pin.versionId };
|
|
21
|
+
}
|
|
22
|
+
/** The pin of what the storage holds now. An object with no ETag cannot be pinned. */
|
|
23
|
+
static pinOf(opts) {
|
|
24
|
+
const { stat, scope } = opts;
|
|
25
|
+
if (!stat.etag) {
|
|
26
|
+
throw getError({
|
|
27
|
+
message: `[${scope}] The storage reported no ETag for the pending object | a pinned validation needs one`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
etag: stat.etag,
|
|
32
|
+
versionId: StorageUtility.realVersionId({ value: stat.versionId }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async stream(opts) {
|
|
36
|
+
try {
|
|
37
|
+
const stream = await this.helper.getObjectStream({
|
|
38
|
+
...this.location,
|
|
39
|
+
range: opts?.range,
|
|
40
|
+
...StaticAssetPinnedFile.conditionOf({ pin: this.pin }),
|
|
41
|
+
});
|
|
42
|
+
return stream;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (StorageUtility.isPreconditionFailedError({ error }) ||
|
|
46
|
+
StorageUtility.isNotFoundError({ error })) {
|
|
47
|
+
throw getError({ error: StaticAssetErrors.UPLOAD_CHANGED, cause: error });
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=pinned-file.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinned-file.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/pinned-file.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAIf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAwB,MAAM,WAAW,CAAC;AAEpE;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAQhC,YAAY,IAKX;QACC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,2GAA2G;IAC3G,MAAM,CAAC,WAAW,CAAC,IAA8B;QAC/C,MAAM,EAAE,GAAG,EAAE,GAAG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AAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n StorageUtility,\n type IFileStat,\n type IObjectLocation,\n type IStorageHelper,\n} from '@venizia/ignis-helpers';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetErrors, type IStaticAssetPin } from '../common';\n\n/**\n * The pending file as `validation.handler` sees it. Every read asks the storage for exactly the\n * content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:\n * a read that finds other content or no object throws `UPLOAD_CHANGED`.\n */\nexport class StaticAssetPinnedFile {\n readonly key: string;\n readonly size: number;\n\n private readonly helper: IStorageHelper;\n private readonly location: IObjectLocation;\n private readonly pin: IStaticAssetPin;\n\n constructor(opts: {\n helper: IStorageHelper;\n location: IObjectLocation;\n pin: IStaticAssetPin;\n size: number;\n }) {\n this.helper = opts.helper;\n this.location = opts.location;\n this.pin = opts.pin;\n this.key = opts.location.object.key;\n this.size = opts.size;\n }\n\n /** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */\n static conditionOf(opts: { pin: IStaticAssetPin }): { ifMatch?: string; versionId?: string } {\n const { pin } = opts;\n\n return pin.versionId === undefined ? { ifMatch: pin.etag } : { versionId: pin.versionId };\n }\n\n /** The pin of what the storage holds now. An object with no ETag cannot be pinned. */\n static pinOf(opts: { stat: IFileStat; scope: string }): IStaticAssetPin {\n const { stat, scope } = opts;\n\n if (!stat.etag) {\n throw getError({\n message: `[${scope}] The storage reported no ETag for the pending object | a pinned validation needs one`,\n });\n }\n\n return {\n etag: stat.etag,\n versionId: StorageUtility.realVersionId({ value: stat.versionId }),\n };\n }\n\n async stream(opts?: {\n range?: { start: number; end?: number };\n }): Promise<ReadableStream<Uint8Array>> {\n try {\n const stream = await this.helper.getObjectStream({\n ...this.location,\n range: opts?.range,\n ...StaticAssetPinnedFile.conditionOf({ pin: this.pin }),\n });\n\n return stream;\n } catch (error) {\n if (\n StorageUtility.isPreconditionFailedError({ error }) ||\n StorageUtility.isNotFoundError({ error })\n ) {\n throw getError({ error: StaticAssetErrors.UPLOAD_CHANGED, cause: error });\n }\n\n throw error;\n }\n }\n}\n"]}
|
|
@@ -27,15 +27,14 @@ export declare class StaticAssetRouteOptionsUtility {
|
|
|
27
27
|
override: TStaticAssetRouteOverride;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* The route's body validator reads the whole multipart body, so a
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* The route's body validator reads the whole multipart body, so a limit checked in the handler arrives
|
|
31
|
+
* too late to save any memory. Appended after the application's own middleware, so a check of its own
|
|
32
|
+
* still answers first.
|
|
33
33
|
*
|
|
34
|
-
* The
|
|
35
|
-
*
|
|
36
|
-
* which has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
34
|
+
* The limit is `maxFiles` files of `maxBytes` each, plus their multipart framing. A chunked body, which
|
|
35
|
+
* has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
37
36
|
*/
|
|
38
|
-
static
|
|
37
|
+
static appendBodyLimit(opts: {
|
|
39
38
|
middleware: TStaticAssetRouteConfig['middleware'];
|
|
40
39
|
maxBytes: number;
|
|
41
40
|
maxFiles: number;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
2
|
-
import { getError } from '@venizia/ignis-helpers/core';
|
|
3
1
|
import { BodyLimits, RouteConfigResolver } from '@venizia/ignis-kernel';
|
|
4
|
-
import {
|
|
2
|
+
import { StaticAssetRouteKeys, } from '../common/index.js';
|
|
5
3
|
export class StaticAssetRouteOptionsUtility {
|
|
6
4
|
/** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */
|
|
7
5
|
static { this.ENVELOPE_BYTES_PER_FILE = 4 * 1024; }
|
|
@@ -51,35 +49,23 @@ export class StaticAssetRouteOptionsUtility {
|
|
|
51
49
|
};
|
|
52
50
|
}
|
|
53
51
|
/**
|
|
54
|
-
* The route's body validator reads the whole multipart body, so a
|
|
55
|
-
*
|
|
56
|
-
*
|
|
52
|
+
* The route's body validator reads the whole multipart body, so a limit checked in the handler arrives
|
|
53
|
+
* too late to save any memory. Appended after the application's own middleware, so a check of its own
|
|
54
|
+
* still answers first.
|
|
57
55
|
*
|
|
58
|
-
* The
|
|
59
|
-
*
|
|
60
|
-
* which has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
56
|
+
* The limit is `maxFiles` files of `maxBytes` each, plus their multipart framing. A chunked body, which
|
|
57
|
+
* has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
61
58
|
*/
|
|
62
|
-
static
|
|
59
|
+
static appendBodyLimit(opts) {
|
|
63
60
|
const { middleware, maxBytes, maxFiles } = opts;
|
|
64
|
-
const guard = async (context, next) => {
|
|
65
|
-
const declaredLength = Number(context.req.header(HTTP.Headers.CONTENT_LENGTH));
|
|
66
|
-
// Not authoritative: a multipart envelope is larger than its files, so the per-file check in the handler decides.
|
|
67
|
-
if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
|
|
68
|
-
throw getError({
|
|
69
|
-
error: StaticAssetErrors.UPLOAD_TOO_LARGE,
|
|
70
|
-
message: `Request body of ${declaredLength} bytes exceeds the maximum of ${maxBytes}`,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
await next();
|
|
74
|
-
};
|
|
75
61
|
const limit = BodyLimits.route({
|
|
76
62
|
maxSize: maxFiles * (maxBytes + StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_PER_FILE) +
|
|
77
63
|
StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_BASE,
|
|
78
64
|
});
|
|
79
65
|
if (!middleware) {
|
|
80
|
-
return [
|
|
66
|
+
return [limit];
|
|
81
67
|
}
|
|
82
|
-
return Array.isArray(middleware) ? [...middleware,
|
|
68
|
+
return Array.isArray(middleware) ? [...middleware, limit] : [middleware, limit];
|
|
83
69
|
}
|
|
84
70
|
}
|
|
85
71
|
//# sourceMappingURL=route-options.utility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-options.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/route-options.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"route-options.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/route-options.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,EACL,oBAAoB,GAGrB,MAAM,WAAW,CAAC;AAUnB,MAAM,OAAO,8BAA8B;IACzC,oKAAoK;aACpJ,4BAAuB,GAAG,CAAC,GAAG,IAAI,CAAC;IAEnD,qHAAqH;aACrG,wBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;IAEhD,sGAAsG;aAC9E,uBAAkB,GAAsC,IAAI,GAAG,CAAC;QACtF,oBAAoB,CAAC,kBAAkB;QACvC,oBAAoB,CAAC,uBAAuB;KAC7C,CAAC,CAAC;IAEH;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,IAIhB;QACC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAClC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,QAAQ,IAAI,EAAE,CAAC;QAEvE,MAAM,YAAY,GAChB,IAAI,EAAE,YAAY,KAAK,IAAI;YAC3B,8BAA8B,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC;YAC1D,YAAY,IAAI,IAAI;YACpB,SAAS,IAAI,IAAI,CAAC;QACpB,MAAM,QAAQ,GAAqB,YAAY;YAC7C,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;YAClC,CAAC,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;QAEhC,kEAAkE;QAClE,MAAM,iBAAiB,GAC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CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAClF,CAAC","sourcesContent":["import { BodyLimits, RouteConfigResolver } from '@venizia/ignis-kernel';\nimport type { IAuthRouteConfig, TRouteAuthConfig } from '@/base';\nimport {\n StaticAssetRouteKeys,\n type TStaticAssetRouteConfig,\n type TStaticAssetRouteKey,\n} from '../common';\nimport type { IStaticAssetResolvedEntry, IStaticAssetResolvedRoute } from './entry.utility';\n\n/** What a route is registered with: the application's overrides, and the auth it ends up with. */\nexport type TStaticAssetRouteOverride = Omit<\n TStaticAssetRouteConfig,\n 'authenticate' | 'authorize'\n> &\n Pick<IAuthRouteConfig, 'authenticate' | 'authorize'>;\n\nexport class StaticAssetRouteOptionsUtility {\n /** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */\n static readonly ENVELOPE_BYTES_PER_FILE = 4 * 1024;\n\n /** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */\n static readonly ENVELOPE_BYTES_BASE = 64 * 1024;\n\n /** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */\n private static readonly PUBLIC_READ_ROUTES: ReadonlySet<TStaticAssetRouteKey> = new Set([\n StaticAssetRouteKeys.GET_OBJECT_BY_NAME,\n StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,\n ]);\n\n /**\n * Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the\n * authentication and authorization it ends up with.\n *\n * Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the\n * entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for\n * the two read routes and loses to any auth the route sets itself.\n */\n static readRoute(opts: {\n key: TStaticAssetRouteKey;\n route?: IStaticAssetResolvedRoute;\n auth?: IStaticAssetResolvedEntry<never>['auth'];\n }): { isEnabled: boolean; override: TStaticAssetRouteOverride } {\n const { key, route, auth } = opts;\n const { authenticate, authorize, ...override } = route?.override ?? {};\n\n const isPublicRead =\n auth?.isPublicRead === true &&\n StaticAssetRouteOptionsUtility.PUBLIC_READ_ROUTES.has(key) &&\n authenticate == null &&\n authorize == null;\n const endpoint: TRouteAuthConfig = isPublicRead\n ? { authenticate: { skip: true } }\n : { authenticate, authorize };\n\n // An entry-level `skip` is no default at all: nothing to inherit.\n const entryAuthenticate =\n auth?.authenticate == null || auth.authenticate.skip === true ? undefined : auth.authenticate;\n const entryAuthorize =\n auth?.authorize == null || (!Array.isArray(auth.authorize) && 'skip' in auth.authorize)\n ? undefined\n : auth.authorize;\n\n return {\n isEnabled: route?.isEnabled ?? true,\n override: {\n ...override,\n authenticate: RouteConfigResolver.resolveAuthenticate({\n controller: entryAuthenticate,\n endpoint: endpoint.authenticate,\n }),\n authorize: RouteConfigResolver.resolveAuthorize({\n controller: entryAuthorize,\n endpoint,\n }),\n },\n };\n }\n\n /**\n * The route's body validator reads the whole multipart body, so a limit checked in the handler arrives\n * too late to save any memory. Appended after the application's own middleware, so a check of its own\n * still answers first.\n *\n * The limit is `maxFiles` files of `maxBytes` each, plus their multipart framing. A chunked body, which\n * has no declared length, is counted too. The per-file check in the handler still decides each file.\n */\n static appendBodyLimit(opts: {\n middleware: TStaticAssetRouteConfig['middleware'];\n maxBytes: number;\n maxFiles: number;\n }): NonNullable<TStaticAssetRouteConfig['middleware']> {\n const { middleware, maxBytes, maxFiles } = opts;\n\n const limit = BodyLimits.route({\n maxSize:\n maxFiles * (maxBytes + StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_PER_FILE) +\n StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_BASE,\n });\n\n if (!middleware) {\n return [limit];\n }\n\n return Array.isArray(middleware) ? [...middleware, limit] : [middleware, limit];\n }\n}\n"]}
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@hono/zod-openapi": "^1.6.3",
|
|
16
16
|
"@scalar/hono-api-reference": "^0.12.13",
|
|
17
|
-
"@venizia/ignis": "0.4.8-
|
|
18
|
-
"@venizia/ignis-boot": "0.4.8-
|
|
19
|
-
"@venizia/ignis-helpers": "0.4.8-
|
|
17
|
+
"@venizia/ignis": "0.4.8-14",
|
|
18
|
+
"@venizia/ignis-boot": "0.4.8-11",
|
|
19
|
+
"@venizia/ignis-helpers": "0.4.8-11",
|
|
20
20
|
"hono": "^4.13.13",
|
|
21
21
|
"winston": "^3.19.0",
|
|
22
22
|
"winston-daily-rotate-file": "^5.0.0",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/bun": "^1.4.3",
|
|
27
|
-
"@venizia/dev-configs": "0.4.8-
|
|
27
|
+
"@venizia/dev-configs": "0.4.8-8",
|
|
28
28
|
"eslint": "^10.13.0",
|
|
29
29
|
"oxlint": "1.89.0",
|
|
30
30
|
"oxlint-tsgolint": "7.0.2004",
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"dependencies": {},
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@types/bun": "^1.4.3",
|
|
7
|
-
"@venizia/dev-configs": "0.4.8-
|
|
8
|
-
"@venizia/ignis": "0.4.8-
|
|
7
|
+
"@venizia/dev-configs": "0.4.8-8",
|
|
8
|
+
"@venizia/ignis": "0.4.8-14",
|
|
9
9
|
"eslint": "^10.13.0",
|
|
10
10
|
"oxlint": "1.89.0",
|
|
11
11
|
"oxlint-tsgolint": "7.0.2004",
|
|
12
12
|
"typescript": "^6.0.3"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@venizia/ignis": "0.4.8-
|
|
15
|
+
"@venizia/ignis": "0.4.8-14"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"typecheck": "bun check",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis",
|
|
3
|
-
"version": "0.4.8-
|
|
3
|
+
"version": "0.4.8-14",
|
|
4
4
|
"description": "TypeScript server framework with decorator-based DI, the repository pattern and a component system, on Hono. Features auto-generated OpenAPI docs, Drizzle ORM type-safe SQL, JWT/Basic authentication, Casbin authorization, convention-based bootstrapping, and pluggable components for health checks, Swagger UI, mail, Socket.IO, and static assets. Built for Bun.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"access-control",
|
|
@@ -134,11 +134,11 @@
|
|
|
134
134
|
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
135
135
|
},
|
|
136
136
|
"dependencies": {
|
|
137
|
-
"@venizia/ignis-connectors": "0.4.8-
|
|
137
|
+
"@venizia/ignis-connectors": "0.4.8-13",
|
|
138
138
|
"@venizia/ignis-filter": "0.4.7-4",
|
|
139
|
-
"@venizia/ignis-helpers": "0.4.8-
|
|
139
|
+
"@venizia/ignis-helpers": "0.4.8-11",
|
|
140
140
|
"@venizia/ignis-inversion": "0.4.7-3",
|
|
141
|
-
"@venizia/ignis-kernel": "0.4.8-
|
|
141
|
+
"@venizia/ignis-kernel": "0.4.8-13",
|
|
142
142
|
"reflect-metadata": "^0.2.2"
|
|
143
143
|
},
|
|
144
144
|
"devDependencies": {
|
|
@@ -151,8 +151,8 @@
|
|
|
151
151
|
"@types/bun": "^1.4.3",
|
|
152
152
|
"@types/nodemailer": "^8.0.2",
|
|
153
153
|
"@types/pg": "^8.23.1",
|
|
154
|
-
"@venizia/dev-configs": "0.4.8-
|
|
155
|
-
"@venizia/ignis-boot": "0.4.8-
|
|
154
|
+
"@venizia/dev-configs": "0.4.8-8",
|
|
155
|
+
"@venizia/ignis-boot": "0.4.8-11",
|
|
156
156
|
"casbin": "^5.51.1",
|
|
157
157
|
"eslint": "^10.13.0",
|
|
158
158
|
"meilisearch": "^0.62.0",
|