@dynamic-labs-sdk/client 1.5.0 → 1.7.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.
Files changed (105) hide show
  1. package/dist/{InvalidParamError-DKJhDrK8.cjs → InvalidParamError-CTssOe86.cjs} +111 -994
  2. package/dist/InvalidParamError-CTssOe86.cjs.map +1 -0
  3. package/dist/{InvalidParamError-DkAMYJOW.native.esm.js → InvalidParamError-Crwntjl7.native.esm.js} +96 -829
  4. package/dist/InvalidParamError-Crwntjl7.native.esm.js.map +1 -0
  5. package/dist/{InvalidParamError-DWjMfOZ5.esm.js → InvalidParamError-fQLJaGBW.esm.js} +96 -796
  6. package/dist/InvalidParamError-fQLJaGBW.esm.js.map +1 -0
  7. package/dist/{NotWaasWalletAccountError-CHzpa9kk.cjs → NotWaasWalletAccountError-2RaDipZu.cjs} +4 -4
  8. package/dist/NotWaasWalletAccountError-2RaDipZu.cjs.map +1 -0
  9. package/dist/{NotWaasWalletAccountError-C7NUlvvM.esm.js → NotWaasWalletAccountError-BJLGGYmU.native.esm.js} +4 -4
  10. package/dist/NotWaasWalletAccountError-BJLGGYmU.native.esm.js.map +1 -0
  11. package/dist/{NotWaasWalletAccountError-BVrvQzLz.native.esm.js → NotWaasWalletAccountError-DF_S7gqo.esm.js} +4 -4
  12. package/dist/NotWaasWalletAccountError-DF_S7gqo.esm.js.map +1 -0
  13. package/dist/core.cjs +23 -23
  14. package/dist/core.cjs.map +1 -1
  15. package/dist/core.esm.js +7 -7
  16. package/dist/core.esm.js.map +1 -1
  17. package/dist/core.native.esm.js +5 -5
  18. package/dist/errors/CorruptedKeyShareError.d.ts +19 -0
  19. package/dist/errors/CorruptedKeyShareError.d.ts.map +1 -0
  20. package/dist/errors/WebViewLoadFailedError.d.ts +32 -0
  21. package/dist/errors/WebViewLoadFailedError.d.ts.map +1 -0
  22. package/dist/errors/base/BaseError.d.ts.map +1 -1
  23. package/dist/{getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js → getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js} +310 -67
  24. package/dist/getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js.map +1 -0
  25. package/dist/{getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js → getNetworkProviderFromNetworkId-BWhaD23J.esm.js} +280 -42
  26. package/dist/getNetworkProviderFromNetworkId-BWhaD23J.esm.js.map +1 -0
  27. package/dist/{getNetworkProviderFromNetworkId-BJ27N-7S.cjs → getNetworkProviderFromNetworkId-C1p9Rrg3.cjs} +351 -44
  28. package/dist/getNetworkProviderFromNetworkId-C1p9Rrg3.cjs.map +1 -0
  29. package/dist/{getSignedSessionId-CHDHr-hY.cjs → getSignedSessionId-CxxYNC_8.cjs} +3 -3
  30. package/dist/{getSignedSessionId-CHDHr-hY.cjs.map → getSignedSessionId-CxxYNC_8.cjs.map} +1 -1
  31. package/dist/{getSignedSessionId-D3KQrN8W.native.esm.js → getSignedSessionId-DPOXdh6y.native.esm.js} +3 -3
  32. package/dist/{getSignedSessionId-D3KQrN8W.native.esm.js.map → getSignedSessionId-DPOXdh6y.native.esm.js.map} +1 -1
  33. package/dist/{getSignedSessionId-CDdKrnw6.esm.js → getSignedSessionId-c7dS4PQ9.esm.js} +3 -3
  34. package/dist/{getSignedSessionId-CDdKrnw6.esm.js.map → getSignedSessionId-c7dS4PQ9.esm.js.map} +1 -1
  35. package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js +701 -0
  36. package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js.map +1 -0
  37. package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs +887 -0
  38. package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs.map +1 -0
  39. package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js +701 -0
  40. package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js.map +1 -0
  41. package/dist/index.cjs +76 -76
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.esm.js +17 -17
  44. package/dist/index.esm.js.map +1 -1
  45. package/dist/index.native.esm.js +14 -14
  46. package/dist/index.native.esm.js.map +1 -1
  47. package/dist/{isMfaRequiredForAction-C_QPI1LH.esm.js → isMfaRequiredForAction-BjRvPrU6.esm.js} +2 -2
  48. package/dist/{isMfaRequiredForAction-C_QPI1LH.esm.js.map → isMfaRequiredForAction-BjRvPrU6.esm.js.map} +1 -1
  49. package/dist/{isMfaRequiredForAction-B0xNvBpU.native.esm.js → isMfaRequiredForAction-D8G5PBAd.native.esm.js} +32 -3
  50. package/dist/isMfaRequiredForAction-D8G5PBAd.native.esm.js.map +1 -0
  51. package/dist/{isMfaRequiredForAction-CLMvTTwl.cjs → isMfaRequiredForAction-hlhj0qAC.cjs} +2 -2
  52. package/dist/{isMfaRequiredForAction-CLMvTTwl.cjs.map → isMfaRequiredForAction-hlhj0qAC.cjs.map} +1 -1
  53. package/dist/modules/apiClient/apiClient.types.d.ts +0 -12
  54. package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
  55. package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
  56. package/dist/modules/auth/logoutReason.d.ts +1 -1
  57. package/dist/modules/auth/logoutReason.d.ts.map +1 -1
  58. package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
  59. package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
  60. package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
  61. package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts +12 -1
  62. package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts.map +1 -1
  63. package/dist/modules/waas/createWaasClient/createWaasClient.d.ts +2 -7
  64. package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
  65. package/dist/modules/waas/createWaasClient/createWaasClient.types.d.ts +8 -0
  66. package/dist/modules/waas/createWaasClient/createWaasClient.types.d.ts.map +1 -0
  67. package/dist/modules/waas/createWaasClient/createWaasSDKContainer.d.ts +15 -0
  68. package/dist/modules/waas/createWaasClient/createWaasSDKContainer.d.ts.map +1 -0
  69. package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts +18 -0
  70. package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts.map +1 -0
  71. package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
  72. package/dist/modules/waas/waas.types.d.ts +1 -0
  73. package/dist/modules/waas/waas.types.d.ts.map +1 -1
  74. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  75. package/dist/waas.cjs +12 -9
  76. package/dist/waas.cjs.map +1 -1
  77. package/dist/waas.esm.js +6 -4
  78. package/dist/waas.esm.js.map +1 -1
  79. package/dist/waas.native.esm.js +6 -4
  80. package/dist/waas.native.esm.js.map +1 -1
  81. package/dist/waasCore.cjs +6 -4
  82. package/dist/waasCore.cjs.map +1 -1
  83. package/dist/waasCore.esm.js +5 -4
  84. package/dist/waasCore.esm.js.map +1 -1
  85. package/dist/waasCore.native.esm.js +210 -8
  86. package/dist/waasCore.native.esm.js.map +1 -1
  87. package/package.json +5 -3
  88. package/dist/InvalidParamError-DKJhDrK8.cjs.map +0 -1
  89. package/dist/InvalidParamError-DWjMfOZ5.esm.js.map +0 -1
  90. package/dist/InvalidParamError-DkAMYJOW.native.esm.js.map +0 -1
  91. package/dist/NotWaasWalletAccountError-BVrvQzLz.native.esm.js.map +0 -1
  92. package/dist/NotWaasWalletAccountError-C7NUlvvM.esm.js.map +0 -1
  93. package/dist/NotWaasWalletAccountError-CHzpa9kk.cjs.map +0 -1
  94. package/dist/getNetworkProviderFromNetworkId-BJ27N-7S.cjs.map +0 -1
  95. package/dist/getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js.map +0 -1
  96. package/dist/getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js.map +0 -1
  97. package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js +0 -269
  98. package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js.map +0 -1
  99. package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js +0 -269
  100. package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js.map +0 -1
  101. package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs +0 -346
  102. package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs.map +0 -1
  103. package/dist/isMfaRequiredForAction-B0xNvBpU.native.esm.js.map +0 -1
  104. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +0 -27
  105. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +0 -1
@@ -1,12 +1,148 @@
1
- const require_InvalidParamError = require('./InvalidParamError-DKJhDrK8.cjs');
2
- const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-gCx0smU8.cjs');
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ const require_InvalidParamError = require('./InvalidParamError-CTssOe86.cjs');
29
+ const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs');
3
30
  let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
4
31
  let zod_mini = require("zod/mini");
5
- zod_mini = require_InvalidParamError.__toESM(zod_mini);
32
+ zod_mini = __toESM(zod_mini);
6
33
  let buffer = require("buffer");
7
34
  let eventemitter3 = require("eventemitter3");
8
- eventemitter3 = require_InvalidParamError.__toESM(eventemitter3);
35
+ eventemitter3 = __toESM(eventemitter3);
36
+
37
+ //#region src/utils/isEqualShallow/isEqualShallow.ts
38
+ /**
39
+ * Shallow compare two objects.
40
+ *
41
+ * Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
42
+ * @not-instrumented
43
+ */
44
+ const isEqualShallow = (objA, objB) => {
45
+ if (Object.is(objA, objB)) return true;
46
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) return objA === objB;
47
+ if (objA instanceof Map && objB instanceof Map) {
48
+ if (objA.size !== objB.size) return false;
49
+ for (const [key, value] of objA) if (!Object.is(value, objB.get(key))) return false;
50
+ return true;
51
+ }
52
+ if (objA instanceof Set && objB instanceof Set) {
53
+ if (objA.size !== objB.size) return false;
54
+ for (const value of objA) if (!objB.has(value)) return false;
55
+ return true;
56
+ }
57
+ const keysA = Object.keys(objA);
58
+ if (keysA.length !== Object.keys(objB).length) return false;
59
+ for (const keyA of keysA) if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) return false;
60
+ if (objA.constructor !== objB.constructor) return false;
61
+ return true;
62
+ };
63
+
64
+ //#endregion
65
+ //#region src/utils/observable/subscribeWithSelector/subscribeWithSelector.ts
66
+ /**
67
+ * Allows subscribing to a slice of the state.
68
+ * The slice is a computation of the states.
69
+ *
70
+ * The callback will only be called when the slice has changed.
71
+ * Change is determined by shallow comparison.
72
+ *
73
+ * Returns a function to unsubscribe the callback.
74
+ * @not-instrumented
75
+ */
76
+ const subscribeWithSelector = (observable, selector) => (callback) => {
77
+ let lastSlice = selector(observable.get());
78
+ return observable.subscribe((value) => {
79
+ const nextSlice = selector(value);
80
+ if (isEqualShallow(nextSlice, lastSlice)) return;
81
+ lastSlice = nextSlice;
82
+ callback(nextSlice);
83
+ });
84
+ };
85
+
86
+ //#endregion
87
+ //#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
88
+ /**
89
+ * This error is thrown when the `retryOnFail` function is called with an invalid
90
+ * number of retries (i.e. less than 0).
91
+ */
92
+ var InvalidRetryOnFailCallError = class extends require_InvalidParamError.BaseError {
93
+ constructor(maxRetries) {
94
+ super({
95
+ cause: null,
96
+ code: "invalid_retry_on_fail_call_error",
97
+ docsUrl: null,
98
+ name: "InvalidRetryOnFailCallError",
99
+ shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
100
+ });
101
+ }
102
+ };
103
+
104
+ //#endregion
105
+ //#region src/utils/retryOnFail/retryOnFail.ts
106
+ /** @not-instrumented */
107
+ const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
108
+ for (let retry = 0; retry <= maxRetries; retry++) try {
109
+ return await fn();
110
+ } catch (error) {
111
+ if (retry >= maxRetries) throw error;
112
+ if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
113
+ }
114
+ /**
115
+ * Reaching this point should never happen and this
116
+ * error is thrown to help us debug the issue.
117
+ */
118
+ throw new InvalidRetryOnFailCallError(maxRetries);
119
+ };
120
+
121
+ //#endregion
122
+ //#region src/modules/auth/isSignedIn/isSignedIn.ts
123
+ /**
124
+ * Checks if the user is currently signed in to the Dynamic client.
125
+ *
126
+ * The client is considered to be in a signed in state if a user has
127
+ * authenticated or if the client has at least one wallet connected.
128
+ *
129
+ * @deprecated What counts as "signed in" is your app's business logic, not the
130
+ * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
131
+ * which rarely matches every app and forces a dependency on us for every
132
+ * variation. Compose your own check from the underlying primitives instead —
133
+ * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
134
+ * layer in whatever your app requires (device registration, completed
135
+ * onboarding, satisfied MFA, a required embedded wallet, …). See the
136
+ * "Check if signed in" guide:
137
+ * https://www.dynamic.xyz/docs/javascript/user-session-management
138
+ *
139
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
140
+ * @returns True if the user is signed in, false otherwise.
141
+ * @not-instrumented
142
+ */
143
+ const isSignedIn = (client = require_InvalidParamError.getDefaultClient()) => Boolean(client.user || require_getVerifiedCredentialForWalletAccount.getWalletAccounts(client).length > 0);
9
144
 
145
+ //#endregion
10
146
  //#region src/services/storage/createLocalStorageAdapter/createLocalStorageAdapter.ts
11
147
  /**
12
148
  * Creates a localStorage adapter.
@@ -117,54 +253,183 @@ const createStorage = ({ prefix = "", storageAdapter }) => {
117
253
  };
118
254
 
119
255
  //#endregion
120
- //#region src/utils/isEqualShallow/isEqualShallow.ts
256
+ //#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
257
+ /** @not-instrumented */
258
+ const createStorageKeySchema = (params) => {
259
+ return params;
260
+ };
261
+
262
+ //#endregion
263
+ //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
121
264
  /**
122
- * Shallow compare two objects.
265
+ * The schema to track the expiration time of the project settings.
266
+ */
267
+ const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
268
+ key: "projectSettingsExpiration",
269
+ schema: zod_mini.number()
270
+ });
271
+
272
+ //#endregion
273
+ //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
274
+ /**
275
+ * Expiration time of the project settings in milliseconds.
276
+ */
277
+ const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
278
+ /**
279
+ * Fetches and updates the project settings from the API.
123
280
  *
124
- * Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
281
+ * This function retrieves the latest project configuration settings
282
+ * from Dynamic's servers, including authentication options, enabled chains,
283
+ * and security configurations. The settings are cached for performance.
284
+ *
285
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
286
+ * @returns A promise that resolves to the updated project settings.
125
287
  * @not-instrumented
126
288
  */
127
- const isEqualShallow = (objA, objB) => {
128
- if (Object.is(objA, objB)) return true;
129
- if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) return objA === objB;
130
- if (objA instanceof Map && objB instanceof Map) {
131
- if (objA.size !== objB.size) return false;
132
- for (const [key, value] of objA) if (!Object.is(value, objB.get(key))) return false;
133
- return true;
134
- }
135
- if (objA instanceof Set && objB instanceof Set) {
136
- if (objA.size !== objB.size) return false;
137
- for (const value of objA) if (!objB.has(value)) return false;
138
- return true;
139
- }
140
- const keysA = Object.keys(objA);
141
- if (keysA.length !== Object.keys(objB).length) return false;
142
- for (const keyA of keysA) if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) return false;
143
- if (objA.constructor !== objB.constructor) return false;
144
- return true;
289
+ const fetchProjectSettings = async (client = require_InvalidParamError.getDefaultClient()) => {
290
+ const core = require_InvalidParamError.getCore(client);
291
+ const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
292
+ if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
293
+ const apiClient = require_InvalidParamError.createApiClient({}, client);
294
+ core.logger.debug("[fetchProjectSettings] Fetching project settings...");
295
+ const doFetch = async () => apiClient.getEnvironmentSettings({
296
+ environmentId: core.environmentId,
297
+ sdkVersion: `${require_InvalidParamError.CLIENT_SDK_NAME}/${core.version}`
298
+ }, { credentials: "omit" });
299
+ const projectSettings = await retryOnFail({
300
+ fn: doFetch,
301
+ maxRetries: 2
302
+ });
303
+ core.state.set({ projectSettings: projectSettings ?? null });
304
+ await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
305
+ return projectSettings;
145
306
  };
146
307
 
147
308
  //#endregion
148
- //#region src/utils/observable/subscribeWithSelector/subscribeWithSelector.ts
309
+ //#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
310
+ /** @not-instrumented */
311
+ const generateSessionKeys = async (client) => {
312
+ const core = require_InvalidParamError.getCore(client);
313
+ await core.keychain.removeKey("session");
314
+ const publicKey = await core.keychain.generateKey("session");
315
+ require_InvalidParamError.assertDefined(publicKey, "Public key not found");
316
+ core.state.set({ sessionKeys: publicKey });
317
+ return { publicKey };
318
+ };
319
+
320
+ //#endregion
321
+ //#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
322
+ /** @not-instrumented */
323
+ const getAvailableWalletProvidersFromWalletAccounts = (client) => {
324
+ const core = require_InvalidParamError.getCore(client);
325
+ const walletProvidersMap = /* @__PURE__ */ new Map();
326
+ require_getVerifiedCredentialForWalletAccount.getWalletAccounts(client).forEach((walletAccount) => {
327
+ if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
328
+ try {
329
+ const walletProvider = require_getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({ walletAccount }, client);
330
+ walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
331
+ } catch (error) {
332
+ core.logger.debug("Wallet provider not found for wallet account", {
333
+ error,
334
+ walletAccount: walletAccount.address
335
+ });
336
+ }
337
+ });
338
+ return Array.from(walletProvidersMap.values());
339
+ };
340
+
341
+ //#endregion
342
+ //#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
149
343
  /**
150
- * Allows subscribing to a slice of the state.
151
- * The slice is a computation of the states.
344
+ * Tear down every wallet provider on the client.
152
345
  *
153
- * The callback will only be called when the slice has changed.
154
- * Change is determined by shallow comparison.
346
+ * Each provider's `destroy` is responsible for its own local + remote
347
+ * cleanup. We swallow errors so a failing destroy on one provider does not
348
+ * block teardown of the others (e.g. during logout).
155
349
  *
156
- * Returns a function to unsubscribe the callback.
157
350
  * @not-instrumented
158
351
  */
159
- const subscribeWithSelector = (observable, selector) => (callback) => {
160
- let lastSlice = selector(observable.get());
161
- return observable.subscribe((value) => {
162
- const nextSlice = selector(value);
163
- if (isEqualShallow(nextSlice, lastSlice)) return;
164
- lastSlice = nextSlice;
165
- callback(nextSlice);
352
+ const destroyWalletProviders = async ({ reason }, client) => {
353
+ const core = require_InvalidParamError.getCore(client);
354
+ const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
355
+ await Promise.all(walletProviders.map(async (walletProvider) => {
356
+ if (!walletProvider.destroy) return;
357
+ try {
358
+ await walletProvider.destroy({ reason });
359
+ } catch (err) {
360
+ core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
361
+ }
362
+ }));
363
+ };
364
+
365
+ //#endregion
366
+ //#region src/modules/auth/logoutWithReason/logoutWithReason.ts
367
+ /**
368
+ * Logs the user out with an explicit reason.
369
+ *
370
+ * Revokes the session, clears auth state, terminates wallet providers, and
371
+ * emits the `logout` client event with the given reason. The reason is also
372
+ * captured as an argument on the function-instrumentation event, which is
373
+ * how Datadog distinguishes between different logout causes.
374
+ *
375
+ * Use this instead of the public `logout` when triggering a logout from
376
+ * internal or extension code — the caller owns the reason string, so the
377
+ * telemetry correctly attributes *why* the logout happened.
378
+ *
379
+ * @param params - The logout params.
380
+ * @param params.reason - Why the logout is being triggered. Extension authors
381
+ * needing a reason outside the SDK catalog can cast with `as LogoutReason`.
382
+ * @param client - The Dynamic client instance.
383
+ * @instrumented
384
+ */
385
+ const logoutWithReason = async ({ reason }, client) => {
386
+ const core = require_InvalidParamError.getCore(client);
387
+ core.logger.debug("[logoutWithReason] Logging out...", { reason });
388
+ await destroyWalletProviders({ reason }, client);
389
+ if (client.user !== null) {
390
+ const apiClient = require_InvalidParamError.createApiClient({}, client);
391
+ try {
392
+ await apiClient.revokeSession({ environmentId: core.environmentId });
393
+ } catch (error) {
394
+ core.logger.error("Failed to revoke session", error);
395
+ }
396
+ /**
397
+ * This deletes the auth cookie if it exists.
398
+ * If the cookie doesn't exist, this sets a new cookie that expires immediately.
399
+ */
400
+ if (require_InvalidParamError.isCookieEnabled(client)) require_getVerifiedCredentialForWalletAccount.setCookie(`${require_getVerifiedCredentialForWalletAccount.DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
401
+ }
402
+ await core.keychain.removeKey("session");
403
+ core.state.set({
404
+ captchaToken: null,
405
+ elevatedAccessTokens: [],
406
+ legacyToken: null,
407
+ mfaToken: null,
408
+ sessionExpiresAt: null,
409
+ sessionKeys: null,
410
+ token: null,
411
+ unverifiedWalletAccounts: [],
412
+ user: null
166
413
  });
414
+ require_getVerifiedCredentialForWalletAccount.emitEvent({
415
+ args: { reason },
416
+ event: "logout"
417
+ }, client);
418
+ fetchProjectSettings(client);
419
+ generateSessionKeys(client);
167
420
  };
421
+ const __logoutWithReason_impl = logoutWithReason;
422
+ const __logoutWithReason_wrapped = require_InvalidParamError.instrumentFunction({
423
+ fn: __logoutWithReason_impl,
424
+ functionName: "logoutWithReason",
425
+ getCore: () => {
426
+ try {
427
+ return require_InvalidParamError.getCore(require_InvalidParamError.getDefaultClient());
428
+ } catch {
429
+ return;
430
+ }
431
+ }
432
+ });
168
433
 
169
434
  //#endregion
170
435
  //#region src/utils/getBuffer/getBuffer.ts
@@ -804,9 +1069,9 @@ const hasExtension = ({ extensionKey }, client = require_InvalidParamError.getDe
804
1069
  const createVisit = async ({ walletAccount, authMode = _dynamic_labs_sdk_api_core.AuthModeEnum.Only }, client) => {
805
1070
  const core = require_InvalidParamError.getCore(client);
806
1071
  const apiClient = require_InvalidParamError.createApiClient({}, client);
807
- const walletProvider = require_InvalidParamError.getWalletProviderFromWalletAccount({ walletAccount }, client);
1072
+ const walletProvider = require_getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({ walletAccount }, client);
808
1073
  try {
809
- const walletName = require_InvalidParamError.normalizeWalletNameWithChain({
1074
+ const walletName = require_getVerifiedCredentialForWalletAccount.normalizeWalletNameWithChain({
810
1075
  chain: walletProvider.chain,
811
1076
  displayName: walletProvider.metadata.displayName
812
1077
  });
@@ -869,7 +1134,7 @@ const updateWalletProviderKeysForVerifiedCredentials = ({ keysToUpdate }, client
869
1134
  */
870
1135
  const reconcileWalletAccountsAgainstClient = ({ addToDynamicWalletAccounts = true, walletAccounts, walletProviderKey }, client) => {
871
1136
  if (walletAccounts.length === 0) return [];
872
- const existingWalletAccounts = require_InvalidParamError.getWalletAccounts(client);
1137
+ const existingWalletAccounts = require_getVerifiedCredentialForWalletAccount.getWalletAccounts(client);
873
1138
  const newWalletAccounts = [];
874
1139
  const unverifiedWalletAccountsToUpdate = [];
875
1140
  const verifiedCredentialIdToWalletProviderKeyMap = {};
@@ -1006,7 +1271,7 @@ const isErrorWithCode = (error, code) => {
1006
1271
  const verifyMessageSignatureOwnership = async ({ messageToSign, walletAddress, addressesWithTypes, signature, chain, isTransfer = false, walletDisplayName, walletProviderType, networkId, requestedScopes }, client) => {
1007
1272
  const core = require_InvalidParamError.getCore(client);
1008
1273
  const apiClient = require_InvalidParamError.createApiClient({}, client);
1009
- const walletName = require_InvalidParamError.normalizeWalletNameWithChain({
1274
+ const walletName = require_getVerifiedCredentialForWalletAccount.normalizeWalletNameWithChain({
1010
1275
  chain,
1011
1276
  displayName: walletDisplayName
1012
1277
  });
@@ -1117,7 +1382,7 @@ const createNetworkProviderBuilderRegistry = () => {
1117
1382
 
1118
1383
  //#endregion
1119
1384
  //#region src/modules/wallets/networks/networkProviderBuilderRegistry/getNetworkProviderBuilderRegistry/getNetworkProviderBuilderRegistry.ts
1120
- const getNetworkProviderBuilderRegistry = require_InvalidParamError.createRuntimeServiceAccessKey("networkProviderBuilderRegistry", createNetworkProviderBuilderRegistry);
1385
+ const getNetworkProviderBuilderRegistry = require_getVerifiedCredentialForWalletAccount.createRuntimeServiceAccessKey("networkProviderBuilderRegistry", createNetworkProviderBuilderRegistry);
1121
1386
 
1122
1387
  //#endregion
1123
1388
  //#region src/modules/wallets/networks/getNetworkProviders/getNetworkProviders.ts
@@ -1212,12 +1477,24 @@ Object.defineProperty(exports, 'WalletAlreadyLinkedToAnotherUserError', {
1212
1477
  return WalletAlreadyLinkedToAnotherUserError;
1213
1478
  }
1214
1479
  });
1480
+ Object.defineProperty(exports, '__logoutWithReason_wrapped', {
1481
+ enumerable: true,
1482
+ get: function () {
1483
+ return __logoutWithReason_wrapped;
1484
+ }
1485
+ });
1215
1486
  Object.defineProperty(exports, '__setCaptchaToken_wrapped', {
1216
1487
  enumerable: true,
1217
1488
  get: function () {
1218
1489
  return __setCaptchaToken_wrapped;
1219
1490
  }
1220
1491
  });
1492
+ Object.defineProperty(exports, '__toESM', {
1493
+ enumerable: true,
1494
+ get: function () {
1495
+ return __toESM;
1496
+ }
1497
+ });
1221
1498
  Object.defineProperty(exports, 'consumeCaptchaToken', {
1222
1499
  enumerable: true,
1223
1500
  get: function () {
@@ -1272,18 +1549,36 @@ Object.defineProperty(exports, 'createStorage', {
1272
1549
  return createStorage;
1273
1550
  }
1274
1551
  });
1552
+ Object.defineProperty(exports, 'createStorageKeySchema', {
1553
+ enumerable: true,
1554
+ get: function () {
1555
+ return createStorageKeySchema;
1556
+ }
1557
+ });
1275
1558
  Object.defineProperty(exports, 'createVisit', {
1276
1559
  enumerable: true,
1277
1560
  get: function () {
1278
1561
  return createVisit;
1279
1562
  }
1280
1563
  });
1564
+ Object.defineProperty(exports, 'fetchProjectSettings', {
1565
+ enumerable: true,
1566
+ get: function () {
1567
+ return fetchProjectSettings;
1568
+ }
1569
+ });
1281
1570
  Object.defineProperty(exports, 'formatSignInMessage', {
1282
1571
  enumerable: true,
1283
1572
  get: function () {
1284
1573
  return formatSignInMessage;
1285
1574
  }
1286
1575
  });
1576
+ Object.defineProperty(exports, 'generateSessionKeys', {
1577
+ enumerable: true,
1578
+ get: function () {
1579
+ return generateSessionKeys;
1580
+ }
1581
+ });
1287
1582
  Object.defineProperty(exports, 'getAppMetadata', {
1288
1583
  enumerable: true,
1289
1584
  get: function () {
@@ -1350,6 +1645,12 @@ Object.defineProperty(exports, 'isServerSideRendering', {
1350
1645
  return isServerSideRendering;
1351
1646
  }
1352
1647
  });
1648
+ Object.defineProperty(exports, 'isSignedIn', {
1649
+ enumerable: true,
1650
+ get: function () {
1651
+ return isSignedIn;
1652
+ }
1653
+ });
1353
1654
  Object.defineProperty(exports, 'reconcileWalletAccountsAgainstClient', {
1354
1655
  enumerable: true,
1355
1656
  get: function () {
@@ -1362,6 +1663,12 @@ Object.defineProperty(exports, 'removeUnverifiedWalletAccount', {
1362
1663
  return removeUnverifiedWalletAccount;
1363
1664
  }
1364
1665
  });
1666
+ Object.defineProperty(exports, 'retryOnFail', {
1667
+ enumerable: true,
1668
+ get: function () {
1669
+ return retryOnFail;
1670
+ }
1671
+ });
1365
1672
  Object.defineProperty(exports, 'setUnverifiedWalletAccounts', {
1366
1673
  enumerable: true,
1367
1674
  get: function () {
@@ -1386,4 +1693,4 @@ Object.defineProperty(exports, 'verifyMessageSignatureOwnership', {
1386
1693
  return verifyMessageSignatureOwnership;
1387
1694
  }
1388
1695
  });
1389
- //# sourceMappingURL=getNetworkProviderFromNetworkId-BJ27N-7S.cjs.map
1696
+ //# sourceMappingURL=getNetworkProviderFromNetworkId-C1p9Rrg3.cjs.map