@domino-sdk/relay 1.0.0-next.6 → 1.0.0-next.8

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 (43) hide show
  1. package/README.md +13 -1
  2. package/build.mjs +18 -1
  3. package/dist/authoring.d.ts +317 -15
  4. package/dist/authoring.js +177 -23
  5. package/dist/avatar.d.ts +29 -0
  6. package/dist/avatar.js +21 -0
  7. package/dist/browser.d.ts +174 -2239
  8. package/dist/browser.js +6 -6
  9. package/dist/{chunk-RTHN22KO.js → chunk-6A6K5RUD.js} +22 -8
  10. package/dist/chunk-77H7APVD.js +171 -0
  11. package/dist/chunk-MRIURJE3.js +257 -0
  12. package/dist/{chunk-5IIWKDFX.js → chunk-QBOHLT7M.js} +26 -5
  13. package/dist/chunk-V5R2DMGY.js +1407 -0
  14. package/dist/chunk-V7EZUZ3Z.js +1003 -0
  15. package/dist/chunk-V7UKZLHA.js +35 -0
  16. package/dist/{chunk-BRESOTKV.js → chunk-VARGF4JS.js} +660 -770
  17. package/dist/chunk-ZWY3R6B3.js +26 -0
  18. package/dist/client-CK4nwt7V.d.ts +2631 -0
  19. package/dist/collection-BGneJ6Bk.d.ts +114 -0
  20. package/dist/images--vZ9U0kr.d.ts +234 -0
  21. package/dist/index.d.ts +11 -13132
  22. package/dist/index.js +20 -690
  23. package/dist/integrations-C3Sp558f.d.ts +1297 -0
  24. package/dist/internal.d.ts +120 -0
  25. package/dist/internal.js +111 -0
  26. package/dist/pages-BzqJuI69.d.ts +4006 -0
  27. package/dist/point-ledgers-iS00Z_v0.d.ts +37 -0
  28. package/dist/portal-proxy.js +8 -9
  29. package/dist/profiles-DDMFBRKe.d.ts +297 -0
  30. package/dist/react/index.d.ts +186 -2251
  31. package/dist/react/index.js +11 -15
  32. package/dist/schema-pnuWqvGn.d.ts +3396 -0
  33. package/dist/schema.d.ts +3196 -2374
  34. package/dist/schema.js +549 -3
  35. package/dist/streaks-CwGReWGt.d.ts +73 -0
  36. package/dist/submission-input-C9qm9ixd.d.ts +2672 -0
  37. package/dist/units-CwgsPB_r.d.ts +9 -0
  38. package/dist/wallet-BGOfFkG9.d.ts +231 -0
  39. package/package.json +17 -4
  40. package/dist/chunk-ERBVT7GE.js +0 -1847
  41. package/dist/chunk-XEQDW7FM.js +0 -373
  42. package/dist/chunk-ZKJBCQNI.js +0 -624
  43. package/dist/submission-input-CZDukyb3.d.ts +0 -4998
@@ -0,0 +1,1407 @@
1
+ import {
2
+ collectionPassSchema,
3
+ pointLedgerReferenceSchema,
4
+ questExperienceSchema,
5
+ rewardDeliveriesSchema
6
+ } from "./chunk-MRIURJE3.js";
7
+ import {
8
+ AVATAR_UPLOAD_LIMIT,
9
+ RelayError,
10
+ RelayErrorCode,
11
+ avatarUploadTypes,
12
+ clientError,
13
+ engagementBoundaryPageSchema,
14
+ engagementPageQuerySchema,
15
+ engagementPageSchema,
16
+ leaderboardDefinitionSchema,
17
+ leaderboardPageSchema,
18
+ leaderboardPlacementSchema,
19
+ leaderboardQuerySchema,
20
+ linkedWalletSchema,
21
+ ownProfileSchema,
22
+ parseInput,
23
+ profileCompletionPageSchema,
24
+ profileCompletionQuerySchema,
25
+ profileReferralSchema,
26
+ profileSummarySchema,
27
+ profileUpdateSchema,
28
+ referralAcceptSchema,
29
+ referralDefinitionSchema,
30
+ referralHistorySchema,
31
+ referralSummarySchema,
32
+ walletAddressInput,
33
+ walletAddressInputSchema,
34
+ walletMessageChallengeSchema,
35
+ walletSignInNetworksSchema,
36
+ walletSignatureSchema,
37
+ walletUnlinkInputSchema
38
+ } from "./chunk-V7EZUZ3Z.js";
39
+ import {
40
+ exchangeResultSchema,
41
+ exchangeSchema,
42
+ memberSummarySchema,
43
+ participantSessionSchema,
44
+ sessionMember
45
+ } from "./chunk-QBOHLT7M.js";
46
+ import {
47
+ accountConnectionSchema,
48
+ attemptSchema,
49
+ authProviderSchema,
50
+ contentAdmissionPageSchema,
51
+ contentAdmissionQuerySchema,
52
+ contentAdmissionSchema,
53
+ contentEnrollmentInputSchema,
54
+ contentEnrollmentSchema,
55
+ contentPerformancePageSchema,
56
+ contentPerformanceQuerySchema,
57
+ contentQualificationPageSchema,
58
+ contentQualificationQuerySchema,
59
+ contentReleaseInputSchema,
60
+ evidenceSchema,
61
+ identifier,
62
+ memberProgressSchema,
63
+ pageQuerySchema,
64
+ quizEvidenceSchema,
65
+ submissionEvidenceSchema,
66
+ submitSchema,
67
+ tieredRewardReferenceSchema,
68
+ validateSubmissionValue,
69
+ valueEvidenceSchema
70
+ } from "./chunk-VARGF4JS.js";
71
+
72
+ // src/submissions.ts
73
+ import { z } from "zod";
74
+ var common = {
75
+ id: identifier,
76
+ quest: identifier,
77
+ release: identifier.optional()
78
+ };
79
+ var claimInputSchema = z.union([
80
+ submissionEvidenceSchema,
81
+ z.object({ kind: z.literal("none") }).strict()
82
+ ]);
83
+ var draftSchema = z.union([
84
+ claimInputSchema,
85
+ z.object({ kind: z.literal("photo"), file: z.instanceof(Blob) })
86
+ ]);
87
+ var recordSchema = z.union([
88
+ z.object({
89
+ ...common,
90
+ stage: z.literal("review"),
91
+ draft: draftSchema.nullable()
92
+ }),
93
+ z.object({ ...common, stage: z.literal("upload"), file: z.instanceof(Blob) }),
94
+ z.object({
95
+ ...common,
96
+ stage: z.literal("claim"),
97
+ evidence: identifier,
98
+ file: z.instanceof(Blob).optional()
99
+ }),
100
+ z.object({
101
+ ...common,
102
+ stage: z.literal("submitted"),
103
+ evidence: identifier,
104
+ attempt: identifier
105
+ }),
106
+ z.object({ ...common, stage: z.literal("claim"), input: claimInputSchema }),
107
+ z.object({
108
+ ...common,
109
+ stage: z.literal("submitted"),
110
+ input: claimInputSchema,
111
+ attempt: identifier
112
+ })
113
+ ]);
114
+ function submissions(transport, configuredStore, namespace) {
115
+ async function open(quest, options = {
116
+ input: "photo"
117
+ }) {
118
+ if (!configuredStore) {
119
+ throw clientError(
120
+ "Submissions require durable storage. Use createBrowserRelayClient or provide a SubmissionStore.",
121
+ RelayErrorCode.SubmissionStorage
122
+ );
123
+ }
124
+ const store = configuredStore;
125
+ parseInput(identifier, quest);
126
+ const session = await transport.session();
127
+ const member = sessionMember(session);
128
+ if (!session || !member) {
129
+ throw clientError(
130
+ "Sign in to submit an activity",
131
+ RelayErrorCode.NotSignedIn
132
+ );
133
+ }
134
+ const sessionId = session.id;
135
+ const key = JSON.stringify([
136
+ "relay-submission-v1",
137
+ namespace,
138
+ session.organization,
139
+ session.environment,
140
+ session.project,
141
+ member,
142
+ quest
143
+ ]);
144
+ async function currentSession() {
145
+ const current = await transport.session();
146
+ if (current?.id !== sessionId) {
147
+ throw clientError(
148
+ "Your session changed. Reopen the submission before continuing.",
149
+ RelayErrorCode.StaleSession
150
+ );
151
+ }
152
+ }
153
+ async function read() {
154
+ const saved = await store.read(key);
155
+ if (saved === void 0 || saved === null) {
156
+ return null;
157
+ }
158
+ const parsed = recordSchema.safeParse(saved);
159
+ if (!parsed.success || parsed.data.quest !== quest) {
160
+ throw clientError(
161
+ "Saved submission could not be read. Do not create another claim until it is recovered.",
162
+ RelayErrorCode.SubmissionStorage
163
+ );
164
+ }
165
+ const record = parsed.data;
166
+ const input = record.stage === "review" ? record.draft?.kind : "input" in record ? record.input.kind : "photo";
167
+ if (!options.recoverPrevious && input !== options.input) {
168
+ throw clientError(
169
+ "Saved submission uses a different input type. Reopen it with its original type to recover it.",
170
+ RelayErrorCode.SubmissionConflict
171
+ );
172
+ }
173
+ return record;
174
+ }
175
+ function claim(record) {
176
+ return transport.claim(
177
+ {
178
+ quest,
179
+ actionId: record.id,
180
+ ...record.release ? { release: record.release } : {},
181
+ ..."evidence" in record ? { evidence: record.evidence } : record.input.kind !== "none" ? { input: record.input } : {}
182
+ },
183
+ sessionId
184
+ );
185
+ }
186
+ async function resumeRecord(saved) {
187
+ if (saved.stage === "review") {
188
+ throw new QuestUpdatedError(
189
+ "This quest changed. Review it before submitting again.",
190
+ "quest-updated",
191
+ saved.draft
192
+ );
193
+ }
194
+ let record = saved;
195
+ if (record.stage === "upload") {
196
+ const evidence = await transport.upload(
197
+ record.file,
198
+ record.id,
199
+ sessionId
200
+ );
201
+ record = {
202
+ id: record.id,
203
+ quest,
204
+ ...record.release ? { release: record.release } : {},
205
+ file: record.file,
206
+ stage: "claim",
207
+ evidence: evidence.id
208
+ };
209
+ await store.write(key, record);
210
+ }
211
+ let attempt;
212
+ try {
213
+ attempt = await claim(record);
214
+ } catch (error) {
215
+ if (error instanceof RelayError && error.status === 422 && error.code === "invalid-submission" && record.stage === "claim") {
216
+ await store.write(key, null);
217
+ throw error;
218
+ }
219
+ const changed = !(error instanceof RelayError) || error.status !== 409 ? null : error.code === "quest-updated" ? "quest-updated" : error.code === "stale-quiz" ? "stale-quiz" : null;
220
+ if (changed && error instanceof RelayError && record.stage === "claim") {
221
+ const draft = "input" in record ? record.input : "file" in record && record.file ? { kind: "photo", file: record.file } : null;
222
+ await store.write(
223
+ key,
224
+ changed === "quest-updated" ? {
225
+ id: record.id,
226
+ quest,
227
+ release: record.release,
228
+ stage: "review",
229
+ draft
230
+ } : null
231
+ );
232
+ throw new QuestUpdatedError(error.message, changed, draft, error);
233
+ }
234
+ throw error;
235
+ }
236
+ await store.write(key, {
237
+ ...record,
238
+ stage: "submitted",
239
+ attempt: attempt.id
240
+ });
241
+ if (attempt.status === "failed") {
242
+ attempt = await transport.retry(attempt.id, sessionId);
243
+ }
244
+ return attempt;
245
+ }
246
+ async function submit(record) {
247
+ return store.exclusive(key, async () => {
248
+ await currentSession();
249
+ const existing = await read();
250
+ if (existing?.stage === "review" && existing.release === record.release) {
251
+ throw new QuestUpdatedError(
252
+ "Review the latest quest before submitting again.",
253
+ "quest-updated",
254
+ existing.draft
255
+ );
256
+ }
257
+ if (existing && existing.stage !== "submitted" && existing.stage !== "review") {
258
+ throw clientError(
259
+ "A submission is unfinished. Resume it before choosing new input.",
260
+ RelayErrorCode.SubmissionConflict
261
+ );
262
+ }
263
+ if (existing?.stage === "submitted") {
264
+ const previous = await claim(existing);
265
+ if (previous.status === "failed") {
266
+ return transport.retry(previous.id, sessionId);
267
+ }
268
+ if (previous.status !== "rejected" && !(options.repeatable && previous.status === "accepted")) {
269
+ return previous;
270
+ }
271
+ }
272
+ await store.write(key, record);
273
+ return resumeRecord(record);
274
+ });
275
+ }
276
+ const handle = {
277
+ async discard() {
278
+ return store.exclusive(key, async () => {
279
+ await currentSession();
280
+ const record = await read();
281
+ if (!record) {
282
+ return;
283
+ }
284
+ if (record.stage !== "submitted") {
285
+ throw clientError(
286
+ "Resume the unfinished submission before starting over.",
287
+ RelayErrorCode.SubmissionConflict
288
+ );
289
+ }
290
+ const attempt = await claim(record);
291
+ if (attempt.status !== "failed" && attempt.status !== "rejected" && !(options.repeatable && attempt.status === "accepted")) {
292
+ throw clientError(
293
+ "Only a failed or rejected submission can be discarded.",
294
+ RelayErrorCode.SubmissionConflict
295
+ );
296
+ }
297
+ await store.write(key, null);
298
+ });
299
+ },
300
+ async status() {
301
+ await currentSession();
302
+ const record = await read();
303
+ if (!record) {
304
+ return { kind: "empty" };
305
+ }
306
+ if (record.stage === "review") {
307
+ return { kind: "needs-review" };
308
+ }
309
+ return record.stage === "submitted" ? { kind: "submitted", attempt: record.attempt } : { kind: "pending", stage: record.stage };
310
+ },
311
+ async resume() {
312
+ return store.exclusive(key, async () => {
313
+ await currentSession();
314
+ const record = await read();
315
+ if (!record) {
316
+ throw clientError(
317
+ "There is no saved submission to resume",
318
+ RelayErrorCode.SubmissionConflict
319
+ );
320
+ }
321
+ return resumeRecord(record);
322
+ });
323
+ }
324
+ };
325
+ if (options.input === "text" || options.input === "url") {
326
+ const kind = options.input;
327
+ return {
328
+ ...handle,
329
+ submit(value) {
330
+ const input = parseInput(valueEvidenceSchema, { kind, value });
331
+ return submit({
332
+ id: crypto.randomUUID(),
333
+ quest,
334
+ release: options.release,
335
+ stage: "claim",
336
+ input
337
+ });
338
+ }
339
+ };
340
+ }
341
+ if (options.input === "quiz") {
342
+ return {
343
+ ...handle,
344
+ submit(answers, version) {
345
+ const input = parseInput(quizEvidenceSchema, {
346
+ kind: "quiz",
347
+ answers,
348
+ ...version || options.release ? { release: version?.release ?? options.release } : {}
349
+ });
350
+ return submit({
351
+ id: crypto.randomUUID(),
352
+ ...options.release ? { release: options.release } : {},
353
+ quest,
354
+ stage: "claim",
355
+ input
356
+ });
357
+ }
358
+ };
359
+ }
360
+ if (options.input === "none") {
361
+ return {
362
+ ...handle,
363
+ submit() {
364
+ return submit({
365
+ id: crypto.randomUUID(),
366
+ ...options.release ? { release: options.release } : {},
367
+ quest,
368
+ stage: "claim",
369
+ input: { kind: "none" }
370
+ });
371
+ }
372
+ };
373
+ }
374
+ return {
375
+ ...handle,
376
+ async submit(file) {
377
+ if (!["image/jpeg", "image/png"].includes(file.type) || file.size === 0 || file.size > 5 * 1024 * 1024) {
378
+ throw clientError(
379
+ "Choose a JPG or PNG photo under 5 MB",
380
+ RelayErrorCode.InvalidInput
381
+ );
382
+ }
383
+ const bytes = new Uint8Array(await file.slice(0, 4).arrayBuffer());
384
+ const signature = file.type === "image/png" ? [137, 80, 78, 71] : [255, 216, 255];
385
+ if (!signature.every((byte, index) => bytes[index] === byte)) {
386
+ throw clientError(
387
+ "Image content does not match its file type",
388
+ RelayErrorCode.InvalidInput
389
+ );
390
+ }
391
+ return submit({
392
+ id: crypto.randomUUID(),
393
+ ...options.release ? { release: options.release } : {},
394
+ quest,
395
+ stage: "upload",
396
+ file
397
+ });
398
+ }
399
+ };
400
+ }
401
+ return open;
402
+ }
403
+ var QuestUpdatedError = class extends RelayError {
404
+ constructor(message, code, draft, source) {
405
+ super(message, {
406
+ kind: source?.kind ?? "client",
407
+ status: source?.status,
408
+ code,
409
+ operationId: source?.operationId,
410
+ cause: source
411
+ });
412
+ this.draft = draft;
413
+ }
414
+ draft;
415
+ name = "QuestUpdatedError";
416
+ };
417
+
418
+ // src/client.ts
419
+ import { z as z2 } from "zod";
420
+
421
+ // src/progress.ts
422
+ function observeProgress(transport, listener, options = {}, onDispose = () => {
423
+ }) {
424
+ const interval = options.intervalMs ?? 1500;
425
+ const maximum = options.maxBackoffMs ?? 3e4;
426
+ if (!Number.isFinite(interval) || interval <= 0 || !Number.isFinite(maximum) || maximum < interval) {
427
+ throw clientError(
428
+ "Progress polling requires a positive interval and a maximum at least as large",
429
+ RelayErrorCode.InvalidInput
430
+ );
431
+ }
432
+ let disposed = false;
433
+ let controller;
434
+ let timer;
435
+ let sessionId;
436
+ let failures = 0;
437
+ function clear() {
438
+ controller?.abort();
439
+ if (timer !== void 0) {
440
+ clearTimeout(timer);
441
+ }
442
+ sessionId = void 0;
443
+ if (!disposed) {
444
+ listener({ kind: "loading" });
445
+ }
446
+ }
447
+ async function refresh() {
448
+ if (disposed) {
449
+ return;
450
+ }
451
+ controller?.abort();
452
+ if (timer !== void 0) {
453
+ clearTimeout(timer);
454
+ }
455
+ const request = new AbortController();
456
+ controller = request;
457
+ const current = () => !disposed && !request.signal.aborted;
458
+ try {
459
+ const session = await transport.session(request.signal);
460
+ if (!current()) {
461
+ return;
462
+ }
463
+ if (sessionId !== (session?.id ?? null)) {
464
+ sessionId = session?.id ?? null;
465
+ listener({ kind: "session", session });
466
+ }
467
+ const member = sessionMember(session);
468
+ if (session && member) {
469
+ const progress = await transport.progress(session.id, request.signal);
470
+ if (!current()) {
471
+ return;
472
+ }
473
+ const confirmed = await transport.session(request.signal);
474
+ if (!current()) {
475
+ return;
476
+ }
477
+ if (confirmed?.id !== session.id || progress.member !== member) {
478
+ sessionId = void 0;
479
+ listener({ kind: "loading" });
480
+ return;
481
+ }
482
+ listener({ kind: "ready", session: confirmed, progress });
483
+ }
484
+ failures = 0;
485
+ } catch (error) {
486
+ if (!current()) {
487
+ return;
488
+ }
489
+ failures = Math.min(failures + 1, 20);
490
+ sessionId = void 0;
491
+ listener({
492
+ kind: "error",
493
+ error: error instanceof Error ? error : new Error("Could not refresh progress")
494
+ });
495
+ } finally {
496
+ if (current()) {
497
+ timer = setTimeout(
498
+ () => void refresh(),
499
+ Math.min(maximum, interval * 2 ** failures)
500
+ );
501
+ }
502
+ }
503
+ }
504
+ const observer = {
505
+ refresh,
506
+ clear,
507
+ dispose() {
508
+ if (disposed) {
509
+ return;
510
+ }
511
+ disposed = true;
512
+ controller?.abort();
513
+ if (timer !== void 0) {
514
+ clearTimeout(timer);
515
+ }
516
+ onDispose();
517
+ }
518
+ };
519
+ return observer;
520
+ }
521
+
522
+ // src/quest-experience.ts
523
+ function reconcileQuestDraft(view, draft) {
524
+ if (!draft) {
525
+ return null;
526
+ }
527
+ if (draft.kind === "text" || draft.kind === "url") {
528
+ return view.interaction === draft.kind ? draft : null;
529
+ }
530
+ if (draft.kind === "photo") {
531
+ return view.interaction === "photo" ? draft : null;
532
+ }
533
+ if (draft.kind === "none") {
534
+ return view.interaction === "claim" ? draft : null;
535
+ }
536
+ if (view.interaction !== "quiz") {
537
+ return null;
538
+ }
539
+ const answers = Object.fromEntries(
540
+ (view.presentation.quiz ?? []).flatMap((q) => {
541
+ const answer = draft.answers[q.id];
542
+ return q.choices.some((c) => c.id === answer) ? [[q.id, answer]] : [];
543
+ })
544
+ );
545
+ return { kind: "quiz", release: view.release, answers };
546
+ }
547
+ function questActions(submission, latest) {
548
+ return async (view) => {
549
+ async function run(task) {
550
+ try {
551
+ return { kind: "submitted", attempt: await task() };
552
+ } catch (error) {
553
+ if (!(error instanceof QuestUpdatedError)) {
554
+ throw error;
555
+ }
556
+ const current = await latest(view.quest).catch(() => {
557
+ throw error;
558
+ });
559
+ return {
560
+ kind: "quest-updated",
561
+ latest: current,
562
+ originalDraft: error.draft,
563
+ draft: reconcileQuestDraft(current, error.draft)
564
+ };
565
+ }
566
+ }
567
+ if (view.lifecycle !== "active" || view.interaction === "staff" || view.interaction === "automatic") {
568
+ const handle = await submission(view.quest, {
569
+ input: "none",
570
+ release: view.release,
571
+ recoverPrevious: true,
572
+ repeatable: view.completion.kind === "keyed"
573
+ });
574
+ return {
575
+ kind: "status",
576
+ view,
577
+ status: handle.status,
578
+ discard: handle.discard,
579
+ resume: () => run(handle.resume)
580
+ };
581
+ }
582
+ switch (view.interaction) {
583
+ case "text":
584
+ case "url": {
585
+ const kind = view.interaction;
586
+ const handle = await submission(view.quest, {
587
+ input: kind,
588
+ release: view.release,
589
+ recoverPrevious: true,
590
+ repeatable: view.completion.kind === "keyed"
591
+ });
592
+ return {
593
+ kind,
594
+ view,
595
+ status: handle.status,
596
+ discard: handle.discard,
597
+ resume: () => run(handle.resume),
598
+ submit: (value) => run(() => {
599
+ if (view.trigger.kind !== "manual" || view.trigger.input !== "text" && view.trigger.input !== "url") {
600
+ throw clientError(
601
+ "Quest input changed",
602
+ RelayErrorCode.QuestUpdated
603
+ );
604
+ }
605
+ const problem = validateSubmissionValue(
606
+ { kind, value },
607
+ view.trigger
608
+ );
609
+ if (problem) {
610
+ throw clientError(problem, RelayErrorCode.InvalidInput);
611
+ }
612
+ return handle.submit(value);
613
+ })
614
+ };
615
+ }
616
+ case "photo": {
617
+ const handle = await submission(view.quest, {
618
+ input: "photo",
619
+ release: view.release,
620
+ recoverPrevious: true,
621
+ repeatable: view.completion.kind === "keyed"
622
+ });
623
+ return {
624
+ kind: "photo",
625
+ view,
626
+ status: handle.status,
627
+ discard: handle.discard,
628
+ resume: () => run(handle.resume),
629
+ submit: (file) => run(() => handle.submit(file))
630
+ };
631
+ }
632
+ case "quiz": {
633
+ const handle = await submission(view.quest, {
634
+ input: "quiz",
635
+ release: view.release,
636
+ recoverPrevious: true,
637
+ repeatable: view.completion.kind === "keyed"
638
+ });
639
+ return {
640
+ kind: "quiz",
641
+ view,
642
+ status: handle.status,
643
+ discard: handle.discard,
644
+ resume: () => run(handle.resume),
645
+ submit: (answers) => run(() => handle.submit(answers, { release: view.release }))
646
+ };
647
+ }
648
+ case "claim": {
649
+ const handle = await submission(view.quest, {
650
+ input: "none",
651
+ release: view.release,
652
+ recoverPrevious: true,
653
+ repeatable: view.completion.kind === "keyed"
654
+ });
655
+ return {
656
+ kind: "claim",
657
+ view,
658
+ status: handle.status,
659
+ discard: handle.discard,
660
+ resume: () => run(handle.resume),
661
+ submit: () => run(handle.submit)
662
+ };
663
+ }
664
+ }
665
+ };
666
+ }
667
+
668
+ // src/client.ts
669
+ var TIMEOUT_MS = 15e3;
670
+ var missingEntrySchema = z2.object({ quest: identifier, title: z2.string() });
671
+ function errorBody(value) {
672
+ const body = value !== null && typeof value === "object" ? value : {};
673
+ return {
674
+ message: typeof body.error === "string" && body.error.trim() ? body.error : void 0,
675
+ code: typeof body.code === "string" && body.code.trim() ? body.code : void 0,
676
+ missing: Array.isArray(body.missing) ? body.missing.flatMap((entry) => {
677
+ const parsed = missingEntrySchema.safeParse(entry);
678
+ return parsed.success ? [parsed.data] : [];
679
+ }) : []
680
+ };
681
+ }
682
+ async function fromSigner(step) {
683
+ try {
684
+ return await step();
685
+ } catch (error) {
686
+ if (error instanceof RelayError) {
687
+ throw error;
688
+ }
689
+ throw clientError(
690
+ error instanceof Error && error.message ? error.message : "The wallet did not complete the request",
691
+ RelayErrorCode.WalletSigner,
692
+ { cause: error }
693
+ );
694
+ }
695
+ }
696
+ var uncertainStatuses = /* @__PURE__ */ new Set([500, 502, 504]);
697
+ var methodOf = (call) => call.method ?? (call.json === void 0 ? "GET" : "POST");
698
+ function withQuery(path, values) {
699
+ const params = new URLSearchParams();
700
+ for (const [key, value] of Object.entries(values)) {
701
+ if (value !== void 0) {
702
+ params.set(key, String(value));
703
+ }
704
+ }
705
+ const search = params.toString();
706
+ return search ? path + "?" + search : path;
707
+ }
708
+ function interrupted(call, error, stage) {
709
+ const details = {
710
+ status: stage.status,
711
+ operationId: call.operationId,
712
+ uncertain: stage.sent && methodOf(call) !== "GET",
713
+ cause: error
714
+ };
715
+ if (call.options?.signal?.aborted) {
716
+ return new RelayError("The request was cancelled", {
717
+ ...details,
718
+ kind: "aborted",
719
+ code: RelayErrorCode.Aborted
720
+ });
721
+ }
722
+ if (call.deadline?.aborted) {
723
+ return new RelayError("Relay did not respond in time", {
724
+ ...details,
725
+ kind: "timeout",
726
+ code: RelayErrorCode.Timeout
727
+ });
728
+ }
729
+ return new RelayError(
730
+ stage.status === void 0 ? "Could not reach Relay" : "Relay's response was cut off",
731
+ { ...details, kind: "network", code: RelayErrorCode.Network }
732
+ );
733
+ }
734
+ function createRelayClient(options) {
735
+ async function send(path, call = {}) {
736
+ const method = methodOf(call);
737
+ const headers = new Headers(call.headers);
738
+ let body2 = call.body;
739
+ if (options.token) {
740
+ headers.set("Authorization", `Bearer ${options.token}`);
741
+ }
742
+ if (options.organization) {
743
+ headers.set("X-Relay-Organization", options.organization);
744
+ }
745
+ if (options.project) {
746
+ headers.set("X-Relay-Project", options.project);
747
+ }
748
+ if (options.environment) {
749
+ headers.set("X-Relay-Environment", options.environment);
750
+ }
751
+ if (call.options?.session) {
752
+ headers.set("X-Relay-Session", call.options.session);
753
+ }
754
+ if (call.json !== void 0) {
755
+ headers.set("Content-Type", "application/json");
756
+ body2 = JSON.stringify(call.json);
757
+ }
758
+ if (method !== "GET") {
759
+ headers.set("X-Relay-CSRF", "1");
760
+ }
761
+ const caller = call.options?.signal;
762
+ const deadline = AbortSignal.timeout(TIMEOUT_MS);
763
+ call.deadline = deadline;
764
+ if (caller?.aborted) {
765
+ throw interrupted(call, caller.reason, { sent: false });
766
+ }
767
+ let response;
768
+ try {
769
+ response = await fetch(options.baseUrl + path, {
770
+ method,
771
+ headers,
772
+ body: body2,
773
+ signal: caller ? AbortSignal.any([caller, deadline]) : deadline
774
+ });
775
+ } catch (error) {
776
+ throw interrupted(call, error, { sent: true });
777
+ }
778
+ if (!response.ok) {
779
+ const text = await response.text().catch(() => "");
780
+ let value = null;
781
+ try {
782
+ value = JSON.parse(text);
783
+ } catch {
784
+ }
785
+ const { message, code, missing } = errorBody(value);
786
+ throw new RelayError(message ?? `Request failed (${response.status})`, {
787
+ kind: "http",
788
+ status: response.status,
789
+ code,
790
+ missing,
791
+ operationId: call.operationId,
792
+ uncertain: methodOf(call) !== "GET" && uncertainStatuses.has(response.status)
793
+ });
794
+ }
795
+ return response;
796
+ }
797
+ async function body(response, call, reader) {
798
+ try {
799
+ return await reader(response);
800
+ } catch (error) {
801
+ throw interrupted(call, error, { sent: true, status: response.status });
802
+ }
803
+ }
804
+ function invalidResponse(status, call, cause) {
805
+ return new RelayError(
806
+ "Relay sent a response this SDK version cannot read. Update @domino-sdk/relay.",
807
+ {
808
+ kind: "invalid-response",
809
+ code: RelayErrorCode.InvalidResponse,
810
+ status,
811
+ operationId: call.operationId,
812
+ // Relay accepted the write, but this client cannot tell what it did.
813
+ uncertain: methodOf(call) !== "GET",
814
+ cause
815
+ }
816
+ );
817
+ }
818
+ async function read(response, schema, call) {
819
+ const text = await body(response, call, (value2) => value2.text());
820
+ let value;
821
+ try {
822
+ value = JSON.parse(text);
823
+ } catch (error) {
824
+ throw invalidResponse(response.status, call, error);
825
+ }
826
+ const parsed = schema.safeParse(value);
827
+ if (!parsed.success) {
828
+ throw invalidResponse(response.status, call, parsed.error);
829
+ }
830
+ return parsed.data;
831
+ }
832
+ async function request(path, schema, call = {}) {
833
+ return read(await send(path, call), schema, call);
834
+ }
835
+ async function walletRequest(path, schema, call = {}) {
836
+ for (let attempt = 0; ; attempt++) {
837
+ let response;
838
+ try {
839
+ response = await send(path, call);
840
+ } catch (error) {
841
+ const transient = error instanceof RelayError && (error.kind === "network" || error.kind === "timeout" || error.kind === "http" && [500, 502, 503, 504].includes(error.status ?? 0));
842
+ if (!transient || attempt === 2) {
843
+ throw error;
844
+ }
845
+ await new Promise(
846
+ (resolve) => setTimeout(resolve, attempt === 0 ? 250 : 750)
847
+ );
848
+ continue;
849
+ }
850
+ return read(response, schema, call);
851
+ }
852
+ }
853
+ const readSession = (requestOptions) => request("/v1/auth/session", participantSessionSchema.nullable(), {
854
+ options: { signal: requestOptions?.signal }
855
+ });
856
+ async function bound(requestOptions = {}) {
857
+ if (requestOptions.session) {
858
+ return requestOptions;
859
+ }
860
+ const session = await readSession(requestOptions);
861
+ if (session?.principal.kind !== "member") {
862
+ throw clientError("Sign in to continue", RelayErrorCode.NotSignedIn);
863
+ }
864
+ return { ...requestOptions, session: session.id };
865
+ }
866
+ const submission = submissions(
867
+ {
868
+ session: () => readSession(),
869
+ upload: (file, action, session) => request("/v1/me/evidence", evidenceSchema, {
870
+ method: "POST",
871
+ body: file,
872
+ headers: { "Content-Type": file.type, "X-Relay-Upload-ID": action },
873
+ options: { session },
874
+ operationId: action
875
+ }),
876
+ claim: async (claim, session) => request("/v1/me/attempts", attemptSchema, {
877
+ json: claim,
878
+ options: { session },
879
+ operationId: claim.actionId
880
+ }),
881
+ retry: (attempt, session) => request(`/v1/attempts/${attempt}/retry`, attemptSchema, {
882
+ json: {},
883
+ options: { session }
884
+ })
885
+ },
886
+ options.submissionStore,
887
+ options.baseUrl
888
+ );
889
+ const observers = /* @__PURE__ */ new Set();
890
+ async function changeSession(task) {
891
+ for (const observer of observers) {
892
+ observer.clear();
893
+ }
894
+ try {
895
+ return await task();
896
+ } finally {
897
+ for (const observer of observers) {
898
+ void observer.refresh();
899
+ }
900
+ }
901
+ }
902
+ const experience = (requestOptions) => request("/v1/me/experience", questExperienceSchema, {
903
+ options: requestOptions
904
+ });
905
+ async function getQuest(id, requestOptions) {
906
+ const quest = (await experience(requestOptions)).quests.find(
907
+ (q) => q.quest === id || q.key === id
908
+ );
909
+ if (!quest) {
910
+ throw clientError("Quest not found", RelayErrorCode.NotFound);
911
+ }
912
+ return quest;
913
+ }
914
+ const ok = z2.object({ ok: z2.literal(true) });
915
+ const acknowledged = z2.object({ ok: z2.boolean() });
916
+ return {
917
+ referrals: {
918
+ list: (requestOptions) => request("/v1/referrals", z2.array(referralDefinitionSchema), {
919
+ options: requestOptions
920
+ }),
921
+ summary: (requestOptions) => request("/v1/referrals/me", referralSummarySchema, {
922
+ options: requestOptions
923
+ }),
924
+ /** The member's referral point history, newest first. */
925
+ history: async (query = {}, requestOptions) => request(
926
+ withQuery("/v1/referrals/history", parseInput(pageQuerySchema, query)),
927
+ referralHistorySchema,
928
+ { options: requestOptions }
929
+ ),
930
+ accept: async (value, requestOptions) => {
931
+ const body2 = parseInput(referralAcceptSchema, value);
932
+ return request("/v1/referrals/accept", ok, {
933
+ json: body2,
934
+ options: requestOptions,
935
+ operationId: body2.actionId
936
+ });
937
+ }
938
+ },
939
+ tieredRewards: {
940
+ /**
941
+ * The project's tiered rewards with their keys. Entitlements and reward
942
+ * definitions name them by ID: use this to find the ID for a key.
943
+ */
944
+ list: (requestOptions) => request("/v1/tiered-rewards", z2.array(tieredRewardReferenceSchema), {
945
+ options: requestOptions
946
+ })
947
+ },
948
+ pointLedgers: {
949
+ /**
950
+ * The project's point ledgers with their keys and names. Reads return
951
+ * ledger IDs: use this to find the ID for a key, or a ledger's name.
952
+ */
953
+ list: (requestOptions) => request("/v1/point-ledgers", z2.array(pointLedgerReferenceSchema), {
954
+ options: requestOptions
955
+ })
956
+ },
957
+ leaderboards: {
958
+ list: (requestOptions) => request("/v1/leaderboards", z2.array(leaderboardDefinitionSchema), {
959
+ options: requestOptions
960
+ }),
961
+ standings: async (board, query = {}, requestOptions) => request(
962
+ withQuery(
963
+ `/v1/leaderboards/${parseInput(identifier, board)}`,
964
+ parseInput(leaderboardQuerySchema, query)
965
+ ),
966
+ leaderboardPageSchema,
967
+ { options: requestOptions }
968
+ ),
969
+ /**
970
+ * A profile's current rank and score on `board` (`profile.id` from a leaderboard row or
971
+ * `profiles.mine()`). Needs the board's access, like `standings`; a profile this viewer
972
+ * cannot see is a 404, as in `profiles.get`.
973
+ */
974
+ placement: async (board, profile, requestOptions) => request(
975
+ `/v1/leaderboards/${parseInput(identifier, board)}/profiles/${parseInput(identifier, profile)}`,
976
+ leaderboardPlacementSchema,
977
+ { options: requestOptions }
978
+ )
979
+ },
980
+ /**
981
+ * Participant profiles: the display name and avatar other participants see where the project
982
+ * enables profiles in Console. Render an avatar with `avatarSrc(profile.avatar)` from
983
+ * `@domino-sdk/relay/avatar`.
984
+ */
985
+ profiles: {
986
+ /** The signed-in member's own profile, whatever the project shows to others. */
987
+ mine: (requestOptions) => request("/v1/me/profile", ownProfileSchema, {
988
+ options: requestOptions
989
+ }),
990
+ /**
991
+ * Changes the member's own name, avatar choice or visibility; omitted fields stay, and null
992
+ * returns to the default.
993
+ */
994
+ update: async (value, requestOptions) => request("/v1/me/profile", ownProfileSchema, {
995
+ json: parseInput(profileUpdateSchema, value),
996
+ options: requestOptions
997
+ }),
998
+ /**
999
+ * Uploads a JPEG, PNG or WebP of at most 5 MB as the member's avatar. The server crops it to
1000
+ * a 512×512 WebP without metadata. Retrying with the same `uploadId` is idempotent.
1001
+ */
1002
+ uploadAvatar: async (file, requestOptions = {}) => {
1003
+ if (!avatarUploadTypes.includes(file.type)) {
1004
+ throw clientError(
1005
+ "Use a JPEG, PNG or WebP image",
1006
+ RelayErrorCode.InvalidInput
1007
+ );
1008
+ }
1009
+ if (file.size > AVATAR_UPLOAD_LIMIT) {
1010
+ throw clientError(
1011
+ "Use an image smaller than 5 MB",
1012
+ RelayErrorCode.InvalidInput
1013
+ );
1014
+ }
1015
+ const { uploadId, ...rest } = requestOptions;
1016
+ const operationId = parseInput(identifier, uploadId ?? crypto.randomUUID());
1017
+ return request("/v1/me/profile/avatar", ownProfileSchema, {
1018
+ method: "POST",
1019
+ body: file,
1020
+ headers: {
1021
+ "Content-Type": file.type,
1022
+ "X-Relay-Upload-ID": operationId
1023
+ },
1024
+ options: rest,
1025
+ operationId
1026
+ });
1027
+ },
1028
+ /**
1029
+ * A profile's name and avatar by its public ID (`profile.id` from a leaderboard row or
1030
+ * `mine()`). A profile that is missing, hidden or not visible to this viewer is a 404.
1031
+ */
1032
+ get: async (profile, requestOptions) => request(
1033
+ `/v1/profiles/${parseInput(identifier, profile)}`,
1034
+ profileSummarySchema,
1035
+ { options: requestOptions }
1036
+ ),
1037
+ /**
1038
+ * A page of the profile's completions of quests that show on profiles, most recently
1039
+ * completed first.
1040
+ */
1041
+ completions: async (profile, query = {}, requestOptions) => request(
1042
+ withQuery(
1043
+ `/v1/profiles/${parseInput(identifier, profile)}/completions`,
1044
+ parseInput(profileCompletionQuerySchema, query)
1045
+ ),
1046
+ profileCompletionPageSchema,
1047
+ { options: requestOptions }
1048
+ ),
1049
+ /**
1050
+ * The profile's invited and qualified counts and milestones in one referral program. Needs
1051
+ * a signed-in participant, as referral programs do.
1052
+ */
1053
+ referral: async (profile, program, requestOptions) => request(
1054
+ `/v1/profiles/${parseInput(identifier, profile)}/referrals/${parseInput(identifier, program)}`,
1055
+ profileReferralSchema,
1056
+ { options: requestOptions }
1057
+ )
1058
+ },
1059
+ quests: {
1060
+ get: getQuest,
1061
+ /** Retries verification of the quest's failed attempt. */
1062
+ retry: async (view, requestOptions) => {
1063
+ if (view.trigger.kind === "automatic") {
1064
+ throw clientError(
1065
+ "Automatic quests recover without participant retries.",
1066
+ RelayErrorCode.RetryUnavailable
1067
+ );
1068
+ }
1069
+ if (!view.attempt || view.attempt.status !== "failed") {
1070
+ throw clientError(
1071
+ "There is no failed attempt to retry.",
1072
+ RelayErrorCode.RetryUnavailable
1073
+ );
1074
+ }
1075
+ return request(`/v1/attempts/${view.attempt.id}/retry`, attemptSchema, {
1076
+ json: {},
1077
+ options: await bound(requestOptions)
1078
+ });
1079
+ },
1080
+ experience,
1081
+ collection: async (id, requestOptions) => {
1082
+ const collection = (await experience(requestOptions)).collections.find(
1083
+ (c) => c.id === id || c.key === id
1084
+ );
1085
+ if (!collection) {
1086
+ throw clientError("Collection not found", RelayErrorCode.NotFound);
1087
+ }
1088
+ return collection;
1089
+ },
1090
+ open: questActions(submission, (id) => getQuest(id)),
1091
+ observe: (listener, observeOptions) => {
1092
+ const observer = observeProgress(
1093
+ {
1094
+ session: (signal) => readSession({ signal }),
1095
+ progress: (session, signal) => request("/v1/me/experience", questExperienceSchema, {
1096
+ options: { session, signal }
1097
+ })
1098
+ },
1099
+ listener,
1100
+ observeOptions,
1101
+ () => observers.delete(observer)
1102
+ );
1103
+ observers.add(observer);
1104
+ observer.clear();
1105
+ void observer.refresh();
1106
+ return { refresh: observer.refresh, dispose: observer.dispose };
1107
+ }
1108
+ },
1109
+ /** The signed-in member's linked Solana, EVM and Cosmos wallets for this project. */
1110
+ wallets: {
1111
+ list: (requestOptions) => walletRequest(
1112
+ "/v1/me/wallets",
1113
+ z2.object({ wallets: z2.array(linkedWalletSchema) }),
1114
+ { options: requestOptions }
1115
+ ).then((result) => result.wallets),
1116
+ challenge: async (value, requestOptions) => walletRequest(
1117
+ "/v1/me/wallets/challenge",
1118
+ walletMessageChallengeSchema,
1119
+ {
1120
+ json: parseInput(walletAddressInputSchema, value),
1121
+ options: await bound(requestOptions)
1122
+ }
1123
+ ),
1124
+ verify: async (value, requestOptions) => walletRequest("/v1/me/wallets/verify", linkedWalletSchema, {
1125
+ json: parseInput(walletSignatureSchema, value),
1126
+ options: await bound(requestOptions)
1127
+ }),
1128
+ /** The address stays bound to this member: another member still cannot link it. */
1129
+ unlink: async (wallet, requestOptions) => request("/v1/me/wallets/unlink", ok, {
1130
+ json: parseInput(walletUnlinkInputSchema, {
1131
+ chain: wallet.chain,
1132
+ address: wallet.address
1133
+ }),
1134
+ options: requestOptions
1135
+ }),
1136
+ /** Asks the signer for its address, signs the returned challenge, and links the wallet. */
1137
+ link: async (signer, requestOptions) => {
1138
+ const session = await bound(requestOptions);
1139
+ const challenge = await walletRequest(
1140
+ "/v1/me/wallets/challenge",
1141
+ walletMessageChallengeSchema,
1142
+ {
1143
+ json: parseInput(
1144
+ walletAddressInputSchema,
1145
+ await fromSigner(() => walletAddressInput(signer))
1146
+ ),
1147
+ options: session
1148
+ }
1149
+ );
1150
+ const proof = await fromSigner(
1151
+ () => signer.sign(challenge.message, challenge.address)
1152
+ );
1153
+ return walletRequest("/v1/me/wallets/verify", linkedWalletSchema, {
1154
+ json: parseInput(walletSignatureSchema, {
1155
+ challenge: challenge.id,
1156
+ ...proof
1157
+ }),
1158
+ options: session
1159
+ });
1160
+ }
1161
+ },
1162
+ auth: {
1163
+ providers: (requestOptions) => request(
1164
+ "/v1/auth/providers",
1165
+ z2.object({
1166
+ providers: z2.array(
1167
+ z2.object({
1168
+ provider: authProviderSchema,
1169
+ configured: z2.boolean()
1170
+ })
1171
+ ),
1172
+ email: z2.boolean(),
1173
+ /** The wallet sign-in this project enabled; older servers omit it. */
1174
+ wallets: walletSignInNetworksSchema.default([]),
1175
+ demo: z2.boolean()
1176
+ }),
1177
+ { options: requestOptions }
1178
+ ),
1179
+ start: async (provider, mode, requestOptions) => request("/v1/auth/start", z2.object({ url: z2.string() }), {
1180
+ json: {
1181
+ provider: parseInput(authProviderSchema, provider),
1182
+ mode: parseInput(z2.enum(["sign-in", "connect"]), mode)
1183
+ },
1184
+ options: requestOptions
1185
+ }),
1186
+ emailStart: async (email, requestOptions) => request("/v1/auth/email/start", z2.object({ challenge: z2.string() }), {
1187
+ json: { email: parseInput(z2.email().max(254), email.trim()) },
1188
+ options: requestOptions
1189
+ }),
1190
+ emailVerify: async (challenge, code, requestOptions) => {
1191
+ const body2 = {
1192
+ challenge: parseInput(z2.string().min(1).max(200), challenge),
1193
+ code: parseInput(
1194
+ z2.string().regex(/^\d{6}$/, "Enter the 6-digit code"),
1195
+ code.trim()
1196
+ )
1197
+ };
1198
+ return changeSession(
1199
+ () => request("/v1/auth/email/verify", participantSessionSchema, {
1200
+ json: body2,
1201
+ options: requestOptions
1202
+ })
1203
+ );
1204
+ },
1205
+ /**
1206
+ * Sign in, or sign up, with a Solana, EVM or Cosmos wallet where the project enabled it
1207
+ * (`providers().wallets`). A wallet the member linked while signed in cannot sign in.
1208
+ */
1209
+ wallet: {
1210
+ /** A sign-in challenge for the wallet's address; binds the flow to this browser. */
1211
+ start: async (value, requestOptions) => request("/v1/auth/wallet/start", walletMessageChallengeSchema, {
1212
+ json: parseInput(walletAddressInputSchema, value),
1213
+ options: requestOptions
1214
+ }),
1215
+ /** Verifies the signed challenge and starts the session. Not retried: start again instead. */
1216
+ verify: (proof, requestOptions) => changeSession(
1217
+ () => request("/v1/auth/wallet/verify", participantSessionSchema, {
1218
+ json: parseInput(walletSignatureSchema, proof),
1219
+ options: requestOptions
1220
+ })
1221
+ ),
1222
+ /**
1223
+ * Asks the signer for its address, signs the challenge and starts the session. Rejects with
1224
+ * an `http` `RelayError` (status 403) when the project has not enabled this wallet family.
1225
+ */
1226
+ signIn: async (signer, requestOptions) => {
1227
+ const challenge = await request(
1228
+ "/v1/auth/wallet/start",
1229
+ walletMessageChallengeSchema,
1230
+ {
1231
+ json: parseInput(
1232
+ walletAddressInputSchema,
1233
+ await fromSigner(() => walletAddressInput(signer))
1234
+ ),
1235
+ options: requestOptions
1236
+ }
1237
+ );
1238
+ const proof = await fromSigner(
1239
+ () => signer.sign(challenge.message, challenge.address)
1240
+ );
1241
+ return changeSession(
1242
+ () => request("/v1/auth/wallet/verify", participantSessionSchema, {
1243
+ json: parseInput(walletSignatureSchema, {
1244
+ challenge: challenge.id,
1245
+ ...proof
1246
+ }),
1247
+ options: requestOptions
1248
+ })
1249
+ );
1250
+ }
1251
+ },
1252
+ /** The member's connected sign-in accounts, one per provider. */
1253
+ accounts: (requestOptions) => request("/v1/auth/accounts", z2.array(accountConnectionSchema), {
1254
+ options: requestOptions
1255
+ }),
1256
+ disconnect: async (provider, requestOptions) => request("/v1/auth/accounts/disconnect", acknowledged, {
1257
+ json: { provider: parseInput(authProviderSchema, provider) },
1258
+ options: requestOptions
1259
+ }),
1260
+ session: (requestOptions) => readSession(requestOptions),
1261
+ signOut: (requestOptions) => changeSession(
1262
+ () => request("/v1/auth/logout", acknowledged, {
1263
+ json: {},
1264
+ options: requestOptions
1265
+ })
1266
+ ),
1267
+ /** Local development only. Existing hosted apps use createParticipantBackend from /portal-proxy. */
1268
+ exchange: async (value, requestOptions) => request("/v1/auth/exchange", exchangeResultSchema, {
1269
+ json: parseInput(exchangeSchema, value),
1270
+ options: requestOptions
1271
+ })
1272
+ },
1273
+ me: {
1274
+ /** The signed-in member, and the seed of their generated avatar: `defaultAvatar(avatarSeed)`. */
1275
+ get: async (requestOptions) => request("/v1/me", memberSummarySchema, { options: requestOptions }),
1276
+ observeProgress: (listener, observeOptions) => {
1277
+ const observer = observeProgress(
1278
+ {
1279
+ session: (signal) => readSession({ signal }),
1280
+ progress: (session, signal) => request("/v1/me/progress", memberProgressSchema, {
1281
+ options: { session, signal }
1282
+ })
1283
+ },
1284
+ listener,
1285
+ observeOptions,
1286
+ () => observers.delete(observer)
1287
+ );
1288
+ observers.add(observer);
1289
+ observer.clear();
1290
+ void observer.refresh();
1291
+ return { refresh: observer.refresh, dispose: observer.dispose };
1292
+ },
1293
+ submission,
1294
+ collectionPass: async (entitlement, requestOptions) => request("/v1/me/collection-pass", collectionPassSchema, {
1295
+ json: { entitlement: parseInput(identifier, entitlement) },
1296
+ options: await bound(requestOptions)
1297
+ }),
1298
+ progress: (requestOptions) => request("/v1/me/progress", memberProgressSchema, {
1299
+ options: requestOptions
1300
+ }),
1301
+ rewardDeliveries: (requestOptions) => request("/v1/reward-deliveries", rewardDeliveriesSchema, {
1302
+ options: requestOptions
1303
+ }),
1304
+ /** Claims a quest for the signed-in member. Quest controllers (`quests.open`) call this. */
1305
+ claim: async (value, requestOptions) => {
1306
+ const claim = parseInput(submitSchema.omit({ member: true }), value);
1307
+ return request("/v1/me/attempts", attemptSchema, {
1308
+ json: claim,
1309
+ options: requestOptions,
1310
+ operationId: claim.actionId
1311
+ });
1312
+ },
1313
+ /** Uploads a photo as the signed-in member's evidence. */
1314
+ upload: (file, requestOptions) => request("/v1/me/evidence", evidenceSchema, {
1315
+ method: "POST",
1316
+ body: file,
1317
+ headers: { "Content-Type": file.type },
1318
+ options: requestOptions
1319
+ })
1320
+ },
1321
+ evidence: {
1322
+ async download(id, requestOptions) {
1323
+ const call = { options: requestOptions };
1324
+ const response = await send(
1325
+ `/v1/evidence/${parseInput(identifier, id)}`,
1326
+ call
1327
+ );
1328
+ const type = response.headers.get("Content-Type");
1329
+ if (type !== "image/jpeg" && type !== "image/png") {
1330
+ throw invalidResponse(
1331
+ response.status,
1332
+ call,
1333
+ new Error("Unexpected evidence content type")
1334
+ );
1335
+ }
1336
+ return body(response, call, (value) => value.blob());
1337
+ }
1338
+ },
1339
+ engagement: {
1340
+ /** The member's engagement settlements for one post under one rule, newest first. */
1341
+ page: async (query, requestOptions) => request(
1342
+ withQuery(
1343
+ "/v1/engagement/history",
1344
+ parseInput(engagementPageQuerySchema, query)
1345
+ ),
1346
+ engagementPageSchema,
1347
+ { options: requestOptions }
1348
+ ),
1349
+ /** The formula boundaries the member's settlements for one post crossed, newest first. */
1350
+ boundaries: async (query, requestOptions) => request(
1351
+ withQuery(
1352
+ "/v1/engagement/boundaries",
1353
+ parseInput(engagementPageQuerySchema, query)
1354
+ ),
1355
+ engagementBoundaryPageSchema,
1356
+ { options: requestOptions }
1357
+ )
1358
+ },
1359
+ content: {
1360
+ performance: async (query, requestOptions) => request(
1361
+ withQuery(
1362
+ "/v1/content/performance",
1363
+ parseInput(contentPerformanceQuerySchema, query)
1364
+ ),
1365
+ contentPerformancePageSchema,
1366
+ { options: requestOptions }
1367
+ ),
1368
+ qualifications: async (query, requestOptions) => request(
1369
+ withQuery(
1370
+ "/v1/content/qualifications",
1371
+ parseInput(contentQualificationQuerySchema, query)
1372
+ ),
1373
+ contentQualificationPageSchema,
1374
+ { options: requestOptions }
1375
+ ),
1376
+ admissions: async (query, requestOptions) => request(
1377
+ withQuery(
1378
+ "/v1/content/admissions",
1379
+ parseInput(contentAdmissionQuerySchema, query)
1380
+ ),
1381
+ contentAdmissionPageSchema,
1382
+ { options: requestOptions }
1383
+ ),
1384
+ enroll: async (value, requestOptions) => {
1385
+ const body2 = parseInput(contentEnrollmentInputSchema, value);
1386
+ return request("/v1/content/enrollments", contentEnrollmentSchema, {
1387
+ json: body2,
1388
+ options: requestOptions,
1389
+ operationId: body2.actionId
1390
+ });
1391
+ },
1392
+ claim: async (value, requestOptions) => {
1393
+ const body2 = parseInput(contentReleaseInputSchema, value);
1394
+ return request("/v1/content/claims", contentAdmissionSchema, {
1395
+ json: body2,
1396
+ options: requestOptions,
1397
+ operationId: body2.actionId
1398
+ });
1399
+ }
1400
+ }
1401
+ };
1402
+ }
1403
+
1404
+ export {
1405
+ QuestUpdatedError,
1406
+ createRelayClient
1407
+ };