@venizia/ignis 0.4.8-8 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/README.md +1 -0
  2. package/dist/esm/base/applications/base.js.map +1 -1
  3. package/dist/esm/components/api-reference/common/types.d.ts +6 -3
  4. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  5. package/dist/esm/components/api-reference/component.js +8 -3
  6. package/dist/esm/components/api-reference/component.js.map +1 -1
  7. package/dist/esm/components/auth/authenticate/component.js +3 -2
  8. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  9. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
  10. package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
  11. package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
  12. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
  13. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +18 -1
  14. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  15. package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
  16. package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
  17. package/dist/esm/components/index.d.ts +1 -0
  18. package/dist/esm/components/index.js +1 -0
  19. package/dist/esm/components/index.js.map +1 -1
  20. package/dist/esm/components/mail/common/constants.d.ts +24 -14
  21. package/dist/esm/components/mail/common/constants.js +19 -32
  22. package/dist/esm/components/mail/common/constants.js.map +1 -1
  23. package/dist/esm/components/mail/common/errors.d.ts +10 -1
  24. package/dist/esm/components/mail/common/errors.js +7 -1
  25. package/dist/esm/components/mail/common/errors.js.map +1 -1
  26. package/dist/esm/components/mail/common/types/message.d.ts +4 -4
  27. package/dist/esm/components/mail/common/types/message.js.map +1 -1
  28. package/dist/esm/components/mail/common/types/options.d.ts +54 -10
  29. package/dist/esm/components/mail/common/types/options.js.map +1 -1
  30. package/dist/esm/components/mail/common/types/queue.d.ts +23 -12
  31. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  32. package/dist/esm/components/mail/common/types/template.d.ts +5 -4
  33. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  34. package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
  35. package/dist/esm/components/mail/common/types/verification.js.map +1 -1
  36. package/dist/esm/components/mail/component.js +11 -2
  37. package/dist/esm/components/mail/component.js.map +1 -1
  38. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +1 -1
  39. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +15 -28
  40. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  41. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
  42. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
  43. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  44. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +11 -6
  45. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  46. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
  47. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
  48. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  49. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
  50. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
  51. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  52. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
  53. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
  54. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  55. package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
  56. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  57. package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -6
  58. package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
  59. package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
  60. package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
  61. package/dist/esm/components/mail/services/generators/random-token.js +9 -6
  62. package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
  63. package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
  64. package/dist/esm/components/mail/services/mail.service.js +21 -19
  65. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  66. package/dist/esm/components/mail/services/template.service.d.ts +7 -5
  67. package/dist/esm/components/mail/services/template.service.js +24 -16
  68. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  69. package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
  70. package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
  71. package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
  72. package/dist/esm/components/mail/utilities/header.utility.js +44 -0
  73. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
  74. package/dist/esm/components/mail/utilities/index.d.ts +1 -0
  75. package/dist/esm/components/mail/utilities/index.js +1 -0
  76. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  77. package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
  78. package/dist/esm/components/mail/utilities/mime.utility.js +12 -58
  79. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  80. package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
  81. package/dist/esm/components/mail/utilities/type.utility.js +6 -7
  82. package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
  83. package/dist/esm/components/server-info/common/constants.d.ts +6 -0
  84. package/dist/esm/components/server-info/common/constants.js +6 -0
  85. package/dist/esm/components/server-info/common/constants.js.map +1 -0
  86. package/dist/esm/components/server-info/common/index.d.ts +5 -0
  87. package/dist/esm/components/server-info/common/index.js +5 -0
  88. package/dist/esm/components/server-info/common/index.js.map +1 -0
  89. package/dist/esm/components/server-info/common/keys.d.ts +5 -0
  90. package/dist/esm/components/server-info/common/keys.js +5 -0
  91. package/dist/esm/components/server-info/common/keys.js.map +1 -0
  92. package/dist/esm/components/server-info/common/rest-paths.d.ts +5 -0
  93. package/dist/esm/components/server-info/common/rest-paths.js +5 -0
  94. package/dist/esm/components/server-info/common/rest-paths.js.map +1 -0
  95. package/dist/esm/components/server-info/common/types.d.ts +68 -0
  96. package/dist/esm/components/server-info/common/types.js +2 -0
  97. package/dist/esm/components/server-info/common/types.js.map +1 -0
  98. package/dist/esm/components/server-info/component.d.ts +31 -0
  99. package/dist/esm/components/server-info/component.js +87 -0
  100. package/dist/esm/components/server-info/component.js.map +1 -0
  101. package/dist/esm/components/server-info/controller.d.ts +14 -0
  102. package/dist/esm/components/server-info/controller.js +68 -0
  103. package/dist/esm/components/server-info/controller.js.map +1 -0
  104. package/dist/esm/components/server-info/index.d.ts +5 -0
  105. package/dist/esm/components/server-info/index.js +5 -0
  106. package/dist/esm/components/server-info/index.js.map +1 -0
  107. package/dist/esm/components/server-info/reporter.d.ts +25 -0
  108. package/dist/esm/components/server-info/reporter.js +68 -0
  109. package/dist/esm/components/server-info/reporter.js.map +1 -0
  110. package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
  111. package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
  112. package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
  113. package/dist/esm/components/static-asset/common/constants.js +75 -47
  114. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  115. package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
  116. package/dist/esm/components/static-asset/common/errors.js +31 -33
  117. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  118. package/dist/esm/components/static-asset/common/index.d.ts +1 -1
  119. package/dist/esm/components/static-asset/common/index.js +1 -1
  120. package/dist/esm/components/static-asset/common/index.js.map +1 -1
  121. package/dist/esm/components/static-asset/common/keys.d.ts +10 -2
  122. package/dist/esm/components/static-asset/common/keys.js +10 -2
  123. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  124. package/dist/esm/components/static-asset/common/types.d.ts +267 -147
  125. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  126. package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
  127. package/dist/esm/components/static-asset/common/validation.js +8 -0
  128. package/dist/esm/components/static-asset/common/validation.js.map +1 -0
  129. package/dist/esm/components/static-asset/component.d.ts +4 -2
  130. package/dist/esm/components/static-asset/component.js +26 -31
  131. package/dist/esm/components/static-asset/component.js.map +1 -1
  132. package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
  133. package/dist/esm/components/static-asset/controller/factory.js +26 -917
  134. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  135. package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
  136. package/dist/esm/components/static-asset/controller/index.js +1 -0
  137. package/dist/esm/components/static-asset/controller/index.js.map +1 -1
  138. package/dist/esm/components/static-asset/controller/routes/context.d.ts +62 -0
  139. package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
  140. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
  141. package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
  142. package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
  143. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
  144. package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
  145. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
  146. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
  147. package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
  148. package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
  149. package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
  150. package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
  151. package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
  152. package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
  153. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
  154. package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
  155. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
  156. package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
  157. package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
  158. package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
  159. package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
  160. package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
  161. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
  162. package/dist/esm/components/static-asset/index.d.ts +2 -1
  163. package/dist/esm/components/static-asset/index.js +2 -1
  164. package/dist/esm/components/static-asset/index.js.map +1 -1
  165. package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
  166. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  167. package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
  168. package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
  169. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
  170. package/dist/esm/components/static-asset/services/index.d.ts +3 -0
  171. package/dist/esm/components/static-asset/services/index.js +3 -0
  172. package/dist/esm/components/static-asset/services/index.js.map +1 -0
  173. package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
  174. package/dist/esm/components/static-asset/services/policy.service.js +104 -0
  175. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
  176. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
  177. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
  178. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
  179. package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
  180. package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
  181. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
  182. package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
  183. package/dist/esm/components/static-asset/utilities/index.js +6 -0
  184. package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
  185. package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +5 -5
  186. package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +12 -10
  187. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
  188. package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
  189. package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
  190. package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
  191. package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
  192. package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
  193. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
  194. package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
  195. package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
  196. package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
  197. package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
  198. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
  199. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
  200. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +43 -0
  201. package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
  202. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
  203. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
  204. package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
  205. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
  206. package/dist/esm/testing/assert-application-boots.d.ts +2 -2
  207. package/dist/esm/testing/assert-application-boots.js +6 -2
  208. package/dist/esm/testing/assert-application-boots.js.map +1 -1
  209. package/dist/presets/app/preset.json +4 -4
  210. package/dist/presets/lib/preset.json +3 -3
  211. package/dist/presets/shared/preset.json +1 -1
  212. package/package.json +8 -8
  213. package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
  214. package/dist/esm/components/static-asset/common/commit-token.js +0 -48
  215. package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
  216. package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
  217. package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
  218. package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
  219. package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
  220. package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
  221. package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
  222. package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
  223. package/dist/esm/components/static-asset/controller/route-options.js +0 -47
  224. package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
  225. package/dist/esm/components/static-asset/ingest.js.map +0 -1
@@ -311,13 +311,30 @@ export class AbstractBearerTokenService extends BaseService {
311
311
  message: key,
312
312
  secret: this.applicationSecret,
313
313
  });
314
+ const encryptedValue = payload[key];
315
+ if (typeof encryptedValue !== 'string') {
316
+ throw getError({
317
+ statusCode: HTTP.ResultCodes.RS_4.Unauthorized,
318
+ message: '[decryptPayload] An encrypted claim is not a string',
319
+ });
320
+ }
314
321
  const decryptedValue = await this.aes.decrypt({
315
- message: payload[key],
322
+ message: encryptedValue,
316
323
  secret: this.applicationSecret,
317
324
  });
318
325
  rs[decryptedKey] = this.deserializeField({ key: decryptedKey, value: decryptedValue });
319
326
  }
327
+ if (!AbstractBearerTokenService.isTokenPayload(rs)) {
328
+ throw getError({
329
+ statusCode: HTTP.ResultCodes.RS_4.Unauthorized,
330
+ message: '[decryptPayload] The decrypted claims carry no userId',
331
+ });
332
+ }
320
333
  return rs;
321
334
  }
335
+ /** A decrypted claim set is a payload only if it names its user. */
336
+ static isTokenPayload(value) {
337
+ return 'userId' in value && value.userId !== undefined;
338
+ }
322
339
  }
323
340
  //# sourceMappingURL=abstract.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/bearer/abstract.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAUtE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiB5C,gGAAgG;AAChG,MAAM,OAAgB,0BAAgD,SAAQ,WAAW;IAAzF;;QAYY,QAAG,GAAe,IAAI,CAAC;QACvB,sBAAiB,GAAkB,IAAI,CAAC;QACxC,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;QAEnE,oJAAoJ;QAC1I,iBAAY,GAA6B,IAAI,CAAC;QAExD,yFAAyF;QAC/E,kBAAa,GAA4B,IAAI,CAAC;IA4a1D,CAAC;IA/bC,oDAAoD;aACpC,sBAAiB,GAAG,IAAI,GAAG,CAAmB;QAC5D,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC,AAR+B,CAQ9B;IAYH,2CAA2C;aAC3B,eAAU,GAA0B,CAAC,QAAQ,EAAE,UAAU,CAAC,AAAhD,CAAiD;IAE3E;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,CAAC,IAI1B;QACC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;QAClD,MAAM,IAA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AC;gBACrB,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YAEH,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QACzF,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC","sourcesContent":["import type { AESAlgorithmType } from '@venizia/ignis-helpers';\nimport { AES } from '@venizia/ignis-helpers';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, RecordUtility } from '@venizia/ignis-helpers/core';\nimport type {\n IJWTClaimsOptions,\n IJWTIssueClaims,\n IJWTTokenPayload,\n IJWTVerifyOptions,\n IPayloadFieldCodec,\n TContext,\n TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport {\n Authentication,\n AuthenticationErrors,\n BaseService,\n ServiceAssertion,\n} from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport { JoseLoader } from '../jose-loader';\nimport type { JWTPayload, JWTVerifyOptions, JWTVerifyResult, SignJWT } from 'jose';\n\n/** What a token service is configured with for claims: the required `claims`, the `verify` checks, and the removed `sign` it refuses. */\nexport interface IClaimsConfigSource {\n claims?: unknown;\n verify?: unknown;\n /** Removed: refused with a message that points to `claims`. */\n sign?: unknown;\n}\n\n/** What {@link AbstractBearerTokenService.resolveClaimsConfig} answers: the validated claims and the verify options jose receives. */\nexport interface IResolvedClaimsConfig {\n claims: IJWTClaimsOptions;\n verify: JWTVerifyOptions & { algorithms: string[] };\n}\n\n/** Abstract base for Bearer-token services (JWS, JWKS) with optional AES payload encryption. */\nexport abstract class AbstractBearerTokenService<E extends Env = Env> extends BaseService {\n /** Standard JWT fields that are never encrypted. */\n static readonly JWT_COMMON_FIELDS = new Set<keyof JWTPayload>([\n 'iss',\n 'sub',\n 'aud',\n 'jti',\n 'nbf',\n 'exp',\n 'iat',\n ]);\n\n protected aes: AES | null = null;\n protected applicationSecret: string | null = null;\n protected fieldCodecs: Map<string, IPayloadFieldCodec> = new Map();\n\n /** Configured `iss` / `aud`: stamped on every issued token, authoritative over anything the payload carries, and required on every verified one. */\n protected claimOptions: IJWTClaimsOptions | null = null;\n\n /** What jose verifies against: the claims, the algorithm pin and the `verify` checks. */\n protected verifyOptions: JWTVerifyOptions | null = null;\n\n /** The keys a `claims` object may hold. */\n static readonly CLAIM_KEYS: ReadonlyArray<string> = ['issuer', 'audience'];\n\n /**\n * Validates the claims configuration of a token service and answers what the service uses. It throws, naming the\n * key, when `claims.issuer` is missing or empty, when `claims.audience` is present but not a non-empty string or a\n * non-empty list of them, when `claims` holds another key, when the removed `sign` or `verify.issuer` /\n * `verify.audience` is still passed, and when no algorithm is pinned. `claims.audience` is optional: without it\n * no `aud` is stamped and none is checked.\n * `pinnedAlgorithms` is what the service signs with; a verifier has none and requires `verify.algorithms`.\n * The component calls it at boot, and a service calls it when it is built, so neither can start without them.\n */\n static resolveClaimsConfig(opts: {\n scope: string;\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): IResolvedClaimsConfig {\n const { scope, options, pinnedAlgorithms } = opts;\n const fail = (detail: string) =>\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${detail}`,\n });\n\n if (options.sign !== undefined) {\n throw fail(\n '`sign` was removed | put the issuer and the audience in `claims: { issuer, audience }`: they are stamped on every token and required on every verified one',\n );\n }\n\n if (options.verify !== undefined && !RecordUtility.isPlainRecord(options.verify)) {\n throw fail(\n 'verify must be an object | its checks (maxTokenAge, subject, ...) would be dropped silently',\n );\n }\n\n const verify = RecordUtility.isPlainRecord(options.verify) ? options.verify : {};\n\n for (const key of AbstractBearerTokenService.CLAIM_KEYS) {\n if (key in verify) {\n throw fail(\n `verify.${key} was removed | set claims.${key}: it is stamped on every token and required on every verified one`,\n );\n }\n }\n\n const { claims } = options;\n\n if (!RecordUtility.isPlainRecord(claims)) {\n throw fail(\n 'claims is required | pass claims: { issuer: string, audience: string | string[] }: a token signed with the same key for another purpose must not authenticate a request',\n );\n }\n\n const unknown = Object.keys(claims).filter(\n (key) => !AbstractBearerTokenService.CLAIM_KEYS.includes(key),\n );\n\n if (unknown.length > 0) {\n throw fail(\n `claims holds unknown keys ${JSON.stringify(unknown)} | accepted: ${AbstractBearerTokenService.CLAIM_KEYS.join(', ')}`,\n );\n }\n\n const { issuer, audience } = claims;\n const isName = (value: unknown): value is string =>\n typeof value === 'string' && value.trim().length > 0;\n\n if (!isName(issuer)) {\n throw fail('claims.issuer is required | a non-empty string');\n }\n\n // Optional, but a present value is checked: `null`, `''` and `[]` are mistakes, not \"no audience\".\n if (\n audience !== undefined &&\n !isName(audience) &&\n !(Array.isArray(audience) && audience.length > 0 && audience.every(isName))\n ) {\n throw fail(\n 'claims.audience must be a non-empty string or a non-empty list of them | or leave it out',\n );\n }\n\n const resolvedAudience = Array.isArray(audience) ? [...audience] : audience;\n\n const algorithms = verify.algorithms ?? pinnedAlgorithms;\n\n if (!Array.isArray(algorithms) || algorithms.length === 0 || !algorithms.every(isName)) {\n throw fail(\n \"verify.algorithms is required | the accepted JWS algorithms, for example ['RS256']: a verifier cannot know what the issuer signs with\",\n );\n }\n\n if (algorithms.some((algorithm) => algorithm.trim().toLowerCase() === 'none')) {\n throw fail(\"the algorithm 'none' is refused | a token with no signature verifies nothing\");\n }\n\n return {\n claims: { issuer, ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }) },\n verify: {\n ...(verify as IJWTVerifyOptions),\n issuer,\n ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }),\n algorithms: [...algorithms],\n },\n };\n }\n\n /** Validates the claims configuration (see {@link AbstractBearerTokenService.resolveClaimsConfig}) and keeps the result. */\n protected configureClaims(opts: {\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): void {\n const resolved = AbstractBearerTokenService.resolveClaimsConfig({\n scope: this.scope,\n options: opts.options,\n pinnedAlgorithms: opts.pinnedAlgorithms,\n });\n\n this.claimOptions = resolved.claims;\n this.verifyOptions = resolved.verify;\n }\n\n /** Configures AES payload encryption and field codecs. Both aesAlgorithm and applicationSecret required to activate encryption. */\n protected configurePayloadEncryption(opts: {\n aesAlgorithm?: AESAlgorithmType;\n applicationSecret?: string;\n fieldCodecs?: IPayloadFieldCodec[];\n }): void {\n const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs } = opts;\n\n if (fieldCodecs) {\n for (const codec of fieldCodecs) {\n this.fieldCodecs.set(codec.key, codec);\n }\n }\n\n if (!applicationSecret) {\n return;\n }\n\n this.aes = AES.withAlgorithm(aesAlgorithm);\n this.applicationSecret = applicationSecret;\n }\n\n extractCredentials(context: TContext<E, string>): { type: string; token: string } {\n const request = context.req;\n\n const authHeaderValue = request.header('Authorization');\n\n if (!authHeaderValue) {\n throw getError({\n error: AuthenticationErrors.HEADER_MISSING,\n message: 'Unauthorized user! Missing authorization header',\n });\n }\n\n if (!authHeaderValue.startsWith(Authentication.TYPE_BEARER)) {\n throw getError({\n error: AuthenticationErrors.SCHEME_INVALID,\n message: 'Unauthorized user! Invalid schema of request token!',\n });\n }\n\n const parts = authHeaderValue.split(' ');\n\n if (parts.length !== 2) {\n throw getError({\n error: AuthenticationErrors.HEADER_MALFORMED,\n message: `Authorization header value is invalid format. It must follow the pattern: 'Bearer xx.yy.zz' where xx.yy.zz is a valid JWT token.`,\n });\n }\n\n const [tokenType, tokenValue] = parts;\n\n return { type: tokenType, token: tokenValue };\n }\n\n async verify(opts: { type: string; token: string }): Promise<IJWTTokenPayload> {\n const { token } = opts;\n\n if (!token) {\n this.logger.for(this.verify.name).error('Missing token for validating request!');\n throw getError({\n error: AuthenticationErrors.TOKEN_MISSING,\n message: '[verify] Invalid request token!',\n });\n }\n\n try {\n await this.assertNotServiceAssertion({ token });\n const result = await this.doVerify(token);\n\n return result;\n } catch (error) {\n // No log here - `cause` carries the reason (JWTExpired, signature mismatch) to the error handler, which logs the request once. An expired token is the caller's problem, hence `warn`.\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] Invalid or expired token',\n logLevel: 'warn',\n cause: error,\n });\n }\n }\n\n /**\n * A service assertion (`typ: svc+jwt`) is not a user token. When a JWKS issuer shares the key of the service\n * assertions and the names collide, an assertion would otherwise verify here, so the user-token path refuses it.\n */\n protected async assertNotServiceAssertion(opts: { token: string }): Promise<void> {\n const { decodeProtectedHeader } = await JoseLoader.load();\n const { typ } = decodeProtectedHeader(opts.token);\n const kind = typeof typ === 'string' ? typ.toLowerCase().replace(/^application\\//, '') : '';\n\n if (kind === ServiceAssertion.TYP) {\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] A service assertion is not a user token',\n });\n }\n }\n\n async generate(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn?: TGetTokenExpiresFn;\n /** Per-token registered claims. The supported way to vary `aud` / `sub`; the payload is not. */\n claims?: IJWTIssueClaims;\n }): Promise<string> {\n const { payload, claims, getTokenExpiresFn = this.getDefaultTokenExpiresFn() } = opts;\n\n if (!payload) {\n throw getError({\n error: AuthenticationErrors.TOKEN_PAYLOAD_INVALID,\n message: '[generate] Invalid token payload!',\n });\n }\n\n const signer = await this.getSigner({ payload, getTokenExpiresFn, claims });\n\n try {\n const result = await this.getSigningKey();\n const rs = await signer.sign(result);\n\n return rs;\n } catch (error) {\n this.logger.for(this.generate.name).error('Failed to generate token | Error: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[generate] Failed to generate token',\n });\n }\n }\n\n /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */\n protected serializeField(opts: { key: string; value: any }): string {\n const { key, value } = opts;\n const codec = value === null ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.serialize({ value });\n }\n\n return JSON.stringify(value);\n }\n\n /**\n * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;\n * without it, returns the payload as is. A `null` claim is encrypted like any other value and decodes as `null`,\n * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An\n * `undefined` claim is skipped, as JSON drops it.\n */\n async encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, any>> {\n if (!this.aes || !this.applicationSecret) {\n return payload;\n }\n\n const rs: Record<string, string> = {};\n\n const keys = Object.keys(payload);\n\n for (const key of keys) {\n const value = payload[key];\n\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = value;\n continue;\n }\n\n // Only `undefined` is skipped: JSON drops it too, so the claim is absent either way. `null` is a value, and\n // `serializeField` writes it as `null`, which `deserializeField` reads back, so an encrypted token decodes the\n // same payload as a plain one.\n if (value === undefined) {\n continue;\n }\n\n const encryptedKey = await this.aes.encrypt({\n message: key,\n secret: this.applicationSecret,\n });\n\n const serialized = this.serializeField({ key, value });\n\n const encryptedValue = await this.aes.encrypt({\n message: serialized,\n secret: this.applicationSecret,\n });\n rs[encryptedKey] = encryptedValue;\n }\n\n return rs;\n }\n\n /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */\n protected deserializeField(opts: { key: string; value: string }) {\n const { key, value } = opts;\n const codec = value === 'null' ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.deserialize({ raw: value });\n }\n\n return JSON.parse(value);\n }\n\n /**\n * Stamps the configured `iss` / `aud` onto a signer, plus any per-token claims the caller passed.\n *\n * The configured value is AUTHORITATIVE. `iss` and `aud` are in `JWT_COMMON_FIELDS`, so they ride\n * through the AES envelope in the clear and an application-shaped payload can carry them - an\n * issuer identity any payload could overwrite would not be an identity. A conflicting payload\n * claim is overwritten and reported.\n *\n * Per-token audience is an explicit argument rather than a smuggled payload key, so the caller\n * that legitimately needs one says so.\n */\n protected applySignClaims(opts: {\n signer: SignJWT;\n payload: Record<string, any>;\n claims?: IJWTIssueClaims;\n }): SignJWT {\n const { signer, payload, claims } = opts;\n const configured = this.claimOptions;\n\n const issuer = claims?.issuer ?? configured?.issuer;\n const audience = claims?.audience ?? configured?.audience;\n\n const logger = this.logger.for(this.applySignClaims.name);\n\n if (issuer !== undefined) {\n if (payload.iss !== undefined && payload.iss !== issuer) {\n logger.warn(\n 'Payload iss overridden by the configured issuer | payload: %s | configured: %s',\n payload.iss,\n issuer,\n );\n }\n\n signer.setIssuer(issuer);\n }\n\n if (audience !== undefined) {\n if (payload.aud !== undefined) {\n logger.warn('Payload aud overridden | payload: %j | applied: %j', payload.aud, audience);\n }\n\n signer.setAudience(audience);\n }\n\n if (claims?.subject !== undefined) {\n signer.setSubject(claims.subject);\n }\n\n if (claims?.jwtId !== undefined) {\n signer.setJti(claims.jwtId);\n }\n\n return signer;\n }\n\n async decryptPayload(opts: {\n result: JWTVerifyResult<IJWTTokenPayload>;\n }): Promise<IJWTTokenPayload> {\n const { payload, protectedHeader } = opts.result;\n\n if (!this.aes || !this.applicationSecret) {\n return payload as IJWTTokenPayload;\n }\n\n this.logger\n .for(this.decryptPayload.name)\n .debug('JWT Token | payload: %j | header: %j', payload, protectedHeader);\n\n const rs: any = {};\n\n for (const key in payload) {\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = payload[key];\n continue;\n }\n\n const decryptedKey = await this.aes.decrypt({\n message: key,\n secret: this.applicationSecret,\n });\n const decryptedValue = await this.aes.decrypt({\n message: payload[key],\n secret: this.applicationSecret,\n });\n\n rs[decryptedKey] = this.deserializeField({ key: decryptedKey, value: decryptedValue });\n }\n\n return rs;\n }\n\n protected abstract doVerify(token: string): Promise<IJWTTokenPayload>;\n\n abstract getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }): Promise<SignJWT>;\n\n protected abstract getSigningKey(): ValueOrPromise<Uint8Array | CryptoKey>;\n\n protected abstract getDefaultTokenExpiresFn(): TGetTokenExpiresFn;\n}\n"]}
1
+ {"version":3,"file":"abstract.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/bearer/abstract.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAUtE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiB5C,gGAAgG;AAChG,MAAM,OAAgB,0BAAgD,SAAQ,WAAW;IAAzF;;QAYY,QAAG,GAAe,IAAI,CAAC;QACvB,sBAAiB,GAAkB,IAAI,CAAC;QACxC,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;QAEnE,oJAAoJ;QAC1I,iBAAY,GAA6B,IAAI,CAAC;QAExD,yFAAyF;QAC/E,kBAAa,GAA4B,IAAI,CAAC;IAic1D,CAAC;IApdC,oDAAoD;aACpC,sBAAiB,GAAG,IAAI,GAAG,CAAmB;QAC5D,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC,AAR+B,CAQ9B;IAYH,2CAA2C;aAC3B,eAAU,GAA0B,CAAC,QAAQ,EAAE,UAAU,CAAC,AAAhD,CAAiD;IAE3E;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,CAAC,IAI1B;QACC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;QAClD,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,EAAE,CAC9B,QAAQ,CAAC;YACP,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,KAAK,KAAK,MAAM,EAAE;SAChC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,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC5C,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YAEH,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QACzF,CAAC;QAED,IAAI,CAAC,0BAA0B,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC;YACnD,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY;gBAC9C,OAAO,EAAE,uDAAuD;aACjE,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,oEAAoE;IAC5D,MAAM,CAAC,cAAc,CAAC,KAA8B;QAC1D,OAAO,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC;IACzD,CAAC","sourcesContent":["import type { AESAlgorithmType } from '@venizia/ignis-helpers';\nimport { AES } from '@venizia/ignis-helpers';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, RecordUtility } from '@venizia/ignis-helpers/core';\nimport type {\n IJWTClaimsOptions,\n IJWTIssueClaims,\n IJWTTokenPayload,\n IJWTVerifyOptions,\n IPayloadFieldCodec,\n TContext,\n TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport {\n Authentication,\n AuthenticationErrors,\n BaseService,\n ServiceAssertion,\n} from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport { JoseLoader } from '../jose-loader';\nimport type { JWTPayload, JWTVerifyOptions, JWTVerifyResult, SignJWT } from 'jose';\n\n/** What a token service is configured with for claims: the required `claims`, the `verify` checks, and the removed `sign` it refuses. */\nexport interface IClaimsConfigSource {\n claims?: unknown;\n verify?: unknown;\n /** Removed: refused with a message that points to `claims`. */\n sign?: unknown;\n}\n\n/** What {@link AbstractBearerTokenService.resolveClaimsConfig} answers: the validated claims and the verify options jose receives. */\nexport interface IResolvedClaimsConfig {\n claims: IJWTClaimsOptions;\n verify: JWTVerifyOptions & { algorithms: string[] };\n}\n\n/** Abstract base for Bearer-token services (JWS, JWKS) with optional AES payload encryption. */\nexport abstract class AbstractBearerTokenService<E extends Env = Env> extends BaseService {\n /** Standard JWT fields that are never encrypted. */\n static readonly JWT_COMMON_FIELDS = new Set<keyof JWTPayload>([\n 'iss',\n 'sub',\n 'aud',\n 'jti',\n 'nbf',\n 'exp',\n 'iat',\n ]);\n\n protected aes: AES | null = null;\n protected applicationSecret: string | null = null;\n protected fieldCodecs: Map<string, IPayloadFieldCodec> = new Map();\n\n /** Configured `iss` / `aud`: stamped on every issued token, authoritative over anything the payload carries, and required on every verified one. */\n protected claimOptions: IJWTClaimsOptions | null = null;\n\n /** What jose verifies against: the claims, the algorithm pin and the `verify` checks. */\n protected verifyOptions: JWTVerifyOptions | null = null;\n\n /** The keys a `claims` object may hold. */\n static readonly CLAIM_KEYS: ReadonlyArray<string> = ['issuer', 'audience'];\n\n /**\n * Validates the claims configuration of a token service and answers what the service uses. It throws, naming the\n * key, when `claims.issuer` is missing or empty, when `claims.audience` is present but not a non-empty string or a\n * non-empty list of them, when `claims` holds another key, when the removed `sign` or `verify.issuer` /\n * `verify.audience` is still passed, and when no algorithm is pinned. `claims.audience` is optional: without it\n * no `aud` is stamped and none is checked.\n * `pinnedAlgorithms` is what the service signs with; a verifier has none and requires `verify.algorithms`.\n * The component calls it at boot, and a service calls it when it is built, so neither can start without them.\n */\n static resolveClaimsConfig(opts: {\n scope: string;\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): IResolvedClaimsConfig {\n const { scope, options, pinnedAlgorithms } = opts;\n const fail = (detail: string) =>\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${detail}`,\n });\n\n if (options.sign !== undefined) {\n throw fail(\n '`sign` was removed | put the issuer and the audience in `claims: { issuer, audience }`: they are stamped on every token and required on every verified one',\n );\n }\n\n if (options.verify !== undefined && !RecordUtility.isPlainRecord(options.verify)) {\n throw fail(\n 'verify must be an object | its checks (maxTokenAge, subject, ...) would be dropped silently',\n );\n }\n\n const verify = RecordUtility.isPlainRecord(options.verify) ? options.verify : {};\n\n for (const key of AbstractBearerTokenService.CLAIM_KEYS) {\n if (key in verify) {\n throw fail(\n `verify.${key} was removed | set claims.${key}: it is stamped on every token and required on every verified one`,\n );\n }\n }\n\n const { claims } = options;\n\n if (!RecordUtility.isPlainRecord(claims)) {\n throw fail(\n 'claims is required | pass claims: { issuer: string, audience: string | string[] }: a token signed with the same key for another purpose must not authenticate a request',\n );\n }\n\n const unknown = Object.keys(claims).filter(\n (key) => !AbstractBearerTokenService.CLAIM_KEYS.includes(key),\n );\n\n if (unknown.length > 0) {\n throw fail(\n `claims holds unknown keys ${JSON.stringify(unknown)} | accepted: ${AbstractBearerTokenService.CLAIM_KEYS.join(', ')}`,\n );\n }\n\n const { issuer, audience } = claims;\n const isName = (value: unknown): value is string =>\n typeof value === 'string' && value.trim().length > 0;\n\n if (!isName(issuer)) {\n throw fail('claims.issuer is required | a non-empty string');\n }\n\n // Optional, but a present value is checked: `null`, `''` and `[]` are mistakes, not \"no audience\".\n if (\n audience !== undefined &&\n !isName(audience) &&\n !(Array.isArray(audience) && audience.length > 0 && audience.every(isName))\n ) {\n throw fail(\n 'claims.audience must be a non-empty string or a non-empty list of them | or leave it out',\n );\n }\n\n const resolvedAudience = Array.isArray(audience) ? [...audience] : audience;\n\n const algorithms = verify.algorithms ?? pinnedAlgorithms;\n\n if (!Array.isArray(algorithms) || algorithms.length === 0 || !algorithms.every(isName)) {\n throw fail(\n \"verify.algorithms is required | the accepted JWS algorithms, for example ['RS256']: a verifier cannot know what the issuer signs with\",\n );\n }\n\n if (algorithms.some((algorithm) => algorithm.trim().toLowerCase() === 'none')) {\n throw fail(\"the algorithm 'none' is refused | a token with no signature verifies nothing\");\n }\n\n return {\n claims: { issuer, ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }) },\n verify: {\n ...(verify as IJWTVerifyOptions),\n issuer,\n ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }),\n algorithms: [...algorithms],\n },\n };\n }\n\n /** Validates the claims configuration (see {@link AbstractBearerTokenService.resolveClaimsConfig}) and keeps the result. */\n protected configureClaims(opts: {\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): void {\n const resolved = AbstractBearerTokenService.resolveClaimsConfig({\n scope: this.scope,\n options: opts.options,\n pinnedAlgorithms: opts.pinnedAlgorithms,\n });\n\n this.claimOptions = resolved.claims;\n this.verifyOptions = resolved.verify;\n }\n\n /** Configures AES payload encryption and field codecs. Both aesAlgorithm and applicationSecret required to activate encryption. */\n protected configurePayloadEncryption(opts: {\n aesAlgorithm?: AESAlgorithmType;\n applicationSecret?: string;\n fieldCodecs?: IPayloadFieldCodec[];\n }): void {\n const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs } = opts;\n\n if (fieldCodecs) {\n for (const codec of fieldCodecs) {\n this.fieldCodecs.set(codec.key, codec);\n }\n }\n\n if (!applicationSecret) {\n return;\n }\n\n this.aes = AES.withAlgorithm(aesAlgorithm);\n this.applicationSecret = applicationSecret;\n }\n\n extractCredentials(context: TContext<E, string>): { type: string; token: string } {\n const request = context.req;\n\n const authHeaderValue = request.header('Authorization');\n\n if (!authHeaderValue) {\n throw getError({\n error: AuthenticationErrors.HEADER_MISSING,\n message: 'Unauthorized user! Missing authorization header',\n });\n }\n\n if (!authHeaderValue.startsWith(Authentication.TYPE_BEARER)) {\n throw getError({\n error: AuthenticationErrors.SCHEME_INVALID,\n message: 'Unauthorized user! Invalid schema of request token!',\n });\n }\n\n const parts = authHeaderValue.split(' ');\n\n if (parts.length !== 2) {\n throw getError({\n error: AuthenticationErrors.HEADER_MALFORMED,\n message: `Authorization header value is invalid format. It must follow the pattern: 'Bearer xx.yy.zz' where xx.yy.zz is a valid JWT token.`,\n });\n }\n\n const [tokenType, tokenValue] = parts;\n\n return { type: tokenType, token: tokenValue };\n }\n\n async verify(opts: { type: string; token: string }): Promise<IJWTTokenPayload> {\n const { token } = opts;\n\n if (!token) {\n this.logger.for(this.verify.name).error('Missing token for validating request!');\n throw getError({\n error: AuthenticationErrors.TOKEN_MISSING,\n message: '[verify] Invalid request token!',\n });\n }\n\n try {\n await this.assertNotServiceAssertion({ token });\n const result = await this.doVerify(token);\n\n return result;\n } catch (error) {\n // No log here - `cause` carries the reason (JWTExpired, signature mismatch) to the error handler, which logs the request once. An expired token is the caller's problem, hence `warn`.\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] Invalid or expired token',\n logLevel: 'warn',\n cause: error,\n });\n }\n }\n\n /**\n * A service assertion (`typ: svc+jwt`) is not a user token. When a JWKS issuer shares the key of the service\n * assertions and the names collide, an assertion would otherwise verify here, so the user-token path refuses it.\n */\n protected async assertNotServiceAssertion(opts: { token: string }): Promise<void> {\n const { decodeProtectedHeader } = await JoseLoader.load();\n const { typ } = decodeProtectedHeader(opts.token);\n const kind = typeof typ === 'string' ? typ.toLowerCase().replace(/^application\\//, '') : '';\n\n if (kind === ServiceAssertion.TYP) {\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] A service assertion is not a user token',\n });\n }\n }\n\n async generate(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn?: TGetTokenExpiresFn;\n /** Per-token registered claims. The supported way to vary `aud` / `sub`; the payload is not. */\n claims?: IJWTIssueClaims;\n }): Promise<string> {\n const { payload, claims, getTokenExpiresFn = this.getDefaultTokenExpiresFn() } = opts;\n\n if (!payload) {\n throw getError({\n error: AuthenticationErrors.TOKEN_PAYLOAD_INVALID,\n message: '[generate] Invalid token payload!',\n });\n }\n\n const signer = await this.getSigner({ payload, getTokenExpiresFn, claims });\n\n try {\n const result = await this.getSigningKey();\n const rs = await signer.sign(result);\n\n return rs;\n } catch (error) {\n this.logger.for(this.generate.name).error('Failed to generate token | Error: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[generate] Failed to generate token',\n });\n }\n }\n\n /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */\n protected serializeField(opts: { key: string; value: unknown }): string {\n const { key, value } = opts;\n const codec = value === null ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.serialize({ value });\n }\n\n return JSON.stringify(value);\n }\n\n /**\n * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;\n * without it, returns the payload as is. A `null` claim is encrypted like any other value and decodes as `null`,\n * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An\n * `undefined` claim is skipped, as JSON drops it.\n */\n async encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, unknown>> {\n if (!this.aes || !this.applicationSecret) {\n return payload;\n }\n\n const rs: Record<string, unknown> = {};\n\n const keys = Object.keys(payload);\n\n for (const key of keys) {\n const value = payload[key];\n\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = value;\n continue;\n }\n\n // Only `undefined` is skipped: JSON drops it too, so the claim is absent either way. `null` is a value, and\n // `serializeField` writes it as `null`, which `deserializeField` reads back, so an encrypted token decodes the\n // same payload as a plain one.\n if (value === undefined) {\n continue;\n }\n\n const encryptedKey = await this.aes.encrypt({\n message: key,\n secret: this.applicationSecret,\n });\n\n const serialized = this.serializeField({ key, value });\n\n const encryptedValue = await this.aes.encrypt({\n message: serialized,\n secret: this.applicationSecret,\n });\n rs[encryptedKey] = encryptedValue;\n }\n\n return rs;\n }\n\n /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */\n protected deserializeField(opts: { key: string; value: string }) {\n const { key, value } = opts;\n const codec = value === 'null' ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.deserialize({ raw: value });\n }\n\n return JSON.parse(value);\n }\n\n /**\n * Stamps the configured `iss` / `aud` onto a signer, plus any per-token claims the caller passed.\n *\n * The configured value is AUTHORITATIVE. `iss` and `aud` are in `JWT_COMMON_FIELDS`, so they ride\n * through the AES envelope in the clear and an application-shaped payload can carry them - an\n * issuer identity any payload could overwrite would not be an identity. A conflicting payload\n * claim is overwritten and reported.\n *\n * Per-token audience is an explicit argument rather than a smuggled payload key, so the caller\n * that legitimately needs one says so.\n */\n protected applySignClaims(opts: {\n signer: SignJWT;\n payload: Record<string, unknown>;\n claims?: IJWTIssueClaims;\n }): SignJWT {\n const { signer, payload, claims } = opts;\n const configured = this.claimOptions;\n\n const issuer = claims?.issuer ?? configured?.issuer;\n const audience = claims?.audience ?? configured?.audience;\n\n const logger = this.logger.for(this.applySignClaims.name);\n\n if (issuer !== undefined) {\n if (payload.iss !== undefined && payload.iss !== issuer) {\n logger.warn(\n 'Payload iss overridden by the configured issuer | payload: %s | configured: %s',\n payload.iss,\n issuer,\n );\n }\n\n signer.setIssuer(issuer);\n }\n\n if (audience !== undefined) {\n if (payload.aud !== undefined) {\n logger.warn('Payload aud overridden | payload: %j | applied: %j', payload.aud, audience);\n }\n\n signer.setAudience(audience);\n }\n\n if (claims?.subject !== undefined) {\n signer.setSubject(claims.subject);\n }\n\n if (claims?.jwtId !== undefined) {\n signer.setJti(claims.jwtId);\n }\n\n return signer;\n }\n\n async decryptPayload(opts: {\n result: JWTVerifyResult<IJWTTokenPayload>;\n }): Promise<IJWTTokenPayload> {\n const { payload, protectedHeader } = opts.result;\n\n if (!this.aes || !this.applicationSecret) {\n return payload as IJWTTokenPayload;\n }\n\n this.logger\n .for(this.decryptPayload.name)\n .debug('JWT Token | payload: %j | header: %j', payload, protectedHeader);\n\n const rs: Record<string, unknown> = {};\n\n for (const key in payload) {\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = payload[key];\n continue;\n }\n\n const decryptedKey = await this.aes.decrypt({\n message: key,\n secret: this.applicationSecret,\n });\n const encryptedValue = payload[key];\n\n if (typeof encryptedValue !== 'string') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.Unauthorized,\n message: '[decryptPayload] An encrypted claim is not a string',\n });\n }\n\n const decryptedValue = await this.aes.decrypt({\n message: encryptedValue,\n secret: this.applicationSecret,\n });\n\n rs[decryptedKey] = this.deserializeField({ key: decryptedKey, value: decryptedValue });\n }\n\n if (!AbstractBearerTokenService.isTokenPayload(rs)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.Unauthorized,\n message: '[decryptPayload] The decrypted claims carry no userId',\n });\n }\n\n return rs;\n }\n\n /** A decrypted claim set is a payload only if it names its user. */\n private static isTokenPayload(value: Record<string, unknown>): value is IJWTTokenPayload {\n return 'userId' in value && value.userId !== undefined;\n }\n\n protected abstract doVerify(token: string): Promise<IJWTTokenPayload>;\n\n abstract getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }): Promise<SignJWT>;\n\n protected abstract getSigningKey(): ValueOrPromise<Uint8Array | CryptoKey>;\n\n protected abstract getDefaultTokenExpiresFn(): TGetTokenExpiresFn;\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import type { IdType } from '../../../../../base/index.js';
2
- import type { AnyType } from '@venizia/ignis-helpers/common';
3
2
  import type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
4
3
  /** Filter passed to loadFilteredPolicy: which principal's policies to load. */
5
4
  export interface ICasbinPolicyFilter {
@@ -9,7 +8,7 @@ export interface ICasbinPolicyFilter {
9
8
  };
10
9
  }
11
10
  /** Drizzle connector for policy queries, typed on the shared `PgDatabase` base so postgres-js fits too. Declared here rather than imported from `@/connectors/postgres`: components depend on a minimal local contract, never a connector class. */
12
- export type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, AnyType>>;
11
+ export type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
13
12
  /** Minimal source the adapters depend on - any drizzle-backed datasource satisfies it. */
14
13
  export interface ICasbinPolicySource {
15
14
  /** A datasource that opens on first use opens here; one that opens at start resolves at once. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authorize/adapters/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IdType } from '@/base';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';\n\n/** Filter passed to loadFilteredPolicy: which principal's policies to load. */\nexport interface ICasbinPolicyFilter {\n principal: { type: string; id: IdType };\n}\n\n/** Drizzle connector for policy queries, typed on the shared `PgDatabase` base so postgres-js fits too. Declared here rather than imported from `@/connectors/postgres`: components depend on a minimal local contract, never a connector class. */\nexport type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, AnyType>>;\n\n/** Minimal source the adapters depend on - any drizzle-backed datasource satisfies it. */\nexport interface ICasbinPolicySource {\n /** A datasource that opens on first use opens here; one that opens at start resolves at once. */\n ensureOpen?(): Promise<void>;\n\n /** Preferred: lazily wires the driver on first read and survives pool rotation, mirroring repositories. */\n getConnector?(): TCasbinPolicyConnector;\n\n /** Back-compat: a pre-wired connector. Prefer getConnector on a real datasource. */\n connector?: TCasbinPolicyConnector;\n}\n\n/** Maps a logical table onto its physical name + schema. */\nexport interface IScopedCasbinTable {\n tableName: string;\n schemaName?: string;\n}\n\n/** All physical mapping the ScopedCasbinAdapter needs. App provides this; framework stays decoupled. */\nexport interface IScopedCasbinEntities {\n policyDefinition: IScopedCasbinTable & {\n metadata?: { columnName: string };\n };\n\n /** Permission catalog (id, code, ...). */\n permission: IScopedCasbinTable;\n\n /** Principal type labels used as casbin name prefixes. */\n principals: { user: string; role: string };\n\n /** Domain type labels (e.g. ['Merchant', 'Organizer']). */\n domainTypes: string[];\n\n /** Soft-delete handling for both tables. */\n softDelete?: { use: false } | { use: true; columnName: string };\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authorize/adapters/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IdType } from '@/base';\nimport type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';\n\n/** Filter passed to loadFilteredPolicy: which principal's policies to load. */\nexport interface ICasbinPolicyFilter {\n principal: { type: string; id: IdType };\n}\n\n/** Drizzle connector for policy queries, typed on the shared `PgDatabase` base so postgres-js fits too. Declared here rather than imported from `@/connectors/postgres`: components depend on a minimal local contract, never a connector class. */\nexport type TCasbinPolicyConnector = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;\n\n/** Minimal source the adapters depend on - any drizzle-backed datasource satisfies it. */\nexport interface ICasbinPolicySource {\n /** A datasource that opens on first use opens here; one that opens at start resolves at once. */\n ensureOpen?(): Promise<void>;\n\n /** Preferred: lazily wires the driver on first read and survives pool rotation, mirroring repositories. */\n getConnector?(): TCasbinPolicyConnector;\n\n /** Back-compat: a pre-wired connector. Prefer getConnector on a real datasource. */\n connector?: TCasbinPolicyConnector;\n}\n\n/** Maps a logical table onto its physical name + schema. */\nexport interface IScopedCasbinTable {\n tableName: string;\n schemaName?: string;\n}\n\n/** All physical mapping the ScopedCasbinAdapter needs. App provides this; framework stays decoupled. */\nexport interface IScopedCasbinEntities {\n policyDefinition: IScopedCasbinTable & {\n metadata?: { columnName: string };\n };\n\n /** Permission catalog (id, code, ...). */\n permission: IScopedCasbinTable;\n\n /** Principal type labels used as casbin name prefixes. */\n principals: { user: string; role: string };\n\n /** Domain type labels (e.g. ['Merchant', 'Organizer']). */\n domainTypes: string[];\n\n /** Soft-delete handling for both tables. */\n softDelete?: { use: false } | { use: true; columnName: string };\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  export * from './auth/index.js';
2
2
  export * from './health-check/index.js';
3
+ export * from './server-info/index.js';
3
4
  export * from './request-tracker/index.js';
4
5
  export * from './api-reference/index.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
1
  export * from './auth/index.js';
2
2
  export * from './health-check/index.js';
3
+ export * from './server-info/index.js';
3
4
  export * from './request-tracker/index.js';
4
5
  export * from './api-reference/index.js';
5
6
  // Excluded from the barrel - import directly from the subpath: mail, socket-io, static-asset, websocket
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAEhC,wGAAwG","sourcesContent":["export * from './auth';\nexport * from './health-check';\nexport * from './request-tracker';\nexport * from './api-reference';\n\n// Excluded from the barrel - import directly from the subpath: mail, socket-io, static-asset, websocket\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAEhC,wGAAwG","sourcesContent":["export * from './auth';\nexport * from './health-check';\nexport * from './server-info';\nexport * from './request-tracker';\nexport * from './api-reference';\n\n// Excluded from the barrel - import directly from the subpath: mail, socket-io, static-asset, websocket\n"]}
@@ -5,38 +5,50 @@ export declare class MailDefaults {
5
5
  static readonly FALLBACK_FROM = "noreply@example.com";
6
6
  /** Bytes of attachment content one message may carry, all attachments together. */
7
7
  static readonly MAX_ATTACHMENT_BYTES: number;
8
+ /** The subject of a template mail that has none of its own. */
9
+ static readonly SUBJECT = "No Subject";
10
+ /** Tries per queued mail, the first included, unless the job options say otherwise. */
11
+ static readonly ATTEMPTS = 3;
12
+ static readonly BACKOFF_DELAY_MS = 1000;
13
+ /** How long a failed BullMQ mail job stays in Redis (it holds a recipient address), and the most that stay. */
14
+ static readonly FAILED_JOB_RETENTION: {
15
+ age: number;
16
+ count: number;
17
+ };
8
18
  }
9
- /** Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */
19
+ /** Where a rendered template is going: `HTML` escapes every double-brace placeholder, `TEXT` (a subject, a plain-text part) inserts it as it is. A triple-brace placeholder is raw in both. */
20
+ export declare class MailTemplateFormats {
21
+ static readonly HTML = "html";
22
+ static readonly TEXT = "text";
23
+ }
24
+ /** Union of the `MailTemplateFormats` values. */
25
+ export type TMailTemplateFormat = TConstValue<typeof MailTemplateFormats>;
26
+ /** Names of the jobs the BullMQ mail executor adds. */
27
+ export declare class MailQueueJobNames {
28
+ static readonly SEND_VERIFICATION_EMAIL = "send-verification-email";
29
+ }
30
+ /** The codes of the server-side failures, which are not in the 4xx `MailErrors` catalog. Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */
10
31
  export declare class MailErrorCodes {
11
- static readonly INVALID_CONFIGURATION: string;
12
32
  static readonly SEND_FAILED: string;
13
33
  static readonly VERIFICATION_FAILED: string;
14
- static readonly INVALID_RECIPIENT: string;
15
34
  static readonly BATCH_SEND_FAILED: string;
16
- static readonly TEMPLATE_NOT_FOUND: string;
17
- static readonly ATTACHMENT_PATH_REFUSED: string;
18
- static readonly ATTACHMENT_TOO_LARGE: string;
19
- static readonly BODY_SOURCE_REFUSED: string;
20
35
  }
21
36
  /** Messages thrown by the mail queue executors. */
22
37
  export declare class MailExecutorErrors {
23
38
  static readonly PROCESSOR_NOT_SET = "Processor not set. Call setProcessor() first.";
39
+ static readonly CLOSED = "The executor is closed and takes no more jobs.";
24
40
  }
25
- /** Values of `IMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */
41
+ /** Values of `TMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */
26
42
  export declare class MailQueueExecutorTypes {
27
43
  static readonly DIRECT = "direct";
28
44
  static readonly INTERNAL_QUEUE = "internal-queue";
29
45
  static readonly BULLMQ = "bullmq";
30
- static readonly SCHEME_SET: Set<string>;
31
- static isValid(value: string): boolean;
32
46
  }
33
47
  /** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */
34
48
  export declare class BullMQExecutorModes {
35
49
  static readonly QUEUE_ONLY = "queue-only";
36
50
  static readonly WORKER_ONLY = "worker-only";
37
51
  static readonly BOTH = "both";
38
- static readonly MODE_SET: Set<string>;
39
- static isValid(value: string): boolean;
40
52
  }
41
53
  /** Values of `TMailOptions.provider`, naming the transport the mail component builds. */
42
54
  export declare class MailProviders {
@@ -51,8 +63,6 @@ export type TMailProvider = TConstValue<typeof MailProviders>;
51
63
  export declare class MailBackoffTypes {
52
64
  static readonly FIXED = "fixed";
53
65
  static readonly EXPONENTIAL = "exponential";
54
- static readonly SCHEME_SET: Set<string>;
55
- static isValid(value: string): boolean;
56
66
  }
57
67
  /** Valid mail backoff type values. */
58
68
  export type TMailBackoffType = TConstValue<typeof MailBackoffTypes>;
@@ -5,58 +5,49 @@ export class MailDefaults {
5
5
  static { this.FALLBACK_FROM = 'noreply@example.com'; }
6
6
  /** Bytes of attachment content one message may carry, all attachments together. */
7
7
  static { this.MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024; }
8
+ /** The subject of a template mail that has none of its own. */
9
+ static { this.SUBJECT = 'No Subject'; }
10
+ /** Tries per queued mail, the first included, unless the job options say otherwise. */
11
+ static { this.ATTEMPTS = 3; }
12
+ static { this.BACKOFF_DELAY_MS = 1000; }
13
+ /** How long a failed BullMQ mail job stays in Redis (it holds a recipient address), and the most that stay. */
14
+ static { this.FAILED_JOB_RETENTION = { age: 7 * 24 * 60 * 60, count: 1000 }; }
8
15
  }
9
- /** Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */
16
+ /** Where a rendered template is going: `HTML` escapes every double-brace placeholder, `TEXT` (a subject, a plain-text part) inserts it as it is. A triple-brace placeholder is raw in both. */
17
+ export class MailTemplateFormats {
18
+ static { this.HTML = 'html'; }
19
+ static { this.TEXT = 'text'; }
20
+ }
21
+ /** Names of the jobs the BullMQ mail executor adds. */
22
+ export class MailQueueJobNames {
23
+ static { this.SEND_VERIFICATION_EMAIL = 'send-verification-email'; }
24
+ }
25
+ /** The codes of the server-side failures, which are not in the 4xx `MailErrors` catalog. Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */
10
26
  export class MailErrorCodes {
11
- static { this.INVALID_CONFIGURATION = MessageCode.build({
12
- parts: ['core', 'mail', 'invalid_configuration'],
13
- }); }
14
27
  static { this.SEND_FAILED = MessageCode.build({ parts: ['core', 'mail', 'send_failed'] }); }
15
28
  static { this.VERIFICATION_FAILED = MessageCode.build({
16
29
  parts: ['core', 'mail', 'verification_failed'],
17
30
  }); }
18
- static { this.INVALID_RECIPIENT = MessageCode.build({
19
- parts: ['core', 'mail', 'invalid_recipient'],
20
- }); }
21
31
  static { this.BATCH_SEND_FAILED = MessageCode.build({
22
32
  parts: ['core', 'mail', 'batch_send_failed'],
23
33
  }); }
24
- static { this.TEMPLATE_NOT_FOUND = MessageCode.build({
25
- parts: ['core', 'mail', 'template_not_found'],
26
- }); }
27
- static { this.ATTACHMENT_PATH_REFUSED = MessageCode.build({
28
- parts: ['core', 'mail', 'attachment_path_refused'],
29
- }); }
30
- static { this.ATTACHMENT_TOO_LARGE = MessageCode.build({
31
- parts: ['core', 'mail', 'attachment_too_large'],
32
- }); }
33
- static { this.BODY_SOURCE_REFUSED = MessageCode.build({
34
- parts: ['core', 'mail', 'body_source_refused'],
35
- }); }
36
34
  }
37
35
  /** Messages thrown by the mail queue executors. */
38
36
  export class MailExecutorErrors {
39
37
  static { this.PROCESSOR_NOT_SET = 'Processor not set. Call setProcessor() first.'; }
38
+ static { this.CLOSED = 'The executor is closed and takes no more jobs.'; }
40
39
  }
41
- /** Values of `IMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */
40
+ /** Values of `TMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */
42
41
  export class MailQueueExecutorTypes {
43
42
  static { this.DIRECT = 'direct'; }
44
43
  static { this.INTERNAL_QUEUE = 'internal-queue'; }
45
44
  static { this.BULLMQ = 'bullmq'; }
46
- static { this.SCHEME_SET = new Set([this.DIRECT, this.INTERNAL_QUEUE, this.BULLMQ]); }
47
- static isValid(value) {
48
- return this.SCHEME_SET.has(value);
49
- }
50
45
  }
51
46
  /** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */
52
47
  export class BullMQExecutorModes {
53
48
  static { this.QUEUE_ONLY = 'queue-only'; }
54
49
  static { this.WORKER_ONLY = 'worker-only'; }
55
50
  static { this.BOTH = 'both'; }
56
- static { this.MODE_SET = new Set([this.QUEUE_ONLY, this.WORKER_ONLY, this.BOTH]); }
57
- static isValid(value) {
58
- return this.MODE_SET.has(value);
59
- }
60
51
  }
61
52
  /** Values of `TMailOptions.provider`, naming the transport the mail component builds. */
62
53
  export class MailProviders {
@@ -70,9 +61,5 @@ export class MailProviders {
70
61
  export class MailBackoffTypes {
71
62
  static { this.FIXED = 'fixed'; }
72
63
  static { this.EXPONENTIAL = 'exponential'; }
73
- static { this.SCHEME_SET = new Set([this.FIXED, this.EXPONENTIAL]); }
74
- static isValid(value) {
75
- return this.SCHEME_SET.has(value);
76
- }
77
64
  }
78
65
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/components/mail/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,gKAAgK;AAChK,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IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAE7E,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { MessageCode } from '@venizia/ignis-helpers/core';\n\n/** Fallbacks for mail sending: the batch concurrency, the `from` address used when neither the message nor the options set one, and the attachment size cap. */\nexport class MailDefaults {\n static readonly BATCH_CONCURRENCY = 5;\n static readonly FALLBACK_FROM = 'noreply@example.com';\n /** Bytes of attachment content one message may carry, all attachments together. */\n static readonly MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024;\n}\n\n/** Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */\nexport class MailErrorCodes {\n static readonly INVALID_CONFIGURATION = MessageCode.build({\n parts: ['core', 'mail', 'invalid_configuration'],\n });\n\n static readonly SEND_FAILED = MessageCode.build({ parts: ['core', 'mail', 'send_failed'] });\n static readonly VERIFICATION_FAILED = MessageCode.build({\n parts: ['core', 'mail', 'verification_failed'],\n });\n\n static readonly INVALID_RECIPIENT = MessageCode.build({\n parts: ['core', 'mail', 'invalid_recipient'],\n });\n\n static readonly BATCH_SEND_FAILED = MessageCode.build({\n parts: ['core', 'mail', 'batch_send_failed'],\n });\n\n static readonly TEMPLATE_NOT_FOUND = MessageCode.build({\n parts: ['core', 'mail', 'template_not_found'],\n });\n\n static readonly ATTACHMENT_PATH_REFUSED = MessageCode.build({\n parts: ['core', 'mail', 'attachment_path_refused'],\n });\n\n static readonly ATTACHMENT_TOO_LARGE = MessageCode.build({\n parts: ['core', 'mail', 'attachment_too_large'],\n });\n\n static readonly BODY_SOURCE_REFUSED = MessageCode.build({\n parts: ['core', 'mail', 'body_source_refused'],\n });\n}\n\n/** Messages thrown by the mail queue executors. */\nexport class MailExecutorErrors {\n static readonly PROCESSOR_NOT_SET = 'Processor not set. Call setProcessor() first.';\n}\n\n/** Values of `IMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */\nexport class MailQueueExecutorTypes {\n static readonly DIRECT = 'direct';\n static readonly INTERNAL_QUEUE = 'internal-queue';\n static readonly BULLMQ = 'bullmq';\n\n static readonly SCHEME_SET = new Set<string>([this.DIRECT, this.INTERNAL_QUEUE, this.BULLMQ]);\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */\nexport class BullMQExecutorModes {\n static readonly QUEUE_ONLY = 'queue-only';\n static readonly WORKER_ONLY = 'worker-only';\n static readonly BOTH = 'both';\n\n static readonly MODE_SET = new Set<string>([this.QUEUE_ONLY, this.WORKER_ONLY, this.BOTH]);\n static isValid(value: string): boolean {\n return this.MODE_SET.has(value);\n }\n}\n\n/** Values of `TMailOptions.provider`, naming the transport the mail component builds. */\nexport class MailProviders {\n static readonly NODEMAILER = 'nodemailer';\n static readonly MAILGUN = 'mailgun';\n static readonly CUSTOM = 'custom';\n // Amazon SES supports both SMTP and HTTPS - this provider is the HTTPS API path; SMTP goes through NODEMAILER instead.\n static readonly AMAZON_SES = 'amazon-ses';\n}\n\n/** Union of the `MailProviders` values. */\nexport type TMailProvider = TConstValue<typeof MailProviders>;\n\n/** How the delay between two attempts to send a queued mail grows: FIXED stays the same, EXPONENTIAL doubles. */\nexport class MailBackoffTypes {\n static readonly FIXED = 'fixed';\n static readonly EXPONENTIAL = 'exponential';\n\n static readonly SCHEME_SET = new Set<string>([this.FIXED, this.EXPONENTIAL]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid mail backoff type values. */\nexport type TMailBackoffType = TConstValue<typeof MailBackoffTypes>;\n"]}
1
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,WAAM,GAAG,gDAAgD,CAAC;;AAG5E,iJAAiJ;AACjJ,MAAM,OAAO,sBAAsB;aACjB,WAAM,GAAG,QAAQ,CAAC;aAClB,mBAAc,GAAG,gBAAgB,CAAC;aAClC,WAAM,GAAG,QAAQ,CAAC;;AAGpC,qKAAqK;AACrK,MAAM,OAAO,mBAAmB;aACd,eAAU,GAAG,YAAY,CAAC;aAC1B,gBAAW,GAAG,aAAa,CAAC;aAC5B,SAAI,GAAG,MAAM,CAAC;;AAGhC,yFAAyF;AACzF,MAAM,OAAO,aAAa;aACR,eAAU,GAAG,YAAY,CAAC;aAC1B,YAAO,GAAG,SAAS,CAAC;aACpB,WAAM,GAAG,QAAQ,CAAC;IAClC,uHAAuH;aACvG,eAAU,GAAG,YAAY,CAAC;;AAM5C,iHAAiH;AACjH,MAAM,OAAO,gBAAgB;aACX,UAAK,GAAG,OAAO,CAAC;aAChB,gBAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { MessageCode } from '@venizia/ignis-helpers/core';\n\n/** Fallbacks for mail sending: the batch concurrency, the `from` address used when neither the message nor the options set one, and the attachment size cap. */\nexport class MailDefaults {\n static readonly BATCH_CONCURRENCY = 5;\n static readonly FALLBACK_FROM = 'noreply@example.com';\n /** Bytes of attachment content one message may carry, all attachments together. */\n static readonly MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024;\n /** The subject of a template mail that has none of its own. */\n static readonly SUBJECT = 'No Subject';\n /** Tries per queued mail, the first included, unless the job options say otherwise. */\n static readonly ATTEMPTS = 3;\n static readonly BACKOFF_DELAY_MS = 1000;\n /** How long a failed BullMQ mail job stays in Redis (it holds a recipient address), and the most that stay. */\n static readonly FAILED_JOB_RETENTION = { age: 7 * 24 * 60 * 60, count: 1000 };\n}\n\n/** Where a rendered template is going: `HTML` escapes every double-brace placeholder, `TEXT` (a subject, a plain-text part) inserts it as it is. A triple-brace placeholder is raw in both. */\nexport class MailTemplateFormats {\n static readonly HTML = 'html';\n static readonly TEXT = 'text';\n}\n\n/** Union of the `MailTemplateFormats` values. */\nexport type TMailTemplateFormat = TConstValue<typeof MailTemplateFormats>;\n\n/** Names of the jobs the BullMQ mail executor adds. */\nexport class MailQueueJobNames {\n static readonly SEND_VERIFICATION_EMAIL = 'send-verification-email';\n}\n\n/** The codes of the server-side failures, which are not in the 4xx `MailErrors` catalog. Built via {@link MessageCode.build}: `ApplicationError` lower-cases codes, so a SCREAMING_CASE literal would reach the client in a spelling no const here matches. */\nexport class MailErrorCodes {\n static readonly SEND_FAILED = MessageCode.build({ parts: ['core', 'mail', 'send_failed'] });\n static readonly VERIFICATION_FAILED = MessageCode.build({\n parts: ['core', 'mail', 'verification_failed'],\n });\n\n static readonly BATCH_SEND_FAILED = MessageCode.build({\n parts: ['core', 'mail', 'batch_send_failed'],\n });\n}\n\n/** Messages thrown by the mail queue executors. */\nexport class MailExecutorErrors {\n static readonly PROCESSOR_NOT_SET = 'Processor not set. Call setProcessor() first.';\n static readonly CLOSED = 'The executor is closed and takes no more jobs.';\n}\n\n/** Values of `TMailQueueExecutorConfig.type`, selecting how verification mails are queued: sent inline, held in process, or handed to BullMQ. */\nexport class MailQueueExecutorTypes {\n static readonly DIRECT = 'direct';\n static readonly INTERNAL_QUEUE = 'internal-queue';\n static readonly BULLMQ = 'bullmq';\n}\n\n/** Values of `IBullMQMailExecutorOpts.mode`: `queue-only` enqueues jobs without starting workers, `worker-only` starts workers without a queue, `both` does each. */\nexport class BullMQExecutorModes {\n static readonly QUEUE_ONLY = 'queue-only';\n static readonly WORKER_ONLY = 'worker-only';\n static readonly BOTH = 'both';\n}\n\n/** Values of `TMailOptions.provider`, naming the transport the mail component builds. */\nexport class MailProviders {\n static readonly NODEMAILER = 'nodemailer';\n static readonly MAILGUN = 'mailgun';\n static readonly CUSTOM = 'custom';\n // Amazon SES supports both SMTP and HTTPS - this provider is the HTTPS API path; SMTP goes through NODEMAILER instead.\n static readonly AMAZON_SES = 'amazon-ses';\n}\n\n/** Union of the `MailProviders` values. */\nexport type TMailProvider = TConstValue<typeof MailProviders>;\n\n/** How the delay between two attempts to send a queued mail grows: FIXED stays the same, EXPONENTIAL doubles. */\nexport class MailBackoffTypes {\n static readonly FIXED = 'fixed';\n static readonly EXPONENTIAL = 'exponential';\n}\n\n/** Valid mail backoff type values. */\nexport type TMailBackoffType = TConstValue<typeof MailBackoffTypes>;\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { TRegisterErrors } from '@venizia/ignis-helpers/core';
2
2
  /** Codes a client branches on for a mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */
3
- /** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. The values are identical to what those constants produce - they are a public contract and must not shift. */
3
+ /** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. `MailErrorCodes` holds only the codes of the server-side failures, which are not in this 4xx catalog: every code string has one home. They are a public contract and must not shift. */
4
4
  export declare const MailErrors: {
5
5
  readonly TEMPLATE_NOT_FOUND: {
6
6
  readonly message: {
@@ -43,6 +43,15 @@ export declare const MailErrors: {
43
43
  readonly statusCode: 413;
44
44
  readonly category: "validation";
45
45
  };
46
+ /** An address, the subject or a header holds a line break or another control character, or a header name is not printable ASCII: it would break out of its header line. */
47
+ readonly INVALID_HEADER: {
48
+ readonly message: {
49
+ readonly text: "Invalid mail header";
50
+ readonly code: "core.mail.invalid_header";
51
+ };
52
+ readonly statusCode: 400;
53
+ readonly category: "validation";
54
+ };
46
55
  readonly BODY_SOURCE_REFUSED: {
47
56
  readonly message: {
48
57
  readonly text: "Mail body must be text";
@@ -1,7 +1,7 @@
1
1
  import { ErrorScopes } from '@venizia/ignis-helpers/core';
2
2
  import { HTTP } from '@venizia/ignis-helpers/common';
3
3
  /** Codes a client branches on for a mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */
4
- /** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. The values are identical to what those constants produce - they are a public contract and must not shift. */
4
+ /** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. `MailErrorCodes` holds only the codes of the server-side failures, which are not in this 4xx catalog: every code string has one home. They are a public contract and must not shift. */
5
5
  export const MailErrors = {
6
6
  TEMPLATE_NOT_FOUND: {
7
7
  message: { text: 'Mail template not found', code: 'core.mail.template_not_found' },
@@ -35,6 +35,12 @@ export const MailErrors = {
35
35
  statusCode: HTTP.ResultCodes.RS_4.ContentTooLarge,
36
36
  category: ErrorScopes.VALIDATION,
37
37
  },
38
+ /** An address, the subject or a header holds a line break or another control character, or a header name is not printable ASCII: it would break out of its header line. */
39
+ INVALID_HEADER: {
40
+ message: { text: 'Invalid mail header', code: 'core.mail.invalid_header' },
41
+ statusCode: HTTP.ResultCodes.RS_4.BadRequest,
42
+ category: ErrorScopes.VALIDATION,
43
+ },
38
44
  BODY_SOURCE_REFUSED: {
39
45
  message: { text: 'Mail body must be text', code: 'core.mail.body_source_refused' },
40
46
  statusCode: HTTP.ResultCodes.RS_4.BadRequest,
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/components/mail/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,oPAAoP;AACpP,qTAAqT;AACrT,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,kBAAkB,EAAE;QAClB,OAAO,EAAE,EAAE,IAAI,EAAE,yBAAyB,EA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Scopes } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\n/** Codes a client branches on for a mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */\n/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. The values are identical to what those constants produce - they are a public contract and must not shift. */\nexport const MailErrors = {\n TEMPLATE_NOT_FOUND: {\n message: { text: 'Mail template not found', code: 'core.mail.template_not_found' },\n statusCode: HTTP.ResultCodes.RS_4.NotFound,\n category: ErrorScopes.BUSINESS,\n },\n INVALID_CONFIGURATION: {\n message: { text: 'Invalid mail configuration', code: 'core.mail.invalid_configuration' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n INVALID_RECIPIENT: {\n message: { text: 'Invalid mail recipient', code: 'core.mail.invalid_recipient' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n /** One answer for every refused source - outside the root, missing, not a file - so a caller cannot probe which files exist. */\n ATTACHMENT_PATH_REFUSED: {\n message: {\n text: 'Mail attachment path refused',\n code: 'core.mail.attachment_path_refused',\n },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n ATTACHMENT_TOO_LARGE: {\n message: {\n text: 'Mail attachments are larger than the maximum allowed',\n code: 'core.mail.attachment_too_large',\n },\n statusCode: HTTP.ResultCodes.RS_4.ContentTooLarge,\n category: ErrorScopes.VALIDATION,\n },\n BODY_SOURCE_REFUSED: {\n message: { text: 'Mail body must be text', code: 'core.mail.body_source_refused' },\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 MailErrors> {}\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/components/mail/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,oPAAoP;AACpP,gYAAgY;AAChY,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,kBAAkB,EAAE;QAClB,OAAO,EAAE,EAAE,IAAI,EAAE,yBAAyB,EAAE,IAAI,EAAE,8BAA8B,EAAE;QAClF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ;QAC1C,QAAQ,EAAE,WAAW,CAAC,QAAQ;KAC/B;IACD,qBAAqB,EAAE;QACrB,OAAO,EAAE,EAAE,IAAI,EAAE,4BAA4B,EAAE,IAAI,EAAE,iCAAiC,EAAE;QACxF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,iBAAiB,EAAE;QACjB,OAAO,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,6BAA6B,EAAE;QAChF,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,gIAAgI;IAChI,uBAAuB,EAAE;QACvB,OAAO,EAAE;YACP,IAAI,EAAE,8BAA8B;YACpC,IAAI,EAAE,mCAAmC;SAC1C;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,oBAAoB,EAAE;QACpB,OAAO,EAAE;YACP,IAAI,EAAE,sDAAsD;YAC5D,IAAI,EAAE,gCAAgC;SACvC;QACD,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe;QACjD,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,2KAA2K;IAC3K,cAAc,EAAE;QACd,OAAO,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,0BAA0B,EAAE;QAC1E,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,UAAU;KACjC;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,+BAA+B,EAAE;QAClF,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 mail request it can fix - a missing template, a message that is not sendable. Delivery failures are NOT here: they are 5xx and stay codeless, because a client cannot act on the remote provider being down. */\n/** Codes are LITERAL strings, deliberately not `MailErrorCodes.*`: `MessageCode.build()` returns `string`, which erases the literal type `TRegisterErrors` is built on and silently kills autocomplete. `MailErrorCodes` holds only the codes of the server-side failures, which are not in this 4xx catalog: every code string has one home. They are a public contract and must not shift. */\nexport const MailErrors = {\n TEMPLATE_NOT_FOUND: {\n message: { text: 'Mail template not found', code: 'core.mail.template_not_found' },\n statusCode: HTTP.ResultCodes.RS_4.NotFound,\n category: ErrorScopes.BUSINESS,\n },\n INVALID_CONFIGURATION: {\n message: { text: 'Invalid mail configuration', code: 'core.mail.invalid_configuration' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n INVALID_RECIPIENT: {\n message: { text: 'Invalid mail recipient', code: 'core.mail.invalid_recipient' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n /** One answer for every refused source - outside the root, missing, not a file - so a caller cannot probe which files exist. */\n ATTACHMENT_PATH_REFUSED: {\n message: {\n text: 'Mail attachment path refused',\n code: 'core.mail.attachment_path_refused',\n },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n ATTACHMENT_TOO_LARGE: {\n message: {\n text: 'Mail attachments are larger than the maximum allowed',\n code: 'core.mail.attachment_too_large',\n },\n statusCode: HTTP.ResultCodes.RS_4.ContentTooLarge,\n category: ErrorScopes.VALIDATION,\n },\n /** An address, the subject or a header holds a line break or another control character, or a header name is not printable ASCII: it would break out of its header line. */\n INVALID_HEADER: {\n message: { text: 'Invalid mail header', code: 'core.mail.invalid_header' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.VALIDATION,\n },\n BODY_SOURCE_REFUSED: {\n message: { text: 'Mail body must be text', code: 'core.mail.body_source_refused' },\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 MailErrors> {}\n}\n"]}
@@ -8,7 +8,7 @@ export interface IMailAttachment {
8
8
  content?: string | Buffer | Uint8Array | Readable | ReadableStream<Uint8Array>;
9
9
  encoding?: BufferEncoding;
10
10
  cid?: string;
11
- [key: string]: any;
11
+ [key: string]: unknown;
12
12
  }
13
13
  /** A mail to send. `to` needs at least one recipient, `subject` is required, and at least one of `text` or `html` must be set; `from` falls back to the options' `from` (with `fromName`). */
14
14
  export interface IMailMessage {
@@ -28,13 +28,13 @@ export interface IMailMessage {
28
28
  attachments?: IMailAttachment[];
29
29
  headers?: Record<string, string>;
30
30
  requireValidate?: boolean;
31
- [key: string]: any;
31
+ [key: string]: unknown;
32
32
  }
33
33
  /** Outcome of one send: `success` plus the provider `messageId`, or an `error` string when the send failed. */
34
34
  export interface IMailSendResult {
35
35
  success: boolean;
36
36
  messageId?: string;
37
- response?: any;
37
+ response?: unknown;
38
38
  error?: string;
39
39
  }
40
40
  /** A mail provider backend. `verify` checks the connection or credentials; `close`, when present, releases the client. */
@@ -51,7 +51,7 @@ export interface IMailService {
51
51
  }): Promise<IMailSendResult[]>;
52
52
  sendTemplate(opts: {
53
53
  templateName: string;
54
- data: Record<string, any>;
54
+ data: Record<string, unknown>;
55
55
  recipients: string | string[];
56
56
  options?: Partial<IMailMessage>;
57
57
  }): Promise<IMailSendResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/message.ts"],"names":[],"mappings":"","sourcesContent":["import type { Readable } from 'node:stream';\n\n/** One attachment on an `IMailMessage`. Give `content` or `path`; `cid` makes the part inline, referenced as `cid:<value>` from the HTML body. */\nexport interface IMailAttachment {\n filename?: string;\n contentType?: string;\n /** A file under the mail options' `attachmentRoot`; refused when no root is set. */\n path?: string;\n content?: string | Buffer | Uint8Array | Readable | ReadableStream<Uint8Array>;\n encoding?: BufferEncoding;\n cid?: string;\n [key: string]: any;\n}\n\n/** A mail to send. `to` needs at least one recipient, `subject` is required, and at least one of `text` or `html` must be set; `from` falls back to the options' `from` (with `fromName`). */\nexport interface IMailMessage {\n /**\n * Sender of this message.\n *\n * @default the mail options' `from` with `fromName`, else `MailDefaults.FALLBACK_FROM`\n */\n from?: string;\n to: string | string[];\n cc?: string | string[];\n bcc?: string | string[];\n replyTo?: string;\n subject: string;\n text?: string;\n html?: string;\n attachments?: IMailAttachment[];\n headers?: Record<string, string>;\n requireValidate?: boolean;\n [key: string]: any;\n}\n\n/** Outcome of one send: `success` plus the provider `messageId`, or an `error` string when the send failed. */\nexport interface IMailSendResult {\n success: boolean;\n messageId?: string;\n response?: any;\n error?: string;\n}\n\n/** A mail provider backend. `verify` checks the connection or credentials; `close`, when present, releases the client. */\nexport interface IMailTransport {\n send(message: IMailMessage): Promise<IMailSendResult>;\n verify(): Promise<boolean>;\n close?(): Promise<void>;\n}\n\n/** The service callers use to send mail; wraps the configured `IMailTransport`. */\nexport interface IMailService {\n send(message: IMailMessage): Promise<IMailSendResult>;\n sendBatch(\n messages: IMailMessage[],\n options?: {\n concurrency?: number;\n },\n ): Promise<IMailSendResult[]>;\n sendTemplate(opts: {\n templateName: string;\n data: Record<string, any>;\n recipients: string | string[];\n options?: Partial<IMailMessage>;\n }): Promise<IMailSendResult>;\n verify(): Promise<boolean>;\n}\n"]}
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../../../src/components/mail/common/types/message.ts"],"names":[],"mappings":"","sourcesContent":["import type { Readable } from 'node:stream';\n\n/** One attachment on an `IMailMessage`. Give `content` or `path`; `cid` makes the part inline, referenced as `cid:<value>` from the HTML body. */\nexport interface IMailAttachment {\n filename?: string;\n contentType?: string;\n /** A file under the mail options' `attachmentRoot`; refused when no root is set. */\n path?: string;\n content?: string | Buffer | Uint8Array | Readable | ReadableStream<Uint8Array>;\n encoding?: BufferEncoding;\n cid?: string;\n [key: string]: unknown;\n}\n\n/** A mail to send. `to` needs at least one recipient, `subject` is required, and at least one of `text` or `html` must be set; `from` falls back to the options' `from` (with `fromName`). */\nexport interface IMailMessage {\n /**\n * Sender of this message.\n *\n * @default the mail options' `from` with `fromName`, else `MailDefaults.FALLBACK_FROM`\n */\n from?: string;\n to: string | string[];\n cc?: string | string[];\n bcc?: string | string[];\n replyTo?: string;\n subject: string;\n text?: string;\n html?: string;\n attachments?: IMailAttachment[];\n headers?: Record<string, string>;\n requireValidate?: boolean;\n [key: string]: unknown;\n}\n\n/** Outcome of one send: `success` plus the provider `messageId`, or an `error` string when the send failed. */\nexport interface IMailSendResult {\n success: boolean;\n messageId?: string;\n response?: unknown;\n error?: string;\n}\n\n/** A mail provider backend. `verify` checks the connection or credentials; `close`, when present, releases the client. */\nexport interface IMailTransport {\n send(message: IMailMessage): Promise<IMailSendResult>;\n verify(): Promise<boolean>;\n close?(): Promise<void>;\n}\n\n/** The service callers use to send mail; wraps the configured `IMailTransport`. */\nexport interface IMailService {\n send(message: IMailMessage): Promise<IMailSendResult>;\n sendBatch(\n messages: IMailMessage[],\n options?: {\n concurrency?: number;\n },\n ): Promise<IMailSendResult[]>;\n sendTemplate(opts: {\n templateName: string;\n data: Record<string, unknown>;\n recipients: string | string[];\n options?: Partial<IMailMessage>;\n }): Promise<IMailSendResult>;\n verify(): Promise<boolean>;\n}\n"]}