@venizia/ignis 0.4.8-1 → 0.4.8-10
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 +7 -14
- package/dist/esm/base/applications/server.d.ts +12 -0
- package/dist/esm/base/applications/server.js +11 -0
- package/dist/esm/base/applications/server.js.map +1 -1
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.d.ts +1 -0
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +9 -2
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
- package/dist/esm/components/auth/authenticate/component.js +37 -1
- package/dist/esm/components/auth/authenticate/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +1 -0
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +56 -5
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +115 -11
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +2 -2
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +10 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +11 -0
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +25 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/index.d.ts +1 -0
- package/dist/esm/components/auth/authenticate/services/index.js +1 -0
- package/dist/esm/components/auth/authenticate/services/index.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +42 -0
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +162 -0
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -0
- package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +7 -1
- package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/service.strategy.js +2 -4
- package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/base-filtered.d.ts +1 -1
- package/dist/esm/components/auth/authorize/adapters/base-filtered.js +3 -2
- package/dist/esm/components/auth/authorize/adapters/base-filtered.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +2 -0
- package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/connector.d.ts +2 -2
- package/dist/esm/components/auth/authorize/adapters/connector.js +3 -2
- package/dist/esm/components/auth/authorize/adapters/connector.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/custom-grant-expander.js +1 -1
- package/dist/esm/components/auth/authorize/adapters/custom-grant-expander.js.map +1 -1
- package/dist/esm/components/health-check/reporter.js +2 -2
- package/dist/esm/components/health-check/reporter.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/types/verification.d.ts +1 -0
- package/dist/esm/components/mail/common/types/verification.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/utilities/mime.utility.js +4 -4
- package/dist/esm/components/mail/utilities/mime.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/static-asset/common/constants.d.ts +2 -0
- package/dist/esm/components/static-asset/common/constants.js +2 -0
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +6 -0
- package/dist/esm/components/static-asset/common/types.js.map +1 -1
- package/dist/esm/components/static-asset/controller/base.definition.d.ts +2 -0
- package/dist/esm/components/static-asset/controller/base.definition.js +6 -4
- package/dist/esm/components/static-asset/controller/base.definition.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +1 -0
- package/dist/esm/components/static-asset/controller/factory.js +17 -9
- package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
- package/dist/esm/components/static-asset/controller/meta-link.js +1 -1
- package/dist/esm/components/static-asset/controller/meta-link.js.map +1 -1
- package/dist/esm/components/static-asset/controller/route-options.d.ts +9 -0
- package/dist/esm/components/static-asset/controller/route-options.js +16 -3
- package/dist/esm/components/static-asset/controller/route-options.js.map +1 -1
- package/dist/esm/components/static-asset/ingest.d.ts +2 -2
- package/dist/esm/components/static-asset/ingest.js +2 -2
- package/dist/esm/components/static-asset/ingest.js.map +1 -1
- package/dist/esm/testing/assert-application-boots.d.ts +9 -0
- package/dist/esm/testing/assert-application-boots.js +11 -1
- 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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type BaseApplication } from '../../base/applications/index.js';
|
|
2
|
+
import { BaseComponent } from '@venizia/ignis-kernel';
|
|
3
|
+
import { type IServerInfoOptions } from './common/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Mounts the server info controller: `GET <path>/time`, public, no authentication.
|
|
6
|
+
*
|
|
7
|
+
* The rule of this component: it carries only data that is safe to publish and does not help an
|
|
8
|
+
* attacker. No version, runtime, pid, memory or environment - those stay in the gated
|
|
9
|
+
* `/health/stats`. It is separate from `HealthCheckComponent` on purpose: operators may lock
|
|
10
|
+
* `/health/*` away, and client features must not depend on it. `/server/info/*` is public by design.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { BaseApplication, ServerInfoComponent, type IServerInfoOptions } from '@venizia/ignis';
|
|
15
|
+
*
|
|
16
|
+
* abstract class App extends BaseApplication {
|
|
17
|
+
* preConfigure(): void {
|
|
18
|
+
* const options: IServerInfoOptions = { restOptions: { path: '/clock' } };
|
|
19
|
+
* this.component(ServerInfoComponent, { options });
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class ServerInfoComponent extends BaseComponent<IServerInfoOptions> {
|
|
25
|
+
private application;
|
|
26
|
+
constructor(application: BaseApplication);
|
|
27
|
+
/** Options given at the call site win over anything bound earlier, as in `HealthCheckComponent`. */
|
|
28
|
+
configure(opts?: IServerInfoOptions): Promise<void>;
|
|
29
|
+
binding(): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var ServerInfoComponent_1;
|
|
14
|
+
import { controller, inject } from '../../base/metadata/index.js';
|
|
15
|
+
import { BaseComponent, Binding, CoreBindings } from '@venizia/ignis-kernel';
|
|
16
|
+
import { ServerInfoBindingKeys } from './common/index.js';
|
|
17
|
+
import { ServerInfoController } from './controller.js';
|
|
18
|
+
const DEFAULT_REST_PATH = '/server/info';
|
|
19
|
+
const DEFAULT_OPTIONS = {
|
|
20
|
+
restOptions: { path: DEFAULT_REST_PATH },
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Mounts the server info controller: `GET <path>/time`, public, no authentication.
|
|
24
|
+
*
|
|
25
|
+
* The rule of this component: it carries only data that is safe to publish and does not help an
|
|
26
|
+
* attacker. No version, runtime, pid, memory or environment - those stay in the gated
|
|
27
|
+
* `/health/stats`. It is separate from `HealthCheckComponent` on purpose: operators may lock
|
|
28
|
+
* `/health/*` away, and client features must not depend on it. `/server/info/*` is public by design.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { BaseApplication, ServerInfoComponent, type IServerInfoOptions } from '@venizia/ignis';
|
|
33
|
+
*
|
|
34
|
+
* abstract class App extends BaseApplication {
|
|
35
|
+
* preConfigure(): void {
|
|
36
|
+
* const options: IServerInfoOptions = { restOptions: { path: '/clock' } };
|
|
37
|
+
* this.component(ServerInfoComponent, { options });
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
let ServerInfoComponent = ServerInfoComponent_1 = class ServerInfoComponent extends BaseComponent {
|
|
43
|
+
constructor(application) {
|
|
44
|
+
super({
|
|
45
|
+
scope: ServerInfoComponent_1.name,
|
|
46
|
+
initDefault: { enable: true, container: application },
|
|
47
|
+
bindings: {
|
|
48
|
+
[ServerInfoBindingKeys.SERVER_INFO_OPTIONS]: Binding.bind({
|
|
49
|
+
key: ServerInfoBindingKeys.SERVER_INFO_OPTIONS,
|
|
50
|
+
}).toValue(DEFAULT_OPTIONS),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
this.application = application;
|
|
54
|
+
}
|
|
55
|
+
/** Options given at the call site win over anything bound earlier, as in `HealthCheckComponent`. */
|
|
56
|
+
async configure(opts) {
|
|
57
|
+
// The base short-circuits a second call; binding before that check would swap the options
|
|
58
|
+
// under routes that were already mounted from the first ones.
|
|
59
|
+
if (this.isConfigured) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (opts !== undefined) {
|
|
63
|
+
this.application
|
|
64
|
+
.bind({ key: ServerInfoBindingKeys.SERVER_INFO_OPTIONS })
|
|
65
|
+
.toValue(opts);
|
|
66
|
+
}
|
|
67
|
+
await super.configure(opts);
|
|
68
|
+
}
|
|
69
|
+
binding() {
|
|
70
|
+
const options = this.application.get({
|
|
71
|
+
key: ServerInfoBindingKeys.SERVER_INFO_OPTIONS,
|
|
72
|
+
isOptional: true,
|
|
73
|
+
});
|
|
74
|
+
// A partially filled options binding (env/config driven) must not take the app down at boot.
|
|
75
|
+
const path = options?.restOptions?.path ?? DEFAULT_REST_PATH;
|
|
76
|
+
// `@controller` writes the PATH onto this shared class in the process-wide MetadataRegistry;
|
|
77
|
+
// two applications booted concurrently with different paths would race, as in health-check.
|
|
78
|
+
Reflect.decorate([controller({ path })], ServerInfoController);
|
|
79
|
+
this.application.controller(ServerInfoController);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
ServerInfoComponent = ServerInfoComponent_1 = __decorate([
|
|
83
|
+
__param(0, inject({ key: CoreBindings.APPLICATION_INSTANCE })),
|
|
84
|
+
__metadata("design:paramtypes", [Function])
|
|
85
|
+
], ServerInfoComponent);
|
|
86
|
+
export { ServerInfoComponent };
|
|
87
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/server-info/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAA2B,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,eAAe,GAAuB;IAC1C,WAAW,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE;CACzC,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AE,IAAI,EAAE,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAC/D,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACpD,CAAC;CACF,CAAA;AA9CY,mBAAmB;IAE3B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,mBAAmB,CA8C/B","sourcesContent":["import { type BaseApplication } from '@/base/applications';\nimport { controller, inject } from '@/base/metadata';\nimport { BaseComponent, Binding, CoreBindings } from '@venizia/ignis-kernel';\nimport { ServerInfoBindingKeys, type IServerInfoOptions } from './common';\nimport { ServerInfoController } from './controller';\n\nconst DEFAULT_REST_PATH = '/server/info';\nconst DEFAULT_OPTIONS: IServerInfoOptions = {\n restOptions: { path: DEFAULT_REST_PATH },\n};\n\n/**\n * Mounts the server info controller: `GET <path>/time`, public, no authentication.\n *\n * The rule of this component: it carries only data that is safe to publish and does not help an\n * attacker. No version, runtime, pid, memory or environment - those stay in the gated\n * `/health/stats`. It is separate from `HealthCheckComponent` on purpose: operators may lock\n * `/health/*` away, and client features must not depend on it. `/server/info/*` is public by design.\n *\n * @example\n * ```typescript\n * import { BaseApplication, ServerInfoComponent, type IServerInfoOptions } from '@venizia/ignis';\n *\n * abstract class App extends BaseApplication {\n * preConfigure(): void {\n * const options: IServerInfoOptions = { restOptions: { path: '/clock' } };\n * this.component(ServerInfoComponent, { options });\n * }\n * }\n * ```\n */\nexport class ServerInfoComponent extends BaseComponent<IServerInfoOptions> {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: ServerInfoComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [ServerInfoBindingKeys.SERVER_INFO_OPTIONS]: Binding.bind<IServerInfoOptions>({\n key: ServerInfoBindingKeys.SERVER_INFO_OPTIONS,\n }).toValue(DEFAULT_OPTIONS),\n },\n });\n }\n\n /** Options given at the call site win over anything bound earlier, as in `HealthCheckComponent`. */\n override async configure(opts?: IServerInfoOptions): Promise<void> {\n // The base short-circuits a second call; binding before that check would swap the options\n // under routes that were already mounted from the first ones.\n if (this.isConfigured) {\n return;\n }\n\n if (opts !== undefined) {\n this.application\n .bind<IServerInfoOptions>({ key: ServerInfoBindingKeys.SERVER_INFO_OPTIONS })\n .toValue(opts);\n }\n\n await super.configure(opts);\n }\n\n override binding(): void {\n const options = this.application.get<IServerInfoOptions>({\n key: ServerInfoBindingKeys.SERVER_INFO_OPTIONS,\n isOptional: true,\n });\n\n // A partially filled options binding (env/config driven) must not take the app down at boot.\n const path = options?.restOptions?.path ?? DEFAULT_REST_PATH;\n\n // `@controller` writes the PATH onto this shared class in the process-wide MetadataRegistry;\n // two applications booted concurrently with different paths would race, as in health-check.\n Reflect.decorate([controller({ path })], ServerInfoController);\n this.application.controller(ServerInfoController);\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseRestController } from '../../base/controllers/index.js';
|
|
2
|
+
import { type ValueOrPromise } from '@venizia/ignis-helpers/common';
|
|
3
|
+
/**
|
|
4
|
+
* Serves `GET <path>/time`, a PUBLIC route with no authentication.
|
|
5
|
+
*
|
|
6
|
+
* Everything this controller answers must be safe to publish and must not help an attacker: a
|
|
7
|
+
* clock and a time zone, nothing else. No version, runtime, pid, memory or environment - those
|
|
8
|
+
* belong to the gated `/health/stats`. A new route here needs that same test.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ServerInfoController extends BaseRestController {
|
|
11
|
+
constructor();
|
|
12
|
+
binding(): ValueOrPromise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BaseRestController } from '../../base/controllers/index.js';
|
|
2
|
+
import { OpenApiResponses } from '@venizia/ignis-kernel';
|
|
3
|
+
import { z } from '@hono/zod-openapi';
|
|
4
|
+
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
5
|
+
import { ServerInfoCacheControls, ServerInfoRestPaths } from './common/index.js';
|
|
6
|
+
import { ServerInfoReporter } from './reporter.js';
|
|
7
|
+
const RouteConfigs = {
|
|
8
|
+
TIME: {
|
|
9
|
+
method: HTTP.Methods.GET,
|
|
10
|
+
path: ServerInfoRestPaths.TIME,
|
|
11
|
+
responses: OpenApiResponses.jsonResponse({
|
|
12
|
+
schema: z
|
|
13
|
+
.object({
|
|
14
|
+
server: z.object({
|
|
15
|
+
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
16
|
+
time: z.string().regex(/^\d{2}:\d{2}:\d{2}\.\d{3}$/),
|
|
17
|
+
epoch: z.number().int(),
|
|
18
|
+
iso: z.iso.datetime({ offset: true }),
|
|
19
|
+
}),
|
|
20
|
+
tz: z.string(),
|
|
21
|
+
utc: z.object({
|
|
22
|
+
offset: z.string().regex(/^[+-]\d{2}:\d{2}$/),
|
|
23
|
+
minutes: z.number().int(),
|
|
24
|
+
iso: z.iso.datetime(),
|
|
25
|
+
}),
|
|
26
|
+
})
|
|
27
|
+
.openapi({
|
|
28
|
+
description: 'Server time',
|
|
29
|
+
examples: [
|
|
30
|
+
{
|
|
31
|
+
server: {
|
|
32
|
+
date: '2026-11-10',
|
|
33
|
+
time: '15:00:00.123',
|
|
34
|
+
epoch: 1794297600123,
|
|
35
|
+
iso: '2026-11-10T15:00:00.123+07:00',
|
|
36
|
+
},
|
|
37
|
+
tz: 'Asia/Ho_Chi_Minh',
|
|
38
|
+
utc: { offset: '+07:00', minutes: 420, iso: '2026-11-10T08:00:00.123Z' },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
42
|
+
description: 'The server clock: local date and time, epoch milliseconds, time zone, UTC offset and the UTC instant',
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Serves `GET <path>/time`, a PUBLIC route with no authentication.
|
|
48
|
+
*
|
|
49
|
+
* Everything this controller answers must be safe to publish and must not help an attacker: a
|
|
50
|
+
* clock and a time zone, nothing else. No version, runtime, pid, memory or environment - those
|
|
51
|
+
* belong to the gated `/health/stats`. A new route here needs that same test.
|
|
52
|
+
*/
|
|
53
|
+
export class ServerInfoController extends BaseRestController {
|
|
54
|
+
constructor() {
|
|
55
|
+
super({ scope: ServerInfoController.name });
|
|
56
|
+
this.definitions = RouteConfigs;
|
|
57
|
+
}
|
|
58
|
+
binding() {
|
|
59
|
+
this.bindRoute({ configs: RouteConfigs.TIME }).to({
|
|
60
|
+
handler: (context) => {
|
|
61
|
+
// A cached time is a wrong time; without this a cache or a service worker may serve it stale.
|
|
62
|
+
context.header(HTTP.Headers.CACHE_CONTROL, ServerInfoCacheControls.NO_STORE);
|
|
63
|
+
return context.json(ServerInfoReporter.buildTime(), HTTP.ResultCodes.RS_2.Ok);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/components/server-info/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE;QACJ,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;QACxB,IAAI,EAAE,mBAAmB,CAAC,IAAI;QAC9B,SAAS,EAAE,gBAAgB,CAAC,YAAY,CA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,EAAE,CAAC,CAAC;QAE5C,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC;IAClC,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;YAChD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;gBACnB,8FAA8F;gBAC9F,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,uBAAuB,CAAC,QAAQ,CAAC,CAAC;gBAE7E,OAAO,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAChF,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { BaseRestController } from '@/base/controllers';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { z } from '@hono/zod-openapi';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { ServerInfoCacheControls, ServerInfoRestPaths } from './common';\nimport { ServerInfoReporter } from './reporter';\n\nconst RouteConfigs = {\n TIME: {\n method: HTTP.Methods.GET,\n path: ServerInfoRestPaths.TIME,\n responses: OpenApiResponses.jsonResponse({\n schema: z\n .object({\n server: z.object({\n date: z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/),\n time: z.string().regex(/^\\d{2}:\\d{2}:\\d{2}\\.\\d{3}$/),\n epoch: z.number().int(),\n iso: z.iso.datetime({ offset: true }),\n }),\n tz: z.string(),\n utc: z.object({\n offset: z.string().regex(/^[+-]\\d{2}:\\d{2}$/),\n minutes: z.number().int(),\n iso: z.iso.datetime(),\n }),\n })\n .openapi({\n description: 'Server time',\n examples: [\n {\n server: {\n date: '2026-11-10',\n time: '15:00:00.123',\n epoch: 1794297600123,\n iso: '2026-11-10T15:00:00.123+07:00',\n },\n tz: 'Asia/Ho_Chi_Minh',\n utc: { offset: '+07:00', minutes: 420, iso: '2026-11-10T08:00:00.123Z' },\n },\n ],\n }),\n description:\n 'The server clock: local date and time, epoch milliseconds, time zone, UTC offset and the UTC instant',\n }),\n },\n} as const;\n\n/**\n * Serves `GET <path>/time`, a PUBLIC route with no authentication.\n *\n * Everything this controller answers must be safe to publish and must not help an attacker: a\n * clock and a time zone, nothing else. No version, runtime, pid, memory or environment - those\n * belong to the gated `/health/stats`. A new route here needs that same test.\n */\nexport class ServerInfoController extends BaseRestController {\n constructor() {\n super({ scope: ServerInfoController.name });\n\n this.definitions = RouteConfigs;\n }\n\n override binding(): ValueOrPromise<void> {\n this.bindRoute({ configs: RouteConfigs.TIME }).to({\n handler: (context) => {\n // A cached time is a wrong time; without this a cache or a service worker may serve it stale.\n context.header(HTTP.Headers.CACHE_CONTROL, ServerInfoCacheControls.NO_STORE);\n\n return context.json(ServerInfoReporter.buildTime(), HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/server-info/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC","sourcesContent":["export * from './common';\nexport * from './component';\nexport * from './controller';\nexport * from './reporter';\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IServerTime } from './common/index.js';
|
|
2
|
+
/** Assembles what `GET <path>/time` answers. Reads the clock and the process time zone, nothing else. */
|
|
3
|
+
export declare class ServerInfoReporter {
|
|
4
|
+
private static readonly MINUTES_PER_HOUR;
|
|
5
|
+
private static readonly MS_PER_SECOND;
|
|
6
|
+
private static readonly MS_PER_MINUTE;
|
|
7
|
+
private static readonly formatters;
|
|
8
|
+
private static getFormatter;
|
|
9
|
+
/** `+07:00` style text for an offset in minutes, positive east of UTC; `+00:00` for UTC itself. */
|
|
10
|
+
static formatUtcOffset(opts: {
|
|
11
|
+
minutes: number;
|
|
12
|
+
}): string;
|
|
13
|
+
/** The process time zone as the runtime resolved it (`TZ`, or the host setting). */
|
|
14
|
+
static resolveTimeZone(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Every field comes from the one `now`, so `server.iso`, `server.epoch` and `utc.iso` name the
|
|
17
|
+
* same instant. The offset is read from the zone AT that instant (a DST change moves it), not
|
|
18
|
+
* from the zone's standard offset.
|
|
19
|
+
*/
|
|
20
|
+
static buildTime(opts?: {
|
|
21
|
+
now?: Date;
|
|
22
|
+
timeZone?: string;
|
|
23
|
+
}): IServerTime;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=reporter.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Assembles what `GET <path>/time` answers. Reads the clock and the process time zone, nothing else. */
|
|
2
|
+
export class ServerInfoReporter {
|
|
3
|
+
static { this.MINUTES_PER_HOUR = 60; }
|
|
4
|
+
static { this.MS_PER_SECOND = 1000; }
|
|
5
|
+
static { this.MS_PER_MINUTE = 60_000; }
|
|
6
|
+
static { this.formatters = new Map(); }
|
|
7
|
+
static getFormatter(opts) {
|
|
8
|
+
const cached = ServerInfoReporter.formatters.get(opts.timeZone);
|
|
9
|
+
if (cached) {
|
|
10
|
+
return cached;
|
|
11
|
+
}
|
|
12
|
+
// `h23` keeps midnight as `00`; the default `h24` of some locales prints `24`.
|
|
13
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
14
|
+
timeZone: opts.timeZone,
|
|
15
|
+
hourCycle: 'h23',
|
|
16
|
+
year: 'numeric',
|
|
17
|
+
month: '2-digit',
|
|
18
|
+
day: '2-digit',
|
|
19
|
+
hour: '2-digit',
|
|
20
|
+
minute: '2-digit',
|
|
21
|
+
second: '2-digit',
|
|
22
|
+
});
|
|
23
|
+
ServerInfoReporter.formatters.set(opts.timeZone, formatter);
|
|
24
|
+
return formatter;
|
|
25
|
+
}
|
|
26
|
+
/** `+07:00` style text for an offset in minutes, positive east of UTC; `+00:00` for UTC itself. */
|
|
27
|
+
static formatUtcOffset(opts) {
|
|
28
|
+
const sign = opts.minutes < 0 ? '-' : '+';
|
|
29
|
+
const absolute = Math.abs(opts.minutes);
|
|
30
|
+
const hh = String(Math.trunc(absolute / ServerInfoReporter.MINUTES_PER_HOUR)).padStart(2, '0');
|
|
31
|
+
const mm = String(absolute % ServerInfoReporter.MINUTES_PER_HOUR).padStart(2, '0');
|
|
32
|
+
return `${sign}${hh}:${mm}`;
|
|
33
|
+
}
|
|
34
|
+
/** The process time zone as the runtime resolved it (`TZ`, or the host setting). */
|
|
35
|
+
static resolveTimeZone() {
|
|
36
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Every field comes from the one `now`, so `server.iso`, `server.epoch` and `utc.iso` name the
|
|
40
|
+
* same instant. The offset is read from the zone AT that instant (a DST change moves it), not
|
|
41
|
+
* from the zone's standard offset.
|
|
42
|
+
*/
|
|
43
|
+
static buildTime(opts) {
|
|
44
|
+
const now = opts?.now ?? new Date();
|
|
45
|
+
const tz = opts?.timeZone ?? ServerInfoReporter.resolveTimeZone();
|
|
46
|
+
const epoch = now.getTime();
|
|
47
|
+
const parts = {};
|
|
48
|
+
for (const part of ServerInfoReporter.getFormatter({ timeZone: tz }).formatToParts(now)) {
|
|
49
|
+
parts[part.type] = part.value;
|
|
50
|
+
}
|
|
51
|
+
const date = `${parts.year}-${parts.month}-${parts.day}`;
|
|
52
|
+
const ms = String(((epoch % ServerInfoReporter.MS_PER_SECOND) + ServerInfoReporter.MS_PER_SECOND) %
|
|
53
|
+
ServerInfoReporter.MS_PER_SECOND).padStart(3, '0');
|
|
54
|
+
const time = `${parts.hour}:${parts.minute}:${parts.second}.${ms}`;
|
|
55
|
+
// The wall clock, read back as if it were UTC, minus the true instant (both cut to the
|
|
56
|
+
// second) is the zone's offset. Intl has no offset field that is portable across runtimes.
|
|
57
|
+
const wallAsUtc = Date.UTC(Number(parts.year), Number(parts.month) - 1, Number(parts.day), Number(parts.hour), Number(parts.minute), Number(parts.second));
|
|
58
|
+
const epochSecond = Math.floor(epoch / ServerInfoReporter.MS_PER_SECOND) * ServerInfoReporter.MS_PER_SECOND;
|
|
59
|
+
const minutes = (wallAsUtc - epochSecond) / ServerInfoReporter.MS_PER_MINUTE;
|
|
60
|
+
const offset = ServerInfoReporter.formatUtcOffset({ minutes });
|
|
61
|
+
return {
|
|
62
|
+
server: { date, time, epoch, iso: `${date}T${time}${offset}` },
|
|
63
|
+
tz,
|
|
64
|
+
utc: { offset, minutes, iso: now.toISOString() },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=reporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.js","sourceRoot":"","sources":["../../../../src/components/server-info/reporter.ts"],"names":[],"mappings":"AAEA,yGAAyG;AACzG,MAAM,OAAO,kBAAkB;aACL,qBAAgB,GAAG,EAAE,CAAC;aACtB,kBAAa,GAAG,IAAI,CAAC;aACrB,kBAAa,GAAG,MAAM,CAAC;aAEvB,eAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEpE,MAAM,CAAC,YAAY,CAAC,IAA0B;QACpD,MAAM,MAAM,GAAG,kBAAkB,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEhE,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,+EAA+E;QAC/E,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YACjD,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,SAAS;YACd,IAAI,EAAE,SAAS;YACf,MAAM,EAAE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EAAE,CAAC,CAAC;QAE/D,OAAO;YACL,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,IAAI,IAAI,GAAG,MAAM,EAAE,EAAE;YAC9D,EAAE;YACF,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE;SACjD,CAAC;IACJ,CAAC","sourcesContent":["import type { IServerTime } from './common';\n\n/** Assembles what `GET <path>/time` answers. Reads the clock and the process time zone, nothing else. */\nexport class ServerInfoReporter {\n private static readonly MINUTES_PER_HOUR = 60;\n private static readonly MS_PER_SECOND = 1000;\n private static readonly MS_PER_MINUTE = 60_000;\n\n private static readonly formatters = new Map<string, Intl.DateTimeFormat>();\n\n private static getFormatter(opts: { timeZone: string }): Intl.DateTimeFormat {\n const cached = ServerInfoReporter.formatters.get(opts.timeZone);\n\n if (cached) {\n return cached;\n }\n\n // `h23` keeps midnight as `00`; the default `h24` of some locales prints `24`.\n const formatter = new Intl.DateTimeFormat('en-US', {\n timeZone: opts.timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n });\n ServerInfoReporter.formatters.set(opts.timeZone, formatter);\n\n return formatter;\n }\n\n /** `+07:00` style text for an offset in minutes, positive east of UTC; `+00:00` for UTC itself. */\n static formatUtcOffset(opts: { minutes: number }): string {\n const sign = opts.minutes < 0 ? '-' : '+';\n const absolute = Math.abs(opts.minutes);\n const hh = String(Math.trunc(absolute / ServerInfoReporter.MINUTES_PER_HOUR)).padStart(2, '0');\n const mm = String(absolute % ServerInfoReporter.MINUTES_PER_HOUR).padStart(2, '0');\n\n return `${sign}${hh}:${mm}`;\n }\n\n /** The process time zone as the runtime resolved it (`TZ`, or the host setting). */\n static resolveTimeZone(): string {\n return Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n /**\n * Every field comes from the one `now`, so `server.iso`, `server.epoch` and `utc.iso` name the\n * same instant. The offset is read from the zone AT that instant (a DST change moves it), not\n * from the zone's standard offset.\n */\n static buildTime(opts?: { now?: Date; timeZone?: string }): IServerTime {\n const now = opts?.now ?? new Date();\n const tz = opts?.timeZone ?? ServerInfoReporter.resolveTimeZone();\n const epoch = now.getTime();\n\n const parts: Record<string, string> = {};\n\n for (const part of ServerInfoReporter.getFormatter({ timeZone: tz }).formatToParts(now)) {\n parts[part.type] = part.value;\n }\n\n const date = `${parts.year}-${parts.month}-${parts.day}`;\n const ms = String(\n ((epoch % ServerInfoReporter.MS_PER_SECOND) + ServerInfoReporter.MS_PER_SECOND) %\n ServerInfoReporter.MS_PER_SECOND,\n ).padStart(3, '0');\n const time = `${parts.hour}:${parts.minute}:${parts.second}.${ms}`;\n\n // The wall clock, read back as if it were UTC, minus the true instant (both cut to the\n // second) is the zone's offset. Intl has no offset field that is portable across runtimes.\n const wallAsUtc = Date.UTC(\n Number(parts.year),\n Number(parts.month) - 1,\n Number(parts.day),\n Number(parts.hour),\n Number(parts.minute),\n Number(parts.second),\n );\n const epochSecond =\n Math.floor(epoch / ServerInfoReporter.MS_PER_SECOND) * ServerInfoReporter.MS_PER_SECOND;\n const minutes = (wallAsUtc - epochSecond) / ServerInfoReporter.MS_PER_MINUTE;\n const offset = ServerInfoReporter.formatUtcOffset({ minutes });\n\n return {\n server: { date, time, epoch, iso: `${date}T${time}${offset}` },\n tz,\n utc: { offset, minutes, iso: now.toISOString() },\n };\n }\n}\n"]}
|
|
@@ -27,6 +27,8 @@ export declare class MetaLinkRecreateActions {
|
|
|
27
27
|
export type TMetaLinkRecreateAction = TConstValue<typeof MetaLinkRecreateActions>;
|
|
28
28
|
/** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */
|
|
29
29
|
export declare const DEFAULT_PENDING_PREFIX = "pending/";
|
|
30
|
+
/** The most file parts one upload request may carry unless `parseMultipartBody.maxFiles` says otherwise. */
|
|
31
|
+
export declare const DEFAULT_MAX_UPLOAD_FILES = 20;
|
|
30
32
|
/** Reported in the body, never thrown: the bytes are stored, only the row is not. A CODE, because a 200 bypasses the middleware that strips the driver's `detail`/`table`/`constraint`. */
|
|
31
33
|
export declare const META_LINK_CREATE_FAILED = "META_LINK_CREATE_FAILED";
|
|
32
34
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -48,6 +48,8 @@ export class MetaLinkRecreateActions {
|
|
|
48
48
|
}
|
|
49
49
|
/** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */
|
|
50
50
|
export const DEFAULT_PENDING_PREFIX = 'pending/';
|
|
51
|
+
/** The most file parts one upload request may carry unless `parseMultipartBody.maxFiles` says otherwise. */
|
|
52
|
+
export const DEFAULT_MAX_UPLOAD_FILES = 20;
|
|
51
53
|
/** Reported in the body, never thrown: the bytes are stored, only the row is not. A CODE, because a 200 bypasses the middleware that strips the driver's `detail`/`table`/`constraint`. */
|
|
52
54
|
export const META_LINK_CREATE_FAILED = 'META_LINK_CREATE_FAILED';
|
|
53
55
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,uGAAuG;AACvG,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,CAAC,OAAO,CAAC,gBAAgB;IAC7B,IAAI,CAAC,OAAO,CAAC,aAAa;IAC1B,IAAI,CAAC,OAAO,CAAC,IAAI;IACjB,IAAI,CAAC,OAAO,CAAC,aAAa;CAClB,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAS;IACtD,WAAW;IACX,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,cAAc;IACd,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,WAAW;IACX,iBAAiB;IACjB,YAAY;IACZ,UAAU;CACX,CAAC,CAAC;AAEH,yGAAyG;AACzG,MAAM,OAAO,uBAAuB;aAClB,SAAI,GAAG,MAAM,CAAC;aACd,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/D,MAAM,CAAC,OAAO,CAAC,OAAe;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;;AAMH,+FAA+F;AAC/F,MAAM,OAAO,uBAAuB;aAClB,YAAO,GAAG,SAAS,CAAC;aACpB,cAAS,GAAG,WAAW,CAAC;aAExB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAErE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,yHAAyH;AACzH,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAEjD,2LAA2L;AAC3L,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\n/** `content-type` is absent on purpose: it is decided from the object name, never from the backend. */\nexport const WHITELIST_HEADERS = [\n HTTP.Headers.CONTENT_ENCODING,\n HTTP.Headers.CACHE_CONTROL,\n HTTP.Headers.ETAG,\n HTTP.Headers.LAST_MODIFIED,\n] as const;\n\n/**\n * Types the controller will let a browser render, keyed off the object name. Anything absent here is\n * served as an attachment, because a renderable upload on the API origin is stored XSS - and `nosniff`\n * cannot stop a type we declared ourselves. `image/svg+xml` is deliberately excluded: SVG carries script.\n */\nexport const RENDERABLE_CONTENT_TYPES = new Set<string>([\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/avif',\n 'image/bmp',\n 'image/x-icon',\n 'video/mp4',\n 'video/webm',\n 'audio/mpeg',\n 'audio/wav',\n 'audio/ogg',\n 'application/pdf',\n 'text/plain',\n 'text/csv',\n]);\n\n/** Storage backends a static asset controller can serve from. `isValid` checks a string against them. */\nexport class StaticAssetStorageTypes {\n static readonly DISK = 'disk';\n static readonly BUN_S3 = 'bun-s3';\n\n static readonly SCHEME_SET = new Set([this.DISK, this.BUN_S3]);\n\n static isValid(orgType: string): boolean {\n return this.SCHEME_SET.has(orgType);\n }\n}\n\n/** One of the `StaticAssetStorageTypes` values. */\nexport type TStaticAssetStorageType = TConstValue<typeof StaticAssetStorageTypes>;\n\n/** What `recreate-metalink` did: refreshed the rows of an object, or created its first one. */\nexport class MetaLinkRecreateActions {\n static readonly CREATED = 'created';\n static readonly REFRESHED = 'refreshed';\n\n static readonly SCHEME_SET = new Set([this.CREATED, this.REFRESHED]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** One of the `MetaLinkRecreateActions` values. */\nexport type TMetaLinkRecreateAction = TConstValue<typeof MetaLinkRecreateActions>;\n\n/** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */\nexport const DEFAULT_PENDING_PREFIX = 'pending/';\n\n/** Reported in the body, never thrown: the bytes are stored, only the row is not. A CODE, because a 200 bypasses the middleware that strips the driver's `detail`/`table`/`constraint`. */\nexport const META_LINK_CREATE_FAILED = 'META_LINK_CREATE_FAILED';\n"]}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,uGAAuG;AACvG,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,I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uBAAuB,GAAG,yBAAyB,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\n/** `content-type` is absent on purpose: it is decided from the object name, never from the backend. */\nexport const WHITELIST_HEADERS = [\n HTTP.Headers.CONTENT_ENCODING,\n HTTP.Headers.CACHE_CONTROL,\n HTTP.Headers.ETAG,\n HTTP.Headers.LAST_MODIFIED,\n] as const;\n\n/**\n * Types the controller will let a browser render, keyed off the object name. Anything absent here is\n * served as an attachment, because a renderable upload on the API origin is stored XSS - and `nosniff`\n * cannot stop a type we declared ourselves. `image/svg+xml` is deliberately excluded: SVG carries script.\n */\nexport const RENDERABLE_CONTENT_TYPES = new Set<string>([\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/avif',\n 'image/bmp',\n 'image/x-icon',\n 'video/mp4',\n 'video/webm',\n 'audio/mpeg',\n 'audio/wav',\n 'audio/ogg',\n 'application/pdf',\n 'text/plain',\n 'text/csv',\n]);\n\n/** Storage backends a static asset controller can serve from. `isValid` checks a string against them. */\nexport class StaticAssetStorageTypes {\n static readonly DISK = 'disk';\n static readonly BUN_S3 = 'bun-s3';\n\n static readonly SCHEME_SET = new Set([this.DISK, this.BUN_S3]);\n\n static isValid(orgType: string): boolean {\n return this.SCHEME_SET.has(orgType);\n }\n}\n\n/** One of the `StaticAssetStorageTypes` values. */\nexport type TStaticAssetStorageType = TConstValue<typeof StaticAssetStorageTypes>;\n\n/** What `recreate-metalink` did: refreshed the rows of an object, or created its first one. */\nexport class MetaLinkRecreateActions {\n static readonly CREATED = 'created';\n static readonly REFRESHED = 'refreshed';\n\n static readonly SCHEME_SET = new Set([this.CREATED, this.REFRESHED]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** One of the `MetaLinkRecreateActions` values. */\nexport type TMetaLinkRecreateAction = TConstValue<typeof MetaLinkRecreateActions>;\n\n/** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */\nexport const DEFAULT_PENDING_PREFIX = 'pending/';\n\n/** The most file parts one upload request may carry unless `parseMultipartBody.maxFiles` says otherwise. */\nexport const DEFAULT_MAX_UPLOAD_FILES = 20;\n\n/** Reported in the body, never thrown: the bytes are stored, only the row is not. A CODE, because a 200 bypasses the middleware that strips the driver's `detail`/`table`/`constraint`. */\nexport const META_LINK_CREATE_FAILED = 'META_LINK_CREATE_FAILED';\n"]}
|
|
@@ -12,6 +12,12 @@ export type TStaticAssetExtraOptions = {
|
|
|
12
12
|
parseMultipartBody?: {
|
|
13
13
|
storage?: TMultipartStorage;
|
|
14
14
|
uploadDir?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The most file parts one upload request may carry; more is refused with 413 before anything is written. The upload-policy request is bounded by the same number (more is a 422).
|
|
17
|
+
*
|
|
18
|
+
* @default DEFAULT_MAX_UPLOAD_FILES (20)
|
|
19
|
+
*/
|
|
20
|
+
maxFiles?: number;
|
|
15
21
|
};
|
|
16
22
|
/** `folderPath` carries the upload query's target folder - dropping it flattens nested uploads. */
|
|
17
23
|
normalizeNameFn?: (opts: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseRestController, IAuthRouteConfig, TRouteContext } from '@/base';\nimport type { IDuration } from '@venizia/ignis-helpers/common';\nimport type {\n BaseRelationalEntity,\n DefaultCRUDRepository,\n TTableObject,\n} from '@venizia/ignis-connectors/postgres';\nimport type {\n DiskHelper,\n IBucketRef,\n IFileStat,\n IObjectLocation,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n TUploadNaming,\n} from '@venizia/ignis-helpers';\nimport type { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';\nimport type { AnyType, TValueOrAsyncResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { TMultipartStorage } from '@venizia/ignis-helpers';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetStorageTypes } from './constants';\n\n/** Per-controller upload tuning: multipart parsing, name and link normalization, folder depth and size ceiling. */\nexport type TStaticAssetExtraOptions = {\n parseMultipartBody?: {\n storage?: TMultipartStorage;\n uploadDir?: string;\n };\n\n /** `folderPath` carries the upload query's target folder - dropping it flattens nested uploads. */\n normalizeNameFn?: (opts: { file: TUploadNaming }) => string;\n normalizeLinkFn?: (opts: IObjectLocation) => string;\n\n /**\n * Maximum folder nesting depth allowed in object paths.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n\n /** Largest file the UPLOAD route accepts. Absent means no ceiling. Checked against `content-length` before spooling, then per file after parsing. */\n maxBytes?: number;\n [key: string]: AnyType;\n};\n\n/** Decides the key one uploaded file is stored under. `defaultKey` is what IGNIS would have written. */\nexport type TObjectNameResolver = (opts: {\n bucket: IBucketRef;\n file: TUploadNaming;\n defaultKey: string;\n}) => string;\n\n/** Adds routes of the application's own to a generated asset controller. Runs after every built-in route, so a built-in route always wins a path collision. `basePath` is the mount path with exactly one leading slash. */\n/** Adds routes of the application's own. Registration order decides a path collision, so the same shape serves both the before and the after hook. */\nexport type TDefineExtraRoutes = (opts: {\n controller: BaseRestController;\n helper: IStorageHelper;\n basePath: string;\n}) => void;\n\n// Declared by hand rather than inferred: RouteHandler inference here is heavy.\n/** Path parameters of the bucket routes. */\nexport type TBucketParams = { bucketName: string };\n/** Path parameters of the object routes. */\nexport type TObjectParams = { bucketName: string; objectName: string };\n/** Labels recorded on the MetaLink row of an uploaded object. */\nexport type TUploadQuery = {\n principalType?: string;\n principalId?: string;\n variant?: string;\n /** Display order within the principal. Caller-supplied: deriving it would be a non-atomic read of `max(sequence)` then a write of `max + 1`. */\n sequence?: number;\n folderPath?: string;\n};\n/** Query of the list objects route. Every value arrives as a string. */\nexport type TListQuery = { prefix?: string; recursive?: string; maxKeys?: string };\n\n/** Enables the signed-policy upload flow, where the client posts bytes straight to the storage and IGNIS only signs the permission and verifies the commit. */\nexport type TDirectUploadOptions = {\n /** Who may ask for a policy. REQUIRED, not defaulted: this route hands out a write credential, and there is no safe default for that. */\n authorize: (opts: { context: TRouteContext }) => ValueOrPromise<boolean>;\n\n /** Signs the commit token. Keep it out of the repository and out of the client. */\n secretKey: string;\n\n /** The ceiling the policy carries as `content-length-range`. A signed PUT cannot express this at all, which is why this is a POST policy. */\n maxBytes: number;\n\n /**\n * Where a policy may write. The final key is NEVER in a policy, so content cannot be replaced after the commit.\n *\n * @default 'pending/'\n */\n pendingPrefix?: string;\n\n /**\n * How long a policy and its commit token stay good.\n *\n * @default StoragePresignDefaults.POST_EXPIRES_IN\n */\n expiresIn?: IDuration;\n\n /** Runs BEFORE the copy to the final key, so a hook that throws leaves the object under the pending prefix for a lifecycle rule to collect, rather than stranding it at the final key. */\n onCommit?: (opts: {\n bucket: IBucketRef;\n pendingObject: IObjectRef;\n object: IObjectRef;\n }) => ValueOrPromise<void>;\n};\n\n/** Body of the upload policy route: the files the client intends to upload. */\nexport type TUploadPolicyRequest = {\n files: Array<{ fileName: string; contentType?: string; size?: number }>;\n};\n\n/** The MetaLink table belongs to the application. `Schema` defaults to the table IGNIS ships, and widens to any table whose row carries the same fields. */\nexport type TMetaLinkConfig<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {\n model: TValueOrAsyncResolver<typeof BaseRelationalEntity<Schema>>;\n repository: TValueOrAsyncResolver<DefaultCRUDRepository<Schema>>;\n createMetaLink?: (opts: {\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n /** The caller's labels. Named for where they used to travel - they arrive in the request BODY now, as form fields on an upload and beside the commit token on a direct one. */\n query: TUploadQuery;\n }) => ValueOrPromise<{ count: number; data: TTableObject<Schema> }>;\n};\n\n/** The part of a built-in route an application may change. */\nexport type TStaticAssetRouteConfig = Partial<\n Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>\n> & {\n /**\n * Whether this route is registered.\n *\n * @default true\n */\n enabled?: boolean;\n};\n\n/** Per-route overrides for the built-in routes of a generated asset controller. A key left out keeps that route as built. */\nexport type TStaticAssetRoutes = {\n getBuckets?: TStaticAssetRouteConfig;\n getBucketByName?: TStaticAssetRouteConfig;\n createBucket?: TStaticAssetRouteConfig;\n deleteBucket?: TStaticAssetRouteConfig;\n\n upload?: TStaticAssetRouteConfig;\n listObjects?: TStaticAssetRouteConfig;\n deleteObject?: TStaticAssetRouteConfig;\n getObjectByName?: TStaticAssetRouteConfig;\n downloadObjectByName?: TStaticAssetRouteConfig;\n\n uploadPolicy?: TStaticAssetRouteConfig;\n uploadCommit?: TStaticAssetRouteConfig;\n\n recreateMetaLink?: TStaticAssetRouteConfig;\n};\n\n/** Static asset controllers keyed by an application-chosen name. Each entry pairs a storage type with its matching helper, and `useMetaLink: true` requires a `metaLink` config. */\nexport type TStaticAssetsComponentOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> = {\n [key: string]: {\n controller: {\n name: string;\n basePath: string;\n\n /**\n * Whether `/path` and `/path/` are different routes on this controller.\n *\n * @default true\n */\n isStrict?: boolean;\n\n /**\n * `true` serves a raw nested object path (`/objects/photos/2024/f.jpg`) - a URL shape change; a percent-encoded path keeps working either way.\n *\n * @default false\n */\n rawObjectPath?: boolean;\n\n /** The single bucket every object route uses. It leaves the URL (`/objects/{objectName}`) and the four bucket-management routes are not registered. The function form is read per request, so an environment variable can be read lazily. */\n bucket?: TValueOrAsyncResolver<string>;\n\n /**\n * The key scope this controller owns, e.g. `inventory/`. Every route refuses a key outside it\n * as a 404 without calling the storage, `listObjects` lists only inside it, and an upload key\n * must land inside it: the default name is placed there, a `resolveObjectName` or\n * `extra.normalizeNameFn` key outside it is refused. `maxFolderDepth` counts the folders below\n * it.\n *\n * @default every key in the bucket\n */\n keyPrefix?: string;\n\n routes?: TStaticAssetRoutes;\n\n /** Direct upload: the browser posts the bytes to the storage and IGNIS only signs the permission. Absent leaves both routes unregistered. Requires `bucket` - a policy names one bucket, and a bucket in the URL is a bucket the caller chooses. */\n directUpload?: TDirectUploadOptions;\n };\n extra?: TStaticAssetExtraOptions;\n\n /** Decides the stored object name of each uploaded file; absent keeps the storage helper's own naming. */\n resolveObjectName?: TObjectNameResolver;\n\n /** Registers the application's own routes BEFORE every built-in one, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */\n defineRoutesBefore?: TDefineExtraRoutes;\n\n /** Registers the application's own routes on the generated controller, after every built-in one. */\n defineExtraRoutes?: TDefineExtraRoutes;\n } & (\n | { storage: typeof StaticAssetStorageTypes.BUN_S3; helper: BunS3Helper }\n | { storage: typeof StaticAssetStorageTypes.DISK; helper: DiskHelper }\n ) &\n (\n | { useMetaLink?: false | undefined }\n | { useMetaLink: true; metaLink: TMetaLinkConfig<Schema> }\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseRestController, IAuthRouteConfig, TRouteContext } from '@/base';\nimport type { IDuration } from '@venizia/ignis-helpers/common';\nimport type {\n BaseRelationalEntity,\n DefaultCRUDRepository,\n TTableObject,\n} from '@venizia/ignis-connectors/postgres';\nimport type {\n DiskHelper,\n IBucketRef,\n IFileStat,\n IObjectLocation,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n TUploadNaming,\n} from '@venizia/ignis-helpers';\nimport type { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';\nimport type { AnyType, TValueOrAsyncResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { TMultipartStorage } from '@venizia/ignis-helpers';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetStorageTypes } from './constants';\n\n/** Per-controller upload tuning: multipart parsing, name and link normalization, folder depth and size ceiling. */\nexport type TStaticAssetExtraOptions = {\n parseMultipartBody?: {\n storage?: TMultipartStorage;\n uploadDir?: string;\n /**\n * The most file parts one upload request may carry; more is refused with 413 before anything is written. The upload-policy request is bounded by the same number (more is a 422).\n *\n * @default DEFAULT_MAX_UPLOAD_FILES (20)\n */\n maxFiles?: number;\n };\n\n /** `folderPath` carries the upload query's target folder - dropping it flattens nested uploads. */\n normalizeNameFn?: (opts: { file: TUploadNaming }) => string;\n normalizeLinkFn?: (opts: IObjectLocation) => string;\n\n /**\n * Maximum folder nesting depth allowed in object paths.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n\n /** Largest file the UPLOAD route accepts. Absent means no ceiling. Checked against `content-length` before spooling, then per file after parsing. */\n maxBytes?: number;\n [key: string]: AnyType;\n};\n\n/** Decides the key one uploaded file is stored under. `defaultKey` is what IGNIS would have written. */\nexport type TObjectNameResolver = (opts: {\n bucket: IBucketRef;\n file: TUploadNaming;\n defaultKey: string;\n}) => string;\n\n/** Adds routes of the application's own to a generated asset controller. Runs after every built-in route, so a built-in route always wins a path collision. `basePath` is the mount path with exactly one leading slash. */\n/** Adds routes of the application's own. Registration order decides a path collision, so the same shape serves both the before and the after hook. */\nexport type TDefineExtraRoutes = (opts: {\n controller: BaseRestController;\n helper: IStorageHelper;\n basePath: string;\n}) => void;\n\n// Declared by hand rather than inferred: RouteHandler inference here is heavy.\n/** Path parameters of the bucket routes. */\nexport type TBucketParams = { bucketName: string };\n/** Path parameters of the object routes. */\nexport type TObjectParams = { bucketName: string; objectName: string };\n/** Labels recorded on the MetaLink row of an uploaded object. */\nexport type TUploadQuery = {\n principalType?: string;\n principalId?: string;\n variant?: string;\n /** Display order within the principal. Caller-supplied: deriving it would be a non-atomic read of `max(sequence)` then a write of `max + 1`. */\n sequence?: number;\n folderPath?: string;\n};\n/** Query of the list objects route. Every value arrives as a string. */\nexport type TListQuery = { prefix?: string; recursive?: string; maxKeys?: string };\n\n/** Enables the signed-policy upload flow, where the client posts bytes straight to the storage and IGNIS only signs the permission and verifies the commit. */\nexport type TDirectUploadOptions = {\n /** Who may ask for a policy. REQUIRED, not defaulted: this route hands out a write credential, and there is no safe default for that. */\n authorize: (opts: { context: TRouteContext }) => ValueOrPromise<boolean>;\n\n /** Signs the commit token. Keep it out of the repository and out of the client. */\n secretKey: string;\n\n /** The ceiling the policy carries as `content-length-range`. A signed PUT cannot express this at all, which is why this is a POST policy. */\n maxBytes: number;\n\n /**\n * Where a policy may write. The final key is NEVER in a policy, so content cannot be replaced after the commit.\n *\n * @default 'pending/'\n */\n pendingPrefix?: string;\n\n /**\n * How long a policy and its commit token stay good.\n *\n * @default StoragePresignDefaults.POST_EXPIRES_IN\n */\n expiresIn?: IDuration;\n\n /** Runs BEFORE the copy to the final key, so a hook that throws leaves the object under the pending prefix for a lifecycle rule to collect, rather than stranding it at the final key. */\n onCommit?: (opts: {\n bucket: IBucketRef;\n pendingObject: IObjectRef;\n object: IObjectRef;\n }) => ValueOrPromise<void>;\n};\n\n/** Body of the upload policy route: the files the client intends to upload. */\nexport type TUploadPolicyRequest = {\n files: Array<{ fileName: string; contentType?: string; size?: number }>;\n};\n\n/** The MetaLink table belongs to the application. `Schema` defaults to the table IGNIS ships, and widens to any table whose row carries the same fields. */\nexport type TMetaLinkConfig<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {\n model: TValueOrAsyncResolver<typeof BaseRelationalEntity<Schema>>;\n repository: TValueOrAsyncResolver<DefaultCRUDRepository<Schema>>;\n createMetaLink?: (opts: {\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n /** The caller's labels. Named for where they used to travel - they arrive in the request BODY now, as form fields on an upload and beside the commit token on a direct one. */\n query: TUploadQuery;\n }) => ValueOrPromise<{ count: number; data: TTableObject<Schema> }>;\n};\n\n/** The part of a built-in route an application may change. */\nexport type TStaticAssetRouteConfig = Partial<\n Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>\n> & {\n /**\n * Whether this route is registered.\n *\n * @default true\n */\n enabled?: boolean;\n};\n\n/** Per-route overrides for the built-in routes of a generated asset controller. A key left out keeps that route as built. */\nexport type TStaticAssetRoutes = {\n getBuckets?: TStaticAssetRouteConfig;\n getBucketByName?: TStaticAssetRouteConfig;\n createBucket?: TStaticAssetRouteConfig;\n deleteBucket?: TStaticAssetRouteConfig;\n\n upload?: TStaticAssetRouteConfig;\n listObjects?: TStaticAssetRouteConfig;\n deleteObject?: TStaticAssetRouteConfig;\n getObjectByName?: TStaticAssetRouteConfig;\n downloadObjectByName?: TStaticAssetRouteConfig;\n\n uploadPolicy?: TStaticAssetRouteConfig;\n uploadCommit?: TStaticAssetRouteConfig;\n\n recreateMetaLink?: TStaticAssetRouteConfig;\n};\n\n/** Static asset controllers keyed by an application-chosen name. Each entry pairs a storage type with its matching helper, and `useMetaLink: true` requires a `metaLink` config. */\nexport type TStaticAssetsComponentOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> = {\n [key: string]: {\n controller: {\n name: string;\n basePath: string;\n\n /**\n * Whether `/path` and `/path/` are different routes on this controller.\n *\n * @default true\n */\n isStrict?: boolean;\n\n /**\n * `true` serves a raw nested object path (`/objects/photos/2024/f.jpg`) - a URL shape change; a percent-encoded path keeps working either way.\n *\n * @default false\n */\n rawObjectPath?: boolean;\n\n /** The single bucket every object route uses. It leaves the URL (`/objects/{objectName}`) and the four bucket-management routes are not registered. The function form is read per request, so an environment variable can be read lazily. */\n bucket?: TValueOrAsyncResolver<string>;\n\n /**\n * The key scope this controller owns, e.g. `inventory/`. Every route refuses a key outside it\n * as a 404 without calling the storage, `listObjects` lists only inside it, and an upload key\n * must land inside it: the default name is placed there, a `resolveObjectName` or\n * `extra.normalizeNameFn` key outside it is refused. `maxFolderDepth` counts the folders below\n * it.\n *\n * @default every key in the bucket\n */\n keyPrefix?: string;\n\n routes?: TStaticAssetRoutes;\n\n /** Direct upload: the browser posts the bytes to the storage and IGNIS only signs the permission. Absent leaves both routes unregistered. Requires `bucket` - a policy names one bucket, and a bucket in the URL is a bucket the caller chooses. */\n directUpload?: TDirectUploadOptions;\n };\n extra?: TStaticAssetExtraOptions;\n\n /** Decides the stored object name of each uploaded file; absent keeps the storage helper's own naming. */\n resolveObjectName?: TObjectNameResolver;\n\n /** Registers the application's own routes BEFORE every built-in one, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */\n defineRoutesBefore?: TDefineExtraRoutes;\n\n /** Registers the application's own routes on the generated controller, after every built-in one. */\n defineExtraRoutes?: TDefineExtraRoutes;\n } & (\n | { storage: typeof StaticAssetStorageTypes.BUN_S3; helper: BunS3Helper }\n | { storage: typeof StaticAssetStorageTypes.DISK; helper: DiskHelper }\n ) &\n (\n | { useMetaLink?: false | undefined }\n | { useMetaLink: true; metaLink: TMetaLinkConfig<Schema> }\n );\n};\n"]}
|
|
@@ -23,6 +23,8 @@ export declare class AssetDefinitionBuilder {
|
|
|
23
23
|
static build(opts: {
|
|
24
24
|
hasConfiguredBucket?: boolean;
|
|
25
25
|
rawObjectPath?: boolean;
|
|
26
|
+
/** The most files one upload-policy request may name. */
|
|
27
|
+
maxPolicyFiles?: number;
|
|
26
28
|
}): IAssetDefinitions;
|
|
27
29
|
}
|
|
28
30
|
//# sourceMappingURL=base.definition.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OpenApiResponses } from '@venizia/ignis-kernel';
|
|
2
2
|
import { z } from '@hono/zod-openapi';
|
|
3
3
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
4
|
-
import { MetaLinkRecreateActions } from '../common/constants.js';
|
|
4
|
+
import { DEFAULT_MAX_UPLOAD_FILES, MetaLinkRecreateActions } from '../common/constants.js';
|
|
5
5
|
/** The labels both upload paths take. They ride the BODY, not the URL - an identifier in a query string lands in every access log between the client and here. */
|
|
6
6
|
const uploadLabels = () => ({
|
|
7
7
|
principalType: z.string().optional(),
|
|
@@ -59,7 +59,7 @@ const fileStreamResponses = () => ({
|
|
|
59
59
|
*/
|
|
60
60
|
export class AssetDefinitionBuilder {
|
|
61
61
|
static build(opts) {
|
|
62
|
-
const { hasConfiguredBucket = false, rawObjectPath = false } = opts;
|
|
62
|
+
const { hasConfiguredBucket = false, rawObjectPath = false, maxPolicyFiles = DEFAULT_MAX_UPLOAD_FILES, } = opts;
|
|
63
63
|
const bucketPrefix = hasConfiguredBucket ? '' : '/buckets/{bucketName}';
|
|
64
64
|
// `{objectName}` is ONE segment: a folder path travels percent-encoded (`photos%2F2024%2Ff.jpg`).
|
|
65
65
|
// The catch-all also matches a RAW nested path; the encoded form keeps working either way.
|
|
@@ -144,11 +144,13 @@ export class AssetDefinitionBuilder {
|
|
|
144
144
|
content: {
|
|
145
145
|
'application/json': {
|
|
146
146
|
schema: z.object({
|
|
147
|
-
files: z
|
|
147
|
+
files: z
|
|
148
|
+
.array(z.object({
|
|
148
149
|
fileName: z.string().min(1),
|
|
149
150
|
contentType: z.string().optional(),
|
|
150
151
|
size: z.number().int().nonnegative().optional(),
|
|
151
|
-
}))
|
|
152
|
+
}))
|
|
153
|
+
.max(maxPolicyFiles),
|
|
152
154
|
}),
|
|
153
155
|
},
|
|
154
156
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.definition.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/base.definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAI9D,kKAAkK;AAClK,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,CAAC;IAC1B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACpC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAA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AAC,MAAM,EAAE,CAAC,QAAQ,EAAE;qBAC9B,CAAC,CACH;iBACF,CAAC;aACH;YACD,iBAAiB,EAAE;gBACjB,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,GAAG,YAAY,eAAe,aAAa,EAAE;gBACnD,OAAO,EAAE,aAAa,EAAE;gBACxB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;oBACvC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;wBACf,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;wBACpB,MAAM,EAAE,CAAC;6BACN,IAAI,CAAC,CAAC,uBAAuB,CAAC,SAAS,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;6BAC1E,OAAO,CAAC;4BACP,WAAW,EACT,uEAAuE;4BACzE,OAAO,EAAE,WAAW;yBACrB,CAAC;wBACJ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;wBACvE,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,0BAA0B,EAAE,CAAC;wBACjF,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;qBAC5B,CAAC;iBACH,CAAC;aACH;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { IAuthRouteConfig } from '@/base';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { z } from '@hono/zod-openapi';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { MetaLinkRecreateActions } from '../common/constants';\n\ntype TRouteRequest = NonNullable<IAuthRouteConfig['request']>;\n\n/** The labels both upload paths take. They ride the BODY, not the URL - an identifier in a query string lands in every access log between the client and here. */\nconst uploadLabels = () => ({\n principalType: z.string().optional(),\n principalId: z.string().or(z.number()).optional(),\n variant: z.string().optional(),\n sequence: z.coerce.number().int().optional(),\n});\n\nconst MultipartBodySchema = z.object({\n files: z.union([z.instanceof(File), z.array(z.instanceof(File))]).openapi({\n type: 'array',\n items: {\n type: 'string',\n format: 'binary',\n },\n }),\n ...uploadLabels(),\n folderPath: z.string().optional().openapi({\n description: 'Target folder path for uploaded files (e.g., \"photos/2024\")',\n example: 'photos/2024',\n }),\n});\n\nconst bucketNameParam = () =>\n z.string().openapi({\n param: {\n name: 'bucketName',\n in: 'path',\n },\n example: 'images',\n });\n\nconst objectNameParam = () =>\n z.string().openapi({\n param: {\n name: 'objectName',\n in: 'path',\n description: 'Object name or path (e.g., \"photo.jpg\" or \"photos/2024/photo.jpg\")',\n },\n example: 'photos/2024/photo.jpg',\n });\n\nconst fileStreamResponses = (): IAuthRouteConfig['responses'] => ({\n [HTTP.ResultCodes.RS_2.Ok]: {\n description: 'File stream response',\n content: {\n 'application/octet-stream': {\n schema: {\n type: 'string',\n format: 'binary',\n },\n },\n },\n },\n ...OpenApiResponses.errorResponses(),\n});\n\n/** The ten built-in asset routes. Only `path` and `request.params` differ between option combinations. */\nexport interface IAssetDefinitions {\n GET_BUCKETS: IAuthRouteConfig;\n GET_BUCKET_BY_NAME: IAuthRouteConfig;\n CREATE_BUCKET: IAuthRouteConfig;\n DELETE_BUCKET: IAuthRouteConfig;\n GET_OBJECT_BY_NAME: IAuthRouteConfig;\n DOWNLOAD_OBJECT_BY_NAME: IAuthRouteConfig;\n UPLOAD_POLICY: IAuthRouteConfig;\n UPLOAD_COMMIT: IAuthRouteConfig;\n UPLOAD: IAuthRouteConfig;\n DELETE_OBJECT: IAuthRouteConfig;\n LIST_OBJECTS: IAuthRouteConfig;\n RECREATE_METALINK: IAuthRouteConfig;\n}\n\n/**\n * Builds the route configs of one asset controller.\n * `hasConfiguredBucket` drops `/buckets/{bucketName}` and its param from every object route.\n * `rawObjectPath` appends the `{.+}` catch-all, the spelling `@hono/zod-openapi` translates.\n */\nexport class AssetDefinitionBuilder {\n static build(opts: {\n hasConfiguredBucket?: boolean;\n rawObjectPath?: boolean;\n }): IAssetDefinitions {\n const { hasConfiguredBucket = false, rawObjectPath = false } = opts;\n\n const bucketPrefix = hasConfiguredBucket ? '' : '/buckets/{bucketName}';\n\n // `{objectName}` is ONE segment: a folder path travels percent-encoded (`photos%2F2024%2Ff.jpg`).\n // The catch-all also matches a RAW nested path; the encoded form keeps working either way.\n const objectSegment = rawObjectPath ? '{objectName}{.+}' : '{objectName}';\n\n // A configured bucket is never in the URL, so a route whose only param was `bucketName` carries none.\n const bucketRequest = (): Pick<TRouteRequest, 'params'> =>\n hasConfiguredBucket ? {} : { params: z.object({ bucketName: bucketNameParam() }) };\n\n const objectRequest = (): TRouteRequest => ({\n params: hasConfiguredBucket\n ? z.object({ objectName: objectNameParam() })\n : z.object({ bucketName: bucketNameParam(), objectName: objectNameParam() }),\n });\n\n return {\n GET_BUCKETS: {\n method: 'get',\n path: '/buckets',\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n name: z.string(),\n creationDate: z.iso.datetime(),\n }),\n ),\n }),\n },\n GET_BUCKET_BY_NAME: {\n method: 'get',\n path: bucketPrefix,\n request: {\n params: z.object({ bucketName: bucketNameParam() }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z\n .object({\n name: z.string(),\n creationDate: z.iso.datetime(),\n })\n .nullable(),\n }),\n },\n CREATE_BUCKET: {\n method: 'post',\n path: bucketPrefix,\n request: {\n params: z.object({ bucketName: bucketNameParam() }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z\n .object({\n name: z.string(),\n creationDate: z.iso.datetime(),\n })\n .nullable(),\n }),\n },\n DELETE_BUCKET: {\n method: 'delete',\n path: bucketPrefix,\n request: {\n params: z.object({ bucketName: bucketNameParam() }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n isDeleted: z.boolean(),\n }),\n }),\n },\n GET_OBJECT_BY_NAME: {\n method: 'get',\n path: `${bucketPrefix}/objects/${objectSegment}`,\n request: objectRequest(),\n responses: fileStreamResponses(),\n },\n DOWNLOAD_OBJECT_BY_NAME: {\n method: 'get',\n path: `${bucketPrefix}/download/${objectSegment}`,\n request: objectRequest(),\n responses: fileStreamResponses(),\n },\n UPLOAD_POLICY: {\n method: 'post',\n path: `${bucketPrefix}/upload-policy`,\n request: {\n body: {\n content: {\n 'application/json': {\n schema: z.object({\n files: z.array(\n z.object({\n fileName: z.string().min(1),\n contentType: z.string().optional(),\n size: z.number().int().nonnegative().optional(),\n }),\n ),\n }),\n },\n },\n },\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n postURL: z.string(),\n formData: z.record(z.string(), z.string()),\n objectName: z.string(),\n commitToken: z.string(),\n expiresAt: z.string(),\n }),\n ),\n description: 'One signed POST policy per file, plus the token its commit is claimed with',\n }),\n },\n UPLOAD_COMMIT: {\n method: 'post',\n path: `${bucketPrefix}/upload-commit`,\n request: {\n body: {\n content: {\n 'application/json': {\n // The labels sit beside the token, not inside it: the token is an HMAC over\n // { bucket, key, expiresAt } and deliberately carries no business fields.\n schema: z.object({ commitToken: z.string().min(1), ...uploadLabels() }),\n },\n },\n },\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n bucket: z.object({ name: z.string() }),\n object: z.object({ key: z.string() }),\n link: z.string(),\n metaLink: z\n .union([z.object({ data: z.any() }), z.object({ error: z.string() })])\n .optional(),\n }),\n description: 'The object at its final key, copied out of the pending prefix',\n }),\n },\n UPLOAD: {\n method: 'post',\n path: `${bucketPrefix}/objects`,\n request: {\n ...bucketRequest(),\n body: {\n content: {\n 'multipart/form-data': {\n schema: MultipartBodySchema,\n },\n },\n },\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n bucket: z.object({ name: z.string() }),\n object: z.object({\n key: z.string(),\n size: z.number(),\n contentType: z.string(),\n }),\n link: z.string(),\n metaLink: z\n .union([z.object({ data: z.any() }), z.object({ error: z.string() })])\n .optional(),\n }),\n ),\n }),\n },\n DELETE_OBJECT: {\n method: 'delete',\n path: `${bucketPrefix}/objects/${objectSegment}`,\n request: objectRequest(),\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n success: z.boolean(),\n }),\n }),\n },\n LIST_OBJECTS: {\n method: 'get',\n path: `${bucketPrefix}/objects`,\n request: {\n ...bucketRequest(),\n query: z.object({\n prefix: z\n .string()\n .optional()\n .openapi({\n param: {\n name: 'prefix',\n in: 'query',\n description: 'Filter objects by prefix',\n },\n example: 'folder/',\n }),\n recursive: z\n .string()\n .optional()\n .openapi({\n param: {\n name: 'recursive',\n in: 'query',\n description: 'Recursive listing',\n },\n example: 'true',\n }),\n maxKeys: z\n .string()\n .optional()\n .openapi({\n param: {\n name: 'maxKeys',\n in: 'query',\n description: 'Maximum number of objects to return',\n },\n example: '100',\n }),\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n name: z.string().optional(),\n size: z.number().optional(),\n lastModified: z.iso.datetime().optional(),\n etag: z.string().optional(),\n prefix: z.string().optional(),\n }),\n ),\n }),\n },\n RECREATE_METALINK: {\n method: 'put',\n path: `${bucketPrefix}/meta-links/${objectSegment}`,\n request: objectRequest(),\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n success: z.boolean(),\n action: z\n .enum([MetaLinkRecreateActions.REFRESHED, MetaLinkRecreateActions.CREATED])\n .openapi({\n description:\n '`refreshed` when rows for the object existed, `created` when none did',\n example: 'refreshed',\n }),\n count: z.number().openapi({ description: 'Rows refreshed or created' }),\n metaLink: z.any().optional().openapi({ description: 'The first of `metaLinks`' }),\n metaLinks: z.array(z.any()),\n }),\n }),\n },\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.definition.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/base.definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,IAAI,EAA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AAC;IACJ,CAAC;CACF","sourcesContent":["import type { IAuthRouteConfig } from '@/base';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { z } from '@hono/zod-openapi';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { DEFAULT_MAX_UPLOAD_FILES, MetaLinkRecreateActions } from '../common/constants';\n\ntype TRouteRequest = NonNullable<IAuthRouteConfig['request']>;\n\n/** The labels both upload paths take. They ride the BODY, not the URL - an identifier in a query string lands in every access log between the client and here. */\nconst uploadLabels = () => ({\n principalType: z.string().optional(),\n principalId: z.string().or(z.number()).optional(),\n variant: z.string().optional(),\n sequence: z.coerce.number().int().optional(),\n});\n\nconst MultipartBodySchema = z.object({\n files: z.union([z.instanceof(File), z.array(z.instanceof(File))]).openapi({\n type: 'array',\n items: {\n type: 'string',\n format: 'binary',\n },\n }),\n ...uploadLabels(),\n folderPath: z.string().optional().openapi({\n description: 'Target folder path for uploaded files (e.g., \"photos/2024\")',\n example: 'photos/2024',\n }),\n});\n\nconst bucketNameParam = () =>\n z.string().openapi({\n param: {\n name: 'bucketName',\n in: 'path',\n },\n example: 'images',\n });\n\nconst objectNameParam = () =>\n z.string().openapi({\n param: {\n name: 'objectName',\n in: 'path',\n description: 'Object name or path (e.g., \"photo.jpg\" or \"photos/2024/photo.jpg\")',\n },\n example: 'photos/2024/photo.jpg',\n });\n\nconst fileStreamResponses = (): IAuthRouteConfig['responses'] => ({\n [HTTP.ResultCodes.RS_2.Ok]: {\n description: 'File stream response',\n content: {\n 'application/octet-stream': {\n schema: {\n type: 'string',\n format: 'binary',\n },\n },\n },\n },\n ...OpenApiResponses.errorResponses(),\n});\n\n/** The ten built-in asset routes. Only `path` and `request.params` differ between option combinations. */\nexport interface IAssetDefinitions {\n GET_BUCKETS: IAuthRouteConfig;\n GET_BUCKET_BY_NAME: IAuthRouteConfig;\n CREATE_BUCKET: IAuthRouteConfig;\n DELETE_BUCKET: IAuthRouteConfig;\n GET_OBJECT_BY_NAME: IAuthRouteConfig;\n DOWNLOAD_OBJECT_BY_NAME: IAuthRouteConfig;\n UPLOAD_POLICY: IAuthRouteConfig;\n UPLOAD_COMMIT: IAuthRouteConfig;\n UPLOAD: IAuthRouteConfig;\n DELETE_OBJECT: IAuthRouteConfig;\n LIST_OBJECTS: IAuthRouteConfig;\n RECREATE_METALINK: IAuthRouteConfig;\n}\n\n/**\n * Builds the route configs of one asset controller.\n * `hasConfiguredBucket` drops `/buckets/{bucketName}` and its param from every object route.\n * `rawObjectPath` appends the `{.+}` catch-all, the spelling `@hono/zod-openapi` translates.\n */\nexport class AssetDefinitionBuilder {\n static build(opts: {\n hasConfiguredBucket?: boolean;\n rawObjectPath?: boolean;\n /** The most files one upload-policy request may name. */\n maxPolicyFiles?: number;\n }): IAssetDefinitions {\n const {\n hasConfiguredBucket = false,\n rawObjectPath = false,\n maxPolicyFiles = DEFAULT_MAX_UPLOAD_FILES,\n } = opts;\n\n const bucketPrefix = hasConfiguredBucket ? '' : '/buckets/{bucketName}';\n\n // `{objectName}` is ONE segment: a folder path travels percent-encoded (`photos%2F2024%2Ff.jpg`).\n // The catch-all also matches a RAW nested path; the encoded form keeps working either way.\n const objectSegment = rawObjectPath ? '{objectName}{.+}' : '{objectName}';\n\n // A configured bucket is never in the URL, so a route whose only param was `bucketName` carries none.\n const bucketRequest = (): Pick<TRouteRequest, 'params'> =>\n hasConfiguredBucket ? {} : { params: z.object({ bucketName: bucketNameParam() }) };\n\n const objectRequest = (): TRouteRequest => ({\n params: hasConfiguredBucket\n ? z.object({ objectName: objectNameParam() })\n : z.object({ bucketName: bucketNameParam(), objectName: objectNameParam() }),\n });\n\n return {\n GET_BUCKETS: {\n method: 'get',\n path: '/buckets',\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n name: z.string(),\n creationDate: z.iso.datetime(),\n }),\n ),\n }),\n },\n GET_BUCKET_BY_NAME: {\n method: 'get',\n path: bucketPrefix,\n request: {\n params: z.object({ bucketName: bucketNameParam() }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z\n .object({\n name: z.string(),\n creationDate: z.iso.datetime(),\n })\n .nullable(),\n }),\n },\n CREATE_BUCKET: {\n method: 'post',\n path: bucketPrefix,\n request: {\n params: z.object({ bucketName: bucketNameParam() }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z\n .object({\n name: z.string(),\n creationDate: z.iso.datetime(),\n })\n .nullable(),\n }),\n },\n DELETE_BUCKET: {\n method: 'delete',\n path: bucketPrefix,\n request: {\n params: z.object({ bucketName: bucketNameParam() }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n isDeleted: z.boolean(),\n }),\n }),\n },\n GET_OBJECT_BY_NAME: {\n method: 'get',\n path: `${bucketPrefix}/objects/${objectSegment}`,\n request: objectRequest(),\n responses: fileStreamResponses(),\n },\n DOWNLOAD_OBJECT_BY_NAME: {\n method: 'get',\n path: `${bucketPrefix}/download/${objectSegment}`,\n request: objectRequest(),\n responses: fileStreamResponses(),\n },\n UPLOAD_POLICY: {\n method: 'post',\n path: `${bucketPrefix}/upload-policy`,\n request: {\n body: {\n content: {\n 'application/json': {\n schema: z.object({\n files: z\n .array(\n z.object({\n fileName: z.string().min(1),\n contentType: z.string().optional(),\n size: z.number().int().nonnegative().optional(),\n }),\n )\n .max(maxPolicyFiles),\n }),\n },\n },\n },\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n postURL: z.string(),\n formData: z.record(z.string(), z.string()),\n objectName: z.string(),\n commitToken: z.string(),\n expiresAt: z.string(),\n }),\n ),\n description: 'One signed POST policy per file, plus the token its commit is claimed with',\n }),\n },\n UPLOAD_COMMIT: {\n method: 'post',\n path: `${bucketPrefix}/upload-commit`,\n request: {\n body: {\n content: {\n 'application/json': {\n // The labels sit beside the token, not inside it: the token is an HMAC over\n // { bucket, key, expiresAt } and deliberately carries no business fields.\n schema: z.object({ commitToken: z.string().min(1), ...uploadLabels() }),\n },\n },\n },\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n bucket: z.object({ name: z.string() }),\n object: z.object({ key: z.string() }),\n link: z.string(),\n metaLink: z\n .union([z.object({ data: z.any() }), z.object({ error: z.string() })])\n .optional(),\n }),\n description: 'The object at its final key, copied out of the pending prefix',\n }),\n },\n UPLOAD: {\n method: 'post',\n path: `${bucketPrefix}/objects`,\n request: {\n ...bucketRequest(),\n body: {\n content: {\n 'multipart/form-data': {\n schema: MultipartBodySchema,\n },\n },\n },\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n bucket: z.object({ name: z.string() }),\n object: z.object({\n key: z.string(),\n size: z.number(),\n contentType: z.string(),\n }),\n link: z.string(),\n metaLink: z\n .union([z.object({ data: z.any() }), z.object({ error: z.string() })])\n .optional(),\n }),\n ),\n }),\n },\n DELETE_OBJECT: {\n method: 'delete',\n path: `${bucketPrefix}/objects/${objectSegment}`,\n request: objectRequest(),\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n success: z.boolean(),\n }),\n }),\n },\n LIST_OBJECTS: {\n method: 'get',\n path: `${bucketPrefix}/objects`,\n request: {\n ...bucketRequest(),\n query: z.object({\n prefix: z\n .string()\n .optional()\n .openapi({\n param: {\n name: 'prefix',\n in: 'query',\n description: 'Filter objects by prefix',\n },\n example: 'folder/',\n }),\n recursive: z\n .string()\n .optional()\n .openapi({\n param: {\n name: 'recursive',\n in: 'query',\n description: 'Recursive listing',\n },\n example: 'true',\n }),\n maxKeys: z\n .string()\n .optional()\n .openapi({\n param: {\n name: 'maxKeys',\n in: 'query',\n description: 'Maximum number of objects to return',\n },\n example: '100',\n }),\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: z.array(\n z.object({\n name: z.string().optional(),\n size: z.number().optional(),\n lastModified: z.iso.datetime().optional(),\n etag: z.string().optional(),\n prefix: z.string().optional(),\n }),\n ),\n }),\n },\n RECREATE_METALINK: {\n method: 'put',\n path: `${bucketPrefix}/meta-links/${objectSegment}`,\n request: objectRequest(),\n responses: OpenApiResponses.jsonResponse({\n schema: z.object({\n success: z.boolean(),\n action: z\n .enum([MetaLinkRecreateActions.REFRESHED, MetaLinkRecreateActions.CREATED])\n .openapi({\n description:\n '`refreshed` when rows for the object existed, `created` when none did',\n example: 'refreshed',\n }),\n count: z.number().openapi({ description: 'Rows refreshed or created' }),\n metaLink: z.any().optional().openapi({ description: 'The first of `metaLinks`' }),\n metaLinks: z.array(z.any()),\n }),\n }),\n },\n };\n }\n}\n"]}
|