@b3dotfun/sdk 0.1.69-alpha.0 → 0.1.69-alpha.10

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 (137) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +1 -1
  2. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +1 -1
  3. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -4
  4. package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
  5. package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.js +5 -3
  6. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +1 -2
  7. package/dist/cjs/anyspend/react/components/checkout/KycGate.js +1 -2
  8. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -0
  9. package/dist/cjs/anyspend/react/components/common/OrderStatus.js +37 -6
  10. package/dist/cjs/anyspend/react/components/common/StepProgress.d.ts +2 -0
  11. package/dist/cjs/anyspend/react/components/common/StepProgress.js +7 -2
  12. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -6
  13. package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +3 -1
  14. package/dist/cjs/anyspend/react/hooks/useKycStatus.js +11 -7
  15. package/dist/cjs/app.shared.js +9 -7
  16. package/dist/cjs/global-account/react/components/B3DynamicModal.js +5 -2
  17. package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +3 -1
  18. package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.js +2 -1
  19. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +5 -2
  20. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +3 -3
  21. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +2 -1
  22. package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
  23. package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
  24. package/dist/cjs/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
  25. package/dist/cjs/global-account/react/components/ManageAccount/SessionDurationContent.js +57 -0
  26. package/dist/cjs/global-account/react/components/ManageAccount/SettingsContent.js +12 -29
  27. package/dist/cjs/global-account/react/components/SignInWithB3/components/AuthButton.js +10 -1
  28. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +96 -15
  29. package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
  30. package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.js +15 -2
  31. package/dist/cjs/global-account/react/components/Toast/ToastContext.d.ts +3 -0
  32. package/dist/cjs/global-account/react/components/Toast/ToastContext.js +30 -7
  33. package/dist/cjs/global-account/react/hooks/useAuth.js +26 -15
  34. package/dist/cjs/global-account/react/hooks/useAuthentication.js +23 -12
  35. package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.d.ts +6 -3
  36. package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.js +31 -3
  37. package/dist/cjs/global-account/react/hooks/useConnect.d.ts +2 -2
  38. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +8 -8
  39. package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -1
  40. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +10 -1
  41. package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +0 -18
  42. package/dist/cjs/global-account/react/utils/createWagmiConfig.js +0 -17
  43. package/dist/cjs/shared/utils/session-duration.d.ts +15 -0
  44. package/dist/cjs/shared/utils/session-duration.js +69 -0
  45. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +2 -2
  46. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +2 -2
  47. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -4
  48. package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
  49. package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.js +5 -3
  50. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +2 -3
  51. package/dist/esm/anyspend/react/components/checkout/KycGate.js +2 -3
  52. package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -1
  53. package/dist/esm/anyspend/react/components/common/OrderStatus.js +34 -3
  54. package/dist/esm/anyspend/react/components/common/StepProgress.d.ts +2 -0
  55. package/dist/esm/anyspend/react/components/common/StepProgress.js +4 -2
  56. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +5 -7
  57. package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +3 -1
  58. package/dist/esm/anyspend/react/hooks/useKycStatus.js +9 -5
  59. package/dist/esm/app.shared.js +9 -7
  60. package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -2
  61. package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +3 -1
  62. package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.js +2 -1
  63. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +5 -2
  64. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +3 -3
  65. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +2 -1
  66. package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
  67. package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
  68. package/dist/esm/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
  69. package/dist/esm/global-account/react/components/ManageAccount/SessionDurationContent.js +52 -0
  70. package/dist/esm/global-account/react/components/ManageAccount/SettingsContent.js +12 -29
  71. package/dist/esm/global-account/react/components/SignInWithB3/components/AuthButton.js +11 -2
  72. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +100 -19
  73. package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
  74. package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.js +14 -1
  75. package/dist/esm/global-account/react/components/Toast/ToastContext.d.ts +3 -0
  76. package/dist/esm/global-account/react/components/Toast/ToastContext.js +30 -7
  77. package/dist/esm/global-account/react/hooks/useAuth.js +28 -17
  78. package/dist/esm/global-account/react/hooks/useAuthentication.js +24 -13
  79. package/dist/esm/global-account/react/hooks/useAutoSelectWallet.d.ts +6 -3
  80. package/dist/esm/global-account/react/hooks/useAutoSelectWallet.js +33 -5
  81. package/dist/esm/global-account/react/hooks/useConnect.d.ts +2 -2
  82. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +8 -8
  83. package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -1
  84. package/dist/esm/global-account/react/stores/useModalStore.d.ts +10 -1
  85. package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +0 -18
  86. package/dist/esm/global-account/react/utils/createWagmiConfig.js +0 -16
  87. package/dist/esm/shared/utils/session-duration.d.ts +15 -0
  88. package/dist/esm/shared/utils/session-duration.js +64 -0
  89. package/dist/styles/index.css +1 -1
  90. package/dist/types/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
  91. package/dist/types/anyspend/react/components/common/StepProgress.d.ts +2 -0
  92. package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +3 -1
  93. package/dist/types/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +3 -1
  94. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +5 -2
  95. package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
  96. package/dist/types/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
  97. package/dist/types/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
  98. package/dist/types/global-account/react/components/Toast/ToastContext.d.ts +3 -0
  99. package/dist/types/global-account/react/hooks/useAutoSelectWallet.d.ts +6 -3
  100. package/dist/types/global-account/react/hooks/useConnect.d.ts +2 -2
  101. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +8 -8
  102. package/dist/types/global-account/react/stores/useModalStore.d.ts +10 -1
  103. package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +0 -18
  104. package/dist/types/shared/utils/session-duration.d.ts +15 -0
  105. package/package.json +2 -1
  106. package/src/anyspend/react/components/AnySpendStakeB3.tsx +2 -2
  107. package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +2 -2
  108. package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +2 -4
  109. package/src/anyspend/react/components/checkout/CheckoutSuccess.tsx +13 -3
  110. package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +9 -3
  111. package/src/anyspend/react/components/checkout/KycGate.tsx +8 -3
  112. package/src/anyspend/react/components/common/OrderDetails.tsx +8 -0
  113. package/src/anyspend/react/components/common/OrderStatus.tsx +38 -3
  114. package/src/anyspend/react/components/common/StepProgress.tsx +15 -5
  115. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +5 -7
  116. package/src/anyspend/react/hooks/useKycStatus.ts +8 -5
  117. package/src/app.shared.ts +9 -8
  118. package/src/global-account/react/components/B3DynamicModal.tsx +5 -2
  119. package/src/global-account/react/components/B3Provider/AuthenticationProvider.tsx +4 -0
  120. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +2 -1
  121. package/src/global-account/react/components/B3Provider/B3Provider.tsx +16 -3
  122. package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +5 -0
  123. package/src/global-account/react/components/ManageAccount/SessionDurationContent.tsx +107 -0
  124. package/src/global-account/react/components/ManageAccount/SettingsContent.tsx +28 -30
  125. package/src/global-account/react/components/SignInWithB3/components/AuthButton.tsx +21 -2
  126. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +207 -54
  127. package/src/global-account/react/components/SignInWithB3/utils/signInUtils.ts +19 -3
  128. package/src/global-account/react/components/Toast/ToastContext.tsx +39 -7
  129. package/src/global-account/react/hooks/useAuth.ts +28 -17
  130. package/src/global-account/react/hooks/useAuthentication.ts +24 -13
  131. package/src/global-account/react/hooks/useAutoSelectWallet.ts +40 -6
  132. package/src/global-account/react/hooks/useConnect.tsx +2 -2
  133. package/src/global-account/react/hooks/useTWAuth.tsx +0 -1
  134. package/src/global-account/react/stores/useModalStore.ts +11 -0
  135. package/src/global-account/react/utils/createWagmiConfig.tsx +0 -18
  136. package/src/shared/utils/session-duration.ts +64 -0
  137. package/src/types/torph.d.ts +4 -0
@@ -6,7 +6,7 @@ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
6
6
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
7
7
  import { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
8
8
  import { getConnectors } from "@wagmi/core";
9
- import { useCallback, useContext, useEffect, useRef } from "react";
9
+ import { useCallback, useContext, useEffect, useMemo, useRef } from "react";
10
10
  import {
11
11
  useActiveWallet,
12
12
  useAutoConnect,
@@ -25,7 +25,7 @@ import { useUserQuery } from "./useUserQuery";
25
25
  const debug = debugB3React("useAuthentication");
26
26
 
27
27
  export function useAuthentication(partnerId: string, { skipAutoConnect = false }: { skipAutoConnect?: boolean } = {}) {
28
- const { onConnectCallback, onLogoutCallback } = useContext(LocalSDKContext);
28
+ const { onConnectCallback, onLogoutCallback, disableBSMNTAuthentication } = useContext(LocalSDKContext);
29
29
  const { disconnect } = useDisconnect();
30
30
  const wallets = useConnectedWallets();
31
31
  // Keep refs so logout() always disconnects current wallets, not stale closure values.
@@ -57,7 +57,7 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
57
57
  const { authenticate } = useTWAuth();
58
58
  const { user, setUser } = useUserQuery();
59
59
  const useAutoConnectLoadingPrevious = useRef(false);
60
- const wagmiConfig = createWagmiConfig({ partnerId });
60
+ const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId }), [partnerId]);
61
61
  const { connect } = useConnect();
62
62
  const activeWagmiAccount = useAccount();
63
63
  const { switchAccount } = useSwitchAccount();
@@ -113,9 +113,7 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
113
113
  });
114
114
  }
115
115
  syncWagmiFunc();
116
- // wagmi config shouldn't change
117
- // eslint-disable-next-line react-hooks/exhaustive-deps
118
- }, [partnerId, wallets]);
116
+ }, [wagmiConfig, wallets, connect, switchAccount]);
119
117
 
120
118
  useEffect(() => {
121
119
  syncWagmi();
@@ -142,9 +140,11 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
142
140
  setIsAuthenticating(false);
143
141
  debug("Re-authenticated successfully", { userAuth });
144
142
 
145
- // Authenticate on BSMNT with B3 JWT
146
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
147
- debug("@@b3Jwt", b3Jwt);
143
+ if (!disableBSMNTAuthentication) {
144
+ // Authenticate on BSMNT with B3 JWT
145
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
146
+ debug("@@b3Jwt", b3Jwt);
147
+ }
148
148
 
149
149
  return userAuth;
150
150
  } catch (error) {
@@ -156,14 +156,25 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
156
156
  setIsAuthenticating(false);
157
157
  debug("Fresh authentication successful", { userAuth });
158
158
 
159
- // Authenticate on BSMNT with B3 JWT
160
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
161
- debug("@@b3Jwt", b3Jwt);
159
+ if (!disableBSMNTAuthentication) {
160
+ // Authenticate on BSMNT with B3 JWT
161
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
162
+ debug("@@b3Jwt", b3Jwt);
163
+ }
162
164
 
163
165
  return userAuth;
164
166
  }
165
167
  },
166
- [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting],
168
+ [
169
+ activeWallet,
170
+ partnerId,
171
+ authenticate,
172
+ setIsAuthenticated,
173
+ setIsAuthenticating,
174
+ setUser,
175
+ setHasStartedConnecting,
176
+ disableBSMNTAuthentication,
177
+ ],
167
178
  );
168
179
 
169
180
  const logout = useCallback(
@@ -1,19 +1,53 @@
1
+ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
1
2
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
2
- import { useCallback, useEffect } from "react";
3
- import { getLastAuthProvider, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
4
- import { Wallet } from "thirdweb/wallets";
3
+ import { useCallback, useEffect, useRef } from "react";
4
+ import { getLastAuthProvider, useAddConnectedWallet, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
5
+ import { EIP1193, Wallet } from "thirdweb/wallets";
5
6
  import { useAuthStore } from "../stores";
6
7
 
7
8
  const debug = debugB3React("useAutoSelectWallet");
8
9
 
9
10
  /**
10
- * Hook to automatically select the first EOA wallet when user is authenticated
11
- * Only auto-selects if the last auth was via wallet or no previous auth provider
11
+ * Hook to automatically connect a default EOA provider (if given) and
12
+ * select the first EOA wallet when user is authenticated.
13
+ * Only auto-selects if the last auth was via wallet or no previous auth provider.
12
14
  */
13
- export function useAutoSelectWallet({ enabled }: { enabled: boolean }) {
15
+ export function useAutoSelectWallet({
16
+ enabled,
17
+ defaultEoaProvider,
18
+ }: {
19
+ enabled: boolean;
20
+ defaultEoaProvider?: EIP1193.EIP1193Provider;
21
+ }) {
14
22
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
15
23
  const wallets = useConnectedWallets();
16
24
  const setActiveWallet = useSetActiveWallet();
25
+ const addConnectedWallet = useAddConnectedWallet();
26
+ const hasConnectedProvider = useRef(false);
27
+
28
+ // Auto-connect the default EOA provider (e.g. Farcaster frame wallet) on mount.
29
+ // Uses useAddConnectedWallet instead of useConnect so the wallet is added to
30
+ // connectedWallets WITHOUT becoming the active wallet. This prevents
31
+ // useAuthentication's logout/onTimeout from disconnecting it (logout only
32
+ // disconnects ecosystem wallets and the active wallet).
33
+ useEffect(() => {
34
+ if (!defaultEoaProvider || hasConnectedProvider.current) return;
35
+ hasConnectedProvider.current = true;
36
+
37
+ const connectDefaultProvider = async () => {
38
+ try {
39
+ const wallet = EIP1193.fromProvider({ provider: defaultEoaProvider });
40
+ await wallet.connect({ client });
41
+ addConnectedWallet(wallet);
42
+ debug("Auto-connected default EOA provider", wallet.id);
43
+ } catch (error) {
44
+ debug("Failed to auto-connect default EOA provider", error);
45
+ hasConnectedProvider.current = false;
46
+ }
47
+ };
48
+
49
+ connectDefaultProvider();
50
+ }, [defaultEoaProvider, addConnectedWallet]);
17
51
 
18
52
  const setWallet = useCallback(
19
53
  (wallet: Wallet) => {
@@ -4,7 +4,7 @@ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
4
4
  import { useCallback, useState } from "react";
5
5
  import { Chain } from "thirdweb";
6
6
  import { useConnect as useConnectTW } from "thirdweb/react";
7
- import { ecosystemWallet, SingleStepAuthArgsType } from "thirdweb/wallets";
7
+ import { ecosystemWallet, MultiStepAuthArgsType, SingleStepAuthArgsType } from "thirdweb/wallets";
8
8
  const debug = debugB3React("useConnect");
9
9
 
10
10
  /**
@@ -23,7 +23,7 @@ export function useConnect(partnerId: string, chain?: Chain) {
23
23
  * It is used to connect to a wallet using the thirdweb client.
24
24
  */
25
25
  const connectTw = useCallback(
26
- async (strategyOptions?: SingleStepAuthArgsType) => {
26
+ async (strategyOptions?: MultiStepAuthArgsType | SingleStepAuthArgsType) => {
27
27
  setIsLoading(true);
28
28
  return await connect(async () => {
29
29
  if (!strategyOptions) throw new Error("Strategy options are required");
@@ -12,7 +12,6 @@ import { useSearchParam } from "./useSearchParamsSSR";
12
12
  * @deprecated Use useAuth() instead
13
13
  */
14
14
  export function useTWAuth() {
15
- console.warn("useTWAuth is deprecated. Please migrate to useAuth() for authentication.");
16
15
  const referralCode = useSearchParam("referralCode");
17
16
 
18
17
  const authenticate = useCallback(
@@ -451,6 +451,16 @@ export interface SendModalProps extends BaseModalProps {
451
451
  onSuccess?: (txHash?: string) => void;
452
452
  }
453
453
 
454
+ /**
455
+ * Props for the Session Duration modal
456
+ * Allows users to configure how long they stay signed in
457
+ */
458
+ export interface SessionDurationModalProps extends BaseModalProps {
459
+ type: "sessionDuration";
460
+ partnerId: string;
461
+ chain: Chain;
462
+ }
463
+
454
464
  /**
455
465
  * Props for the Notifications modal
456
466
  * Allows users to manage notification settings and channels
@@ -677,6 +687,7 @@ export type ModalContentType =
677
687
  | DepositModalProps
678
688
  | SendModalProps
679
689
  | NotificationsModalProps
690
+ | SessionDurationModalProps
680
691
  | AnySpendCollectorClubPurchaseProps
681
692
  | AnySpendDepositModalProps
682
693
  | AnySpendWorkflowTriggerModalProps
@@ -38,21 +38,3 @@ export function createWagmiConfig(options: CreateWagmiConfigOptions) {
38
38
  connectors: finalConnectors,
39
39
  });
40
40
  }
41
-
42
- /** Module-level cache — wagmi configs must not be recreated on every render. */
43
- const wagmiConfigCache = new Map<string, ReturnType<typeof createWagmiConfig>>();
44
-
45
- /**
46
- * Returns a cached wagmi config for the given partnerId.
47
- * Use this instead of calling createWagmiConfig() directly inside React components or hooks
48
- * to avoid registering duplicate EventEmitter listeners on every render.
49
- */
50
- export function getCachedWagmiConfig(options: CreateWagmiConfigOptions) {
51
- const key = options.partnerId;
52
- let config = wagmiConfigCache.get(key);
53
- if (!config) {
54
- config = createWagmiConfig(options);
55
- wagmiConfigCache.set(key, config);
56
- }
57
- return config;
58
- }
@@ -0,0 +1,64 @@
1
+ const STORAGE_KEY_PREFIX = "b3-session-duration";
2
+ const DEFAULT_DAYS = 7;
3
+
4
+ // 0 = session cookie (expires when browser closes)
5
+ export const SESSION_DURATION_OPTIONS = [0, 1, 7, 14, 30] as const;
6
+ export type SessionDurationDays = (typeof SESSION_DURATION_OPTIONS)[number];
7
+
8
+ function storageKey(partnerId?: string) {
9
+ return partnerId ? `${STORAGE_KEY_PREFIX}_${partnerId}` : STORAGE_KEY_PREFIX;
10
+ }
11
+
12
+ /**
13
+ * Read session duration for a specific partner.
14
+ *
15
+ * preferences shape: { [partnerId]: { sessionDuration: number }, sessionDuration?: number }
16
+ *
17
+ * Priority: user.preferences[partnerId].sessionDuration
18
+ * → user.preferences.sessionDuration (global fallback)
19
+ * → localStorage (per-partner) → localStorage (global) → default 7d
20
+ */
21
+ export function getSessionDurationDays(userPreferences?: Record<string, any>, partnerId?: string): SessionDurationDays {
22
+ if (userPreferences) {
23
+ if (partnerId) {
24
+ const v = userPreferences[partnerId]?.sessionDuration;
25
+ if (SESSION_DURATION_OPTIONS.includes(v as SessionDurationDays)) return v as SessionDurationDays;
26
+ }
27
+ const v = userPreferences["sessionDuration"];
28
+ if (SESSION_DURATION_OPTIONS.includes(v as SessionDurationDays)) return v as SessionDurationDays;
29
+ }
30
+ try {
31
+ if (partnerId) {
32
+ const stored = localStorage.getItem(storageKey(partnerId));
33
+ if (stored !== null) {
34
+ const parsed = Number(stored);
35
+ if (SESSION_DURATION_OPTIONS.includes(parsed as SessionDurationDays)) return parsed as SessionDurationDays;
36
+ }
37
+ }
38
+ const stored = localStorage.getItem(STORAGE_KEY_PREFIX);
39
+ if (stored !== null) {
40
+ const parsed = Number(stored);
41
+ if (SESSION_DURATION_OPTIONS.includes(parsed as SessionDurationDays)) return parsed as SessionDurationDays;
42
+ }
43
+ } catch {
44
+ // localStorage unavailable (e.g. SSR)
45
+ }
46
+ return DEFAULT_DAYS;
47
+ }
48
+
49
+ export const SESSION_DURATION_LABELS: Record<SessionDurationDays, string> = {
50
+ 0: "Session only",
51
+ 1: "1 day",
52
+ 7: "7 days",
53
+ 14: "14 days",
54
+ 30: "30 days",
55
+ };
56
+
57
+ /** Cache the preference locally so it's available immediately on next login */
58
+ export function setSessionDurationDays(days: SessionDurationDays, partnerId?: string): void {
59
+ try {
60
+ localStorage.setItem(storageKey(partnerId), String(days));
61
+ } catch {
62
+ // ignore
63
+ }
64
+ }
@@ -0,0 +1,4 @@
1
+ declare module "torph/react" {
2
+ import type { JSX } from "react";
3
+ export function TextMorph(props: { children: string; className?: string }): JSX.Element;
4
+ }