@domino-sdk/relay 0.17.2 → 0.18.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.
@@ -1,1048 +0,0 @@
1
- // src/streaks.ts
2
- import { z } from "zod";
3
- var communityTimeZoneSchema = z.string().min(1).max(100).refine((zone) => {
4
- try {
5
- if (/^[+-]/.test(zone)) {
6
- return false;
7
- }
8
- new Intl.DateTimeFormat("en", { timeZone: zone });
9
- return true;
10
- } catch {
11
- return false;
12
- }
13
- }, "Use an IANA community timezone, such as Europe/Budapest");
14
- var streakPolicySchema = z.object({
15
- kind: z.literal("streak"),
16
- days: z.number().int().min(1).max(3650),
17
- timeZone: communityTimeZoneSchema
18
- }).strict();
19
- var streak = (options) => streakPolicySchema.parse({ kind: "streak", ...options });
20
- var streakProgressSchema = z.object({
21
- goal: z.number().int().positive(),
22
- current: z.number().int().nonnegative(),
23
- best: z.number().int().nonnegative(),
24
- today: z.string(),
25
- todayQualified: z.boolean(),
26
- timeZone: communityTimeZoneSchema,
27
- nextBoundary: z.number().int(),
28
- pendingTimeZone: z.object({
29
- timeZone: communityTimeZoneSchema,
30
- effectiveAt: z.number().int()
31
- }).nullable(),
32
- days: z.array(
33
- z.object({
34
- day: z.number().int(),
35
- date: z.string(),
36
- timeZone: communityTimeZoneSchema,
37
- occurredAt: z.number().int()
38
- })
39
- ),
40
- milestone: z.discriminatedUnion("status", [
41
- z.object({ status: z.literal("pending") }),
42
- z.object({
43
- status: z.literal("awarded"),
44
- completion: z.string(),
45
- achievedAt: z.number().int()
46
- }),
47
- z.object({
48
- status: z.literal("budget-exhausted"),
49
- budget: z.string(),
50
- achievedAt: z.number().int()
51
- })
52
- ])
53
- });
54
-
55
- // src/identifier.ts
56
- import { z as z2 } from "zod";
57
- var identifier = z2.string().min(1).max(100).regex(/^[a-zA-Z0-9_-]+$/);
58
-
59
- // src/observations.ts
60
- import { z as z3 } from "zod";
61
- var name = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,199}$/);
62
- var observationInputSchema = z3.object({
63
- id: name,
64
- source: name,
65
- type: name,
66
- member: identifier,
67
- actor: z3.object({ provider: identifier, subject: z3.string().min(1).max(200) }).strict().optional(),
68
- occurredAt: z3.number().int().nonnegative().max(864e13),
69
- data: z3.record(z3.string(), z3.json())
70
- }).strict().refine(
71
- (value) => JSON.stringify(value.data).length <= 32768,
72
- "Observation data exceeds 32 KB"
73
- );
74
- var observationSchema = observationInputSchema.safeExtend({
75
- receivedAt: z3.number().int().nonnegative()
76
- });
77
- var observationTriggerSchema = z3.object({ source: name, type: name }).strict();
78
- var completionPolicySchema = z3.discriminatedUnion("kind", [
79
- streakPolicySchema,
80
- z3.object({ kind: z3.literal("once") }).strict(),
81
- z3.object({ kind: z3.literal("keyed") }).strict()
82
- ]);
83
- var completionKeySchema = z3.string().min(1).max(500);
84
- var budgetSchema = z3.object({
85
- id: name,
86
- scope: z3.enum(["member", "project"]),
87
- period: z3.enum(["lifetime", "day"]),
88
- limit: z3.number().int().positive().max(Number.MAX_SAFE_INTEGER),
89
- cost: z3.union([
90
- z3.number().int().positive().max(Number.MAX_SAFE_INTEGER),
91
- z3.object({ balance: name }).strict()
92
- ])
93
- }).strict();
94
- var observationReceiptSchema = z3.object({
95
- id: name,
96
- source: name,
97
- attempts: z3.array(z3.string()),
98
- receivedAt: z3.number()
99
- });
100
- var discordReactionSchema = z3.object({
101
- guildId: z3.string(),
102
- channelId: z3.string(),
103
- messageId: z3.string(),
104
- userId: z3.string(),
105
- messageAuthorId: z3.string().nullable().default(null),
106
- actorRoles: z3.array(z3.string()).default([]),
107
- emoji: z3.object({ id: z3.string().nullable(), name: z3.string() }),
108
- messagePublishedAt: z3.number()
109
- }).strict();
110
- var discordMessageSchema = z3.object({
111
- guildId: z3.string(),
112
- channelId: z3.string(),
113
- messageId: z3.string(),
114
- userId: z3.string(),
115
- content: z3.string().nullable(),
116
- replyTo: z3.string().nullable(),
117
- publishedAt: z3.number()
118
- }).strict();
119
-
120
- // src/integrations.ts
121
- import { z as z4 } from "zod";
122
- var integrationProviderSchema = z4.enum(["discord"]);
123
- var discordServerSchema = z4.object({
124
- id: z4.string().regex(/^[0-9]{1,20}$/),
125
- name: z4.string().min(1),
126
- icon: z4.string().nullable()
127
- });
128
- var projectIntegrationSchema = z4.object({
129
- provider: integrationProviderSchema,
130
- configured: z4.boolean(),
131
- status: z4.enum(["disconnected", "ready", "attention"]),
132
- revision: z4.number().int().nonnegative(),
133
- server: discordServerSchema.nullable(),
134
- issue: z4.string().nullable(),
135
- connectedAt: z4.number().default(0)
136
- });
137
-
138
- // src/accounts.ts
139
- import { z as z5 } from "zod";
140
- var authProviderSchema = z5.enum(["google", "apple", "x", "discord"]);
141
- var accountConnectionSchema = z5.object({
142
- provider: authProviderSchema,
143
- configured: z5.boolean(),
144
- status: z5.enum(["disconnected", "connected", "reconnect"]),
145
- subject: z5.string().nullable(),
146
- revision: z5.number().int().nonnegative()
147
- });
148
- var discordMemberInputSchema = z5.object({}).strict();
149
- var discordMessageInputSchema = z5.object({
150
- channelId: z5.string().regex(/^[0-9]{1,20}$/),
151
- messageId: z5.string().regex(/^[0-9]{1,20}$/)
152
- }).strict();
153
- var discordMemberSchema = z5.object({
154
- userId: z5.string().regex(/^[0-9]{1,20}$/).nullable().default(null),
155
- nickname: z5.string().nullable().default(null),
156
- displayName: z5.string().nullable().default(null),
157
- boostingSince: z5.string().datetime({ offset: true }).nullable().default(null),
158
- roles: z5.array(z5.string().regex(/^[0-9]{1,20}$/)),
159
- joinedAt: z5.string().datetime({ offset: true }).nullable(),
160
- pending: z5.boolean()
161
- });
162
-
163
- // src/submission-input.ts
164
- import { z as z6 } from "zod";
165
- var textOptionsSchema = z6.object({
166
- required: z6.boolean().default(true),
167
- minLength: z6.number().int().min(0).max(1e4).default(1),
168
- maxLength: z6.number().int().min(1).max(1e4).default(1e4)
169
- }).strict().refine(
170
- (v) => v.minLength <= v.maxLength,
171
- "minLength must not exceed maxLength"
172
- );
173
- var hostSchema = z6.string().min(1).max(253).refine((host) => {
174
- if (!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/i.test(host) || host.includes("..")) {
175
- return false;
176
- }
177
- try {
178
- const url = new URL(`https://${host}`);
179
- return url.hostname === host.toLowerCase() && !url.port && !url.username && !url.password && url.pathname === "/" && !url.search && !url.hash;
180
- } catch {
181
- return false;
182
- }
183
- }, "Use a hostname without a scheme, path, port, or wildcard");
184
- var urlOptionsSchema = z6.object({
185
- required: z6.boolean().default(true),
186
- allowedHosts: z6.array(hostSchema).min(1).max(100).optional()
187
- }).strict();
188
- var textEvidenceSchema = z6.object({ kind: z6.literal("text"), value: z6.string().max(1e4) }).strict();
189
- var urlEvidenceSchema = z6.object({ kind: z6.literal("url"), value: z6.string().max(2048) }).strict();
190
- var valueEvidenceSchema = z6.discriminatedUnion("kind", [
191
- textEvidenceSchema,
192
- urlEvidenceSchema
193
- ]);
194
- function validateSubmissionValue(input, contract) {
195
- const maximum = input.kind === "text" ? 1e4 : 2048;
196
- if (input.value.length > maximum) {
197
- return `Enter no more than ${maximum} characters`;
198
- }
199
- if (input.kind !== contract.input) {
200
- return `This quest requires ${contract.input} input`;
201
- }
202
- if (!input.value.trim()) {
203
- return contract.constraints.required ? "This field is required" : null;
204
- }
205
- if (contract.input === "text") {
206
- if (input.value.length < contract.constraints.minLength) {
207
- return `Enter at least ${contract.constraints.minLength} characters`;
208
- }
209
- if (input.value.length > contract.constraints.maxLength) {
210
- return `Enter no more than ${contract.constraints.maxLength} characters`;
211
- }
212
- return null;
213
- }
214
- const url = parseHttpUrl(input.value);
215
- if (!url) {
216
- return "Enter a valid HTTP or HTTPS URL without credentials";
217
- }
218
- if (contract.constraints.allowedHosts && !contract.constraints.allowedHosts.some(
219
- (host) => host.toLowerCase() === url.hostname.toLowerCase()
220
- )) {
221
- return `Use a URL hosted on: ${contract.constraints.allowedHosts.join(", ")}`;
222
- }
223
- return null;
224
- }
225
- function parseHttpUrl(value) {
226
- if (value !== value.trim() || /[\\\s]/.test(value) || !/^https?:\/\//i.test(value)) {
227
- return null;
228
- }
229
- try {
230
- const url = new URL(value);
231
- return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password ? url : null;
232
- } catch {
233
- return null;
234
- }
235
- }
236
- function xPostId(value) {
237
- const url = parseHttpUrl(value);
238
- if (!url || url.port || ![
239
- "x.com",
240
- "www.x.com",
241
- "twitter.com",
242
- "www.twitter.com",
243
- "mobile.twitter.com"
244
- ].includes(url.hostname)) {
245
- return null;
246
- }
247
- return /^\/(?:[A-Za-z0-9_]+|i\/web)\/status\/([0-9]{1,20})\/?$/.exec(
248
- url.pathname
249
- )?.[1] ?? null;
250
- }
251
-
252
- // src/quiz.ts
253
- import { z as z7 } from "zod";
254
- var quizId = z7.string().regex(/^[a-zA-Z0-9_-]+$/).max(100);
255
- var quizChoiceSchema = z7.object({ id: quizId, label: z7.string().trim().min(1).max(500) }).strict();
256
- var quizQuestionSchema = z7.object({
257
- id: quizId,
258
- prompt: z7.string().trim().min(1).max(1e3),
259
- choices: z7.array(quizChoiceSchema).min(2).max(8).refine(
260
- (choices) => new Set(choices.map((choice) => choice.id)).size === choices.length,
261
- "Choice IDs must be unique"
262
- )
263
- }).strict();
264
- var quizQuestionsSchema = z7.array(quizQuestionSchema).min(1).max(20).refine(
265
- (questions) => new Set(questions.map((question) => question.id)).size === questions.length,
266
- "Question IDs must be unique"
267
- );
268
- var quizContentSchema = z7.array(
269
- quizQuestionSchema.extend({ correct: quizId }).refine(
270
- (question) => question.choices.some((choice) => choice.id === question.correct),
271
- "Choose a correct answer from the available choices"
272
- )
273
- ).min(1).max(20).refine(
274
- (questions) => new Set(questions.map((question) => question.id)).size === questions.length,
275
- "Question IDs must be unique"
276
- );
277
-
278
- // src/schema.ts
279
- import { z as z10 } from "zod";
280
-
281
- // src/settings.ts
282
- import { z as z9 } from "zod";
283
-
284
- // src/resources.ts
285
- import { z as z8 } from "zod";
286
- var channelSourceSchema = z8.object({
287
- provider: z8.literal("discord"),
288
- resource: z8.literal("channel"),
289
- types: z8.array(z8.enum(["text", "announcement"])).min(1)
290
- }).strict();
291
- var resourceSourceSchema = z8.union([
292
- z8.object({
293
- provider: z8.literal("domino"),
294
- resource: z8.literal("point-ledger")
295
- }).strict(),
296
- channelSourceSchema,
297
- z8.object({
298
- provider: z8.literal("discord"),
299
- resource: z8.literal("role"),
300
- assignable: z8.boolean().default(false)
301
- }).strict()
302
- ]);
303
- var resourceRequestSchema = z8.object({
304
- source: resourceSourceSchema,
305
- query: z8.string().max(100).optional(),
306
- cursor: z8.string().regex(/^\d{1,6}$/).optional(),
307
- ids: z8.array(z8.string().min(1).max(100)).max(50).optional()
308
- }).strict();
309
- var resourceOptionsSchema = z8.object({
310
- revision: z8.number().int(),
311
- options: z8.array(
312
- z8.object({
313
- id: z8.string(),
314
- label: z8.string(),
315
- description: z8.string().optional(),
316
- group: z8.string().optional(),
317
- disabledReason: z8.string().optional()
318
- })
319
- ),
320
- cursor: z8.string().nullable()
321
- });
322
- var discord = {
323
- roles(options = {}) {
324
- return resourceSourceSchema.parse({
325
- provider: "discord",
326
- resource: "role",
327
- assignable: options.assignable ?? false
328
- });
329
- },
330
- channels(options = {}) {
331
- return resourceSourceSchema.parse({
332
- provider: "discord",
333
- resource: "channel",
334
- types: options.types ?? ["text", "announcement"]
335
- });
336
- }
337
- };
338
- var pointLedgers = () => ({
339
- provider: "domino",
340
- resource: "point-ledger"
341
- });
342
-
343
- // src/settings.ts
344
- var instant = z9.iso.datetime({ offset: true }).transform((value) => new Date(value).toISOString());
345
- var resourceId = z9.union([z9.literal(""), z9.string().regex(/^\S{1,200}$/)]);
346
- var base = { label: z9.string().min(1), description: z9.string().optional() };
347
- var settingFieldSchema = z9.discriminatedUnion("kind", [
348
- z9.object({ ...base, kind: z9.literal("point-ledger"), default: identifier }).strict(),
349
- z9.object({ ...base, kind: z9.literal("datetime"), default: instant }).strict(),
350
- z9.object({
351
- ...base,
352
- kind: z9.literal("resource"),
353
- default: resourceId,
354
- source: resourceSourceSchema
355
- }).strict(),
356
- z9.object({ ...base, kind: z9.literal("quiz"), default: quizContentSchema }).strict(),
357
- z9.object({
358
- ...base,
359
- kind: z9.literal("text"),
360
- default: z9.string(),
361
- minLength: z9.number().int().nonnegative(),
362
- maxLength: z9.number().int().positive(),
363
- multiline: z9.boolean()
364
- }).strict(),
365
- z9.object({
366
- ...base,
367
- kind: z9.literal("integer"),
368
- default: z9.number().int(),
369
- min: z9.number().int(),
370
- max: z9.number().int()
371
- }).strict(),
372
- z9.object({ ...base, kind: z9.literal("boolean"), default: z9.boolean() }).strict(),
373
- z9.object({
374
- ...base,
375
- kind: z9.literal("choice"),
376
- default: z9.string(),
377
- options: z9.array(z9.string().min(1)).min(1)
378
- }).strict()
379
- ]);
380
- var settingsFieldsSchema = z9.record(
381
- z9.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),
382
- settingFieldSchema
383
- );
384
- var settingsValuesSchema = z9.record(
385
- z9.string(),
386
- z9.union([z9.string(), z9.number().finite(), z9.boolean(), quizContentSchema])
387
- );
388
- var settings = {
389
- pointLedger(options) {
390
- const field = {
391
- ...options,
392
- kind: "point-ledger",
393
- default: identifier.parse(options.default)
394
- };
395
- return identifier.default(field.default).meta(field);
396
- },
397
- datetime(options) {
398
- const field = {
399
- ...options,
400
- kind: "datetime",
401
- default: instant.parse(options.default)
402
- };
403
- return instant.default(field.default).meta(field);
404
- },
405
- resource(options) {
406
- const field = {
407
- ...options,
408
- source: resourceSourceSchema.parse(options.source),
409
- kind: "resource",
410
- default: resourceId.parse(options.default ?? "")
411
- };
412
- return resourceId.default(field.default).meta(field);
413
- },
414
- quiz(options) {
415
- const value = quizContentSchema.parse(options.default);
416
- return quizContentSchema.default(value).meta({ ...options, default: value, kind: "quiz" });
417
- },
418
- text(options) {
419
- const field = {
420
- ...options,
421
- kind: "text",
422
- minLength: options.minLength ?? 1,
423
- maxLength: options.maxLength ?? 2e3,
424
- multiline: options.multiline ?? false
425
- };
426
- return z9.string().min(field.minLength).max(field.maxLength).default(field.default).meta(field);
427
- },
428
- integer(options) {
429
- return z9.number().int().min(options.min).max(options.max).default(options.default).meta({ ...options, kind: "integer" });
430
- },
431
- boolean(options) {
432
- return z9.boolean().default(options.default).meta({ ...options, kind: "boolean" });
433
- },
434
- choice(options) {
435
- return z9.enum(options.options).default(options.default).meta({ ...options, kind: "choice" });
436
- },
437
- object(shape) {
438
- return z9.object(shape).strict();
439
- }
440
- };
441
- function parseSettings(fields, input) {
442
- const shape = {};
443
- for (const [key, field] of Object.entries(fields)) {
444
- switch (field.kind) {
445
- case "point-ledger":
446
- shape[key] = identifier.default(field.default);
447
- break;
448
- case "datetime":
449
- shape[key] = instant.default(field.default);
450
- break;
451
- case "resource":
452
- shape[key] = resourceId.default(field.default);
453
- break;
454
- case "quiz":
455
- shape[key] = quizContentSchema.default(field.default);
456
- break;
457
- case "text":
458
- shape[key] = z9.string().min(field.minLength).max(field.maxLength).default(field.default);
459
- break;
460
- case "integer":
461
- shape[key] = z9.number().int().min(field.min).max(field.max).default(field.default);
462
- break;
463
- case "boolean":
464
- shape[key] = z9.boolean().default(field.default);
465
- break;
466
- case "choice":
467
- shape[key] = z9.enum(field.options).default(field.default);
468
- break;
469
- }
470
- }
471
- return settingsValuesSchema.parse(z9.object(shape).strict().parse(input));
472
- }
473
- function missingResourceSettings(fields, values) {
474
- return Object.entries(fields).filter(([key, field]) => field.kind === "resource" && !values[key]).map(([key]) => key);
475
- }
476
- function compatibleSettingKinds(previous, next) {
477
- return previous.kind === next.kind || previous.kind === "text" && (next.kind === "resource" || next.kind === "datetime" || next.kind === "point-ledger");
478
- }
479
-
480
- // src/schema.ts
481
- var pointsRewardSchema = z10.object({
482
- kind: z10.literal("points").default("points"),
483
- balance: identifier,
484
- amount: z10.number().int().min(0).max(1e4)
485
- }).strict();
486
- var tieredRewardDefinitionSchema = z10.object({
487
- id: identifier,
488
- title: z10.string().min(1).max(120),
489
- tiers: z10.array(
490
- z10.object({ id: identifier, title: z10.string().min(1).max(120) }).strict()
491
- ).min(1).max(20).refine(
492
- (tiers) => new Set(tiers.map((t) => t.id)).size === tiers.length,
493
- "Tier IDs must be unique"
494
- ),
495
- inventory: z10.object({ kind: z10.literal("untracked") }).strict(),
496
- fulfillment: z10.object({ kind: z10.literal("staff-handover") }).strict()
497
- }).strict();
498
- var tierRewardSchema = z10.object({
499
- kind: z10.literal("tier"),
500
- reward: tieredRewardDefinitionSchema,
501
- tier: identifier
502
- }).strict().refine(
503
- (value) => value.reward.tiers.some((t) => t.id === value.tier),
504
- "Unknown reward tier"
505
- );
506
- var integrationRewardSchema = z10.object({
507
- kind: z10.literal("integration"),
508
- provider: z10.literal("discord"),
509
- action: z10.literal("grant-role"),
510
- roleId: z10.string().regex(/^[0-9]{1,20}$/)
511
- }).strict();
512
- var rewardSchema = z10.union([
513
- pointsRewardSchema,
514
- tierRewardSchema,
515
- integrationRewardSchema
516
- ]);
517
- function rewardKey(reward) {
518
- if (reward.kind === "integration") {
519
- return `integration:${reward.provider}:${reward.action}:${reward.roleId}`;
520
- }
521
- return reward.kind === "points" ? "points:" + reward.balance : "tier:" + reward.reward.id;
522
- }
523
- var triggerSchema = z10.union([
524
- z10.object({
525
- kind: z10.literal("manual"),
526
- input: z10.literal("text"),
527
- constraints: textOptionsSchema,
528
- actor: z10.enum(["member", "staff"]).optional()
529
- }).strict(),
530
- z10.object({
531
- kind: z10.literal("manual"),
532
- input: z10.literal("url"),
533
- constraints: urlOptionsSchema,
534
- actor: z10.enum(["member", "staff"]).optional()
535
- }).strict(),
536
- z10.object({
537
- kind: z10.literal("manual"),
538
- input: z10.enum(["photo", "quiz", "none"]),
539
- actor: z10.enum(["member", "staff"]).optional()
540
- }).strict(),
541
- z10.object({
542
- kind: z10.literal("automatic"),
543
- observation: observationTriggerSchema.optional()
544
- }).strict()
545
- ]);
546
- var prerequisiteSchema = z10.object({ quest: identifier, scope: z10.literal("ever") }).strict();
547
- var photoResultSchema = z10.object({
548
- kind: z10.enum(["pass", "fail", "unclear"]),
549
- reason: z10.string().min(1).max(2e3)
550
- }).strict();
551
- var textReviewInputSchema = z10.object({
552
- text: z10.string().min(1).max(16e3).refine((value) => value.trim().length > 0, "Text must not be blank"),
553
- criteria: z10.string().trim().min(1).max(2e3)
554
- }).strict();
555
- var textResultSchema = photoResultSchema;
556
- var decisionSchema = z10.discriminatedUnion("kind", [
557
- z10.object({
558
- kind: z10.literal("accept"),
559
- rewards: z10.array(rewardSchema).max(10),
560
- completionKey: completionKeySchema.optional()
561
- }).strict(),
562
- z10.object({ kind: z10.literal("reject"), reason: z10.string().min(1).max(2e3) }).strict(),
563
- z10.object({
564
- kind: z10.literal("review"),
565
- reason: z10.string().min(1).max(2e3),
566
- rewards: z10.array(rewardSchema).max(10).optional(),
567
- completionKey: completionKeySchema.optional()
568
- }).strict()
569
- ]);
570
- var reviewModeSchema = z10.enum(["workers-ai"]);
571
- var storedReviewModeSchema = z10.enum([
572
- "fixture-pass",
573
- "fixture-fail",
574
- "fixture-unclear",
575
- "fixture-error",
576
- "workers-ai"
577
- ]);
578
- var rewardBundleSchema = z10.array(rewardSchema).max(10).refine(
579
- (rewards) => new Set(rewards.map(rewardKey)).size === rewards.length,
580
- "Use one entry per balance or shared reward"
581
- );
582
- var mediaUrlSchema = z10.string().max(2e3).refine((value) => {
583
- if (/^\/(?!\/)[^\\\s]*$/.test(value)) {
584
- return true;
585
- }
586
- try {
587
- return new URL(value).protocol === "https:";
588
- } catch {
589
- return false;
590
- }
591
- }, "Use an HTTPS URL or a same-site path beginning with /");
592
- var questPresentationSchema = z10.object({
593
- quiz: quizQuestionsSchema.optional(),
594
- instructions: z10.string().max(4e3).optional(),
595
- video: z10.object({
596
- url: mediaUrlSchema,
597
- poster: mediaUrlSchema.optional(),
598
- captions: z10.object({
599
- url: mediaUrlSchema,
600
- language: z10.string().min(2).max(20),
601
- label: z10.string().min(1).max(80)
602
- }).strict().optional()
603
- }).strict().optional()
604
- }).strict();
605
- var questDescriptionSchema = z10.object({
606
- quest: identifier,
607
- runtimeVersion: z10.union([z10.literal(1), z10.literal(2)]).default(1),
608
- title: z10.string().min(1).max(120),
609
- presentation: questPresentationSchema.default({}),
610
- integrations: z10.array(integrationProviderSchema).max(10).default([]),
611
- fields: settingsFieldsSchema,
612
- values: settingsValuesSchema,
613
- rewards: rewardBundleSchema,
614
- humanReview: z10.boolean(),
615
- trigger: triggerSchema,
616
- requires: z10.array(prerequisiteSchema).max(30).default([]),
617
- completion: completionPolicySchema,
618
- visibility: z10.enum(["visible", "hidden"]).default("visible"),
619
- budgets: z10.array(budgetSchema).max(20).default([])
620
- }).strict();
621
- var artifactSchema = z10.object({ code: z10.string().min(1).max(1e6) }).strict();
622
- var releaseSchema = artifactSchema.extend({
623
- settings: settingsValuesSchema,
624
- provider: reviewModeSchema,
625
- expectedRelease: identifier.nullable().optional(),
626
- settingRenames: z10.record(z10.string(), z10.string()).optional()
627
- }).strict();
628
- var batchReleaseSchema = z10.object({ releases: z10.array(releaseSchema).min(1).max(50) }).strict();
629
- var questSettingsInputSchema = z10.object({
630
- quest: identifier,
631
- expectedRelease: identifier,
632
- set: settingsValuesSchema,
633
- reset: z10.array(z10.string())
634
- }).strict();
635
- var storedReleaseSchema = questDescriptionSchema.extend({
636
- key: identifier.optional(),
637
- code: z10.string(),
638
- provider: storedReviewModeSchema,
639
- id: identifier,
640
- createdAt: z10.number(),
641
- legacy: z10.boolean().default(false),
642
- origin: z10.object({ typeVersion: identifier }).strict().optional(),
643
- lifecycle: z10.enum(["active", "paused", "archived"]).default("active"),
644
- configuration: z10.object({
645
- defaults: settingsValuesSchema,
646
- overrides: settingsValuesSchema,
647
- preserved: z10.array(z10.string())
648
- }).strict().optional()
649
- });
650
- var legacyReleaseSchema = z10.object({
651
- quest: identifier,
652
- title: z10.string(),
653
- criteria: z10.string(),
654
- humanReview: z10.boolean(),
655
- rewards: rewardBundleSchema,
656
- code: z10.string(),
657
- provider: storedReviewModeSchema,
658
- id: identifier,
659
- createdAt: z10.number()
660
- }).transform((r) => {
661
- const { criteria, ...stored } = r;
662
- return storedReleaseSchema.parse({
663
- ...stored,
664
- fields: {},
665
- values: { criteria, humanReview: r.humanReview },
666
- trigger: { kind: "manual", input: "photo" },
667
- completion: { kind: "once" },
668
- legacy: true
669
- });
670
- });
671
- var publishedReleaseSchema = z10.union([
672
- storedReleaseSchema,
673
- legacyReleaseSchema
674
- ]);
675
- var templateSchema = z10.object({
676
- code: z10.string(),
677
- definition: questDescriptionSchema
678
- });
679
- var quizAnswersSchema = z10.record(identifier, identifier).refine(
680
- (answers) => Object.keys(answers).length > 0 && Object.keys(answers).length <= 50,
681
- "Provide between 1 and 50 answers"
682
- ).transform(
683
- (answers) => Object.fromEntries(
684
- Object.entries(answers).sort(([a], [b]) => a.localeCompare(b))
685
- )
686
- );
687
- var quizEvidenceSchema = z10.object({
688
- kind: z10.literal("quiz"),
689
- release: identifier.optional(),
690
- answers: quizAnswersSchema
691
- }).strict();
692
- var submissionEvidenceSchema = z10.union([
693
- quizEvidenceSchema,
694
- textEvidenceSchema,
695
- urlEvidenceSchema
696
- ]);
697
- var submitSchema = z10.object({
698
- actionId: identifier,
699
- quest: identifier,
700
- member: identifier,
701
- evidence: identifier.optional(),
702
- input: submissionEvidenceSchema.optional(),
703
- release: identifier.optional(),
704
- faultAfterReview: z10.boolean().optional()
705
- }).strict();
706
- var attemptSchema = z10.object({
707
- id: identifier,
708
- release: identifier,
709
- quest: identifier,
710
- member: identifier,
711
- evidence: identifier.nullable(),
712
- input: submissionEvidenceSchema.optional(),
713
- status: z10.enum([
714
- "queued",
715
- "evaluating",
716
- "accepted",
717
- "progressed",
718
- "rejected",
719
- "needs-review",
720
- "failed"
721
- ]),
722
- reason: z10.string().nullable(),
723
- retries: z10.number(),
724
- generation: z10.number(),
725
- completion: z10.string().nullable(),
726
- reviewRewards: rewardBundleSchema.nullable().default(null),
727
- createdAt: z10.number()
728
- });
729
- var eventSchema = z10.object({
730
- id: z10.number(),
731
- attempt: z10.string().nullable(),
732
- kind: z10.string(),
733
- detail: z10.string(),
734
- actor: z10.string().nullable().default(null),
735
- at: z10.number()
736
- });
737
- var pickupSelectionSchema = z10.object({
738
- item: identifier,
739
- revision: z10.number().int().nonnegative()
740
- }).strict();
741
- var pickupAllocationSchema = z10.object({
742
- item: identifier,
743
- label: z10.string().min(1).max(80)
744
- }).strict();
745
- var pickupPolicySchema = z10.discriminatedUnion("kind", [
746
- z10.object({ kind: z10.literal("untracked") }).strict(),
747
- z10.object({
748
- kind: z10.literal("at-pickup"),
749
- tiers: z10.array(
750
- z10.object({
751
- tier: identifier,
752
- variants: z10.array(pickupAllocationSchema).min(1).max(100)
753
- }).strict()
754
- ).min(1).max(100)
755
- }).strict()
756
- ]);
757
- var pickupCatalogSchema = z10.object({
758
- reward: tieredRewardDefinitionSchema,
759
- revision: z10.number().int().nonnegative(),
760
- policy: pickupPolicySchema
761
- });
762
- var pickupAvailabilitySchema = z10.discriminatedUnion("kind", [
763
- z10.object({ kind: z10.literal("untracked") }).strict(),
764
- z10.object({
765
- kind: z10.literal("at-pickup"),
766
- revision: z10.number().int().nonnegative(),
767
- variants: z10.array(
768
- pickupAllocationSchema.extend({
769
- available: z10.number().int().nonnegative()
770
- })
771
- )
772
- }).strict()
773
- ]);
774
- var configurePickupSchema = z10.object({
775
- reward: identifier,
776
- revision: z10.number().int().nonnegative(),
777
- actionId: identifier,
778
- policy: z10.discriminatedUnion("kind", [
779
- z10.object({ kind: z10.literal("untracked") }).strict(),
780
- z10.object({
781
- kind: z10.literal("at-pickup"),
782
- tiers: z10.array(
783
- z10.object({
784
- tier: identifier,
785
- variants: z10.array(
786
- pickupAllocationSchema.extend({
787
- item: identifier.optional()
788
- })
789
- ).min(1).max(100)
790
- }).strict()
791
- ).min(1).max(100)
792
- }).strict()
793
- ])
794
- }).strict();
795
- var entitlementBase = {
796
- id: identifier,
797
- member: identifier,
798
- reward: tieredRewardDefinitionSchema,
799
- earnedTier: identifier,
800
- tier: identifier,
801
- revision: z10.number().int().positive()
802
- };
803
- var entitlementSchema = z10.discriminatedUnion("status", [
804
- z10.object({ ...entitlementBase, status: z10.literal("available") }).strict(),
805
- z10.object({
806
- ...entitlementBase,
807
- status: z10.literal("handing-over"),
808
- handover: identifier,
809
- startedAt: z10.number(),
810
- allocation: pickupAllocationSchema.optional()
811
- }).strict(),
812
- z10.object({
813
- ...entitlementBase,
814
- status: z10.literal("collected"),
815
- handover: identifier,
816
- startedAt: z10.number(),
817
- allocation: pickupAllocationSchema.optional(),
818
- collectedAt: z10.number()
819
- }).strict()
820
- ]);
821
- var beginHandoverSchema = z10.object({
822
- actionId: identifier,
823
- revision: z10.number().int().positive(),
824
- selection: pickupSelectionSchema.optional()
825
- }).strict();
826
- var confirmHandoverSchema = z10.object({ actionId: identifier, handover: identifier }).strict();
827
- var completionRecordSchema = z10.object({
828
- key: z10.string().default("once"),
829
- id: identifier,
830
- quest: identifier,
831
- member: identifier
832
- });
833
- var questAvailabilitySchema = z10.discriminatedUnion("kind", [
834
- z10.object({
835
- kind: z10.literal("available"),
836
- input: z10.enum(["photo", "quiz", "none", "text", "url"])
837
- }).strict(),
838
- z10.object({ kind: z10.literal("completed") }).strict(),
839
- z10.object({
840
- kind: z10.literal("locked"),
841
- missing: z10.array(z10.object({ quest: identifier, title: z10.string() })).min(1)
842
- }).strict(),
843
- z10.object({ kind: z10.literal("staff-required") }).strict(),
844
- z10.object({
845
- kind: z10.literal("automatic"),
846
- observation: observationTriggerSchema.optional()
847
- }).strict(),
848
- z10.object({ kind: z10.literal("checking"), attempt: identifier }).strict(),
849
- z10.object({ kind: z10.literal("needs-review"), attempt: identifier }).strict(),
850
- z10.object({ kind: z10.literal("retryable"), attempt: identifier }).strict()
851
- ]);
852
- var memberProgressSchema = z10.object({
853
- member: identifier,
854
- quests: z10.array(
855
- z10.object({
856
- quest: identifier,
857
- key: identifier.optional(),
858
- release: identifier.optional(),
859
- title: z10.string(),
860
- presentation: questPresentationSchema.default({}),
861
- connections: z10.array(authProviderSchema).default([]),
862
- trigger: triggerSchema,
863
- availability: questAvailabilitySchema,
864
- completed: z10.boolean(),
865
- completion: completionPolicySchema.default({ kind: "once" }),
866
- streak: streakProgressSchema.nullable().optional(),
867
- completionCount: z10.number().int().nonnegative().default(0),
868
- visibility: z10.enum(["visible", "hidden"]).default("visible"),
869
- missing: z10.array(z10.object({ quest: identifier, title: z10.string() })),
870
- attempt: attemptSchema.nullable()
871
- })
872
- ),
873
- entitlements: z10.array(entitlementSchema)
874
- });
875
- var snapshotSchema = z10.object({
876
- releases: z10.array(publishedReleaseSchema),
877
- completions: z10.array(completionRecordSchema),
878
- entitlements: z10.array(entitlementSchema),
879
- attempts: z10.array(attemptSchema),
880
- balances: z10.array(
881
- z10.object({
882
- member: z10.string(),
883
- balance: z10.string(),
884
- earned: z10.number(),
885
- held: z10.number(),
886
- available: z10.number()
887
- })
888
- ),
889
- events: z10.array(eventSchema)
890
- });
891
- var evidenceSchema = z10.object({
892
- id: identifier,
893
- member: identifier,
894
- type: z10.enum(["image/jpeg", "image/png"]),
895
- size: z10.number()
896
- });
897
- var errorSchema = z10.object({
898
- error: z10.string(),
899
- code: z10.enum(["stale-quiz", "quest-updated", "invalid-submission"]).optional(),
900
- missing: z10.array(z10.object({ quest: identifier, title: z10.string() })).optional()
901
- });
902
- var staffDecisionSchema = z10.object({
903
- actionId: identifier,
904
- generation: z10.number().int().nonnegative(),
905
- decision: z10.enum(["accept", "reject"]),
906
- reason: z10.string().trim().min(1).max(2e3)
907
- }).strict();
908
- var stockSchema = z10.object({ item: identifier, quantity: z10.number().int().min(0).max(1e4) }).strict();
909
- var reservationSchema = z10.object({
910
- actionId: identifier,
911
- member: identifier,
912
- item: identifier,
913
- balance: identifier,
914
- price: z10.number().int().positive().max(1e4)
915
- }).strict();
916
- var pageOptions = {
917
- limit: z10.number().int().min(1).max(100).default(25),
918
- cursor: z10.string().min(1).max(4096).optional()
919
- };
920
- var reviewListSchema = z10.object({
921
- ...pageOptions,
922
- member: identifier.optional(),
923
- quest: identifier.optional()
924
- }).strict();
925
- var memberListSchema = z10.object({
926
- ...pageOptions,
927
- prefix: identifier.optional()
928
- }).strict();
929
- var reviewItemSchema = z10.object({
930
- attempt: attemptSchema,
931
- title: z10.string(),
932
- checks: z10.array(
933
- z10.object({ criteria: z10.string(), result: photoResultSchema })
934
- )
935
- });
936
- var reviewPageSchema = z10.object({
937
- items: z10.array(reviewItemSchema).max(100),
938
- nextCursor: z10.string().nullable()
939
- });
940
- var memberPageSchema = z10.object({
941
- items: z10.array(z10.object({ member: identifier })).max(100),
942
- nextCursor: z10.string().nullable()
943
- });
944
- var createStockItemSchema = z10.object({ actionId: identifier, name: z10.string().trim().min(1).max(80) }).strict();
945
- var stockItemSchema = z10.object({ id: identifier, name: z10.string() });
946
-
947
- export {
948
- communityTimeZoneSchema,
949
- streakPolicySchema,
950
- streak,
951
- streakProgressSchema,
952
- identifier,
953
- observationInputSchema,
954
- observationSchema,
955
- observationTriggerSchema,
956
- completionPolicySchema,
957
- completionKeySchema,
958
- budgetSchema,
959
- observationReceiptSchema,
960
- discordReactionSchema,
961
- discordMessageSchema,
962
- integrationProviderSchema,
963
- discordServerSchema,
964
- projectIntegrationSchema,
965
- authProviderSchema,
966
- accountConnectionSchema,
967
- discordMemberInputSchema,
968
- discordMessageInputSchema,
969
- discordMemberSchema,
970
- textOptionsSchema,
971
- urlOptionsSchema,
972
- textEvidenceSchema,
973
- urlEvidenceSchema,
974
- valueEvidenceSchema,
975
- validateSubmissionValue,
976
- xPostId,
977
- quizChoiceSchema,
978
- quizQuestionSchema,
979
- quizQuestionsSchema,
980
- quizContentSchema,
981
- resourceSourceSchema,
982
- resourceRequestSchema,
983
- resourceOptionsSchema,
984
- discord,
985
- pointLedgers,
986
- settingFieldSchema,
987
- settingsFieldsSchema,
988
- settingsValuesSchema,
989
- settings,
990
- parseSettings,
991
- missingResourceSettings,
992
- compatibleSettingKinds,
993
- pointsRewardSchema,
994
- tieredRewardDefinitionSchema,
995
- tierRewardSchema,
996
- integrationRewardSchema,
997
- rewardSchema,
998
- rewardKey,
999
- triggerSchema,
1000
- prerequisiteSchema,
1001
- photoResultSchema,
1002
- textReviewInputSchema,
1003
- textResultSchema,
1004
- decisionSchema,
1005
- reviewModeSchema,
1006
- storedReviewModeSchema,
1007
- rewardBundleSchema,
1008
- mediaUrlSchema,
1009
- questPresentationSchema,
1010
- questDescriptionSchema,
1011
- artifactSchema,
1012
- releaseSchema,
1013
- batchReleaseSchema,
1014
- questSettingsInputSchema,
1015
- publishedReleaseSchema,
1016
- templateSchema,
1017
- quizAnswersSchema,
1018
- quizEvidenceSchema,
1019
- submissionEvidenceSchema,
1020
- submitSchema,
1021
- attemptSchema,
1022
- eventSchema,
1023
- pickupSelectionSchema,
1024
- pickupAllocationSchema,
1025
- pickupPolicySchema,
1026
- pickupCatalogSchema,
1027
- pickupAvailabilitySchema,
1028
- configurePickupSchema,
1029
- entitlementSchema,
1030
- beginHandoverSchema,
1031
- confirmHandoverSchema,
1032
- completionRecordSchema,
1033
- questAvailabilitySchema,
1034
- memberProgressSchema,
1035
- snapshotSchema,
1036
- evidenceSchema,
1037
- errorSchema,
1038
- staffDecisionSchema,
1039
- stockSchema,
1040
- reservationSchema,
1041
- reviewListSchema,
1042
- memberListSchema,
1043
- reviewItemSchema,
1044
- reviewPageSchema,
1045
- memberPageSchema,
1046
- createStockItemSchema,
1047
- stockItemSchema
1048
- };