@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.
- package/dist/{InvalidParamError-DKJhDrK8.cjs → InvalidParamError-CTssOe86.cjs} +111 -994
- package/dist/InvalidParamError-CTssOe86.cjs.map +1 -0
- package/dist/{InvalidParamError-DkAMYJOW.native.esm.js → InvalidParamError-Crwntjl7.native.esm.js} +96 -829
- package/dist/InvalidParamError-Crwntjl7.native.esm.js.map +1 -0
- package/dist/{InvalidParamError-DWjMfOZ5.esm.js → InvalidParamError-fQLJaGBW.esm.js} +96 -796
- package/dist/InvalidParamError-fQLJaGBW.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-CHzpa9kk.cjs → NotWaasWalletAccountError-2RaDipZu.cjs} +4 -4
- package/dist/NotWaasWalletAccountError-2RaDipZu.cjs.map +1 -0
- package/dist/{NotWaasWalletAccountError-C7NUlvvM.esm.js → NotWaasWalletAccountError-BJLGGYmU.native.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-BJLGGYmU.native.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-BVrvQzLz.native.esm.js → NotWaasWalletAccountError-DF_S7gqo.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-DF_S7gqo.esm.js.map +1 -0
- package/dist/core.cjs +23 -23
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +7 -7
- package/dist/core.esm.js.map +1 -1
- package/dist/core.native.esm.js +5 -5
- package/dist/errors/CorruptedKeyShareError.d.ts +19 -0
- package/dist/errors/CorruptedKeyShareError.d.ts.map +1 -0
- package/dist/errors/WebViewLoadFailedError.d.ts +32 -0
- package/dist/errors/WebViewLoadFailedError.d.ts.map +1 -0
- package/dist/errors/base/BaseError.d.ts.map +1 -1
- package/dist/{getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js → getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js} +310 -67
- package/dist/getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js → getNetworkProviderFromNetworkId-BWhaD23J.esm.js} +280 -42
- package/dist/getNetworkProviderFromNetworkId-BWhaD23J.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-BJ27N-7S.cjs → getNetworkProviderFromNetworkId-C1p9Rrg3.cjs} +351 -44
- package/dist/getNetworkProviderFromNetworkId-C1p9Rrg3.cjs.map +1 -0
- package/dist/{getSignedSessionId-CHDHr-hY.cjs → getSignedSessionId-CxxYNC_8.cjs} +3 -3
- package/dist/{getSignedSessionId-CHDHr-hY.cjs.map → getSignedSessionId-CxxYNC_8.cjs.map} +1 -1
- package/dist/{getSignedSessionId-D3KQrN8W.native.esm.js → getSignedSessionId-DPOXdh6y.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-D3KQrN8W.native.esm.js.map → getSignedSessionId-DPOXdh6y.native.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-CDdKrnw6.esm.js → getSignedSessionId-c7dS4PQ9.esm.js} +3 -3
- package/dist/{getSignedSessionId-CDdKrnw6.esm.js.map → getSignedSessionId-c7dS4PQ9.esm.js.map} +1 -1
- package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js +701 -0
- package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs +887 -0
- package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js +701 -0
- package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js.map +1 -0
- package/dist/index.cjs +76 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +17 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +14 -14
- package/dist/index.native.esm.js.map +1 -1
- package/dist/{isMfaRequiredForAction-C_QPI1LH.esm.js → isMfaRequiredForAction-BjRvPrU6.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-C_QPI1LH.esm.js.map → isMfaRequiredForAction-BjRvPrU6.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-B0xNvBpU.native.esm.js → isMfaRequiredForAction-D8G5PBAd.native.esm.js} +32 -3
- package/dist/isMfaRequiredForAction-D8G5PBAd.native.esm.js.map +1 -0
- package/dist/{isMfaRequiredForAction-CLMvTTwl.cjs → isMfaRequiredForAction-hlhj0qAC.cjs} +2 -2
- package/dist/{isMfaRequiredForAction-CLMvTTwl.cjs.map → isMfaRequiredForAction-hlhj0qAC.cjs.map} +1 -1
- package/dist/modules/apiClient/apiClient.types.d.ts +0 -12
- package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
- package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
- package/dist/modules/auth/logoutReason.d.ts +1 -1
- package/dist/modules/auth/logoutReason.d.ts.map +1 -1
- package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
- package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
- package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
- package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts +12 -1
- package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts.map +1 -1
- package/dist/modules/waas/createWaasClient/createWaasClient.d.ts +2 -7
- package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
- package/dist/modules/waas/createWaasClient/createWaasClient.types.d.ts +8 -0
- package/dist/modules/waas/createWaasClient/createWaasClient.types.d.ts.map +1 -0
- package/dist/modules/waas/createWaasClient/createWaasSDKContainer.d.ts +15 -0
- package/dist/modules/waas/createWaasClient/createWaasSDKContainer.d.ts.map +1 -0
- package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts +18 -0
- package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts.map +1 -0
- package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
- package/dist/modules/waas/waas.types.d.ts +1 -0
- package/dist/modules/waas/waas.types.d.ts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/waas.cjs +12 -9
- package/dist/waas.cjs.map +1 -1
- package/dist/waas.esm.js +6 -4
- package/dist/waas.esm.js.map +1 -1
- package/dist/waas.native.esm.js +6 -4
- package/dist/waas.native.esm.js.map +1 -1
- package/dist/waasCore.cjs +6 -4
- package/dist/waasCore.cjs.map +1 -1
- package/dist/waasCore.esm.js +5 -4
- package/dist/waasCore.esm.js.map +1 -1
- package/dist/waasCore.native.esm.js +210 -8
- package/dist/waasCore.native.esm.js.map +1 -1
- package/package.json +5 -3
- package/dist/InvalidParamError-DKJhDrK8.cjs.map +0 -1
- package/dist/InvalidParamError-DWjMfOZ5.esm.js.map +0 -1
- package/dist/InvalidParamError-DkAMYJOW.native.esm.js.map +0 -1
- package/dist/NotWaasWalletAccountError-BVrvQzLz.native.esm.js.map +0 -1
- package/dist/NotWaasWalletAccountError-C7NUlvvM.esm.js.map +0 -1
- package/dist/NotWaasWalletAccountError-CHzpa9kk.cjs.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-BJ27N-7S.cjs.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js +0 -269
- package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js +0 -269
- package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs +0 -346
- package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs.map +0 -1
- package/dist/isMfaRequiredForAction-B0xNvBpU.native.esm.js.map +0 -1
- package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +0 -27
- package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseError.d.ts","sourceRoot":"","sources":["../../../src/errors/base/BaseError.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG;IAChC,0DAA0D;IAC1D,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAoCF;;GAEG;AACH,8BAAsB,SAAU,SAAQ,KAAK;IAC3C,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IAC7C,IAAI,SAAe;IACnB,KAAK,EAAE,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;gBAElC,IAAI,EAAE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"BaseError.d.ts","sourceRoot":"","sources":["../../../src/errors/base/BaseError.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG;IAChC,0DAA0D;IAC1D,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAoCF;;GAEG;AACH,8BAAsB,SAAU,SAAQ,KAAK;IAC3C,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IAC7C,IAAI,SAAe;IACnB,KAAK,EAAE,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;gBAElC,IAAI,EAAE,mBAAmB;IAwBrC;;OAEG;IACH,IAAI,IAAI,KAAK,GAAG,SAAS;IAUhB,QAAQ;CAGlB"}
|
|
@@ -1,11 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as checkAndRaiseWalletAccountsChangedEvent, p as emitWalletAccountsChangedEvent } from "./getVerifiedCredentialForWalletAccount-
|
|
1
|
+
import { B as getCore, C as isCookieEnabled, D as instrumentFunction, I as getDefaultClient, N as CLIENT_SDK_NAME, c as CHAINS_INFO_MAP, u as createApiClient, w as assertDefined, z as BaseError } from "./InvalidParamError-Crwntjl7.native.esm.js";
|
|
2
|
+
import { D as emitEvent, S as normalizeWalletNameWithChain, b as getWalletAccounts, f as checkAndRaiseWalletAccountsChangedEvent, h as getWalletProviderFromWalletAccount, j as setCookie, m as DYNAMIC_AUTH_COOKIE_NAME, p as emitWalletAccountsChangedEvent, v as createRuntimeServiceAccessKey } from "./getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js";
|
|
3
|
+
import { i as NativeModuleNotLinkedError } from "./isMfaRequiredForAction-D8G5PBAd.native.esm.js";
|
|
3
4
|
import { AuthModeEnum } from "@dynamic-labs/sdk-api-core";
|
|
4
5
|
import * as z from "zod/mini";
|
|
6
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
7
|
+
import { getGenericPassword, resetGenericPassword, setGenericPassword } from "react-native-keychain";
|
|
5
8
|
import { Buffer as Buffer$1 } from "buffer";
|
|
6
9
|
import EventEmitter, { EventEmitter as EventEmitter$1 } from "eventemitter3";
|
|
7
10
|
import { TurboModuleRegistry } from "react-native";
|
|
8
11
|
|
|
12
|
+
//#region src/utils/isEqualShallow/isEqualShallow.ts
|
|
13
|
+
/**
|
|
14
|
+
* Shallow compare two objects.
|
|
15
|
+
*
|
|
16
|
+
* Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
|
|
17
|
+
* @not-instrumented
|
|
18
|
+
*/
|
|
19
|
+
const isEqualShallow = (objA, objB) => {
|
|
20
|
+
if (Object.is(objA, objB)) return true;
|
|
21
|
+
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) return objA === objB;
|
|
22
|
+
if (objA instanceof Map && objB instanceof Map) {
|
|
23
|
+
if (objA.size !== objB.size) return false;
|
|
24
|
+
for (const [key, value] of objA) if (!Object.is(value, objB.get(key))) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (objA instanceof Set && objB instanceof Set) {
|
|
28
|
+
if (objA.size !== objB.size) return false;
|
|
29
|
+
for (const value of objA) if (!objB.has(value)) return false;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const keysA = Object.keys(objA);
|
|
33
|
+
if (keysA.length !== Object.keys(objB).length) return false;
|
|
34
|
+
for (const keyA of keysA) if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) return false;
|
|
35
|
+
if (objA.constructor !== objB.constructor) return false;
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/utils/observable/subscribeWithSelector/subscribeWithSelector.ts
|
|
41
|
+
/**
|
|
42
|
+
* Allows subscribing to a slice of the state.
|
|
43
|
+
* The slice is a computation of the states.
|
|
44
|
+
*
|
|
45
|
+
* The callback will only be called when the slice has changed.
|
|
46
|
+
* Change is determined by shallow comparison.
|
|
47
|
+
*
|
|
48
|
+
* Returns a function to unsubscribe the callback.
|
|
49
|
+
* @not-instrumented
|
|
50
|
+
*/
|
|
51
|
+
const subscribeWithSelector = (observable, selector) => (callback) => {
|
|
52
|
+
let lastSlice = selector(observable.get());
|
|
53
|
+
return observable.subscribe((value) => {
|
|
54
|
+
const nextSlice = selector(value);
|
|
55
|
+
if (isEqualShallow(nextSlice, lastSlice)) return;
|
|
56
|
+
lastSlice = nextSlice;
|
|
57
|
+
callback(nextSlice);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
|
|
63
|
+
/**
|
|
64
|
+
* This error is thrown when the `retryOnFail` function is called with an invalid
|
|
65
|
+
* number of retries (i.e. less than 0).
|
|
66
|
+
*/
|
|
67
|
+
var InvalidRetryOnFailCallError = class extends BaseError {
|
|
68
|
+
constructor(maxRetries) {
|
|
69
|
+
super({
|
|
70
|
+
cause: null,
|
|
71
|
+
code: "invalid_retry_on_fail_call_error",
|
|
72
|
+
docsUrl: null,
|
|
73
|
+
name: "InvalidRetryOnFailCallError",
|
|
74
|
+
shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/utils/retryOnFail/retryOnFail.ts
|
|
81
|
+
/** @not-instrumented */
|
|
82
|
+
const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
|
|
83
|
+
for (let retry = 0; retry <= maxRetries; retry++) try {
|
|
84
|
+
return await fn();
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (retry >= maxRetries) throw error;
|
|
87
|
+
if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reaching this point should never happen and this
|
|
91
|
+
* error is thrown to help us debug the issue.
|
|
92
|
+
*/
|
|
93
|
+
throw new InvalidRetryOnFailCallError(maxRetries);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/modules/auth/isSignedIn/isSignedIn.ts
|
|
98
|
+
/**
|
|
99
|
+
* Checks if the user is currently signed in to the Dynamic client.
|
|
100
|
+
*
|
|
101
|
+
* The client is considered to be in a signed in state if a user has
|
|
102
|
+
* authenticated or if the client has at least one wallet connected.
|
|
103
|
+
*
|
|
104
|
+
* @deprecated What counts as "signed in" is your app's business logic, not the
|
|
105
|
+
* SDK's. This helper bakes in one opinion (a user OR any connected wallet),
|
|
106
|
+
* which rarely matches every app and forces a dependency on us for every
|
|
107
|
+
* variation. Compose your own check from the underlying primitives instead —
|
|
108
|
+
* e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
|
|
109
|
+
* layer in whatever your app requires (device registration, completed
|
|
110
|
+
* onboarding, satisfied MFA, a required embedded wallet, …). See the
|
|
111
|
+
* "Check if signed in" guide:
|
|
112
|
+
* https://www.dynamic.xyz/docs/javascript/user-session-management
|
|
113
|
+
*
|
|
114
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
115
|
+
* @returns True if the user is signed in, false otherwise.
|
|
116
|
+
* @not-instrumented
|
|
117
|
+
*/
|
|
118
|
+
const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/services/storage/createLocalStorageAdapter/createLocalStorageAdapter.native.ts
|
|
122
|
+
const NAMESPACE = "dynamic";
|
|
123
|
+
const namespaceKey = (key) => `${NAMESPACE}:${key}`;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a localStorage adapter for React Native.
|
|
126
|
+
* Routes operations based on the `storageTier` option:
|
|
127
|
+
* - `'default'`: uses AsyncStorage
|
|
128
|
+
* - `'secure'`: uses react-native-keychain
|
|
129
|
+
* @not-instrumented
|
|
130
|
+
*/
|
|
131
|
+
const createLocalStorageAdapter = () => {
|
|
132
|
+
return {
|
|
133
|
+
getItem: async (key, options) => {
|
|
134
|
+
if (options.storageTier === "secure") {
|
|
135
|
+
const result = await getGenericPassword({ service: key });
|
|
136
|
+
if (!result) return null;
|
|
137
|
+
return result.password;
|
|
138
|
+
} else return AsyncStorage.getItem(namespaceKey(key));
|
|
139
|
+
},
|
|
140
|
+
removeItem: async (key, options) => {
|
|
141
|
+
if (options.storageTier === "secure") await resetGenericPassword({ service: key });
|
|
142
|
+
else await AsyncStorage.removeItem(namespaceKey(key));
|
|
143
|
+
},
|
|
144
|
+
setItem: async (key, value, options) => {
|
|
145
|
+
if (options.storageTier === "secure") await setGenericPassword(key, value, { service: key });
|
|
146
|
+
else await AsyncStorage.setItem(namespaceKey(key), value);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
9
152
|
//#region src/errors/InvalidStorageSet.ts
|
|
10
153
|
var InvalidStorageSet = class extends BaseError {
|
|
11
154
|
constructor({ key, value }) {
|
|
@@ -104,54 +247,183 @@ const createStorage = ({ prefix = "", storageAdapter }) => {
|
|
|
104
247
|
};
|
|
105
248
|
|
|
106
249
|
//#endregion
|
|
107
|
-
//#region src/
|
|
250
|
+
//#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
|
|
251
|
+
/** @not-instrumented */
|
|
252
|
+
const createStorageKeySchema = (params) => {
|
|
253
|
+
return params;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
|
|
108
258
|
/**
|
|
109
|
-
*
|
|
259
|
+
* The schema to track the expiration time of the project settings.
|
|
260
|
+
*/
|
|
261
|
+
const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
|
|
262
|
+
key: "projectSettingsExpiration",
|
|
263
|
+
schema: z.number()
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
|
|
268
|
+
/**
|
|
269
|
+
* Expiration time of the project settings in milliseconds.
|
|
270
|
+
*/
|
|
271
|
+
const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
|
|
272
|
+
/**
|
|
273
|
+
* Fetches and updates the project settings from the API.
|
|
110
274
|
*
|
|
111
|
-
*
|
|
275
|
+
* This function retrieves the latest project configuration settings
|
|
276
|
+
* from Dynamic's servers, including authentication options, enabled chains,
|
|
277
|
+
* and security configurations. The settings are cached for performance.
|
|
278
|
+
*
|
|
279
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
280
|
+
* @returns A promise that resolves to the updated project settings.
|
|
112
281
|
* @not-instrumented
|
|
113
282
|
*/
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return true;
|
|
283
|
+
const fetchProjectSettings = async (client = getDefaultClient()) => {
|
|
284
|
+
const core = getCore(client);
|
|
285
|
+
const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
|
|
286
|
+
if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
|
|
287
|
+
const apiClient = createApiClient({}, client);
|
|
288
|
+
core.logger.debug("[fetchProjectSettings] Fetching project settings...");
|
|
289
|
+
const doFetch = async () => apiClient.getEnvironmentSettings({
|
|
290
|
+
environmentId: core.environmentId,
|
|
291
|
+
sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
|
|
292
|
+
}, { credentials: "omit" });
|
|
293
|
+
const projectSettings = await retryOnFail({
|
|
294
|
+
fn: doFetch,
|
|
295
|
+
maxRetries: 2
|
|
296
|
+
});
|
|
297
|
+
core.state.set({ projectSettings: projectSettings ?? null });
|
|
298
|
+
await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
|
|
299
|
+
return projectSettings;
|
|
132
300
|
};
|
|
133
301
|
|
|
134
302
|
//#endregion
|
|
135
|
-
//#region src/
|
|
303
|
+
//#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
|
|
304
|
+
/** @not-instrumented */
|
|
305
|
+
const generateSessionKeys = async (client) => {
|
|
306
|
+
const core = getCore(client);
|
|
307
|
+
await core.keychain.removeKey("session");
|
|
308
|
+
const publicKey = await core.keychain.generateKey("session");
|
|
309
|
+
assertDefined(publicKey, "Public key not found");
|
|
310
|
+
core.state.set({ sessionKeys: publicKey });
|
|
311
|
+
return { publicKey };
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
|
|
316
|
+
/** @not-instrumented */
|
|
317
|
+
const getAvailableWalletProvidersFromWalletAccounts = (client) => {
|
|
318
|
+
const core = getCore(client);
|
|
319
|
+
const walletProvidersMap = /* @__PURE__ */ new Map();
|
|
320
|
+
getWalletAccounts(client).forEach((walletAccount) => {
|
|
321
|
+
if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
|
|
322
|
+
try {
|
|
323
|
+
const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
324
|
+
walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
core.logger.debug("Wallet provider not found for wallet account", {
|
|
327
|
+
error,
|
|
328
|
+
walletAccount: walletAccount.address
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
return Array.from(walletProvidersMap.values());
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
|
|
136
337
|
/**
|
|
137
|
-
*
|
|
138
|
-
* The slice is a computation of the states.
|
|
338
|
+
* Tear down every wallet provider on the client.
|
|
139
339
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
340
|
+
* Each provider's `destroy` is responsible for its own local + remote
|
|
341
|
+
* cleanup. We swallow errors so a failing destroy on one provider does not
|
|
342
|
+
* block teardown of the others (e.g. during logout).
|
|
142
343
|
*
|
|
143
|
-
* Returns a function to unsubscribe the callback.
|
|
144
344
|
* @not-instrumented
|
|
145
345
|
*/
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
346
|
+
const destroyWalletProviders = async ({ reason }, client) => {
|
|
347
|
+
const core = getCore(client);
|
|
348
|
+
const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
|
|
349
|
+
await Promise.all(walletProviders.map(async (walletProvider) => {
|
|
350
|
+
if (!walletProvider.destroy) return;
|
|
351
|
+
try {
|
|
352
|
+
await walletProvider.destroy({ reason });
|
|
353
|
+
} catch (err) {
|
|
354
|
+
core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
|
|
355
|
+
}
|
|
356
|
+
}));
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/modules/auth/logoutWithReason/logoutWithReason.ts
|
|
361
|
+
/**
|
|
362
|
+
* Logs the user out with an explicit reason.
|
|
363
|
+
*
|
|
364
|
+
* Revokes the session, clears auth state, terminates wallet providers, and
|
|
365
|
+
* emits the `logout` client event with the given reason. The reason is also
|
|
366
|
+
* captured as an argument on the function-instrumentation event, which is
|
|
367
|
+
* how Datadog distinguishes between different logout causes.
|
|
368
|
+
*
|
|
369
|
+
* Use this instead of the public `logout` when triggering a logout from
|
|
370
|
+
* internal or extension code — the caller owns the reason string, so the
|
|
371
|
+
* telemetry correctly attributes *why* the logout happened.
|
|
372
|
+
*
|
|
373
|
+
* @param params - The logout params.
|
|
374
|
+
* @param params.reason - Why the logout is being triggered. Extension authors
|
|
375
|
+
* needing a reason outside the SDK catalog can cast with `as LogoutReason`.
|
|
376
|
+
* @param client - The Dynamic client instance.
|
|
377
|
+
* @instrumented
|
|
378
|
+
*/
|
|
379
|
+
const logoutWithReason = async ({ reason }, client) => {
|
|
380
|
+
const core = getCore(client);
|
|
381
|
+
core.logger.debug("[logoutWithReason] Logging out...", { reason });
|
|
382
|
+
await destroyWalletProviders({ reason }, client);
|
|
383
|
+
if (client.user !== null) {
|
|
384
|
+
const apiClient = createApiClient({}, client);
|
|
385
|
+
try {
|
|
386
|
+
await apiClient.revokeSession({ environmentId: core.environmentId });
|
|
387
|
+
} catch (error) {
|
|
388
|
+
core.logger.error("Failed to revoke session", error);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* This deletes the auth cookie if it exists.
|
|
392
|
+
* If the cookie doesn't exist, this sets a new cookie that expires immediately.
|
|
393
|
+
*/
|
|
394
|
+
if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
|
|
395
|
+
}
|
|
396
|
+
await core.keychain.removeKey("session");
|
|
397
|
+
core.state.set({
|
|
398
|
+
captchaToken: null,
|
|
399
|
+
elevatedAccessTokens: [],
|
|
400
|
+
legacyToken: null,
|
|
401
|
+
mfaToken: null,
|
|
402
|
+
sessionExpiresAt: null,
|
|
403
|
+
sessionKeys: null,
|
|
404
|
+
token: null,
|
|
405
|
+
unverifiedWalletAccounts: [],
|
|
406
|
+
user: null
|
|
153
407
|
});
|
|
408
|
+
emitEvent({
|
|
409
|
+
args: { reason },
|
|
410
|
+
event: "logout"
|
|
411
|
+
}, client);
|
|
412
|
+
fetchProjectSettings(client);
|
|
413
|
+
generateSessionKeys(client);
|
|
154
414
|
};
|
|
415
|
+
const __logoutWithReason_impl = logoutWithReason;
|
|
416
|
+
const __logoutWithReason_wrapped = instrumentFunction({
|
|
417
|
+
fn: __logoutWithReason_impl,
|
|
418
|
+
functionName: "logoutWithReason",
|
|
419
|
+
getCore: () => {
|
|
420
|
+
try {
|
|
421
|
+
return getCore(getDefaultClient());
|
|
422
|
+
} catch {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
});
|
|
155
427
|
|
|
156
428
|
//#endregion
|
|
157
429
|
//#region src/utils/getBuffer/getBuffer.ts
|
|
@@ -301,35 +573,6 @@ const createLogger = (options = {}) => {
|
|
|
301
573
|
};
|
|
302
574
|
};
|
|
303
575
|
|
|
304
|
-
//#endregion
|
|
305
|
-
//#region src/errors/NativeModuleNotLinkedError.ts
|
|
306
|
-
var NativeModuleNotLinkedError = class extends BaseError {
|
|
307
|
-
constructor({ moduleName }) {
|
|
308
|
-
super({
|
|
309
|
-
cause: null,
|
|
310
|
-
code: "native_module_not_linked_error",
|
|
311
|
-
details: [
|
|
312
|
-
`The "${moduleName}" TurboModule is not registered with React Native.`,
|
|
313
|
-
"This usually means the native module was not autolinked into the host app,",
|
|
314
|
-
"or the app binary was not rebuilt after installing the SDK.",
|
|
315
|
-
"",
|
|
316
|
-
"To resolve:",
|
|
317
|
-
" 1. Ensure \"@dynamic-labs-sdk/client\" is a direct dependency of the app",
|
|
318
|
-
" and reinstall (e.g. `pnpm install`).",
|
|
319
|
-
" 2. Rebuild the native app:",
|
|
320
|
-
" iOS: `cd ios && pod install && cd .. && npx react-native run-ios`",
|
|
321
|
-
" Android: `npx react-native run-android`",
|
|
322
|
-
" Expo: `npx expo prebuild --clean` then run the app.",
|
|
323
|
-
" 3. Confirm autolinking sees the package:",
|
|
324
|
-
" `npx expo-modules-autolinking react-native-config --json`"
|
|
325
|
-
].join("\n"),
|
|
326
|
-
docsUrl: null,
|
|
327
|
-
name: "NativeModuleNotLinkedError",
|
|
328
|
-
shortMessage: `Native TurboModule "${moduleName}" is not linked.`
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
|
|
333
576
|
//#endregion
|
|
334
577
|
//#region src/turboModules/NativeKeychain.ts
|
|
335
578
|
var NativeKeychain_default = TurboModuleRegistry.getEnforcing("Keychain");
|
|
@@ -1139,5 +1382,5 @@ const getNetworkProviderFromNetworkId = ({ networkId, chain }, client) => {
|
|
|
1139
1382
|
};
|
|
1140
1383
|
|
|
1141
1384
|
//#endregion
|
|
1142
|
-
export {
|
|
1143
|
-
//# sourceMappingURL=getNetworkProviderFromNetworkId-
|
|
1385
|
+
export { GENERATE_SESSION_KEYS_TRACKER_KEY as A, createStorage as B, createKeychainService as C, CannotTrackError as D, CrossTabBroadcastMessageSchema as E, getBuffer as F, subscribeWithSelector as G, createLocalStorageAdapter as H, __logoutWithReason_wrapped as I, isEqualShallow as K, generateSessionKeys as L, REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY as M, REFRESH_USER_STATE_FROM_VALID_TOKEN_TRACKER_KEY as N, createDeferredPromise as O, isServerSideRendering as P, fetchProjectSettings as R, createRealtimeService as S, createCrossTabBroadcast as T, isSignedIn as U, InvalidStorageSet as V, retryOnFail as W, getAppMetadata as _, verifyMessageSignatureOwnership as a, NoNetworkProvidersError as b, formatSignInMessage as c, setUnverifiedWalletAccounts as d, createVisit as f, isCaptchaRequired as g, consumeCaptchaToken as h, getNetworksData as i, INITIALIZE_STORAGE_SYNC_TRACKER_KEY as j, FETCH_PROJECT_SETTINGS_TRACKER_KEY as k, reconcileWalletAccountsAgainstClient as l, __setCaptchaToken_wrapped as m, getNetworkProviders as n, removeUnverifiedWalletAccount as o, hasExtension as p, getNetworkProviderBuilderRegistry as r, createSignInMessageStatement as s, getNetworkProviderFromNetworkId as t, updateWalletProviderKeysForVerifiedCredentials as u, MethodNotImplementedError as v, createLogger as w, getKeychainIndexedDBName as x, WalletAlreadyLinkedToAnotherUserError as y, createStorageKeySchema as z };
|
|
1386
|
+
//# sourceMappingURL=getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js.map
|