arky-sdk 0.8.0 → 0.9.6

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.
@@ -142,6 +142,12 @@ function normalizeOrderCheckoutItems(items) {
142
142
  return { type: "service", ...item };
143
143
  });
144
144
  }
145
+ function normalizePublicCheckoutItems(items) {
146
+ return normalizeOrderCheckoutItems(items).map((item) => {
147
+ const { price: _price, ...publicItem } = item;
148
+ return publicItem;
149
+ });
150
+ }
145
151
 
146
152
  // src/api/storefront.ts
147
153
  var COMMON_ACTIVITY_TYPES = [
@@ -173,7 +179,7 @@ var createActivityApi = (apiConfig) => ({
173
179
  }
174
180
  }
175
181
  });
176
- var createStorefrontApi = (apiConfig, updateCustomerSession) => {
182
+ var createStorefrontApi = (apiConfig, updateProfileSession) => {
177
183
  const base = (storeId = apiConfig.storeId) => `/v1/storefront/${storeId}`;
178
184
  return {
179
185
  store: {
@@ -357,7 +363,7 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
357
363
  {
358
364
  ...payload,
359
365
  store_id: target,
360
- ...items ? { items: normalizeOrderCheckoutItems(items) } : {}
366
+ ...items ? { items: normalizePublicCheckoutItems(items) } : {}
361
367
  },
362
368
  options
363
369
  );
@@ -370,7 +376,7 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
370
376
  {
371
377
  ...payload,
372
378
  store_id: target,
373
- item: normalizeOrderCheckoutItems([item])[0]
379
+ item: normalizePublicCheckoutItems([item])[0]
374
380
  },
375
381
  options
376
382
  );
@@ -494,11 +500,11 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
494
500
  }
495
501
  },
496
502
  crm: {
497
- customer: {
503
+ profile: {
498
504
  async identify(params, options) {
499
505
  const store_id = apiConfig.storeId;
500
506
  const result = await apiConfig.httpClient.post(
501
- `${base(store_id)}/customers/identify`,
507
+ `${base(store_id)}/profiles/identify`,
502
508
  {
503
509
  store_id,
504
510
  market: params?.market || apiConfig.market || null,
@@ -508,9 +514,9 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
508
514
  options
509
515
  );
510
516
  if (result?.token?.token) {
511
- updateCustomerSession(() => ({
517
+ updateProfileSession(() => ({
512
518
  access_token: result.token.token,
513
- customer: result.customer,
519
+ profile: result.profile,
514
520
  store: result.store,
515
521
  market: result.market
516
522
  }));
@@ -520,12 +526,12 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
520
526
  async verify(params, options) {
521
527
  const store_id = apiConfig.storeId;
522
528
  const result = await apiConfig.httpClient.post(
523
- `${base(store_id)}/customers/verify`,
529
+ `${base(store_id)}/profiles/verify`,
524
530
  { store_id, code: params.code },
525
531
  options
526
532
  );
527
533
  if (result?.token) {
528
- updateCustomerSession(
534
+ updateProfileSession(
529
535
  (prev) => prev ? { ...prev, access_token: result.token } : null
530
536
  );
531
537
  }
@@ -535,132 +541,63 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
535
541
  const store_id = apiConfig.storeId;
536
542
  try {
537
543
  await apiConfig.httpClient.post(
538
- `${base(store_id)}/customers/logout`,
544
+ `${base(store_id)}/profiles/logout`,
539
545
  {},
540
546
  options
541
547
  );
542
548
  } finally {
543
- updateCustomerSession(() => null);
549
+ updateProfileSession(() => null);
544
550
  }
545
551
  },
546
552
  getMe(options) {
547
- return apiConfig.httpClient.get(`${base()}/customers/me`, options);
553
+ return apiConfig.httpClient.get(`${base()}/profiles/me`, options);
548
554
  }
549
555
  },
550
- audience: {
556
+ profileList: {
551
557
  get(params, options) {
552
- let identifier;
553
- if (params.id) {
554
- identifier = params.id;
555
- } else if (params.key) {
556
- identifier = `${apiConfig.storeId}:${params.key}`;
557
- } else {
558
- throw new Error("GetAudienceParams requires id or key");
559
- }
558
+ const store_id = params.store_id || apiConfig.storeId;
560
559
  return apiConfig.httpClient.get(
561
- `${base(apiConfig.storeId)}/audiences/${identifier}`,
560
+ `${base(store_id)}/profile-lists/${params.id}`,
562
561
  options
563
562
  );
564
563
  },
565
564
  find(params, options) {
566
- return apiConfig.httpClient.get(`${base()}/audiences`, {
565
+ const { store_id, ...queryParams } = params || {};
566
+ return apiConfig.httpClient.get(`${base(store_id)}/profile-lists`, {
567
567
  ...options,
568
- params
568
+ params: queryParams
569
569
  });
570
570
  },
571
571
  subscribe(params, options) {
572
+ const { store_id, id, ...payload } = params;
572
573
  return apiConfig.httpClient.post(
573
- `${base()}/audiences/${params.id}/subscribe`,
574
- {
575
- customer_id: params.customer_id,
576
- price_id: params.price_id,
577
- success_url: params.success_url,
578
- cancel_url: params.cancel_url,
579
- confirm_url: params.confirm_url
580
- },
574
+ `${base(store_id)}/profile-lists/${id}/subscribe`,
575
+ payload,
581
576
  options
582
577
  );
583
578
  },
584
579
  checkAccess(params, options) {
580
+ const store_id = params.store_id || apiConfig.storeId;
585
581
  return apiConfig.httpClient.get(
586
- `${base()}/audiences/${params.id}/access`,
582
+ `${base(store_id)}/profile-lists/${params.id}/access`,
587
583
  options
588
584
  );
589
585
  },
590
586
  unsubscribe(token, options) {
591
- return apiConfig.httpClient.get(`${base()}/audiences/unsubscribe`, {
587
+ return apiConfig.httpClient.get(`${base()}/profile-lists/unsubscribe`, {
592
588
  ...options,
593
589
  params: { token }
594
590
  });
595
591
  },
596
592
  confirm(token, options) {
597
- return apiConfig.httpClient.get(`${base()}/audiences/confirm`, {
593
+ return apiConfig.httpClient.get(`${base()}/profile-lists/confirm`, {
598
594
  ...options,
599
595
  params: { token }
600
596
  });
601
597
  }
602
598
  }
603
599
  },
604
- activity: createActivityApi(apiConfig),
605
- automation: {
606
- agent: {
607
- getAgents(params, options) {
608
- const store_id = params?.store_id || apiConfig.storeId;
609
- const queryParams = { ...params || {} };
610
- delete queryParams.store_id;
611
- return apiConfig.httpClient.get(`${base(store_id)}/agents`, {
612
- ...options,
613
- params: Object.keys(queryParams).length > 0 ? queryParams : void 0
614
- });
615
- },
616
- getAgent(params, options) {
617
- const store_id = params.store_id || apiConfig.storeId;
618
- return apiConfig.httpClient.get(
619
- `${base(store_id)}/agents/${params.id}`,
620
- options
621
- );
622
- },
623
- sendMessage(params, options) {
624
- const store_id = params.store_id || apiConfig.storeId;
625
- const body = { message: params.message };
626
- if (params.chat_id) body.chat_id = params.chat_id;
627
- return apiConfig.httpClient.post(
628
- `${base(store_id)}/agents/${params.id}/chats/messages`,
629
- body,
630
- options
631
- );
632
- },
633
- getChat(params, options) {
634
- const store_id = params.store_id || apiConfig.storeId;
635
- return apiConfig.httpClient.get(
636
- `${base(store_id)}/agents/${params.id}/chats/${params.chat_id}`,
637
- options
638
- );
639
- },
640
- getChatMessages(params, options) {
641
- const store_id = params.store_id || apiConfig.storeId;
642
- const queryParams = {};
643
- if (params.limit) queryParams.limit = String(params.limit);
644
- return apiConfig.httpClient.get(
645
- `${base(store_id)}/agents/${params.id}/chats/${params.chat_id}/messages`,
646
- {
647
- ...options,
648
- params: Object.keys(queryParams).length > 0 ? queryParams : void 0
649
- }
650
- );
651
- },
652
- rateChat(params, options) {
653
- const store_id = params.store_id || apiConfig.storeId;
654
- const body = { rating: params.rating };
655
- if (params.comment) body.comment = params.comment;
656
- return apiConfig.httpClient.post(
657
- `${base(store_id)}/agents/${params.id}/chats/${params.chat_id}/rate`,
658
- body,
659
- options
660
- );
661
- }
662
- }
663
- }
600
+ activity: createActivityApi(apiConfig)
664
601
  };
665
602
  };
666
603
 
@@ -995,6 +932,41 @@ function createHttpClient(cfg) {
995
932
  };
996
933
  }
997
934
 
935
+ // src/api/support.ts
936
+ function supportConversationQuery(params) {
937
+ const qs = new URLSearchParams({ store_id: params.store_id });
938
+ if (params.message_limit) qs.set("message_limit", String(params.message_limit));
939
+ if (typeof params.after_created_at === "number") qs.set("after_created_at", String(params.after_created_at));
940
+ if (params.after_id) qs.set("after_id", params.after_id);
941
+ return qs.toString();
942
+ }
943
+ function createStorefrontSupportApi(config) {
944
+ const { httpClient, storeId } = config;
945
+ return {
946
+ async startConversation(params = {}, opts) {
947
+ return httpClient.post(
948
+ `/v1/storefront/${storeId}/support/conversations`,
949
+ { store_id: storeId, ...params },
950
+ opts
951
+ );
952
+ },
953
+ async sendMessage(params, opts) {
954
+ return httpClient.post(
955
+ `/v1/storefront/${storeId}/support/conversations/${params.conversation_id}/messages`,
956
+ { store_id: storeId, ...params },
957
+ opts
958
+ );
959
+ },
960
+ async getConversation(params, opts) {
961
+ const qs = supportConversationQuery({ store_id: storeId, ...params });
962
+ return httpClient.get(
963
+ `/v1/storefront/${storeId}/support/conversations/${params.conversation_id}?${qs}`,
964
+ opts
965
+ );
966
+ }
967
+ };
968
+ }
969
+
998
970
  // src/utils/price.ts
999
971
  function formatCurrency(amount, currencyCode, locale = "en") {
1000
972
  if (!currencyCode) return "";
@@ -1284,22 +1256,22 @@ function createUtilitySurface(apiConfig) {
1284
1256
  getFirstAvailableFCId
1285
1257
  };
1286
1258
  }
1287
- var CUSTOMER_STORAGE_KEY = "arky_customer_session";
1288
- function readCustomerSession() {
1259
+ var PROFILE_STORAGE_KEY = "arky_profile_session";
1260
+ function readProfileSession() {
1289
1261
  if (typeof window === "undefined") return null;
1290
1262
  try {
1291
- const raw = localStorage.getItem(CUSTOMER_STORAGE_KEY);
1263
+ const raw = localStorage.getItem(PROFILE_STORAGE_KEY);
1292
1264
  return raw ? JSON.parse(raw) : null;
1293
1265
  } catch {
1294
1266
  return null;
1295
1267
  }
1296
1268
  }
1297
- function writeCustomerSession(s) {
1269
+ function writeProfileSession(s) {
1298
1270
  if (typeof window === "undefined") return;
1299
1271
  if (s) {
1300
- localStorage.setItem(CUSTOMER_STORAGE_KEY, JSON.stringify(s));
1272
+ localStorage.setItem(PROFILE_STORAGE_KEY, JSON.stringify(s));
1301
1273
  } else {
1302
- localStorage.removeItem(CUSTOMER_STORAGE_KEY);
1274
+ localStorage.removeItem(PROFILE_STORAGE_KEY);
1303
1275
  }
1304
1276
  }
1305
1277
  function createStorefront(config) {
@@ -1308,10 +1280,10 @@ function createStorefront(config) {
1308
1280
  const listeners = /* @__PURE__ */ new Set();
1309
1281
  let bareIdentifyPromise = null;
1310
1282
  function toPublic(s) {
1311
- return s ? { customer: s.customer, store: s.store, market: s.market } : null;
1283
+ return s ? { profile: s.profile, store: s.store, market: s.market } : null;
1312
1284
  }
1313
1285
  function emit() {
1314
- const pub = toPublic(readCustomerSession());
1286
+ const pub = toPublic(readProfileSession());
1315
1287
  for (const l of listeners) {
1316
1288
  Promise.resolve().then(() => l(pub)).catch(() => {
1317
1289
  });
@@ -1319,9 +1291,9 @@ function createStorefront(config) {
1319
1291
  }
1320
1292
  const updateSession = (updater) => {
1321
1293
  if (config.apiToken) return;
1322
- const prev = readCustomerSession();
1294
+ const prev = readProfileSession();
1323
1295
  const next = updater(prev);
1324
- writeCustomerSession(next);
1296
+ writeProfileSession(next);
1325
1297
  emit();
1326
1298
  };
1327
1299
  const authStorage = config.apiToken ? {
@@ -1332,7 +1304,7 @@ function createStorefront(config) {
1332
1304
  }
1333
1305
  } : {
1334
1306
  getTokens() {
1335
- const s = readCustomerSession();
1307
+ const s = readProfileSession();
1336
1308
  return s ? { access_token: s.access_token } : null;
1337
1309
  },
1338
1310
  onTokensRefreshed() {
@@ -1359,20 +1331,20 @@ function createStorefront(config) {
1359
1331
  authStorage
1360
1332
  };
1361
1333
  const storefrontApi = createStorefrontApi(apiConfig, updateSession);
1362
- const customerApi = storefrontApi.crm.customer;
1334
+ const profileApi = storefrontApi.crm.profile;
1363
1335
  function identify(params) {
1364
1336
  if (params?.market !== void 0) apiConfig.market = params.market;
1365
1337
  const isBareCall = !params?.email && !params?.verify;
1366
1338
  if (isBareCall && bareIdentifyPromise) return bareIdentifyPromise;
1367
1339
  const promise = (async () => {
1368
1340
  try {
1369
- const result = await customerApi.identify({
1341
+ const result = await profileApi.identify({
1370
1342
  market: apiConfig.market,
1371
1343
  email: params?.email,
1372
1344
  verify: params?.verify
1373
1345
  });
1374
1346
  return {
1375
- customer: result.customer,
1347
+ profile: result.profile,
1376
1348
  store: result.store,
1377
1349
  market: result.market
1378
1350
  };
@@ -1381,9 +1353,9 @@ function createStorefront(config) {
1381
1353
  const status = e?.statusCode || e?.status || e?.response?.status;
1382
1354
  if (isBareCall && status === 401) {
1383
1355
  updateSession(() => null);
1384
- const result = await customerApi.identify({ market: apiConfig.market });
1356
+ const result = await profileApi.identify({ market: apiConfig.market });
1385
1357
  return {
1386
- customer: result.customer,
1358
+ profile: result.profile,
1387
1359
  store: result.store,
1388
1360
  market: result.market
1389
1361
  };
@@ -1398,7 +1370,7 @@ function createStorefront(config) {
1398
1370
  return promise;
1399
1371
  }
1400
1372
  async function verify(params) {
1401
- const result = await customerApi.verify(params);
1373
+ const result = await profileApi.verify(params);
1402
1374
  bareIdentifyPromise = null;
1403
1375
  return result;
1404
1376
  }
@@ -1406,7 +1378,7 @@ function createStorefront(config) {
1406
1378
  if (config.apiToken) return;
1407
1379
  bareIdentifyPromise = null;
1408
1380
  try {
1409
- await customerApi.logout();
1381
+ await profileApi.logout();
1410
1382
  } catch {
1411
1383
  updateSession(() => null);
1412
1384
  }
@@ -1415,19 +1387,19 @@ function createStorefront(config) {
1415
1387
  identify,
1416
1388
  verify,
1417
1389
  logout,
1418
- me: () => customerApi.getMe(),
1390
+ me: () => profileApi.getMe(),
1419
1391
  get session() {
1420
1392
  if (config.apiToken) return null;
1421
- return toPublic(readCustomerSession());
1393
+ return toPublic(readProfileSession());
1422
1394
  },
1423
1395
  get isAuthenticated() {
1424
1396
  if (config.apiToken) return true;
1425
- const s = readCustomerSession();
1397
+ const s = readProfileSession();
1426
1398
  return s !== null && !!s.access_token;
1427
1399
  },
1428
1400
  onAuthStateChanged(listener) {
1429
1401
  listeners.add(listener);
1430
- const current = toPublic(readCustomerSession());
1402
+ const current = toPublic(readProfileSession());
1431
1403
  if (current) {
1432
1404
  Promise.resolve().then(() => listener(current)).catch(() => {
1433
1405
  });
@@ -1442,7 +1414,7 @@ function createStorefront(config) {
1442
1414
  eshop: storefrontApi.eshop,
1443
1415
  crm: storefrontApi.crm,
1444
1416
  activity: storefrontApi.activity,
1445
- automation: storefrontApi.automation,
1417
+ support: createStorefrontSupportApi(apiConfig),
1446
1418
  setStoreId: (storeId) => {
1447
1419
  apiConfig.storeId = storeId;
1448
1420
  bareIdentifyPromise = null;
@@ -1513,7 +1485,7 @@ function priceForMarket(prices, market, fallbackCurrency) {
1513
1485
  market: price?.market || market,
1514
1486
  currency: price?.currency || fallbackCurrency || "",
1515
1487
  compare_at: price?.compare_at,
1516
- audience_id: price?.audience_id
1488
+ profile_list_id: price?.profile_list_id
1517
1489
  };
1518
1490
  }
1519
1491
  function availableStock(client, variant) {
@@ -1561,8 +1533,7 @@ function toServiceCheckoutItems(items) {
1561
1533
  service_id: item.service_id,
1562
1534
  provider_id: item.provider_id,
1563
1535
  slots: [slot],
1564
- forms: item.forms || [],
1565
- price: item.price
1536
+ forms: item.forms || []
1566
1537
  });
1567
1538
  }
1568
1539
  return [...groups.values()].map((item) => ({
@@ -1709,18 +1680,46 @@ function createArkyStore(config) {
1709
1680
  selected_shipping_method_id: null,
1710
1681
  user_token: null
1711
1682
  });
1683
+ function rawProductItemCount(value) {
1684
+ return (value?.items || []).reduce((total, item) => {
1685
+ if (item.type !== "product") return total;
1686
+ return total + (item.quantity || 0);
1687
+ }, 0);
1688
+ }
1689
+ function rawServiceItemCount(value) {
1690
+ return (value?.items || []).reduce((total, item) => {
1691
+ if (item.type !== "service") return total;
1692
+ return total + Math.max(1, item.slots?.length || 0);
1693
+ }, 0);
1694
+ }
1712
1695
  const product_item_count = nanostores.computed(
1713
- product_items,
1714
- (items) => items.reduce((total, item) => total + (item.quantity || 0), 0)
1696
+ [cart, product_items],
1697
+ (cartValue, items) => Math.max(
1698
+ rawProductItemCount(cartValue),
1699
+ items.reduce((total, item) => total + (item.quantity || 0), 0)
1700
+ )
1701
+ );
1702
+ const service_item_count = nanostores.computed(
1703
+ [cart, service_items],
1704
+ (cartValue, items) => Math.max(rawServiceItemCount(cartValue), items.length)
1705
+ );
1706
+ const item_count = nanostores.computed(
1707
+ [cart, product_item_count, service_item_count],
1708
+ (cartValue, products, services) => Math.max(cartValue?.item_count || 0, products + services)
1715
1709
  );
1716
- const service_item_count = nanostores.computed(service_items, (items) => items.length);
1717
- const item_count = nanostores.computed([product_item_count, service_item_count], (products, services) => products + services);
1718
1710
  const snapshot = nanostores.computed([cart, product_items, service_items, item_count], (cartValue, products, services, count) => ({
1719
1711
  cart: cartValue,
1720
1712
  product_items: products,
1721
1713
  service_items: services,
1722
1714
  item_count: count
1723
1715
  }));
1716
+ let cartWriteRevision = 0;
1717
+ let sessionRequest = null;
1718
+ let cartRequest = null;
1719
+ function nextCartWriteRevision() {
1720
+ cartWriteRevision += 1;
1721
+ return cartWriteRevision;
1722
+ }
1724
1723
  const cms_state = nanostores.map({
1725
1724
  nodes: {},
1726
1725
  forms: {},
@@ -1768,7 +1767,12 @@ function createArkyStore(config) {
1768
1767
  const current = session.get();
1769
1768
  const marketKey = currentMarketKey();
1770
1769
  if (current && (!marketKey || current.market?.key === marketKey)) return current;
1771
- return identify({ market: marketKey });
1770
+ if (!sessionRequest) {
1771
+ sessionRequest = identify({ market: marketKey }).finally(() => {
1772
+ sessionRequest = null;
1773
+ });
1774
+ }
1775
+ return sessionRequest;
1772
1776
  }
1773
1777
  async function identify(params = {}) {
1774
1778
  if (params.market) setMarket(params.market);
@@ -1794,17 +1798,23 @@ function createArkyStore(config) {
1794
1798
  if (context.market) setMarket(context.market);
1795
1799
  }
1796
1800
  async function ensureCart() {
1801
+ if (cartRequest) return cartRequest;
1797
1802
  cart_status.setKey("loading", true);
1798
1803
  cart_status.setKey("error", null);
1799
- try {
1804
+ const refreshRevision = cartWriteRevision;
1805
+ cartRequest = (async () => {
1800
1806
  await ensureSession();
1801
1807
  const response = await client.cart.refresh({ market: currentMarketKey() });
1802
- await hydrateCart(response);
1808
+ await hydrateCart(response, { ifRevision: refreshRevision });
1803
1809
  return response;
1810
+ })();
1811
+ try {
1812
+ return await cartRequest;
1804
1813
  } catch (error) {
1805
1814
  cart_status.setKey("error", readErrorMessage(error, "Failed to load cart."));
1806
1815
  throw error;
1807
1816
  } finally {
1817
+ cartRequest = null;
1808
1818
  cart_status.setKey("loading", false);
1809
1819
  }
1810
1820
  }
@@ -1850,7 +1860,6 @@ function createArkyStore(config) {
1850
1860
  from: slot.from,
1851
1861
  to: slot.to,
1852
1862
  forms: item.forms || [],
1853
- price: item.price,
1854
1863
  service_name: service ? serviceName(service, currentLocale()) : item.service_id,
1855
1864
  provider_name: provider ? providerName(provider, currentLocale()) : item.provider_id
1856
1865
  });
@@ -1858,7 +1867,10 @@ function createArkyStore(config) {
1858
1867
  }
1859
1868
  return rows;
1860
1869
  }
1861
- async function hydrateCart(response) {
1870
+ async function hydrateCart(response, options = {}) {
1871
+ if (options.ifRevision !== void 0 && options.ifRevision !== cartWriteRevision) {
1872
+ return cart.get() || response;
1873
+ }
1862
1874
  cart.set(response);
1863
1875
  cart_status.setKey("user_token", response.token || null);
1864
1876
  cart_status.setKey("selected_shipping_method_id", response.shipping_method_id || null);
@@ -1881,7 +1893,7 @@ function createArkyStore(config) {
1881
1893
  ...toServiceCheckoutItems(input.service_items || service_items.get())
1882
1894
  ];
1883
1895
  }
1884
- async function syncCart(input = {}) {
1896
+ async function syncCart(input = {}, writeRevision = nextCartWriteRevision()) {
1885
1897
  cart_status.setKey("syncing", true);
1886
1898
  cart_status.setKey("error", null);
1887
1899
  try {
@@ -1901,7 +1913,7 @@ function createArkyStore(config) {
1901
1913
  if (input.shipping_method_id !== void 0) {
1902
1914
  cart_status.setKey("selected_shipping_method_id", input.shipping_method_id);
1903
1915
  }
1904
- await hydrateCart(response);
1916
+ await hydrateCart(response, { ifRevision: writeRevision });
1905
1917
  return response;
1906
1918
  } catch (error) {
1907
1919
  cart_status.setKey("error", readErrorMessage(error, "Failed to sync cart."));
@@ -1912,6 +1924,7 @@ function createArkyStore(config) {
1912
1924
  }
1913
1925
  async function addProduct(product, variant, quantity = 1) {
1914
1926
  cart_status.setKey("error", null);
1927
+ const writeRevision = nextCartWriteRevision();
1915
1928
  try {
1916
1929
  const current = cart.get() || await ensureCart();
1917
1930
  const response = await client.cart.addItem({
@@ -1923,7 +1936,7 @@ function createArkyStore(config) {
1923
1936
  quantity
1924
1937
  }
1925
1938
  });
1926
- await hydrateCart(response);
1939
+ await hydrateCart(response, { ifRevision: writeRevision });
1927
1940
  await client.activity.track({ type: "cart_added", payload: { product_id: product.id, variant_id: variant.id, quantity } });
1928
1941
  return response;
1929
1942
  } catch (error) {
@@ -1932,15 +1945,17 @@ function createArkyStore(config) {
1932
1945
  }
1933
1946
  }
1934
1947
  async function setProductQuantity(itemId, quantity) {
1948
+ const writeRevision = nextCartWriteRevision();
1935
1949
  const next = product_items.get().map((item) => {
1936
1950
  if (item.id !== itemId) return item;
1937
1951
  const bounded = item.max_stock ? Math.min(Math.max(1, quantity), item.max_stock) : Math.max(1, quantity);
1938
1952
  return { ...item, quantity: bounded };
1939
1953
  });
1940
1954
  product_items.set(next);
1941
- return syncCart({ product_items: next });
1955
+ return syncCart({ product_items: next }, writeRevision);
1942
1956
  }
1943
1957
  async function removeProduct(itemId) {
1958
+ const writeRevision = nextCartWriteRevision();
1944
1959
  const item = product_items.get().find((candidate) => candidate.id === itemId);
1945
1960
  product_items.set(product_items.get().filter((candidate) => candidate.id !== itemId));
1946
1961
  const current = cart.get();
@@ -1951,21 +1966,24 @@ function createArkyStore(config) {
1951
1966
  product_id: item.product_id,
1952
1967
  variant_id: item.variant_id
1953
1968
  });
1954
- await hydrateCart(response);
1969
+ await hydrateCart(response, { ifRevision: writeRevision });
1955
1970
  await client.activity.track({ type: "cart_removed", payload: { product_id: item.product_id, variant_id: item.variant_id } });
1956
1971
  return response;
1957
1972
  }
1958
1973
  async function addServiceItem(item) {
1974
+ const writeRevision = nextCartWriteRevision();
1959
1975
  const next = [...service_items.get(), item];
1960
1976
  service_items.set(next);
1961
- return syncCart({ service_items: next });
1977
+ return syncCart({ service_items: next }, writeRevision);
1962
1978
  }
1963
1979
  async function removeServiceItem(itemId) {
1980
+ const writeRevision = nextCartWriteRevision();
1964
1981
  const next = service_items.get().filter((item) => item.id !== itemId);
1965
1982
  service_items.set(next);
1966
- return syncCart({ service_items: next });
1983
+ return syncCart({ service_items: next }, writeRevision);
1967
1984
  }
1968
1985
  async function clearCart() {
1986
+ const writeRevision = nextCartWriteRevision();
1969
1987
  product_items.set([]);
1970
1988
  service_items.set([]);
1971
1989
  quote.set(null);
@@ -1974,7 +1992,7 @@ function createArkyStore(config) {
1974
1992
  const current = cart.get();
1975
1993
  if (!current) return null;
1976
1994
  const response = await client.cart.clear({ id: current.id });
1977
- await hydrateCart(response);
1995
+ await hydrateCart(response, { ifRevision: writeRevision });
1978
1996
  return response;
1979
1997
  }
1980
1998
  async function fetchQuote(input = {}) {
@@ -2742,6 +2760,7 @@ function createArkyStore(config) {
2742
2760
  setMarket,
2743
2761
  setLocale,
2744
2762
  setContext,
2763
+ getStoreId: client.getStoreId,
2745
2764
  getMarket: currentMarketKey,
2746
2765
  getLocale: currentLocale,
2747
2766
  cms: {
@@ -2779,8 +2798,8 @@ function createArkyStore(config) {
2779
2798
  },
2780
2799
  state: nanostores.atom(null)
2781
2800
  },
2801
+ support: client.support,
2782
2802
  store: client.store,
2783
- automation: client.automation,
2784
2803
  utils: client.utils
2785
2804
  };
2786
2805
  }