@closerepo/notification-contracts 1.0.1 → 1.2.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.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,87 @@
1
1
  import { z } from "zod";
2
2
  //#region src/index.d.ts
3
3
  declare const notificationDeliveryContractVersionV1: 1;
4
+ declare const notificationDeliveryContractVersionV2: 2;
5
+ declare const notificationDeliveryContractVersionV3: 3;
4
6
  declare const notificationDeliveryRequestMaximumUtf8BytesV1: number;
5
7
  declare const notificationDeliveryMaximumDeadlineMillisecondsV1: number;
8
+ declare const notificationDeliveryRequestMaximumUtf8BytesV2: number;
9
+ declare const notificationDeliveryMaximumDeadlineMillisecondsV2: number;
10
+ declare const notificationDeliveryRequestMaximumUtf8BytesV3: number;
11
+ declare const notificationDeliveryMaximumDeadlineMillisecondsV3: number;
6
12
  declare const notificationDeliveryStatesV1: readonly ["pending", "delivering", "partial", "delivered", "failed", "expired"];
7
13
  declare const notificationDeliveryReasonsV1: readonly ["accepted", "enqueue_retry_wait", "in_progress", "partial_delivery", "complete", "retry_exhausted", "delivery_deadline_exceeded", "destination_configuration_unavailable"];
8
14
  declare const notificationDestinationStatesV1: readonly ["pending", "delivering", "delivered", "failed", "expired"];
9
15
  declare const notificationDestinationFailureCodesV1: readonly ["provider_timeout", "provider_rate_limited", "provider_unavailable", "provider_rejected", "destination_configuration_unavailable", "delivery_interrupted", "retry_exhausted"];
10
16
  declare const notificationDeliveryRejectionCodesV1: readonly ["invalid_request", "request_too_large", "producer_scope_mismatch", "route_not_allowed", "event_identity_conflict", "route_not_found", "route_empty", "delivery_deadline_invalid"];
11
17
  declare const notificationValidationIssueCodesV1: readonly ["invalid_type", "invalid_value", "too_small", "too_big", "invalid_format", "unrecognized_keys", "custom"];
18
+ declare const notificationMessageVariantKeys: readonly ["source", "zh-CN"];
12
19
  declare const notificationDeliveryRequestV1Schema: z.ZodObject<{
20
+ message: z.ZodObject<{
21
+ type: z.ZodLiteral<"link_summary">;
22
+ title: z.ZodString;
23
+ summary: z.ZodString;
24
+ facts: z.ZodArray<z.ZodObject<{
25
+ label: z.ZodString;
26
+ value: z.ZodString;
27
+ }, z.core.$strict>>;
28
+ primaryLink: z.ZodObject<{
29
+ label: z.ZodString;
30
+ url: z.ZodString;
31
+ }, z.core.$strict>;
32
+ sourceLink: z.ZodOptional<z.ZodObject<{
33
+ label: z.ZodString;
34
+ url: z.ZodString;
35
+ }, z.core.$strict>>;
36
+ }, z.core.$strict>;
37
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
38
+ eventId: z.ZodString;
39
+ producer: z.ZodObject<{
40
+ key: z.ZodString;
41
+ environment: z.ZodString;
42
+ }, z.core.$strict>;
43
+ routeKey: z.ZodString;
44
+ occurredAt: z.ZodString;
45
+ requestedAt: z.ZodString;
46
+ deliverBy: z.ZodString;
47
+ subject: z.ZodObject<{
48
+ type: z.ZodString;
49
+ id: z.ZodString;
50
+ revision: z.ZodNumber;
51
+ }, z.core.$strict>;
13
52
  contractVersion: z.ZodLiteral<1>;
53
+ }, z.core.$strict>;
54
+ declare const notificationDeliveryRequestV2Schema: z.ZodObject<{
55
+ message: z.ZodObject<{
56
+ type: z.ZodLiteral<"localized_link_summary">;
57
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
58
+ title: z.ZodString;
59
+ summary: z.ZodString;
60
+ facts: z.ZodArray<z.ZodObject<{
61
+ label: z.ZodString;
62
+ value: z.ZodString;
63
+ }, z.core.$strict>>;
64
+ key: z.ZodLiteral<"source">;
65
+ locale: z.ZodLiteral<"und">;
66
+ }, z.core.$strict>, z.ZodObject<{
67
+ title: z.ZodString;
68
+ summary: z.ZodString;
69
+ facts: z.ZodArray<z.ZodObject<{
70
+ label: z.ZodString;
71
+ value: z.ZodString;
72
+ }, z.core.$strict>>;
73
+ key: z.ZodLiteral<"zh-CN">;
74
+ locale: z.ZodLiteral<"zh-CN">;
75
+ }, z.core.$strict>], "key">>;
76
+ primaryLink: z.ZodObject<{
77
+ label: z.ZodString;
78
+ url: z.ZodString;
79
+ }, z.core.$strict>;
80
+ sourceLink: z.ZodOptional<z.ZodObject<{
81
+ label: z.ZodString;
82
+ url: z.ZodString;
83
+ }, z.core.$strict>>;
84
+ }, z.core.$strict>;
14
85
  eventType: z.ZodLiteral<"notification.delivery.requested">;
15
86
  eventId: z.ZodString;
16
87
  producer: z.ZodObject<{
@@ -26,6 +97,118 @@ declare const notificationDeliveryRequestV1Schema: z.ZodObject<{
26
97
  id: z.ZodString;
27
98
  revision: z.ZodNumber;
28
99
  }, z.core.$strict>;
100
+ contractVersion: z.ZodLiteral<2>;
101
+ }, z.core.$strict>;
102
+ declare const structuredMessageSectionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
103
+ key: z.ZodString;
104
+ type: z.ZodLiteral<"text">;
105
+ label: z.ZodOptional<z.ZodString>;
106
+ value: z.ZodString;
107
+ }, z.core.$strict>, z.ZodObject<{
108
+ key: z.ZodString;
109
+ type: z.ZodLiteral<"fields">;
110
+ items: z.ZodArray<z.ZodObject<{
111
+ label: z.ZodString;
112
+ value: z.ZodString;
113
+ }, z.core.$strict>>;
114
+ }, z.core.$strict>], "type">;
115
+ declare const structuredNotificationVariantSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
116
+ key: z.ZodLiteral<"source">;
117
+ locale: z.ZodLiteral<"und">;
118
+ title: z.ZodString;
119
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
120
+ key: z.ZodString;
121
+ type: z.ZodLiteral<"text">;
122
+ label: z.ZodOptional<z.ZodString>;
123
+ value: z.ZodString;
124
+ }, z.core.$strict>, z.ZodObject<{
125
+ key: z.ZodString;
126
+ type: z.ZodLiteral<"fields">;
127
+ items: z.ZodArray<z.ZodObject<{
128
+ label: z.ZodString;
129
+ value: z.ZodString;
130
+ }, z.core.$strict>>;
131
+ }, z.core.$strict>], "type">>;
132
+ }, z.core.$strict>, z.ZodObject<{
133
+ key: z.ZodLiteral<"zh-CN">;
134
+ locale: z.ZodLiteral<"zh-CN">;
135
+ title: z.ZodString;
136
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
137
+ key: z.ZodString;
138
+ type: z.ZodLiteral<"text">;
139
+ label: z.ZodOptional<z.ZodString>;
140
+ value: z.ZodString;
141
+ }, z.core.$strict>, z.ZodObject<{
142
+ key: z.ZodString;
143
+ type: z.ZodLiteral<"fields">;
144
+ items: z.ZodArray<z.ZodObject<{
145
+ label: z.ZodString;
146
+ value: z.ZodString;
147
+ }, z.core.$strict>>;
148
+ }, z.core.$strict>], "type">>;
149
+ }, z.core.$strict>], "key">;
150
+ declare const notificationDeliveryRequestV3Schema: z.ZodObject<{
151
+ message: z.ZodObject<{
152
+ type: z.ZodLiteral<"structured_notification">;
153
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
154
+ key: z.ZodLiteral<"source">;
155
+ locale: z.ZodLiteral<"und">;
156
+ title: z.ZodString;
157
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
158
+ key: z.ZodString;
159
+ type: z.ZodLiteral<"text">;
160
+ label: z.ZodOptional<z.ZodString>;
161
+ value: z.ZodString;
162
+ }, z.core.$strict>, z.ZodObject<{
163
+ key: z.ZodString;
164
+ type: z.ZodLiteral<"fields">;
165
+ items: z.ZodArray<z.ZodObject<{
166
+ label: z.ZodString;
167
+ value: z.ZodString;
168
+ }, z.core.$strict>>;
169
+ }, z.core.$strict>], "type">>;
170
+ }, z.core.$strict>, z.ZodObject<{
171
+ key: z.ZodLiteral<"zh-CN">;
172
+ locale: z.ZodLiteral<"zh-CN">;
173
+ title: z.ZodString;
174
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
175
+ key: z.ZodString;
176
+ type: z.ZodLiteral<"text">;
177
+ label: z.ZodOptional<z.ZodString>;
178
+ value: z.ZodString;
179
+ }, z.core.$strict>, z.ZodObject<{
180
+ key: z.ZodString;
181
+ type: z.ZodLiteral<"fields">;
182
+ items: z.ZodArray<z.ZodObject<{
183
+ label: z.ZodString;
184
+ value: z.ZodString;
185
+ }, z.core.$strict>>;
186
+ }, z.core.$strict>], "type">>;
187
+ }, z.core.$strict>], "key">>;
188
+ links: z.ZodArray<z.ZodObject<{
189
+ label: z.ZodString;
190
+ url: z.ZodString;
191
+ key: z.ZodString;
192
+ }, z.core.$strict>>;
193
+ }, z.core.$strict>;
194
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
195
+ eventId: z.ZodString;
196
+ producer: z.ZodObject<{
197
+ key: z.ZodString;
198
+ environment: z.ZodString;
199
+ }, z.core.$strict>;
200
+ routeKey: z.ZodString;
201
+ occurredAt: z.ZodString;
202
+ requestedAt: z.ZodString;
203
+ deliverBy: z.ZodString;
204
+ subject: z.ZodObject<{
205
+ type: z.ZodString;
206
+ id: z.ZodString;
207
+ revision: z.ZodNumber;
208
+ }, z.core.$strict>;
209
+ contractVersion: z.ZodLiteral<3>;
210
+ }, z.core.$strict>;
211
+ declare const notificationDeliveryRequestSchema: z.ZodUnion<readonly [z.ZodObject<{
29
212
  message: z.ZodObject<{
30
213
  type: z.ZodLiteral<"link_summary">;
31
214
  title: z.ZodString;
@@ -43,7 +226,130 @@ declare const notificationDeliveryRequestV1Schema: z.ZodObject<{
43
226
  url: z.ZodString;
44
227
  }, z.core.$strict>>;
45
228
  }, z.core.$strict>;
46
- }, z.core.$strict>;
229
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
230
+ eventId: z.ZodString;
231
+ producer: z.ZodObject<{
232
+ key: z.ZodString;
233
+ environment: z.ZodString;
234
+ }, z.core.$strict>;
235
+ routeKey: z.ZodString;
236
+ occurredAt: z.ZodString;
237
+ requestedAt: z.ZodString;
238
+ deliverBy: z.ZodString;
239
+ subject: z.ZodObject<{
240
+ type: z.ZodString;
241
+ id: z.ZodString;
242
+ revision: z.ZodNumber;
243
+ }, z.core.$strict>;
244
+ contractVersion: z.ZodLiteral<1>;
245
+ }, z.core.$strict>, z.ZodObject<{
246
+ message: z.ZodObject<{
247
+ type: z.ZodLiteral<"localized_link_summary">;
248
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
249
+ title: z.ZodString;
250
+ summary: z.ZodString;
251
+ facts: z.ZodArray<z.ZodObject<{
252
+ label: z.ZodString;
253
+ value: z.ZodString;
254
+ }, z.core.$strict>>;
255
+ key: z.ZodLiteral<"source">;
256
+ locale: z.ZodLiteral<"und">;
257
+ }, z.core.$strict>, z.ZodObject<{
258
+ title: z.ZodString;
259
+ summary: z.ZodString;
260
+ facts: z.ZodArray<z.ZodObject<{
261
+ label: z.ZodString;
262
+ value: z.ZodString;
263
+ }, z.core.$strict>>;
264
+ key: z.ZodLiteral<"zh-CN">;
265
+ locale: z.ZodLiteral<"zh-CN">;
266
+ }, z.core.$strict>], "key">>;
267
+ primaryLink: z.ZodObject<{
268
+ label: z.ZodString;
269
+ url: z.ZodString;
270
+ }, z.core.$strict>;
271
+ sourceLink: z.ZodOptional<z.ZodObject<{
272
+ label: z.ZodString;
273
+ url: z.ZodString;
274
+ }, z.core.$strict>>;
275
+ }, z.core.$strict>;
276
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
277
+ eventId: z.ZodString;
278
+ producer: z.ZodObject<{
279
+ key: z.ZodString;
280
+ environment: z.ZodString;
281
+ }, z.core.$strict>;
282
+ routeKey: z.ZodString;
283
+ occurredAt: z.ZodString;
284
+ requestedAt: z.ZodString;
285
+ deliverBy: z.ZodString;
286
+ subject: z.ZodObject<{
287
+ type: z.ZodString;
288
+ id: z.ZodString;
289
+ revision: z.ZodNumber;
290
+ }, z.core.$strict>;
291
+ contractVersion: z.ZodLiteral<2>;
292
+ }, z.core.$strict>, z.ZodObject<{
293
+ message: z.ZodObject<{
294
+ type: z.ZodLiteral<"structured_notification">;
295
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
296
+ key: z.ZodLiteral<"source">;
297
+ locale: z.ZodLiteral<"und">;
298
+ title: z.ZodString;
299
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
300
+ key: z.ZodString;
301
+ type: z.ZodLiteral<"text">;
302
+ label: z.ZodOptional<z.ZodString>;
303
+ value: z.ZodString;
304
+ }, z.core.$strict>, z.ZodObject<{
305
+ key: z.ZodString;
306
+ type: z.ZodLiteral<"fields">;
307
+ items: z.ZodArray<z.ZodObject<{
308
+ label: z.ZodString;
309
+ value: z.ZodString;
310
+ }, z.core.$strict>>;
311
+ }, z.core.$strict>], "type">>;
312
+ }, z.core.$strict>, z.ZodObject<{
313
+ key: z.ZodLiteral<"zh-CN">;
314
+ locale: z.ZodLiteral<"zh-CN">;
315
+ title: z.ZodString;
316
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
317
+ key: z.ZodString;
318
+ type: z.ZodLiteral<"text">;
319
+ label: z.ZodOptional<z.ZodString>;
320
+ value: z.ZodString;
321
+ }, z.core.$strict>, z.ZodObject<{
322
+ key: z.ZodString;
323
+ type: z.ZodLiteral<"fields">;
324
+ items: z.ZodArray<z.ZodObject<{
325
+ label: z.ZodString;
326
+ value: z.ZodString;
327
+ }, z.core.$strict>>;
328
+ }, z.core.$strict>], "type">>;
329
+ }, z.core.$strict>], "key">>;
330
+ links: z.ZodArray<z.ZodObject<{
331
+ label: z.ZodString;
332
+ url: z.ZodString;
333
+ key: z.ZodString;
334
+ }, z.core.$strict>>;
335
+ }, z.core.$strict>;
336
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
337
+ eventId: z.ZodString;
338
+ producer: z.ZodObject<{
339
+ key: z.ZodString;
340
+ environment: z.ZodString;
341
+ }, z.core.$strict>;
342
+ routeKey: z.ZodString;
343
+ occurredAt: z.ZodString;
344
+ requestedAt: z.ZodString;
345
+ deliverBy: z.ZodString;
346
+ subject: z.ZodObject<{
347
+ type: z.ZodString;
348
+ id: z.ZodString;
349
+ revision: z.ZodNumber;
350
+ }, z.core.$strict>;
351
+ contractVersion: z.ZodLiteral<3>;
352
+ }, z.core.$strict>]>;
47
353
  declare const notificationDeliveryReceiptV1Schema: z.ZodObject<{
48
354
  contractVersion: z.ZodLiteral<1>;
49
355
  eventId: z.ZodString;
@@ -290,6 +596,12 @@ declare const notificationGetReceiptResultV1Schema: z.ZodDiscriminatedUnion<[z.Z
290
596
  }, z.core.$strict>;
291
597
  }, z.core.$strict>], "status">;
292
598
  type NotificationDeliveryRequestV1 = z.infer<typeof notificationDeliveryRequestV1Schema>;
599
+ type NotificationDeliveryRequestV2 = z.infer<typeof notificationDeliveryRequestV2Schema>;
600
+ type NotificationDeliveryRequestV3 = z.infer<typeof notificationDeliveryRequestV3Schema>;
601
+ type NotificationDeliveryRequest = z.infer<typeof notificationDeliveryRequestSchema>;
602
+ type NotificationMessageVariantKey = (typeof notificationMessageVariantKeys)[number];
603
+ type NotificationStructuredMessageSection = z.infer<typeof structuredMessageSectionSchema>;
604
+ type NotificationStructuredMessageVariant = z.infer<typeof structuredNotificationVariantSchema>;
293
605
  type NotificationDeliveryReceiptV1 = z.infer<typeof notificationDeliveryReceiptV1Schema>;
294
606
  type NotificationDeliveryRejectionV1 = z.infer<typeof notificationDeliveryRejectionV1Schema>;
295
607
  type NotificationDeliverResultV1 = z.infer<typeof notificationDeliverResultV1Schema>;
@@ -299,5 +611,10 @@ interface NotificationDeliveryServiceV1 {
299
611
  deliver: (request: NotificationDeliveryRequestV1) => Promise<NotificationDeliverResultV1>;
300
612
  getReceipt: (eventId: string) => Promise<NotificationGetReceiptResultV1>;
301
613
  }
614
+ /** Private Service Binding contract accepting all published request versions. */
615
+ interface NotificationDeliveryServiceV2 {
616
+ deliver: (request: NotificationDeliveryRequest) => Promise<NotificationDeliverResultV1>;
617
+ getReceipt: (eventId: string) => Promise<NotificationGetReceiptResultV1>;
618
+ }
302
619
  //#endregion
303
- export { NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequestV1, NotificationDeliveryServiceV1, NotificationGetReceiptResultV1, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestV1Schema, notificationDeliveryStatesV1, notificationDestinationFailureCodesV1, notificationDestinationStatesV1, notificationGetReceiptResultV1Schema, notificationValidationIssueCodesV1 };
620
+ export { NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequest, NotificationDeliveryRequestV1, NotificationDeliveryRequestV2, NotificationDeliveryRequestV3, NotificationDeliveryServiceV1, NotificationDeliveryServiceV2, NotificationGetReceiptResultV1, NotificationMessageVariantKey, NotificationStructuredMessageSection, NotificationStructuredMessageVariant, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryContractVersionV2, notificationDeliveryContractVersionV3, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryMaximumDeadlineMillisecondsV2, notificationDeliveryMaximumDeadlineMillisecondsV3, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestMaximumUtf8BytesV2, notificationDeliveryRequestMaximumUtf8BytesV3, notificationDeliveryRequestSchema, notificationDeliveryRequestV1Schema, notificationDeliveryRequestV2Schema, notificationDeliveryRequestV3Schema, notificationDeliveryStatesV1, notificationDestinationFailureCodesV1, notificationDestinationStatesV1, notificationGetReceiptResultV1Schema, notificationMessageVariantKeys, notificationValidationIssueCodesV1 };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{z as e}from"zod";const t=1,n=32*1024,r=1380*60*1e3,i=[`pending`,`delivering`,`partial`,`delivered`,`failed`,`expired`],a=[`accepted`,`enqueue_retry_wait`,`in_progress`,`partial_delivery`,`complete`,`retry_exhausted`,`delivery_deadline_exceeded`,`destination_configuration_unavailable`],o=[`pending`,`delivering`,`delivered`,`failed`,`expired`],s=[`provider_timeout`,`provider_rate_limited`,`provider_unavailable`,`provider_rejected`,`destination_configuration_unavailable`,`delivery_interrupted`,`retry_exhausted`],c=[`invalid_request`,`request_too_large`,`producer_scope_mismatch`,`route_not_allowed`,`event_identity_conflict`,`route_not_found`,`route_empty`,`delivery_deadline_invalid`],l=[`invalid_type`,`invalid_value`,`too_small`,`too_big`,`invalid_format`,`unrecognized_keys`,`custom`],u=new TextEncoder,d=/^[a-z][a-z0-9-]{0,62}$/,f=/^[a-z][a-z0-9-]{0,31}(?:\.[a-z][a-z0-9-]{0,31}){1,3}$/,p=/^[A-Z0-9][\w.:-]{0,127}$/i;function m(e){return[...e].length}function h(t){return e.string().refine(e=>m(e)>0,{message:`too_small`}).refine(e=>m(e)<=t,{message:`too_big`})}const g=e.string().datetime({offset:!0}),_=e.object({key:e.string().regex(d),environment:e.string().regex(d)}).strict(),v=e.object({type:e.string().regex(d),id:e.string().regex(p),revision:e.number().int().positive()}).strict(),y=e.string().min(1).max(127).regex(f),b=e.object({label:h(48),url:h(2048).refine(e=>[...e].every(e=>{let t=e.codePointAt(0);return t!==void 0&&t>31&&t!==127}),{message:`invalid_https_url`}).refine(e=>{try{return new URL(e).protocol===`https:`}catch{return!1}},{message:`invalid_https_url`})}).strict(),x=e.object({contractVersion:e.literal(1),eventType:e.literal(`notification.delivery.requested`),eventId:e.string().uuid(),producer:_,routeKey:y,occurredAt:g,requestedAt:g,deliverBy:g,subject:v,message:e.object({type:e.literal(`link_summary`),title:h(160),summary:h(1200),facts:e.array(e.object({label:h(48),value:h(500)}).strict()).max(10),primaryLink:b,sourceLink:b.optional()}).strict()}).strict().superRefine((e,t)=>{let n=Date.parse(e.requestedAt),r=Date.parse(e.deliverBy);(!Number.isFinite(n)||!Number.isFinite(r)||r<=n||r-n>828e5)&&t.addIssue({code:`custom`,message:`delivery_deadline_invalid`,path:[`deliverBy`]}),u.encode(JSON.stringify(e)).byteLength>32768&&t.addIssue({code:`custom`,message:`request_too_large`})}),S=e.object({destinationKey:e.string().min(1),state:e.enum(o),attempts:e.number().int().min(0).max(4),failureCode:e.enum(s).nullable(),lastAttemptAt:g.nullable(),nextAttemptAt:g.nullable(),leaseExpiresAt:g.nullable()}).strict(),C=e.object({contractVersion:e.literal(1),eventId:e.string().uuid(),producer:_,routeKey:y,subject:v,state:e.enum(i),reason:e.enum(a),terminal:e.boolean(),acceptedAt:g,updatedAt:g,deliverBy:g,terminalAt:g.nullable(),destinations:e.array(S).min(1).max(20)}).strict(),w=e.object({path:e.array(e.union([e.string(),e.number().int().min(0)])).max(16),code:e.enum(l)}).strict(),T=e.object({code:e.literal(`invalid_request`),issues:e.array(w).max(20).optional()}).strict(),E=e.object({code:e.enum(c.filter(e=>e!==`invalid_request`))}).strict(),D=e.union([T,E]),O=e.discriminatedUnion(`status`,[e.object({status:e.literal(`accepted`),receipt:C}).strict(),e.object({status:e.literal(`rejected`),error:D}).strict()]),k=e.discriminatedUnion(`status`,[e.object({status:e.literal(`found`),receipt:C}).strict(),e.object({status:e.literal(`not_found`)}).strict(),e.object({status:e.literal(`unavailable`),error:e.object({code:e.literal(`receipt_unavailable`)}).strict()}).strict()]);export{O as notificationDeliverResultV1Schema,t as notificationDeliveryContractVersionV1,r as notificationDeliveryMaximumDeadlineMillisecondsV1,a as notificationDeliveryReasonsV1,C as notificationDeliveryReceiptV1Schema,c as notificationDeliveryRejectionCodesV1,D as notificationDeliveryRejectionV1Schema,n as notificationDeliveryRequestMaximumUtf8BytesV1,x as notificationDeliveryRequestV1Schema,i as notificationDeliveryStatesV1,s as notificationDestinationFailureCodesV1,o as notificationDestinationStatesV1,k as notificationGetReceiptResultV1Schema,l as notificationValidationIssueCodesV1};
1
+ import{z as e}from"zod";const t=1,n=2,r=3,i=32*1024,a=1380*60*1e3,o=i,s=a,c=i,l=a,u=[`pending`,`delivering`,`partial`,`delivered`,`failed`,`expired`],d=[`accepted`,`enqueue_retry_wait`,`in_progress`,`partial_delivery`,`complete`,`retry_exhausted`,`delivery_deadline_exceeded`,`destination_configuration_unavailable`],f=[`pending`,`delivering`,`delivered`,`failed`,`expired`],p=[`provider_timeout`,`provider_rate_limited`,`provider_unavailable`,`provider_rejected`,`destination_configuration_unavailable`,`delivery_interrupted`,`retry_exhausted`],m=[`invalid_request`,`request_too_large`,`producer_scope_mismatch`,`route_not_allowed`,`event_identity_conflict`,`route_not_found`,`route_empty`,`delivery_deadline_invalid`],h=[`invalid_type`,`invalid_value`,`too_small`,`too_big`,`invalid_format`,`unrecognized_keys`,`custom`],g=[`source`,`zh-CN`],_=new TextEncoder,v=/^[a-z][a-z0-9-]{0,62}$/,y=/^[a-z][a-z0-9-]{0,31}(?:\.[a-z][a-z0-9-]{0,31}){1,3}$/,b=/^[A-Z0-9][\w.:-]{0,127}$/i;function x(e){return[...e].length}function S(t){return e.string().refine(e=>x(e)>0,{message:`too_small`}).refine(e=>x(e)<=t,{message:`too_big`})}const C=e.string().datetime({offset:!0}),w=e.object({key:e.string().regex(v),environment:e.string().regex(v)}).strict(),T=e.object({type:e.string().regex(v),id:e.string().regex(b),revision:e.number().int().positive()}).strict(),E=e.string().min(1).max(127).regex(y),D=e.object({label:S(48),url:S(2048).refine(e=>[...e].every(e=>{let t=e.codePointAt(0);return t!==void 0&&t>31&&t!==127}),{message:`invalid_https_url`}).refine(e=>{try{return new URL(e).protocol===`https:`}catch{return!1}},{message:`invalid_https_url`})}).strict(),O={eventType:e.literal(`notification.delivery.requested`),eventId:e.string().uuid(),producer:w,routeKey:E,occurredAt:C,requestedAt:C,deliverBy:C,subject:T},k=e.object({contractVersion:e.literal(1),...O,message:e.object({type:e.literal(`link_summary`),title:S(160),summary:S(1200),facts:e.array(e.object({label:S(48),value:S(500)}).strict()).max(10),primaryLink:D,sourceLink:D.optional()}).strict()}).strict();function A(e,t,n,r){let i=Date.parse(e.requestedAt),a=Date.parse(e.deliverBy);(!Number.isFinite(i)||!Number.isFinite(a)||a<=i||a-i>n)&&t.addIssue({code:`custom`,message:`delivery_deadline_invalid`,path:[`deliverBy`]}),_.encode(JSON.stringify(e)).byteLength>r&&t.addIssue({code:`custom`,message:`request_too_large`})}const j=k.superRefine((e,t)=>A(e,t,a,i)),M={title:S(160),summary:S(1200),facts:e.array(e.object({label:S(48),value:S(500)}).strict()).max(10)},N=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),...M}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),...M}).strict()]),P=e.array(N).min(1).max(2).superRefine((e,t)=>{e.filter(e=>e.key===`source`).length!==1&&t.addIssue({code:`custom`,message:`source_variant_required_once`}),new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_variant_duplicate`})}),F=e.object({contractVersion:e.literal(2),...O,message:e.object({type:e.literal(`localized_link_summary`),variants:P,primaryLink:D,sourceLink:D.optional()}).strict()}).strict().superRefine((e,t)=>A(e,t,s,o)),I=e.discriminatedUnion(`type`,[e.object({key:e.string().regex(v),type:e.literal(`text`),label:S(48).optional(),value:S(4e3)}).strict(),e.object({key:e.string().regex(v),type:e.literal(`fields`),items:e.array(e.object({label:S(48),value:S(1200)}).strict()).min(1).max(20)}).strict()]),L=e.array(I).min(1).max(30).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_section_duplicate`})}),R=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),title:S(160),sections:L}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),title:S(160),sections:L}).strict()]),z=e.array(R).min(1).max(2).superRefine((e,t)=>{e.filter(e=>e.key===`source`).length!==1&&t.addIssue({code:`custom`,message:`source_variant_required_once`}),new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_variant_duplicate`});let n=e.find(e=>e.key===`source`),r=e.find(e=>e.key===`zh-CN`);if(n&&r){let i=n.sections.map(e=>`${e.key}:${e.type}`),a=r.sections.map(e=>`${e.key}:${e.type}`);JSON.stringify(i)!==JSON.stringify(a)&&t.addIssue({code:`custom`,message:`message_variant_structure_mismatch`,path:[e.indexOf(r),`sections`]})}}),B=e.object({contractVersion:e.literal(3),...O,message:e.object({type:e.literal(`structured_notification`),variants:z,links:e.array(e.object({key:e.string().regex(v),...D.shape}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_duplicate`})})}).strict()}).strict().superRefine((e,t)=>A(e,t,l,c)),V=e.union([j,F,B]),H=e.object({destinationKey:e.string().min(1),state:e.enum(f),attempts:e.number().int().min(0).max(4),failureCode:e.enum(p).nullable(),lastAttemptAt:C.nullable(),nextAttemptAt:C.nullable(),leaseExpiresAt:C.nullable()}).strict(),U=e.object({contractVersion:e.literal(1),eventId:e.string().uuid(),producer:w,routeKey:E,subject:T,state:e.enum(u),reason:e.enum(d),terminal:e.boolean(),acceptedAt:C,updatedAt:C,deliverBy:C,terminalAt:C.nullable(),destinations:e.array(H).min(1).max(20)}).strict(),W=e.object({path:e.array(e.union([e.string(),e.number().int().min(0)])).max(16),code:e.enum(h)}).strict(),G=e.object({code:e.literal(`invalid_request`),issues:e.array(W).max(20).optional()}).strict(),K=e.object({code:e.enum(m.filter(e=>e!==`invalid_request`))}).strict(),q=e.union([G,K]),J=e.discriminatedUnion(`status`,[e.object({status:e.literal(`accepted`),receipt:U}).strict(),e.object({status:e.literal(`rejected`),error:q}).strict()]),Y=e.discriminatedUnion(`status`,[e.object({status:e.literal(`found`),receipt:U}).strict(),e.object({status:e.literal(`not_found`)}).strict(),e.object({status:e.literal(`unavailable`),error:e.object({code:e.literal(`receipt_unavailable`)}).strict()}).strict()]);export{J as notificationDeliverResultV1Schema,t as notificationDeliveryContractVersionV1,n as notificationDeliveryContractVersionV2,r as notificationDeliveryContractVersionV3,a as notificationDeliveryMaximumDeadlineMillisecondsV1,s as notificationDeliveryMaximumDeadlineMillisecondsV2,l as notificationDeliveryMaximumDeadlineMillisecondsV3,d as notificationDeliveryReasonsV1,U as notificationDeliveryReceiptV1Schema,m as notificationDeliveryRejectionCodesV1,q as notificationDeliveryRejectionV1Schema,i as notificationDeliveryRequestMaximumUtf8BytesV1,o as notificationDeliveryRequestMaximumUtf8BytesV2,c as notificationDeliveryRequestMaximumUtf8BytesV3,V as notificationDeliveryRequestSchema,j as notificationDeliveryRequestV1Schema,F as notificationDeliveryRequestV2Schema,B as notificationDeliveryRequestV3Schema,u as notificationDeliveryStatesV1,p as notificationDestinationFailureCodesV1,f as notificationDestinationStatesV1,Y as notificationGetReceiptResultV1Schema,g as notificationMessageVariantKeys,h as notificationValidationIssueCodesV1};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@closerepo/notification-contracts",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {