@domino-sdk/relay 1.72.0 → 1.74.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/{accounts-COLmXRbW.d.ts → accounts-C9as33l1.d.ts} +2 -2
  3. package/dist/{attempt-captures-CVl161qB.d.ts → attempt-captures-DU4vi20Y.d.ts} +2 -2
  4. package/dist/authoring.d.ts +103 -106
  5. package/dist/authoring.js +187 -286
  6. package/dist/{automatic-outcomes-5l68PGr1.d.ts → automatic-outcomes-D0yMHSHL.d.ts} +2 -2
  7. package/dist/browser.d.ts +9 -9
  8. package/dist/browser.js +11 -11
  9. package/dist/{dashboards-DXpjHnq-.d.ts → capability-error-Bn6cCqof.d.ts} +298 -5
  10. package/dist/{catalog-BR3g-1H9.d.ts → catalog-9I6t18qP.d.ts} +2 -2
  11. package/dist/{chunk-W6DBNBMT.js → chunk-2LURSPDM.js} +232 -232
  12. package/dist/{chunk-VNEJH4NT.js → chunk-2M5FM7FW.js} +21 -0
  13. package/dist/{chunk-74SMLZZ5.js → chunk-6TDHRGBM.js} +1522 -1278
  14. package/dist/{chunk-QG6XVOOO.js → chunk-724CKAC7.js} +4 -4
  15. package/dist/{chunk-I7XIBXT2.js → chunk-7I7P5UVC.js} +3 -3
  16. package/dist/{chunk-LDO5GP7G.js → chunk-AL5XMXPO.js} +1 -1
  17. package/dist/{chunk-TW4RABVS.js → chunk-CW7FJ5PX.js} +1 -1
  18. package/dist/{chunk-BXUF3CRL.js → chunk-DNOLNMCW.js} +9 -9
  19. package/dist/{chunk-5RLIPTL7.js → chunk-E73HZCG2.js} +1 -1
  20. package/dist/{chunk-UEVZ3TST.js → chunk-ELHMJODS.js} +1 -1
  21. package/dist/{chunk-ASBDB436.js → chunk-F66GGNKD.js} +1 -1
  22. package/dist/{chunk-ETGKC2SB.js → chunk-HCOLMJFX.js} +2 -2
  23. package/dist/chunk-JZT2NLSG.js +7201 -0
  24. package/dist/{chunk-FGZGL5PG.js → chunk-KGZ7SRKJ.js} +2 -2
  25. package/dist/{chunk-3KKRXN5E.js → chunk-KP55TMCC.js} +1 -1
  26. package/dist/chunk-NI6XRGEL.js +374 -0
  27. package/dist/{chunk-VFHLMNYV.js → chunk-RALBAKKX.js} +1 -1
  28. package/dist/chunk-SVZ3QWHT.js +142 -0
  29. package/dist/{chunk-CVJTIVAP.js → chunk-T4PTFCSB.js} +2 -2
  30. package/dist/{chunk-KIRXE37T.js → chunk-TGQNNMCY.js} +6 -6
  31. package/dist/{client-B__hMWtK.d.ts → client-B2aVGf38.d.ts} +7 -7
  32. package/dist/{deployments-CT2kQloT.d.ts → deployments-CGV1rIZm.d.ts} +107 -107
  33. package/dist/{identity-integration-ClX4oUAu.d.ts → identity-integration-C03rUYc0.d.ts} +3 -3
  34. package/dist/index.d.ts +10 -10
  35. package/dist/index.js +10 -10
  36. package/dist/internal.d.ts +36197 -18
  37. package/dist/internal.js +518 -15
  38. package/dist/{limits-B7wbnWhd.d.ts → limits-p-Mg0oSi.d.ts} +1 -1
  39. package/dist/{offers-D4pyeY9b.d.ts → offers-CnMyMeQo.d.ts} +2 -2
  40. package/dist/portal-proxy.d.ts +2 -2
  41. package/dist/portal-proxy.js +10 -10
  42. package/dist/react/index.d.ts +11 -11
  43. package/dist/react/index.js +11 -11
  44. package/dist/{reward-deliveries-HGpj1VFz.d.ts → reward-deliveries-zWfsgc6m.d.ts} +1 -1
  45. package/dist/runtime/authoring.js +1 -1
  46. package/dist/runtime/chunks/NYEWMPJH.js +1 -0
  47. package/dist/runtime/manifest.json +3 -3
  48. package/dist/runtime/schema.js +1 -1
  49. package/dist/schema.d.ts +35 -60
  50. package/dist/schema.js +10 -8
  51. package/dist/server/index.d.ts +13 -13
  52. package/dist/server/index.js +2972 -4528
  53. package/dist/{sign-in-providers-lbOXCF8N.d.ts → sign-in-providers-BG22ZZkl.d.ts} +2 -2
  54. package/dist/solana.d.ts +13 -13
  55. package/dist/solana.js +9 -9
  56. package/dist/stake-BSVjB3BJ.d.ts +254 -0
  57. package/dist/{station-check-in-qBiaftfE.d.ts → station-check-in-a1deSjbm.d.ts} +5 -5
  58. package/dist/{submission-input-U4aIkJuT.d.ts → submission-input-DBDLkTF8.d.ts} +2 -2
  59. package/dist/telegram.d.ts +7 -7
  60. package/dist/telegram.js +2 -2
  61. package/dist/testing.d.ts +159 -160
  62. package/dist/testing.js +47 -344
  63. package/dist/{tracker-data-2BYXZjsN.d.ts → tracker-data-Dwq9dWEm.d.ts} +474 -221
  64. package/dist/{transport-DcRXDZ1j.d.ts → transport-D77Rbf4D.d.ts} +77050 -74062
  65. package/dist/{wallet-BqswMAqZ.d.ts → wallet-CeqgtXNm.d.ts} +2 -7
  66. package/dist/{wallet-browser-B5r7u3xB.d.ts → wallet-browser-Cucpqn3F.d.ts} +1 -1
  67. package/package.json +1 -1
  68. package/dist/capability-error-db7kO8-P.d.ts +0 -297
  69. package/dist/chunk-2UELTHW6.js +0 -467
  70. package/dist/chunk-GHBYWDEZ.js +0 -94
  71. package/dist/chunk-HN7DE2UN.js +0 -53
  72. package/dist/runtime/chunks/A7G5P76B.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  activityTypeSchema
3
- } from "./chunk-KIRXE37T.js";
3
+ } from "./chunk-TGQNNMCY.js";
4
4
  import {
5
5
  completionRecordSchema,
6
6
  completionSourceSchema,
@@ -10,146 +10,14 @@ import {
10
10
  pageLimit,
11
11
  solanaAddressSchema,
12
12
  solanaSignatureSchema
13
- } from "./chunk-74SMLZZ5.js";
14
-
15
- // src/server/webhooks.ts
16
- import * as z from "zod";
17
- var PayoutSourceKind = {
18
- Quest: "quest",
19
- Leaderboard: "leaderboard",
20
- Engagement: "engagement",
21
- Manual: "manual"
22
- };
23
- var webhookEventSchema = /* @__PURE__ */ (() => z.object({
24
- id: z.string().uuid(),
25
- version: z.literal(1),
26
- type: activityTypeSchema,
27
- createdAt: z.number().int().nonnegative(),
28
- organization: z.string(),
29
- project: z.string(),
30
- environment: z.enum(["test", "live"]),
31
- data: z.record(z.string(), z.json())
32
- }))();
33
- var walletLinkedEventDataSchema = /* @__PURE__ */ (() => z.object({
34
- member: z.string(),
35
- chain: z.string(),
36
- network: z.string().nullable(),
37
- address: z.string()
38
- }))();
39
- var webhookControlInputSchema = /* @__PURE__ */ (() => z.object({ actionId: z.string().uuid().optional() }).strict())();
40
- var webhookInputSchema = /* @__PURE__ */ (() => z.object({
41
- url: z.url().max(2048).refine((value) => {
42
- const url2 = new URL(value);
43
- return url2.protocol === "https:" && !url2.username && !url2.password && !url2.hash;
44
- }, "Use an HTTPS URL without credentials or a fragment"),
45
- types: z.array(activityTypeSchema).min(1).max(100).refine((v) => new Set(v).size === v.length)
46
- }).strict())();
47
- var webhookCreateInputSchema = /* @__PURE__ */ (() => webhookInputSchema.extend({ actionId: z.string().uuid().optional() }).strict())();
48
- var webhookRotateInputSchema = /* @__PURE__ */ (() => z.object({ actionId: z.string().uuid().optional() }).strict())();
49
- var webhookUpdateSchema = /* @__PURE__ */ (() => webhookInputSchema.partial().extend({ enabled: z.boolean().optional() }).strict())();
50
- var webhookEndpointSchema = /* @__PURE__ */ (() => z.object({
51
- ...webhookInputSchema.shape,
52
- id: z.string().uuid(),
53
- enabled: z.boolean(),
54
- disabledReason: z.string().nullable(),
55
- consecutiveFailures: z.number().int().nonnegative(),
56
- createdAt: z.number(),
57
- updatedAt: z.number()
58
- }))();
59
- var webhookEndpointStateSchema = /* @__PURE__ */ (() => webhookEndpointSchema.extend({
60
- revision: z.number().int().nonnegative(),
61
- deletedAt: z.number().int().safe().nonnegative().nullable()
62
- }))();
63
- var webhookDeleteInputSchema = /* @__PURE__ */ (() => z.strictObject({
64
- actionId: z.string().uuid().default(() => crypto.randomUUID()),
65
- expectedRevision: z.number().int().nonnegative(),
66
- reason: z.string().trim().min(1).max(500)
67
- }))();
68
- var webhookStateQuerySchema = /* @__PURE__ */ (() => z.strictObject({
69
- cursor: pageCursorSchema.optional(),
70
- limit: z.coerce.number().int().min(1).max(100).default(50)
71
- }))();
72
- var webhookStatePageSchema = /* @__PURE__ */ (() => z.object({
73
- items: z.array(webhookEndpointStateSchema),
74
- nextCursor: pageCursorSchema.nullable()
75
- }))();
76
- var webhookSecretSchema = /* @__PURE__ */ (() => z.object({
77
- endpoint: webhookEndpointSchema,
78
- secret: z.string(),
79
- previousValidUntil: z.number().nullable()
80
- }))();
81
- var webhookDeliverySchema = /* @__PURE__ */ (() => z.object({
82
- id: z.string().uuid(),
83
- endpoint: z.string().uuid(),
84
- event: webhookEventSchema,
85
- status: z.enum(["pending", "delivered", "failed", "skipped"]),
86
- attempts: z.number().int().nonnegative(),
87
- responseStatus: z.number().nullable(),
88
- lastError: z.string().nullable(),
89
- createdAt: z.number(),
90
- deliveredAt: z.number().nullable(),
91
- replayOf: z.string().uuid().nullable()
92
- }))();
93
- var webhookQuerySchema = /* @__PURE__ */ (() => z.object({
94
- /** A page's `nextCursor`: the deliveries after it, newest first. */
95
- cursor: pageCursorSchema.optional(),
96
- /** @deprecated Use `cursor`. Removed in 2.0.0. */
97
- before: z.string().uuid().optional(),
98
- limit: z.coerce.number().int().min(1).max(100).default(50)
99
- }).strict())();
100
- var webhookDeliveryPageSchema = /* @__PURE__ */ (() => z.object({
101
- items: z.array(webhookDeliverySchema),
102
- nextCursor: pageCursorSchema.nullable().default(null),
103
- /** @deprecated Use `nextCursor`, passed back as `cursor`. Removed in 2.0.0. */
104
- next: z.string().uuid().nullable()
105
- }))();
106
- var WEBHOOK_MAX_BYTES = 64 * 1024;
107
- async function verifyWebhook(input) {
108
- const bytes = new TextEncoder().encode(input.body);
109
- const tolerance = input.toleranceSeconds ?? 300;
110
- const now = input.now ?? Date.now();
111
- if (bytes.length > WEBHOOK_MAX_BYTES || !Number.isFinite(now) || !Number.isFinite(tolerance) || tolerance < 0 || tolerance > 300) {
112
- throw new Error("Invalid webhook verification input");
113
- }
114
- const parts = input.signature.split(",");
115
- const timestamps = parts.filter((part) => part.startsWith("t="));
116
- const timestamp = timestamps[0]?.slice(2) ?? "";
117
- const signatures = parts.filter((part) => /^v1=[a-f0-9]{64}$/.test(part)).map((part) => part.slice(3));
118
- if (timestamps.length !== 1 || !/^\d{1,12}$/.test(timestamp) || Math.abs(now / 1e3 - Number(timestamp)) > tolerance || signatures.length < 1 || signatures.length > 2) {
119
- throw new Error("Invalid or expired webhook signature");
120
- }
121
- const secrets = typeof input.secret === "string" ? [input.secret] : input.secret;
122
- const message = new TextEncoder().encode(`${timestamp}.${input.body}`);
123
- for (const secret of secrets) {
124
- if (!secret) {
125
- continue;
126
- }
127
- const key = await crypto.subtle.importKey(
128
- "raw",
129
- new TextEncoder().encode(secret),
130
- { name: "HMAC", hash: "SHA-256" },
131
- false,
132
- ["verify"]
133
- );
134
- for (const signature of signatures) {
135
- const digest = Uint8Array.from(
136
- signature.match(/../g) ?? [],
137
- (byte) => Number.parseInt(byte, 16)
138
- );
139
- if (await crypto.subtle.verify("HMAC", key, digest, message)) {
140
- return webhookEventSchema.parse(JSON.parse(input.body));
141
- }
142
- }
143
- }
144
- throw new Error("Invalid webhook signature");
145
- }
13
+ } from "./chunk-6TDHRGBM.js";
146
14
 
147
15
  // src/server/completions.ts
148
- import * as z2 from "zod";
149
- var completionRevokeSchema = /* @__PURE__ */ (() => z2.object({
16
+ import * as z from "zod";
17
+ var completionRevokeSchema = /* @__PURE__ */ (() => z.object({
150
18
  actionId: identifier,
151
- reason: z2.string().trim().min(1).max(500),
152
- freeOccurrence: z2.boolean().default(false)
19
+ reason: z.string().trim().min(1).max(500),
20
+ freeOccurrence: z.boolean().default(false)
153
21
  }).strict())();
154
22
  var RevokedEntitlementOutcome = {
155
23
  /** No other completion grants the reward: it is void, after cancelling a handover in progress. */
@@ -177,63 +45,63 @@ var RevokedReferralOutcome = {
177
45
  /** Qualified on another accepted completion of the program's quest instead. */
178
46
  Requalified: "requalified"
179
47
  };
180
- var entitlementOutcomeSchema = /* @__PURE__ */ (() => z2.string().min(1).max(64))();
181
- var deliveryOutcomeSchema = /* @__PURE__ */ (() => z2.string().min(1).max(64))();
182
- var referralOutcomeSchema = /* @__PURE__ */ (() => z2.string().min(1).max(64))();
183
- var completionRevocationSchema = /* @__PURE__ */ (() => z2.object({
48
+ var entitlementOutcomeSchema = /* @__PURE__ */ (() => z.string().min(1).max(64))();
49
+ var deliveryOutcomeSchema = /* @__PURE__ */ (() => z.string().min(1).max(64))();
50
+ var referralOutcomeSchema = /* @__PURE__ */ (() => z.string().min(1).max(64))();
51
+ var completionRevocationSchema = /* @__PURE__ */ (() => z.object({
184
52
  completion: identifier,
185
53
  /** The quest ID, or the board ID when `source.kind` is `leaderboard`. */
186
54
  quest: identifier,
187
55
  member: identifier,
188
56
  /** What paid the revoked completion. `source.id` repeats `quest`. */
189
57
  source: completionSourceSchema.optional(),
190
- revokedAt: z2.number(),
191
- occurrenceFreed: z2.boolean(),
192
- badges: z2.array(z2.object({ badge: identifier, stillAwarded: z2.boolean() })).optional(),
193
- groups: z2.array(z2.object({ group: identifier, stillMember: z2.boolean() })).optional(),
194
- points: z2.array(
195
- z2.object({
58
+ revokedAt: z.number(),
59
+ occurrenceFreed: z.boolean(),
60
+ badges: z.array(z.object({ badge: identifier, stillAwarded: z.boolean() })).optional(),
61
+ groups: z.array(z.object({ group: identifier, stillMember: z.boolean() })).optional(),
62
+ points: z.array(
63
+ z.object({
196
64
  entry: identifier,
197
65
  balance: identifier,
198
66
  reversal: identifier.nullable(),
199
- reversed: z2.number().int(),
200
- unreversed: z2.number().int()
67
+ reversed: z.number().int(),
68
+ unreversed: z.number().int()
201
69
  })
202
70
  ),
203
- entitlements: z2.array(
204
- z2.object({
71
+ entitlements: z.array(
72
+ z.object({
205
73
  entitlement: identifier,
206
74
  reward: identifier,
207
75
  outcome: entitlementOutcomeSchema,
208
- status: z2.string()
76
+ status: z.string()
209
77
  })
210
78
  ),
211
- deliveries: z2.array(
212
- z2.object({
213
- delivery: z2.string(),
214
- roleId: z2.string(),
79
+ deliveries: z.array(
80
+ z.object({
81
+ delivery: z.string(),
82
+ roleId: z.string(),
215
83
  outcome: deliveryOutcomeSchema,
216
84
  /**
217
85
  * By Relay's records, another accepted, unrevoked completion of the member also granted this
218
86
  * role to the same Discord account and server. Relay does not read Discord's membership.
219
87
  */
220
- stillGranted: z2.boolean()
88
+ stillGranted: z.boolean()
221
89
  })
222
90
  ),
223
- referrals: z2.array(
224
- z2.object({
91
+ referrals: z.array(
92
+ z.object({
225
93
  program: identifier,
226
94
  outcome: referralOutcomeSchema
227
95
  })
228
96
  ),
229
- streakMilestone: z2.boolean(),
230
- budgets: z2.array(
231
- z2.object({ budget: identifier, released: z2.number().int().nonnegative() })
97
+ streakMilestone: z.boolean(),
98
+ budgets: z.array(
99
+ z.object({ budget: identifier, released: z.number().int().nonnegative() })
232
100
  ).optional()
233
101
  }))();
234
- var completionRestoreSchema = /* @__PURE__ */ (() => z2.object({
102
+ var completionRestoreSchema = /* @__PURE__ */ (() => z.object({
235
103
  actionId: identifier,
236
- reason: z2.string().trim().min(1).max(500)
104
+ reason: z.string().trim().min(1).max(500)
237
105
  }).strict())();
238
106
  var RestoredEntitlementOutcome = {
239
107
  /** The revocation voided it, and it is available again. */
@@ -255,83 +123,83 @@ var RestoredReferralOutcome = {
255
123
  /** The program is disabled or gone, or the referral is suspended, so nothing changed. */
256
124
  Kept: "kept"
257
125
  };
258
- var openOutcome = /* @__PURE__ */ (() => z2.string().min(1).max(64))();
259
- var completionRestorationSchema = /* @__PURE__ */ (() => z2.object({
126
+ var openOutcome = /* @__PURE__ */ (() => z.string().min(1).max(64))();
127
+ var completionRestorationSchema = /* @__PURE__ */ (() => z.object({
260
128
  completion: identifier,
261
129
  /** The quest ID, or the board ID when `source.kind` is `leaderboard`. */
262
130
  quest: identifier,
263
131
  member: identifier,
264
132
  source: completionSourceSchema.optional(),
265
- restoredAt: z2.number(),
266
- points: z2.array(
267
- z2.object({
133
+ restoredAt: z.number(),
134
+ points: z.array(
135
+ z.object({
268
136
  entry: identifier,
269
137
  balance: identifier,
270
138
  reversal: identifier,
271
- amount: z2.number().int()
139
+ amount: z.number().int()
272
140
  })
273
141
  ),
274
- badges: z2.array(z2.object({ badge: identifier })),
275
- groups: z2.array(z2.object({ group: identifier, added: z2.boolean() })),
276
- entitlements: z2.array(
277
- z2.object({
142
+ badges: z.array(z.object({ badge: identifier })),
143
+ groups: z.array(z.object({ group: identifier, added: z.boolean() })),
144
+ entitlements: z.array(
145
+ z.object({
278
146
  entitlement: identifier,
279
147
  reward: identifier,
280
148
  outcome: openOutcome,
281
- status: z2.string()
149
+ status: z.string()
282
150
  })
283
151
  ),
284
- deliveries: z2.array(
285
- z2.object({
286
- delivery: z2.string(),
287
- roleId: z2.string(),
152
+ deliveries: z.array(
153
+ z.object({
154
+ delivery: z.string(),
155
+ roleId: z.string(),
288
156
  outcome: openOutcome
289
157
  })
290
158
  ),
291
- referrals: z2.array(
292
- z2.object({
159
+ referrals: z.array(
160
+ z.object({
293
161
  program: identifier,
294
162
  outcome: openOutcome
295
163
  })
296
164
  ),
297
- streakMilestone: z2.boolean(),
298
- budgets: z2.array(
299
- z2.object({ budget: identifier, charged: z2.number().int().nonnegative() })
165
+ streakMilestone: z.boolean(),
166
+ budgets: z.array(
167
+ z.object({ budget: identifier, charged: z.number().int().nonnegative() })
300
168
  ).optional()
301
169
  }))();
302
- var completionRevocationShortfallSchema = /* @__PURE__ */ (() => z2.object({
170
+ var completionRevocationShortfallSchema = /* @__PURE__ */ (() => z.object({
303
171
  completion: identifier,
304
172
  quest: identifier,
305
- revokedAt: z2.number().int().nonnegative().safe(),
306
- unreversedPoints: z2.record(identifier, z2.number().int().positive().safe())
173
+ revokedAt: z.number().int().nonnegative().safe(),
174
+ unreversedPoints: z.record(identifier, z.number().int().positive().safe())
307
175
  }))();
308
- var revokedCompletionSchema = /* @__PURE__ */ (() => z2.object({
176
+ var revokedCompletionSchema = /* @__PURE__ */ (() => z.object({
309
177
  completion: identifier,
310
178
  quest: identifier,
311
179
  /** The completion key: its occurrence, such as `once` or a day. */
312
- key: z2.string(),
313
- revokedAt: z2.number().int().nonnegative().safe(),
180
+ key: z.string(),
181
+ revokedAt: z.number().int().nonnegative().safe(),
314
182
  /** Why it was revoked, and what the revoke did, which a restore re-applies. */
315
- reason: z2.string().optional(),
183
+ reason: z.string().optional(),
316
184
  revocation: completionRevocationSchema.optional()
317
185
  }))();
318
186
  var maxCompletionReceipts = 20;
319
187
  var receiptNetworkPattern = /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/;
320
- var receiptValue = /* @__PURE__ */ (() => z2.string().min(1).max(256).regex(/^[\x21-\x7e]+$/, "Use printable characters without spaces"))();
321
- var completionReceiptInputSchema = /* @__PURE__ */ (() => z2.object({
188
+ var receiptValue = /* @__PURE__ */ (() => z.string().min(1).max(256).regex(/^[\x21-\x7e]+$/, "Use printable characters without spaces"))();
189
+ var completionReceiptInputSchema = /* @__PURE__ */ (() => z.object({
322
190
  actionId: identifier,
323
- key: z2.string().regex(
191
+ key: z.string().regex(
324
192
  /^[a-z0-9][a-z0-9._-]{0,63}$/,
325
193
  "Use 1 to 64 lowercase letters, digits, dots, hyphens or underscores"
326
194
  ),
327
- network: z2.string().regex(
195
+ network: z.string().regex(
328
196
  receiptNetworkPattern,
329
197
  "Use a CAIP-2 chain ID such as solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
330
198
  ),
331
199
  signature: receiptValue,
332
200
  asset: receiptValue.optional(),
333
201
  recipient: receiptValue.optional(),
334
- label: z2.string().trim().min(1).max(120).optional()
202
+ label: z.string().trim().min(1).max(120).optional()
335
203
  }).strict().superRefine((receipt, context) => {
336
204
  if (!isSolanaNetwork(receipt.network)) {
337
205
  return;
@@ -354,57 +222,170 @@ var completionReceiptInputSchema = /* @__PURE__ */ (() => z2.object({
354
222
  }
355
223
  }
356
224
  }))();
357
- var completionReceiptSchema = /* @__PURE__ */ (() => z2.object({
225
+ var completionReceiptSchema = /* @__PURE__ */ (() => z.object({
358
226
  completion: identifier,
359
227
  /** The quest ID, or the board ID for a leaderboard prize's completion. */
360
228
  quest: identifier,
361
229
  member: identifier,
362
- key: z2.string(),
363
- network: z2.string(),
364
- signature: z2.string(),
365
- asset: z2.string().nullable(),
366
- recipient: z2.string().nullable(),
367
- label: z2.string().nullable(),
368
- recordedAt: z2.number().int().nonnegative().safe(),
230
+ key: z.string(),
231
+ network: z.string(),
232
+ signature: z.string(),
233
+ asset: z.string().nullable(),
234
+ recipient: z.string().nullable(),
235
+ label: z.string().nullable(),
236
+ recordedAt: z.number().int().nonnegative().safe(),
369
237
  /** The operator or key that recorded it. */
370
- recordedBy: z2.string().nullable(),
371
- completionRevokedAt: z2.number().int().nonnegative().safe().nullable()
238
+ recordedBy: z.string().nullable(),
239
+ completionRevokedAt: z.number().int().nonnegative().safe().nullable()
372
240
  }))();
373
- var completionReceiptListSchema = /* @__PURE__ */ (() => z2.array(completionReceiptSchema))();
374
- var memberCompletionQuerySchema = /* @__PURE__ */ (() => z2.strictObject({
241
+ var completionReceiptListSchema = /* @__PURE__ */ (() => z.array(completionReceiptSchema))();
242
+ var memberCompletionQuerySchema = /* @__PURE__ */ (() => z.strictObject({
375
243
  member: identifier,
376
244
  quest: identifier.optional(),
377
245
  cursor: pageCursorSchema.optional(),
378
246
  limit: pageLimit
379
247
  }))();
380
248
  var memberCompletionSchema = /* @__PURE__ */ (() => completionRecordSchema.extend({
381
- completedAt: z2.number().int().nonnegative().safe().nullable()
249
+ completedAt: z.number().int().nonnegative().safe().nullable()
250
+ }))();
251
+ var memberCompletionPageSchema = /* @__PURE__ */ (() => z.object({
252
+ items: z.array(memberCompletionSchema),
253
+ nextCursor: pageCursorSchema.nullable()
254
+ }))();
255
+
256
+ // src/server/webhooks.ts
257
+ import * as z2 from "zod";
258
+ var PayoutSourceKind = {
259
+ Quest: "quest",
260
+ Leaderboard: "leaderboard",
261
+ Engagement: "engagement",
262
+ Manual: "manual"
263
+ };
264
+ var webhookEventSchema = /* @__PURE__ */ (() => z2.object({
265
+ id: z2.string().uuid(),
266
+ version: z2.literal(1),
267
+ type: activityTypeSchema,
268
+ createdAt: z2.number().int().nonnegative(),
269
+ organization: z2.string(),
270
+ project: z2.string(),
271
+ environment: z2.enum(["test", "live"]),
272
+ data: z2.record(z2.string(), z2.json())
273
+ }))();
274
+ var walletLinkedEventDataSchema = /* @__PURE__ */ (() => z2.object({
275
+ member: z2.string(),
276
+ chain: z2.string(),
277
+ network: z2.string().nullable(),
278
+ address: z2.string()
279
+ }))();
280
+ var webhookControlInputSchema = /* @__PURE__ */ (() => z2.object({ actionId: z2.string().uuid().optional() }).strict())();
281
+ var webhookInputSchema = /* @__PURE__ */ (() => z2.object({
282
+ url: z2.url().max(2048).refine((value) => {
283
+ const url2 = new URL(value);
284
+ return url2.protocol === "https:" && !url2.username && !url2.password && !url2.hash;
285
+ }, "Use an HTTPS URL without credentials or a fragment"),
286
+ types: z2.array(activityTypeSchema).min(1).max(100).refine((v) => new Set(v).size === v.length)
287
+ }).strict())();
288
+ var webhookCreateInputSchema = /* @__PURE__ */ (() => webhookInputSchema.extend({ actionId: z2.string().uuid().optional() }).strict())();
289
+ var webhookRotateInputSchema = /* @__PURE__ */ (() => z2.object({ actionId: z2.string().uuid().optional() }).strict())();
290
+ var webhookUpdateSchema = /* @__PURE__ */ (() => webhookInputSchema.partial().extend({ enabled: z2.boolean().optional() }).strict())();
291
+ var webhookEndpointSchema = /* @__PURE__ */ (() => z2.object({
292
+ ...webhookInputSchema.shape,
293
+ id: z2.string().uuid(),
294
+ enabled: z2.boolean(),
295
+ disabledReason: z2.string().nullable(),
296
+ consecutiveFailures: z2.number().int().nonnegative(),
297
+ createdAt: z2.number(),
298
+ updatedAt: z2.number()
382
299
  }))();
383
- var memberCompletionPageSchema = /* @__PURE__ */ (() => z2.object({
384
- items: z2.array(memberCompletionSchema),
300
+ var webhookEndpointStateSchema = /* @__PURE__ */ (() => webhookEndpointSchema.extend({
301
+ revision: z2.number().int().nonnegative(),
302
+ deletedAt: z2.number().int().safe().nonnegative().nullable()
303
+ }))();
304
+ var webhookDeleteInputSchema = /* @__PURE__ */ (() => z2.strictObject({
305
+ actionId: z2.string().uuid().default(() => crypto.randomUUID()),
306
+ expectedRevision: z2.number().int().nonnegative(),
307
+ reason: z2.string().trim().min(1).max(500)
308
+ }))();
309
+ var webhookStateQuerySchema = /* @__PURE__ */ (() => z2.strictObject({
310
+ cursor: pageCursorSchema.optional(),
311
+ limit: z2.coerce.number().int().min(1).max(100).default(50)
312
+ }))();
313
+ var webhookStatePageSchema = /* @__PURE__ */ (() => z2.object({
314
+ items: z2.array(webhookEndpointStateSchema),
385
315
  nextCursor: pageCursorSchema.nullable()
386
316
  }))();
317
+ var webhookSecretSchema = /* @__PURE__ */ (() => z2.object({
318
+ endpoint: webhookEndpointSchema,
319
+ secret: z2.string(),
320
+ previousValidUntil: z2.number().nullable()
321
+ }))();
322
+ var webhookDeliverySchema = /* @__PURE__ */ (() => z2.object({
323
+ id: z2.string().uuid(),
324
+ endpoint: z2.string().uuid(),
325
+ event: webhookEventSchema,
326
+ status: z2.enum(["pending", "delivered", "failed", "skipped"]),
327
+ attempts: z2.number().int().nonnegative(),
328
+ responseStatus: z2.number().nullable(),
329
+ lastError: z2.string().nullable(),
330
+ createdAt: z2.number(),
331
+ deliveredAt: z2.number().nullable(),
332
+ replayOf: z2.string().uuid().nullable()
333
+ }))();
334
+ var webhookQuerySchema = /* @__PURE__ */ (() => z2.object({
335
+ /** A page's `nextCursor`: the deliveries after it, newest first. */
336
+ cursor: pageCursorSchema.optional(),
337
+ /** @deprecated Use `cursor`. Removed in 2.0.0. */
338
+ before: z2.string().uuid().optional(),
339
+ limit: z2.coerce.number().int().min(1).max(100).default(50)
340
+ }).strict())();
341
+ var webhookDeliveryPageSchema = /* @__PURE__ */ (() => z2.object({
342
+ items: z2.array(webhookDeliverySchema),
343
+ nextCursor: pageCursorSchema.nullable().default(null),
344
+ /** @deprecated Use `nextCursor`, passed back as `cursor`. Removed in 2.0.0. */
345
+ next: z2.string().uuid().nullable()
346
+ }))();
347
+ var WEBHOOK_MAX_BYTES = 64 * 1024;
348
+ async function verifyWebhook(input) {
349
+ const bytes = new TextEncoder().encode(input.body);
350
+ const tolerance = input.toleranceSeconds ?? 300;
351
+ const now = input.now ?? Date.now();
352
+ if (bytes.length > WEBHOOK_MAX_BYTES || !Number.isFinite(now) || !Number.isFinite(tolerance) || tolerance < 0 || tolerance > 300) {
353
+ throw new Error("Invalid webhook verification input");
354
+ }
355
+ const parts = input.signature.split(",");
356
+ const timestamps = parts.filter((part) => part.startsWith("t="));
357
+ const timestamp = timestamps[0]?.slice(2) ?? "";
358
+ const signatures = parts.filter((part) => /^v1=[a-f0-9]{64}$/.test(part)).map((part) => part.slice(3));
359
+ if (timestamps.length !== 1 || !/^\d{1,12}$/.test(timestamp) || Math.abs(now / 1e3 - Number(timestamp)) > tolerance || signatures.length < 1 || signatures.length > 2) {
360
+ throw new Error("Invalid or expired webhook signature");
361
+ }
362
+ const secrets = typeof input.secret === "string" ? [input.secret] : input.secret;
363
+ const message = new TextEncoder().encode(`${timestamp}.${input.body}`);
364
+ for (const secret of secrets) {
365
+ if (!secret) {
366
+ continue;
367
+ }
368
+ const key = await crypto.subtle.importKey(
369
+ "raw",
370
+ new TextEncoder().encode(secret),
371
+ { name: "HMAC", hash: "SHA-256" },
372
+ false,
373
+ ["verify"]
374
+ );
375
+ for (const signature of signatures) {
376
+ const digest = Uint8Array.from(
377
+ signature.match(/../g) ?? [],
378
+ (byte) => Number.parseInt(byte, 16)
379
+ );
380
+ if (await crypto.subtle.verify("HMAC", key, digest, message)) {
381
+ return webhookEventSchema.parse(JSON.parse(input.body));
382
+ }
383
+ }
384
+ }
385
+ throw new Error("Invalid webhook signature");
386
+ }
387
387
 
388
388
  export {
389
- PayoutSourceKind,
390
- webhookEventSchema,
391
- walletLinkedEventDataSchema,
392
- webhookControlInputSchema,
393
- webhookInputSchema,
394
- webhookCreateInputSchema,
395
- webhookRotateInputSchema,
396
- webhookUpdateSchema,
397
- webhookEndpointSchema,
398
- webhookEndpointStateSchema,
399
- webhookDeleteInputSchema,
400
- webhookStateQuerySchema,
401
- webhookStatePageSchema,
402
- webhookSecretSchema,
403
- webhookDeliverySchema,
404
- webhookQuerySchema,
405
- webhookDeliveryPageSchema,
406
- WEBHOOK_MAX_BYTES,
407
- verifyWebhook,
408
389
  completionRevokeSchema,
409
390
  RevokedEntitlementOutcome,
410
391
  RevokedDeliveryOutcome,
@@ -423,5 +404,24 @@ export {
423
404
  completionReceiptListSchema,
424
405
  memberCompletionQuerySchema,
425
406
  memberCompletionSchema,
426
- memberCompletionPageSchema
407
+ memberCompletionPageSchema,
408
+ PayoutSourceKind,
409
+ webhookEventSchema,
410
+ walletLinkedEventDataSchema,
411
+ webhookControlInputSchema,
412
+ webhookInputSchema,
413
+ webhookCreateInputSchema,
414
+ webhookRotateInputSchema,
415
+ webhookUpdateSchema,
416
+ webhookEndpointSchema,
417
+ webhookEndpointStateSchema,
418
+ webhookDeleteInputSchema,
419
+ webhookStateQuerySchema,
420
+ webhookStatePageSchema,
421
+ webhookSecretSchema,
422
+ webhookDeliverySchema,
423
+ webhookQuerySchema,
424
+ webhookDeliveryPageSchema,
425
+ WEBHOOK_MAX_BYTES,
426
+ verifyWebhook
427
427
  };
@@ -60,6 +60,26 @@ function namedSchemaFailure(name, error) {
60
60
  }
61
61
  return error;
62
62
  }
63
+ function namedRefusal(name, error) {
64
+ if (isSchemaFailure(error)) {
65
+ return namedSchemaFailure(name, error);
66
+ }
67
+ if (error instanceof Error && !error.message.startsWith(`${name}:`)) {
68
+ Object.defineProperty(error, "message", {
69
+ value: `${name}: ${error.message}`,
70
+ configurable: true,
71
+ writable: true
72
+ });
73
+ }
74
+ return error;
75
+ }
76
+ function refusing(name, check) {
77
+ try {
78
+ return check();
79
+ } catch (error) {
80
+ throw namedRefusal(name, error);
81
+ }
82
+ }
63
83
  function parseField(field, parse) {
64
84
  try {
65
85
  return parse();
@@ -253,6 +273,7 @@ export {
253
273
  issueText,
254
274
  parseDefinition,
255
275
  namedSchemaFailure,
276
+ refusing,
256
277
  parseField,
257
278
  RelayErrorCode,
258
279
  isRelayError,