@zonos/elements 1.0.16 → 1.0.17-alpha.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 (85) hide show
  1. package/dist/cjs/{cart-e27fd17c.js → cart-108bc407.js} +8 -1
  2. package/dist/cjs/cart-108bc407.js.map +1 -0
  3. package/dist/cjs/zonos-address_2.cjs.entry.js +1 -1
  4. package/dist/cjs/zonos-banner_2.cjs.entry.js +1 -1
  5. package/dist/cjs/zonos-cart-items_10.cjs.entry.js +5 -3
  6. package/dist/cjs/zonos-cart-items_10.cjs.entry.js.map +1 -1
  7. package/dist/cjs/zonos-checkout.cjs.entry.js +6 -2
  8. package/dist/cjs/zonos-checkout.cjs.entry.js.map +1 -1
  9. package/dist/cjs/zonos-controller.cjs.entry.js +1 -1
  10. package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js +3 -1
  11. package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js.map +1 -1
  12. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +1 -1
  13. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js.map +1 -1
  14. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +5 -1
  15. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js.map +1 -1
  16. package/dist/collection/components/store/checkout/cart.js +6 -0
  17. package/dist/collection/components/store/checkout/cart.js.map +1 -1
  18. package/dist/collection/components/store/checkout/stripe.js +2 -0
  19. package/dist/collection/components/store/checkout/stripe.js.map +1 -1
  20. package/dist/collection/environment.js +9 -1
  21. package/dist/collection/environment.js.map +1 -1
  22. package/dist/collection/scripts/stripe.js +3 -3
  23. package/dist/collection/scripts/stripe.js.map +1 -1
  24. package/dist/collection/types/generated/graphql.customer.types.js +5 -0
  25. package/dist/collection/types/generated/graphql.customer.types.js.map +1 -1
  26. package/dist/components/stripe.js +8 -1
  27. package/dist/components/stripe.js.map +1 -1
  28. package/dist/components/zonos-cart-items2.js +3 -1
  29. package/dist/components/zonos-cart-items2.js.map +1 -1
  30. package/dist/components/zonos-checkout-finish2.js +1 -1
  31. package/dist/components/zonos-checkout-finish2.js.map +1 -1
  32. package/dist/components/zonos-checkout.js +5 -1
  33. package/dist/components/zonos-checkout.js.map +1 -1
  34. package/dist/esm/{cart-36c33342.js → cart-2f83e048.js} +8 -1
  35. package/dist/esm/cart-2f83e048.js.map +1 -0
  36. package/dist/esm/zonos-address_2.entry.js +1 -1
  37. package/dist/esm/zonos-banner_2.entry.js +1 -1
  38. package/dist/esm/zonos-cart-items_10.entry.js +5 -3
  39. package/dist/esm/zonos-cart-items_10.entry.js.map +1 -1
  40. package/dist/esm/zonos-checkout.entry.js +6 -2
  41. package/dist/esm/zonos-checkout.entry.js.map +1 -1
  42. package/dist/esm/zonos-controller.entry.js +1 -1
  43. package/dist/esm-es5/cart-2f83e048.js +2 -0
  44. package/dist/esm-es5/cart-2f83e048.js.map +1 -0
  45. package/dist/esm-es5/zonos-address_2.entry.js +1 -1
  46. package/dist/esm-es5/zonos-banner_2.entry.js +1 -1
  47. package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
  48. package/dist/esm-es5/zonos-cart-items_10.entry.js.map +1 -1
  49. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  50. package/dist/esm-es5/zonos-checkout.entry.js.map +1 -1
  51. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  52. package/dist/scripts/loadStripe.js +118 -0
  53. package/dist/scripts/loadZonos.js +300 -0
  54. package/dist/scripts/stripe.js +126 -0
  55. package/dist/scripts/zonos.js +300 -0
  56. package/dist/types/components/store/checkout/cart.d.ts +14 -0
  57. package/dist/types/components/store/checkout/stripe.d.ts +1 -1
  58. package/dist/types/types/generated/graphql.customer.types.d.ts +48 -0
  59. package/dist/types/types/generated/graphql.customer.types.ts +50 -0
  60. package/dist/zonos-elements/{cart-36c33342.js → cart-2f83e048.js} +8 -1
  61. package/dist/zonos-elements/cart-2f83e048.js.map +1 -0
  62. package/dist/zonos-elements/cart-9780fa28.system.js +2 -0
  63. package/dist/zonos-elements/cart-9780fa28.system.js.map +1 -0
  64. package/dist/zonos-elements/zonos-address_2.entry.js +1 -1
  65. package/dist/zonos-elements/zonos-address_2.system.entry.js +1 -1
  66. package/dist/zonos-elements/zonos-banner_2.entry.js +1 -1
  67. package/dist/zonos-elements/zonos-banner_2.system.entry.js +1 -1
  68. package/dist/zonos-elements/zonos-cart-items_10.entry.js +5 -3
  69. package/dist/zonos-elements/zonos-cart-items_10.entry.js.map +1 -1
  70. package/dist/zonos-elements/zonos-cart-items_10.system.entry.js +1 -1
  71. package/dist/zonos-elements/zonos-cart-items_10.system.entry.js.map +1 -1
  72. package/dist/zonos-elements/zonos-checkout.entry.js +6 -2
  73. package/dist/zonos-elements/zonos-checkout.entry.js.map +1 -1
  74. package/dist/zonos-elements/zonos-checkout.system.entry.js +1 -1
  75. package/dist/zonos-elements/zonos-checkout.system.entry.js.map +1 -1
  76. package/dist/zonos-elements/zonos-controller.entry.js +1 -1
  77. package/dist/zonos-elements/zonos-controller.system.entry.js +1 -1
  78. package/package.json +2 -2
  79. package/dist/cjs/cart-e27fd17c.js.map +0 -1
  80. package/dist/esm/cart-36c33342.js.map +0 -1
  81. package/dist/esm-es5/cart-36c33342.js +0 -2
  82. package/dist/esm-es5/cart-36c33342.js.map +0 -1
  83. package/dist/zonos-elements/cart-36c33342.js.map +0 -1
  84. package/dist/zonos-elements/cart-ecd9011b.system.js +0 -2
  85. package/dist/zonos-elements/cart-ecd9011b.system.js.map +0 -1
@@ -136,6 +136,7 @@ const stripeStorePrefetchLandedCost = async () => {
136
136
  if (subtotals) {
137
137
  // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
138
138
  cartStoreApplySubtotals({
139
+ exchangeRate: subtotals.exchangeRate,
139
140
  items: subtotals.items,
140
141
  landedCostTotal: 0,
141
142
  presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
@@ -271,6 +272,7 @@ const stripeStoreInitCheckoutSession = async () => {
271
272
  // update cart store with updated informations
272
273
  cartStore.checkoutSessionId = result.id;
273
274
  cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
275
+ log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
274
276
  log('done-init-checkout-session');
275
277
  return true;
276
278
  };
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../../../src/components/store/checkout/stripe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAc7C,OAAO,EACL,SAAS,EACT,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AA0CpE,MAAM,EACJ,QAAQ,EACR,KAAK,EACL,KAAK,EAAE,WAAW,GACnB,GAAG,WAAW,CAAc,GAAG,EAAE,CAAC,CAAC;EAClC,YAAY,EAAE,cAAc,CAAC,OAAO,CAAC,sBAAsB,CAAC,IAAI,IAAI;EACpE,iCAAiC,EAAE,IAAI;E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ACjB,cAAc,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;GACnD;AACH,CAAC,CAAC,CAAC;AAEH,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,yBAAyB,EACzB,8BAA8B,EAC9B,6BAA6B,EAC7B,gBAAgB,EAChB,0BAA0B,EAC1B,gCAAgC,GACjC,CAAC","sourcesContent":["import { createStore } from '@stencil/store';\nimport type {\n PaymentIntent,\n Stripe,\n StripeAddressElement,\n StripeAddressElementChangeEvent,\n StripeElements,\n StripeElementsOptionsClientSecret,\n StripeLinkAuthenticationElement,\n StripeLinkAuthenticationElementChangeEvent,\n StripePaymentElement,\n StripePaymentElementChangeEvent,\n} from '@stripe/stripe-js';\n\nimport {\n cartStore,\n cartStoreApplySubtotals,\n} from 'src/components/store/checkout/cart';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { zonosStore } from 'src/components/store/zonosStore';\nimport { calculateLandedCost } from 'src/components/utils/api/calculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport { isDarkColor } from 'src/components/utils/isDarkColor';\nimport { log } from 'src/components/utils/logging/log';\nimport { logError } from 'src/components/utils/logging/logError';\nimport { addressRuleStyle } from 'src/styles/stripe/addressRuleStyle';\nimport { defaultVariable } from 'src/styles/stripe/defaultVariable';\nimport type {\n CheckoutSessionCreateMutation,\n CheckoutSessionUpdateMutation,\n CountryCode,\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type ContactOption = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n phone?: string;\n};\n\ntype StripeStore = {\n // client secret is used to render link and payment elements\n clientSecret: string | null;\n fetchingLandedCostAbordController: AbortController | null;\n // toggle to indicate if we are pre-fetching/fetching landed cost\n isFetchingLandedCost: boolean;\n // toggle to indicate if we are fetching checkout session\n isFetchingSession: boolean;\n stripe: Stripe | null;\n stripeAddressElement: StripeAddressElement | null;\n stripeAddressEventData: StripeAddressElementChangeEvent | null;\n stripeAddressUsedWhenFetchingLC: StripeAddressElementChangeEvent | null;\n stripeElements: StripeElements | null;\n stripeLinkElement: StripeLinkAuthenticationElement | null;\n stripeLinkEventData: StripeLinkAuthenticationElementChangeEvent | null;\n stripeLinkUsedWhenFetchingLC: StripeLinkAuthenticationElementChangeEvent | null;\n stripePaymentElement: StripePaymentElement | null;\n stripePaymentEventData: StripePaymentElementChangeEvent | null;\n};\n\nconst {\n onChange,\n reset,\n state: stripeStore,\n} = createStore<StripeStore>(() => ({\n clientSecret: sessionStorage.getItem('zonos--client-secret') || null,\n fetchingLandedCostAbordController: null,\n isFetchingLandedCost: false,\n isFetchingSession: false,\n stripe: null,\n stripeAddressElement: null,\n stripeAddressEventData: null,\n stripeAddressUsedWhenFetchingLC: null,\n stripeElements: null,\n stripeLinkElement: null,\n stripeLinkEventData: null,\n stripeLinkUsedWhenFetchingLC: null,\n stripePaymentElement: null,\n stripePaymentEventData: null,\n}));\n\nconst getStripeOptions = ({\n clientSecret,\n overrideBorderRaidus,\n overridePrimaryColor,\n overrideTheme,\n}: {\n clientSecret?: string;\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}): StripeElementsOptionsClientSecret => {\n const primaryColor =\n overridePrimaryColor || zonosStore.appearance.colorPrimary;\n const themeBasedColor =\n primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';\n // if overrideTheme is provided, use it. Otherwise, use theme based on primary color\n const theme = overrideTheme === 'DARK' ? 'night' : 'flat';\n return {\n appearance: {\n labels: 'floating',\n rules: {\n ...addressRuleStyle({ theme: 'LIGHT' }),\n },\n // get contrast theme color base on primary color\n theme: overrideTheme ? theme : themeBasedColor,\n variables: {\n ...defaultVariable({\n borderStyle: overrideBorderRaidus,\n theme: 'LIGHT',\n }),\n },\n },\n clientSecret,\n locale: localizationStore.selectedLocale,\n };\n};\n\nconst initStripeElements = async (props?: {\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}) => {\n const clientSecret = stripeStore.clientSecret;\n\n if (!stripeStore.stripe) {\n log('Skip. Stripe is not initialized');\n return;\n }\n if (clientSecret) {\n const stripeOptions = getStripeOptions({\n clientSecret,\n overrideBorderRaidus: props?.overrideBorderRaidus,\n overridePrimaryColor: props?.overridePrimaryColor,\n overrideTheme: props?.overrideTheme,\n });\n\n if (!stripeStore.stripeElements) {\n // init stripe elements if it doesn't exist\n stripeStore.stripeElements = stripeStore.stripe?.elements(stripeOptions);\n } else {\n // update elements with new option if it already exists\n stripeStore.stripeElements.update(stripeOptions);\n }\n log('Stripe elements initialized');\n }\n};\n\nconst stripeStoreReset = () => {\n // clean clientSecret so that we can start the new one.\n sessionStorage.removeItem('zonos--client-secret');\n\n // cleanup stripe elements\n reset();\n // set stripe back to window.Zonos.stripe\n stripeStore.stripe = window.Zonos.stripe;\n};\n\n/**\n * Check if the address and email info used when fetching landed cost with the current email and address info are different\n * Purpose is to resend the request if the info used when fetching landed cost is different from the current info\n */\nconst isPrefetchInfoOutdated = () => {\n const hasAbortController = stripeStore.fetchingLandedCostAbordController;\n if (!hasAbortController) {\n // if there is no abort controller, this is a new request\n return false;\n }\n\n const isLinkDataDirty =\n JSON.stringify(stripeStore.stripeLinkUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeLinkEventData?.value);\n const isAddressDataDirty =\n JSON.stringify(stripeStore.stripeAddressUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeAddressEventData?.value);\n\n return isLinkDataDirty || isAddressDataDirty;\n};\n\nconst stripeStorePrefetchLandedCost = async () => {\n const stripeAddressReady = !!stripeStore.stripeAddressEventData?.complete;\n const stripeLinkReady = !!stripeStore.stripeLinkEventData?.complete;\n const shouldRefetch = isPrefetchInfoOutdated();\n\n if (shouldRefetch) {\n // if the info used when fetching landed cost is different from the current info, abort the previous request\n stripeStore.fetchingLandedCostAbordController?.abort();\n stripeStore.fetchingLandedCostAbordController = null;\n }\n\n // only fetch if we are not fetching or we need to refetch\n if (\n stripeAddressReady &&\n stripeLinkReady &&\n (shouldRefetch || !stripeStore.isFetchingLandedCost)\n ) {\n stripeStore.isFetchingLandedCost = true;\n if (stripeStore.stripeAddressEventData) {\n stripeStore.stripeAddressUsedWhenFetchingLC = {\n ...stripeStore.stripeAddressEventData,\n };\n }\n if (stripeStore.stripeLinkEventData) {\n stripeStore.stripeLinkUsedWhenFetchingLC = {\n ...stripeStore.stripeLinkEventData,\n };\n }\n try {\n const abortController = new AbortController();\n stripeStore.fetchingLandedCostAbordController = abortController;\n const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } =\n await calculateLandedCost(abortController);\n\n // reset abort controller after we are done\n stripeStore.fetchingLandedCostAbordController = null;\n\n // update cart store with landed cost info\n cartStore.landedCostData =\n checkoutSessionWorkflow?.filter(Boolean) || null;\n\n cartStore.shippingData =\n shipmentRatingCalculateWorkflow?.filter(Boolean) || null;\n // apply new subtotal and total, this is mainly to show items in the presentment currency\n const firstLandedCostData = cartStore.landedCostData?.find(Boolean);\n const subtotals = !!firstLandedCostData\n ? firstLandedCostData.subtotals\n : null;\n if (subtotals) {\n // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet\n cartStoreApplySubtotals({\n items: subtotals.items,\n landedCostTotal: 0,\n presentmentCurrencyCode: subtotals.presentmentCurrencyCode,\n shipping: 0,\n total: subtotals.items,\n });\n }\n } catch (err) {\n logError(err);\n }\n stripeStore.isFetchingLandedCost = false;\n }\n};\n\nconst getStripeMessageBasedOnStatus = (status?: PaymentIntent['status']) => {\n let messages: string[] = [];\n let isError = true;\n // Inspect the PaymentIntent `status` to indicate the status of the payment\n // to your customer.\n //\n // Some payment methods will [immediately succeed or fail][0] upon\n // confirmation, while others will first enter a `processing` state.\n //\n // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification\n switch (status) {\n case 'succeeded': {\n messages = [\n translate(\n 'Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us.',\n ),\n '',\n '',\n translate(\n \"We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time.\",\n ),\n ];\n isError = false;\n break;\n }\n case 'requires_capture':\n case 'processing': {\n messages = [\n translate(\n \"Payment processing. We'll update you when payment is received.\",\n ),\n ];\n isError = false;\n break;\n }\n\n case 'requires_payment_method': {\n messages = [\n translate('Payment failed. Please try another payment method.'),\n ];\n break;\n }\n\n default: {\n messages = [translate('Something went wrong.')];\n break;\n }\n }\n return {\n isError,\n messages,\n };\n};\n\nconst stripeStoreRetrievePayment = async ({\n clientSecret: _clientSecret,\n storybookForceStatus,\n}: {\n clientSecret?: string;\n storybookForceStatus?: PaymentIntent['status'];\n}) => {\n if (storybookForceStatus) {\n // return status right away if we are in storybook mode\n const { isError, messages } =\n getStripeMessageBasedOnStatus(storybookForceStatus);\n\n return { error: isError, messages };\n }\n const clientSecret = _clientSecret || stripeStore.clientSecret;\n if (!stripeStore.stripe || !clientSecret) {\n logError('Failed to retrieve payment intent. Stripe is not initialized');\n return { error: true, message: [translate('Something went wrong.')] };\n }\n const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(\n clientSecret,\n );\n\n const status = paymentIntent?.status;\n\n const { isError, messages } = getStripeMessageBasedOnStatus(status);\n\n return { error: isError, messages };\n};\n\nconst stripeStoreConfirmPayment = async () => {\n const stripePaymentReady = !!stripeStore.stripePaymentEventData?.complete;\n const stripeElements = stripeStore.stripeElements;\n const stripe = stripeStore.stripe;\n const stripeClientSecret = stripeStore.clientSecret;\n if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {\n const { error } = await stripe.confirmPayment({\n confirmParams: {\n receipt_email: stripeStore.stripeLinkEventData?.value?.email,\n return_url: window.location.href,\n },\n elements: stripeElements,\n redirect: 'if_required',\n });\n\n if (error) {\n if (error.type === 'card_error' || error.type === 'validation_error') {\n throw new Error(error.message);\n }\n if (error.type === 'invalid_request_error') {\n if (error.code === 'payment_intent_unexpected_state') {\n // PaymentIntent was canceled or expired, or status is `require_capture`.\n // don't throw error here because we will reset the checkout session last step\n return;\n }\n }\n throw new Error('An unexpected error occurred.');\n }\n }\n};\n\ntype CheckoutSessionCreateRequest = {\n currency: string;\n itemsAmount: number;\n presentmentCountryCode: CountryCode | null;\n};\n\n/**\n * Init checkout session\n * @returns {boolean} whether or not the checkout session is successfully created\n */\nconst stripeStoreInitCheckoutSession = async () => {\n const total = cartStore.items.reduce(\n (amount, item) => amount + item.amount * item.quantity,\n 0,\n );\n\n if (!total || !localizationStore.targetCurrency) {\n logError('Fail to create checkout session - invalid total or currency');\n return false;\n }\n\n stripeStore.isFetchingSession = true;\n\n const { errors, json } = await handleFetch<\n CheckoutSessionCreateMutation,\n CheckoutSessionCreateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/create-checkout-session`, {\n body: {\n currency: cartStore.items.find(Boolean)?.currencyCode || '',\n itemsAmount: total,\n presentmentCountryCode: localizationStore.selectedCountryCode || null,\n },\n method: 'POST',\n });\n\n stripeStore.isFetchingSession = false;\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when creating checkout session',\n JSON.stringify(errors, null, 2),\n );\n\n return false;\n }\n const result = json.checkoutSessionCreate;\n\n stripeStore.clientSecret = result.clientSecret;\n // update cart store with updated informations\n cartStore.checkoutSessionId = result.id;\n cartStoreApplySubtotals({\n ...result.subtotals,\n landedCostTotal: 0,\n shipping: 0,\n total: result.subtotals.items,\n });\n\n log('done-init-checkout-session');\n return true;\n};\n\ntype CheckoutSessionUpdateRequest = {\n currency?: string;\n id: string;\n itemsAmount?: number;\n landedCostId?: string;\n presentmentCountryCode: CountryCode | null;\n};\n/**\n * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change\n */\nconst stripeStoreUpdateCheckoutSession = async ({\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n}: CheckoutSessionUpdateRequest) => {\n // No need to set loading state here because this function will be called under the hood to update\n // landed cost id for the section.\n const { errors, json } = await handleFetch<\n CheckoutSessionUpdateMutation,\n CheckoutSessionUpdateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/update-checkout-session`, {\n body: {\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n },\n method: 'POST',\n });\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when updating checkout session',\n JSON.stringify(errors, null, 2),\n );\n return { errors, json };\n }\n\n return { errors: [], json };\n};\n\nonChange('clientSecret', clientSecret => {\n // update stripe elements when client secret changes\n if (clientSecret && stripeStore.stripe) {\n sessionStorage.setItem('zonos--client-secret', clientSecret);\n }\n\n if (!clientSecret) {\n sessionStorage.removeItem('zonos--client-secret');\n }\n});\n\nexport {\n initStripeElements,\n stripeStore,\n stripeStoreConfirmPayment,\n stripeStoreInitCheckoutSession,\n stripeStorePrefetchLandedCost,\n stripeStoreReset,\n stripeStoreRetrievePayment,\n stripeStoreUpdateCheckoutSession,\n};\n"]}
1
+ {"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../../../src/components/store/checkout/stripe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAc7C,OAAO,EACL,SAAS,EACT,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACv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C,IAAI,EAAE;IAC1B,QAAQ,CACN,6CAA6C,EAC7C,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAChC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACzB;EAED,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC9B,CAAC,CAAC;AAEF,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC,EAAE;EACtC,oDAAoD;EACpD,IAAI,YAAY,IAAI,WAAW,CAAC,MAAM,EAAE;IACtC,cAAc,CAAC,OAAO,CAAC,sBAAsB,EAAE,YAAY,CAAC,CAAC;GAC9D;EAED,IAAI,CAAC,YAAY,EAAE;IACjB,cAAc,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;GACnD;AACH,CAAC,CAAC,CAAC;AAEH,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,yBAAyB,EACzB,8BAA8B,EAC9B,6BAA6B,EAC7B,gBAAgB,EAChB,0BAA0B,EAC1B,gCAAgC,GACjC,CAAC","sourcesContent":["import { createStore } from '@stencil/store';\nimport type {\n PaymentIntent,\n Stripe,\n StripeAddressElement,\n StripeAddressElementChangeEvent,\n StripeElements,\n StripeElementsOptionsClientSecret,\n StripeLinkAuthenticationElement,\n StripeLinkAuthenticationElementChangeEvent,\n StripePaymentElement,\n StripePaymentElementChangeEvent,\n} from '@stripe/stripe-js';\n\nimport {\n cartStore,\n cartStoreApplySubtotals,\n} from 'src/components/store/checkout/cart';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { zonosStore } from 'src/components/store/zonosStore';\nimport { calculateLandedCost } from 'src/components/utils/api/calculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport { isDarkColor } from 'src/components/utils/isDarkColor';\nimport { log } from 'src/components/utils/logging/log';\nimport { logError } from 'src/components/utils/logging/logError';\nimport { addressRuleStyle } from 'src/styles/stripe/addressRuleStyle';\nimport { defaultVariable } from 'src/styles/stripe/defaultVariable';\nimport type {\n CheckoutSessionCreateMutation,\n CheckoutSessionUpdateMutation,\n CountryCode,\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type ContactOption = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n phone?: string;\n};\n\ntype StripeStore = {\n // client secret is used to render link and payment elements\n clientSecret: string | null;\n fetchingLandedCostAbordController: AbortController | null;\n // toggle to indicate if we are pre-fetching/fetching landed cost\n isFetchingLandedCost: boolean;\n // toggle to indicate if we are fetching checkout session\n isFetchingSession: boolean;\n stripe: Stripe | null;\n stripeAddressElement: StripeAddressElement | null;\n stripeAddressEventData: StripeAddressElementChangeEvent | null;\n stripeAddressUsedWhenFetchingLC: StripeAddressElementChangeEvent | null;\n stripeElements: StripeElements | null;\n stripeLinkElement: StripeLinkAuthenticationElement | null;\n stripeLinkEventData: StripeLinkAuthenticationElementChangeEvent | null;\n stripeLinkUsedWhenFetchingLC: StripeLinkAuthenticationElementChangeEvent | null;\n stripePaymentElement: StripePaymentElement | null;\n stripePaymentEventData: StripePaymentElementChangeEvent | null;\n};\n\nconst {\n onChange,\n reset,\n state: stripeStore,\n} = createStore<StripeStore>(() => ({\n clientSecret: sessionStorage.getItem('zonos--client-secret') || null,\n fetchingLandedCostAbordController: null,\n isFetchingLandedCost: false,\n isFetchingSession: false,\n stripe: null,\n stripeAddressElement: null,\n stripeAddressEventData: null,\n stripeAddressUsedWhenFetchingLC: null,\n stripeElements: null,\n stripeLinkElement: null,\n stripeLinkEventData: null,\n stripeLinkUsedWhenFetchingLC: null,\n stripePaymentElement: null,\n stripePaymentEventData: null,\n}));\n\nconst getStripeOptions = ({\n clientSecret,\n overrideBorderRaidus,\n overridePrimaryColor,\n overrideTheme,\n}: {\n clientSecret?: string;\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}): StripeElementsOptionsClientSecret => {\n const primaryColor =\n overridePrimaryColor || zonosStore.appearance.colorPrimary;\n const themeBasedColor =\n primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';\n // if overrideTheme is provided, use it. Otherwise, use theme based on primary color\n const theme = overrideTheme === 'DARK' ? 'night' : 'flat';\n return {\n appearance: {\n labels: 'floating',\n rules: {\n ...addressRuleStyle({ theme: 'LIGHT' }),\n },\n // get contrast theme color base on primary color\n theme: overrideTheme ? theme : themeBasedColor,\n variables: {\n ...defaultVariable({\n borderStyle: overrideBorderRaidus,\n theme: 'LIGHT',\n }),\n },\n },\n clientSecret,\n locale: localizationStore.selectedLocale,\n };\n};\n\nconst initStripeElements = async (props?: {\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}) => {\n const clientSecret = stripeStore.clientSecret;\n\n if (!stripeStore.stripe) {\n log('Skip. Stripe is not initialized');\n return;\n }\n if (clientSecret) {\n const stripeOptions = getStripeOptions({\n clientSecret,\n overrideBorderRaidus: props?.overrideBorderRaidus,\n overridePrimaryColor: props?.overridePrimaryColor,\n overrideTheme: props?.overrideTheme,\n });\n\n if (!stripeStore.stripeElements) {\n // init stripe elements if it doesn't exist\n stripeStore.stripeElements = stripeStore.stripe?.elements(stripeOptions);\n } else {\n // update elements with new option if it already exists\n stripeStore.stripeElements.update(stripeOptions);\n }\n log('Stripe elements initialized');\n }\n};\n\nconst stripeStoreReset = () => {\n // clean clientSecret so that we can start the new one.\n sessionStorage.removeItem('zonos--client-secret');\n\n // cleanup stripe elements\n reset();\n // set stripe back to window.Zonos.stripe\n stripeStore.stripe = window.Zonos.stripe;\n};\n\n/**\n * Check if the address and email info used when fetching landed cost with the current email and address info are different\n * Purpose is to resend the request if the info used when fetching landed cost is different from the current info\n */\nconst isPrefetchInfoOutdated = () => {\n const hasAbortController = stripeStore.fetchingLandedCostAbordController;\n if (!hasAbortController) {\n // if there is no abort controller, this is a new request\n return false;\n }\n\n const isLinkDataDirty =\n JSON.stringify(stripeStore.stripeLinkUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeLinkEventData?.value);\n const isAddressDataDirty =\n JSON.stringify(stripeStore.stripeAddressUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeAddressEventData?.value);\n\n return isLinkDataDirty || isAddressDataDirty;\n};\n\nconst stripeStorePrefetchLandedCost = async () => {\n const stripeAddressReady = !!stripeStore.stripeAddressEventData?.complete;\n const stripeLinkReady = !!stripeStore.stripeLinkEventData?.complete;\n const shouldRefetch = isPrefetchInfoOutdated();\n\n if (shouldRefetch) {\n // if the info used when fetching landed cost is different from the current info, abort the previous request\n stripeStore.fetchingLandedCostAbordController?.abort();\n stripeStore.fetchingLandedCostAbordController = null;\n }\n\n // only fetch if we are not fetching or we need to refetch\n if (\n stripeAddressReady &&\n stripeLinkReady &&\n (shouldRefetch || !stripeStore.isFetchingLandedCost)\n ) {\n stripeStore.isFetchingLandedCost = true;\n if (stripeStore.stripeAddressEventData) {\n stripeStore.stripeAddressUsedWhenFetchingLC = {\n ...stripeStore.stripeAddressEventData,\n };\n }\n if (stripeStore.stripeLinkEventData) {\n stripeStore.stripeLinkUsedWhenFetchingLC = {\n ...stripeStore.stripeLinkEventData,\n };\n }\n try {\n const abortController = new AbortController();\n stripeStore.fetchingLandedCostAbordController = abortController;\n const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } =\n await calculateLandedCost(abortController);\n\n // reset abort controller after we are done\n stripeStore.fetchingLandedCostAbordController = null;\n\n // update cart store with landed cost info\n cartStore.landedCostData =\n checkoutSessionWorkflow?.filter(Boolean) || null;\n\n cartStore.shippingData =\n shipmentRatingCalculateWorkflow?.filter(Boolean) || null;\n // apply new subtotal and total, this is mainly to show items in the presentment currency\n const firstLandedCostData = cartStore.landedCostData?.find(Boolean);\n const subtotals = !!firstLandedCostData\n ? firstLandedCostData.subtotals\n : null;\n if (subtotals) {\n // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet\n cartStoreApplySubtotals({\n exchangeRate: subtotals.exchangeRate,\n items: subtotals.items,\n landedCostTotal: 0,\n presentmentCurrencyCode: subtotals.presentmentCurrencyCode,\n shipping: 0,\n total: subtotals.items,\n });\n }\n } catch (err) {\n logError(err);\n }\n stripeStore.isFetchingLandedCost = false;\n }\n};\n\nconst getStripeMessageBasedOnStatus = (status?: PaymentIntent['status']) => {\n let messages: string[] = [];\n let isError = true;\n // Inspect the PaymentIntent `status` to indicate the status of the payment\n // to your customer.\n //\n // Some payment methods will [immediately succeed or fail][0] upon\n // confirmation, while others will first enter a `processing` state.\n //\n // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification\n switch (status) {\n case 'succeeded': {\n messages = [\n translate(\n 'Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us.',\n ),\n '',\n '',\n translate(\n \"We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time.\",\n ),\n ];\n isError = false;\n break;\n }\n case 'requires_capture':\n case 'processing': {\n messages = [\n translate(\n \"Payment processing. We'll update you when payment is received.\",\n ),\n ];\n isError = false;\n break;\n }\n\n case 'requires_payment_method': {\n messages = [\n translate('Payment failed. Please try another payment method.'),\n ];\n break;\n }\n\n default: {\n messages = [translate('Something went wrong.')];\n break;\n }\n }\n return {\n isError,\n messages,\n };\n};\n\nconst stripeStoreRetrievePayment = async ({\n clientSecret: _clientSecret,\n storybookForceStatus,\n}: {\n clientSecret: string | null;\n storybookForceStatus?: PaymentIntent['status'];\n}) => {\n if (storybookForceStatus) {\n // return status right away if we are in storybook mode\n const { isError, messages } =\n getStripeMessageBasedOnStatus(storybookForceStatus);\n\n return { error: isError, messages };\n }\n const clientSecret = _clientSecret || stripeStore.clientSecret;\n if (!stripeStore.stripe || !clientSecret) {\n logError('Failed to retrieve payment intent. Stripe is not initialized');\n return { error: true, message: [translate('Something went wrong.')] };\n }\n const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(\n clientSecret,\n );\n\n const status = paymentIntent?.status;\n\n const { isError, messages } = getStripeMessageBasedOnStatus(status);\n\n return { error: isError, messages };\n};\n\nconst stripeStoreConfirmPayment = async () => {\n const stripePaymentReady = !!stripeStore.stripePaymentEventData?.complete;\n const stripeElements = stripeStore.stripeElements;\n const stripe = stripeStore.stripe;\n const stripeClientSecret = stripeStore.clientSecret;\n if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {\n const { error } = await stripe.confirmPayment({\n confirmParams: {\n receipt_email: stripeStore.stripeLinkEventData?.value?.email,\n return_url: window.location.href,\n },\n elements: stripeElements,\n redirect: 'if_required',\n });\n\n if (error) {\n if (error.type === 'card_error' || error.type === 'validation_error') {\n throw new Error(error.message);\n }\n if (error.type === 'invalid_request_error') {\n if (error.code === 'payment_intent_unexpected_state') {\n // PaymentIntent was canceled or expired, or status is `require_capture`.\n // don't throw error here because we will reset the checkout session last step\n return;\n }\n }\n throw new Error('An unexpected error occurred.');\n }\n }\n};\n\ntype CheckoutSessionCreateRequest = {\n currency: string;\n itemsAmount: number;\n presentmentCountryCode: CountryCode | null;\n};\n\n/**\n * Init checkout session\n * @returns {boolean} whether or not the checkout session is successfully created\n */\nconst stripeStoreInitCheckoutSession = async () => {\n const total = cartStore.items.reduce(\n (amount, item) => amount + item.amount * item.quantity,\n 0,\n );\n\n if (!total || !localizationStore.targetCurrency) {\n logError('Fail to create checkout session - invalid total or currency');\n return false;\n }\n\n stripeStore.isFetchingSession = true;\n\n const { errors, json } = await handleFetch<\n CheckoutSessionCreateMutation,\n CheckoutSessionCreateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/create-checkout-session`, {\n body: {\n currency: cartStore.items.find(Boolean)?.currencyCode || '',\n itemsAmount: total,\n presentmentCountryCode: localizationStore.selectedCountryCode || null,\n },\n method: 'POST',\n });\n\n stripeStore.isFetchingSession = false;\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when creating checkout session',\n JSON.stringify(errors, null, 2),\n );\n\n return false;\n }\n const result = json.checkoutSessionCreate;\n\n stripeStore.clientSecret = result.clientSecret;\n // update cart store with updated informations\n cartStore.checkoutSessionId = result.id;\n cartStoreApplySubtotals({\n ...result.subtotals,\n landedCostTotal: 0,\n shipping: 0,\n total: result.subtotals.items,\n });\n log(\n 'Exchange rate updated for cart items (checkout session create)',\n 'info',\n cartStore.exchangeRate,\n );\n\n log('done-init-checkout-session');\n return true;\n};\n\ntype CheckoutSessionUpdateRequest = {\n currency?: string;\n id: string;\n itemsAmount?: number;\n landedCostId?: string;\n presentmentCountryCode: CountryCode | null;\n};\n/**\n * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change\n */\nconst stripeStoreUpdateCheckoutSession = async ({\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n}: CheckoutSessionUpdateRequest) => {\n // No need to set loading state here because this function will be called under the hood to update\n // landed cost id for the section.\n const { errors, json } = await handleFetch<\n CheckoutSessionUpdateMutation,\n CheckoutSessionUpdateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/update-checkout-session`, {\n body: {\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n },\n method: 'POST',\n });\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when updating checkout session',\n JSON.stringify(errors, null, 2),\n );\n return { errors, json };\n }\n\n return { errors: [], json };\n};\n\nonChange('clientSecret', clientSecret => {\n // update stripe elements when client secret changes\n if (clientSecret && stripeStore.stripe) {\n sessionStorage.setItem('zonos--client-secret', clientSecret);\n }\n\n if (!clientSecret) {\n sessionStorage.removeItem('zonos--client-secret');\n }\n});\n\nexport {\n initStripeElements,\n stripeStore,\n stripeStoreConfirmPayment,\n stripeStoreInitCheckoutSession,\n stripeStorePrefetchLandedCost,\n stripeStoreReset,\n stripeStoreRetrievePayment,\n stripeStoreUpdateCheckoutSession,\n};\n"]}
@@ -7,6 +7,7 @@ export const isClientSide = typeof window !== 'undefined';
7
7
  export const inProdEnvironment = process.env.NODE_ENV === 'production';
8
8
  export const inTestEnvironment = process.env.NODE_ENV === 'test';
9
9
  export const inVercel = !!process.env.VERCEL;
10
+ const packageVersion = process.env.npm_package_version;
10
11
  if (typeof window === 'undefined') {
11
12
  // storybook can't access to any "node" modules
12
13
  config();
@@ -16,6 +17,7 @@ if (inVercel || !!process.env.CI) {
16
17
  CI: process.env.CI,
17
18
  NODE_ENV: process.env.NODE_ENV,
18
19
  inVercel,
20
+ packageVersion: packageVersion,
19
21
  }, null, 2));
20
22
  }
21
23
  const skipValidation = inTestEnvironment;
@@ -49,7 +51,13 @@ export const env = createEnv({
49
51
  runtimeEnvStrict: {
50
52
  NEXT_PUBLIC_FLAG_URL: process.env.NEXT_PUBLIC_FLAG_URL,
51
53
  NEXT_PUBLIC_ZONOS_API_KEY: process.env.NEXT_PUBLIC_ZONOS_API_KEY,
52
- NEXT_PUBLIC_ZONOS_CDN_URL: process.env.NEXT_PUBLIC_ZONOS_CDN_URL,
54
+ /**
55
+ * Use url with version in unpkg format if in Github CI and not vercel, otherwise use regular url
56
+ * @example unpkg.com/@zonos/elements@latest/dist/zonos-elements/zonos-elements.js
57
+ */
58
+ NEXT_PUBLIC_ZONOS_CDN_URL: !inVercel && process.env.CI
59
+ ? `${process.env.NEXT_PUBLIC_ZONOS_CDN_URL}@${packageVersion}`
60
+ : process.env.NEXT_PUBLIC_ZONOS_CDN_URL,
53
61
  NEXT_PUBLIC_ZONOS_ROUTE_URL: process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL,
54
62
  },
55
63
  });
@@ -1 +1 @@
1
- {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,+BAA+B;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAA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,GAAG,GAAG,SAAS,CAAC;EAC3B,cAAc;EACd,mDAAmD;EACnD,YAAY,EAAE,cAAc;EAC5B,eAAe,EAAE,QAAQ,CAAC,EAAE;IAC1B,MAAM,IAAI,KAAK,CACb,2EAA2E,QAAQ,EAAE,CACtF,CAAC;EACJ,CAAC;EACD,iBAAiB,EAAE,KAAK,CAAC,EAAE;IACzB,OAAO,CAAC,KAAK,CACX,kCAAkC,EAClC,KAAK,CAAC,OAAO,EAAE,CAAC,WAAW,CAC5B,CAAC;IACF,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;EACnD,CAAC;EACD,mDAAmD;EACnD,MAAM,EAAE,SAAS;EACjB,mDAAmD;EACnD,gBAAgB,EAAE;IAChB,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB;IACtD,yBAAyB,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;IAChE,yBAAyB,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;IAChE,2BAA2B,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B;GACrE;CACF,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAA0C,EAAE,CACvE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;EACrC,MAAM,OAAO,GAAG,IAAI,CAAC;EACrB,IAAI,OAAO,EAAE;IACX,mBAAmB;IACnB,IAAI,CAAC,eAAe,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;GAC5D;EACD,OAAO,IAAI,CAAC;AACd,CAAC,EAAE,EAAE,CAA0C,CAAC","sourcesContent":["/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable no-console */\nimport { createEnv } from '@t3-oss/env-core';\nimport { config } from 'dotenv';\nimport { z } from 'zod';\nexport const isClientSide = typeof window !== 'undefined';\n\nexport const inProdEnvironment = process.env.NODE_ENV === 'production';\nexport const inTestEnvironment = process.env.NODE_ENV === 'test';\n\nexport const inVercel = !!process.env.VERCEL;\n\nif (typeof window === 'undefined') {\n // storybook can't access to any \"node\" modules\n config();\n}\n\nif (inVercel || !!process.env.CI) {\n console.debug(\n JSON.stringify(\n {\n CI: process.env.CI,\n NODE_ENV: process.env.NODE_ENV,\n inVercel,\n },\n null,\n 2,\n ),\n );\n}\n\nconst skipValidation = inTestEnvironment;\n\nif (!skipValidation) {\n console.debug('Checking env variables');\n} else {\n console.debug('Skipping env validation');\n}\n\nconst envClient = {\n NEXT_PUBLIC_FLAG_URL: z.string(),\n NEXT_PUBLIC_ZONOS_API_KEY: z.string(),\n NEXT_PUBLIC_ZONOS_CDN_URL: z.string(),\n NEXT_PUBLIC_ZONOS_ROUTE_URL: z.string(),\n};\n\nconst envClientSchema = z.object(envClient);\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface Env extends z.infer<typeof envClientSchema> {}\n\nexport const env = createEnv({\n skipValidation,\n // eslint-disable-next-line sort-keys/sort-keys-fix\n clientPrefix: 'NEXT_PUBLIC_',\n onInvalidAccess: variable => {\n throw new Error(\n `❌ Attempted to access a server-side environment variable on the client: ${variable}`,\n );\n },\n onValidationError: error => {\n console.error(\n '❌ Invalid environment variables:',\n error.flatten().fieldErrors,\n );\n throw new Error('Invalid environment variables');\n },\n // eslint-disable-next-line sort-keys/sort-keys-fix\n client: envClient,\n // eslint-disable-next-line sort-keys/sort-keys-fix\n runtimeEnvStrict: {\n NEXT_PUBLIC_FLAG_URL: process.env.NEXT_PUBLIC_FLAG_URL,\n NEXT_PUBLIC_ZONOS_API_KEY: process.env.NEXT_PUBLIC_ZONOS_API_KEY,\n NEXT_PUBLIC_ZONOS_CDN_URL: process.env.NEXT_PUBLIC_ZONOS_CDN_URL,\n NEXT_PUBLIC_ZONOS_ROUTE_URL: process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL,\n },\n});\n\ntype Keys = keyof typeof env;\n\n/**\n * Env object that has all of native env variable used in code to replace them with\n * actual values from .env\n */\nexport const getReplaceEnv = (): Record<`process.env.${Keys}`, string> =>\n Object.keys(env).reduce((prev, curr) => {\n const currEnv = curr;\n if (currEnv) {\n // @ts-expect-error\n prev[`process.env.${currEnv}`] = `\"${env[currEnv] || ''}\"`;\n }\n return prev;\n }, {}) as Record<`process.env.${Keys}`, string>;\n"]}
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,+BAA+B;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAE1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AACvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC;AAEjE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;AAE7C,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;AAEvD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;EACjC,+CAA+C;EAC/C,MAAM,EAAE,CAAC;CACV;AAED,IAAI,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE;EAChC,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CACZ;IACE,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE;IAClB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;IAC9B,QAAQ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,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,cAAc,EAAE;MAC9D,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB;IAC3C,2BAA2B,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B;GACrE;CACF,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAA0C,EAAE,CACvE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;EACrC,MAAM,OAAO,GAAG,IAAI,CAAC;EACrB,IAAI,OAAO,EAAE;IACX,mBAAmB;IACnB,IAAI,CAAC,eAAe,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;GAC5D;EACD,OAAO,IAAI,CAAC;AACd,CAAC,EAAE,EAAE,CAA0C,CAAC","sourcesContent":["/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable no-console */\nimport { createEnv } from '@t3-oss/env-core';\nimport { config } from 'dotenv';\nimport { z } from 'zod';\nexport const isClientSide = typeof window !== 'undefined';\n\nexport const inProdEnvironment = process.env.NODE_ENV === 'production';\nexport const inTestEnvironment = process.env.NODE_ENV === 'test';\n\nexport const inVercel = !!process.env.VERCEL;\n\nconst packageVersion = process.env.npm_package_version;\n\nif (typeof window === 'undefined') {\n // storybook can't access to any \"node\" modules\n config();\n}\n\nif (inVercel || !!process.env.CI) {\n console.debug(\n JSON.stringify(\n {\n CI: process.env.CI,\n NODE_ENV: process.env.NODE_ENV,\n inVercel,\n packageVersion: packageVersion,\n },\n null,\n 2,\n ),\n );\n}\n\nconst skipValidation = inTestEnvironment;\n\nif (!skipValidation) {\n console.debug('Checking env variables');\n} else {\n console.debug('Skipping env validation');\n}\n\nconst envClient = {\n NEXT_PUBLIC_FLAG_URL: z.string(),\n NEXT_PUBLIC_ZONOS_API_KEY: z.string(),\n NEXT_PUBLIC_ZONOS_CDN_URL: z.string(),\n NEXT_PUBLIC_ZONOS_ROUTE_URL: z.string(),\n};\n\nconst envClientSchema = z.object(envClient);\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface Env extends z.infer<typeof envClientSchema> {}\n\nexport const env = createEnv({\n skipValidation,\n // eslint-disable-next-line sort-keys/sort-keys-fix\n clientPrefix: 'NEXT_PUBLIC_',\n onInvalidAccess: variable => {\n throw new Error(\n `❌ Attempted to access a server-side environment variable on the client: ${variable}`,\n );\n },\n onValidationError: error => {\n console.error(\n '❌ Invalid environment variables:',\n error.flatten().fieldErrors,\n );\n throw new Error('Invalid environment variables');\n },\n // eslint-disable-next-line sort-keys/sort-keys-fix\n client: envClient,\n // eslint-disable-next-line sort-keys/sort-keys-fix\n runtimeEnvStrict: {\n NEXT_PUBLIC_FLAG_URL: process.env.NEXT_PUBLIC_FLAG_URL,\n NEXT_PUBLIC_ZONOS_API_KEY: process.env.NEXT_PUBLIC_ZONOS_API_KEY,\n /**\n * Use url with version in unpkg format if in Github CI and not vercel, otherwise use regular url\n * @example unpkg.com/@zonos/elements@latest/dist/zonos-elements/zonos-elements.js\n */\n NEXT_PUBLIC_ZONOS_CDN_URL:\n !inVercel && process.env.CI\n ? `${process.env.NEXT_PUBLIC_ZONOS_CDN_URL}@${packageVersion}`\n : process.env.NEXT_PUBLIC_ZONOS_CDN_URL,\n NEXT_PUBLIC_ZONOS_ROUTE_URL: process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL,\n },\n});\n\ntype Keys = keyof typeof env;\n\n/**\n * Env object that has all of native env variable used in code to replace them with\n * actual values from .env\n */\nexport const getReplaceEnv = (): Record<`process.env.${Keys}`, string> =>\n Object.keys(env).reduce((prev, curr) => {\n const currEnv = curr;\n if (currEnv) {\n // @ts-expect-error\n prev[`process.env.${currEnv}`] = `\"${env[currEnv] || ''}\"`;\n }\n return prev;\n }, {}) as Record<`process.env.${Keys}`, string>;\n"]}
@@ -23,12 +23,12 @@ export const injectScript = (params) => {
23
23
  const queryString = params && !params.advancedFraudSignals ? '?advancedFraudSignals=false' : '';
24
24
  const script = document.createElement('script');
25
25
  script.src = `${V3_URL}${queryString}`;
26
- const headOrBody = document.head || document.body;
27
- if (!headOrBody) {
26
+ const headBody = document.head || document.body;
27
+ if (!headBody) {
28
28
  logError('Expected document.body not to be null. Stripe.js requires a <body> element.');
29
29
  return null;
30
30
  }
31
- headOrBody.appendChild(script);
31
+ headBody.appendChild(script);
32
32
  return script;
33
33
  };
34
34
  export const loadScript = (params) => {
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/scripts/stripe.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,iEAAiE;AAIjE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAEjE,MAAM,MAAM,GAAG,0BAA0B,CAAC;AAC1C,MAAM,YAAY,GAAG,2CAA2C,CAAC;AAEjE,MAAM,uBAAuB,GAC3B,kJAAkJ,CAAC;AAWrJ,MAAM,CAAC,MAAM,UAAU,GAAG,GAA6B,EAAE;EACvD,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CACvC,gBAAgB,MAAM,IAAI,CAC3B,CAAC;EAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACvC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,CAAC,MAAM,EAAE;MACX,SAAS;KACV;IAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;MAClC,SAAS;KACV;IAED,OAAO,MAAM,CAAC;GACf;EAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,IAAI,aAAa,GAA6C,IAAI,CAAC;AAEnE,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAyB,EACC,EAAE;EAC5B,MAA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B,CAAC,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAElC,EAAqB,EAAE;EACtB,MAAM,YAAY,GAAG;;;;;;MAMjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3B,CAAC;EAEA,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;IACjD,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvB,OAAO;GACR;EAED,IACE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;IAChC,OAAO,MAAM,CAAC,oBAAoB,KAAK,SAAS,EAChD;IACA,OAAO,MAAM,CAAC;GACf;EAED,QAAQ,CAAC,YAAY,CAAC,CAAC;AACzB,CAAC,CAAC","sourcesContent":["/* eslint-disable no-console */\n/** Loading stripe script extracted from stripe.js repository */\n\nimport type { Stripe, StripeConstructor } from '@stripe/stripe-js';\n\nimport { logError } from 'src/components/utils/logging/logError';\n\nconst V3_URL = 'https://js.stripe.com/v3';\nconst V3_URL_REGEX = /^https:\\/\\/js\\.stripe\\.com\\/v3\\/?(\\?.*)?$/;\n\nconst EXISTING_SCRIPT_MESSAGE =\n 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface LoadParams {\n advancedFraudSignals: boolean;\n}\n\nexport type LoadStripe = (\n ...args: Parameters<StripeConstructor>\n) => Promise<Stripe | null>;\n\nexport const findScript = (): HTMLScriptElement | null => {\n const scripts = document.querySelectorAll<HTMLScriptElement>(\n `script[src^=\"${V3_URL}\"]`,\n );\n\n for (let i = 0; i < scripts.length; i++) {\n const script = scripts[i];\n if (!script) {\n continue;\n }\n\n if (!V3_URL_REGEX.test(script.src)) {\n continue;\n }\n\n return script;\n }\n\n return null;\n};\n\nlet stripePromise: Promise<StripeConstructor | null> | null = null;\n\nexport const injectScript = (\n params: null | LoadParams,\n): HTMLScriptElement | null => {\n const queryString =\n params && !params.advancedFraudSignals ? '?advancedFraudSignals=false' : '';\n const script = document.createElement('script');\n script.src = `${V3_URL}${queryString}`;\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n logError(\n 'Expected document.body not to be null. Stripe.js requires a <body> element.',\n );\n\n return null;\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\nexport const loadScript = (\n params: null | LoadParams,\n): Promise<StripeConstructor | null> => {\n // Ensure that we only attempt to load Stripe.js at most once\n if (stripePromise !== null) {\n return stripePromise;\n }\n\n stripePromise = new Promise((resolve, reject) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n // Resolve to null when imported server side. This makes the module\n // safe to import in an isomorphic code base.\n resolve(null);\n return;\n }\n\n if (window.Stripe && params) {\n console.warn(EXISTING_SCRIPT_MESSAGE);\n }\n\n if (window.Stripe) {\n resolve(window.Stripe);\n return;\n }\n\n try {\n let script = findScript();\n\n if (script && params) {\n console.warn(EXISTING_SCRIPT_MESSAGE);\n } else if (!script) {\n script = injectScript(params);\n }\n\n script?.addEventListener('load', () => {\n if (window.Stripe) {\n resolve(window.Stripe);\n } else {\n reject(new Error('Stripe.js not available'));\n }\n });\n\n script?.addEventListener('error', () => {\n reject(new Error('Failed to load Stripe.js'));\n });\n } catch (error) {\n reject(error);\n return;\n }\n });\n\n return stripePromise;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst registerWrapper = (stripe: any, startTime: number): void => {\n if (!stripe || !stripe._registerWrapper) {\n return;\n }\n\n stripe._registerWrapper({ name: 'stripe-js', startTime });\n};\n\nexport const initStripe = (\n maybeStripe: StripeConstructor | null,\n args: Parameters<StripeConstructor>,\n startTime: number,\n): Stripe | null => {\n if (maybeStripe === null) {\n return null;\n }\n\n const stripe = maybeStripe.apply(undefined, args);\n registerWrapper(stripe, startTime);\n return stripe;\n};\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport const validateLoadParams = (params: {\n advancedFraudSignals: boolean;\n}): LoadParams | void => {\n const errorMessage = `invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ${JSON.stringify(params)}\n`;\n\n if (params === null || typeof params !== 'object') {\n logError(errorMessage);\n return;\n }\n\n if (\n Object.keys(params).length === 1 &&\n typeof params.advancedFraudSignals === 'boolean'\n ) {\n return params;\n }\n\n logError(errorMessage);\n};\n"]}
1
+ {"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/scripts/stripe.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,iEAAiE;AAIjE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAEjE,MAAM,MAAM,GAAG,0BAA0B,CAAC;AAC1C,MAAM,YAAY,GAAG,2CAA2C,CAAC;AAEjE,MAAM,uBAAuB,GAC3B,kJAAkJ,CAAC;AAWrJ,MAAM,CAAC,MAAM,UAAU,GAAG,GAA6B,EAAE;EACvD,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CACvC,gBAAgB,MAAM,IAAI,CAC3B,CAAC;EAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACvC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,CAAC,MAAM,EAAE;MACX,SAAS;KACV;IAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;MAClC,SAAS;KACV;IAED,OAAO,MAAM,CAAC;GACf;EAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,IAAI,aAAa,GAA6C,IAAI,CAAC;AAEnE,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAyB,EACC,EAAE;EAC5B,MAAM,WAAW,GACf,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,6BAA6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AC,MAElC,EAAqB,EAAE;EACtB,MAAM,YAAY,GAAG;;;;;;MAMjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3B,CAAC;EAEA,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;IACjD,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvB,OAAO;GACR;EAED,IACE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;IAChC,OAAO,MAAM,CAAC,oBAAoB,KAAK,SAAS,EAChD;IACA,OAAO,MAAM,CAAC;GACf;EAED,QAAQ,CAAC,YAAY,CAAC,CAAC;AACzB,CAAC,CAAC","sourcesContent":["/* eslint-disable no-console */\n/** Loading stripe script extracted from stripe.js repository */\n\nimport type { Stripe, StripeConstructor } from '@stripe/stripe-js';\n\nimport { logError } from 'src/components/utils/logging/logError';\n\nconst V3_URL = 'https://js.stripe.com/v3';\nconst V3_URL_REGEX = /^https:\\/\\/js\\.stripe\\.com\\/v3\\/?(\\?.*)?$/;\n\nconst EXISTING_SCRIPT_MESSAGE =\n 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface LoadParams {\n advancedFraudSignals: boolean;\n}\n\nexport type LoadStripe = (\n ...args: Parameters<StripeConstructor>\n) => Promise<Stripe | null>;\n\nexport const findScript = (): HTMLScriptElement | null => {\n const scripts = document.querySelectorAll<HTMLScriptElement>(\n `script[src^=\"${V3_URL}\"]`,\n );\n\n for (let i = 0; i < scripts.length; i++) {\n const script = scripts[i];\n if (!script) {\n continue;\n }\n\n if (!V3_URL_REGEX.test(script.src)) {\n continue;\n }\n\n return script;\n }\n\n return null;\n};\n\nlet stripePromise: Promise<StripeConstructor | null> | null = null;\n\nexport const injectScript = (\n params: null | LoadParams,\n): HTMLScriptElement | null => {\n const queryString =\n params && !params.advancedFraudSignals ? '?advancedFraudSignals=false' : '';\n const script = document.createElement('script');\n script.src = `${V3_URL}${queryString}`;\n\n const headBody = document.head || document.body;\n\n if (!headBody) {\n logError(\n 'Expected document.body not to be null. Stripe.js requires a <body> element.',\n );\n\n return null;\n }\n\n headBody.appendChild(script);\n\n return script;\n};\n\nexport const loadScript = (\n params: null | LoadParams,\n): Promise<StripeConstructor | null> => {\n // Ensure that we only attempt to load Stripe.js at most once\n if (stripePromise !== null) {\n return stripePromise;\n }\n\n stripePromise = new Promise((resolve, reject) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n // Resolve to null when imported server side. This makes the module\n // safe to import in an isomorphic code base.\n resolve(null);\n return;\n }\n\n if (window.Stripe && params) {\n console.warn(EXISTING_SCRIPT_MESSAGE);\n }\n\n if (window.Stripe) {\n resolve(window.Stripe);\n return;\n }\n\n try {\n let script = findScript();\n\n if (script && params) {\n console.warn(EXISTING_SCRIPT_MESSAGE);\n } else if (!script) {\n script = injectScript(params);\n }\n\n script?.addEventListener('load', () => {\n if (window.Stripe) {\n resolve(window.Stripe);\n } else {\n reject(new Error('Stripe.js not available'));\n }\n });\n\n script?.addEventListener('error', () => {\n reject(new Error('Failed to load Stripe.js'));\n });\n } catch (error) {\n reject(error);\n return;\n }\n });\n\n return stripePromise;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst registerWrapper = (stripe: any, startTime: number): void => {\n if (!stripe || !stripe._registerWrapper) {\n return;\n }\n\n stripe._registerWrapper({ name: 'stripe-js', startTime });\n};\n\nexport const initStripe = (\n maybeStripe: StripeConstructor | null,\n args: Parameters<StripeConstructor>,\n startTime: number,\n): Stripe | null => {\n if (maybeStripe === null) {\n return null;\n }\n\n const stripe = maybeStripe.apply(undefined, args);\n registerWrapper(stripe, startTime);\n return stripe;\n};\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport const validateLoadParams = (params: {\n advancedFraudSignals: boolean;\n}): LoadParams | void => {\n const errorMessage = `invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ${JSON.stringify(params)}\n`;\n\n if (params === null || typeof params !== 'object') {\n logError(errorMessage);\n return;\n }\n\n if (\n Object.keys(params).length === 1 &&\n typeof params.advancedFraudSignals === 'boolean'\n ) {\n return params;\n }\n\n logError(errorMessage);\n};\n"]}
@@ -1497,6 +1497,11 @@ export const stripeSubscriptionStatus = {
1497
1497
  Trialing: 'TRIALING',
1498
1498
  Unpaid: 'UNPAID',
1499
1499
  };
1500
+ export const taxCalculationType = {
1501
+ Cif: 'CIF',
1502
+ Custom: 'CUSTOM',
1503
+ Fob: 'FOB',
1504
+ };
1500
1505
  export const taxIdType = {
1501
1506
  Cnp: 'CNP',
1502
1507
  Dan: 'DAN',