@domino-sdk/relay 1.0.0-next.2 → 1.0.0-next.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/build.mjs +18 -1
- package/dist/activity-B8k9Sa_a.d.ts +9112 -0
- package/dist/authoring.d.ts +1355 -182
- package/dist/authoring.js +658 -225
- package/dist/automatic-outcomes-B1xrETxm.d.ts +758 -0
- package/dist/avatar.d.ts +29 -0
- package/dist/avatar.js +21 -0
- package/dist/browser-J7tUpXxy.d.ts +4154 -0
- package/dist/browser.d.ts +11 -4580
- package/dist/browser.js +8 -6
- package/dist/capability-error-DNMwKmlL.d.ts +458 -0
- package/dist/chunk-36HTX2BM.js +1223 -0
- package/dist/chunk-6QJ3LADK.js +112 -0
- package/dist/chunk-BGGKNIRP.js +171 -0
- package/dist/chunk-EYH5RDIE.js +496 -0
- package/dist/chunk-GQKYAQM6.js +84 -0
- package/dist/chunk-GUP7YRR4.js +42 -0
- package/dist/chunk-GZ6FJAXN.js +1659 -0
- package/dist/chunk-JON5SESL.js +2986 -0
- package/dist/chunk-MC6V6VMG.js +49 -0
- package/dist/chunk-NPGENI7K.js +37 -0
- package/dist/chunk-V7UKZLHA.js +35 -0
- package/dist/chunk-VFHHLN6A.js +284 -0
- package/dist/chunk-WJSSJ7AF.js +151 -0
- package/dist/{chunk-VH4OQ5VX.js → chunk-XFMSUPNS.js} +26 -5
- package/dist/{chunk-FDWRBMB3.js → chunk-ZVIRG24J.js} +150 -33
- package/dist/client-XiuFnug_.d.ts +4262 -0
- package/dist/groups-Ck-OxzjD.d.ts +2449 -0
- package/dist/identity-integration-GxAHdKR2.d.ts +58 -0
- package/dist/images-Dv-P5VBw.d.ts +234 -0
- package/dist/index.d.ts +15 -13115
- package/dist/index.js +30 -689
- package/dist/internal.d.ts +159 -0
- package/dist/internal.js +79 -0
- package/dist/offers-Cy-e4o5x.d.ts +431 -0
- package/dist/outcomes-kVB-Juzs.d.ts +4902 -0
- package/dist/pages-BBYD21IE.d.ts +359 -0
- package/dist/participant-rewards-3duLb8YJ.d.ts +668 -0
- package/dist/portal-proxy.js +26 -9
- package/dist/profiles-D2aFcOxu.d.ts +297 -0
- package/dist/react/index.d.ts +3378 -3318
- package/dist/react/index.js +1635 -783
- package/dist/request-error-DWduJCGV.d.ts +62 -0
- package/dist/schema-DfJzH2ci.d.ts +5644 -0
- package/dist/schema.d.ts +15 -3388
- package/dist/schema.js +790 -3
- package/dist/server/index.d.ts +81498 -0
- package/dist/server/index.js +2520 -0
- package/dist/streaks-CWyq8Px5.d.ts +71 -0
- package/dist/submission-input-BZkm6ohU.d.ts +290 -0
- package/dist/units-CwgsPB_r.d.ts +9 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -0
- package/dist/wallet-YssWxGg8.d.ts +228 -0
- package/package.json +24 -5
- package/dist/chunk-4KNTMNXA.js +0 -1847
- package/dist/chunk-B76BAJ25.js +0 -624
- package/dist/chunk-NKGJEYZM.js +0 -1833
- package/dist/chunk-ONDBQSMU.js +0 -373
- package/dist/submission-input-JDwq3EVK.d.ts +0 -4986
|
@@ -0,0 +1,1659 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectionPassSchema,
|
|
3
|
+
participantActivityQuerySchema,
|
|
4
|
+
participantActivitySchema,
|
|
5
|
+
participantDeliveriesSchema,
|
|
6
|
+
participantEntitlementsSchema,
|
|
7
|
+
questClaimInputSchema,
|
|
8
|
+
questEnrollmentInputSchema,
|
|
9
|
+
questEnrollmentSchema,
|
|
10
|
+
questExperienceSchema,
|
|
11
|
+
questOutcomePageSchema,
|
|
12
|
+
questOutcomeQuerySchema,
|
|
13
|
+
questOutcomeSchema,
|
|
14
|
+
rewardDeliveriesSchema
|
|
15
|
+
} from "./chunk-EYH5RDIE.js";
|
|
16
|
+
import {
|
|
17
|
+
AVATAR_UPLOAD_LIMIT,
|
|
18
|
+
RelayError,
|
|
19
|
+
RelayErrorCode,
|
|
20
|
+
avatarUploadTypes,
|
|
21
|
+
clientError,
|
|
22
|
+
engagementBoundaryPageSchema,
|
|
23
|
+
engagementPageQuerySchema,
|
|
24
|
+
engagementPageSchema,
|
|
25
|
+
leaderboardDefinitionSchema,
|
|
26
|
+
leaderboardPageSchema,
|
|
27
|
+
leaderboardPlacementSchema,
|
|
28
|
+
leaderboardQuerySchema,
|
|
29
|
+
linkedWalletSchema,
|
|
30
|
+
offerSchema,
|
|
31
|
+
ownProfileSchema,
|
|
32
|
+
parseInput,
|
|
33
|
+
pointBalancesSchema,
|
|
34
|
+
pointHistoryPageSchema,
|
|
35
|
+
pointHistoryQuerySchema,
|
|
36
|
+
pointLedgerReferenceSchema,
|
|
37
|
+
profileCompletionPageSchema,
|
|
38
|
+
profileCompletionQuerySchema,
|
|
39
|
+
profileReferralSchema,
|
|
40
|
+
profileSummarySchema,
|
|
41
|
+
profileUpdateSchema,
|
|
42
|
+
redemptionSchema,
|
|
43
|
+
referralAcceptSchema,
|
|
44
|
+
referralDefinitionSchema,
|
|
45
|
+
referralHistorySchema,
|
|
46
|
+
referralSummarySchema,
|
|
47
|
+
walletAddressInput,
|
|
48
|
+
walletAddressInputSchema,
|
|
49
|
+
walletMessageChallengeSchema,
|
|
50
|
+
walletSignInNetworksSchema,
|
|
51
|
+
walletSignatureSchema,
|
|
52
|
+
walletUnlinkInputSchema
|
|
53
|
+
} from "./chunk-36HTX2BM.js";
|
|
54
|
+
import {
|
|
55
|
+
PARTICIPANT_TIMEOUT,
|
|
56
|
+
lifetime,
|
|
57
|
+
retryAfter,
|
|
58
|
+
retrying,
|
|
59
|
+
validTimeout
|
|
60
|
+
} from "./chunk-6QJ3LADK.js";
|
|
61
|
+
import {
|
|
62
|
+
exchangeResultSchema,
|
|
63
|
+
exchangeSchema,
|
|
64
|
+
memberSummarySchema,
|
|
65
|
+
participantSessionSchema,
|
|
66
|
+
sessionMember
|
|
67
|
+
} from "./chunk-XFMSUPNS.js";
|
|
68
|
+
import {
|
|
69
|
+
accountConnectionSchema,
|
|
70
|
+
attemptSchema,
|
|
71
|
+
authProviderSchema,
|
|
72
|
+
campaignEnrollmentInputSchema,
|
|
73
|
+
campaignEnrollmentSchema,
|
|
74
|
+
campaignWithdrawalInputSchema,
|
|
75
|
+
contentPerformancePageSchema,
|
|
76
|
+
contentPerformanceQuerySchema,
|
|
77
|
+
contentQualificationPageSchema,
|
|
78
|
+
contentQualificationQuerySchema,
|
|
79
|
+
evidenceSchema,
|
|
80
|
+
identifier,
|
|
81
|
+
memberProgressSchema,
|
|
82
|
+
missingPrerequisiteSchema,
|
|
83
|
+
pageQuerySchema,
|
|
84
|
+
quizEvidenceSchema,
|
|
85
|
+
submissionEvidenceSchema,
|
|
86
|
+
submitSchema,
|
|
87
|
+
tieredRewardReferenceSchema,
|
|
88
|
+
validateSubmissionValue,
|
|
89
|
+
valueEvidenceSchema
|
|
90
|
+
} from "./chunk-JON5SESL.js";
|
|
91
|
+
|
|
92
|
+
// src/submissions.ts
|
|
93
|
+
import { z } from "zod";
|
|
94
|
+
var common = {
|
|
95
|
+
id: identifier,
|
|
96
|
+
quest: identifier,
|
|
97
|
+
release: identifier.optional()
|
|
98
|
+
};
|
|
99
|
+
var claimInputSchema = z.union([
|
|
100
|
+
submissionEvidenceSchema,
|
|
101
|
+
z.object({ kind: z.literal("none") }).strict()
|
|
102
|
+
]);
|
|
103
|
+
var draftSchema = z.union([
|
|
104
|
+
claimInputSchema,
|
|
105
|
+
z.object({ kind: z.literal("photo"), file: z.instanceof(Blob) })
|
|
106
|
+
]);
|
|
107
|
+
var recordSchema = z.union([
|
|
108
|
+
z.object({
|
|
109
|
+
...common,
|
|
110
|
+
stage: z.literal("review"),
|
|
111
|
+
draft: draftSchema.nullable()
|
|
112
|
+
}),
|
|
113
|
+
z.object({ ...common, stage: z.literal("upload"), file: z.instanceof(Blob) }),
|
|
114
|
+
z.object({
|
|
115
|
+
...common,
|
|
116
|
+
stage: z.literal("claim"),
|
|
117
|
+
evidence: identifier,
|
|
118
|
+
file: z.instanceof(Blob).optional()
|
|
119
|
+
}),
|
|
120
|
+
z.object({
|
|
121
|
+
...common,
|
|
122
|
+
stage: z.literal("submitted"),
|
|
123
|
+
evidence: identifier,
|
|
124
|
+
attempt: identifier
|
|
125
|
+
}),
|
|
126
|
+
z.object({ ...common, stage: z.literal("claim"), input: claimInputSchema }),
|
|
127
|
+
z.object({
|
|
128
|
+
...common,
|
|
129
|
+
stage: z.literal("submitted"),
|
|
130
|
+
input: claimInputSchema,
|
|
131
|
+
attempt: identifier
|
|
132
|
+
})
|
|
133
|
+
]);
|
|
134
|
+
function submissions(transport, configuredStore, namespace) {
|
|
135
|
+
async function open(quest, options = {
|
|
136
|
+
input: "photo"
|
|
137
|
+
}) {
|
|
138
|
+
if (!configuredStore) {
|
|
139
|
+
throw clientError(
|
|
140
|
+
"Submissions require durable storage. Use createBrowserRelayClient or provide a SubmissionStore.",
|
|
141
|
+
RelayErrorCode.SubmissionStorage
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const store = configuredStore;
|
|
145
|
+
parseInput(identifier, quest);
|
|
146
|
+
const session = await transport.session();
|
|
147
|
+
const member = sessionMember(session);
|
|
148
|
+
if (!session || !member) {
|
|
149
|
+
throw clientError(
|
|
150
|
+
"Sign in to submit an activity",
|
|
151
|
+
RelayErrorCode.NotSignedIn
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
const sessionId = session.id;
|
|
155
|
+
const key = JSON.stringify([
|
|
156
|
+
"relay-submission-v1",
|
|
157
|
+
namespace,
|
|
158
|
+
session.organization,
|
|
159
|
+
session.environment,
|
|
160
|
+
session.project,
|
|
161
|
+
member,
|
|
162
|
+
quest
|
|
163
|
+
]);
|
|
164
|
+
async function currentSession() {
|
|
165
|
+
const current = await transport.session();
|
|
166
|
+
if (current?.id !== sessionId) {
|
|
167
|
+
throw clientError(
|
|
168
|
+
"Your session changed. Reopen the submission before continuing.",
|
|
169
|
+
RelayErrorCode.StaleSession
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function read() {
|
|
174
|
+
const saved = await store.read(key);
|
|
175
|
+
if (saved === void 0 || saved === null) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const parsed = recordSchema.safeParse(saved);
|
|
179
|
+
if (!parsed.success || parsed.data.quest !== quest) {
|
|
180
|
+
throw clientError(
|
|
181
|
+
"Saved submission could not be read. Do not create another claim until it is recovered.",
|
|
182
|
+
RelayErrorCode.SubmissionStorage
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const record = parsed.data;
|
|
186
|
+
const input = record.stage === "review" ? record.draft?.kind : "input" in record ? record.input.kind : "photo";
|
|
187
|
+
if (!options.recoverPrevious && input !== options.input) {
|
|
188
|
+
throw clientError(
|
|
189
|
+
"Saved submission uses a different input type. Reopen it with its original type to recover it.",
|
|
190
|
+
RelayErrorCode.SubmissionConflict
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return record;
|
|
194
|
+
}
|
|
195
|
+
function claim(record) {
|
|
196
|
+
return transport.claim(
|
|
197
|
+
{
|
|
198
|
+
quest,
|
|
199
|
+
actionId: record.id,
|
|
200
|
+
...record.release ? { release: record.release } : {},
|
|
201
|
+
..."evidence" in record ? { evidence: record.evidence } : record.input.kind !== "none" ? { input: record.input } : {}
|
|
202
|
+
},
|
|
203
|
+
sessionId
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
async function resumeRecord(saved) {
|
|
207
|
+
if (saved.stage === "review") {
|
|
208
|
+
throw new QuestUpdatedError(
|
|
209
|
+
"This quest changed. Review it before submitting again.",
|
|
210
|
+
"quest-updated",
|
|
211
|
+
saved.draft
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
let record = saved;
|
|
215
|
+
if (record.stage === "upload") {
|
|
216
|
+
const evidence = await transport.upload(
|
|
217
|
+
record.file,
|
|
218
|
+
record.id,
|
|
219
|
+
sessionId
|
|
220
|
+
);
|
|
221
|
+
record = {
|
|
222
|
+
id: record.id,
|
|
223
|
+
quest,
|
|
224
|
+
...record.release ? { release: record.release } : {},
|
|
225
|
+
file: record.file,
|
|
226
|
+
stage: "claim",
|
|
227
|
+
evidence: evidence.id
|
|
228
|
+
};
|
|
229
|
+
await store.write(key, record);
|
|
230
|
+
}
|
|
231
|
+
let attempt;
|
|
232
|
+
try {
|
|
233
|
+
attempt = await claim(record);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (error instanceof RelayError && error.status === 422 && error.code === "invalid-submission" && record.stage === "claim") {
|
|
236
|
+
await store.write(key, null);
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
const changed = !(error instanceof RelayError) || error.status !== 409 ? null : error.code === "quest-updated" ? "quest-updated" : error.code === "stale-quiz" ? "stale-quiz" : null;
|
|
240
|
+
if (changed && error instanceof RelayError && record.stage === "claim") {
|
|
241
|
+
const draft = "input" in record ? record.input : "file" in record && record.file ? { kind: "photo", file: record.file } : null;
|
|
242
|
+
await store.write(
|
|
243
|
+
key,
|
|
244
|
+
changed === "quest-updated" ? {
|
|
245
|
+
id: record.id,
|
|
246
|
+
quest,
|
|
247
|
+
release: record.release,
|
|
248
|
+
stage: "review",
|
|
249
|
+
draft
|
|
250
|
+
} : null
|
|
251
|
+
);
|
|
252
|
+
throw new QuestUpdatedError(error.message, changed, draft, error);
|
|
253
|
+
}
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
await store.write(key, {
|
|
257
|
+
...record,
|
|
258
|
+
stage: "submitted",
|
|
259
|
+
attempt: attempt.id
|
|
260
|
+
});
|
|
261
|
+
if (attempt.status === "failed") {
|
|
262
|
+
attempt = await transport.retry(attempt.id, sessionId);
|
|
263
|
+
}
|
|
264
|
+
return attempt;
|
|
265
|
+
}
|
|
266
|
+
async function submit(record) {
|
|
267
|
+
return store.exclusive(key, async () => {
|
|
268
|
+
await currentSession();
|
|
269
|
+
const existing = await read();
|
|
270
|
+
if (existing?.stage === "review" && existing.release === record.release) {
|
|
271
|
+
throw new QuestUpdatedError(
|
|
272
|
+
"Review the latest quest before submitting again.",
|
|
273
|
+
"quest-updated",
|
|
274
|
+
existing.draft
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
if (existing && existing.stage !== "submitted" && existing.stage !== "review") {
|
|
278
|
+
throw clientError(
|
|
279
|
+
"A submission is unfinished. Resume it before choosing new input.",
|
|
280
|
+
RelayErrorCode.SubmissionConflict
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
if (existing?.stage === "submitted") {
|
|
284
|
+
const previous = await claim(existing);
|
|
285
|
+
if (previous.status === "failed") {
|
|
286
|
+
return transport.retry(previous.id, sessionId);
|
|
287
|
+
}
|
|
288
|
+
if (previous.status !== "rejected" && !(options.repeatable && previous.status === "accepted")) {
|
|
289
|
+
return previous;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
await store.write(key, record);
|
|
293
|
+
return resumeRecord(record);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const handle = {
|
|
297
|
+
async discard() {
|
|
298
|
+
return store.exclusive(key, async () => {
|
|
299
|
+
await currentSession();
|
|
300
|
+
const record = await read();
|
|
301
|
+
if (!record) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (record.stage !== "submitted") {
|
|
305
|
+
throw clientError(
|
|
306
|
+
"Resume the unfinished submission before starting over.",
|
|
307
|
+
RelayErrorCode.SubmissionConflict
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
const attempt = await claim(record);
|
|
311
|
+
if (attempt.status !== "failed" && attempt.status !== "rejected" && !(options.repeatable && attempt.status === "accepted")) {
|
|
312
|
+
throw clientError(
|
|
313
|
+
"Only a failed or rejected submission can be discarded.",
|
|
314
|
+
RelayErrorCode.SubmissionConflict
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
await store.write(key, null);
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
async status() {
|
|
321
|
+
await currentSession();
|
|
322
|
+
const record = await read();
|
|
323
|
+
if (!record) {
|
|
324
|
+
return { kind: "empty" };
|
|
325
|
+
}
|
|
326
|
+
if (record.stage === "review") {
|
|
327
|
+
return { kind: "needs-review" };
|
|
328
|
+
}
|
|
329
|
+
return record.stage === "submitted" ? { kind: "submitted", attempt: record.attempt } : { kind: "pending", stage: record.stage };
|
|
330
|
+
},
|
|
331
|
+
async resume() {
|
|
332
|
+
return store.exclusive(key, async () => {
|
|
333
|
+
await currentSession();
|
|
334
|
+
const record = await read();
|
|
335
|
+
if (!record) {
|
|
336
|
+
throw clientError(
|
|
337
|
+
"There is no saved submission to resume",
|
|
338
|
+
RelayErrorCode.SubmissionConflict
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
return resumeRecord(record);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
if (options.input === "text" || options.input === "url") {
|
|
346
|
+
const kind = options.input;
|
|
347
|
+
return {
|
|
348
|
+
...handle,
|
|
349
|
+
submit(value) {
|
|
350
|
+
const input = parseInput(valueEvidenceSchema, { kind, value });
|
|
351
|
+
return submit({
|
|
352
|
+
id: crypto.randomUUID(),
|
|
353
|
+
quest,
|
|
354
|
+
release: options.release,
|
|
355
|
+
stage: "claim",
|
|
356
|
+
input
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
if (options.input === "quiz") {
|
|
362
|
+
return {
|
|
363
|
+
...handle,
|
|
364
|
+
submit(answers, version) {
|
|
365
|
+
const input = parseInput(quizEvidenceSchema, {
|
|
366
|
+
kind: "quiz",
|
|
367
|
+
answers,
|
|
368
|
+
...version || options.release ? { release: version?.release ?? options.release } : {}
|
|
369
|
+
});
|
|
370
|
+
return submit({
|
|
371
|
+
id: crypto.randomUUID(),
|
|
372
|
+
...options.release ? { release: options.release } : {},
|
|
373
|
+
quest,
|
|
374
|
+
stage: "claim",
|
|
375
|
+
input
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
if (options.input === "none") {
|
|
381
|
+
return {
|
|
382
|
+
...handle,
|
|
383
|
+
submit() {
|
|
384
|
+
return submit({
|
|
385
|
+
id: crypto.randomUUID(),
|
|
386
|
+
...options.release ? { release: options.release } : {},
|
|
387
|
+
quest,
|
|
388
|
+
stage: "claim",
|
|
389
|
+
input: { kind: "none" }
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return {
|
|
395
|
+
...handle,
|
|
396
|
+
async submit(file) {
|
|
397
|
+
if (!["image/jpeg", "image/png"].includes(file.type) || file.size === 0 || file.size > 5 * 1024 * 1024) {
|
|
398
|
+
throw clientError(
|
|
399
|
+
"Choose a JPG or PNG photo under 5 MB",
|
|
400
|
+
RelayErrorCode.InvalidInput
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
const bytes = new Uint8Array(await file.slice(0, 4).arrayBuffer());
|
|
404
|
+
const signature = file.type === "image/png" ? [137, 80, 78, 71] : [255, 216, 255];
|
|
405
|
+
if (!signature.every((byte, index) => bytes[index] === byte)) {
|
|
406
|
+
throw clientError(
|
|
407
|
+
"Image content does not match its file type",
|
|
408
|
+
RelayErrorCode.InvalidInput
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
return submit({
|
|
412
|
+
id: crypto.randomUUID(),
|
|
413
|
+
...options.release ? { release: options.release } : {},
|
|
414
|
+
quest,
|
|
415
|
+
stage: "upload",
|
|
416
|
+
file
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return open;
|
|
422
|
+
}
|
|
423
|
+
var QuestUpdatedError = class extends RelayError {
|
|
424
|
+
constructor(message, code, draft, source) {
|
|
425
|
+
super(message, {
|
|
426
|
+
kind: source?.kind ?? "client",
|
|
427
|
+
status: source?.status,
|
|
428
|
+
code,
|
|
429
|
+
operationId: source?.operationId,
|
|
430
|
+
cause: source
|
|
431
|
+
});
|
|
432
|
+
this.draft = draft;
|
|
433
|
+
}
|
|
434
|
+
draft;
|
|
435
|
+
name = "QuestUpdatedError";
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/client.ts
|
|
439
|
+
import { z as z2 } from "zod";
|
|
440
|
+
|
|
441
|
+
// src/progress.ts
|
|
442
|
+
function observeProgress(transport, listener, options = {}, onDispose = () => {
|
|
443
|
+
}) {
|
|
444
|
+
const interval = options.intervalMs ?? 1500;
|
|
445
|
+
const maximum = options.maxBackoffMs ?? 3e4;
|
|
446
|
+
if (!Number.isFinite(interval) || interval <= 0 || !Number.isFinite(maximum) || maximum < interval) {
|
|
447
|
+
throw clientError(
|
|
448
|
+
"Progress polling requires a positive interval and a maximum at least as large",
|
|
449
|
+
RelayErrorCode.InvalidInput
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
let disposed = false;
|
|
453
|
+
let controller;
|
|
454
|
+
let timer;
|
|
455
|
+
let sessionId;
|
|
456
|
+
let failures = 0;
|
|
457
|
+
const visible = () => typeof document === "undefined" || document.visibilityState !== "hidden";
|
|
458
|
+
const visibility = () => {
|
|
459
|
+
if (visible()) {
|
|
460
|
+
void refresh();
|
|
461
|
+
} else {
|
|
462
|
+
controller?.abort();
|
|
463
|
+
if (timer !== void 0) {
|
|
464
|
+
clearTimeout(timer);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
if (typeof document !== "undefined") {
|
|
469
|
+
document.addEventListener("visibilitychange", visibility);
|
|
470
|
+
}
|
|
471
|
+
function clear() {
|
|
472
|
+
controller?.abort();
|
|
473
|
+
if (timer !== void 0) {
|
|
474
|
+
clearTimeout(timer);
|
|
475
|
+
}
|
|
476
|
+
sessionId = void 0;
|
|
477
|
+
if (!disposed) {
|
|
478
|
+
listener({ kind: "loading" });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
async function refresh() {
|
|
482
|
+
if (disposed || !visible()) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
controller?.abort();
|
|
486
|
+
if (timer !== void 0) {
|
|
487
|
+
clearTimeout(timer);
|
|
488
|
+
}
|
|
489
|
+
const request = new AbortController();
|
|
490
|
+
controller = request;
|
|
491
|
+
const current = () => !disposed && !request.signal.aborted;
|
|
492
|
+
try {
|
|
493
|
+
const session = await transport.session(request.signal);
|
|
494
|
+
if (!current()) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (sessionId !== (session?.id ?? null)) {
|
|
498
|
+
sessionId = session?.id ?? null;
|
|
499
|
+
listener({ kind: "session", session });
|
|
500
|
+
}
|
|
501
|
+
const member = sessionMember(session);
|
|
502
|
+
if (session && member) {
|
|
503
|
+
const progress = await transport.progress(session.id, request.signal);
|
|
504
|
+
if (!current()) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
const confirmed = await transport.session(request.signal);
|
|
508
|
+
if (!current()) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (confirmed?.id !== session.id || progress.member !== member) {
|
|
512
|
+
sessionId = void 0;
|
|
513
|
+
listener({ kind: "loading" });
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
listener({ kind: "ready", session: confirmed, progress });
|
|
517
|
+
}
|
|
518
|
+
failures = 0;
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (!current()) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
failures = Math.min(failures + 1, 20);
|
|
524
|
+
sessionId = void 0;
|
|
525
|
+
listener({
|
|
526
|
+
kind: "error",
|
|
527
|
+
error: error instanceof Error ? error : new Error("Could not refresh progress")
|
|
528
|
+
});
|
|
529
|
+
} finally {
|
|
530
|
+
if (current()) {
|
|
531
|
+
timer = setTimeout(
|
|
532
|
+
() => void refresh(),
|
|
533
|
+
Math.min(maximum, interval * 2 ** failures)
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const observer = {
|
|
539
|
+
refresh,
|
|
540
|
+
clear,
|
|
541
|
+
dispose() {
|
|
542
|
+
if (disposed) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
disposed = true;
|
|
546
|
+
if (typeof document !== "undefined") {
|
|
547
|
+
document.removeEventListener("visibilitychange", visibility);
|
|
548
|
+
}
|
|
549
|
+
controller?.abort();
|
|
550
|
+
if (timer !== void 0) {
|
|
551
|
+
clearTimeout(timer);
|
|
552
|
+
}
|
|
553
|
+
onDispose();
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
return observer;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// src/quest-experience.ts
|
|
560
|
+
function reconcileQuestDraft(view, draft) {
|
|
561
|
+
if (!draft) {
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
if (draft.kind === "text" || draft.kind === "url") {
|
|
565
|
+
return view.interaction === draft.kind ? draft : null;
|
|
566
|
+
}
|
|
567
|
+
if (draft.kind === "photo") {
|
|
568
|
+
return view.interaction === "photo" ? draft : null;
|
|
569
|
+
}
|
|
570
|
+
if (draft.kind === "none") {
|
|
571
|
+
return view.interaction === "claim" ? draft : null;
|
|
572
|
+
}
|
|
573
|
+
if (view.interaction !== "quiz") {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const answers = Object.fromEntries(
|
|
577
|
+
(view.presentation.quiz ?? []).flatMap((q) => {
|
|
578
|
+
const answer = draft.answers[q.id];
|
|
579
|
+
return q.choices.some((c) => c.id === answer) ? [[q.id, answer]] : [];
|
|
580
|
+
})
|
|
581
|
+
);
|
|
582
|
+
return { kind: "quiz", release: view.release, answers };
|
|
583
|
+
}
|
|
584
|
+
function questActions(submission, latest) {
|
|
585
|
+
return async (view) => {
|
|
586
|
+
async function run(task) {
|
|
587
|
+
try {
|
|
588
|
+
return { kind: "submitted", attempt: await task() };
|
|
589
|
+
} catch (error) {
|
|
590
|
+
if (!(error instanceof QuestUpdatedError)) {
|
|
591
|
+
throw error;
|
|
592
|
+
}
|
|
593
|
+
const current = await latest(view.quest).catch(() => {
|
|
594
|
+
throw error;
|
|
595
|
+
});
|
|
596
|
+
return {
|
|
597
|
+
kind: "quest-updated",
|
|
598
|
+
latest: current,
|
|
599
|
+
originalDraft: error.draft,
|
|
600
|
+
draft: reconcileQuestDraft(current, error.draft)
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
if (view.lifecycle !== "active" || view.interaction === "staff" || view.interaction === "automatic") {
|
|
605
|
+
const handle = await submission(view.quest, {
|
|
606
|
+
input: "none",
|
|
607
|
+
release: view.release,
|
|
608
|
+
recoverPrevious: true,
|
|
609
|
+
repeatable: view.completion.kind === "keyed" || view.completion.kind === "progress"
|
|
610
|
+
});
|
|
611
|
+
return {
|
|
612
|
+
kind: "status",
|
|
613
|
+
view,
|
|
614
|
+
status: handle.status,
|
|
615
|
+
discard: handle.discard,
|
|
616
|
+
resume: () => run(handle.resume)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
switch (view.interaction) {
|
|
620
|
+
case "text":
|
|
621
|
+
case "url": {
|
|
622
|
+
const kind = view.interaction;
|
|
623
|
+
const handle = await submission(view.quest, {
|
|
624
|
+
input: kind,
|
|
625
|
+
release: view.release,
|
|
626
|
+
recoverPrevious: true,
|
|
627
|
+
repeatable: view.completion.kind === "keyed" || view.completion.kind === "progress"
|
|
628
|
+
});
|
|
629
|
+
return {
|
|
630
|
+
kind,
|
|
631
|
+
view,
|
|
632
|
+
status: handle.status,
|
|
633
|
+
discard: handle.discard,
|
|
634
|
+
resume: () => run(handle.resume),
|
|
635
|
+
submit: (value) => run(() => {
|
|
636
|
+
if (view.trigger.kind !== "manual" || view.trigger.input !== "text" && view.trigger.input !== "url") {
|
|
637
|
+
throw clientError(
|
|
638
|
+
"Quest input changed",
|
|
639
|
+
RelayErrorCode.QuestUpdated
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
const problem = validateSubmissionValue(
|
|
643
|
+
{ kind, value },
|
|
644
|
+
view.trigger
|
|
645
|
+
);
|
|
646
|
+
if (problem) {
|
|
647
|
+
throw clientError(problem, RelayErrorCode.InvalidInput);
|
|
648
|
+
}
|
|
649
|
+
return handle.submit(value);
|
|
650
|
+
})
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
case "photo": {
|
|
654
|
+
const handle = await submission(view.quest, {
|
|
655
|
+
input: "photo",
|
|
656
|
+
release: view.release,
|
|
657
|
+
recoverPrevious: true,
|
|
658
|
+
repeatable: view.completion.kind === "keyed" || view.completion.kind === "progress"
|
|
659
|
+
});
|
|
660
|
+
return {
|
|
661
|
+
kind: "photo",
|
|
662
|
+
view,
|
|
663
|
+
status: handle.status,
|
|
664
|
+
discard: handle.discard,
|
|
665
|
+
resume: () => run(handle.resume),
|
|
666
|
+
submit: (file) => run(() => handle.submit(file))
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
case "quiz": {
|
|
670
|
+
const handle = await submission(view.quest, {
|
|
671
|
+
input: "quiz",
|
|
672
|
+
release: view.release,
|
|
673
|
+
recoverPrevious: true,
|
|
674
|
+
repeatable: view.completion.kind === "keyed" || view.completion.kind === "progress"
|
|
675
|
+
});
|
|
676
|
+
return {
|
|
677
|
+
kind: "quiz",
|
|
678
|
+
view,
|
|
679
|
+
status: handle.status,
|
|
680
|
+
discard: handle.discard,
|
|
681
|
+
resume: () => run(handle.resume),
|
|
682
|
+
submit: (answers) => run(() => handle.submit(answers, { release: view.release }))
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
case "claim": {
|
|
686
|
+
const handle = await submission(view.quest, {
|
|
687
|
+
input: "none",
|
|
688
|
+
release: view.release,
|
|
689
|
+
recoverPrevious: true,
|
|
690
|
+
repeatable: view.completion.kind === "keyed" || view.completion.kind === "progress"
|
|
691
|
+
});
|
|
692
|
+
return {
|
|
693
|
+
kind: "claim",
|
|
694
|
+
view,
|
|
695
|
+
status: handle.status,
|
|
696
|
+
discard: handle.discard,
|
|
697
|
+
resume: () => run(handle.resume),
|
|
698
|
+
submit: () => run(handle.submit)
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/client.ts
|
|
706
|
+
function errorBody(value) {
|
|
707
|
+
const body = value !== null && typeof value === "object" ? value : {};
|
|
708
|
+
return {
|
|
709
|
+
message: typeof body.error === "string" && body.error.trim() ? body.error : void 0,
|
|
710
|
+
code: typeof body.code === "string" && body.code.trim() ? body.code : void 0,
|
|
711
|
+
missing: Array.isArray(body.missing) ? body.missing.flatMap((entry) => {
|
|
712
|
+
const parsed = missingPrerequisiteSchema.safeParse(entry);
|
|
713
|
+
return parsed.success ? [parsed.data] : [];
|
|
714
|
+
}) : []
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
async function fromSigner(step, signal) {
|
|
718
|
+
let stop;
|
|
719
|
+
try {
|
|
720
|
+
return await new Promise((resolve, reject) => {
|
|
721
|
+
stop = () => reject(
|
|
722
|
+
new RelayError("The request was cancelled", {
|
|
723
|
+
kind: "aborted",
|
|
724
|
+
code: RelayErrorCode.Aborted,
|
|
725
|
+
cause: signal?.reason
|
|
726
|
+
})
|
|
727
|
+
);
|
|
728
|
+
if (signal?.aborted) {
|
|
729
|
+
stop();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
733
|
+
step().then(resolve, reject);
|
|
734
|
+
});
|
|
735
|
+
} catch (error) {
|
|
736
|
+
if (error instanceof RelayError) {
|
|
737
|
+
throw error;
|
|
738
|
+
}
|
|
739
|
+
throw clientError(
|
|
740
|
+
error instanceof Error && error.message ? error.message : "The wallet did not complete the request",
|
|
741
|
+
RelayErrorCode.WalletSigner,
|
|
742
|
+
{ cause: error }
|
|
743
|
+
);
|
|
744
|
+
} finally {
|
|
745
|
+
if (stop) {
|
|
746
|
+
signal?.removeEventListener("abort", stop);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
var invalidTimeout = () => clientError(
|
|
751
|
+
"timeout must be a positive, finite number of milliseconds",
|
|
752
|
+
RelayErrorCode.InvalidInput
|
|
753
|
+
);
|
|
754
|
+
var uncertainStatuses = /* @__PURE__ */ new Set([500, 502, 504]);
|
|
755
|
+
var methodOf = (call) => call.method ?? (call.json === void 0 ? "GET" : "POST");
|
|
756
|
+
function withQuery(path, values) {
|
|
757
|
+
const params = new URLSearchParams();
|
|
758
|
+
for (const [key, value] of Object.entries(values)) {
|
|
759
|
+
if (value !== void 0) {
|
|
760
|
+
params.set(key, String(value));
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const search = params.toString();
|
|
764
|
+
return search ? path + "?" + search : path;
|
|
765
|
+
}
|
|
766
|
+
function interrupted(call, life, error, stage) {
|
|
767
|
+
const details = {
|
|
768
|
+
status: stage.status,
|
|
769
|
+
retryAfter: stage.headers ? retryAfter(stage.headers) : void 0,
|
|
770
|
+
operationId: call.operationId,
|
|
771
|
+
replaySafe: call.replaySafe,
|
|
772
|
+
uncertain: stage.sent && methodOf(call) !== "GET" && // An error status whose body broke off still refused the write, unless the status itself
|
|
773
|
+
// does not prove that (500, 502, 504).
|
|
774
|
+
(!stage.refused || uncertainStatuses.has(stage.status ?? 0)),
|
|
775
|
+
cause: error
|
|
776
|
+
};
|
|
777
|
+
const ended = life.ended();
|
|
778
|
+
if (ended === "aborted") {
|
|
779
|
+
return new RelayError("The request was cancelled", {
|
|
780
|
+
...details,
|
|
781
|
+
kind: "aborted",
|
|
782
|
+
code: RelayErrorCode.Aborted
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
if (ended === "timeout") {
|
|
786
|
+
return new RelayError(`Relay did not respond within ${life.timeout} ms`, {
|
|
787
|
+
...details,
|
|
788
|
+
kind: "timeout",
|
|
789
|
+
code: RelayErrorCode.Timeout
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return new RelayError(
|
|
793
|
+
stage.status === void 0 ? "Could not reach Relay" : "Relay's response was cut off",
|
|
794
|
+
{ ...details, kind: "network", code: RelayErrorCode.Network }
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
function createRelayClient(options) {
|
|
798
|
+
if (options.timeout !== void 0 && !validTimeout(options.timeout)) {
|
|
799
|
+
throw invalidTimeout();
|
|
800
|
+
}
|
|
801
|
+
const clientTimeout = options.timeout ?? PARTICIPANT_TIMEOUT;
|
|
802
|
+
async function send(path, call, life) {
|
|
803
|
+
const method = methodOf(call);
|
|
804
|
+
const headers = new Headers(call.headers);
|
|
805
|
+
let body2 = call.body;
|
|
806
|
+
if (options.token) {
|
|
807
|
+
headers.set("Authorization", `Bearer ${options.token}`);
|
|
808
|
+
}
|
|
809
|
+
if (options.organization) {
|
|
810
|
+
headers.set("X-Relay-Organization", options.organization);
|
|
811
|
+
}
|
|
812
|
+
if (options.project) {
|
|
813
|
+
headers.set("X-Relay-Project", options.project);
|
|
814
|
+
}
|
|
815
|
+
if (options.environment) {
|
|
816
|
+
headers.set("X-Relay-Environment", options.environment);
|
|
817
|
+
}
|
|
818
|
+
if (call.options?.session) {
|
|
819
|
+
headers.set("X-Relay-Session", call.options.session);
|
|
820
|
+
}
|
|
821
|
+
if (call.json !== void 0) {
|
|
822
|
+
headers.set("Content-Type", "application/json");
|
|
823
|
+
body2 = JSON.stringify(call.json);
|
|
824
|
+
}
|
|
825
|
+
if (method !== "GET") {
|
|
826
|
+
headers.set("X-Relay-CSRF", "1");
|
|
827
|
+
}
|
|
828
|
+
if (life.signal.aborted) {
|
|
829
|
+
throw interrupted(call, life, life.reason(), { sent: false });
|
|
830
|
+
}
|
|
831
|
+
let response;
|
|
832
|
+
try {
|
|
833
|
+
response = await fetch(options.baseUrl + path, {
|
|
834
|
+
method,
|
|
835
|
+
headers,
|
|
836
|
+
body: body2,
|
|
837
|
+
signal: life.signal
|
|
838
|
+
});
|
|
839
|
+
} catch (error) {
|
|
840
|
+
throw interrupted(call, life, error, { sent: true });
|
|
841
|
+
}
|
|
842
|
+
if (!response.ok) {
|
|
843
|
+
let text;
|
|
844
|
+
try {
|
|
845
|
+
text = await response.text();
|
|
846
|
+
} catch (error) {
|
|
847
|
+
throw interrupted(call, life, error, {
|
|
848
|
+
sent: true,
|
|
849
|
+
status: response.status,
|
|
850
|
+
headers: response.headers,
|
|
851
|
+
refused: true
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
let value = null;
|
|
855
|
+
try {
|
|
856
|
+
value = JSON.parse(text);
|
|
857
|
+
} catch {
|
|
858
|
+
}
|
|
859
|
+
const { message, code, missing } = errorBody(value);
|
|
860
|
+
throw new RelayError(message ?? `Request failed (${response.status})`, {
|
|
861
|
+
kind: "http",
|
|
862
|
+
status: response.status,
|
|
863
|
+
code,
|
|
864
|
+
missing,
|
|
865
|
+
operationId: call.operationId,
|
|
866
|
+
replaySafe: call.replaySafe,
|
|
867
|
+
uncertain: methodOf(call) !== "GET" && uncertainStatuses.has(response.status),
|
|
868
|
+
retryAfter: retryAfter(response.headers)
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
return response;
|
|
872
|
+
}
|
|
873
|
+
async function exchange(path, call, receive) {
|
|
874
|
+
const timeout = call.options?.timeout ?? clientTimeout;
|
|
875
|
+
if (!validTimeout(timeout)) {
|
|
876
|
+
throw invalidTimeout();
|
|
877
|
+
}
|
|
878
|
+
const life = lifetime(timeout, call.options?.signal);
|
|
879
|
+
try {
|
|
880
|
+
return await retrying(
|
|
881
|
+
life,
|
|
882
|
+
{
|
|
883
|
+
replaySafe: methodOf(call) === "GET" || (call.replaySafe ?? call.operationId !== void 0)
|
|
884
|
+
},
|
|
885
|
+
async () => receive(await send(path, call, life), life)
|
|
886
|
+
);
|
|
887
|
+
} finally {
|
|
888
|
+
life.end();
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
async function body(response, call, life, reader) {
|
|
892
|
+
try {
|
|
893
|
+
return await reader(response);
|
|
894
|
+
} catch (error) {
|
|
895
|
+
throw interrupted(call, life, error, {
|
|
896
|
+
sent: true,
|
|
897
|
+
status: response.status,
|
|
898
|
+
headers: response.headers
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function invalidResponse(status, call, cause) {
|
|
903
|
+
return new RelayError(
|
|
904
|
+
"Relay sent a response this SDK version cannot read. Update @domino-sdk/relay.",
|
|
905
|
+
{
|
|
906
|
+
kind: "invalid-response",
|
|
907
|
+
code: RelayErrorCode.InvalidResponse,
|
|
908
|
+
status,
|
|
909
|
+
operationId: call.operationId,
|
|
910
|
+
replaySafe: call.replaySafe,
|
|
911
|
+
// Relay accepted the write, but this client cannot tell what it did.
|
|
912
|
+
uncertain: methodOf(call) !== "GET",
|
|
913
|
+
cause
|
|
914
|
+
}
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
async function read(response, schema, call, life) {
|
|
918
|
+
const text = await body(response, call, life, (value2) => value2.text());
|
|
919
|
+
let value;
|
|
920
|
+
try {
|
|
921
|
+
value = JSON.parse(text);
|
|
922
|
+
} catch (error) {
|
|
923
|
+
throw invalidResponse(response.status, call, error);
|
|
924
|
+
}
|
|
925
|
+
const parsed = schema.safeParse(value);
|
|
926
|
+
if (!parsed.success) {
|
|
927
|
+
throw invalidResponse(response.status, call, parsed.error);
|
|
928
|
+
}
|
|
929
|
+
return parsed.data;
|
|
930
|
+
}
|
|
931
|
+
async function request(path, schema, call = {}) {
|
|
932
|
+
return exchange(
|
|
933
|
+
path,
|
|
934
|
+
call,
|
|
935
|
+
(response, life) => read(response, schema, call, life)
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
const unusedChallengeExpires = true;
|
|
939
|
+
async function linkVerify(value, session) {
|
|
940
|
+
const proof = parseInput(walletSignatureSchema, value);
|
|
941
|
+
return request("/v1/me/wallets/verify", linkedWalletSchema, {
|
|
942
|
+
json: proof,
|
|
943
|
+
options: session,
|
|
944
|
+
operationId: proof.challenge
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
const readSession = (requestOptions) => request("/v1/auth/session", participantSessionSchema.nullable(), {
|
|
948
|
+
options: {
|
|
949
|
+
signal: requestOptions?.signal,
|
|
950
|
+
timeout: requestOptions?.timeout
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
async function bound(requestOptions = {}) {
|
|
954
|
+
if (requestOptions.session) {
|
|
955
|
+
return requestOptions;
|
|
956
|
+
}
|
|
957
|
+
const timeout = requestOptions.timeout ?? clientTimeout;
|
|
958
|
+
if (!validTimeout(timeout)) {
|
|
959
|
+
throw invalidTimeout();
|
|
960
|
+
}
|
|
961
|
+
const started = Date.now();
|
|
962
|
+
const session = await readSession({ ...requestOptions, timeout });
|
|
963
|
+
if (session?.principal.kind !== "member") {
|
|
964
|
+
throw clientError("Sign in to continue", RelayErrorCode.NotSignedIn);
|
|
965
|
+
}
|
|
966
|
+
const remaining = timeout - (Date.now() - started);
|
|
967
|
+
if (remaining <= 0) {
|
|
968
|
+
throw new RelayError(`Relay did not respond within ${timeout} ms`, {
|
|
969
|
+
kind: "timeout",
|
|
970
|
+
code: RelayErrorCode.Timeout
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
return { ...requestOptions, session: session.id, timeout: remaining };
|
|
974
|
+
}
|
|
975
|
+
const submission = submissions(
|
|
976
|
+
{
|
|
977
|
+
session: () => readSession(),
|
|
978
|
+
upload: (file, action, session) => request("/v1/me/evidence", evidenceSchema, {
|
|
979
|
+
method: "POST",
|
|
980
|
+
body: file,
|
|
981
|
+
headers: { "Content-Type": file.type, "X-Relay-Upload-ID": action },
|
|
982
|
+
options: { session },
|
|
983
|
+
operationId: action
|
|
984
|
+
}),
|
|
985
|
+
claim: async (claim, session) => request("/v1/me/attempts", attemptSchema, {
|
|
986
|
+
json: claim,
|
|
987
|
+
options: { session },
|
|
988
|
+
operationId: claim.actionId
|
|
989
|
+
}),
|
|
990
|
+
retry: (attempt, session) => request(`/v1/attempts/${attempt}/retry`, attemptSchema, {
|
|
991
|
+
json: {},
|
|
992
|
+
options: { session }
|
|
993
|
+
})
|
|
994
|
+
},
|
|
995
|
+
options.submissionStore,
|
|
996
|
+
options.baseUrl
|
|
997
|
+
);
|
|
998
|
+
const observers = /* @__PURE__ */ new Set();
|
|
999
|
+
async function changeSession(task) {
|
|
1000
|
+
for (const observer of observers) {
|
|
1001
|
+
observer.clear();
|
|
1002
|
+
}
|
|
1003
|
+
try {
|
|
1004
|
+
return await task();
|
|
1005
|
+
} finally {
|
|
1006
|
+
for (const observer of observers) {
|
|
1007
|
+
void observer.refresh();
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
const experience = (requestOptions) => request("/v1/me/experience", questExperienceSchema, {
|
|
1012
|
+
options: requestOptions
|
|
1013
|
+
});
|
|
1014
|
+
async function getQuest(id, requestOptions) {
|
|
1015
|
+
const quest = (await experience(requestOptions)).quests.find(
|
|
1016
|
+
(q) => q.quest === id || q.key === id
|
|
1017
|
+
);
|
|
1018
|
+
if (!quest) {
|
|
1019
|
+
throw clientError("Quest not found", RelayErrorCode.NotFound);
|
|
1020
|
+
}
|
|
1021
|
+
return quest;
|
|
1022
|
+
}
|
|
1023
|
+
const ok = z2.object({ ok: z2.literal(true) });
|
|
1024
|
+
const acknowledged = z2.object({ ok: z2.boolean() });
|
|
1025
|
+
return {
|
|
1026
|
+
offers: {
|
|
1027
|
+
/** Offers available to this participant, including stock and per-member availability. */
|
|
1028
|
+
list: (requestOptions) => request("/v1/offers", z2.array(offerSchema), {
|
|
1029
|
+
options: requestOptions
|
|
1030
|
+
}),
|
|
1031
|
+
/** Redeems one offer. Persist `actionId` to retry after an uncertain result. */
|
|
1032
|
+
redeem: (offer, input = {}, requestOptions) => {
|
|
1033
|
+
const actionId = identifier.parse(input.actionId ?? crypto.randomUUID());
|
|
1034
|
+
return request(
|
|
1035
|
+
`/v1/offers/${identifier.parse(offer)}/redeem`,
|
|
1036
|
+
redemptionSchema,
|
|
1037
|
+
{
|
|
1038
|
+
json: { actionId },
|
|
1039
|
+
options: requestOptions,
|
|
1040
|
+
operationId: actionId
|
|
1041
|
+
}
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
referrals: {
|
|
1046
|
+
list: (requestOptions) => request("/v1/referrals", z2.array(referralDefinitionSchema), {
|
|
1047
|
+
options: requestOptions
|
|
1048
|
+
}),
|
|
1049
|
+
summary: (requestOptions) => request("/v1/referrals/me", referralSummarySchema, {
|
|
1050
|
+
options: requestOptions
|
|
1051
|
+
}),
|
|
1052
|
+
/** The member's referral point history, newest first. */
|
|
1053
|
+
history: async (query = {}, requestOptions) => request(
|
|
1054
|
+
withQuery("/v1/referrals/history", parseInput(pageQuerySchema, query)),
|
|
1055
|
+
referralHistorySchema,
|
|
1056
|
+
{ options: requestOptions }
|
|
1057
|
+
),
|
|
1058
|
+
accept: async (value, requestOptions) => {
|
|
1059
|
+
const body2 = parseInput(referralAcceptSchema, value);
|
|
1060
|
+
return request("/v1/referrals/accept", ok, {
|
|
1061
|
+
json: body2,
|
|
1062
|
+
options: requestOptions,
|
|
1063
|
+
operationId: body2.actionId
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
rewards: {
|
|
1068
|
+
/** The signed-in member's earned rewards, including pickup allocation and collection state. */
|
|
1069
|
+
entitlements: (options2) => request("/v1/me/entitlements", participantEntitlementsSchema, {
|
|
1070
|
+
options: options2
|
|
1071
|
+
}),
|
|
1072
|
+
/** Point awards, current tier entitlements, and integration delivery states. */
|
|
1073
|
+
deliveries: (options2) => request("/v1/me/deliveries", participantDeliveriesSchema, { options: options2 })
|
|
1074
|
+
},
|
|
1075
|
+
tieredRewards: {
|
|
1076
|
+
/**
|
|
1077
|
+
* The project's tiered rewards with their keys. Entitlements and reward
|
|
1078
|
+
* definitions name them by ID: use this to find the ID for a key.
|
|
1079
|
+
*/
|
|
1080
|
+
list: (requestOptions) => request("/v1/tiered-rewards", z2.array(tieredRewardReferenceSchema), {
|
|
1081
|
+
options: requestOptions
|
|
1082
|
+
})
|
|
1083
|
+
},
|
|
1084
|
+
pointLedgers: {
|
|
1085
|
+
/**
|
|
1086
|
+
* The project's point ledgers with their keys and names. Reads return
|
|
1087
|
+
* ledger IDs: use this to find the ID for a key, or a ledger's name.
|
|
1088
|
+
*/
|
|
1089
|
+
list: (requestOptions) => request("/v1/point-ledgers", z2.array(pointLedgerReferenceSchema), {
|
|
1090
|
+
options: requestOptions
|
|
1091
|
+
})
|
|
1092
|
+
},
|
|
1093
|
+
leaderboards: {
|
|
1094
|
+
list: (requestOptions) => request("/v1/leaderboards", z2.array(leaderboardDefinitionSchema), {
|
|
1095
|
+
options: requestOptions
|
|
1096
|
+
}),
|
|
1097
|
+
standings: async (board, query = {}, requestOptions) => request(
|
|
1098
|
+
withQuery(
|
|
1099
|
+
`/v1/leaderboards/${parseInput(identifier, board)}`,
|
|
1100
|
+
parseInput(leaderboardQuerySchema, query)
|
|
1101
|
+
),
|
|
1102
|
+
leaderboardPageSchema,
|
|
1103
|
+
{ options: requestOptions }
|
|
1104
|
+
),
|
|
1105
|
+
/**
|
|
1106
|
+
* A profile's current rank and score on `board` (`profile.id` from a leaderboard row or
|
|
1107
|
+
* `profiles.mine()`). Needs the board's access, like `standings`; a profile this viewer
|
|
1108
|
+
* cannot see is a 404, as in `profiles.get`.
|
|
1109
|
+
*/
|
|
1110
|
+
placement: async (board, profile, requestOptions) => request(
|
|
1111
|
+
`/v1/leaderboards/${parseInput(identifier, board)}/profiles/${parseInput(identifier, profile)}`,
|
|
1112
|
+
leaderboardPlacementSchema,
|
|
1113
|
+
{ options: requestOptions }
|
|
1114
|
+
)
|
|
1115
|
+
},
|
|
1116
|
+
/**
|
|
1117
|
+
* Participant profiles: the display name and avatar other participants see where the project
|
|
1118
|
+
* enables profiles in Console. Render an avatar with `avatarSrc(profile.avatar)` from
|
|
1119
|
+
* `@domino-sdk/relay/avatar`.
|
|
1120
|
+
*/
|
|
1121
|
+
profiles: {
|
|
1122
|
+
/** The signed-in member's own profile, whatever the project shows to others. */
|
|
1123
|
+
mine: (requestOptions) => request("/v1/me/profile", ownProfileSchema, {
|
|
1124
|
+
options: requestOptions
|
|
1125
|
+
}),
|
|
1126
|
+
/**
|
|
1127
|
+
* Changes the member's own name, avatar choice or visibility; omitted fields stay, and null
|
|
1128
|
+
* returns to the default.
|
|
1129
|
+
*/
|
|
1130
|
+
update: async (value, requestOptions) => request("/v1/me/profile", ownProfileSchema, {
|
|
1131
|
+
json: parseInput(profileUpdateSchema, value),
|
|
1132
|
+
options: requestOptions
|
|
1133
|
+
}),
|
|
1134
|
+
/**
|
|
1135
|
+
* Uploads a JPEG, PNG or WebP of at most 5 MB as the member's avatar. The server crops it to
|
|
1136
|
+
* a 512×512 WebP without metadata. The client never resends it: retrying with the same
|
|
1137
|
+
* `uploadId` and file stores no second picture, but only before another upload replaces it.
|
|
1138
|
+
*/
|
|
1139
|
+
uploadAvatar: async (file, requestOptions = {}) => {
|
|
1140
|
+
if (!avatarUploadTypes.includes(file.type)) {
|
|
1141
|
+
throw clientError(
|
|
1142
|
+
"Use a JPEG, PNG or WebP image",
|
|
1143
|
+
RelayErrorCode.InvalidInput
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
if (file.size > AVATAR_UPLOAD_LIMIT) {
|
|
1147
|
+
throw clientError(
|
|
1148
|
+
"Use an image smaller than 5 MB",
|
|
1149
|
+
RelayErrorCode.InvalidInput
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
const { uploadId, ...rest } = requestOptions;
|
|
1153
|
+
const operationId = parseInput(identifier, uploadId ?? crypto.randomUUID());
|
|
1154
|
+
return request("/v1/me/profile/avatar", ownProfileSchema, {
|
|
1155
|
+
method: "POST",
|
|
1156
|
+
body: file,
|
|
1157
|
+
headers: {
|
|
1158
|
+
"Content-Type": file.type,
|
|
1159
|
+
"X-Relay-Upload-ID": operationId
|
|
1160
|
+
},
|
|
1161
|
+
options: rest,
|
|
1162
|
+
operationId,
|
|
1163
|
+
// Relay keeps no receipt for an upload ID: replaying an upload another one replaced
|
|
1164
|
+
// would make it current again. Retry only on purpose, with the same file.
|
|
1165
|
+
replaySafe: false
|
|
1166
|
+
});
|
|
1167
|
+
},
|
|
1168
|
+
/**
|
|
1169
|
+
* A profile's name and avatar by its public ID (`profile.id` from a leaderboard row or
|
|
1170
|
+
* `mine()`). A profile that is missing, hidden or not visible to this viewer is a 404.
|
|
1171
|
+
*/
|
|
1172
|
+
get: async (profile, requestOptions) => request(
|
|
1173
|
+
`/v1/profiles/${parseInput(identifier, profile)}`,
|
|
1174
|
+
profileSummarySchema,
|
|
1175
|
+
{ options: requestOptions }
|
|
1176
|
+
),
|
|
1177
|
+
/**
|
|
1178
|
+
* A page of the profile's completions of quests that show on profiles, most recently
|
|
1179
|
+
* completed first.
|
|
1180
|
+
*/
|
|
1181
|
+
completions: async (profile, query = {}, requestOptions) => request(
|
|
1182
|
+
withQuery(
|
|
1183
|
+
`/v1/profiles/${parseInput(identifier, profile)}/completions`,
|
|
1184
|
+
parseInput(profileCompletionQuerySchema, query)
|
|
1185
|
+
),
|
|
1186
|
+
profileCompletionPageSchema,
|
|
1187
|
+
{ options: requestOptions }
|
|
1188
|
+
),
|
|
1189
|
+
/**
|
|
1190
|
+
* The profile's invited and qualified counts and milestones in one referral program. Needs
|
|
1191
|
+
* a signed-in participant, as referral programs do.
|
|
1192
|
+
*/
|
|
1193
|
+
referral: async (profile, program, requestOptions) => request(
|
|
1194
|
+
`/v1/profiles/${parseInput(identifier, profile)}/referrals/${parseInput(identifier, program)}`,
|
|
1195
|
+
profileReferralSchema,
|
|
1196
|
+
{ options: requestOptions }
|
|
1197
|
+
)
|
|
1198
|
+
},
|
|
1199
|
+
quests: {
|
|
1200
|
+
get: getQuest,
|
|
1201
|
+
/**
|
|
1202
|
+
* Enrolls the signed-in member in a quest whose tracker trigger requires enrollment. Activity
|
|
1203
|
+
* counts from then on; earlier activity is historical, or skipped with `before-enrollment`
|
|
1204
|
+
* on a quest that counts from enrollment. Enrolling again returns the first enrollment.
|
|
1205
|
+
*/
|
|
1206
|
+
enroll: async (value, requestOptions) => {
|
|
1207
|
+
const body2 = parseInput(questEnrollmentInputSchema, value);
|
|
1208
|
+
return request("/v1/quests/enrollments", questEnrollmentSchema, {
|
|
1209
|
+
json: body2,
|
|
1210
|
+
options: requestOptions,
|
|
1211
|
+
operationId: body2.actionId
|
|
1212
|
+
});
|
|
1213
|
+
},
|
|
1214
|
+
/**
|
|
1215
|
+
* Claims one of the signed-in member's outcomes skipped as `historical`, on a quest whose
|
|
1216
|
+
* historical policy is `"claim"` (`outcome.claimable`). Relay decides it again with
|
|
1217
|
+
* historical activity released and returns the outcome; a rule that still fails rejects
|
|
1218
|
+
* with a `RelayError` whose code is that rule's skip code.
|
|
1219
|
+
*/
|
|
1220
|
+
claim: async (value, requestOptions) => {
|
|
1221
|
+
const body2 = parseInput(questClaimInputSchema, value);
|
|
1222
|
+
return request("/v1/quests/claims", questOutcomeSchema, {
|
|
1223
|
+
json: body2,
|
|
1224
|
+
options: requestOptions,
|
|
1225
|
+
operationId: body2.actionId
|
|
1226
|
+
});
|
|
1227
|
+
},
|
|
1228
|
+
/**
|
|
1229
|
+
* Why automatic quests did or did not run for the signed-in member's activity, newest first:
|
|
1230
|
+
* each admission, and each skip with its stable code.
|
|
1231
|
+
*/
|
|
1232
|
+
outcomes: async (query = {}, requestOptions) => request(
|
|
1233
|
+
withQuery(
|
|
1234
|
+
"/v1/quests/outcomes",
|
|
1235
|
+
parseInput(questOutcomeQuerySchema, query)
|
|
1236
|
+
),
|
|
1237
|
+
questOutcomePageSchema,
|
|
1238
|
+
{ options: requestOptions }
|
|
1239
|
+
),
|
|
1240
|
+
/** Retries verification of the quest's failed attempt. */
|
|
1241
|
+
retry: async (view, requestOptions) => {
|
|
1242
|
+
if (view.trigger.kind === "automatic") {
|
|
1243
|
+
throw clientError(
|
|
1244
|
+
"Automatic quests recover without participant retries.",
|
|
1245
|
+
RelayErrorCode.RetryUnavailable
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
if (!view.attempt || view.attempt.status !== "failed") {
|
|
1249
|
+
throw clientError(
|
|
1250
|
+
"There is no failed attempt to retry.",
|
|
1251
|
+
RelayErrorCode.RetryUnavailable
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
return request(`/v1/attempts/${view.attempt.id}/retry`, attemptSchema, {
|
|
1255
|
+
json: {},
|
|
1256
|
+
options: await bound(requestOptions)
|
|
1257
|
+
});
|
|
1258
|
+
},
|
|
1259
|
+
experience,
|
|
1260
|
+
collection: async (id, requestOptions) => {
|
|
1261
|
+
const collection = (await experience(requestOptions)).collections.find(
|
|
1262
|
+
(c) => c.id === id || c.key === id
|
|
1263
|
+
);
|
|
1264
|
+
if (!collection) {
|
|
1265
|
+
throw clientError("Collection not found", RelayErrorCode.NotFound);
|
|
1266
|
+
}
|
|
1267
|
+
return collection;
|
|
1268
|
+
},
|
|
1269
|
+
open: questActions(submission, (id) => getQuest(id)),
|
|
1270
|
+
observe: (listener, observeOptions) => {
|
|
1271
|
+
const observer = observeProgress(
|
|
1272
|
+
{
|
|
1273
|
+
session: (signal) => readSession({ signal }),
|
|
1274
|
+
progress: (session, signal) => request("/v1/me/experience", questExperienceSchema, {
|
|
1275
|
+
options: { session, signal }
|
|
1276
|
+
})
|
|
1277
|
+
},
|
|
1278
|
+
listener,
|
|
1279
|
+
observeOptions,
|
|
1280
|
+
() => observers.delete(observer)
|
|
1281
|
+
);
|
|
1282
|
+
observers.add(observer);
|
|
1283
|
+
observer.clear();
|
|
1284
|
+
void observer.refresh();
|
|
1285
|
+
return { refresh: observer.refresh, dispose: observer.dispose };
|
|
1286
|
+
}
|
|
1287
|
+
},
|
|
1288
|
+
campaigns: {
|
|
1289
|
+
/** Enrolls the signed-in member once in every quest of a campaign that requires it. */
|
|
1290
|
+
enroll: async (value, requestOptions) => {
|
|
1291
|
+
const body2 = parseInput(campaignEnrollmentInputSchema, value);
|
|
1292
|
+
return request("/v1/campaigns/enrollments", campaignEnrollmentSchema, {
|
|
1293
|
+
json: body2,
|
|
1294
|
+
options: requestOptions,
|
|
1295
|
+
operationId: body2.actionId
|
|
1296
|
+
});
|
|
1297
|
+
},
|
|
1298
|
+
/** Pauses the signed-in member's campaign enrollment without erasing its history. */
|
|
1299
|
+
withdraw: async (value, requestOptions) => {
|
|
1300
|
+
const body2 = parseInput(campaignWithdrawalInputSchema, value);
|
|
1301
|
+
return request(
|
|
1302
|
+
"/v1/campaigns/enrollments/withdraw",
|
|
1303
|
+
campaignEnrollmentSchema,
|
|
1304
|
+
{
|
|
1305
|
+
json: body2,
|
|
1306
|
+
options: requestOptions,
|
|
1307
|
+
operationId: body2.actionId
|
|
1308
|
+
}
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
},
|
|
1312
|
+
/** The signed-in member's linked Solana, EVM and Cosmos wallets for this project. */
|
|
1313
|
+
wallets: {
|
|
1314
|
+
list: (requestOptions) => request(
|
|
1315
|
+
"/v1/me/wallets",
|
|
1316
|
+
z2.object({ wallets: z2.array(linkedWalletSchema) }),
|
|
1317
|
+
{ options: requestOptions }
|
|
1318
|
+
).then((result) => result.wallets),
|
|
1319
|
+
challenge: async (value, requestOptions) => request("/v1/me/wallets/challenge", walletMessageChallengeSchema, {
|
|
1320
|
+
json: parseInput(walletAddressInputSchema, value),
|
|
1321
|
+
options: await bound(requestOptions),
|
|
1322
|
+
replaySafe: unusedChallengeExpires
|
|
1323
|
+
}),
|
|
1324
|
+
verify: async (value, requestOptions) => linkVerify(value, await bound(requestOptions)),
|
|
1325
|
+
/** The address stays bound to this member: another member still cannot link it. */
|
|
1326
|
+
unlink: async (wallet, requestOptions) => request("/v1/me/wallets/unlink", ok, {
|
|
1327
|
+
json: parseInput(walletUnlinkInputSchema, {
|
|
1328
|
+
chain: wallet.chain,
|
|
1329
|
+
address: wallet.address
|
|
1330
|
+
}),
|
|
1331
|
+
options: requestOptions
|
|
1332
|
+
}),
|
|
1333
|
+
/**
|
|
1334
|
+
* Asks the signer for its address, signs the returned challenge, and links the wallet. The
|
|
1335
|
+
* session read and the challenge share one deadline, and the verification gets its own:
|
|
1336
|
+
* the time the member takes in the wallet counts against neither.
|
|
1337
|
+
*/
|
|
1338
|
+
link: async (signer, requestOptions) => {
|
|
1339
|
+
const session = await bound(requestOptions);
|
|
1340
|
+
const challenge = await request(
|
|
1341
|
+
"/v1/me/wallets/challenge",
|
|
1342
|
+
walletMessageChallengeSchema,
|
|
1343
|
+
{
|
|
1344
|
+
json: parseInput(
|
|
1345
|
+
walletAddressInputSchema,
|
|
1346
|
+
await fromSigner(
|
|
1347
|
+
() => walletAddressInput(signer),
|
|
1348
|
+
requestOptions?.signal
|
|
1349
|
+
)
|
|
1350
|
+
),
|
|
1351
|
+
options: session,
|
|
1352
|
+
replaySafe: unusedChallengeExpires
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
const proof = await fromSigner(
|
|
1356
|
+
() => signer.sign(challenge.message, challenge.address),
|
|
1357
|
+
requestOptions?.signal
|
|
1358
|
+
);
|
|
1359
|
+
return linkVerify(
|
|
1360
|
+
{ challenge: challenge.id, ...proof },
|
|
1361
|
+
{ ...requestOptions, session: session.session }
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
},
|
|
1365
|
+
auth: {
|
|
1366
|
+
providers: (requestOptions) => request(
|
|
1367
|
+
"/v1/auth/providers",
|
|
1368
|
+
z2.object({
|
|
1369
|
+
providers: z2.array(
|
|
1370
|
+
z2.object({
|
|
1371
|
+
provider: authProviderSchema,
|
|
1372
|
+
configured: z2.boolean()
|
|
1373
|
+
})
|
|
1374
|
+
),
|
|
1375
|
+
email: z2.boolean(),
|
|
1376
|
+
/** The wallet sign-in this project enabled. */
|
|
1377
|
+
wallets: walletSignInNetworksSchema,
|
|
1378
|
+
demo: z2.boolean()
|
|
1379
|
+
}),
|
|
1380
|
+
{ options: requestOptions }
|
|
1381
|
+
),
|
|
1382
|
+
start: async (provider, mode, requestOptions) => request("/v1/auth/start", z2.object({ url: z2.string() }), {
|
|
1383
|
+
json: {
|
|
1384
|
+
provider: parseInput(authProviderSchema, provider),
|
|
1385
|
+
mode: parseInput(z2.enum(["sign-in", "connect"]), mode)
|
|
1386
|
+
},
|
|
1387
|
+
options: requestOptions
|
|
1388
|
+
}),
|
|
1389
|
+
emailStart: async (email, requestOptions) => request("/v1/auth/email/start", z2.object({ challenge: z2.string() }), {
|
|
1390
|
+
json: { email: parseInput(z2.email().max(254), email.trim()) },
|
|
1391
|
+
options: requestOptions
|
|
1392
|
+
}),
|
|
1393
|
+
emailVerify: async (challenge, code, requestOptions) => {
|
|
1394
|
+
const body2 = {
|
|
1395
|
+
challenge: parseInput(z2.string().min(1).max(200), challenge),
|
|
1396
|
+
code: parseInput(
|
|
1397
|
+
z2.string().regex(/^\d{6}$/, "Enter the 6-digit code"),
|
|
1398
|
+
code.trim()
|
|
1399
|
+
)
|
|
1400
|
+
};
|
|
1401
|
+
return changeSession(
|
|
1402
|
+
() => request("/v1/auth/email/verify", participantSessionSchema, {
|
|
1403
|
+
json: body2,
|
|
1404
|
+
options: requestOptions
|
|
1405
|
+
})
|
|
1406
|
+
);
|
|
1407
|
+
},
|
|
1408
|
+
/**
|
|
1409
|
+
* Sign in, or sign up, with a Solana, EVM or Cosmos wallet where the project enabled it
|
|
1410
|
+
* (`providers().wallets`). A wallet the member linked while signed in cannot sign in.
|
|
1411
|
+
*/
|
|
1412
|
+
wallet: {
|
|
1413
|
+
/** A sign-in challenge for the wallet's address; binds the flow to this browser. */
|
|
1414
|
+
start: async (value, requestOptions) => request("/v1/auth/wallet/start", walletMessageChallengeSchema, {
|
|
1415
|
+
json: parseInput(walletAddressInputSchema, value),
|
|
1416
|
+
options: requestOptions
|
|
1417
|
+
}),
|
|
1418
|
+
/** Verifies the signed challenge and starts the session. Not retried: start again instead. */
|
|
1419
|
+
verify: (proof, requestOptions) => changeSession(
|
|
1420
|
+
() => request("/v1/auth/wallet/verify", participantSessionSchema, {
|
|
1421
|
+
json: parseInput(walletSignatureSchema, proof),
|
|
1422
|
+
options: requestOptions
|
|
1423
|
+
})
|
|
1424
|
+
),
|
|
1425
|
+
/**
|
|
1426
|
+
* Asks the signer for its address, signs the challenge and starts the session. Rejects with
|
|
1427
|
+
* an `http` `RelayError` (status 403) when the project has not enabled this wallet family.
|
|
1428
|
+
*/
|
|
1429
|
+
signIn: async (signer, requestOptions) => {
|
|
1430
|
+
const challenge = await request(
|
|
1431
|
+
"/v1/auth/wallet/start",
|
|
1432
|
+
walletMessageChallengeSchema,
|
|
1433
|
+
{
|
|
1434
|
+
json: parseInput(
|
|
1435
|
+
walletAddressInputSchema,
|
|
1436
|
+
await fromSigner(
|
|
1437
|
+
() => walletAddressInput(signer),
|
|
1438
|
+
requestOptions?.signal
|
|
1439
|
+
)
|
|
1440
|
+
),
|
|
1441
|
+
options: requestOptions
|
|
1442
|
+
}
|
|
1443
|
+
);
|
|
1444
|
+
const proof = await fromSigner(
|
|
1445
|
+
() => signer.sign(challenge.message, challenge.address),
|
|
1446
|
+
requestOptions?.signal
|
|
1447
|
+
);
|
|
1448
|
+
return changeSession(
|
|
1449
|
+
() => request("/v1/auth/wallet/verify", participantSessionSchema, {
|
|
1450
|
+
json: parseInput(walletSignatureSchema, {
|
|
1451
|
+
challenge: challenge.id,
|
|
1452
|
+
...proof
|
|
1453
|
+
}),
|
|
1454
|
+
options: requestOptions
|
|
1455
|
+
})
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
/** The member's connected sign-in accounts, one per provider. */
|
|
1460
|
+
accounts: (requestOptions) => request("/v1/auth/accounts", z2.array(accountConnectionSchema), {
|
|
1461
|
+
options: requestOptions
|
|
1462
|
+
}),
|
|
1463
|
+
disconnect: async (provider, requestOptions) => request("/v1/auth/accounts/disconnect", acknowledged, {
|
|
1464
|
+
json: { provider: parseInput(authProviderSchema, provider) },
|
|
1465
|
+
options: requestOptions
|
|
1466
|
+
}),
|
|
1467
|
+
session: (requestOptions) => readSession(requestOptions),
|
|
1468
|
+
signOut: (requestOptions) => changeSession(
|
|
1469
|
+
() => request("/v1/auth/logout", acknowledged, {
|
|
1470
|
+
json: {},
|
|
1471
|
+
options: requestOptions
|
|
1472
|
+
})
|
|
1473
|
+
),
|
|
1474
|
+
/** Local development only. Existing hosted apps use createParticipantBackend from /portal-proxy. */
|
|
1475
|
+
exchange: async (value, requestOptions) => request("/v1/auth/exchange", exchangeResultSchema, {
|
|
1476
|
+
json: parseInput(exchangeSchema, value),
|
|
1477
|
+
options: requestOptions
|
|
1478
|
+
})
|
|
1479
|
+
},
|
|
1480
|
+
me: {
|
|
1481
|
+
activity: {
|
|
1482
|
+
list: (query = {}, options2) => {
|
|
1483
|
+
const parsed = parseInput(participantActivityQuerySchema, query);
|
|
1484
|
+
return request(
|
|
1485
|
+
withQuery("/v1/me/activity", parsed),
|
|
1486
|
+
participantActivitySchema,
|
|
1487
|
+
{ options: options2 }
|
|
1488
|
+
);
|
|
1489
|
+
},
|
|
1490
|
+
observe: (listener, options2 = {}) => {
|
|
1491
|
+
let cursor = options2.cursor;
|
|
1492
|
+
let owner;
|
|
1493
|
+
const observer = observeProgress(
|
|
1494
|
+
{
|
|
1495
|
+
session: (signal) => readSession({ signal }),
|
|
1496
|
+
progress: (session, signal) => request(
|
|
1497
|
+
withQuery("/v1/me/activity", { cursor }),
|
|
1498
|
+
participantActivitySchema,
|
|
1499
|
+
{ options: { session, signal } }
|
|
1500
|
+
)
|
|
1501
|
+
},
|
|
1502
|
+
(state) => {
|
|
1503
|
+
if (state.kind === "session") {
|
|
1504
|
+
if (owner !== void 0 && owner !== (state.session?.id ?? null)) {
|
|
1505
|
+
cursor = void 0;
|
|
1506
|
+
}
|
|
1507
|
+
owner = state.session?.id ?? null;
|
|
1508
|
+
}
|
|
1509
|
+
if (state.kind === "ready") {
|
|
1510
|
+
for (const event of state.progress.items) {
|
|
1511
|
+
listener(event);
|
|
1512
|
+
}
|
|
1513
|
+
cursor = state.progress.nextCursor;
|
|
1514
|
+
if (state.progress.items.length === 50) {
|
|
1515
|
+
queueMicrotask(() => void observer.refresh());
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
options2.onState?.(state);
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
intervalMs: options2.intervalMs ?? 5e3,
|
|
1522
|
+
maxBackoffMs: options2.maxBackoffMs
|
|
1523
|
+
},
|
|
1524
|
+
() => observers.delete(observer)
|
|
1525
|
+
);
|
|
1526
|
+
observers.add(observer);
|
|
1527
|
+
observer.clear();
|
|
1528
|
+
void observer.refresh();
|
|
1529
|
+
return { refresh: observer.refresh, dispose: observer.dispose };
|
|
1530
|
+
}
|
|
1531
|
+
},
|
|
1532
|
+
/** The signed-in member, and the seed of their generated avatar: `defaultAvatar(avatarSeed)`. */
|
|
1533
|
+
get: async (requestOptions) => request("/v1/me", memberSummarySchema, { options: requestOptions }),
|
|
1534
|
+
observeProgress: (listener, observeOptions) => {
|
|
1535
|
+
const observer = observeProgress(
|
|
1536
|
+
{
|
|
1537
|
+
session: (signal) => readSession({ signal }),
|
|
1538
|
+
progress: (session, signal) => request("/v1/me/progress", memberProgressSchema, {
|
|
1539
|
+
options: { session, signal }
|
|
1540
|
+
})
|
|
1541
|
+
},
|
|
1542
|
+
listener,
|
|
1543
|
+
observeOptions,
|
|
1544
|
+
() => observers.delete(observer)
|
|
1545
|
+
);
|
|
1546
|
+
observers.add(observer);
|
|
1547
|
+
observer.clear();
|
|
1548
|
+
void observer.refresh();
|
|
1549
|
+
return { refresh: observer.refresh, dispose: observer.dispose };
|
|
1550
|
+
},
|
|
1551
|
+
submission,
|
|
1552
|
+
collectionPass: async (entitlement, requestOptions) => request("/v1/me/collection-pass", collectionPassSchema, {
|
|
1553
|
+
json: { entitlement: parseInput(identifier, entitlement) },
|
|
1554
|
+
options: await bound(requestOptions)
|
|
1555
|
+
}),
|
|
1556
|
+
progress: (requestOptions) => request("/v1/me/progress", memberProgressSchema, {
|
|
1557
|
+
options: requestOptions
|
|
1558
|
+
}),
|
|
1559
|
+
rewardDeliveries: (requestOptions) => request("/v1/reward-deliveries", rewardDeliveriesSchema, {
|
|
1560
|
+
options: requestOptions
|
|
1561
|
+
}),
|
|
1562
|
+
/**
|
|
1563
|
+
* `{ items }`: the member's balance in each of the project's point ledgers, in the project's
|
|
1564
|
+
* ledger order, zero in a ledger they have no entries in.
|
|
1565
|
+
*/
|
|
1566
|
+
balances: (requestOptions) => request("/v1/me/points", pointBalancesSchema, {
|
|
1567
|
+
options: requestOptions
|
|
1568
|
+
}),
|
|
1569
|
+
/** The member's own entries in one ledger, by key or ID, most recently recorded first. */
|
|
1570
|
+
pointHistory: async (query, requestOptions) => {
|
|
1571
|
+
const { ledger, cursor } = parseInput(pointHistoryQuerySchema, query);
|
|
1572
|
+
return request(
|
|
1573
|
+
withQuery(`/v1/me/points/${ledger}/history`, { cursor }),
|
|
1574
|
+
pointHistoryPageSchema,
|
|
1575
|
+
{ options: requestOptions }
|
|
1576
|
+
);
|
|
1577
|
+
},
|
|
1578
|
+
/** Claims a quest for the signed-in member. Quest controllers (`quests.open`) call this. */
|
|
1579
|
+
claim: async (value, requestOptions) => {
|
|
1580
|
+
const claim = parseInput(submitSchema.omit({ member: true }), value);
|
|
1581
|
+
return request("/v1/me/attempts", attemptSchema, {
|
|
1582
|
+
json: claim,
|
|
1583
|
+
options: requestOptions,
|
|
1584
|
+
operationId: claim.actionId
|
|
1585
|
+
});
|
|
1586
|
+
},
|
|
1587
|
+
/** Uploads a photo as the signed-in member's evidence. */
|
|
1588
|
+
upload: (file, requestOptions) => request("/v1/me/evidence", evidenceSchema, {
|
|
1589
|
+
method: "POST",
|
|
1590
|
+
body: file,
|
|
1591
|
+
headers: { "Content-Type": file.type },
|
|
1592
|
+
options: requestOptions
|
|
1593
|
+
})
|
|
1594
|
+
},
|
|
1595
|
+
evidence: {
|
|
1596
|
+
async download(id, requestOptions) {
|
|
1597
|
+
const call = { options: requestOptions };
|
|
1598
|
+
return exchange(
|
|
1599
|
+
`/v1/evidence/${parseInput(identifier, id)}`,
|
|
1600
|
+
call,
|
|
1601
|
+
(response, life) => {
|
|
1602
|
+
const type = response.headers.get("Content-Type");
|
|
1603
|
+
if (type !== "image/jpeg" && type !== "image/png") {
|
|
1604
|
+
throw invalidResponse(
|
|
1605
|
+
response.status,
|
|
1606
|
+
call,
|
|
1607
|
+
new Error("Unexpected evidence content type")
|
|
1608
|
+
);
|
|
1609
|
+
}
|
|
1610
|
+
return body(response, call, life, (value) => value.blob());
|
|
1611
|
+
}
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
},
|
|
1615
|
+
engagement: {
|
|
1616
|
+
/** The member's engagement settlements for one post under one rule, newest first. */
|
|
1617
|
+
page: async (query, requestOptions) => request(
|
|
1618
|
+
withQuery(
|
|
1619
|
+
"/v1/engagement/history",
|
|
1620
|
+
parseInput(engagementPageQuerySchema, query)
|
|
1621
|
+
),
|
|
1622
|
+
engagementPageSchema,
|
|
1623
|
+
{ options: requestOptions }
|
|
1624
|
+
),
|
|
1625
|
+
/** The formula boundaries the member's settlements for one post crossed, newest first. */
|
|
1626
|
+
boundaries: async (query, requestOptions) => request(
|
|
1627
|
+
withQuery(
|
|
1628
|
+
"/v1/engagement/boundaries",
|
|
1629
|
+
parseInput(engagementPageQuerySchema, query)
|
|
1630
|
+
),
|
|
1631
|
+
engagementBoundaryPageSchema,
|
|
1632
|
+
{ options: requestOptions }
|
|
1633
|
+
)
|
|
1634
|
+
},
|
|
1635
|
+
content: {
|
|
1636
|
+
performance: async (query, requestOptions) => request(
|
|
1637
|
+
withQuery(
|
|
1638
|
+
"/v1/content/performance",
|
|
1639
|
+
parseInput(contentPerformanceQuerySchema, query)
|
|
1640
|
+
),
|
|
1641
|
+
contentPerformancePageSchema,
|
|
1642
|
+
{ options: requestOptions }
|
|
1643
|
+
),
|
|
1644
|
+
qualifications: async (query, requestOptions) => request(
|
|
1645
|
+
withQuery(
|
|
1646
|
+
"/v1/content/qualifications",
|
|
1647
|
+
parseInput(contentQualificationQuerySchema, query)
|
|
1648
|
+
),
|
|
1649
|
+
contentQualificationPageSchema,
|
|
1650
|
+
{ options: requestOptions }
|
|
1651
|
+
)
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
export {
|
|
1657
|
+
QuestUpdatedError,
|
|
1658
|
+
createRelayClient
|
|
1659
|
+
};
|