@domino-sdk/relay 1.0.0-next.1 → 1.0.0-next.12

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 (56) hide show
  1. package/README.md +13 -1
  2. package/build.mjs +18 -1
  3. package/dist/authoring.d.ts +461 -51
  4. package/dist/authoring.js +317 -65
  5. package/dist/avatar.d.ts +29 -0
  6. package/dist/avatar.js +21 -0
  7. package/dist/browser.d.ts +325 -2266
  8. package/dist/browser.js +6 -6
  9. package/dist/catalog-qrYne8qV.d.ts +4161 -0
  10. package/dist/chunk-22J4K7ED.js +1426 -0
  11. package/dist/chunk-4LBUTHD6.js +171 -0
  12. package/dist/chunk-5L7XZA4Y.js +1012 -0
  13. package/dist/chunk-6A2V4L3T.js +30 -0
  14. package/dist/{chunk-OQ4ZNOC7.js → chunk-7Q4BGGT6.js} +26 -5
  15. package/dist/{chunk-BGN3CQC6.js → chunk-EWFB35JW.js} +145 -32
  16. package/dist/chunk-LY7SXUNW.js +301 -0
  17. package/dist/chunk-NZA2TLBF.js +68 -0
  18. package/dist/chunk-UW5CQHPQ.js +100 -0
  19. package/dist/chunk-V7UKZLHA.js +35 -0
  20. package/dist/chunk-YYD4QUBO.js +2348 -0
  21. package/dist/client-CW72TaAs.d.ts +2704 -0
  22. package/dist/collection-BGneJ6Bk.d.ts +114 -0
  23. package/dist/deployments-Bc0dPSXN.d.ts +4119 -0
  24. package/dist/identity-integration-CBR8l3ju.d.ts +37 -0
  25. package/dist/images-D0Txfte6.d.ts +234 -0
  26. package/dist/index.d.ts +13 -13133
  27. package/dist/index.js +23 -690
  28. package/dist/integrations-EjQzIApL.d.ts +323 -0
  29. package/dist/internal.d.ts +90 -0
  30. package/dist/internal.js +52 -0
  31. package/dist/observations-bFY4yv2K.d.ts +90 -0
  32. package/dist/pages-KYK1L60W.d.ts +152 -0
  33. package/dist/portal-proxy.js +9 -9
  34. package/dist/profiles-BtOXMGcC.d.ts +297 -0
  35. package/dist/react/index.d.ts +403 -2230
  36. package/dist/react/index.js +165 -23
  37. package/dist/referrals-CvSmxvjm.d.ts +2592 -0
  38. package/dist/request-error-VnTiMXc3.d.ts +52 -0
  39. package/dist/schema-ZfjL-d1N.d.ts +3532 -0
  40. package/dist/schema.d.ts +36 -3375
  41. package/dist/schema.js +547 -3
  42. package/dist/server/index.d.ts +19411 -0
  43. package/dist/server/index.js +1860 -0
  44. package/dist/streaks-CwGReWGt.d.ts +73 -0
  45. package/dist/submission-input-CccwAl5Z.d.ts +83 -0
  46. package/dist/trackers-BsUh5Ky0.d.ts +1333 -0
  47. package/dist/units-CwgsPB_r.d.ts +9 -0
  48. package/dist/vite.d.ts +1 -1
  49. package/dist/vite.js +1 -0
  50. package/dist/wallet-BtiG0Xhr.d.ts +231 -0
  51. package/package.json +22 -5
  52. package/dist/chunk-IZYXEXUO.js +0 -1847
  53. package/dist/chunk-QEN4GHL7.js +0 -624
  54. package/dist/chunk-UI4N4XRZ.js +0 -373
  55. package/dist/chunk-UPWID5KS.js +0 -1833
  56. package/dist/submission-input-JDwq3EVK.d.ts +0 -4986
package/dist/authoring.js CHANGED
@@ -1,49 +1,250 @@
1
1
  import {
2
- authoringKey,
3
- defineEngagementReward,
4
- defineLeaderboard,
5
- defineReferral,
6
2
  formatUnits,
7
3
  parseUnits
8
- } from "./chunk-QEN4GHL7.js";
4
+ } from "./chunk-V7UKZLHA.js";
9
5
  import {
10
- isEvmChainId
11
- } from "./chunk-UI4N4XRZ.js";
6
+ authoringKey,
7
+ engagementDefinitionSchema,
8
+ engagementScoreInputSchema,
9
+ engagementScoreSchema,
10
+ isEvmChainId,
11
+ leaderboardAuthoringSchema,
12
+ referralAuthoringSchema
13
+ } from "./chunk-5L7XZA4Y.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,
32
+ schemaCheckedReader,
31
33
  settingFieldSchema,
32
- settings,
34
+ settingInstant,
35
+ settingResourceId,
33
36
  sourceIdentities,
34
- streak,
37
+ streakPolicySchema,
35
38
  textOptionsSchema,
36
39
  tierRewardSchema,
37
40
  tieredRewardDefinitionSchema,
41
+ trackerDataIssue,
42
+ trackerDataSchema,
43
+ trackerDefinitionSchema,
38
44
  trackerTriggerContextSchema,
39
45
  trackerTriggerPolicySchema,
40
46
  urlOptionsSchema,
41
- x,
42
- xAccountRoles
43
- } from "./chunk-UPWID5KS.js";
47
+ whereSchemaIssue,
48
+ whereSettings,
49
+ xAccountRoles,
50
+ xSearchSourceSchema
51
+ } from "./chunk-YYD4QUBO.js";
44
52
 
45
- // src/authoring.ts
53
+ // src/builders.ts
46
54
  import { z } from "zod";
55
+ function content(tracker, policy = {}) {
56
+ if (tracker.source.kind !== "x-search") {
57
+ throw new Error("Content quests require an X tracker");
58
+ }
59
+ return {
60
+ kind: "automatic",
61
+ content: contentPolicySchema.parse({
62
+ tracker: tracker.key,
63
+ window: tracker.window,
64
+ ...policy
65
+ })
66
+ };
67
+ }
68
+ function perContent() {
69
+ return {
70
+ kind: "keyed",
71
+ perContent: true,
72
+ key: (ctx) => {
73
+ if (!ctx.content) {
74
+ throw new Error("perContent requires an admitted content item");
75
+ }
76
+ return ctx.content.completionKey;
77
+ }
78
+ };
79
+ }
80
+ function defineEngagementReward(input) {
81
+ const { target, ...config } = input;
82
+ const definition = engagementDefinitionSchema.parse({
83
+ ...config,
84
+ qualifiedBy: typeof input.qualifiedBy === "string" ? input.qualifiedBy : input.qualifiedBy.key
85
+ });
86
+ const selected = z.record(
87
+ z.enum(input.metrics),
88
+ engagementScoreSchema.shape.target
89
+ );
90
+ return {
91
+ key: definition.key,
92
+ describe: () => definition,
93
+ score(raw) {
94
+ const sample = engagementScoreInputSchema.parse(raw);
95
+ return engagementScoreSchema.parse({
96
+ target: target({ metrics: selected.parse(sample.metrics) }),
97
+ baseline: target({ metrics: selected.parse(sample.baseline) })
98
+ });
99
+ }
100
+ };
101
+ }
102
+ var streak = (options) => streakPolicySchema.parse({ kind: "streak", ...options });
103
+ function defineReferral(input) {
104
+ const definition = referralAuthoringSchema.parse(input);
105
+ return {
106
+ ...definition,
107
+ /** @deprecated Use key. */
108
+ id: definition.key
109
+ };
110
+ }
111
+ function defineLeaderboard(input) {
112
+ const definition = leaderboardAuthoringSchema.parse(input);
113
+ return {
114
+ ...definition,
115
+ /** @deprecated Use key. */
116
+ id: definition.key
117
+ };
118
+ }
119
+ var x = {
120
+ /** Posts matching an X search. Each record's `data` is the provider's post payload. */
121
+ search: (input) => xSearchSourceSchema.parse({ kind: "x-search", ...input })
122
+ };
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
+ }
140
+ function defineTracker(input) {
141
+ return trackerDefinitionSchema.parse(input);
142
+ }
143
+ var discord = {
144
+ roles(options = {}) {
145
+ return resourceSourceSchema.parse({
146
+ provider: "discord",
147
+ resource: "role",
148
+ assignable: options.assignable ?? false
149
+ });
150
+ },
151
+ channels(options = {}) {
152
+ return resourceSourceSchema.parse({
153
+ provider: "discord",
154
+ resource: "channel",
155
+ types: options.types ?? ["text", "announcement"]
156
+ });
157
+ }
158
+ };
159
+ var pointLedgers = () => ({
160
+ provider: "domino",
161
+ resource: "point-ledger"
162
+ });
163
+ function setting(_kind, schema) {
164
+ return schema;
165
+ }
166
+ var settings = {
167
+ pointLedger(options) {
168
+ const field = {
169
+ ...options,
170
+ kind: "point-ledger",
171
+ default: identifier.parse(options.default)
172
+ };
173
+ return setting(
174
+ "point-ledger",
175
+ identifier.default(field.default).meta(field)
176
+ );
177
+ },
178
+ datetime(options) {
179
+ const field = {
180
+ ...options,
181
+ kind: "datetime",
182
+ default: settingInstant.parse(options.default)
183
+ };
184
+ return setting(
185
+ "datetime",
186
+ settingInstant.default(field.default).meta(field)
187
+ );
188
+ },
189
+ resource(options) {
190
+ const field = {
191
+ ...options,
192
+ source: resourceSourceSchema.parse(options.source),
193
+ kind: "resource",
194
+ default: settingResourceId.parse(options.default ?? "")
195
+ };
196
+ return setting(
197
+ "resource",
198
+ settingResourceId.default(field.default).meta(field)
199
+ );
200
+ },
201
+ quiz(options) {
202
+ const value = quizContentSchema.parse(options.default);
203
+ return setting(
204
+ "quiz",
205
+ quizContentSchema.default(value).meta({ ...options, default: value, kind: "quiz" })
206
+ );
207
+ },
208
+ text(options) {
209
+ const field = {
210
+ ...options,
211
+ kind: "text",
212
+ minLength: options.minLength ?? 1,
213
+ maxLength: options.maxLength ?? 2e3,
214
+ multiline: options.multiline ?? false
215
+ };
216
+ return setting(
217
+ "text",
218
+ z.string().min(field.minLength).max(field.maxLength).default(field.default).meta(field)
219
+ );
220
+ },
221
+ integer(options) {
222
+ return setting(
223
+ "integer",
224
+ z.number().int().min(options.min).max(options.max).default(options.default).meta({ ...options, kind: "integer" })
225
+ );
226
+ },
227
+ boolean(options) {
228
+ return setting(
229
+ "boolean",
230
+ z.boolean().default(options.default).meta({ ...options, kind: "boolean" })
231
+ );
232
+ },
233
+ choice(options) {
234
+ return setting(
235
+ "choice",
236
+ z.enum(options.options).default(options.default).meta({ ...options, kind: "choice" })
237
+ );
238
+ },
239
+ /** A quest's settings: every field is built with one of the builders above. */
240
+ object(shape) {
241
+ return z.object(shape).strict();
242
+ }
243
+ };
244
+
245
+ // src/authoring.ts
246
+ import { z as z2 } from "zod";
247
+ import { z as z3 } from "zod";
47
248
  var points = (balance, amount) => pointsRewardSchema.parse({ kind: "points", balance, amount });
48
249
  var discordRole = (roleId) => integrationRewardSchema.parse({
49
250
  kind: "integration",
@@ -64,6 +265,11 @@ var evidence = {
64
265
  quiz: () => "quiz"
65
266
  };
66
267
  function manual(options) {
268
+ if (options?.actor && options.input !== void 0) {
269
+ throw new Error(
270
+ 'manual() cannot combine actor "staff" with input: staff-captured evidence is not supported. Use manual({ actor: "staff" }) for a staff confirmation, or manual({ input }) for evidence the participant submits.'
271
+ );
272
+ }
67
273
  if (typeof options?.input === "object") {
68
274
  return { kind: "manual", ...options.input };
69
275
  }
@@ -73,6 +279,7 @@ function manual(options) {
73
279
  ...options?.actor ? { actor: options.actor } : {}
74
280
  };
75
281
  }
282
+ var triggerDataSchemas = /* @__PURE__ */ new WeakMap();
76
283
  function automatic(input) {
77
284
  if (!input) {
78
285
  return { kind: "automatic" };
@@ -95,26 +302,34 @@ function automatic(input) {
95
302
  `Tracker "${tracker.key}" has no "${beneficiary}" account: declare it in customSource(namespace, { accounts: ["${beneficiary}"] })`
96
303
  );
97
304
  }
98
- return {
99
- kind: "automatic",
100
- tracker: trackerTriggerPolicySchema.parse({
101
- tracker: tracker.key,
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 } : {},
107
- beneficiary
108
- })
109
- };
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;
110
323
  }
111
324
  return { kind: "automatic", observation: input };
112
325
  }
113
326
  var budget = (definition) => budgetSchema.parse(definition);
114
- var keyed = (key) => ({ kind: "keyed", key });
327
+ var keyed = (key) => ({
328
+ kind: "keyed",
329
+ key
330
+ });
115
331
  var completed = (quest) => ({
116
- quest: typeof quest === "string" ? quest : authoringKey(quest),
117
- scope: "ever"
332
+ quest: typeof quest === "string" ? quest : authoringKey(quest)
118
333
  });
119
334
  var untracked = () => ({ kind: "untracked" });
120
335
  var staffHandover = () => ({ kind: "staff-handover" });
@@ -130,25 +345,25 @@ function defineTieredReward(input) {
130
345
  };
131
346
  }
132
347
  var once = () => ({ kind: "once" });
348
+ function accept(options = {}) {
349
+ return { kind: "accept", ...options };
350
+ }
351
+ function review(options) {
352
+ return { kind: "review", ...options };
353
+ }
133
354
  var decision = {
134
- accept: (options = {}) => ({
135
- kind: "accept",
136
- ...options
137
- }),
355
+ accept,
138
356
  reject: (options) => ({
139
357
  kind: "reject",
140
358
  ...options
141
359
  }),
142
- review: (options) => ({
143
- kind: "review",
144
- ...options
145
- })
360
+ review
146
361
  };
147
362
  var evaluators = {
148
363
  quiz(answerKey, options = {}) {
149
364
  const expected = quizAnswersSchema.parse(answerKey);
150
365
  const questions = Object.keys(expected);
151
- const minimum = z.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);
152
367
  return async ({ input }) => {
153
368
  const complete = Object.keys(input.answers).length === questions.length && questions.every((question) => Object.hasOwn(input.answers, question));
154
369
  const correct = questions.filter(
@@ -178,32 +393,43 @@ function defineQuest(definition) {
178
393
  throw new Error("Performance requires a content trigger");
179
394
  }
180
395
  const trackerTrigger = definition.trigger.kind === "automatic" && definition.trigger.tracker !== void 0;
181
- if (trackerTrigger && definition.completion.kind === "streak") {
182
- throw new Error("Tracker triggers complete once() or keyed()");
183
- }
184
396
  const contentCompletion = "perContent" in definition.completion;
185
397
  if (contentTrigger !== contentCompletion) {
186
398
  throw new Error(
187
399
  "Content triggers require perContent completion, and perContent requires a content trigger"
188
400
  );
189
401
  }
190
- if (definition.completion.kind === "streak" && (definition.trigger.kind !== "automatic" || !definition.trigger.observation)) {
191
- throw new Error("Streaks require an automatic observation trigger");
402
+ const bareAutomatic = definition.trigger.kind === "automatic" && !definition.trigger.observation && !definition.trigger.content && !definition.trigger.tracker;
403
+ if (bareAutomatic && !definition.requires?.length) {
404
+ throw new Error(
405
+ "A bare automatic() quest needs at least one requires entry, such as requires: [completed(quest)]. Give it an observation, content or tracker trigger, or a prerequisite."
406
+ );
407
+ }
408
+ if (bareAutomatic && definition.completion.kind !== "once") {
409
+ throw new Error(
410
+ `A bare automatic() quest cannot use ${definition.completion.kind}() completion. Give it a tracker or observation trigger, or use once().`
411
+ );
192
412
  }
193
413
  if (definition.trigger.kind === "manual" && definition.trigger.input !== "none" && !definition.evaluate) {
194
414
  throw new Error("Evidence quests require an evaluator");
195
415
  }
196
416
  const fields = Object.fromEntries(
197
- Object.entries(definition.settings.shape).map(([key2, schema]) => [
198
- key2,
199
- settingFieldSchema.parse(schema.meta())
200
- ])
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
+ })
201
426
  );
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") {
427
+ for (const setting2 of whereSettings(
428
+ definition.trigger.kind === "automatic" ? definition.trigger.tracker?.where : void 0
429
+ )) {
430
+ if (fields[setting2]?.kind !== "integer") {
205
431
  throw new Error(
206
- `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`
207
433
  );
208
434
  }
209
435
  }
@@ -255,15 +481,24 @@ function defineQuest(definition) {
255
481
  describe,
256
482
  async evaluate(ctx) {
257
483
  const settings2 = definition.settings.parse(ctx.settings);
258
- 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;
259
494
  if (ctx.performance) {
260
495
  if (!definition.performance) {
261
496
  throw new Error("Quest has no performance evaluator");
262
497
  }
263
498
  const sample = contentPerformanceSnapshotSchema.parse(ctx.performance);
264
- const metrics = z.record(
265
- z.enum(definition.performance.metrics),
266
- z.number().int().safe().nonnegative()
499
+ const metrics = z3.record(
500
+ z3.enum(definition.performance.metrics),
501
+ z3.number().int().safe().nonnegative()
267
502
  ).parse(sample.metrics);
268
503
  const result2 = await definition.performance.evaluate({
269
504
  settings: settings2,
@@ -275,6 +510,11 @@ function defineQuest(definition) {
275
510
  if (!result2) {
276
511
  throw new Error("Performance evaluator returned no decision");
277
512
  }
513
+ if (result2.rewards !== void 0) {
514
+ throw new Error(
515
+ "A performance evaluator cannot select rewards. It gates the rewards content evaluation selected: return accept, review or reject with a reason only."
516
+ );
517
+ }
278
518
  return decisionSchema.parse(
279
519
  result2.kind === "accept" ? {
280
520
  kind: "accept",
@@ -284,7 +524,11 @@ function defineQuest(definition) {
284
524
  kind: "review",
285
525
  reason: result2.reason,
286
526
  rewards: sample.rewards
287
- } : { kind: "reject", reason: result2.reason }
527
+ } : {
528
+ kind: "reject",
529
+ reason: result2.reason,
530
+ ...result2.kind === "review" ? { requestedReview: true } : {}
531
+ }
288
532
  );
289
533
  }
290
534
  const result = definition.evaluate ? await definition.evaluate({
@@ -295,8 +539,9 @@ function defineQuest(definition) {
295
539
  observation: ctx.observation ?? null,
296
540
  tracker,
297
541
  eligibleAt: ctx.eligibleAt,
542
+ now: ctx.now,
298
543
  review: ctx.review,
299
- trackers: ctx.trackers,
544
+ trackers: schemaCheckedReader(ctx.trackers),
300
545
  wallet: ctx.wallet,
301
546
  x: ctx.x,
302
547
  images: ctx.images,
@@ -306,7 +551,11 @@ function defineQuest(definition) {
306
551
  throw new Error("Evaluator returned no decision");
307
552
  }
308
553
  if (result.kind === "review" && !ctx.humanReview) {
309
- return decisionSchema.parse({ kind: "reject", reason: result.reason });
554
+ return decisionSchema.parse({
555
+ kind: "reject",
556
+ reason: result.reason,
557
+ requestedReview: true
558
+ });
310
559
  }
311
560
  return decisionSchema.parse(
312
561
  result.kind === "accept" || result.kind === "review" ? {
@@ -315,7 +564,8 @@ function defineQuest(definition) {
315
564
  ...definition.completion.kind === "keyed" ? {
316
565
  completionKey: definition.completion.key({
317
566
  ...ctx,
318
- tracker
567
+ observation: ctx.observation ?? null,
568
+ tracker: pinned
319
569
  })
320
570
  } : {}
321
571
  } : result
@@ -354,7 +604,9 @@ export {
354
604
  settings,
355
605
  staffHandover,
356
606
  streak,
607
+ trackerDataSchema,
357
608
  trackerTriggerContextSchema,
358
609
  untracked,
359
- x
610
+ x,
611
+ z2 as z
360
612
  };
@@ -0,0 +1,29 @@
1
+ import { L as LinkedWallet } from './wallet-BtiG0Xhr.js';
2
+ import { P as ProfileAvatar } from './profiles-BtOXMGcC.js';
3
+ import 'zod';
4
+
5
+ /**
6
+ * The `<img src>` of a profile's avatar (`profile.avatar`). Pictures from accounts are hotlinked
7
+ * and can disappear: on the image's error event, fall back to `defaultAvatar(avatar.seed)`.
8
+ */
9
+ declare function avatarSrc(avatar: ProfileAvatar): string;
10
+ /**
11
+ * A deterministic SVG avatar for `seed`, as a data URI for an `<img src>`. The same seed always
12
+ * gives the same image.
13
+ *
14
+ * Seed avatars that other people see with a value that reveals nothing, such as the `avatarSeed`
15
+ * Relay returns (`relay.me.get()`), never with a wallet address: anyone could compute the avatar
16
+ * of every holder's address and match members to wallets. Use `walletAvatarSeed` only for a
17
+ * member's own wallets, in their own UI.
18
+ */
19
+ declare function defaultAvatar(seed: string): string;
20
+ /** `defaultAvatar` as raw SVG markup, for inlining during server rendering. */
21
+ declare function defaultAvatarSvg(seed: string): string;
22
+ /**
23
+ * The seed for a wallet shown to its own member, such as in their list of linked wallets. EVM and
24
+ * Cosmos addresses are case-folded, so a checksummed and a lowercase address give one image. Never
25
+ * use it on surfaces other people see (see `defaultAvatar`).
26
+ */
27
+ declare function walletAvatarSeed(wallet: Pick<LinkedWallet, "chain" | "address">): string;
28
+
29
+ export { avatarSrc, defaultAvatar, defaultAvatarSvg, walletAvatarSeed };
package/dist/avatar.js ADDED
@@ -0,0 +1,21 @@
1
+ // src/avatar.ts
2
+ import { createAvatar } from "@dicebear/core";
3
+ import * as shapes from "@dicebear/shapes";
4
+ function avatarSrc(avatar) {
5
+ return avatar.source === "generated" ? defaultAvatar(avatar.seed) : avatar.url;
6
+ }
7
+ function defaultAvatar(seed) {
8
+ return createAvatar(shapes, { seed }).toDataUri();
9
+ }
10
+ function defaultAvatarSvg(seed) {
11
+ return createAvatar(shapes, { seed }).toString();
12
+ }
13
+ function walletAvatarSeed(wallet) {
14
+ return `${wallet.chain}:${wallet.chain === "solana" ? wallet.address : wallet.address.toLowerCase()}`;
15
+ }
16
+ export {
17
+ avatarSrc,
18
+ defaultAvatar,
19
+ defaultAvatarSvg,
20
+ walletAvatarSeed
21
+ };