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.
@@ -58,16 +58,14 @@ var createActionApi = (apiConfig, lifecycle) => ({
58
58
  var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
59
59
  const base = "/v1/storefront";
60
60
  function persistIdentification(result) {
61
- const sessionToken = result.token?.token;
61
+ const sessionToken = result.token?.token ?? apiConfig.authStorage.getTokens()?.access_token;
62
62
  if (sessionToken) {
63
63
  updateContactSession(() => ({
64
64
  sessionToken,
65
65
  contact: result.contact
66
66
  }));
67
67
  } else {
68
- updateContactSession(
69
- (current) => current ? { ...current, contact: result.contact } : null
70
- );
68
+ updateContactSession(() => null);
71
69
  }
72
70
  return result;
73
71
  }
@@ -212,11 +210,27 @@ var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
212
210
  },
213
211
  async get(params, options) {
214
212
  await lifecycle.ensureVisitorSession();
213
+ const queryParams = Object.fromEntries(
214
+ Object.entries(
215
+ options?.params || {}
216
+ ).filter(
217
+ ([name]) => !["token", "cart_token"].includes(name.toLowerCase())
218
+ )
219
+ );
220
+ const headers = Object.fromEntries(
221
+ Object.entries(options?.headers || {}).filter(
222
+ ([name]) => name.toLowerCase() !== "x-arky-cart-token"
223
+ )
224
+ );
215
225
  return apiConfig.httpClient.get(
216
226
  `${base}/carts/${params.id}`,
217
227
  {
218
228
  ...options,
219
- params: params.token ? { token: params.token } : options?.params
229
+ headers: {
230
+ ...headers,
231
+ ...params.token ? { "X-Arky-Cart-Token": params.token } : {}
232
+ },
233
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
220
234
  }
221
235
  );
222
236
  },
@@ -1441,7 +1455,8 @@ function createElements(stripe, config) {
1441
1455
  amount: config.amount,
1442
1456
  currency: normalizeCurrency(config.currency),
1443
1457
  paymentMethodCreation: "manual",
1444
- ...config.appearance ? { appearance: config.appearance } : {}
1458
+ ...config.appearance ? { appearance: config.appearance } : {},
1459
+ ...config.setupFutureUsage ? { setupFutureUsage: config.setupFutureUsage } : {}
1445
1460
  });
1446
1461
  }
1447
1462
 
@@ -1910,7 +1925,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
1910
1925
  }
1911
1926
  return result;
1912
1927
  }
1913
- async function mountStripePayment(target, options = {}) {
1928
+ async function mountPayment(target, options = {}) {
1914
1929
  await loadSetup();
1915
1930
  const publishableKey2 = currentStripePublishableKey();
1916
1931
  if (!publishableKey2) {
@@ -1934,7 +1949,8 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
1934
1949
  connectedAccountId: currentStripeConnectedAccountId() || void 0,
1935
1950
  amount,
1936
1951
  currency: paymentCurrency,
1937
- ...options.appearance ? { appearance: options.appearance } : {}
1952
+ ...options.appearance ? { appearance: options.appearance } : {},
1953
+ ...options.setupFutureUsage ? { setupFutureUsage: options.setupFutureUsage } : {}
1938
1954
  });
1939
1955
  controller.mount(target);
1940
1956
  setPaymentController(controller);
@@ -2015,8 +2031,16 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
2015
2031
  async function buildProductCartItem(item, source, productHint) {
2016
2032
  try {
2017
2033
  const product = productHint?.id === item.product_id ? productHint : await client.eshop.product.get({ id: item.product_id });
2018
- const variant = product.variants.find((candidate) => candidate.id === item.variant_id);
2019
- if (!variant) return null;
2034
+ const variant = product.variants.find(
2035
+ (candidate) => candidate.id === item.variant_id
2036
+ );
2037
+ if (!variant) {
2038
+ cart_status.setKey(
2039
+ "error",
2040
+ `Cart product ${item.product_id} references unavailable variant ${item.variant_id}.`
2041
+ );
2042
+ return null;
2043
+ }
2020
2044
  return {
2021
2045
  id: item.id || createId("product"),
2022
2046
  product_id: product.id,
@@ -2030,7 +2054,14 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
2030
2054
  added_at: source.created_at ? source.created_at * 1e3 : Date.now(),
2031
2055
  max_stock: availableStock(client, variant)
2032
2056
  };
2033
- } catch {
2057
+ } catch (error) {
2058
+ cart_status.setKey(
2059
+ "error",
2060
+ readErrorMessage(
2061
+ error,
2062
+ `Failed to load cart product ${item.product_id}.`
2063
+ )
2064
+ );
2034
2065
  return null;
2035
2066
  }
2036
2067
  }
@@ -2069,6 +2100,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
2069
2100
  promo_code.set(response.promo_code || null);
2070
2101
  quote.set(response.quote_snapshot || null);
2071
2102
  const items = response.items || [];
2103
+ if (items.length > 0) await loadSetup();
2072
2104
  const products = await Promise.all(
2073
2105
  items.filter((item) => item.type === "product").map((item) => buildProductCartItem(item, response, options.productHint))
2074
2106
  );
@@ -2987,7 +3019,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
2987
3019
  ready: payment_ready,
2988
3020
  setController: setPaymentController,
2989
3021
  getController: () => payment_controller.get(),
2990
- mountStripe: mountStripePayment,
3022
+ mount: mountPayment,
2991
3023
  update: updatePaymentController,
2992
3024
  destroy: destroyPaymentController
2993
3025
  },