@dynamic-labs-sdk/legacy-embedded-wallet-upgrade 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.
Files changed (36) hide show
  1. package/dist/errors/UpgradePopupBlockedError.d.ts +5 -0
  2. package/dist/errors/UpgradePopupBlockedError.d.ts.map +1 -0
  3. package/dist/errors/UpgradePopupClosedError.d.ts +5 -0
  4. package/dist/errors/UpgradePopupClosedError.d.ts.map +1 -0
  5. package/dist/exports/index.d.ts +2 -0
  6. package/dist/exports/index.d.ts.map +1 -1
  7. package/dist/exports/react.d.ts +1 -0
  8. package/dist/exports/react.d.ts.map +1 -1
  9. package/dist/index.cjs +11 -10
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.esm.js +2 -2
  12. package/dist/index.esm.js.map +1 -1
  13. package/dist/index.native.esm.js +109 -3
  14. package/dist/index.native.esm.js.map +1 -1
  15. package/dist/openUpgradePopup/index.d.ts +3 -0
  16. package/dist/openUpgradePopup/index.d.ts.map +1 -0
  17. package/dist/openUpgradePopup/openUpgradePopup.d.ts +40 -0
  18. package/dist/openUpgradePopup/openUpgradePopup.d.ts.map +1 -0
  19. package/dist/openUpgradePopup/openUpgradePopup.types.d.ts +44 -0
  20. package/dist/openUpgradePopup/openUpgradePopup.types.d.ts.map +1 -0
  21. package/dist/{subscribeToUpgradeCompletion-CfKOBwip.cjs → openUpgradePopup-C_vOjG3Q.cjs} +114 -2
  22. package/dist/openUpgradePopup-C_vOjG3Q.cjs.map +1 -0
  23. package/dist/{subscribeToUpgradeCompletion-D7xhWUn8.esm.js → openUpgradePopup-DQcEdgY_.esm.js} +110 -4
  24. package/dist/openUpgradePopup-DQcEdgY_.esm.js.map +1 -0
  25. package/dist/react/useUpgradePopup/index.d.ts +2 -0
  26. package/dist/react/useUpgradePopup/index.d.ts.map +1 -0
  27. package/dist/react/useUpgradePopup/useUpgradePopup.d.ts +93 -0
  28. package/dist/react/useUpgradePopup/useUpgradePopup.d.ts.map +1 -0
  29. package/dist/react.cjs +102 -8
  30. package/dist/react.cjs.map +1 -1
  31. package/dist/react.esm.js +96 -3
  32. package/dist/react.esm.js.map +1 -1
  33. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  34. package/package.json +6 -6
  35. package/dist/subscribeToUpgradeCompletion-CfKOBwip.cjs.map +0 -1
  36. package/dist/subscribeToUpgradeCompletion-D7xhWUn8.esm.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '@dynamic-labs-sdk/client';
2
+ export declare class UpgradePopupBlockedError extends BaseError {
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=UpgradePopupBlockedError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UpgradePopupBlockedError.d.ts","sourceRoot":"","sources":["../../src/errors/UpgradePopupBlockedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,qBAAa,wBAAyB,SAAQ,SAAS;;CAWtD"}
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '@dynamic-labs-sdk/client';
2
+ export declare class UpgradePopupClosedError extends BaseError {
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=UpgradePopupClosedError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UpgradePopupClosedError.d.ts","sourceRoot":"","sources":["../../src/errors/UpgradePopupClosedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,qBAAa,uBAAwB,SAAQ,SAAS;;CAUrD"}
@@ -6,5 +6,7 @@ export { consumeUpgradeRedirect, type ConsumeUpgradeRedirectParams, } from '../c
6
6
  export { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';
7
7
  export { openUpgradeIframe } from '../openUpgradeIframe';
8
8
  export type { UpgradeIframeSession } from '../openUpgradeIframe';
9
+ export { openUpgradePopup } from '../openUpgradePopup';
10
+ export type { UpgradePopupSession } from '../openUpgradePopup';
9
11
  export type { WalletUpgradeOutcome, WalletUpgradeStatus, } from '../upgradeAppContract';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EACL,sBAAsB,EACtB,KAAK,4BAA4B,GAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EACL,sBAAsB,EACtB,KAAK,4BAA4B,GAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC"}
@@ -2,4 +2,5 @@ export { useWalletsRequiringUpgrade } from '../react/useWalletsRequiringUpgrade'
2
2
  export { useHasWalletsRequiringUpgrade } from '../react/useHasWalletsRequiringUpgrade';
3
3
  export { useUpgradeRedirectResult, type UseUpgradeRedirectResultParams, } from '../react/useUpgradeRedirectResult';
4
4
  export { useUpgradeIframe, type UseUpgradeIframeParams, type UseUpgradeIframeResult, } from '../react/useUpgradeIframe';
5
+ export { useUpgradePopup, type UseUpgradePopupParams, type UseUpgradePopupResult, } from '../react/useUpgradePopup';
5
6
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/exports/react.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EACL,wBAAwB,EACxB,KAAK,8BAA8B,GACpC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/exports/react.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EACL,wBAAwB,EACxB,KAAK,8BAA8B,GACpC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_subscribeToUpgradeCompletion = require('./subscribeToUpgradeCompletion-CfKOBwip.cjs');
1
+ const require_openUpgradePopup = require('./openUpgradePopup-C_vOjG3Q.cjs');
2
2
  let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
3
3
  let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
4
4
  let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
@@ -24,7 +24,7 @@ let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
24
24
  * @see getWalletsRequiringUpgrade
25
25
  * @see startUpgradeRedirect
26
26
  */
27
- const hasWalletsRequiringUpgrade = (client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => require_subscribeToUpgradeCompletion.getWalletsRequiringUpgrade(client).length > 0;
27
+ const hasWalletsRequiringUpgrade = (client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => require_openUpgradePopup.getWalletsRequiringUpgrade(client).length > 0;
28
28
 
29
29
  //#endregion
30
30
  //#region src/startUpgradeRedirect/startUpgradeRedirect.ts
@@ -51,7 +51,7 @@ const hasWalletsRequiringUpgrade = (client = (0, _dynamic_labs_sdk_client.getDef
51
51
  * @see consumeUpgradeRedirect
52
52
  * @see buildUpgradeUrl
53
53
  */
54
- const startUpgradeRedirect = async (params = {}, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => (0, _dynamic_labs_sdk_client_core.getCore)(client).navigate(require_subscribeToUpgradeCompletion.buildUpgradeUrl(params, client));
54
+ const startUpgradeRedirect = async (params = {}, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => (0, _dynamic_labs_sdk_client_core.getCore)(client).navigate(require_openUpgradePopup.buildUpgradeUrl(params, client));
55
55
 
56
56
  //#endregion
57
57
  //#region src/errors/UpgradeIframeClosedError.ts
@@ -102,7 +102,7 @@ const UPGRADE_IFRAME_TITLE = "Dynamic embedded wallet upgrade";
102
102
  */
103
103
  const openUpgradeIframe = ({ container, redirectUrl, baseUrl }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
104
104
  const iframe = document.createElement("iframe");
105
- iframe.src = require_subscribeToUpgradeCompletion.buildUpgradeUrl({
105
+ iframe.src = require_openUpgradePopup.buildUpgradeUrl({
106
106
  baseUrl,
107
107
  redirectUrl
108
108
  }, client);
@@ -117,7 +117,7 @@ const openUpgradeIframe = ({ container, redirectUrl, baseUrl }, client = (0, _dy
117
117
  });
118
118
  completed.catch(() => void 0);
119
119
  let hasReceivedCompletion = false;
120
- const unsubscribe = require_subscribeToUpgradeCompletion.subscribeToUpgradeCompletion({
120
+ const unsubscribe = require_openUpgradePopup.subscribeToUpgradeCompletion({
121
121
  baseUrl,
122
122
  onComplete: (outcome) => resolveCompleted?.(outcome),
123
123
  onReceived: () => {
@@ -138,14 +138,15 @@ const openUpgradeIframe = ({ container, redirectUrl, baseUrl }, client = (0, _dy
138
138
 
139
139
  //#endregion
140
140
  //#region src/exports/index.ts
141
- (0, _dynamic_labs_sdk_assert_package_version.assertPackageVersion)(require_subscribeToUpgradeCompletion.name, require_subscribeToUpgradeCompletion.version);
141
+ (0, _dynamic_labs_sdk_assert_package_version.assertPackageVersion)(require_openUpgradePopup.name, require_openUpgradePopup.version);
142
142
 
143
143
  //#endregion
144
- exports.buildUpgradeUrl = require_subscribeToUpgradeCompletion.buildUpgradeUrl;
145
- exports.consumeUpgradeRedirect = require_subscribeToUpgradeCompletion.consumeUpgradeRedirect;
146
- exports.getWalletsRequiringUpgrade = require_subscribeToUpgradeCompletion.getWalletsRequiringUpgrade;
144
+ exports.buildUpgradeUrl = require_openUpgradePopup.buildUpgradeUrl;
145
+ exports.consumeUpgradeRedirect = require_openUpgradePopup.consumeUpgradeRedirect;
146
+ exports.getWalletsRequiringUpgrade = require_openUpgradePopup.getWalletsRequiringUpgrade;
147
147
  exports.hasWalletsRequiringUpgrade = hasWalletsRequiringUpgrade;
148
148
  exports.openUpgradeIframe = openUpgradeIframe;
149
+ exports.openUpgradePopup = require_openUpgradePopup.openUpgradePopup;
149
150
  exports.startUpgradeRedirect = startUpgradeRedirect;
150
- exports.subscribeToUpgradeCompletion = require_subscribeToUpgradeCompletion.subscribeToUpgradeCompletion;
151
+ exports.subscribeToUpgradeCompletion = require_openUpgradePopup.subscribeToUpgradeCompletion;
151
152
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["getWalletsRequiringUpgrade","buildUpgradeUrl","BaseError","buildUpgradeUrl","resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined","rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined","subscribeToUpgradeCompletion","packageName","packageVersion"],"sources":["../src/hasWalletsRequiringUpgrade/hasWalletsRequiringUpgrade.ts","../src/startUpgradeRedirect/startUpgradeRedirect.ts","../src/errors/UpgradeIframeClosedError.ts","../src/openUpgradeIframe/openUpgradeIframe.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\n\n/**\n * Returns whether the current session has any legacy Dynamic embedded wallet\n * that requires an upgrade to Dynamic WaaS.\n *\n * A boolean convenience over {@link getWalletsRequiringUpgrade} for the common\n * case where you only need to decide whether to surface the upgrade flow (e.g.\n * show a banner or gate a wallet's actions) rather than act on the specific\n * accounts.\n *\n * @example\n * ```ts\n * if (hasWalletsRequiringUpgrade()) {\n * showUpgradeToWaasBanner();\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True when at least one wallet account requires an upgrade to Dynamic WaaS, false otherwise.\n * @see getWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const hasWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): boolean => getWalletsRequiringUpgrade(client).length > 0;\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\n\ntype StartUpgradeRedirectParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to on completion. Defaults to\n * the current page (`window.location.href`), so the outcome can be picked up\n * by {@link consumeUpgradeRedirect} when the user lands back.\n */\n redirectUrl?: string;\n};\n\n/**\n * Starts the redirect upgrade path by navigating the top-level window to the\n * hosted upgrade app.\n *\n * Call this from an \"Upgrade\" button. The upgrade app runs full-page and, once\n * finished, returns the user to `redirectUrl` with the outcome encoded in the\n * URL — call {@link consumeUpgradeRedirect} on load to pick it up. The\n * environment id and return URL are derived from the client and current page,\n * so the common call is zero-arg.\n *\n * @example\n * ```ts\n * // on the \"Upgrade via redirect\" button\n * await startUpgradeRedirect();\n * ```\n * @param [params] - Options for the redirect.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves once navigation has been initiated.\n * @see consumeUpgradeRedirect\n * @see buildUpgradeUrl\n */\nexport const startUpgradeRedirect = async (\n params: StartUpgradeRedirectParams = {},\n client = getDefaultClient()\n): Promise<void> =>\n getCore(client).navigate(buildUpgradeUrl(params, client));\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradeIframeClosedError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_iframe_closed_error',\n docsUrl: null,\n name: 'UpgradeIframeClosedError',\n shortMessage: 'Upgrade iframe was closed before the upgrade completed',\n });\n }\n}\n","/* eslint-disable no-restricted-globals */\n\nimport { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\nimport { UpgradeIframeClosedError } from '../errors/UpgradeIframeClosedError';\nimport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nimport type { WalletUpgradeOutcome } from '../upgradeAppContract';\nimport type {\n OpenUpgradeIframeParams,\n UpgradeIframeSession,\n} from './openUpgradeIframe.types';\n\nexport type { UpgradeIframeSession } from './openUpgradeIframe.types';\n\n// Permissions the upgrade app needs inside the iframe: clipboard writes plus\n// passkey (WebAuthn) get/create, which the embedded wallet upgrade relies on.\nconst UPGRADE_IFRAME_ALLOW =\n 'clipboard-write; publickey-credentials-get *; publickey-credentials-create *';\n\nconst UPGRADE_IFRAME_TITLE = 'Dynamic embedded wallet upgrade';\n\n/**\n * Runs the embedded upgrade path by mounting the hosted upgrade app in an\n * iframe inside a container you provide.\n *\n * The package renders no UI of its own: pass the element of your modal/sheet\n * and it appends the iframe, wires the origin-checked completion handshake, and\n * refreshes the session on success. `completed` resolves with the outcome once\n * the app reports back; call `close()` when the user dismisses the surface (or\n * after completion) to remove the iframe and detach the listener. Closing\n * before completion rejects `completed` with {@link UpgradeIframeClosedError}\n * so awaiters don't hang — wrap `await session.completed` in try/catch if you\n * allow early dismissal. For React Native or custom mounts, use\n * {@link subscribeToUpgradeCompletion} with {@link buildUpgradeUrl} instead.\n *\n * @example\n * ```ts\n * const session = openUpgradeIframe({ container: sheetBodyEl });\n * const { status } = await session.completed;\n * session.close();\n * ```\n * @param params - Iframe options.\n * @param params.container - Element the upgrade iframe is appended into.\n * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A session handle exposing the `iframe`, a `close` function, and the `completed` promise.\n * @see subscribeToUpgradeCompletion\n * @see buildUpgradeUrl\n */\nexport const openUpgradeIframe = (\n { container, redirectUrl, baseUrl }: OpenUpgradeIframeParams,\n client = getDefaultClient()\n): UpgradeIframeSession => {\n const iframe = document.createElement('iframe');\n iframe.src = buildUpgradeUrl({ baseUrl, redirectUrl }, client);\n iframe.title = UPGRADE_IFRAME_TITLE;\n iframe.setAttribute('allow', UPGRADE_IFRAME_ALLOW);\n\n container.appendChild(iframe);\n\n // Executor runs synchronously, so both settlers are assigned before the\n // subscription below (or `close`) can ever fire.\n let resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined;\n let rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined;\n const completed = new Promise<WalletUpgradeOutcome>((resolve, reject) => {\n resolveCompleted = resolve;\n rejectCompleted = reject;\n });\n\n // Callers may use `close()` purely for teardown and never await `completed`.\n // Attach a no-op catch so an early-close rejection is treated as handled\n // globally (no unhandled-rejection noise); a caller that does await\n // `completed` still receives the rejection in its own context.\n completed.catch(() => undefined);\n\n // Set the instant a valid completion message arrives — before the async\n // session refresh resolves `completed` via `onComplete`. `close()` checks\n // this so dismissing the surface during that refresh window does not reject a\n // promise for an upgrade that already succeeded.\n let hasReceivedCompletion = false;\n\n const unsubscribe = subscribeToUpgradeCompletion(\n {\n baseUrl,\n onComplete: (outcome) => resolveCompleted?.(outcome),\n onReceived: () => {\n hasReceivedCompletion = true;\n },\n },\n client\n );\n\n const close = () => {\n unsubscribe();\n iframe.remove();\n // Reject `completed` only as a genuine cancellation — i.e. no completion\n // has been received yet — so anything awaiting it doesn't hang forever. If\n // a completion already arrived, `onComplete` (after the refresh) resolves\n // `completed` with the real outcome, so we must not reject here.\n if (!hasReceivedCompletion) {\n rejectCompleted?.(new UpgradeIframeClosedError());\n }\n };\n\n return { close, completed, iframe };\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\n\nassertPackageVersion(packageName, packageVersion);\n\nexport { buildUpgradeUrl } from '../buildUpgradeUrl';\nexport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\nexport { hasWalletsRequiringUpgrade } from '../hasWalletsRequiringUpgrade';\nexport { startUpgradeRedirect } from '../startUpgradeRedirect';\nexport {\n consumeUpgradeRedirect,\n type ConsumeUpgradeRedirectParams,\n} from '../consumeUpgradeRedirect';\nexport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nexport { openUpgradeIframe } from '../openUpgradeIframe';\nexport type { UpgradeIframeSession } from '../openUpgradeIframe';\nexport type {\n WalletUpgradeOutcome,\n WalletUpgradeStatus,\n} from '../upgradeAppContract';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,8BACX,yDAA2B,KACfA,gEAA2B,OAAO,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgB1D,MAAa,uBAAuB,OAClC,SAAqC,EAAE,EACvC,yDAA2B,gDAEnB,OAAO,CAAC,SAASC,qDAAgB,QAAQ,OAAO,CAAC;;;;AC5C3D,IAAa,2BAAb,cAA8CC,mCAAU;CACtD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc;GACf,CAAC;;;;;;ACON,MAAM,uBACJ;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B7B,MAAa,qBACX,EAAE,WAAW,aAAa,WAC1B,yDAA2B,KACF;CACzB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,QAAO,MAAMC,qDAAgB;EAAE;EAAS;EAAa,EAAE,OAAO;AAC9D,QAAO,QAAQ;AACf,QAAO,aAAa,SAAS,qBAAqB;AAElD,WAAU,YAAY,OAAO;CAI7B,IAAIC;CACJ,IAAIC;CACJ,MAAM,YAAY,IAAI,SAA+B,SAAS,WAAW;AACvE,qBAAmB;AACnB,oBAAkB;GAClB;AAMF,WAAU,YAAY,OAAU;CAMhC,IAAI,wBAAwB;CAE5B,MAAM,cAAcC,kEAClB;EACE;EACA,aAAa,YAAY,mBAAmB,QAAQ;EACpD,kBAAkB;AAChB,2BAAwB;;EAE3B,EACD,OACD;CAED,MAAM,cAAc;AAClB,eAAa;AACb,SAAO,QAAQ;AAKf,MAAI,CAAC,sBACH,mBAAkB,IAAI,0BAA0B,CAAC;;AAIrD,QAAO;EAAE;EAAO;EAAW;EAAQ;;;;;mECnGhBC,2CAAaC,6CAAe"}
1
+ {"version":3,"file":"index.cjs","names":["getWalletsRequiringUpgrade","buildUpgradeUrl","BaseError","buildUpgradeUrl","resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined","rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined","subscribeToUpgradeCompletion","packageName","packageVersion"],"sources":["../src/hasWalletsRequiringUpgrade/hasWalletsRequiringUpgrade.ts","../src/startUpgradeRedirect/startUpgradeRedirect.ts","../src/errors/UpgradeIframeClosedError.ts","../src/openUpgradeIframe/openUpgradeIframe.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\n\n/**\n * Returns whether the current session has any legacy Dynamic embedded wallet\n * that requires an upgrade to Dynamic WaaS.\n *\n * A boolean convenience over {@link getWalletsRequiringUpgrade} for the common\n * case where you only need to decide whether to surface the upgrade flow (e.g.\n * show a banner or gate a wallet's actions) rather than act on the specific\n * accounts.\n *\n * @example\n * ```ts\n * if (hasWalletsRequiringUpgrade()) {\n * showUpgradeToWaasBanner();\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True when at least one wallet account requires an upgrade to Dynamic WaaS, false otherwise.\n * @see getWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const hasWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): boolean => getWalletsRequiringUpgrade(client).length > 0;\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\n\ntype StartUpgradeRedirectParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to on completion. Defaults to\n * the current page (`window.location.href`), so the outcome can be picked up\n * by {@link consumeUpgradeRedirect} when the user lands back.\n */\n redirectUrl?: string;\n};\n\n/**\n * Starts the redirect upgrade path by navigating the top-level window to the\n * hosted upgrade app.\n *\n * Call this from an \"Upgrade\" button. The upgrade app runs full-page and, once\n * finished, returns the user to `redirectUrl` with the outcome encoded in the\n * URL — call {@link consumeUpgradeRedirect} on load to pick it up. The\n * environment id and return URL are derived from the client and current page,\n * so the common call is zero-arg.\n *\n * @example\n * ```ts\n * // on the \"Upgrade via redirect\" button\n * await startUpgradeRedirect();\n * ```\n * @param [params] - Options for the redirect.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves once navigation has been initiated.\n * @see consumeUpgradeRedirect\n * @see buildUpgradeUrl\n */\nexport const startUpgradeRedirect = async (\n params: StartUpgradeRedirectParams = {},\n client = getDefaultClient()\n): Promise<void> =>\n getCore(client).navigate(buildUpgradeUrl(params, client));\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradeIframeClosedError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_iframe_closed_error',\n docsUrl: null,\n name: 'UpgradeIframeClosedError',\n shortMessage: 'Upgrade iframe was closed before the upgrade completed',\n });\n }\n}\n","/* eslint-disable no-restricted-globals */\n\nimport { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\nimport { UpgradeIframeClosedError } from '../errors/UpgradeIframeClosedError';\nimport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nimport type { WalletUpgradeOutcome } from '../upgradeAppContract';\nimport type {\n OpenUpgradeIframeParams,\n UpgradeIframeSession,\n} from './openUpgradeIframe.types';\n\nexport type { UpgradeIframeSession } from './openUpgradeIframe.types';\n\n// Permissions the upgrade app needs inside the iframe: clipboard writes plus\n// passkey (WebAuthn) get/create, which the embedded wallet upgrade relies on.\nconst UPGRADE_IFRAME_ALLOW =\n 'clipboard-write; publickey-credentials-get *; publickey-credentials-create *';\n\nconst UPGRADE_IFRAME_TITLE = 'Dynamic embedded wallet upgrade';\n\n/**\n * Runs the embedded upgrade path by mounting the hosted upgrade app in an\n * iframe inside a container you provide.\n *\n * The package renders no UI of its own: pass the element of your modal/sheet\n * and it appends the iframe, wires the origin-checked completion handshake, and\n * refreshes the session on success. `completed` resolves with the outcome once\n * the app reports back; call `close()` when the user dismisses the surface (or\n * after completion) to remove the iframe and detach the listener. Closing\n * before completion rejects `completed` with {@link UpgradeIframeClosedError}\n * so awaiters don't hang — wrap `await session.completed` in try/catch if you\n * allow early dismissal. For React Native or custom mounts, use\n * {@link subscribeToUpgradeCompletion} with {@link buildUpgradeUrl} instead.\n *\n * @example\n * ```ts\n * const session = openUpgradeIframe({ container: sheetBodyEl });\n * const { status } = await session.completed;\n * session.close();\n * ```\n * @param params - Iframe options.\n * @param params.container - Element the upgrade iframe is appended into.\n * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A session handle exposing the `iframe`, a `close` function, and the `completed` promise.\n * @see subscribeToUpgradeCompletion\n * @see buildUpgradeUrl\n */\nexport const openUpgradeIframe = (\n { container, redirectUrl, baseUrl }: OpenUpgradeIframeParams,\n client = getDefaultClient()\n): UpgradeIframeSession => {\n const iframe = document.createElement('iframe');\n iframe.src = buildUpgradeUrl({ baseUrl, redirectUrl }, client);\n iframe.title = UPGRADE_IFRAME_TITLE;\n iframe.setAttribute('allow', UPGRADE_IFRAME_ALLOW);\n\n container.appendChild(iframe);\n\n // Executor runs synchronously, so both settlers are assigned before the\n // subscription below (or `close`) can ever fire.\n let resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined;\n let rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined;\n const completed = new Promise<WalletUpgradeOutcome>((resolve, reject) => {\n resolveCompleted = resolve;\n rejectCompleted = reject;\n });\n\n // Callers may use `close()` purely for teardown and never await `completed`.\n // Attach a no-op catch so an early-close rejection is treated as handled\n // globally (no unhandled-rejection noise); a caller that does await\n // `completed` still receives the rejection in its own context.\n completed.catch(() => undefined);\n\n // Set the instant a valid completion message arrives — before the async\n // session refresh resolves `completed` via `onComplete`. `close()` checks\n // this so dismissing the surface during that refresh window does not reject a\n // promise for an upgrade that already succeeded.\n let hasReceivedCompletion = false;\n\n const unsubscribe = subscribeToUpgradeCompletion(\n {\n baseUrl,\n onComplete: (outcome) => resolveCompleted?.(outcome),\n onReceived: () => {\n hasReceivedCompletion = true;\n },\n },\n client\n );\n\n const close = () => {\n unsubscribe();\n iframe.remove();\n // Reject `completed` only as a genuine cancellation — i.e. no completion\n // has been received yet — so anything awaiting it doesn't hang forever. If\n // a completion already arrived, `onComplete` (after the refresh) resolves\n // `completed` with the real outcome, so we must not reject here.\n if (!hasReceivedCompletion) {\n rejectCompleted?.(new UpgradeIframeClosedError());\n }\n };\n\n return { close, completed, iframe };\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\n\nassertPackageVersion(packageName, packageVersion);\n\nexport { buildUpgradeUrl } from '../buildUpgradeUrl';\nexport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\nexport { hasWalletsRequiringUpgrade } from '../hasWalletsRequiringUpgrade';\nexport { startUpgradeRedirect } from '../startUpgradeRedirect';\nexport {\n consumeUpgradeRedirect,\n type ConsumeUpgradeRedirectParams,\n} from '../consumeUpgradeRedirect';\nexport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nexport { openUpgradeIframe } from '../openUpgradeIframe';\nexport type { UpgradeIframeSession } from '../openUpgradeIframe';\nexport { openUpgradePopup } from '../openUpgradePopup';\nexport type { UpgradePopupSession } from '../openUpgradePopup';\nexport type {\n WalletUpgradeOutcome,\n WalletUpgradeStatus,\n} from '../upgradeAppContract';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,8BACX,yDAA2B,KACfA,oDAA2B,OAAO,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgB1D,MAAa,uBAAuB,OAClC,SAAqC,EAAE,EACvC,yDAA2B,gDAEnB,OAAO,CAAC,SAASC,yCAAgB,QAAQ,OAAO,CAAC;;;;AC5C3D,IAAa,2BAAb,cAA8CC,mCAAU;CACtD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc;GACf,CAAC;;;;;;ACON,MAAM,uBACJ;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B7B,MAAa,qBACX,EAAE,WAAW,aAAa,WAC1B,yDAA2B,KACF;CACzB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,QAAO,MAAMC,yCAAgB;EAAE;EAAS;EAAa,EAAE,OAAO;AAC9D,QAAO,QAAQ;AACf,QAAO,aAAa,SAAS,qBAAqB;AAElD,WAAU,YAAY,OAAO;CAI7B,IAAIC;CACJ,IAAIC;CACJ,MAAM,YAAY,IAAI,SAA+B,SAAS,WAAW;AACvE,qBAAmB;AACnB,oBAAkB;GAClB;AAMF,WAAU,YAAY,OAAU;CAMhC,IAAI,wBAAwB;CAE5B,MAAM,cAAcC,sDAClB;EACE;EACA,aAAa,YAAY,mBAAmB,QAAQ;EACpD,kBAAkB;AAChB,2BAAwB;;EAE3B,EACD,OACD;CAED,MAAM,cAAc;AAClB,eAAa;AACb,SAAO,QAAQ;AAKf,MAAI,CAAC,sBACH,mBAAkB,IAAI,0BAA0B,CAAC;;AAIrD,QAAO;EAAE;EAAO;EAAW;EAAQ;;;;;mECnGhBC,+BAAaC,iCAAe"}
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as buildUpgradeUrl, n as consumeUpgradeRedirect, o as name, r as getWalletsRequiringUpgrade, s as version, t as subscribeToUpgradeCompletion } from "./subscribeToUpgradeCompletion-D7xhWUn8.esm.js";
1
+ import { a as buildUpgradeUrl, c as version, i as getWalletsRequiringUpgrade, n as subscribeToUpgradeCompletion, r as consumeUpgradeRedirect, s as name, t as openUpgradePopup } from "./openUpgradePopup-DQcEdgY_.esm.js";
2
2
  import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
3
3
  import { BaseError, getDefaultClient } from "@dynamic-labs-sdk/client";
4
4
  import { getCore } from "@dynamic-labs-sdk/client/core";
@@ -141,5 +141,5 @@ const openUpgradeIframe = ({ container, redirectUrl, baseUrl }, client = getDefa
141
141
  assertPackageVersion(name, version);
142
142
 
143
143
  //#endregion
144
- export { buildUpgradeUrl, consumeUpgradeRedirect, getWalletsRequiringUpgrade, hasWalletsRequiringUpgrade, openUpgradeIframe, startUpgradeRedirect, subscribeToUpgradeCompletion };
144
+ export { buildUpgradeUrl, consumeUpgradeRedirect, getWalletsRequiringUpgrade, hasWalletsRequiringUpgrade, openUpgradeIframe, openUpgradePopup, startUpgradeRedirect, subscribeToUpgradeCompletion };
145
145
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","names":["resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined","rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined","packageName","packageVersion"],"sources":["../src/hasWalletsRequiringUpgrade/hasWalletsRequiringUpgrade.ts","../src/startUpgradeRedirect/startUpgradeRedirect.ts","../src/errors/UpgradeIframeClosedError.ts","../src/openUpgradeIframe/openUpgradeIframe.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\n\n/**\n * Returns whether the current session has any legacy Dynamic embedded wallet\n * that requires an upgrade to Dynamic WaaS.\n *\n * A boolean convenience over {@link getWalletsRequiringUpgrade} for the common\n * case where you only need to decide whether to surface the upgrade flow (e.g.\n * show a banner or gate a wallet's actions) rather than act on the specific\n * accounts.\n *\n * @example\n * ```ts\n * if (hasWalletsRequiringUpgrade()) {\n * showUpgradeToWaasBanner();\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True when at least one wallet account requires an upgrade to Dynamic WaaS, false otherwise.\n * @see getWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const hasWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): boolean => getWalletsRequiringUpgrade(client).length > 0;\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\n\ntype StartUpgradeRedirectParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to on completion. Defaults to\n * the current page (`window.location.href`), so the outcome can be picked up\n * by {@link consumeUpgradeRedirect} when the user lands back.\n */\n redirectUrl?: string;\n};\n\n/**\n * Starts the redirect upgrade path by navigating the top-level window to the\n * hosted upgrade app.\n *\n * Call this from an \"Upgrade\" button. The upgrade app runs full-page and, once\n * finished, returns the user to `redirectUrl` with the outcome encoded in the\n * URL — call {@link consumeUpgradeRedirect} on load to pick it up. The\n * environment id and return URL are derived from the client and current page,\n * so the common call is zero-arg.\n *\n * @example\n * ```ts\n * // on the \"Upgrade via redirect\" button\n * await startUpgradeRedirect();\n * ```\n * @param [params] - Options for the redirect.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves once navigation has been initiated.\n * @see consumeUpgradeRedirect\n * @see buildUpgradeUrl\n */\nexport const startUpgradeRedirect = async (\n params: StartUpgradeRedirectParams = {},\n client = getDefaultClient()\n): Promise<void> =>\n getCore(client).navigate(buildUpgradeUrl(params, client));\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradeIframeClosedError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_iframe_closed_error',\n docsUrl: null,\n name: 'UpgradeIframeClosedError',\n shortMessage: 'Upgrade iframe was closed before the upgrade completed',\n });\n }\n}\n","/* eslint-disable no-restricted-globals */\n\nimport { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\nimport { UpgradeIframeClosedError } from '../errors/UpgradeIframeClosedError';\nimport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nimport type { WalletUpgradeOutcome } from '../upgradeAppContract';\nimport type {\n OpenUpgradeIframeParams,\n UpgradeIframeSession,\n} from './openUpgradeIframe.types';\n\nexport type { UpgradeIframeSession } from './openUpgradeIframe.types';\n\n// Permissions the upgrade app needs inside the iframe: clipboard writes plus\n// passkey (WebAuthn) get/create, which the embedded wallet upgrade relies on.\nconst UPGRADE_IFRAME_ALLOW =\n 'clipboard-write; publickey-credentials-get *; publickey-credentials-create *';\n\nconst UPGRADE_IFRAME_TITLE = 'Dynamic embedded wallet upgrade';\n\n/**\n * Runs the embedded upgrade path by mounting the hosted upgrade app in an\n * iframe inside a container you provide.\n *\n * The package renders no UI of its own: pass the element of your modal/sheet\n * and it appends the iframe, wires the origin-checked completion handshake, and\n * refreshes the session on success. `completed` resolves with the outcome once\n * the app reports back; call `close()` when the user dismisses the surface (or\n * after completion) to remove the iframe and detach the listener. Closing\n * before completion rejects `completed` with {@link UpgradeIframeClosedError}\n * so awaiters don't hang — wrap `await session.completed` in try/catch if you\n * allow early dismissal. For React Native or custom mounts, use\n * {@link subscribeToUpgradeCompletion} with {@link buildUpgradeUrl} instead.\n *\n * @example\n * ```ts\n * const session = openUpgradeIframe({ container: sheetBodyEl });\n * const { status } = await session.completed;\n * session.close();\n * ```\n * @param params - Iframe options.\n * @param params.container - Element the upgrade iframe is appended into.\n * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A session handle exposing the `iframe`, a `close` function, and the `completed` promise.\n * @see subscribeToUpgradeCompletion\n * @see buildUpgradeUrl\n */\nexport const openUpgradeIframe = (\n { container, redirectUrl, baseUrl }: OpenUpgradeIframeParams,\n client = getDefaultClient()\n): UpgradeIframeSession => {\n const iframe = document.createElement('iframe');\n iframe.src = buildUpgradeUrl({ baseUrl, redirectUrl }, client);\n iframe.title = UPGRADE_IFRAME_TITLE;\n iframe.setAttribute('allow', UPGRADE_IFRAME_ALLOW);\n\n container.appendChild(iframe);\n\n // Executor runs synchronously, so both settlers are assigned before the\n // subscription below (or `close`) can ever fire.\n let resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined;\n let rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined;\n const completed = new Promise<WalletUpgradeOutcome>((resolve, reject) => {\n resolveCompleted = resolve;\n rejectCompleted = reject;\n });\n\n // Callers may use `close()` purely for teardown and never await `completed`.\n // Attach a no-op catch so an early-close rejection is treated as handled\n // globally (no unhandled-rejection noise); a caller that does await\n // `completed` still receives the rejection in its own context.\n completed.catch(() => undefined);\n\n // Set the instant a valid completion message arrives — before the async\n // session refresh resolves `completed` via `onComplete`. `close()` checks\n // this so dismissing the surface during that refresh window does not reject a\n // promise for an upgrade that already succeeded.\n let hasReceivedCompletion = false;\n\n const unsubscribe = subscribeToUpgradeCompletion(\n {\n baseUrl,\n onComplete: (outcome) => resolveCompleted?.(outcome),\n onReceived: () => {\n hasReceivedCompletion = true;\n },\n },\n client\n );\n\n const close = () => {\n unsubscribe();\n iframe.remove();\n // Reject `completed` only as a genuine cancellation — i.e. no completion\n // has been received yet — so anything awaiting it doesn't hang forever. If\n // a completion already arrived, `onComplete` (after the refresh) resolves\n // `completed` with the real outcome, so we must not reject here.\n if (!hasReceivedCompletion) {\n rejectCompleted?.(new UpgradeIframeClosedError());\n }\n };\n\n return { close, completed, iframe };\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\n\nassertPackageVersion(packageName, packageVersion);\n\nexport { buildUpgradeUrl } from '../buildUpgradeUrl';\nexport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\nexport { hasWalletsRequiringUpgrade } from '../hasWalletsRequiringUpgrade';\nexport { startUpgradeRedirect } from '../startUpgradeRedirect';\nexport {\n consumeUpgradeRedirect,\n type ConsumeUpgradeRedirectParams,\n} from '../consumeUpgradeRedirect';\nexport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nexport { openUpgradeIframe } from '../openUpgradeIframe';\nexport type { UpgradeIframeSession } from '../openUpgradeIframe';\nexport type {\n WalletUpgradeOutcome,\n WalletUpgradeStatus,\n} from '../upgradeAppContract';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,8BACX,SAAS,kBAAkB,KACf,2BAA2B,OAAO,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgB1D,MAAa,uBAAuB,OAClC,SAAqC,EAAE,EACvC,SAAS,kBAAkB,KAE3B,QAAQ,OAAO,CAAC,SAAS,gBAAgB,QAAQ,OAAO,CAAC;;;;AC5C3D,IAAa,2BAAb,cAA8C,UAAU;CACtD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc;GACf,CAAC;;;;;;ACON,MAAM,uBACJ;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B7B,MAAa,qBACX,EAAE,WAAW,aAAa,WAC1B,SAAS,kBAAkB,KACF;CACzB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,QAAO,MAAM,gBAAgB;EAAE;EAAS;EAAa,EAAE,OAAO;AAC9D,QAAO,QAAQ;AACf,QAAO,aAAa,SAAS,qBAAqB;AAElD,WAAU,YAAY,OAAO;CAI7B,IAAIA;CACJ,IAAIC;CACJ,MAAM,YAAY,IAAI,SAA+B,SAAS,WAAW;AACvE,qBAAmB;AACnB,oBAAkB;GAClB;AAMF,WAAU,YAAY,OAAU;CAMhC,IAAI,wBAAwB;CAE5B,MAAM,cAAc,6BAClB;EACE;EACA,aAAa,YAAY,mBAAmB,QAAQ;EACpD,kBAAkB;AAChB,2BAAwB;;EAE3B,EACD,OACD;CAED,MAAM,cAAc;AAClB,eAAa;AACb,SAAO,QAAQ;AAKf,MAAI,CAAC,sBACH,mBAAkB,IAAI,0BAA0B,CAAC;;AAIrD,QAAO;EAAE;EAAO;EAAW;EAAQ;;;;;ACnGrC,qBAAqBC,MAAaC,QAAe"}
1
+ {"version":3,"file":"index.esm.js","names":["resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined","rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined","packageName","packageVersion"],"sources":["../src/hasWalletsRequiringUpgrade/hasWalletsRequiringUpgrade.ts","../src/startUpgradeRedirect/startUpgradeRedirect.ts","../src/errors/UpgradeIframeClosedError.ts","../src/openUpgradeIframe/openUpgradeIframe.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\n\n/**\n * Returns whether the current session has any legacy Dynamic embedded wallet\n * that requires an upgrade to Dynamic WaaS.\n *\n * A boolean convenience over {@link getWalletsRequiringUpgrade} for the common\n * case where you only need to decide whether to surface the upgrade flow (e.g.\n * show a banner or gate a wallet's actions) rather than act on the specific\n * accounts.\n *\n * @example\n * ```ts\n * if (hasWalletsRequiringUpgrade()) {\n * showUpgradeToWaasBanner();\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True when at least one wallet account requires an upgrade to Dynamic WaaS, false otherwise.\n * @see getWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const hasWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): boolean => getWalletsRequiringUpgrade(client).length > 0;\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\n\ntype StartUpgradeRedirectParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to on completion. Defaults to\n * the current page (`window.location.href`), so the outcome can be picked up\n * by {@link consumeUpgradeRedirect} when the user lands back.\n */\n redirectUrl?: string;\n};\n\n/**\n * Starts the redirect upgrade path by navigating the top-level window to the\n * hosted upgrade app.\n *\n * Call this from an \"Upgrade\" button. The upgrade app runs full-page and, once\n * finished, returns the user to `redirectUrl` with the outcome encoded in the\n * URL — call {@link consumeUpgradeRedirect} on load to pick it up. The\n * environment id and return URL are derived from the client and current page,\n * so the common call is zero-arg.\n *\n * @example\n * ```ts\n * // on the \"Upgrade via redirect\" button\n * await startUpgradeRedirect();\n * ```\n * @param [params] - Options for the redirect.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves once navigation has been initiated.\n * @see consumeUpgradeRedirect\n * @see buildUpgradeUrl\n */\nexport const startUpgradeRedirect = async (\n params: StartUpgradeRedirectParams = {},\n client = getDefaultClient()\n): Promise<void> =>\n getCore(client).navigate(buildUpgradeUrl(params, client));\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradeIframeClosedError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_iframe_closed_error',\n docsUrl: null,\n name: 'UpgradeIframeClosedError',\n shortMessage: 'Upgrade iframe was closed before the upgrade completed',\n });\n }\n}\n","/* eslint-disable no-restricted-globals */\n\nimport { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\nimport { UpgradeIframeClosedError } from '../errors/UpgradeIframeClosedError';\nimport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nimport type { WalletUpgradeOutcome } from '../upgradeAppContract';\nimport type {\n OpenUpgradeIframeParams,\n UpgradeIframeSession,\n} from './openUpgradeIframe.types';\n\nexport type { UpgradeIframeSession } from './openUpgradeIframe.types';\n\n// Permissions the upgrade app needs inside the iframe: clipboard writes plus\n// passkey (WebAuthn) get/create, which the embedded wallet upgrade relies on.\nconst UPGRADE_IFRAME_ALLOW =\n 'clipboard-write; publickey-credentials-get *; publickey-credentials-create *';\n\nconst UPGRADE_IFRAME_TITLE = 'Dynamic embedded wallet upgrade';\n\n/**\n * Runs the embedded upgrade path by mounting the hosted upgrade app in an\n * iframe inside a container you provide.\n *\n * The package renders no UI of its own: pass the element of your modal/sheet\n * and it appends the iframe, wires the origin-checked completion handshake, and\n * refreshes the session on success. `completed` resolves with the outcome once\n * the app reports back; call `close()` when the user dismisses the surface (or\n * after completion) to remove the iframe and detach the listener. Closing\n * before completion rejects `completed` with {@link UpgradeIframeClosedError}\n * so awaiters don't hang — wrap `await session.completed` in try/catch if you\n * allow early dismissal. For React Native or custom mounts, use\n * {@link subscribeToUpgradeCompletion} with {@link buildUpgradeUrl} instead.\n *\n * @example\n * ```ts\n * const session = openUpgradeIframe({ container: sheetBodyEl });\n * const { status } = await session.completed;\n * session.close();\n * ```\n * @param params - Iframe options.\n * @param params.container - Element the upgrade iframe is appended into.\n * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A session handle exposing the `iframe`, a `close` function, and the `completed` promise.\n * @see subscribeToUpgradeCompletion\n * @see buildUpgradeUrl\n */\nexport const openUpgradeIframe = (\n { container, redirectUrl, baseUrl }: OpenUpgradeIframeParams,\n client = getDefaultClient()\n): UpgradeIframeSession => {\n const iframe = document.createElement('iframe');\n iframe.src = buildUpgradeUrl({ baseUrl, redirectUrl }, client);\n iframe.title = UPGRADE_IFRAME_TITLE;\n iframe.setAttribute('allow', UPGRADE_IFRAME_ALLOW);\n\n container.appendChild(iframe);\n\n // Executor runs synchronously, so both settlers are assigned before the\n // subscription below (or `close`) can ever fire.\n let resolveCompleted: ((outcome: WalletUpgradeOutcome) => void) | undefined;\n let rejectCompleted: ((reason: UpgradeIframeClosedError) => void) | undefined;\n const completed = new Promise<WalletUpgradeOutcome>((resolve, reject) => {\n resolveCompleted = resolve;\n rejectCompleted = reject;\n });\n\n // Callers may use `close()` purely for teardown and never await `completed`.\n // Attach a no-op catch so an early-close rejection is treated as handled\n // globally (no unhandled-rejection noise); a caller that does await\n // `completed` still receives the rejection in its own context.\n completed.catch(() => undefined);\n\n // Set the instant a valid completion message arrives — before the async\n // session refresh resolves `completed` via `onComplete`. `close()` checks\n // this so dismissing the surface during that refresh window does not reject a\n // promise for an upgrade that already succeeded.\n let hasReceivedCompletion = false;\n\n const unsubscribe = subscribeToUpgradeCompletion(\n {\n baseUrl,\n onComplete: (outcome) => resolveCompleted?.(outcome),\n onReceived: () => {\n hasReceivedCompletion = true;\n },\n },\n client\n );\n\n const close = () => {\n unsubscribe();\n iframe.remove();\n // Reject `completed` only as a genuine cancellation — i.e. no completion\n // has been received yet — so anything awaiting it doesn't hang forever. If\n // a completion already arrived, `onComplete` (after the refresh) resolves\n // `completed` with the real outcome, so we must not reject here.\n if (!hasReceivedCompletion) {\n rejectCompleted?.(new UpgradeIframeClosedError());\n }\n };\n\n return { close, completed, iframe };\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\n\nassertPackageVersion(packageName, packageVersion);\n\nexport { buildUpgradeUrl } from '../buildUpgradeUrl';\nexport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\nexport { hasWalletsRequiringUpgrade } from '../hasWalletsRequiringUpgrade';\nexport { startUpgradeRedirect } from '../startUpgradeRedirect';\nexport {\n consumeUpgradeRedirect,\n type ConsumeUpgradeRedirectParams,\n} from '../consumeUpgradeRedirect';\nexport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nexport { openUpgradeIframe } from '../openUpgradeIframe';\nexport type { UpgradeIframeSession } from '../openUpgradeIframe';\nexport { openUpgradePopup } from '../openUpgradePopup';\nexport type { UpgradePopupSession } from '../openUpgradePopup';\nexport type {\n WalletUpgradeOutcome,\n WalletUpgradeStatus,\n} from '../upgradeAppContract';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,8BACX,SAAS,kBAAkB,KACf,2BAA2B,OAAO,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgB1D,MAAa,uBAAuB,OAClC,SAAqC,EAAE,EACvC,SAAS,kBAAkB,KAE3B,QAAQ,OAAO,CAAC,SAAS,gBAAgB,QAAQ,OAAO,CAAC;;;;AC5C3D,IAAa,2BAAb,cAA8C,UAAU;CACtD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc;GACf,CAAC;;;;;;ACON,MAAM,uBACJ;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B7B,MAAa,qBACX,EAAE,WAAW,aAAa,WAC1B,SAAS,kBAAkB,KACF;CACzB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,QAAO,MAAM,gBAAgB;EAAE;EAAS;EAAa,EAAE,OAAO;AAC9D,QAAO,QAAQ;AACf,QAAO,aAAa,SAAS,qBAAqB;AAElD,WAAU,YAAY,OAAO;CAI7B,IAAIA;CACJ,IAAIC;CACJ,MAAM,YAAY,IAAI,SAA+B,SAAS,WAAW;AACvE,qBAAmB;AACnB,oBAAkB;GAClB;AAMF,WAAU,YAAY,OAAU;CAMhC,IAAI,wBAAwB;CAE5B,MAAM,cAAc,6BAClB;EACE;EACA,aAAa,YAAY,mBAAmB,QAAQ;EACpD,kBAAkB;AAChB,2BAAwB;;EAE3B,EACD,OACD;CAED,MAAM,cAAc;AAClB,eAAa;AACb,SAAO,QAAQ;AAKf,MAAI,CAAC,sBACH,mBAAkB,IAAI,0BAA0B,CAAC;;AAIrD,QAAO;EAAE;EAAO;EAAW;EAAQ;;;;;ACnGrC,qBAAqBC,MAAaC,QAAe"}
@@ -1,10 +1,10 @@
1
1
  import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
2
2
  import { BaseError, UnavailableInServerSideError, getDefaultClient, getWalletAccounts, refreshAuth } from "@dynamic-labs-sdk/client";
3
- import { getCore } from "@dynamic-labs-sdk/client/core";
3
+ import { createDeferredPromise, getCore, isServerSideRendering } from "@dynamic-labs-sdk/client/core";
4
4
 
5
5
  //#region package.json
6
6
  var name = "@dynamic-labs-sdk/legacy-embedded-wallet-upgrade";
7
- var version = "1.22.0";
7
+ var version = "1.23.0";
8
8
 
9
9
  //#endregion
10
10
  //#region src/errors/InvalidUpgradeBaseUrlError.ts
@@ -356,10 +356,116 @@ const openUpgradeIframe = ({ container, redirectUrl, baseUrl }, client = getDefa
356
356
  throw new UpgradeIframeUnavailableInReactNativeError();
357
357
  };
358
358
 
359
+ //#endregion
360
+ //#region src/errors/UpgradePopupBlockedError.ts
361
+ var UpgradePopupBlockedError = class extends BaseError {
362
+ constructor() {
363
+ super({
364
+ cause: null,
365
+ code: "upgrade_popup_blocked_error",
366
+ docsUrl: null,
367
+ name: "UpgradePopupBlockedError",
368
+ shortMessage: "Upgrade popup was blocked by the browser. Call openUpgradePopup directly from a user gesture (e.g. a click handler) so the browser allows the window to open."
369
+ });
370
+ }
371
+ };
372
+
373
+ //#endregion
374
+ //#region src/errors/UpgradePopupClosedError.ts
375
+ var UpgradePopupClosedError = class extends BaseError {
376
+ constructor() {
377
+ super({
378
+ cause: null,
379
+ code: "upgrade_popup_closed_error",
380
+ docsUrl: null,
381
+ name: "UpgradePopupClosedError",
382
+ shortMessage: "Upgrade popup was closed before the upgrade completed"
383
+ });
384
+ }
385
+ };
386
+
387
+ //#endregion
388
+ //#region src/openUpgradePopup/openUpgradePopup.ts
389
+ const UPGRADE_POPUP_TARGET = "dynamic-embedded-wallet-upgrade";
390
+ const DEFAULT_WINDOW_FEATURES = "popup=yes,width=420,height=640";
391
+ const POPUP_CLOSED_POLL_INTERVAL_MS = 500;
392
+ /**
393
+ * Runs the upgrade path in a browser popup window.
394
+ *
395
+ * Opens the hosted upgrade app with `window.open`, wires the same
396
+ * origin-checked completion handshake as {@link openUpgradeIframe}, and
397
+ * refreshes the session on success. `completed` resolves with the outcome once
398
+ * the app reports back; it rejects with {@link UpgradePopupClosedError} if the
399
+ * user closes the popup first. Because popup blockers reject windows opened
400
+ * outside a user gesture, **call this synchronously from a click handler** — do
401
+ * no `await` before it. If the browser blocks the popup (window.open returns
402
+ * `null`), it throws {@link UpgradePopupBlockedError} synchronously.
403
+ *
404
+ * Prefer {@link openUpgradeIframe} when you want the flow embedded in your own
405
+ * modal/sheet; use the popup when a separate window is preferable.
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * // in a click handler — no awaits before openUpgradePopup
410
+ * const session = openUpgradePopup();
411
+ * try {
412
+ * const { status } = await session.completed;
413
+ * } catch (error) {
414
+ * // UpgradePopupClosedError when the user dismissed the popup
415
+ * }
416
+ * ```
417
+ * @param [params] - Popup options.
418
+ * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.
419
+ * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.
420
+ * @param [params.webOptions.popupFeatures] - `window.open` feature string; defaults to a small window.
421
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
422
+ * @returns A session handle exposing a `close` function and the `completed` promise.
423
+ * @throws {UpgradePopupBlockedError} When the browser blocks the popup (`window.open` returns null).
424
+ * @throws {UnavailableInServerSideError} When called during SSR (no window to open from).
425
+ * @see openUpgradeIframe
426
+ * @see subscribeToUpgradeCompletion
427
+ */
428
+ const openUpgradePopup = ({ baseUrl, redirectUrl, webOptions } = {}, client = getDefaultClient()) => {
429
+ if (isServerSideRendering()) throw new UnavailableInServerSideError("openUpgradePopup");
430
+ const url = buildUpgradeUrl({
431
+ baseUrl,
432
+ redirectUrl
433
+ }, client);
434
+ const popup = window.open(url, UPGRADE_POPUP_TARGET, webOptions?.popupFeatures ?? DEFAULT_WINDOW_FEATURES);
435
+ if (popup === null) throw new UpgradePopupBlockedError();
436
+ const completed = createDeferredPromise();
437
+ completed.promise.catch(() => void 0);
438
+ let hasReceivedCompletion = false;
439
+ const poll = {};
440
+ const unsubscribe = subscribeToUpgradeCompletion({
441
+ baseUrl,
442
+ onComplete: (outcome) => {
443
+ completed.resolve(outcome);
444
+ clearInterval(poll.id);
445
+ },
446
+ onReceived: () => {
447
+ hasReceivedCompletion = true;
448
+ }
449
+ }, client);
450
+ const close = () => {
451
+ unsubscribe();
452
+ clearInterval(poll.id);
453
+ if (!popup.closed) popup.close();
454
+ if (!hasReceivedCompletion) completed.reject(new UpgradePopupClosedError());
455
+ };
456
+ poll.id = setInterval(() => {
457
+ if (popup.closed) close();
458
+ }, POPUP_CLOSED_POLL_INTERVAL_MS);
459
+ return {
460
+ close,
461
+ completed: completed.promise
462
+ };
463
+ };
464
+
359
465
  //#endregion
360
466
  //#region src/exports/index.ts
361
467
  assertPackageVersion(name, version);
362
468
 
363
469
  //#endregion
364
- export { buildUpgradeUrl, consumeUpgradeRedirect, getWalletsRequiringUpgrade, hasWalletsRequiringUpgrade, openUpgradeIframe, startUpgradeRedirect, subscribeToUpgradeCompletion };
470
+ export { buildUpgradeUrl, consumeUpgradeRedirect, getWalletsRequiringUpgrade, hasWalletsRequiringUpgrade, openUpgradeIframe, openUpgradePopup, startUpgradeRedirect, subscribeToUpgradeCompletion };
365
471
  //# sourceMappingURL=index.native.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.esm.js","names":["outcome: WalletUpgradeOutcome","packageName","packageVersion"],"sources":["../package.json","../src/errors/InvalidUpgradeBaseUrlError.ts","../src/errors/InvalidUpgradeRedirectUrlError.ts","../src/upgradeAppContract.ts","../src/buildUpgradeUrl/buildUpgradeUrl.ts","../src/walletAccountRequiresUpgrade/walletAccountRequiresUpgrade.ts","../src/getWalletsRequiringUpgrade/getWalletsRequiringUpgrade.ts","../src/hasWalletsRequiringUpgrade/hasWalletsRequiringUpgrade.ts","../src/startUpgradeRedirect/startUpgradeRedirect.ts","../src/consumeUpgradeRedirect/consumeUpgradeRedirect.ts","../src/subscribeToUpgradeCompletion/subscribeToUpgradeCompletion.ts","../src/errors/UpgradeIframeUnavailableInReactNativeError.ts","../src/openUpgradeIframe/openUpgradeIframe.native.ts","../src/exports/index.ts"],"sourcesContent":["","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class InvalidUpgradeBaseUrlError extends BaseError {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(baseUrl: string) {\n super({\n cause: null,\n code: 'invalid_upgrade_base_url_error',\n docsUrl: null,\n name: 'InvalidUpgradeBaseUrlError',\n shortMessage: `Upgrade baseUrl must be an absolute https URL, received: ${baseUrl}`,\n });\n }\n}\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class InvalidUpgradeRedirectUrlError extends BaseError {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(redirectUrl: string) {\n super({\n cause: null,\n code: 'invalid_upgrade_redirect_url_error',\n docsUrl: null,\n name: 'InvalidUpgradeRedirectUrlError',\n shortMessage: `Upgrade redirectUrl must be an absolute https URL, received: ${redirectUrl}`,\n });\n }\n}\n","// Contract shared with the standalone WaaS upgrade app\n// (dynamic-labs-oss/waas-migration). Every identifier below MUST stay\n// byte-for-byte identical to the ones the upgrade app reads/emits in its\n// `migrationConfig.ts`, otherwise the redirect round-trip and the iframe\n// postMessage handshake break silently.\n\n/**\n * Default base URL of the hosted WaaS upgrade app. Both upgrade paths point at\n * this origin and append `environmentId` + `redirectUrl` query params. Callers\n * can override it (e.g. to target a local or preview build during QA) via the\n * `baseUrl` option on the public functions.\n */\nexport const UPGRADE_APP_BASE_URL =\n 'https://waas-migration-dynamic-xyz.vercel.app';\n\n/**\n * Query param the upgrade app requires: which Dynamic environment to\n * authenticate the user against. Derived from the Dynamic client so callers\n * never pass it explicitly.\n */\nexport const UPGRADE_ENVIRONMENT_ID_PARAM = 'environmentId';\n\n/**\n * Query param the upgrade app requires: where to send the user (redirect flow)\n * or which origin it postMessages to (iframe flow) once the upgrade finishes.\n * The upgrade app rejects anything that is not an absolute https URL.\n */\nexport const UPGRADE_REDIRECT_URL_PARAM = 'redirectUrl';\n\n/**\n * postMessage `type` the upgrade app emits to its iframe parent on completion.\n */\nexport const UPGRADE_COMPLETE_MESSAGE_TYPE = 'dynamic-waas-migration:complete';\n\n/**\n * Query param the upgrade app appends to `redirectUrl` when it runs top-level\n * (redirect flow), carrying the outcome back to the app after navigation.\n */\nexport const UPGRADE_STATUS_PARAM = 'dynamicWaasMigrationStatus';\n\n/** Outcome value the upgrade app reports when the upgrade succeeded. */\nexport const UPGRADE_STATUS_SUCCESS = 'success';\n\n/** Outcome value the upgrade app reports when the upgrade failed. */\nexport const UPGRADE_STATUS_ERROR = 'error';\n\n/**\n * The outcome of a legacy embedded wallet upgrade attempt: `success` when the\n * wallet was upgraded to Dynamic WaaS, `error` when it failed. These are the\n * only two values the upgrade app ever reports, on both the redirect and the\n * iframe paths.\n *\n * @example\n * ```ts\n * const isSuccess = (status: WalletUpgradeStatus) => status === 'success';\n * ```\n * @see WalletUpgradeOutcome\n * @see consumeUpgradeRedirect\n */\nexport type WalletUpgradeStatus =\n | typeof UPGRADE_STATUS_SUCCESS\n | typeof UPGRADE_STATUS_ERROR;\n\n/**\n * The resolved result of an upgrade flow, carrying the reported\n * {@link WalletUpgradeStatus}. Returned by the redirect-result consumer and\n * handed to the iframe completion callback so callers can react (toast,\n * refetch, close a sheet, etc.).\n *\n * @example\n * ```ts\n * const onComplete = (outcome: WalletUpgradeOutcome) => {\n * if (outcome.status === 'success') showSuccessToast();\n * };\n * ```\n * @see WalletUpgradeStatus\n * @see subscribeToUpgradeCompletion\n */\nexport type WalletUpgradeOutcome = {\n status: WalletUpgradeStatus;\n};\n\n/**\n * Shape of the completion message the upgrade app posts to its parent window\n * in the iframe flow. Internal to the message handshake — consumers receive the\n * parsed {@link WalletUpgradeOutcome} instead.\n */\nexport type UpgradeCompleteMessage = {\n status: WalletUpgradeStatus;\n type: typeof UPGRADE_COMPLETE_MESSAGE_TYPE;\n};\n","/* eslint-disable no-restricted-globals */\n\nimport {\n UnavailableInServerSideError,\n getDefaultClient,\n} from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { InvalidUpgradeBaseUrlError } from '../errors/InvalidUpgradeBaseUrlError';\nimport { InvalidUpgradeRedirectUrlError } from '../errors/InvalidUpgradeRedirectUrlError';\nimport {\n UPGRADE_APP_BASE_URL,\n UPGRADE_ENVIRONMENT_ID_PARAM,\n UPGRADE_REDIRECT_URL_PARAM,\n} from '../upgradeAppContract';\n\nconst HTTPS_PROTOCOL = 'https:';\n\ntype BuildUpgradeUrlParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to (redirect flow) or\n * postMessages (iframe flow) on completion. Defaults to the current page\n * (`window.location.href`). The upgrade app rejects any non-https URL.\n */\n redirectUrl?: string;\n};\n\n/**\n * Builds the URL that drives the hosted upgrade app for the client's Dynamic\n * environment and a return target.\n *\n * This is the low-level primitive behind every upgrade path: the redirect flow\n * navigates the top-level window to it, the iframe flow loads it as the iframe\n * `src`, and a React Native WebView can load it directly. The environment id is\n * read from the client, and `redirectUrl` defaults to the current page, so the\n * common call is zero-arg. Prefer {@link startUpgradeRedirect} or\n * {@link openUpgradeIframe} unless you are mounting the upgrade app yourself.\n *\n * @example\n * ```ts\n * const src = buildUpgradeUrl();\n * // or target a local upgrade app during QA:\n * const localSrc = buildUpgradeUrl({ baseUrl: 'https://localhost:3000' });\n * ```\n * @param [params] - Options for the generated URL.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The fully-qualified upgrade app URL to load.\n * @throws {InvalidUpgradeRedirectUrlError} When `redirectUrl` is not an absolute https URL.\n * @throws {InvalidUpgradeBaseUrlError} When `baseUrl` is not an absolute https URL.\n * @throws {UnavailableInServerSideError} When called during SSR without an explicit `redirectUrl`.\n * @see startUpgradeRedirect\n * @see openUpgradeIframe\n */\nexport const buildUpgradeUrl = (\n { redirectUrl, baseUrl = UPGRADE_APP_BASE_URL }: BuildUpgradeUrlParams = {},\n client = getDefaultClient()\n): string => {\n // The default return target is the current page, which only exists in the\n // browser; fail loudly during SSR rather than dereferencing an absent window.\n if (redirectUrl === undefined && typeof window === 'undefined') {\n throw new UnavailableInServerSideError('buildUpgradeUrl');\n }\n\n const resolvedRedirectUrl = redirectUrl ?? window.location.href;\n\n // Validate the return target up front: the upgrade app only accepts an\n // absolute https URL, so reject anything else (relative, http, other schemes)\n // here rather than letting it be silently refused after navigation. `new URL`\n // throws on non-absolute input, so the explicit check only guards the scheme.\n const parsedRedirectUrl = new URL(resolvedRedirectUrl);\n\n if (parsedRedirectUrl.protocol !== HTTPS_PROTOCOL) {\n throw new InvalidUpgradeRedirectUrlError(resolvedRedirectUrl);\n }\n\n // Validate the upgrade app origin before we ever load it in an iframe or\n // navigate to it. The default is a trusted https app, but `baseUrl` is an\n // override (custom deployments, forks, local QA), so enforce the https scheme\n // to reject non-secure or dangerous schemes (`http:`, `javascript:`, `data:`)\n // rather than mounting an untrusted origin. Any https host is allowed on\n // purpose — customers self-host the upgrade app on their own domains.\n const url = new URL(baseUrl);\n\n if (url.protocol !== HTTPS_PROTOCOL) {\n throw new InvalidUpgradeBaseUrlError(baseUrl);\n }\n\n const { environmentId } = getCore(client);\n\n url.searchParams.set(UPGRADE_ENVIRONMENT_ID_PARAM, environmentId);\n url.searchParams.set(UPGRADE_REDIRECT_URL_PARAM, resolvedRedirectUrl);\n\n return url.toString();\n};\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\n\n/**\n * Provider-key substring shared by every Dynamic embedded wallet that predates\n * Dynamic WaaS and can therefore be upgraded to it. A wallet account's\n * `walletProviderKey` is a composite backend value (e.g. `<provider>evm` /\n * `<provider>hdsolana` suffixed with `:embeddedWallet`); both the standard and\n * HD variants contain this marker, so matching it as a substring identifies all\n * of them. This is an opaque backend value, matched verbatim — not a user-facing\n * concept.\n */\nconst LEGACY_EMBEDDED_WALLET_PROVIDER_KEY = 'turnkey';\n\n/**\n * Returns whether a wallet account is a legacy Dynamic embedded wallet that\n * requires an upgrade to Dynamic WaaS.\n *\n * Shared predicate behind both the imperative {@link getWalletsRequiringUpgrade}\n * getter and the reactive `useWalletsRequiringUpgrade` hook, so the definition\n * of \"requires upgrade\" lives in exactly one place.\n *\n * @example\n * ```ts\n * const upgradeable = walletAccounts.filter(walletAccountRequiresUpgrade);\n * ```\n * @param walletAccount - The wallet account to test.\n * @returns True when the account is a legacy embedded wallet requiring an upgrade.\n * @see getWalletsRequiringUpgrade\n * @see hasWalletsRequiringUpgrade\n */\nexport const walletAccountRequiresUpgrade = (\n walletAccount: WalletAccount\n): boolean =>\n walletAccount.walletProviderKey.includes(\n LEGACY_EMBEDDED_WALLET_PROVIDER_KEY\n );\n","import {\n type WalletAccount,\n getDefaultClient,\n getWalletAccounts,\n} from '@dynamic-labs-sdk/client';\n\nimport { walletAccountRequiresUpgrade } from '../walletAccountRequiresUpgrade';\n\n/**\n * Returns the current session's wallet accounts that are legacy Dynamic\n * embedded wallets requiring an upgrade to Dynamic WaaS.\n *\n * These are earlier-generation Dynamic embedded wallets that predate Dynamic\n * WaaS (the current TSS-MPC embedded wallet) and can be upgraded to it. Use this\n * when you need the accounts themselves — for example to render only the\n * upgrade entry points on those wallets. Already-upgraded Dynamic WaaS accounts\n * are never returned. For a simple boolean check, use\n * {@link hasWalletsRequiringUpgrade}.\n *\n * @example\n * ```ts\n * const walletsRequiringUpgrade = getWalletsRequiringUpgrade();\n * if (walletsRequiringUpgrade.length > 0) {\n * promptUpgrade(walletsRequiringUpgrade);\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The wallet accounts requiring an upgrade to Dynamic WaaS (empty when none).\n * @see hasWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const getWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): WalletAccount[] =>\n getWalletAccounts(client).filter(walletAccountRequiresUpgrade);\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\n\n/**\n * Returns whether the current session has any legacy Dynamic embedded wallet\n * that requires an upgrade to Dynamic WaaS.\n *\n * A boolean convenience over {@link getWalletsRequiringUpgrade} for the common\n * case where you only need to decide whether to surface the upgrade flow (e.g.\n * show a banner or gate a wallet's actions) rather than act on the specific\n * accounts.\n *\n * @example\n * ```ts\n * if (hasWalletsRequiringUpgrade()) {\n * showUpgradeToWaasBanner();\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True when at least one wallet account requires an upgrade to Dynamic WaaS, false otherwise.\n * @see getWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const hasWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): boolean => getWalletsRequiringUpgrade(client).length > 0;\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\n\ntype StartUpgradeRedirectParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to on completion. Defaults to\n * the current page (`window.location.href`), so the outcome can be picked up\n * by {@link consumeUpgradeRedirect} when the user lands back.\n */\n redirectUrl?: string;\n};\n\n/**\n * Starts the redirect upgrade path by navigating the top-level window to the\n * hosted upgrade app.\n *\n * Call this from an \"Upgrade\" button. The upgrade app runs full-page and, once\n * finished, returns the user to `redirectUrl` with the outcome encoded in the\n * URL — call {@link consumeUpgradeRedirect} on load to pick it up. The\n * environment id and return URL are derived from the client and current page,\n * so the common call is zero-arg.\n *\n * @example\n * ```ts\n * // on the \"Upgrade via redirect\" button\n * await startUpgradeRedirect();\n * ```\n * @param [params] - Options for the redirect.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves once navigation has been initiated.\n * @see consumeUpgradeRedirect\n * @see buildUpgradeUrl\n */\nexport const startUpgradeRedirect = async (\n params: StartUpgradeRedirectParams = {},\n client = getDefaultClient()\n): Promise<void> =>\n getCore(client).navigate(buildUpgradeUrl(params, client));\n","import { getDefaultClient, refreshAuth } from '@dynamic-labs-sdk/client';\n\nimport {\n UPGRADE_STATUS_ERROR,\n UPGRADE_STATUS_PARAM,\n UPGRADE_STATUS_SUCCESS,\n type WalletUpgradeOutcome,\n} from '../upgradeAppContract';\n\n/**\n * Options for {@link consumeUpgradeRedirect}.\n *\n * @example\n * ```ts\n * // Browser: read the outcome from the current page.\n * await consumeUpgradeRedirect({ url: window.location.href });\n * ```\n * @see consumeUpgradeRedirect\n * @see startUpgradeRedirect\n */\nexport type ConsumeUpgradeRedirectParams = {\n /**\n * The return URL to read the upgrade outcome from. Pass the URL yourself so\n * the flow works everywhere: in the browser pass `window.location.href`; in\n * React Native pass the deep-link URL you received. This mirrors how social\n * sign-in and device registration consume their redirects, and keeps the\n * function free of any implicit `window` dependency.\n */\n url: string;\n};\n\n/**\n * Handles the return leg of the redirect upgrade path.\n *\n * The upgrade app sends the user back with the outcome in the\n * `dynamicWaasMigrationStatus` query param. Call this once on app load with the\n * return URL: it reads the param, and when it is present refreshes the session\n * on success (so the upgraded wallet appears). Returns the outcome, or `null`\n * when the URL carries no upgrade result — so callers can drive their own\n * toast/UI.\n *\n * You always pass the URL (`window.location.href` in the browser, the deep-link\n * URL in React Native), matching how social sign-in and device registration\n * consume their redirects. The function never touches browser history, so you\n * own clearing the param from your navigation state once you have the outcome.\n *\n * @example\n * ```ts\n * // Browser\n * const outcome = await consumeUpgradeRedirect({ url: window.location.href });\n * if (outcome?.status === 'error') showRetryToast();\n * ```\n * @example\n * ```ts\n * // React Native: pass the deep-link URL you received.\n * const outcome = await consumeUpgradeRedirect({ url: deepLinkUrl });\n * ```\n * @param params - Options.\n * @param params.url - Return URL to read the outcome from (e.g. `window.location.href`).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise resolving to the upgrade outcome, or `null` when there was no upgrade result to consume.\n * @see startUpgradeRedirect\n * @see subscribeToUpgradeCompletion\n */\nexport const consumeUpgradeRedirect = async (\n { url }: ConsumeUpgradeRedirectParams,\n client = getDefaultClient()\n): Promise<WalletUpgradeOutcome | null> => {\n const status = new URL(url).searchParams.get(UPGRADE_STATUS_PARAM);\n\n // The param is user-controlled, so only ever act on the two values the\n // upgrade app emits and ignore anything else (including tampered values).\n const isKnownStatus =\n status === UPGRADE_STATUS_SUCCESS || status === UPGRADE_STATUS_ERROR;\n\n if (!isKnownStatus) {\n return null;\n }\n\n if (status === UPGRADE_STATUS_SUCCESS) {\n await refreshAuth(client);\n\n return { status: UPGRADE_STATUS_SUCCESS };\n }\n\n return { status: UPGRADE_STATUS_ERROR };\n};\n","/* eslint-disable no-restricted-globals */\n\nimport {\n UnavailableInServerSideError,\n getDefaultClient,\n refreshAuth,\n} from '@dynamic-labs-sdk/client';\n\nimport {\n UPGRADE_APP_BASE_URL,\n UPGRADE_COMPLETE_MESSAGE_TYPE,\n UPGRADE_STATUS_ERROR,\n UPGRADE_STATUS_SUCCESS,\n type UpgradeCompleteMessage,\n type WalletUpgradeOutcome,\n} from '../upgradeAppContract';\n\ntype SubscribeToUpgradeCompletionParams = {\n /**\n * Base URL of the upgrade app the message is expected from. Its origin is\n * used to reject completion messages from any other window. Defaults to the\n * production upgrade app; must match the URL the app is loaded from.\n */\n baseUrl?: string;\n /**\n * Called once with the outcome when the upgrade app reports completion. On\n * success the session has already been refreshed by the time this runs.\n */\n onComplete: (outcome: WalletUpgradeOutcome) => void;\n /**\n * Called synchronously the moment a valid completion message is received,\n * before the (async) success session refresh runs — so `onComplete` still\n * fires after the refresh. Use it to treat the upgrade as already finished\n * (e.g. so dismissing the surface during the refresh is not mistaken for a\n * cancellation, or to show a \"finalizing\" state).\n */\n onReceived?: (outcome: WalletUpgradeOutcome) => void;\n};\n\n// Fully validate the incoming postMessage before acting on it: even though the\n// origin check already gates who can send, the payload shape is still untrusted\n// input, so we verify both the message type AND that `status` is one of the\n// known outcomes rather than trusting whatever `status` string arrives.\nconst isUpgradeCompleteMessage = (\n data: unknown\n): data is UpgradeCompleteMessage =>\n typeof data === 'object' &&\n data !== null &&\n 'type' in data &&\n (data as { type: unknown }).type === UPGRADE_COMPLETE_MESSAGE_TYPE &&\n 'status' in data &&\n ((data as { status: unknown }).status === UPGRADE_STATUS_SUCCESS ||\n (data as { status: unknown }).status === UPGRADE_STATUS_ERROR);\n\n/**\n * Subscribes to the upgrade app's completion signal for an embedded upgrade\n * (iframe or WebView).\n *\n * This is the DOM-agnostic primitive behind {@link openUpgradeIframe}: use it\n * directly when you mount the upgrade app yourself (e.g. a React Native\n * `WebView` or a custom iframe). It listens for the app's origin-checked\n * completion postMessage, refreshes the session on success, then invokes\n * `onComplete` with the outcome. Returns an unsubscribe function that detaches\n * the listener — always call it when your surface unmounts.\n *\n * @example\n * ```ts\n * const unsubscribe = subscribeToUpgradeCompletion({\n * onComplete: ({ status }) => closeSheet(status),\n * });\n * // later, on unmount:\n * unsubscribe();\n * ```\n * @param params - Subscription options.\n * @param params.onComplete - Invoked once with the resolved outcome on completion.\n * @param [params.baseUrl] - Upgrade app base URL whose origin gates messages; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that removes the completion listener.\n * @throws {UnavailableInServerSideError} When called during SSR (no window to listen on).\n * @see openUpgradeIframe\n * @see buildUpgradeUrl\n */\nexport const subscribeToUpgradeCompletion = (\n {\n onComplete,\n onReceived,\n baseUrl = UPGRADE_APP_BASE_URL,\n }: SubscribeToUpgradeCompletionParams,\n client = getDefaultClient()\n): (() => void) => {\n // The completion handshake relies on the browser's postMessage; there is no\n // window to listen on during SSR.\n if (typeof window === 'undefined') {\n throw new UnavailableInServerSideError('subscribeToUpgradeCompletion');\n }\n\n const expectedOrigin = new URL(baseUrl).origin;\n\n const handleMessage = async (event: MessageEvent) => {\n // Ignore messages from any other window so a random page cannot fake an\n // upgrade result.\n if (event.origin !== expectedOrigin) {\n return;\n }\n\n if (!isUpgradeCompleteMessage(event.data)) {\n return;\n }\n\n // Only the first valid completion is honored. Detach synchronously, before\n // the async session refresh, so a duplicate message cannot trigger a second\n // refresh or a second `onComplete` call.\n window.removeEventListener('message', handleMessage);\n\n let outcome: WalletUpgradeOutcome;\n if (event.data.status === UPGRADE_STATUS_SUCCESS) {\n outcome = { status: UPGRADE_STATUS_SUCCESS };\n } else {\n outcome = { status: UPGRADE_STATUS_ERROR };\n }\n\n // Signal receipt synchronously, before the async refresh below, so a\n // consumer can lock in that the upgrade already finished — otherwise a\n // surface dismissed during the refresh window would look like a cancel.\n onReceived?.(outcome);\n\n if (outcome.status === UPGRADE_STATUS_SUCCESS) {\n // The upgrade already succeeded on the backend; refreshing the local\n // session is best-effort. Swallow a refresh failure (it reconciles on the\n // next auth refresh) so completion is always reported — otherwise, since\n // this runs in an event handler with no caller to catch it, a rejected\n // refresh would hang openUpgradeIframe's `completed` promise forever.\n try {\n await refreshAuth(client);\n } catch {\n // ignore: report success anyway, the refresh will reconcile later\n }\n }\n\n onComplete(outcome);\n };\n\n window.addEventListener('message', handleMessage);\n\n return () => window.removeEventListener('message', handleMessage);\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradeIframeUnavailableInReactNativeError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_iframe_unavailable_in_react_native_error',\n docsUrl: null,\n name: 'UpgradeIframeUnavailableInReactNativeError',\n shortMessage:\n 'openUpgradeIframe is not available in React Native — there is no DOM iframe to mount. Use the redirect flow (startUpgradeRedirect / consumeUpgradeRedirect) instead.',\n });\n }\n}\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { UpgradeIframeUnavailableInReactNativeError } from '../errors/UpgradeIframeUnavailableInReactNativeError';\nimport type {\n OpenUpgradeIframeParams,\n UpgradeIframeSession,\n} from './openUpgradeIframe.types';\n\nexport type { UpgradeIframeSession } from './openUpgradeIframe.types';\n\n/**\n * React Native counterpart of {@link openUpgradeIframe} — always throws.\n *\n * The iframe path mounts the hosted upgrade app in a DOM `<iframe>`, which does\n * not exist in React Native. This variant is resolved on React Native so the\n * failure is an explicit, descriptive error at the call site instead of an\n * opaque `document is not defined` crash. Use the redirect flow\n * (`startUpgradeRedirect` / `consumeUpgradeRedirect`) on React Native instead.\n *\n * @example\n * ```ts\n * // On React Native this throws UpgradeIframeUnavailableInReactNativeError.\n * openUpgradeIframe({ container });\n * ```\n * @param params - Iframe options; ignored, since this always throws.\n * @param [client] - The Dynamic client instance; ignored, since this always throws.\n * @returns Never — always throws {@link UpgradeIframeUnavailableInReactNativeError}.\n * @throws UpgradeIframeUnavailableInReactNativeError Always, on React Native.\n */\nexport const openUpgradeIframe = (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- params destructured to match the web signature checked by check-platform-types\n { container, redirectUrl, baseUrl }: OpenUpgradeIframeParams,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- client default required to match the web signature\n client = getDefaultClient()\n): UpgradeIframeSession => {\n throw new UpgradeIframeUnavailableInReactNativeError();\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\n\nassertPackageVersion(packageName, packageVersion);\n\nexport { buildUpgradeUrl } from '../buildUpgradeUrl';\nexport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\nexport { hasWalletsRequiringUpgrade } from '../hasWalletsRequiringUpgrade';\nexport { startUpgradeRedirect } from '../startUpgradeRedirect';\nexport {\n consumeUpgradeRedirect,\n type ConsumeUpgradeRedirectParams,\n} from '../consumeUpgradeRedirect';\nexport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nexport { openUpgradeIframe } from '../openUpgradeIframe';\nexport type { UpgradeIframeSession } from '../openUpgradeIframe';\nexport type {\n WalletUpgradeOutcome,\n WalletUpgradeStatus,\n} from '../upgradeAppContract';\n"],"mappings":";;;;;;;;;;ACEA,IAAa,6BAAb,cAAgD,UAAU;CAExD,YAAY,SAAiB;AAC3B,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc,4DAA4D;GAC3E,CAAC;;;;;;ACTN,IAAa,iCAAb,cAAoD,UAAU;CAE5D,YAAY,aAAqB;AAC/B,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc,gEAAgE;GAC/E,CAAC;;;;;;;;;;;;ACCN,MAAa,uBACX;;;;;;AAOF,MAAa,+BAA+B;;;;;;AAO5C,MAAa,6BAA6B;;;;AAK1C,MAAa,gCAAgC;;;;;AAM7C,MAAa,uBAAuB;;AAGpC,MAAa,yBAAyB;;AAGtC,MAAa,uBAAuB;;;;AC5BpC,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CvB,MAAa,mBACX,EAAE,aAAa,UAAU,yBAAgD,EAAE,EAC3E,SAAS,kBAAkB,KAChB;AAGX,KAAI,gBAAgB,UAAa,OAAO,WAAW,YACjD,OAAM,IAAI,6BAA6B,kBAAkB;CAG3D,MAAM,sBAAsB,eAAe,OAAO,SAAS;AAQ3D,KAF0B,IAAI,IAAI,oBAAoB,CAEhC,aAAa,eACjC,OAAM,IAAI,+BAA+B,oBAAoB;CAS/D,MAAM,MAAM,IAAI,IAAI,QAAQ;AAE5B,KAAI,IAAI,aAAa,eACnB,OAAM,IAAI,2BAA2B,QAAQ;CAG/C,MAAM,EAAE,kBAAkB,QAAQ,OAAO;AAEzC,KAAI,aAAa,IAAI,8BAA8B,cAAc;AACjE,KAAI,aAAa,IAAI,4BAA4B,oBAAoB;AAErE,QAAO,IAAI,UAAU;;;;;;;;;;;;;;ACxFvB,MAAM,sCAAsC;;;;;;;;;;;;;;;;;;AAmB5C,MAAa,gCACX,kBAEA,cAAc,kBAAkB,SAC9B,oCACD;;;;;;;;;;;;;;;;;;;;;;;;;;;ACJH,MAAa,8BACX,SAAS,kBAAkB,KAE3B,kBAAkB,OAAO,CAAC,OAAO,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;ACVhE,MAAa,8BACX,SAAS,kBAAkB,KACf,2BAA2B,OAAO,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgB1D,MAAa,uBAAuB,OAClC,SAAqC,EAAE,EACvC,SAAS,kBAAkB,KAE3B,QAAQ,OAAO,CAAC,SAAS,gBAAgB,QAAQ,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACkB3D,MAAa,yBAAyB,OACpC,EAAE,OACF,SAAS,kBAAkB,KACc;CACzC,MAAM,SAAS,IAAI,IAAI,IAAI,CAAC,aAAa,IAAI,qBAAqB;AAOlE,KAAI,EAFF,WAAW,0BAA0B,WAAW,sBAGhD,QAAO;AAGT,KAAI,WAAW,wBAAwB;AACrC,QAAM,YAAY,OAAO;AAEzB,SAAO,EAAE,QAAQ,wBAAwB;;AAG3C,QAAO,EAAE,QAAQ,sBAAsB;;;;;AC1CzC,MAAM,4BACJ,SAEA,OAAO,SAAS,YAChB,SAAS,QACT,UAAU,QACT,KAA2B,SAAS,iCACrC,YAAY,SACV,KAA6B,WAAW,0BACvC,KAA6B,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B7C,MAAa,gCACX,EACE,YACA,YACA,UAAU,wBAEZ,SAAS,kBAAkB,KACV;AAGjB,KAAI,OAAO,WAAW,YACpB,OAAM,IAAI,6BAA6B,+BAA+B;CAGxE,MAAM,iBAAiB,IAAI,IAAI,QAAQ,CAAC;CAExC,MAAM,gBAAgB,OAAO,UAAwB;AAGnD,MAAI,MAAM,WAAW,eACnB;AAGF,MAAI,CAAC,yBAAyB,MAAM,KAAK,CACvC;AAMF,SAAO,oBAAoB,WAAW,cAAc;EAEpD,IAAIA;AACJ,MAAI,MAAM,KAAK,WAAW,uBACxB,WAAU,EAAE,QAAQ,wBAAwB;MAE5C,WAAU,EAAE,QAAQ,sBAAsB;AAM5C,eAAa,QAAQ;AAErB,MAAI,QAAQ,WAAW,uBAMrB,KAAI;AACF,SAAM,YAAY,OAAO;UACnB;AAKV,aAAW,QAAQ;;AAGrB,QAAO,iBAAiB,WAAW,cAAc;AAEjD,cAAa,OAAO,oBAAoB,WAAW,cAAc;;;;;AC9InE,IAAa,6CAAb,cAAgE,UAAU;CACxE,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cACE;GACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;ACkBN,MAAa,qBAEX,EAAE,WAAW,aAAa,WAE1B,SAAS,kBAAkB,KACF;AACzB,OAAM,IAAI,4CAA4C;;;;;AC5BxD,qBAAqBC,MAAaC,QAAe"}
1
+ {"version":3,"file":"index.native.esm.js","names":["outcome: WalletUpgradeOutcome","poll: { id?: ReturnType<typeof setInterval> }","packageName","packageVersion"],"sources":["../package.json","../src/errors/InvalidUpgradeBaseUrlError.ts","../src/errors/InvalidUpgradeRedirectUrlError.ts","../src/upgradeAppContract.ts","../src/buildUpgradeUrl/buildUpgradeUrl.ts","../src/walletAccountRequiresUpgrade/walletAccountRequiresUpgrade.ts","../src/getWalletsRequiringUpgrade/getWalletsRequiringUpgrade.ts","../src/hasWalletsRequiringUpgrade/hasWalletsRequiringUpgrade.ts","../src/startUpgradeRedirect/startUpgradeRedirect.ts","../src/consumeUpgradeRedirect/consumeUpgradeRedirect.ts","../src/subscribeToUpgradeCompletion/subscribeToUpgradeCompletion.ts","../src/errors/UpgradeIframeUnavailableInReactNativeError.ts","../src/openUpgradeIframe/openUpgradeIframe.native.ts","../src/errors/UpgradePopupBlockedError.ts","../src/errors/UpgradePopupClosedError.ts","../src/openUpgradePopup/openUpgradePopup.ts","../src/exports/index.ts"],"sourcesContent":["","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class InvalidUpgradeBaseUrlError extends BaseError {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(baseUrl: string) {\n super({\n cause: null,\n code: 'invalid_upgrade_base_url_error',\n docsUrl: null,\n name: 'InvalidUpgradeBaseUrlError',\n shortMessage: `Upgrade baseUrl must be an absolute https URL, received: ${baseUrl}`,\n });\n }\n}\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class InvalidUpgradeRedirectUrlError extends BaseError {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(redirectUrl: string) {\n super({\n cause: null,\n code: 'invalid_upgrade_redirect_url_error',\n docsUrl: null,\n name: 'InvalidUpgradeRedirectUrlError',\n shortMessage: `Upgrade redirectUrl must be an absolute https URL, received: ${redirectUrl}`,\n });\n }\n}\n","// Contract shared with the standalone WaaS upgrade app\n// (dynamic-labs-oss/waas-migration). Every identifier below MUST stay\n// byte-for-byte identical to the ones the upgrade app reads/emits in its\n// `migrationConfig.ts`, otherwise the redirect round-trip and the iframe\n// postMessage handshake break silently.\n\n/**\n * Default base URL of the hosted WaaS upgrade app. Both upgrade paths point at\n * this origin and append `environmentId` + `redirectUrl` query params. Callers\n * can override it (e.g. to target a local or preview build during QA) via the\n * `baseUrl` option on the public functions.\n */\nexport const UPGRADE_APP_BASE_URL =\n 'https://waas-migration-dynamic-xyz.vercel.app';\n\n/**\n * Query param the upgrade app requires: which Dynamic environment to\n * authenticate the user against. Derived from the Dynamic client so callers\n * never pass it explicitly.\n */\nexport const UPGRADE_ENVIRONMENT_ID_PARAM = 'environmentId';\n\n/**\n * Query param the upgrade app requires: where to send the user (redirect flow)\n * or which origin it postMessages to (iframe flow) once the upgrade finishes.\n * The upgrade app rejects anything that is not an absolute https URL.\n */\nexport const UPGRADE_REDIRECT_URL_PARAM = 'redirectUrl';\n\n/**\n * postMessage `type` the upgrade app emits to its iframe parent on completion.\n */\nexport const UPGRADE_COMPLETE_MESSAGE_TYPE = 'dynamic-waas-migration:complete';\n\n/**\n * Query param the upgrade app appends to `redirectUrl` when it runs top-level\n * (redirect flow), carrying the outcome back to the app after navigation.\n */\nexport const UPGRADE_STATUS_PARAM = 'dynamicWaasMigrationStatus';\n\n/** Outcome value the upgrade app reports when the upgrade succeeded. */\nexport const UPGRADE_STATUS_SUCCESS = 'success';\n\n/** Outcome value the upgrade app reports when the upgrade failed. */\nexport const UPGRADE_STATUS_ERROR = 'error';\n\n/**\n * The outcome of a legacy embedded wallet upgrade attempt: `success` when the\n * wallet was upgraded to Dynamic WaaS, `error` when it failed. These are the\n * only two values the upgrade app ever reports, on both the redirect and the\n * iframe paths.\n *\n * @example\n * ```ts\n * const isSuccess = (status: WalletUpgradeStatus) => status === 'success';\n * ```\n * @see WalletUpgradeOutcome\n * @see consumeUpgradeRedirect\n */\nexport type WalletUpgradeStatus =\n | typeof UPGRADE_STATUS_SUCCESS\n | typeof UPGRADE_STATUS_ERROR;\n\n/**\n * The resolved result of an upgrade flow, carrying the reported\n * {@link WalletUpgradeStatus}. Returned by the redirect-result consumer and\n * handed to the iframe completion callback so callers can react (toast,\n * refetch, close a sheet, etc.).\n *\n * @example\n * ```ts\n * const onComplete = (outcome: WalletUpgradeOutcome) => {\n * if (outcome.status === 'success') showSuccessToast();\n * };\n * ```\n * @see WalletUpgradeStatus\n * @see subscribeToUpgradeCompletion\n */\nexport type WalletUpgradeOutcome = {\n status: WalletUpgradeStatus;\n};\n\n/**\n * Shape of the completion message the upgrade app posts to its parent window\n * in the iframe flow. Internal to the message handshake — consumers receive the\n * parsed {@link WalletUpgradeOutcome} instead.\n */\nexport type UpgradeCompleteMessage = {\n status: WalletUpgradeStatus;\n type: typeof UPGRADE_COMPLETE_MESSAGE_TYPE;\n};\n","/* eslint-disable no-restricted-globals */\n\nimport {\n UnavailableInServerSideError,\n getDefaultClient,\n} from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { InvalidUpgradeBaseUrlError } from '../errors/InvalidUpgradeBaseUrlError';\nimport { InvalidUpgradeRedirectUrlError } from '../errors/InvalidUpgradeRedirectUrlError';\nimport {\n UPGRADE_APP_BASE_URL,\n UPGRADE_ENVIRONMENT_ID_PARAM,\n UPGRADE_REDIRECT_URL_PARAM,\n} from '../upgradeAppContract';\n\nconst HTTPS_PROTOCOL = 'https:';\n\ntype BuildUpgradeUrlParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to (redirect flow) or\n * postMessages (iframe flow) on completion. Defaults to the current page\n * (`window.location.href`). The upgrade app rejects any non-https URL.\n */\n redirectUrl?: string;\n};\n\n/**\n * Builds the URL that drives the hosted upgrade app for the client's Dynamic\n * environment and a return target.\n *\n * This is the low-level primitive behind every upgrade path: the redirect flow\n * navigates the top-level window to it, the iframe flow loads it as the iframe\n * `src`, and a React Native WebView can load it directly. The environment id is\n * read from the client, and `redirectUrl` defaults to the current page, so the\n * common call is zero-arg. Prefer {@link startUpgradeRedirect} or\n * {@link openUpgradeIframe} unless you are mounting the upgrade app yourself.\n *\n * @example\n * ```ts\n * const src = buildUpgradeUrl();\n * // or target a local upgrade app during QA:\n * const localSrc = buildUpgradeUrl({ baseUrl: 'https://localhost:3000' });\n * ```\n * @param [params] - Options for the generated URL.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The fully-qualified upgrade app URL to load.\n * @throws {InvalidUpgradeRedirectUrlError} When `redirectUrl` is not an absolute https URL.\n * @throws {InvalidUpgradeBaseUrlError} When `baseUrl` is not an absolute https URL.\n * @throws {UnavailableInServerSideError} When called during SSR without an explicit `redirectUrl`.\n * @see startUpgradeRedirect\n * @see openUpgradeIframe\n */\nexport const buildUpgradeUrl = (\n { redirectUrl, baseUrl = UPGRADE_APP_BASE_URL }: BuildUpgradeUrlParams = {},\n client = getDefaultClient()\n): string => {\n // The default return target is the current page, which only exists in the\n // browser; fail loudly during SSR rather than dereferencing an absent window.\n if (redirectUrl === undefined && typeof window === 'undefined') {\n throw new UnavailableInServerSideError('buildUpgradeUrl');\n }\n\n const resolvedRedirectUrl = redirectUrl ?? window.location.href;\n\n // Validate the return target up front: the upgrade app only accepts an\n // absolute https URL, so reject anything else (relative, http, other schemes)\n // here rather than letting it be silently refused after navigation. `new URL`\n // throws on non-absolute input, so the explicit check only guards the scheme.\n const parsedRedirectUrl = new URL(resolvedRedirectUrl);\n\n if (parsedRedirectUrl.protocol !== HTTPS_PROTOCOL) {\n throw new InvalidUpgradeRedirectUrlError(resolvedRedirectUrl);\n }\n\n // Validate the upgrade app origin before we ever load it in an iframe or\n // navigate to it. The default is a trusted https app, but `baseUrl` is an\n // override (custom deployments, forks, local QA), so enforce the https scheme\n // to reject non-secure or dangerous schemes (`http:`, `javascript:`, `data:`)\n // rather than mounting an untrusted origin. Any https host is allowed on\n // purpose — customers self-host the upgrade app on their own domains.\n const url = new URL(baseUrl);\n\n if (url.protocol !== HTTPS_PROTOCOL) {\n throw new InvalidUpgradeBaseUrlError(baseUrl);\n }\n\n const { environmentId } = getCore(client);\n\n url.searchParams.set(UPGRADE_ENVIRONMENT_ID_PARAM, environmentId);\n url.searchParams.set(UPGRADE_REDIRECT_URL_PARAM, resolvedRedirectUrl);\n\n return url.toString();\n};\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\n\n/**\n * Provider-key substring shared by every Dynamic embedded wallet that predates\n * Dynamic WaaS and can therefore be upgraded to it. A wallet account's\n * `walletProviderKey` is a composite backend value (e.g. `<provider>evm` /\n * `<provider>hdsolana` suffixed with `:embeddedWallet`); both the standard and\n * HD variants contain this marker, so matching it as a substring identifies all\n * of them. This is an opaque backend value, matched verbatim — not a user-facing\n * concept.\n */\nconst LEGACY_EMBEDDED_WALLET_PROVIDER_KEY = 'turnkey';\n\n/**\n * Returns whether a wallet account is a legacy Dynamic embedded wallet that\n * requires an upgrade to Dynamic WaaS.\n *\n * Shared predicate behind both the imperative {@link getWalletsRequiringUpgrade}\n * getter and the reactive `useWalletsRequiringUpgrade` hook, so the definition\n * of \"requires upgrade\" lives in exactly one place.\n *\n * @example\n * ```ts\n * const upgradeable = walletAccounts.filter(walletAccountRequiresUpgrade);\n * ```\n * @param walletAccount - The wallet account to test.\n * @returns True when the account is a legacy embedded wallet requiring an upgrade.\n * @see getWalletsRequiringUpgrade\n * @see hasWalletsRequiringUpgrade\n */\nexport const walletAccountRequiresUpgrade = (\n walletAccount: WalletAccount\n): boolean =>\n walletAccount.walletProviderKey.includes(\n LEGACY_EMBEDDED_WALLET_PROVIDER_KEY\n );\n","import {\n type WalletAccount,\n getDefaultClient,\n getWalletAccounts,\n} from '@dynamic-labs-sdk/client';\n\nimport { walletAccountRequiresUpgrade } from '../walletAccountRequiresUpgrade';\n\n/**\n * Returns the current session's wallet accounts that are legacy Dynamic\n * embedded wallets requiring an upgrade to Dynamic WaaS.\n *\n * These are earlier-generation Dynamic embedded wallets that predate Dynamic\n * WaaS (the current TSS-MPC embedded wallet) and can be upgraded to it. Use this\n * when you need the accounts themselves — for example to render only the\n * upgrade entry points on those wallets. Already-upgraded Dynamic WaaS accounts\n * are never returned. For a simple boolean check, use\n * {@link hasWalletsRequiringUpgrade}.\n *\n * @example\n * ```ts\n * const walletsRequiringUpgrade = getWalletsRequiringUpgrade();\n * if (walletsRequiringUpgrade.length > 0) {\n * promptUpgrade(walletsRequiringUpgrade);\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The wallet accounts requiring an upgrade to Dynamic WaaS (empty when none).\n * @see hasWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const getWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): WalletAccount[] =>\n getWalletAccounts(client).filter(walletAccountRequiresUpgrade);\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\n\n/**\n * Returns whether the current session has any legacy Dynamic embedded wallet\n * that requires an upgrade to Dynamic WaaS.\n *\n * A boolean convenience over {@link getWalletsRequiringUpgrade} for the common\n * case where you only need to decide whether to surface the upgrade flow (e.g.\n * show a banner or gate a wallet's actions) rather than act on the specific\n * accounts.\n *\n * @example\n * ```ts\n * if (hasWalletsRequiringUpgrade()) {\n * showUpgradeToWaasBanner();\n * }\n * ```\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True when at least one wallet account requires an upgrade to Dynamic WaaS, false otherwise.\n * @see getWalletsRequiringUpgrade\n * @see startUpgradeRedirect\n */\nexport const hasWalletsRequiringUpgrade = (\n client = getDefaultClient()\n): boolean => getWalletsRequiringUpgrade(client).length > 0;\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\n\ntype StartUpgradeRedirectParams = {\n /**\n * Base URL of the hosted upgrade app. Defaults to the production upgrade app;\n * override it to target a local or preview build (e.g. during QA).\n */\n baseUrl?: string;\n /**\n * Absolute https URL the upgrade app returns to on completion. Defaults to\n * the current page (`window.location.href`), so the outcome can be picked up\n * by {@link consumeUpgradeRedirect} when the user lands back.\n */\n redirectUrl?: string;\n};\n\n/**\n * Starts the redirect upgrade path by navigating the top-level window to the\n * hosted upgrade app.\n *\n * Call this from an \"Upgrade\" button. The upgrade app runs full-page and, once\n * finished, returns the user to `redirectUrl` with the outcome encoded in the\n * URL — call {@link consumeUpgradeRedirect} on load to pick it up. The\n * environment id and return URL are derived from the client and current page,\n * so the common call is zero-arg.\n *\n * @example\n * ```ts\n * // on the \"Upgrade via redirect\" button\n * await startUpgradeRedirect();\n * ```\n * @param [params] - Options for the redirect.\n * @param [params.redirectUrl] - Absolute https return URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves once navigation has been initiated.\n * @see consumeUpgradeRedirect\n * @see buildUpgradeUrl\n */\nexport const startUpgradeRedirect = async (\n params: StartUpgradeRedirectParams = {},\n client = getDefaultClient()\n): Promise<void> =>\n getCore(client).navigate(buildUpgradeUrl(params, client));\n","import { getDefaultClient, refreshAuth } from '@dynamic-labs-sdk/client';\n\nimport {\n UPGRADE_STATUS_ERROR,\n UPGRADE_STATUS_PARAM,\n UPGRADE_STATUS_SUCCESS,\n type WalletUpgradeOutcome,\n} from '../upgradeAppContract';\n\n/**\n * Options for {@link consumeUpgradeRedirect}.\n *\n * @example\n * ```ts\n * // Browser: read the outcome from the current page.\n * await consumeUpgradeRedirect({ url: window.location.href });\n * ```\n * @see consumeUpgradeRedirect\n * @see startUpgradeRedirect\n */\nexport type ConsumeUpgradeRedirectParams = {\n /**\n * The return URL to read the upgrade outcome from. Pass the URL yourself so\n * the flow works everywhere: in the browser pass `window.location.href`; in\n * React Native pass the deep-link URL you received. This mirrors how social\n * sign-in and device registration consume their redirects, and keeps the\n * function free of any implicit `window` dependency.\n */\n url: string;\n};\n\n/**\n * Handles the return leg of the redirect upgrade path.\n *\n * The upgrade app sends the user back with the outcome in the\n * `dynamicWaasMigrationStatus` query param. Call this once on app load with the\n * return URL: it reads the param, and when it is present refreshes the session\n * on success (so the upgraded wallet appears). Returns the outcome, or `null`\n * when the URL carries no upgrade result — so callers can drive their own\n * toast/UI.\n *\n * You always pass the URL (`window.location.href` in the browser, the deep-link\n * URL in React Native), matching how social sign-in and device registration\n * consume their redirects. The function never touches browser history, so you\n * own clearing the param from your navigation state once you have the outcome.\n *\n * @example\n * ```ts\n * // Browser\n * const outcome = await consumeUpgradeRedirect({ url: window.location.href });\n * if (outcome?.status === 'error') showRetryToast();\n * ```\n * @example\n * ```ts\n * // React Native: pass the deep-link URL you received.\n * const outcome = await consumeUpgradeRedirect({ url: deepLinkUrl });\n * ```\n * @param params - Options.\n * @param params.url - Return URL to read the outcome from (e.g. `window.location.href`).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise resolving to the upgrade outcome, or `null` when there was no upgrade result to consume.\n * @see startUpgradeRedirect\n * @see subscribeToUpgradeCompletion\n */\nexport const consumeUpgradeRedirect = async (\n { url }: ConsumeUpgradeRedirectParams,\n client = getDefaultClient()\n): Promise<WalletUpgradeOutcome | null> => {\n const status = new URL(url).searchParams.get(UPGRADE_STATUS_PARAM);\n\n // The param is user-controlled, so only ever act on the two values the\n // upgrade app emits and ignore anything else (including tampered values).\n const isKnownStatus =\n status === UPGRADE_STATUS_SUCCESS || status === UPGRADE_STATUS_ERROR;\n\n if (!isKnownStatus) {\n return null;\n }\n\n if (status === UPGRADE_STATUS_SUCCESS) {\n await refreshAuth(client);\n\n return { status: UPGRADE_STATUS_SUCCESS };\n }\n\n return { status: UPGRADE_STATUS_ERROR };\n};\n","/* eslint-disable no-restricted-globals */\n\nimport {\n UnavailableInServerSideError,\n getDefaultClient,\n refreshAuth,\n} from '@dynamic-labs-sdk/client';\n\nimport {\n UPGRADE_APP_BASE_URL,\n UPGRADE_COMPLETE_MESSAGE_TYPE,\n UPGRADE_STATUS_ERROR,\n UPGRADE_STATUS_SUCCESS,\n type UpgradeCompleteMessage,\n type WalletUpgradeOutcome,\n} from '../upgradeAppContract';\n\ntype SubscribeToUpgradeCompletionParams = {\n /**\n * Base URL of the upgrade app the message is expected from. Its origin is\n * used to reject completion messages from any other window. Defaults to the\n * production upgrade app; must match the URL the app is loaded from.\n */\n baseUrl?: string;\n /**\n * Called once with the outcome when the upgrade app reports completion. On\n * success the session has already been refreshed by the time this runs.\n */\n onComplete: (outcome: WalletUpgradeOutcome) => void;\n /**\n * Called synchronously the moment a valid completion message is received,\n * before the (async) success session refresh runs — so `onComplete` still\n * fires after the refresh. Use it to treat the upgrade as already finished\n * (e.g. so dismissing the surface during the refresh is not mistaken for a\n * cancellation, or to show a \"finalizing\" state).\n */\n onReceived?: (outcome: WalletUpgradeOutcome) => void;\n};\n\n// Fully validate the incoming postMessage before acting on it: even though the\n// origin check already gates who can send, the payload shape is still untrusted\n// input, so we verify both the message type AND that `status` is one of the\n// known outcomes rather than trusting whatever `status` string arrives.\nconst isUpgradeCompleteMessage = (\n data: unknown\n): data is UpgradeCompleteMessage =>\n typeof data === 'object' &&\n data !== null &&\n 'type' in data &&\n (data as { type: unknown }).type === UPGRADE_COMPLETE_MESSAGE_TYPE &&\n 'status' in data &&\n ((data as { status: unknown }).status === UPGRADE_STATUS_SUCCESS ||\n (data as { status: unknown }).status === UPGRADE_STATUS_ERROR);\n\n/**\n * Subscribes to the upgrade app's completion signal for an embedded upgrade\n * (iframe or WebView).\n *\n * This is the DOM-agnostic primitive behind {@link openUpgradeIframe}: use it\n * directly when you mount the upgrade app yourself (e.g. a React Native\n * `WebView` or a custom iframe). It listens for the app's origin-checked\n * completion postMessage, refreshes the session on success, then invokes\n * `onComplete` with the outcome. Returns an unsubscribe function that detaches\n * the listener — always call it when your surface unmounts.\n *\n * @example\n * ```ts\n * const unsubscribe = subscribeToUpgradeCompletion({\n * onComplete: ({ status }) => closeSheet(status),\n * });\n * // later, on unmount:\n * unsubscribe();\n * ```\n * @param params - Subscription options.\n * @param params.onComplete - Invoked once with the resolved outcome on completion.\n * @param [params.baseUrl] - Upgrade app base URL whose origin gates messages; defaults to the production app.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that removes the completion listener.\n * @throws {UnavailableInServerSideError} When called during SSR (no window to listen on).\n * @see openUpgradeIframe\n * @see buildUpgradeUrl\n */\nexport const subscribeToUpgradeCompletion = (\n {\n onComplete,\n onReceived,\n baseUrl = UPGRADE_APP_BASE_URL,\n }: SubscribeToUpgradeCompletionParams,\n client = getDefaultClient()\n): (() => void) => {\n // The completion handshake relies on the browser's postMessage; there is no\n // window to listen on during SSR.\n if (typeof window === 'undefined') {\n throw new UnavailableInServerSideError('subscribeToUpgradeCompletion');\n }\n\n const expectedOrigin = new URL(baseUrl).origin;\n\n const handleMessage = async (event: MessageEvent) => {\n // Ignore messages from any other window so a random page cannot fake an\n // upgrade result.\n if (event.origin !== expectedOrigin) {\n return;\n }\n\n if (!isUpgradeCompleteMessage(event.data)) {\n return;\n }\n\n // Only the first valid completion is honored. Detach synchronously, before\n // the async session refresh, so a duplicate message cannot trigger a second\n // refresh or a second `onComplete` call.\n window.removeEventListener('message', handleMessage);\n\n let outcome: WalletUpgradeOutcome;\n if (event.data.status === UPGRADE_STATUS_SUCCESS) {\n outcome = { status: UPGRADE_STATUS_SUCCESS };\n } else {\n outcome = { status: UPGRADE_STATUS_ERROR };\n }\n\n // Signal receipt synchronously, before the async refresh below, so a\n // consumer can lock in that the upgrade already finished — otherwise a\n // surface dismissed during the refresh window would look like a cancel.\n onReceived?.(outcome);\n\n if (outcome.status === UPGRADE_STATUS_SUCCESS) {\n // The upgrade already succeeded on the backend; refreshing the local\n // session is best-effort. Swallow a refresh failure (it reconciles on the\n // next auth refresh) so completion is always reported — otherwise, since\n // this runs in an event handler with no caller to catch it, a rejected\n // refresh would hang openUpgradeIframe's `completed` promise forever.\n try {\n await refreshAuth(client);\n } catch {\n // ignore: report success anyway, the refresh will reconcile later\n }\n }\n\n onComplete(outcome);\n };\n\n window.addEventListener('message', handleMessage);\n\n return () => window.removeEventListener('message', handleMessage);\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradeIframeUnavailableInReactNativeError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_iframe_unavailable_in_react_native_error',\n docsUrl: null,\n name: 'UpgradeIframeUnavailableInReactNativeError',\n shortMessage:\n 'openUpgradeIframe is not available in React Native — there is no DOM iframe to mount. Use the redirect flow (startUpgradeRedirect / consumeUpgradeRedirect) instead.',\n });\n }\n}\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\n\nimport { UpgradeIframeUnavailableInReactNativeError } from '../errors/UpgradeIframeUnavailableInReactNativeError';\nimport type {\n OpenUpgradeIframeParams,\n UpgradeIframeSession,\n} from './openUpgradeIframe.types';\n\nexport type { UpgradeIframeSession } from './openUpgradeIframe.types';\n\n/**\n * React Native counterpart of {@link openUpgradeIframe} — always throws.\n *\n * The iframe path mounts the hosted upgrade app in a DOM `<iframe>`, which does\n * not exist in React Native. This variant is resolved on React Native so the\n * failure is an explicit, descriptive error at the call site instead of an\n * opaque `document is not defined` crash. Use the redirect flow\n * (`startUpgradeRedirect` / `consumeUpgradeRedirect`) on React Native instead.\n *\n * @example\n * ```ts\n * // On React Native this throws UpgradeIframeUnavailableInReactNativeError.\n * openUpgradeIframe({ container });\n * ```\n * @param params - Iframe options; ignored, since this always throws.\n * @param [client] - The Dynamic client instance; ignored, since this always throws.\n * @returns Never — always throws {@link UpgradeIframeUnavailableInReactNativeError}.\n * @throws UpgradeIframeUnavailableInReactNativeError Always, on React Native.\n */\nexport const openUpgradeIframe = (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- params destructured to match the web signature checked by check-platform-types\n { container, redirectUrl, baseUrl }: OpenUpgradeIframeParams,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- client default required to match the web signature\n client = getDefaultClient()\n): UpgradeIframeSession => {\n throw new UpgradeIframeUnavailableInReactNativeError();\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradePopupBlockedError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_popup_blocked_error',\n docsUrl: null,\n name: 'UpgradePopupBlockedError',\n shortMessage:\n 'Upgrade popup was blocked by the browser. Call openUpgradePopup directly from a user gesture (e.g. a click handler) so the browser allows the window to open.',\n });\n }\n}\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class UpgradePopupClosedError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'upgrade_popup_closed_error',\n docsUrl: null,\n name: 'UpgradePopupClosedError',\n shortMessage: 'Upgrade popup was closed before the upgrade completed',\n });\n }\n}\n","/* eslint-disable no-restricted-globals */\n\nimport {\n UnavailableInServerSideError,\n getDefaultClient,\n} from '@dynamic-labs-sdk/client';\nimport {\n createDeferredPromise,\n isServerSideRendering,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { buildUpgradeUrl } from '../buildUpgradeUrl';\nimport { UpgradePopupBlockedError } from '../errors/UpgradePopupBlockedError';\nimport { UpgradePopupClosedError } from '../errors/UpgradePopupClosedError';\nimport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nimport type { WalletUpgradeOutcome } from '../upgradeAppContract';\nimport type {\n OpenUpgradePopupParams,\n UpgradePopupSession,\n} from './openUpgradePopup.types';\n\nexport type { UpgradePopupSession } from './openUpgradePopup.types';\n\nconst UPGRADE_POPUP_TARGET = 'dynamic-embedded-wallet-upgrade';\n\n// Small window (browser picks the position); large enough for the upgrade\n// app's passkey prompts.\nconst DEFAULT_WINDOW_FEATURES = 'popup=yes,width=420,height=640';\n\n// A closed popup has no reliable DOM event, so `popup.closed` is polled.\nconst POPUP_CLOSED_POLL_INTERVAL_MS = 500;\n\n/**\n * Runs the upgrade path in a browser popup window.\n *\n * Opens the hosted upgrade app with `window.open`, wires the same\n * origin-checked completion handshake as {@link openUpgradeIframe}, and\n * refreshes the session on success. `completed` resolves with the outcome once\n * the app reports back; it rejects with {@link UpgradePopupClosedError} if the\n * user closes the popup first. Because popup blockers reject windows opened\n * outside a user gesture, **call this synchronously from a click handler** — do\n * no `await` before it. If the browser blocks the popup (window.open returns\n * `null`), it throws {@link UpgradePopupBlockedError} synchronously.\n *\n * Prefer {@link openUpgradeIframe} when you want the flow embedded in your own\n * modal/sheet; use the popup when a separate window is preferable.\n *\n * @example\n * ```ts\n * // in a click handler — no awaits before openUpgradePopup\n * const session = openUpgradePopup();\n * try {\n * const { status } = await session.completed;\n * } catch (error) {\n * // UpgradePopupClosedError when the user dismissed the popup\n * }\n * ```\n * @param [params] - Popup options.\n * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.\n * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.\n * @param [params.webOptions.popupFeatures] - `window.open` feature string; defaults to a small window.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A session handle exposing a `close` function and the `completed` promise.\n * @throws {UpgradePopupBlockedError} When the browser blocks the popup (`window.open` returns null).\n * @throws {UnavailableInServerSideError} When called during SSR (no window to open from).\n * @see openUpgradeIframe\n * @see subscribeToUpgradeCompletion\n */\nexport const openUpgradePopup = (\n { baseUrl, redirectUrl, webOptions }: OpenUpgradePopupParams = {},\n client = getDefaultClient()\n): UpgradePopupSession => {\n // window.open only exists in the browser; fail fast during SSR.\n if (isServerSideRendering()) {\n throw new UnavailableInServerSideError('openUpgradePopup');\n }\n\n const url = buildUpgradeUrl({ baseUrl, redirectUrl }, client);\n\n const popup = window.open(\n url,\n UPGRADE_POPUP_TARGET,\n webOptions?.popupFeatures ?? DEFAULT_WINDOW_FEATURES\n );\n\n // A blocked popup returns null; surface it as an explicit, actionable error\n // rather than a session whose `completed` never settles.\n if (popup === null) {\n throw new UpgradePopupBlockedError();\n }\n\n const completed = createDeferredPromise<WalletUpgradeOutcome>();\n\n // Callers may use `close()` purely for teardown and never await the promise.\n // Attach a no-op catch so an early-close rejection is treated as handled\n // globally (no unhandled-rejection noise); a caller that does await\n // `completed.promise` still receives the rejection in its own context.\n completed.promise.catch(() => undefined);\n\n // Set the instant a valid completion message arrives — before the async\n // session refresh resolves `completed`. The close poll checks this so a popup\n // that closes right after signalling success is not treated as a cancel.\n let hasReceivedCompletion = false;\n\n // Holds the close-poll interval id. A holder object lets `onComplete` (defined\n // before the interval is created) clear the poll once completion arrives,\n // without a forward `let` reference.\n // `ReturnType<typeof setInterval>` (not `window.setInterval`) because the\n // lib includes both \"dom\" and \"@types/node\": DOM returns `number`, Node\n // returns `Timeout`, and the unqualified form is the one both resolve to.\n const poll: { id?: ReturnType<typeof setInterval> } = {};\n\n const unsubscribe = subscribeToUpgradeCompletion(\n {\n baseUrl,\n onComplete: (outcome) => {\n completed.resolve(outcome);\n // The subscription already removed its own message listener on the\n // first completion; just stop the close poll and leave the popup open\n // for the app's own completion screen (the caller closes it).\n clearInterval(poll.id);\n },\n onReceived: () => {\n hasReceivedCompletion = true;\n },\n },\n client\n );\n\n // Detach the listener, stop polling, and close the window. Reject `completed`\n // as a cancellation only when no completion has been received yet, so a popup\n // closed after a successful handshake still resolves with the real outcome.\n const close = () => {\n unsubscribe();\n clearInterval(poll.id);\n if (!popup.closed) {\n popup.close();\n }\n if (!hasReceivedCompletion) {\n completed.reject(new UpgradePopupClosedError());\n }\n };\n\n poll.id = setInterval(() => {\n if (popup.closed) {\n close();\n }\n }, POPUP_CLOSED_POLL_INTERVAL_MS);\n\n return { close, completed: completed.promise };\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\n\nassertPackageVersion(packageName, packageVersion);\n\nexport { buildUpgradeUrl } from '../buildUpgradeUrl';\nexport { getWalletsRequiringUpgrade } from '../getWalletsRequiringUpgrade';\nexport { hasWalletsRequiringUpgrade } from '../hasWalletsRequiringUpgrade';\nexport { startUpgradeRedirect } from '../startUpgradeRedirect';\nexport {\n consumeUpgradeRedirect,\n type ConsumeUpgradeRedirectParams,\n} from '../consumeUpgradeRedirect';\nexport { subscribeToUpgradeCompletion } from '../subscribeToUpgradeCompletion';\nexport { openUpgradeIframe } from '../openUpgradeIframe';\nexport type { UpgradeIframeSession } from '../openUpgradeIframe';\nexport { openUpgradePopup } from '../openUpgradePopup';\nexport type { UpgradePopupSession } from '../openUpgradePopup';\nexport type {\n WalletUpgradeOutcome,\n WalletUpgradeStatus,\n} from '../upgradeAppContract';\n"],"mappings":"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"}
@@ -0,0 +1,3 @@
1
+ export { openUpgradePopup } from './openUpgradePopup';
2
+ export type { UpgradePopupSession } from './openUpgradePopup';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openUpgradePopup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { OpenUpgradePopupParams, UpgradePopupSession } from './openUpgradePopup.types';
2
+ export type { UpgradePopupSession } from './openUpgradePopup.types';
3
+ /**
4
+ * Runs the upgrade path in a browser popup window.
5
+ *
6
+ * Opens the hosted upgrade app with `window.open`, wires the same
7
+ * origin-checked completion handshake as {@link openUpgradeIframe}, and
8
+ * refreshes the session on success. `completed` resolves with the outcome once
9
+ * the app reports back; it rejects with {@link UpgradePopupClosedError} if the
10
+ * user closes the popup first. Because popup blockers reject windows opened
11
+ * outside a user gesture, **call this synchronously from a click handler** — do
12
+ * no `await` before it. If the browser blocks the popup (window.open returns
13
+ * `null`), it throws {@link UpgradePopupBlockedError} synchronously.
14
+ *
15
+ * Prefer {@link openUpgradeIframe} when you want the flow embedded in your own
16
+ * modal/sheet; use the popup when a separate window is preferable.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // in a click handler — no awaits before openUpgradePopup
21
+ * const session = openUpgradePopup();
22
+ * try {
23
+ * const { status } = await session.completed;
24
+ * } catch (error) {
25
+ * // UpgradePopupClosedError when the user dismissed the popup
26
+ * }
27
+ * ```
28
+ * @param [params] - Popup options.
29
+ * @param [params.redirectUrl] - Absolute https completion URL; defaults to `window.location.href`.
30
+ * @param [params.baseUrl] - Upgrade app base URL; defaults to the production app.
31
+ * @param [params.webOptions.popupFeatures] - `window.open` feature string; defaults to a small window.
32
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
33
+ * @returns A session handle exposing a `close` function and the `completed` promise.
34
+ * @throws {UpgradePopupBlockedError} When the browser blocks the popup (`window.open` returns null).
35
+ * @throws {UnavailableInServerSideError} When called during SSR (no window to open from).
36
+ * @see openUpgradeIframe
37
+ * @see subscribeToUpgradeCompletion
38
+ */
39
+ export declare const openUpgradePopup: ({ baseUrl, redirectUrl, webOptions }?: OpenUpgradePopupParams, client?: import("@dynamic-labs-sdk/client").DynamicClient) => UpgradePopupSession;
40
+ //# sourceMappingURL=openUpgradePopup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openUpgradePopup.d.ts","sourceRoot":"","sources":["../../src/openUpgradePopup/openUpgradePopup.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;AAElC,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAWpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,gBAAgB,0CACW,sBAAsB,gEAE3D,mBA+EF,CAAC"}