@domino-sdk/relay 0.14.1 → 0.16.1

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/dist/browser.js CHANGED
@@ -1,62 +1,11 @@
1
1
  import {
2
- createRelayClient
3
- } from "./chunk-YZJOZL4V.js";
4
- import "./chunk-CJARNIVP.js";
5
- import "./chunk-I2CCMGN6.js";
6
- import "./chunk-FUQYKTOJ.js";
7
-
8
- // src/browser.ts
9
- function createBrowserRelayClient(options) {
10
- return createRelayClient({
11
- ...options,
12
- submissionStore: options.submissionStore ?? browserSubmissionStore()
13
- });
14
- }
15
- function browserSubmissionStore() {
16
- let database;
17
- function open() {
18
- if (!globalThis.indexedDB || !globalThis.navigator?.locks) {
19
- throw new Error(
20
- "This browser cannot safely save submissions. Use a browser with IndexedDB and Web Locks enabled."
21
- );
22
- }
23
- return database ??= new Promise((resolve, reject) => {
24
- const request = indexedDB.open("domino-relay-submissions", 1);
25
- request.onupgradeneeded = () => request.result.createObjectStore("submissions");
26
- request.onerror = () => reject(new Error("Could not open submission storage"));
27
- request.onsuccess = () => resolve(request.result);
28
- request.onblocked = () => reject(new Error("Close other Relay tabs and try again"));
29
- });
30
- }
31
- async function transact(key, value) {
32
- const db = await open();
33
- return new Promise((resolve, reject) => {
34
- const transaction = db.transaction(
35
- "submissions",
36
- value === void 0 ? "readonly" : "readwrite",
37
- { durability: "strict" }
38
- );
39
- const store = transaction.objectStore("submissions");
40
- const request = value === void 0 ? store.get(key) : store.put(value, key);
41
- transaction.oncomplete = () => resolve(request.result);
42
- transaction.onerror = transaction.onabort = () => reject(
43
- new Error(
44
- "Could not save submission progress. Resume the saved submission when browser storage is available."
45
- )
46
- );
47
- });
48
- }
49
- return {
50
- read: (key) => transact(key),
51
- write: async (key, value) => {
52
- await transact(key, value);
53
- },
54
- exclusive: async (key, task) => {
55
- await open();
56
- return navigator.locks.request(key, task);
57
- }
58
- };
59
- }
2
+ browserSubmissionStore,
3
+ createBrowserRelayClient
4
+ } from "./chunk-MK2E36HR.js";
5
+ import "./chunk-TI22MU2X.js";
6
+ import "./chunk-XNS25KST.js";
7
+ import "./chunk-GEJK7LMK.js";
8
+ import "./chunk-YUAE6PFY.js";
60
9
  export {
61
10
  browserSubmissionStore,
62
11
  createBrowserRelayClient
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  identifier
3
- } from "./chunk-FUQYKTOJ.js";
3
+ } from "./chunk-YUAE6PFY.js";
4
4
 
5
5
  // src/auth.ts
6
6
  import { z } from "zod";
@@ -0,0 +1,61 @@
1
+ import {
2
+ createRelayClient
3
+ } from "./chunk-TI22MU2X.js";
4
+
5
+ // src/browser.ts
6
+ function createBrowserRelayClient(options) {
7
+ return createRelayClient({
8
+ ...options,
9
+ submissionStore: options.submissionStore ?? browserSubmissionStore()
10
+ });
11
+ }
12
+ function browserSubmissionStore() {
13
+ let database;
14
+ function open() {
15
+ if (!globalThis.indexedDB || !globalThis.navigator?.locks) {
16
+ throw new Error(
17
+ "This browser cannot safely save submissions. Use a browser with IndexedDB and Web Locks enabled."
18
+ );
19
+ }
20
+ return database ??= new Promise((resolve, reject) => {
21
+ const request = indexedDB.open("domino-relay-submissions", 1);
22
+ request.onupgradeneeded = () => request.result.createObjectStore("submissions");
23
+ request.onerror = () => reject(new Error("Could not open submission storage"));
24
+ request.onsuccess = () => resolve(request.result);
25
+ request.onblocked = () => reject(new Error("Close other Relay tabs and try again"));
26
+ });
27
+ }
28
+ async function transact(key, value) {
29
+ const db = await open();
30
+ return new Promise((resolve, reject) => {
31
+ const transaction = db.transaction(
32
+ "submissions",
33
+ value === void 0 ? "readonly" : "readwrite",
34
+ { durability: "strict" }
35
+ );
36
+ const store = transaction.objectStore("submissions");
37
+ const request = value === void 0 ? store.get(key) : store.put(value, key);
38
+ transaction.oncomplete = () => resolve(request.result);
39
+ transaction.onerror = transaction.onabort = () => reject(
40
+ new Error(
41
+ "Could not save submission progress. Resume the saved submission when browser storage is available."
42
+ )
43
+ );
44
+ });
45
+ }
46
+ return {
47
+ read: (key) => transact(key),
48
+ write: async (key, value) => {
49
+ await transact(key, value);
50
+ },
51
+ exclusive: async (key, task) => {
52
+ await open();
53
+ return navigator.locks.request(key, task);
54
+ }
55
+ };
56
+ }
57
+
58
+ export {
59
+ createBrowserRelayClient,
60
+ browserSubmissionStore
61
+ };
@@ -14,13 +14,14 @@ import {
14
14
  referralHistorySchema,
15
15
  referralSummarySchema,
16
16
  trackerArtifactSchema,
17
- validateAuthoringIdentity
18
- } from "./chunk-CJARNIVP.js";
17
+ validateAuthoringIdentity,
18
+ xTweetSchema
19
+ } from "./chunk-XNS25KST.js";
19
20
  import {
20
21
  authScopeSchema,
21
22
  exchangeResultSchema,
22
23
  sessionSchema
23
- } from "./chunk-I2CCMGN6.js";
24
+ } from "./chunk-GEJK7LMK.js";
24
25
  import {
25
26
  accountConnectionSchema,
26
27
  attemptSchema,
@@ -44,8 +45,11 @@ import {
44
45
  settingsValuesSchema,
45
46
  snapshotSchema,
46
47
  storedReviewModeSchema,
47
- templateSchema
48
- } from "./chunk-FUQYKTOJ.js";
48
+ submissionEvidenceSchema,
49
+ templateSchema,
50
+ validateSubmissionValue,
51
+ valueEvidenceSchema
52
+ } from "./chunk-YUAE6PFY.js";
49
53
 
50
54
  // src/point-ledgers.ts
51
55
  import { z } from "zod";
@@ -91,6 +95,8 @@ var rewardDeliveriesSchema = z2.object({
91
95
  import { z as z3 } from "zod";
92
96
  var interactionSchema = z3.enum([
93
97
  "photo",
98
+ "text",
99
+ "url",
94
100
  "quiz",
95
101
  "claim",
96
102
  "staff",
@@ -229,7 +235,7 @@ var common = {
229
235
  release: identifier.optional()
230
236
  };
231
237
  var claimInputSchema = z4.union([
232
- quizEvidenceSchema,
238
+ submissionEvidenceSchema,
233
239
  z4.object({ kind: z4.literal("none") }).strict()
234
240
  ]);
235
241
  var draftSchema = z4.union([
@@ -322,7 +328,7 @@ function submissions(transport, configuredStore, namespace) {
322
328
  quest,
323
329
  actionId: record.id,
324
330
  ...record.release ? { release: record.release } : {},
325
- ..."evidence" in record ? { evidence: record.evidence } : record.input.kind === "quiz" ? { input: record.input } : {}
331
+ ..."evidence" in record ? { evidence: record.evidence } : record.input.kind !== "none" ? { input: record.input } : {}
326
332
  },
327
333
  sessionId
328
334
  );
@@ -356,6 +362,10 @@ function submissions(transport, configuredStore, namespace) {
356
362
  try {
357
363
  attempt = await claim(record);
358
364
  } catch (error) {
365
+ if (error instanceof RelayError && error.status === 422 && error.code === "invalid-submission" && record.stage === "claim") {
366
+ await store.write(key, null);
367
+ throw error;
368
+ }
359
369
  if (error instanceof RelayError && error.status === 409 && (error.code === "quest-updated" || error.code === "stale-quiz") && record.stage === "claim") {
360
370
  const draft = "input" in record ? record.input : "file" in record && record.file ? { kind: "photo", file: record.file } : null;
361
371
  await store.write(
@@ -455,6 +465,22 @@ function submissions(transport, configuredStore, namespace) {
455
465
  });
456
466
  }
457
467
  };
468
+ if (options.input === "text" || options.input === "url") {
469
+ const kind = options.input;
470
+ return {
471
+ ...handle,
472
+ submit(value) {
473
+ const input = valueEvidenceSchema.parse({ kind, value });
474
+ return submit({
475
+ id: crypto.randomUUID(),
476
+ quest,
477
+ release: options.release,
478
+ stage: "claim",
479
+ input
480
+ });
481
+ }
482
+ };
483
+ }
458
484
  if (options.input === "quiz") {
459
485
  return {
460
486
  ...handle,
@@ -524,6 +550,9 @@ function reconcileQuestDraft(view, draft) {
524
550
  if (!draft) {
525
551
  return null;
526
552
  }
553
+ if (draft.kind === "text" || draft.kind === "url") {
554
+ return view.interaction === draft.kind ? draft : null;
555
+ }
527
556
  if (draft.kind === "photo") {
528
557
  return view.interaction === "photo" ? draft : null;
529
558
  }
@@ -577,6 +606,36 @@ function questActions(submission, latest) {
577
606
  };
578
607
  }
579
608
  switch (view.interaction) {
609
+ case "text":
610
+ case "url": {
611
+ const kind = view.interaction;
612
+ const handle = await submission(view.quest, {
613
+ input: kind,
614
+ release: view.release,
615
+ recoverPrevious: true,
616
+ repeatable: view.completion.kind === "keyed"
617
+ });
618
+ return {
619
+ kind,
620
+ view,
621
+ status: handle.status,
622
+ discard: handle.discard,
623
+ resume: () => run(handle.resume),
624
+ submit: (value) => run(() => {
625
+ if (view.trigger.kind !== "manual" || view.trigger.input !== "text" && view.trigger.input !== "url") {
626
+ throw new Error("Quest input changed");
627
+ }
628
+ const problem = validateSubmissionValue(
629
+ { kind, value },
630
+ view.trigger
631
+ );
632
+ if (problem) {
633
+ throw new Error(problem);
634
+ }
635
+ return handle.submit(value);
636
+ })
637
+ };
638
+ }
580
639
  case "photo": {
581
640
  const handle = await submission(view.quest, {
582
641
  input: "photo",
@@ -729,7 +788,7 @@ function observeProgress(transport, listener, options = {}, onDispose = () => {
729
788
  }
730
789
 
731
790
  // src/index.ts
732
- import { z as z9 } from "zod";
791
+ import { z as z10 } from "zod";
733
792
 
734
793
  // src/wallet.ts
735
794
  import { z as z5 } from "zod";
@@ -849,6 +908,33 @@ var participantExchangeSchema = z8.object({
849
908
  previousToken: z8.string().max(200).optional()
850
909
  }).strict();
851
910
 
911
+ // src/x.ts
912
+ import { z as z9 } from "zod";
913
+ var xIdSchema = z9.string().regex(/^[0-9]{1,20}$/);
914
+ var xConnectionSchema = z9.object({ userId: xIdSchema });
915
+ var xProfileSchema = z9.object({
916
+ id: xIdSchema,
917
+ username: z9.string(),
918
+ name: z9.string(),
919
+ bio: z9.string().nullable(),
920
+ profileImageUrl: z9.string().url().nullable(),
921
+ followersCount: z9.number().int().nonnegative().nullable(),
922
+ verified: z9.boolean().nullable()
923
+ });
924
+ var xPostSchema = xTweetSchema.extend({
925
+ quotedTweetId: xIdSchema.nullish().transform((v) => v ?? null),
926
+ inReplyToUserId: xIdSchema.nullish().transform((v) => v ?? null),
927
+ inReplyToStatusId: xIdSchema.nullish().transform((v) => v ?? null),
928
+ retweetedTweetId: xIdSchema.nullish().transform((v) => v ?? null)
929
+ });
930
+ var xRequestSchema = z9.discriminatedUnion("operation", [
931
+ z9.object({ operation: z9.literal("connection") }).strict(),
932
+ z9.object({ operation: z9.literal("profile") }).strict(),
933
+ z9.object({ operation: z9.literal("post"), postId: xIdSchema }).strict(),
934
+ z9.object({ operation: z9.literal("follows"), userId: xIdSchema }).strict(),
935
+ z9.object({ operation: z9.literal("reposted"), postId: xIdSchema }).strict()
936
+ ]);
937
+
852
938
  // src/index.ts
853
939
  function createRelayClient(options) {
854
940
  async function send(path, init = {}) {
@@ -980,19 +1066,19 @@ function createRelayClient(options) {
980
1066
  }
981
1067
  return {
982
1068
  referrals: {
983
- list: () => request("/v1/referrals", z9.array(referralDefinitionSchema)),
1069
+ list: () => request("/v1/referrals", z10.array(referralDefinitionSchema)),
984
1070
  summary: () => request("/v1/referrals/me", referralSummarySchema),
985
1071
  history: (before) => request(
986
1072
  query("/v1/referrals/history", { before }),
987
1073
  referralHistorySchema
988
1074
  ),
989
- accept: (input) => request("/v1/referrals/accept", z9.object({ ok: z9.literal(true) }), {
1075
+ accept: (input) => request("/v1/referrals/accept", z10.object({ ok: z10.literal(true) }), {
990
1076
  method: "POST",
991
1077
  body: JSON.stringify(referralAcceptSchema.parse(input))
992
1078
  })
993
1079
  },
994
1080
  leaderboards: {
995
- list: () => request("/v1/leaderboards", z9.array(leaderboardDefinitionSchema)),
1081
+ list: () => request("/v1/leaderboards", z10.array(leaderboardDefinitionSchema)),
996
1082
  standings: (board, options2 = {}) => {
997
1083
  const parsed = leaderboardQuerySchema.parse(options2);
998
1084
  return request(
@@ -1077,25 +1163,25 @@ function createRelayClient(options) {
1077
1163
  auth: {
1078
1164
  providers: () => request(
1079
1165
  "/v1/auth/providers",
1080
- z9.object({
1081
- providers: z9.array(
1082
- z9.object({
1166
+ z10.object({
1167
+ providers: z10.array(
1168
+ z10.object({
1083
1169
  provider: authProviderSchema,
1084
- configured: z9.boolean()
1170
+ configured: z10.boolean()
1085
1171
  })
1086
1172
  ),
1087
- email: z9.boolean(),
1088
- demo: z9.boolean()
1173
+ email: z10.boolean(),
1174
+ demo: z10.boolean()
1089
1175
  })
1090
1176
  ),
1091
1177
  start: (provider, mode) => request(
1092
1178
  "/v1/auth/start",
1093
- z9.object({ url: z9.string() }),
1179
+ z10.object({ url: z10.string() }),
1094
1180
  json({ provider, mode })
1095
1181
  ),
1096
1182
  emailStart: (email) => request(
1097
1183
  "/v1/auth/email/start",
1098
- z9.object({ challenge: z9.string() }),
1184
+ z10.object({ challenge: z10.string() }),
1099
1185
  json({ email })
1100
1186
  ),
1101
1187
  emailVerify: (challenge, code) => changeSession(
@@ -1105,25 +1191,25 @@ function createRelayClient(options) {
1105
1191
  json({ challenge, code })
1106
1192
  )
1107
1193
  ),
1108
- accounts: () => request("/v1/auth/accounts", z9.array(accountConnectionSchema)),
1194
+ accounts: () => request("/v1/auth/accounts", z10.array(accountConnectionSchema)),
1109
1195
  disconnect: (provider) => request(
1110
1196
  "/v1/auth/accounts/disconnect",
1111
- z9.object({ ok: z9.boolean() }),
1197
+ z10.object({ ok: z10.boolean() }),
1112
1198
  json({ provider })
1113
1199
  ),
1114
1200
  connections: () => request(
1115
1201
  "/v1/auth/connections",
1116
- z9.array(
1117
- z9.object({
1118
- provider: z9.string(),
1119
- subject: z9.string(),
1120
- signInEnabled: z9.boolean()
1202
+ z10.array(
1203
+ z10.object({
1204
+ provider: z10.string(),
1205
+ subject: z10.string(),
1206
+ signInEnabled: z10.boolean()
1121
1207
  })
1122
1208
  )
1123
1209
  ),
1124
1210
  session: () => request("/v1/auth/session", sessionSchema.nullable()),
1125
1211
  signOut: () => changeSession(
1126
- () => request("/v1/auth/logout", z9.object({ ok: z9.boolean() }), json({}))
1212
+ () => request("/v1/auth/logout", z10.object({ ok: z10.boolean() }), json({}))
1127
1213
  ),
1128
1214
  /** Local development only. Existing hosted apps use createParticipantBackend from /portal-proxy. */
1129
1215
  exchange: (input) => request("/v1/auth/exchange", exchangeResultSchema, json(input))
@@ -1204,11 +1290,11 @@ function createRelayClient(options) {
1204
1290
  /** @deprecated The participant API accepts only member sessions and rejects this staff call. Use the management API with a management key instead. */
1205
1291
  lookupMember: (issuer, subject) => request(
1206
1292
  "/v1/members/lookup",
1207
- z9.object({ member: z9.string() }),
1293
+ z10.object({ member: z10.string() }),
1208
1294
  json({ issuer, subject })
1209
1295
  ),
1210
1296
  /** @deprecated Removed from the participant API. Build quests with `domino` and `@domino-sdk/relay/build`. */
1211
- journeyTemplate: () => request("/v1/journey-template", z9.array(templateSchema)),
1297
+ journeyTemplate: () => request("/v1/journey-template", z10.array(templateSchema)),
1212
1298
  /** @deprecated Removed from the participant API. Build quests with `domino` and `@domino-sdk/relay/build`. */
1213
1299
  template: () => request("/v1/template", templateSchema),
1214
1300
  /** @deprecated The participant API accepts only member sessions and rejects this staff call. Use the management API with a management key instead. */
@@ -1218,7 +1304,7 @@ function createRelayClient(options) {
1218
1304
  /** @deprecated The participant API rejects publication. Publish with `domino deploy` or the management API. */
1219
1305
  publishBatch: (releases) => request(
1220
1306
  "/v1/releases/batch",
1221
- z9.array(publishedReleaseSchema),
1307
+ z10.array(publishedReleaseSchema),
1222
1308
  json({ releases })
1223
1309
  ),
1224
1310
  progress: (member) => request(
@@ -1297,5 +1383,10 @@ export {
1297
1383
  identityIntegrationSchema,
1298
1384
  identityIntegrationSecretSchema,
1299
1385
  participantExchangeSchema,
1386
+ xIdSchema,
1387
+ xConnectionSchema,
1388
+ xProfileSchema,
1389
+ xPostSchema,
1390
+ xRequestSchema,
1300
1391
  createRelayClient
1301
1392
  };
@@ -2,7 +2,7 @@ import {
2
2
  identifier,
3
3
  pointsRewardSchema,
4
4
  tierRewardSchema
5
- } from "./chunk-FUQYKTOJ.js";
5
+ } from "./chunk-YUAE6PFY.js";
6
6
 
7
7
  // src/authoring-identity.ts
8
8
  import { z } from "zod";