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.js CHANGED
@@ -63,16 +63,14 @@ var createActionApi = (apiConfig, lifecycle) => ({
63
63
  var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
64
64
  const base = "/v1/storefront";
65
65
  function persistIdentification(result) {
66
- const sessionToken = result.token?.token;
66
+ const sessionToken = result.token?.token ?? apiConfig.authStorage.getTokens()?.access_token;
67
67
  if (sessionToken) {
68
68
  updateContactSession(() => ({
69
69
  sessionToken,
70
70
  contact: result.contact
71
71
  }));
72
72
  } else {
73
- updateContactSession(
74
- (current) => current ? { ...current, contact: result.contact } : null
75
- );
73
+ updateContactSession(() => null);
76
74
  }
77
75
  return result;
78
76
  }
@@ -217,11 +215,27 @@ var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
217
215
  },
218
216
  async get(params, options) {
219
217
  await lifecycle.ensureVisitorSession();
218
+ const queryParams = Object.fromEntries(
219
+ Object.entries(
220
+ options?.params || {}
221
+ ).filter(
222
+ ([name]) => !["token", "cart_token"].includes(name.toLowerCase())
223
+ )
224
+ );
225
+ const headers = Object.fromEntries(
226
+ Object.entries(options?.headers || {}).filter(
227
+ ([name]) => name.toLowerCase() !== "x-arky-cart-token"
228
+ )
229
+ );
220
230
  return apiConfig.httpClient.get(
221
231
  `${base}/carts/${params.id}`,
222
232
  {
223
233
  ...options,
224
- params: params.token ? { token: params.token } : options?.params
234
+ headers: {
235
+ ...headers,
236
+ ...params.token ? { "X-Arky-Cart-Token": params.token } : {}
237
+ },
238
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
225
239
  }
226
240
  );
227
241
  },
@@ -4093,7 +4107,8 @@ function createElements(stripe, config) {
4093
4107
  amount: config.amount,
4094
4108
  currency: normalizeCurrency(config.currency),
4095
4109
  paymentMethodCreation: "manual",
4096
- ...config.appearance ? { appearance: config.appearance } : {}
4110
+ ...config.appearance ? { appearance: config.appearance } : {},
4111
+ ...config.setupFutureUsage ? { setupFutureUsage: config.setupFutureUsage } : {}
4097
4112
  });
4098
4113
  }
4099
4114
 
@@ -4562,7 +4577,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4562
4577
  }
4563
4578
  return result;
4564
4579
  }
4565
- async function mountStripePayment(target, options = {}) {
4580
+ async function mountPayment(target, options = {}) {
4566
4581
  await loadSetup();
4567
4582
  const publishableKey2 = currentStripePublishableKey();
4568
4583
  if (!publishableKey2) {
@@ -4586,7 +4601,8 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4586
4601
  connectedAccountId: currentStripeConnectedAccountId() || void 0,
4587
4602
  amount,
4588
4603
  currency: paymentCurrency,
4589
- ...options.appearance ? { appearance: options.appearance } : {}
4604
+ ...options.appearance ? { appearance: options.appearance } : {},
4605
+ ...options.setupFutureUsage ? { setupFutureUsage: options.setupFutureUsage } : {}
4590
4606
  });
4591
4607
  controller.mount(target);
4592
4608
  setPaymentController(controller);
@@ -4667,8 +4683,16 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4667
4683
  async function buildProductCartItem(item, source, productHint) {
4668
4684
  try {
4669
4685
  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;
4686
+ const variant = product.variants.find(
4687
+ (candidate) => candidate.id === item.variant_id
4688
+ );
4689
+ if (!variant) {
4690
+ cart_status.setKey(
4691
+ "error",
4692
+ `Cart product ${item.product_id} references unavailable variant ${item.variant_id}.`
4693
+ );
4694
+ return null;
4695
+ }
4672
4696
  return {
4673
4697
  id: item.id || createId("product"),
4674
4698
  product_id: product.id,
@@ -4682,7 +4706,14 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4682
4706
  added_at: source.created_at ? source.created_at * 1e3 : Date.now(),
4683
4707
  max_stock: availableStock(client, variant)
4684
4708
  };
4685
- } catch {
4709
+ } catch (error) {
4710
+ cart_status.setKey(
4711
+ "error",
4712
+ readErrorMessage(
4713
+ error,
4714
+ `Failed to load cart product ${item.product_id}.`
4715
+ )
4716
+ );
4686
4717
  return null;
4687
4718
  }
4688
4719
  }
@@ -4721,6 +4752,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
4721
4752
  promo_code.set(response.promo_code || null);
4722
4753
  quote.set(response.quote_snapshot || null);
4723
4754
  const items = response.items || [];
4755
+ if (items.length > 0) await loadSetup();
4724
4756
  const products = await Promise.all(
4725
4757
  items.filter((item) => item.type === "product").map((item) => buildProductCartItem(item, response, options.productHint))
4726
4758
  );
@@ -5639,7 +5671,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
5639
5671
  ready: payment_ready,
5640
5672
  setController: setPaymentController,
5641
5673
  getController: () => payment_controller.get(),
5642
- mountStripe: mountStripePayment,
5674
+ mount: mountPayment,
5643
5675
  update: updatePaymentController,
5644
5676
  destroy: destroyPaymentController
5645
5677
  },
@@ -5794,7 +5826,7 @@ function initialize(publishableKey, options = {}) {
5794
5826
  }
5795
5827
 
5796
5828
  // src/index.ts
5797
- var SDK_VERSION = "0.10.0";
5829
+ var SDK_VERSION = "0.11.1";
5798
5830
  var SUPPORTED_FRAMEWORKS = [
5799
5831
  "astro",
5800
5832
  "react",