@domino-sdk/relay 1.62.0 → 1.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +145 -0
  2. package/dist/{accounts-CCqCKCVx.d.ts → accounts-_lNsiR2k.d.ts} +42 -4
  3. package/dist/{attempt-captures-Cm-5G0PC.d.ts → attempt-captures-BqPggxTU.d.ts} +1 -1
  4. package/dist/authoring.d.ts +54 -20
  5. package/dist/authoring.js +60 -31
  6. package/dist/{automatic-outcomes-pAsOyIVp.d.ts → automatic-outcomes-BzAvfcpd.d.ts} +11 -1
  7. package/dist/avatar.d.ts +1 -1
  8. package/dist/browser.d.ts +10 -10
  9. package/dist/browser.js +12 -13
  10. package/dist/capability-error-CuI_F7yM.d.ts +296 -0
  11. package/dist/{catalog--ZIlskAo.d.ts → catalog-ByZMRS7I.d.ts} +21 -10
  12. package/dist/{chunk-XNKSSE32.js → chunk-4NIV4NPV.js} +7 -7
  13. package/dist/chunk-7H4MRVQF.js +199 -0
  14. package/dist/{chunk-UPQPUJOU.js → chunk-CVQZ2YP7.js} +73 -202
  15. package/dist/{chunk-3PYYGFSB.js → chunk-DLABJSBO.js} +3 -3
  16. package/dist/{chunk-Y322OTCH.js → chunk-E22XSC4L.js} +1 -1
  17. package/dist/{chunk-E6IKQHTX.js → chunk-EDNKKVGU.js} +2 -2
  18. package/dist/{chunk-K2KS3JLY.js → chunk-EOUEAOWJ.js} +35 -4
  19. package/dist/{chunk-6WCIWXUV.js → chunk-EUEW2APU.js} +2 -2
  20. package/dist/{chunk-MK425RXJ.js → chunk-HNR6G3GV.js} +2335 -1538
  21. package/dist/{chunk-UW5232GG.js → chunk-KCUUHT2V.js} +5 -5
  22. package/dist/{chunk-CICDIBOF.js → chunk-MPTE7EIV.js} +76 -74
  23. package/dist/{chunk-4OC7REYX.js → chunk-MWMCQLCG.js} +3 -3
  24. package/dist/{chunk-GTDW453U.js → chunk-NG4GZ54I.js} +100 -114
  25. package/dist/chunk-R2KZFX6E.js +405 -0
  26. package/dist/{chunk-HTZHBTIL.js → chunk-RD3XJ4DH.js} +208 -376
  27. package/dist/{chunk-5TEYFX6X.js → chunk-SE7XHQFP.js} +2 -2
  28. package/dist/{chunk-CZFXGGEK.js → chunk-U66GUVSG.js} +2 -2
  29. package/dist/{chunk-KDR2VAJP.js → chunk-UYVJZR33.js} +2 -2
  30. package/dist/chunk-UZ765UGH.js +18 -0
  31. package/dist/{chunk-GKIFABGN.js → chunk-VBYOAT46.js} +100 -277
  32. package/dist/{chunk-QYPMPWVX.js → chunk-XVZ4YOF2.js} +43 -43
  33. package/dist/{chunk-3KLC4AMA.js → chunk-ZQ3IPCI6.js} +177 -176
  34. package/dist/chunk-ZXGBDLVB.js +1510 -0
  35. package/dist/{client-B-hbHX30.d.ts → client-D7IiwEq2.d.ts} +31 -62
  36. package/dist/{capability-error-DFMwSuSf.d.ts → dashboards-pVfclkyh.d.ts} +14 -294
  37. package/dist/{deployments-M4OHn7G3.d.ts → deployments-Cr1tfqrr.d.ts} +46 -3
  38. package/dist/{identity-integration-3mX6b5iH.d.ts → identity-integration-Ci2vGKtX.d.ts} +67 -2
  39. package/dist/index.d.ts +11 -11
  40. package/dist/index.js +11 -13
  41. package/dist/internal.d.ts +27 -13
  42. package/dist/internal.js +46 -13
  43. package/dist/{analytics-BwAKLi7O.d.ts → limits-pE04y9O2.d.ts} +131 -3
  44. package/dist/{offers-DhAtss4_.d.ts → offers-Hw2P6tcK.d.ts} +3 -2
  45. package/dist/{participant-activity-D-Drp24G.d.ts → participant-activity-DXRq4s6K.d.ts} +1 -0
  46. package/dist/portal-proxy.d.ts +21 -3
  47. package/dist/portal-proxy.js +72 -22
  48. package/dist/react/index.d.ts +29 -15
  49. package/dist/react/index.js +52 -29
  50. package/dist/{pages-B8q8Y_dQ.d.ts → reward-deliveries-BCV8hznc.d.ts} +300 -233
  51. package/dist/runtime/authoring.js +1 -1
  52. package/dist/runtime/chunks/6EBN6IZU.js +1 -0
  53. package/dist/runtime/manifest.json +3 -3
  54. package/dist/runtime/schema.js +1 -1
  55. package/dist/schema.d.ts +197 -19
  56. package/dist/schema.js +126 -124
  57. package/dist/server/index.d.ts +13 -13
  58. package/dist/server/index.js +5701 -6302
  59. package/dist/{sign-in-providers-BkjcDsFF.d.ts → sign-in-providers-BAkGjSXo.d.ts} +7 -2
  60. package/dist/{submission-input-DHGKhXfp.d.ts → submission-input-ChL1aYNH.d.ts} +3 -2
  61. package/dist/{telegram-browser-BCE7zdOb.d.ts → telegram-browser-K27t4TwM.d.ts} +5 -5
  62. package/dist/telegram.d.ts +9 -9
  63. package/dist/telegram.js +2 -2
  64. package/dist/testing.d.ts +229 -27
  65. package/dist/testing.js +146 -105
  66. package/dist/{tracker-data-Hb1uQnk5.d.ts → tracker-data-Bl-qPIvZ.d.ts} +37 -9
  67. package/dist/{transport-DkhX2Cbs.d.ts → transport-DC1m73Tp.d.ts} +40211 -37736
  68. package/dist/{wallet-DTO7SXj7.d.ts → wallet-B7e06v4m.d.ts} +14 -4
  69. package/package.json +1 -1
  70. package/dist/chunk-D26YNACF.js +0 -320
  71. package/dist/chunk-UAKYDVT3.js +0 -565
  72. package/dist/chunk-WSBYWVTZ.js +0 -717
  73. package/dist/chunk-XJFYAXET.js +0 -87
  74. package/dist/runtime/chunks/Y4OAVXFR.js +0 -1
@@ -5,7 +5,7 @@ import {
5
5
  isKnownTrackerSource,
6
6
  trackerDataSchema,
7
7
  xAccountRoles
8
- } from "./chunk-MK425RXJ.js";
8
+ } from "./chunk-HNR6G3GV.js";
9
9
 
10
10
  // src/quest-shape.ts
11
11
  function validateQuestShape(description, options = {}) {
@@ -83,7 +83,7 @@ function sourceRoles(source) {
83
83
  return ["author", ...source.accounts ?? []];
84
84
  }
85
85
  }
86
- var discordSchemas = /* @__PURE__ */ new Map();
86
+ var discordSchemas = /* @__PURE__ */ (() => /* @__PURE__ */ new Map())();
87
87
  function discordDataSchema(source) {
88
88
  const key = source.kind === "discord-messages" && source.text ? "messages-text" : source.kind;
89
89
  let schema = discordSchemas.get(key);
@@ -110,10 +110,10 @@ function participantRoutePattern(path) {
110
110
  });
111
111
  return new RegExp("^" + source.join("") + "$");
112
112
  }
113
- var compiled = participantRoutes.map((route) => ({
113
+ var compiled = /* @__PURE__ */ (() => participantRoutes.map((route) => ({
114
114
  ...route,
115
115
  pattern: participantRoutePattern(route.path)
116
- }));
116
+ })))();
117
117
  function isParticipantRoute(path, method) {
118
118
  return compiled.some(
119
119
  (route) => route.method === method && route.pattern.test(path)
@@ -1,10 +1,10 @@
1
1
  // src/host-environment.ts
2
2
  import * as z from "zod";
3
3
  var hostEnvironmentPath = "/__domino/environment";
4
- var hostEnvironmentSchema = z.object({
4
+ var hostEnvironmentSchema = /* @__PURE__ */ (() => z.object({
5
5
  environment: z.enum(["test", "live"]),
6
6
  kind: z.enum(["staging", "preview", "live"])
7
- });
7
+ }))();
8
8
  var pending;
9
9
  async function readHostEnvironment() {
10
10
  try {
@@ -0,0 +1,18 @@
1
+ // src/origins.ts
2
+ var loopbackHosts = [
3
+ "localhost",
4
+ "127.0.0.1",
5
+ "[::1]"
6
+ ];
7
+ function secureOrLoopbackOrigin(url, options = {}) {
8
+ return url.protocol === "https:" || url.protocol === "http:" && (loopbackHosts.includes(url.hostname) || (options.localHosts ?? []).includes(url.hostname));
9
+ }
10
+ function bareOrigin(url) {
11
+ return !url.username && !url.password && !url.search && !url.hash && url.pathname === "/";
12
+ }
13
+
14
+ export {
15
+ loopbackHosts,
16
+ secureOrLoopbackOrigin,
17
+ bareOrigin
18
+ };
@@ -1,10 +1,21 @@
1
1
  import {
2
2
  createRelayAction,
3
3
  withActionId
4
- } from "./chunk-Y322OTCH.js";
4
+ } from "./chunk-E22XSC4L.js";
5
5
  import {
6
6
  setPluginTransport
7
- } from "./chunk-6WCIWXUV.js";
7
+ } from "./chunk-EUEW2APU.js";
8
+ import {
9
+ createHttpExchange,
10
+ untilAborted,
11
+ withQuery
12
+ } from "./chunk-7H4MRVQF.js";
13
+ import {
14
+ PARTICIPANT_TIMEOUT,
15
+ lifetime,
16
+ retrying,
17
+ validTimeout
18
+ } from "./chunk-DLABJSBO.js";
8
19
  import {
9
20
  authProvidersSchema,
10
21
  collectionPassSchema,
@@ -23,12 +34,17 @@ import {
23
34
  questOutcomeSchema,
24
35
  rewardDeliveriesSchema,
25
36
  rewardDeliveryQuerySchema
26
- } from "./chunk-CICDIBOF.js";
37
+ } from "./chunk-MPTE7EIV.js";
27
38
  import {
39
+ exchangeResultSchema,
40
+ exchangeSchema,
41
+ memberSummarySchema,
28
42
  participantActivityQuerySchema,
29
43
  participantActivitySchema,
30
- questExperienceSchema
31
- } from "./chunk-D26YNACF.js";
44
+ participantSessionSchema,
45
+ questExperienceSchema,
46
+ sessionMember
47
+ } from "./chunk-R2KZFX6E.js";
32
48
  import {
33
49
  engagementBoundaryPageSchema,
34
50
  engagementPageQuerySchema,
@@ -39,20 +55,36 @@ import {
39
55
  referralDefinitionSchema,
40
56
  referralHistorySchema,
41
57
  referralSummarySchema
42
- } from "./chunk-GTDW453U.js";
58
+ } from "./chunk-NG4GZ54I.js";
43
59
  import {
44
60
  AVATAR_UPLOAD_LIMIT,
61
+ accountConnectionSchema,
62
+ attemptSchema,
45
63
  avatarUploadTypes,
46
64
  badgeCatalogSchema,
47
65
  badgeSchema,
66
+ campaignEnrollmentInputSchema,
67
+ campaignEnrollmentSchema,
68
+ campaignWithdrawalInputSchema,
69
+ contentPerformancePageSchema,
70
+ contentPerformanceQuerySchema,
71
+ contentQualificationPageSchema,
72
+ contentQualificationQuerySchema,
73
+ evidenceSchema,
74
+ identifier,
75
+ knownResponse,
48
76
  leaderboardDefinitionResponseSchema,
49
77
  leaderboardHistoryPageSchema,
50
78
  leaderboardHistoryQuerySchema,
51
79
  leaderboardPageSchema,
52
80
  leaderboardPlacementSchema,
53
81
  leaderboardQuerySchema,
82
+ linkedWalletSchema,
54
83
  memberBadgesSchema,
84
+ memberProgressSchema,
85
+ missingPrerequisiteSchema,
55
86
  ownProfileSchema,
87
+ pageQuerySchema,
56
88
  pointBalancesSchema,
57
89
  pointHistoryPageSchema,
58
90
  pointHistoryQuerySchema,
@@ -61,40 +93,7 @@ import {
61
93
  profileCompletionQuerySchema,
62
94
  profileReferralSchema,
63
95
  profileSummarySchema,
64
- profileUpdateSchema
65
- } from "./chunk-WSBYWVTZ.js";
66
- import {
67
- PARTICIPANT_TIMEOUT,
68
- clientIdentity,
69
- lifetime,
70
- retryAfter,
71
- retrying,
72
- validTimeout
73
- } from "./chunk-3PYYGFSB.js";
74
- import {
75
- exchangeResultSchema,
76
- exchangeSchema,
77
- memberSummarySchema,
78
- participantSessionSchema,
79
- sessionMember
80
- } from "./chunk-XJFYAXET.js";
81
- import {
82
- accountConnectionSchema,
83
- attemptSchema,
84
- campaignEnrollmentInputSchema,
85
- campaignEnrollmentSchema,
86
- campaignWithdrawalInputSchema,
87
- contentPerformancePageSchema,
88
- contentPerformanceQuerySchema,
89
- contentQualificationPageSchema,
90
- contentQualificationQuerySchema,
91
- evidenceSchema,
92
- identifier,
93
- knownResponse,
94
- linkedWalletSchema,
95
- memberProgressSchema,
96
- missingPrerequisiteSchema,
97
- pageQuerySchema,
96
+ profileUpdateSchema,
98
97
  questSubmissionResultSchema,
99
98
  questSubmissionSchema,
100
99
  quizEvidenceSchema,
@@ -112,7 +111,7 @@ import {
112
111
  walletMessageChallengeSchema,
113
112
  walletSignatureSchema,
114
113
  walletUnlinkInputSchema
115
- } from "./chunk-MK425RXJ.js";
114
+ } from "./chunk-HNR6G3GV.js";
116
115
  import {
117
116
  RelayError,
118
117
  RelayErrorCode,
@@ -120,24 +119,24 @@ import {
120
119
  isRelayError,
121
120
  isRequestError,
122
121
  parseInput
123
- } from "./chunk-K2KS3JLY.js";
122
+ } from "./chunk-EOUEAOWJ.js";
124
123
 
125
124
  // src/legacy-submissions.ts
126
125
  import * as z from "zod";
127
- var common = {
126
+ var common = /* @__PURE__ */ (() => ({
128
127
  id: identifier,
129
128
  quest: identifier,
130
129
  release: identifier.optional()
131
- };
132
- var claimInputSchema = z.union([
130
+ }))();
131
+ var claimInputSchema = /* @__PURE__ */ (() => z.union([
133
132
  submissionEvidenceSchema,
134
133
  z.object({ kind: z.literal("none") }).strict()
135
- ]);
136
- var draftSchema = z.union([
134
+ ]))();
135
+ var draftSchema = /* @__PURE__ */ (() => z.union([
137
136
  claimInputSchema,
138
137
  z.object({ kind: z.literal("photo"), file: z.instanceof(Blob) })
139
- ]);
140
- var activeRecordSchema = z.union([
138
+ ]))();
139
+ var activeRecordSchema = /* @__PURE__ */ (() => z.union([
141
140
  z.object({
142
141
  ...common,
143
142
  stage: z.literal("review"),
@@ -163,15 +162,15 @@ var activeRecordSchema = z.union([
163
162
  input: claimInputSchema,
164
163
  attempt: identifier
165
164
  })
166
- ]);
167
- var recordSchema = z.union([
165
+ ]))();
166
+ var recordSchema = /* @__PURE__ */ (() => z.union([
168
167
  activeRecordSchema,
169
168
  z.object({
170
169
  ...common,
171
170
  stage: z.literal("retired"),
172
171
  previous: activeRecordSchema
173
172
  })
174
- ]);
173
+ ]))();
175
174
  function legacySubmissions(transport, configuredStore, namespace) {
176
175
  async function open(quest, options = {
177
176
  input: "photo"
@@ -806,7 +805,7 @@ import * as z2 from "zod";
806
805
 
807
806
  // src/progress.ts
808
807
  function sessionEnded(error) {
809
- return isRequestError(error) && (error.code === RelayErrorCode.StaleSession || error.code === RelayErrorCode.NotSignedIn);
808
+ return isRequestError(error) && (error.code === RelayErrorCode.StaleSession || error.code === RelayErrorCode.NotSignedIn || error.code === RelayErrorCode.Unauthenticated);
810
809
  }
811
810
  function observeProgress(transport, listener, options = {}, onDispose = () => {
812
811
  }) {
@@ -1121,14 +1120,14 @@ function questActions(submission, latest) {
1121
1120
  }
1122
1121
 
1123
1122
  // src/client.ts
1124
- var authStartSchema = z2.strictObject({
1123
+ var authStartSchema = /* @__PURE__ */ (() => z2.strictObject({
1125
1124
  provider: signInProviderInputSchema,
1126
1125
  mode: z2.enum(["sign-in", "connect"])
1127
- });
1128
- var emailVerificationSchema = z2.strictObject({
1126
+ }))();
1127
+ var emailVerificationSchema = /* @__PURE__ */ (() => z2.strictObject({
1129
1128
  challenge: z2.string().min(1).max(200),
1130
1129
  code: z2.string().transform((code) => code.trim()).pipe(z2.string().regex(/^\d{6}$/, "Enter the 6-digit code"))
1131
- });
1130
+ }))();
1132
1131
  function errorBody(value) {
1133
1132
  const body = value !== null && typeof value === "object" ? value : {};
1134
1133
  const window = body.window === "tracker" ? "tracker" : body.window === "quest" ? "quest" : void 0;
@@ -1144,24 +1143,16 @@ function errorBody(value) {
1144
1143
  };
1145
1144
  }
1146
1145
  async function fromSigner(step, signal) {
1147
- let stop;
1148
1146
  try {
1149
- return await new Promise((resolve, reject) => {
1150
- stop = () => reject(
1151
- new RelayError("The request was cancelled", {
1152
- kind: "aborted",
1153
- code: RelayErrorCode.Aborted,
1154
- cause: signal?.reason
1155
- })
1156
- );
1157
- if (signal?.aborted) {
1158
- stop();
1159
- return;
1160
- }
1161
- signal?.addEventListener("abort", stop, { once: true });
1162
- step().then(resolve, reject);
1163
- });
1147
+ return await untilAborted(step, signal);
1164
1148
  } catch (error) {
1149
+ if (signal?.aborted && error === signal.reason) {
1150
+ throw new RelayError("The request was cancelled", {
1151
+ kind: "aborted",
1152
+ code: RelayErrorCode.Aborted,
1153
+ cause: error
1154
+ });
1155
+ }
1165
1156
  if (error instanceof RelayError) {
1166
1157
  throw error;
1167
1158
  }
@@ -1170,59 +1161,13 @@ async function fromSigner(step, signal) {
1170
1161
  RelayErrorCode.WalletSigner,
1171
1162
  { cause: error }
1172
1163
  );
1173
- } finally {
1174
- if (stop) {
1175
- signal?.removeEventListener("abort", stop);
1176
- }
1177
1164
  }
1178
1165
  }
1179
1166
  var invalidTimeout = () => clientError(
1180
1167
  "timeout must be a positive, finite number of milliseconds",
1181
1168
  RelayErrorCode.InvalidInput
1182
1169
  );
1183
- var uncertainStatuses = /* @__PURE__ */ new Set([500, 502, 504]);
1184
1170
  var methodOf = (call) => call.method ?? (call.json === void 0 ? "GET" : "POST");
1185
- function withQuery(path, values) {
1186
- const params = new URLSearchParams();
1187
- for (const [key, value] of Object.entries(values)) {
1188
- if (value !== void 0) {
1189
- params.set(key, String(value));
1190
- }
1191
- }
1192
- const search = params.toString();
1193
- return search ? path + "?" + search : path;
1194
- }
1195
- function interrupted(call, life, error, stage) {
1196
- const details = {
1197
- status: stage.status,
1198
- retryAfter: stage.headers ? retryAfter(stage.headers) : void 0,
1199
- operationId: call.operationId,
1200
- replaySafe: call.replaySafe,
1201
- uncertain: stage.sent && methodOf(call) !== "GET" && // An error status whose body broke off still refused the write, unless the status itself
1202
- // does not prove that (500, 502, 504).
1203
- (!stage.refused || uncertainStatuses.has(stage.status ?? 0)),
1204
- cause: error
1205
- };
1206
- const ended = life.ended();
1207
- if (ended === "aborted") {
1208
- return new RelayError("The request was cancelled", {
1209
- ...details,
1210
- kind: "aborted",
1211
- code: RelayErrorCode.Aborted
1212
- });
1213
- }
1214
- if (ended === "timeout") {
1215
- return new RelayError(`Relay did not respond within ${life.timeout} ms`, {
1216
- ...details,
1217
- kind: "timeout",
1218
- code: RelayErrorCode.Timeout
1219
- });
1220
- }
1221
- return new RelayError(
1222
- stage.status === void 0 ? "Could not reach Relay" : "Relay's response was cut off",
1223
- { ...details, kind: "network", code: RelayErrorCode.Network }
1224
- );
1225
- }
1226
1171
  function createRelayClient(options) {
1227
1172
  return relayClient(options);
1228
1173
  }
@@ -1236,158 +1181,28 @@ function relayClient(options) {
1236
1181
  RelayErrorCode.InvalidInput
1237
1182
  );
1238
1183
  }
1239
- try {
1240
- const headers = new Headers(options.headers);
1241
- if (options.token) {
1242
- headers.set("Authorization", `Bearer ${options.token}`);
1243
- }
1244
- headers.set("X-Relay-Organization", options.organization ?? "");
1245
- headers.set("X-Relay-Project", options.project ?? "");
1246
- } catch (error) {
1247
- throw clientError(
1248
- "headers, token, organization and project must be valid HTTP header values",
1249
- RelayErrorCode.InvalidInput,
1250
- { cause: error }
1251
- );
1252
- }
1253
1184
  const clientTimeout = options.timeout ?? PARTICIPANT_TIMEOUT;
1254
- async function credential(call, life) {
1255
- if (!options.getToken) {
1256
- return options.token;
1257
- }
1258
- const getToken = options.getToken;
1259
- try {
1260
- return await new Promise((resolve, reject) => {
1261
- const stop = () => reject(life.signal.reason);
1262
- life.signal.addEventListener("abort", stop, { once: true });
1263
- getToken().then(resolve, reject).finally(() => life.signal.removeEventListener("abort", stop));
1264
- });
1265
- } catch (error) {
1266
- if (life.signal.aborted) {
1267
- throw interrupted(call, life, error, { sent: false });
1268
- }
1269
- throw new RelayError("Could not get a Relay credential", {
1270
- // A token source that could not reach its own service failed like a network call.
1271
- kind: error instanceof TypeError ? "network" : "client",
1272
- code: RelayErrorCode.Credential,
1273
- operationId: call.operationId,
1274
- replaySafe: call.replaySafe,
1275
- cause: error
1276
- });
1277
- }
1278
- }
1279
- async function send(path, call, life) {
1280
- if (life.signal.aborted) {
1281
- throw interrupted(call, life, life.reason(), { sent: false });
1282
- }
1283
- const method = methodOf(call);
1284
- const token = await credential(call, life);
1285
- let headers;
1286
- let body2 = call.body;
1287
- try {
1288
- headers = new Headers(options.headers);
1289
- new Headers(call.headers).forEach(
1290
- (value, name) => headers.set(name, value)
1291
- );
1292
- headers.set("X-Domino-Client", clientIdentity());
1293
- if (token) {
1294
- try {
1295
- headers.set("Authorization", `Bearer ${token}`);
1296
- } catch (error) {
1297
- throw new RelayError(
1298
- "getToken returned a value that is not a token",
1299
- {
1300
- kind: "client",
1301
- code: RelayErrorCode.Credential,
1302
- operationId: call.operationId,
1303
- replaySafe: call.replaySafe,
1304
- cause: error
1305
- }
1306
- );
1307
- }
1308
- } else if (options.getToken) {
1309
- headers.delete("Authorization");
1310
- }
1311
- if (options.organization) {
1312
- headers.set("X-Relay-Organization", options.organization);
1313
- }
1314
- if (options.project) {
1315
- headers.set("X-Relay-Project", options.project);
1316
- }
1317
- if (options.environment) {
1318
- headers.set("X-Relay-Environment", options.environment);
1319
- }
1320
- if (call.options?.session) {
1321
- headers.set("X-Relay-Session", call.options.session);
1322
- }
1323
- if (call.json !== void 0) {
1324
- headers.set("Content-Type", "application/json");
1325
- body2 = JSON.stringify(call.json);
1326
- }
1327
- if (method !== "GET") {
1328
- headers.set("X-Relay-CSRF", "1");
1329
- }
1330
- } catch (error) {
1331
- if (isRelayError(error)) {
1332
- throw error;
1333
- }
1334
- throw clientError(
1335
- "The request has a header or body that cannot be sent",
1336
- RelayErrorCode.InvalidInput,
1337
- {
1338
- operationId: call.operationId,
1339
- replaySafe: call.replaySafe,
1340
- cause: error
1341
- }
1342
- );
1343
- }
1344
- if (life.signal.aborted) {
1345
- throw interrupted(call, life, life.reason(), { sent: false });
1346
- }
1347
- let response;
1348
- try {
1349
- response = await (options.fetch ?? fetch)(options.baseUrl + path, {
1350
- method,
1351
- headers,
1352
- body: body2,
1353
- signal: life.signal
1354
- });
1355
- } catch (error) {
1356
- throw interrupted(call, life, error, { sent: true });
1357
- }
1358
- if (!response.ok) {
1359
- let text;
1360
- try {
1361
- text = await response.text();
1362
- } catch (error) {
1363
- throw interrupted(call, life, error, {
1364
- sent: true,
1365
- status: response.status,
1366
- headers: response.headers,
1367
- refused: true
1368
- });
1369
- }
1370
- let value = null;
1371
- try {
1372
- value = JSON.parse(text);
1373
- } catch {
1374
- }
1375
- const { message, code, window, missing, retryAt } = errorBody(value);
1376
- throw new RelayError(message ?? `Request failed (${response.status})`, {
1377
- kind: "http",
1378
- status: response.status,
1379
- code,
1380
- window,
1381
- missing,
1382
- ...retryAt === void 0 ? {} : { retryAt },
1383
- operationId: call.operationId,
1384
- replaySafe: call.replaySafe,
1385
- uncertain: methodOf(call) !== "GET" && uncertainStatuses.has(response.status),
1386
- retryAfter: retryAfter(response.headers)
1387
- });
1388
- }
1389
- return response;
1390
- }
1185
+ const http = createHttpExchange(options, {
1186
+ csrf: true,
1187
+ session: (call) => call.options?.session,
1188
+ messages: {
1189
+ aborted: "The request was cancelled",
1190
+ timeout: (milliseconds) => `Relay did not respond within ${milliseconds} ms`,
1191
+ network: (status) => status === void 0 ? "Could not reach Relay" : "Relay's response was cut off",
1192
+ credential: "Could not get a Relay credential",
1193
+ invalidToken: "getToken returned a value that is not a token",
1194
+ invalidOptions: "headers, token, organization and project must be valid HTTP header values",
1195
+ unsendable: "The request has a header or body that cannot be sent"
1196
+ },
1197
+ // Unlike the management client's, a write that failed to connect stays uncertain: this client
1198
+ // does not read the socket error that would prove it was never sent.
1199
+ makeError: (message, details, call) => new RelayError(message, {
1200
+ ...details,
1201
+ operationId: call?.operationId,
1202
+ replaySafe: call?.replaySafe
1203
+ }),
1204
+ parseRefusal: errorBody
1205
+ });
1391
1206
  async function exchange(path, call, receive) {
1392
1207
  const timeout = call.options?.timeout ?? clientTimeout;
1393
1208
  if (!validTimeout(timeout)) {
@@ -1400,7 +1215,7 @@ function relayClient(options) {
1400
1215
  {
1401
1216
  replaySafe: methodOf(call) === "GET" || (call.replaySafe ?? call.operationId !== void 0)
1402
1217
  },
1403
- async () => receive(await send(path, call, life), life)
1218
+ async () => receive(await http.send(path, call, call, life), life)
1404
1219
  );
1405
1220
  } finally {
1406
1221
  life.end();
@@ -1410,7 +1225,7 @@ function relayClient(options) {
1410
1225
  try {
1411
1226
  return await reader(response);
1412
1227
  } catch (error) {
1413
- throw interrupted(call, life, error, {
1228
+ throw http.interrupted(error, methodOf(call), call, life, {
1414
1229
  sent: true,
1415
1230
  status: response.status,
1416
1231
  headers: response.headers
@@ -1869,7 +1684,8 @@ function relayClient(options) {
1869
1684
  * Claims one of the signed-in member's outcomes skipped as `historical`, on a quest whose
1870
1685
  * historical policy is `"claim"` (`outcome.claimable`). Relay decides it again with
1871
1686
  * historical activity released and returns the outcome; a rule that still fails rejects
1872
- * with a `RelayError` whose code is that rule's skip code.
1687
+ * with a `RelayError` whose code is that rule's skip code. This claim is of a skipped
1688
+ * outcome; `me.claim` submits an attempt.
1873
1689
  */
1874
1690
  claim: async (value, requestOptions) => {
1875
1691
  const body2 = parseInput(questClaimInputSchema, withActionId(value));
@@ -2344,11 +2160,13 @@ function relayClient(options) {
2344
2160
  }),
2345
2161
  /**
2346
2162
  * The member's reward deliveries, newest first, one page at a time. Pass a page's
2347
- * `nextCursor` back as `cursor` for older ones; `limit` is 1 to 500, 500 by default.
2163
+ * `nextCursor` back as `cursor` for older ones; `limit` is 1 to 500, 500 by default. The
2164
+ * page answers its deliveries as `items` (and, for 1.x callers, as `deliveries`), so
2165
+ * `paginate((cursor) => relay.me.rewardDeliveries({ cursor }))` reads them all.
2348
2166
  */
2349
- rewardDeliveries: (requestOptions = {}) => {
2167
+ rewardDeliveries: async (requestOptions = {}) => {
2350
2168
  const { cursor, limit, ...options2 } = requestOptions;
2351
- return request(
2169
+ const page = await request(
2352
2170
  withQuery(
2353
2171
  "/v1/reward-deliveries",
2354
2172
  parseInput(rewardDeliveryQuerySchema, { cursor, limit })
@@ -2356,6 +2174,7 @@ function relayClient(options) {
2356
2174
  rewardDeliveriesSchema,
2357
2175
  { options: options2 }
2358
2176
  );
2177
+ return { ...page, items: page.items ?? page.deliveries };
2359
2178
  },
2360
2179
  /**
2361
2180
  * `{ items }`: the member's balance in each of the project's point ledgers, in the project's
@@ -2388,7 +2207,11 @@ function relayClient(options) {
2388
2207
  { options: requestOptions }
2389
2208
  );
2390
2209
  },
2391
- /** Claims a quest for the signed-in member. Quest controllers (`quests.open`) call this. */
2210
+ /**
2211
+ * Submits an attempt at a quest for the signed-in member, whatever input the quest takes;
2212
+ * a quest whose interaction is `"claim"` takes none. Quest controllers (`quests.open`) call
2213
+ * this. `quests.claim` is different: it claims an outcome skipped as historical.
2214
+ */
2392
2215
  claim: async (value, requestOptions) => {
2393
2216
  const claim = parseInput(
2394
2217
  submitSchema.omit({ member: true }),