arky-sdk 0.10.0 → 0.11.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.
package/dist/index.cjs CHANGED
@@ -65,16 +65,14 @@ var createActionApi = (apiConfig, lifecycle) => ({
65
65
  var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
66
66
  const base = "/v1/storefront";
67
67
  function persistIdentification(result) {
68
- const sessionToken = result.token?.token;
68
+ const sessionToken = result.token?.token ?? apiConfig.authStorage.getTokens()?.access_token;
69
69
  if (sessionToken) {
70
70
  updateContactSession(() => ({
71
71
  sessionToken,
72
72
  contact: result.contact
73
73
  }));
74
74
  } else {
75
- updateContactSession(
76
- (current) => current ? { ...current, contact: result.contact } : null
77
- );
75
+ updateContactSession(() => null);
78
76
  }
79
77
  return result;
80
78
  }
@@ -219,11 +217,27 @@ var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
219
217
  },
220
218
  async get(params, options) {
221
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
+ );
222
232
  return apiConfig.httpClient.get(
223
233
  `${base}/carts/${params.id}`,
224
234
  {
225
235
  ...options,
226
- 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
227
241
  }
228
242
  );
229
243
  },
@@ -4095,7 +4109,8 @@ function createElements(stripe, config) {
4095
4109
  amount: config.amount,
4096
4110
  currency: normalizeCurrency(config.currency),
4097
4111
  paymentMethodCreation: "manual",
4098
- ...config.appearance ? { appearance: config.appearance } : {}
4112
+ ...config.appearance ? { appearance: config.appearance } : {},
4113
+ ...config.setupFutureUsage ? { setupFutureUsage: config.setupFutureUsage } : {}
4099
4114
  });
4100
4115
  }
4101
4116
 
@@ -4564,7 +4579,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4564
4579
  }
4565
4580
  return result;
4566
4581
  }
4567
- async function mountStripePayment(target, options = {}) {
4582
+ async function mountPayment(target, options = {}) {
4568
4583
  await loadSetup();
4569
4584
  const publishableKey2 = currentStripePublishableKey();
4570
4585
  if (!publishableKey2) {
@@ -4588,7 +4603,8 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4588
4603
  connectedAccountId: currentStripeConnectedAccountId() || void 0,
4589
4604
  amount,
4590
4605
  currency: paymentCurrency,
4591
- ...options.appearance ? { appearance: options.appearance } : {}
4606
+ ...options.appearance ? { appearance: options.appearance } : {},
4607
+ ...options.setupFutureUsage ? { setupFutureUsage: options.setupFutureUsage } : {}
4592
4608
  });
4593
4609
  controller.mount(target);
4594
4610
  setPaymentController(controller);
@@ -4669,8 +4685,16 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4669
4685
  async function buildProductCartItem(item, source, productHint) {
4670
4686
  try {
4671
4687
  const product = productHint?.id === item.product_id ? productHint : await client.eshop.product.get({ id: item.product_id });
4672
- const variant = product.variants.find((candidate) => candidate.id === item.variant_id);
4673
- 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
+ }
4674
4698
  return {
4675
4699
  id: item.id || createId("product"),
4676
4700
  product_id: product.id,
@@ -4684,7 +4708,14 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4684
4708
  added_at: source.created_at ? source.created_at * 1e3 : Date.now(),
4685
4709
  max_stock: availableStock(client, variant)
4686
4710
  };
4687
- } 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
+ );
4688
4719
  return null;
4689
4720
  }
4690
4721
  }
@@ -4723,6 +4754,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4723
4754
  promo_code.set(response.promo_code || null);
4724
4755
  quote.set(response.quote_snapshot || null);
4725
4756
  const items = response.items || [];
4757
+ if (items.length > 0) await loadSetup();
4726
4758
  const products = await Promise.all(
4727
4759
  items.filter((item) => item.type === "product").map((item) => buildProductCartItem(item, response, options.productHint))
4728
4760
  );
@@ -5641,7 +5673,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
5641
5673
  ready: payment_ready,
5642
5674
  setController: setPaymentController,
5643
5675
  getController: () => payment_controller.get(),
5644
- mountStripe: mountStripePayment,
5676
+ mount: mountPayment,
5645
5677
  update: updatePaymentController,
5646
5678
  destroy: destroyPaymentController
5647
5679
  },
@@ -5796,7 +5828,7 @@ function initialize(publishableKey, options = {}) {
5796
5828
  }
5797
5829
 
5798
5830
  // src/index.ts
5799
- var SDK_VERSION = "0.10.0";
5831
+ var SDK_VERSION = "0.11.1";
5800
5832
  var SUPPORTED_FRAMEWORKS = [
5801
5833
  "astro",
5802
5834
  "react",