@domino-sdk/relay 0.28.0 → 0.30.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.
@@ -8,17 +8,17 @@ import {
8
8
  discoverSolanaWallets,
9
9
  readSignInMethods,
10
10
  signInOptionsFrom
11
- } from "../chunk-NHSA6ATH.js";
11
+ } from "../chunk-UMKGCDBX.js";
12
12
  import {
13
13
  RelayError,
14
14
  avatarSrc,
15
15
  defaultAvatar,
16
16
  walletAvatarSeed
17
- } from "../chunk-ZP43MHO3.js";
18
- import "../chunk-AKB266O5.js";
19
- import "../chunk-AL5GXMKI.js";
20
- import "../chunk-D6BX627V.js";
21
- import "../chunk-IXLY3A7B.js";
17
+ } from "../chunk-CB7RKKDX.js";
18
+ import "../chunk-HINZLW46.js";
19
+ import "../chunk-TYYGYDYX.js";
20
+ import "../chunk-CWIJDQDT.js";
21
+ import "../chunk-BE5V6RFD.js";
22
22
 
23
23
  // src/react/provider.tsx
24
24
  import { useState as useState3 } from "react";
@@ -689,12 +689,9 @@ function useMe() {
689
689
  return;
690
690
  }
691
691
  let active = true;
692
- const read = () => void relay.me.get().then((value) => active && setMe(value)).catch(() => active && setMe(null));
693
- read();
694
- window.addEventListener(WALLETS_CHANGED, read);
692
+ void relay.me.get().then((value) => active && setMe(value)).catch(() => active && setMe(null));
695
693
  return () => {
696
694
  active = false;
697
- window.removeEventListener(WALLETS_CHANGED, read);
698
695
  };
699
696
  }, [relay, member]);
700
697
  return me;
@@ -985,26 +982,26 @@ function useMyProfile() {
985
982
  )
986
983
  };
987
984
  }
988
- function useProfile(id, options = {}) {
989
- const relay = useRelay();
985
+ function useProfileRead(read, intervalMs, fallback) {
990
986
  const { member } = useExperience();
991
- const { intervalMs = 6e4 } = options;
992
- const [state, setState] = useState8({ status: "loading" });
987
+ const [state, setState] = useState8({
988
+ status: "loading"
989
+ });
993
990
  const refresh = useCallback5(async () => {
994
991
  try {
995
- const profile = await relay.profiles.get(id);
996
- setState({ status: "ready", profile, stale: null });
992
+ const value = await read();
993
+ setState({ status: "ready", value, stale: null });
997
994
  } catch (cause) {
998
995
  if (cause instanceof RelayError && cause.status === 404) {
999
996
  setState({ status: "missing" });
1000
997
  return;
1001
998
  }
1002
- const message = cause instanceof Error && cause.message ? cause.message : "Could not load the profile.";
999
+ const message = cause instanceof Error && cause.message ? cause.message : fallback;
1003
1000
  setState(
1004
1001
  (previous) => previous.status === "ready" ? { ...previous, stale: message } : { status: "error", message }
1005
1002
  );
1006
1003
  }
1007
- }, [relay, id]);
1004
+ }, [read, fallback]);
1008
1005
  useEffect7(() => {
1009
1006
  setState({ status: "loading" });
1010
1007
  void refresh();
@@ -1020,8 +1017,129 @@ function useProfile(id, options = {}) {
1020
1017
  window.removeEventListener(PROFILE_CHANGED, changed);
1021
1018
  };
1022
1019
  }, [refresh, member, intervalMs]);
1020
+ return { state, refresh };
1021
+ }
1022
+ function useProfile(id, options = {}) {
1023
+ const relay = useRelay();
1024
+ const read = useCallback5(() => relay.profiles.get(id), [relay, id]);
1025
+ const { state, refresh } = useProfileRead(
1026
+ read,
1027
+ options.intervalMs ?? 6e4,
1028
+ "Could not load the profile."
1029
+ );
1030
+ const value = state.status === "ready" ? { status: "ready", profile: state.value, stale: state.stale } : state;
1031
+ return { ...value, refresh };
1032
+ }
1033
+ function useLeaderboardPlacement(board, profile, options = {}) {
1034
+ const relay = useRelay();
1035
+ const read = useCallback5(
1036
+ () => relay.leaderboards.placement(board, profile),
1037
+ [relay, board, profile]
1038
+ );
1039
+ const { state, refresh } = useProfileRead(
1040
+ read,
1041
+ options.intervalMs ?? 3e4,
1042
+ "Could not load the leaderboard placement."
1043
+ );
1023
1044
  return { ...state, refresh };
1024
1045
  }
1046
+ function useProfileReferral(profile, program, options = {}) {
1047
+ const relay = useRelay();
1048
+ const read = useCallback5(
1049
+ () => relay.profiles.referral(profile, program),
1050
+ [relay, profile, program]
1051
+ );
1052
+ const { state, refresh } = useProfileRead(
1053
+ read,
1054
+ options.intervalMs ?? 6e4,
1055
+ "Could not load referral progress."
1056
+ );
1057
+ return { ...state, refresh };
1058
+ }
1059
+ function useProfileCompletions(profile, options = {}) {
1060
+ const relay = useRelay();
1061
+ const { member } = useExperience();
1062
+ const { limit = 20 } = options;
1063
+ const [state, setState] = useState8({
1064
+ status: "loading"
1065
+ });
1066
+ const cursor = useRef3(null);
1067
+ const generation = useRef3(0);
1068
+ const paging = useRef3({ ready: false, busy: false });
1069
+ const load = useCallback5(
1070
+ async (first) => {
1071
+ if (first) {
1072
+ generation.current++;
1073
+ paging.current = { ready: false, busy: false };
1074
+ } else {
1075
+ if (!paging.current.ready || paging.current.busy || cursor.current === null) {
1076
+ return;
1077
+ }
1078
+ paging.current.busy = true;
1079
+ setState(
1080
+ (previous) => previous.status === "ready" ? { ...previous, loading: true, error: null } : previous
1081
+ );
1082
+ }
1083
+ const current = generation.current;
1084
+ const own = paging.current;
1085
+ try {
1086
+ const page = await relay.profiles.completions(profile, {
1087
+ limit,
1088
+ ...!first && cursor.current ? { cursor: cursor.current } : {}
1089
+ });
1090
+ if (current !== generation.current) {
1091
+ return;
1092
+ }
1093
+ cursor.current = page.nextCursor;
1094
+ own.ready = true;
1095
+ setState((previous) => ({
1096
+ status: "ready",
1097
+ items: !first && previous.status === "ready" ? [...previous.items, ...page.items] : page.items,
1098
+ more: page.nextCursor !== null,
1099
+ loading: false,
1100
+ error: null
1101
+ }));
1102
+ } catch (cause) {
1103
+ if (current !== generation.current) {
1104
+ return;
1105
+ }
1106
+ if (first && cause instanceof RelayError && cause.status === 404) {
1107
+ setState({ status: "missing" });
1108
+ return;
1109
+ }
1110
+ const message = cause instanceof Error && cause.message ? cause.message : "Could not load completed quests.";
1111
+ setState(
1112
+ (previous) => !first && previous.status === "ready" ? { ...previous, loading: false, error: message } : { status: "error", message }
1113
+ );
1114
+ } finally {
1115
+ if (!first) {
1116
+ own.busy = false;
1117
+ }
1118
+ }
1119
+ },
1120
+ [relay, profile, limit]
1121
+ );
1122
+ useEffect7(() => {
1123
+ setState({ status: "loading" });
1124
+ cursor.current = null;
1125
+ void load(true);
1126
+ const changed = () => void load(true);
1127
+ window.addEventListener(PROFILE_CHANGED, changed);
1128
+ return () => {
1129
+ generation.current++;
1130
+ window.removeEventListener(PROFILE_CHANGED, changed);
1131
+ };
1132
+ }, [load, member]);
1133
+ return {
1134
+ ...state,
1135
+ refresh: () => load(true),
1136
+ /**
1137
+ * Appends the next page; does nothing while one loads, while the first page reloads, or when
1138
+ * there is none.
1139
+ */
1140
+ loadMore: () => load(false)
1141
+ };
1142
+ }
1025
1143
 
1026
1144
  // src/react/referrals.ts
1027
1145
  import { useCallback as useCallback6, useEffect as useEffect8, useRef as useRef4, useState as useState9 } from "react";
@@ -1198,10 +1316,13 @@ export {
1198
1316
  useExperience,
1199
1317
  useInvitation,
1200
1318
  useLeaderboard,
1319
+ useLeaderboardPlacement,
1201
1320
  useMe,
1202
1321
  useMyProfile,
1203
1322
  usePointLedgers,
1204
1323
  useProfile,
1324
+ useProfileCompletions,
1325
+ useProfileReferral,
1205
1326
  useQuest,
1206
1327
  useReferralSummary,
1207
1328
  useRelay,
package/dist/schema.d.ts CHANGED
@@ -310,6 +310,14 @@ declare const questPresentationSchema: z.ZodObject<{
310
310
  }, z.core.$strict>>;
311
311
  }, z.core.$strict>;
312
312
  type QuestPresentation = z.infer<typeof questPresentationSchema>;
313
+ /**
314
+ * How a quest appears on participant profiles. Hidden by default: a completion can reveal what a
315
+ * member holds or did, so each quest opts in.
316
+ */
317
+ declare const questProfileSchema: z.ZodObject<{
318
+ visible: z.ZodBoolean;
319
+ }, z.core.$strict>;
320
+ type QuestProfile = z.infer<typeof questProfileSchema>;
313
321
  declare const questDescriptionSchema: z.ZodObject<{
314
322
  quest: z.ZodString;
315
323
  runtimeVersion: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
@@ -544,6 +552,9 @@ declare const questDescriptionSchema: z.ZodObject<{
544
552
  visible: "visible";
545
553
  hidden: "hidden";
546
554
  }>>;
555
+ profile: z.ZodOptional<z.ZodObject<{
556
+ visible: z.ZodBoolean;
557
+ }, z.core.$strict>>;
547
558
  budgets: z.ZodDefault<z.ZodArray<z.ZodObject<{
548
559
  id: z.ZodString;
549
560
  scope: z.ZodEnum<{
@@ -851,6 +862,9 @@ declare const publishedReleaseSchema: z.ZodUnion<readonly [z.ZodObject<{
851
862
  visible: "visible";
852
863
  hidden: "hidden";
853
864
  }>>;
865
+ profile: z.ZodOptional<z.ZodObject<{
866
+ visible: z.ZodBoolean;
867
+ }, z.core.$strict>>;
854
868
  budgets: z.ZodDefault<z.ZodArray<z.ZodObject<{
855
869
  id: z.ZodString;
856
870
  scope: z.ZodEnum<{
@@ -1155,6 +1169,9 @@ declare const publishedReleaseSchema: z.ZodUnion<readonly [z.ZodObject<{
1155
1169
  metrics: ("likes" | "replies" | "reposts" | "quotes" | "views" | "bookmarks")[];
1156
1170
  maxAgeMs: number;
1157
1171
  } | undefined;
1172
+ profile?: {
1173
+ visible: boolean;
1174
+ } | undefined;
1158
1175
  key?: string | undefined;
1159
1176
  origin?: {
1160
1177
  typeVersion: string;
@@ -1454,6 +1471,9 @@ declare const templateSchema: z.ZodObject<{
1454
1471
  visible: "visible";
1455
1472
  hidden: "hidden";
1456
1473
  }>>;
1474
+ profile: z.ZodOptional<z.ZodObject<{
1475
+ visible: z.ZodBoolean;
1476
+ }, z.core.$strict>>;
1457
1477
  budgets: z.ZodDefault<z.ZodArray<z.ZodObject<{
1458
1478
  id: z.ZodString;
1459
1479
  scope: z.ZodEnum<{
@@ -2363,6 +2383,9 @@ declare const snapshotSchema: z.ZodObject<{
2363
2383
  visible: "visible";
2364
2384
  hidden: "hidden";
2365
2385
  }>>;
2386
+ profile: z.ZodOptional<z.ZodObject<{
2387
+ visible: z.ZodBoolean;
2388
+ }, z.core.$strict>>;
2366
2389
  budgets: z.ZodDefault<z.ZodArray<z.ZodObject<{
2367
2390
  id: z.ZodString;
2368
2391
  scope: z.ZodEnum<{
@@ -2667,6 +2690,9 @@ declare const snapshotSchema: z.ZodObject<{
2667
2690
  metrics: ("likes" | "replies" | "reposts" | "quotes" | "views" | "bookmarks")[];
2668
2691
  maxAgeMs: number;
2669
2692
  } | undefined;
2693
+ profile?: {
2694
+ visible: boolean;
2695
+ } | undefined;
2670
2696
  key?: string | undefined;
2671
2697
  origin?: {
2672
2698
  typeVersion: string;
@@ -3212,4 +3238,4 @@ declare const contentPerformancePageSchema: z.ZodObject<{
3212
3238
  next: z.ZodNullable<z.ZodNumber>;
3213
3239
  }, z.core.$strict>;
3214
3240
 
3215
- export { type Attempt, type ContentPerformanceSnapshot, type Decision, type Entitlement, type MemberPage, type MemberProgress, type PhotoResult, type PickupAvailability, type PublishedRelease, type QuestAvailability, type QuestDescription, type QuestPresentation, type QuestSettingsInput, type QuizEvidence, type ReleaseInput, type ReviewPage, type Reward, type Snapshot, type SubmissionEvidence, type SubmitInput, type TextResult, type TextReviewInput, type TieredRewardDefinition, type TieredRewardReference, artifactSchema, attemptSchema, batchReleaseSchema, beginHandoverSchema, completionRecordSchema, configurePickupSchema, confirmHandoverSchema, contentPerformancePageSchema, contentPerformanceQuerySchema, contentPerformanceSnapshotSchema, createStockItemSchema, decisionSchema, entitlementSchema, errorSchema, eventSchema, evidenceSchema, identifier, integrationRewardSchema, mediaUrlSchema, memberListSchema, memberPageSchema, memberProgressSchema, photoResultSchema, pickupAllocationSchema, pickupAvailabilitySchema, pickupCatalogSchema, pickupPolicySchema, pickupSelectionSchema, pointsRewardSchema, prerequisiteSchema, publishedReleaseSchema, questAvailabilitySchema, questDescriptionSchema, questPresentationSchema, questSettingsInputSchema, quizAnswersSchema, quizEvidenceSchema, releaseSchema, reservationSchema, reviewItemSchema, reviewListSchema, reviewModeSchema, reviewPageSchema, rewardBundleSchema, rewardKey, rewardSchema, snapshotSchema, staffDecisionSchema, stockItemSchema, stockSchema, storedReviewModeSchema, submissionEvidenceSchema, submitSchema, templateSchema, textResultSchema, textReviewInputSchema, tierRewardSchema, tieredRewardDefinitionSchema, tieredRewardReferenceSchema, triggerSchema };
3241
+ export { type Attempt, type ContentPerformanceSnapshot, type Decision, type Entitlement, type MemberPage, type MemberProgress, type PhotoResult, type PickupAvailability, type PublishedRelease, type QuestAvailability, type QuestDescription, type QuestPresentation, type QuestProfile, type QuestSettingsInput, type QuizEvidence, type ReleaseInput, type ReviewPage, type Reward, type Snapshot, type SubmissionEvidence, type SubmitInput, type TextResult, type TextReviewInput, type TieredRewardDefinition, type TieredRewardReference, artifactSchema, attemptSchema, batchReleaseSchema, beginHandoverSchema, completionRecordSchema, configurePickupSchema, confirmHandoverSchema, contentPerformancePageSchema, contentPerformanceQuerySchema, contentPerformanceSnapshotSchema, createStockItemSchema, decisionSchema, entitlementSchema, errorSchema, eventSchema, evidenceSchema, identifier, integrationRewardSchema, mediaUrlSchema, memberListSchema, memberPageSchema, memberProgressSchema, photoResultSchema, pickupAllocationSchema, pickupAvailabilitySchema, pickupCatalogSchema, pickupPolicySchema, pickupSelectionSchema, pointsRewardSchema, prerequisiteSchema, publishedReleaseSchema, questAvailabilitySchema, questDescriptionSchema, questPresentationSchema, questProfileSchema, questSettingsInputSchema, quizAnswersSchema, quizEvidenceSchema, releaseSchema, reservationSchema, reviewItemSchema, reviewListSchema, reviewModeSchema, reviewPageSchema, rewardBundleSchema, rewardKey, rewardSchema, snapshotSchema, staffDecisionSchema, stockItemSchema, stockSchema, storedReviewModeSchema, submissionEvidenceSchema, submitSchema, templateSchema, textResultSchema, textReviewInputSchema, tierRewardSchema, tieredRewardDefinitionSchema, tieredRewardReferenceSchema, triggerSchema };
package/dist/schema.js CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  questAvailabilitySchema,
34
34
  questDescriptionSchema,
35
35
  questPresentationSchema,
36
+ questProfileSchema,
36
37
  questSettingsInputSchema,
37
38
  quizAnswersSchema,
38
39
  quizEvidenceSchema,
@@ -59,7 +60,7 @@ import {
59
60
  tieredRewardDefinitionSchema,
60
61
  tieredRewardReferenceSchema,
61
62
  triggerSchema
62
- } from "./chunk-IXLY3A7B.js";
63
+ } from "./chunk-BE5V6RFD.js";
63
64
  export {
64
65
  artifactSchema,
65
66
  attemptSchema,
@@ -95,6 +96,7 @@ export {
95
96
  questAvailabilitySchema,
96
97
  questDescriptionSchema,
97
98
  questPresentationSchema,
99
+ questProfileSchema,
98
100
  questSettingsInputSchema,
99
101
  quizAnswersSchema,
100
102
  quizEvidenceSchema,