@closerepo/notification-contracts 1.0.1 → 1.1.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,84 @@
1
1
  import { z } from "zod";
2
2
  //#region src/index.d.ts
3
3
  declare const notificationDeliveryContractVersionV1: 1;
4
+ declare const notificationDeliveryContractVersionV2: 2;
4
5
  declare const notificationDeliveryRequestMaximumUtf8BytesV1: number;
5
6
  declare const notificationDeliveryMaximumDeadlineMillisecondsV1: number;
7
+ declare const notificationDeliveryRequestMaximumUtf8BytesV2: number;
8
+ declare const notificationDeliveryMaximumDeadlineMillisecondsV2: number;
6
9
  declare const notificationDeliveryStatesV1: readonly ["pending", "delivering", "partial", "delivered", "failed", "expired"];
7
10
  declare const notificationDeliveryReasonsV1: readonly ["accepted", "enqueue_retry_wait", "in_progress", "partial_delivery", "complete", "retry_exhausted", "delivery_deadline_exceeded", "destination_configuration_unavailable"];
8
11
  declare const notificationDestinationStatesV1: readonly ["pending", "delivering", "delivered", "failed", "expired"];
9
12
  declare const notificationDestinationFailureCodesV1: readonly ["provider_timeout", "provider_rate_limited", "provider_unavailable", "provider_rejected", "destination_configuration_unavailable", "delivery_interrupted", "retry_exhausted"];
10
13
  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
14
  declare const notificationValidationIssueCodesV1: readonly ["invalid_type", "invalid_value", "too_small", "too_big", "invalid_format", "unrecognized_keys", "custom"];
15
+ declare const notificationMessageVariantKeys: readonly ["source", "zh-CN"];
12
16
  declare const notificationDeliveryRequestV1Schema: z.ZodObject<{
17
+ message: z.ZodObject<{
18
+ type: z.ZodLiteral<"link_summary">;
19
+ title: z.ZodString;
20
+ summary: z.ZodString;
21
+ facts: z.ZodArray<z.ZodObject<{
22
+ label: z.ZodString;
23
+ value: z.ZodString;
24
+ }, z.core.$strict>>;
25
+ primaryLink: z.ZodObject<{
26
+ label: z.ZodString;
27
+ url: z.ZodString;
28
+ }, z.core.$strict>;
29
+ sourceLink: z.ZodOptional<z.ZodObject<{
30
+ label: z.ZodString;
31
+ url: z.ZodString;
32
+ }, z.core.$strict>>;
33
+ }, z.core.$strict>;
34
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
35
+ eventId: z.ZodString;
36
+ producer: z.ZodObject<{
37
+ key: z.ZodString;
38
+ environment: z.ZodString;
39
+ }, z.core.$strict>;
40
+ routeKey: z.ZodString;
41
+ occurredAt: z.ZodString;
42
+ requestedAt: z.ZodString;
43
+ deliverBy: z.ZodString;
44
+ subject: z.ZodObject<{
45
+ type: z.ZodString;
46
+ id: z.ZodString;
47
+ revision: z.ZodNumber;
48
+ }, z.core.$strict>;
13
49
  contractVersion: z.ZodLiteral<1>;
50
+ }, z.core.$strict>;
51
+ declare const notificationDeliveryRequestV2Schema: z.ZodObject<{
52
+ message: z.ZodObject<{
53
+ type: z.ZodLiteral<"localized_link_summary">;
54
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
55
+ title: z.ZodString;
56
+ summary: z.ZodString;
57
+ facts: z.ZodArray<z.ZodObject<{
58
+ label: z.ZodString;
59
+ value: z.ZodString;
60
+ }, z.core.$strict>>;
61
+ key: z.ZodLiteral<"source">;
62
+ locale: z.ZodLiteral<"und">;
63
+ }, z.core.$strict>, z.ZodObject<{
64
+ title: z.ZodString;
65
+ summary: z.ZodString;
66
+ facts: z.ZodArray<z.ZodObject<{
67
+ label: z.ZodString;
68
+ value: z.ZodString;
69
+ }, z.core.$strict>>;
70
+ key: z.ZodLiteral<"zh-CN">;
71
+ locale: z.ZodLiteral<"zh-CN">;
72
+ }, z.core.$strict>], "key">>;
73
+ primaryLink: z.ZodObject<{
74
+ label: z.ZodString;
75
+ url: z.ZodString;
76
+ }, z.core.$strict>;
77
+ sourceLink: z.ZodOptional<z.ZodObject<{
78
+ label: z.ZodString;
79
+ url: z.ZodString;
80
+ }, z.core.$strict>>;
81
+ }, z.core.$strict>;
14
82
  eventType: z.ZodLiteral<"notification.delivery.requested">;
15
83
  eventId: z.ZodString;
16
84
  producer: z.ZodObject<{
@@ -26,6 +94,9 @@ declare const notificationDeliveryRequestV1Schema: z.ZodObject<{
26
94
  id: z.ZodString;
27
95
  revision: z.ZodNumber;
28
96
  }, z.core.$strict>;
97
+ contractVersion: z.ZodLiteral<2>;
98
+ }, z.core.$strict>;
99
+ declare const notificationDeliveryRequestSchema: z.ZodUnion<readonly [z.ZodObject<{
29
100
  message: z.ZodObject<{
30
101
  type: z.ZodLiteral<"link_summary">;
31
102
  title: z.ZodString;
@@ -43,7 +114,70 @@ declare const notificationDeliveryRequestV1Schema: z.ZodObject<{
43
114
  url: z.ZodString;
44
115
  }, z.core.$strict>>;
45
116
  }, z.core.$strict>;
46
- }, z.core.$strict>;
117
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
118
+ eventId: z.ZodString;
119
+ producer: z.ZodObject<{
120
+ key: z.ZodString;
121
+ environment: z.ZodString;
122
+ }, z.core.$strict>;
123
+ routeKey: z.ZodString;
124
+ occurredAt: z.ZodString;
125
+ requestedAt: z.ZodString;
126
+ deliverBy: z.ZodString;
127
+ subject: z.ZodObject<{
128
+ type: z.ZodString;
129
+ id: z.ZodString;
130
+ revision: z.ZodNumber;
131
+ }, z.core.$strict>;
132
+ contractVersion: z.ZodLiteral<1>;
133
+ }, z.core.$strict>, z.ZodObject<{
134
+ message: z.ZodObject<{
135
+ type: z.ZodLiteral<"localized_link_summary">;
136
+ variants: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
137
+ title: z.ZodString;
138
+ summary: z.ZodString;
139
+ facts: z.ZodArray<z.ZodObject<{
140
+ label: z.ZodString;
141
+ value: z.ZodString;
142
+ }, z.core.$strict>>;
143
+ key: z.ZodLiteral<"source">;
144
+ locale: z.ZodLiteral<"und">;
145
+ }, z.core.$strict>, z.ZodObject<{
146
+ title: z.ZodString;
147
+ summary: z.ZodString;
148
+ facts: z.ZodArray<z.ZodObject<{
149
+ label: z.ZodString;
150
+ value: z.ZodString;
151
+ }, z.core.$strict>>;
152
+ key: z.ZodLiteral<"zh-CN">;
153
+ locale: z.ZodLiteral<"zh-CN">;
154
+ }, z.core.$strict>], "key">>;
155
+ primaryLink: z.ZodObject<{
156
+ label: z.ZodString;
157
+ url: z.ZodString;
158
+ }, z.core.$strict>;
159
+ sourceLink: z.ZodOptional<z.ZodObject<{
160
+ label: z.ZodString;
161
+ url: z.ZodString;
162
+ }, z.core.$strict>>;
163
+ }, z.core.$strict>;
164
+ eventType: z.ZodLiteral<"notification.delivery.requested">;
165
+ eventId: z.ZodString;
166
+ producer: z.ZodObject<{
167
+ key: z.ZodString;
168
+ environment: z.ZodString;
169
+ }, z.core.$strict>;
170
+ routeKey: z.ZodString;
171
+ occurredAt: z.ZodString;
172
+ requestedAt: z.ZodString;
173
+ deliverBy: z.ZodString;
174
+ subject: z.ZodObject<{
175
+ type: z.ZodString;
176
+ id: z.ZodString;
177
+ revision: z.ZodNumber;
178
+ }, z.core.$strict>;
179
+ contractVersion: z.ZodLiteral<2>;
180
+ }, z.core.$strict>]>;
47
181
  declare const notificationDeliveryReceiptV1Schema: z.ZodObject<{
48
182
  contractVersion: z.ZodLiteral<1>;
49
183
  eventId: z.ZodString;
@@ -290,6 +424,9 @@ declare const notificationGetReceiptResultV1Schema: z.ZodDiscriminatedUnion<[z.Z
290
424
  }, z.core.$strict>;
291
425
  }, z.core.$strict>], "status">;
292
426
  type NotificationDeliveryRequestV1 = z.infer<typeof notificationDeliveryRequestV1Schema>;
427
+ type NotificationDeliveryRequestV2 = z.infer<typeof notificationDeliveryRequestV2Schema>;
428
+ type NotificationDeliveryRequest = z.infer<typeof notificationDeliveryRequestSchema>;
429
+ type NotificationMessageVariantKey = (typeof notificationMessageVariantKeys)[number];
293
430
  type NotificationDeliveryReceiptV1 = z.infer<typeof notificationDeliveryReceiptV1Schema>;
294
431
  type NotificationDeliveryRejectionV1 = z.infer<typeof notificationDeliveryRejectionV1Schema>;
295
432
  type NotificationDeliverResultV1 = z.infer<typeof notificationDeliverResultV1Schema>;
@@ -299,5 +436,10 @@ interface NotificationDeliveryServiceV1 {
299
436
  deliver: (request: NotificationDeliveryRequestV1) => Promise<NotificationDeliverResultV1>;
300
437
  getReceipt: (eventId: string) => Promise<NotificationGetReceiptResultV1>;
301
438
  }
439
+ /** Private Service Binding contract accepting both published request versions. */
440
+ interface NotificationDeliveryServiceV2 {
441
+ deliver: (request: NotificationDeliveryRequest) => Promise<NotificationDeliverResultV1>;
442
+ getReceipt: (eventId: string) => Promise<NotificationGetReceiptResultV1>;
443
+ }
302
444
  //#endregion
303
- export { NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequestV1, NotificationDeliveryServiceV1, NotificationGetReceiptResultV1, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestV1Schema, notificationDeliveryStatesV1, notificationDestinationFailureCodesV1, notificationDestinationStatesV1, notificationGetReceiptResultV1Schema, notificationValidationIssueCodesV1 };
445
+ export { NotificationDeliverResultV1, NotificationDeliveryReceiptV1, NotificationDeliveryRejectionV1, NotificationDeliveryRequest, NotificationDeliveryRequestV1, NotificationDeliveryRequestV2, NotificationDeliveryServiceV1, NotificationDeliveryServiceV2, NotificationGetReceiptResultV1, NotificationMessageVariantKey, notificationDeliverResultV1Schema, notificationDeliveryContractVersionV1, notificationDeliveryContractVersionV2, notificationDeliveryMaximumDeadlineMillisecondsV1, notificationDeliveryMaximumDeadlineMillisecondsV2, notificationDeliveryReasonsV1, notificationDeliveryReceiptV1Schema, notificationDeliveryRejectionCodesV1, notificationDeliveryRejectionV1Schema, notificationDeliveryRequestMaximumUtf8BytesV1, notificationDeliveryRequestMaximumUtf8BytesV2, notificationDeliveryRequestSchema, notificationDeliveryRequestV1Schema, notificationDeliveryRequestV2Schema, 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=32*1024,i=1380*60*1e3,a=r,o=i,s=[`pending`,`delivering`,`partial`,`delivered`,`failed`,`expired`],c=[`accepted`,`enqueue_retry_wait`,`in_progress`,`partial_delivery`,`complete`,`retry_exhausted`,`delivery_deadline_exceeded`,`destination_configuration_unavailable`],l=[`pending`,`delivering`,`delivered`,`failed`,`expired`],u=[`provider_timeout`,`provider_rate_limited`,`provider_unavailable`,`provider_rejected`,`destination_configuration_unavailable`,`delivery_interrupted`,`retry_exhausted`],d=[`invalid_request`,`request_too_large`,`producer_scope_mismatch`,`route_not_allowed`,`event_identity_conflict`,`route_not_found`,`route_empty`,`delivery_deadline_invalid`],f=[`invalid_type`,`invalid_value`,`too_small`,`too_big`,`invalid_format`,`unrecognized_keys`,`custom`],p=[`source`,`zh-CN`],m=new TextEncoder,h=/^[a-z][a-z0-9-]{0,62}$/,g=/^[a-z][a-z0-9-]{0,31}(?:\.[a-z][a-z0-9-]{0,31}){1,3}$/,_=/^[A-Z0-9][\w.:-]{0,127}$/i;function v(e){return[...e].length}function y(t){return e.string().refine(e=>v(e)>0,{message:`too_small`}).refine(e=>v(e)<=t,{message:`too_big`})}const b=e.string().datetime({offset:!0}),x=e.object({key:e.string().regex(h),environment:e.string().regex(h)}).strict(),S=e.object({type:e.string().regex(h),id:e.string().regex(_),revision:e.number().int().positive()}).strict(),C=e.string().min(1).max(127).regex(g),w=e.object({label:y(48),url:y(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(),T={eventType:e.literal(`notification.delivery.requested`),eventId:e.string().uuid(),producer:x,routeKey:C,occurredAt:b,requestedAt:b,deliverBy:b,subject:S},E=e.object({contractVersion:e.literal(1),...T,message:e.object({type:e.literal(`link_summary`),title:y(160),summary:y(1200),facts:e.array(e.object({label:y(48),value:y(500)}).strict()).max(10),primaryLink:w,sourceLink:w.optional()}).strict()}).strict();function D(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`]}),m.encode(JSON.stringify(e)).byteLength>r&&t.addIssue({code:`custom`,message:`request_too_large`})}const O=E.superRefine((e,t)=>D(e,t,i,r)),k={title:y(160),summary:y(1200),facts:e.array(e.object({label:y(48),value:y(500)}).strict()).max(10)},A=e.discriminatedUnion(`key`,[e.object({key:e.literal(`source`),locale:e.literal(`und`),...k}).strict(),e.object({key:e.literal(`zh-CN`),locale:e.literal(`zh-CN`),...k}).strict()]),j=e.array(A).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`})}),M=e.object({contractVersion:e.literal(2),...T,message:e.object({type:e.literal(`localized_link_summary`),variants:j,primaryLink:w,sourceLink:w.optional()}).strict()}).strict().superRefine((e,t)=>D(e,t,o,a)),N=e.union([O,M]),P=e.object({destinationKey:e.string().min(1),state:e.enum(l),attempts:e.number().int().min(0).max(4),failureCode:e.enum(u).nullable(),lastAttemptAt:b.nullable(),nextAttemptAt:b.nullable(),leaseExpiresAt:b.nullable()}).strict(),F=e.object({contractVersion:e.literal(1),eventId:e.string().uuid(),producer:x,routeKey:C,subject:S,state:e.enum(s),reason:e.enum(c),terminal:e.boolean(),acceptedAt:b,updatedAt:b,deliverBy:b,terminalAt:b.nullable(),destinations:e.array(P).min(1).max(20)}).strict(),I=e.object({path:e.array(e.union([e.string(),e.number().int().min(0)])).max(16),code:e.enum(f)}).strict(),L=e.object({code:e.literal(`invalid_request`),issues:e.array(I).max(20).optional()}).strict(),R=e.object({code:e.enum(d.filter(e=>e!==`invalid_request`))}).strict(),z=e.union([L,R]),B=e.discriminatedUnion(`status`,[e.object({status:e.literal(`accepted`),receipt:F}).strict(),e.object({status:e.literal(`rejected`),error:z}).strict()]),V=e.discriminatedUnion(`status`,[e.object({status:e.literal(`found`),receipt:F}).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{B as notificationDeliverResultV1Schema,t as notificationDeliveryContractVersionV1,n as notificationDeliveryContractVersionV2,i as notificationDeliveryMaximumDeadlineMillisecondsV1,o as notificationDeliveryMaximumDeadlineMillisecondsV2,c as notificationDeliveryReasonsV1,F as notificationDeliveryReceiptV1Schema,d as notificationDeliveryRejectionCodesV1,z as notificationDeliveryRejectionV1Schema,r as notificationDeliveryRequestMaximumUtf8BytesV1,a as notificationDeliveryRequestMaximumUtf8BytesV2,N as notificationDeliveryRequestSchema,O as notificationDeliveryRequestV1Schema,M as notificationDeliveryRequestV2Schema,s as notificationDeliveryStatesV1,u as notificationDestinationFailureCodesV1,l as notificationDestinationStatesV1,V as notificationGetReceiptResultV1Schema,p as notificationMessageVariantKeys,f 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.1.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {