arky-sdk 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -725,6 +725,7 @@ interface StripeConfirmationTokenControllerConfig {
725
725
  amount: number;
726
726
  currency: string;
727
727
  appearance?: StripeElementsOptions["appearance"];
728
+ setupFutureUsage?: "off_session" | "on_session";
728
729
  }
729
730
  interface StripeConfirmationTokenOptions {
730
731
  return_url?: string;
@@ -763,7 +764,7 @@ type StorefrontProvider$1 = StorefrontDto<Provider>;
763
764
  type StorefrontService$1 = StorefrontDto<Service>;
764
765
  type StorefrontServiceProvider = StorefrontDto<ServiceProvider>;
765
766
  type ArkyPaymentController = StripeConfirmationTokenController;
766
- type ArkyStripePaymentMountOptions = Partial<Pick<StripeConfirmationTokenControllerConfig, "amount" | "currency" | "appearance">>;
767
+ type ArkyStripePaymentMountOptions = Partial<Pick<StripeConfirmationTokenControllerConfig, "amount" | "currency" | "appearance" | "setupFutureUsage">>;
767
768
  type ArkyStoreConfig = StorefrontOptions;
768
769
  interface ArkyStoreContext {
769
770
  locale?: string;
@@ -2200,7 +2201,7 @@ declare function initializeStoreCore(publishableKey: string, config: ArkyStoreCo
2200
2201
  ready: nanostores.ReadableAtom<boolean>;
2201
2202
  setController: (controller: StripeConfirmationTokenController | null) => StripeConfirmationTokenController | null;
2202
2203
  getController: () => StripeConfirmationTokenController | null;
2203
- mountStripe: (target: string | HTMLElement, options?: ArkyStripePaymentMountOptions) => Promise<StripeConfirmationTokenController>;
2204
+ mount: (target: string | HTMLElement, options?: ArkyStripePaymentMountOptions) => Promise<StripeConfirmationTokenController>;
2204
2205
  update: (input: {
2205
2206
  amount?: number;
2206
2207
  currency?: string;
@@ -2906,7 +2907,7 @@ type ArkyStore = ReturnType<typeof initialize>;
2906
2907
  type ArkyCartStore = ArkyStore["eshop"]["cart"];
2907
2908
  type ArkyServiceStore = ArkyStore["eshop"]["service"];
2908
2909
 
2909
- declare const SDK_VERSION = "0.10.0";
2910
+ declare const SDK_VERSION = "0.11.0";
2910
2911
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
2911
2912
 
2912
2913
  interface ApiConfig {
package/dist/index.d.ts CHANGED
@@ -725,6 +725,7 @@ interface StripeConfirmationTokenControllerConfig {
725
725
  amount: number;
726
726
  currency: string;
727
727
  appearance?: StripeElementsOptions["appearance"];
728
+ setupFutureUsage?: "off_session" | "on_session";
728
729
  }
729
730
  interface StripeConfirmationTokenOptions {
730
731
  return_url?: string;
@@ -763,7 +764,7 @@ type StorefrontProvider$1 = StorefrontDto<Provider>;
763
764
  type StorefrontService$1 = StorefrontDto<Service>;
764
765
  type StorefrontServiceProvider = StorefrontDto<ServiceProvider>;
765
766
  type ArkyPaymentController = StripeConfirmationTokenController;
766
- type ArkyStripePaymentMountOptions = Partial<Pick<StripeConfirmationTokenControllerConfig, "amount" | "currency" | "appearance">>;
767
+ type ArkyStripePaymentMountOptions = Partial<Pick<StripeConfirmationTokenControllerConfig, "amount" | "currency" | "appearance" | "setupFutureUsage">>;
767
768
  type ArkyStoreConfig = StorefrontOptions;
768
769
  interface ArkyStoreContext {
769
770
  locale?: string;
@@ -2200,7 +2201,7 @@ declare function initializeStoreCore(publishableKey: string, config: ArkyStoreCo
2200
2201
  ready: nanostores.ReadableAtom<boolean>;
2201
2202
  setController: (controller: StripeConfirmationTokenController | null) => StripeConfirmationTokenController | null;
2202
2203
  getController: () => StripeConfirmationTokenController | null;
2203
- mountStripe: (target: string | HTMLElement, options?: ArkyStripePaymentMountOptions) => Promise<StripeConfirmationTokenController>;
2204
+ mount: (target: string | HTMLElement, options?: ArkyStripePaymentMountOptions) => Promise<StripeConfirmationTokenController>;
2204
2205
  update: (input: {
2205
2206
  amount?: number;
2206
2207
  currency?: string;
@@ -2906,7 +2907,7 @@ type ArkyStore = ReturnType<typeof initialize>;
2906
2907
  type ArkyCartStore = ArkyStore["eshop"]["cart"];
2907
2908
  type ArkyServiceStore = ArkyStore["eshop"]["service"];
2908
2909
 
2909
- declare const SDK_VERSION = "0.10.0";
2910
+ declare const SDK_VERSION = "0.11.0";
2910
2911
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
2911
2912
 
2912
2913
  interface ApiConfig {
package/dist/index.js CHANGED
@@ -217,11 +217,27 @@ var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
217
217
  },
218
218
  async get(params, options) {
219
219
  await lifecycle.ensureVisitorSession();
220
+ const queryParams = Object.fromEntries(
221
+ Object.entries(
222
+ options?.params || {}
223
+ ).filter(
224
+ ([name]) => !["token", "cart_token"].includes(name.toLowerCase())
225
+ )
226
+ );
227
+ const headers = Object.fromEntries(
228
+ Object.entries(options?.headers || {}).filter(
229
+ ([name]) => name.toLowerCase() !== "x-arky-cart-token"
230
+ )
231
+ );
220
232
  return apiConfig.httpClient.get(
221
233
  `${base}/carts/${params.id}`,
222
234
  {
223
235
  ...options,
224
- params: params.token ? { token: params.token } : options?.params
236
+ headers: {
237
+ ...headers,
238
+ ...params.token ? { "X-Arky-Cart-Token": params.token } : {}
239
+ },
240
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
225
241
  }
226
242
  );
227
243
  },
@@ -4093,7 +4109,8 @@ function createElements(stripe, config) {
4093
4109
  amount: config.amount,
4094
4110
  currency: normalizeCurrency(config.currency),
4095
4111
  paymentMethodCreation: "manual",
4096
- ...config.appearance ? { appearance: config.appearance } : {}
4112
+ ...config.appearance ? { appearance: config.appearance } : {},
4113
+ ...config.setupFutureUsage ? { setupFutureUsage: config.setupFutureUsage } : {}
4097
4114
  });
4098
4115
  }
4099
4116
 
@@ -4562,7 +4579,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4562
4579
  }
4563
4580
  return result;
4564
4581
  }
4565
- async function mountStripePayment(target, options = {}) {
4582
+ async function mountPayment(target, options = {}) {
4566
4583
  await loadSetup();
4567
4584
  const publishableKey2 = currentStripePublishableKey();
4568
4585
  if (!publishableKey2) {
@@ -4586,7 +4603,8 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4586
4603
  connectedAccountId: currentStripeConnectedAccountId() || void 0,
4587
4604
  amount,
4588
4605
  currency: paymentCurrency,
4589
- ...options.appearance ? { appearance: options.appearance } : {}
4606
+ ...options.appearance ? { appearance: options.appearance } : {},
4607
+ ...options.setupFutureUsage ? { setupFutureUsage: options.setupFutureUsage } : {}
4590
4608
  });
4591
4609
  controller.mount(target);
4592
4610
  setPaymentController(controller);
@@ -4667,8 +4685,16 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4667
4685
  async function buildProductCartItem(item, source, productHint) {
4668
4686
  try {
4669
4687
  const product = productHint?.id === item.product_id ? productHint : await client.eshop.product.get({ id: item.product_id });
4670
- const variant = product.variants.find((candidate) => candidate.id === item.variant_id);
4671
- if (!variant) return null;
4688
+ const variant = product.variants.find(
4689
+ (candidate) => candidate.id === item.variant_id
4690
+ );
4691
+ if (!variant) {
4692
+ cart_status.setKey(
4693
+ "error",
4694
+ `Cart product ${item.product_id} references unavailable variant ${item.variant_id}.`
4695
+ );
4696
+ return null;
4697
+ }
4672
4698
  return {
4673
4699
  id: item.id || createId("product"),
4674
4700
  product_id: product.id,
@@ -4682,7 +4708,14 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4682
4708
  added_at: source.created_at ? source.created_at * 1e3 : Date.now(),
4683
4709
  max_stock: availableStock(client, variant)
4684
4710
  };
4685
- } catch {
4711
+ } catch (error) {
4712
+ cart_status.setKey(
4713
+ "error",
4714
+ readErrorMessage(
4715
+ error,
4716
+ `Failed to load cart product ${item.product_id}.`
4717
+ )
4718
+ );
4686
4719
  return null;
4687
4720
  }
4688
4721
  }
@@ -4721,6 +4754,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4721
4754
  promo_code.set(response.promo_code || null);
4722
4755
  quote.set(response.quote_snapshot || null);
4723
4756
  const items = response.items || [];
4757
+ if (items.length > 0) await loadSetup();
4724
4758
  const products = await Promise.all(
4725
4759
  items.filter((item) => item.type === "product").map((item) => buildProductCartItem(item, response, options.productHint))
4726
4760
  );
@@ -5639,7 +5673,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
5639
5673
  ready: payment_ready,
5640
5674
  setController: setPaymentController,
5641
5675
  getController: () => payment_controller.get(),
5642
- mountStripe: mountStripePayment,
5676
+ mount: mountPayment,
5643
5677
  update: updatePaymentController,
5644
5678
  destroy: destroyPaymentController
5645
5679
  },
@@ -5794,7 +5828,7 @@ function initialize(publishableKey, options = {}) {
5794
5828
  }
5795
5829
 
5796
5830
  // src/index.ts
5797
- var SDK_VERSION = "0.10.0";
5831
+ var SDK_VERSION = "0.11.0";
5798
5832
  var SUPPORTED_FRAMEWORKS = [
5799
5833
  "astro",
5800
5834
  "react",