@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
|
@@ -3,18 +3,7 @@ import * as z from "zod/mini";
|
|
|
3
3
|
|
|
4
4
|
//#region package.json
|
|
5
5
|
var name = "@dynamic-labs-sdk/client";
|
|
6
|
-
var version = "1.
|
|
7
|
-
var dependencies = {
|
|
8
|
-
"@dynamic-labs-sdk/assert-package-version": "workspace:*",
|
|
9
|
-
"@dynamic-labs-wallet/browser-wallet-client": "1.0.79",
|
|
10
|
-
"@dynamic-labs-wallet/forward-mpc-client": "1.0.1",
|
|
11
|
-
"@dynamic-labs/sdk-api-core": "catalog:",
|
|
12
|
-
"@simplewebauthn/browser": "13.1.0",
|
|
13
|
-
"ably": "2.17.1",
|
|
14
|
-
"buffer": "6.0.3",
|
|
15
|
-
"eventemitter3": "5.0.1",
|
|
16
|
-
"zod": "4.0.5"
|
|
17
|
-
};
|
|
6
|
+
var version = "1.23.0";
|
|
18
7
|
|
|
19
8
|
//#endregion
|
|
20
9
|
//#region src/client/core/getCore/getCore.ts
|
|
@@ -138,26 +127,6 @@ const setDefaultClient = (client) => {
|
|
|
138
127
|
const NONCE_POOL_EXPIRATION_TIME = 6e4 * 60 * 24;
|
|
139
128
|
const NONCE_POOL_SIZE = 5;
|
|
140
129
|
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/modules/apiClient/constants.ts
|
|
143
|
-
const DYNAMIC_API_VERSION_HEADER = "x-dyn-api-version";
|
|
144
|
-
const DYNAMIC_REQUEST_ID_HEADER = "x-dyn-request-id";
|
|
145
|
-
const DYNAMIC_SDK_VERSION_HEADER = "x-dyn-version";
|
|
146
|
-
const ELEVATED_ACCESS_TOKEN_HEADER = "x-dyn-elevated-access-token";
|
|
147
|
-
const MFA_TOKEN_HEADER = "x-mfa-auth-token";
|
|
148
|
-
const SESSION_PUBLIC_KEY_HEADER = "x-dyn-session-public-key";
|
|
149
|
-
const DYNAMIC_SDK_API_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
150
|
-
const DYNAMIC_SDK_SESSION_ID_HEADER = "x-dyn-session-id";
|
|
151
|
-
/**
|
|
152
|
-
* Reports the runtime platform (`web` or `react-native`) to the Dynamic API.
|
|
153
|
-
*
|
|
154
|
-
* Named `x-dynamic-platform` (not `x-dyn-*`) to match the header the legacy
|
|
155
|
-
* webview-controller already sends, so the backend receives a consistent
|
|
156
|
-
* platform signal across SDK generations.
|
|
157
|
-
*/
|
|
158
|
-
const DYNAMIC_PLATFORM_HEADER = "x-dynamic-platform";
|
|
159
|
-
const CLIENT_SDK_NAME = "ClientSDK";
|
|
160
|
-
|
|
161
130
|
//#endregion
|
|
162
131
|
//#region src/utils/getPlatform/getPlatform.ts
|
|
163
132
|
/**
|
|
@@ -284,6 +253,41 @@ const getSessionKeys = (client) => {
|
|
|
284
253
|
return { publicKey };
|
|
285
254
|
};
|
|
286
255
|
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/generated/dependencyCatalog.ts
|
|
258
|
+
const dependencyCatalog = { "@dynamic-labs/sdk-api-core": "0.0.1083" };
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/constants.ts
|
|
262
|
+
const SDK_API_CORE_VERSION = dependencyCatalog["@dynamic-labs/sdk-api-core"];
|
|
263
|
+
const DYNAMIC_ICONIC_SPRITE_URL = "https://iconic.dynamic-static-assets.com/icons/sprite.svg";
|
|
264
|
+
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/modules/apiClient/constants.ts
|
|
267
|
+
const DYNAMIC_API_VERSION_HEADER = "x-dyn-api-version";
|
|
268
|
+
const DYNAMIC_REQUEST_ID_HEADER = "x-dyn-request-id";
|
|
269
|
+
const DYNAMIC_SDK_VERSION_HEADER = "x-dyn-version";
|
|
270
|
+
/**
|
|
271
|
+
* Reports *why* the SDK is logging the user out on the `revokeSession`
|
|
272
|
+
* (`/sdk/{env}/revoke`) request. The backend logs it so SDK-initiated session
|
|
273
|
+
* revocations are attributable in Datadog (e.g. `token-expired`,
|
|
274
|
+
* `keychain-key-missing`) instead of being inferred from downstream 401s.
|
|
275
|
+
*/
|
|
276
|
+
const DYNAMIC_LOGOUT_REASON_HEADER = "x-dyn-logout-reason";
|
|
277
|
+
const ELEVATED_ACCESS_TOKEN_HEADER = "x-dyn-elevated-access-token";
|
|
278
|
+
const MFA_TOKEN_HEADER = "x-mfa-auth-token";
|
|
279
|
+
const SESSION_PUBLIC_KEY_HEADER = "x-dyn-session-public-key";
|
|
280
|
+
const DYNAMIC_SDK_SESSION_ID_HEADER = "x-dyn-session-id";
|
|
281
|
+
/**
|
|
282
|
+
* Reports the runtime platform (`web` or `react-native`) to the Dynamic API.
|
|
283
|
+
*
|
|
284
|
+
* Named `x-dynamic-platform` (not `x-dyn-*`) to match the header the legacy
|
|
285
|
+
* webview-controller already sends, so the backend receives a consistent
|
|
286
|
+
* platform signal across SDK generations.
|
|
287
|
+
*/
|
|
288
|
+
const DYNAMIC_PLATFORM_HEADER = "x-dynamic-platform";
|
|
289
|
+
const CLIENT_SDK_NAME = "ClientSDK";
|
|
290
|
+
|
|
287
291
|
//#endregion
|
|
288
292
|
//#region src/errors/APIError/APIError.ts
|
|
289
293
|
var APIError = class APIError extends BaseError {
|
|
@@ -455,6 +459,81 @@ const createConvertToApiErrorMiddleware = ({ errorMappers = [] }) => ({ post: as
|
|
|
455
459
|
return context.response;
|
|
456
460
|
} });
|
|
457
461
|
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/errors/UnauthorizedError.ts
|
|
464
|
+
var UnauthorizedError = class extends BaseError {
|
|
465
|
+
constructor({ cause }) {
|
|
466
|
+
super({
|
|
467
|
+
cause,
|
|
468
|
+
code: "unauthorized_error",
|
|
469
|
+
docsUrl: null,
|
|
470
|
+
name: "UnauthorizedError",
|
|
471
|
+
shortMessage: "Unauthorized"
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
478
|
+
/** @notInstrumented */
|
|
479
|
+
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
480
|
+
if (context.response.status === 401) {
|
|
481
|
+
let cause = null;
|
|
482
|
+
try {
|
|
483
|
+
const errorBody = await context.response.clone().json();
|
|
484
|
+
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
485
|
+
} catch {}
|
|
486
|
+
throw new UnauthorizedError({ cause });
|
|
487
|
+
}
|
|
488
|
+
return context.response;
|
|
489
|
+
} });
|
|
490
|
+
|
|
491
|
+
//#endregion
|
|
492
|
+
//#region src/modules/apiClient/createBaseApiClient.ts
|
|
493
|
+
/**
|
|
494
|
+
* Creates the base SDK API client from the client's core state, applying the
|
|
495
|
+
* standard headers and the always-on error-conversion and unauthorized
|
|
496
|
+
* middleware. Any middleware passed via `middleware` runs before those two.
|
|
497
|
+
* @notInstrumented
|
|
498
|
+
*/
|
|
499
|
+
const createBaseApiClient = ({ middleware = [], options = {} }, client) => {
|
|
500
|
+
const core = getCore(client);
|
|
501
|
+
const coreState = core.state.get();
|
|
502
|
+
const settings = {
|
|
503
|
+
basePath: core.apiBaseUrl,
|
|
504
|
+
headers: {
|
|
505
|
+
"Content-Type": "application/json",
|
|
506
|
+
[DYNAMIC_API_VERSION_HEADER]: `API/${SDK_API_CORE_VERSION}`,
|
|
507
|
+
[DYNAMIC_PLATFORM_HEADER]: getPlatform(),
|
|
508
|
+
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
509
|
+
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
510
|
+
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
511
|
+
...core.getApiHeaders(),
|
|
512
|
+
...options.headers
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
516
|
+
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
517
|
+
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
518
|
+
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
519
|
+
if (options.elevatedAccessTokenScope) {
|
|
520
|
+
const elevatedToken = getElevatedAccessToken({ scope: options.elevatedAccessTokenScope }, client);
|
|
521
|
+
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
522
|
+
}
|
|
523
|
+
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
524
|
+
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
525
|
+
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
526
|
+
return new SDKApi(new Configuration({
|
|
527
|
+
...settings,
|
|
528
|
+
fetchApi: core.fetch,
|
|
529
|
+
middleware: [
|
|
530
|
+
...middleware,
|
|
531
|
+
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
532
|
+
createUnauthorizedMiddleware()
|
|
533
|
+
]
|
|
534
|
+
}));
|
|
535
|
+
};
|
|
536
|
+
|
|
458
537
|
//#endregion
|
|
459
538
|
//#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
|
|
460
539
|
/** @notInstrumented */
|
|
@@ -505,6 +584,85 @@ const updateNoncePoolStorage = async ({ update }, client) => {
|
|
|
505
584
|
return storedBeforeUpdate;
|
|
506
585
|
};
|
|
507
586
|
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
589
|
+
/**
|
|
590
|
+
* Fetches a batch of nonces from the API and appends them to the pool in
|
|
591
|
+
* storage.
|
|
592
|
+
*
|
|
593
|
+
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
594
|
+
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
595
|
+
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
596
|
+
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
597
|
+
* `getNonce` can return from the stored pool without an interrupting network
|
|
598
|
+
* round-trip.
|
|
599
|
+
*
|
|
600
|
+
* New nonces are **appended** to the stored pool so that unconsumed entries
|
|
601
|
+
* are not discarded by a background refetch; an expired stored pool is
|
|
602
|
+
* replaced instead, since its nonces have already been evicted server-side.
|
|
603
|
+
*
|
|
604
|
+
* Concurrent refills are coalesced behind a single in-flight promise so that
|
|
605
|
+
* simultaneous callers share one `GET /nonces` round-trip instead of each
|
|
606
|
+
* issuing their own (which would inflate the pool and hammer the backend).
|
|
607
|
+
* @notInstrumented
|
|
608
|
+
*/
|
|
609
|
+
const fetchAndStoreNonces = async (client) => {
|
|
610
|
+
const core = getCore(client);
|
|
611
|
+
const inFlight = core.state.get().nonceFetchInFlight;
|
|
612
|
+
if (inFlight) return inFlight;
|
|
613
|
+
const { environmentId } = core;
|
|
614
|
+
const apiClient = createBaseApiClient({}, client);
|
|
615
|
+
const fetchPromise = (async () => {
|
|
616
|
+
const { nonces } = await apiClient.getNonces({
|
|
617
|
+
count: NONCE_POOL_SIZE,
|
|
618
|
+
environmentId
|
|
619
|
+
});
|
|
620
|
+
const expiration = Date.now() + NONCE_POOL_EXPIRATION_TIME;
|
|
621
|
+
await updateNoncePoolStorage({ update: (stored) => {
|
|
622
|
+
return {
|
|
623
|
+
expiration,
|
|
624
|
+
nonces: [...stored && stored.expiration > Date.now() ? stored.nonces : [], ...nonces]
|
|
625
|
+
};
|
|
626
|
+
} }, client);
|
|
627
|
+
})().finally(() => {
|
|
628
|
+
core.state.set({ nonceFetchInFlight: null });
|
|
629
|
+
});
|
|
630
|
+
core.state.set({ nonceFetchInFlight: fetchPromise });
|
|
631
|
+
return fetchPromise;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
//#endregion
|
|
635
|
+
//#region src/utils/getSecureCookieAttribute/getSecureCookieAttribute.ts
|
|
636
|
+
/**
|
|
637
|
+
* Returns the cookie `Secure` attribute suffix (`'; Secure'`) when the current
|
|
638
|
+
* document is running in a secure context, or an empty string otherwise.
|
|
639
|
+
*
|
|
640
|
+
* The `Secure` attribute prevents the browser from ever transmitting the cookie
|
|
641
|
+
* over an unencrypted `http://` connection, which mitigates cleartext token
|
|
642
|
+
* capture (CWE-614). It is intentionally omitted on insecure/localhost dev,
|
|
643
|
+
* because browsers reject `Secure` cookies set over `http://` and that would
|
|
644
|
+
* silently break local testing.
|
|
645
|
+
*
|
|
646
|
+
* Used when building the Dynamic auth JWT cookie string so the attribute is
|
|
647
|
+
* applied consistently on both the write (sign-in/refresh) and clear (logout)
|
|
648
|
+
* paths.
|
|
649
|
+
*
|
|
650
|
+
* @notInstrumented
|
|
651
|
+
*/
|
|
652
|
+
const getSecureCookieAttribute = () => {
|
|
653
|
+
return Boolean(globalThis.window?.isSecureContext) || globalThis.location?.protocol === "https:" ? "; Secure" : "";
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region src/utils/setCookie/setCookie.ts
|
|
658
|
+
/**
|
|
659
|
+
* Sefelly sets the cookie in the browser.
|
|
660
|
+
* @notInstrumented
|
|
661
|
+
*/
|
|
662
|
+
const setCookie = (cookie) => {
|
|
663
|
+
document.cookie = cookie;
|
|
664
|
+
};
|
|
665
|
+
|
|
508
666
|
//#endregion
|
|
509
667
|
//#region src/utils/getNonce/getNonce.ts
|
|
510
668
|
/**
|
|
@@ -607,35 +765,6 @@ const createDeviceSignatureHeadersMiddleware = (client) => {
|
|
|
607
765
|
} };
|
|
608
766
|
};
|
|
609
767
|
|
|
610
|
-
//#endregion
|
|
611
|
-
//#region src/errors/UnauthorizedError.ts
|
|
612
|
-
var UnauthorizedError = class extends BaseError {
|
|
613
|
-
constructor({ cause }) {
|
|
614
|
-
super({
|
|
615
|
-
cause,
|
|
616
|
-
code: "unauthorized_error",
|
|
617
|
-
docsUrl: null,
|
|
618
|
-
name: "UnauthorizedError",
|
|
619
|
-
shortMessage: "Unauthorized"
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
626
|
-
/** @notInstrumented */
|
|
627
|
-
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
628
|
-
if (context.response.status === 401) {
|
|
629
|
-
let cause = null;
|
|
630
|
-
try {
|
|
631
|
-
const errorBody = await context.response.clone().json();
|
|
632
|
-
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
633
|
-
} catch {}
|
|
634
|
-
throw new UnauthorizedError({ cause });
|
|
635
|
-
}
|
|
636
|
-
return context.response;
|
|
637
|
-
} });
|
|
638
|
-
|
|
639
768
|
//#endregion
|
|
640
769
|
//#region src/modules/apiClient/createApiClient.ts
|
|
641
770
|
/**
|
|
@@ -645,120 +774,10 @@ const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
|
645
774
|
* @notInstrumented
|
|
646
775
|
*/
|
|
647
776
|
const createApiClient = (options = {}, client) => {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
headers: {
|
|
653
|
-
"Content-Type": "application/json",
|
|
654
|
-
[DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
|
|
655
|
-
[DYNAMIC_PLATFORM_HEADER]: getPlatform(),
|
|
656
|
-
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
657
|
-
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
658
|
-
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
659
|
-
...core.getApiHeaders(),
|
|
660
|
-
...options.headers
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
664
|
-
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
665
|
-
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
666
|
-
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
667
|
-
if (options.elevatedAccessTokenScope) {
|
|
668
|
-
const elevatedToken = getElevatedAccessToken({ scope: options.elevatedAccessTokenScope }, client);
|
|
669
|
-
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
670
|
-
}
|
|
671
|
-
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
672
|
-
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
673
|
-
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
674
|
-
return new SDKApi(new Configuration({
|
|
675
|
-
...settings,
|
|
676
|
-
fetchApi: core.fetch,
|
|
677
|
-
middleware: [
|
|
678
|
-
createDeviceSignatureHeadersMiddleware(client),
|
|
679
|
-
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
680
|
-
createUnauthorizedMiddleware()
|
|
681
|
-
]
|
|
682
|
-
}));
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
//#endregion
|
|
686
|
-
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
687
|
-
/**
|
|
688
|
-
* Fetches a batch of nonces from the API and appends them to the pool in
|
|
689
|
-
* storage.
|
|
690
|
-
*
|
|
691
|
-
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
692
|
-
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
693
|
-
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
694
|
-
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
695
|
-
* `getNonce` can return from the stored pool without an interrupting network
|
|
696
|
-
* round-trip.
|
|
697
|
-
*
|
|
698
|
-
* New nonces are **appended** to the stored pool so that unconsumed entries
|
|
699
|
-
* are not discarded by a background refetch; an expired stored pool is
|
|
700
|
-
* replaced instead, since its nonces have already been evicted server-side.
|
|
701
|
-
*
|
|
702
|
-
* Concurrent refills are coalesced behind a single in-flight promise so that
|
|
703
|
-
* simultaneous callers share one `GET /nonces` round-trip instead of each
|
|
704
|
-
* issuing their own (which would inflate the pool and hammer the backend).
|
|
705
|
-
* @notInstrumented
|
|
706
|
-
*/
|
|
707
|
-
const fetchAndStoreNonces = async (client) => {
|
|
708
|
-
const core = getCore(client);
|
|
709
|
-
const inFlight = core.state.get().nonceFetchInFlight;
|
|
710
|
-
if (inFlight) return inFlight;
|
|
711
|
-
const { environmentId } = core;
|
|
712
|
-
const apiClient = createApiClient({}, client);
|
|
713
|
-
const fetchPromise = (async () => {
|
|
714
|
-
const { nonces } = await apiClient.getNonces({
|
|
715
|
-
count: NONCE_POOL_SIZE,
|
|
716
|
-
environmentId
|
|
717
|
-
});
|
|
718
|
-
const expiration = Date.now() + NONCE_POOL_EXPIRATION_TIME;
|
|
719
|
-
await updateNoncePoolStorage({ update: (stored) => {
|
|
720
|
-
return {
|
|
721
|
-
expiration,
|
|
722
|
-
nonces: [...stored && stored.expiration > Date.now() ? stored.nonces : [], ...nonces]
|
|
723
|
-
};
|
|
724
|
-
} }, client);
|
|
725
|
-
})().finally(() => {
|
|
726
|
-
core.state.set({ nonceFetchInFlight: null });
|
|
727
|
-
});
|
|
728
|
-
core.state.set({ nonceFetchInFlight: fetchPromise });
|
|
729
|
-
return fetchPromise;
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
//#endregion
|
|
733
|
-
//#region src/utils/getSecureCookieAttribute/getSecureCookieAttribute.ts
|
|
734
|
-
/**
|
|
735
|
-
* Returns the cookie `Secure` attribute suffix (`'; Secure'`) when the current
|
|
736
|
-
* document is running in a secure context, or an empty string otherwise.
|
|
737
|
-
*
|
|
738
|
-
* The `Secure` attribute prevents the browser from ever transmitting the cookie
|
|
739
|
-
* over an unencrypted `http://` connection, which mitigates cleartext token
|
|
740
|
-
* capture (CWE-614). It is intentionally omitted on insecure/localhost dev,
|
|
741
|
-
* because browsers reject `Secure` cookies set over `http://` and that would
|
|
742
|
-
* silently break local testing.
|
|
743
|
-
*
|
|
744
|
-
* Used when building the Dynamic auth JWT cookie string so the attribute is
|
|
745
|
-
* applied consistently on both the write (sign-in/refresh) and clear (logout)
|
|
746
|
-
* paths.
|
|
747
|
-
*
|
|
748
|
-
* @notInstrumented
|
|
749
|
-
*/
|
|
750
|
-
const getSecureCookieAttribute = () => {
|
|
751
|
-
return Boolean(globalThis.window?.isSecureContext) || globalThis.location?.protocol === "https:" ? "; Secure" : "";
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
//#endregion
|
|
755
|
-
//#region src/utils/setCookie/setCookie.ts
|
|
756
|
-
/**
|
|
757
|
-
* Sefelly sets the cookie in the browser.
|
|
758
|
-
* @notInstrumented
|
|
759
|
-
*/
|
|
760
|
-
const setCookie = (cookie) => {
|
|
761
|
-
document.cookie = cookie;
|
|
777
|
+
return createBaseApiClient({
|
|
778
|
+
middleware: [createDeviceSignatureHeadersMiddleware(client)],
|
|
779
|
+
options
|
|
780
|
+
}, client);
|
|
762
781
|
};
|
|
763
782
|
|
|
764
783
|
//#endregion
|
|
@@ -1968,7 +1987,7 @@ const logoutWithReason = async ({ reason }, client) => {
|
|
|
1968
1987
|
core.logger.debug("[logoutWithReason] Logging out...", { reason });
|
|
1969
1988
|
await destroyWalletProviders({ reason }, client);
|
|
1970
1989
|
if (client.user !== null) {
|
|
1971
|
-
const apiClient = createApiClient({}, client);
|
|
1990
|
+
const apiClient = createApiClient({ headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } }, client);
|
|
1972
1991
|
try {
|
|
1973
1992
|
await apiClient.revokeSession({ environmentId: core.environmentId });
|
|
1974
1993
|
} catch (error) {
|
|
@@ -2012,11 +2031,6 @@ const __logoutWithReason_wrapped = instrumentFunction({
|
|
|
2012
2031
|
}
|
|
2013
2032
|
});
|
|
2014
2033
|
|
|
2015
|
-
//#endregion
|
|
2016
|
-
//#region src/constants.ts
|
|
2017
|
-
const SDK_API_CORE_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
2018
|
-
const DYNAMIC_ICONIC_SPRITE_URL = "https://iconic.dynamic-static-assets.com/icons/sprite.svg";
|
|
2019
|
-
|
|
2020
2034
|
//#endregion
|
|
2021
2035
|
//#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
|
|
2022
2036
|
/**
|
|
@@ -2302,5 +2316,5 @@ const updateAuthFromVerifyResponse = ({ response }, client) => {
|
|
|
2302
2316
|
};
|
|
2303
2317
|
|
|
2304
2318
|
//#endregion
|
|
2305
|
-
export {
|
|
2306
|
-
//# sourceMappingURL=updateAuthFromVerifyResponse-
|
|
2319
|
+
export { UnauthorizedError as $, isSignedIn as A, retryOnFail as B, getWalletProviderFromWalletAccount as C, version as Ct, NoWalletProviderFoundError as D, createRuntimeServiceAccessKey as E, CHAINS_INFO_MAP as F, createApiClient as G, offEvent as H, formatWalletAccountId as I, getDeviceSigner as J, createDeviceSignatureHeadersMiddleware as K, normalizeAddress as L, formatWalletProviderKey as M, normalizeWalletNameWithChain as N, generateSessionKeys as O, getChainFromVerifiedCredentialChain as P, createStorageKeySchema as Q, splitWalletProviderKey as R, extractSessionId as S, name as St, getWalletProviderRegistry as T, onEvent as U, emitEvent as V, onceEvent as W, fetchAndStoreNonces as X, getNonce as Y, updateNoncePoolStorage as Z, instrumentFunction as _, getDefaultClient as _t, initializeWaasClientsForEagerRecovery as a, APIError as at, getUserAgent as b, BaseError as bt, isWaasWalletProvider as c, SDK_API_CORE_VERSION as ct, DYNAMIC_WAAS_METADATA as d, assertDefined as dt, SandboxMaximumThresholdReachedError as et, getWalletProviders as f, ValueMustBeDefinedError as ft, __logoutWithReason_wrapped as g, NONCE_POOL_SIZE as gt, emitWalletAccountsChangedEvent as h, getPlatform as ht, InvalidParamError as i, InvalidExternalAuthError as it, getWalletAccounts as j, fetchProjectSettings as k, DEFAULT_WAAS_BASE_API_URL as l, getSessionKeys as lt, checkAndRaiseWalletAccountsChangedEvent as m, randomString as mt, upsertElevatedAccessToken as n, MfaInvalidOtpError as nt, isWaasWalletAccount as o, CLIENT_SDK_NAME as ot, isUserMissingMfaAuth as p, getElevatedAccessToken as pt, getHeadersForNonceSignedByDeviceSigners as q, parseElevatedAccessToken as r, LinkCredentialError as rt, findWaasWalletProviderByChain as s, DYNAMIC_ICONIC_SPRITE_URL as st, updateAuthFromVerifyResponse as t, MfaRateLimitedError as tt, DEFAULT_WAAS_BASE_MPC_RELAY_API_URL as u, isCookieEnabled as ut, scrubParameters as v, setDefaultClient as vt, WalletProviderPriority as w, getOperatingSystem as x, getCore as xt, DEFAULT_PII_FIELDS as y, ClientNotFoundError as yt, InvalidWalletProviderKeyError as z };
|
|
2320
|
+
//# sourceMappingURL=updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js.map
|