@domino-sdk/relay 1.0.0-next.7 → 1.0.0-next.9

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 (33) hide show
  1. package/dist/authoring.d.ts +143 -87
  2. package/dist/authoring.js +119 -44
  3. package/dist/avatar.d.ts +2 -2
  4. package/dist/browser.d.ts +291 -2274
  5. package/dist/browser.js +6 -6
  6. package/dist/{chunk-SKETUPST.js → chunk-4LBUTHD6.js} +1 -1
  7. package/dist/{chunk-ADSP377G.js → chunk-7Q4BGGT6.js} +26 -5
  8. package/dist/{chunk-AWLLGCKU.js → chunk-P6FK43GG.js} +22 -8
  9. package/dist/{chunk-DJZB5RY5.js → chunk-PHU5VDLR.js} +345 -243
  10. package/dist/{chunk-UFXBQ6FN.js → chunk-QR7ZA2BJ.js} +2 -2
  11. package/dist/{chunk-X6FJIPXR.js → chunk-X2F2RAR3.js} +553 -435
  12. package/dist/chunk-YYD4QUBO.js +2348 -0
  13. package/dist/{chunk-7HSTFBMO.js → chunk-ZWY3R6B3.js} +5 -3
  14. package/dist/{client-BufGakEt.d.ts → client-CT4-S5vc.d.ts} +371 -2232
  15. package/dist/{integrations-C3Sp558f.d.ts → images-BTgk6OmC.d.ts} +748 -481
  16. package/dist/index.d.ts +6 -6
  17. package/dist/index.js +19 -7
  18. package/dist/integrations-Ba5TtqTv.d.ts +410 -0
  19. package/dist/internal.d.ts +17 -5
  20. package/dist/internal.js +27 -6
  21. package/dist/{catalog-C09gnPYT.d.ts → pages-D3titw5B.d.ts} +297 -52
  22. package/dist/portal-proxy.js +6 -6
  23. package/dist/{profiles-BtOXMGcC.d.ts → profiles-DDMFBRKe.d.ts} +1 -1
  24. package/dist/react/index.d.ts +243 -2209
  25. package/dist/react/index.js +12 -10
  26. package/dist/{schema-DCapSPHz.d.ts → schema-Di3aLSiK.d.ts} +166 -30
  27. package/dist/schema.d.ts +223 -271
  28. package/dist/schema.js +27 -5
  29. package/dist/{submission-input-Bter6XiI.d.ts → submission-input-0OOGaq8c.d.ts} +14 -14
  30. package/dist/{wallet-Bu6sqJvQ.d.ts → wallet-BGOfFkG9.d.ts} +1 -1
  31. package/package.json +1 -1
  32. package/dist/chunk-UW6R2QGT.js +0 -1724
  33. package/dist/images-e6FW9QSx.d.ts +0 -234
package/dist/authoring.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  isEvmChainId,
11
11
  leaderboardAuthoringSchema,
12
12
  referralAuthoringSchema
13
- } from "./chunk-DJZB5RY5.js";
13
+ } from "./chunk-PHU5VDLR.js";
14
14
  import {
15
15
  admittedContentSchema,
16
16
  budgetSchema,
@@ -29,6 +29,7 @@ import {
29
29
  quizContentSchema,
30
30
  resourceSourceSchema,
31
31
  rewardBundleSchema,
32
+ schemaCheckedReader,
32
33
  settingFieldSchema,
33
34
  settingInstant,
34
35
  settingResourceId,
@@ -37,13 +38,17 @@ import {
37
38
  textOptionsSchema,
38
39
  tierRewardSchema,
39
40
  tieredRewardDefinitionSchema,
41
+ trackerDataIssue,
42
+ trackerDataSchema,
40
43
  trackerDefinitionSchema,
41
44
  trackerTriggerContextSchema,
42
45
  trackerTriggerPolicySchema,
43
46
  urlOptionsSchema,
47
+ whereSchemaIssue,
48
+ whereSettings,
44
49
  xAccountRoles,
45
50
  xSearchSourceSchema
46
- } from "./chunk-UW6R2QGT.js";
51
+ } from "./chunk-YYD4QUBO.js";
47
52
 
48
53
  // src/builders.ts
49
54
  import { z } from "zod";
@@ -112,13 +117,26 @@ function defineLeaderboard(input) {
112
117
  };
113
118
  }
114
119
  var x = {
120
+ /** Posts matching an X search. Each record's `data` is the provider's post payload. */
115
121
  search: (input) => xSearchSourceSchema.parse({ kind: "x-search", ...input })
116
122
  };
117
- var customSource = (namespace, options = {}) => customSourceSchema.parse({
118
- kind: "custom",
119
- namespace,
120
- ...options
121
- });
123
+ function customSource(namespace, options) {
124
+ const { data, ...rest } = options ?? {};
125
+ if (!isZodSchema(data)) {
126
+ throw new Error(
127
+ `customSource("${namespace}") needs a data schema: customSource(namespace, { data: z.object({ ... }) }) describes each record's data`
128
+ );
129
+ }
130
+ return customSourceSchema.parse({
131
+ kind: "custom",
132
+ namespace,
133
+ ...rest,
134
+ data: trackerDataSchema(data)
135
+ });
136
+ }
137
+ function isZodSchema(value) {
138
+ return typeof value === "object" && value !== null && "_zod" in value;
139
+ }
122
140
  function defineTracker(input) {
123
141
  return trackerDefinitionSchema.parse(input);
124
142
  }
@@ -142,6 +160,9 @@ var pointLedgers = () => ({
142
160
  provider: "domino",
143
161
  resource: "point-ledger"
144
162
  });
163
+ function setting(_kind, schema) {
164
+ return schema;
165
+ }
145
166
  var settings = {
146
167
  pointLedger(options) {
147
168
  const field = {
@@ -149,7 +170,10 @@ var settings = {
149
170
  kind: "point-ledger",
150
171
  default: identifier.parse(options.default)
151
172
  };
152
- return identifier.default(field.default).meta(field);
173
+ return setting(
174
+ "point-ledger",
175
+ identifier.default(field.default).meta(field)
176
+ );
153
177
  },
154
178
  datetime(options) {
155
179
  const field = {
@@ -157,7 +181,10 @@ var settings = {
157
181
  kind: "datetime",
158
182
  default: settingInstant.parse(options.default)
159
183
  };
160
- return settingInstant.default(field.default).meta(field);
184
+ return setting(
185
+ "datetime",
186
+ settingInstant.default(field.default).meta(field)
187
+ );
161
188
  },
162
189
  resource(options) {
163
190
  const field = {
@@ -166,11 +193,17 @@ var settings = {
166
193
  kind: "resource",
167
194
  default: settingResourceId.parse(options.default ?? "")
168
195
  };
169
- return settingResourceId.default(field.default).meta(field);
196
+ return setting(
197
+ "resource",
198
+ settingResourceId.default(field.default).meta(field)
199
+ );
170
200
  },
171
201
  quiz(options) {
172
202
  const value = quizContentSchema.parse(options.default);
173
- return quizContentSchema.default(value).meta({ ...options, default: value, kind: "quiz" });
203
+ return setting(
204
+ "quiz",
205
+ quizContentSchema.default(value).meta({ ...options, default: value, kind: "quiz" })
206
+ );
174
207
  },
175
208
  text(options) {
176
209
  const field = {
@@ -180,17 +213,30 @@ var settings = {
180
213
  maxLength: options.maxLength ?? 2e3,
181
214
  multiline: options.multiline ?? false
182
215
  };
183
- return z.string().min(field.minLength).max(field.maxLength).default(field.default).meta(field);
216
+ return setting(
217
+ "text",
218
+ z.string().min(field.minLength).max(field.maxLength).default(field.default).meta(field)
219
+ );
184
220
  },
185
221
  integer(options) {
186
- return z.number().int().min(options.min).max(options.max).default(options.default).meta({ ...options, kind: "integer" });
222
+ return setting(
223
+ "integer",
224
+ z.number().int().min(options.min).max(options.max).default(options.default).meta({ ...options, kind: "integer" })
225
+ );
187
226
  },
188
227
  boolean(options) {
189
- return z.boolean().default(options.default).meta({ ...options, kind: "boolean" });
228
+ return setting(
229
+ "boolean",
230
+ z.boolean().default(options.default).meta({ ...options, kind: "boolean" })
231
+ );
190
232
  },
191
233
  choice(options) {
192
- return z.enum(options.options).default(options.default).meta({ ...options, kind: "choice" });
234
+ return setting(
235
+ "choice",
236
+ z.enum(options.options).default(options.default).meta({ ...options, kind: "choice" })
237
+ );
193
238
  },
239
+ /** A quest's settings: every field is built with one of the builders above. */
194
240
  object(shape) {
195
241
  return z.object(shape).strict();
196
242
  }
@@ -198,6 +244,7 @@ var settings = {
198
244
 
199
245
  // src/authoring.ts
200
246
  import { z as z2 } from "zod";
247
+ import { z as z3 } from "zod";
201
248
  var points = (balance, amount) => pointsRewardSchema.parse({ kind: "points", balance, amount });
202
249
  var discordRole = (roleId) => integrationRewardSchema.parse({
203
250
  kind: "integration",
@@ -232,6 +279,7 @@ function manual(options) {
232
279
  ...options?.actor ? { actor: options.actor } : {}
233
280
  };
234
281
  }
282
+ var triggerDataSchemas = /* @__PURE__ */ new WeakMap();
235
283
  function automatic(input) {
236
284
  if (!input) {
237
285
  return { kind: "automatic" };
@@ -254,23 +302,32 @@ function automatic(input) {
254
302
  `Tracker "${tracker.key}" has no "${beneficiary}" account: declare it in customSource(namespace, { accounts: ["${beneficiary}"] })`
255
303
  );
256
304
  }
257
- return {
258
- kind: "automatic",
259
- tracker: trackerTriggerPolicySchema.parse({
260
- tracker: tracker.key,
261
- source: source.kind,
262
- // The source's default mode is left out, so default quests keep the policy shape
263
- // earlier SDKs and servers read.
264
- ...on && on !== defaultTriggerMode(source.kind) ? { on } : {},
265
- ...where ? { where } : {},
266
- beneficiary
267
- })
268
- };
305
+ const policy = trackerTriggerPolicySchema.parse({
306
+ tracker: tracker.key,
307
+ source: source.kind,
308
+ // The source's default mode is left out, so default quests keep the policy shape
309
+ // earlier SDKs and servers read.
310
+ ...on && on !== defaultTriggerMode(source.kind) ? { on } : {},
311
+ ...where ? { where } : {},
312
+ beneficiary
313
+ });
314
+ const issue = source.kind === "custom" && source.data ? whereSchemaIssue(source.data, policy.where) : null;
315
+ if (issue) {
316
+ throw new Error(issue);
317
+ }
318
+ const trigger = { kind: "automatic", tracker: policy };
319
+ if (source.kind === "custom" && source.data) {
320
+ triggerDataSchemas.set(trigger, source.data);
321
+ }
322
+ return trigger;
269
323
  }
270
324
  return { kind: "automatic", observation: input };
271
325
  }
272
326
  var budget = (definition) => budgetSchema.parse(definition);
273
- var keyed = (key) => ({ kind: "keyed", key });
327
+ var keyed = (key) => ({
328
+ kind: "keyed",
329
+ key
330
+ });
274
331
  var completed = (quest) => ({
275
332
  quest: typeof quest === "string" ? quest : authoringKey(quest)
276
333
  });
@@ -306,7 +363,7 @@ var evaluators = {
306
363
  quiz(answerKey, options = {}) {
307
364
  const expected = quizAnswersSchema.parse(answerKey);
308
365
  const questions = Object.keys(expected);
309
- const minimum = z2.number().int().min(1).max(questions.length).parse(options.minimumCorrect ?? questions.length);
366
+ const minimum = z3.number().int().min(1).max(questions.length).parse(options.minimumCorrect ?? questions.length);
310
367
  return async ({ input }) => {
311
368
  const complete = Object.keys(input.answers).length === questions.length && questions.every((question) => Object.hasOwn(input.answers, question));
312
369
  const correct = questions.filter(
@@ -357,16 +414,22 @@ function defineQuest(definition) {
357
414
  throw new Error("Evidence quests require an evaluator");
358
415
  }
359
416
  const fields = Object.fromEntries(
360
- Object.entries(definition.settings.shape).map(([key2, schema]) => [
361
- key2,
362
- settingFieldSchema.parse(schema.meta())
363
- ])
417
+ Object.entries(definition.settings.shape).map(([key2, schema]) => {
418
+ const field = settingFieldSchema.safeParse(schema.meta());
419
+ if (!field.success) {
420
+ throw new Error(
421
+ `Setting "${key2}" is not a quest setting: build it with a settings builder, such as settings.integer({ label, default, min, max })`
422
+ );
423
+ }
424
+ return [key2, field.data];
425
+ })
364
426
  );
365
- const where = definition.trigger.kind === "automatic" ? definition.trigger.tracker?.where : void 0;
366
- for (const bound of where && !("equals" in where) ? [where.gt, where.gte, where.lt, where.lte] : []) {
367
- if (typeof bound === "object" && fields[bound.setting]?.kind !== "integer") {
427
+ for (const setting2 of whereSettings(
428
+ definition.trigger.kind === "automatic" ? definition.trigger.tracker?.where : void 0
429
+ )) {
430
+ if (fields[setting2]?.kind !== "integer") {
368
431
  throw new Error(
369
- `The tracker filter compares with setting "${bound.setting}", which is not an integer setting`
432
+ `The tracker filter compares with setting "${setting2}", which is not an integer setting`
370
433
  );
371
434
  }
372
435
  }
@@ -418,15 +481,24 @@ function defineQuest(definition) {
418
481
  describe,
419
482
  async evaluate(ctx) {
420
483
  const settings2 = definition.settings.parse(ctx.settings);
421
- const tracker = trackerTrigger ? trackerTriggerContextSchema.parse(ctx.tracker) : null;
484
+ const pinned = trackerTrigger ? trackerTriggerContextSchema.parse(ctx.tracker) : null;
485
+ const schema = triggerDataSchemas.get(definition.trigger);
486
+ const dataIssue = pinned && schema ? trackerDataIssue(schema, pinned.record.data) : null;
487
+ if (dataIssue) {
488
+ return decisionSchema.parse({
489
+ kind: "reject",
490
+ reason: `The record's data does not match the data schema this quest was built with: ${dataIssue.path} ${dataIssue.reason}`
491
+ });
492
+ }
493
+ const tracker = pinned;
422
494
  if (ctx.performance) {
423
495
  if (!definition.performance) {
424
496
  throw new Error("Quest has no performance evaluator");
425
497
  }
426
498
  const sample = contentPerformanceSnapshotSchema.parse(ctx.performance);
427
- const metrics = z2.record(
428
- z2.enum(definition.performance.metrics),
429
- z2.number().int().safe().nonnegative()
499
+ const metrics = z3.record(
500
+ z3.enum(definition.performance.metrics),
501
+ z3.number().int().safe().nonnegative()
430
502
  ).parse(sample.metrics);
431
503
  const result2 = await definition.performance.evaluate({
432
504
  settings: settings2,
@@ -469,7 +541,7 @@ function defineQuest(definition) {
469
541
  eligibleAt: ctx.eligibleAt,
470
542
  now: ctx.now,
471
543
  review: ctx.review,
472
- trackers: ctx.trackers,
544
+ trackers: schemaCheckedReader(ctx.trackers),
473
545
  wallet: ctx.wallet,
474
546
  x: ctx.x,
475
547
  images: ctx.images,
@@ -492,7 +564,8 @@ function defineQuest(definition) {
492
564
  ...definition.completion.kind === "keyed" ? {
493
565
  completionKey: definition.completion.key({
494
566
  ...ctx,
495
- tracker
567
+ observation: ctx.observation ?? null,
568
+ tracker: pinned
496
569
  })
497
570
  } : {}
498
571
  } : result
@@ -531,7 +604,9 @@ export {
531
604
  settings,
532
605
  staffHandover,
533
606
  streak,
607
+ trackerDataSchema,
534
608
  trackerTriggerContextSchema,
535
609
  untracked,
536
- x
610
+ x,
611
+ z2 as z
537
612
  };
package/dist/avatar.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as LinkedWallet } from './wallet-Bu6sqJvQ.js';
2
- import { P as ProfileAvatar } from './profiles-BtOXMGcC.js';
1
+ import { L as LinkedWallet } from './wallet-BGOfFkG9.js';
2
+ import { P as ProfileAvatar } from './profiles-DDMFBRKe.js';
3
3
  import 'zod';
4
4
 
5
5
  /**