@domino-sdk/relay 1.7.0 → 1.9.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.
- package/dist/action-9Xl0StBg.d.ts +33 -0
- package/dist/{activity-Br6vyYze.d.ts → activity-CCe1e_7a.d.ts} +115 -115
- package/dist/authoring.d.ts +45 -45
- package/dist/authoring.js +1 -1
- package/dist/{automatic-outcomes-C1Q9LrDb.d.ts → automatic-outcomes-Dyk0VTUs.d.ts} +1 -1
- package/dist/browser.d.ts +7 -6
- package/dist/browser.js +5 -4
- package/dist/{chunk-C25TDFHN.js → chunk-2N464DDE.js} +1 -1
- package/dist/{chunk-GMPPLZKH.js → chunk-2V74CHDL.js} +191 -191
- package/dist/{chunk-6RBF3UDA.js → chunk-734LYHWP.js} +2 -2
- package/dist/chunk-ETPL6AAJ.js +98 -0
- package/dist/{chunk-ZOUEEK5L.js → chunk-FWSSMSIA.js} +49 -21
- package/dist/{chunk-BFZHJA2B.js → chunk-L3QFIRGO.js} +2 -2
- package/dist/{client-pfml_XAa.d.ts → client-CbASImpi.d.ts} +42 -36
- package/dist/{groups-BpWEqaPn.d.ts → groups-Dvmd4CYk.d.ts} +1 -1
- package/dist/{images-BaKYd0fl.d.ts → images-Dekv3DYF.d.ts} +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +7 -3
- package/dist/internal.d.ts +3 -3
- package/dist/{offers-CYtal8jO.d.ts → offers-BEGVSOTD.d.ts} +2 -2
- package/dist/{pages-CixTNnF4.d.ts → pages-HmS6eedC.d.ts} +38 -38
- package/dist/react/index.d.ts +197 -10
- package/dist/react/index.js +253 -111
- package/dist/{referral-reward-kinds-ClxAuCGx.d.ts → referral-reward-kinds-Flbb1D2q.d.ts} +2 -2
- package/dist/schema.d.ts +8 -8
- package/dist/schema.js +3 -3
- package/dist/server/index.d.ts +592 -46
- package/dist/server/index.js +166 -43
- package/dist/{sign-in-options-CtXUFV7E.d.ts → sign-in-options-z3wsfizk.d.ts} +2 -2
- package/dist/{submission-input-CLefHTrj.d.ts → submission-input-Bs14jIsu.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/{schema-CQydLqw4.d.ts → schema-BCuiO7eD.d.ts} +15 -15
|
@@ -16,37 +16,159 @@ import {
|
|
|
16
16
|
tierRewardSchema
|
|
17
17
|
} from "./chunk-KGJSKGKI.js";
|
|
18
18
|
|
|
19
|
-
// src/
|
|
19
|
+
// src/errors.ts
|
|
20
20
|
import { z } from "zod";
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
var RelayErrorCode = {
|
|
22
|
+
/** The call needs a signed-in member. */
|
|
23
|
+
NotSignedIn: "not-signed-in",
|
|
24
|
+
/** The session changed since the app read it (the `session` option). Reload before retrying. */
|
|
25
|
+
StaleSession: "stale-session",
|
|
26
|
+
/** The input failed validation before it was sent. */
|
|
27
|
+
InvalidInput: "invalid-input",
|
|
28
|
+
/** Relay's answer was not JSON or not the expected shape (kind `invalid-response`). */
|
|
29
|
+
InvalidResponse: "invalid-response",
|
|
30
|
+
/** The transport failed, before a response or while reading its body (kind `network`). */
|
|
31
|
+
Network: "network",
|
|
32
|
+
/** The client's deadline elapsed (kind `timeout`). */
|
|
33
|
+
Timeout: "timeout",
|
|
34
|
+
/** The caller cancelled the request (kind `aborted`). */
|
|
35
|
+
Aborted: "aborted",
|
|
36
|
+
/** A quest or collection the call named is not in the member's experience. */
|
|
37
|
+
NotFound: "not-found",
|
|
38
|
+
/** The quest has no failed attempt the member can retry. */
|
|
39
|
+
RetryUnavailable: "retry-unavailable",
|
|
40
|
+
/**
|
|
41
|
+
* Durable submission storage is missing, blocked or unreadable. Nothing was lost: call the
|
|
42
|
+
* handle's `status()` or `resume()` again once storage is available.
|
|
43
|
+
*/
|
|
44
|
+
SubmissionStorage: "submission-storage",
|
|
45
|
+
/** Browser storage is full, so submission progress was not saved. Free space, then resume. */
|
|
46
|
+
SubmissionStorageQuota: "submission-storage-quota",
|
|
47
|
+
/** The saved submission is in a state that does not allow this action. */
|
|
48
|
+
SubmissionConflict: "submission-conflict",
|
|
49
|
+
/** The quest changed since the member saw it; review it before submitting again. */
|
|
50
|
+
QuestUpdated: "quest-updated",
|
|
51
|
+
/** Wait for the deferred attempt before submitting another action. */
|
|
52
|
+
AttemptPending: "attempt-pending",
|
|
53
|
+
/** The quiz changed since the member answered it. */
|
|
54
|
+
StaleQuiz: "stale-quiz",
|
|
55
|
+
/** Relay refused the submitted evidence. */
|
|
56
|
+
InvalidSubmission: "invalid-submission",
|
|
57
|
+
/** A page cursor Relay cannot read; start again from the first page. */
|
|
58
|
+
InvalidCursor: "invalid-cursor",
|
|
59
|
+
/** No point ledger in the project has the key or ID the call named. */
|
|
60
|
+
PointLedgerNotFound: "point-ledger-not-found",
|
|
61
|
+
/** The member has not joined this project, so it holds no points here. */
|
|
62
|
+
NotJoined: "not-joined",
|
|
63
|
+
/** The quest or campaign is not open at this time. */
|
|
64
|
+
OutsideWindow: "outside-window",
|
|
65
|
+
/** The signed-in member must enroll in the campaign first. */
|
|
66
|
+
EnrollmentRequired: "enrollment-required",
|
|
67
|
+
/** The quest's current reward budget has no remaining capacity. */
|
|
68
|
+
BudgetExhausted: "budget-exhausted",
|
|
69
|
+
/** No published offer has the key or ID the call named. */
|
|
70
|
+
OfferNotFound: "offer-not-found",
|
|
71
|
+
/** The operator paused this offer. */
|
|
72
|
+
OfferPaused: "offer-paused",
|
|
73
|
+
/** This member has already used the offer's allowed number of redemptions. */
|
|
74
|
+
OfferLimitReached: "offer-limit-reached",
|
|
75
|
+
/** No declared units remain. */
|
|
76
|
+
OfferOutOfStock: "offer-out-of-stock",
|
|
77
|
+
/** The participant's available point balance is below the offer price. */
|
|
78
|
+
InsufficientPoints: "insufficient-points",
|
|
79
|
+
/** A wallet signer failed or the member refused to sign; `cause` is the wallet's own error. */
|
|
80
|
+
WalletSigner: "wallet-signer",
|
|
81
|
+
/** The member has not met the quest's prerequisites; `missing` lists them. */
|
|
82
|
+
PrerequisitesIncomplete: "prerequisites-incomplete",
|
|
83
|
+
/** The quest is archived or retired: it takes no new participation. */
|
|
84
|
+
QuestClosed: "quest-closed",
|
|
85
|
+
/** An operator paused the quest. */
|
|
86
|
+
QuestPaused: "quest-paused",
|
|
87
|
+
/** An operator locked the member's profile; hiding it is still allowed. */
|
|
88
|
+
ProfileLocked: "profile-locked",
|
|
89
|
+
/** No member in the project has the invitation code the member accepted. */
|
|
90
|
+
InvitationNotFound: "invitation-not-found",
|
|
91
|
+
/** The email sign-in code is wrong; the member can type it again. */
|
|
92
|
+
InvalidCode: "invalid-code",
|
|
93
|
+
/** The email sign-in code expired, was used or had too many attempts; request another. */
|
|
94
|
+
CodeExpired: "code-expired",
|
|
95
|
+
/** The wallet sign-in challenge expired, was used or changed; start sign-in again. */
|
|
96
|
+
ChallengeExpired: "challenge-expired",
|
|
97
|
+
/** Too many requests; `retryAfter` says how long to wait when Relay knows. */
|
|
98
|
+
RateLimited: "rate-limited"
|
|
99
|
+
};
|
|
100
|
+
var relayErrorBrand = /* @__PURE__ */ Symbol.for("@domino-sdk/relay.RelayError");
|
|
101
|
+
function isRelayError(value) {
|
|
102
|
+
return isRequestError(value) && value[relayErrorBrand] === true;
|
|
103
|
+
}
|
|
104
|
+
var RelayError = class extends RequestError {
|
|
105
|
+
name = "RelayError";
|
|
106
|
+
[relayErrorBrand] = true;
|
|
107
|
+
/** Which window refused admission when `code` is `outside-window`. */
|
|
108
|
+
window;
|
|
109
|
+
/** Prerequisites the member does not currently meet, when Relay refused for that reason. */
|
|
110
|
+
missing;
|
|
111
|
+
constructor(message, details) {
|
|
112
|
+
super(message, details);
|
|
113
|
+
this.window = details.window;
|
|
114
|
+
this.missing = details.missing ?? [];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function asRelayError(cause, fallback = "Request failed") {
|
|
118
|
+
if (isRelayError(cause)) {
|
|
119
|
+
return cause;
|
|
120
|
+
}
|
|
121
|
+
return new RelayError(
|
|
122
|
+
cause instanceof Error && cause.message ? cause.message : fallback,
|
|
123
|
+
{ kind: "client", cause }
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function clientError(message, code, details = {}) {
|
|
127
|
+
return new RelayError(message, { ...details, kind: "client", code });
|
|
128
|
+
}
|
|
129
|
+
function parseInput(schema, value) {
|
|
130
|
+
const parsed = schema.safeParse(value);
|
|
131
|
+
if (!parsed.success) {
|
|
132
|
+
throw clientError(
|
|
133
|
+
z.prettifyError(parsed.error),
|
|
134
|
+
RelayErrorCode.InvalidInput,
|
|
135
|
+
{ cause: parsed.error }
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return parsed.data;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/point-ledgers.ts
|
|
142
|
+
import { z as z2 } from "zod";
|
|
143
|
+
var pointLedgerPropertiesSchema = z2.object({
|
|
144
|
+
name: z2.string().trim().min(1).max(120),
|
|
145
|
+
description: z2.string().trim().max(1e3).default("")
|
|
24
146
|
}).strict();
|
|
25
147
|
var createPointLedgerSchema = pointLedgerPropertiesSchema.extend({ actionId: identifier, key: identifier.optional() }).strict();
|
|
26
148
|
var pointLedgerSchema = pointLedgerPropertiesSchema.extend({
|
|
27
149
|
id: identifier
|
|
28
150
|
});
|
|
29
151
|
var managedPointLedgerSchema = pointLedgerSchema.extend({
|
|
30
|
-
archivedAt:
|
|
152
|
+
archivedAt: z2.number().int().nonnegative().nullable()
|
|
31
153
|
});
|
|
32
154
|
var pointLedgerDeclarationSchema = pointLedgerPropertiesSchema.extend({ key: identifier }).strict();
|
|
33
|
-
var pointLedgerArtifactSchema =
|
|
155
|
+
var pointLedgerArtifactSchema = z2.union([
|
|
34
156
|
pointLedgerDeclarationSchema,
|
|
35
|
-
|
|
157
|
+
z2.object({ code: z2.string().min(1).max(2e6) }).strict()
|
|
36
158
|
]);
|
|
37
|
-
var pointLedgerReferenceSchema =
|
|
159
|
+
var pointLedgerReferenceSchema = z2.object({
|
|
38
160
|
id: identifier,
|
|
39
161
|
key: identifier.nullable(),
|
|
40
|
-
name:
|
|
162
|
+
name: z2.string()
|
|
41
163
|
});
|
|
42
|
-
var points =
|
|
43
|
-
var pointBalanceSchema =
|
|
164
|
+
var points = z2.number().int().safe();
|
|
165
|
+
var pointBalanceSchema = z2.object({
|
|
44
166
|
ledger: pointLedgerReferenceSchema,
|
|
45
167
|
balance: points,
|
|
46
168
|
available: points
|
|
47
169
|
});
|
|
48
|
-
var pointBalancesSchema =
|
|
49
|
-
items:
|
|
170
|
+
var pointBalancesSchema = z2.object({
|
|
171
|
+
items: z2.array(pointBalanceSchema)
|
|
50
172
|
});
|
|
51
173
|
var PointEntryKind = {
|
|
52
174
|
/** Points a quest completion, an engagement settlement or an operator awarded. */
|
|
@@ -58,8 +180,8 @@ var PointEntryKind = {
|
|
|
58
180
|
/** Undoes part or all of an award or a positive adjustment (`reverses`). */
|
|
59
181
|
Reverse: "reverse"
|
|
60
182
|
};
|
|
61
|
-
var pointEntryKindSchema =
|
|
62
|
-
var pointEntrySchema =
|
|
183
|
+
var pointEntryKindSchema = z2.string().min(1).max(64);
|
|
184
|
+
var pointEntrySchema = z2.object({
|
|
63
185
|
id: identifier,
|
|
64
186
|
amount: points,
|
|
65
187
|
kind: pointEntryKindSchema,
|
|
@@ -68,64 +190,64 @@ var pointEntrySchema = z.object({
|
|
|
68
190
|
quest: identifier.nullable(),
|
|
69
191
|
reverses: identifier.nullable()
|
|
70
192
|
});
|
|
71
|
-
var pointHistoryQuerySchema =
|
|
193
|
+
var pointHistoryQuerySchema = z2.strictObject({
|
|
72
194
|
ledger: identifier,
|
|
73
195
|
cursor: pageCursorSchema.optional()
|
|
74
196
|
});
|
|
75
|
-
var pointHistoryPageSchema =
|
|
76
|
-
items:
|
|
197
|
+
var pointHistoryPageSchema = z2.object({
|
|
198
|
+
items: z2.array(pointEntrySchema),
|
|
77
199
|
nextCursor: pageCursorSchema.nullable()
|
|
78
200
|
});
|
|
79
201
|
|
|
80
202
|
// src/engagement.ts
|
|
81
|
-
import { z as
|
|
82
|
-
var amount =
|
|
83
|
-
var engagementBudgetSchema =
|
|
84
|
-
scope:
|
|
203
|
+
import { z as z3 } from "zod";
|
|
204
|
+
var amount = z3.number().int().safe().nonnegative();
|
|
205
|
+
var engagementBudgetSchema = z3.strictObject({
|
|
206
|
+
scope: z3.enum(["member", "project"]),
|
|
85
207
|
period: calendarPeriodSchema,
|
|
86
208
|
limit: amount
|
|
87
209
|
});
|
|
88
|
-
var engagementDefinitionSchema =
|
|
210
|
+
var engagementDefinitionSchema = z3.strictObject({
|
|
89
211
|
key: identifier,
|
|
90
212
|
qualifiedBy: identifier,
|
|
91
213
|
balance: identifier,
|
|
92
|
-
metrics:
|
|
214
|
+
metrics: z3.array(contentMetricSchema).min(1).max(10).refine(
|
|
93
215
|
(metrics) => new Set(metrics).size === metrics.length,
|
|
94
216
|
"Metrics must be unique"
|
|
95
217
|
),
|
|
96
|
-
baseline:
|
|
97
|
-
maxAgeMs:
|
|
98
|
-
budgets:
|
|
218
|
+
baseline: z3.literal("historical"),
|
|
219
|
+
maxAgeMs: z3.number().int().positive().max(864e5).default(36e5),
|
|
220
|
+
budgets: z3.array(engagementBudgetSchema).max(8).default([]).refine(
|
|
99
221
|
(budgets) => new Set(budgets.map((b) => b.scope + ":" + b.period)).size === budgets.length,
|
|
100
222
|
"Give each scope and period one budget"
|
|
101
223
|
)
|
|
102
224
|
});
|
|
103
|
-
var engagementScoreInputSchema =
|
|
225
|
+
var engagementScoreInputSchema = z3.strictObject({
|
|
104
226
|
metrics: contentMetricsSchema,
|
|
105
227
|
baseline: contentMetricsSchema
|
|
106
228
|
});
|
|
107
|
-
var engagementScoreSchema =
|
|
229
|
+
var engagementScoreSchema = z3.strictObject({
|
|
108
230
|
target: amount,
|
|
109
231
|
baseline: amount
|
|
110
232
|
});
|
|
111
|
-
var engagementPublishSchema =
|
|
233
|
+
var engagementPublishSchema = z3.strictObject({
|
|
112
234
|
actionId: identifier,
|
|
113
|
-
code:
|
|
235
|
+
code: z3.string().min(1).max(1e6)
|
|
114
236
|
});
|
|
115
|
-
var engagementRuleSchema =
|
|
237
|
+
var engagementRuleSchema = z3.strictObject({
|
|
116
238
|
version: identifier,
|
|
117
239
|
definition: engagementDefinitionSchema,
|
|
118
240
|
publishedAt: amount
|
|
119
241
|
});
|
|
120
|
-
var engagementPageQuerySchema =
|
|
242
|
+
var engagementPageQuerySchema = z3.strictObject({
|
|
121
243
|
rule: identifier,
|
|
122
|
-
content:
|
|
244
|
+
content: z3.string().min(1).max(256),
|
|
123
245
|
member: identifier.optional(),
|
|
124
246
|
cursor: pageCursorSchema.optional()
|
|
125
247
|
});
|
|
126
|
-
var engagementSettlementSchema =
|
|
248
|
+
var engagementSettlementSchema = z3.strictObject({
|
|
127
249
|
id: identifier,
|
|
128
|
-
day:
|
|
250
|
+
day: z3.string(),
|
|
129
251
|
observation: identifier,
|
|
130
252
|
qualification: identifier,
|
|
131
253
|
earned: amount,
|
|
@@ -135,9 +257,9 @@ var engagementSettlementSchema = z2.strictObject({
|
|
|
135
257
|
entry: identifier.nullable(),
|
|
136
258
|
createdAt: amount
|
|
137
259
|
});
|
|
138
|
-
var engagementPageSchema =
|
|
260
|
+
var engagementPageSchema = z3.strictObject({
|
|
139
261
|
rule: engagementRuleSchema,
|
|
140
|
-
account:
|
|
262
|
+
account: z3.strictObject({
|
|
141
263
|
member: identifier,
|
|
142
264
|
earned: amount,
|
|
143
265
|
accounted: amount,
|
|
@@ -148,28 +270,28 @@ var engagementPageSchema = z2.strictObject({
|
|
|
148
270
|
baseline: contentMetricsSchema,
|
|
149
271
|
observation: identifier.nullable(),
|
|
150
272
|
nextSettlementAt: amount.nullable(),
|
|
151
|
-
reason:
|
|
273
|
+
reason: z3.string().nullable()
|
|
152
274
|
}).nullable(),
|
|
153
|
-
items:
|
|
275
|
+
items: z3.array(engagementSettlementSchema),
|
|
154
276
|
nextCursor: pageCursorSchema.nullable()
|
|
155
277
|
});
|
|
156
|
-
var engagementChangePreviewInputSchema =
|
|
157
|
-
code:
|
|
278
|
+
var engagementChangePreviewInputSchema = z3.strictObject({
|
|
279
|
+
code: z3.string().min(1).max(1e6)
|
|
158
280
|
});
|
|
159
281
|
var engagementChangeSchema = engagementPublishSchema.extend({
|
|
160
282
|
expectedVersion: identifier,
|
|
161
283
|
previewHash: identifier
|
|
162
284
|
});
|
|
163
|
-
var total =
|
|
164
|
-
var engagementChangePreviewSchema =
|
|
285
|
+
var total = z3.string().regex(/^(0|[1-9][0-9]*)$/);
|
|
286
|
+
var engagementChangePreviewSchema = z3.strictObject({
|
|
165
287
|
rule: identifier,
|
|
166
288
|
fromVersion: identifier,
|
|
167
289
|
toVersion: identifier,
|
|
168
290
|
previewHash: identifier,
|
|
169
291
|
definition: engagementDefinitionSchema,
|
|
170
|
-
boundary:
|
|
171
|
-
settlement:
|
|
172
|
-
summary:
|
|
292
|
+
boundary: z3.literal("available-eligible-observation"),
|
|
293
|
+
settlement: z3.literal("deferred"),
|
|
294
|
+
summary: z3.strictObject({
|
|
173
295
|
knownAdmissions: amount,
|
|
174
296
|
accounts: amount,
|
|
175
297
|
uninitialized: amount,
|
|
@@ -183,13 +305,13 @@ var engagementChangePreviewSchema = z2.strictObject({
|
|
|
183
305
|
var engagementVersionSchema = engagementRuleSchema.extend({
|
|
184
306
|
previousVersion: identifier.nullable()
|
|
185
307
|
});
|
|
186
|
-
var engagementRuleVersionPageSchema =
|
|
187
|
-
items:
|
|
188
|
-
|
|
308
|
+
var engagementRuleVersionPageSchema = z3.object({
|
|
309
|
+
items: z3.array(
|
|
310
|
+
z3.object({
|
|
189
311
|
version: identifier,
|
|
190
|
-
definition:
|
|
312
|
+
definition: z3.object({
|
|
191
313
|
...engagementDefinitionSchema.shape,
|
|
192
|
-
budgets:
|
|
314
|
+
budgets: z3.array(z3.object(engagementBudgetSchema.shape)).max(8).default([])
|
|
193
315
|
}),
|
|
194
316
|
publishedAt: amount,
|
|
195
317
|
previousVersion: identifier.nullable()
|
|
@@ -197,19 +319,19 @@ var engagementRuleVersionPageSchema = z2.object({
|
|
|
197
319
|
),
|
|
198
320
|
nextCursor: pageCursorSchema.nullable()
|
|
199
321
|
});
|
|
200
|
-
var engagementVersionPageSchema =
|
|
201
|
-
items:
|
|
322
|
+
var engagementVersionPageSchema = z3.strictObject({
|
|
323
|
+
items: z3.array(engagementVersionSchema),
|
|
202
324
|
next: amount.nullable()
|
|
203
325
|
});
|
|
204
|
-
var engagementVersionQuerySchema =
|
|
326
|
+
var engagementVersionQuerySchema = z3.strictObject({
|
|
205
327
|
rule: identifier,
|
|
206
|
-
before:
|
|
328
|
+
before: z3.coerce.number().int().positive().safe().optional()
|
|
207
329
|
});
|
|
208
|
-
var engagementBoundaryPageSchema =
|
|
330
|
+
var engagementBoundaryPageSchema = z3.strictObject({
|
|
209
331
|
current: engagementRuleSchema.nullable(),
|
|
210
332
|
requested: engagementRuleSchema,
|
|
211
|
-
items:
|
|
212
|
-
|
|
333
|
+
items: z3.array(
|
|
334
|
+
z3.strictObject({
|
|
213
335
|
from: identifier,
|
|
214
336
|
to: identifier,
|
|
215
337
|
baseline: contentMetricsSchema,
|
|
@@ -225,137 +347,15 @@ var engagementArtifactSchema = engagementPublishSchema.omit({
|
|
|
225
347
|
var deploymentEntry = engagementArtifactSchema.extend({
|
|
226
348
|
rule: engagementRuleSchema
|
|
227
349
|
});
|
|
228
|
-
var engagementDeploymentEntrySchema =
|
|
229
|
-
deploymentEntry.extend({ kind:
|
|
230
|
-
deploymentEntry.extend({ kind:
|
|
350
|
+
var engagementDeploymentEntrySchema = z3.discriminatedUnion("kind", [
|
|
351
|
+
deploymentEntry.extend({ kind: z3.literal("create") }),
|
|
352
|
+
deploymentEntry.extend({ kind: z3.literal("unchanged") }),
|
|
231
353
|
deploymentEntry.extend({
|
|
232
|
-
kind:
|
|
354
|
+
kind: z3.literal("change"),
|
|
233
355
|
change: engagementChangePreviewSchema
|
|
234
356
|
})
|
|
235
357
|
]);
|
|
236
358
|
|
|
237
|
-
// src/errors.ts
|
|
238
|
-
import { z as z3 } from "zod";
|
|
239
|
-
var RelayErrorCode = {
|
|
240
|
-
/** The call needs a signed-in member. */
|
|
241
|
-
NotSignedIn: "not-signed-in",
|
|
242
|
-
/** The session changed since the app read it (the `session` option). Reload before retrying. */
|
|
243
|
-
StaleSession: "stale-session",
|
|
244
|
-
/** The input failed validation before it was sent. */
|
|
245
|
-
InvalidInput: "invalid-input",
|
|
246
|
-
/** Relay's answer was not JSON or not the expected shape (kind `invalid-response`). */
|
|
247
|
-
InvalidResponse: "invalid-response",
|
|
248
|
-
/** The transport failed, before a response or while reading its body (kind `network`). */
|
|
249
|
-
Network: "network",
|
|
250
|
-
/** The client's deadline elapsed (kind `timeout`). */
|
|
251
|
-
Timeout: "timeout",
|
|
252
|
-
/** The caller cancelled the request (kind `aborted`). */
|
|
253
|
-
Aborted: "aborted",
|
|
254
|
-
/** A quest or collection the call named is not in the member's experience. */
|
|
255
|
-
NotFound: "not-found",
|
|
256
|
-
/** The quest has no failed attempt the member can retry. */
|
|
257
|
-
RetryUnavailable: "retry-unavailable",
|
|
258
|
-
/**
|
|
259
|
-
* Durable submission storage is missing, blocked or unreadable. Nothing was lost: call the
|
|
260
|
-
* handle's `status()` or `resume()` again once storage is available.
|
|
261
|
-
*/
|
|
262
|
-
SubmissionStorage: "submission-storage",
|
|
263
|
-
/** Browser storage is full, so submission progress was not saved. Free space, then resume. */
|
|
264
|
-
SubmissionStorageQuota: "submission-storage-quota",
|
|
265
|
-
/** The saved submission is in a state that does not allow this action. */
|
|
266
|
-
SubmissionConflict: "submission-conflict",
|
|
267
|
-
/** The quest changed since the member saw it; review it before submitting again. */
|
|
268
|
-
QuestUpdated: "quest-updated",
|
|
269
|
-
/** Wait for the deferred attempt before submitting another action. */
|
|
270
|
-
AttemptPending: "attempt-pending",
|
|
271
|
-
/** The quiz changed since the member answered it. */
|
|
272
|
-
StaleQuiz: "stale-quiz",
|
|
273
|
-
/** Relay refused the submitted evidence. */
|
|
274
|
-
InvalidSubmission: "invalid-submission",
|
|
275
|
-
/** A page cursor Relay cannot read; start again from the first page. */
|
|
276
|
-
InvalidCursor: "invalid-cursor",
|
|
277
|
-
/** No point ledger in the project has the key or ID the call named. */
|
|
278
|
-
PointLedgerNotFound: "point-ledger-not-found",
|
|
279
|
-
/** The member has not joined this project, so it holds no points here. */
|
|
280
|
-
NotJoined: "not-joined",
|
|
281
|
-
/** The quest or campaign is not open at this time. */
|
|
282
|
-
OutsideWindow: "outside-window",
|
|
283
|
-
/** The signed-in member must enroll in the campaign first. */
|
|
284
|
-
EnrollmentRequired: "enrollment-required",
|
|
285
|
-
/** The quest's current reward budget has no remaining capacity. */
|
|
286
|
-
BudgetExhausted: "budget-exhausted",
|
|
287
|
-
/** No published offer has the key or ID the call named. */
|
|
288
|
-
OfferNotFound: "offer-not-found",
|
|
289
|
-
/** The operator paused this offer. */
|
|
290
|
-
OfferPaused: "offer-paused",
|
|
291
|
-
/** This member has already used the offer's allowed number of redemptions. */
|
|
292
|
-
OfferLimitReached: "offer-limit-reached",
|
|
293
|
-
/** No declared units remain. */
|
|
294
|
-
OfferOutOfStock: "offer-out-of-stock",
|
|
295
|
-
/** The participant's available point balance is below the offer price. */
|
|
296
|
-
InsufficientPoints: "insufficient-points",
|
|
297
|
-
/** A wallet signer failed or the member refused to sign; `cause` is the wallet's own error. */
|
|
298
|
-
WalletSigner: "wallet-signer",
|
|
299
|
-
/** The member has not met the quest's prerequisites; `missing` lists them. */
|
|
300
|
-
PrerequisitesIncomplete: "prerequisites-incomplete",
|
|
301
|
-
/** The quest is archived or retired: it takes no new participation. */
|
|
302
|
-
QuestClosed: "quest-closed",
|
|
303
|
-
/** An operator paused the quest. */
|
|
304
|
-
QuestPaused: "quest-paused",
|
|
305
|
-
/** An operator locked the member's profile; hiding it is still allowed. */
|
|
306
|
-
ProfileLocked: "profile-locked",
|
|
307
|
-
/** No member in the project has the invitation code the member accepted. */
|
|
308
|
-
InvitationNotFound: "invitation-not-found",
|
|
309
|
-
/** The email sign-in code is wrong; the member can type it again. */
|
|
310
|
-
InvalidCode: "invalid-code",
|
|
311
|
-
/** The email sign-in code expired, was used or had too many attempts; request another. */
|
|
312
|
-
CodeExpired: "code-expired",
|
|
313
|
-
/** The wallet sign-in challenge expired, was used or changed; start sign-in again. */
|
|
314
|
-
ChallengeExpired: "challenge-expired",
|
|
315
|
-
/** Too many requests; `retryAfter` says how long to wait when Relay knows. */
|
|
316
|
-
RateLimited: "rate-limited"
|
|
317
|
-
};
|
|
318
|
-
var relayErrorBrand = /* @__PURE__ */ Symbol.for("@domino-sdk/relay.RelayError");
|
|
319
|
-
function isRelayError(value) {
|
|
320
|
-
return isRequestError(value) && value[relayErrorBrand] === true;
|
|
321
|
-
}
|
|
322
|
-
var RelayError = class extends RequestError {
|
|
323
|
-
name = "RelayError";
|
|
324
|
-
[relayErrorBrand] = true;
|
|
325
|
-
/** Which window refused admission when `code` is `outside-window`. */
|
|
326
|
-
window;
|
|
327
|
-
/** Prerequisites the member does not currently meet, when Relay refused for that reason. */
|
|
328
|
-
missing;
|
|
329
|
-
constructor(message, details) {
|
|
330
|
-
super(message, details);
|
|
331
|
-
this.window = details.window;
|
|
332
|
-
this.missing = details.missing ?? [];
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
function asRelayError(cause, fallback = "Request failed") {
|
|
336
|
-
if (isRelayError(cause)) {
|
|
337
|
-
return cause;
|
|
338
|
-
}
|
|
339
|
-
return new RelayError(
|
|
340
|
-
cause instanceof Error && cause.message ? cause.message : fallback,
|
|
341
|
-
{ kind: "client", cause }
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
function clientError(message, code, details = {}) {
|
|
345
|
-
return new RelayError(message, { ...details, kind: "client", code });
|
|
346
|
-
}
|
|
347
|
-
function parseInput(schema, value) {
|
|
348
|
-
const parsed = schema.safeParse(value);
|
|
349
|
-
if (!parsed.success) {
|
|
350
|
-
throw clientError(
|
|
351
|
-
z3.prettifyError(parsed.error),
|
|
352
|
-
RelayErrorCode.InvalidInput,
|
|
353
|
-
{ cause: parsed.error }
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
return parsed.data;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
359
|
// src/profiles.ts
|
|
360
360
|
import { z as z4 } from "zod";
|
|
361
361
|
var count = z4.number().int().nonnegative().safe();
|
|
@@ -1146,6 +1146,12 @@ var walletBalanceSchema = z8.object({
|
|
|
1146
1146
|
}).strict();
|
|
1147
1147
|
|
|
1148
1148
|
export {
|
|
1149
|
+
RelayErrorCode,
|
|
1150
|
+
isRelayError,
|
|
1151
|
+
RelayError,
|
|
1152
|
+
asRelayError,
|
|
1153
|
+
clientError,
|
|
1154
|
+
parseInput,
|
|
1149
1155
|
pointLedgerPropertiesSchema,
|
|
1150
1156
|
createPointLedgerSchema,
|
|
1151
1157
|
pointLedgerSchema,
|
|
@@ -1177,12 +1183,6 @@ export {
|
|
|
1177
1183
|
engagementBoundaryPageSchema,
|
|
1178
1184
|
engagementArtifactSchema,
|
|
1179
1185
|
engagementDeploymentEntrySchema,
|
|
1180
|
-
RelayErrorCode,
|
|
1181
|
-
isRelayError,
|
|
1182
|
-
RelayError,
|
|
1183
|
-
asRelayError,
|
|
1184
|
-
clientError,
|
|
1185
|
-
parseInput,
|
|
1186
1186
|
profileVisibilitySchema,
|
|
1187
1187
|
avatarProviderSchema,
|
|
1188
1188
|
profileDefaultProviderSchema,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
interactionSchema,
|
|
8
8
|
questCollectionSchema,
|
|
9
9
|
questTypeVersionSchema
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2N464DDE.js";
|
|
11
11
|
import {
|
|
12
12
|
engagementArtifactSchema,
|
|
13
13
|
engagementDeploymentEntrySchema,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
pointLedgerSchema,
|
|
20
20
|
publishedReferralSchema,
|
|
21
21
|
referralArtifactSchema
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-2V74CHDL.js";
|
|
23
23
|
import {
|
|
24
24
|
attemptSchema,
|
|
25
25
|
identifier,
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RelayErrorCode,
|
|
3
|
+
clientError
|
|
4
|
+
} from "./chunk-2V74CHDL.js";
|
|
5
|
+
import {
|
|
6
|
+
isRequestError
|
|
7
|
+
} from "./chunk-NPGENI7K.js";
|
|
8
|
+
|
|
9
|
+
// src/action.ts
|
|
10
|
+
function withActionId(value) {
|
|
11
|
+
return { ...value, actionId: value.actionId ?? crypto.randomUUID() };
|
|
12
|
+
}
|
|
13
|
+
function createRelayAction() {
|
|
14
|
+
let pending;
|
|
15
|
+
let flight;
|
|
16
|
+
let error;
|
|
17
|
+
let retryAt = 0;
|
|
18
|
+
function send(write) {
|
|
19
|
+
pending = write;
|
|
20
|
+
const previousError = error;
|
|
21
|
+
flight = Promise.resolve().then(async () => {
|
|
22
|
+
const wait = retryAt - Date.now();
|
|
23
|
+
if (wait > 0) {
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
25
|
+
}
|
|
26
|
+
return write.task(write.actionId);
|
|
27
|
+
}).then(
|
|
28
|
+
(value) => {
|
|
29
|
+
pending = void 0;
|
|
30
|
+
error = void 0;
|
|
31
|
+
return value;
|
|
32
|
+
},
|
|
33
|
+
(cause) => {
|
|
34
|
+
retryAt = Date.now() + (isRequestError(cause) ? cause.retryAfter ?? 0 : 0);
|
|
35
|
+
if (isRequestError(cause) && cause.uncertain) {
|
|
36
|
+
error = cause;
|
|
37
|
+
} else if (previousError) {
|
|
38
|
+
throw previousError;
|
|
39
|
+
} else {
|
|
40
|
+
pending = void 0;
|
|
41
|
+
}
|
|
42
|
+
throw cause;
|
|
43
|
+
}
|
|
44
|
+
).finally(() => {
|
|
45
|
+
flight = void 0;
|
|
46
|
+
});
|
|
47
|
+
return flight;
|
|
48
|
+
}
|
|
49
|
+
function retry() {
|
|
50
|
+
if (flight) {
|
|
51
|
+
return flight;
|
|
52
|
+
}
|
|
53
|
+
if (!pending || !error || error.recovery !== "replay" || error.operationId !== pending.actionId) {
|
|
54
|
+
return Promise.reject(
|
|
55
|
+
error ?? clientError(
|
|
56
|
+
"There is no replay-safe action to retry",
|
|
57
|
+
RelayErrorCode.InvalidInput
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return send(pending);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
get actionId() {
|
|
65
|
+
return pending?.actionId;
|
|
66
|
+
},
|
|
67
|
+
get busy() {
|
|
68
|
+
return flight !== void 0;
|
|
69
|
+
},
|
|
70
|
+
get error() {
|
|
71
|
+
return error;
|
|
72
|
+
},
|
|
73
|
+
run(task) {
|
|
74
|
+
if (flight) {
|
|
75
|
+
return flight;
|
|
76
|
+
}
|
|
77
|
+
if (pending) {
|
|
78
|
+
return retry();
|
|
79
|
+
}
|
|
80
|
+
return send({ actionId: crypto.randomUUID(), task });
|
|
81
|
+
},
|
|
82
|
+
retry,
|
|
83
|
+
settle() {
|
|
84
|
+
if (flight) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
pending = void 0;
|
|
88
|
+
error = void 0;
|
|
89
|
+
retryAt = 0;
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
withActionId,
|
|
97
|
+
createRelayAction
|
|
98
|
+
};
|