@closerepo/notification-contracts 1.4.0 → 1.6.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
@@ -15,6 +15,9 @@ declare const notificationDeliveryRequestMaximumUtf8BytesV4: number;
15
15
  declare const notificationDeliveryMaximumDeadlineMillisecondsV4: number;
16
16
  declare const notificationDeliveryRequestMaximumUtf8BytesV5: number;
17
17
  declare const notificationDeliveryMaximumDeadlineMillisecondsV5: number;
18
+ declare const localTaskDeliveryContractVersionV1: 1;
19
+ declare const localTaskDeliveryRequestMaximumUtf8BytesV1: number;
20
+ declare const localTaskDeliveryMaximumDeadlineMillisecondsV1: number;
18
21
  declare const notificationDeliveryStatesV1: readonly ["pending", "delivering", "partial", "delivered", "failed", "expired"];
19
22
  declare const notificationDeliveryReasonsV1: readonly ["accepted", "enqueue_retry_wait", "in_progress", "partial_delivery", "complete", "retry_exhausted", "delivery_deadline_exceeded", "destination_configuration_unavailable"];
20
23
  declare const notificationDestinationStatesV1: readonly ["pending", "delivering", "delivered", "failed", "expired"];
@@ -363,6 +366,146 @@ declare const notificationDeliveryRequestV5Schema: z.ZodObject<{
363
366
  }, z.core.$strict>;
364
367
  contractVersion: z.ZodLiteral<5>;
365
368
  }, z.core.$strict>;
369
+ declare const notificationDeliveryRequestV6Schema: z.ZodObject<{
370
+ contractVersion: z.ZodLiteral<6>;
371
+ message: z.ZodObject<{
372
+ type: z.ZodLiteral<"structured_notification">;
373
+ links: z.ZodArray<z.ZodObject<{
374
+ key: z.ZodString;
375
+ url: z.ZodString;
376
+ }, z.core.$strict>>;
377
+ bodies: z.ZodArray<z.ZodObject<{
378
+ key: z.ZodString;
379
+ value: z.ZodString;
380
+ }, z.core.$strict>>;
381
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
382
+ key: z.ZodLiteral<"source">;
383
+ title: z.ZodString;
384
+ locale: z.ZodLiteral<"und">;
385
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
386
+ key: z.ZodString;
387
+ type: z.ZodLiteral<"text">;
388
+ label: z.ZodOptional<z.ZodString>;
389
+ value: z.ZodString;
390
+ }, z.core.$strict>, z.ZodObject<{
391
+ key: z.ZodString;
392
+ type: z.ZodLiteral<"fields">;
393
+ items: z.ZodArray<z.ZodObject<{
394
+ label: z.ZodString;
395
+ value: z.ZodString;
396
+ }, z.core.$strict>>;
397
+ }, z.core.$strict>], "type">>;
398
+ linkLabels: z.ZodArray<z.ZodObject<{
399
+ key: z.ZodString;
400
+ label: z.ZodString;
401
+ }, z.core.$strict>>;
402
+ bodyRefs: z.ZodArray<z.ZodObject<{
403
+ key: z.ZodString;
404
+ label: z.ZodString;
405
+ }, z.core.$strict>>;
406
+ footer: z.ZodString;
407
+ }, z.core.$strict>, z.ZodObject<{
408
+ key: z.ZodLiteral<"zh-CN">;
409
+ title: z.ZodString;
410
+ locale: z.ZodLiteral<"zh-CN">;
411
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
412
+ key: z.ZodString;
413
+ type: z.ZodLiteral<"text">;
414
+ label: z.ZodOptional<z.ZodString>;
415
+ value: z.ZodString;
416
+ }, z.core.$strict>, z.ZodObject<{
417
+ key: z.ZodString;
418
+ type: z.ZodLiteral<"fields">;
419
+ items: z.ZodArray<z.ZodObject<{
420
+ label: z.ZodString;
421
+ value: z.ZodString;
422
+ }, z.core.$strict>>;
423
+ }, z.core.$strict>], "type">>;
424
+ linkLabels: z.ZodArray<z.ZodObject<{
425
+ key: z.ZodString;
426
+ label: z.ZodString;
427
+ }, z.core.$strict>>;
428
+ bodyRefs: z.ZodArray<z.ZodObject<{
429
+ key: z.ZodString;
430
+ label: z.ZodString;
431
+ }, z.core.$strict>>;
432
+ footer: z.ZodString;
433
+ }, z.core.$strict>], "key">>;
434
+ }, z.core.$strict>;
435
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
436
+ eventId: z.ZodString;
437
+ producer: z.ZodObject<{
438
+ key: z.ZodString;
439
+ environment: z.ZodString;
440
+ }, z.core.$strict>;
441
+ routeKey: z.ZodString;
442
+ occurredAt: z.ZodString;
443
+ requestedAt: z.ZodString;
444
+ deliverBy: z.ZodString;
445
+ subject: z.ZodObject<{
446
+ type: z.ZodString;
447
+ id: z.ZodString;
448
+ revision: z.ZodNumber;
449
+ }, z.core.$strict>;
450
+ }, z.core.$strict>;
451
+ type NotificationDeliveryRequestV6 = z.infer<typeof notificationDeliveryRequestV6Schema>;
452
+ declare const creatorDraftTaskV1Schema: z.ZodObject<{
453
+ type: z.ZodLiteral<"creator.draft.v1">;
454
+ templateId: z.ZodString;
455
+ signalType: z.ZodString;
456
+ sourceTextZh: z.ZodString;
457
+ sourceUrl: z.ZodOptional<z.ZodString>;
458
+ }, z.core.$strict>;
459
+ declare const localTaskDeliveryRequestV1Schema: z.ZodObject<{
460
+ contractVersion: z.ZodLiteral<1>;
461
+ eventType: z.ZodLiteral<"local-task.delivery.requested">;
462
+ eventId: z.ZodString;
463
+ producer: z.ZodObject<{
464
+ key: z.ZodString;
465
+ environment: z.ZodString;
466
+ }, z.core.$strict>;
467
+ routeKey: z.ZodString;
468
+ occurredAt: z.ZodString;
469
+ requestedAt: z.ZodString;
470
+ deliverBy: z.ZodString;
471
+ subject: z.ZodObject<{
472
+ id: z.ZodString;
473
+ revision: z.ZodNumber;
474
+ type: z.ZodLiteral<"creator-event">;
475
+ }, z.core.$strict>;
476
+ task: z.ZodObject<{
477
+ type: z.ZodLiteral<"creator.draft.v1">;
478
+ templateId: z.ZodString;
479
+ signalType: z.ZodString;
480
+ sourceTextZh: z.ZodString;
481
+ sourceUrl: z.ZodOptional<z.ZodString>;
482
+ }, z.core.$strict>;
483
+ }, z.core.$strict>;
484
+ declare const localTaskDeliveryRequestSchema: z.ZodObject<{
485
+ contractVersion: z.ZodLiteral<1>;
486
+ eventType: z.ZodLiteral<"local-task.delivery.requested">;
487
+ eventId: z.ZodString;
488
+ producer: z.ZodObject<{
489
+ key: z.ZodString;
490
+ environment: z.ZodString;
491
+ }, z.core.$strict>;
492
+ routeKey: z.ZodString;
493
+ occurredAt: z.ZodString;
494
+ requestedAt: z.ZodString;
495
+ deliverBy: z.ZodString;
496
+ subject: z.ZodObject<{
497
+ id: z.ZodString;
498
+ revision: z.ZodNumber;
499
+ type: z.ZodLiteral<"creator-event">;
500
+ }, z.core.$strict>;
501
+ task: z.ZodObject<{
502
+ type: z.ZodLiteral<"creator.draft.v1">;
503
+ templateId: z.ZodString;
504
+ signalType: z.ZodString;
505
+ sourceTextZh: z.ZodString;
506
+ sourceUrl: z.ZodOptional<z.ZodString>;
507
+ }, z.core.$strict>;
508
+ }, z.core.$strict>;
366
509
  declare const notificationDeliveryRequestSchema: z.ZodUnion<readonly [z.ZodObject<{
367
510
  message: z.ZodObject<{
368
511
  type: z.ZodLiteral<"link_summary">;
@@ -644,6 +787,87 @@ declare const notificationDeliveryRequestSchema: z.ZodUnion<readonly [z.ZodObjec
644
787
  revision: z.ZodNumber;
645
788
  }, z.core.$strict>;
646
789
  contractVersion: z.ZodLiteral<5>;
790
+ }, z.core.$strict>, z.ZodObject<{
791
+ contractVersion: z.ZodLiteral<6>;
792
+ message: z.ZodObject<{
793
+ type: z.ZodLiteral<"structured_notification">;
794
+ links: z.ZodArray<z.ZodObject<{
795
+ key: z.ZodString;
796
+ url: z.ZodString;
797
+ }, z.core.$strict>>;
798
+ bodies: z.ZodArray<z.ZodObject<{
799
+ key: z.ZodString;
800
+ value: z.ZodString;
801
+ }, z.core.$strict>>;
802
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
803
+ key: z.ZodLiteral<"source">;
804
+ title: z.ZodString;
805
+ locale: z.ZodLiteral<"und">;
806
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
807
+ key: z.ZodString;
808
+ type: z.ZodLiteral<"text">;
809
+ label: z.ZodOptional<z.ZodString>;
810
+ value: z.ZodString;
811
+ }, z.core.$strict>, z.ZodObject<{
812
+ key: z.ZodString;
813
+ type: z.ZodLiteral<"fields">;
814
+ items: z.ZodArray<z.ZodObject<{
815
+ label: z.ZodString;
816
+ value: z.ZodString;
817
+ }, z.core.$strict>>;
818
+ }, z.core.$strict>], "type">>;
819
+ linkLabels: z.ZodArray<z.ZodObject<{
820
+ key: z.ZodString;
821
+ label: z.ZodString;
822
+ }, z.core.$strict>>;
823
+ bodyRefs: z.ZodArray<z.ZodObject<{
824
+ key: z.ZodString;
825
+ label: z.ZodString;
826
+ }, z.core.$strict>>;
827
+ footer: z.ZodString;
828
+ }, z.core.$strict>, z.ZodObject<{
829
+ key: z.ZodLiteral<"zh-CN">;
830
+ title: z.ZodString;
831
+ locale: z.ZodLiteral<"zh-CN">;
832
+ sections: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
833
+ key: z.ZodString;
834
+ type: z.ZodLiteral<"text">;
835
+ label: z.ZodOptional<z.ZodString>;
836
+ value: z.ZodString;
837
+ }, z.core.$strict>, z.ZodObject<{
838
+ key: z.ZodString;
839
+ type: z.ZodLiteral<"fields">;
840
+ items: z.ZodArray<z.ZodObject<{
841
+ label: z.ZodString;
842
+ value: z.ZodString;
843
+ }, z.core.$strict>>;
844
+ }, z.core.$strict>], "type">>;
845
+ linkLabels: z.ZodArray<z.ZodObject<{
846
+ key: z.ZodString;
847
+ label: z.ZodString;
848
+ }, z.core.$strict>>;
849
+ bodyRefs: z.ZodArray<z.ZodObject<{
850
+ key: z.ZodString;
851
+ label: z.ZodString;
852
+ }, z.core.$strict>>;
853
+ footer: z.ZodString;
854
+ }, z.core.$strict>], "key">>;
855
+ }, z.core.$strict>;
856
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
857
+ eventId: z.ZodString;
858
+ producer: z.ZodObject<{
859
+ key: z.ZodString;
860
+ environment: z.ZodString;
861
+ }, z.core.$strict>;
862
+ routeKey: z.ZodString;
863
+ occurredAt: z.ZodString;
864
+ requestedAt: z.ZodString;
865
+ deliverBy: z.ZodString;
866
+ subject: z.ZodObject<{
867
+ type: z.ZodString;
868
+ id: z.ZodString;
869
+ revision: z.ZodNumber;
870
+ }, z.core.$strict>;
647
871
  }, z.core.$strict>]>;
648
872
  declare const notificationDeliveryReceiptV1Schema: z.ZodObject<{
649
873
  contractVersion: z.ZodLiteral<1>;
@@ -905,6 +1129,12 @@ type NotificationDeliveryReceiptV1 = z.infer<typeof notificationDeliveryReceiptV
905
1129
  type NotificationDeliveryRejectionV1 = z.infer<typeof notificationDeliveryRejectionV1Schema>;
906
1130
  type NotificationDeliverResultV1 = z.infer<typeof notificationDeliverResultV1Schema>;
907
1131
  type NotificationGetReceiptResultV1 = z.infer<typeof notificationGetReceiptResultV1Schema>;
1132
+ type CreatorDraftTaskV1 = z.infer<typeof creatorDraftTaskV1Schema>;
1133
+ type LocalTaskDeliveryRequestV1 = z.infer<typeof localTaskDeliveryRequestV1Schema>;
1134
+ type LocalTaskDeliveryRequest = z.infer<typeof localTaskDeliveryRequestSchema>;
1135
+ type LocalTaskDeliveryReceiptV1 = NotificationDeliveryReceiptV1;
1136
+ type LocalTaskDeliverResultV1 = NotificationDeliverResultV1;
1137
+ type LocalTaskGetReceiptResultV1 = NotificationGetReceiptResultV1;
908
1138
  /** Private Service Binding contract implemented by a Notification producer entrypoint. */
909
1139
  interface NotificationDeliveryServiceV1 {
910
1140
  deliver: (request: NotificationDeliveryRequestV1) => Promise<NotificationDeliverResultV1>;
@@ -915,5 +1145,12 @@ interface NotificationDeliveryServiceV2 {
915
1145
  deliver: (request: NotificationDeliveryRequest) => Promise<NotificationDeliverResultV1>;
916
1146
  getReceipt: (eventId: string) => Promise<NotificationGetReceiptResultV1>;
917
1147
  }
1148
+ /** Private Service Binding contract for profile-routed local tasks. */
1149
+ interface LocalTaskDeliveryServiceV1 {
1150
+ deliverTask: (request: LocalTaskDeliveryRequest) => Promise<LocalTaskDeliverResultV1>;
1151
+ getTaskReceipt: (eventId: string) => Promise<LocalTaskGetReceiptResultV1>;
1152
+ }
1153
+ /** Private Service Binding supporting notifications and profile-routed local tasks. */
1154
+ interface NotificationDeliveryServiceV3 extends NotificationDeliveryServiceV2, LocalTaskDeliveryServiceV1 {}
918
1155
  //#endregion
919
- export { NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequest, NotificationDeliveryRequestV1, NotificationDeliveryRequestV2, NotificationDeliveryRequestV3, NotificationDeliveryRequestV4, NotificationDeliveryRequestV5, NotificationDeliveryServiceV1, NotificationDeliveryServiceV2, NotificationGetReceiptResultV1, NotificationMessageBody, NotificationMessageVariantKey, NotificationSharedMessageBody, NotificationStructuredMessageSection, NotificationStructuredMessageVariant, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryContractVersionV2, notificationDeliveryContractVersionV3, notificationDeliveryContractVersionV4, notificationDeliveryContractVersionV5, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryMaximumDeadlineMillisecondsV2, notificationDeliveryMaximumDeadlineMillisecondsV3, notificationDeliveryMaximumDeadlineMillisecondsV4, notificationDeliveryMaximumDeadlineMillisecondsV5, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestMaximumUtf8BytesV2, notificationDeliveryRequestMaximumUtf8BytesV3, notificationDeliveryRequestMaximumUtf8BytesV4, notificationDeliveryRequestMaximumUtf8BytesV5, notificationDeliveryRequestSchema, notificationDeliveryRequestV1Schema, notificationDeliveryRequestV2Schema, notificationDeliveryRequestV3Schema, notificationDeliveryRequestV4Schema, notificationDeliveryRequestV5Schema, notificationDeliveryStatesV1, notificationDestinationFailureCodesV1, notificationDestinationStatesV1, notificationGetReceiptResultV1Schema, notificationMessageVariantKeys, notificationValidationIssueCodesV1 };
1156
+ export { CreatorDraftTaskV1, LocalTaskDeliverResultV1, LocalTaskDeliveryReceiptV1, LocalTaskDeliveryRequest, LocalTaskDeliveryRequestV1, LocalTaskDeliveryServiceV1, LocalTaskGetReceiptResultV1, NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequest, NotificationDeliveryRequestV1, NotificationDeliveryRequestV2, NotificationDeliveryRequestV3, NotificationDeliveryRequestV4, NotificationDeliveryRequestV5, NotificationDeliveryRequestV6, NotificationDeliveryServiceV1, NotificationDeliveryServiceV2, NotificationDeliveryServiceV3, NotificationGetReceiptResultV1, NotificationMessageBody, NotificationMessageVariantKey, NotificationSharedMessageBody, NotificationStructuredMessageSection, NotificationStructuredMessageVariant, localTaskDeliveryContractVersionV1, localTaskDeliveryMaximumDeadlineMillisecondsV1, localTaskDeliveryRequestMaximumUtf8BytesV1, localTaskDeliveryRequestSchema, localTaskDeliveryRequestV1Schema, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryContractVersionV2, notificationDeliveryContractVersionV3, notificationDeliveryContractVersionV4, notificationDeliveryContractVersionV5, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryMaximumDeadlineMillisecondsV2, notificationDeliveryMaximumDeadlineMillisecondsV3, notificationDeliveryMaximumDeadlineMillisecondsV4, notificationDeliveryMaximumDeadlineMillisecondsV5, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestMaximumUtf8BytesV2, notificationDeliveryRequestMaximumUtf8BytesV3, notificationDeliveryRequestMaximumUtf8BytesV4, notificationDeliveryRequestMaximumUtf8BytesV5, notificationDeliveryRequestSchema, notificationDeliveryRequestV1Schema, notificationDeliveryRequestV2Schema, notificationDeliveryRequestV3Schema, notificationDeliveryRequestV4Schema, notificationDeliveryRequestV5Schema, notificationDeliveryRequestV6Schema, 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=4,a=5,o=32*1024,s=1380*60*1e3,c=o,l=s,u=o,d=s,f=o,p=s,m=o,h=s,g=[`pending`,`delivering`,`partial`,`delivered`,`failed`,`expired`],_=[`accepted`,`enqueue_retry_wait`,`in_progress`,`partial_delivery`,`complete`,`retry_exhausted`,`delivery_deadline_exceeded`,`destination_configuration_unavailable`],v=[`pending`,`delivering`,`delivered`,`failed`,`expired`],y=[`provider_timeout`,`provider_rate_limited`,`provider_unavailable`,`provider_rejected`,`destination_configuration_unavailable`,`delivery_interrupted`,`retry_exhausted`],b=[`invalid_request`,`request_too_large`,`producer_scope_mismatch`,`route_not_allowed`,`event_identity_conflict`,`route_not_found`,`route_empty`,`delivery_deadline_invalid`],x=[`invalid_type`,`invalid_value`,`too_small`,`too_big`,`invalid_format`,`unrecognized_keys`,`custom`],S=[`source`,`zh-CN`],ee=new TextEncoder,C=/^[a-z][a-z0-9-]{0,62}$/,te=/^[a-z][a-z0-9-]{0,31}(?:\.[a-z][a-z0-9-]{0,31}){1,3}$/,ne=/^[A-Z0-9][\w.:-]{0,127}$/i;function w(e){return[...e].length}function T(t){return e.string().refine(e=>w(e)>0,{message:`too_small`}).refine(e=>w(e)<=t,{message:`too_big`})}const E=e.string().datetime({offset:!0}),D=e.object({key:e.string().regex(C),environment:e.string().regex(C)}).strict(),O=e.object({type:e.string().regex(C),id:e.string().regex(ne),revision:e.number().int().positive()}).strict(),k=e.string().min(1).max(127).regex(te),A=e.object({label:T(48),url:T(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(),j={eventType:e.literal(`notification.delivery.requested`),eventId:e.string().uuid(),producer:D,routeKey:k,occurredAt:E,requestedAt:E,deliverBy:E,subject:O},M=e.object({contractVersion:e.literal(1),...j,message:e.object({type:e.literal(`link_summary`),title:T(160),summary:T(1200),facts:e.array(e.object({label:T(48),value:T(500)}).strict()).max(10),primaryLink:A,sourceLink:A.optional()}).strict()}).strict();function N(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 P=M.superRefine((e,t)=>N(e,t,s,o)),F={title:T(160),summary:T(1200),facts:e.array(e.object({label:T(48),value:T(500)}).strict()).max(10)},I=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),...F}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),...F}).strict()]),L=e.array(I).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`})}),R=e.object({contractVersion:e.literal(2),...j,message:e.object({type:e.literal(`localized_link_summary`),variants:L,primaryLink:A,sourceLink:A.optional()}).strict()}).strict().superRefine((e,t)=>N(e,t,l,c)),z=e.discriminatedUnion(`type`,[e.object({key:e.string().regex(C),type:e.literal(`text`),label:T(48).optional(),value:T(4e3)}).strict(),e.object({key:e.string().regex(C),type:e.literal(`fields`),items:e.array(e.object({label:T(48),value:T(1200)}).strict()).min(1).max(20)}).strict()]),B=e.array(z).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`})}),V=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),title:T(160),sections:B}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),title:T(160),sections:B}).strict()]),H=(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`]})}},U=e.array(V).min(1).max(2).superRefine(H),W=e.object({contractVersion:e.literal(3),...j,message:e.object({type:e.literal(`structured_notification`),variants:U,links:e.array(e.object({key:e.string().regex(C),...A.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(),G=W.superRefine((e,t)=>N(e,t,d,u)),K=e.object({label:T(48).optional(),value:T(f)}).strict(),q=e.discriminatedUnion(`key`,[V.options[0].extend({body:K}),V.options[1].extend({body:K})]),J=W.extend({contractVersion:e.literal(4),message:W.shape.message.extend({variants:e.array(q).min(1).max(2).superRefine(H)})}).superRefine((e,t)=>N(e,t,p,f)),Y=e.discriminatedUnion(`key`,[V.options[0].extend({bodyLabel:T(48).optional(),linkLabels:e.array(e.object({key:e.string().regex(C),label:T(48)}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_label_duplicate`})})}),V.options[1].extend({bodyLabel:T(48).optional(),linkLabels:e.array(e.object({key:e.string().regex(C),label:T(48)}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_label_duplicate`})})})]),X=e.object({value:T(m)}).strict(),Z=e.object({contractVersion:e.literal(5),...j,message:e.object({type:e.literal(`structured_notification`),variants:e.array(Y).min(1).max(2).superRefine(H),links:e.array(e.object({key:e.string().regex(C),url:A.shape.url}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_duplicate`})}),body:X}).strict()}).strict().superRefine((e,t)=>{N(e,t,h,m);let n=e.message.links.map(e=>e.key);for(let[r,i]of e.message.variants.entries()){let e=i.linkLabels.map(e=>e.key);JSON.stringify(e)!==JSON.stringify(n)&&t.addIssue({code:`custom`,message:`message_variant_link_labels_mismatch`,path:[`message`,`variants`,r,`linkLabels`]})}}),re=e.union([P,R,G,J,Z]),ie=e.object({destinationKey:e.string().min(1),state:e.enum(v),attempts:e.number().int().min(0).max(4),failureCode:e.enum(y).nullable(),lastAttemptAt:E.nullable(),nextAttemptAt:E.nullable(),leaseExpiresAt:E.nullable()}).strict(),Q=e.object({contractVersion:e.literal(1),eventId:e.string().uuid(),producer:D,routeKey:k,subject:O,state:e.enum(g),reason:e.enum(_),terminal:e.boolean(),acceptedAt:E,updatedAt:E,deliverBy:E,terminalAt:E.nullable(),destinations:e.array(ie).min(1).max(20)}).strict(),ae=e.object({path:e.array(e.union([e.string(),e.number().int().min(0)])).max(16),code:e.enum(x)}).strict(),oe=e.object({code:e.literal(`invalid_request`),issues:e.array(ae).max(20).optional()}).strict(),se=e.object({code:e.enum(b.filter(e=>e!==`invalid_request`))}).strict(),$=e.union([oe,se]),ce=e.discriminatedUnion(`status`,[e.object({status:e.literal(`accepted`),receipt:Q}).strict(),e.object({status:e.literal(`rejected`),error:$}).strict()]),le=e.discriminatedUnion(`status`,[e.object({status:e.literal(`found`),receipt:Q}).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{ce as notificationDeliverResultV1Schema,t as notificationDeliveryContractVersionV1,n as notificationDeliveryContractVersionV2,r as notificationDeliveryContractVersionV3,i as notificationDeliveryContractVersionV4,a as notificationDeliveryContractVersionV5,s as notificationDeliveryMaximumDeadlineMillisecondsV1,l as notificationDeliveryMaximumDeadlineMillisecondsV2,d as notificationDeliveryMaximumDeadlineMillisecondsV3,p as notificationDeliveryMaximumDeadlineMillisecondsV4,h as notificationDeliveryMaximumDeadlineMillisecondsV5,_ as notificationDeliveryReasonsV1,Q as notificationDeliveryReceiptV1Schema,b as notificationDeliveryRejectionCodesV1,$ as notificationDeliveryRejectionV1Schema,o as notificationDeliveryRequestMaximumUtf8BytesV1,c as notificationDeliveryRequestMaximumUtf8BytesV2,u as notificationDeliveryRequestMaximumUtf8BytesV3,f as notificationDeliveryRequestMaximumUtf8BytesV4,m as notificationDeliveryRequestMaximumUtf8BytesV5,re as notificationDeliveryRequestSchema,P as notificationDeliveryRequestV1Schema,R as notificationDeliveryRequestV2Schema,G as notificationDeliveryRequestV3Schema,J as notificationDeliveryRequestV4Schema,Z as notificationDeliveryRequestV5Schema,g as notificationDeliveryStatesV1,y as notificationDestinationFailureCodesV1,v as notificationDestinationStatesV1,le as notificationGetReceiptResultV1Schema,S as notificationMessageVariantKeys,x as notificationValidationIssueCodesV1};
1
+ import{z as e}from"zod";const t=1,n=2,r=3,i=4,a=5,o=32*1024,s=1380*60*1e3,c=o,l=s,u=o,d=s,f=o,p=s,m=o,h=s,ee=1,g=32*1024,_=10080*60*1e3,v=[`pending`,`delivering`,`partial`,`delivered`,`failed`,`expired`],y=[`accepted`,`enqueue_retry_wait`,`in_progress`,`partial_delivery`,`complete`,`retry_exhausted`,`delivery_deadline_exceeded`,`destination_configuration_unavailable`],b=[`pending`,`delivering`,`delivered`,`failed`,`expired`],x=[`provider_timeout`,`provider_rate_limited`,`provider_unavailable`,`provider_rejected`,`destination_configuration_unavailable`,`delivery_interrupted`,`retry_exhausted`],S=[`invalid_request`,`request_too_large`,`producer_scope_mismatch`,`route_not_allowed`,`event_identity_conflict`,`route_not_found`,`route_empty`,`delivery_deadline_invalid`],C=[`invalid_type`,`invalid_value`,`too_small`,`too_big`,`invalid_format`,`unrecognized_keys`,`custom`],te=[`source`,`zh-CN`],ne=new TextEncoder,w=/^[a-z][a-z0-9-]{0,62}$/,re=/^[a-z][a-z0-9-]{0,31}(?:\.[a-z][a-z0-9-]{0,31}){1,3}$/,T=/^[A-Z0-9][\w.:-]{0,127}$/i;function E(e){return[...e].length}function D(t){return e.string().refine(e=>E(e)>0,{message:`too_small`}).refine(e=>E(e)<=t,{message:`too_big`})}const O=e.string().datetime({offset:!0}),k=e.object({key:e.string().regex(w),environment:e.string().regex(w)}).strict(),A=e.object({type:e.string().regex(w),id:e.string().regex(T),revision:e.number().int().positive()}).strict(),j=e.string().min(1).max(127).regex(re),M=e.object({label:D(48),url:D(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(),N={eventType:e.literal(`notification.delivery.requested`),eventId:e.string().uuid(),producer:k,routeKey:j,occurredAt:O,requestedAt:O,deliverBy:O,subject:A},ie=e.object({contractVersion:e.literal(1),...N,message:e.object({type:e.literal(`link_summary`),title:D(160),summary:D(1200),facts:e.array(e.object({label:D(48),value:D(500)}).strict()).max(10),primaryLink:M,sourceLink:M.optional()}).strict()}).strict();function P(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`]}),ne.encode(JSON.stringify(e)).byteLength>r&&t.addIssue({code:`custom`,message:`request_too_large`})}const F=ie.superRefine((e,t)=>P(e,t,s,o)),I={title:D(160),summary:D(1200),facts:e.array(e.object({label:D(48),value:D(500)}).strict()).max(10)},ae=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),...I}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),...I}).strict()]),oe=e.array(ae).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),...N,message:e.object({type:e.literal(`localized_link_summary`),variants:oe,primaryLink:M,sourceLink:M.optional()}).strict()}).strict().superRefine((e,t)=>P(e,t,l,c)),R=e.discriminatedUnion(`type`,[e.object({key:e.string().regex(w),type:e.literal(`text`),label:D(48).optional(),value:D(4e3)}).strict(),e.object({key:e.string().regex(w),type:e.literal(`fields`),items:e.array(e.object({label:D(48),value:D(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:D(160),sections:z}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),title:D(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`]})}},se=e.array(B).min(1).max(2).superRefine(V),H=e.object({contractVersion:e.literal(3),...N,message:e.object({type:e.literal(`structured_notification`),variants:se,links:e.array(e.object({key:e.string().regex(w),...M.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(),U=H.superRefine((e,t)=>P(e,t,d,u)),W=e.object({label:D(48).optional(),value:D(f)}).strict(),G=e.discriminatedUnion(`key`,[B.options[0].extend({body:W}),B.options[1].extend({body:W})]),K=H.extend({contractVersion:e.literal(4),message:H.shape.message.extend({variants:e.array(G).min(1).max(2).superRefine(V)})}).superRefine((e,t)=>P(e,t,p,f)),q=e.discriminatedUnion(`key`,[B.options[0].extend({bodyLabel:D(48).optional(),linkLabels:e.array(e.object({key:e.string().regex(w),label:D(48)}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_label_duplicate`})})}),B.options[1].extend({bodyLabel:D(48).optional(),linkLabels:e.array(e.object({key:e.string().regex(w),label:D(48)}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_label_duplicate`})})})]),ce=e.object({value:D(m)}).strict(),J=e.object({contractVersion:e.literal(5),...N,message:e.object({type:e.literal(`structured_notification`),variants:e.array(q).min(1).max(2).superRefine(V),links:e.array(e.object({key:e.string().regex(w),url:M.shape.url}).strict()).max(10).superRefine((e,t)=>{new Set(e.map(e=>e.key)).size!==e.length&&t.addIssue({code:`custom`,message:`message_link_duplicate`})}),body:ce}).strict()}).strict().superRefine((e,t)=>{P(e,t,h,m);let n=e.message.links.map(e=>e.key);for(let[r,i]of e.message.variants.entries()){let e=i.linkLabels.map(e=>e.key);JSON.stringify(e)!==JSON.stringify(n)&&t.addIssue({code:`custom`,message:`message_variant_link_labels_mismatch`,path:[`message`,`variants`,r,`linkLabels`]})}}),Y=e.object({...J.shape,contractVersion:e.literal(6),message:J.shape.message.omit({body:!0}).extend({bodies:e.array(e.object({key:e.string().regex(w),value:D(m)}).strict()).min(1).max(2),variants:e.array(e.discriminatedUnion(`key`,[q.options[0].omit({bodyLabel:!0}).extend({bodyRefs:e.array(e.object({key:e.string().regex(w),label:D(48)}).strict()).min(1).max(2),footer:D(500)}),q.options[1].omit({bodyLabel:!0}).extend({bodyRefs:e.array(e.object({key:e.string().regex(w),label:D(48)}).strict()).min(1).max(2),footer:D(500)})])).min(1).max(2).superRefine(V)})}).strict().superRefine((e,t)=>{P(e,t,h,m);let n=e.message.bodies.map(e=>e.key),r=e.message.links.map(e=>e.key);new Set(n).size!==n.length&&t.addIssue({code:`custom`,message:`message_body_duplicate`});for(let i of e.message.variants){let e=i.bodyRefs.map(e=>e.key);(new Set(e).size!==e.length||e.some(e=>!n.includes(e)))&&t.addIssue({code:`custom`,message:`message_body_reference_invalid`}),JSON.stringify(i.linkLabels.map(e=>e.key))!==JSON.stringify(r)&&t.addIssue({code:`custom`,message:`message_variant_link_labels_mismatch`})}}),le=e.object({type:e.literal(`creator.draft.v1`),templateId:e.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),signalType:e.string().regex(/^[a-z][a-z0-9_]*$/),sourceTextZh:D(g),sourceUrl:M.shape.url.optional()}).strict(),X=e.object({contractVersion:e.literal(1),eventType:e.literal(`local-task.delivery.requested`),eventId:e.string().uuid(),producer:k,routeKey:j,occurredAt:O,requestedAt:O,deliverBy:O,subject:A.extend({type:e.literal(`creator-event`)}),task:le}).strict().superRefine((e,t)=>P(e,t,_,g)),ue=X,de=e.union([F,L,U,K,J,Y]),Z=e.object({destinationKey:e.string().min(1),state:e.enum(b),attempts:e.number().int().min(0).max(4),failureCode:e.enum(x).nullable(),lastAttemptAt:O.nullable(),nextAttemptAt:O.nullable(),leaseExpiresAt:O.nullable()}).strict(),Q=e.object({contractVersion:e.literal(1),eventId:e.string().uuid(),producer:k,routeKey:j,subject:A,state:e.enum(v),reason:e.enum(y),terminal:e.boolean(),acceptedAt:O,updatedAt:O,deliverBy:O,terminalAt:O.nullable(),destinations:e.array(Z).min(1).max(20)}).strict(),fe=e.object({path:e.array(e.union([e.string(),e.number().int().min(0)])).max(16),code:e.enum(C)}).strict(),pe=e.object({code:e.literal(`invalid_request`),issues:e.array(fe).max(20).optional()}).strict(),me=e.object({code:e.enum(S.filter(e=>e!==`invalid_request`))}).strict(),$=e.union([pe,me]),he=e.discriminatedUnion(`status`,[e.object({status:e.literal(`accepted`),receipt:Q}).strict(),e.object({status:e.literal(`rejected`),error:$}).strict()]),ge=e.discriminatedUnion(`status`,[e.object({status:e.literal(`found`),receipt:Q}).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{ee as localTaskDeliveryContractVersionV1,_ as localTaskDeliveryMaximumDeadlineMillisecondsV1,g as localTaskDeliveryRequestMaximumUtf8BytesV1,ue as localTaskDeliveryRequestSchema,X as localTaskDeliveryRequestV1Schema,he as notificationDeliverResultV1Schema,t as notificationDeliveryContractVersionV1,n as notificationDeliveryContractVersionV2,r as notificationDeliveryContractVersionV3,i as notificationDeliveryContractVersionV4,a as notificationDeliveryContractVersionV5,s as notificationDeliveryMaximumDeadlineMillisecondsV1,l as notificationDeliveryMaximumDeadlineMillisecondsV2,d as notificationDeliveryMaximumDeadlineMillisecondsV3,p as notificationDeliveryMaximumDeadlineMillisecondsV4,h as notificationDeliveryMaximumDeadlineMillisecondsV5,y as notificationDeliveryReasonsV1,Q as notificationDeliveryReceiptV1Schema,S as notificationDeliveryRejectionCodesV1,$ as notificationDeliveryRejectionV1Schema,o as notificationDeliveryRequestMaximumUtf8BytesV1,c as notificationDeliveryRequestMaximumUtf8BytesV2,u as notificationDeliveryRequestMaximumUtf8BytesV3,f as notificationDeliveryRequestMaximumUtf8BytesV4,m as notificationDeliveryRequestMaximumUtf8BytesV5,de as notificationDeliveryRequestSchema,F as notificationDeliveryRequestV1Schema,L as notificationDeliveryRequestV2Schema,U as notificationDeliveryRequestV3Schema,K as notificationDeliveryRequestV4Schema,J as notificationDeliveryRequestV5Schema,Y as notificationDeliveryRequestV6Schema,v as notificationDeliveryStatesV1,x as notificationDestinationFailureCodesV1,b as notificationDestinationStatesV1,ge as notificationGetReceiptResultV1Schema,te as notificationMessageVariantKeys,C as notificationValidationIssueCodesV1};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@closerepo/notification-contracts",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {