@beignet/core 0.0.1 → 0.0.2

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 (274) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +149 -4
  3. package/dist/application/index.d.ts +93 -9
  4. package/dist/application/index.d.ts.map +1 -1
  5. package/dist/application/index.js +11 -11
  6. package/dist/application/index.js.map +1 -1
  7. package/dist/client/client.d.ts +73 -12
  8. package/dist/client/client.d.ts.map +1 -1
  9. package/dist/client/client.js +37 -12
  10. package/dist/client/client.js.map +1 -1
  11. package/dist/client/index.d.ts +12 -0
  12. package/dist/client/index.d.ts.map +1 -1
  13. package/dist/client/index.js +6 -0
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/client/types.d.ts +69 -8
  16. package/dist/client/types.d.ts.map +1 -1
  17. package/dist/config/index.d.ts +84 -0
  18. package/dist/config/index.d.ts.map +1 -1
  19. package/dist/config/index.js +36 -0
  20. package/dist/config/index.js.map +1 -1
  21. package/dist/contracts/contract-builder.d.ts +49 -22
  22. package/dist/contracts/contract-builder.d.ts.map +1 -1
  23. package/dist/contracts/contract-builder.js +48 -21
  24. package/dist/contracts/contract-builder.js.map +1 -1
  25. package/dist/contracts/contract-group.d.ts +35 -19
  26. package/dist/contracts/contract-group.d.ts.map +1 -1
  27. package/dist/contracts/contract-group.js +35 -19
  28. package/dist/contracts/contract-group.js.map +1 -1
  29. package/dist/contracts/contract-like.d.ts +4 -4
  30. package/dist/contracts/contract-like.d.ts.map +1 -1
  31. package/dist/contracts/contract-like.js +2 -1
  32. package/dist/contracts/contract-like.js.map +1 -1
  33. package/dist/contracts/index.d.ts +28 -0
  34. package/dist/contracts/index.d.ts.map +1 -1
  35. package/dist/contracts/index.js +12 -0
  36. package/dist/contracts/index.js.map +1 -1
  37. package/dist/contracts/openapi-meta.d.ts +8 -8
  38. package/dist/contracts/openapi-meta.d.ts.map +1 -1
  39. package/dist/contracts/path-template.d.ts +27 -0
  40. package/dist/contracts/path-template.d.ts.map +1 -1
  41. package/dist/contracts/path-template.js +6 -0
  42. package/dist/contracts/path-template.js.map +1 -1
  43. package/dist/contracts/types.d.ts +104 -10
  44. package/dist/contracts/types.d.ts.map +1 -1
  45. package/dist/contracts/types.js +15 -0
  46. package/dist/contracts/types.js.map +1 -1
  47. package/dist/contracts/utils.d.ts +6 -0
  48. package/dist/contracts/utils.d.ts.map +1 -1
  49. package/dist/contracts/utils.js +6 -0
  50. package/dist/contracts/utils.js.map +1 -1
  51. package/dist/domain/entity.d.ts +22 -11
  52. package/dist/domain/entity.d.ts.map +1 -1
  53. package/dist/domain/entity.js +5 -1
  54. package/dist/domain/entity.js.map +1 -1
  55. package/dist/domain/events.d.ts +5 -2
  56. package/dist/domain/events.d.ts.map +1 -1
  57. package/dist/domain/events.js +4 -1
  58. package/dist/domain/events.js.map +1 -1
  59. package/dist/domain/value-object.d.ts +19 -9
  60. package/dist/domain/value-object.d.ts.map +1 -1
  61. package/dist/domain/value-object.js +5 -1
  62. package/dist/domain/value-object.js.map +1 -1
  63. package/dist/errors/catalog.d.ts +40 -16
  64. package/dist/errors/catalog.d.ts.map +1 -1
  65. package/dist/errors/catalog.js +18 -7
  66. package/dist/errors/catalog.js.map +1 -1
  67. package/dist/errors/response.d.ts +16 -4
  68. package/dist/errors/response.d.ts.map +1 -1
  69. package/dist/errors/response.js +3 -3
  70. package/dist/errors/response.js.map +1 -1
  71. package/dist/errors/validation.d.ts +10 -1
  72. package/dist/errors/validation.d.ts.map +1 -1
  73. package/dist/errors/validation.js +3 -0
  74. package/dist/errors/validation.js.map +1 -1
  75. package/dist/events/index.d.ts +133 -0
  76. package/dist/events/index.d.ts.map +1 -1
  77. package/dist/events/index.js +30 -0
  78. package/dist/events/index.js.map +1 -1
  79. package/dist/idempotency/index.d.ts +355 -0
  80. package/dist/idempotency/index.d.ts.map +1 -0
  81. package/dist/idempotency/index.js +360 -0
  82. package/dist/idempotency/index.js.map +1 -0
  83. package/dist/jobs/index.d.ts +110 -0
  84. package/dist/jobs/index.d.ts.map +1 -1
  85. package/dist/jobs/index.js +22 -0
  86. package/dist/jobs/index.js.map +1 -1
  87. package/dist/mail/index.d.ts +149 -0
  88. package/dist/mail/index.d.ts.map +1 -1
  89. package/dist/mail/index.js +30 -0
  90. package/dist/mail/index.js.map +1 -1
  91. package/dist/notifications/index.d.ts +369 -0
  92. package/dist/notifications/index.d.ts.map +1 -0
  93. package/dist/notifications/index.js +310 -0
  94. package/dist/notifications/index.js.map +1 -0
  95. package/dist/openapi/index.d.ts +132 -16
  96. package/dist/openapi/index.d.ts.map +1 -1
  97. package/dist/openapi/index.js +1 -1
  98. package/dist/openapi/index.js.map +1 -1
  99. package/dist/outbox/index.d.ts +469 -0
  100. package/dist/outbox/index.d.ts.map +1 -0
  101. package/dist/outbox/index.js +482 -0
  102. package/dist/outbox/index.js.map +1 -0
  103. package/dist/pagination/index.d.ts +166 -0
  104. package/dist/pagination/index.d.ts.map +1 -0
  105. package/dist/pagination/index.js +96 -0
  106. package/dist/pagination/index.js.map +1 -0
  107. package/dist/ports/audit.d.ts +271 -0
  108. package/dist/ports/audit.d.ts.map +1 -1
  109. package/dist/ports/audit.js +128 -0
  110. package/dist/ports/audit.js.map +1 -1
  111. package/dist/ports/auth.d.ts +70 -0
  112. package/dist/ports/auth.d.ts.map +1 -1
  113. package/dist/ports/auth.js +30 -0
  114. package/dist/ports/auth.js.map +1 -1
  115. package/dist/ports/cache.d.ts +41 -0
  116. package/dist/ports/cache.d.ts.map +1 -1
  117. package/dist/ports/cache.js +10 -0
  118. package/dist/ports/cache.js.map +1 -1
  119. package/dist/ports/clock.d.ts +38 -0
  120. package/dist/ports/clock.d.ts.map +1 -1
  121. package/dist/ports/clock.js +20 -0
  122. package/dist/ports/clock.js.map +1 -1
  123. package/dist/ports/id-generator.d.ts +37 -0
  124. package/dist/ports/id-generator.d.ts.map +1 -1
  125. package/dist/ports/id-generator.js +22 -0
  126. package/dist/ports/id-generator.js.map +1 -1
  127. package/dist/ports/index.d.ts +83 -0
  128. package/dist/ports/index.d.ts.map +1 -1
  129. package/dist/ports/index.js +41 -5
  130. package/dist/ports/index.js.map +1 -1
  131. package/dist/ports/logger.d.ts +56 -0
  132. package/dist/ports/logger.d.ts.map +1 -1
  133. package/dist/ports/logger.js +17 -0
  134. package/dist/ports/logger.js.map +1 -1
  135. package/dist/ports/policy.d.ts +132 -0
  136. package/dist/ports/policy.d.ts.map +1 -1
  137. package/dist/ports/policy.js +45 -0
  138. package/dist/ports/policy.js.map +1 -1
  139. package/dist/ports/rate-limit.d.ts +25 -0
  140. package/dist/ports/rate-limit.d.ts.map +1 -1
  141. package/dist/ports/rate-limit.js +10 -0
  142. package/dist/ports/rate-limit.js.map +1 -1
  143. package/dist/ports/redaction.d.ts +101 -0
  144. package/dist/ports/redaction.d.ts.map +1 -1
  145. package/dist/ports/redaction.js +59 -0
  146. package/dist/ports/redaction.js.map +1 -1
  147. package/dist/ports/storage.d.ts +100 -0
  148. package/dist/ports/storage.d.ts.map +1 -1
  149. package/dist/ports/storage.js +10 -0
  150. package/dist/ports/storage.js.map +1 -1
  151. package/dist/ports/testing.d.ts +47 -0
  152. package/dist/ports/testing.d.ts.map +1 -1
  153. package/dist/ports/testing.js +23 -0
  154. package/dist/ports/testing.js.map +1 -1
  155. package/dist/ports/unit-of-work.d.ts +60 -3
  156. package/dist/ports/unit-of-work.d.ts.map +1 -1
  157. package/dist/ports/unit-of-work.js +11 -2
  158. package/dist/ports/unit-of-work.js.map +1 -1
  159. package/dist/providers/instrumentation.d.ts +204 -0
  160. package/dist/providers/instrumentation.d.ts.map +1 -1
  161. package/dist/providers/instrumentation.js +14 -0
  162. package/dist/providers/instrumentation.js.map +1 -1
  163. package/dist/providers/provider.d.ts +14 -1
  164. package/dist/providers/provider.d.ts.map +1 -1
  165. package/dist/providers/provider.js.map +1 -1
  166. package/dist/schedules/index.d.ts +246 -0
  167. package/dist/schedules/index.d.ts.map +1 -1
  168. package/dist/schedules/index.js +27 -0
  169. package/dist/schedules/index.js.map +1 -1
  170. package/dist/server/health.d.ts +14 -5
  171. package/dist/server/health.d.ts.map +1 -1
  172. package/dist/server/health.js +5 -2
  173. package/dist/server/health.js.map +1 -1
  174. package/dist/server/hooks/auth.d.ts +57 -0
  175. package/dist/server/hooks/auth.d.ts.map +1 -1
  176. package/dist/server/hooks/auth.js.map +1 -1
  177. package/dist/server/hooks/cors.d.ts +27 -0
  178. package/dist/server/hooks/cors.d.ts.map +1 -1
  179. package/dist/server/hooks/cors.js +12 -0
  180. package/dist/server/hooks/cors.js.map +1 -1
  181. package/dist/server/hooks/errors.d.ts +15 -6
  182. package/dist/server/hooks/errors.d.ts.map +1 -1
  183. package/dist/server/hooks/errors.js.map +1 -1
  184. package/dist/server/hooks/index.d.ts +3 -0
  185. package/dist/server/hooks/index.d.ts.map +1 -1
  186. package/dist/server/hooks/index.js +3 -0
  187. package/dist/server/hooks/index.js.map +1 -1
  188. package/dist/server/hooks/logging.d.ts +36 -0
  189. package/dist/server/hooks/logging.d.ts.map +1 -1
  190. package/dist/server/hooks/logging.js +6 -0
  191. package/dist/server/hooks/logging.js.map +1 -1
  192. package/dist/server/hooks/rate-limit.d.ts +33 -0
  193. package/dist/server/hooks/rate-limit.d.ts.map +1 -1
  194. package/dist/server/hooks/rate-limit.js +11 -0
  195. package/dist/server/hooks/rate-limit.js.map +1 -1
  196. package/dist/server/http.d.ts +170 -0
  197. package/dist/server/http.d.ts.map +1 -1
  198. package/dist/server/index.d.ts +18 -0
  199. package/dist/server/index.d.ts.map +1 -1
  200. package/dist/server/index.js +6 -0
  201. package/dist/server/index.js.map +1 -1
  202. package/dist/server/openapi.d.ts +5 -3
  203. package/dist/server/openapi.d.ts.map +1 -1
  204. package/dist/server/openapi.js +4 -2
  205. package/dist/server/openapi.js.map +1 -1
  206. package/dist/server/providers/loadProviderConfig.d.ts +9 -0
  207. package/dist/server/providers/loadProviderConfig.d.ts.map +1 -1
  208. package/dist/server/providers/loadProviderConfig.js +9 -0
  209. package/dist/server/providers/loadProviderConfig.js.map +1 -1
  210. package/dist/server/server.d.ts +107 -8
  211. package/dist/server/server.d.ts.map +1 -1
  212. package/dist/server/server.js +27 -7
  213. package/dist/server/server.js.map +1 -1
  214. package/dist/testing/index.d.ts +167 -0
  215. package/dist/testing/index.d.ts.map +1 -0
  216. package/dist/testing/index.js +119 -0
  217. package/dist/testing/index.js.map +1 -0
  218. package/package.json +21 -1
  219. package/src/application/index.ts +85 -22
  220. package/src/client/client.ts +73 -12
  221. package/src/client/index.ts +12 -0
  222. package/src/client/types.ts +70 -9
  223. package/src/config/index.ts +86 -0
  224. package/src/contracts/contract-builder.ts +49 -22
  225. package/src/contracts/contract-group.ts +35 -19
  226. package/src/contracts/contract-like.ts +4 -4
  227. package/src/contracts/index.ts +28 -1
  228. package/src/contracts/openapi-meta.ts +8 -8
  229. package/src/contracts/path-template.ts +27 -0
  230. package/src/contracts/types.ts +111 -10
  231. package/src/contracts/utils.ts +6 -0
  232. package/src/domain/entity.ts +22 -11
  233. package/src/domain/events.ts +5 -2
  234. package/src/domain/value-object.ts +19 -9
  235. package/src/errors/catalog.ts +40 -16
  236. package/src/errors/response.ts +16 -4
  237. package/src/errors/validation.ts +10 -1
  238. package/src/events/index.ts +134 -0
  239. package/src/idempotency/index.ts +767 -0
  240. package/src/jobs/index.ts +111 -0
  241. package/src/mail/index.ts +149 -0
  242. package/src/notifications/index.ts +771 -0
  243. package/src/openapi/index.ts +133 -16
  244. package/src/outbox/index.ts +1024 -0
  245. package/src/pagination/index.ts +278 -0
  246. package/src/ports/audit.ts +271 -0
  247. package/src/ports/auth.ts +70 -0
  248. package/src/ports/cache.ts +41 -0
  249. package/src/ports/clock.ts +38 -0
  250. package/src/ports/id-generator.ts +37 -0
  251. package/src/ports/index.ts +106 -11
  252. package/src/ports/logger.ts +56 -0
  253. package/src/ports/policy.ts +133 -0
  254. package/src/ports/rate-limit.ts +25 -0
  255. package/src/ports/redaction.ts +101 -0
  256. package/src/ports/storage.ts +100 -0
  257. package/src/ports/testing.ts +47 -0
  258. package/src/ports/unit-of-work.ts +60 -3
  259. package/src/providers/instrumentation.ts +204 -0
  260. package/src/providers/provider.ts +14 -1
  261. package/src/schedules/index.ts +247 -0
  262. package/src/server/health.ts +14 -5
  263. package/src/server/hooks/auth.ts +58 -0
  264. package/src/server/hooks/cors.ts +27 -0
  265. package/src/server/hooks/errors.ts +15 -6
  266. package/src/server/hooks/index.ts +3 -0
  267. package/src/server/hooks/logging.ts +36 -0
  268. package/src/server/hooks/rate-limit.ts +33 -0
  269. package/src/server/http.ts +170 -1
  270. package/src/server/index.ts +18 -1
  271. package/src/server/openapi.ts +5 -3
  272. package/src/server/providers/loadProviderConfig.ts +9 -0
  273. package/src/server/server.ts +107 -9
  274. package/src/testing/index.ts +337 -0
@@ -3,21 +3,65 @@
3
3
  *
4
4
  * Shared mail port and test adapters for Beignet applications.
5
5
  */
6
+ /**
7
+ * Value or promise of that value.
8
+ */
6
9
  export type MaybePromise<T> = T | Promise<T>;
10
+ /**
11
+ * Email address accepted by Beignet mail helpers.
12
+ */
7
13
  export type MailAddress = string | {
14
+ /**
15
+ * Email address.
16
+ */
8
17
  email: string;
18
+ /**
19
+ * Optional display name.
20
+ */
9
21
  name?: string;
10
22
  };
23
+ /**
24
+ * Single address or address list.
25
+ */
11
26
  export type MailAddressList = MailAddress | readonly MailAddress[];
27
+ /**
28
+ * Common mail message fields shared by all send options.
29
+ */
12
30
  export interface MailBaseMessage {
31
+ /**
32
+ * Required recipients.
33
+ */
13
34
  to: MailAddressList;
35
+ /**
36
+ * Message subject.
37
+ */
14
38
  subject: string;
39
+ /**
40
+ * Sender address. Providers or adapters may supply a default.
41
+ */
15
42
  from?: MailAddress;
43
+ /**
44
+ * Carbon-copy recipients.
45
+ */
16
46
  cc?: MailAddressList;
47
+ /**
48
+ * Blind-carbon-copy recipients.
49
+ */
17
50
  bcc?: MailAddressList;
51
+ /**
52
+ * Reply-to recipients.
53
+ */
18
54
  replyTo?: MailAddressList;
55
+ /**
56
+ * Provider-specific message headers.
57
+ */
19
58
  headers?: Record<string, string>;
20
59
  }
60
+ /**
61
+ * Mail send options.
62
+ *
63
+ * A message must include at least one body format: `text` or `html`.
64
+ */
21
65
  export type SendMailOptions = MailBaseMessage & ({
22
66
  text: string;
23
67
  html?: string;
@@ -25,39 +69,123 @@ export type SendMailOptions = MailBaseMessage & ({
25
69
  html: string;
26
70
  text?: string;
27
71
  });
72
+ /**
73
+ * Normalized mail message with address fields converted to arrays.
74
+ */
28
75
  export interface NormalizedMailMessage extends MailBaseMessage {
76
+ /**
77
+ * Normalized recipients.
78
+ */
29
79
  to: readonly MailAddress[];
80
+ /**
81
+ * Sender address after applying any default.
82
+ */
30
83
  from?: MailAddress;
84
+ /**
85
+ * Normalized carbon-copy recipients.
86
+ */
31
87
  cc?: readonly MailAddress[];
88
+ /**
89
+ * Normalized blind-carbon-copy recipients.
90
+ */
32
91
  bcc?: readonly MailAddress[];
92
+ /**
93
+ * Normalized reply-to recipients.
94
+ */
33
95
  replyTo?: readonly MailAddress[];
96
+ /**
97
+ * Plain text body.
98
+ */
34
99
  text?: string;
100
+ /**
101
+ * HTML body.
102
+ */
35
103
  html?: string;
36
104
  }
105
+ /**
106
+ * Result returned by a mail provider.
107
+ */
37
108
  export interface SendMailResult {
109
+ /**
110
+ * Provider message ID when available.
111
+ */
38
112
  id?: string;
113
+ /**
114
+ * Provider name.
115
+ */
39
116
  provider?: string;
40
117
  }
118
+ /**
119
+ * App-facing mailer port.
120
+ */
41
121
  export interface MailerPort {
122
+ /**
123
+ * Send one mail message.
124
+ */
42
125
  send(message: SendMailOptions): Promise<SendMailResult>;
43
126
  }
127
+ /**
128
+ * Delivery captured by the memory mailer.
129
+ */
44
130
  export interface MemoryMailDelivery {
131
+ /**
132
+ * Generated delivery ID.
133
+ */
45
134
  id: string;
135
+ /**
136
+ * Normalized message that would have been sent.
137
+ */
46
138
  message: NormalizedMailMessage;
139
+ /**
140
+ * Timestamp assigned by the memory mailer.
141
+ */
47
142
  sentAt: Date;
48
143
  }
144
+ /**
145
+ * In-memory mailer port for tests and local examples.
146
+ */
49
147
  export interface MemoryMailerPort extends MailerPort {
148
+ /**
149
+ * Captured deliveries.
150
+ */
50
151
  readonly deliveries: readonly MemoryMailDelivery[];
152
+ /**
153
+ * Clear captured deliveries.
154
+ */
51
155
  clear(): void;
52
156
  }
157
+ /**
158
+ * Options for `createMemoryMailer(...)`.
159
+ */
53
160
  export interface CreateMemoryMailerOptions {
161
+ /**
162
+ * Sender used when a message does not specify `from`.
163
+ */
54
164
  defaultFrom?: MailAddress;
165
+ /**
166
+ * Clock used for captured deliveries.
167
+ */
55
168
  now?: () => Date;
169
+ /**
170
+ * ID factory used for captured deliveries.
171
+ */
56
172
  id?: () => string;
173
+ /**
174
+ * Observer called after a delivery is captured.
175
+ */
57
176
  onSend?: (delivery: MemoryMailDelivery) => MaybePromise<void>;
58
177
  }
178
+ /**
179
+ * Error thrown by mail helpers and provider adapters.
180
+ */
59
181
  export declare class MailDeliveryError extends Error {
182
+ /**
183
+ * Provider name when known.
184
+ */
60
185
  readonly provider?: string;
186
+ /**
187
+ * Original provider error when available.
188
+ */
61
189
  readonly cause?: unknown;
62
190
  constructor(args: {
63
191
  provider?: string;
@@ -65,11 +193,32 @@ export declare class MailDeliveryError extends Error {
65
193
  cause?: unknown;
66
194
  });
67
195
  }
196
+ /**
197
+ * Normalize a single address or address list into an array.
198
+ *
199
+ * This helper does not validate email syntax.
200
+ */
68
201
  export declare function normalizeMailAddressList(addresses: MailAddressList | undefined): readonly MailAddress[] | undefined;
202
+ /**
203
+ * Format one address for providers that accept RFC-like address strings.
204
+ */
69
205
  export declare function formatMailAddress(address: MailAddress): string;
206
+ /**
207
+ * Format one or more addresses for providers that accept string address fields.
208
+ */
70
209
  export declare function formatMailAddressList(addresses: MailAddressList): string | string[];
210
+ /**
211
+ * Normalize a mail message and apply a default sender.
212
+ *
213
+ * Throws when the message has no recipients.
214
+ */
71
215
  export declare function normalizeMailMessage(message: SendMailOptions, options?: {
72
216
  defaultFrom?: MailAddress;
73
217
  }): NormalizedMailMessage;
218
+ /**
219
+ * Create an in-memory mailer for tests, local development, and examples.
220
+ *
221
+ * The memory mailer does not send real email or validate address syntax.
222
+ */
74
223
  export declare function createMemoryMailer(options?: CreateMemoryMailerOptions): MemoryMailerPort;
75
224
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mail/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,WAAW,GACnB,MAAM,GACN;IACE,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,SAAS,WAAW,EAAE,CAAC;AAEnE,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,eAAe,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,EAAE,CAAC,EAAE,eAAe,CAAC;IACrB,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,MAAM,eAAe,GAAG,eAAe,GAC3C,CACI;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CACJ,CAAC;AAEJ,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,EAAE,EAAE,SAAS,WAAW,EAAE,CAAC;IAC3B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et applications.
5
5
  */
6
+ /**
7
+ * Error thrown by mail helpers and provider adapters.
8
+ */
6
9
  export class MailDeliveryError extends Error {
10
+ /**
11
+ * Provider name when known.
12
+ */
7
13
  provider;
14
+ /**
15
+ * Original provider error when available.
16
+ */
8
17
  cause;
9
18
  constructor(args) {
10
19
  super(args.message);
@@ -13,6 +22,11 @@ export class MailDeliveryError extends Error {
13
22
  this.cause = args.cause;
14
23
  }
15
24
  }
25
+ /**
26
+ * Normalize a single address or address list into an array.
27
+ *
28
+ * This helper does not validate email syntax.
29
+ */
16
30
  export function normalizeMailAddressList(addresses) {
17
31
  if (addresses === undefined)
18
32
  return undefined;
@@ -22,6 +36,9 @@ function normalizeOptionalMailAddressList(addresses) {
22
36
  const normalized = normalizeMailAddressList(addresses);
23
37
  return normalized && normalized.length > 0 ? normalized : undefined;
24
38
  }
39
+ /**
40
+ * Format one address for providers that accept RFC-like address strings.
41
+ */
25
42
  export function formatMailAddress(address) {
26
43
  if (typeof address === "string")
27
44
  return address;
@@ -30,11 +47,19 @@ export function formatMailAddress(address) {
30
47
  const escapedName = address.name.replace(/"/g, '\\"');
31
48
  return `"${escapedName}" <${address.email}>`;
32
49
  }
50
+ /**
51
+ * Format one or more addresses for providers that accept string address fields.
52
+ */
33
53
  export function formatMailAddressList(addresses) {
34
54
  const normalized = normalizeMailAddressList(addresses) ?? [];
35
55
  const formatted = normalized.map(formatMailAddress);
36
56
  return formatted.length === 1 ? formatted[0] : formatted;
37
57
  }
58
+ /**
59
+ * Normalize a mail message and apply a default sender.
60
+ *
61
+ * Throws when the message has no recipients.
62
+ */
38
63
  export function normalizeMailMessage(message, options = {}) {
39
64
  const to = normalizeMailAddressList(message.to) ?? [];
40
65
  if (to.length === 0) {
@@ -53,6 +78,11 @@ export function normalizeMailMessage(message, options = {}) {
53
78
  html: "html" in message ? message.html : undefined,
54
79
  };
55
80
  }
81
+ /**
82
+ * Create an in-memory mailer for tests, local development, and examples.
83
+ *
84
+ * The memory mailer does not send real email or validate address syntax.
85
+ */
56
86
  export function createMemoryMailer(options = {}) {
57
87
  const deliveries = [];
58
88
  const now = options.now ?? (() => new Date());
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mail/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwEH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,QAAQ,CAAU;IAClB,KAAK,CAAW;IAEzB,YAAY,IAA6D;QACvE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CACtC,SAAsC;IAEtC,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAwB,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,gCAAgC,CACvC,SAAsC;IAEtC,MAAM,UAAU,GAAG,wBAAwB,CAAC,SAAS,CAAC,CAAC;IACvD,OAAO,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAoB;IACpD,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IAExC,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,OAAO,IAA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AW;iBACjC,CAAC;gBACF,MAAM,EAAE,GAAG,EAAE;aACd,CAAC;YAEF,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1B,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;YAEjC,OAAO;gBACL,EAAE,EAAE,QAAQ,CAAC,EAAE;gBACf,QAAQ,EAAE,QAAQ;aACnB,CAAC;QACJ,CAAC;QAED,KAAK;YACH,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,369 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import type { SendMailOptions } from "../mail";
3
+ import type { ProviderInstrumentationTarget } from "../providers";
4
+ /**
5
+ * Any Standard Schema compatible validator.
6
+ */
7
+ export type StandardSchema = StandardSchemaV1<unknown, unknown>;
8
+ /**
9
+ * Value or promise of that value.
10
+ */
11
+ export type MaybePromise<T> = T | Promise<T>;
12
+ /**
13
+ * Infer the parsed output type from a Standard Schema.
14
+ */
15
+ export type InferSchemaOutput<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
16
+ /**
17
+ * Minimal notification definition shape accepted by notification ports.
18
+ */
19
+ export interface NotificationPayloadDef<Name extends string = string, Payload extends StandardSchema = StandardSchema> {
20
+ /**
21
+ * Stable notification name used by dispatchers, tests, and tooling.
22
+ */
23
+ readonly name: Name;
24
+ /**
25
+ * Standard Schema payload validator.
26
+ */
27
+ readonly payload: Payload;
28
+ /**
29
+ * Optional human-readable description for docs and tooling.
30
+ */
31
+ readonly description?: string;
32
+ }
33
+ /**
34
+ * Infer the parsed payload type for a notification definition.
35
+ */
36
+ export type InferNotificationPayload<N extends NotificationPayloadDef> = N["payload"] extends StandardSchemaV1<unknown, infer Output> ? Output : never;
37
+ /**
38
+ * Result for one notification channel.
39
+ */
40
+ export interface NotificationChannelResult {
41
+ /**
42
+ * Channel name, such as `email`, `sms`, `push`, or `inApp`.
43
+ */
44
+ channel: string;
45
+ /**
46
+ * Delivery outcome for this channel.
47
+ */
48
+ status: "sent" | "skipped" | "failed";
49
+ /**
50
+ * Provider delivery ID when available.
51
+ */
52
+ id?: string;
53
+ /**
54
+ * Provider name when available.
55
+ */
56
+ provider?: string;
57
+ /**
58
+ * Human-readable skip or failure reason.
59
+ */
60
+ reason?: string;
61
+ /**
62
+ * Channel-specific metadata. Dispatchers should keep this safe to log.
63
+ */
64
+ details?: Record<string, unknown>;
65
+ }
66
+ /**
67
+ * Arguments passed to a notification channel handler.
68
+ */
69
+ export interface NotificationChannelHandleArgs<Payload extends StandardSchema, Ctx> {
70
+ /**
71
+ * Notification definition being delivered.
72
+ */
73
+ notification: NotificationDef<string, Payload, Ctx>;
74
+ /**
75
+ * Parsed notification payload.
76
+ */
77
+ payload: InferSchemaOutput<Payload>;
78
+ /**
79
+ * Handler context.
80
+ */
81
+ ctx: Ctx;
82
+ /**
83
+ * Channel name being delivered.
84
+ */
85
+ channel: string;
86
+ }
87
+ /**
88
+ * Handler for one notification channel.
89
+ */
90
+ export type NotificationChannelHandler<Payload extends StandardSchema, Ctx> = (args: NotificationChannelHandleArgs<Payload, Ctx>) => MaybePromise<NotificationChannelResult | undefined>;
91
+ /**
92
+ * Notification channel handlers keyed by channel name.
93
+ */
94
+ export type NotificationChannels<Payload extends StandardSchema, Ctx> = Record<string, NotificationChannelHandler<Payload, Ctx>>;
95
+ /**
96
+ * Notification definition created by `defineNotification(...)`.
97
+ */
98
+ export interface NotificationDef<Name extends string = string, Payload extends StandardSchema = StandardSchema, Ctx = unknown> extends NotificationPayloadDef<Name, Payload> {
99
+ /**
100
+ * Discriminator for notification definitions.
101
+ */
102
+ readonly kind: "notification";
103
+ /**
104
+ * Channel handlers that deliver the notification.
105
+ */
106
+ readonly channels: NotificationChannels<Payload, Ctx>;
107
+ }
108
+ /**
109
+ * Options for declaring a typed notification.
110
+ */
111
+ export interface DefineNotificationOptions<Payload extends StandardSchema, Ctx> {
112
+ /**
113
+ * Standard Schema payload validator.
114
+ */
115
+ payload: Payload;
116
+ /**
117
+ * Optional human-readable description for docs and tooling.
118
+ */
119
+ description?: string;
120
+ /**
121
+ * Channel handlers that deliver the notification.
122
+ */
123
+ channels: NotificationChannels<Payload, Ctx>;
124
+ }
125
+ /**
126
+ * Options passed when sending a notification.
127
+ */
128
+ export interface SendNotificationOptions {
129
+ /**
130
+ * Subset of channels to deliver. Defaults to all channels on the definition.
131
+ */
132
+ channels?: readonly string[];
133
+ /**
134
+ * Optional app metadata attached to memory deliveries and instrumentation.
135
+ */
136
+ metadata?: Record<string, unknown>;
137
+ /**
138
+ * Request correlation ID for instrumentation.
139
+ */
140
+ requestId?: string;
141
+ /**
142
+ * Trace identifier for instrumentation.
143
+ */
144
+ traceId?: string;
145
+ /**
146
+ * Span identifier for instrumentation.
147
+ */
148
+ spanId?: string;
149
+ /**
150
+ * Parent span identifier for instrumentation.
151
+ */
152
+ parentSpanId?: string;
153
+ /**
154
+ * W3C traceparent header value for instrumentation.
155
+ */
156
+ traceparent?: string;
157
+ }
158
+ /**
159
+ * Result returned after a notification send attempt.
160
+ */
161
+ export interface SendNotificationResult {
162
+ /**
163
+ * Notification name.
164
+ */
165
+ notificationName: string;
166
+ /**
167
+ * Parsed notification payload.
168
+ */
169
+ payload: unknown;
170
+ /**
171
+ * Channels selected for delivery.
172
+ */
173
+ channels: readonly string[];
174
+ /**
175
+ * Per-channel delivery results.
176
+ */
177
+ results: readonly NotificationChannelResult[];
178
+ }
179
+ /**
180
+ * App-facing notification port.
181
+ */
182
+ export interface NotificationPort {
183
+ /**
184
+ * Send a typed notification.
185
+ */
186
+ send<N extends NotificationDef>(notification: N, payload: InferNotificationPayload<N>, options?: SendNotificationOptions): Promise<SendNotificationResult>;
187
+ }
188
+ /**
189
+ * Options for the inline notification dispatcher.
190
+ */
191
+ export interface InlineNotificationDispatcherOptions<Ctx> {
192
+ /**
193
+ * Static notification context or factory evaluated for each send.
194
+ */
195
+ ctx?: Ctx | (() => MaybePromise<Ctx>);
196
+ /**
197
+ * Called when a channel handler fails. When omitted, errors are rethrown to
198
+ * the caller as `NotificationDeliveryError`.
199
+ */
200
+ onError?: (error: unknown, args: NotificationChannelHandleArgs<StandardSchema, Ctx>) => MaybePromise<NotificationChannelResult | undefined>;
201
+ /**
202
+ * Optional devtools/provider instrumentation target.
203
+ */
204
+ instrumentation?: ProviderInstrumentationTarget;
205
+ }
206
+ /**
207
+ * Delivery captured by the memory notification port.
208
+ */
209
+ export interface MemoryNotificationDelivery {
210
+ /**
211
+ * Generated delivery ID.
212
+ */
213
+ id: string;
214
+ /**
215
+ * Notification name.
216
+ */
217
+ notificationName: string;
218
+ /**
219
+ * Parsed payload that would have been sent.
220
+ */
221
+ payload: unknown;
222
+ /**
223
+ * Selected channels.
224
+ */
225
+ channels: readonly string[];
226
+ /**
227
+ * Optional app metadata supplied by the caller.
228
+ */
229
+ metadata?: Record<string, unknown>;
230
+ /**
231
+ * Timestamp assigned by the memory port.
232
+ */
233
+ sentAt: Date;
234
+ }
235
+ /**
236
+ * In-memory notification port for tests and local examples.
237
+ */
238
+ export interface MemoryNotificationPort extends NotificationPort {
239
+ /**
240
+ * Captured notification sends.
241
+ */
242
+ readonly deliveries: readonly MemoryNotificationDelivery[];
243
+ /**
244
+ * Clear captured notification sends.
245
+ */
246
+ clear(): void;
247
+ }
248
+ /**
249
+ * Options for `createMemoryNotificationPort(...)`.
250
+ */
251
+ export interface CreateMemoryNotificationPortOptions {
252
+ /**
253
+ * Clock used for captured deliveries.
254
+ */
255
+ now?: () => Date;
256
+ /**
257
+ * ID factory used for captured deliveries.
258
+ */
259
+ id?: () => string;
260
+ /**
261
+ * Observer called after a delivery is captured.
262
+ */
263
+ onSend?: (delivery: MemoryNotificationDelivery) => MaybePromise<void>;
264
+ }
265
+ /**
266
+ * Context shape required by `defineMailNotificationChannel(...)`.
267
+ */
268
+ export interface MailNotificationContext {
269
+ ports: {
270
+ mailer: {
271
+ send(message: SendMailOptions): MaybePromise<{
272
+ id?: string;
273
+ provider?: string;
274
+ }>;
275
+ };
276
+ };
277
+ }
278
+ /**
279
+ * Render a mail message for one notification payload.
280
+ */
281
+ export type MailNotificationRenderer<Payload extends StandardSchema, Ctx extends MailNotificationContext> = (args: NotificationChannelHandleArgs<Payload, Ctx>) => MaybePromise<SendMailOptions | undefined>;
282
+ /**
283
+ * Context-bound notification helper factory.
284
+ */
285
+ export interface NotificationHandlers<Ctx> {
286
+ /**
287
+ * Define a notification with the bound context type.
288
+ */
289
+ defineNotification<Name extends string, Payload extends StandardSchema>(name: Name, options: DefineNotificationOptions<Payload, Ctx>): NotificationDef<Name, Payload, Ctx>;
290
+ /**
291
+ * Create an inline dispatcher with the bound context type.
292
+ */
293
+ createInlineNotificationDispatcher(options?: InlineNotificationDispatcherOptions<Ctx>): NotificationPort;
294
+ }
295
+ /**
296
+ * Error thrown when notification payload validation fails.
297
+ */
298
+ export declare class NotificationValidationError extends Error {
299
+ /**
300
+ * Raw Standard Schema validation issues.
301
+ */
302
+ readonly issues: readonly StandardSchemaV1.Issue[];
303
+ constructor(args: {
304
+ name: string;
305
+ issues: readonly StandardSchemaV1.Issue[];
306
+ });
307
+ }
308
+ /**
309
+ * Error thrown when notification delivery fails.
310
+ */
311
+ export declare class NotificationDeliveryError extends Error {
312
+ /**
313
+ * Notification name.
314
+ */
315
+ readonly notificationName: string;
316
+ /**
317
+ * Channel that failed.
318
+ */
319
+ readonly channel: string;
320
+ /**
321
+ * Original channel error.
322
+ */
323
+ readonly cause: unknown;
324
+ constructor(args: {
325
+ notificationName: string;
326
+ channel: string;
327
+ cause: unknown;
328
+ });
329
+ }
330
+ /**
331
+ * Define a typed notification.
332
+ *
333
+ * Notifications represent user-facing communication intent. Channel handlers
334
+ * decide how that intent becomes mail, SMS, push, in-app delivery, or another
335
+ * app-owned channel.
336
+ */
337
+ export declare function defineNotification<Name extends string, Payload extends StandardSchema, Ctx = unknown>(name: Name, options: DefineNotificationOptions<Payload, Ctx>): NotificationDef<Name, Payload, Ctx>;
338
+ /**
339
+ * Validate and parse a notification payload with the notification's Standard
340
+ * Schema.
341
+ */
342
+ export declare function parseNotificationPayload<N extends NotificationPayloadDef>(notification: N, payload: unknown): Promise<InferNotificationPayload<N>>;
343
+ /**
344
+ * Create an inline notification dispatcher.
345
+ *
346
+ * The dispatcher validates payloads and runs selected channel handlers
347
+ * immediately. Use this directly in tests and local apps, or wrap it in jobs
348
+ * and outbox delivery for production background execution.
349
+ */
350
+ export declare function createInlineNotificationDispatcher<Ctx>(options?: InlineNotificationDispatcherOptions<Ctx>): NotificationPort;
351
+ /**
352
+ * Define a mail-backed notification channel.
353
+ *
354
+ * Return `undefined` from the renderer when the channel should be skipped, for
355
+ * example when a recipient does not have an email address.
356
+ */
357
+ export declare function defineMailNotificationChannel<Payload extends StandardSchema, Ctx extends MailNotificationContext>(render: MailNotificationRenderer<Payload, Ctx>): NotificationChannelHandler<Payload, Ctx>;
358
+ /**
359
+ * Create an in-memory notification port for tests and examples.
360
+ *
361
+ * The memory port validates payloads and records notification intent without
362
+ * running channel handlers.
363
+ */
364
+ export declare function createMemoryNotificationPort(options?: CreateMemoryNotificationPortOptions): MemoryNotificationPort;
365
+ /**
366
+ * Create notification helper methods bound to an application context type.
367
+ */
368
+ export declare function createNotificationHandlers<Ctx>(): NotificationHandlers<Ctx>;
369
+ //# sourceMappingURL=index.d.ts.map