@dynamic-labs-sdk/client 1.33.1 → 1.33.2

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 (80) hide show
  1. package/dist/{apiClient-BbjPoAwE.native.esm.js → apiClient-B0eCQXEJ.native.esm.js} +2 -2
  2. package/dist/{apiClient-BbjPoAwE.native.esm.js.map → apiClient-B0eCQXEJ.native.esm.js.map} +1 -1
  3. package/dist/core.cjs +5 -5
  4. package/dist/core.esm.js +7 -7
  5. package/dist/core.esm.js.map +1 -1
  6. package/dist/core.native.esm.js +7 -7
  7. package/dist/core.native.esm.js.map +1 -1
  8. package/dist/{getNetworkProviderFromNetworkId-D_Hg6kP7.esm.js → getNetworkProviderFromNetworkId-CgxCy8qP.esm.js} +9 -8
  9. package/dist/getNetworkProviderFromNetworkId-CgxCy8qP.esm.js.map +1 -0
  10. package/dist/{getNetworkProviderFromNetworkId-BXoTukxv.cjs → getNetworkProviderFromNetworkId-DaxDzIv4.cjs} +9 -2
  11. package/dist/getNetworkProviderFromNetworkId-DaxDzIv4.cjs.map +1 -0
  12. package/dist/{getNetworkProviderFromNetworkId-Cs3hLqBS.native.esm.js → getNetworkProviderFromNetworkId-OXG2gPby.native.esm.js} +10 -9
  13. package/dist/getNetworkProviderFromNetworkId-OXG2gPby.native.esm.js.map +1 -0
  14. package/dist/{getSignedSessionId-Bk-8is5J.native.esm.js → getSignedSessionId-B2s2UuwJ.native.esm.js} +3 -3
  15. package/dist/{getSignedSessionId-Bk-8is5J.native.esm.js.map → getSignedSessionId-B2s2UuwJ.native.esm.js.map} +1 -1
  16. package/dist/{getSignedSessionId-D_TknHwX.esm.js → getSignedSessionId-DdMeCIV-.esm.js} +3 -3
  17. package/dist/{getSignedSessionId-D_TknHwX.esm.js.map → getSignedSessionId-DdMeCIV-.esm.js.map} +1 -1
  18. package/dist/{getSignedSessionId-2O_cJtIV.cjs → getSignedSessionId-KiBgLtda.cjs} +3 -3
  19. package/dist/{getSignedSessionId-2O_cJtIV.cjs.map → getSignedSessionId-KiBgLtda.cjs.map} +1 -1
  20. package/dist/{getVerifiedCredentialForWalletAccount-BmsHgXbj.esm.js → getVerifiedCredentialForWalletAccount-DzZ-0SaQ.esm.js} +2 -2
  21. package/dist/{getVerifiedCredentialForWalletAccount-BmsHgXbj.esm.js.map → getVerifiedCredentialForWalletAccount-DzZ-0SaQ.esm.js.map} +1 -1
  22. package/dist/{getVerifiedCredentialForWalletAccount-upiwolAi.cjs → getVerifiedCredentialForWalletAccount-y2drOcyb.cjs} +2 -2
  23. package/dist/{getVerifiedCredentialForWalletAccount-upiwolAi.cjs.map → getVerifiedCredentialForWalletAccount-y2drOcyb.cjs.map} +1 -1
  24. package/dist/index.cjs +56 -69
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.esm.js +50 -63
  27. package/dist/index.esm.js.map +1 -1
  28. package/dist/index.native.esm.js +50 -63
  29. package/dist/index.native.esm.js.map +1 -1
  30. package/dist/{isMfaRequiredForAction-CHqeZeTS.esm.js → isMfaRequiredForAction-BLegdReE.esm.js} +2 -2
  31. package/dist/{isMfaRequiredForAction-CHqeZeTS.esm.js.map → isMfaRequiredForAction-BLegdReE.esm.js.map} +1 -1
  32. package/dist/{isMfaRequiredForAction-DF65MJNN.cjs → isMfaRequiredForAction-By7uHgpn.cjs} +2 -2
  33. package/dist/{isMfaRequiredForAction-DF65MJNN.cjs.map → isMfaRequiredForAction-By7uHgpn.cjs.map} +1 -1
  34. package/dist/{isMfaRequiredForAction-D7b7mUT9.native.esm.js → isMfaRequiredForAction-CXuuO-wy.native.esm.js} +2 -2
  35. package/dist/{isMfaRequiredForAction-D7b7mUT9.native.esm.js.map → isMfaRequiredForAction-CXuuO-wy.native.esm.js.map} +1 -1
  36. package/dist/{isUserOnboardingComplete-CpHVw8ee.esm.js → isUserOnboardingComplete-Bvh4NLBz.esm.js} +3 -3
  37. package/dist/{isUserOnboardingComplete-CpHVw8ee.esm.js.map → isUserOnboardingComplete-Bvh4NLBz.esm.js.map} +1 -1
  38. package/dist/{isUserOnboardingComplete-BAL-3zu7.cjs → isUserOnboardingComplete-DMefkHRY.cjs} +3 -3
  39. package/dist/{isUserOnboardingComplete-BAL-3zu7.cjs.map → isUserOnboardingComplete-DMefkHRY.cjs.map} +1 -1
  40. package/dist/{isUserOnboardingComplete-CYpgo52t.native.esm.js → isUserOnboardingComplete-hn1rWlA-.native.esm.js} +3 -3
  41. package/dist/{isUserOnboardingComplete-CYpgo52t.native.esm.js.map → isUserOnboardingComplete-hn1rWlA-.native.esm.js.map} +1 -1
  42. package/dist/{logoutWithReason-CX9hGTPw.esm.js → logoutWithReason-B-cf-dUs.esm.js} +61 -49
  43. package/dist/logoutWithReason-B-cf-dUs.esm.js.map +1 -0
  44. package/dist/{logoutWithReason-Bd1qUh7l.native.esm.js → logoutWithReason-C4AgSbjv.native.esm.js} +61 -49
  45. package/dist/logoutWithReason-C4AgSbjv.native.esm.js.map +1 -0
  46. package/dist/{logoutWithReason-CFjm8dbR.cjs → logoutWithReason-c1DmyRBx.cjs} +72 -54
  47. package/dist/logoutWithReason-c1DmyRBx.cjs.map +1 -0
  48. package/dist/{migrateFromFireblocks-BLz9aHOY.native.esm.js → migrateFromFireblocks-B0pkwAaK.native.esm.js} +2 -2
  49. package/dist/{migrateFromFireblocks-BLz9aHOY.native.esm.js.map → migrateFromFireblocks-B0pkwAaK.native.esm.js.map} +1 -1
  50. package/dist/{migrateFromFireblocks-C8KXMXk-.esm.js → migrateFromFireblocks-B76sFd7a.esm.js} +2 -2
  51. package/dist/{migrateFromFireblocks-C8KXMXk-.esm.js.map → migrateFromFireblocks-B76sFd7a.esm.js.map} +1 -1
  52. package/dist/{migrateFromFireblocks-BiZmnKp9.cjs → migrateFromFireblocks-RCqy2qOG.cjs} +2 -2
  53. package/dist/{migrateFromFireblocks-BiZmnKp9.cjs.map → migrateFromFireblocks-RCqy2qOG.cjs.map} +1 -1
  54. package/dist/modules/initializeClient/consts.d.ts +1 -0
  55. package/dist/modules/initializeClient/consts.d.ts.map +1 -1
  56. package/dist/modules/initializeClient/initializeClient.d.ts.map +1 -1
  57. package/dist/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.d.ts +4 -5
  58. package/dist/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.d.ts.map +1 -1
  59. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  60. package/dist/{waas-G-4JvdgJ.cjs → waas-7vSYuH3H.cjs} +4 -4
  61. package/dist/{waas-G-4JvdgJ.cjs.map → waas-7vSYuH3H.cjs.map} +1 -1
  62. package/dist/{waas-oKD6ZDP9.native.esm.js → waas-DIlnOHm6.native.esm.js} +4 -4
  63. package/dist/{waas-oKD6ZDP9.native.esm.js.map → waas-DIlnOHm6.native.esm.js.map} +1 -1
  64. package/dist/{waas-DjgZ-ghV.esm.js → waas-H5xyBfTI.esm.js} +4 -4
  65. package/dist/{waas-DjgZ-ghV.esm.js.map → waas-H5xyBfTI.esm.js.map} +1 -1
  66. package/dist/waas.cjs +4 -4
  67. package/dist/waas.esm.js +4 -4
  68. package/dist/waas.native.esm.js +4 -4
  69. package/dist/waasCore.cjs +5 -5
  70. package/dist/waasCore.esm.js +5 -5
  71. package/dist/waasCore.native.esm.js +5 -5
  72. package/package.json +2 -2
  73. package/dist/getNetworkProviderFromNetworkId-BXoTukxv.cjs.map +0 -1
  74. package/dist/getNetworkProviderFromNetworkId-Cs3hLqBS.native.esm.js.map +0 -1
  75. package/dist/getNetworkProviderFromNetworkId-D_Hg6kP7.esm.js.map +0 -1
  76. package/dist/logoutWithReason-Bd1qUh7l.native.esm.js.map +0 -1
  77. package/dist/logoutWithReason-CFjm8dbR.cjs.map +0 -1
  78. package/dist/logoutWithReason-CX9hGTPw.esm.js.map +0 -1
  79. package/dist/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.d.ts +0 -5
  80. package/dist/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logoutWithReason-C4AgSbjv.native.esm.js","names":["walletProvider","walletProvidersMap: Map<string, WalletProvider>"],"sources":["../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts","../src/utils/retryOnFail/InvalidRetryOnFailCallError.ts","../src/utils/retryOnFail/retryOnFail.ts","../src/modules/wallets/unverifiedWalletAccounts/schema.ts","../src/modules/wallets/walletProvider/walletProviderKeyMap/schema.ts","../src/modules/storageSync/schema.ts","../src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts","../src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts","../src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts","../src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts","../src/modules/auth/logoutWithReason/logoutWithReason.ts"],"sourcesContent":["import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\nimport type { WalletProvider } from '../walletProvider';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\n/** @notInstrumented */\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n): WalletProvider => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/** @notInstrumented */\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n): JwtVerifiedCredential | undefined => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n","import { BaseError } from '../../errors/base';\n\n/**\n * This error is thrown when the `retryOnFail` function is called with an invalid\n * number of retries (i.e. less than 0).\n */\nexport class InvalidRetryOnFailCallError extends BaseError {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(maxRetries: number) {\n super({\n cause: null,\n code: 'invalid_retry_on_fail_call_error',\n docsUrl: null,\n name: 'InvalidRetryOnFailCallError',\n shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`,\n });\n }\n}\n","import { InvalidRetryOnFailCallError } from './InvalidRetryOnFailCallError';\n\nexport type RetryOnFailParams<T> = {\n /**\n * The delay between retries in milliseconds.\n */\n delay?: number;\n /**\n * The function to call.\n */\n fn: () => Promise<T>;\n /**\n * The maximum number of retries.\n *\n * When set to 0, the function will be called only once and is\n * therefore equivalent to calling the function directly.\n */\n maxRetries: number;\n};\n\n/** @notInstrumented */\nexport const retryOnFail = async <T>({\n delay = 0,\n fn,\n maxRetries,\n}: RetryOnFailParams<T>): Promise<T> => {\n for (let retry = 0; retry <= maxRetries; retry++) {\n try {\n return await fn();\n } catch (error) {\n if (retry >= maxRetries) {\n throw error;\n }\n\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n }\n\n /**\n * Reaching this point should never happen and this\n * error is thrown to help us debug the issue.\n */\n throw new InvalidRetryOnFailCallError(maxRetries);\n};\n","import * as z from 'zod/mini';\n\nimport type { Chain } from '../../chain';\nimport type { HardwareWalletVendor } from '../hardwareWallet/hardwareWallet.types';\nimport type { WalletAddressType } from '../walletAccount';\n\nexport const unverifiedWalletAccountSchema = z.object({\n address: z.string(),\n addressesWithTypes: z.optional(\n z.array(\n z.object({\n address: z.string(),\n publicKey: z.optional(z.string()),\n type: z.custom<WalletAddressType>((val) => typeof val === 'string'),\n })\n )\n ),\n chain: z.custom<Chain>((val) => typeof val === 'string'),\n hardwareWalletVendor: z.optional(\n z.custom<HardwareWalletVendor>((val) => typeof val === 'string')\n ),\n id: z.string(),\n lastSelectedAt: z.nullable(z.date()),\n walletProviderKey: z.string(),\n});\n","import * as z from 'zod/mini';\n\nexport const walletProviderKeyMapSchema = z.record(z.string(), z.string());\n","import type { ProjectSettings } from '@dynamic-labs/sdk-api-core';\nimport * as z from 'zod/mini';\n\nimport { createStorageKeySchema } from '../../services/storage';\nimport { unverifiedWalletAccountSchema } from '../wallets/unverifiedWalletAccounts';\nimport { walletProviderKeyMapSchema } from '../wallets/walletProvider/walletProviderKeyMap/schema';\nimport type { User } from '../user/user.types';\n\nexport const stateStorageKeySchema = createStorageKeySchema({\n key: 'state',\n schema: z.object({\n apiVersion: z.string(),\n projectSettings: z.custom<ProjectSettings | null>(),\n unverifiedWalletAccounts: z.array(unverifiedWalletAccountSchema),\n user: z.custom<User | null>(),\n walletProviderKeyMap: walletProviderKeyMapSchema,\n }),\n});\n\nexport const sessionStorageKeySchema = createStorageKeySchema({\n config: { storageTier: 'secure' },\n key: 'session',\n schema: z.object({\n /**\n * The current available captcha token.\n */\n captchaToken: z.nullable(z.string()),\n\n /**\n * The current available elevated access tokens.\n */\n elevatedAccessTokens: z.array(\n z.object({\n /**\n * Milliseconds since epoch of token expiration.\n */\n expiresAt: z.number(),\n /**\n * The scopes of the token.\n */\n scopes: z.array(z.string()),\n /**\n * Whether the token is single use.\n */\n singleUse: z.nullable(z.boolean()),\n /**\n * The token string.\n */\n token: z.string(),\n })\n ),\n\n /**\n * Legacy token will be undefined in environments with cookie based sessions.\n *\n * @deprecated Use `token` instead.\n */\n legacyToken: z.nullable(z.string()),\n\n /**\n * The current available MFA token.\n */\n mfaToken: z.nullable(z.string()),\n\n /**\n * Milliseconds since epoch of session expiration.\n */\n sessionExpiration: z.number(),\n\n /**\n * The current session keys.\n */\n sessionKeys: z.nullable(z.string()),\n\n /**\n * Token will be undefined in environments with cookie based sessions.\n */\n token: z.nullable(z.string()),\n }),\n});\n","import type { ProjectSettings } from '../projectSettings.types';\nimport { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { SDK_API_CORE_VERSION } from '../../../constants';\nimport { retryOnFail } from '../../../utils/retryOnFail';\nimport { createApiClient } from '../../apiClient';\nimport { CLIENT_SDK_NAME } from '../../apiClient/constants';\nimport { stateStorageKeySchema } from '../../storageSync/schema';\n\n/**\n * Fetches and updates the project settings from the API.\n *\n * This function retrieves the latest project configuration settings\n * from Dynamic's servers, including authentication options, enabled chains,\n * and security configurations. It always performs a live fetch. If the API\n * call fails, it falls back to the last known-good settings from storage,\n * provided they were saved by a matching SDK API version.\n *\n * @example\n * ```ts\n * const settings = await fetchProjectSettings();\n * console.log('Enabled chains:', settings.chains);\n * ```\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the updated project settings.\n * @throws {Error} Rethrows the original fetch error when no matching-version cached settings exist.\n * @see createDynamicClient\n * @see initializeClient\n * @notInstrumented\n * @noHook Internal settings fetch that is not part of the public hook surface.\n */\nexport const fetchProjectSettings = async (\n client = getDefaultClient()\n): Promise<ProjectSettings | null> => {\n const core = getCore(client);\n\n const apiClient = createApiClient({}, client);\n\n core.logger.debug('[fetchProjectSettings] Fetching project settings...');\n\n const doFetch = async () =>\n apiClient.getEnvironmentSettings(\n {\n environmentId: core.environmentId,\n sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`,\n },\n {\n credentials: 'omit',\n }\n );\n\n const projectSettings = await retryOnFail({\n fn: doFetch,\n maxRetries: 2,\n }).catch(async (error) => {\n const cachedState = await core.storage\n .getItem(stateStorageKeySchema)\n .catch(() => null);\n\n if (\n cachedState?.apiVersion === SDK_API_CORE_VERSION &&\n cachedState.projectSettings\n ) {\n core.logger.error(\n '[fetchProjectSettings] Failed to fetch project settings, falling back to cached settings',\n error\n );\n\n return cachedState.projectSettings;\n }\n\n core.logger.error(\n '[fetchProjectSettings] Failed to fetch project settings and no cached settings are available',\n error\n );\n\n throw error;\n });\n\n core.state.set({ projectSettings: projectSettings ?? null });\n\n return projectSettings;\n};\n","import { getCore } from '../../../client/core/getCore';\nimport type { DynamicClient } from '../../../client/types';\nimport { assertDefined } from '../../../utils/assertDefined';\nimport type { SessionKeys } from '../sessionKeys.types';\n\n/** @notInstrumented */\nexport const generateSessionKeys = async (\n client: DynamicClient\n): Promise<SessionKeys> => {\n const core = getCore(client);\n\n const currentState = core.state.get();\n\n const isRotation = Boolean(currentState.sessionKeys);\n\n const logContext = {\n environmentId: core.environmentId,\n operation: isRotation ? 'rotate' : 'create',\n userId: currentState.user?.id ?? null,\n };\n\n core.logger.info(\n isRotation\n ? '[generateSessionKeys] Rotating session key...'\n : '[generateSessionKeys] Creating session key...',\n logContext\n );\n\n await core.keychain.removeKey('session');\n\n const publicKey = await core.keychain.generateKey('session');\n\n assertDefined(publicKey, 'Public key not found');\n\n core.state.set({\n sessionKeys: publicKey,\n });\n\n core.logger.info(\n isRotation\n ? '[generateSessionKeys] Session key rotated'\n : '[generateSessionKeys] Session key created',\n logContext\n );\n\n return { publicKey };\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { getWalletAccounts } from '../../getWalletAccounts';\nimport type { WalletProvider } from '../../walletProvider';\nimport { getWalletProviderFromWalletAccount } from '../getWalletProviderFromWalletAccount';\n\n/** @notInstrumented */\nexport const getAvailableWalletProvidersFromWalletAccounts = (\n client: DynamicClient\n): WalletProvider[] => {\n const core = getCore(client);\n\n const walletProvidersMap: Map<string, WalletProvider> = new Map();\n\n const walletAccounts = getWalletAccounts(client);\n\n walletAccounts.forEach((walletAccount) => {\n if (walletProvidersMap.has(walletAccount.walletProviderKey)) {\n return;\n }\n\n try {\n const walletProvider = getWalletProviderFromWalletAccount(\n {\n walletAccount,\n },\n client\n );\n\n walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);\n } catch (error) {\n core.logger.debug('Wallet provider not found for wallet account', {\n error,\n walletAccount: walletAccount.address,\n });\n }\n });\n\n return Array.from(walletProvidersMap.values());\n};\n","import { getCore } from '../../../client/core/getCore';\nimport type { DynamicClient } from '../../../client/types/DynamicClient';\nimport type { LogoutReason } from '../../auth/logoutReason';\nimport { getAvailableWalletProvidersFromWalletAccounts } from '../utils/getAvailableWalletProvidersFromWalletAccounts';\n\n/**\n * Tear down every wallet provider on the client.\n *\n * Each provider's `destroy` is responsible for its own local + remote\n * cleanup. We swallow errors so a failing destroy on one provider does not\n * block teardown of the others (e.g. during logout).\n *\n * @notInstrumented\n */\nexport const destroyWalletProviders = async (\n { reason }: { reason?: LogoutReason },\n client: DynamicClient\n): Promise<void> => {\n const core = getCore(client);\n\n const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);\n\n await Promise.all(\n walletProviders.map(async (walletProvider) => {\n if (!walletProvider.destroy) return;\n try {\n await walletProvider.destroy({ reason });\n } catch (err) {\n core.logger.error(\n `Error destroying wallet provider ${walletProvider.key}`,\n err\n );\n }\n })\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getCore } from '../../../client/core/getCore';\nimport { getSecureCookieAttribute } from '../../../utils/getSecureCookieAttribute';\nimport { setCookie } from '../../../utils/setCookie';\nimport { createApiClient } from '../../apiClient';\nimport { DYNAMIC_LOGOUT_REASON_HEADER } from '../../apiClient/constants';\nimport { emitEvent } from '../../clientEvents';\nimport { fetchProjectSettings } from '../../projectSettings/fetchProjectSettings';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { generateSessionKeys } from '../../sessionKeys/generateSessionKeys';\nimport { destroyWalletProviders } from '../../wallets/destroyWalletProviders';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport type { LogoutReason } from '../logoutReason';\nimport { checkAndRaiseWalletAccountsChangedEvent } from '../updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent';\n\n/**\n * Logs the user out with an explicit reason.\n *\n * Revokes the session, clears auth state, terminates wallet providers, and\n * emits the `logout` client event with the given reason. The reason is also\n * captured as an argument on the function-instrumentation event, which is\n * how Datadog distinguishes between different logout causes.\n *\n * Use this instead of the public `logout` when triggering a logout from\n * internal or extension code — the caller owns the reason string, so the\n * telemetry correctly attributes *why* the logout happened.\n *\n * @param params - The logout params.\n * @param params.reason - Why the logout is being triggered. Extension authors\n * needing a reason outside the SDK catalog can cast with `as LogoutReason`.\n * @param client - The Dynamic client instance.\n * @instrumented\n */\nexport const logoutWithReason = async (\n { reason }: { reason: LogoutReason },\n client: DynamicClient\n): Promise<void> => {\n const core = getCore(client);\n\n core.logger.debug('[logoutWithReason] Logging out...', { reason });\n\n await destroyWalletProviders({ reason }, client);\n\n if (client.user !== null) {\n // Forward the logout reason so the backend can attribute the revocation in\n // Datadog instead of it being inferred from downstream 401s.\n const apiClient = createApiClient(\n { headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } },\n client\n );\n\n try {\n await apiClient.revokeSession({\n environmentId: core.environmentId,\n });\n } catch (error) {\n core.logger.error('Failed to revoke session', error);\n }\n\n /**\n * This deletes the auth cookie if it exists.\n * If the cookie doesn't exist, this sets a new cookie that expires immediately.\n */\n if (isCookieEnabled(client)) {\n // Match the Secure attribute used when the cookie was written so the\n // deletion cookie is accepted consistently in a secure context.\n const secureAttribute = getSecureCookieAttribute();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax${secureAttribute}`\n );\n }\n }\n\n await core.keychain.removeKey('session');\n\n const previousState = core.state.get();\n\n core.state.set({\n captchaToken: null,\n elevatedAccessTokens: [],\n legacyToken: null,\n mfaToken: null,\n sessionExpiresAt: null,\n sessionKeys: null,\n token: null,\n unverifiedWalletAccounts: [],\n user: null,\n });\n\n emitEvent({ args: { reason }, event: 'logout' }, client);\n // core.state.set above has no subscribers of its own, so this is the only\n // way listeners relying on getWalletAccounts() (e.g. chain extensions\n // reconciling a wallet provider's registration) learn the accounts are\n // gone. We diff against the pre-logout snapshot so this only fires when\n // there actually were wallet accounts to lose.\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n\n // Refetch project settings\n void fetchProjectSettings(client);\n\n // Regenerate session keys\n void generateSessionKeys(client);\n};\n"],"mappings":";;;;;AAUA,MAAa,0BACX,EAAE,qBACF,WACmB;CAGnB,MAAM,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBA,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO;;;;;;ACdT,MAAa,yCACX,EAAE,iBACF,WACsC;AACtC,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC;;;;;;;;;ACVH,IAAa,8BAAb,cAAiD,UAAU;CAEzD,YAAY,YAAoB;AAC9B,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc,mDAAmD;GAClE,CAAC;;;;;;;ACMN,MAAa,cAAc,OAAU,EACnC,QAAQ,GACR,IACA,iBACsC;AACtC,MAAK,IAAI,QAAQ,GAAG,SAAS,YAAY,QACvC,KAAI;AACF,SAAO,MAAM,IAAI;UACV,OAAO;AACd,MAAI,SAAS,WACX,OAAM;AAGR,MAAI,QAAQ,EACV,OAAM,IAAI,SAAS,YAAY,WAAW,SAAS,MAAM,CAAC;;;;;;AAShE,OAAM,IAAI,4BAA4B,WAAW;;;;;ACtCnD,MAAa,gCAAgC,EAAE,OAAO;CACpD,SAAS,EAAE,QAAQ;CACnB,oBAAoB,EAAE,SACpB,EAAE,MACA,EAAE,OAAO;EACP,SAAS,EAAE,QAAQ;EACnB,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC;EACjC,MAAM,EAAE,QAA2B,QAAQ,OAAO,QAAQ,SAAS;EACpE,CAAC,CACH,CACF;CACD,OAAO,EAAE,QA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AA;;EAEF,CAAA;AAEA,WAAO;EAAA,MAAU,EAAA,QAAW;EAAA,OAAA;EAAmB,EAAE,OAAK;AAMtD,yCAAmB,EAAA,eAAA,EAAA,OAAA;AAGnB,CAAG,qBAAmB,OAAA"}
@@ -31,7 +31,7 @@ zod_mini = __toESM(zod_mini);
31
31
 
32
32
  //#region package.json
33
33
  var name = "@dynamic-labs-sdk/client";
34
- var version = "1.33.1";
34
+ var version = "1.33.2";
35
35
 
36
36
  //#endregion
37
37
  //#region src/modules/auth/consts.ts
@@ -2263,60 +2263,66 @@ const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
2263
2263
  };
2264
2264
 
2265
2265
  //#endregion
2266
- //#region src/modules/auth/isSignedIn/isSignedIn.ts
2267
- /**
2268
- * Checks if the user is currently signed in to the Dynamic client.
2269
- *
2270
- * The client is considered to be in a signed in state if a user has
2271
- * authenticated or if the client has at least one wallet connected.
2272
- *
2273
- * @deprecated What counts as "signed in" is your app's business logic, not the
2274
- * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
2275
- * which rarely matches every app and forces a dependency on us for every
2276
- * variation. Compose your own check from the underlying primitives instead —
2277
- * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
2278
- * layer in whatever your app requires (device registration, completed
2279
- * onboarding, satisfied MFA, a required embedded wallet, …). See the
2280
- * "Check if signed in" guide:
2281
- * https://www.dynamic.xyz/docs/javascript/user-session-management
2282
- *
2283
- * @example
2284
- * ```ts
2285
- * if (isSignedIn()) {
2286
- * console.log('User is authenticated or has a wallet connected');
2287
- * }
2288
- * ```
2289
- *
2290
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2291
- * @returns True if the user is signed in, false otherwise.
2292
- * @see logout
2293
- * @see isAnyWalletAccountConnected
2294
- * @notInstrumented
2295
- */
2296
- const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
2266
+ //#region src/modules/wallets/unverifiedWalletAccounts/schema.ts
2267
+ const unverifiedWalletAccountSchema = zod_mini.object({
2268
+ address: zod_mini.string(),
2269
+ addressesWithTypes: zod_mini.optional(zod_mini.array(zod_mini.object({
2270
+ address: zod_mini.string(),
2271
+ publicKey: zod_mini.optional(zod_mini.string()),
2272
+ type: zod_mini.custom((val) => typeof val === "string")
2273
+ }))),
2274
+ chain: zod_mini.custom((val) => typeof val === "string"),
2275
+ hardwareWalletVendor: zod_mini.optional(zod_mini.custom((val) => typeof val === "string")),
2276
+ id: zod_mini.string(),
2277
+ lastSelectedAt: zod_mini.nullable(zod_mini.date()),
2278
+ walletProviderKey: zod_mini.string()
2279
+ });
2297
2280
 
2298
2281
  //#endregion
2299
- //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
2300
- /**
2301
- * The schema to track the expiration time of the project settings.
2302
- */
2303
- const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
2304
- key: "projectSettingsExpiration",
2305
- schema: zod_mini.number()
2282
+ //#region src/modules/wallets/walletProvider/walletProviderKeyMap/schema.ts
2283
+ const walletProviderKeyMapSchema = zod_mini.record(zod_mini.string(), zod_mini.string());
2284
+
2285
+ //#endregion
2286
+ //#region src/modules/storageSync/schema.ts
2287
+ const stateStorageKeySchema = createStorageKeySchema({
2288
+ key: "state",
2289
+ schema: zod_mini.object({
2290
+ apiVersion: zod_mini.string(),
2291
+ projectSettings: zod_mini.custom(),
2292
+ unverifiedWalletAccounts: zod_mini.array(unverifiedWalletAccountSchema),
2293
+ user: zod_mini.custom(),
2294
+ walletProviderKeyMap: walletProviderKeyMapSchema
2295
+ })
2296
+ });
2297
+ const sessionStorageKeySchema = createStorageKeySchema({
2298
+ config: { storageTier: "secure" },
2299
+ key: "session",
2300
+ schema: zod_mini.object({
2301
+ captchaToken: zod_mini.nullable(zod_mini.string()),
2302
+ elevatedAccessTokens: zod_mini.array(zod_mini.object({
2303
+ expiresAt: zod_mini.number(),
2304
+ scopes: zod_mini.array(zod_mini.string()),
2305
+ singleUse: zod_mini.nullable(zod_mini.boolean()),
2306
+ token: zod_mini.string()
2307
+ })),
2308
+ legacyToken: zod_mini.nullable(zod_mini.string()),
2309
+ mfaToken: zod_mini.nullable(zod_mini.string()),
2310
+ sessionExpiration: zod_mini.number(),
2311
+ sessionKeys: zod_mini.nullable(zod_mini.string()),
2312
+ token: zod_mini.nullable(zod_mini.string())
2313
+ })
2306
2314
  });
2307
2315
 
2308
2316
  //#endregion
2309
2317
  //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
2310
2318
  /**
2311
- * Expiration time of the project settings in milliseconds.
2312
- */
2313
- const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
2314
- /**
2315
2319
  * Fetches and updates the project settings from the API.
2316
2320
  *
2317
2321
  * This function retrieves the latest project configuration settings
2318
2322
  * from Dynamic's servers, including authentication options, enabled chains,
2319
- * and security configurations. The settings are cached for performance.
2323
+ * and security configurations. It always performs a live fetch. If the API
2324
+ * call fails, it falls back to the last known-good settings from storage,
2325
+ * provided they were saved by a matching SDK API version.
2320
2326
  *
2321
2327
  * @example
2322
2328
  * ```ts
@@ -2326,6 +2332,7 @@ const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
2326
2332
  *
2327
2333
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2328
2334
  * @returns A promise that resolves to the updated project settings.
2335
+ * @throws {Error} Rethrows the original fetch error when no matching-version cached settings exist.
2329
2336
  * @see createDynamicClient
2330
2337
  * @see initializeClient
2331
2338
  * @notInstrumented
@@ -2333,8 +2340,6 @@ const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
2333
2340
  */
2334
2341
  const fetchProjectSettings = async (client = getDefaultClient()) => {
2335
2342
  const core = getCore(client);
2336
- const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
2337
- if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
2338
2343
  const apiClient = createApiClient({}, client);
2339
2344
  core.logger.debug("[fetchProjectSettings] Fetching project settings...");
2340
2345
  const doFetch = async () => apiClient.getEnvironmentSettings({
@@ -2344,9 +2349,16 @@ const fetchProjectSettings = async (client = getDefaultClient()) => {
2344
2349
  const projectSettings = await retryOnFail({
2345
2350
  fn: doFetch,
2346
2351
  maxRetries: 2
2352
+ }).catch(async (error) => {
2353
+ const cachedState = await core.storage.getItem(stateStorageKeySchema).catch(() => null);
2354
+ if (cachedState?.apiVersion === SDK_API_CORE_VERSION && cachedState.projectSettings) {
2355
+ core.logger.error("[fetchProjectSettings] Failed to fetch project settings, falling back to cached settings", error);
2356
+ return cachedState.projectSettings;
2357
+ }
2358
+ core.logger.error("[fetchProjectSettings] Failed to fetch project settings and no cached settings are available", error);
2359
+ throw error;
2347
2360
  });
2348
2361
  core.state.set({ projectSettings: projectSettings ?? null });
2349
- await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
2350
2362
  return projectSettings;
2351
2363
  };
2352
2364
 
@@ -2854,12 +2866,6 @@ Object.defineProperty(exports, 'isCookieEnabled', {
2854
2866
  return isCookieEnabled;
2855
2867
  }
2856
2868
  });
2857
- Object.defineProperty(exports, 'isSignedIn', {
2858
- enumerable: true,
2859
- get: function () {
2860
- return isSignedIn;
2861
- }
2862
- });
2863
2869
  Object.defineProperty(exports, 'isUserMissingMfaAuth', {
2864
2870
  enumerable: true,
2865
2871
  get: function () {
@@ -2944,6 +2950,12 @@ Object.defineProperty(exports, 'scrubParameters', {
2944
2950
  return scrubParameters;
2945
2951
  }
2946
2952
  });
2953
+ Object.defineProperty(exports, 'sessionStorageKeySchema', {
2954
+ enumerable: true,
2955
+ get: function () {
2956
+ return sessionStorageKeySchema;
2957
+ }
2958
+ });
2947
2959
  Object.defineProperty(exports, 'setDefaultClient', {
2948
2960
  enumerable: true,
2949
2961
  get: function () {
@@ -2956,6 +2968,12 @@ Object.defineProperty(exports, 'splitWalletProviderKey', {
2956
2968
  return splitWalletProviderKey;
2957
2969
  }
2958
2970
  });
2971
+ Object.defineProperty(exports, 'stateStorageKeySchema', {
2972
+ enumerable: true,
2973
+ get: function () {
2974
+ return stateStorageKeySchema;
2975
+ }
2976
+ });
2959
2977
  Object.defineProperty(exports, 'updateAuthFromVerifyResponse', {
2960
2978
  enumerable: true,
2961
2979
  get: function () {
@@ -2980,4 +2998,4 @@ Object.defineProperty(exports, 'version', {
2980
2998
  return version;
2981
2999
  }
2982
3000
  });
2983
- //# sourceMappingURL=logoutWithReason-CFjm8dbR.cjs.map
3001
+ //# sourceMappingURL=logoutWithReason-c1DmyRBx.cjs.map