@venizia/ignis 0.4.8-13 → 0.4.8-15

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.
Files changed (89) hide show
  1. package/dist/esm/components/mail/common/constants.d.ts +24 -14
  2. package/dist/esm/components/mail/common/constants.js +19 -32
  3. package/dist/esm/components/mail/common/constants.js.map +1 -1
  4. package/dist/esm/components/mail/common/errors.d.ts +10 -1
  5. package/dist/esm/components/mail/common/errors.js +7 -1
  6. package/dist/esm/components/mail/common/errors.js.map +1 -1
  7. package/dist/esm/components/mail/common/types/queue.d.ts +15 -8
  8. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  9. package/dist/esm/components/mail/common/types/template.d.ts +3 -2
  10. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  11. package/dist/esm/components/mail/component.js +11 -2
  12. package/dist/esm/components/mail/component.js.map +1 -1
  13. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +13 -12
  14. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  15. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
  16. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
  17. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  18. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +4 -4
  19. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  20. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
  21. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  22. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
  23. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  24. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
  25. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
  26. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  27. package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
  28. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  29. package/dist/esm/components/mail/services/mail.service.js +21 -19
  30. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  31. package/dist/esm/components/mail/services/template.service.d.ts +4 -1
  32. package/dist/esm/components/mail/services/template.service.js +24 -16
  33. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  34. package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
  35. package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
  36. package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
  37. package/dist/esm/components/mail/utilities/header.utility.js +44 -0
  38. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
  39. package/dist/esm/components/mail/utilities/index.d.ts +1 -0
  40. package/dist/esm/components/mail/utilities/index.js +1 -0
  41. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  42. package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
  43. package/dist/esm/components/mail/utilities/mime.utility.js +9 -55
  44. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  45. package/dist/esm/components/static-asset/common/constants.d.ts +5 -4
  46. package/dist/esm/components/static-asset/common/constants.js +5 -9
  47. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  48. package/dist/esm/components/static-asset/common/errors.d.ts +18 -0
  49. package/dist/esm/components/static-asset/common/errors.js +18 -0
  50. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  51. package/dist/esm/components/static-asset/common/types.d.ts +47 -18
  52. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  53. package/dist/esm/components/static-asset/component.js +1 -1
  54. package/dist/esm/components/static-asset/component.js.map +1 -1
  55. package/dist/esm/components/static-asset/controller/factory.d.ts +2 -166
  56. package/dist/esm/components/static-asset/controller/factory.js +7 -20
  57. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  58. package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
  59. package/dist/esm/components/static-asset/controller/index.js +1 -0
  60. package/dist/esm/components/static-asset/controller/index.js.map +1 -1
  61. package/dist/esm/components/static-asset/controller/routes/context.d.ts +1 -1
  62. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -1
  63. package/dist/esm/components/static-asset/controller/routes/definition.js +15 -6
  64. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -1
  65. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +24 -2
  66. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -1
  67. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +14 -2
  68. package/dist/esm/components/static-asset/controller/routes/serve.js +40 -15
  69. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -1
  70. package/dist/esm/components/static-asset/controller/routes/upload.js +11 -10
  71. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -1
  72. package/dist/esm/components/static-asset/services/commitment.service.d.ts +35 -16
  73. package/dist/esm/components/static-asset/services/commitment.service.js +92 -30
  74. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -1
  75. package/dist/esm/components/static-asset/services/policy.service.d.ts +7 -3
  76. package/dist/esm/components/static-asset/services/policy.service.js +21 -2
  77. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -1
  78. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +2 -1
  79. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +14 -5
  80. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -1
  81. package/dist/esm/components/static-asset/utilities/entry.utility.js +9 -2
  82. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -1
  83. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +6 -7
  84. package/dist/esm/components/static-asset/utilities/route-options.utility.js +9 -23
  85. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -1
  86. package/dist/presets/app/preset.json +4 -4
  87. package/dist/presets/lib/preset.json +3 -3
  88. package/dist/presets/shared/preset.json +1 -1
  89. package/package.json +8 -8
@@ -2,4 +2,5 @@ export * from './type.utility.js';
2
2
  export * from './address.utility.js';
3
3
  export * from './verification.utility.js';
4
4
  export * from './mime.utility.js';
5
+ export * from './header.utility.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,5 @@ export * from './type.utility.js';
2
2
  export * from './address.utility.js';
3
3
  export * from './verification.utility.js';
4
4
  export * from './mime.utility.js';
5
+ export * from './header.utility.js';
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC","sourcesContent":["export * from './type.utility';\nexport * from './address.utility';\nexport * from './verification.utility';\nexport * from './mime.utility';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './type.utility';\nexport * from './address.utility';\nexport * from './verification.utility';\nexport * from './mime.utility';\nexport * from './header.utility';\n"]}
@@ -1,6 +1,10 @@
1
- import { type IMailMessage } from '../common/index.js';
1
+ import type { IMailMessage } from '../common/index.js';
2
2
  /** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */
3
3
  export declare class MailMimeUtility {
4
+ /** Escapes `\` and `"` so a value can sit inside a quoted string: a display name, a MIME parameter. */
5
+ static escapeQuotedString(opts: {
6
+ value: string;
7
+ }): string;
4
8
  /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a
5
9
  * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,
6
10
  * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */
@@ -1,8 +1,7 @@
1
- import { HTTP } from '@venizia/ignis-helpers/common';
2
- import { getError, TokenUidHelper, UidTokenEncodings } from '@venizia/ignis-helpers/core';
3
- import { MailErrorCodes } from '../common/index.js';
1
+ import { TokenUidHelper, UidTokenEncodings } from '@venizia/ignis-helpers/core';
4
2
  import { MailAddressUtility } from './address.utility.js';
5
3
  import { MailAttachmentUtility } from './attachment.utility.js';
4
+ import { MailHeaderUtility } from './header.utility.js';
6
5
  const CRLF = '\r\n';
7
6
  const BASE64_LINE_LENGTH = 76;
8
7
  /** RFC 5322 recommends folding well under its own 998-byte hard limit; 78 matches common MTA
@@ -147,43 +146,6 @@ function encodeTextBase64(text) {
147
146
  function encodeBufferBase64(buffer) {
148
147
  return foldBase64(buffer.toString('base64'));
149
148
  }
150
- /** A literal CR/LF/NUL inside a header-bound value would let it break out of its own header line and forge additional headers or smuggle body content - classic email header injection. Every value spliced into a raw header line is checked here first, so an attempt fails loudly instead of silently reaching the wire.
151
- *
152
- * `value` is `unknown`, not `string`: `IMailMessage`/`IMailAttachment` both end in
153
- * `[key: string]: any`, so nothing at the type layer stops a caller (e.g. a controller
154
- * forwarding a request body) from putting a non-string - notably an array - where a string is
155
- * declared. `Array.prototype.includes('\r')` checks element *equality*, not substring, so
156
- * `['x\r\nBcc: evil'].includes('\r')` is `false` and a naive string-only check would wave a
157
- * forged header straight through once it is later stringified by a template literal. Requiring
158
- * `typeof value === 'string'` up front closes that gap for every field that flows through here. */
159
- function assertNoHeaderInjection(opts) {
160
- const { field, value } = opts;
161
- if (typeof value !== 'string') {
162
- throw getError({
163
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
164
- messageCode: MailErrorCodes.INVALID_CONFIGURATION,
165
- message: `Invalid Amazon SES message | ${field} must be a string`,
166
- });
167
- }
168
- if (!value.includes('\r') && !value.includes('\n') && !value.includes('\0')) {
169
- return;
170
- }
171
- throw getError({
172
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
173
- messageCode: MailErrorCodes.INVALID_CONFIGURATION,
174
- message: `Invalid Amazon SES message | ${field} contains illegal control characters`,
175
- });
176
- }
177
- /** Same guard as {@link assertNoHeaderInjection}, applied to every address in a `to`/`cc`/`bcc`
178
- * field individually - a string field only, not `[key: string]: any`; validating the raw
179
- * caller-provided value (before splitting/joining) both types and content-checks each entry. */
180
- function assertNoAddressListInjection(opts) {
181
- const { field, value } = opts;
182
- const list = Array.isArray(value) ? value : [value];
183
- for (const item of list) {
184
- assertNoHeaderInjection({ field, value: item });
185
- }
186
- }
187
149
  function extractDomain(address) {
188
150
  const match = address ? /@([^@>\s]+)>?\s*$/.exec(address) : null;
189
151
  return match ? match[1] : 'localhost';
@@ -191,27 +153,17 @@ function extractDomain(address) {
191
153
  function buildHeaders(message) {
192
154
  const headers = [];
193
155
  if (message.from) {
194
- assertNoAddressListInjection({ field: 'from', value: message.from });
195
156
  headers.push(foldHeaderLine(`From: ${formatAddressList(message.from)}`));
196
157
  }
197
158
  if (message.to) {
198
- assertNoAddressListInjection({ field: 'to', value: message.to });
199
159
  headers.push(foldHeaderLine(`To: ${formatAddressList(message.to)}`));
200
160
  }
201
161
  if (message.cc) {
202
- assertNoAddressListInjection({ field: 'cc', value: message.cc });
203
162
  headers.push(foldHeaderLine(`Cc: ${formatAddressList(message.cc)}`));
204
163
  }
205
164
  if (message.replyTo) {
206
- assertNoAddressListInjection({ field: 'replyTo', value: message.replyTo });
207
165
  headers.push(foldHeaderLine(`Reply-To: ${formatAddressList(message.replyTo)}`));
208
166
  }
209
- // Checked, never emitted: a `Bcc:` header would disclose the blind recipients, so they travel as
210
- // `Destination.BccAddresses`. Without this, `bcc` is the one address field that fails at AWS.
211
- if (message.bcc) {
212
- assertNoAddressListInjection({ field: 'bcc', value: message.bcc });
213
- }
214
- assertNoHeaderInjection({ field: 'subject', value: message.subject });
215
167
  headers.push(foldHeaderLine(`Subject: ${encodeHeaderValue(message.subject)}`));
216
168
  // RFC 5322 requires both on every message; SES's raw-message parser does not synthesize them,
217
169
  // so an omission here is an omission on the wire (some receiving MTAs reject a `Date`-less
@@ -222,8 +174,6 @@ function buildHeaders(message) {
222
174
  if (message.headers) {
223
175
  const messageHeadersEntries = Object.entries(message.headers);
224
176
  for (const [key, value] of messageHeadersEntries) {
225
- assertNoHeaderInjection({ field: `headers.${key}`, value: key });
226
- assertNoHeaderInjection({ field: `headers.${key}`, value });
227
177
  headers.push(foldHeaderLine(`${key}: ${encodeHeaderValue(value)}`));
228
178
  }
229
179
  }
@@ -265,12 +215,12 @@ async function attachmentPart(attachment, boundary) {
265
215
  // No root here: a `path` that did not go through `MailAttachmentUtility.resolve` is refused, never read.
266
216
  const content = await MailAttachmentUtility.readContent({ attachment });
267
217
  const contentType = attachment.contentType ?? 'application/octet-stream';
268
- assertNoHeaderInjection({ field: 'attachment.contentType', value: contentType });
218
+ MailHeaderUtility.assertValue({ field: 'attachment.contentType', value: contentType });
269
219
  if (attachment.filename) {
270
- assertNoHeaderInjection({ field: 'attachment.filename', value: attachment.filename });
220
+ MailHeaderUtility.assertValue({ field: 'attachment.filename', value: attachment.filename });
271
221
  }
272
222
  if (attachment.cid) {
273
- assertNoHeaderInjection({ field: 'attachment.cid', value: attachment.cid });
223
+ MailHeaderUtility.assertValue({ field: 'attachment.cid', value: attachment.cid });
274
224
  }
275
225
  const nameAttribute = attachment.filename
276
226
  ? attachmentNameParams('name', attachment.filename)
@@ -296,6 +246,10 @@ function newBoundary(label) {
296
246
  }
297
247
  /** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */
298
248
  export class MailMimeUtility {
249
+ /** Escapes `\` and `"` so a value can sit inside a quoted string: a display name, a MIME parameter. */
250
+ static escapeQuotedString(opts) {
251
+ return escapeQuotedString(opts.value);
252
+ }
299
253
  /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a
300
254
  * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,
301
255
  * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */
@@ -1 +1 @@
1
- {"version":3,"file":"mime.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/mime.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,cAAc,EAA2C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B;;2FAE2F;AAC3F,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC;;;;0FAI0F;AAC1F,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,sFAAsF;AACtF,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,8HAA8H;AAC9H,SAAS,iBAAiB,CAAC,IAAuB;IAChD,OAAO,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAC7F,CAAC;AAED,SAAS,OAAO,CAAC,KAAa;IAC5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;A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AAC,CAAC;YAChE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,CAAC;QAEvC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACjF,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, TokenUidHelper, UidTokenEncodings } from '@venizia/ignis-helpers/core';\nimport { MailErrorCodes, type IMailAttachment, type IMailMessage } from '../common';\nimport { MailAddressUtility } from './address.utility';\nimport { MailAttachmentUtility } from './attachment.utility';\n\nconst CRLF = '\\r\\n';\nconst BASE64_LINE_LENGTH = 76;\n/** RFC 5322 recommends folding well under its own 998-byte hard limit; 78 matches common MTA\n * practice. This is a *soft* preferred width, not a hard requirement - {@link foldHeaderLine}\n * only forces a line break past it when a natural whitespace break point exists nearby. */\nconst MAX_HEADER_LINE_LENGTH = 78;\n/** The real hard requirement: SES rejects any raw-message physical line at or over 1000 bytes.\n * A 10-byte margin below that, and comfortably under RFC 5322's own 998-octet hard limit. Only\n * an unbroken token that would itself cross this line forces {@link foldHeaderLine}'s\n * content-altering hard-wrap fallback - below it, one long line is safer than corrupting an\n * atomic value (a single very long address, an unbroken encoded-word) by splitting it. */\nconst MAX_HEADER_HARD_LIMIT = 990;\n/** RFC 2047 caps one encoded-word (`=?charset?B?...?=` included) at 75 characters. */\nconst ENCODED_WORD_MAX_LENGTH = 75;\n\n/** `bytes` random bytes as lowercase hex, from the platform CSPRNG. `bytes` is at least 16, the floor of `TokenUidHelper`. */\nfunction generateRandomHex(opts: { bytes: number }): string {\n return new TokenUidHelper({ bytes: opts.bytes, encoding: UidTokenEncodings.HEX }).nextId();\n}\n\nfunction isAscii(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n if (value.charCodeAt(index) > 127) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * RFC 2047 §5(3) requires each encoded-word to carry whole characters - a multi-byte UTF-8\n * sequence split across two encoded-words decodes to mojibake or invalid UTF-8 on either side of\n * the cut. `bytesPerChunk` is a fixed byte budget, not a character-aligned one, so after slicing\n * at that budget we walk the boundary back over any UTF-8 continuation bytes (`10xxxxxx`, i.e.\n * `byte & 0xC0 === 0x80`) until it lands on the leading byte of a character. `bytesPerChunk` is\n * always far larger than the longest UTF-8 sequence (4 bytes), so this walk-back can never\n * consume the whole chunk. Words are joined with a single space - the required separator between\n * adjacent encoded-words, and also a valid header-folding point.\n */\nfunction encodeWord(text: string): string {\n const prefix = '=?UTF-8?B?';\n const suffix = '?=';\n const maxPayloadChars = ENCODED_WORD_MAX_LENGTH - prefix.length - suffix.length;\n const bytesPerChunk = Math.floor(maxPayloadChars / 4) * 3;\n const bytes = Buffer.from(text, 'utf-8');\n const words: string[] = [];\n let offset = 0;\n\n while (offset < bytes.length) {\n let end = Math.min(offset + bytesPerChunk, bytes.length);\n\n while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) {\n end--;\n }\n\n const chunk = bytes.subarray(offset, end);\n words.push(`${prefix}${chunk.toString('base64')}${suffix}`);\n offset = end;\n }\n\n return words.join(' ');\n}\n\n/** Only non-ASCII values pay for RFC 2047 encoding, so a plain-English subject or custom header\n * stays byte-for-byte readable. */\nfunction encodeHeaderValue(value: string): string {\n return isAscii(value) ? value : encodeWord(value);\n}\n\n/**\n * Encodes only the *display-name* portion of `\"Name\" <addr@x.com>` (or bare `Name <addr@x.com>`).\n * The `<addr-spec>` must stay 7-bit ASCII per RFC 5321/5322 and per the SES raw-message\n * requirements - only the free-text name may become an RFC 2047 encoded-word. A bare address with\n * no display name is returned unchanged.\n */\nfunction encodeAddress(address: string): string {\n const match = /^(.*)<([^<>]+)>\\s*$/.exec(address);\n\n if (!match) {\n return address;\n }\n\n const [, rawName, addr] = match;\n const name = rawName.trim().replace(/^\"|\"$/g, '');\n\n if (name.length === 0 || isAscii(name)) {\n return rawName.trim().length > 0 ? `${rawName.trim()} <${addr}>` : `<${addr}>`;\n }\n\n return `${encodeWord(name)} <${addr}>`;\n}\n\n/** The body of `MailMimeUtility.formatAddressHeader`, callable from the header builder. */\nfunction formatAddressList(value: string | string[]): string {\n return MailAddressUtility.splitList({ value }).map(encodeAddress).join(', ');\n}\n\n/**\n * RFC 5322 §2.2.3 header folding: inserting CRLF immediately before an existing whitespace\n * character splits one logical header value across physical lines without changing its content\n * (the folded whitespace is still there, just after a line break). SES enforces a 1000-byte\n * ceiling per raw-message line; folding at {@link MAX_HEADER_LINE_LENGTH} keeps arbitrarily long\n * recipient lists, subjects, or encoded display names deliverable regardless of how many\n * addresses or how much non-ASCII text a caller supplies - purely by adding more physical\n * lines, never by dropping or truncating anything (verified: rejoining every folded line always\n * reproduces the original value exactly).\n *\n * The one value-altering fallback is deliberately gated on the *hard* limit, not the soft one:\n * an unbroken token (a single very long address, an encoded-word with no adjacent break) that\n * fits under {@link MAX_HEADER_HARD_LIMIT} is left on one long physical line rather than\n * force-broken at the soft width - forcing a break through the middle of an atomic token (an\n * email address has no internal whitespace) would insert a space that was never there,\n * corrupting it. Only a token that would itself violate the real transport limit gets the\n * content-altering hard-wrap - a case that essentially never occurs with real-world input.\n */\nfunction foldHeaderLine(line: string): string {\n const lines: string[] = [];\n let remaining = line;\n\n while (remaining.length > MAX_HEADER_LINE_LENGTH) {\n let breakAt = remaining.lastIndexOf(' ', MAX_HEADER_LINE_LENGTH);\n\n if (breakAt <= 0) {\n // No break within the soft width - look further ahead instead of forcing one through an\n // atomic token. Still bounded by the hard limit, so the physical line this produces can\n // never violate the real transport constraint.\n const nextBreak = remaining.indexOf(' ', MAX_HEADER_LINE_LENGTH);\n breakAt = nextBreak > 0 && nextBreak <= MAX_HEADER_HARD_LIMIT ? nextBreak : -1;\n }\n\n if (breakAt > 0) {\n lines.push(remaining.slice(0, breakAt));\n remaining = remaining.slice(breakAt);\n continue;\n }\n\n if (remaining.length <= MAX_HEADER_HARD_LIMIT) {\n break;\n }\n\n // Truly no natural break within the hard limit - an unbroken token that would itself\n // violate the transport line cap. This is the only path that can alter the value.\n lines.push(remaining.slice(0, MAX_HEADER_HARD_LIMIT));\n remaining = ` ${remaining.slice(MAX_HEADER_HARD_LIMIT)}`;\n }\n\n lines.push(remaining);\n\n return lines.join(CRLF);\n}\n\n/** MIME requires encoded body lines capped well under the RFC 5322 998-byte hard limit. */\nfunction foldBase64(base64: string): string {\n const lines: string[] = [];\n\n for (let index = 0; index < base64.length; index += BASE64_LINE_LENGTH) {\n lines.push(base64.slice(index, index + BASE64_LINE_LENGTH));\n }\n\n return lines.join(CRLF);\n}\n\n/** UTF-8 text (`text`/`html` bodies) must be encoded before folding - unlike {@link encodeBufferBase64}, which folds bytes that are already final. Two names instead of one so the caller can never feed raw bytes through the wrong path and silently double-encode them. */\nfunction encodeTextBase64(text: string): string {\n return foldBase64(Buffer.from(text, 'utf-8').toString('base64'));\n}\n\n/** Attachment bytes are already final binary content - only folding applies, no UTF-8 re-encode. */\nfunction encodeBufferBase64(buffer: Buffer): string {\n return foldBase64(buffer.toString('base64'));\n}\n\n/** A literal CR/LF/NUL inside a header-bound value would let it break out of its own header line and forge additional headers or smuggle body content - classic email header injection. Every value spliced into a raw header line is checked here first, so an attempt fails loudly instead of silently reaching the wire.\n *\n * `value` is `unknown`, not `string`: `IMailMessage`/`IMailAttachment` both end in\n * `[key: string]: any`, so nothing at the type layer stops a caller (e.g. a controller\n * forwarding a request body) from putting a non-string - notably an array - where a string is\n * declared. `Array.prototype.includes('\\r')` checks element *equality*, not substring, so\n * `['x\\r\\nBcc: evil'].includes('\\r')` is `false` and a naive string-only check would wave a\n * forged header straight through once it is later stringified by a template literal. Requiring\n * `typeof value === 'string'` up front closes that gap for every field that flows through here. */\nfunction assertNoHeaderInjection(opts: { field: string; value: unknown }): void {\n const { field, value } = opts;\n\n if (typeof value !== 'string') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.INVALID_CONFIGURATION,\n message: `Invalid Amazon SES message | ${field} must be a string`,\n });\n }\n\n if (!value.includes('\\r') && !value.includes('\\n') && !value.includes('\\0')) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.INVALID_CONFIGURATION,\n message: `Invalid Amazon SES message | ${field} contains illegal control characters`,\n });\n}\n\n/** Same guard as {@link assertNoHeaderInjection}, applied to every address in a `to`/`cc`/`bcc`\n * field individually - a string field only, not `[key: string]: any`; validating the raw\n * caller-provided value (before splitting/joining) both types and content-checks each entry. */\nfunction assertNoAddressListInjection(opts: { field: string; value: string | string[] }): void {\n const { field, value } = opts;\n const list = Array.isArray(value) ? value : [value];\n\n for (const item of list) {\n assertNoHeaderInjection({ field, value: item });\n }\n}\n\nfunction extractDomain(address: string | undefined): string {\n const match = address ? /@([^@>\\s]+)>?\\s*$/.exec(address) : null;\n\n return match ? match[1] : 'localhost';\n}\n\nfunction buildHeaders(message: IMailMessage): string[] {\n const headers: string[] = [];\n\n if (message.from) {\n assertNoAddressListInjection({ field: 'from', value: message.from });\n headers.push(foldHeaderLine(`From: ${formatAddressList(message.from)}`));\n }\n\n if (message.to) {\n assertNoAddressListInjection({ field: 'to', value: message.to });\n headers.push(foldHeaderLine(`To: ${formatAddressList(message.to)}`));\n }\n\n if (message.cc) {\n assertNoAddressListInjection({ field: 'cc', value: message.cc });\n headers.push(foldHeaderLine(`Cc: ${formatAddressList(message.cc)}`));\n }\n\n if (message.replyTo) {\n assertNoAddressListInjection({ field: 'replyTo', value: message.replyTo });\n headers.push(foldHeaderLine(`Reply-To: ${formatAddressList(message.replyTo)}`));\n }\n\n // Checked, never emitted: a `Bcc:` header would disclose the blind recipients, so they travel as\n // `Destination.BccAddresses`. Without this, `bcc` is the one address field that fails at AWS.\n if (message.bcc) {\n assertNoAddressListInjection({ field: 'bcc', value: message.bcc });\n }\n\n assertNoHeaderInjection({ field: 'subject', value: message.subject });\n headers.push(foldHeaderLine(`Subject: ${encodeHeaderValue(message.subject)}`));\n // RFC 5322 requires both on every message; SES's raw-message parser does not synthesize them,\n // so an omission here is an omission on the wire (some receiving MTAs reject a `Date`-less\n // message outright, and a missing `Message-ID` breaks threading and dedup).\n headers.push(`Date: ${new Date().toUTCString()}`);\n headers.push(`Message-ID: <${generateRandomHex({ bytes: 16 })}@${extractDomain(message.from)}>`);\n headers.push('MIME-Version: 1.0');\n\n if (message.headers) {\n const messageHeadersEntries = Object.entries(message.headers);\n\n for (const [key, value] of messageHeadersEntries) {\n assertNoHeaderInjection({ field: `headers.${key}`, value: key });\n assertNoHeaderInjection({ field: `headers.${key}`, value });\n headers.push(foldHeaderLine(`${key}: ${encodeHeaderValue(value)}`));\n }\n }\n\n return headers;\n}\n\n/** One text/plain or text/html MIME part. `boundary` omitted only for the single-part, no-attachment case, where the content type belongs on the top-level headers instead of a nested part. */\nfunction textPart(\n boundary: string,\n contentType: 'text/plain' | 'text/html',\n content: string,\n): string {\n return [\n `--${boundary}`,\n `Content-Type: ${contentType}; charset=UTF-8`,\n 'Content-Transfer-Encoding: base64',\n '',\n encodeTextBase64(content),\n ].join(CRLF);\n}\n\nfunction escapeQuotedString(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\n/** RFC 2231 percent-encoding for the `filename*=`/`name*=` extended parameter form. */\nfunction encodeRfc2231(value: string): string {\n return encodeURIComponent(value).replace(\n /[!'()*]/g,\n (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n}\n\n/**\n * Builds the `; name=\"...\"`/`; filename=\"...\"` (and, for non-ASCII names, the RFC 2231\n * `; filename*=UTF-8''...` extended form) suffix for a Content-Type/Content-Disposition line.\n * ASCII names are still quoted-string escaped - an unescaped `\"` or `\\` in a filename would\n * terminate the quoted string early and let the rest of the value merge into a sibling MIME\n * parameter, corrupting the part header for every downstream reader.\n */\nfunction attachmentNameParams(attribute: 'name' | 'filename', value: string): string {\n if (isAscii(value)) {\n return `; ${attribute}=\"${escapeQuotedString(value)}\"`;\n }\n\n const asciiFallback = value.replace(/[^\\x20-\\x7E]/g, '_');\n\n return (\n `; ${attribute}=\"${escapeQuotedString(asciiFallback)}\"` +\n `; ${attribute}*=UTF-8''${encodeRfc2231(value)}`\n );\n}\n\nasync function attachmentPart(attachment: IMailAttachment, boundary: string): Promise<string> {\n // No root here: a `path` that did not go through `MailAttachmentUtility.resolve` is refused, never read.\n const content = await MailAttachmentUtility.readContent({ attachment });\n const contentType = attachment.contentType ?? 'application/octet-stream';\n assertNoHeaderInjection({ field: 'attachment.contentType', value: contentType });\n\n if (attachment.filename) {\n assertNoHeaderInjection({ field: 'attachment.filename', value: attachment.filename });\n }\n\n if (attachment.cid) {\n assertNoHeaderInjection({ field: 'attachment.cid', value: attachment.cid });\n }\n\n const nameAttribute = attachment.filename\n ? attachmentNameParams('name', attachment.filename)\n : '';\n const filenameAttribute = attachment.filename\n ? attachmentNameParams('filename', attachment.filename)\n : '';\n const disposition = attachment.cid ? 'inline' : 'attachment';\n\n const headerLines = [\n `--${boundary}`,\n foldHeaderLine(`Content-Type: ${contentType}${nameAttribute}`),\n 'Content-Transfer-Encoding: base64',\n foldHeaderLine(`Content-Disposition: ${disposition}${filenameAttribute}`),\n ];\n\n if (attachment.cid) {\n headerLines.push(`Content-ID: <${attachment.cid}>`);\n }\n\n return [...headerLines, '', encodeBufferBase64(content)].join(CRLF);\n}\n\n/** Every boundary is generated the same way - a fixed prefix plus random hex - so no two nested multipart sections in one message can ever collide. */\nfunction newBoundary(label: string): string {\n return `----=_${label}_${generateRandomHex({ bytes: 16 })}`;\n}\n\n/** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */\nexport class MailMimeUtility {\n /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a\n * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,\n * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */\n static formatAddressHeader(opts: { value: string | string[] }): string {\n return formatAddressList(opts.value);\n }\n\n /**\n * Builds a raw RFC 822 message with zero external dependencies - Amazon SES's `SendEmailCommand`\n * `Content.Simple` shape has no attachment field, so attachments require a raw MIME body. Written\n * by hand instead of depending on `nodemailer`'s `MailComposer` so the `ses` provider never needs\n * the `nodemailer` peer installed at all.\n *\n * Inline (`cid`) attachments nest under `multipart/related` next to the body - a mail client\n * only renders `cid:` references inline when they share a `multipart/related` parent with the\n * body; under `multipart/mixed` they show up as ordinary downloadable attachments instead. Plain\n * file attachments (no `cid`) stay under `multipart/mixed`, alongside the body or the\n * `multipart/related` group when both kinds are present.\n */\n static async buildRawMessage(opts: { message: IMailMessage }): Promise<Buffer> {\n const { message } = opts;\n const headers = buildHeaders(message);\n const attachments = message.attachments ?? [];\n const inlineAttachments = attachments.filter((attachment) => Boolean(attachment.cid));\n const fileAttachments = attachments.filter((attachment) => !attachment.cid);\n const hasBothBodies = Boolean(message.text) && Boolean(message.html);\n const singleContentType = message.html ? ('text/html' as const) : ('text/plain' as const);\n const singleContent = message.html ?? message.text ?? '';\n\n const bodyPart = (boundary: string): string => {\n if (!hasBothBodies) {\n return textPart(boundary, singleContentType, singleContent);\n }\n\n const altBoundary = newBoundary('Alt');\n\n return [\n `--${boundary}`,\n `Content-Type: multipart/alternative; boundary=\"${altBoundary}\"`,\n '',\n [\n textPart(altBoundary, 'text/plain', message.text ?? ''),\n textPart(altBoundary, 'text/html', message.html ?? ''),\n `--${altBoundary}--`,\n ].join(CRLF),\n ].join(CRLF);\n };\n\n if (attachments.length === 0 && !hasBothBodies) {\n headers.push(`Content-Type: ${singleContentType}; charset=UTF-8`);\n headers.push('Content-Transfer-Encoding: base64');\n\n return Buffer.from([...headers, '', encodeTextBase64(singleContent)].join(CRLF), 'utf-8');\n }\n\n if (attachments.length === 0) {\n const boundary = newBoundary('Alt');\n headers.push(`Content-Type: multipart/alternative; boundary=\"${boundary}\"`);\n const parts = [\n textPart(boundary, 'text/plain', message.text ?? ''),\n textPart(boundary, 'text/html', message.html ?? ''),\n `--${boundary}--`,\n ];\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const buildRelatedPart = async (parentBoundary: string): Promise<string> => {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n\n return [\n `--${parentBoundary}`,\n `Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`,\n '',\n parts.join(CRLF),\n ].join(CRLF);\n };\n\n if (inlineAttachments.length > 0 && fileAttachments.length === 0) {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n headers.push(`Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`);\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const mixedBoundary = newBoundary('Mixed');\n headers.push(`Content-Type: multipart/mixed; boundary=\"${mixedBoundary}\"`);\n\n const bodyParts: string[] = [];\n\n if (inlineAttachments.length > 0) {\n const result2 = await buildRelatedPart(mixedBoundary);\n bodyParts.push(result2);\n } else {\n bodyParts.push(bodyPart(mixedBoundary));\n }\n\n for (const attachment of fileAttachments) {\n const result3 = await attachmentPart(attachment, mixedBoundary);\n bodyParts.push(result3);\n }\n\n bodyParts.push(`--${mixedBoundary}--`);\n\n return Buffer.from([...headers, '', bodyParts.join(CRLF)].join(CRLF), 'utf-8');\n }\n}\n"]}
1
+ {"version":3,"file":"mime.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/mime.utility.ts"],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B,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACtD,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;QAC1C,CAAC;QAED,KAAK,MAAM,UAAU,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YAChE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,CAAC;QAEvC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACjF,CAAC;CACF","sourcesContent":["import { TokenUidHelper, UidTokenEncodings } from '@venizia/ignis-helpers/core';\nimport type { IMailAttachment, IMailMessage } from '../common';\nimport { MailAddressUtility } from './address.utility';\nimport { MailAttachmentUtility } from './attachment.utility';\nimport { MailHeaderUtility } from './header.utility';\n\nconst CRLF = '\\r\\n';\nconst BASE64_LINE_LENGTH = 76;\n/** RFC 5322 recommends folding well under its own 998-byte hard limit; 78 matches common MTA\n * practice. This is a *soft* preferred width, not a hard requirement - {@link foldHeaderLine}\n * only forces a line break past it when a natural whitespace break point exists nearby. */\nconst MAX_HEADER_LINE_LENGTH = 78;\n/** The real hard requirement: SES rejects any raw-message physical line at or over 1000 bytes.\n * A 10-byte margin below that, and comfortably under RFC 5322's own 998-octet hard limit. Only\n * an unbroken token that would itself cross this line forces {@link foldHeaderLine}'s\n * content-altering hard-wrap fallback - below it, one long line is safer than corrupting an\n * atomic value (a single very long address, an unbroken encoded-word) by splitting it. */\nconst MAX_HEADER_HARD_LIMIT = 990;\n/** RFC 2047 caps one encoded-word (`=?charset?B?...?=` included) at 75 characters. */\nconst ENCODED_WORD_MAX_LENGTH = 75;\n\n/** `bytes` random bytes as lowercase hex, from the platform CSPRNG. `bytes` is at least 16, the floor of `TokenUidHelper`. */\nfunction generateRandomHex(opts: { bytes: number }): string {\n return new TokenUidHelper({ bytes: opts.bytes, encoding: UidTokenEncodings.HEX }).nextId();\n}\n\nfunction isAscii(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n if (value.charCodeAt(index) > 127) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * RFC 2047 §5(3) requires each encoded-word to carry whole characters - a multi-byte UTF-8\n * sequence split across two encoded-words decodes to mojibake or invalid UTF-8 on either side of\n * the cut. `bytesPerChunk` is a fixed byte budget, not a character-aligned one, so after slicing\n * at that budget we walk the boundary back over any UTF-8 continuation bytes (`10xxxxxx`, i.e.\n * `byte & 0xC0 === 0x80`) until it lands on the leading byte of a character. `bytesPerChunk` is\n * always far larger than the longest UTF-8 sequence (4 bytes), so this walk-back can never\n * consume the whole chunk. Words are joined with a single space - the required separator between\n * adjacent encoded-words, and also a valid header-folding point.\n */\nfunction encodeWord(text: string): string {\n const prefix = '=?UTF-8?B?';\n const suffix = '?=';\n const maxPayloadChars = ENCODED_WORD_MAX_LENGTH - prefix.length - suffix.length;\n const bytesPerChunk = Math.floor(maxPayloadChars / 4) * 3;\n const bytes = Buffer.from(text, 'utf-8');\n const words: string[] = [];\n let offset = 0;\n\n while (offset < bytes.length) {\n let end = Math.min(offset + bytesPerChunk, bytes.length);\n\n while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) {\n end--;\n }\n\n const chunk = bytes.subarray(offset, end);\n words.push(`${prefix}${chunk.toString('base64')}${suffix}`);\n offset = end;\n }\n\n return words.join(' ');\n}\n\n/** Only non-ASCII values pay for RFC 2047 encoding, so a plain-English subject or custom header\n * stays byte-for-byte readable. */\nfunction encodeHeaderValue(value: string): string {\n return isAscii(value) ? value : encodeWord(value);\n}\n\n/**\n * Encodes only the *display-name* portion of `\"Name\" <addr@x.com>` (or bare `Name <addr@x.com>`).\n * The `<addr-spec>` must stay 7-bit ASCII per RFC 5321/5322 and per the SES raw-message\n * requirements - only the free-text name may become an RFC 2047 encoded-word. A bare address with\n * no display name is returned unchanged.\n */\nfunction encodeAddress(address: string): string {\n const match = /^(.*)<([^<>]+)>\\s*$/.exec(address);\n\n if (!match) {\n return address;\n }\n\n const [, rawName, addr] = match;\n const name = rawName.trim().replace(/^\"|\"$/g, '');\n\n if (name.length === 0 || isAscii(name)) {\n return rawName.trim().length > 0 ? `${rawName.trim()} <${addr}>` : `<${addr}>`;\n }\n\n return `${encodeWord(name)} <${addr}>`;\n}\n\n/** The body of `MailMimeUtility.formatAddressHeader`, callable from the header builder. */\nfunction formatAddressList(value: string | string[]): string {\n return MailAddressUtility.splitList({ value }).map(encodeAddress).join(', ');\n}\n\n/**\n * RFC 5322 §2.2.3 header folding: inserting CRLF immediately before an existing whitespace\n * character splits one logical header value across physical lines without changing its content\n * (the folded whitespace is still there, just after a line break). SES enforces a 1000-byte\n * ceiling per raw-message line; folding at {@link MAX_HEADER_LINE_LENGTH} keeps arbitrarily long\n * recipient lists, subjects, or encoded display names deliverable regardless of how many\n * addresses or how much non-ASCII text a caller supplies - purely by adding more physical\n * lines, never by dropping or truncating anything (verified: rejoining every folded line always\n * reproduces the original value exactly).\n *\n * The one value-altering fallback is deliberately gated on the *hard* limit, not the soft one:\n * an unbroken token (a single very long address, an encoded-word with no adjacent break) that\n * fits under {@link MAX_HEADER_HARD_LIMIT} is left on one long physical line rather than\n * force-broken at the soft width - forcing a break through the middle of an atomic token (an\n * email address has no internal whitespace) would insert a space that was never there,\n * corrupting it. Only a token that would itself violate the real transport limit gets the\n * content-altering hard-wrap - a case that essentially never occurs with real-world input.\n */\nfunction foldHeaderLine(line: string): string {\n const lines: string[] = [];\n let remaining = line;\n\n while (remaining.length > MAX_HEADER_LINE_LENGTH) {\n let breakAt = remaining.lastIndexOf(' ', MAX_HEADER_LINE_LENGTH);\n\n if (breakAt <= 0) {\n // No break within the soft width - look further ahead instead of forcing one through an\n // atomic token. Still bounded by the hard limit, so the physical line this produces can\n // never violate the real transport constraint.\n const nextBreak = remaining.indexOf(' ', MAX_HEADER_LINE_LENGTH);\n breakAt = nextBreak > 0 && nextBreak <= MAX_HEADER_HARD_LIMIT ? nextBreak : -1;\n }\n\n if (breakAt > 0) {\n lines.push(remaining.slice(0, breakAt));\n remaining = remaining.slice(breakAt);\n continue;\n }\n\n if (remaining.length <= MAX_HEADER_HARD_LIMIT) {\n break;\n }\n\n // Truly no natural break within the hard limit - an unbroken token that would itself\n // violate the transport line cap. This is the only path that can alter the value.\n lines.push(remaining.slice(0, MAX_HEADER_HARD_LIMIT));\n remaining = ` ${remaining.slice(MAX_HEADER_HARD_LIMIT)}`;\n }\n\n lines.push(remaining);\n\n return lines.join(CRLF);\n}\n\n/** MIME requires encoded body lines capped well under the RFC 5322 998-byte hard limit. */\nfunction foldBase64(base64: string): string {\n const lines: string[] = [];\n\n for (let index = 0; index < base64.length; index += BASE64_LINE_LENGTH) {\n lines.push(base64.slice(index, index + BASE64_LINE_LENGTH));\n }\n\n return lines.join(CRLF);\n}\n\n/** UTF-8 text (`text`/`html` bodies) must be encoded before folding - unlike {@link encodeBufferBase64}, which folds bytes that are already final. Two names instead of one so the caller can never feed raw bytes through the wrong path and silently double-encode them. */\nfunction encodeTextBase64(text: string): string {\n return foldBase64(Buffer.from(text, 'utf-8').toString('base64'));\n}\n\n/** Attachment bytes are already final binary content - only folding applies, no UTF-8 re-encode. */\nfunction encodeBufferBase64(buffer: Buffer): string {\n return foldBase64(buffer.toString('base64'));\n}\n\nfunction extractDomain(address: string | undefined): string {\n const match = address ? /@([^@>\\s]+)>?\\s*$/.exec(address) : null;\n\n return match ? match[1] : 'localhost';\n}\n\nfunction buildHeaders(message: IMailMessage): string[] {\n const headers: string[] = [];\n\n if (message.from) {\n headers.push(foldHeaderLine(`From: ${formatAddressList(message.from)}`));\n }\n\n if (message.to) {\n headers.push(foldHeaderLine(`To: ${formatAddressList(message.to)}`));\n }\n\n if (message.cc) {\n headers.push(foldHeaderLine(`Cc: ${formatAddressList(message.cc)}`));\n }\n\n if (message.replyTo) {\n headers.push(foldHeaderLine(`Reply-To: ${formatAddressList(message.replyTo)}`));\n }\n\n headers.push(foldHeaderLine(`Subject: ${encodeHeaderValue(message.subject)}`));\n // RFC 5322 requires both on every message; SES's raw-message parser does not synthesize them,\n // so an omission here is an omission on the wire (some receiving MTAs reject a `Date`-less\n // message outright, and a missing `Message-ID` breaks threading and dedup).\n headers.push(`Date: ${new Date().toUTCString()}`);\n headers.push(`Message-ID: <${generateRandomHex({ bytes: 16 })}@${extractDomain(message.from)}>`);\n headers.push('MIME-Version: 1.0');\n\n if (message.headers) {\n const messageHeadersEntries = Object.entries(message.headers);\n\n for (const [key, value] of messageHeadersEntries) {\n headers.push(foldHeaderLine(`${key}: ${encodeHeaderValue(value)}`));\n }\n }\n\n return headers;\n}\n\n/** One text/plain or text/html MIME part. `boundary` omitted only for the single-part, no-attachment case, where the content type belongs on the top-level headers instead of a nested part. */\nfunction textPart(\n boundary: string,\n contentType: 'text/plain' | 'text/html',\n content: string,\n): string {\n return [\n `--${boundary}`,\n `Content-Type: ${contentType}; charset=UTF-8`,\n 'Content-Transfer-Encoding: base64',\n '',\n encodeTextBase64(content),\n ].join(CRLF);\n}\n\nfunction escapeQuotedString(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\n/** RFC 2231 percent-encoding for the `filename*=`/`name*=` extended parameter form. */\nfunction encodeRfc2231(value: string): string {\n return encodeURIComponent(value).replace(\n /[!'()*]/g,\n (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n}\n\n/**\n * Builds the `; name=\"...\"`/`; filename=\"...\"` (and, for non-ASCII names, the RFC 2231\n * `; filename*=UTF-8''...` extended form) suffix for a Content-Type/Content-Disposition line.\n * ASCII names are still quoted-string escaped - an unescaped `\"` or `\\` in a filename would\n * terminate the quoted string early and let the rest of the value merge into a sibling MIME\n * parameter, corrupting the part header for every downstream reader.\n */\nfunction attachmentNameParams(attribute: 'name' | 'filename', value: string): string {\n if (isAscii(value)) {\n return `; ${attribute}=\"${escapeQuotedString(value)}\"`;\n }\n\n const asciiFallback = value.replace(/[^\\x20-\\x7E]/g, '_');\n\n return (\n `; ${attribute}=\"${escapeQuotedString(asciiFallback)}\"` +\n `; ${attribute}*=UTF-8''${encodeRfc2231(value)}`\n );\n}\n\nasync function attachmentPart(attachment: IMailAttachment, boundary: string): Promise<string> {\n // No root here: a `path` that did not go through `MailAttachmentUtility.resolve` is refused, never read.\n const content = await MailAttachmentUtility.readContent({ attachment });\n const contentType = attachment.contentType ?? 'application/octet-stream';\n MailHeaderUtility.assertValue({ field: 'attachment.contentType', value: contentType });\n\n if (attachment.filename) {\n MailHeaderUtility.assertValue({ field: 'attachment.filename', value: attachment.filename });\n }\n\n if (attachment.cid) {\n MailHeaderUtility.assertValue({ field: 'attachment.cid', value: attachment.cid });\n }\n\n const nameAttribute = attachment.filename\n ? attachmentNameParams('name', attachment.filename)\n : '';\n const filenameAttribute = attachment.filename\n ? attachmentNameParams('filename', attachment.filename)\n : '';\n const disposition = attachment.cid ? 'inline' : 'attachment';\n\n const headerLines = [\n `--${boundary}`,\n foldHeaderLine(`Content-Type: ${contentType}${nameAttribute}`),\n 'Content-Transfer-Encoding: base64',\n foldHeaderLine(`Content-Disposition: ${disposition}${filenameAttribute}`),\n ];\n\n if (attachment.cid) {\n headerLines.push(`Content-ID: <${attachment.cid}>`);\n }\n\n return [...headerLines, '', encodeBufferBase64(content)].join(CRLF);\n}\n\n/** Every boundary is generated the same way - a fixed prefix plus random hex - so no two nested multipart sections in one message can ever collide. */\nfunction newBoundary(label: string): string {\n return `----=_${label}_${generateRandomHex({ bytes: 16 })}`;\n}\n\n/** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */\nexport class MailMimeUtility {\n /** Escapes `\\` and `\"` so a value can sit inside a quoted string: a display name, a MIME parameter. */\n static escapeQuotedString(opts: { value: string }): string {\n return escapeQuotedString(opts.value);\n }\n\n /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a\n * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,\n * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */\n static formatAddressHeader(opts: { value: string | string[] }): string {\n return formatAddressList(opts.value);\n }\n\n /**\n * Builds a raw RFC 822 message with zero external dependencies - Amazon SES's `SendEmailCommand`\n * `Content.Simple` shape has no attachment field, so attachments require a raw MIME body. Written\n * by hand instead of depending on `nodemailer`'s `MailComposer` so the `ses` provider never needs\n * the `nodemailer` peer installed at all.\n *\n * Inline (`cid`) attachments nest under `multipart/related` next to the body - a mail client\n * only renders `cid:` references inline when they share a `multipart/related` parent with the\n * body; under `multipart/mixed` they show up as ordinary downloadable attachments instead. Plain\n * file attachments (no `cid`) stay under `multipart/mixed`, alongside the body or the\n * `multipart/related` group when both kinds are present.\n */\n static async buildRawMessage(opts: { message: IMailMessage }): Promise<Buffer> {\n const { message } = opts;\n const headers = buildHeaders(message);\n const attachments = message.attachments ?? [];\n const inlineAttachments = attachments.filter((attachment) => Boolean(attachment.cid));\n const fileAttachments = attachments.filter((attachment) => !attachment.cid);\n const hasBothBodies = Boolean(message.text) && Boolean(message.html);\n const singleContentType = message.html ? ('text/html' as const) : ('text/plain' as const);\n const singleContent = message.html ?? message.text ?? '';\n\n const bodyPart = (boundary: string): string => {\n if (!hasBothBodies) {\n return textPart(boundary, singleContentType, singleContent);\n }\n\n const altBoundary = newBoundary('Alt');\n\n return [\n `--${boundary}`,\n `Content-Type: multipart/alternative; boundary=\"${altBoundary}\"`,\n '',\n [\n textPart(altBoundary, 'text/plain', message.text ?? ''),\n textPart(altBoundary, 'text/html', message.html ?? ''),\n `--${altBoundary}--`,\n ].join(CRLF),\n ].join(CRLF);\n };\n\n if (attachments.length === 0 && !hasBothBodies) {\n headers.push(`Content-Type: ${singleContentType}; charset=UTF-8`);\n headers.push('Content-Transfer-Encoding: base64');\n\n return Buffer.from([...headers, '', encodeTextBase64(singleContent)].join(CRLF), 'utf-8');\n }\n\n if (attachments.length === 0) {\n const boundary = newBoundary('Alt');\n headers.push(`Content-Type: multipart/alternative; boundary=\"${boundary}\"`);\n const parts = [\n textPart(boundary, 'text/plain', message.text ?? ''),\n textPart(boundary, 'text/html', message.html ?? ''),\n `--${boundary}--`,\n ];\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const buildRelatedPart = async (parentBoundary: string): Promise<string> => {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n\n return [\n `--${parentBoundary}`,\n `Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`,\n '',\n parts.join(CRLF),\n ].join(CRLF);\n };\n\n if (inlineAttachments.length > 0 && fileAttachments.length === 0) {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n headers.push(`Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`);\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const mixedBoundary = newBoundary('Mixed');\n headers.push(`Content-Type: multipart/mixed; boundary=\"${mixedBoundary}\"`);\n\n const bodyParts: string[] = [];\n\n if (inlineAttachments.length > 0) {\n const result2 = await buildRelatedPart(mixedBoundary);\n bodyParts.push(result2);\n } else {\n bodyParts.push(bodyPart(mixedBoundary));\n }\n\n for (const attachment of fileAttachments) {\n const result3 = await attachmentPart(attachment, mixedBoundary);\n bodyParts.push(result3);\n }\n\n bodyParts.push(`--${mixedBoundary}--`);\n\n return Buffer.from([...headers, '', bodyParts.join(CRLF)].join(CRLF), 'utf-8');\n }\n}\n"]}
@@ -1,9 +1,6 @@
1
1
  import type { TConstValue } from '@venizia/ignis-helpers/common';
2
- /** The response headers a controller echoes from the backend's metadata. */
2
+ /** What a controller sends with every object. */
3
3
  export declare class StaticAssetHeaders {
4
- /** `content-type` is absent on purpose: it is decided from the object name, never from the backend. */
5
- static readonly ALLOWED: readonly ["content-encoding", "cache-control", "etag", "last-modified"];
6
- /** Of what a controller sends with every object. */
7
4
  static readonly NOSNIFF = "nosniff";
8
5
  static readonly CSP_SANDBOX = "sandbox";
9
6
  static readonly RANGE_UNIT: "bytes";
@@ -51,6 +48,10 @@ export declare class StaticAssetDefaults {
51
48
  static readonly PENDING_PREFIX = "pending/";
52
49
  /** The most file parts one upload request may carry unless `serverUpload.maxFiles` says otherwise. */
53
50
  static readonly MAX_UPLOAD_FILES = 20;
51
+ /** The most bytes of JSON one file's signed `metadata` may take: the token travels in every request. */
52
+ static readonly MAX_TOKEN_METADATA_BYTES = 1024;
53
+ /** The key of the application's token metadata inside a MetaLink row's `metadata` column. */
54
+ static readonly META_LINK_METADATA_KEY = "app";
54
55
  }
55
56
  /** Codes the component reports in a body instead of throwing. */
56
57
  export declare class StaticAssetMetaLinkCodes {
@@ -1,14 +1,6 @@
1
1
  import { HTTP } from '@venizia/ignis-helpers/common';
2
- /** The response headers a controller echoes from the backend's metadata. */
2
+ /** What a controller sends with every object. */
3
3
  export class StaticAssetHeaders {
4
- /** `content-type` is absent on purpose: it is decided from the object name, never from the backend. */
5
- static { this.ALLOWED = [
6
- HTTP.Headers.CONTENT_ENCODING,
7
- HTTP.Headers.CACHE_CONTROL,
8
- HTTP.Headers.ETAG,
9
- HTTP.Headers.LAST_MODIFIED,
10
- ]; }
11
- /** Of what a controller sends with every object. */
12
4
  static { this.NOSNIFF = 'nosniff'; }
13
5
  static { this.CSP_SANDBOX = 'sandbox'; }
14
6
  static { this.RANGE_UNIT = HTTP.HeaderValues.RANGE_UNIT_BYTES; }
@@ -78,6 +70,10 @@ export class StaticAssetDefaults {
78
70
  static { this.PENDING_PREFIX = 'pending/'; }
79
71
  /** The most file parts one upload request may carry unless `serverUpload.maxFiles` says otherwise. */
80
72
  static { this.MAX_UPLOAD_FILES = 20; }
73
+ /** The most bytes of JSON one file's signed `metadata` may take: the token travels in every request. */
74
+ static { this.MAX_TOKEN_METADATA_BYTES = 1024; }
75
+ /** The key of the application's token metadata inside a MetaLink row's `metadata` column. */
76
+ static { this.META_LINK_METADATA_KEY = 'app'; }
81
77
  }
82
78
  /** Codes the component reports in a body instead of throwing. */
83
79
  export class StaticAssetMetaLinkCodes {
@@ -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;IAEX,oDAAoD;aACpC,YAAO,GAAG,SAAS,CAAC;aACpB,gBAAW,GAAG,SAAS,CAAC;aACxB,eAAU,GAAG,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC;;AAGlE,2CAA2C;AAC3C,MAAM,OAAO,uBAAuB;IAClC;;;;OAIG;aACa,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,YAAY,CAAC,SAAS;QAC3B,IAAI,CAAC,YAAY,CAAC,UAAU;QAC5B,IAAI,CAAC,YAAY,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BAAgB,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"]}
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,iDAAiD;AACjD,MAAM,OAAO,kBAAkB;aACb,YAAO,GAAG,SAAS,CAAC;aACpB,gBAAW,GAAG,SAAS,CAAC;aACxB,eAAU,GAAG,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC;;AAGlE,2CAA2C;AAC3C,MAAM,OAAO,uBAAuB;IAClC;;;;OAIG;aACa,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,YAAY,CAAC,SAAS;QAC3B,IAAI,CAAC,YAAY,CAAC,UAAU;QAC5B,IAAI,CAAC,YAAY,CAAC,SAAS;QAC3B,IAAI,CAAC,YAAY,CAAC,UAAU;QAC5B,YAAY;QACZ,WAAW;QACX,cAAc;QACd,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,WAAW;QACX,IAAI,CAAC,YAAY,CAAC,eAAe;QACjC,IAAI,CAAC,YAAY,CAAC,UAAU;QAC5B,IAAI,CAAC,YAAY,CAAC,QAAQ;KAC3B,CAAC,CAAC;;AAGL,2EAA2E;AAC3E,MAAM,OAAO,oBAAoB;aACf,WAAM,GAAG,QAAQ,CAAC;aAClB,iBAAY,GAAG,aAAa,CAAC;aAC7B,kBAAa,GAAG,cAAc,CAAC;aAC/B,uBAAkB,GAAG,iBAAiB,CAAC;aACvC,4BAAuB,GAAG,sBAAsB,CAAC;aAEjD,kBAAa,GAAG,cAAc,CAAC;aAC/B,kBAAa,GAAG,cAAc,CAAC;aAC/B,oBAAe,GAAG,gBAAgB,CAAC;aAEnC,uBAAkB,GAAG,kBAAkB,CAAC;IAExD,wCAAwC;aACxB,QAAG,GAAG;QACpB,oBAAoB,CAAC,kBAAkB;QACvC,oBAAoB,CAAC,uBAAuB;QAC5C,oBAAoB,CAAC,MAAM;QAC3B,oBAAoB,CAAC,aAAa;QAClC,oBAAoB,CAAC,YAAY;QACjC,oBAAoB,CAAC,aAAa;QAClC,oBAAoB,CAAC,aAAa;QAClC,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;IAEtC,wGAAwG;aACxF,6BAAwB,GAAG,IAAI,CAAC;IAEhD,6FAA6F;aAC7E,2BAAsB,GAAG,KAAK,CAAC;;AAGjD,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/** What a controller sends with every object. */\nexport class StaticAssetHeaders {\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 /** The most bytes of JSON one file's signed `metadata` may take: the token travels in every request. */\n static readonly MAX_TOKEN_METADATA_BYTES = 1024;\n\n /** The key of the application's token metadata inside a MetaLink row's `metadata` column. */\n static readonly META_LINK_METADATA_KEY = 'app';\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"]}
@@ -44,6 +44,24 @@ export declare const StaticAssetErrors: {
44
44
  readonly statusCode: 409;
45
45
  readonly category: "validation";
46
46
  };
47
+ /** The destination already holds an object: the token was committed once, and a second commit would overwrite it. */
48
+ readonly UPLOAD_ALREADY_COMMITTED: {
49
+ readonly message: {
50
+ readonly text: "The upload was already committed";
51
+ readonly code: "core.static_asset.upload_already_committed";
52
+ };
53
+ readonly statusCode: 409;
54
+ readonly category: "validation";
55
+ };
56
+ /** The metadata a policy would sign is not allowed: oversized, or sent by a client with no `resolvers.metadata` to read it. */
57
+ readonly UPLOAD_METADATA_INVALID: {
58
+ readonly message: {
59
+ readonly text: "Invalid upload metadata";
60
+ readonly code: "core.static_asset.upload_metadata_invalid";
61
+ };
62
+ readonly statusCode: 400;
63
+ readonly category: "validation";
64
+ };
47
65
  /** With a `validation` on, `commit` takes the token `upload-validate` returned, not the one the policy issued. */
48
66
  readonly UPLOAD_NOT_VALIDATED: {
49
67
  readonly message: {
@@ -39,6 +39,24 @@ export const StaticAssetErrors = {
39
39
  statusCode: HTTP.ResultCodes.RS_4.Conflict,
40
40
  category: ErrorScopes.VALIDATION,
41
41
  },
42
+ /** The destination already holds an object: the token was committed once, and a second commit would overwrite it. */
43
+ UPLOAD_ALREADY_COMMITTED: {
44
+ message: {
45
+ text: 'The upload was already committed',
46
+ code: 'core.static_asset.upload_already_committed',
47
+ },
48
+ statusCode: HTTP.ResultCodes.RS_4.Conflict,
49
+ category: ErrorScopes.VALIDATION,
50
+ },
51
+ /** The metadata a policy would sign is not allowed: oversized, or sent by a client with no `resolvers.metadata` to read it. */
52
+ UPLOAD_METADATA_INVALID: {
53
+ message: {
54
+ text: 'Invalid upload metadata',
55
+ code: 'core.static_asset.upload_metadata_invalid',
56
+ },
57
+ statusCode: HTTP.ResultCodes.RS_4.BadRequest,
58
+ category: ErrorScopes.VALIDATION,
59
+ },
42
60
  /** With a `validation` on, `commit` takes the token `upload-validate` returned, not the one the policy issued. */
43
61
  UPLOAD_NOT_VALIDATED: {
44
62
  message: {
@@ -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,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,E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B;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"]}
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,IA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AAI,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 /** The destination already holds an object: the token was committed once, and a second commit would overwrite it. */\n UPLOAD_ALREADY_COMMITTED: {\n message: {\n text: 'The upload was already committed',\n code: 'core.static_asset.upload_already_committed',\n },\n statusCode: HTTP.ResultCodes.RS_4.Conflict,\n category: ErrorScopes.VALIDATION,\n },\n /** The metadata a policy would sign is not allowed: oversized, or sent by a client with no `resolvers.metadata` to read it. */\n UPLOAD_METADATA_INVALID: {\n message: {\n text: 'Invalid upload metadata',\n code: 'core.static_asset.upload_metadata_invalid',\n },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\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"]}
@@ -43,6 +43,43 @@ export type TStaticAssetUploadLabels = {
43
43
  /** Display order within the principal. Caller-supplied: deriving it would be a non-atomic read of `max(sequence)` then a write of `max + 1`. */
44
44
  sequence?: number;
45
45
  };
46
+ /** Application-chosen strings the commit token signs for one file. The token is signed, not encrypted: no secrets. */
47
+ export type TStaticAssetTokenMetadata = Record<string, string>;
48
+ /** One file of an upload-policy request. `metadata` is the client's hint: `resolvers.metadata` reads it, and only what that returns is signed. */
49
+ export type TStaticAssetUploadPolicyFile = {
50
+ fileName: string;
51
+ contentType?: string;
52
+ size?: number;
53
+ metadata?: TStaticAssetTokenMetadata;
54
+ };
55
+ /** The decisions of a direct upload that belong to the application, each made on a different call. */
56
+ export type TStaticAssetDirectUploadResolvers = {
57
+ /**
58
+ * Who the upload belongs to. Called on every direct-upload route: the policy route signs the
59
+ * answer into the commit token, and the other routes refuse a token whose owner differs.
60
+ */
61
+ owner: (opts: {
62
+ context: TRouteContext;
63
+ }) => ValueOrPromise<string>;
64
+ /** Per file, at policy time: what the token signs for it, readable again at validate and commit. Absent, a client that sends `metadata` is refused. */
65
+ metadata?: (opts: {
66
+ context: TRouteContext;
67
+ file: TStaticAssetUploadPolicyFile;
68
+ }) => ValueOrPromise<TStaticAssetTokenMetadata>;
69
+ commit?: {
70
+ /** At commit time: the final key, in the same bucket and inside the `keyPrefix`. Absent keeps `defaultKey`. */
71
+ destination?: (opts: {
72
+ owner: string;
73
+ metadata: TStaticAssetTokenMetadata;
74
+ file: {
75
+ fileName: string;
76
+ };
77
+ defaultKey: string;
78
+ }) => ValueOrPromise<{
79
+ key: string;
80
+ }>;
81
+ };
82
+ };
46
83
  /** 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. */
47
84
  export type TStaticAssetDirectUploadOptions = {
48
85
  /**
@@ -54,14 +91,8 @@ export type TStaticAssetDirectUploadOptions = {
54
91
  authorize?: (opts: {
55
92
  context: TRouteContext;
56
93
  }) => ValueOrPromise<boolean>;
57
- /**
58
- * Who the upload belongs to. Called on every direct-upload route: the policy route signs the
59
- * answer into the commit token, and the other routes refuse a token whose owner differs. Absent,
60
- * a token commits for whoever holds it.
61
- */
62
- resolveOwner?: (opts: {
63
- context: TRouteContext;
64
- }) => ValueOrPromise<string>;
94
+ /** What the application decides about an upload; `owner` is required, the rest is optional. */
95
+ resolvers: TStaticAssetDirectUploadResolvers;
65
96
  /** Signs the commit token. Keep it out of the repository and out of the client. */
66
97
  secretKey: string;
67
98
  /** 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. */
@@ -119,7 +150,8 @@ export interface IStaticAssetValidation<IssueSchema extends z.ZodType> {
119
150
  /** Runs once per `upload-validate`. Read the file through `file`: every read is pinned to the content `commit` will copy. */
120
151
  handler: (opts: {
121
152
  file: StaticAssetPinnedFile;
122
- owner?: string;
153
+ owner: string;
154
+ metadata: TStaticAssetTokenMetadata;
123
155
  }) => ValueOrPromise<IStaticAssetValidationResult<z.infer<IssueSchema>>>;
124
156
  }
125
157
  /** What `validate` answers. `commitToken` is present only when the file is valid: it is the token `commit` takes. */
@@ -128,11 +160,7 @@ export interface IStaticAssetValidateResult<Issue> extends IStaticAssetValidatio
128
160
  }
129
161
  /** Body of the upload policy route: the files the client intends to upload. */
130
162
  export type TStaticAssetUploadPolicyRequest = {
131
- files: Array<{
132
- fileName: string;
133
- contentType?: string;
134
- size?: number;
135
- }>;
163
+ files: TStaticAssetUploadPolicyFile[];
136
164
  };
137
165
  /** 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. */
138
166
  export type TMetaLinkConfig<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {
@@ -255,15 +283,16 @@ export interface IStaticAssetPin {
255
283
  }
256
284
  /**
257
285
  * What a commit token binds: the pending object a policy was issued for, when the grant dies and,
258
- * when the application supplies one, who it was issued to. Other business fields are deliberately
259
- * absent - which order or tenant an upload belongs to is the application's.
286
+ * who it was issued to and the application's own metadata for the file.
260
287
  */
261
288
  export interface IStaticAssetCommitTokenPayload {
262
289
  bucket: IBucketRef;
263
290
  object: IObjectRef;
264
291
  expiresAt: number;
265
- /** Absent when `directUpload.resolveOwner` is not set; present, the token commits only for that owner. */
266
- owner?: string;
292
+ /** The token commits only for this owner. */
293
+ owner: string;
294
+ /** What `resolvers.metadata` returned for the file; `{}` without one. Signed, not encrypted. */
295
+ metadata: TStaticAssetTokenMetadata;
267
296
  stage: TStaticAssetTokenStage;
268
297
  /** Present from `VALIDATED` on: `commit` copies only content that still matches it. */
269
298
  pin?: IStaticAssetPin;