@dynamic-labs-sdk/client 1.22.0 → 1.23.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/{NativeModuleNotLinkedError-BK7v1pWC.native.esm.js → NativeModuleNotLinkedError-DIpQjh_K.native.esm.js} +196 -182
- package/dist/NativeModuleNotLinkedError-DIpQjh_K.native.esm.js.map +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/{consumeMfaTokenIfRequiredForAction-BIgGN1OX.esm.js → consumeMfaTokenIfRequiredForAction-jsAdDyDj.esm.js} +2 -2
- package/dist/{consumeMfaTokenIfRequiredForAction-BIgGN1OX.esm.js.map → consumeMfaTokenIfRequiredForAction-jsAdDyDj.esm.js.map} +1 -1
- package/dist/{consumeMfaTokenIfRequiredForAction-csagEe9v.cjs → consumeMfaTokenIfRequiredForAction-pUcqlY3s.cjs} +2 -2
- package/dist/{consumeMfaTokenIfRequiredForAction-csagEe9v.cjs.map → consumeMfaTokenIfRequiredForAction-pUcqlY3s.cjs.map} +1 -1
- package/dist/core.cjs +8 -7
- 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 +6 -6
- package/dist/core.native.esm.js.map +1 -1
- package/dist/exports/core.d.ts +2 -0
- package/dist/exports/core.d.ts.map +1 -1
- package/dist/exports/waas.d.ts +1 -0
- package/dist/exports/waas.d.ts.map +1 -1
- package/dist/generated/dependencyCatalog.d.ts +4 -0
- package/dist/generated/dependencyCatalog.d.ts.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-BAbc7qAr.cjs → getNetworkProviderFromNetworkId-DPFHY3b8.cjs} +2 -2
- package/dist/{getNetworkProviderFromNetworkId-BAbc7qAr.cjs.map → getNetworkProviderFromNetworkId-DPFHY3b8.cjs.map} +1 -1
- package/dist/{getNetworkProviderFromNetworkId-4Xoiy8NQ.esm.js → getNetworkProviderFromNetworkId-DTNPpR5H.esm.js} +2 -2
- package/dist/{getNetworkProviderFromNetworkId-4Xoiy8NQ.esm.js.map → getNetworkProviderFromNetworkId-DTNPpR5H.esm.js.map} +1 -1
- package/dist/{getNetworkProviderFromNetworkId-BZJXSy5b.native.esm.js → getNetworkProviderFromNetworkId-YcalZlDG.native.esm.js} +3 -3
- package/dist/getNetworkProviderFromNetworkId-YcalZlDG.native.esm.js.map +1 -0
- package/dist/{getSignedSessionId-C9EFdGfb.native.esm.js → getSignedSessionId-BjhgfsJD.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-C9EFdGfb.native.esm.js.map → getSignedSessionId-BjhgfsJD.native.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-bbTK-sA0.esm.js → getSignedSessionId-Btl5p_7b.esm.js} +2 -2
- package/dist/{getSignedSessionId-bbTK-sA0.esm.js.map → getSignedSessionId-Btl5p_7b.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-DpZexHsP.cjs → getSignedSessionId-VX7LkxVJ.cjs} +2 -2
- package/dist/{getSignedSessionId-DpZexHsP.cjs.map → getSignedSessionId-VX7LkxVJ.cjs.map} +1 -1
- package/dist/{getWalletProviderByKey-Bmqc0Duc.cjs → getWalletProviderByKey--K4N2u-M.cjs} +2 -2
- package/dist/{getWalletProviderByKey-Bmqc0Duc.cjs.map → getWalletProviderByKey--K4N2u-M.cjs.map} +1 -1
- package/dist/{getWalletProviderByKey-D_TZdpYc.esm.js → getWalletProviderByKey-5sZK6kAJ.esm.js} +2 -2
- package/dist/{getWalletProviderByKey-D_TZdpYc.esm.js.map → getWalletProviderByKey-5sZK6kAJ.esm.js.map} +1 -1
- package/dist/{getWalletProviderByKey-DVBZq2sg.native.esm.js → getWalletProviderByKey-BhcBoGMW.native.esm.js} +2 -2
- package/dist/{getWalletProviderByKey-DVBZq2sg.native.esm.js.map → getWalletProviderByKey-BhcBoGMW.native.esm.js.map} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.esm.js +6 -6
- package/dist/index.native.esm.js +6 -6
- package/dist/{isDynamicWaasEnabled-NC2_jndd.native.esm.js → isDynamicWaasEnabled-BR_pG4jM.native.esm.js} +2 -2
- package/dist/{isDynamicWaasEnabled-NC2_jndd.native.esm.js.map → isDynamicWaasEnabled-BR_pG4jM.native.esm.js.map} +1 -1
- package/dist/{isDynamicWaasEnabled-Bfd-h02Q.cjs → isDynamicWaasEnabled-MtEVK3ov.cjs} +2 -2
- package/dist/{isDynamicWaasEnabled-Bfd-h02Q.cjs.map → isDynamicWaasEnabled-MtEVK3ov.cjs.map} +1 -1
- package/dist/{isDynamicWaasEnabled-BJimir8s.esm.js → isDynamicWaasEnabled-sI3vpWvA.esm.js} +2 -2
- package/dist/{isDynamicWaasEnabled-BJimir8s.esm.js.map → isDynamicWaasEnabled-sI3vpWvA.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-W1y6oe6Y.cjs → isMfaRequiredForAction-BiPVqg49.cjs} +2 -2
- package/dist/{isMfaRequiredForAction-W1y6oe6Y.cjs.map → isMfaRequiredForAction-BiPVqg49.cjs.map} +1 -1
- package/dist/{isMfaRequiredForAction-DMB9vA5-.esm.js → isMfaRequiredForAction-DJ2UX11y.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-DMB9vA5-.esm.js.map → isMfaRequiredForAction-DJ2UX11y.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-MdS-yMQf.native.esm.js → isMfaRequiredForAction-GWZny7T2.native.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-MdS-yMQf.native.esm.js.map → isMfaRequiredForAction-GWZny7T2.native.esm.js.map} +1 -1
- package/dist/{isUserOnboardingComplete-BmGd69SF.cjs → isUserOnboardingComplete-D1hw1c5_.cjs} +3 -3
- package/dist/{isUserOnboardingComplete-BmGd69SF.cjs.map → isUserOnboardingComplete-D1hw1c5_.cjs.map} +1 -1
- package/dist/{isUserOnboardingComplete-Bj0ClaGP.native.esm.js → isUserOnboardingComplete-Hzz6fwTk.native.esm.js} +3 -3
- package/dist/{isUserOnboardingComplete-Bj0ClaGP.native.esm.js.map → isUserOnboardingComplete-Hzz6fwTk.native.esm.js.map} +1 -1
- package/dist/{isUserOnboardingComplete-Cm2VLmIH.esm.js → isUserOnboardingComplete-OvzVH1rg.esm.js} +3 -3
- package/dist/{isUserOnboardingComplete-Cm2VLmIH.esm.js.map → isUserOnboardingComplete-OvzVH1rg.esm.js.map} +1 -1
- package/dist/{migrateFromFireblocks-rs5CZz-4.native.esm.js → migrateFromFireblocks-BiLoNIkA.native.esm.js} +3 -3
- package/dist/{migrateFromFireblocks-rs5CZz-4.native.esm.js.map → migrateFromFireblocks-BiLoNIkA.native.esm.js.map} +1 -1
- package/dist/{migrateFromFireblocks-rQkE9cQa.cjs → migrateFromFireblocks-NRfLh1JL.cjs} +4 -4
- package/dist/{migrateFromFireblocks-rQkE9cQa.cjs.map → migrateFromFireblocks-NRfLh1JL.cjs.map} +1 -1
- package/dist/{migrateFromFireblocks-BUuulRx2.esm.js → migrateFromFireblocks-Y5pPtmew.esm.js} +4 -4
- package/dist/{migrateFromFireblocks-BUuulRx2.esm.js.map → migrateFromFireblocks-Y5pPtmew.esm.js.map} +1 -1
- package/dist/modules/apiClient/constants.d.ts +8 -1
- package/dist/modules/apiClient/constants.d.ts.map +1 -1
- package/dist/modules/apiClient/createApiClient.d.ts +1 -2
- package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
- package/dist/modules/apiClient/createBaseApiClient.d.ts +16 -0
- package/dist/modules/apiClient/createBaseApiClient.d.ts.map +1 -0
- package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
- package/dist/modules/waas/businessAccounts/updateBusinessAccountMemberRole/index.d.ts +2 -0
- package/dist/modules/waas/businessAccounts/updateBusinessAccountMemberRole/index.d.ts.map +1 -0
- package/dist/modules/waas/businessAccounts/updateBusinessAccountMemberRole/updateBusinessAccountMemberRole.d.ts +35 -0
- package/dist/modules/waas/businessAccounts/updateBusinessAccountMemberRole/updateBusinessAccountMemberRole.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/{updateAuthFromVerifyResponse-CNfUcLNC.cjs → updateAuthFromVerifyResponse-ChnvPY0m.cjs} +196 -188
- package/dist/updateAuthFromVerifyResponse-ChnvPY0m.cjs.map +1 -0
- package/dist/{updateAuthFromVerifyResponse-85pmbAH4.esm.js → updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js} +197 -183
- package/dist/updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js.map +1 -0
- package/dist/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.d.ts.map +1 -1
- package/dist/waas.cjs +45 -5
- package/dist/waas.cjs.map +1 -1
- package/dist/waas.esm.js +46 -7
- package/dist/waas.esm.js.map +1 -1
- package/dist/waas.native.esm.js +45 -6
- package/dist/waas.native.esm.js.map +1 -1
- package/dist/waasCore.cjs +7 -7
- package/dist/waasCore.esm.js +7 -7
- package/dist/waasCore.native.esm.js +6 -6
- package/package.json +6 -4
- package/dist/NativeModuleNotLinkedError-BK7v1pWC.native.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-BZJXSy5b.native.esm.js.map +0 -1
- package/dist/updateAuthFromVerifyResponse-85pmbAH4.esm.js.map +0 -1
- package/dist/updateAuthFromVerifyResponse-CNfUcLNC.cjs.map +0 -1
package/dist/{updateAuthFromVerifyResponse-CNfUcLNC.cjs → updateAuthFromVerifyResponse-ChnvPY0m.cjs}
RENAMED
|
@@ -31,18 +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.
|
|
35
|
-
var dependencies = {
|
|
36
|
-
"@dynamic-labs-sdk/assert-package-version": "workspace:*",
|
|
37
|
-
"@dynamic-labs-wallet/browser-wallet-client": "1.0.79",
|
|
38
|
-
"@dynamic-labs-wallet/forward-mpc-client": "1.0.1",
|
|
39
|
-
"@dynamic-labs/sdk-api-core": "catalog:",
|
|
40
|
-
"@simplewebauthn/browser": "13.1.0",
|
|
41
|
-
"ably": "2.17.1",
|
|
42
|
-
"buffer": "6.0.3",
|
|
43
|
-
"eventemitter3": "5.0.1",
|
|
44
|
-
"zod": "4.0.5"
|
|
45
|
-
};
|
|
34
|
+
var version = "1.23.0";
|
|
46
35
|
|
|
47
36
|
//#endregion
|
|
48
37
|
//#region src/client/core/getCore/getCore.ts
|
|
@@ -166,26 +155,6 @@ const setDefaultClient = (client) => {
|
|
|
166
155
|
const NONCE_POOL_EXPIRATION_TIME = 6e4 * 60 * 24;
|
|
167
156
|
const NONCE_POOL_SIZE = 5;
|
|
168
157
|
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region src/modules/apiClient/constants.ts
|
|
171
|
-
const DYNAMIC_API_VERSION_HEADER = "x-dyn-api-version";
|
|
172
|
-
const DYNAMIC_REQUEST_ID_HEADER = "x-dyn-request-id";
|
|
173
|
-
const DYNAMIC_SDK_VERSION_HEADER = "x-dyn-version";
|
|
174
|
-
const ELEVATED_ACCESS_TOKEN_HEADER = "x-dyn-elevated-access-token";
|
|
175
|
-
const MFA_TOKEN_HEADER = "x-mfa-auth-token";
|
|
176
|
-
const SESSION_PUBLIC_KEY_HEADER = "x-dyn-session-public-key";
|
|
177
|
-
const DYNAMIC_SDK_API_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
178
|
-
const DYNAMIC_SDK_SESSION_ID_HEADER = "x-dyn-session-id";
|
|
179
|
-
/**
|
|
180
|
-
* Reports the runtime platform (`web` or `react-native`) to the Dynamic API.
|
|
181
|
-
*
|
|
182
|
-
* Named `x-dynamic-platform` (not `x-dyn-*`) to match the header the legacy
|
|
183
|
-
* webview-controller already sends, so the backend receives a consistent
|
|
184
|
-
* platform signal across SDK generations.
|
|
185
|
-
*/
|
|
186
|
-
const DYNAMIC_PLATFORM_HEADER = "x-dynamic-platform";
|
|
187
|
-
const CLIENT_SDK_NAME = "ClientSDK";
|
|
188
|
-
|
|
189
158
|
//#endregion
|
|
190
159
|
//#region src/utils/getPlatform/getPlatform.ts
|
|
191
160
|
/**
|
|
@@ -312,6 +281,41 @@ const getSessionKeys = (client) => {
|
|
|
312
281
|
return { publicKey };
|
|
313
282
|
};
|
|
314
283
|
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/generated/dependencyCatalog.ts
|
|
286
|
+
const dependencyCatalog = { "@dynamic-labs/sdk-api-core": "0.0.1083" };
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/constants.ts
|
|
290
|
+
const SDK_API_CORE_VERSION = dependencyCatalog["@dynamic-labs/sdk-api-core"];
|
|
291
|
+
const DYNAMIC_ICONIC_SPRITE_URL = "https://iconic.dynamic-static-assets.com/icons/sprite.svg";
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/modules/apiClient/constants.ts
|
|
295
|
+
const DYNAMIC_API_VERSION_HEADER = "x-dyn-api-version";
|
|
296
|
+
const DYNAMIC_REQUEST_ID_HEADER = "x-dyn-request-id";
|
|
297
|
+
const DYNAMIC_SDK_VERSION_HEADER = "x-dyn-version";
|
|
298
|
+
/**
|
|
299
|
+
* Reports *why* the SDK is logging the user out on the `revokeSession`
|
|
300
|
+
* (`/sdk/{env}/revoke`) request. The backend logs it so SDK-initiated session
|
|
301
|
+
* revocations are attributable in Datadog (e.g. `token-expired`,
|
|
302
|
+
* `keychain-key-missing`) instead of being inferred from downstream 401s.
|
|
303
|
+
*/
|
|
304
|
+
const DYNAMIC_LOGOUT_REASON_HEADER = "x-dyn-logout-reason";
|
|
305
|
+
const ELEVATED_ACCESS_TOKEN_HEADER = "x-dyn-elevated-access-token";
|
|
306
|
+
const MFA_TOKEN_HEADER = "x-mfa-auth-token";
|
|
307
|
+
const SESSION_PUBLIC_KEY_HEADER = "x-dyn-session-public-key";
|
|
308
|
+
const DYNAMIC_SDK_SESSION_ID_HEADER = "x-dyn-session-id";
|
|
309
|
+
/**
|
|
310
|
+
* Reports the runtime platform (`web` or `react-native`) to the Dynamic API.
|
|
311
|
+
*
|
|
312
|
+
* Named `x-dynamic-platform` (not `x-dyn-*`) to match the header the legacy
|
|
313
|
+
* webview-controller already sends, so the backend receives a consistent
|
|
314
|
+
* platform signal across SDK generations.
|
|
315
|
+
*/
|
|
316
|
+
const DYNAMIC_PLATFORM_HEADER = "x-dynamic-platform";
|
|
317
|
+
const CLIENT_SDK_NAME = "ClientSDK";
|
|
318
|
+
|
|
315
319
|
//#endregion
|
|
316
320
|
//#region src/errors/APIError/APIError.ts
|
|
317
321
|
var APIError = class APIError extends BaseError {
|
|
@@ -483,6 +487,81 @@ const createConvertToApiErrorMiddleware = ({ errorMappers = [] }) => ({ post: as
|
|
|
483
487
|
return context.response;
|
|
484
488
|
} });
|
|
485
489
|
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/errors/UnauthorizedError.ts
|
|
492
|
+
var UnauthorizedError = class extends BaseError {
|
|
493
|
+
constructor({ cause }) {
|
|
494
|
+
super({
|
|
495
|
+
cause,
|
|
496
|
+
code: "unauthorized_error",
|
|
497
|
+
docsUrl: null,
|
|
498
|
+
name: "UnauthorizedError",
|
|
499
|
+
shortMessage: "Unauthorized"
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
506
|
+
/** @notInstrumented */
|
|
507
|
+
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
508
|
+
if (context.response.status === 401) {
|
|
509
|
+
let cause = null;
|
|
510
|
+
try {
|
|
511
|
+
const errorBody = await context.response.clone().json();
|
|
512
|
+
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
513
|
+
} catch {}
|
|
514
|
+
throw new UnauthorizedError({ cause });
|
|
515
|
+
}
|
|
516
|
+
return context.response;
|
|
517
|
+
} });
|
|
518
|
+
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/modules/apiClient/createBaseApiClient.ts
|
|
521
|
+
/**
|
|
522
|
+
* Creates the base SDK API client from the client's core state, applying the
|
|
523
|
+
* standard headers and the always-on error-conversion and unauthorized
|
|
524
|
+
* middleware. Any middleware passed via `middleware` runs before those two.
|
|
525
|
+
* @notInstrumented
|
|
526
|
+
*/
|
|
527
|
+
const createBaseApiClient = ({ middleware = [], options = {} }, client) => {
|
|
528
|
+
const core = getCore(client);
|
|
529
|
+
const coreState = core.state.get();
|
|
530
|
+
const settings = {
|
|
531
|
+
basePath: core.apiBaseUrl,
|
|
532
|
+
headers: {
|
|
533
|
+
"Content-Type": "application/json",
|
|
534
|
+
[DYNAMIC_API_VERSION_HEADER]: `API/${SDK_API_CORE_VERSION}`,
|
|
535
|
+
[DYNAMIC_PLATFORM_HEADER]: getPlatform(),
|
|
536
|
+
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
537
|
+
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
538
|
+
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
539
|
+
...core.getApiHeaders(),
|
|
540
|
+
...options.headers
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
544
|
+
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
545
|
+
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
546
|
+
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
547
|
+
if (options.elevatedAccessTokenScope) {
|
|
548
|
+
const elevatedToken = getElevatedAccessToken({ scope: options.elevatedAccessTokenScope }, client);
|
|
549
|
+
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
550
|
+
}
|
|
551
|
+
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
552
|
+
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
553
|
+
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
554
|
+
return new _dynamic_labs_sdk_api_core.SDKApi(new _dynamic_labs_sdk_api_core.Configuration({
|
|
555
|
+
...settings,
|
|
556
|
+
fetchApi: core.fetch,
|
|
557
|
+
middleware: [
|
|
558
|
+
...middleware,
|
|
559
|
+
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
560
|
+
createUnauthorizedMiddleware()
|
|
561
|
+
]
|
|
562
|
+
}));
|
|
563
|
+
};
|
|
564
|
+
|
|
486
565
|
//#endregion
|
|
487
566
|
//#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
|
|
488
567
|
/** @notInstrumented */
|
|
@@ -533,6 +612,85 @@ const updateNoncePoolStorage = async ({ update }, client) => {
|
|
|
533
612
|
return storedBeforeUpdate;
|
|
534
613
|
};
|
|
535
614
|
|
|
615
|
+
//#endregion
|
|
616
|
+
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
617
|
+
/**
|
|
618
|
+
* Fetches a batch of nonces from the API and appends them to the pool in
|
|
619
|
+
* storage.
|
|
620
|
+
*
|
|
621
|
+
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
622
|
+
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
623
|
+
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
624
|
+
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
625
|
+
* `getNonce` can return from the stored pool without an interrupting network
|
|
626
|
+
* round-trip.
|
|
627
|
+
*
|
|
628
|
+
* New nonces are **appended** to the stored pool so that unconsumed entries
|
|
629
|
+
* are not discarded by a background refetch; an expired stored pool is
|
|
630
|
+
* replaced instead, since its nonces have already been evicted server-side.
|
|
631
|
+
*
|
|
632
|
+
* Concurrent refills are coalesced behind a single in-flight promise so that
|
|
633
|
+
* simultaneous callers share one `GET /nonces` round-trip instead of each
|
|
634
|
+
* issuing their own (which would inflate the pool and hammer the backend).
|
|
635
|
+
* @notInstrumented
|
|
636
|
+
*/
|
|
637
|
+
const fetchAndStoreNonces = async (client) => {
|
|
638
|
+
const core = getCore(client);
|
|
639
|
+
const inFlight = core.state.get().nonceFetchInFlight;
|
|
640
|
+
if (inFlight) return inFlight;
|
|
641
|
+
const { environmentId } = core;
|
|
642
|
+
const apiClient = createBaseApiClient({}, client);
|
|
643
|
+
const fetchPromise = (async () => {
|
|
644
|
+
const { nonces } = await apiClient.getNonces({
|
|
645
|
+
count: NONCE_POOL_SIZE,
|
|
646
|
+
environmentId
|
|
647
|
+
});
|
|
648
|
+
const expiration = Date.now() + NONCE_POOL_EXPIRATION_TIME;
|
|
649
|
+
await updateNoncePoolStorage({ update: (stored) => {
|
|
650
|
+
return {
|
|
651
|
+
expiration,
|
|
652
|
+
nonces: [...stored && stored.expiration > Date.now() ? stored.nonces : [], ...nonces]
|
|
653
|
+
};
|
|
654
|
+
} }, client);
|
|
655
|
+
})().finally(() => {
|
|
656
|
+
core.state.set({ nonceFetchInFlight: null });
|
|
657
|
+
});
|
|
658
|
+
core.state.set({ nonceFetchInFlight: fetchPromise });
|
|
659
|
+
return fetchPromise;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/utils/getSecureCookieAttribute/getSecureCookieAttribute.ts
|
|
664
|
+
/**
|
|
665
|
+
* Returns the cookie `Secure` attribute suffix (`'; Secure'`) when the current
|
|
666
|
+
* document is running in a secure context, or an empty string otherwise.
|
|
667
|
+
*
|
|
668
|
+
* The `Secure` attribute prevents the browser from ever transmitting the cookie
|
|
669
|
+
* over an unencrypted `http://` connection, which mitigates cleartext token
|
|
670
|
+
* capture (CWE-614). It is intentionally omitted on insecure/localhost dev,
|
|
671
|
+
* because browsers reject `Secure` cookies set over `http://` and that would
|
|
672
|
+
* silently break local testing.
|
|
673
|
+
*
|
|
674
|
+
* Used when building the Dynamic auth JWT cookie string so the attribute is
|
|
675
|
+
* applied consistently on both the write (sign-in/refresh) and clear (logout)
|
|
676
|
+
* paths.
|
|
677
|
+
*
|
|
678
|
+
* @notInstrumented
|
|
679
|
+
*/
|
|
680
|
+
const getSecureCookieAttribute = () => {
|
|
681
|
+
return Boolean(globalThis.window?.isSecureContext) || globalThis.location?.protocol === "https:" ? "; Secure" : "";
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/utils/setCookie/setCookie.ts
|
|
686
|
+
/**
|
|
687
|
+
* Sefelly sets the cookie in the browser.
|
|
688
|
+
* @notInstrumented
|
|
689
|
+
*/
|
|
690
|
+
const setCookie = (cookie) => {
|
|
691
|
+
document.cookie = cookie;
|
|
692
|
+
};
|
|
693
|
+
|
|
536
694
|
//#endregion
|
|
537
695
|
//#region src/utils/getNonce/getNonce.ts
|
|
538
696
|
/**
|
|
@@ -635,35 +793,6 @@ const createDeviceSignatureHeadersMiddleware = (client) => {
|
|
|
635
793
|
} };
|
|
636
794
|
};
|
|
637
795
|
|
|
638
|
-
//#endregion
|
|
639
|
-
//#region src/errors/UnauthorizedError.ts
|
|
640
|
-
var UnauthorizedError = class extends BaseError {
|
|
641
|
-
constructor({ cause }) {
|
|
642
|
-
super({
|
|
643
|
-
cause,
|
|
644
|
-
code: "unauthorized_error",
|
|
645
|
-
docsUrl: null,
|
|
646
|
-
name: "UnauthorizedError",
|
|
647
|
-
shortMessage: "Unauthorized"
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
|
|
652
|
-
//#endregion
|
|
653
|
-
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
654
|
-
/** @notInstrumented */
|
|
655
|
-
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
656
|
-
if (context.response.status === 401) {
|
|
657
|
-
let cause = null;
|
|
658
|
-
try {
|
|
659
|
-
const errorBody = await context.response.clone().json();
|
|
660
|
-
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
661
|
-
} catch {}
|
|
662
|
-
throw new UnauthorizedError({ cause });
|
|
663
|
-
}
|
|
664
|
-
return context.response;
|
|
665
|
-
} });
|
|
666
|
-
|
|
667
796
|
//#endregion
|
|
668
797
|
//#region src/modules/apiClient/createApiClient.ts
|
|
669
798
|
/**
|
|
@@ -673,120 +802,10 @@ const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
|
673
802
|
* @notInstrumented
|
|
674
803
|
*/
|
|
675
804
|
const createApiClient = (options = {}, client) => {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
headers: {
|
|
681
|
-
"Content-Type": "application/json",
|
|
682
|
-
[DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
|
|
683
|
-
[DYNAMIC_PLATFORM_HEADER]: getPlatform(),
|
|
684
|
-
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
685
|
-
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
686
|
-
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
687
|
-
...core.getApiHeaders(),
|
|
688
|
-
...options.headers
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
692
|
-
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
693
|
-
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
694
|
-
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
695
|
-
if (options.elevatedAccessTokenScope) {
|
|
696
|
-
const elevatedToken = getElevatedAccessToken({ scope: options.elevatedAccessTokenScope }, client);
|
|
697
|
-
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
698
|
-
}
|
|
699
|
-
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
700
|
-
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
701
|
-
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
702
|
-
return new _dynamic_labs_sdk_api_core.SDKApi(new _dynamic_labs_sdk_api_core.Configuration({
|
|
703
|
-
...settings,
|
|
704
|
-
fetchApi: core.fetch,
|
|
705
|
-
middleware: [
|
|
706
|
-
createDeviceSignatureHeadersMiddleware(client),
|
|
707
|
-
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
708
|
-
createUnauthorizedMiddleware()
|
|
709
|
-
]
|
|
710
|
-
}));
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
//#endregion
|
|
714
|
-
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
715
|
-
/**
|
|
716
|
-
* Fetches a batch of nonces from the API and appends them to the pool in
|
|
717
|
-
* storage.
|
|
718
|
-
*
|
|
719
|
-
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
720
|
-
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
721
|
-
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
722
|
-
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
723
|
-
* `getNonce` can return from the stored pool without an interrupting network
|
|
724
|
-
* round-trip.
|
|
725
|
-
*
|
|
726
|
-
* New nonces are **appended** to the stored pool so that unconsumed entries
|
|
727
|
-
* are not discarded by a background refetch; an expired stored pool is
|
|
728
|
-
* replaced instead, since its nonces have already been evicted server-side.
|
|
729
|
-
*
|
|
730
|
-
* Concurrent refills are coalesced behind a single in-flight promise so that
|
|
731
|
-
* simultaneous callers share one `GET /nonces` round-trip instead of each
|
|
732
|
-
* issuing their own (which would inflate the pool and hammer the backend).
|
|
733
|
-
* @notInstrumented
|
|
734
|
-
*/
|
|
735
|
-
const fetchAndStoreNonces = async (client) => {
|
|
736
|
-
const core = getCore(client);
|
|
737
|
-
const inFlight = core.state.get().nonceFetchInFlight;
|
|
738
|
-
if (inFlight) return inFlight;
|
|
739
|
-
const { environmentId } = core;
|
|
740
|
-
const apiClient = createApiClient({}, client);
|
|
741
|
-
const fetchPromise = (async () => {
|
|
742
|
-
const { nonces } = await apiClient.getNonces({
|
|
743
|
-
count: NONCE_POOL_SIZE,
|
|
744
|
-
environmentId
|
|
745
|
-
});
|
|
746
|
-
const expiration = Date.now() + NONCE_POOL_EXPIRATION_TIME;
|
|
747
|
-
await updateNoncePoolStorage({ update: (stored) => {
|
|
748
|
-
return {
|
|
749
|
-
expiration,
|
|
750
|
-
nonces: [...stored && stored.expiration > Date.now() ? stored.nonces : [], ...nonces]
|
|
751
|
-
};
|
|
752
|
-
} }, client);
|
|
753
|
-
})().finally(() => {
|
|
754
|
-
core.state.set({ nonceFetchInFlight: null });
|
|
755
|
-
});
|
|
756
|
-
core.state.set({ nonceFetchInFlight: fetchPromise });
|
|
757
|
-
return fetchPromise;
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
//#endregion
|
|
761
|
-
//#region src/utils/getSecureCookieAttribute/getSecureCookieAttribute.ts
|
|
762
|
-
/**
|
|
763
|
-
* Returns the cookie `Secure` attribute suffix (`'; Secure'`) when the current
|
|
764
|
-
* document is running in a secure context, or an empty string otherwise.
|
|
765
|
-
*
|
|
766
|
-
* The `Secure` attribute prevents the browser from ever transmitting the cookie
|
|
767
|
-
* over an unencrypted `http://` connection, which mitigates cleartext token
|
|
768
|
-
* capture (CWE-614). It is intentionally omitted on insecure/localhost dev,
|
|
769
|
-
* because browsers reject `Secure` cookies set over `http://` and that would
|
|
770
|
-
* silently break local testing.
|
|
771
|
-
*
|
|
772
|
-
* Used when building the Dynamic auth JWT cookie string so the attribute is
|
|
773
|
-
* applied consistently on both the write (sign-in/refresh) and clear (logout)
|
|
774
|
-
* paths.
|
|
775
|
-
*
|
|
776
|
-
* @notInstrumented
|
|
777
|
-
*/
|
|
778
|
-
const getSecureCookieAttribute = () => {
|
|
779
|
-
return Boolean(globalThis.window?.isSecureContext) || globalThis.location?.protocol === "https:" ? "; Secure" : "";
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
//#endregion
|
|
783
|
-
//#region src/utils/setCookie/setCookie.ts
|
|
784
|
-
/**
|
|
785
|
-
* Sefelly sets the cookie in the browser.
|
|
786
|
-
* @notInstrumented
|
|
787
|
-
*/
|
|
788
|
-
const setCookie = (cookie) => {
|
|
789
|
-
document.cookie = cookie;
|
|
805
|
+
return createBaseApiClient({
|
|
806
|
+
middleware: [createDeviceSignatureHeadersMiddleware(client)],
|
|
807
|
+
options
|
|
808
|
+
}, client);
|
|
790
809
|
};
|
|
791
810
|
|
|
792
811
|
//#endregion
|
|
@@ -1996,7 +2015,7 @@ const logoutWithReason = async ({ reason }, client) => {
|
|
|
1996
2015
|
core.logger.debug("[logoutWithReason] Logging out...", { reason });
|
|
1997
2016
|
await destroyWalletProviders({ reason }, client);
|
|
1998
2017
|
if (client.user !== null) {
|
|
1999
|
-
const apiClient = createApiClient({}, client);
|
|
2018
|
+
const apiClient = createApiClient({ headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } }, client);
|
|
2000
2019
|
try {
|
|
2001
2020
|
await apiClient.revokeSession({ environmentId: core.environmentId });
|
|
2002
2021
|
} catch (error) {
|
|
@@ -2040,11 +2059,6 @@ const __logoutWithReason_wrapped = instrumentFunction({
|
|
|
2040
2059
|
}
|
|
2041
2060
|
});
|
|
2042
2061
|
|
|
2043
|
-
//#endregion
|
|
2044
|
-
//#region src/constants.ts
|
|
2045
|
-
const SDK_API_CORE_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
2046
|
-
const DYNAMIC_ICONIC_SPRITE_URL = "https://iconic.dynamic-static-assets.com/icons/sprite.svg";
|
|
2047
|
-
|
|
2048
2062
|
//#endregion
|
|
2049
2063
|
//#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
|
|
2050
2064
|
/**
|
|
@@ -2384,12 +2398,6 @@ Object.defineProperty(exports, 'DYNAMIC_ICONIC_SPRITE_URL', {
|
|
|
2384
2398
|
return DYNAMIC_ICONIC_SPRITE_URL;
|
|
2385
2399
|
}
|
|
2386
2400
|
});
|
|
2387
|
-
Object.defineProperty(exports, 'DYNAMIC_SDK_API_VERSION', {
|
|
2388
|
-
enumerable: true,
|
|
2389
|
-
get: function () {
|
|
2390
|
-
return DYNAMIC_SDK_API_VERSION;
|
|
2391
|
-
}
|
|
2392
|
-
});
|
|
2393
2401
|
Object.defineProperty(exports, 'DYNAMIC_WAAS_METADATA', {
|
|
2394
2402
|
enumerable: true,
|
|
2395
2403
|
get: function () {
|
|
@@ -2804,4 +2812,4 @@ Object.defineProperty(exports, 'version', {
|
|
|
2804
2812
|
return version;
|
|
2805
2813
|
}
|
|
2806
2814
|
});
|
|
2807
|
-
//# sourceMappingURL=updateAuthFromVerifyResponse-
|
|
2815
|
+
//# sourceMappingURL=updateAuthFromVerifyResponse-ChnvPY0m.cjs.map
|