@dynamic-labs-sdk/client 0.23.3 → 0.24.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 (64) hide show
  1. package/dist/{InvalidParamError-AGSIdKWg.cjs.js → InvalidParamError-BgmShvv_.cjs.js} +9 -5
  2. package/dist/{InvalidParamError-AGSIdKWg.cjs.js.map → InvalidParamError-BgmShvv_.cjs.js.map} +1 -1
  3. package/dist/{InvalidParamError-16q5iBqn.esm.js → InvalidParamError-kLBXFKhe.esm.js} +8 -4
  4. package/dist/{InvalidParamError-16q5iBqn.esm.js.map → InvalidParamError-kLBXFKhe.esm.js.map} +1 -1
  5. package/dist/{NotWaasWalletAccountError-nhXCxVcy.esm.js → NotWaasWalletAccountError-VJL72OTC.esm.js} +3 -3
  6. package/dist/{NotWaasWalletAccountError-nhXCxVcy.esm.js.map → NotWaasWalletAccountError-VJL72OTC.esm.js.map} +1 -1
  7. package/dist/{NotWaasWalletAccountError-BF6AAjX2.cjs.js → NotWaasWalletAccountError-qK9GIBpr.cjs.js} +3 -3
  8. package/dist/{NotWaasWalletAccountError-BF6AAjX2.cjs.js.map → NotWaasWalletAccountError-qK9GIBpr.cjs.js.map} +1 -1
  9. package/dist/core.cjs.js +6 -29
  10. package/dist/core.cjs.js.map +1 -1
  11. package/dist/core.esm.js +5 -28
  12. package/dist/core.esm.js.map +1 -1
  13. package/dist/exports/index.d.ts +3 -0
  14. package/dist/exports/index.d.ts.map +1 -1
  15. package/dist/{getNetworkProviderFromNetworkId-Its21Jgg.cjs.js → getNetworkProviderFromNetworkId-B8OjAdet.cjs.js} +39 -3
  16. package/dist/getNetworkProviderFromNetworkId-B8OjAdet.cjs.js.map +1 -0
  17. package/dist/{getNetworkProviderFromNetworkId-BcIgAfM0.esm.js → getNetworkProviderFromNetworkId-RlnraKJN.esm.js} +28 -4
  18. package/dist/getNetworkProviderFromNetworkId-RlnraKJN.esm.js.map +1 -0
  19. package/dist/{getSignedSessionId-dezYwjyJ.esm.js → getSignedSessionId-CvNFnwt1.esm.js} +3 -3
  20. package/dist/{getSignedSessionId-dezYwjyJ.esm.js.map → getSignedSessionId-CvNFnwt1.esm.js.map} +1 -1
  21. package/dist/{getSignedSessionId-DzWdq-Af.cjs.js → getSignedSessionId-DBQS7lht.cjs.js} +3 -3
  22. package/dist/{getSignedSessionId-DzWdq-Af.cjs.js.map → getSignedSessionId-DBQS7lht.cjs.js.map} +1 -1
  23. package/dist/{getVerifiedCredentialForWalletAccount-BSZiw2I7.esm.js → getVerifiedCredentialForWalletAccount-8VlwTOBc.esm.js} +2 -2
  24. package/dist/{getVerifiedCredentialForWalletAccount-BSZiw2I7.esm.js.map → getVerifiedCredentialForWalletAccount-8VlwTOBc.esm.js.map} +1 -1
  25. package/dist/{getVerifiedCredentialForWalletAccount-CExk0n4h.cjs.js → getVerifiedCredentialForWalletAccount-CBJrrV08.cjs.js} +3 -3
  26. package/dist/{getVerifiedCredentialForWalletAccount-CExk0n4h.cjs.js.map → getVerifiedCredentialForWalletAccount-CBJrrV08.cjs.js.map} +1 -1
  27. package/dist/index.cjs.js +162 -39
  28. package/dist/index.cjs.js.map +1 -1
  29. package/dist/index.esm.js +162 -40
  30. package/dist/index.esm.js.map +1 -1
  31. package/dist/{isMfaRequiredForAction-DSjzrlmn.esm.js → isMfaRequiredForAction-8NlpzYe6.esm.js} +2 -2
  32. package/dist/{isMfaRequiredForAction-DSjzrlmn.esm.js.map → isMfaRequiredForAction-8NlpzYe6.esm.js.map} +1 -1
  33. package/dist/{isMfaRequiredForAction-Drc_xwpq.cjs.js → isMfaRequiredForAction-9NDyQhHS.cjs.js} +2 -2
  34. package/dist/{isMfaRequiredForAction-Drc_xwpq.cjs.js.map → isMfaRequiredForAction-9NDyQhHS.cjs.js.map} +1 -1
  35. package/dist/modules/checkout/createCheckoutTransaction/createCheckoutTransaction.d.ts.map +1 -1
  36. package/dist/modules/checkout/events.d.ts +27 -0
  37. package/dist/modules/checkout/events.d.ts.map +1 -0
  38. package/dist/modules/checkout/trackCheckoutTransaction/index.d.ts +3 -0
  39. package/dist/modules/checkout/trackCheckoutTransaction/index.d.ts.map +1 -0
  40. package/dist/modules/checkout/trackCheckoutTransaction/trackCheckoutTransaction.d.ts +15 -0
  41. package/dist/modules/checkout/trackCheckoutTransaction/trackCheckoutTransaction.d.ts.map +1 -0
  42. package/dist/modules/checkout/utils/createCheckoutTransactionChannelSchema/createCheckoutTransactionChannelSchema.d.ts +28 -0
  43. package/dist/modules/checkout/utils/createCheckoutTransactionChannelSchema/createCheckoutTransactionChannelSchema.d.ts.map +1 -0
  44. package/dist/modules/checkout/utils/createCheckoutTransactionChannelSchema/index.d.ts +3 -0
  45. package/dist/modules/checkout/utils/createCheckoutTransactionChannelSchema/index.d.ts.map +1 -0
  46. package/dist/modules/checkout/utils/subscribeToCheckoutTransaction/index.d.ts +3 -0
  47. package/dist/modules/checkout/utils/subscribeToCheckoutTransaction/index.d.ts.map +1 -0
  48. package/dist/modules/checkout/utils/subscribeToCheckoutTransaction/subscribeToCheckoutTransaction.d.ts +15 -0
  49. package/dist/modules/checkout/utils/subscribeToCheckoutTransaction/subscribeToCheckoutTransaction.d.ts.map +1 -0
  50. package/dist/modules/initializeClient/consts.d.ts +1 -0
  51. package/dist/modules/initializeClient/consts.d.ts.map +1 -1
  52. package/dist/modules/initializeClient/initializeClient.d.ts +1 -1
  53. package/dist/modules/initializeClient/initializeClient.d.ts.map +1 -1
  54. package/dist/modules/user/refreshUser/refreshUser.d.ts +1 -1
  55. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  56. package/dist/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.d.ts +4 -1
  57. package/dist/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.d.ts.map +1 -1
  58. package/dist/waas.cjs.js +4 -4
  59. package/dist/waas.esm.js +3 -3
  60. package/dist/waasCore.cjs.js +4 -4
  61. package/dist/waasCore.esm.js +3 -3
  62. package/package.json +3 -3
  63. package/dist/getNetworkProviderFromNetworkId-BcIgAfM0.esm.js.map +0 -1
  64. package/dist/getNetworkProviderFromNetworkId-Its21Jgg.cjs.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -1,8 +1,8 @@
1
- const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-Its21Jgg.cjs.js');
2
- const require_InvalidParamError = require('./InvalidParamError-AGSIdKWg.cjs.js');
3
- const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-CExk0n4h.cjs.js');
4
- const require_NotWaasWalletAccountError = require('./NotWaasWalletAccountError-BF6AAjX2.cjs.js');
5
- const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-Drc_xwpq.cjs.js');
1
+ const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-B8OjAdet.cjs.js');
2
+ const require_InvalidParamError = require('./InvalidParamError-BgmShvv_.cjs.js');
3
+ const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-CBJrrV08.cjs.js');
4
+ const require_NotWaasWalletAccountError = require('./NotWaasWalletAccountError-qK9GIBpr.cjs.js');
5
+ const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-9NDyQhHS.cjs.js');
6
6
  let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
7
7
  let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
8
8
  let zod_mini = require("zod/mini");
@@ -589,6 +589,40 @@ const initializeStorageSync = async (client) => {
589
589
  syncStateWithStorage(client);
590
590
  };
591
591
 
592
+ //#endregion
593
+ //#region src/modules/user/refreshUser/refreshUser.ts
594
+ /**
595
+ * Refreshes the current user's data from the server.
596
+ *
597
+ * This function fetches the latest authenticated user information from the backend
598
+ * and updates the local user state.
599
+ *
600
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
601
+ * @returns A promise that resolves to the authenticated user.
602
+ * @instrumented
603
+ */
604
+ const refreshUser = async (client = require_InvalidParamError.getDefaultClient()) => {
605
+ const core = require_InvalidParamError.getCore(client);
606
+ const apiClient = require_InvalidParamError.__createApiClient_wrapped({}, client);
607
+ const previousState = { ...core.state.get() };
608
+ const user = await apiClient.getAuthenticatedUser({ environmentId: core.environmentId });
609
+ core.state.set({ user });
610
+ require_getVerifiedCredentialForWalletAccount.checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
611
+ return user;
612
+ };
613
+ const __refreshUser_impl = refreshUser;
614
+ const __refreshUser_wrapped = require_InvalidParamError.instrumentFunction({
615
+ fn: __refreshUser_impl,
616
+ functionName: "refreshUser",
617
+ getCore: () => {
618
+ try {
619
+ return require_InvalidParamError.getCore(require_InvalidParamError.getDefaultClient());
620
+ } catch {
621
+ return;
622
+ }
623
+ }
624
+ });
625
+
592
626
  //#endregion
593
627
  //#region src/errors/ClientAlreadyInitializedError.ts
594
628
  var ClientAlreadyInitializedError = class extends require_InvalidParamError.BaseError {
@@ -675,6 +709,16 @@ const initializeClient = async (client = require_InvalidParamError.getDefaultCli
675
709
  } else throw error;
676
710
  });
677
711
  });
712
+ /**
713
+ * When a token is persisted but the user state was lost (e.g. storage cleared
714
+ * partially), re-fetch the user from the server. This path is skipped when
715
+ * cookies are enabled because the token is not stored in SDK state.
716
+ */
717
+ const refreshUserStateFromValidTokenPromise = refreshUserStateFromCookiePromise.then(async () => {
718
+ if (core.state.get().token && !core.state.get().user) await __refreshUser_wrapped(client).catch(async () => {
719
+ await __logout_wrapped(client);
720
+ });
721
+ });
678
722
  core.initTrack.track({
679
723
  name: require_getNetworkProviderFromNetworkId.INITIALIZE_STORAGE_SYNC_TRACKER_KEY,
680
724
  promise: initializeStorageSyncPromise
@@ -691,6 +735,10 @@ const initializeClient = async (client = require_InvalidParamError.getDefaultCli
691
735
  name: require_getNetworkProviderFromNetworkId.REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY,
692
736
  promise: refreshUserStateFromCookiePromise
693
737
  });
738
+ core.initTrack.track({
739
+ name: require_getNetworkProviderFromNetworkId.REFRESH_USER_STATE_FROM_VALID_TOKEN_TRACKER_KEY,
740
+ promise: refreshUserStateFromValidTokenPromise
741
+ });
694
742
  try {
695
743
  await core.initTrack.waitForAll();
696
744
  core.state.set({ initStatus: "finished" });
@@ -2547,6 +2595,85 @@ const getCheckouts = async (client) => {
2547
2595
  return projectSettings.checkouts ?? [];
2548
2596
  };
2549
2597
 
2598
+ //#endregion
2599
+ //#region src/modules/checkout/utils/createCheckoutTransactionChannelSchema/createCheckoutTransactionChannelSchema.ts
2600
+ /**
2601
+ * Zod schema for realtime events published to a checkout transaction's channel.
2602
+ * Uses z.string() for axis and state fields to remain valid when new states are
2603
+ * added to the backend without requiring a SDK update.
2604
+ */
2605
+ const checkoutTransactionEventSchema = zod_mini.object({
2606
+ axis: zod_mini.string(),
2607
+ newState: zod_mini.string(),
2608
+ previousState: zod_mini.string(),
2609
+ timestamp: zod_mini.string(),
2610
+ transactionId: zod_mini.string()
2611
+ });
2612
+ /**
2613
+ * Creates a typed realtime channel schema for a given checkout transaction.
2614
+ * Channel name follows the backend convention: `transaction:{transactionId}`.
2615
+ * @not-instrumented
2616
+ */
2617
+ const createCheckoutTransactionChannelSchema = (transactionId) => require_getNetworkProviderFromNetworkId.__createRealtimeChannelSchema_wrapped({
2618
+ channel: `transaction:${transactionId}`,
2619
+ schema: checkoutTransactionEventSchema
2620
+ });
2621
+
2622
+ //#endregion
2623
+ //#region src/modules/checkout/utils/subscribeToCheckoutTransaction/subscribeToCheckoutTransaction.ts
2624
+ const TERMINAL_EXECUTION_STATES = new Set([
2625
+ "cancelled",
2626
+ "expired",
2627
+ "failed"
2628
+ ]);
2629
+ const TERMINAL_SETTLEMENT_STATES = new Set(["completed", "failed"]);
2630
+ const isTerminalEvent = (data) => {
2631
+ if (data.axis === "execution") return TERMINAL_EXECUTION_STATES.has(data.newState);
2632
+ if (data.axis === "settlement") return TERMINAL_SETTLEMENT_STATES.has(data.newState);
2633
+ return false;
2634
+ };
2635
+ /**
2636
+ * Connects to the realtime service if not already connected and subscribes to
2637
+ * all state transition events for the given checkout transaction.
2638
+ *
2639
+ * Settlement and execution axis events are forwarded as public SDK events.
2640
+ * The subscription is torn down automatically when a terminal event is received.
2641
+ * @not-instrumented
2642
+ */
2643
+ const subscribeToCheckoutTransaction = async ({ transactionId }, client) => {
2644
+ const { realtime } = require_InvalidParamError.getCore(client);
2645
+ if (realtime.getConnectionState() === "idle") await realtime.connect({ client });
2646
+ const channelSchema = createCheckoutTransactionChannelSchema(transactionId);
2647
+ const handler = ({ data }) => {
2648
+ if (data.axis === "execution") require_getVerifiedCredentialForWalletAccount.emitEvent({
2649
+ args: {
2650
+ newState: data.newState,
2651
+ previousState: data.previousState,
2652
+ timestamp: data.timestamp,
2653
+ transactionId: data.transactionId
2654
+ },
2655
+ event: "checkoutTransactionExecutionStateChanged"
2656
+ }, client);
2657
+ if (data.axis === "settlement") require_getVerifiedCredentialForWalletAccount.emitEvent({
2658
+ args: {
2659
+ newState: data.newState,
2660
+ previousState: data.previousState,
2661
+ timestamp: data.timestamp,
2662
+ transactionId: data.transactionId
2663
+ },
2664
+ event: "checkoutTransactionSettlementStateChanged"
2665
+ }, client);
2666
+ if (isTerminalEvent(data)) realtime.unsubscribe({
2667
+ callback: handler,
2668
+ channelSchema
2669
+ });
2670
+ };
2671
+ await realtime.subscribe({
2672
+ callback: handler,
2673
+ channelSchema
2674
+ });
2675
+ };
2676
+
2550
2677
  //#endregion
2551
2678
  //#region src/modules/checkout/createCheckoutTransaction/createCheckoutTransaction.ts
2552
2679
  /**
@@ -2578,6 +2705,9 @@ const createCheckoutTransaction = async (params, client = require_InvalidParamEr
2578
2705
  environmentId: core.environmentId
2579
2706
  });
2580
2707
  await core.storage.setItem(createCheckoutSessionTokenStorageKey(result.transaction.id), result.sessionToken);
2708
+ subscribeToCheckoutTransaction({ transactionId: result.transaction.id }, client).catch((error) => {
2709
+ core.logger.error("Failed to subscribe to checkout transaction realtime channel", error);
2710
+ });
2581
2711
  return result;
2582
2712
  };
2583
2713
  const __createCheckoutTransaction_impl = createCheckoutTransaction;
@@ -2850,6 +2980,32 @@ const __requiresConversion_wrapped = require_InvalidParamError.instrumentFunctio
2850
2980
  }
2851
2981
  });
2852
2982
 
2983
+ //#endregion
2984
+ //#region src/modules/checkout/trackCheckoutTransaction/trackCheckoutTransaction.ts
2985
+ /**
2986
+ * Subscribes to realtime state change events for an existing checkout transaction.
2987
+ *
2988
+ * Call this after a page refresh to resume receiving transaction events
2989
+ * for a transaction that was created in a previous page session.
2990
+ *
2991
+ * @param params.transactionId - The ID of the checkout transaction to track.
2992
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2993
+ * @instrumented
2994
+ */
2995
+ const trackCheckoutTransaction = ({ transactionId }, client = require_InvalidParamError.getDefaultClient()) => subscribeToCheckoutTransaction({ transactionId }, client);
2996
+ const __trackCheckoutTransaction_impl = trackCheckoutTransaction;
2997
+ const __trackCheckoutTransaction_wrapped = require_InvalidParamError.instrumentFunction({
2998
+ fn: __trackCheckoutTransaction_impl,
2999
+ functionName: "trackCheckoutTransaction",
3000
+ getCore: () => {
3001
+ try {
3002
+ return require_InvalidParamError.getCore(require_InvalidParamError.getDefaultClient());
3003
+ } catch {
3004
+ return;
3005
+ }
3006
+ }
3007
+ });
3008
+
2853
3009
  //#endregion
2854
3010
  //#region src/modules/deviceRegistration/completeDeviceRegistration/completeDeviceRegistration.ts
2855
3011
  const DEVICE_REGISTRATION_TOKEN_HEADER = "x-dynamic-device-registration-token";
@@ -5639,40 +5795,6 @@ const isUserOnboardingComplete = (client = require_InvalidParamError.getDefaultC
5639
5795
  return !hasMissingKycFields && !hasPendingMfaAuth && !hasPendingRecoveryCodes;
5640
5796
  };
5641
5797
 
5642
- //#endregion
5643
- //#region src/modules/user/refreshUser/refreshUser.ts
5644
- /**
5645
- * Refreshes the current user's data from the server.
5646
- *
5647
- * This function fetches the latest authenticated user information from the backend
5648
- * and updates the local user state.
5649
- *
5650
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
5651
- * @returns A promise that resolves to the authenticated user.
5652
- * @instrumented
5653
- */
5654
- const refreshUser = async (client = require_InvalidParamError.getDefaultClient()) => {
5655
- const core = require_InvalidParamError.getCore(client);
5656
- const apiClient = require_InvalidParamError.__createApiClient_wrapped({}, client);
5657
- const previousState = { ...core.state.get() };
5658
- const user = await apiClient.getAuthenticatedUser({ environmentId: core.environmentId });
5659
- core.state.set({ user });
5660
- require_getVerifiedCredentialForWalletAccount.checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
5661
- return user;
5662
- };
5663
- const __refreshUser_impl = refreshUser;
5664
- const __refreshUser_wrapped = require_InvalidParamError.instrumentFunction({
5665
- fn: __refreshUser_impl,
5666
- functionName: "refreshUser",
5667
- getCore: () => {
5668
- try {
5669
- return require_InvalidParamError.getCore(require_InvalidParamError.getDefaultClient());
5670
- } catch {
5671
- return;
5672
- }
5673
- }
5674
- });
5675
-
5676
5798
  //#endregion
5677
5799
  //#region src/modules/wallets/assertWalletAccountSigningAvailability/assertWalletAccountSigningAvailability.ts
5678
5800
  /**
@@ -7006,6 +7128,7 @@ exports.signMessage = __signMessage_wrapped;
7006
7128
  exports.submitCheckoutTransaction = __submitCheckoutTransaction_wrapped;
7007
7129
  exports.supportedCountries = supportedCountries;
7008
7130
  exports.switchActiveNetwork = __switchActiveNetwork_wrapped;
7131
+ exports.trackCheckoutTransaction = __trackCheckoutTransaction_wrapped;
7009
7132
  exports.transferAmount = __transferAmount_wrapped;
7010
7133
  exports.transferWalletAccount = __transferWalletAccount_wrapped;
7011
7134
  exports.unlinkSocialAccount = __unlinkSocialAccount_wrapped;