@venizia/ignis 0.4.8-11 → 0.4.8-13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/components/mail/common/types/queue.d.ts +8 -4
- package/dist/esm/components/mail/common/types/queue.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 +2 -16
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
- package/dist/esm/components/static-asset/common/constants.d.ts +25 -11
- package/dist/esm/components/static-asset/common/constants.js +40 -20
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/errors.d.ts +16 -39
- package/dist/esm/components/static-asset/common/errors.js +16 -36
- package/dist/esm/components/static-asset/common/errors.js.map +1 -1
- package/dist/esm/components/static-asset/common/index.d.ts +1 -0
- package/dist/esm/components/static-asset/common/index.js +1 -0
- package/dist/esm/components/static-asset/common/index.js.map +1 -1
- package/dist/esm/components/static-asset/common/keys.d.ts +1 -1
- package/dist/esm/components/static-asset/common/keys.js +1 -1
- package/dist/esm/components/static-asset/common/keys.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +203 -140
- 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 +1 -1
- package/dist/esm/components/static-asset/component.js +13 -55
- package/dist/esm/components/static-asset/component.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +185 -67
- package/dist/esm/components/static-asset/controller/factory.js +32 -821
- package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.d.ts +61 -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 +74 -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 +131 -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 +17 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js +127 -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 +174 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
- 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 +53 -16
- package/dist/esm/components/static-asset/services/commitment.service.js +114 -35
- package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -1
- package/dist/esm/components/static-asset/services/policy.service.d.ts +7 -3
- package/dist/esm/components/static-asset/services/policy.service.js +29 -7
- package/dist/esm/components/static-asset/services/policy.service.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +5 -1
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js +58 -2
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js +153 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/index.d.ts +3 -0
- package/dist/esm/components/static-asset/utilities/index.js +3 -0
- package/dist/esm/components/static-asset/utilities/index.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/ingest.utility.js +2 -4
- package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/key-scope.utility.d.ts +6 -2
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js +24 -6
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/meta-link.utility.d.ts +2 -2
- package/dist/esm/components/static-asset/utilities/meta-link.utility.js +6 -6
- package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +2 -2
- package/dist/esm/components/static-asset/utilities/object-link.utility.js +4 -5
- package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +20 -5
- package/dist/esm/components/static-asset/utilities/route-options.utility.js +44 -6
- package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -1
- package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +13 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js +16 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
- package/dist/presets/app/preset.json +4 -4
- package/dist/presets/lib/preset.json +3 -3
- package/dist/presets/shared/preset.json +1 -1
- package/package.json +6 -6
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TMailBackoffType } from '../constants.js';
|
|
2
2
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
3
|
-
import type {
|
|
3
|
+
import type { IRedisHelper } from '@venizia/ignis-helpers';
|
|
4
4
|
import type { BullMQExecutorModes, MailQueueExecutorTypes } from '../constants.js';
|
|
5
5
|
/** Per-job options for a queued verification mail. `delay` and `backoff.delay` are milliseconds; `attempts` is the total number of tries, first included. */
|
|
6
6
|
export interface IMailQueueOptions {
|
|
@@ -43,10 +43,14 @@ export interface IQueueJobPayload {
|
|
|
43
43
|
export interface IInternalQueueMailExecutorOpts {
|
|
44
44
|
identifier: string;
|
|
45
45
|
}
|
|
46
|
-
/** Options of the BullMQ mail executor: the Redis
|
|
46
|
+
/** Options of the BullMQ mail executor: the Redis helper, the queue `identifier` and BullMQ `name`, and which of queue and workers this process runs. */
|
|
47
47
|
export interface IBullMQMailExecutorOpts {
|
|
48
|
-
/**
|
|
49
|
-
|
|
48
|
+
/**
|
|
49
|
+
* A ready single, cluster or sentinel helper. The queue and each worker duplicate its client, and the
|
|
50
|
+
* application closes it: the executor never disconnects a connection it did not create. On a cluster
|
|
51
|
+
* the queue name is wrapped in a `{hash tag}` so its keys share one slot.
|
|
52
|
+
*/
|
|
53
|
+
redis: IRedisHelper;
|
|
50
54
|
queue: {
|
|
51
55
|
identifier: string;
|
|
52
56
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/queue.ts"],"names":[],"mappings":"","sourcesContent":["import type { TMailBackoffType } from '../constants';\nimport type { TConstValue } from '@venizia/ignis-helpers/common';\nimport type {
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/queue.ts"],"names":[],"mappings":"","sourcesContent":["import type { TMailBackoffType } from '../constants';\nimport type { TConstValue } from '@venizia/ignis-helpers/common';\nimport type { IRedisHelper } from '@venizia/ignis-helpers';\nimport type { BullMQExecutorModes, MailQueueExecutorTypes } from '../constants';\n\n/** Per-job options for a queued verification mail. `delay` and `backoff.delay` are milliseconds; `attempts` is the total number of tries, first included. */\nexport interface IMailQueueOptions {\n priority?: number;\n delay?: number;\n attempts?: number;\n backoff?: {\n type: TMailBackoffType;\n delay: number;\n };\n}\n\n/** Result a queue processor returns for one verification mail; returning `success: false` marks the job failed so it is retried. */\nexport interface IMailProcessorResult {\n success: boolean;\n message: string;\n expiresInMinutes: number;\n nextResendAt?: string;\n}\n\n/** Result of enqueueing a verification mail; `queued` is `false` and `result` is set when the executor ran the mail inline. */\nexport interface IMailQueueResult {\n jobId?: string;\n queued: boolean;\n message: string;\n result?: IMailProcessorResult;\n}\n\n/** Queues verification mails and runs them through the processor registered with `setProcessor`. */\nexport interface IMailQueueExecutor {\n enqueueVerificationEmail(email: string, options?: IMailQueueOptions): Promise<IMailQueueResult>;\n setProcessor(processor: (email: string) => Promise<IMailProcessorResult>): void;\n}\n\n/** Envelope every queue-backed executor stores for one pending verification email. */\nexport interface IQueueJobPayload {\n id: string;\n email: string;\n options?: IMailQueueOptions;\n attempts: number;\n scheduledAt: number;\n}\n\n/** Options of the in-process queue executor; `identifier` names its queue. */\nexport interface IInternalQueueMailExecutorOpts {\n identifier: string;\n}\n\n/** Options of the BullMQ mail executor: the Redis helper, the queue `identifier` and BullMQ `name`, and which of queue and workers this process runs. */\nexport interface IBullMQMailExecutorOpts {\n /**\n * A ready single, cluster or sentinel helper. The queue and each worker duplicate its client, and the\n * application closes it: the executor never disconnects a connection it did not create. On a cluster\n * the queue name is wrapped in a `{hash tag}` so its keys share one slot.\n */\n redis: IRedisHelper;\n queue: { identifier: string; name: string };\n mode: TConstValue<typeof BullMQExecutorModes>;\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. */\n module?: typeof import('bullmq');\n}\n\n/** Selects and configures the mail queue executor; the field matching `type` (`internalQueue` or `bullmq`) is required for that type. */\nexport interface IMailQueueExecutorConfig {\n type: TConstValue<typeof MailQueueExecutorTypes>;\n internalQueue?: IInternalQueueMailExecutorOpts;\n bullmq?: IBullMQMailExecutorOpts;\n}\n"]}
|
|
@@ -32,7 +32,7 @@ export declare class BullMQMailExecutorHelper extends BaseHelper implements IMai
|
|
|
32
32
|
/** Closes every worker without stopping at the first failure, always empties the list, and returns failures instead of throwing so teardown can continue. */
|
|
33
33
|
private closeWorkers;
|
|
34
34
|
clearWorkers(): Promise<void>;
|
|
35
|
-
/**
|
|
35
|
+
/** Closes the workers, then the queue. Every step runs even if an earlier one failed; failures are reported once, at the end. The Redis helper is the application's, so it stays open. */
|
|
36
36
|
close(): Promise<void>;
|
|
37
37
|
getWorkerCount(): number;
|
|
38
38
|
getMode(): TConstValue<typeof BullMQExecutorModes>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
|
|
2
|
-
import { RedisSingleHelper } from '@venizia/ignis-helpers';
|
|
3
2
|
import { BullMQHelper } from '@venizia/ignis-helpers/bullmq';
|
|
4
3
|
import { BullMQExecutorModes, MailBackoffTypes, MailErrorCodes, MailExecutorErrors, } from '../../common/index.js';
|
|
5
4
|
/** Mail queue executor backed by BullMQ. The `mode` option decides whether this process holds the queue, the workers, or both; a processor returning `success: false` fails the job so BullMQ retries it. */
|
|
@@ -9,10 +8,7 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
9
8
|
this.workerHelpers = [];
|
|
10
9
|
this.jobIdCounter = 0;
|
|
11
10
|
this.mode = opts.mode;
|
|
12
|
-
this.redisConnection =
|
|
13
|
-
...opts.redis,
|
|
14
|
-
maxRetry: undefined,
|
|
15
|
-
});
|
|
11
|
+
this.redisConnection = opts.redis;
|
|
16
12
|
this.bullmqModule = opts.module;
|
|
17
13
|
this.queueIdentifier = opts.queue.identifier;
|
|
18
14
|
this.queueName = opts.queue.name;
|
|
@@ -162,7 +158,7 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
162
158
|
await this.closeWorkers();
|
|
163
159
|
this.logger.for(this.clearWorkers.name).info('All workers cleared | Count: %d', count);
|
|
164
160
|
}
|
|
165
|
-
/**
|
|
161
|
+
/** Closes the workers, then the queue. Every step runs even if an earlier one failed; failures are reported once, at the end. The Redis helper is the application's, so it stays open. */
|
|
166
162
|
async close() {
|
|
167
163
|
const result = await this.closeWorkers();
|
|
168
164
|
const failures = [...result];
|
|
@@ -176,16 +172,6 @@ export class BullMQMailExecutorHelper extends BaseHelper {
|
|
|
176
172
|
this.logger.for(this.close.name).error('Failed to close queue | error: %s', closeError);
|
|
177
173
|
}
|
|
178
174
|
}
|
|
179
|
-
try {
|
|
180
|
-
await this.redisConnection.disconnect();
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
const disconnectError = error instanceof Error ? error : getError({ message: String(error) });
|
|
184
|
-
failures.push(disconnectError);
|
|
185
|
-
this.logger
|
|
186
|
-
.for(this.close.name)
|
|
187
|
-
.error('Failed to disconnect redis | error: %s', disconnectError);
|
|
188
|
-
}
|
|
189
175
|
if (failures.length > 0) {
|
|
190
176
|
throw getError({
|
|
191
177
|
message: `[close] Incomplete BullMQ mail executor teardown | failures: ${failures
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bull-mq-executor.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/executors/bull-mq-executor.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,E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AAE;YAC/E,QAAQ,EAAE,OAAO,EAAE,QAAQ;YAC3B,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAC;YAChC,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,gBAAgB,CAAC,WAAW;gBAC5D,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;aACvC;YACD,gBAAgB,EAAE,IAAI;YACtB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,OAAO;YACL,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,KAAK;YAC1B,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,0CAA0C;SACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { RedisSingleHelper } from '@venizia/ignis-helpers';\nimport type { TConstValue } from '@/helpers';\nimport { BullMQHelper } from '@venizia/ignis-helpers/bullmq';\nimport type {\n IBullMQMailExecutorOpts,\n IMailProcessorResult,\n IMailQueueExecutor,\n IMailQueueOptions,\n IMailQueueResult,\n IQueueJobPayload,\n} from '../../common';\nimport {\n BullMQExecutorModes,\n MailBackoffTypes,\n MailErrorCodes,\n MailExecutorErrors,\n} from '../../common';\nimport type { Job } from 'bullmq';\n\n/** Mail queue executor backed by BullMQ. The `mode` option decides whether this process holds the queue, the workers, or both; a processor returning `success: false` fails the job so BullMQ retries it. */\nexport class BullMQMailExecutorHelper extends BaseHelper implements IMailQueueExecutor {\n private queueIdentifier: string;\n private queueName: string;\n private mode: TConstValue<typeof BullMQExecutorModes>;\n\n private queueHelper?: BullMQHelper<IQueueJobPayload, IMailQueueResult>;\n private workerHelpers: BullMQHelper<IQueueJobPayload, IMailProcessorResult>[] = [];\n private redisConnection: RedisSingleHelper;\n private readonly bullmqModule?: typeof import('bullmq');\n private jobIdCounter = 0;\n\n private processor?: (email: string) => Promise<IMailProcessorResult>;\n\n constructor(opts: IBullMQMailExecutorOpts) {\n super({ scope: BullMQMailExecutorHelper.name });\n\n this.mode = opts.mode;\n\n this.redisConnection = new RedisSingleHelper({\n ...opts.redis,\n maxRetry: undefined,\n });\n\n this.bullmqModule = opts.module;\n this.queueIdentifier = opts.queue.identifier;\n this.queueName = opts.queue.name;\n\n this.initQueue(opts.queue);\n }\n\n initQueue(queue: { identifier: string; name: string }) {\n switch (this.mode) {\n case BullMQExecutorModes.QUEUE_ONLY:\n case BullMQExecutorModes.BOTH: {\n this.queueHelper = new BullMQHelper<IQueueJobPayload, IMailQueueResult>({\n identifier: queue.identifier,\n queueName: queue.name,\n redisConnection: this.redisConnection,\n role: 'queue',\n module: this.bullmqModule,\n });\n\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (queue enabled) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n break;\n }\n default: {\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (worker-only mode) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n\n break;\n }\n }\n }\n\n async setProcessor(\n processor: (email: string) => Promise<IMailProcessorResult>,\n opts?: {\n numberOfWorkers?: number;\n concurrencyPerWorker?: number;\n lockDuration?: number;\n },\n ): Promise<void> {\n this.processor = processor;\n\n if (this.mode === BullMQExecutorModes.QUEUE_ONLY) {\n this.logger\n .for(this.setProcessor.name)\n .warn('Skipping worker creation in queue-only mode. Workers will not be started.');\n\n return;\n }\n\n const numberOfWorkers = opts?.numberOfWorkers ?? 1;\n const concurrencyPerWorker = opts?.concurrencyPerWorker ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n await this.clearWorkers();\n\n for (let i = 0; i < numberOfWorkers; i++) {\n this.addWorker({\n workerIdentifier: `${this.queueIdentifier}-worker-${i}`,\n concurrency: concurrencyPerWorker,\n lockDuration,\n });\n }\n\n this.logger\n .for(this.setProcessor.name)\n .info(\n 'Processor registered | Mode: %s | Workers: %d | Concurrency per worker: %d',\n this.mode,\n numberOfWorkers,\n concurrencyPerWorker,\n );\n }\n\n addWorker(opts: { workerIdentifier: string; concurrency?: number; lockDuration?: number }): void {\n if (!this.processor) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const workerIdentifier = opts.workerIdentifier;\n const concurrency = opts?.concurrency ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n const workerHelper = new BullMQHelper<IQueueJobPayload, IMailProcessorResult>({\n identifier: workerIdentifier,\n queueName: this.queueName,\n redisConnection: this.redisConnection,\n role: 'worker',\n module: this.bullmqModule,\n numberOfWorker: concurrency,\n lockDuration,\n onWorkerData: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n const maxAttempts = job.data.options?.attempts ?? 3;\n\n this.logger\n .for('onWorkerData')\n .info(\n 'Processing job | Worker: %s | jobId: %s | email: %s | attempt: %d/%d',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade + 1,\n maxAttempts,\n );\n\n if (!this.processor) {\n // Returning undefined would let BullMQ mark the job COMPLETED and (with removeOnComplete) delete it - mail silently dropped.\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] ${MailExecutorErrors.PROCESSOR_NOT_SET} | jobId: ${job.data.id}`,\n });\n }\n\n const result = await this.processor(job.data.email);\n\n // A processor reports SMTP rejection by RETURNING `{ success: false }`; BullMQ only treats a REJECTION as failure, so resolving completes the job - no retry, no DLQ.\n if (result?.success === false) {\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] Processor reported failure | jobId: ${job.data.id} | reason: ${result.message}`,\n });\n }\n\n return result;\n },\n onWorkerDataCompleted: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n this.logger\n .for('onWorkerDataCompleted')\n .info(\n 'Job completed | Worker: %s | jobId: %s | email: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n );\n },\n onWorkerDataFail: async (\n job: Job<IQueueJobPayload, IMailProcessorResult> | undefined,\n error: Error,\n ) => {\n if (job) {\n const maxAttempts = job.data.options?.attempts ?? 3;\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Job failed | Worker: %s | jobId: %s | email: %s | attempt: %d/%d | error: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade,\n maxAttempts,\n error.message,\n );\n } else {\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Worker error (no job) | Worker: %s | error: %s',\n workerIdentifier,\n error.message,\n );\n }\n },\n });\n\n this.workerHelpers.push(workerHelper);\n\n this.logger\n .for(this.addWorker.name)\n .info(\n 'Worker added | Identifier: %s | Concurrency: %d | Total workers: %d',\n workerIdentifier,\n concurrency,\n this.workerHelpers.length,\n );\n }\n\n async removeWorker(index: number): Promise<boolean> {\n if (index < 0 || index >= this.workerHelpers.length) {\n this.logger.for(this.removeWorker.name).warn('Invalid worker index: %d', index);\n\n return false;\n }\n\n // Dropped from the list BEFORE the close is awaited: a rejecting close must not leave a half-closed worker still counted and still handed jobs.\n const [workerHelper] = this.workerHelpers.splice(index, 1);\n await workerHelper.worker.close();\n\n this.logger\n .for(this.removeWorker.name)\n .info('Worker removed | Index: %d | Remaining workers: %d', index, this.workerHelpers.length);\n\n return true;\n }\n\n /** Closes every worker without stopping at the first failure, always empties the list, and returns failures instead of throwing so teardown can continue. */\n private async closeWorkers(): Promise<Error[]> {\n const workerHelpers = this.workerHelpers;\n this.workerHelpers = [];\n\n const results = await Promise.allSettled(\n workerHelpers.map((workerHelper) => workerHelper.worker.close()),\n );\n\n const failures: Error[] = [];\n\n for (const result of results) {\n if (result.status !== 'rejected') {\n continue;\n }\n\n const error =\n result.reason instanceof Error\n ? result.reason\n : getError({ message: `Worker close failed | reason: ${String(result.reason)}` });\n\n failures.push(error);\n this.logger.for('closeWorkers').error('Failed to close worker | error: %s', error.message);\n }\n\n return failures;\n }\n\n async clearWorkers(): Promise<void> {\n const count = this.workerHelpers.length;\n await this.closeWorkers();\n\n this.logger.for(this.clearWorkers.name).info('All workers cleared | Count: %d', count);\n }\n\n /** Full teardown: workers -> queue -> Redis. Every step runs even if an earlier one failed (skipping leaks a queue client + Redis socket); failures are reported once, at the end. */\n async close(): Promise<void> {\n const result = await this.closeWorkers();\n const failures: Error[] = [...result];\n\n if (this.queueHelper) {\n try {\n await this.queueHelper.queue.close();\n } catch (error) {\n const closeError = error instanceof Error ? error : getError({ message: String(error) });\n failures.push(closeError);\n this.logger.for(this.close.name).error('Failed to close queue | error: %s', closeError);\n }\n }\n\n try {\n await this.redisConnection.disconnect();\n } catch (error) {\n const disconnectError = error instanceof Error ? error : getError({ message: String(error) });\n failures.push(disconnectError);\n this.logger\n .for(this.close.name)\n .error('Failed to disconnect redis | error: %s', disconnectError);\n }\n\n if (failures.length > 0) {\n throw getError({\n message: `[close] Incomplete BullMQ mail executor teardown | failures: ${failures\n .map((failure) => failure.message)\n .join(' | ')}`,\n });\n }\n\n this.logger.for(this.close.name).info('BullMQ mail executor closed | Mode: %s', this.mode);\n }\n\n getWorkerCount(): number {\n return this.workerHelpers.length;\n }\n\n getMode(): TConstValue<typeof BullMQExecutorModes> {\n return this.mode;\n }\n\n async enqueueVerificationEmail(\n email: string,\n options?: IMailQueueOptions,\n ): Promise<IMailQueueResult> {\n if (this.mode === BullMQExecutorModes.WORKER_ONLY) {\n throw getError({\n message: 'Cannot enqueue jobs in worker-only mode. Set mode to \"queue-only\" or \"both\".',\n });\n }\n\n if (!this.queueHelper) {\n throw getError({\n message: 'Queue helper not initialized. This should not happen in queue-enabled mode.',\n });\n }\n\n if (!this.processor && this.mode !== BullMQExecutorModes.QUEUE_ONLY) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;\n const job: IQueueJobPayload = {\n id: jobId,\n email,\n options,\n attempts: 0,\n scheduledAt: Date.now() + (options?.delay ?? 0),\n };\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .info(\n 'Queuing email to BullMQ/Redis | jobId: %s | email: %s | mode: %s',\n jobId,\n email,\n this.mode,\n );\n\n const bullJob = await this.queueHelper.queue.add('send-verification-email', job, {\n priority: options?.priority,\n delay: options?.delay,\n attempts: options?.attempts ?? 3,\n backoff: {\n type: options?.backoff?.type ?? MailBackoffTypes.EXPONENTIAL,\n delay: options?.backoff?.delay ?? 1000,\n },\n removeOnComplete: true,\n removeOnFail: false,\n });\n\n return {\n jobId: bullJob.id ?? jobId,\n queued: true,\n message: 'Email queued successfully (BullMQ/Redis)',\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bull-mq-executor.helper.js","sourceRoot":"","sources":["../../../../../../src/components/mail/helpers/executors/bull-mq-executor.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGnE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAS7D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB,6MAA6M;AAC7M,MAAM,OAAO,wBAAyB,SAAQ,UAAU;IAatD,YAAY,IAA6B;QACvC,KAAK,CAAC,EAAE,KAAK,EAAE,wBAAwB,CAAC,IAAI,EAAE,CAAC,CAAC;QAR1C,kBAAa,GAA2D,EAAE,CAAC;QAG3E,iBAAY,GAAG,CAAC,CAAC;QAOvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEtB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAE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W,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,EAAE,GAAG,EAAE;YAC/E,QAAQ,EAAE,OAAO,EAAE,QAAQ;YAC3B,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAC;YAChC,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,gBAAgB,CAAC,WAAW;gBAC5D,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;aACvC;YACD,gBAAgB,EAAE,IAAI;YACtB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,OAAO;YACL,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,KAAK;YAC1B,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,0CAA0C;SACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { IRedisHelper } from '@venizia/ignis-helpers';\nimport type { TConstValue } from '@/helpers';\nimport { BullMQHelper } from '@venizia/ignis-helpers/bullmq';\nimport type {\n IBullMQMailExecutorOpts,\n IMailProcessorResult,\n IMailQueueExecutor,\n IMailQueueOptions,\n IMailQueueResult,\n IQueueJobPayload,\n} from '../../common';\nimport {\n BullMQExecutorModes,\n MailBackoffTypes,\n MailErrorCodes,\n MailExecutorErrors,\n} from '../../common';\nimport type { Job } from 'bullmq';\n\n/** Mail queue executor backed by BullMQ. The `mode` option decides whether this process holds the queue, the workers, or both; a processor returning `success: false` fails the job so BullMQ retries it. */\nexport class BullMQMailExecutorHelper extends BaseHelper implements IMailQueueExecutor {\n private queueIdentifier: string;\n private queueName: string;\n private mode: TConstValue<typeof BullMQExecutorModes>;\n\n private queueHelper?: BullMQHelper<IQueueJobPayload, IMailQueueResult>;\n private workerHelpers: BullMQHelper<IQueueJobPayload, IMailProcessorResult>[] = [];\n private redisConnection: IRedisHelper;\n private readonly bullmqModule?: typeof import('bullmq');\n private jobIdCounter = 0;\n\n private processor?: (email: string) => Promise<IMailProcessorResult>;\n\n constructor(opts: IBullMQMailExecutorOpts) {\n super({ scope: BullMQMailExecutorHelper.name });\n\n this.mode = opts.mode;\n\n this.redisConnection = opts.redis;\n\n this.bullmqModule = opts.module;\n this.queueIdentifier = opts.queue.identifier;\n this.queueName = opts.queue.name;\n\n this.initQueue(opts.queue);\n }\n\n initQueue(queue: { identifier: string; name: string }) {\n switch (this.mode) {\n case BullMQExecutorModes.QUEUE_ONLY:\n case BullMQExecutorModes.BOTH: {\n this.queueHelper = new BullMQHelper<IQueueJobPayload, IMailQueueResult>({\n identifier: queue.identifier,\n queueName: queue.name,\n redisConnection: this.redisConnection,\n role: 'queue',\n module: this.bullmqModule,\n });\n\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (queue enabled) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n break;\n }\n default: {\n this.logger\n .for(this.constructor.name)\n .info(\n 'BullMQ queue executor initialized (worker-only mode) | Identifier: %s | Mode: %s',\n this.queueIdentifier,\n this.mode,\n );\n\n break;\n }\n }\n }\n\n async setProcessor(\n processor: (email: string) => Promise<IMailProcessorResult>,\n opts?: {\n numberOfWorkers?: number;\n concurrencyPerWorker?: number;\n lockDuration?: number;\n },\n ): Promise<void> {\n this.processor = processor;\n\n if (this.mode === BullMQExecutorModes.QUEUE_ONLY) {\n this.logger\n .for(this.setProcessor.name)\n .warn('Skipping worker creation in queue-only mode. Workers will not be started.');\n\n return;\n }\n\n const numberOfWorkers = opts?.numberOfWorkers ?? 1;\n const concurrencyPerWorker = opts?.concurrencyPerWorker ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n await this.clearWorkers();\n\n for (let i = 0; i < numberOfWorkers; i++) {\n this.addWorker({\n workerIdentifier: `${this.queueIdentifier}-worker-${i}`,\n concurrency: concurrencyPerWorker,\n lockDuration,\n });\n }\n\n this.logger\n .for(this.setProcessor.name)\n .info(\n 'Processor registered | Mode: %s | Workers: %d | Concurrency per worker: %d',\n this.mode,\n numberOfWorkers,\n concurrencyPerWorker,\n );\n }\n\n addWorker(opts: { workerIdentifier: string; concurrency?: number; lockDuration?: number }): void {\n if (!this.processor) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const workerIdentifier = opts.workerIdentifier;\n const concurrency = opts?.concurrency ?? 5;\n const lockDuration = opts?.lockDuration ?? 30000;\n\n const workerHelper = new BullMQHelper<IQueueJobPayload, IMailProcessorResult>({\n identifier: workerIdentifier,\n queueName: this.queueName,\n redisConnection: this.redisConnection,\n role: 'worker',\n module: this.bullmqModule,\n numberOfWorker: concurrency,\n lockDuration,\n onWorkerData: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n const maxAttempts = job.data.options?.attempts ?? 3;\n\n this.logger\n .for('onWorkerData')\n .info(\n 'Processing job | Worker: %s | jobId: %s | email: %s | attempt: %d/%d',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade + 1,\n maxAttempts,\n );\n\n if (!this.processor) {\n // Returning undefined would let BullMQ mark the job COMPLETED and (with removeOnComplete) delete it - mail silently dropped.\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] ${MailExecutorErrors.PROCESSOR_NOT_SET} | jobId: ${job.data.id}`,\n });\n }\n\n const result = await this.processor(job.data.email);\n\n // A processor reports SMTP rejection by RETURNING `{ success: false }`; BullMQ only treats a REJECTION as failure, so resolving completes the job - no retry, no DLQ.\n if (result?.success === false) {\n throw getError({\n messageCode: MailErrorCodes.SEND_FAILED,\n message: `[onWorkerData] Processor reported failure | jobId: ${job.data.id} | reason: ${result.message}`,\n });\n }\n\n return result;\n },\n onWorkerDataCompleted: async (job: Job<IQueueJobPayload, IMailProcessorResult>) => {\n this.logger\n .for('onWorkerDataCompleted')\n .info(\n 'Job completed | Worker: %s | jobId: %s | email: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n );\n },\n onWorkerDataFail: async (\n job: Job<IQueueJobPayload, IMailProcessorResult> | undefined,\n error: Error,\n ) => {\n if (job) {\n const maxAttempts = job.data.options?.attempts ?? 3;\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Job failed | Worker: %s | jobId: %s | email: %s | attempt: %d/%d | error: %s',\n workerIdentifier,\n job.data.id,\n job.data.email,\n job.attemptsMade,\n maxAttempts,\n error.message,\n );\n } else {\n this.logger\n .for('onWorkerDataFail')\n .error(\n 'Worker error (no job) | Worker: %s | error: %s',\n workerIdentifier,\n error.message,\n );\n }\n },\n });\n\n this.workerHelpers.push(workerHelper);\n\n this.logger\n .for(this.addWorker.name)\n .info(\n 'Worker added | Identifier: %s | Concurrency: %d | Total workers: %d',\n workerIdentifier,\n concurrency,\n this.workerHelpers.length,\n );\n }\n\n async removeWorker(index: number): Promise<boolean> {\n if (index < 0 || index >= this.workerHelpers.length) {\n this.logger.for(this.removeWorker.name).warn('Invalid worker index: %d', index);\n\n return false;\n }\n\n // Dropped from the list BEFORE the close is awaited: a rejecting close must not leave a half-closed worker still counted and still handed jobs.\n const [workerHelper] = this.workerHelpers.splice(index, 1);\n await workerHelper.worker.close();\n\n this.logger\n .for(this.removeWorker.name)\n .info('Worker removed | Index: %d | Remaining workers: %d', index, this.workerHelpers.length);\n\n return true;\n }\n\n /** Closes every worker without stopping at the first failure, always empties the list, and returns failures instead of throwing so teardown can continue. */\n private async closeWorkers(): Promise<Error[]> {\n const workerHelpers = this.workerHelpers;\n this.workerHelpers = [];\n\n const results = await Promise.allSettled(\n workerHelpers.map((workerHelper) => workerHelper.worker.close()),\n );\n\n const failures: Error[] = [];\n\n for (const result of results) {\n if (result.status !== 'rejected') {\n continue;\n }\n\n const error =\n result.reason instanceof Error\n ? result.reason\n : getError({ message: `Worker close failed | reason: ${String(result.reason)}` });\n\n failures.push(error);\n this.logger.for('closeWorkers').error('Failed to close worker | error: %s', error.message);\n }\n\n return failures;\n }\n\n async clearWorkers(): Promise<void> {\n const count = this.workerHelpers.length;\n await this.closeWorkers();\n\n this.logger.for(this.clearWorkers.name).info('All workers cleared | Count: %d', count);\n }\n\n /** Closes the workers, then the queue. Every step runs even if an earlier one failed; failures are reported once, at the end. The Redis helper is the application's, so it stays open. */\n async close(): Promise<void> {\n const result = await this.closeWorkers();\n const failures: Error[] = [...result];\n\n if (this.queueHelper) {\n try {\n await this.queueHelper.queue.close();\n } catch (error) {\n const closeError = error instanceof Error ? error : getError({ message: String(error) });\n failures.push(closeError);\n this.logger.for(this.close.name).error('Failed to close queue | error: %s', closeError);\n }\n }\n\n if (failures.length > 0) {\n throw getError({\n message: `[close] Incomplete BullMQ mail executor teardown | failures: ${failures\n .map((failure) => failure.message)\n .join(' | ')}`,\n });\n }\n\n this.logger.for(this.close.name).info('BullMQ mail executor closed | Mode: %s', this.mode);\n }\n\n getWorkerCount(): number {\n return this.workerHelpers.length;\n }\n\n getMode(): TConstValue<typeof BullMQExecutorModes> {\n return this.mode;\n }\n\n async enqueueVerificationEmail(\n email: string,\n options?: IMailQueueOptions,\n ): Promise<IMailQueueResult> {\n if (this.mode === BullMQExecutorModes.WORKER_ONLY) {\n throw getError({\n message: 'Cannot enqueue jobs in worker-only mode. Set mode to \"queue-only\" or \"both\".',\n });\n }\n\n if (!this.queueHelper) {\n throw getError({\n message: 'Queue helper not initialized. This should not happen in queue-enabled mode.',\n });\n }\n\n if (!this.processor && this.mode !== BullMQExecutorModes.QUEUE_ONLY) {\n throw getError({ message: MailExecutorErrors.PROCESSOR_NOT_SET });\n }\n\n const jobId = `job_${++this.jobIdCounter}_${Date.now()}`;\n const job: IQueueJobPayload = {\n id: jobId,\n email,\n options,\n attempts: 0,\n scheduledAt: Date.now() + (options?.delay ?? 0),\n };\n\n this.logger\n .for(this.enqueueVerificationEmail.name)\n .info(\n 'Queuing email to BullMQ/Redis | jobId: %s | email: %s | mode: %s',\n jobId,\n email,\n this.mode,\n );\n\n const bullJob = await this.queueHelper.queue.add('send-verification-email', job, {\n priority: options?.priority,\n delay: options?.delay,\n attempts: options?.attempts ?? 3,\n backoff: {\n type: options?.backoff?.type ?? MailBackoffTypes.EXPONENTIAL,\n delay: options?.backoff?.delay ?? 1000,\n },\n removeOnComplete: true,\n removeOnFail: false,\n });\n\n return {\n jobId: bullJob.id ?? jobId,\n queued: true,\n message: 'Email queued successfully (BullMQ/Redis)',\n };\n }\n}\n"]}
|
|
@@ -3,6 +3,10 @@ import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
|
3
3
|
export declare class StaticAssetHeaders {
|
|
4
4
|
/** `content-type` is absent on purpose: it is decided from the object name, never from the backend. */
|
|
5
5
|
static readonly ALLOWED: readonly ["content-encoding", "cache-control", "etag", "last-modified"];
|
|
6
|
+
/** Of what a controller sends with every object. */
|
|
7
|
+
static readonly NOSNIFF = "nosniff";
|
|
8
|
+
static readonly CSP_SANDBOX = "sandbox";
|
|
9
|
+
static readonly RANGE_UNIT: "bytes";
|
|
6
10
|
}
|
|
7
11
|
/** Content types the controller serves. */
|
|
8
12
|
export declare class StaticAssetContentTypes {
|
|
@@ -13,29 +17,39 @@ export declare class StaticAssetContentTypes {
|
|
|
13
17
|
*/
|
|
14
18
|
static readonly RENDERABLE: Set<string>;
|
|
15
19
|
}
|
|
16
|
-
/**
|
|
17
|
-
export declare class
|
|
18
|
-
static readonly
|
|
19
|
-
static readonly
|
|
20
|
-
static readonly
|
|
21
|
-
static
|
|
20
|
+
/** The built-in routes of a generated controller, the keys of `routes`. */
|
|
21
|
+
export declare class StaticAssetRouteKeys {
|
|
22
|
+
static readonly UPLOAD = "upload";
|
|
23
|
+
static readonly LIST_OBJECTS = "listObjects";
|
|
24
|
+
static readonly DELETE_OBJECT = "deleteObject";
|
|
25
|
+
static readonly GET_OBJECT_BY_NAME = "getObjectByName";
|
|
26
|
+
static readonly DOWNLOAD_OBJECT_BY_NAME = "downloadObjectByName";
|
|
27
|
+
static readonly UPLOAD_POLICY = "uploadPolicy";
|
|
28
|
+
static readonly UPLOAD_COMMIT = "uploadCommit";
|
|
29
|
+
static readonly UPLOAD_VALIDATE = "uploadValidate";
|
|
30
|
+
static readonly RECREATE_META_LINK = "recreateMetaLink";
|
|
31
|
+
/** Every key, in registration order. */
|
|
32
|
+
static readonly ALL: readonly ["getObjectByName", "downloadObjectByName", "upload", "deleteObject", "listObjects", "uploadPolicy", "uploadCommit", "uploadValidate", "recreateMetaLink"];
|
|
22
33
|
}
|
|
23
|
-
/** One of the `StaticAssetStorageTypes` values. */
|
|
24
|
-
export type TStaticAssetStorageType = TConstValue<typeof StaticAssetStorageTypes>;
|
|
25
34
|
/** What `recreate-metalink` did: refreshed the rows of an object, or created its first one. */
|
|
26
35
|
export declare class MetaLinkRecreateActions {
|
|
27
36
|
static readonly CREATED = "created";
|
|
28
37
|
static readonly REFRESHED = "refreshed";
|
|
29
|
-
static readonly SCHEME_SET: Set<string>;
|
|
30
|
-
static isValid(value: string): boolean;
|
|
31
38
|
}
|
|
32
39
|
/** One of the `MetaLinkRecreateActions` values. */
|
|
33
40
|
export type TMetaLinkRecreateAction = TConstValue<typeof MetaLinkRecreateActions>;
|
|
41
|
+
/** Where a commit token is in its life: issued with the policy, then validated against the content it pins. */
|
|
42
|
+
export declare class StaticAssetTokenStages {
|
|
43
|
+
static readonly ISSUED = "issued";
|
|
44
|
+
static readonly VALIDATED = "validated";
|
|
45
|
+
}
|
|
46
|
+
/** One of the `StaticAssetTokenStages` values. */
|
|
47
|
+
export type TStaticAssetTokenStage = TConstValue<typeof StaticAssetTokenStages>;
|
|
34
48
|
/** Defaults of the static asset component. */
|
|
35
49
|
export declare class StaticAssetDefaults {
|
|
36
50
|
/** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */
|
|
37
51
|
static readonly PENDING_PREFIX = "pending/";
|
|
38
|
-
/** The most file parts one upload request may carry unless `
|
|
52
|
+
/** The most file parts one upload request may carry unless `serverUpload.maxFiles` says otherwise. */
|
|
39
53
|
static readonly MAX_UPLOAD_FILES = 20;
|
|
40
54
|
}
|
|
41
55
|
/** Codes the component reports in a body instead of throwing. */
|
|
@@ -8,6 +8,10 @@ export class StaticAssetHeaders {
|
|
|
8
8
|
HTTP.Headers.ETAG,
|
|
9
9
|
HTTP.Headers.LAST_MODIFIED,
|
|
10
10
|
]; }
|
|
11
|
+
/** Of what a controller sends with every object. */
|
|
12
|
+
static { this.NOSNIFF = 'nosniff'; }
|
|
13
|
+
static { this.CSP_SANDBOX = 'sandbox'; }
|
|
14
|
+
static { this.RANGE_UNIT = HTTP.HeaderValues.RANGE_UNIT_BYTES; }
|
|
11
15
|
}
|
|
12
16
|
/** Content types the controller serves. */
|
|
13
17
|
export class StaticAssetContentTypes {
|
|
@@ -17,10 +21,10 @@ export class StaticAssetContentTypes {
|
|
|
17
21
|
* cannot stop a type we declared ourselves. `image/svg+xml` is deliberately excluded: SVG carries script.
|
|
18
22
|
*/
|
|
19
23
|
static { this.RENDERABLE = new Set([
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
HTTP.HeaderValues.IMAGE_PNG,
|
|
25
|
+
HTTP.HeaderValues.IMAGE_JPEG,
|
|
26
|
+
HTTP.HeaderValues.IMAGE_GIF,
|
|
27
|
+
HTTP.HeaderValues.IMAGE_WEBP,
|
|
24
28
|
'image/avif',
|
|
25
29
|
'image/bmp',
|
|
26
30
|
'image/x-icon',
|
|
@@ -29,34 +33,50 @@ export class StaticAssetContentTypes {
|
|
|
29
33
|
'audio/mpeg',
|
|
30
34
|
'audio/wav',
|
|
31
35
|
'audio/ogg',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
HTTP.HeaderValues.APPLICATION_PDF,
|
|
37
|
+
HTTP.HeaderValues.TEXT_PLAIN,
|
|
38
|
+
HTTP.HeaderValues.TEXT_CSV,
|
|
35
39
|
]); }
|
|
36
40
|
}
|
|
37
|
-
/**
|
|
38
|
-
export class
|
|
39
|
-
static { this.
|
|
40
|
-
static { this.
|
|
41
|
-
static { this.
|
|
42
|
-
static
|
|
43
|
-
|
|
44
|
-
}
|
|
41
|
+
/** The built-in routes of a generated controller, the keys of `routes`. */
|
|
42
|
+
export class StaticAssetRouteKeys {
|
|
43
|
+
static { this.UPLOAD = 'upload'; }
|
|
44
|
+
static { this.LIST_OBJECTS = 'listObjects'; }
|
|
45
|
+
static { this.DELETE_OBJECT = 'deleteObject'; }
|
|
46
|
+
static { this.GET_OBJECT_BY_NAME = 'getObjectByName'; }
|
|
47
|
+
static { this.DOWNLOAD_OBJECT_BY_NAME = 'downloadObjectByName'; }
|
|
48
|
+
static { this.UPLOAD_POLICY = 'uploadPolicy'; }
|
|
49
|
+
static { this.UPLOAD_COMMIT = 'uploadCommit'; }
|
|
50
|
+
static { this.UPLOAD_VALIDATE = 'uploadValidate'; }
|
|
51
|
+
static { this.RECREATE_META_LINK = 'recreateMetaLink'; }
|
|
52
|
+
/** Every key, in registration order. */
|
|
53
|
+
static { this.ALL = [
|
|
54
|
+
StaticAssetRouteKeys.GET_OBJECT_BY_NAME,
|
|
55
|
+
StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,
|
|
56
|
+
StaticAssetRouteKeys.UPLOAD,
|
|
57
|
+
StaticAssetRouteKeys.DELETE_OBJECT,
|
|
58
|
+
StaticAssetRouteKeys.LIST_OBJECTS,
|
|
59
|
+
StaticAssetRouteKeys.UPLOAD_POLICY,
|
|
60
|
+
StaticAssetRouteKeys.UPLOAD_COMMIT,
|
|
61
|
+
StaticAssetRouteKeys.UPLOAD_VALIDATE,
|
|
62
|
+
StaticAssetRouteKeys.RECREATE_META_LINK,
|
|
63
|
+
]; }
|
|
45
64
|
}
|
|
46
65
|
/** What `recreate-metalink` did: refreshed the rows of an object, or created its first one. */
|
|
47
66
|
export class MetaLinkRecreateActions {
|
|
48
67
|
static { this.CREATED = 'created'; }
|
|
49
68
|
static { this.REFRESHED = 'refreshed'; }
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
69
|
+
}
|
|
70
|
+
/** Where a commit token is in its life: issued with the policy, then validated against the content it pins. */
|
|
71
|
+
export class StaticAssetTokenStages {
|
|
72
|
+
static { this.ISSUED = 'issued'; }
|
|
73
|
+
static { this.VALIDATED = 'validated'; }
|
|
54
74
|
}
|
|
55
75
|
/** Defaults of the static asset component. */
|
|
56
76
|
export class StaticAssetDefaults {
|
|
57
77
|
/** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */
|
|
58
78
|
static { this.PENDING_PREFIX = 'pending/'; }
|
|
59
|
-
/** The most file parts one upload request may carry unless `
|
|
79
|
+
/** The most file parts one upload request may carry unless `serverUpload.maxFiles` says otherwise. */
|
|
60
80
|
static { this.MAX_UPLOAD_FILES = 20; }
|
|
61
81
|
}
|
|
62
82
|
/** Codes the component reports in a body instead of throwing. */
|
|
@@ -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,4EAA4E;AAC5E,MAAM,OAAO,kBAAkB;IAC7B,uGAAuG;aACvF,YAAO,GAAG;QACxB,IAAI,CAAC,OAAO,CAAC,gBAAgB;QAC7B,IAAI,CAAC,OAAO,CAAC,aAAa;QAC1B,IAAI,CAAC,OAAO,CAAC,IAAI;QACjB,IAAI,CAAC,OAAO,CAAC,aAAa;KAClB,CAAC;;
|
|
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,4EAA4E;AAC5E,MAAM,OAAO,kBAAkB;IAC7B,uGAAuG;aACvF,YAAO,GAAG;QACxB,IAAI,CAAC,OAAO,CAAC,gBAAgB;QAC7B,IAAI,CAAC,OAAO,CAAC,aAAa;QAC1B,IAAI,CAAC,OA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AClC,oBAAoB,CAAC,eAAe;QACpC,oBAAoB,CAAC,kBAAkB;KAC/B,CAAC;;AAGb,+FAA+F;AAC/F,MAAM,OAAO,uBAAuB;aAClB,YAAO,GAAG,SAAS,CAAC;aACpB,cAAS,GAAG,WAAW,CAAC;;AAM1C,+GAA+G;AAC/G,MAAM,OAAO,sBAAsB;aACjB,WAAM,GAAG,QAAQ,CAAC;aAClB,cAAS,GAAG,WAAW,CAAC;;AAM1C,8CAA8C;AAC9C,MAAM,OAAO,mBAAmB;IAC9B,yHAAyH;aACzG,mBAAc,GAAG,UAAU,CAAC;IAE5C,sGAAsG;aACtF,qBAAgB,GAAG,EAAE,CAAC;;AAGxC,iEAAiE;AACjE,MAAM,OAAO,wBAAwB;IACnC,2LAA2L;aAC3K,kBAAa,GAAG,yBAAyB,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\n/** The response headers a controller echoes from the backend's metadata. */\nexport class StaticAssetHeaders {\n /** `content-type` is absent on purpose: it is decided from the object name, never from the backend. */\n static readonly ALLOWED = [\n HTTP.Headers.CONTENT_ENCODING,\n HTTP.Headers.CACHE_CONTROL,\n HTTP.Headers.ETAG,\n HTTP.Headers.LAST_MODIFIED,\n ] as const;\n\n /** Of what a controller sends with every object. */\n static readonly NOSNIFF = 'nosniff';\n static readonly CSP_SANDBOX = 'sandbox';\n static readonly RANGE_UNIT = HTTP.HeaderValues.RANGE_UNIT_BYTES;\n}\n\n/** Content types the controller serves. */\nexport class StaticAssetContentTypes {\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 */\n static readonly RENDERABLE = new Set<string>([\n HTTP.HeaderValues.IMAGE_PNG,\n HTTP.HeaderValues.IMAGE_JPEG,\n HTTP.HeaderValues.IMAGE_GIF,\n HTTP.HeaderValues.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 HTTP.HeaderValues.APPLICATION_PDF,\n HTTP.HeaderValues.TEXT_PLAIN,\n HTTP.HeaderValues.TEXT_CSV,\n ]);\n}\n\n/** The built-in routes of a generated controller, the keys of `routes`. */\nexport class StaticAssetRouteKeys {\n static readonly UPLOAD = 'upload';\n static readonly LIST_OBJECTS = 'listObjects';\n static readonly DELETE_OBJECT = 'deleteObject';\n static readonly GET_OBJECT_BY_NAME = 'getObjectByName';\n static readonly DOWNLOAD_OBJECT_BY_NAME = 'downloadObjectByName';\n\n static readonly UPLOAD_POLICY = 'uploadPolicy';\n static readonly UPLOAD_COMMIT = 'uploadCommit';\n static readonly UPLOAD_VALIDATE = 'uploadValidate';\n\n static readonly RECREATE_META_LINK = 'recreateMetaLink';\n\n /** Every key, in registration order. */\n static readonly ALL = [\n StaticAssetRouteKeys.GET_OBJECT_BY_NAME,\n StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,\n StaticAssetRouteKeys.UPLOAD,\n StaticAssetRouteKeys.DELETE_OBJECT,\n StaticAssetRouteKeys.LIST_OBJECTS,\n StaticAssetRouteKeys.UPLOAD_POLICY,\n StaticAssetRouteKeys.UPLOAD_COMMIT,\n StaticAssetRouteKeys.UPLOAD_VALIDATE,\n StaticAssetRouteKeys.RECREATE_META_LINK,\n ] as const;\n}\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\n/** One of the `MetaLinkRecreateActions` values. */\nexport type TMetaLinkRecreateAction = TConstValue<typeof MetaLinkRecreateActions>;\n\n/** Where a commit token is in its life: issued with the policy, then validated against the content it pins. */\nexport class StaticAssetTokenStages {\n static readonly ISSUED = 'issued';\n static readonly VALIDATED = 'validated';\n}\n\n/** One of the `StaticAssetTokenStages` values. */\nexport type TStaticAssetTokenStage = TConstValue<typeof StaticAssetTokenStages>;\n\n/** Defaults of the static asset component. */\nexport class StaticAssetDefaults {\n /** Where a signed policy may write. The final key is never inside it, so content cannot be replaced after the commit. */\n static readonly PENDING_PREFIX = 'pending/';\n\n /** The most file parts one upload request may carry unless `serverUpload.maxFiles` says otherwise. */\n static readonly MAX_UPLOAD_FILES = 20;\n}\n\n/** Codes the component reports in a body instead of throwing. */\nexport class StaticAssetMetaLinkCodes {\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`. */\n static readonly CREATE_FAILED = 'META_LINK_CREATE_FAILED';\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import type { TRegisterErrors } from '@venizia/ignis-helpers/core';
|
|
|
3
3
|
export declare const StaticAssetErrors: {
|
|
4
4
|
readonly UPLOAD_NOT_AUTHORIZED: {
|
|
5
5
|
readonly message: {
|
|
6
|
-
readonly text: "Not allowed to
|
|
6
|
+
readonly text: "Not allowed to upload";
|
|
7
7
|
readonly code: "core.static_asset.upload_not_authorized";
|
|
8
8
|
};
|
|
9
9
|
readonly statusCode: 403;
|
|
@@ -35,13 +35,22 @@ export declare const StaticAssetErrors: {
|
|
|
35
35
|
readonly statusCode: 400;
|
|
36
36
|
readonly category: "validation";
|
|
37
37
|
};
|
|
38
|
-
/**
|
|
39
|
-
readonly
|
|
38
|
+
/** The pending object is not the one that was read: it was overwritten or removed after the pin. Raised by a pinned read and by the commit copy. */
|
|
39
|
+
readonly UPLOAD_CHANGED: {
|
|
40
40
|
readonly message: {
|
|
41
|
-
readonly text: "
|
|
42
|
-
readonly code: "core.static_asset.
|
|
41
|
+
readonly text: "The uploaded file changed after it was validated";
|
|
42
|
+
readonly code: "core.static_asset.upload_changed";
|
|
43
43
|
};
|
|
44
|
-
readonly statusCode:
|
|
44
|
+
readonly statusCode: 409;
|
|
45
|
+
readonly category: "validation";
|
|
46
|
+
};
|
|
47
|
+
/** With a `validation` on, `commit` takes the token `upload-validate` returned, not the one the policy issued. */
|
|
48
|
+
readonly UPLOAD_NOT_VALIDATED: {
|
|
49
|
+
readonly message: {
|
|
50
|
+
readonly text: "The upload has not been validated";
|
|
51
|
+
readonly code: "core.static_asset.upload_not_validated";
|
|
52
|
+
};
|
|
53
|
+
readonly statusCode: 422;
|
|
45
54
|
readonly category: "validation";
|
|
46
55
|
};
|
|
47
56
|
readonly BUCKET_NAME_INVALID: {
|
|
@@ -60,7 +69,7 @@ export declare const StaticAssetErrors: {
|
|
|
60
69
|
readonly statusCode: 400;
|
|
61
70
|
readonly category: "validation";
|
|
62
71
|
};
|
|
63
|
-
/** The application's naming hook produced a key outside `
|
|
72
|
+
/** The application's naming hook produced a key outside the entry's `keyPrefix`; nothing is written. */
|
|
64
73
|
readonly OBJECT_KEY_OUT_OF_SCOPE: {
|
|
65
74
|
readonly message: {
|
|
66
75
|
readonly text: "Object key is outside the key prefix of this controller";
|
|
@@ -69,30 +78,6 @@ export declare const StaticAssetErrors: {
|
|
|
69
78
|
readonly statusCode: 400;
|
|
70
79
|
readonly category: "validation";
|
|
71
80
|
};
|
|
72
|
-
readonly FOLDER_PATH_INVALID: {
|
|
73
|
-
readonly message: {
|
|
74
|
-
readonly text: "Invalid folder path";
|
|
75
|
-
readonly code: "core.static_asset.folder_path_invalid";
|
|
76
|
-
};
|
|
77
|
-
readonly statusCode: 400;
|
|
78
|
-
readonly category: "validation";
|
|
79
|
-
};
|
|
80
|
-
readonly FOLDER_SEGMENT_INVALID: {
|
|
81
|
-
readonly message: {
|
|
82
|
-
readonly text: "Invalid folder path segment";
|
|
83
|
-
readonly code: "core.static_asset.folder_segment_invalid";
|
|
84
|
-
};
|
|
85
|
-
readonly statusCode: 400;
|
|
86
|
-
readonly category: "validation";
|
|
87
|
-
};
|
|
88
|
-
readonly FOLDER_DEPTH_EXCEEDED: {
|
|
89
|
-
readonly message: {
|
|
90
|
-
readonly text: "Folder path exceeds the maximum depth";
|
|
91
|
-
readonly code: "core.static_asset.folder_depth_exceeded";
|
|
92
|
-
};
|
|
93
|
-
readonly statusCode: 400;
|
|
94
|
-
readonly category: "validation";
|
|
95
|
-
};
|
|
96
81
|
readonly FILE_EMPTY: {
|
|
97
82
|
readonly message: {
|
|
98
83
|
readonly text: "Empty file content";
|
|
@@ -101,14 +86,6 @@ export declare const StaticAssetErrors: {
|
|
|
101
86
|
readonly statusCode: 400;
|
|
102
87
|
readonly category: "validation";
|
|
103
88
|
};
|
|
104
|
-
readonly MAX_KEYS_INVALID: {
|
|
105
|
-
readonly message: {
|
|
106
|
-
readonly text: "Invalid maxKeys - expected a positive integer";
|
|
107
|
-
readonly code: "core.static_asset.max_keys_invalid";
|
|
108
|
-
};
|
|
109
|
-
readonly statusCode: 400;
|
|
110
|
-
readonly category: "validation";
|
|
111
|
-
};
|
|
112
89
|
};
|
|
113
90
|
/** Registers these codes with the shared key registry so a consumer gets autocomplete on `messageCode`. */
|
|
114
91
|
declare module '@venizia/ignis-helpers' {
|
|
@@ -4,7 +4,7 @@ import { HTTP } from '@venizia/ignis-helpers/common';
|
|
|
4
4
|
export const StaticAssetErrors = {
|
|
5
5
|
UPLOAD_NOT_AUTHORIZED: {
|
|
6
6
|
message: {
|
|
7
|
-
text: 'Not allowed to
|
|
7
|
+
text: 'Not allowed to upload',
|
|
8
8
|
code: 'core.static_asset.upload_not_authorized',
|
|
9
9
|
},
|
|
10
10
|
statusCode: HTTP.ResultCodes.RS_4.Forbidden,
|
|
@@ -30,13 +30,22 @@ export const StaticAssetErrors = {
|
|
|
30
30
|
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
31
31
|
category: ErrorScopes.VALIDATION,
|
|
32
32
|
},
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/** The pending object is not the one that was read: it was overwritten or removed after the pin. Raised by a pinned read and by the commit copy. */
|
|
34
|
+
UPLOAD_CHANGED: {
|
|
35
35
|
message: {
|
|
36
|
-
text: '
|
|
37
|
-
code: 'core.static_asset.
|
|
36
|
+
text: 'The uploaded file changed after it was validated',
|
|
37
|
+
code: 'core.static_asset.upload_changed',
|
|
38
38
|
},
|
|
39
|
-
statusCode: HTTP.ResultCodes.RS_4.
|
|
39
|
+
statusCode: HTTP.ResultCodes.RS_4.Conflict,
|
|
40
|
+
category: ErrorScopes.VALIDATION,
|
|
41
|
+
},
|
|
42
|
+
/** With a `validation` on, `commit` takes the token `upload-validate` returned, not the one the policy issued. */
|
|
43
|
+
UPLOAD_NOT_VALIDATED: {
|
|
44
|
+
message: {
|
|
45
|
+
text: 'The upload has not been validated',
|
|
46
|
+
code: 'core.static_asset.upload_not_validated',
|
|
47
|
+
},
|
|
48
|
+
statusCode: HTTP.ResultCodes.RS_4.UnprocessableEntity,
|
|
40
49
|
category: ErrorScopes.VALIDATION,
|
|
41
50
|
},
|
|
42
51
|
BUCKET_NAME_INVALID: {
|
|
@@ -52,7 +61,7 @@ export const StaticAssetErrors = {
|
|
|
52
61
|
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
53
62
|
category: ErrorScopes.VALIDATION,
|
|
54
63
|
},
|
|
55
|
-
/** The application's naming hook produced a key outside `
|
|
64
|
+
/** The application's naming hook produced a key outside the entry's `keyPrefix`; nothing is written. */
|
|
56
65
|
OBJECT_KEY_OUT_OF_SCOPE: {
|
|
57
66
|
message: {
|
|
58
67
|
text: 'Object key is outside the key prefix of this controller',
|
|
@@ -61,39 +70,10 @@ export const StaticAssetErrors = {
|
|
|
61
70
|
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
62
71
|
category: ErrorScopes.VALIDATION,
|
|
63
72
|
},
|
|
64
|
-
FOLDER_PATH_INVALID: {
|
|
65
|
-
message: { text: 'Invalid folder path', code: 'core.static_asset.folder_path_invalid' },
|
|
66
|
-
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
67
|
-
category: ErrorScopes.VALIDATION,
|
|
68
|
-
},
|
|
69
|
-
FOLDER_SEGMENT_INVALID: {
|
|
70
|
-
message: {
|
|
71
|
-
text: 'Invalid folder path segment',
|
|
72
|
-
code: 'core.static_asset.folder_segment_invalid',
|
|
73
|
-
},
|
|
74
|
-
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
75
|
-
category: ErrorScopes.VALIDATION,
|
|
76
|
-
},
|
|
77
|
-
FOLDER_DEPTH_EXCEEDED: {
|
|
78
|
-
message: {
|
|
79
|
-
text: 'Folder path exceeds the maximum depth',
|
|
80
|
-
code: 'core.static_asset.folder_depth_exceeded',
|
|
81
|
-
},
|
|
82
|
-
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
83
|
-
category: ErrorScopes.VALIDATION,
|
|
84
|
-
},
|
|
85
73
|
FILE_EMPTY: {
|
|
86
74
|
message: { text: 'Empty file content', code: 'core.static_asset.file_empty' },
|
|
87
75
|
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
88
76
|
category: ErrorScopes.VALIDATION,
|
|
89
77
|
},
|
|
90
|
-
MAX_KEYS_INVALID: {
|
|
91
|
-
message: {
|
|
92
|
-
text: 'Invalid maxKeys - expected a positive integer',
|
|
93
|
-
code: 'core.static_asset.max_keys_invalid',
|
|
94
|
-
},
|
|
95
|
-
statusCode: HTTP.ResultCodes.RS_4.BadRequest,
|
|
96
|
-
category: ErrorScopes.VALIDATION,
|
|
97
|
-
},
|
|
98
78
|
};
|
|
99
79
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,uIAAuI;AACvI,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,qBAAqB,EAAE;QACrB,OAAO,EAAE;YACP,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,uIAAuI;AACvI,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,qBAAqB,EAAE;QACrB,OAAO,EAAE;YACP,IAAI,EAAE,uBAAuB;YAC7B,IAAI,EAAE,yCAAyC;SAChD;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;QAC3C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,gEAAgE;IAChE,gBAAgB,EAAE;QAChB,OAAO,EAAE;YACP,IAAI,EAAE,yCAAyC;YAC/C,IAAI,EAAE,oCAAoC;SAC3C;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe;QACjD,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,kJAAkJ;IAClJ,oBAAoB,EAAE;QACpB,OAAO,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,wCAAwC,EAAE;QACzF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,oBAAoB,EAAE;QACpB,OAAO,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE,wCAAwC,EAAE;QAC7F,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,oJAAoJ;IACpJ,cAAc,EAAE;QACd,OAAO,EAAE;YACP,IAAI,EAAE,kDAAkD;YACxD,IAAI,EAAE,kCAAkC;SACzC;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ;QAC1C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,kHAAkH;IAClH,oBAAoB,EAAE;QACpB,OAAO,EAAE;YACP,IAAI,EAAE,mCAAmC;YACzC,IAAI,EAAE,wCAAwC;SAC/C;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;QACrD,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,uCAAuC,EAAE;QACvF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE;YACP,IAAI,EAAE,6BAA6B;YACnC,IAAI,EAAE,uCAAuC;SAC9C;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,wGAAwG;IACxG,uBAAuB,EAAE;QACvB,OAAO,EAAE;YACP,IAAI,EAAE,yDAAyD;YAC/D,IAAI,EAAE,2CAA2C;SAClD;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,8BAA8B,EAAE;QAC7E,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;CACkD,CAAC","sourcesContent":["import type { TErrorDefinition, TRegisterErrors } from '@venizia/ignis-helpers/core';\nimport { ErrorScopes } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\n/** Codes a client branches on for a rejected static-asset request. A throw site may override `message` to name the offending value. */\nexport const StaticAssetErrors = {\n UPLOAD_NOT_AUTHORIZED: {\n message: {\n text: 'Not allowed to upload',\n code: 'core.static_asset.upload_not_authorized',\n },\n statusCode: HTTP.ResultCodes.RS_4.Forbidden,\n category: ErrorScopes.VALIDATION,\n },\n /** Both upload paths - one condition, one code to branch on. */\n UPLOAD_TOO_LARGE: {\n message: {\n text: 'File is larger than the maximum allowed',\n code: 'core.static_asset.upload_too_large',\n },\n statusCode: HTTP.ResultCodes.RS_4.ContentTooLarge,\n category: ErrorScopes.VALIDATION,\n },\n /** Deliberately not 404 and deliberately not \"expired\": a caller learns only that the token is no good, never whether the key it names exists. */\n INVALID_COMMIT_TOKEN: {\n message: { text: 'Invalid commit token', code: 'core.static_asset.invalid_commit_token' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n EXPIRED_COMMIT_TOKEN: {\n message: { text: 'Commit token has expired', code: 'core.static_asset.expired_commit_token' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n /** The pending object is not the one that was read: it was overwritten or removed after the pin. Raised by a pinned read and by the commit copy. */\n UPLOAD_CHANGED: {\n message: {\n text: 'The uploaded file changed after it was validated',\n code: 'core.static_asset.upload_changed',\n },\n statusCode: HTTP.ResultCodes.RS_4.Conflict,\n category: ErrorScopes.VALIDATION,\n },\n /** With a `validation` on, `commit` takes the token `upload-validate` returned, not the one the policy issued. */\n UPLOAD_NOT_VALIDATED: {\n message: {\n text: 'The upload has not been validated',\n code: 'core.static_asset.upload_not_validated',\n },\n statusCode: HTTP.ResultCodes.RS_4.UnprocessableEntity,\n category: ErrorScopes.VALIDATION,\n },\n BUCKET_NAME_INVALID: {\n message: { text: 'Invalid bucket name', code: 'core.static_asset.bucket_name_invalid' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n OBJECT_NAME_INVALID: {\n message: {\n text: 'Invalid object name or path',\n code: 'core.static_asset.object_name_invalid',\n },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n /** The application's naming hook produced a key outside the entry's `keyPrefix`; nothing is written. */\n OBJECT_KEY_OUT_OF_SCOPE: {\n message: {\n text: 'Object key is outside the key prefix of this controller',\n code: 'core.static_asset.object_key_out_of_scope',\n },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n FILE_EMPTY: {\n message: { text: 'Empty file content', code: 'core.static_asset.file_empty' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n} as const satisfies Record<string, TErrorDefinition>;\n\n/** Registers these codes with the shared key registry so a consumer gets autocomplete on `messageCode`. */\ndeclare module '@venizia/ignis-helpers' {\n interface IErrorKeyRegistry extends TRegisterErrors<typeof StaticAssetErrors> {}\n}\n"]}
|