@powerhousedao/reactor-browser 6.2.2-dev.6 → 6.2.2-dev.60

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 (66) hide show
  1. package/README.md +283 -0
  2. package/dist/attachment-service-DTFJRf5j.d.ts +1057 -0
  3. package/dist/attachment-service-DTFJRf5j.d.ts.map +1 -0
  4. package/dist/{client-_Gh2Uf0E.js → client-DB8gP4hz.js} +79 -13
  5. package/dist/client-DB8gP4hz.js.map +1 -0
  6. package/dist/client-DjkEpwu_.d.ts +14 -0
  7. package/dist/client-DjkEpwu_.d.ts.map +1 -0
  8. package/dist/{client-u13cr-Vg.js → client-Zz_l9QzI.js} +30 -3
  9. package/dist/client-Zz_l9QzI.js.map +1 -0
  10. package/dist/{document-by-id-dLYFX-xz.js → document-by-id-BSZqTN66.js} +81 -51
  11. package/dist/document-by-id-BSZqTN66.js.map +1 -0
  12. package/dist/document-operations-C6nce9dH.js +2928 -0
  13. package/dist/document-operations-C6nce9dH.js.map +1 -0
  14. package/dist/global-pg5gy2eZ.d.ts +400 -0
  15. package/dist/global-pg5gy2eZ.d.ts.map +1 -0
  16. package/dist/index-CxxxP14A.d.ts +144 -0
  17. package/dist/index-CxxxP14A.d.ts.map +1 -0
  18. package/dist/index-DjloxNSR.d.ts +345 -0
  19. package/dist/index-DjloxNSR.d.ts.map +1 -0
  20. package/dist/index.d.ts +305 -709
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +608 -1660
  23. package/dist/index.js.map +1 -1
  24. package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-CaCFdEG4.d.ts} +4 -2
  25. package/dist/inspector-proxy-CaCFdEG4.d.ts.map +1 -0
  26. package/dist/{make-ph-event-functions-BHoLPif5.js → make-ph-event-functions-DBq3iWYn.js} +1 -1
  27. package/dist/{make-ph-event-functions-BHoLPif5.js.map → make-ph-event-functions-DBq3iWYn.js.map} +1 -1
  28. package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-BtEalg1H.d.ts} +2 -142
  29. package/dist/pglite-CntadC_p-BtEalg1H.d.ts.map +1 -0
  30. package/dist/{relational-Dj06-YkI.js → relational-C_0GdGVN.js} +2 -2
  31. package/dist/{relational-Dj06-YkI.js.map → relational-C_0GdGVN.js.map} +1 -1
  32. package/dist/renown-BZabzj4l.js +68 -0
  33. package/dist/renown-BZabzj4l.js.map +1 -0
  34. package/dist/{renown-D-1c_Bvx.js → renown-C7a1ygsj.js} +471 -57
  35. package/dist/renown-C7a1ygsj.js.map +1 -0
  36. package/dist/src/analytics/index.d.ts +1 -1
  37. package/dist/src/analytics/index.js +2 -1
  38. package/dist/src/analytics/index.js.map +1 -1
  39. package/dist/src/graphql/client.d.ts +3 -2
  40. package/dist/src/graphql/client.js +1 -1
  41. package/dist/src/graphql-client/entry.d.ts +4 -0
  42. package/dist/src/graphql-client/entry.js +3 -0
  43. package/dist/src/relational/index.d.ts +1 -1
  44. package/dist/src/relational/index.js +1 -1
  45. package/dist/src/renown/index.d.ts +2 -2
  46. package/dist/src/renown/index.js +3 -2
  47. package/dist/src/rpc/index.d.ts +6 -3
  48. package/dist/src/rpc/index.d.ts.map +1 -1
  49. package/dist/src/rpc/index.js +41 -10
  50. package/dist/src/rpc/index.js.map +1 -1
  51. package/dist/store-DAJq6vSs.js +37 -0
  52. package/dist/store-DAJq6vSs.js.map +1 -0
  53. package/dist/{client-09xv0Dq6.d.ts → types-4rfAFZQd.d.ts} +87 -19
  54. package/dist/types-4rfAFZQd.d.ts.map +1 -0
  55. package/dist/{types-CPV0Cnsy.d.ts → types-wGaiXwjh.d.ts} +1 -1
  56. package/dist/{types-CPV0Cnsy.d.ts.map → types-wGaiXwjh.d.ts.map} +1 -1
  57. package/package.json +16 -10
  58. package/dist/client-09xv0Dq6.d.ts.map +0 -1
  59. package/dist/client-_Gh2Uf0E.js.map +0 -1
  60. package/dist/client-u13cr-Vg.js.map +0 -1
  61. package/dist/document-by-id-dLYFX-xz.js.map +0 -1
  62. package/dist/index-D3bV5rcl.d.ts +0 -216
  63. package/dist/index-D3bV5rcl.d.ts.map +0 -1
  64. package/dist/index-DS4W07Y8.d.ts.map +0 -1
  65. package/dist/inspector-proxy-CvQDDxmT.d.ts.map +0 -1
  66. package/dist/renown-D-1c_Bvx.js.map +0 -1
@@ -1,42 +1,69 @@
1
- import { t as makePHEventFunctions } from "./make-ph-event-functions-BHoLPif5.js";
1
+ import { a as useRenown, c as RENOWN_INITIAL_UNKNOWN, i as useLoginStatus, l as RenownInitialUserProvider, n as setRenown, o as useUser, s as RENOWN_INITIAL_ANONYMOUS, t as addRenownEventHandler, u as useRenownInitialAuth } from "./renown-BZabzj4l.js";
2
2
  import { logger } from "document-model";
3
- import { Children, cloneElement, forwardRef, isValidElement, useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
4
- import { BrowserKeyStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, DOMAIN_TYPE, ISSUER_TYPE, RenownBuilder, RenownCryptoBuilder, VERIFIABLE_CREDENTIAL_EIP712_TYPE } from "@renown/sdk";
3
+ import { Children, cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- //#region src/hooks/loading.ts
7
- const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
8
- const loading = null;
9
- //#endregion
10
- //#region src/hooks/renown.ts
11
- const renownEventFunctions = makePHEventFunctions("renown");
12
- /** Adds an event handler for the renown instance */
13
- const addRenownEventHandler = renownEventFunctions.addEventHandler;
14
- /** Returns the renown instance */
15
- const useRenown = renownEventFunctions.useValue;
16
- /** Sets the renown instance */
17
- const setRenown = renownEventFunctions.setValue;
18
- /** Returns the DID from the renown instance */
19
- function useDid() {
20
- return useRenown()?.did;
21
- }
22
- /** Returns the current user from the renown instance, subscribing to user events */
23
- function useUser() {
24
- const renown = useRenown();
25
- const [user, setUser] = useState(renown?.user);
26
- useEffect(() => {
27
- setUser(renown?.user);
28
- if (!renown) return;
29
- return renown.on("user", setUser);
30
- }, [renown]);
31
- return user;
32
- }
33
- /** Returns the login status, subscribing to renown status events */
34
- function useLoginStatus() {
35
- const renown = useRenown();
36
- return useSyncExternalStore((cb) => {
37
- if (!renown) return () => {};
38
- return renown.on("status", cb);
39
- }, () => renown === null ? "loading" : renown?.status, () => void 0);
5
+ import { BrowserKeyStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, DOMAIN_TYPE, ISSUER_TYPE, RenownBuilder, RenownCryptoBuilder, VERIFIABLE_CREDENTIAL_EIP712_TYPE, readPersistedUser } from "@renown/sdk";
6
+ import { LoginMethod, isWalletRedirectReturn, resolveAdapters } from "@renown/sdk/wallet";
7
+ //#region src/renown/wallet-registry.ts
8
+ let activeWalletController;
9
+ let controllerWaiters = [];
10
+ let walletActivator;
11
+ function setActiveWalletController(controller) {
12
+ activeWalletController = controller;
13
+ if (controller) {
14
+ const waiters = controllerWaiters;
15
+ controllerWaiters = [];
16
+ waiters.forEach(({ resolve }) => resolve(controller));
17
+ }
18
+ }
19
+ function failWalletActivation(error) {
20
+ const waiters = controllerWaiters;
21
+ controllerWaiters = [];
22
+ waiters.forEach(({ reject }) => reject(error));
23
+ }
24
+ function getActiveWalletController() {
25
+ return activeWalletController;
26
+ }
27
+ function setWalletActivator(activator) {
28
+ walletActivator = activator;
29
+ }
30
+ function getWalletActivator() {
31
+ return walletActivator;
32
+ }
33
+ function whenWalletControllerReady() {
34
+ if (activeWalletController) return Promise.resolve(activeWalletController);
35
+ return new Promise((resolve, reject) => controllerWaiters.push({
36
+ resolve,
37
+ reject
38
+ }));
39
+ }
40
+ const NO_DESCRIPTORS = Object.freeze([]);
41
+ const DESCRIPTOR_STORE = Symbol.for("@powerhousedao/reactor-browser:renown-wallet-descriptors");
42
+ function descriptorStore() {
43
+ const host = globalThis;
44
+ return host[DESCRIPTOR_STORE] ??= {
45
+ descriptors: NO_DESCRIPTORS,
46
+ listeners: /* @__PURE__ */ new Set()
47
+ };
48
+ }
49
+ function setWalletDescriptors(descriptors) {
50
+ const store = descriptorStore();
51
+ const next = descriptors ?? NO_DESCRIPTORS;
52
+ if (next === store.descriptors) return;
53
+ if (next.length === 0 && store.descriptors.length === 0) return;
54
+ store.descriptors = next;
55
+ store.listeners.forEach((listener) => listener());
56
+ }
57
+ function getWalletDescriptors() {
58
+ return descriptorStore().descriptors;
59
+ }
60
+ function getServerWalletDescriptors() {
61
+ return NO_DESCRIPTORS;
62
+ }
63
+ function subscribeWalletDescriptors(listener) {
64
+ const { listeners } = descriptorStore();
65
+ listeners.add(listener);
66
+ return () => listeners.delete(listener);
40
67
  }
41
68
  //#endregion
42
69
  //#region src/renown/constants.ts
@@ -44,7 +71,7 @@ const RENOWN_URL = "https://www.renown.id";
44
71
  const RENOWN_NETWORK_ID = "eip155";
45
72
  const RENOWN_CHAIN_ID = "1";
46
73
  //#endregion
47
- //#region src/renown/utils.ts
74
+ //#region src/renown/session.ts
48
75
  function openRenown(documentId) {
49
76
  const renown = window.ph?.renown;
50
77
  let renownUrl = renown?.baseUrl;
@@ -65,10 +92,47 @@ function openRenown(documentId) {
65
92
  url.searchParams.set("returnUrl", returnUrl.toJSON());
66
93
  window.open(url, "_self")?.focus();
67
94
  }
68
- /**
69
- * Reads the `?user=` DID from the URL if present.
70
- * Returns the DID and cleans up the URL parameter.
71
- */
95
+ async function signIn(session) {
96
+ const renown = window.ph?.renown;
97
+ if (!renown) {
98
+ logger.warn("Renown instance not found, cannot sign in");
99
+ return;
100
+ }
101
+ return renown.signIn({
102
+ address: session.address,
103
+ chainId: session.chainId,
104
+ signTypedData: session.signTypedData
105
+ });
106
+ }
107
+ let inFlightSignIn;
108
+ let inFlightAddress;
109
+ let lastSignedAddress;
110
+ async function completeSignIn(session) {
111
+ const { address } = session;
112
+ if (address === lastSignedAddress) return;
113
+ if (inFlightSignIn && address === inFlightAddress) return inFlightSignIn;
114
+ inFlightAddress = address;
115
+ inFlightSignIn = (async () => {
116
+ try {
117
+ const user = await signIn(session);
118
+ if (user) lastSignedAddress = address;
119
+ return user;
120
+ } finally {
121
+ inFlightSignIn = void 0;
122
+ inFlightAddress = void 0;
123
+ }
124
+ })();
125
+ return inFlightSignIn;
126
+ }
127
+ function resetSignInGuard() {
128
+ inFlightSignIn = void 0;
129
+ inFlightAddress = void 0;
130
+ lastSignedAddress = void 0;
131
+ }
132
+ function hasRedirectSignIn() {
133
+ if (typeof window === "undefined") return false;
134
+ return new URLSearchParams(window.location.search).has("user");
135
+ }
72
136
  function consumeDidFromUrl() {
73
137
  if (typeof window === "undefined") return;
74
138
  const userParam = new URLSearchParams(window.location.search).get("user");
@@ -79,12 +143,6 @@ function consumeDidFromUrl() {
79
143
  window.history.replaceState({}, "", cleanUrl.toString());
80
144
  return userDid;
81
145
  }
82
- /**
83
- * Log in the user. Resolves the user DID from (in order):
84
- * 1. Explicit `userDid` argument
85
- * 2. `?user=` URL parameter (from Renown portal redirect)
86
- * 3. Previously stored session in the Renown instance
87
- */
88
146
  async function login(userDid, renown) {
89
147
  if (!renown) return;
90
148
  const did = userDid ?? consumeDidFromUrl();
@@ -98,7 +156,13 @@ async function login(userDid, renown) {
98
156
  }
99
157
  }
100
158
  async function logout() {
159
+ try {
160
+ await getActiveWalletController()?.disconnect();
161
+ } catch (error) {
162
+ logger.error(error instanceof Error ? error.message : String(error));
163
+ }
101
164
  await (window.ph?.renown)?.logout();
165
+ resetSignInGuard();
102
166
  const url = new URL(window.location.href);
103
167
  if (url.searchParams.has("user")) {
104
168
  url.searchParams.delete("user");
@@ -111,13 +175,20 @@ function truncateAddress$1(address) {
111
175
  if (address.length <= 13) return address;
112
176
  return `${address.slice(0, 7)}...${address.slice(-5)}`;
113
177
  }
178
+ function isUserCancellation(error) {
179
+ const msg = error.message.toLowerCase();
180
+ return msg.includes("exited_auth_flow") || msg.includes("user rejected") || msg.includes("user denied") || msg.includes("userrejected") || msg.includes("cancel");
181
+ }
114
182
  function toRenownAuthStatus(loginStatus, user) {
115
183
  if (loginStatus === "authorized") return user ? "authorized" : "checking";
116
184
  return loginStatus;
117
185
  }
118
186
  function useRenownAuth() {
119
187
  const user = useUser();
120
- const status = toRenownAuthStatus(useLoginStatus(), user);
188
+ const loginStatus = useLoginStatus();
189
+ const [pending, setPending] = useState(false);
190
+ const [error, setError] = useState(void 0);
191
+ const status = toRenownAuthStatus(loginStatus, user);
121
192
  const address = user?.address;
122
193
  const ensName = user?.ens?.name;
123
194
  const avatarUrl = user?.profile?.userImage ?? user?.ens?.avatarUrl;
@@ -131,9 +202,39 @@ function useRenownAuth() {
131
202
  profileId,
132
203
  displayName: ensName ?? user?.profile?.username ?? void 0,
133
204
  displayAddress: address ? truncateAddress$1(address) : void 0,
134
- login: useCallback(() => {
135
- openRenown();
205
+ login: useCallback((session, method) => {
206
+ const existing = getActiveWalletController();
207
+ const activator = getWalletActivator();
208
+ if (!session && !existing && !activator) {
209
+ openRenown();
210
+ return;
211
+ }
212
+ setPending(true);
213
+ setError(void 0);
214
+ (async () => {
215
+ try {
216
+ let resolved = session;
217
+ if (!resolved) {
218
+ const activated = existing ?? (activator ? await activator() : void 0);
219
+ resolved = await (getActiveWalletController() ?? activated)?.connect(method);
220
+ }
221
+ if (!resolved) {
222
+ openRenown();
223
+ return;
224
+ }
225
+ await completeSignIn(resolved);
226
+ } catch (e) {
227
+ const err = e instanceof Error ? e : new Error(String(e));
228
+ if (isUserCancellation(err)) return;
229
+ setError(err);
230
+ if (/switchboard/i.test(err.message)) openRenown();
231
+ } finally {
232
+ setPending(false);
233
+ }
234
+ })();
136
235
  }, []),
236
+ pending,
237
+ error,
137
238
  logout: useCallback(async () => {
138
239
  await logout();
139
240
  }, []),
@@ -142,6 +243,24 @@ function useRenownAuth() {
142
243
  }, [profileId])
143
244
  };
144
245
  }
246
+ const subscribeNothing$1 = () => () => {};
247
+ function useRenownAuthAsync() {
248
+ const auth = useRenownAuth();
249
+ const initial = useRenownInitialAuth();
250
+ const redirectSignIn = useSyncExternalStore(subscribeNothing$1, hasRedirectSignIn, () => false);
251
+ const { user, status, pending } = auth;
252
+ let state;
253
+ if (user) state = "authenticated";
254
+ else if (pending) state = "resolving";
255
+ else if (initial.state === "anonymous" && !redirectSignIn && status !== "checking") state = "unauthenticated";
256
+ else if (status === void 0 || status === "loading" || status === "checking") state = "resolving";
257
+ else state = "unauthenticated";
258
+ return {
259
+ ...auth,
260
+ state,
261
+ isResolving: state === "resolving"
262
+ };
263
+ }
145
264
  //#endregion
146
265
  //#region src/renown/components/icons.tsx
147
266
  function RenownLogo({ width = 71, height = 19, hovered = false, color = "currentColor", className }) {
@@ -849,13 +968,88 @@ async function initRenownCrypto() {
849
968
  return await new RenownCryptoBuilder().withKeyPairStorage(keyStorage).build();
850
969
  }
851
970
  //#endregion
971
+ //#region src/renown/use-renown-session-cookie.ts
972
+ const DEFAULT_ENDPOINT = "/api/renown/session";
973
+ const DEFAULT_EXPIRES_IN = 10080 * 60;
974
+ function useRenownSessionCookie(options = {}) {
975
+ const endpoint = options.endpoint ?? DEFAULT_ENDPOINT;
976
+ const expiresIn = options.expiresIn ?? DEFAULT_EXPIRES_IN;
977
+ const enabled = options.enabled ?? true;
978
+ const { user, displayName, avatarUrl } = useRenownAuth();
979
+ const renown = useRenown();
980
+ const address = user?.address;
981
+ const profile = user?.profile;
982
+ const hadUser = useRef(false);
983
+ const [synced, setSynced] = useState(false);
984
+ useEffect(() => {
985
+ if (!enabled) return;
986
+ const ready = !!renown && typeof renown.getBearerToken === "function";
987
+ if (address && ready) {
988
+ hadUser.current = true;
989
+ setSynced(false);
990
+ let cancelled = false;
991
+ (async () => {
992
+ try {
993
+ const token = await renown.getBearerToken({ expiresIn });
994
+ await fetch(endpoint, {
995
+ method: "POST",
996
+ headers: { "content-type": "application/json" },
997
+ body: JSON.stringify({
998
+ token,
999
+ profile: {
1000
+ name: displayName ?? null,
1001
+ avatar: avatarUrl ?? null,
1002
+ documentId: profile?.documentId ?? null,
1003
+ username: profile?.username ?? null,
1004
+ userImage: profile?.userImage ?? null
1005
+ }
1006
+ })
1007
+ });
1008
+ if (!cancelled) setSynced(true);
1009
+ } catch (error) {
1010
+ console.error("Failed to sync Renown session cookie", error);
1011
+ }
1012
+ })();
1013
+ return () => {
1014
+ cancelled = true;
1015
+ };
1016
+ }
1017
+ if (!address) {
1018
+ setSynced(false);
1019
+ if (hadUser.current) {
1020
+ hadUser.current = false;
1021
+ fetch(endpoint, { method: "DELETE" }).catch(() => {});
1022
+ }
1023
+ }
1024
+ }, [
1025
+ address,
1026
+ displayName,
1027
+ avatarUrl,
1028
+ profile?.documentId,
1029
+ profile?.username,
1030
+ profile?.userImage,
1031
+ renown,
1032
+ endpoint,
1033
+ expiresIn,
1034
+ enabled
1035
+ ]);
1036
+ return { synced };
1037
+ }
1038
+ const RenownSessionSyncedContext = createContext(false);
1039
+ function useRenownSessionSynced() {
1040
+ return useContext(RenownSessionSyncedContext);
1041
+ }
1042
+ //#endregion
852
1043
  //#region src/renown/use-renown-init.ts
853
- async function initRenown(appName, namespace, url) {
1044
+ async function initRenown(appName, namespace, url, switchboardUrl, revalidate, chainId) {
854
1045
  addRenownEventHandler();
855
1046
  setRenown(null);
856
1047
  const renown = await new RenownBuilder(appName, {
857
1048
  basename: namespace,
858
- baseUrl: url
1049
+ baseUrl: url,
1050
+ switchboardUrl,
1051
+ revalidate,
1052
+ chainId
859
1053
  }).build();
860
1054
  setRenown(renown);
861
1055
  await login(void 0, renown);
@@ -874,14 +1068,14 @@ async function initRenown(appName, namespace, url) {
874
1068
  * }
875
1069
  * ```
876
1070
  */
877
- function useRenownInit({ appName, namespace, url }) {
1071
+ function useRenownInit({ appName, namespace, url, switchboardUrl, revalidate = "always", chainId }) {
878
1072
  const promiseRef = useRef(null);
879
1073
  promiseRef.current ??= Promise.withResolvers();
880
1074
  const initRef = useRef(false);
881
1075
  useEffect(() => {
882
1076
  if (initRef.current) return;
883
1077
  initRef.current = true;
884
- initRenown(appName, namespace, url).then(promiseRef.current.resolve).catch(promiseRef.current.reject);
1078
+ initRenown(appName, namespace, url, switchboardUrl, revalidate, chainId).then(promiseRef.current.resolve).catch(promiseRef.current.reject);
885
1079
  }, []);
886
1080
  return promiseRef.current.promise;
887
1081
  }
@@ -908,6 +1102,226 @@ function Renown({ onError, ...initOptions }) {
908
1102
  return null;
909
1103
  }
910
1104
  //#endregion
911
- export { useLoginStatus as A, RENOWN_CHAIN_ID as C, addRenownEventHandler as D, VERIFIABLE_CREDENTIAL_EIP712_TYPE as E, setLoading as F, useLoading as I, useUser as M, addLoadingEventHandler as N, setRenown as O, loading as P, ISSUER_TYPE as S, RENOWN_URL as T, openRenown as _, RenownAuthButton as a, CREDENTIAL_TYPES as b, ChevronDownIcon as c, RenownLogo as d, SpinnerIcon as f, logout as g, login as h, initRenownCrypto as i, useRenown as j, useDid as k, CopyIcon as l, useRenownAuth as m, useRenownInit as n, RenownUserButton as o, UserIcon as p, initConnectCrypto as r, RenownLoginButton as s, Renown as t, DisconnectIcon as u, CREDENTIAL_SCHEMA_EIP712_TYPE as v, RENOWN_NETWORK_ID as w, DOMAIN_TYPE as x, CREDENTIAL_SUBJECT_TYPE as y };
1105
+ //#region src/renown/use-complete-redirect-sign-in.ts
1106
+ function useCompleteRedirectSignIn(metas) {
1107
+ const renown = useRenown();
1108
+ const user = useUser();
1109
+ const [pendingSilentSession, setPendingSilentSession] = useState(null);
1110
+ const oauthReturnRef = useRef(typeof window !== "undefined" && isWalletRedirectReturn(window.location.search, metas));
1111
+ const onSession = useCallback((_id, session) => {
1112
+ setPendingSilentSession(session?.canSignSilently ? session : null);
1113
+ }, []);
1114
+ useEffect(() => {
1115
+ if (!oauthReturnRef.current) return;
1116
+ if (user) {
1117
+ oauthReturnRef.current = false;
1118
+ return;
1119
+ }
1120
+ if (!pendingSilentSession || !renown) return;
1121
+ oauthReturnRef.current = false;
1122
+ Promise.resolve(completeSignIn(pendingSilentSession)).catch((error) => logger.error(error instanceof Error ? error.message : String(error)));
1123
+ }, [
1124
+ pendingSilentSession,
1125
+ renown,
1126
+ user
1127
+ ]);
1128
+ return { onSession };
1129
+ }
1130
+ //#endregion
1131
+ //#region src/renown/wallet-provider.tsx
1132
+ function mergeControllers(mounted) {
1133
+ if (mounted.length === 0) return void 0;
1134
+ return {
1135
+ connect(method) {
1136
+ if (method) {
1137
+ const target = mounted.find((m) => m.meta.supportedMethods.includes(method));
1138
+ if (!target) throw new Error(`No wallet adapter supports login method "${method}"`);
1139
+ return target.controller.connect(method);
1140
+ }
1141
+ const chosen = mounted.at(0);
1142
+ if (!chosen) throw new Error("No wallet adapter available");
1143
+ return chosen.controller.connect(method);
1144
+ },
1145
+ async disconnect() {
1146
+ await Promise.all(mounted.map((m) => m.controller.disconnect()));
1147
+ },
1148
+ getSession() {
1149
+ for (const { controller } of mounted) {
1150
+ const session = controller.getSession();
1151
+ if (session) return session;
1152
+ }
1153
+ }
1154
+ };
1155
+ }
1156
+ function AdapterControllerBridge(props) {
1157
+ const { adapter, onController, onSession } = props;
1158
+ const { meta } = adapter;
1159
+ const controller = adapter.useController();
1160
+ useEffect(() => {
1161
+ onController(meta, controller);
1162
+ return () => onController(meta, void 0);
1163
+ }, [
1164
+ meta,
1165
+ controller,
1166
+ onController
1167
+ ]);
1168
+ useEffect(() => {
1169
+ if (!controller.subscribe) return;
1170
+ return controller.subscribe((session) => onSession(meta.id, session));
1171
+ }, [
1172
+ meta.id,
1173
+ controller,
1174
+ onSession
1175
+ ]);
1176
+ return null;
1177
+ }
1178
+ /** Drop-in provider for Renown in-page wallet sign-in: registers the login activator, lazy-mounts the configured adapters on first click, and merges their controllers for {@link useRenownAuth}. Full walkthrough + examples: the `@powerhousedao/reactor-browser` README ("Renown in-page sign-in") and the Academy Renown authentication guide. Pair with {@link useRenownLoginMethods} to build the login UI. */
1179
+ function RenownWalletProvider({ adapters: adaptersConfig, theme, children }) {
1180
+ const [descriptors] = useState(() => adaptersConfig);
1181
+ const user = useUser();
1182
+ useEffect(() => {
1183
+ if (typeof process !== "undefined" && true) return;
1184
+ if (adaptersConfig === descriptors) return;
1185
+ console.error("RenownWalletProvider: the `adapters` array changed identity after mount, and the new value was ignored. Build it once at module scope (or memoize it) — see the @powerhousedao/reactor-browser README.");
1186
+ }, [adaptersConfig, descriptors]);
1187
+ useEffect(() => {
1188
+ setWalletDescriptors(descriptors);
1189
+ return () => setWalletDescriptors(void 0);
1190
+ }, [descriptors]);
1191
+ const metas = useMemo(() => descriptors?.map((descriptor) => descriptor.meta) ?? [], [descriptors]);
1192
+ const [activated, setActivated] = useState(() => typeof window !== "undefined" && isWalletRedirectReturn(window.location.search, metas));
1193
+ if (user && !activated) setActivated(true);
1194
+ const active = activated;
1195
+ const [adapters, setAdapters] = useState(null);
1196
+ const mountedRef = useRef(/* @__PURE__ */ new Map());
1197
+ const { onSession } = useCompleteRedirectSignIn(metas);
1198
+ useEffect(() => {
1199
+ if (!descriptors) return;
1200
+ setWalletActivator(() => {
1201
+ setActivated(true);
1202
+ return whenWalletControllerReady();
1203
+ });
1204
+ return () => setWalletActivator(void 0);
1205
+ }, [descriptors]);
1206
+ useEffect(() => {
1207
+ if (!active || !descriptors) return;
1208
+ let cancelled = false;
1209
+ resolveAdapters(descriptors).then((resolved) => {
1210
+ if (cancelled) return;
1211
+ if (resolved.length === 0) {
1212
+ failWalletActivation(/* @__PURE__ */ new Error("No wallet adapters were configured for in-page sign-in."));
1213
+ return;
1214
+ }
1215
+ setAdapters(resolved);
1216
+ }).catch((error) => {
1217
+ if (!cancelled) failWalletActivation(error instanceof Error ? error : new Error(String(error)));
1218
+ });
1219
+ return () => {
1220
+ cancelled = true;
1221
+ };
1222
+ }, [active, descriptors]);
1223
+ const onController = useCallback((meta, controller) => {
1224
+ if (controller) mountedRef.current.set(meta.id, {
1225
+ meta,
1226
+ controller
1227
+ });
1228
+ else mountedRef.current.delete(meta.id);
1229
+ setActiveWalletController(mergeControllers(Array.from(mountedRef.current.values())));
1230
+ }, []);
1231
+ return /* @__PURE__ */ jsxs(Fragment, { children: [children, descriptors && active && adapters && adapters.length > 0 ? adapters.reduceRight((acc, adapter) => {
1232
+ const Provider = adapter.Provider;
1233
+ return /* @__PURE__ */ jsx(Provider, {
1234
+ theme,
1235
+ children: acc
1236
+ });
1237
+ }, /* @__PURE__ */ jsx(Fragment, { children: adapters.map((adapter) => /* @__PURE__ */ jsx(AdapterControllerBridge, {
1238
+ adapter,
1239
+ onController,
1240
+ onSession
1241
+ }, adapter.meta.id)) })) : null] });
1242
+ }
1243
+ //#endregion
1244
+ //#region src/renown/provider.tsx
1245
+ const subscribeNothing = () => () => {};
1246
+ function SessionSync({ enabled, endpoint, children }) {
1247
+ const { synced } = useRenownSessionCookie({
1248
+ endpoint,
1249
+ enabled
1250
+ });
1251
+ return /* @__PURE__ */ jsx(RenownSessionSyncedContext.Provider, {
1252
+ value: synced,
1253
+ children
1254
+ });
1255
+ }
1256
+ function RenownProvider({ appName, namespace, url, switchboardUrl, adapters, theme, revalidate, chainId, session, sessionEndpoint, onError, children }) {
1257
+ const isServerSession = session !== void 0;
1258
+ const mounted = useSyncExternalStore(subscribeNothing, () => true, () => false);
1259
+ const seed = useMemo(() => {
1260
+ if (mounted) {
1261
+ const persisted = readPersistedUser(namespace);
1262
+ return persisted ? {
1263
+ state: "authenticated",
1264
+ user: persisted
1265
+ } : RENOWN_INITIAL_ANONYMOUS;
1266
+ }
1267
+ if (!isServerSession) return RENOWN_INITIAL_UNKNOWN;
1268
+ return session?.user ? {
1269
+ state: "authenticated",
1270
+ user: session.user
1271
+ } : RENOWN_INITIAL_ANONYMOUS;
1272
+ }, [
1273
+ mounted,
1274
+ isServerSession,
1275
+ session,
1276
+ namespace
1277
+ ]);
1278
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renown, {
1279
+ appName,
1280
+ namespace,
1281
+ url,
1282
+ switchboardUrl,
1283
+ revalidate,
1284
+ chainId,
1285
+ onError
1286
+ }), /* @__PURE__ */ jsx(RenownInitialUserProvider, {
1287
+ initialAuth: seed,
1288
+ children: /* @__PURE__ */ jsx(RenownWalletProvider, {
1289
+ adapters,
1290
+ theme,
1291
+ children: /* @__PURE__ */ jsx(SessionSync, {
1292
+ enabled: isServerSession,
1293
+ endpoint: sessionEndpoint,
1294
+ children
1295
+ })
1296
+ })
1297
+ })] });
1298
+ }
1299
+ //#endregion
1300
+ //#region src/renown/login-methods.ts
1301
+ const DEFAULT_METHOD_LABELS = {
1302
+ [LoginMethod.WALLET]: "Connect a Wallet",
1303
+ [LoginMethod.GOOGLE]: "Continue with Google",
1304
+ [LoginMethod.EMAIL]: "Continue with Email",
1305
+ [LoginMethod.APPLE]: "Continue with Apple"
1306
+ };
1307
+ /** The login methods the mounted {@link RenownWalletProvider}'s adapters offer, for building a login UI. Reads each descriptor's eager metadata only — no wallet libraries load. Buttons follow the provider's descriptor array order, deduped; empty when no provider is mounted (redirect-only). Wire each to `useRenownAuth().login(undefined, id)`. Labels are overridable. See the reactor-browser README + Academy Renown auth guide. */
1308
+ function useRenownLoginMethods(labels) {
1309
+ const descriptors = useSyncExternalStore(subscribeWalletDescriptors, getWalletDescriptors, getServerWalletDescriptors);
1310
+ return useMemo(() => {
1311
+ const seen = /* @__PURE__ */ new Set();
1312
+ const methods = [];
1313
+ for (const { meta } of descriptors) for (const id of meta.supportedMethods) {
1314
+ if (seen.has(id)) continue;
1315
+ seen.add(id);
1316
+ methods.push({
1317
+ id,
1318
+ label: labels?.[id] ?? DEFAULT_METHOD_LABELS[id] ?? id
1319
+ });
1320
+ }
1321
+ return methods;
1322
+ }, [descriptors, labels]);
1323
+ }
1324
+ //#endregion
1325
+ export { RENOWN_NETWORK_ID as A, openRenown as C, DOMAIN_TYPE as D, CREDENTIAL_TYPES as E, VERIFIABLE_CREDENTIAL_EIP712_TYPE as M, ISSUER_TYPE as O, logout as S, CREDENTIAL_SUBJECT_TYPE as T, SpinnerIcon as _, useRenownInit as a, useRenownAuthAsync as b, initConnectCrypto as c, RenownUserButton as d, RenownLoginButton as f, RenownLogo as g, DisconnectIcon as h, Renown as i, RENOWN_URL as j, RENOWN_CHAIN_ID as k, initRenownCrypto as l, CopyIcon as m, RenownProvider as n, useRenownSessionCookie as o, ChevronDownIcon as p, RenownWalletProvider as r, useRenownSessionSynced as s, useRenownLoginMethods as t, RenownAuthButton as u, UserIcon as v, CREDENTIAL_SCHEMA_EIP712_TYPE as w, login as x, useRenownAuth as y };
912
1326
 
913
- //# sourceMappingURL=renown-D-1c_Bvx.js.map
1327
+ //# sourceMappingURL=renown-C7a1ygsj.js.map