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