@venizia/ignis 0.4.8-9 → 0.5.0-0

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 (265) hide show
  1. package/dist/esm/base/applications/base.js +5 -2
  2. package/dist/esm/base/applications/base.js.map +1 -1
  3. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +1 -1
  4. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
  5. package/dist/esm/components/api-reference/common/keys.d.ts +2 -1
  6. package/dist/esm/components/api-reference/common/keys.js +4 -1
  7. package/dist/esm/components/api-reference/common/keys.js.map +1 -1
  8. package/dist/esm/components/api-reference/common/types.d.ts +7 -4
  9. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  10. package/dist/esm/components/api-reference/component.js +8 -3
  11. package/dist/esm/components/api-reference/component.js.map +1 -1
  12. package/dist/esm/components/auth/authenticate/component.js +13 -18
  13. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  14. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
  15. package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
  16. package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
  17. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
  18. package/dist/esm/components/auth/authenticate/controllers/jwks/definitions.d.ts +2 -2
  19. package/dist/esm/components/auth/authenticate/controllers/service-certs/controller.js.map +1 -1
  20. package/dist/esm/components/auth/authenticate/controllers/service-certs/definitions.d.ts +2 -2
  21. package/dist/esm/components/auth/authenticate/services/basic/service.js +1 -1
  22. package/dist/esm/components/auth/authenticate/services/basic/service.js.map +1 -1
  23. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
  24. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +19 -2
  25. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  26. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +3 -3
  27. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +1 -1
  28. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
  29. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +3 -3
  30. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +2 -2
  31. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
  32. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +3 -3
  33. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +1 -1
  34. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
  35. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +10 -22
  36. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +16 -112
  37. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -1
  38. package/dist/esm/components/auth/authenticate/services/service/signer.service.d.ts +11 -0
  39. package/dist/esm/components/auth/authenticate/services/service/signer.service.js +18 -0
  40. package/dist/esm/components/auth/authenticate/services/service/signer.service.js.map +1 -1
  41. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +1 -1
  42. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
  43. package/dist/esm/components/auth/authenticate/strategies/basic.strategy.js.map +1 -1
  44. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
  45. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
  46. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
  47. package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
  48. package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
  49. package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
  50. package/dist/esm/components/auth/authorize/component.js.map +1 -1
  51. package/dist/esm/components/controller/grpc/common/types.d.ts +1 -1
  52. package/dist/esm/components/controller/grpc/common/types.js +4 -1
  53. package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
  54. package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
  55. package/dist/esm/components/health-check/common/keys.d.ts +4 -2
  56. package/dist/esm/components/health-check/common/keys.js +7 -2
  57. package/dist/esm/components/health-check/common/keys.js.map +1 -1
  58. package/dist/esm/components/health-check/common/types.d.ts +1 -1
  59. package/dist/esm/components/health-check/common/types.js.map +1 -1
  60. package/dist/esm/components/health-check/component.js +1 -3
  61. package/dist/esm/components/health-check/component.js.map +1 -1
  62. package/dist/esm/components/mail/common/constants.d.ts +32 -14
  63. package/dist/esm/components/mail/common/constants.js +25 -32
  64. package/dist/esm/components/mail/common/constants.js.map +1 -1
  65. package/dist/esm/components/mail/common/errors.d.ts +19 -1
  66. package/dist/esm/components/mail/common/errors.js +13 -1
  67. package/dist/esm/components/mail/common/errors.js.map +1 -1
  68. package/dist/esm/components/mail/common/keys.d.ts +14 -11
  69. package/dist/esm/components/mail/common/keys.js +34 -11
  70. package/dist/esm/components/mail/common/keys.js.map +1 -1
  71. package/dist/esm/components/mail/common/types/message.d.ts +7 -4
  72. package/dist/esm/components/mail/common/types/message.js.map +1 -1
  73. package/dist/esm/components/mail/common/types/options.d.ts +54 -10
  74. package/dist/esm/components/mail/common/types/options.js.map +1 -1
  75. package/dist/esm/components/mail/common/types/queue.d.ts +25 -12
  76. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  77. package/dist/esm/components/mail/common/types/template.d.ts +8 -4
  78. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  79. package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
  80. package/dist/esm/components/mail/common/types/verification.js.map +1 -1
  81. package/dist/esm/components/mail/component.js +11 -2
  82. package/dist/esm/components/mail/component.js.map +1 -1
  83. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +3 -1
  84. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +27 -33
  85. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  86. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
  87. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
  88. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  89. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +11 -6
  90. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  91. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
  92. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
  93. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  94. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
  95. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
  96. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  97. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
  98. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
  99. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  100. package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
  101. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  102. package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -6
  103. package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
  104. package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
  105. package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
  106. package/dist/esm/components/mail/services/generators/random-token.js +9 -6
  107. package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
  108. package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
  109. package/dist/esm/components/mail/services/mail.service.js +22 -19
  110. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  111. package/dist/esm/components/mail/services/template.service.d.ts +8 -6
  112. package/dist/esm/components/mail/services/template.service.js +34 -33
  113. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  114. package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
  115. package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
  116. package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
  117. package/dist/esm/components/mail/utilities/header.utility.js +44 -0
  118. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
  119. package/dist/esm/components/mail/utilities/index.d.ts +2 -0
  120. package/dist/esm/components/mail/utilities/index.js +2 -0
  121. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  122. package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
  123. package/dist/esm/components/mail/utilities/mime.utility.js +12 -58
  124. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  125. package/dist/esm/components/mail/utilities/template-renderer.utility.d.ts +31 -0
  126. package/dist/esm/components/mail/utilities/template-renderer.utility.js +184 -0
  127. package/dist/esm/components/mail/utilities/template-renderer.utility.js.map +1 -0
  128. package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
  129. package/dist/esm/components/mail/utilities/type.utility.js +6 -7
  130. package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
  131. package/dist/esm/components/request-tracker/component.d.ts +2 -1
  132. package/dist/esm/components/request-tracker/component.js +5 -5
  133. package/dist/esm/components/request-tracker/component.js.map +1 -1
  134. package/dist/esm/components/server-info/common/keys.d.ts +2 -1
  135. package/dist/esm/components/server-info/common/keys.js +4 -1
  136. package/dist/esm/components/server-info/common/keys.js.map +1 -1
  137. package/dist/esm/components/server-info/common/types.d.ts +1 -1
  138. package/dist/esm/components/server-info/common/types.js.map +1 -1
  139. package/dist/esm/components/server-info/component.js +1 -3
  140. package/dist/esm/components/server-info/component.js.map +1 -1
  141. package/dist/esm/components/socket-io/common/keys.d.ts +9 -6
  142. package/dist/esm/components/socket-io/common/keys.js +19 -6
  143. package/dist/esm/components/socket-io/common/keys.js.map +1 -1
  144. package/dist/esm/components/socket-io/component.js +1 -1
  145. package/dist/esm/components/socket-io/component.js.map +1 -1
  146. package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
  147. package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
  148. package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
  149. package/dist/esm/components/static-asset/common/constants.js +75 -47
  150. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  151. package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
  152. package/dist/esm/components/static-asset/common/errors.js +31 -33
  153. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  154. package/dist/esm/components/static-asset/common/index.d.ts +1 -1
  155. package/dist/esm/components/static-asset/common/index.js +1 -1
  156. package/dist/esm/components/static-asset/common/index.js.map +1 -1
  157. package/dist/esm/components/static-asset/common/keys.d.ts +14 -2
  158. package/dist/esm/components/static-asset/common/keys.js +17 -2
  159. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  160. package/dist/esm/components/static-asset/common/types.d.ts +267 -147
  161. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  162. package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
  163. package/dist/esm/components/static-asset/common/validation.js +8 -0
  164. package/dist/esm/components/static-asset/common/validation.js.map +1 -0
  165. package/dist/esm/components/static-asset/component.d.ts +4 -2
  166. package/dist/esm/components/static-asset/component.js +27 -31
  167. package/dist/esm/components/static-asset/component.js.map +1 -1
  168. package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
  169. package/dist/esm/components/static-asset/controller/factory.js +26 -917
  170. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  171. package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
  172. package/dist/esm/components/static-asset/controller/index.js +1 -0
  173. package/dist/esm/components/static-asset/controller/index.js.map +1 -1
  174. package/dist/esm/components/static-asset/controller/routes/context.d.ts +62 -0
  175. package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
  176. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
  177. package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
  178. package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
  179. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
  180. package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
  181. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
  182. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
  183. package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
  184. package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
  185. package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
  186. package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
  187. package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
  188. package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
  189. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
  190. package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
  191. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
  192. package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
  193. package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
  194. package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
  195. package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
  196. package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
  197. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
  198. package/dist/esm/components/static-asset/index.d.ts +2 -1
  199. package/dist/esm/components/static-asset/index.js +2 -1
  200. package/dist/esm/components/static-asset/index.js.map +1 -1
  201. package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
  202. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  203. package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
  204. package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
  205. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
  206. package/dist/esm/components/static-asset/services/index.d.ts +3 -0
  207. package/dist/esm/components/static-asset/services/index.js +3 -0
  208. package/dist/esm/components/static-asset/services/index.js.map +1 -0
  209. package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
  210. package/dist/esm/components/static-asset/services/policy.service.js +104 -0
  211. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
  212. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
  213. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
  214. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
  215. package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
  216. package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
  217. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
  218. package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
  219. package/dist/esm/components/static-asset/utilities/index.js +6 -0
  220. package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
  221. package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +8 -8
  222. package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +21 -23
  223. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
  224. package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
  225. package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
  226. package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
  227. package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
  228. package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
  229. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
  230. package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
  231. package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
  232. package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
  233. package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
  234. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
  235. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
  236. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +43 -0
  237. package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
  238. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
  239. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
  240. package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
  241. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
  242. package/dist/esm/components/websocket/common/keys.d.ts +12 -10
  243. package/dist/esm/components/websocket/common/keys.js +31 -10
  244. package/dist/esm/components/websocket/common/keys.js.map +1 -1
  245. package/dist/esm/components/websocket/component.js.map +1 -1
  246. package/dist/esm/testing/assert-application-boots.d.ts +2 -2
  247. package/dist/esm/testing/assert-application-boots.js +6 -2
  248. package/dist/esm/testing/assert-application-boots.js.map +1 -1
  249. package/dist/presets/app/preset.json +4 -4
  250. package/dist/presets/lib/preset.json +3 -3
  251. package/dist/presets/shared/preset.json +1 -1
  252. package/package.json +8 -8
  253. package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
  254. package/dist/esm/components/static-asset/common/commit-token.js +0 -48
  255. package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
  256. package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
  257. package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
  258. package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
  259. package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
  260. package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
  261. package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
  262. package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
  263. package/dist/esm/components/static-asset/controller/route-options.js +0 -47
  264. package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
  265. package/dist/esm/components/static-asset/ingest.js.map +0 -1
@@ -1,8 +1,7 @@
1
- import { HTTP } from '@venizia/ignis-helpers/common';
2
- import { getError } from '@venizia/ignis-helpers/core';
3
- import { MailErrorCodes } from '../common/index.js';
1
+ import { TokenUidHelper, UidTokenEncodings } from '@venizia/ignis-helpers/core';
4
2
  import { MailAddressUtility } from './address.utility.js';
5
3
  import { MailAttachmentUtility } from './attachment.utility.js';
4
+ import { MailHeaderUtility } from './header.utility.js';
6
5
  const CRLF = '\r\n';
7
6
  const BASE64_LINE_LENGTH = 76;
8
7
  /** RFC 5322 recommends folding well under its own 998-byte hard limit; 78 matches common MTA
@@ -17,9 +16,9 @@ const MAX_HEADER_LINE_LENGTH = 78;
17
16
  const MAX_HEADER_HARD_LIMIT = 990;
18
17
  /** RFC 2047 caps one encoded-word (`=?charset?B?...?=` included) at 75 characters. */
19
18
  const ENCODED_WORD_MAX_LENGTH = 75;
20
- /** `bytes` random bytes as lowercase hex, from the platform CSPRNG. */
19
+ /** `bytes` random bytes as lowercase hex, from the platform CSPRNG. `bytes` is at least 16, the floor of `TokenUidHelper`. */
21
20
  function generateRandomHex(opts) {
22
- return Buffer.from(crypto.getRandomValues(new Uint8Array(opts.bytes))).toString('hex');
21
+ return new TokenUidHelper({ bytes: opts.bytes, encoding: UidTokenEncodings.HEX }).nextId();
23
22
  }
24
23
  function isAscii(value) {
25
24
  for (let index = 0; index < value.length; index++) {
@@ -147,43 +146,6 @@ function encodeTextBase64(text) {
147
146
  function encodeBufferBase64(buffer) {
148
147
  return foldBase64(buffer.toString('base64'));
149
148
  }
150
- /** A literal CR/LF/NUL inside a header-bound value would let it break out of its own header line and forge additional headers or smuggle body content - classic email header injection. Every value spliced into a raw header line is checked here first, so an attempt fails loudly instead of silently reaching the wire.
151
- *
152
- * `value` is `unknown`, not `string`: `IMailMessage`/`IMailAttachment` both end in
153
- * `[key: string]: any`, so nothing at the type layer stops a caller (e.g. a controller
154
- * forwarding a request body) from putting a non-string - notably an array - where a string is
155
- * declared. `Array.prototype.includes('\r')` checks element *equality*, not substring, so
156
- * `['x\r\nBcc: evil'].includes('\r')` is `false` and a naive string-only check would wave a
157
- * forged header straight through once it is later stringified by a template literal. Requiring
158
- * `typeof value === 'string'` up front closes that gap for every field that flows through here. */
159
- function assertNoHeaderInjection(opts) {
160
- const { field, value } = opts;
161
- if (typeof value !== 'string') {
162
- throw getError({
163
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
164
- messageCode: MailErrorCodes.INVALID_CONFIGURATION,
165
- message: `Invalid Amazon SES message | ${field} must be a string`,
166
- });
167
- }
168
- if (!value.includes('\r') && !value.includes('\n') && !value.includes('\0')) {
169
- return;
170
- }
171
- throw getError({
172
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
173
- messageCode: MailErrorCodes.INVALID_CONFIGURATION,
174
- message: `Invalid Amazon SES message | ${field} contains illegal control characters`,
175
- });
176
- }
177
- /** Same guard as {@link assertNoHeaderInjection}, applied to every address in a `to`/`cc`/`bcc`
178
- * field individually - a string field only, not `[key: string]: any`; validating the raw
179
- * caller-provided value (before splitting/joining) both types and content-checks each entry. */
180
- function assertNoAddressListInjection(opts) {
181
- const { field, value } = opts;
182
- const list = Array.isArray(value) ? value : [value];
183
- for (const item of list) {
184
- assertNoHeaderInjection({ field, value: item });
185
- }
186
- }
187
149
  function extractDomain(address) {
188
150
  const match = address ? /@([^@>\s]+)>?\s*$/.exec(address) : null;
189
151
  return match ? match[1] : 'localhost';
@@ -191,27 +153,17 @@ function extractDomain(address) {
191
153
  function buildHeaders(message) {
192
154
  const headers = [];
193
155
  if (message.from) {
194
- assertNoAddressListInjection({ field: 'from', value: message.from });
195
156
  headers.push(foldHeaderLine(`From: ${formatAddressList(message.from)}`));
196
157
  }
197
158
  if (message.to) {
198
- assertNoAddressListInjection({ field: 'to', value: message.to });
199
159
  headers.push(foldHeaderLine(`To: ${formatAddressList(message.to)}`));
200
160
  }
201
161
  if (message.cc) {
202
- assertNoAddressListInjection({ field: 'cc', value: message.cc });
203
162
  headers.push(foldHeaderLine(`Cc: ${formatAddressList(message.cc)}`));
204
163
  }
205
164
  if (message.replyTo) {
206
- assertNoAddressListInjection({ field: 'replyTo', value: message.replyTo });
207
165
  headers.push(foldHeaderLine(`Reply-To: ${formatAddressList(message.replyTo)}`));
208
166
  }
209
- // Checked, never emitted: a `Bcc:` header would disclose the blind recipients, so they travel as
210
- // `Destination.BccAddresses`. Without this, `bcc` is the one address field that fails at AWS.
211
- if (message.bcc) {
212
- assertNoAddressListInjection({ field: 'bcc', value: message.bcc });
213
- }
214
- assertNoHeaderInjection({ field: 'subject', value: message.subject });
215
167
  headers.push(foldHeaderLine(`Subject: ${encodeHeaderValue(message.subject)}`));
216
168
  // RFC 5322 requires both on every message; SES's raw-message parser does not synthesize them,
217
169
  // so an omission here is an omission on the wire (some receiving MTAs reject a `Date`-less
@@ -222,8 +174,6 @@ function buildHeaders(message) {
222
174
  if (message.headers) {
223
175
  const messageHeadersEntries = Object.entries(message.headers);
224
176
  for (const [key, value] of messageHeadersEntries) {
225
- assertNoHeaderInjection({ field: `headers.${key}`, value: key });
226
- assertNoHeaderInjection({ field: `headers.${key}`, value });
227
177
  headers.push(foldHeaderLine(`${key}: ${encodeHeaderValue(value)}`));
228
178
  }
229
179
  }
@@ -265,12 +215,12 @@ async function attachmentPart(attachment, boundary) {
265
215
  // No root here: a `path` that did not go through `MailAttachmentUtility.resolve` is refused, never read.
266
216
  const content = await MailAttachmentUtility.readContent({ attachment });
267
217
  const contentType = attachment.contentType ?? 'application/octet-stream';
268
- assertNoHeaderInjection({ field: 'attachment.contentType', value: contentType });
218
+ MailHeaderUtility.assertValue({ field: 'attachment.contentType', value: contentType });
269
219
  if (attachment.filename) {
270
- assertNoHeaderInjection({ field: 'attachment.filename', value: attachment.filename });
220
+ MailHeaderUtility.assertValue({ field: 'attachment.filename', value: attachment.filename });
271
221
  }
272
222
  if (attachment.cid) {
273
- assertNoHeaderInjection({ field: 'attachment.cid', value: attachment.cid });
223
+ MailHeaderUtility.assertValue({ field: 'attachment.cid', value: attachment.cid });
274
224
  }
275
225
  const nameAttribute = attachment.filename
276
226
  ? attachmentNameParams('name', attachment.filename)
@@ -292,10 +242,14 @@ async function attachmentPart(attachment, boundary) {
292
242
  }
293
243
  /** Every boundary is generated the same way - a fixed prefix plus random hex - so no two nested multipart sections in one message can ever collide. */
294
244
  function newBoundary(label) {
295
- return `----=_${label}_${generateRandomHex({ bytes: 12 })}`;
245
+ return `----=_${label}_${generateRandomHex({ bytes: 16 })}`;
296
246
  }
297
247
  /** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */
298
248
  export class MailMimeUtility {
249
+ /** Escapes `\` and `"` so a value can sit inside a quoted string: a display name, a MIME parameter. */
250
+ static escapeQuotedString(opts) {
251
+ return escapeQuotedString(opts.value);
252
+ }
299
253
  /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a
300
254
  * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,
301
255
  * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */
@@ -1 +1 @@
1
- {"version":3,"file":"mime.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/mime.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,cAAc,EAA2C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,kBAAkB,GA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,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,4CAA4C,aAAa,GAAG,CAAC,CAAC;QAE3E,MAAM,SAAS,GAAa,EAAE,CAAC;QAE/B,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACtD,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;QAC1C,CAAC;QAED,KAAK,MAAM,UAAU,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YAChE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,CAAC;QAEvC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACjF,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { MailErrorCodes, type IMailAttachment, type IMailMessage } from '../common';\nimport { MailAddressUtility } from './address.utility';\nimport { MailAttachmentUtility } from './attachment.utility';\n\nconst CRLF = '\\r\\n';\nconst BASE64_LINE_LENGTH = 76;\n/** RFC 5322 recommends folding well under its own 998-byte hard limit; 78 matches common MTA\n * practice. This is a *soft* preferred width, not a hard requirement - {@link foldHeaderLine}\n * only forces a line break past it when a natural whitespace break point exists nearby. */\nconst MAX_HEADER_LINE_LENGTH = 78;\n/** The real hard requirement: SES rejects any raw-message physical line at or over 1000 bytes.\n * A 10-byte margin below that, and comfortably under RFC 5322's own 998-octet hard limit. Only\n * an unbroken token that would itself cross this line forces {@link foldHeaderLine}'s\n * content-altering hard-wrap fallback - below it, one long line is safer than corrupting an\n * atomic value (a single very long address, an unbroken encoded-word) by splitting it. */\nconst MAX_HEADER_HARD_LIMIT = 990;\n/** RFC 2047 caps one encoded-word (`=?charset?B?...?=` included) at 75 characters. */\nconst ENCODED_WORD_MAX_LENGTH = 75;\n\n/** `bytes` random bytes as lowercase hex, from the platform CSPRNG. */\nfunction generateRandomHex(opts: { bytes: number }): string {\n return Buffer.from(crypto.getRandomValues(new Uint8Array(opts.bytes))).toString('hex');\n}\n\nfunction isAscii(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n if (value.charCodeAt(index) > 127) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * RFC 2047 §5(3) requires each encoded-word to carry whole characters - a multi-byte UTF-8\n * sequence split across two encoded-words decodes to mojibake or invalid UTF-8 on either side of\n * the cut. `bytesPerChunk` is a fixed byte budget, not a character-aligned one, so after slicing\n * at that budget we walk the boundary back over any UTF-8 continuation bytes (`10xxxxxx`, i.e.\n * `byte & 0xC0 === 0x80`) until it lands on the leading byte of a character. `bytesPerChunk` is\n * always far larger than the longest UTF-8 sequence (4 bytes), so this walk-back can never\n * consume the whole chunk. Words are joined with a single space - the required separator between\n * adjacent encoded-words, and also a valid header-folding point.\n */\nfunction encodeWord(text: string): string {\n const prefix = '=?UTF-8?B?';\n const suffix = '?=';\n const maxPayloadChars = ENCODED_WORD_MAX_LENGTH - prefix.length - suffix.length;\n const bytesPerChunk = Math.floor(maxPayloadChars / 4) * 3;\n const bytes = Buffer.from(text, 'utf-8');\n const words: string[] = [];\n let offset = 0;\n\n while (offset < bytes.length) {\n let end = Math.min(offset + bytesPerChunk, bytes.length);\n\n while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) {\n end--;\n }\n\n const chunk = bytes.subarray(offset, end);\n words.push(`${prefix}${chunk.toString('base64')}${suffix}`);\n offset = end;\n }\n\n return words.join(' ');\n}\n\n/** Only non-ASCII values pay for RFC 2047 encoding, so a plain-English subject or custom header\n * stays byte-for-byte readable. */\nfunction encodeHeaderValue(value: string): string {\n return isAscii(value) ? value : encodeWord(value);\n}\n\n/**\n * Encodes only the *display-name* portion of `\"Name\" <addr@x.com>` (or bare `Name <addr@x.com>`).\n * The `<addr-spec>` must stay 7-bit ASCII per RFC 5321/5322 and per the SES raw-message\n * requirements - only the free-text name may become an RFC 2047 encoded-word. A bare address with\n * no display name is returned unchanged.\n */\nfunction encodeAddress(address: string): string {\n const match = /^(.*)<([^<>]+)>\\s*$/.exec(address);\n\n if (!match) {\n return address;\n }\n\n const [, rawName, addr] = match;\n const name = rawName.trim().replace(/^\"|\"$/g, '');\n\n if (name.length === 0 || isAscii(name)) {\n return rawName.trim().length > 0 ? `${rawName.trim()} <${addr}>` : `<${addr}>`;\n }\n\n return `${encodeWord(name)} <${addr}>`;\n}\n\n/** The body of `MailMimeUtility.formatAddressHeader`, callable from the header builder. */\nfunction formatAddressList(value: string | string[]): string {\n return MailAddressUtility.splitList({ value }).map(encodeAddress).join(', ');\n}\n\n/**\n * RFC 5322 §2.2.3 header folding: inserting CRLF immediately before an existing whitespace\n * character splits one logical header value across physical lines without changing its content\n * (the folded whitespace is still there, just after a line break). SES enforces a 1000-byte\n * ceiling per raw-message line; folding at {@link MAX_HEADER_LINE_LENGTH} keeps arbitrarily long\n * recipient lists, subjects, or encoded display names deliverable regardless of how many\n * addresses or how much non-ASCII text a caller supplies - purely by adding more physical\n * lines, never by dropping or truncating anything (verified: rejoining every folded line always\n * reproduces the original value exactly).\n *\n * The one value-altering fallback is deliberately gated on the *hard* limit, not the soft one:\n * an unbroken token (a single very long address, an encoded-word with no adjacent break) that\n * fits under {@link MAX_HEADER_HARD_LIMIT} is left on one long physical line rather than\n * force-broken at the soft width - forcing a break through the middle of an atomic token (an\n * email address has no internal whitespace) would insert a space that was never there,\n * corrupting it. Only a token that would itself violate the real transport limit gets the\n * content-altering hard-wrap - a case that essentially never occurs with real-world input.\n */\nfunction foldHeaderLine(line: string): string {\n const lines: string[] = [];\n let remaining = line;\n\n while (remaining.length > MAX_HEADER_LINE_LENGTH) {\n let breakAt = remaining.lastIndexOf(' ', MAX_HEADER_LINE_LENGTH);\n\n if (breakAt <= 0) {\n // No break within the soft width - look further ahead instead of forcing one through an\n // atomic token. Still bounded by the hard limit, so the physical line this produces can\n // never violate the real transport constraint.\n const nextBreak = remaining.indexOf(' ', MAX_HEADER_LINE_LENGTH);\n breakAt = nextBreak > 0 && nextBreak <= MAX_HEADER_HARD_LIMIT ? nextBreak : -1;\n }\n\n if (breakAt > 0) {\n lines.push(remaining.slice(0, breakAt));\n remaining = remaining.slice(breakAt);\n continue;\n }\n\n if (remaining.length <= MAX_HEADER_HARD_LIMIT) {\n break;\n }\n\n // Truly no natural break within the hard limit - an unbroken token that would itself\n // violate the transport line cap. This is the only path that can alter the value.\n lines.push(remaining.slice(0, MAX_HEADER_HARD_LIMIT));\n remaining = ` ${remaining.slice(MAX_HEADER_HARD_LIMIT)}`;\n }\n\n lines.push(remaining);\n\n return lines.join(CRLF);\n}\n\n/** MIME requires encoded body lines capped well under the RFC 5322 998-byte hard limit. */\nfunction foldBase64(base64: string): string {\n const lines: string[] = [];\n\n for (let index = 0; index < base64.length; index += BASE64_LINE_LENGTH) {\n lines.push(base64.slice(index, index + BASE64_LINE_LENGTH));\n }\n\n return lines.join(CRLF);\n}\n\n/** UTF-8 text (`text`/`html` bodies) must be encoded before folding - unlike {@link encodeBufferBase64}, which folds bytes that are already final. Two names instead of one so the caller can never feed raw bytes through the wrong path and silently double-encode them. */\nfunction encodeTextBase64(text: string): string {\n return foldBase64(Buffer.from(text, 'utf-8').toString('base64'));\n}\n\n/** Attachment bytes are already final binary content - only folding applies, no UTF-8 re-encode. */\nfunction encodeBufferBase64(buffer: Buffer): string {\n return foldBase64(buffer.toString('base64'));\n}\n\n/** A literal CR/LF/NUL inside a header-bound value would let it break out of its own header line and forge additional headers or smuggle body content - classic email header injection. Every value spliced into a raw header line is checked here first, so an attempt fails loudly instead of silently reaching the wire.\n *\n * `value` is `unknown`, not `string`: `IMailMessage`/`IMailAttachment` both end in\n * `[key: string]: any`, so nothing at the type layer stops a caller (e.g. a controller\n * forwarding a request body) from putting a non-string - notably an array - where a string is\n * declared. `Array.prototype.includes('\\r')` checks element *equality*, not substring, so\n * `['x\\r\\nBcc: evil'].includes('\\r')` is `false` and a naive string-only check would wave a\n * forged header straight through once it is later stringified by a template literal. Requiring\n * `typeof value === 'string'` up front closes that gap for every field that flows through here. */\nfunction assertNoHeaderInjection(opts: { field: string; value: unknown }): void {\n const { field, value } = opts;\n\n if (typeof value !== 'string') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.INVALID_CONFIGURATION,\n message: `Invalid Amazon SES message | ${field} must be a string`,\n });\n }\n\n if (!value.includes('\\r') && !value.includes('\\n') && !value.includes('\\0')) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n messageCode: MailErrorCodes.INVALID_CONFIGURATION,\n message: `Invalid Amazon SES message | ${field} contains illegal control characters`,\n });\n}\n\n/** Same guard as {@link assertNoHeaderInjection}, applied to every address in a `to`/`cc`/`bcc`\n * field individually - a string field only, not `[key: string]: any`; validating the raw\n * caller-provided value (before splitting/joining) both types and content-checks each entry. */\nfunction assertNoAddressListInjection(opts: { field: string; value: string | string[] }): void {\n const { field, value } = opts;\n const list = Array.isArray(value) ? value : [value];\n\n for (const item of list) {\n assertNoHeaderInjection({ field, value: item });\n }\n}\n\nfunction extractDomain(address: string | undefined): string {\n const match = address ? /@([^@>\\s]+)>?\\s*$/.exec(address) : null;\n\n return match ? match[1] : 'localhost';\n}\n\nfunction buildHeaders(message: IMailMessage): string[] {\n const headers: string[] = [];\n\n if (message.from) {\n assertNoAddressListInjection({ field: 'from', value: message.from });\n headers.push(foldHeaderLine(`From: ${formatAddressList(message.from)}`));\n }\n\n if (message.to) {\n assertNoAddressListInjection({ field: 'to', value: message.to });\n headers.push(foldHeaderLine(`To: ${formatAddressList(message.to)}`));\n }\n\n if (message.cc) {\n assertNoAddressListInjection({ field: 'cc', value: message.cc });\n headers.push(foldHeaderLine(`Cc: ${formatAddressList(message.cc)}`));\n }\n\n if (message.replyTo) {\n assertNoAddressListInjection({ field: 'replyTo', value: message.replyTo });\n headers.push(foldHeaderLine(`Reply-To: ${formatAddressList(message.replyTo)}`));\n }\n\n // Checked, never emitted: a `Bcc:` header would disclose the blind recipients, so they travel as\n // `Destination.BccAddresses`. Without this, `bcc` is the one address field that fails at AWS.\n if (message.bcc) {\n assertNoAddressListInjection({ field: 'bcc', value: message.bcc });\n }\n\n assertNoHeaderInjection({ field: 'subject', value: message.subject });\n headers.push(foldHeaderLine(`Subject: ${encodeHeaderValue(message.subject)}`));\n // RFC 5322 requires both on every message; SES's raw-message parser does not synthesize them,\n // so an omission here is an omission on the wire (some receiving MTAs reject a `Date`-less\n // message outright, and a missing `Message-ID` breaks threading and dedup).\n headers.push(`Date: ${new Date().toUTCString()}`);\n headers.push(`Message-ID: <${generateRandomHex({ bytes: 16 })}@${extractDomain(message.from)}>`);\n headers.push('MIME-Version: 1.0');\n\n if (message.headers) {\n const messageHeadersEntries = Object.entries(message.headers);\n\n for (const [key, value] of messageHeadersEntries) {\n assertNoHeaderInjection({ field: `headers.${key}`, value: key });\n assertNoHeaderInjection({ field: `headers.${key}`, value });\n headers.push(foldHeaderLine(`${key}: ${encodeHeaderValue(value)}`));\n }\n }\n\n return headers;\n}\n\n/** One text/plain or text/html MIME part. `boundary` omitted only for the single-part, no-attachment case, where the content type belongs on the top-level headers instead of a nested part. */\nfunction textPart(\n boundary: string,\n contentType: 'text/plain' | 'text/html',\n content: string,\n): string {\n return [\n `--${boundary}`,\n `Content-Type: ${contentType}; charset=UTF-8`,\n 'Content-Transfer-Encoding: base64',\n '',\n encodeTextBase64(content),\n ].join(CRLF);\n}\n\nfunction escapeQuotedString(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\n/** RFC 2231 percent-encoding for the `filename*=`/`name*=` extended parameter form. */\nfunction encodeRfc2231(value: string): string {\n return encodeURIComponent(value).replace(\n /[!'()*]/g,\n (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n}\n\n/**\n * Builds the `; name=\"...\"`/`; filename=\"...\"` (and, for non-ASCII names, the RFC 2231\n * `; filename*=UTF-8''...` extended form) suffix for a Content-Type/Content-Disposition line.\n * ASCII names are still quoted-string escaped - an unescaped `\"` or `\\` in a filename would\n * terminate the quoted string early and let the rest of the value merge into a sibling MIME\n * parameter, corrupting the part header for every downstream reader.\n */\nfunction attachmentNameParams(attribute: 'name' | 'filename', value: string): string {\n if (isAscii(value)) {\n return `; ${attribute}=\"${escapeQuotedString(value)}\"`;\n }\n\n const asciiFallback = value.replace(/[^\\x20-\\x7E]/g, '_');\n\n return (\n `; ${attribute}=\"${escapeQuotedString(asciiFallback)}\"` +\n `; ${attribute}*=UTF-8''${encodeRfc2231(value)}`\n );\n}\n\nasync function attachmentPart(attachment: IMailAttachment, boundary: string): Promise<string> {\n // No root here: a `path` that did not go through `MailAttachmentUtility.resolve` is refused, never read.\n const content = await MailAttachmentUtility.readContent({ attachment });\n const contentType = attachment.contentType ?? 'application/octet-stream';\n assertNoHeaderInjection({ field: 'attachment.contentType', value: contentType });\n\n if (attachment.filename) {\n assertNoHeaderInjection({ field: 'attachment.filename', value: attachment.filename });\n }\n\n if (attachment.cid) {\n assertNoHeaderInjection({ field: 'attachment.cid', value: attachment.cid });\n }\n\n const nameAttribute = attachment.filename\n ? attachmentNameParams('name', attachment.filename)\n : '';\n const filenameAttribute = attachment.filename\n ? attachmentNameParams('filename', attachment.filename)\n : '';\n const disposition = attachment.cid ? 'inline' : 'attachment';\n\n const headerLines = [\n `--${boundary}`,\n foldHeaderLine(`Content-Type: ${contentType}${nameAttribute}`),\n 'Content-Transfer-Encoding: base64',\n foldHeaderLine(`Content-Disposition: ${disposition}${filenameAttribute}`),\n ];\n\n if (attachment.cid) {\n headerLines.push(`Content-ID: <${attachment.cid}>`);\n }\n\n return [...headerLines, '', encodeBufferBase64(content)].join(CRLF);\n}\n\n/** Every boundary is generated the same way - a fixed prefix plus random hex - so no two nested multipart sections in one message can ever collide. */\nfunction newBoundary(label: string): string {\n return `----=_${label}_${generateRandomHex({ bytes: 12 })}`;\n}\n\n/** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */\nexport class MailMimeUtility {\n /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a\n * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,\n * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */\n static formatAddressHeader(opts: { value: string | string[] }): string {\n return formatAddressList(opts.value);\n }\n\n /**\n * Builds a raw RFC 822 message with zero external dependencies - Amazon SES's `SendEmailCommand`\n * `Content.Simple` shape has no attachment field, so attachments require a raw MIME body. Written\n * by hand instead of depending on `nodemailer`'s `MailComposer` so the `ses` provider never needs\n * the `nodemailer` peer installed at all.\n *\n * Inline (`cid`) attachments nest under `multipart/related` next to the body - a mail client\n * only renders `cid:` references inline when they share a `multipart/related` parent with the\n * body; under `multipart/mixed` they show up as ordinary downloadable attachments instead. Plain\n * file attachments (no `cid`) stay under `multipart/mixed`, alongside the body or the\n * `multipart/related` group when both kinds are present.\n */\n static async buildRawMessage(opts: { message: IMailMessage }): Promise<Buffer> {\n const { message } = opts;\n const headers = buildHeaders(message);\n const attachments = message.attachments ?? [];\n const inlineAttachments = attachments.filter((attachment) => Boolean(attachment.cid));\n const fileAttachments = attachments.filter((attachment) => !attachment.cid);\n const hasBothBodies = Boolean(message.text) && Boolean(message.html);\n const singleContentType = message.html ? ('text/html' as const) : ('text/plain' as const);\n const singleContent = message.html ?? message.text ?? '';\n\n const bodyPart = (boundary: string): string => {\n if (!hasBothBodies) {\n return textPart(boundary, singleContentType, singleContent);\n }\n\n const altBoundary = newBoundary('Alt');\n\n return [\n `--${boundary}`,\n `Content-Type: multipart/alternative; boundary=\"${altBoundary}\"`,\n '',\n [\n textPart(altBoundary, 'text/plain', message.text ?? ''),\n textPart(altBoundary, 'text/html', message.html ?? ''),\n `--${altBoundary}--`,\n ].join(CRLF),\n ].join(CRLF);\n };\n\n if (attachments.length === 0 && !hasBothBodies) {\n headers.push(`Content-Type: ${singleContentType}; charset=UTF-8`);\n headers.push('Content-Transfer-Encoding: base64');\n\n return Buffer.from([...headers, '', encodeTextBase64(singleContent)].join(CRLF), 'utf-8');\n }\n\n if (attachments.length === 0) {\n const boundary = newBoundary('Alt');\n headers.push(`Content-Type: multipart/alternative; boundary=\"${boundary}\"`);\n const parts = [\n textPart(boundary, 'text/plain', message.text ?? ''),\n textPart(boundary, 'text/html', message.html ?? ''),\n `--${boundary}--`,\n ];\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const buildRelatedPart = async (parentBoundary: string): Promise<string> => {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n\n return [\n `--${parentBoundary}`,\n `Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`,\n '',\n parts.join(CRLF),\n ].join(CRLF);\n };\n\n if (inlineAttachments.length > 0 && fileAttachments.length === 0) {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n headers.push(`Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`);\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const mixedBoundary = newBoundary('Mixed');\n headers.push(`Content-Type: multipart/mixed; boundary=\"${mixedBoundary}\"`);\n\n const bodyParts: string[] = [];\n\n if (inlineAttachments.length > 0) {\n const result2 = await buildRelatedPart(mixedBoundary);\n bodyParts.push(result2);\n } else {\n bodyParts.push(bodyPart(mixedBoundary));\n }\n\n for (const attachment of fileAttachments) {\n const result3 = await attachmentPart(attachment, mixedBoundary);\n bodyParts.push(result3);\n }\n\n bodyParts.push(`--${mixedBoundary}--`);\n\n return Buffer.from([...headers, '', bodyParts.join(CRLF)].join(CRLF), 'utf-8');\n }\n}\n"]}
1
+ {"version":3,"file":"mime.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/mime.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B;;2FAE2F;AAC3F,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC;;;;0FAI0F;AAC1F,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,sFAAsF;AACtF,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,8HAA8H;AAC9H,SAAS,iBAAiB,CAAC,IAAuB;IAChD,OAAO,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,iBAA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AAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACjF,CAAC;CACF","sourcesContent":["import { TokenUidHelper, UidTokenEncodings } from '@venizia/ignis-helpers/core';\nimport type { IMailAttachment, IMailMessage } from '../common';\nimport { MailAddressUtility } from './address.utility';\nimport { MailAttachmentUtility } from './attachment.utility';\nimport { MailHeaderUtility } from './header.utility';\n\nconst CRLF = '\\r\\n';\nconst BASE64_LINE_LENGTH = 76;\n/** RFC 5322 recommends folding well under its own 998-byte hard limit; 78 matches common MTA\n * practice. This is a *soft* preferred width, not a hard requirement - {@link foldHeaderLine}\n * only forces a line break past it when a natural whitespace break point exists nearby. */\nconst MAX_HEADER_LINE_LENGTH = 78;\n/** The real hard requirement: SES rejects any raw-message physical line at or over 1000 bytes.\n * A 10-byte margin below that, and comfortably under RFC 5322's own 998-octet hard limit. Only\n * an unbroken token that would itself cross this line forces {@link foldHeaderLine}'s\n * content-altering hard-wrap fallback - below it, one long line is safer than corrupting an\n * atomic value (a single very long address, an unbroken encoded-word) by splitting it. */\nconst MAX_HEADER_HARD_LIMIT = 990;\n/** RFC 2047 caps one encoded-word (`=?charset?B?...?=` included) at 75 characters. */\nconst ENCODED_WORD_MAX_LENGTH = 75;\n\n/** `bytes` random bytes as lowercase hex, from the platform CSPRNG. `bytes` is at least 16, the floor of `TokenUidHelper`. */\nfunction generateRandomHex(opts: { bytes: number }): string {\n return new TokenUidHelper({ bytes: opts.bytes, encoding: UidTokenEncodings.HEX }).nextId();\n}\n\nfunction isAscii(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n if (value.charCodeAt(index) > 127) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * RFC 2047 §5(3) requires each encoded-word to carry whole characters - a multi-byte UTF-8\n * sequence split across two encoded-words decodes to mojibake or invalid UTF-8 on either side of\n * the cut. `bytesPerChunk` is a fixed byte budget, not a character-aligned one, so after slicing\n * at that budget we walk the boundary back over any UTF-8 continuation bytes (`10xxxxxx`, i.e.\n * `byte & 0xC0 === 0x80`) until it lands on the leading byte of a character. `bytesPerChunk` is\n * always far larger than the longest UTF-8 sequence (4 bytes), so this walk-back can never\n * consume the whole chunk. Words are joined with a single space - the required separator between\n * adjacent encoded-words, and also a valid header-folding point.\n */\nfunction encodeWord(text: string): string {\n const prefix = '=?UTF-8?B?';\n const suffix = '?=';\n const maxPayloadChars = ENCODED_WORD_MAX_LENGTH - prefix.length - suffix.length;\n const bytesPerChunk = Math.floor(maxPayloadChars / 4) * 3;\n const bytes = Buffer.from(text, 'utf-8');\n const words: string[] = [];\n let offset = 0;\n\n while (offset < bytes.length) {\n let end = Math.min(offset + bytesPerChunk, bytes.length);\n\n while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) {\n end--;\n }\n\n const chunk = bytes.subarray(offset, end);\n words.push(`${prefix}${chunk.toString('base64')}${suffix}`);\n offset = end;\n }\n\n return words.join(' ');\n}\n\n/** Only non-ASCII values pay for RFC 2047 encoding, so a plain-English subject or custom header\n * stays byte-for-byte readable. */\nfunction encodeHeaderValue(value: string): string {\n return isAscii(value) ? value : encodeWord(value);\n}\n\n/**\n * Encodes only the *display-name* portion of `\"Name\" <addr@x.com>` (or bare `Name <addr@x.com>`).\n * The `<addr-spec>` must stay 7-bit ASCII per RFC 5321/5322 and per the SES raw-message\n * requirements - only the free-text name may become an RFC 2047 encoded-word. A bare address with\n * no display name is returned unchanged.\n */\nfunction encodeAddress(address: string): string {\n const match = /^(.*)<([^<>]+)>\\s*$/.exec(address);\n\n if (!match) {\n return address;\n }\n\n const [, rawName, addr] = match;\n const name = rawName.trim().replace(/^\"|\"$/g, '');\n\n if (name.length === 0 || isAscii(name)) {\n return rawName.trim().length > 0 ? `${rawName.trim()} <${addr}>` : `<${addr}>`;\n }\n\n return `${encodeWord(name)} <${addr}>`;\n}\n\n/** The body of `MailMimeUtility.formatAddressHeader`, callable from the header builder. */\nfunction formatAddressList(value: string | string[]): string {\n return MailAddressUtility.splitList({ value }).map(encodeAddress).join(', ');\n}\n\n/**\n * RFC 5322 §2.2.3 header folding: inserting CRLF immediately before an existing whitespace\n * character splits one logical header value across physical lines without changing its content\n * (the folded whitespace is still there, just after a line break). SES enforces a 1000-byte\n * ceiling per raw-message line; folding at {@link MAX_HEADER_LINE_LENGTH} keeps arbitrarily long\n * recipient lists, subjects, or encoded display names deliverable regardless of how many\n * addresses or how much non-ASCII text a caller supplies - purely by adding more physical\n * lines, never by dropping or truncating anything (verified: rejoining every folded line always\n * reproduces the original value exactly).\n *\n * The one value-altering fallback is deliberately gated on the *hard* limit, not the soft one:\n * an unbroken token (a single very long address, an encoded-word with no adjacent break) that\n * fits under {@link MAX_HEADER_HARD_LIMIT} is left on one long physical line rather than\n * force-broken at the soft width - forcing a break through the middle of an atomic token (an\n * email address has no internal whitespace) would insert a space that was never there,\n * corrupting it. Only a token that would itself violate the real transport limit gets the\n * content-altering hard-wrap - a case that essentially never occurs with real-world input.\n */\nfunction foldHeaderLine(line: string): string {\n const lines: string[] = [];\n let remaining = line;\n\n while (remaining.length > MAX_HEADER_LINE_LENGTH) {\n let breakAt = remaining.lastIndexOf(' ', MAX_HEADER_LINE_LENGTH);\n\n if (breakAt <= 0) {\n // No break within the soft width - look further ahead instead of forcing one through an\n // atomic token. Still bounded by the hard limit, so the physical line this produces can\n // never violate the real transport constraint.\n const nextBreak = remaining.indexOf(' ', MAX_HEADER_LINE_LENGTH);\n breakAt = nextBreak > 0 && nextBreak <= MAX_HEADER_HARD_LIMIT ? nextBreak : -1;\n }\n\n if (breakAt > 0) {\n lines.push(remaining.slice(0, breakAt));\n remaining = remaining.slice(breakAt);\n continue;\n }\n\n if (remaining.length <= MAX_HEADER_HARD_LIMIT) {\n break;\n }\n\n // Truly no natural break within the hard limit - an unbroken token that would itself\n // violate the transport line cap. This is the only path that can alter the value.\n lines.push(remaining.slice(0, MAX_HEADER_HARD_LIMIT));\n remaining = ` ${remaining.slice(MAX_HEADER_HARD_LIMIT)}`;\n }\n\n lines.push(remaining);\n\n return lines.join(CRLF);\n}\n\n/** MIME requires encoded body lines capped well under the RFC 5322 998-byte hard limit. */\nfunction foldBase64(base64: string): string {\n const lines: string[] = [];\n\n for (let index = 0; index < base64.length; index += BASE64_LINE_LENGTH) {\n lines.push(base64.slice(index, index + BASE64_LINE_LENGTH));\n }\n\n return lines.join(CRLF);\n}\n\n/** UTF-8 text (`text`/`html` bodies) must be encoded before folding - unlike {@link encodeBufferBase64}, which folds bytes that are already final. Two names instead of one so the caller can never feed raw bytes through the wrong path and silently double-encode them. */\nfunction encodeTextBase64(text: string): string {\n return foldBase64(Buffer.from(text, 'utf-8').toString('base64'));\n}\n\n/** Attachment bytes are already final binary content - only folding applies, no UTF-8 re-encode. */\nfunction encodeBufferBase64(buffer: Buffer): string {\n return foldBase64(buffer.toString('base64'));\n}\n\nfunction extractDomain(address: string | undefined): string {\n const match = address ? /@([^@>\\s]+)>?\\s*$/.exec(address) : null;\n\n return match ? match[1] : 'localhost';\n}\n\nfunction buildHeaders(message: IMailMessage): string[] {\n const headers: string[] = [];\n\n if (message.from) {\n headers.push(foldHeaderLine(`From: ${formatAddressList(message.from)}`));\n }\n\n if (message.to) {\n headers.push(foldHeaderLine(`To: ${formatAddressList(message.to)}`));\n }\n\n if (message.cc) {\n headers.push(foldHeaderLine(`Cc: ${formatAddressList(message.cc)}`));\n }\n\n if (message.replyTo) {\n headers.push(foldHeaderLine(`Reply-To: ${formatAddressList(message.replyTo)}`));\n }\n\n headers.push(foldHeaderLine(`Subject: ${encodeHeaderValue(message.subject)}`));\n // RFC 5322 requires both on every message; SES's raw-message parser does not synthesize them,\n // so an omission here is an omission on the wire (some receiving MTAs reject a `Date`-less\n // message outright, and a missing `Message-ID` breaks threading and dedup).\n headers.push(`Date: ${new Date().toUTCString()}`);\n headers.push(`Message-ID: <${generateRandomHex({ bytes: 16 })}@${extractDomain(message.from)}>`);\n headers.push('MIME-Version: 1.0');\n\n if (message.headers) {\n const messageHeadersEntries = Object.entries(message.headers);\n\n for (const [key, value] of messageHeadersEntries) {\n headers.push(foldHeaderLine(`${key}: ${encodeHeaderValue(value)}`));\n }\n }\n\n return headers;\n}\n\n/** One text/plain or text/html MIME part. `boundary` omitted only for the single-part, no-attachment case, where the content type belongs on the top-level headers instead of a nested part. */\nfunction textPart(\n boundary: string,\n contentType: 'text/plain' | 'text/html',\n content: string,\n): string {\n return [\n `--${boundary}`,\n `Content-Type: ${contentType}; charset=UTF-8`,\n 'Content-Transfer-Encoding: base64',\n '',\n encodeTextBase64(content),\n ].join(CRLF);\n}\n\nfunction escapeQuotedString(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\n/** RFC 2231 percent-encoding for the `filename*=`/`name*=` extended parameter form. */\nfunction encodeRfc2231(value: string): string {\n return encodeURIComponent(value).replace(\n /[!'()*]/g,\n (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n}\n\n/**\n * Builds the `; name=\"...\"`/`; filename=\"...\"` (and, for non-ASCII names, the RFC 2231\n * `; filename*=UTF-8''...` extended form) suffix for a Content-Type/Content-Disposition line.\n * ASCII names are still quoted-string escaped - an unescaped `\"` or `\\` in a filename would\n * terminate the quoted string early and let the rest of the value merge into a sibling MIME\n * parameter, corrupting the part header for every downstream reader.\n */\nfunction attachmentNameParams(attribute: 'name' | 'filename', value: string): string {\n if (isAscii(value)) {\n return `; ${attribute}=\"${escapeQuotedString(value)}\"`;\n }\n\n const asciiFallback = value.replace(/[^\\x20-\\x7E]/g, '_');\n\n return (\n `; ${attribute}=\"${escapeQuotedString(asciiFallback)}\"` +\n `; ${attribute}*=UTF-8''${encodeRfc2231(value)}`\n );\n}\n\nasync function attachmentPart(attachment: IMailAttachment, boundary: string): Promise<string> {\n // No root here: a `path` that did not go through `MailAttachmentUtility.resolve` is refused, never read.\n const content = await MailAttachmentUtility.readContent({ attachment });\n const contentType = attachment.contentType ?? 'application/octet-stream';\n MailHeaderUtility.assertValue({ field: 'attachment.contentType', value: contentType });\n\n if (attachment.filename) {\n MailHeaderUtility.assertValue({ field: 'attachment.filename', value: attachment.filename });\n }\n\n if (attachment.cid) {\n MailHeaderUtility.assertValue({ field: 'attachment.cid', value: attachment.cid });\n }\n\n const nameAttribute = attachment.filename\n ? attachmentNameParams('name', attachment.filename)\n : '';\n const filenameAttribute = attachment.filename\n ? attachmentNameParams('filename', attachment.filename)\n : '';\n const disposition = attachment.cid ? 'inline' : 'attachment';\n\n const headerLines = [\n `--${boundary}`,\n foldHeaderLine(`Content-Type: ${contentType}${nameAttribute}`),\n 'Content-Transfer-Encoding: base64',\n foldHeaderLine(`Content-Disposition: ${disposition}${filenameAttribute}`),\n ];\n\n if (attachment.cid) {\n headerLines.push(`Content-ID: <${attachment.cid}>`);\n }\n\n return [...headerLines, '', encodeBufferBase64(content)].join(CRLF);\n}\n\n/** Every boundary is generated the same way - a fixed prefix plus random hex - so no two nested multipart sections in one message can ever collide. */\nfunction newBoundary(label: string): string {\n return `----=_${label}_${generateRandomHex({ bytes: 16 })}`;\n}\n\n/** Builds the MIME pieces the Amazon SES transport sends: the raw message and RFC 5322 address headers. */\nexport class MailMimeUtility {\n /** Escapes `\\` and `\"` so a value can sit inside a quoted string: a display name, a MIME parameter. */\n static escapeQuotedString(opts: { value: string }): string {\n return escapeQuotedString(opts.value);\n }\n\n /** Formats a `to`/`cc`/`from`/`replyTo` field as one RFC 5322 address list: splits a\n * comma-separated string or array into individual mailboxes, RFC 2047-encodes each display name,\n * and rejoins with `, ` - the same shape whether the caller passed a string or an array. */\n static formatAddressHeader(opts: { value: string | string[] }): string {\n return formatAddressList(opts.value);\n }\n\n /**\n * Builds a raw RFC 822 message with zero external dependencies - Amazon SES's `SendEmailCommand`\n * `Content.Simple` shape has no attachment field, so attachments require a raw MIME body. Written\n * by hand instead of depending on `nodemailer`'s `MailComposer` so the `ses` provider never needs\n * the `nodemailer` peer installed at all.\n *\n * Inline (`cid`) attachments nest under `multipart/related` next to the body - a mail client\n * only renders `cid:` references inline when they share a `multipart/related` parent with the\n * body; under `multipart/mixed` they show up as ordinary downloadable attachments instead. Plain\n * file attachments (no `cid`) stay under `multipart/mixed`, alongside the body or the\n * `multipart/related` group when both kinds are present.\n */\n static async buildRawMessage(opts: { message: IMailMessage }): Promise<Buffer> {\n const { message } = opts;\n const headers = buildHeaders(message);\n const attachments = message.attachments ?? [];\n const inlineAttachments = attachments.filter((attachment) => Boolean(attachment.cid));\n const fileAttachments = attachments.filter((attachment) => !attachment.cid);\n const hasBothBodies = Boolean(message.text) && Boolean(message.html);\n const singleContentType = message.html ? ('text/html' as const) : ('text/plain' as const);\n const singleContent = message.html ?? message.text ?? '';\n\n const bodyPart = (boundary: string): string => {\n if (!hasBothBodies) {\n return textPart(boundary, singleContentType, singleContent);\n }\n\n const altBoundary = newBoundary('Alt');\n\n return [\n `--${boundary}`,\n `Content-Type: multipart/alternative; boundary=\"${altBoundary}\"`,\n '',\n [\n textPart(altBoundary, 'text/plain', message.text ?? ''),\n textPart(altBoundary, 'text/html', message.html ?? ''),\n `--${altBoundary}--`,\n ].join(CRLF),\n ].join(CRLF);\n };\n\n if (attachments.length === 0 && !hasBothBodies) {\n headers.push(`Content-Type: ${singleContentType}; charset=UTF-8`);\n headers.push('Content-Transfer-Encoding: base64');\n\n return Buffer.from([...headers, '', encodeTextBase64(singleContent)].join(CRLF), 'utf-8');\n }\n\n if (attachments.length === 0) {\n const boundary = newBoundary('Alt');\n headers.push(`Content-Type: multipart/alternative; boundary=\"${boundary}\"`);\n const parts = [\n textPart(boundary, 'text/plain', message.text ?? ''),\n textPart(boundary, 'text/html', message.html ?? ''),\n `--${boundary}--`,\n ];\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const buildRelatedPart = async (parentBoundary: string): Promise<string> => {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n\n return [\n `--${parentBoundary}`,\n `Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`,\n '',\n parts.join(CRLF),\n ].join(CRLF);\n };\n\n if (inlineAttachments.length > 0 && fileAttachments.length === 0) {\n const relatedBoundary = newBoundary('Related');\n const parts = [bodyPart(relatedBoundary)];\n\n for (const attachment of inlineAttachments) {\n const result = await attachmentPart(attachment, relatedBoundary);\n parts.push(result);\n }\n\n parts.push(`--${relatedBoundary}--`);\n headers.push(`Content-Type: multipart/related; boundary=\"${relatedBoundary}\"`);\n\n return Buffer.from([...headers, '', parts.join(CRLF)].join(CRLF), 'utf-8');\n }\n\n const mixedBoundary = newBoundary('Mixed');\n headers.push(`Content-Type: multipart/mixed; boundary=\"${mixedBoundary}\"`);\n\n const bodyParts: string[] = [];\n\n if (inlineAttachments.length > 0) {\n const result2 = await buildRelatedPart(mixedBoundary);\n bodyParts.push(result2);\n } else {\n bodyParts.push(bodyPart(mixedBoundary));\n }\n\n for (const attachment of fileAttachments) {\n const result3 = await attachmentPart(attachment, mixedBoundary);\n bodyParts.push(result3);\n }\n\n bodyParts.push(`--${mixedBoundary}--`);\n\n return Buffer.from([...headers, '', bodyParts.join(CRLF)].join(CRLF), 'utf-8');\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { TMailTemplateFormat, TMailTemplateMissing } from '../common/index.js';
2
+ /** Renders placeholders (escaped, raw and dotted) and sections (a list, a flag, its inverse): no partial, no lambda, no delimiter change, no code. */
3
+ export declare class MailTemplateRenderer {
4
+ private static invalid;
5
+ /** Splits a template into text, values and sections; a closing tag that does not match, a section left open and a tag this renderer does not have throw. */
6
+ private static parse;
7
+ /** The keys a template reads outside any section, and the keys of its sections (a section body reads the item first, so its keys are not the data's to check). */
8
+ static readKeys(opts: {
9
+ template: string;
10
+ }): {
11
+ valueKeys: string[];
12
+ sectionKeys: string[];
13
+ };
14
+ /** Own properties only, so a key such as `constructor` or `__proto__.x` never reaches the prototype chain. The first segment picks the innermost scope that has it. */
15
+ private static lookup;
16
+ /** The value of `key` in `data` (own properties only), or `undefined`. */
17
+ static read(opts: {
18
+ data: Record<string, unknown>;
19
+ key: string;
20
+ }): unknown;
21
+ static render(opts: {
22
+ template: string;
23
+ data: Record<string, unknown>;
24
+ format?: TMailTemplateFormat;
25
+ missing?: TMailTemplateMissing;
26
+ /** Called with the key of every placeholder that rendered empty because the data had no value (never the value). */
27
+ onEmpty?: (key: string) => void;
28
+ }): string;
29
+ private static renderNodes;
30
+ }
31
+ //# sourceMappingURL=template-renderer.utility.d.ts.map
@@ -0,0 +1,184 @@
1
+ import { getError } from '@venizia/ignis-helpers/core';
2
+ import { MailErrors, MailTemplateFormats, MailTemplateMissingModes } from '../common/index.js';
3
+ /**
4
+ * One tag: `{{{key}}}` (group 1), or a placeholder or a section tag (group 2 the sigil `#`, `^` or `/`, group 3 the key; a lone `.` is the current
5
+ * item). The last form only finds the start of a Mustache partial, comment, delimiter change or `&` tag: those are refused. Any other `{{` stays as written.
6
+ */
7
+ const TAG = /\{\{\{\s*([\w.]+)\s*\}\}\}|\{\{\s*(?:([#^/])\s*)?([\w.]+)\s*\}\}|\{\{\s*[>=!&<]/g;
8
+ /** How many sections may be open at once: deeper than any real template, and a bound on the scope stack. */
9
+ const MAX_DEPTH = 64;
10
+ /** Renders placeholders (escaped, raw and dotted) and sections (a list, a flag, its inverse): no partial, no lambda, no delimiter change, no code. */
11
+ export class MailTemplateRenderer {
12
+ static invalid(opts) {
13
+ return getError({ error: MailErrors.TEMPLATE_INVALID, message: opts.message });
14
+ }
15
+ /** Splits a template into text, values and sections; a closing tag that does not match, a section left open and a tag this renderer does not have throw. */
16
+ static parse(opts) {
17
+ const { template } = opts;
18
+ const root = [];
19
+ const open = [];
20
+ let current = root;
21
+ let cursor = 0;
22
+ for (const match of template.matchAll(TAG)) {
23
+ const [source, rawKey, sigil, key] = match;
24
+ current.push({ type: 'text', text: template.slice(cursor, match.index) });
25
+ cursor = match.index + source.length;
26
+ if (rawKey === undefined && key === undefined) {
27
+ throw MailTemplateRenderer.invalid({ message: `Unsupported template tag: ${source}` });
28
+ }
29
+ if (sigil === '#' || sigil === '^') {
30
+ if (open.length >= MAX_DEPTH) {
31
+ throw MailTemplateRenderer.invalid({
32
+ message: `Template nests sections deeper than ${MAX_DEPTH}`,
33
+ });
34
+ }
35
+ const children = [];
36
+ current.push({ type: 'section', key, isInverted: sigil === '^', children });
37
+ open.push({ key, parent: current });
38
+ current = children;
39
+ }
40
+ else if (sigil === '/') {
41
+ const closing = open.pop();
42
+ if (closing?.key !== key) {
43
+ throw MailTemplateRenderer.invalid({
44
+ message: `Template closes {{/${key}}} but ${closing ? `{{#${closing.key}}} is open` : 'no section is open'}`,
45
+ });
46
+ }
47
+ current = closing.parent;
48
+ }
49
+ else {
50
+ current.push({ type: 'value', key: rawKey ?? key, isRaw: rawKey !== undefined, source });
51
+ }
52
+ }
53
+ if (open.length > 0) {
54
+ throw MailTemplateRenderer.invalid({
55
+ message: `Template leaves {{#${open[open.length - 1].key}}} open`,
56
+ });
57
+ }
58
+ current.push({ type: 'text', text: template.slice(cursor) });
59
+ return root;
60
+ }
61
+ /** The keys a template reads outside any section, and the keys of its sections (a section body reads the item first, so its keys are not the data's to check). */
62
+ static readKeys(opts) {
63
+ const valueKeys = [];
64
+ const sectionKeys = [];
65
+ const visit = (nodes, isTopLevel) => {
66
+ for (const node of nodes) {
67
+ if (node.type === 'value' &&
68
+ isTopLevel &&
69
+ node.key !== '.' &&
70
+ !valueKeys.includes(node.key)) {
71
+ valueKeys.push(node.key);
72
+ }
73
+ if (node.type === 'section') {
74
+ if (!sectionKeys.includes(node.key)) {
75
+ sectionKeys.push(node.key);
76
+ }
77
+ visit(node.children, false);
78
+ }
79
+ }
80
+ };
81
+ visit(MailTemplateRenderer.parse(opts), true);
82
+ return { valueKeys, sectionKeys };
83
+ }
84
+ /** Own properties only, so a key such as `constructor` or `__proto__.x` never reaches the prototype chain. The first segment picks the innermost scope that has it. */
85
+ static lookup(opts) {
86
+ const { scopes, key } = opts;
87
+ if (key === '.') {
88
+ return scopes[scopes.length - 1];
89
+ }
90
+ const [head, ...rest] = key.split('.');
91
+ let start;
92
+ for (let index = scopes.length - 1; index >= 0; index -= 1) {
93
+ const scope = scopes[index];
94
+ if (scope !== null && typeof scope === 'object' && Object.hasOwn(scope, head)) {
95
+ start = Reflect.get(scope, head);
96
+ break;
97
+ }
98
+ }
99
+ return rest.reduce((current, segment) => current !== null && typeof current === 'object' && Object.hasOwn(current, segment)
100
+ ? Reflect.get(current, segment)
101
+ : undefined, start);
102
+ }
103
+ /** The value of `key` in `data` (own properties only), or `undefined`. */
104
+ static read(opts) {
105
+ return MailTemplateRenderer.lookup({ scopes: [opts.data], key: opts.key });
106
+ }
107
+ static render(opts) {
108
+ const { template, data, format = MailTemplateFormats.HTML, missing = MailTemplateMissingModes.EMPTY, onEmpty, } = opts;
109
+ return MailTemplateRenderer.renderNodes({
110
+ nodes: MailTemplateRenderer.parse({ template }),
111
+ scopes: [data],
112
+ isHtml: format === MailTemplateFormats.HTML,
113
+ missing,
114
+ onEmpty,
115
+ });
116
+ }
117
+ static renderNodes(opts) {
118
+ const { nodes, scopes, isHtml, missing, onEmpty } = opts;
119
+ let out = '';
120
+ for (const node of nodes) {
121
+ if (node.type === 'text') {
122
+ out += node.text;
123
+ continue;
124
+ }
125
+ const value = MailTemplateRenderer.lookup({ scopes, key: node.key });
126
+ if (typeof value === 'function') {
127
+ throw MailTemplateRenderer.invalid({
128
+ message: `Template value is a function: ${node.key}`,
129
+ });
130
+ }
131
+ if (node.type === 'section') {
132
+ const isEmpty = !value || (Array.isArray(value) && value.length === 0);
133
+ if (node.isInverted) {
134
+ out += isEmpty
135
+ ? MailTemplateRenderer.renderNodes({
136
+ nodes: node.children,
137
+ scopes,
138
+ isHtml,
139
+ missing,
140
+ onEmpty,
141
+ })
142
+ : '';
143
+ }
144
+ else if (!isEmpty) {
145
+ // A list repeats per item, anything else truthy renders once; `{{.}}` is the item, and its keys come before the outer ones.
146
+ for (const item of Array.isArray(value) ? value : [value]) {
147
+ out += MailTemplateRenderer.renderNodes({
148
+ nodes: node.children,
149
+ scopes: [...scopes, item],
150
+ isHtml,
151
+ missing,
152
+ onEmpty,
153
+ });
154
+ }
155
+ }
156
+ continue;
157
+ }
158
+ if (value === undefined || value === null) {
159
+ if (missing === MailTemplateMissingModes.THROW) {
160
+ throw getError({
161
+ error: MailErrors.INVALID_CONFIGURATION,
162
+ message: `Missing template data for keys: ${node.key}`,
163
+ });
164
+ }
165
+ if (missing === MailTemplateMissingModes.KEEP) {
166
+ out += node.source;
167
+ }
168
+ else {
169
+ onEmpty?.(node.key);
170
+ }
171
+ continue;
172
+ }
173
+ if (typeof value === 'object') {
174
+ throw MailTemplateRenderer.invalid({
175
+ message: `Template value is an object or a list, not text: ${node.key} | resolve it (a locale, a date) before rendering`,
176
+ });
177
+ }
178
+ // `{{{key}}}` inserts as it is; `{{key}}` is escaped for HTML.
179
+ out += isHtml && !node.isRaw ? Bun.escapeHTML(String(value)) : String(value);
180
+ }
181
+ return out;
182
+ }
183
+ }
184
+ //# sourceMappingURL=template-renderer.utility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-renderer.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/template-renderer.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAGtF;;;GAGG;AACH,MAAM,GAAG,GAAG,kFAAkF,CAAC;AAE/F,4GAA4G;AAC5G,MAAM,SAAS,GAAG,EAAE,CAAC;AAOrB,sJAAsJ;AACtJ,MAAM,OAAO,oBAAoB;IACvB,MAAM,CAAC,OAAO,CAAC,IAAyB;QAC9C,OAAO,QAAQ,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,gBAAgB,EAAE,OAAO,EAA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AC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport { MailErrors, MailTemplateFormats, MailTemplateMissingModes } from '../common';\nimport type { TMailTemplateFormat, TMailTemplateMissing } from '../common';\n\n/**\n * One tag: `{{{key}}}` (group 1), or a placeholder or a section tag (group 2 the sigil `#`, `^` or `/`, group 3 the key; a lone `.` is the current\n * item). The last form only finds the start of a Mustache partial, comment, delimiter change or `&` tag: those are refused. Any other `{{` stays as written.\n */\nconst TAG = /\\{\\{\\{\\s*([\\w.]+)\\s*\\}\\}\\}|\\{\\{\\s*(?:([#^/])\\s*)?([\\w.]+)\\s*\\}\\}|\\{\\{\\s*[>=!&<]/g;\n\n/** How many sections may be open at once: deeper than any real template, and a bound on the scope stack. */\nconst MAX_DEPTH = 64;\n\ntype TNode =\n | { type: 'text'; text: string }\n | { type: 'value'; key: string; isRaw: boolean; source: string }\n | { type: 'section'; key: string; isInverted: boolean; children: TNode[] };\n\n/** Renders placeholders (escaped, raw and dotted) and sections (a list, a flag, its inverse): no partial, no lambda, no delimiter change, no code. */\nexport class MailTemplateRenderer {\n private static invalid(opts: { message: string }) {\n return getError({ error: MailErrors.TEMPLATE_INVALID, message: opts.message });\n }\n\n /** Splits a template into text, values and sections; a closing tag that does not match, a section left open and a tag this renderer does not have throw. */\n private static parse(opts: { template: string }): TNode[] {\n const { template } = opts;\n const root: TNode[] = [];\n const open: Array<{ key: string; parent: TNode[] }> = [];\n let current = root;\n let cursor = 0;\n\n for (const match of template.matchAll(TAG)) {\n const [source, rawKey, sigil, key] = match;\n\n current.push({ type: 'text', text: template.slice(cursor, match.index) });\n cursor = match.index + source.length;\n\n if (rawKey === undefined && key === undefined) {\n throw MailTemplateRenderer.invalid({ message: `Unsupported template tag: ${source}` });\n }\n\n if (sigil === '#' || sigil === '^') {\n if (open.length >= MAX_DEPTH) {\n throw MailTemplateRenderer.invalid({\n message: `Template nests sections deeper than ${MAX_DEPTH}`,\n });\n }\n\n const children: TNode[] = [];\n\n current.push({ type: 'section', key, isInverted: sigil === '^', children });\n open.push({ key, parent: current });\n current = children;\n } else if (sigil === '/') {\n const closing = open.pop();\n\n if (closing?.key !== key) {\n throw MailTemplateRenderer.invalid({\n message: `Template closes {{/${key}}} but ${closing ? `{{#${closing.key}}} is open` : 'no section is open'}`,\n });\n }\n\n current = closing.parent;\n } else {\n current.push({ type: 'value', key: rawKey ?? key, isRaw: rawKey !== undefined, source });\n }\n }\n\n if (open.length > 0) {\n throw MailTemplateRenderer.invalid({\n message: `Template leaves {{#${open[open.length - 1].key}}} open`,\n });\n }\n\n current.push({ type: 'text', text: template.slice(cursor) });\n\n return root;\n }\n\n /** The keys a template reads outside any section, and the keys of its sections (a section body reads the item first, so its keys are not the data's to check). */\n static readKeys(opts: { template: string }): { valueKeys: string[]; sectionKeys: string[] } {\n const valueKeys: string[] = [];\n const sectionKeys: string[] = [];\n\n const visit = (nodes: TNode[], isTopLevel: boolean) => {\n for (const node of nodes) {\n if (\n node.type === 'value' &&\n isTopLevel &&\n node.key !== '.' &&\n !valueKeys.includes(node.key)\n ) {\n valueKeys.push(node.key);\n }\n\n if (node.type === 'section') {\n if (!sectionKeys.includes(node.key)) {\n sectionKeys.push(node.key);\n }\n\n visit(node.children, false);\n }\n }\n };\n\n visit(MailTemplateRenderer.parse(opts), true);\n\n return { valueKeys, sectionKeys };\n }\n\n /** Own properties only, so a key such as `constructor` or `__proto__.x` never reaches the prototype chain. The first segment picks the innermost scope that has it. */\n private static lookup(opts: { scopes: unknown[]; key: string }): unknown {\n const { scopes, key } = opts;\n\n if (key === '.') {\n return scopes[scopes.length - 1];\n }\n\n const [head, ...rest] = key.split('.');\n let start: unknown;\n\n for (let index = scopes.length - 1; index >= 0; index -= 1) {\n const scope = scopes[index];\n\n if (scope !== null && typeof scope === 'object' && Object.hasOwn(scope, head)) {\n start = Reflect.get(scope, head);\n break;\n }\n }\n\n return rest.reduce<unknown>(\n (current, segment) =>\n current !== null && typeof current === 'object' && Object.hasOwn(current, segment)\n ? Reflect.get(current, segment)\n : undefined,\n start,\n );\n }\n\n /** The value of `key` in `data` (own properties only), or `undefined`. */\n static read(opts: { data: Record<string, unknown>; key: string }): unknown {\n return MailTemplateRenderer.lookup({ scopes: [opts.data], key: opts.key });\n }\n\n static render(opts: {\n template: string;\n data: Record<string, unknown>;\n format?: TMailTemplateFormat;\n missing?: TMailTemplateMissing;\n /** Called with the key of every placeholder that rendered empty because the data had no value (never the value). */\n onEmpty?: (key: string) => void;\n }): string {\n const {\n template,\n data,\n format = MailTemplateFormats.HTML,\n missing = MailTemplateMissingModes.EMPTY,\n onEmpty,\n } = opts;\n\n return MailTemplateRenderer.renderNodes({\n nodes: MailTemplateRenderer.parse({ template }),\n scopes: [data],\n isHtml: format === MailTemplateFormats.HTML,\n missing,\n onEmpty,\n });\n }\n\n private static renderNodes(opts: {\n nodes: TNode[];\n scopes: unknown[];\n isHtml: boolean;\n missing: TMailTemplateMissing;\n onEmpty?: (key: string) => void;\n }): string {\n const { nodes, scopes, isHtml, missing, onEmpty } = opts;\n let out = '';\n\n for (const node of nodes) {\n if (node.type === 'text') {\n out += node.text;\n continue;\n }\n\n const value = MailTemplateRenderer.lookup({ scopes, key: node.key });\n\n if (typeof value === 'function') {\n throw MailTemplateRenderer.invalid({\n message: `Template value is a function: ${node.key}`,\n });\n }\n\n if (node.type === 'section') {\n const isEmpty = !value || (Array.isArray(value) && value.length === 0);\n\n if (node.isInverted) {\n out += isEmpty\n ? MailTemplateRenderer.renderNodes({\n nodes: node.children,\n scopes,\n isHtml,\n missing,\n onEmpty,\n })\n : '';\n } else if (!isEmpty) {\n // A list repeats per item, anything else truthy renders once; `{{.}}` is the item, and its keys come before the outer ones.\n for (const item of Array.isArray(value) ? value : [value]) {\n out += MailTemplateRenderer.renderNodes({\n nodes: node.children,\n scopes: [...scopes, item],\n isHtml,\n missing,\n onEmpty,\n });\n }\n }\n\n continue;\n }\n\n if (value === undefined || value === null) {\n if (missing === MailTemplateMissingModes.THROW) {\n throw getError({\n error: MailErrors.INVALID_CONFIGURATION,\n message: `Missing template data for keys: ${node.key}`,\n });\n }\n\n if (missing === MailTemplateMissingModes.KEEP) {\n out += node.source;\n } else {\n onEmpty?.(node.key);\n }\n\n continue;\n }\n\n if (typeof value === 'object') {\n throw MailTemplateRenderer.invalid({\n message: `Template value is an object or a list, not text: ${node.key} | resolve it (a locale, a date) before rendering`,\n });\n }\n\n // `{{{key}}}` inserts as it is; `{{key}}` is escaped for HTML.\n out += isHtml && !node.isRaw ? Bun.escapeHTML(String(value)) : String(value);\n }\n\n return out;\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- import type { AnyType } from '@venizia/ignis-helpers/common';
2
1
  import type { IMailTransport, TMailOptions } from '../common/index.js';
3
2
  /**
4
3
  * Type guards for the mail component. Each takes its value as a positional parameter, not an options
@@ -7,8 +6,8 @@ import type { IMailTransport, TMailOptions } from '../common/index.js';
7
6
  */
8
7
  export declare class MailTypeUtility {
9
8
  /** Whether `value` is a transport: `send` and `verify` are functions, and `close` is a function or absent. */
10
- static isTransport(value: AnyType): value is IMailTransport;
9
+ static isTransport(value: unknown): value is IMailTransport;
11
10
  /** Whether `options` has a string `provider` and a truthy `config`; the shape of `config` is not checked. */
12
- static isValidOptions(options: AnyType): options is TMailOptions;
11
+ static isValidOptions(options: unknown): options is TMailOptions;
13
12
  }
14
13
  //# sourceMappingURL=type.utility.d.ts.map
@@ -9,14 +9,14 @@ export class MailTypeUtility {
9
9
  if (!value || typeof value !== 'object') {
10
10
  return false;
11
11
  }
12
- const transport = value;
13
- if (typeof transport.send !== 'function') {
12
+ if (typeof Reflect.get(value, 'send') !== 'function') {
14
13
  return false;
15
14
  }
16
- if (typeof transport.verify !== 'function') {
15
+ if (typeof Reflect.get(value, 'verify') !== 'function') {
17
16
  return false;
18
17
  }
19
- if (transport.close !== undefined && typeof transport.close !== 'function') {
18
+ const close = Reflect.get(value, 'close');
19
+ if (close !== undefined && typeof close !== 'function') {
20
20
  return false;
21
21
  }
22
22
  return true;
@@ -26,11 +26,10 @@ export class MailTypeUtility {
26
26
  if (!options || typeof options !== 'object') {
27
27
  return false;
28
28
  }
29
- const opts = options;
30
- if (typeof opts.provider !== 'string') {
29
+ if (typeof Reflect.get(options, 'provider') !== 'string') {
31
30
  return false;
32
31
  }
33
- if (!opts.config) {
32
+ if (!Reflect.get(options, 'config')) {
34
33
  return false;
35
34
  }
36
35
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"type.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/type.utility.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAC1B,8GAA8G;IAC9G,MAAM,CAAC,WAAW,CAAC,KAAc;QAC/B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,SAAS,GAAG,KAAgC,CAAC;QAEnD,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,SAAS,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YAC3E,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6GAA6G;IAC7G,MAAM,CAAC,cAAc,CAAC,OAAgB;QACpC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAG,OAAkC,CAAC;QAEhD,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { IMailTransport, TMailOptions } from '../common';\n\n/**\n * Type guards for the mail component. Each takes its value as a positional parameter, not an options\n * object (V-C-02): a type predicate narrows its own parameter, so `{ value }` could not narrow the\n * caller's variable.\n */\nexport class MailTypeUtility {\n /** Whether `value` is a transport: `send` and `verify` are functions, and `close` is a function or absent. */\n static isTransport(value: AnyType): value is IMailTransport {\n if (!value || typeof value !== 'object') {\n return false;\n }\n\n const transport = value as Record<string, unknown>;\n\n if (typeof transport.send !== 'function') {\n return false;\n }\n\n if (typeof transport.verify !== 'function') {\n return false;\n }\n\n if (transport.close !== undefined && typeof transport.close !== 'function') {\n return false;\n }\n\n return true;\n }\n\n /** Whether `options` has a string `provider` and a truthy `config`; the shape of `config` is not checked. */\n static isValidOptions(options: AnyType): options is TMailOptions {\n if (!options || typeof options !== 'object') {\n return false;\n }\n\n const opts = options as Record<string, unknown>;\n\n if (typeof opts.provider !== 'string') {\n return false;\n }\n\n if (!opts.config) {\n return false;\n }\n\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"type.utility.js","sourceRoot":"","sources":["../../../../../src/components/mail/utilities/type.utility.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAC1B,8GAA8G;IAC9G,MAAM,CAAC,WAAW,CAAC,KAAc;QAC/B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,UAAU,EAAE,CAAC;YACvD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEnD,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YACvD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6GAA6G;IAC7G,MAAM,CAAC,cAAc,CAAC,OAAgB;QACpC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,QAAQ,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import type { IMailTransport, TMailOptions } from '../common';\n\n/**\n * Type guards for the mail component. Each takes its value as a positional parameter, not an options\n * object (V-C-02): a type predicate narrows its own parameter, so `{ value }` could not narrow the\n * caller's variable.\n */\nexport class MailTypeUtility {\n /** Whether `value` is a transport: `send` and `verify` are functions, and `close` is a function or absent. */\n static isTransport(value: unknown): value is IMailTransport {\n if (!value || typeof value !== 'object') {\n return false;\n }\n\n if (typeof Reflect.get(value, 'send') !== 'function') {\n return false;\n }\n\n if (typeof Reflect.get(value, 'verify') !== 'function') {\n return false;\n }\n\n const close: unknown = Reflect.get(value, 'close');\n\n if (close !== undefined && typeof close !== 'function') {\n return false;\n }\n\n return true;\n }\n\n /** Whether `options` has a string `provider` and a truthy `config`; the shape of `config` is not checked. */\n static isValidOptions(options: unknown): options is TMailOptions {\n if (!options || typeof options !== 'object') {\n return false;\n }\n\n if (typeof Reflect.get(options, 'provider') !== 'string') {\n return false;\n }\n\n if (!Reflect.get(options, 'config')) {\n return false;\n }\n\n return true;\n }\n}\n"]}
@@ -1,10 +1,11 @@
1
1
  import { type BaseApplication } from '../../base/applications/index.js';
2
2
  import { BaseComponent } from '@venizia/ignis-kernel';
3
3
  import { type ValueOrPromise } from '@venizia/ignis-helpers/common';
4
+ import { type MiddlewareHandler } from 'hono/types';
4
5
  /** Installs the request spy middleware on the application server, which tracks each request. */
5
6
  export declare class RequestTrackerComponent extends BaseComponent {
6
7
  private application;
7
- static readonly REQUEST_TRACKER_MW_BINDING_KEY: string;
8
+ static readonly REQUEST_TRACKER_MW_BINDING_KEY: import("@venizia/ignis-inversion").TBindingKey<MiddlewareHandler>;
8
9
  constructor(application: BaseApplication);
9
10
  /** No `requestId()` here: the id is installed by `RestApplication.registerDefaultMiddlewares()`, which runs first and uses `RequestIdGenerator`. Same UUID v4 shape hono's own default produces, but hono calls `crypto.randomUUID` unguarded, and a browser leaves that one `undefined` outside a secure context. */
10
11
  binding(): ValueOrPromise<void>;