@imtbl/sdk 1.5.3-alpha.5 → 1.5.4-alpha.1

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.
@@ -23736,11 +23736,14 @@ type CheckoutWidgetsConfig = {
23736
23736
  /**
23737
23737
  * Represents the configuration options for instantiating the Checkout Widgets factory.
23738
23738
  * @property {WidgetConfiguration} config - global configuration options for the widgets.
23739
- * @property {SemanticVersion | undefined} version - version of the Checkout widgets bundle (default latest version will be used).
23739
+ * @property {SemanticVersion | undefined} version - version of the Checkout widgets bundle(default latest version will be used).
23740
+ * @property {boolean | undefined} useEsModules - Set to true to use the esm build of the widgets.
23740
23741
  */
23741
23742
  type WidgetsInit = {
23742
23743
  config: WidgetConfiguration;
23743
23744
  version?: SemanticVersion;
23745
+ /** Loads separate parts of the widget script as required for performance improvements. */
23746
+ useEsModules?: boolean;
23744
23747
  };
23745
23748
 
23746
23749
  declare class Checkout {
package/dist/checkout.js CHANGED
@@ -139,7 +139,7 @@ const flattenProperties$1 = (properties) => {
139
139
  };
140
140
 
141
141
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
142
- const SDK_VERSION$1 = '1.5.3-alpha.5';
142
+ const SDK_VERSION$1 = '1.5.4-alpha.1';
143
143
  const getReferrer$1 = () => {
144
144
  if (isNode$1()) {
145
145
  return '';
@@ -17478,7 +17478,7 @@ const flattenProperties = (properties) => {
17478
17478
  };
17479
17479
 
17480
17480
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
17481
- const SDK_VERSION = '1.5.3-alpha.5';
17481
+ const SDK_VERSION = '1.5.4-alpha.1';
17482
17482
  const getReferrer = () => {
17483
17483
  if (isNode()) {
17484
17484
  return '';
@@ -27715,7 +27715,7 @@ class APIError extends Error {
27715
27715
 
27716
27716
  /* eslint-disable implicit-arrow-linebreak */
27717
27717
  const defaultHeaders = {
27718
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.3-alpha.5',
27718
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.4-alpha.1',
27719
27719
  };
27720
27720
  /**
27721
27721
  * createAPIConfiguration to create a custom Configuration
@@ -29082,7 +29082,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
29082
29082
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
29083
29083
  };
29084
29084
 
29085
- const SDK_VERSION_MARKER = '1.5.3-alpha.5';
29085
+ const SDK_VERSION_MARKER = '1.5.4-alpha.1';
29086
29086
  // This SDK version is replaced by the `yarn build` command ran on the root level
29087
29087
  const globalPackageVersion = () => SDK_VERSION_MARKER;
29088
29088
 
@@ -32697,28 +32697,34 @@ function validateAndBuildVersion(version) {
32697
32697
  return validatedVersion;
32698
32698
  }
32699
32699
 
32700
- function loadUnresolved(version) {
32700
+ // Loads the checkout widgets bundle from the CDN and appends the script to the document head
32701
+ function loadUnresolvedBundle(version) {
32701
32702
  if (window === undefined) {
32702
32703
  throw new Error('missing window object: please run Checkout client side');
32703
32704
  }
32704
32705
  if (document === undefined) {
32705
32706
  throw new Error('missing document object: please run Checkout client side');
32706
32707
  }
32707
- // const scriptId = 'immutable-checkout-widgets-bundle';
32708
+ const scriptId = 'immutable-checkout-widgets-bundle';
32708
32709
  const validVersion = validateAndBuildVersion(version);
32709
32710
  // Prevent the script to be loaded more than once
32710
32711
  // by checking the presence of the script and its version.
32711
- // const initScript = document.getElementById(scriptId) as HTMLScriptElement;
32712
- // if (initScript) return { loaded: true, element: initScript };
32713
- // const tag = document.createElement('script');
32714
- const cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
32715
- // if (useLocalBundle()) cdnUrl = `http://${window.location.host}/lib/js/widgets.js`;
32716
- // tag.setAttribute('id', scriptId);
32717
- // tag.setAttribute('data-version', validVersion);
32718
- // tag.setAttribute('type', 'module');
32719
- // tag.setAttribute('src', cdnUrl);
32720
- // document.head.appendChild(tag);
32721
- return { loaded: false, cdnUrl };
32712
+ const initScript = document.getElementById(scriptId);
32713
+ if (initScript)
32714
+ return { loaded: true, element: initScript };
32715
+ const tag = document.createElement('script');
32716
+ let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
32717
+ tag.setAttribute('id', scriptId);
32718
+ tag.setAttribute('data-version', validVersion);
32719
+ tag.setAttribute('src', cdnUrl);
32720
+ document.head.appendChild(tag);
32721
+ return { loaded: false, element: tag };
32722
+ }
32723
+ // Gets the CDN url for the split checkout widgets bundle
32724
+ function getCdnUrl(version) {
32725
+ const validVersion = validateAndBuildVersion(version);
32726
+ let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets-esm.js`;
32727
+ return cdnUrl;
32722
32728
  }
32723
32729
 
32724
32730
  const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
@@ -32797,6 +32803,7 @@ const SANDBOX_CONFIGURATION = {
32797
32803
  },
32798
32804
  passport: undefined,
32799
32805
  };
32806
+ const WIDGETS_SCRIPT_TIMEOUT = 100;
32800
32807
  // Checkout SDK
32801
32808
  class Checkout {
32802
32809
  readOnlyProviders;
@@ -32826,19 +32833,46 @@ class Checkout {
32826
32833
  const checkout = this;
32827
32834
  // Preload the configurations
32828
32835
  await checkout.config.remote.getConfig();
32829
- const load = loadUnresolved(init.version);
32830
- const checkoutWidgetsModule = await import(/* webpackIgnore: true */ load.cdnUrl);
32831
- const factory = new Promise((resolve, reject) => {
32832
- try {
32836
+ // Resolves the factory for the esm build of the widgets
32837
+ if (init.useEsModules) {
32838
+ const cdnUrl = getCdnUrl(init.version);
32839
+ // WebpackIgnore comment required to prevent webpack modifying the import statement and
32840
+ // breaking the dynamic import in certain applications integrating checkout
32841
+ const checkoutWidgetsModule = await import(/* webpackIgnore: true */ cdnUrl);
32842
+ const factory = new Promise((resolve, reject) => {
32833
32843
  if (checkoutWidgetsModule && checkoutWidgetsModule.WidgetsFactory) {
32834
32844
  resolve(new checkoutWidgetsModule.WidgetsFactory(checkout, init.config));
32835
32845
  }
32836
32846
  else {
32837
- throw new Error('WidgetsFactory is not found in the imported module.');
32847
+ reject(new CheckoutError('Unable to resolve the WidgetsFactory from the checkout widgets module', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
32848
+ }
32849
+ });
32850
+ return factory;
32851
+ }
32852
+ // Resolves the factory for the umd build of the widgets
32853
+ const factory = new Promise((resolve, reject) => {
32854
+ function checkForWidgetsBundleLoaded() {
32855
+ if (typeof ImmutableCheckoutWidgets !== 'undefined') {
32856
+ resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
32857
+ }
32858
+ else {
32859
+ // If ImmutableCheckoutWidgets is not defined, wait for set amount of time.
32860
+ // When time has elapsed, check again if ImmutableCheckoutWidgets is defined.
32861
+ // Once it's defined, the promise will resolve and setTimeout won't be called again.
32862
+ setTimeout(checkForWidgetsBundleLoaded, WIDGETS_SCRIPT_TIMEOUT);
32838
32863
  }
32839
32864
  }
32840
- catch (error) {
32841
- reject(error);
32865
+ try {
32866
+ const script = loadUnresolvedBundle(init.version);
32867
+ if (script.loaded && typeof ImmutableCheckoutWidgets !== 'undefined') {
32868
+ resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
32869
+ }
32870
+ else {
32871
+ checkForWidgetsBundleLoaded();
32872
+ }
32873
+ }
32874
+ catch (err) {
32875
+ reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
32842
32876
  }
32843
32877
  });
32844
32878
  return factory;
package/dist/config.js CHANGED
@@ -128,7 +128,7 @@ const flattenProperties = (properties) => {
128
128
  };
129
129
 
130
130
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
131
- const SDK_VERSION = '1.5.3-alpha.5';
131
+ const SDK_VERSION = '1.5.4-alpha.1';
132
132
  const getReferrer = () => {
133
133
  if (isNode()) {
134
134
  return '';