@antasphere/chassis-contract 1.0.2 → 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.
@@ -0,0 +1,281 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Outbound webhooks (PRDCT-3482): a URL a workspace registers to be told, by a
4
+ * signed POST, when something happens to the tool's own subjects. The tool
5
+ * declares the event types and the subjects they carry (the catalog); the
6
+ * chassis stores the endpoints, matches the events against them, signs and
7
+ * delivers, and keeps each delivery's history. Owners and admins manage them.
8
+ *
9
+ * The signing secret is NEVER part of an endpoint's shape: it is shown once,
10
+ * at creation and at each rotation, and stored sealed.
11
+ */
12
+ /**
13
+ * What an endpoint subscribes to: an exact event type (`thing.created`), a
14
+ * family (`thing.*`) or everything (`*`).
15
+ */
16
+ export declare const webhookEventPatternSchema: z.ZodString;
17
+ /** A subject key of the catalog (`thing`, `project`): lowercase, digits and underscores. */
18
+ export declare const webhookSubjectKeySchema: z.ZodString;
19
+ /**
20
+ * Narrows a subscription by subject: a subject key mapped to the ids it
21
+ * accepts. AND across keys, OR within a key; an event that does not carry a
22
+ * filtered subject does not match. An empty object filters nothing.
23
+ */
24
+ export declare const webhookFiltersSchema: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
25
+ export type WebhookFilters = z.infer<typeof webhookFiltersSchema>;
26
+ /**
27
+ * Where the deliveries go: an http or https URL without credentials. Whitespace
28
+ * and control characters are refused outright, because the URL parser silently
29
+ * strips tabs and newlines, so the stored string would not be the address
30
+ * delivered to. The address rules (ports, private networks, https on the cloud
31
+ * edition) are the server's, answered `url_refused`.
32
+ */
33
+ export declare const webhookUrlSchema: z.ZodString;
34
+ export declare const webhookDeliveryStatusSchema: z.ZodEnum<{
35
+ pending: "pending";
36
+ delivered: "delivered";
37
+ failed: "failed";
38
+ held: "held";
39
+ }>;
40
+ export type WebhookDeliveryStatus = z.infer<typeof webhookDeliveryStatusSchema>;
41
+ export declare const webhookEndpointSchema: z.ZodObject<{
42
+ id: z.ZodString;
43
+ url: z.ZodString;
44
+ description: z.ZodString;
45
+ events: z.ZodArray<z.ZodString>;
46
+ filters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
47
+ enabled: z.ZodBoolean;
48
+ createdBy: z.ZodNullable<z.ZodString>;
49
+ createdAt: z.ZodString;
50
+ updatedAt: z.ZodString;
51
+ disabledAt: z.ZodNullable<z.ZodString>;
52
+ disabledReason: z.ZodNullable<z.ZodString>;
53
+ consecutiveFailures: z.ZodNumber;
54
+ lastDeliveryAt: z.ZodNullable<z.ZodString>;
55
+ lastDeliveryStatus: z.ZodNullable<z.ZodEnum<{
56
+ delivered: "delivered";
57
+ failed: "failed";
58
+ }>>;
59
+ previousSecretExpiresAt: z.ZodNullable<z.ZodString>;
60
+ }, z.core.$strip>;
61
+ export type WebhookEndpoint = z.infer<typeof webhookEndpointSchema>;
62
+ /** The endpoint as created, with its signing secret (`whsec_…`), shown ONCE. */
63
+ export declare const webhookEndpointCreatedSchema: z.ZodObject<{
64
+ id: z.ZodString;
65
+ url: z.ZodString;
66
+ description: z.ZodString;
67
+ events: z.ZodArray<z.ZodString>;
68
+ filters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
69
+ enabled: z.ZodBoolean;
70
+ createdBy: z.ZodNullable<z.ZodString>;
71
+ createdAt: z.ZodString;
72
+ updatedAt: z.ZodString;
73
+ disabledAt: z.ZodNullable<z.ZodString>;
74
+ disabledReason: z.ZodNullable<z.ZodString>;
75
+ consecutiveFailures: z.ZodNumber;
76
+ lastDeliveryAt: z.ZodNullable<z.ZodString>;
77
+ lastDeliveryStatus: z.ZodNullable<z.ZodEnum<{
78
+ delivered: "delivered";
79
+ failed: "failed";
80
+ }>>;
81
+ previousSecretExpiresAt: z.ZodNullable<z.ZodString>;
82
+ secret: z.ZodString;
83
+ }, z.core.$strip>;
84
+ export type WebhookEndpointCreated = z.infer<typeof webhookEndpointCreatedSchema>;
85
+ /**
86
+ * The endpoint after a rotation, with its new secret, shown ONCE; the previous
87
+ * secret keeps signing until `previousSecretExpiresAt`.
88
+ */
89
+ export declare const webhookSecretRotatedSchema: z.ZodObject<{
90
+ id: z.ZodString;
91
+ url: z.ZodString;
92
+ description: z.ZodString;
93
+ events: z.ZodArray<z.ZodString>;
94
+ filters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
95
+ enabled: z.ZodBoolean;
96
+ createdBy: z.ZodNullable<z.ZodString>;
97
+ createdAt: z.ZodString;
98
+ updatedAt: z.ZodString;
99
+ disabledAt: z.ZodNullable<z.ZodString>;
100
+ disabledReason: z.ZodNullable<z.ZodString>;
101
+ consecutiveFailures: z.ZodNumber;
102
+ lastDeliveryAt: z.ZodNullable<z.ZodString>;
103
+ lastDeliveryStatus: z.ZodNullable<z.ZodEnum<{
104
+ delivered: "delivered";
105
+ failed: "failed";
106
+ }>>;
107
+ secret: z.ZodString;
108
+ previousSecretExpiresAt: z.ZodString;
109
+ }, z.core.$strip>;
110
+ export type WebhookSecretRotated = z.infer<typeof webhookSecretRotatedSchema>;
111
+ export declare const webhookEndpointCreateSchema: z.ZodObject<{
112
+ url: z.ZodString;
113
+ description: z.ZodDefault<z.ZodString>;
114
+ events: z.ZodArray<z.ZodString>;
115
+ filters: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
116
+ enabled: z.ZodDefault<z.ZodBoolean>;
117
+ }, z.core.$strip>;
118
+ /** The INPUT shape: `description`, `filters` and `enabled` may be left out. */
119
+ export type WebhookEndpointCreate = z.input<typeof webhookEndpointCreateSchema>;
120
+ /** Every field optional, none defaulted (a PATCH never resets what it does not name). */
121
+ export declare const webhookEndpointUpdateSchema: z.ZodObject<{
122
+ url: z.ZodOptional<z.ZodString>;
123
+ description: z.ZodOptional<z.ZodString>;
124
+ events: z.ZodOptional<z.ZodArray<z.ZodString>>;
125
+ filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
126
+ enabled: z.ZodOptional<z.ZodBoolean>;
127
+ }, z.core.$strip>;
128
+ export type WebhookEndpointUpdate = z.infer<typeof webhookEndpointUpdateSchema>;
129
+ export declare const webhooksListSchema: z.ZodObject<{
130
+ webhooks: z.ZodArray<z.ZodObject<{
131
+ id: z.ZodString;
132
+ url: z.ZodString;
133
+ description: z.ZodString;
134
+ events: z.ZodArray<z.ZodString>;
135
+ filters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
136
+ enabled: z.ZodBoolean;
137
+ createdBy: z.ZodNullable<z.ZodString>;
138
+ createdAt: z.ZodString;
139
+ updatedAt: z.ZodString;
140
+ disabledAt: z.ZodNullable<z.ZodString>;
141
+ disabledReason: z.ZodNullable<z.ZodString>;
142
+ consecutiveFailures: z.ZodNumber;
143
+ lastDeliveryAt: z.ZodNullable<z.ZodString>;
144
+ lastDeliveryStatus: z.ZodNullable<z.ZodEnum<{
145
+ delivered: "delivered";
146
+ failed: "failed";
147
+ }>>;
148
+ previousSecretExpiresAt: z.ZodNullable<z.ZodString>;
149
+ }, z.core.$strip>>;
150
+ nextCursor: z.ZodNullable<z.ZodString>;
151
+ }, z.core.$strip>;
152
+ export type WebhooksList = z.infer<typeof webhooksListSchema>;
153
+ export declare const webhooksListQuerySchema: z.ZodObject<{
154
+ cursor: z.ZodOptional<z.ZodString>;
155
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
156
+ }, z.core.$strip>;
157
+ /**
158
+ * One event sent to one endpoint, with its attempts. `eventId` is the
159
+ * receiver's dedupe key, the same on every attempt and on a redelivery;
160
+ * `lastStatusCode` and `lastError` describe the latest attempt only;
161
+ * `payload` is the envelope as sent.
162
+ */
163
+ export declare const webhookDeliverySchema: z.ZodObject<{
164
+ id: z.ZodString;
165
+ endpointId: z.ZodString;
166
+ eventId: z.ZodString;
167
+ eventType: z.ZodString;
168
+ status: z.ZodEnum<{
169
+ pending: "pending";
170
+ delivered: "delivered";
171
+ failed: "failed";
172
+ held: "held";
173
+ }>;
174
+ attempt: z.ZodNumber;
175
+ lastStatusCode: z.ZodNullable<z.ZodNumber>;
176
+ lastError: z.ZodNullable<z.ZodString>;
177
+ nextAttemptAt: z.ZodNullable<z.ZodString>;
178
+ deliveredAt: z.ZodNullable<z.ZodString>;
179
+ createdAt: z.ZodString;
180
+ updatedAt: z.ZodString;
181
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
182
+ }, z.core.$strip>;
183
+ export type WebhookDelivery = z.infer<typeof webhookDeliverySchema>;
184
+ export declare const webhookDeliveriesListSchema: z.ZodObject<{
185
+ deliveries: z.ZodArray<z.ZodObject<{
186
+ id: z.ZodString;
187
+ endpointId: z.ZodString;
188
+ eventId: z.ZodString;
189
+ eventType: z.ZodString;
190
+ status: z.ZodEnum<{
191
+ pending: "pending";
192
+ delivered: "delivered";
193
+ failed: "failed";
194
+ held: "held";
195
+ }>;
196
+ attempt: z.ZodNumber;
197
+ lastStatusCode: z.ZodNullable<z.ZodNumber>;
198
+ lastError: z.ZodNullable<z.ZodString>;
199
+ nextAttemptAt: z.ZodNullable<z.ZodString>;
200
+ deliveredAt: z.ZodNullable<z.ZodString>;
201
+ createdAt: z.ZodString;
202
+ updatedAt: z.ZodString;
203
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
204
+ }, z.core.$strip>>;
205
+ nextCursor: z.ZodNullable<z.ZodString>;
206
+ }, z.core.$strip>;
207
+ export type WebhookDeliveriesList = z.infer<typeof webhookDeliveriesListSchema>;
208
+ export declare const webhookDeliveriesListQuerySchema: z.ZodObject<{
209
+ cursor: z.ZodOptional<z.ZodString>;
210
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
211
+ status: z.ZodOptional<z.ZodEnum<{
212
+ pending: "pending";
213
+ delivered: "delivered";
214
+ failed: "failed";
215
+ held: "held";
216
+ }>>;
217
+ }, z.core.$strip>;
218
+ /** The `webhook.ping` attempted inline: its outcome is on the delivery row. */
219
+ export declare const webhookTestResultSchema: z.ZodObject<{
220
+ delivery: z.ZodObject<{
221
+ id: z.ZodString;
222
+ endpointId: z.ZodString;
223
+ eventId: z.ZodString;
224
+ eventType: z.ZodString;
225
+ status: z.ZodEnum<{
226
+ pending: "pending";
227
+ delivered: "delivered";
228
+ failed: "failed";
229
+ held: "held";
230
+ }>;
231
+ attempt: z.ZodNumber;
232
+ lastStatusCode: z.ZodNullable<z.ZodNumber>;
233
+ lastError: z.ZodNullable<z.ZodString>;
234
+ nextAttemptAt: z.ZodNullable<z.ZodString>;
235
+ deliveredAt: z.ZodNullable<z.ZodString>;
236
+ createdAt: z.ZodString;
237
+ updatedAt: z.ZodString;
238
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
239
+ }, z.core.$strip>;
240
+ }, z.core.$strip>;
241
+ export type WebhookTestResult = z.infer<typeof webhookTestResultSchema>;
242
+ /** A subject events can carry and endpoints can filter on: its key (what a filter names), the field of the envelope's `subjects` its value is written under (one id or a list of ids). */
243
+ export declare const webhookCatalogSubjectSchema: z.ZodObject<{
244
+ key: z.ZodString;
245
+ field: z.ZodString;
246
+ description: z.ZodString;
247
+ list: z.ZodBoolean;
248
+ }, z.core.$strip>;
249
+ export type WebhookCatalogSubject = z.infer<typeof webhookCatalogSubjectSchema>;
250
+ export declare const webhookCatalogEventSchema: z.ZodObject<{
251
+ type: z.ZodString;
252
+ description: z.ZodString;
253
+ subjects: z.ZodArray<z.ZodString>;
254
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
255
+ }, z.core.$strip>;
256
+ export type WebhookCatalogEvent = z.infer<typeof webhookCatalogEventSchema>;
257
+ export declare const webhookCatalogSchema: z.ZodObject<{
258
+ subjects: z.ZodArray<z.ZodObject<{
259
+ key: z.ZodString;
260
+ field: z.ZodString;
261
+ description: z.ZodString;
262
+ list: z.ZodBoolean;
263
+ }, z.core.$strip>>;
264
+ events: z.ZodArray<z.ZodObject<{
265
+ type: z.ZodString;
266
+ description: z.ZodString;
267
+ subjects: z.ZodArray<z.ZodString>;
268
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
269
+ }, z.core.$strip>>;
270
+ }, z.core.$strip>;
271
+ export type WebhookCatalog = z.infer<typeof webhookCatalogSchema>;
272
+ /** `{id}` the endpoint (a uuid, as every `{id}` path param). */
273
+ export declare const webhookParamsSchema: z.ZodObject<{
274
+ id: z.ZodUUID;
275
+ }, z.core.$strip>;
276
+ /** `{id}` the endpoint, `{deliveryId}` one of its deliveries: both uuids. */
277
+ export declare const webhookDeliveryParamsSchema: z.ZodObject<{
278
+ id: z.ZodUUID;
279
+ deliveryId: z.ZodUUID;
280
+ }, z.core.$strip>;
281
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/schemas/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;GASG;AAEH;;;GAGG;AACH,eAAO,MAAM,yBAAyB,aAMnC,CAAC;AAEJ,4FAA4F;AAC5F,eAAO,MAAM,uBAAuB,aAG8D,CAAC;AAEnG;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,mDAK9B,CAAC;AACJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAwBlE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,aAOgE,CAAC;AAE9F,eAAO,MAAM,2BAA2B;;;;;EAAqD,CAAC;AAC9F,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;iBAkBhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,gFAAgF;AAChF,eAAO,MAAM,4BAA4B;;;;;;;;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,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,0LAA0L;AAC1L,eAAO,MAAM,2BAA2B;;;;;iBAMtC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,eAAO,MAAM,yBAAyB;;;;;iBAOpC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;iBAG/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,gEAAgE;AAChE,eAAO,MAAM,mBAAmB;;iBAA6B,CAAC;AAE9D,6EAA6E;AAC7E,eAAO,MAAM,2BAA2B;;;iBAAuD,CAAC"}
@@ -0,0 +1,175 @@
1
+ import { z } from 'zod';
2
+ import { cursorPageQuerySchema, hasControlChars, plainText } from './common.js';
3
+ /**
4
+ * Outbound webhooks (PRDCT-3482): a URL a workspace registers to be told, by a
5
+ * signed POST, when something happens to the tool's own subjects. The tool
6
+ * declares the event types and the subjects they carry (the catalog); the
7
+ * chassis stores the endpoints, matches the events against them, signs and
8
+ * delivers, and keeps each delivery's history. Owners and admins manage them.
9
+ *
10
+ * The signing secret is NEVER part of an endpoint's shape: it is shown once,
11
+ * at creation and at each rotation, and stored sealed.
12
+ */
13
+ /**
14
+ * What an endpoint subscribes to: an exact event type (`thing.created`), a
15
+ * family (`thing.*`) or everything (`*`).
16
+ */
17
+ export const webhookEventPatternSchema = z
18
+ .string()
19
+ .max(80)
20
+ .regex(/^(\*|[a-z][a-z0-9_]*\.(\*|[a-z][a-z0-9_]*))$/, 'an event type (thing.created), a family (thing.*) or everything (*)');
21
+ /** A subject key of the catalog (`thing`, `project`): lowercase, digits and underscores. */
22
+ export const webhookSubjectKeySchema = z
23
+ .string()
24
+ .max(40)
25
+ .regex(/^[a-z][a-z0-9_]*$/, 'lowercase letters, digits and underscores, starting with a letter');
26
+ /**
27
+ * Narrows a subscription by subject: a subject key mapped to the ids it
28
+ * accepts. AND across keys, OR within a key; an event that does not carry a
29
+ * filtered subject does not match. An empty object filters nothing.
30
+ */
31
+ export const webhookFiltersSchema = z
32
+ .record(webhookSubjectKeySchema, z.array(plainText(1, 200)).min(1).max(100))
33
+ .refine((v) => Object.keys(v).length <= 10, { error: 'at most 10 subject keys' })
34
+ .describe('Subject key → ids; AND across keys, OR within a key; an event that does not carry a filtered subject does not match');
35
+ const UrlParser = globalThis.URL;
36
+ function isHttpUrlWithoutCredentials(value) {
37
+ let parsed;
38
+ try {
39
+ parsed = new UrlParser(value);
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ return ((parsed.protocol === 'http:' || parsed.protocol === 'https:') &&
45
+ parsed.username === '' &&
46
+ parsed.password === '');
47
+ }
48
+ /**
49
+ * Where the deliveries go: an http or https URL without credentials. Whitespace
50
+ * and control characters are refused outright, because the URL parser silently
51
+ * strips tabs and newlines, so the stored string would not be the address
52
+ * delivered to. The address rules (ports, private networks, https on the cloud
53
+ * edition) are the server's, answered `url_refused`.
54
+ */
55
+ export const webhookUrlSchema = z
56
+ .string()
57
+ .max(2048)
58
+ .refine((v) => !/\s/.test(v) && !hasControlChars(v), {
59
+ error: 'must not contain whitespace or control characters',
60
+ abort: true
61
+ })
62
+ .refine(isHttpUrlWithoutCredentials, { error: 'an http or https URL without credentials' });
63
+ export const webhookDeliveryStatusSchema = z.enum(['pending', 'delivered', 'failed', 'held']);
64
+ export const webhookEndpointSchema = z.object({
65
+ id: z.string(),
66
+ url: z.string(),
67
+ description: z.string(),
68
+ events: z.array(z.string()),
69
+ filters: z.record(z.string(), z.array(z.string())),
70
+ enabled: z.boolean(),
71
+ createdBy: z.string().nullable(),
72
+ createdAt: z.string(),
73
+ updatedAt: z.string(),
74
+ /** Set with `disabledReason` when the endpoint was switched off after failing too long. */
75
+ disabledAt: z.string().nullable(),
76
+ disabledReason: z.string().nullable(),
77
+ consecutiveFailures: z.number().int(),
78
+ lastDeliveryAt: z.string().nullable(),
79
+ lastDeliveryStatus: z.enum(['delivered', 'failed']).nullable(),
80
+ /** During a rotation, the previous secret keeps signing until this date. */
81
+ previousSecretExpiresAt: z.string().nullable()
82
+ });
83
+ /** The endpoint as created, with its signing secret (`whsec_…`), shown ONCE. */
84
+ export const webhookEndpointCreatedSchema = webhookEndpointSchema.extend({
85
+ secret: z.string()
86
+ });
87
+ /**
88
+ * The endpoint after a rotation, with its new secret, shown ONCE; the previous
89
+ * secret keeps signing until `previousSecretExpiresAt`.
90
+ */
91
+ export const webhookSecretRotatedSchema = webhookEndpointSchema.extend({
92
+ secret: z.string(),
93
+ previousSecretExpiresAt: z.string()
94
+ });
95
+ const webhookDescriptionSchema = plainText(0, 200);
96
+ const webhookEventsSchema = z.array(webhookEventPatternSchema).min(1).max(50);
97
+ export const webhookEndpointCreateSchema = z.object({
98
+ url: webhookUrlSchema,
99
+ description: webhookDescriptionSchema.default(''),
100
+ events: webhookEventsSchema,
101
+ filters: webhookFiltersSchema.default({}),
102
+ enabled: z.boolean().default(true)
103
+ });
104
+ /** Every field optional, none defaulted (a PATCH never resets what it does not name). */
105
+ export const webhookEndpointUpdateSchema = z
106
+ .object({
107
+ url: webhookUrlSchema.optional(),
108
+ description: webhookDescriptionSchema.optional(),
109
+ events: webhookEventsSchema.optional(),
110
+ filters: webhookFiltersSchema.optional(),
111
+ enabled: z.boolean().optional()
112
+ })
113
+ .refine((b) => Object.values(b).some((v) => v !== undefined), { error: 'nothing to change' });
114
+ export const webhooksListSchema = z.object({
115
+ webhooks: z.array(webhookEndpointSchema),
116
+ nextCursor: z.string().nullable()
117
+ });
118
+ export const webhooksListQuerySchema = cursorPageQuerySchema;
119
+ /**
120
+ * One event sent to one endpoint, with its attempts. `eventId` is the
121
+ * receiver's dedupe key, the same on every attempt and on a redelivery;
122
+ * `lastStatusCode` and `lastError` describe the latest attempt only;
123
+ * `payload` is the envelope as sent.
124
+ */
125
+ export const webhookDeliverySchema = z.object({
126
+ id: z.string(),
127
+ endpointId: z.string(),
128
+ eventId: z.string(),
129
+ eventType: z.string(),
130
+ status: webhookDeliveryStatusSchema,
131
+ attempt: z.number().int(),
132
+ lastStatusCode: z.number().int().nullable(),
133
+ lastError: z.string().nullable(),
134
+ nextAttemptAt: z.string().nullable(),
135
+ deliveredAt: z.string().nullable(),
136
+ createdAt: z.string(),
137
+ updatedAt: z.string(),
138
+ payload: z.record(z.string(), z.unknown())
139
+ });
140
+ export const webhookDeliveriesListSchema = z.object({
141
+ deliveries: z.array(webhookDeliverySchema),
142
+ nextCursor: z.string().nullable()
143
+ });
144
+ export const webhookDeliveriesListQuerySchema = cursorPageQuerySchema.extend({
145
+ status: webhookDeliveryStatusSchema.optional()
146
+ });
147
+ /** The `webhook.ping` attempted inline: its outcome is on the delivery row. */
148
+ export const webhookTestResultSchema = z.object({
149
+ delivery: webhookDeliverySchema
150
+ });
151
+ /** A subject events can carry and endpoints can filter on: its key (what a filter names), the field of the envelope's `subjects` its value is written under (one id or a list of ids). */
152
+ export const webhookCatalogSubjectSchema = z.object({
153
+ key: z.string(),
154
+ field: z.string(),
155
+ description: z.string(),
156
+ /** The value under `field` is always a list of ids (`projectIds`); else always one id. */
157
+ list: z.boolean()
158
+ });
159
+ export const webhookCatalogEventSchema = z.object({
160
+ type: z.string(),
161
+ description: z.string(),
162
+ /** The subject keys this event carries (what a filter can match it on). */
163
+ subjects: z.array(z.string()),
164
+ /** The JSON Schema of the event's `data`. */
165
+ schema: z.record(z.string(), z.unknown())
166
+ });
167
+ export const webhookCatalogSchema = z.object({
168
+ subjects: z.array(webhookCatalogSubjectSchema),
169
+ events: z.array(webhookCatalogEventSchema)
170
+ });
171
+ /** `{id}` the endpoint (a uuid, as every `{id}` path param). */
172
+ export const webhookParamsSchema = z.object({ id: z.uuid() });
173
+ /** `{id}` the endpoint, `{deliveryId}` one of its deliveries: both uuids. */
174
+ export const webhookDeliveryParamsSchema = webhookParamsSchema.extend({ deliveryId: z.uuid() });
175
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/schemas/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEhF;;;;;;;;;GASG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC;KACvC,MAAM,EAAE;KACR,GAAG,CAAC,EAAE,CAAC;KACP,KAAK,CACJ,8CAA8C,EAC9C,qEAAqE,CACtE,CAAC;AAEJ,4FAA4F;AAC5F,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,EAAE;KACR,GAAG,CAAC,EAAE,CAAC;KACP,KAAK,CAAC,mBAAmB,EAAE,mEAAmE,CAAC,CAAC;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC,uBAAuB,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC3E,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC;KAChF,QAAQ,CACP,qHAAqH,CACtH,CAAC;AASJ,MAAM,SAAS,GAAI,UAAkE,CAAC,GAAG,CAAC;AAE1F,SAAS,2BAA2B,CAAC,KAAa;IAChD,IAAI,MAAgB,CAAC;IACrB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,SAAS,CAA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M,EAAE;IACvB,0FAA0F;IAC1F,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;CAClB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,2EAA2E;IAC3E,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7B,6CAA6C;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;CAC1C,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,2BAA2B,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,yBAAyB,CAAC;CAC3C,CAAC,CAAC;AAGH,gEAAgE;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAE9D,6EAA6E;AAC7E,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antasphere/chassis-contract",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "repository": {
6
6
  "type": "git",
package/src/identity.ts CHANGED
@@ -16,8 +16,13 @@ export interface ToolIdentity<TScope extends string = string> {
16
16
  displayName: string;
17
17
  /** API key prefix, without the underscore (`acm` mints `acm_<keyId>_<secret>`). Never change it once keys exist. */
18
18
  apiKeyPrefix: string;
19
- /** The scope vocabulary, by the part each scope plays. `dataExport` is the opt-in full-workspace export. */
20
- scopes: { read: TScope; write: TScope; dataExport: TScope };
19
+ /**
20
+ * The scope vocabulary, by the part each scope plays. `dataExport` is the
21
+ * opt-in full-workspace export; `webhooks` the opt-in management of the
22
+ * workspace's webhook endpoints (PRDCT-3482), absent on a tool that opens
23
+ * them to no machine.
24
+ */
25
+ scopes: { read: TScope; write: TScope; dataExport: TScope; webhooks?: TScope };
21
26
  /** How the OpenAPI document names the CLI key's grant (`things:read+write`). A literal: a contraction, not a join. */
22
27
  cliKeyScopesLabel: string;
23
28
  /**
package/src/index.ts CHANGED
@@ -23,6 +23,7 @@ export {
23
23
  type CliAuthRevoked
24
24
  } from './schemas/cli-auth.js';
25
25
  export * from './schemas/sso-connect.js';
26
+ export * from './schemas/cli-package.js';
26
27
  export * from './schemas/sso-logout.js';
27
28
  export * from './schemas/invitations.js';
28
29
  export * from './schemas/audit.js';
@@ -30,6 +31,7 @@ export * from './schemas/break-glass.js';
30
31
  export * from './schemas/files.js';
31
32
  export * from './schemas/projects.js';
32
33
  export * from './schemas/teams.js';
34
+ export * from './schemas/webhooks.js';
33
35
  export * from './schemas/demo-passes.js';
34
36
  export * from './seams.js';
35
37
  export * from './entitlements.js';