@venizia/ignis 0.4.8-8 → 0.4.8
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/README.md +1 -0
- package/dist/esm/base/applications/base.js.map +1 -1
- package/dist/esm/components/api-reference/common/types.d.ts +6 -3
- package/dist/esm/components/api-reference/common/types.js.map +1 -1
- package/dist/esm/components/api-reference/component.js +8 -3
- package/dist/esm/components/api-reference/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/component.js +3 -2
- package/dist/esm/components/auth/authenticate/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +18 -1
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
- package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- 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/message.d.ts +4 -4
- package/dist/esm/components/mail/common/types/message.js.map +1 -1
- package/dist/esm/components/mail/common/types/options.d.ts +54 -10
- package/dist/esm/components/mail/common/types/options.js.map +1 -1
- package/dist/esm/components/mail/common/types/queue.d.ts +23 -12
- package/dist/esm/components/mail/common/types/queue.js.map +1 -1
- package/dist/esm/components/mail/common/types/template.d.ts +5 -4
- package/dist/esm/components/mail/common/types/template.js.map +1 -1
- package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
- package/dist/esm/components/mail/common/types/verification.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.d.ts +1 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +15 -28
- 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 +11 -6
- 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.d.ts +2 -3
- 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.d.ts +2 -3
- 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/generators/numeric-code.d.ts +1 -6
- package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
- package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
- package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
- package/dist/esm/components/mail/services/generators/random-token.js +9 -6
- package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
- package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
- 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 +7 -5
- 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 +12 -58
- package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
- package/dist/esm/components/mail/utilities/type.utility.js +6 -7
- package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
- package/dist/esm/components/server-info/common/constants.d.ts +6 -0
- package/dist/esm/components/server-info/common/constants.js +6 -0
- package/dist/esm/components/server-info/common/constants.js.map +1 -0
- package/dist/esm/components/server-info/common/index.d.ts +5 -0
- package/dist/esm/components/server-info/common/index.js +5 -0
- package/dist/esm/components/server-info/common/index.js.map +1 -0
- package/dist/esm/components/server-info/common/keys.d.ts +5 -0
- package/dist/esm/components/server-info/common/keys.js +5 -0
- package/dist/esm/components/server-info/common/keys.js.map +1 -0
- package/dist/esm/components/server-info/common/rest-paths.d.ts +5 -0
- package/dist/esm/components/server-info/common/rest-paths.js +5 -0
- package/dist/esm/components/server-info/common/rest-paths.js.map +1 -0
- package/dist/esm/components/server-info/common/types.d.ts +68 -0
- package/dist/esm/components/server-info/common/types.js +2 -0
- package/dist/esm/components/server-info/common/types.js.map +1 -0
- package/dist/esm/components/server-info/component.d.ts +31 -0
- package/dist/esm/components/server-info/component.js +87 -0
- package/dist/esm/components/server-info/component.js.map +1 -0
- package/dist/esm/components/server-info/controller.d.ts +14 -0
- package/dist/esm/components/server-info/controller.js +68 -0
- package/dist/esm/components/server-info/controller.js.map +1 -0
- package/dist/esm/components/server-info/index.d.ts +5 -0
- package/dist/esm/components/server-info/index.js +5 -0
- package/dist/esm/components/server-info/index.js.map +1 -0
- package/dist/esm/components/server-info/reporter.d.ts +25 -0
- package/dist/esm/components/server-info/reporter.js +68 -0
- package/dist/esm/components/server-info/reporter.js.map +1 -0
- package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
- package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
- package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
- package/dist/esm/components/static-asset/common/constants.js +75 -47
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
- package/dist/esm/components/static-asset/common/errors.js +31 -33
- package/dist/esm/components/static-asset/common/errors.js.map +1 -1
- package/dist/esm/components/static-asset/common/index.d.ts +1 -1
- package/dist/esm/components/static-asset/common/index.js +1 -1
- package/dist/esm/components/static-asset/common/index.js.map +1 -1
- package/dist/esm/components/static-asset/common/keys.d.ts +10 -2
- package/dist/esm/components/static-asset/common/keys.js +10 -2
- package/dist/esm/components/static-asset/common/keys.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +267 -147
- package/dist/esm/components/static-asset/common/types.js.map +1 -1
- package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
- package/dist/esm/components/static-asset/common/validation.js +8 -0
- package/dist/esm/components/static-asset/common/validation.js.map +1 -0
- package/dist/esm/components/static-asset/component.d.ts +4 -2
- package/dist/esm/components/static-asset/component.js +26 -31
- package/dist/esm/components/static-asset/component.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
- package/dist/esm/components/static-asset/controller/factory.js +26 -917
- 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 +62 -0
- package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
- package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
- package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
- package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
- package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
- package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
- package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
- package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
- package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
- package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
- package/dist/esm/components/static-asset/index.d.ts +2 -1
- package/dist/esm/components/static-asset/index.js +2 -1
- package/dist/esm/components/static-asset/index.js.map +1 -1
- package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
- package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
- package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
- package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
- package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
- package/dist/esm/components/static-asset/services/index.d.ts +3 -0
- package/dist/esm/components/static-asset/services/index.js +3 -0
- package/dist/esm/components/static-asset/services/index.js.map +1 -0
- package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
- package/dist/esm/components/static-asset/services/policy.service.js +104 -0
- package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
- package/dist/esm/components/static-asset/utilities/index.js +6 -0
- package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
- package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +5 -5
- package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +12 -10
- package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
- package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
- package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
- package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
- package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
- 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 +43 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
- package/dist/esm/testing/assert-application-boots.d.ts +2 -2
- package/dist/esm/testing/assert-application-boots.js +6 -2
- package/dist/esm/testing/assert-application-boots.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 +8 -8
- package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
- package/dist/esm/components/static-asset/common/commit-token.js +0 -48
- package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
- package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
- package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
- package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
- package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
- package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
- package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
- package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
- package/dist/esm/components/static-asset/controller/route-options.js +0 -47
- package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
- package/dist/esm/components/static-asset/ingest.js.map +0 -1
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
2
|
-
import { getError } from '@venizia/ignis-helpers/core';
|
|
3
|
-
import { BodyLimits } from '@venizia/ignis-kernel';
|
|
4
|
-
import { StaticAssetErrors } from '../common/index.js';
|
|
5
|
-
export class AssetRouteOptions {
|
|
6
|
-
/** 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
|
-
static { this.ENVELOPE_BYTES_PER_FILE = 4 * 1024; }
|
|
8
|
-
/** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */
|
|
9
|
-
static { this.ENVELOPE_BYTES_BASE = 64 * 1024; }
|
|
10
|
-
/** Splits the `enabled` switch off the route config: it is this component's field, never a Hono one. */
|
|
11
|
-
static readOverride(opts) {
|
|
12
|
-
const { enabled, ...override } = opts.route ?? {};
|
|
13
|
-
return { isEnabled: enabled !== false, override };
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* The route's body validator reads the whole multipart body, so a declared length checked in the
|
|
17
|
-
* handler arrives too late to save any memory. Appended after the application's own middleware, so
|
|
18
|
-
* a check of its own still answers first.
|
|
19
|
-
*
|
|
20
|
-
* The route also sets its own body limit: `maxFiles` files of `maxBytes` each, plus their multipart framing. An
|
|
21
|
-
* upload route that accepts more than the 5 MiB default would otherwise be held to the default, and a chunked body,
|
|
22
|
-
* which has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
23
|
-
*/
|
|
24
|
-
static appendLengthGuard(opts) {
|
|
25
|
-
const { middleware, maxBytes, maxFiles } = opts;
|
|
26
|
-
const guard = async (context, next) => {
|
|
27
|
-
const declaredLength = Number(context.req.header(HTTP.Headers.CONTENT_LENGTH));
|
|
28
|
-
// Not authoritative: a multipart envelope is larger than its files, so the per-file check in the handler decides.
|
|
29
|
-
if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
|
|
30
|
-
throw getError({
|
|
31
|
-
error: StaticAssetErrors.UPLOAD_TOO_LARGE,
|
|
32
|
-
message: `Request body of ${declaredLength} bytes exceeds the maximum of ${maxBytes}`,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
await next();
|
|
36
|
-
};
|
|
37
|
-
const limit = BodyLimits.route({
|
|
38
|
-
maxSize: maxFiles * (maxBytes + AssetRouteOptions.ENVELOPE_BYTES_PER_FILE) +
|
|
39
|
-
AssetRouteOptions.ENVELOPE_BYTES_BASE,
|
|
40
|
-
});
|
|
41
|
-
if (!middleware) {
|
|
42
|
-
return [guard, limit];
|
|
43
|
-
}
|
|
44
|
-
return Array.isArray(middleware) ? [...middleware, guard, limit] : [middleware, guard, limit];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=route-options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-options.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/route-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAgC,MAAM,WAAW,CAAC;AAE5E,MAAM,OAAO,iBAAiB;IAC5B,oKAAoK;aACpJ,4BAAuB,GAAG,CAAC,GAAG,IAAI,CAAC;IAEnD,qHAAqH;aACrG,wBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;IAEhD,wGAAwG;IACxG,MAAM,CAAC,YAAY,CAAC,IAAyC;QAI3D,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CA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/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { BodyLimits } from '@venizia/ignis-kernel';\nimport type { MiddlewareHandler } from 'hono';\nimport { StaticAssetErrors, type TStaticAssetRouteConfig } from '../common';\n\nexport class AssetRouteOptions {\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 /** Splits the `enabled` switch off the route config: it is this component's field, never a Hono one. */\n static readOverride(opts: { route?: TStaticAssetRouteConfig }): {\n isEnabled: boolean;\n override: Omit<TStaticAssetRouteConfig, 'enabled'>;\n } {\n const { enabled, ...override } = opts.route ?? {};\n\n return { isEnabled: enabled !== false, override };\n }\n\n /**\n * The route's body validator reads the whole multipart body, so a declared length checked in the\n * handler arrives too late to save any memory. Appended after the application's own middleware, so\n * a check of its own still answers first.\n *\n * The route also sets its own body limit: `maxFiles` files of `maxBytes` each, plus their multipart framing. An\n * upload route that accepts more than the 5 MiB default would otherwise be held to the default, and a chunked body,\n * which has no declared length, is counted too. The per-file check in the handler still decides each file.\n */\n static appendLengthGuard(opts: {\n middleware: TStaticAssetRouteConfig['middleware'];\n maxBytes: number;\n maxFiles: number;\n }): NonNullable<TStaticAssetRouteConfig['middleware']> {\n const { middleware, maxBytes, maxFiles } = opts;\n\n const guard: MiddlewareHandler = async (context, next) => {\n const declaredLength = Number(context.req.header(HTTP.Headers.CONTENT_LENGTH));\n\n // Not authoritative: a multipart envelope is larger than its files, so the per-file check in the handler decides.\n if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {\n throw getError({\n error: StaticAssetErrors.UPLOAD_TOO_LARGE,\n message: `Request body of ${declaredLength} bytes exceeds the maximum of ${maxBytes}`,\n });\n }\n\n await next();\n };\n\n const limit = BodyLimits.route({\n maxSize:\n maxFiles * (maxBytes + AssetRouteOptions.ENVELOPE_BYTES_PER_FILE) +\n AssetRouteOptions.ENVELOPE_BYTES_BASE,\n });\n\n if (!middleware) {\n return [guard, limit];\n }\n\n return Array.isArray(middleware) ? [...middleware, guard, limit] : [middleware, guard, limit];\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../../src/components/static-asset/ingest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,GAOhB,MAAM,wBAAwB,CAAC;AA+ChC,MAAM,cAAc,GAAG,CAAC,IAAuC,EAAU,EAAE;IACzE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACjC,MAAM,WAAW,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,IAAI,QAAQ,CAAC;IAC9E,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAEhE,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;AACjE,CAAC,CAAC;AAEF,uDAAuD;AACvD,MAAM,OAAO,WAAW;IACtB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAA2B;QAC9C,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;QAEtF,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/D,MAAM,UAAU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AI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,yDAAyD,GAAG,EAAE,EAAE,CAAC,CAAC;QAC9F,CAAC;QAED,MAAM,MAAM,GAAe,EAAE,GAAG,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;QAE1D,MAAM,MAAM,CAAC,WAAW,CAAC;YACvB,MAAM;YACN,MAAM;YACN,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;YAC9D,WAAW;YACX,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,eAAe,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAEjD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,uEAAuE,GAAG,EAAE;aACtF,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,MAAM,EAAE;gBACN,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;gBAC7B,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE;gBAC7C,IAAI;aACL;YACD,IAAI;SACL,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport {\n UrlIngest,\n UrlSafetyDefaults,\n UrlSafetyErrors,\n type IBucketRef,\n type IObjectRef,\n type IFileStat,\n type IStorageHelper,\n type IUploadResult,\n type IUrlSafetyPolicy,\n} from '@venizia/ignis-helpers';\n\n/**\n * What was stored, and what the backend reports about it. The stat is returned because `getStat`\n * already ran to size the result - a caller writing its own row would otherwise pay for it twice.\n *\n * This does NOT write a meta link. The columns an application attaches to an object - a principal,\n * a variant - come from its own domain, not from the object, so the row stays the caller's.\n */\nexport interface IIngestFromUrlResult {\n upload: IUploadResult;\n stat: IFileStat;\n}\n\n/** Where a fetched object lands, and what it is attached to. */\nexport interface IIngestFromUrlOptions {\n helper: IStorageHelper;\n url: string;\n bucket: IBucketRef;\n\n /**\n * Decides the stored key.\n *\n * **Absent, the key comes from the remote url's last path segment - which on an untrusted url is\n * named by whoever supplied it.** Pass `resolveKey` whenever the url is not your own; the\n * validation below bounds what it can do, but it does not make the remote name yours.\n */\n resolveKey?: (opts: { url: URL; contentType: string }) => string;\n folderPath?: string;\n\n /** Absent leaves IGNIS's own default: https only, no private address, 3 hops, 10s, 10 MB. */\n policy?: IUrlSafetyPolicy;\n\n /**\n * Folder nesting the key may carry.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n\n /**\n * Where the object is served from. **Required**: an absent hook used to yield an empty link, which\n * is exactly the value that satisfies a NOT NULL column and points nowhere.\n */\n normalizeLinkFn: (opts: { bucket: IBucketRef; object: IObjectRef }) => string;\n}\n\nconst readKeyFromUrl = (opts: { url: URL; folderPath?: string }): string => {\n const { url, folderPath } = opts;\n const lastSegment = url.pathname.split('/').filter(Boolean).pop() ?? 'object';\n const normalized = lastSegment.toLowerCase().replace(/ /g, '_');\n\n return folderPath ? `${folderPath}/${normalized}` : normalized;\n};\n\n/** Storing an object that came from somewhere else. */\nexport class AssetIngest {\n /**\n * Fetches an untrusted url and stores what comes back, without the bytes passing through this\n * process: the guarded body is capped and handed to `writeStream` as a stream.\n *\n * The url is guarded by `UrlIngest.fetchGuarded` - scheme allow-list, every resolved address\n * checked, redirects walked by hand with a per-hop re-check, and a timeout. The connection goes to the\n * address that was checked, so a DNS answer that changes afterwards is never used; see `UrlIngest.fetchGuarded`.\n *\n * The served content type is decided from the stored KEY, never from what the remote host\n * claimed - the same rule the asset routes apply, and for the same reason.\n */\n static async fromUrl(opts: IIngestFromUrlOptions): Promise<IIngestFromUrlResult> {\n const { helper, url, bucket, folderPath, policy, resolveKey, normalizeLinkFn } = opts;\n\n const response = await UrlIngest.fetchGuarded({ url, policy });\n const remoteType = response.headers.get('content-type')?.split(';')[0]?.trim() ?? '';\n const parsed = new URL(url);\n\n const key = resolveKey\n ? resolveKey({ url: parsed, contentType: remoteType })\n : readKeyFromUrl({ url: parsed, folderPath });\n\n // The helper's own default, not an unbounded one: an object arriving through ingest must obey\n // the same depth rule as one arriving through the upload route.\n if (!helper.isValidObjectKey({ object: { key }, maxDepth: opts.maxFolderDepth })) {\n await response.body?.cancel();\n throw getError({ message: `[AssetIngest.fromUrl] Invalid object key | key: ${key}` });\n }\n\n // Refused BEFORE the write starts, so a body that declares its size never opens a multipart\n // upload at all. A body that lies or omits the header is caught mid-flight by `capStream`, and\n // Bun's client answers that with `AbortMultipartUpload` - measured against a recording endpoint,\n // not assumed - so no orphaned parts are left behind either way.\n const declaredLength = Number(response.headers.get('content-length') ?? 0);\n const maxBytes = policy?.maxBytes ?? UrlSafetyDefaults.MAX_BYTES;\n\n if (declaredLength > maxBytes) {\n await response.body?.cancel();\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[AssetIngest.fromUrl] Body exceeds the cap | declared: ${declaredLength} | max: ${maxBytes}`,\n });\n }\n\n if (!response.body) {\n throw getError({ message: `[AssetIngest.fromUrl] Response carried no body | url: ${url}` });\n }\n\n const object: IObjectRef = { key };\n const contentType = helper.getMimeType({ filename: key });\n\n await helper.writeStream({\n bucket,\n object,\n source: UrlIngest.capStream({ source: response.body, policy }),\n contentType,\n maxFolderDepth: opts.maxFolderDepth,\n });\n\n const stat = await helper.getStat({ bucket, object });\n const link = normalizeLinkFn({ bucket, object });\n\n if (!link) {\n throw getError({\n message: `[AssetIngest.fromUrl] normalizeLinkFn returned an empty link | key: ${key}`,\n });\n }\n\n return {\n upload: {\n bucket: { name: bucket.name },\n object: { key, size: stat.size, contentType },\n link,\n },\n stat,\n };\n }\n}\n"]}
|