@domino-sdk/relay 0.29.0 → 0.31.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.
@@ -1,5 +1,5 @@
1
- import { A as AdmittedContent, O as Observation, T as TrackerTriggerContext, a as TrackerReader, X as XReader, I as ImageReader, D as DiscordMember, b as DiscordMessage, W as WalletConnection, S as SolanaBalance, L as LinkedWallet, c as WalletBalanceQuery, d as WalletBalance, o as observationTriggerSchema, e as TrackerDefinition, f as TrackerBeneficiary, g as TrackerTriggerPolicy, B as Budget, h as AuthoringIdentity, C as ContentMetric, i as IntegrationProvider, j as StreakPolicy, k as TextEvidence, U as UrlEvidence, l as TextOptions, m as UrlOptions } from './submission-input-C0cOmO4Q.js';
2
- export { n as content, p as customSource, q as defineEngagementReward, r as defineLeaderboard, s as defineReferral, t as defineTracker, u as discord, v as formatUnits, w as parseUnits, x as perContent, y as pointLedgers, z as settings, E as streak, F as trackerTriggerContextSchema, G as x } from './submission-input-C0cOmO4Q.js';
1
+ import { A as AdmittedContent, O as Observation, T as TrackerTriggerContext, a as TrackerReader, X as XReader, I as ImageReader, D as DiscordMember, b as DiscordMessage, W as WalletConnection, S as SolanaBalance, L as LinkedWallet, c as WalletBalanceQuery, d as WalletBalance, e as TrackerDefinition, f as TrackerTriggerMode, g as TrackerWhere, o as observationTriggerSchema, h as TrackerTriggerPolicy, B as Budget, i as AuthoringIdentity, C as ContentMetric, j as IntegrationProvider, k as StreakPolicy, l as TextEvidence, U as UrlEvidence, m as TextOptions, n as UrlOptions } from './submission-input-JDwq3EVK.js';
2
+ export { E as EvmChainId, p as content, q as customSource, r as defineEngagementReward, s as defineLeaderboard, t as defineReferral, u as defineTracker, v as discord, w as formatUnits, x as isEvmChainId, y as parseUnits, z as perContent, F as pointLedgers, G as settings, H as streak, J as trackerTriggerContextSchema, K as x } from './submission-input-JDwq3EVK.js';
3
3
  import { z } from 'zod';
4
4
  import { TextReviewInput, TextResult, PhotoResult, rewardSchema, triggerSchema, QuestPresentation, QuestProfile, QuizEvidence, Decision, TieredRewardDefinition } from './schema.js';
5
5
 
@@ -58,11 +58,32 @@ declare function manual(options: {
58
58
  input: "none";
59
59
  actor: "staff";
60
60
  };
61
+ /** A tracker trigger: which observations of which tracker run the quest, and for whom. */
62
+ type TrackerTriggerInput = {
63
+ tracker: TrackerDefinition;
64
+ /**
65
+ * Which observations fire. `"new-record"`: each record's first observation (the default for X
66
+ * trackers, where it means each newly collected post). `"new-observation"`: each observation
67
+ * that becomes its record's current one (the default for custom trackers). `"data-changed"`: a
68
+ * new record, or a current observation whose `data` differs from the previous one.
69
+ */
70
+ on?: TrackerTriggerMode;
71
+ /**
72
+ * Admit only observations whose `data` matches, such as `{ path: "amount", gte: 1000 }` or
73
+ * `{ path: "amount", gte: { setting: "threshold" } }`. Others record no outcome.
74
+ */
75
+ where?: TrackerWhere;
76
+ /**
77
+ * The record account whose member the quest pays: `"author"` (the default), `"inReplyTo"` on
78
+ * an X tracker, or a named account a custom source declares in `accounts`. Skipped when that
79
+ * account is the record's author account or belongs to the author's member.
80
+ */
81
+ beneficiary?: string;
82
+ };
61
83
  /**
62
84
  * An automatic quest. With no argument it runs once its prerequisites are complete; with an
63
- * observation it runs for each matching observation; with a tracker it runs for each new record
64
- * observation (each newly discovered post, for an X tracker), for the member Relay attributes the
65
- * record to.
85
+ * observation it runs for each matching observation; with a tracker it runs for each observation
86
+ * its firing mode and filter admit, for the member Relay attributes the beneficiary account to.
66
87
  */
67
88
  declare function automatic(): {
68
89
  kind: "automatic";
@@ -71,15 +92,7 @@ declare function automatic(observation: z.infer<typeof observationTriggerSchema>
71
92
  kind: "automatic";
72
93
  observation: z.infer<typeof observationTriggerSchema>;
73
94
  };
74
- declare function automatic(input: {
75
- tracker: TrackerDefinition;
76
- /**
77
- * Whose quest each record is. `"author"` (the default): the member who verified the record
78
- * author's wallet (custom trackers) or X account (X trackers). `"replied-to"`: the member whose
79
- * verified X account an X post replies to.
80
- */
81
- beneficiary?: TrackerBeneficiary;
82
- }): {
95
+ declare function automatic(input: TrackerTriggerInput): {
83
96
  kind: "automatic";
84
97
  tracker: TrackerTriggerPolicy;
85
98
  };
@@ -445,7 +458,26 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
445
458
  tracker?: {
446
459
  tracker: string;
447
460
  source: "custom" | "x-search";
448
- beneficiary: "author" | "replied-to";
461
+ beneficiary: string;
462
+ on?: "new-record" | "new-observation" | "data-changed" | undefined;
463
+ where?: {
464
+ path: string;
465
+ gt?: number | {
466
+ setting: string;
467
+ } | undefined;
468
+ gte?: number | {
469
+ setting: string;
470
+ } | undefined;
471
+ lt?: number | {
472
+ setting: string;
473
+ } | undefined;
474
+ lte?: number | {
475
+ setting: string;
476
+ } | undefined;
477
+ } | {
478
+ path: string;
479
+ equals: string | number | boolean;
480
+ } | undefined;
449
481
  } | undefined;
450
482
  } | {
451
483
  kind: "manual";
@@ -510,4 +542,4 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
510
542
  * Console instances receive independent quest identities and pinned versions. */
511
543
  declare const defineQuestType: typeof defineQuest;
512
544
 
513
- export { type EvaluationContext, TrackerTriggerContext, WalletBalance, WalletBalanceQuery, automatic, budget, completed, decision, defineQuest, defineQuestType, defineTieredReward, discordRole, evaluators, evidence, keyed, manual, once, points, staffHandover, untracked };
545
+ export { type EvaluationContext, TrackerTriggerContext, type TrackerTriggerInput, WalletBalance, WalletBalanceQuery, automatic, budget, completed, decision, defineQuest, defineQuestType, defineTieredReward, discordRole, evaluators, evidence, keyed, manual, once, points, staffHandover, untracked };
package/dist/authoring.js CHANGED
@@ -5,8 +5,10 @@ import {
5
5
  defineReferral,
6
6
  formatUnits,
7
7
  parseUnits
8
- } from "./chunk-YKS6P4IP.js";
9
- import "./chunk-MRKFRCCI.js";
8
+ } from "./chunk-QEN4GHL7.js";
9
+ import {
10
+ isEvmChainId
11
+ } from "./chunk-UI4N4XRZ.js";
10
12
  import {
11
13
  admittedContentSchema,
12
14
  budgetSchema,
@@ -15,6 +17,7 @@ import {
15
17
  contentPerformanceSnapshotSchema,
16
18
  customSource,
17
19
  decisionSchema,
20
+ defaultTriggerMode,
18
21
  defineTracker,
19
22
  discord,
20
23
  integrationRewardSchema,
@@ -27,6 +30,7 @@ import {
27
30
  rewardBundleSchema,
28
31
  settingFieldSchema,
29
32
  settings,
33
+ sourceIdentities,
30
34
  streak,
31
35
  textOptionsSchema,
32
36
  tierRewardSchema,
@@ -34,8 +38,9 @@ import {
34
38
  trackerTriggerContextSchema,
35
39
  trackerTriggerPolicySchema,
36
40
  urlOptionsSchema,
37
- x
38
- } from "./chunk-BE5V6RFD.js";
41
+ x,
42
+ xAccountRoles
43
+ } from "./chunk-UPWID5KS.js";
39
44
 
40
45
  // src/authoring.ts
41
46
  import { z } from "zod";
@@ -73,20 +78,32 @@ function automatic(input) {
73
78
  return { kind: "automatic" };
74
79
  }
75
80
  if ("tracker" in input) {
76
- const { tracker, beneficiary = "author" } = input;
77
- if (beneficiary === "replied-to" && tracker.source.kind !== "x-search") {
78
- throw new Error('"replied-to" requires an X tracker');
81
+ const { tracker, beneficiary = "author", on, where } = input;
82
+ const { source } = tracker;
83
+ if (source.kind === "x-search" && !xAccountRoles.includes(beneficiary)) {
84
+ throw new Error(
85
+ `X trackers pay "author" or "inReplyTo", not "${beneficiary}"`
86
+ );
79
87
  }
80
- if (tracker.source.kind === "custom" && tracker.source.authors !== "wallet") {
88
+ if (!sourceIdentities(source)) {
81
89
  throw new Error(
82
- 'Tracker triggers need attributable authors: use customSource(namespace, { authors: "wallet" })'
90
+ 'Tracker triggers need attributable records: declare customSource(namespace, { identities: ["wallet"] }) or other identity kinds'
91
+ );
92
+ }
93
+ if (source.kind === "custom" && beneficiary !== "author" && !source.accounts?.includes(beneficiary)) {
94
+ throw new Error(
95
+ `Tracker "${tracker.key}" has no "${beneficiary}" account: declare it in customSource(namespace, { accounts: ["${beneficiary}"] })`
83
96
  );
84
97
  }
85
98
  return {
86
99
  kind: "automatic",
87
100
  tracker: trackerTriggerPolicySchema.parse({
88
101
  tracker: tracker.key,
89
- source: tracker.source.kind,
102
+ source: source.kind,
103
+ // The source's default mode is left out, so default quests keep the policy shape
104
+ // earlier SDKs and servers read.
105
+ ...on && on !== defaultTriggerMode(source.kind) ? { on } : {},
106
+ ...where ? { where } : {},
90
107
  beneficiary
91
108
  })
92
109
  };
@@ -182,6 +199,14 @@ function defineQuest(definition) {
182
199
  settingFieldSchema.parse(schema.meta())
183
200
  ])
184
201
  );
202
+ const where = definition.trigger.kind === "automatic" ? definition.trigger.tracker?.where : void 0;
203
+ for (const bound of where && !("equals" in where) ? [where.gt, where.gte, where.lt, where.lte] : []) {
204
+ if (typeof bound === "object" && fields[bound.setting]?.kind !== "integer") {
205
+ throw new Error(
206
+ `The tracker filter compares with setting "${bound.setting}", which is not an integer setting`
207
+ );
208
+ }
209
+ }
185
210
  function describe(input) {
186
211
  const settings2 = definition.settings.parse(input);
187
212
  const values = parseSettings(fields, settings2);
@@ -318,6 +343,7 @@ export {
318
343
  evaluators,
319
344
  evidence,
320
345
  formatUnits,
346
+ isEvmChainId,
321
347
  keyed,
322
348
  manual,
323
349
  once,