@domino-sdk/relay 1.0.0-next.6 → 1.0.0-next.8

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 (43) hide show
  1. package/README.md +13 -1
  2. package/build.mjs +18 -1
  3. package/dist/authoring.d.ts +317 -15
  4. package/dist/authoring.js +177 -23
  5. package/dist/avatar.d.ts +29 -0
  6. package/dist/avatar.js +21 -0
  7. package/dist/browser.d.ts +174 -2239
  8. package/dist/browser.js +6 -6
  9. package/dist/{chunk-RTHN22KO.js → chunk-6A6K5RUD.js} +22 -8
  10. package/dist/chunk-77H7APVD.js +171 -0
  11. package/dist/chunk-MRIURJE3.js +257 -0
  12. package/dist/{chunk-5IIWKDFX.js → chunk-QBOHLT7M.js} +26 -5
  13. package/dist/chunk-V5R2DMGY.js +1407 -0
  14. package/dist/chunk-V7EZUZ3Z.js +1003 -0
  15. package/dist/chunk-V7UKZLHA.js +35 -0
  16. package/dist/{chunk-BRESOTKV.js → chunk-VARGF4JS.js} +660 -770
  17. package/dist/chunk-ZWY3R6B3.js +26 -0
  18. package/dist/client-CK4nwt7V.d.ts +2631 -0
  19. package/dist/collection-BGneJ6Bk.d.ts +114 -0
  20. package/dist/images--vZ9U0kr.d.ts +234 -0
  21. package/dist/index.d.ts +11 -13132
  22. package/dist/index.js +20 -690
  23. package/dist/integrations-C3Sp558f.d.ts +1297 -0
  24. package/dist/internal.d.ts +120 -0
  25. package/dist/internal.js +111 -0
  26. package/dist/pages-BzqJuI69.d.ts +4006 -0
  27. package/dist/point-ledgers-iS00Z_v0.d.ts +37 -0
  28. package/dist/portal-proxy.js +8 -9
  29. package/dist/profiles-DDMFBRKe.d.ts +297 -0
  30. package/dist/react/index.d.ts +186 -2251
  31. package/dist/react/index.js +11 -15
  32. package/dist/schema-pnuWqvGn.d.ts +3396 -0
  33. package/dist/schema.d.ts +3196 -2374
  34. package/dist/schema.js +549 -3
  35. package/dist/streaks-CwGReWGt.d.ts +73 -0
  36. package/dist/submission-input-C9qm9ixd.d.ts +2672 -0
  37. package/dist/units-CwgsPB_r.d.ts +9 -0
  38. package/dist/wallet-BGOfFkG9.d.ts +231 -0
  39. package/package.json +17 -4
  40. package/dist/chunk-ERBVT7GE.js +0 -1847
  41. package/dist/chunk-XEQDW7FM.js +0 -373
  42. package/dist/chunk-ZKJBCQNI.js +0 -624
  43. package/dist/submission-input-CZDukyb3.d.ts +0 -4998
package/README.md CHANGED
@@ -6,6 +6,18 @@ Author quests and connect an application to Domino Relay.
6
6
  pnpm add @domino-sdk/relay
7
7
  ```
8
8
 
9
- Use `@domino-sdk/relay/authoring` for quest definitions, `/browser` for browser integrations, `/portal-proxy` for server proxies, and `/build` for bundling authored modules.
9
+ | Import | For |
10
+ | -------------------------------- | ------------------------------------------------------------------------------------------ |
11
+ | `@domino-sdk/relay` | The participant client (`createRelayClient`), `RelayError`, and the types it returns |
12
+ | `@domino-sdk/relay/browser` | The browser client with durable submission recovery, wallet signers and sign-in options |
13
+ | `@domino-sdk/relay/react` | React hooks over the browser client |
14
+ | `@domino-sdk/relay/avatar` | Generated default avatars (`avatarSrc`, `defaultAvatar`) |
15
+ | `@domino-sdk/relay/authoring` | Quest, tracker, leaderboard, referral and engagement definitions, and evaluator types |
16
+ | `@domino-sdk/relay/schema` | Zod schemas of Relay's API bodies, deployments, tracker records and observations |
17
+ | `@domino-sdk/relay/build` | Bundling authored modules; needs `esbuild` installed |
18
+ | `@domino-sdk/relay/portal-proxy` | Server proxies and hosted app Workers |
19
+ | `@domino-sdk/relay/vite` | The Vite plugin that keeps server code out of the browser build |
20
+
21
+ `@domino-sdk/relay/internal` is shared by Relay's own services and Console. It is not a supported API and can change in any release.
10
22
 
11
23
  Requires Node.js 24 for tooling. Proprietary software; `UNLICENSED`.
package/build.mjs CHANGED
@@ -1,5 +1,21 @@
1
1
  import { resolve, dirname } from "node:path"
2
- import { build } from "esbuild"
2
+
3
+ // esbuild is an optional peer dependency: only quest builds need it, so apps that use the runtime
4
+ // client do not install its native binary. `@domino-sdk/relay-cli` depends on it.
5
+ async function esbuild() {
6
+ try {
7
+ return await import("esbuild")
8
+ } catch (error) {
9
+ if (error?.code === "ERR_MODULE_NOT_FOUND") {
10
+ throw new Error(
11
+ "@domino-sdk/relay/build needs esbuild. Install it next to @domino-sdk/relay, or build with the domino CLI (@domino-sdk/relay-cli).",
12
+ { cause: error }
13
+ )
14
+ }
15
+
16
+ throw error
17
+ }
18
+ }
3
19
 
4
20
  /** Bundle an authored quest without evaluating developer code in the build process. */
5
21
  export async function buildQuest(entry, options = {}) {
@@ -10,6 +26,7 @@ export async function buildQuest(entry, options = {}) {
10
26
  throw new Error("Invalid quest export name")
11
27
  }
12
28
 
29
+ const { build } = await esbuild()
13
30
  const result = await build({
14
31
  ...(options.exportName
15
32
  ? {
@@ -1,7 +1,309 @@
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-CZDukyb3.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-CZDukyb3.js';
3
1
  import { z } from 'zod';
4
- import { TextReviewInput, TextResult, PhotoResult, rewardSchema, triggerSchema, QuestPresentation, QuestProfile, QuizEvidence, Decision, TieredRewardDefinition } from './schema.js';
2
+ import { C as ContentPolicy, g as ContentMetric, E as EngagementDefinition, l as leaderboardAuthoringSchema, r as referralAuthoringSchema, h as AdmittedContent, D as DiscordMember, T as TextEvidence, U as UrlEvidence, e as TextOptions, f as UrlOptions } from './submission-input-C9qm9ixd.js';
3
+ import { Q as QuizContent, a as StreakPolicy } from './streaks-CwGReWGt.js';
4
+ import { T as TrackerDefinition, I as IdentityKind, t as trackerDefinitionSchema, R as ResourceSource, O as Observation, a as TrackerTriggerContext, b as TrackerReader, X as XReader, D as DiscordMessage, c as TrackerTriggerMode, d as TrackerWhere, o as observationTriggerSchema, e as TrackerTriggerPolicy, B as Budget, f as IntegrationProvider } from './integrations-C3Sp558f.js';
5
+ export { g as trackerTriggerContextSchema } from './integrations-C3Sp558f.js';
6
+ import { I as ImageReader } from './images--vZ9U0kr.js';
7
+ import { d as TextReviewInput, e as TextResult, P as PhotoResult, r as rewardSchema, t as triggerSchema, Q as QuestPresentation, a as QuestProfile, b as QuizEvidence, D as Decision, f as TieredRewardDefinition } from './schema-pnuWqvGn.js';
8
+ import { h as WalletConnection, S as SolanaBalance, L as LinkedWallet, i as WalletBalanceQuery, j as WalletBalance } from './wallet-BGOfFkG9.js';
9
+ export { E as EvmChainId, k as isEvmChainId } from './wallet-BGOfFkG9.js';
10
+ export { f as formatUnits, p as parseUnits } from './units-CwgsPB_r.js';
11
+
12
+ /** Legacy `id` names an authoring key, never a server resource ID. */
13
+ type AuthoringIdentity = {
14
+ key: string;
15
+ id?: string;
16
+ } | {
17
+ key?: never; /** @deprecated Use key. */
18
+ id: string;
19
+ };
20
+
21
+ /** Discover posts automatically; historical release remains an explicit policy. */
22
+ declare function content(tracker: TrackerDefinition, policy?: Partial<Pick<ContentPolicy, "enrollment" | "posts" | "historical">>): {
23
+ kind: "automatic";
24
+ content: {
25
+ tracker: string;
26
+ window: {
27
+ start: number;
28
+ end?: number | undefined;
29
+ };
30
+ enrollment: "none" | "required";
31
+ posts: "after-enrollment" | "since-start";
32
+ historical: "automatic" | "claim" | "staff";
33
+ };
34
+ };
35
+ declare function perContent(): {
36
+ kind: "keyed";
37
+ perContent: true;
38
+ key: (ctx: {
39
+ content?: AdmittedContent | null;
40
+ }) => string;
41
+ };
42
+ /** One independent cumulative formula; management changes capture a new scoring boundary. */
43
+ declare function defineEngagementReward<const M extends readonly [ContentMetric, ...ContentMetric[]]>(input: {
44
+ key: string;
45
+ qualifiedBy: string | {
46
+ key: string;
47
+ };
48
+ balance: string;
49
+ metrics: M;
50
+ baseline: "historical";
51
+ maxAgeMs?: number;
52
+ budget?: EngagementDefinition["budget"];
53
+ target: (input: {
54
+ metrics: Record<M[number], number>;
55
+ }) => number;
56
+ }): {
57
+ key: string;
58
+ describe: () => {
59
+ key: string;
60
+ qualifiedBy: string;
61
+ balance: string;
62
+ metrics: ("likes" | "replies" | "reposts" | "quotes" | "views" | "bookmarks")[];
63
+ baseline: "historical";
64
+ maxAgeMs: number;
65
+ budget: {
66
+ projectDaily?: number | undefined;
67
+ memberDaily?: number | undefined;
68
+ projectLifetime?: number | undefined;
69
+ };
70
+ };
71
+ score(raw: unknown): {
72
+ target: number;
73
+ baseline: number;
74
+ };
75
+ };
76
+ /**
77
+ * One milestone per quest, after `days` consecutive community days with an accepted attempt.
78
+ * Multiple accepted attempts occupy one day. The day comes from the attempt's trusted occurrence
79
+ * time: a tracker record's (or observation's) `occurredAt` for `automatic({ tracker })`, and the
80
+ * submission's admission time for `manual()`, so a manual streak counts the days a member
81
+ * submitted. Not available on content quests or prerequisite-only `automatic()`.
82
+ */
83
+ declare const streak: (options: Omit<StreakPolicy, "kind">) => StreakPolicy;
84
+ declare function defineReferral(input: Omit<z.input<typeof referralAuthoringSchema>, "key" | "id"> & AuthoringIdentity): {
85
+ id: string;
86
+ title: string;
87
+ rewards: {
88
+ inviter: ({
89
+ kind: "tier";
90
+ reward: {
91
+ id: string;
92
+ title: string;
93
+ tiers: {
94
+ id: string;
95
+ title: string;
96
+ }[];
97
+ inventory: {
98
+ kind: "untracked";
99
+ };
100
+ fulfillment: {
101
+ kind: "staff-handover";
102
+ };
103
+ };
104
+ tier: string;
105
+ } | {
106
+ kind: "points";
107
+ balance: string;
108
+ amount: number;
109
+ })[];
110
+ invitee: ({
111
+ kind: "tier";
112
+ reward: {
113
+ id: string;
114
+ title: string;
115
+ tiers: {
116
+ id: string;
117
+ title: string;
118
+ }[];
119
+ inventory: {
120
+ kind: "untracked";
121
+ };
122
+ fulfillment: {
123
+ kind: "staff-handover";
124
+ };
125
+ };
126
+ tier: string;
127
+ } | {
128
+ kind: "points";
129
+ balance: string;
130
+ amount: number;
131
+ })[];
132
+ };
133
+ qualification: {
134
+ kind: "signup";
135
+ } | {
136
+ kind: "quest";
137
+ quest: string;
138
+ } | {
139
+ kind: "external";
140
+ };
141
+ enabled: boolean;
142
+ inviterGroup?: string | undefined;
143
+ milestones: {
144
+ id: string;
145
+ count: number;
146
+ rewards: ({
147
+ kind: "tier";
148
+ reward: {
149
+ id: string;
150
+ title: string;
151
+ tiers: {
152
+ id: string;
153
+ title: string;
154
+ }[];
155
+ inventory: {
156
+ kind: "untracked";
157
+ };
158
+ fulfillment: {
159
+ kind: "staff-handover";
160
+ };
161
+ };
162
+ tier: string;
163
+ } | {
164
+ kind: "points";
165
+ balance: string;
166
+ amount: number;
167
+ })[];
168
+ }[];
169
+ bonuses: {
170
+ id: string;
171
+ balance: string;
172
+ basisPoints: number;
173
+ external: boolean;
174
+ quests?: string[] | undefined;
175
+ durationDays?: number | undefined;
176
+ maxPoints?: number | undefined;
177
+ }[];
178
+ key: string;
179
+ };
180
+ declare function defineLeaderboard(input: Omit<z.input<typeof leaderboardAuthoringSchema>, "key" | "id"> & AuthoringIdentity): {
181
+ id: string;
182
+ title: string;
183
+ balance: string;
184
+ group?: string | undefined;
185
+ score: {
186
+ kind: "balance";
187
+ } | {
188
+ window: {
189
+ kind: "fixed";
190
+ start: number;
191
+ end: number;
192
+ } | {
193
+ kind: "all-time";
194
+ } | {
195
+ kind: "rolling";
196
+ days: number;
197
+ } | {
198
+ kind: "calendar";
199
+ period: "day" | "week" | "month";
200
+ timeZone: string;
201
+ };
202
+ kind: "earned";
203
+ quests?: string[] | undefined;
204
+ } | {
205
+ kind: "net";
206
+ window: {
207
+ kind: "fixed";
208
+ start: number;
209
+ end: number;
210
+ } | {
211
+ kind: "all-time";
212
+ } | {
213
+ kind: "rolling";
214
+ days: number;
215
+ } | {
216
+ kind: "calendar";
217
+ period: "day" | "week" | "month";
218
+ timeZone: string;
219
+ };
220
+ };
221
+ access: "participants" | "public";
222
+ key: string;
223
+ };
224
+ declare const x: {
225
+ search: (input: {
226
+ query: string;
227
+ }) => {
228
+ kind: "x-search";
229
+ query: string;
230
+ };
231
+ };
232
+ /**
233
+ * Records your own code sends with `trackers.ingest`. With `identities`, each record's author, and
234
+ * each named account in `accounts`, is a verified identity of one of those kinds, which Relay
235
+ * attributes to the member who verified it, so quests can trigger from the tracker. A record states
236
+ * each account's `kind` unless the source names exactly one.
237
+ */
238
+ declare const customSource: (namespace: string, options?: {
239
+ identities?: IdentityKind[];
240
+ accounts?: string[];
241
+ }) => {
242
+ kind: "custom";
243
+ namespace: string;
244
+ identities?: ("x" | "discord" | "member" | "wallet")[] | undefined;
245
+ accounts?: string[] | undefined;
246
+ authors?: "wallet" | undefined;
247
+ };
248
+ declare function defineTracker(input: z.input<typeof trackerDefinitionSchema>): TrackerDefinition;
249
+ type ChannelTypes = Extract<ResourceSource, {
250
+ resource: "channel";
251
+ }>["types"];
252
+ declare const discord: {
253
+ roles(options?: {
254
+ assignable?: boolean;
255
+ }): ResourceSource;
256
+ channels(options?: {
257
+ types?: ChannelTypes;
258
+ }): ResourceSource;
259
+ };
260
+ declare const pointLedgers: () => ResourceSource;
261
+ type Label = {
262
+ label: string;
263
+ description?: string;
264
+ };
265
+ declare const settings: {
266
+ pointLedger(options: Label & {
267
+ default: string;
268
+ }): z.ZodDefault<z.ZodString>;
269
+ datetime(options: Label & {
270
+ default: string;
271
+ }): z.ZodDefault<z.ZodPipe<z.ZodISODateTime, z.ZodTransform<string, string>>>;
272
+ resource(options: Label & {
273
+ source: ResourceSource;
274
+ default?: string;
275
+ }): z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>>;
276
+ quiz(options: Label & {
277
+ default: QuizContent;
278
+ }): z.ZodDefault<z.ZodArray<z.ZodObject<{
279
+ id: z.ZodString;
280
+ prompt: z.ZodString;
281
+ choices: z.ZodArray<z.ZodObject<{
282
+ id: z.ZodString;
283
+ label: z.ZodString;
284
+ }, z.core.$strict>>;
285
+ correct: z.ZodString;
286
+ }, z.core.$strict>>>;
287
+ text(options: Label & {
288
+ default: string;
289
+ minLength?: number;
290
+ maxLength?: number;
291
+ multiline?: boolean;
292
+ }): z.ZodDefault<z.ZodString>;
293
+ integer(options: Label & {
294
+ default: number;
295
+ min: number;
296
+ max: number;
297
+ }): z.ZodDefault<z.ZodNumber>;
298
+ boolean(options: Label & {
299
+ default: boolean;
300
+ }): z.ZodDefault<z.ZodBoolean>;
301
+ choice<const T extends readonly [string, ...string[]]>(options: Label & {
302
+ options: T;
303
+ default: T[number];
304
+ }): z.ZodDefault<z.ZodEnum<{ [k_1 in T[number]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>>;
305
+ object<T extends Record<string, z.ZodType>>(shape: T): z.ZodObject<{ -readonly [P in keyof T]: T[P]; }, z.core.$strict>;
306
+ };
5
307
 
6
308
  type Reward = z.infer<typeof rewardSchema>;
7
309
  declare const points: (balance: string, amount: number) => {
@@ -99,7 +401,7 @@ declare function automatic(input: TrackerTriggerInput): {
99
401
  declare const budget: (definition: Budget) => {
100
402
  id: string;
101
403
  scope: "member" | "project";
102
- period: "lifetime" | "day" | "week";
404
+ period: "day" | "lifetime" | "week";
103
405
  limit: number;
104
406
  cost: number | {
105
407
  balance: string;
@@ -399,12 +701,12 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
399
701
  kind: "resource";
400
702
  default: string;
401
703
  source: {
402
- provider: "domino";
403
- resource: "point-ledger";
404
- } | {
405
704
  provider: "discord";
406
705
  resource: "channel";
407
706
  types: ("text" | "announcement")[];
707
+ } | {
708
+ provider: "domino";
709
+ resource: "point-ledger";
408
710
  } | {
409
711
  provider: "discord";
410
712
  resource: "role";
@@ -501,9 +803,9 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
501
803
  start: number;
502
804
  end?: number | undefined;
503
805
  };
504
- enrollment: "required" | "none";
806
+ enrollment: "none" | "required";
505
807
  posts: "after-enrollment" | "since-start";
506
- historical: "staff" | "automatic" | "claim";
808
+ historical: "automatic" | "claim" | "staff";
507
809
  } | undefined;
508
810
  tracker?: {
509
811
  tracker: string;
@@ -537,7 +839,7 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
537
839
  minLength: number;
538
840
  maxLength: number;
539
841
  };
540
- actor?: "staff" | "member" | undefined;
842
+ actor?: "member" | "staff" | undefined;
541
843
  } | {
542
844
  kind: "manual";
543
845
  input: "url";
@@ -545,11 +847,11 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
545
847
  required: boolean;
546
848
  allowedHosts?: string[] | undefined;
547
849
  };
548
- actor?: "staff" | "member" | undefined;
850
+ actor?: "member" | "staff" | undefined;
549
851
  } | {
550
852
  kind: "manual";
551
- input: "photo" | "quiz" | "none";
552
- actor?: "staff" | "member" | undefined;
853
+ input: "none" | "quiz" | "photo";
854
+ actor?: "member" | "staff" | undefined;
553
855
  };
554
856
  requires: {
555
857
  quest: string;
@@ -567,7 +869,7 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
567
869
  budgets: {
568
870
  id: string;
569
871
  scope: "member" | "project";
570
- period: "lifetime" | "day" | "week";
872
+ period: "day" | "lifetime" | "week";
571
873
  limit: number;
572
874
  cost: number | {
573
875
  balance: string;
@@ -591,4 +893,4 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
591
893
  * Console instances receive independent quest identities and pinned versions. */
592
894
  declare const defineQuestType: typeof defineQuest;
593
895
 
594
- export { type EvaluationContext, type PerformanceOutcome, TrackerTriggerContext, type TrackerTriggerInput, WalletBalance, WalletBalanceQuery, automatic, budget, completed, decision, defineQuest, defineQuestType, defineTieredReward, discordRole, evaluators, evidence, keyed, manual, once, points, staffHandover, untracked };
896
+ export { type EvaluationContext, ImageReader, type PerformanceOutcome, TrackerReader, TrackerTriggerContext, type TrackerTriggerInput, WalletBalance, WalletBalanceQuery, XReader, automatic, budget, completed, content, customSource, decision, defineEngagementReward, defineLeaderboard, defineQuest, defineQuestType, defineReferral, defineTieredReward, defineTracker, discord, discordRole, evaluators, evidence, keyed, manual, once, perContent, pointLedgers, points, settings, staffHandover, streak, untracked, x };
package/dist/authoring.js CHANGED
@@ -1,49 +1,203 @@
1
1
  import {
2
- authoringKey,
3
- defineEngagementReward,
4
- defineLeaderboard,
5
- defineReferral,
6
2
  formatUnits,
7
3
  parseUnits
8
- } from "./chunk-ZKJBCQNI.js";
4
+ } from "./chunk-V7UKZLHA.js";
9
5
  import {
10
- isEvmChainId
11
- } from "./chunk-XEQDW7FM.js";
6
+ authoringKey,
7
+ engagementDefinitionSchema,
8
+ engagementScoreInputSchema,
9
+ engagementScoreSchema,
10
+ isEvmChainId,
11
+ leaderboardAuthoringSchema,
12
+ referralAuthoringSchema
13
+ } from "./chunk-V7EZUZ3Z.js";
12
14
  import {
13
15
  admittedContentSchema,
14
16
  budgetSchema,
15
- content,
16
17
  contentPerformancePolicySchema,
17
18
  contentPerformanceSnapshotSchema,
18
- customSource,
19
+ contentPolicySchema,
20
+ customSourceSchema,
19
21
  decisionSchema,
20
22
  defaultTriggerMode,
21
- defineTracker,
22
- discord,
23
+ identifier,
23
24
  integrationRewardSchema,
24
25
  parseSettings,
25
- perContent,
26
- pointLedgers,
27
26
  pointsRewardSchema,
28
27
  questDescriptionSchema,
29
28
  quizAnswersSchema,
29
+ quizContentSchema,
30
+ resourceSourceSchema,
30
31
  rewardBundleSchema,
31
32
  settingFieldSchema,
32
- settings,
33
+ settingInstant,
34
+ settingResourceId,
33
35
  sourceIdentities,
34
- streak,
36
+ streakPolicySchema,
35
37
  textOptionsSchema,
36
38
  tierRewardSchema,
37
39
  tieredRewardDefinitionSchema,
40
+ trackerDefinitionSchema,
38
41
  trackerTriggerContextSchema,
39
42
  trackerTriggerPolicySchema,
40
43
  urlOptionsSchema,
41
- x,
42
- xAccountRoles
43
- } from "./chunk-BRESOTKV.js";
44
+ xAccountRoles,
45
+ xSearchSourceSchema
46
+ } from "./chunk-VARGF4JS.js";
44
47
 
45
- // src/authoring.ts
48
+ // src/builders.ts
46
49
  import { z } from "zod";
50
+ function content(tracker, policy = {}) {
51
+ if (tracker.source.kind !== "x-search") {
52
+ throw new Error("Content quests require an X tracker");
53
+ }
54
+ return {
55
+ kind: "automatic",
56
+ content: contentPolicySchema.parse({
57
+ tracker: tracker.key,
58
+ window: tracker.window,
59
+ ...policy
60
+ })
61
+ };
62
+ }
63
+ function perContent() {
64
+ return {
65
+ kind: "keyed",
66
+ perContent: true,
67
+ key: (ctx) => {
68
+ if (!ctx.content) {
69
+ throw new Error("perContent requires an admitted content item");
70
+ }
71
+ return ctx.content.completionKey;
72
+ }
73
+ };
74
+ }
75
+ function defineEngagementReward(input) {
76
+ const { target, ...config } = input;
77
+ const definition = engagementDefinitionSchema.parse({
78
+ ...config,
79
+ qualifiedBy: typeof input.qualifiedBy === "string" ? input.qualifiedBy : input.qualifiedBy.key
80
+ });
81
+ const selected = z.record(
82
+ z.enum(input.metrics),
83
+ engagementScoreSchema.shape.target
84
+ );
85
+ return {
86
+ key: definition.key,
87
+ describe: () => definition,
88
+ score(raw) {
89
+ const sample = engagementScoreInputSchema.parse(raw);
90
+ return engagementScoreSchema.parse({
91
+ target: target({ metrics: selected.parse(sample.metrics) }),
92
+ baseline: target({ metrics: selected.parse(sample.baseline) })
93
+ });
94
+ }
95
+ };
96
+ }
97
+ var streak = (options) => streakPolicySchema.parse({ kind: "streak", ...options });
98
+ function defineReferral(input) {
99
+ const definition = referralAuthoringSchema.parse(input);
100
+ return {
101
+ ...definition,
102
+ /** @deprecated Use key. */
103
+ id: definition.key
104
+ };
105
+ }
106
+ function defineLeaderboard(input) {
107
+ const definition = leaderboardAuthoringSchema.parse(input);
108
+ return {
109
+ ...definition,
110
+ /** @deprecated Use key. */
111
+ id: definition.key
112
+ };
113
+ }
114
+ var x = {
115
+ search: (input) => xSearchSourceSchema.parse({ kind: "x-search", ...input })
116
+ };
117
+ var customSource = (namespace, options = {}) => customSourceSchema.parse({
118
+ kind: "custom",
119
+ namespace,
120
+ ...options
121
+ });
122
+ function defineTracker(input) {
123
+ return trackerDefinitionSchema.parse(input);
124
+ }
125
+ var discord = {
126
+ roles(options = {}) {
127
+ return resourceSourceSchema.parse({
128
+ provider: "discord",
129
+ resource: "role",
130
+ assignable: options.assignable ?? false
131
+ });
132
+ },
133
+ channels(options = {}) {
134
+ return resourceSourceSchema.parse({
135
+ provider: "discord",
136
+ resource: "channel",
137
+ types: options.types ?? ["text", "announcement"]
138
+ });
139
+ }
140
+ };
141
+ var pointLedgers = () => ({
142
+ provider: "domino",
143
+ resource: "point-ledger"
144
+ });
145
+ var settings = {
146
+ pointLedger(options) {
147
+ const field = {
148
+ ...options,
149
+ kind: "point-ledger",
150
+ default: identifier.parse(options.default)
151
+ };
152
+ return identifier.default(field.default).meta(field);
153
+ },
154
+ datetime(options) {
155
+ const field = {
156
+ ...options,
157
+ kind: "datetime",
158
+ default: settingInstant.parse(options.default)
159
+ };
160
+ return settingInstant.default(field.default).meta(field);
161
+ },
162
+ resource(options) {
163
+ const field = {
164
+ ...options,
165
+ source: resourceSourceSchema.parse(options.source),
166
+ kind: "resource",
167
+ default: settingResourceId.parse(options.default ?? "")
168
+ };
169
+ return settingResourceId.default(field.default).meta(field);
170
+ },
171
+ quiz(options) {
172
+ const value = quizContentSchema.parse(options.default);
173
+ return quizContentSchema.default(value).meta({ ...options, default: value, kind: "quiz" });
174
+ },
175
+ text(options) {
176
+ const field = {
177
+ ...options,
178
+ kind: "text",
179
+ minLength: options.minLength ?? 1,
180
+ maxLength: options.maxLength ?? 2e3,
181
+ multiline: options.multiline ?? false
182
+ };
183
+ return z.string().min(field.minLength).max(field.maxLength).default(field.default).meta(field);
184
+ },
185
+ integer(options) {
186
+ return z.number().int().min(options.min).max(options.max).default(options.default).meta({ ...options, kind: "integer" });
187
+ },
188
+ boolean(options) {
189
+ return z.boolean().default(options.default).meta({ ...options, kind: "boolean" });
190
+ },
191
+ choice(options) {
192
+ return z.enum(options.options).default(options.default).meta({ ...options, kind: "choice" });
193
+ },
194
+ object(shape) {
195
+ return z.object(shape).strict();
196
+ }
197
+ };
198
+
199
+ // src/authoring.ts
200
+ import { z as z2 } from "zod";
47
201
  var points = (balance, amount) => pointsRewardSchema.parse({ kind: "points", balance, amount });
48
202
  var discordRole = (roleId) => integrationRewardSchema.parse({
49
203
  kind: "integration",
@@ -152,7 +306,7 @@ var evaluators = {
152
306
  quiz(answerKey, options = {}) {
153
307
  const expected = quizAnswersSchema.parse(answerKey);
154
308
  const questions = Object.keys(expected);
155
- const minimum = z.number().int().min(1).max(questions.length).parse(options.minimumCorrect ?? questions.length);
309
+ const minimum = z2.number().int().min(1).max(questions.length).parse(options.minimumCorrect ?? questions.length);
156
310
  return async ({ input }) => {
157
311
  const complete = Object.keys(input.answers).length === questions.length && questions.every((question) => Object.hasOwn(input.answers, question));
158
312
  const correct = questions.filter(
@@ -270,9 +424,9 @@ function defineQuest(definition) {
270
424
  throw new Error("Quest has no performance evaluator");
271
425
  }
272
426
  const sample = contentPerformanceSnapshotSchema.parse(ctx.performance);
273
- const metrics = z.record(
274
- z.enum(definition.performance.metrics),
275
- z.number().int().safe().nonnegative()
427
+ const metrics = z2.record(
428
+ z2.enum(definition.performance.metrics),
429
+ z2.number().int().safe().nonnegative()
276
430
  ).parse(sample.metrics);
277
431
  const result2 = await definition.performance.evaluate({
278
432
  settings: settings2,