@closerepo/notification-contracts 1.2.0 → 1.3.1

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
@@ -3,12 +3,15 @@ import { z } from "zod";
3
3
  declare const notificationDeliveryContractVersionV1: 1;
4
4
  declare const notificationDeliveryContractVersionV2: 2;
5
5
  declare const notificationDeliveryContractVersionV3: 3;
6
+ declare const notificationDeliveryContractVersionV4: 4;
6
7
  declare const notificationDeliveryRequestMaximumUtf8BytesV1: number;
7
8
  declare const notificationDeliveryMaximumDeadlineMillisecondsV1: number;
8
9
  declare const notificationDeliveryRequestMaximumUtf8BytesV2: number;
9
10
  declare const notificationDeliveryMaximumDeadlineMillisecondsV2: number;
10
11
  declare const notificationDeliveryRequestMaximumUtf8BytesV3: number;
11
12
  declare const notificationDeliveryMaximumDeadlineMillisecondsV3: number;
13
+ declare const notificationDeliveryRequestMaximumUtf8BytesV4: number;
14
+ declare const notificationDeliveryMaximumDeadlineMillisecondsV4: number;
12
15
  declare const notificationDeliveryStatesV1: readonly ["pending", "delivering", "partial", "delivered", "failed", "expired"];
13
16
  declare const notificationDeliveryReasonsV1: readonly ["accepted", "enqueue_retry_wait", "in_progress", "partial_delivery", "complete", "retry_exhausted", "delivery_deadline_exceeded", "destination_configuration_unavailable"];
14
17
  declare const notificationDestinationStatesV1: readonly ["pending", "delivering", "delivered", "failed", "expired"];
@@ -208,6 +211,79 @@ declare const notificationDeliveryRequestV3Schema: z.ZodObject<{
208
211
  }, z.core.$strict>;
209
212
  contractVersion: z.ZodLiteral<3>;
210
213
  }, z.core.$strict>;
214
+ declare const notificationMessageBodySchema: z.ZodObject<{
215
+ label: z.ZodOptional<z.ZodString>;
216
+ value: z.ZodString;
217
+ }, z.core.$strict>;
218
+ declare const notificationDeliveryRequestV4Schema: z.ZodObject<{
219
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
220
+ eventId: z.ZodString;
221
+ producer: z.ZodObject<{
222
+ key: z.ZodString;
223
+ environment: z.ZodString;
224
+ }, z.core.$strict>;
225
+ routeKey: z.ZodString;
226
+ occurredAt: z.ZodString;
227
+ requestedAt: z.ZodString;
228
+ deliverBy: z.ZodString;
229
+ subject: z.ZodObject<{
230
+ type: z.ZodString;
231
+ id: z.ZodString;
232
+ revision: z.ZodNumber;
233
+ }, z.core.$strict>;
234
+ contractVersion: z.ZodLiteral<4>;
235
+ message: z.ZodObject<{
236
+ type: z.ZodLiteral<"structured_notification">;
237
+ links: z.ZodArray<z.ZodObject<{
238
+ label: z.ZodString;
239
+ url: z.ZodString;
240
+ key: z.ZodString;
241
+ }, z.core.$strict>>;
242
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
243
+ key: z.ZodLiteral<"source">;
244
+ locale: z.ZodLiteral<"und">;
245
+ title: z.ZodString;
246
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
247
+ key: z.ZodString;
248
+ type: z.ZodLiteral<"text">;
249
+ label: z.ZodOptional<z.ZodString>;
250
+ value: z.ZodString;
251
+ }, z.core.$strict>, z.ZodObject<{
252
+ key: z.ZodString;
253
+ type: z.ZodLiteral<"fields">;
254
+ items: z.ZodArray<z.ZodObject<{
255
+ label: z.ZodString;
256
+ value: z.ZodString;
257
+ }, z.core.$strict>>;
258
+ }, z.core.$strict>], "type">>;
259
+ body: z.ZodObject<{
260
+ label: z.ZodOptional<z.ZodString>;
261
+ value: z.ZodString;
262
+ }, z.core.$strict>;
263
+ }, z.core.$strict>, z.ZodObject<{
264
+ key: z.ZodLiteral<"zh-CN">;
265
+ locale: z.ZodLiteral<"zh-CN">;
266
+ title: z.ZodString;
267
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
268
+ key: z.ZodString;
269
+ type: z.ZodLiteral<"text">;
270
+ label: z.ZodOptional<z.ZodString>;
271
+ value: z.ZodString;
272
+ }, z.core.$strict>, z.ZodObject<{
273
+ key: z.ZodString;
274
+ type: z.ZodLiteral<"fields">;
275
+ items: z.ZodArray<z.ZodObject<{
276
+ label: z.ZodString;
277
+ value: z.ZodString;
278
+ }, z.core.$strict>>;
279
+ }, z.core.$strict>], "type">>;
280
+ body: z.ZodObject<{
281
+ label: z.ZodOptional<z.ZodString>;
282
+ value: z.ZodString;
283
+ }, z.core.$strict>;
284
+ }, z.core.$strict>], "key">>;
285
+ }, z.core.$strict>;
286
+ }, z.core.$strict>;
211
287
  declare const notificationDeliveryRequestSchema: z.ZodUnion<readonly [z.ZodObject<{
212
288
  message: z.ZodObject<{
213
289
  type: z.ZodLiteral<"link_summary">;
@@ -349,6 +425,74 @@ declare const notificationDeliveryRequestSchema: z.ZodUnion<readonly [z.ZodObjec
349
425
  revision: z.ZodNumber;
350
426
  }, z.core.$strict>;
351
427
  contractVersion: z.ZodLiteral<3>;
428
+ }, z.core.$strict>, z.ZodObject<{
429
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
430
+ eventId: z.ZodString;
431
+ producer: z.ZodObject<{
432
+ key: z.ZodString;
433
+ environment: z.ZodString;
434
+ }, z.core.$strict>;
435
+ routeKey: z.ZodString;
436
+ occurredAt: z.ZodString;
437
+ requestedAt: z.ZodString;
438
+ deliverBy: z.ZodString;
439
+ subject: z.ZodObject<{
440
+ type: z.ZodString;
441
+ id: z.ZodString;
442
+ revision: z.ZodNumber;
443
+ }, z.core.$strict>;
444
+ contractVersion: z.ZodLiteral<4>;
445
+ message: z.ZodObject<{
446
+ type: z.ZodLiteral<"structured_notification">;
447
+ links: z.ZodArray<z.ZodObject<{
448
+ label: z.ZodString;
449
+ url: z.ZodString;
450
+ key: z.ZodString;
451
+ }, z.core.$strict>>;
452
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
453
+ key: z.ZodLiteral<"source">;
454
+ locale: z.ZodLiteral<"und">;
455
+ title: z.ZodString;
456
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
457
+ key: z.ZodString;
458
+ type: z.ZodLiteral<"text">;
459
+ label: z.ZodOptional<z.ZodString>;
460
+ value: z.ZodString;
461
+ }, z.core.$strict>, z.ZodObject<{
462
+ key: z.ZodString;
463
+ type: z.ZodLiteral<"fields">;
464
+ items: z.ZodArray<z.ZodObject<{
465
+ label: z.ZodString;
466
+ value: z.ZodString;
467
+ }, z.core.$strict>>;
468
+ }, z.core.$strict>], "type">>;
469
+ body: z.ZodObject<{
470
+ label: z.ZodOptional<z.ZodString>;
471
+ value: z.ZodString;
472
+ }, z.core.$strict>;
473
+ }, z.core.$strict>, z.ZodObject<{
474
+ key: z.ZodLiteral<"zh-CN">;
475
+ locale: z.ZodLiteral<"zh-CN">;
476
+ title: z.ZodString;
477
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
478
+ key: z.ZodString;
479
+ type: z.ZodLiteral<"text">;
480
+ label: z.ZodOptional<z.ZodString>;
481
+ value: z.ZodString;
482
+ }, z.core.$strict>, z.ZodObject<{
483
+ key: z.ZodString;
484
+ type: z.ZodLiteral<"fields">;
485
+ items: z.ZodArray<z.ZodObject<{
486
+ label: z.ZodString;
487
+ value: z.ZodString;
488
+ }, z.core.$strict>>;
489
+ }, z.core.$strict>], "type">>;
490
+ body: z.ZodObject<{
491
+ label: z.ZodOptional<z.ZodString>;
492
+ value: z.ZodString;
493
+ }, z.core.$strict>;
494
+ }, z.core.$strict>], "key">>;
495
+ }, z.core.$strict>;
352
496
  }, z.core.$strict>]>;
353
497
  declare const notificationDeliveryReceiptV1Schema: z.ZodObject<{
354
498
  contractVersion: z.ZodLiteral<1>;
@@ -598,10 +742,12 @@ declare const notificationGetReceiptResultV1Schema: z.ZodDiscriminatedUnion<[z.Z
598
742
  type NotificationDeliveryRequestV1 = z.infer<typeof notificationDeliveryRequestV1Schema>;
599
743
  type NotificationDeliveryRequestV2 = z.infer<typeof notificationDeliveryRequestV2Schema>;
600
744
  type NotificationDeliveryRequestV3 = z.infer<typeof notificationDeliveryRequestV3Schema>;
745
+ type NotificationDeliveryRequestV4 = z.infer<typeof notificationDeliveryRequestV4Schema>;
601
746
  type NotificationDeliveryRequest = z.infer<typeof notificationDeliveryRequestSchema>;
602
747
  type NotificationMessageVariantKey = (typeof notificationMessageVariantKeys)[number];
603
748
  type NotificationStructuredMessageSection = z.infer<typeof structuredMessageSectionSchema>;
604
749
  type NotificationStructuredMessageVariant = z.infer<typeof structuredNotificationVariantSchema>;
750
+ type NotificationMessageBody = z.infer<typeof notificationMessageBodySchema>;
605
751
  type NotificationDeliveryReceiptV1 = z.infer<typeof notificationDeliveryReceiptV1Schema>;
606
752
  type NotificationDeliveryRejectionV1 = z.infer<typeof notificationDeliveryRejectionV1Schema>;
607
753
  type NotificationDeliverResultV1 = z.infer<typeof notificationDeliverResultV1Schema>;
@@ -617,4 +763,4 @@ interface NotificationDeliveryServiceV2 {
617
763
  getReceipt: (eventId: string) => Promise<NotificationGetReceiptResultV1>;
618
764
  }
619
765
  //#endregion
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 };
766
+ export { NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequest, NotificationDeliveryRequestV1, NotificationDeliveryRequestV2, NotificationDeliveryRequestV3, NotificationDeliveryRequestV4, NotificationDeliveryServiceV1, NotificationDeliveryServiceV2, NotificationGetReceiptResultV1, NotificationMessageBody, NotificationMessageVariantKey, NotificationStructuredMessageSection, NotificationStructuredMessageVariant, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryContractVersionV2, notificationDeliveryContractVersionV3, notificationDeliveryContractVersionV4, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryMaximumDeadlineMillisecondsV2, notificationDeliveryMaximumDeadlineMillisecondsV3, notificationDeliveryMaximumDeadlineMillisecondsV4, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestMaximumUtf8BytesV2, notificationDeliveryRequestMaximumUtf8BytesV3, notificationDeliveryRequestMaximumUtf8BytesV4, notificationDeliveryRequestSchema, notificationDeliveryRequestV1Schema, notificationDeliveryRequestV2Schema, notificationDeliveryRequestV3Schema, notificationDeliveryRequestV4Schema, notificationDeliveryStatesV1, notificationDestinationFailureCodesV1, notificationDestinationStatesV1, notificationGetReceiptResultV1Schema, notificationMessageVariantKeys, notificationValidationIssueCodesV1 };
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import{z as e}from"zod";const t=1,n=2,r=3,i=4,a=32*1024,o=1380*60*1e3,s=a,c=o,l=a,u=o,d=a,f=o,p=[`pending`,`delivering`,`partial`,`delivered`,`failed`,`expired`],m=[`accepted`,`enqueue_retry_wait`,`in_progress`,`partial_delivery`,`complete`,`retry_exhausted`,`delivery_deadline_exceeded`,`destination_configuration_unavailable`],h=[`pending`,`delivering`,`delivered`,`failed`,`expired`],g=[`provider_timeout`,`provider_rate_limited`,`provider_unavailable`,`provider_rejected`,`destination_configuration_unavailable`,`delivery_interrupted`,`retry_exhausted`],_=[`invalid_request`,`request_too_large`,`producer_scope_mismatch`,`route_not_allowed`,`event_identity_conflict`,`route_not_found`,`route_empty`,`delivery_deadline_invalid`],v=[`invalid_type`,`invalid_value`,`too_small`,`too_big`,`invalid_format`,`unrecognized_keys`,`custom`],y=[`source`,`zh-CN`],ee=new TextEncoder,b=/^[a-z][a-z0-9-]{0,62}$/,x=/^[a-z][a-z0-9-]{0,31}(?:\.[a-z][a-z0-9-]{0,31}){1,3}$/,S=/^[A-Z0-9][\w.:-]{0,127}$/i;function C(e){return[...e].length}function w(t){return e.string().refine(e=>C(e)>0,{message:`too_small`}).refine(e=>C(e)<=t,{message:`too_big`})}const T=e.string().datetime({offset:!0}),E=e.object({key:e.string().regex(b),environment:e.string().regex(b)}).strict(),D=e.object({type:e.string().regex(b),id:e.string().regex(S),revision:e.number().int().positive()}).strict(),O=e.string().min(1).max(127).regex(x),k=e.object({label:w(48),url:w(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(),A={eventType:e.literal(`notification.delivery.requested`),eventId:e.string().uuid(),producer:E,routeKey:O,occurredAt:T,requestedAt:T,deliverBy:T,subject:D},j=e.object({contractVersion:e.literal(1),...A,message:e.object({type:e.literal(`link_summary`),title:w(160),summary:w(1200),facts:e.array(e.object({label:w(48),value:w(500)}).strict()).max(10),primaryLink:k,sourceLink:k.optional()}).strict()}).strict();function M(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`]}),ee.encode(JSON.stringify(e)).byteLength>r&&t.addIssue({code:`custom`,message:`request_too_large`})}const N=j.superRefine((e,t)=>M(e,t,o,a)),P={title:w(160),summary:w(1200),facts:e.array(e.object({label:w(48),value:w(500)}).strict()).max(10)},F=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),...P}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),...P}).strict()]),I=e.array(F).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`})}),L=e.object({contractVersion:e.literal(2),...A,message:e.object({type:e.literal(`localized_link_summary`),variants:I,primaryLink:k,sourceLink:k.optional()}).strict()}).strict().superRefine((e,t)=>M(e,t,c,s)),R=e.discriminatedUnion(`type`,[e.object({key:e.string().regex(b),type:e.literal(`text`),label:w(48).optional(),value:w(4e3)}).strict(),e.object({key:e.string().regex(b),type:e.literal(`fields`),items:e.array(e.object({label:w(48),value:w(1200)}).strict()).min(1).max(20)}).strict()]),z=e.array(R).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`})}),B=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),title:w(160),sections:z}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),title:w(160),sections:z}).strict()]),V=(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`]})}},H=e.array(B).min(1).max(2).superRefine(V),U=e.object({contractVersion:e.literal(3),...A,message:e.object({type:e.literal(`structured_notification`),variants:H,links:e.array(e.object({key:e.string().regex(b),...k.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(),W=U.superRefine((e,t)=>M(e,t,u,l)),G=e.object({label:w(48).optional(),value:w(d)}).strict(),K=e.discriminatedUnion(`key`,[B.options[0].extend({body:G}),B.options[1].extend({body:G})]),q=U.extend({contractVersion:e.literal(4),message:U.shape.message.extend({variants:e.array(K).min(1).max(2).superRefine(V)})}).superRefine((e,t)=>M(e,t,f,d)),J=e.union([N,L,W,q]),Y=e.object({destinationKey:e.string().min(1),state:e.enum(h),attempts:e.number().int().min(0).max(4),failureCode:e.enum(g).nullable(),lastAttemptAt:T.nullable(),nextAttemptAt:T.nullable(),leaseExpiresAt:T.nullable()}).strict(),X=e.object({contractVersion:e.literal(1),eventId:e.string().uuid(),producer:E,routeKey:O,subject:D,state:e.enum(p),reason:e.enum(m),terminal:e.boolean(),acceptedAt:T,updatedAt:T,deliverBy:T,terminalAt:T.nullable(),destinations:e.array(Y).min(1).max(20)}).strict(),Z=e.object({path:e.array(e.union([e.string(),e.number().int().min(0)])).max(16),code:e.enum(v)}).strict(),Q=e.object({code:e.literal(`invalid_request`),issues:e.array(Z).max(20).optional()}).strict(),te=e.object({code:e.enum(_.filter(e=>e!==`invalid_request`))}).strict(),$=e.union([Q,te]),ne=e.discriminatedUnion(`status`,[e.object({status:e.literal(`accepted`),receipt:X}).strict(),e.object({status:e.literal(`rejected`),error:$}).strict()]),re=e.discriminatedUnion(`status`,[e.object({status:e.literal(`found`),receipt:X}).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{ne as notificationDeliverResultV1Schema,t as notificationDeliveryContractVersionV1,n as notificationDeliveryContractVersionV2,r as notificationDeliveryContractVersionV3,i as notificationDeliveryContractVersionV4,o as notificationDeliveryMaximumDeadlineMillisecondsV1,c as notificationDeliveryMaximumDeadlineMillisecondsV2,u as notificationDeliveryMaximumDeadlineMillisecondsV3,f as notificationDeliveryMaximumDeadlineMillisecondsV4,m as notificationDeliveryReasonsV1,X as notificationDeliveryReceiptV1Schema,_ as notificationDeliveryRejectionCodesV1,$ as notificationDeliveryRejectionV1Schema,a as notificationDeliveryRequestMaximumUtf8BytesV1,s as notificationDeliveryRequestMaximumUtf8BytesV2,l as notificationDeliveryRequestMaximumUtf8BytesV3,d as notificationDeliveryRequestMaximumUtf8BytesV4,J as notificationDeliveryRequestSchema,N as notificationDeliveryRequestV1Schema,L as notificationDeliveryRequestV2Schema,W as notificationDeliveryRequestV3Schema,q as notificationDeliveryRequestV4Schema,p as notificationDeliveryStatesV1,g as notificationDestinationFailureCodesV1,h as notificationDestinationStatesV1,re as notificationGetReceiptResultV1Schema,y as notificationMessageVariantKeys,v as notificationValidationIssueCodesV1};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@closerepo/notification-contracts",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {