arky-sdk 0.7.80 → 0.7.85

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
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var nanostores = require('nanostores');
4
+
3
5
  // src/types/index.ts
4
6
  var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
5
7
  PaymentMethodType2["Cash"] = "cash";
@@ -26,7 +28,7 @@ function formatBlockValue(block) {
26
28
  case "relationship_entry":
27
29
  case "relationship_media":
28
30
  if (value && typeof value === "object") {
29
- return value.mimeType ? value.name || value.id : value.title || value.name || value.id;
31
+ return value.mime_type ? value.name || value.id : value.title || value.name || value.id;
30
32
  }
31
33
  return String(value);
32
34
  default:
@@ -151,42 +153,26 @@ var COMMON_ACTIVITY_TYPES = [
151
153
  "share",
152
154
  "wishlist_added"
153
155
  ];
154
- async function ensureCustomer(apiConfig) {
155
- if (apiConfig.getToken) {
156
- const tokens = await apiConfig.getToken();
157
- if (tokens?.accessToken) return;
158
- }
159
- const response = await apiConfig.httpClient.post(
160
- `/v1/storefront/${apiConfig.businessId}/customers/initialize`,
161
- {
162
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
163
- }
164
- );
165
- const accessToken = response?.accessToken;
166
- const refreshToken = response?.refreshToken;
167
- const accessExpiresAt = response?.accessExpiresAt;
168
- if (accessToken) {
169
- apiConfig.setToken?.({ accessToken, refreshToken, accessExpiresAt });
170
- }
171
- }
172
156
  var createActivityApi = (apiConfig) => ({
173
157
  COMMON_ACTIVITY_TYPES,
174
158
  async track(params) {
175
- await ensureCustomer(apiConfig);
176
- await apiConfig.httpClient.post(
177
- `/v1/storefront/${apiConfig.businessId}/activities/track`,
178
- { type: params.type, payload: params.payload }
179
- );
159
+ try {
160
+ await apiConfig.httpClient.post(
161
+ `/v1/storefront/${apiConfig.businessId}/activities/track`,
162
+ { type: params.type, payload: params.payload }
163
+ );
164
+ } catch {
165
+ }
180
166
  }
181
167
  });
182
168
  function groupCartToItems(cart) {
183
169
  const groups = /* @__PURE__ */ new Map();
184
170
  for (const slot of cart) {
185
- const key = `${slot.serviceId}:${slot.providerId}`;
171
+ const key = `${slot.service_id}:${slot.provider_id}`;
186
172
  if (!groups.has(key)) {
187
173
  groups.set(key, {
188
- serviceId: slot.serviceId,
189
- providerId: slot.providerId,
174
+ service_id: slot.service_id,
175
+ provider_id: slot.provider_id,
190
176
  slots: []
191
177
  });
192
178
  }
@@ -202,12 +188,6 @@ var createStorefrontApi = (apiConfig) => {
202
188
  getBusiness(options) {
203
189
  return apiConfig.httpClient.get(base(), options);
204
190
  },
205
- getIntegrationConfig(params, options) {
206
- return apiConfig.httpClient.get(
207
- `${base(params.businessId)}/integrations/config/${params.type}`,
208
- options
209
- );
210
- },
211
191
  location: {
212
192
  getCountries(options) {
213
193
  return apiConfig.httpClient.get(`/v1/platform/countries`, options);
@@ -361,18 +341,18 @@ var createStorefrontApi = (apiConfig) => {
361
341
  getQuote(params, options) {
362
342
  const businessId = params.businessId || apiConfig.businessId;
363
343
  const { location, businessId: _businessId, ...rest } = params;
364
- const shippingAddress = location ? {
344
+ const shipping_address = location ? {
365
345
  country: location.country || "",
366
346
  state: location.state || "",
367
347
  city: location.city || "",
368
- postalCode: location.postalCode || "",
348
+ postal_code: location.postal_code || "",
369
349
  name: "",
370
350
  street1: "",
371
351
  street2: null
372
352
  } : void 0;
373
353
  return apiConfig.httpClient.post(
374
354
  `${base(businessId)}/orders/quote`,
375
- { ...rest, shippingAddress, market: apiConfig.market },
355
+ { ...rest, shipping_address, market: apiConfig.market },
376
356
  options
377
357
  );
378
358
  },
@@ -522,15 +502,7 @@ var createStorefrontApi = (apiConfig) => {
522
502
  const businessId = params?.businessId || apiConfig.businessId;
523
503
  return apiConfig.httpClient.post(
524
504
  `${base(businessId)}/customers/initialize`,
525
- { businessId },
526
- options
527
- );
528
- },
529
- signInAnonymously(params, options) {
530
- const businessId = params?.businessId || apiConfig.businessId;
531
- return apiConfig.httpClient.post(
532
- `${base(businessId)}/customers/initialize`,
533
- { businessId },
505
+ { business_id: businessId, market: params?.market || apiConfig.market },
534
506
  options
535
507
  );
536
508
  },
@@ -562,7 +534,7 @@ var createStorefrontApi = (apiConfig) => {
562
534
  const businessId = params.businessId || apiConfig.businessId;
563
535
  return apiConfig.httpClient.post(
564
536
  `${base(businessId)}/customers/auth/refresh`,
565
- { refreshToken: params.refreshToken },
537
+ { refresh_token: params.refresh_token },
566
538
  options
567
539
  );
568
540
  },
@@ -595,11 +567,11 @@ var createStorefrontApi = (apiConfig) => {
595
567
  return apiConfig.httpClient.post(
596
568
  `${base()}/audiences/${params.id}/subscribe`,
597
569
  {
598
- customerId: params.customerId,
599
- priceId: params.priceId,
600
- successUrl: params.successUrl,
601
- cancelUrl: params.cancelUrl,
602
- confirmUrl: params.confirmUrl
570
+ customer_id: params.customer_id,
571
+ price_id: params.price_id,
572
+ success_url: params.success_url,
573
+ cancel_url: params.cancel_url,
574
+ confirm_url: params.confirm_url
603
575
  },
604
576
  options
605
577
  );
@@ -646,7 +618,7 @@ var createStorefrontApi = (apiConfig) => {
646
618
  sendMessage(params, options) {
647
619
  const businessId = params.businessId || apiConfig.businessId;
648
620
  const body = { message: params.message };
649
- if (params.chatId) body.chatId = params.chatId;
621
+ if (params.chat_id) body.chat_id = params.chat_id;
650
622
  return apiConfig.httpClient.post(
651
623
  `${base(businessId)}/agents/${params.id}/chats/messages`,
652
624
  body,
@@ -656,7 +628,7 @@ var createStorefrontApi = (apiConfig) => {
656
628
  getChat(params, options) {
657
629
  const businessId = params.businessId || apiConfig.businessId;
658
630
  return apiConfig.httpClient.get(
659
- `${base(businessId)}/agents/${params.id}/chats/${params.chatId}`,
631
+ `${base(businessId)}/agents/${params.id}/chats/${params.chat_id}`,
660
632
  options
661
633
  );
662
634
  },
@@ -665,7 +637,7 @@ var createStorefrontApi = (apiConfig) => {
665
637
  const queryParams = {};
666
638
  if (params.limit) queryParams.limit = String(params.limit);
667
639
  return apiConfig.httpClient.get(
668
- `${base(businessId)}/agents/${params.id}/chats/${params.chatId}/messages`,
640
+ `${base(businessId)}/agents/${params.id}/chats/${params.chat_id}/messages`,
669
641
  {
670
642
  ...options,
671
643
  params: Object.keys(queryParams).length > 0 ? queryParams : void 0
@@ -677,7 +649,7 @@ var createStorefrontApi = (apiConfig) => {
677
649
  const body = { rating: params.rating };
678
650
  if (params.comment) body.comment = params.comment;
679
651
  return apiConfig.httpClient.post(
680
- `${base(businessId)}/agents/${params.id}/chats/${params.chatId}/rate`,
652
+ `${base(businessId)}/agents/${params.id}/chats/${params.chat_id}/rate`,
681
653
  body,
682
654
  options
683
655
  );
@@ -731,19 +703,19 @@ var STORAGE_KEYS = {
731
703
  accessExpiresAt: "arky_expires_at"
732
704
  };
733
705
  function defaultGetToken() {
734
- if (typeof window === "undefined") return { accessToken: "" };
706
+ if (typeof window === "undefined") return { access_token: "" };
735
707
  return {
736
- accessToken: localStorage.getItem(STORAGE_KEYS.accessToken) || "",
737
- refreshToken: localStorage.getItem(STORAGE_KEYS.refreshToken) || "",
738
- accessExpiresAt: parseInt(localStorage.getItem(STORAGE_KEYS.accessExpiresAt) || "0", 10)
708
+ access_token: localStorage.getItem(STORAGE_KEYS.accessToken) || "",
709
+ refresh_token: localStorage.getItem(STORAGE_KEYS.refreshToken) || "",
710
+ access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.accessExpiresAt) || "0", 10)
739
711
  };
740
712
  }
741
713
  function defaultSetToken(tokens) {
742
714
  if (typeof window === "undefined") return;
743
- if (tokens.accessToken) {
744
- localStorage.setItem(STORAGE_KEYS.accessToken, tokens.accessToken);
745
- localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.refreshToken || "");
746
- localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.accessExpiresAt || 0).toString());
715
+ if (tokens.access_token) {
716
+ localStorage.setItem(STORAGE_KEYS.accessToken, tokens.access_token);
717
+ localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.refresh_token || "");
718
+ localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.access_expires_at || 0).toString());
747
719
  } else {
748
720
  Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
749
721
  }
@@ -768,8 +740,8 @@ function createHttpClient(cfg) {
768
740
  return refreshPromise;
769
741
  }
770
742
  refreshPromise = (async () => {
771
- const { refreshToken } = await getToken();
772
- if (!refreshToken) {
743
+ const { refresh_token } = await getToken();
744
+ if (!refresh_token) {
773
745
  logout();
774
746
  const err = new Error("No refresh token available");
775
747
  err.name = "ApiError";
@@ -779,7 +751,7 @@ function createHttpClient(cfg) {
779
751
  const refRes = await fetch(refreshEndpoint, {
780
752
  method: "POST",
781
753
  headers: { Accept: "application/json", "Content-Type": "application/json" },
782
- body: JSON.stringify({ refreshToken })
754
+ body: JSON.stringify({ refresh_token })
783
755
  });
784
756
  if (!refRes.ok) {
785
757
  logout();
@@ -804,15 +776,15 @@ function createHttpClient(cfg) {
804
776
  "Content-Type": "application/json",
805
777
  ...options?.headers || {}
806
778
  };
807
- let { accessToken, accessExpiresAt } = await getToken();
779
+ let { access_token, access_expires_at } = await getToken();
808
780
  const nowSec = Date.now() / 1e3;
809
- if (accessExpiresAt && nowSec > accessExpiresAt) {
781
+ if (access_expires_at && nowSec > access_expires_at) {
810
782
  await ensureFreshToken();
811
783
  const tokens = await getToken();
812
- accessToken = tokens.accessToken;
784
+ access_token = tokens.access_token;
813
785
  }
814
- if (accessToken) {
815
- headers["Authorization"] = `Bearer ${accessToken}`;
786
+ if (access_token) {
787
+ headers["Authorization"] = `Bearer ${access_token}`;
816
788
  }
817
789
  const finalPath = options?.params ? path + buildQueryString(options.params) : path;
818
790
  const fetchOpts = { method, headers };
@@ -842,7 +814,7 @@ function createHttpClient(cfg) {
842
814
  try {
843
815
  await ensureFreshToken();
844
816
  const tokens = await getToken();
845
- headers["Authorization"] = `Bearer ${tokens.accessToken}`;
817
+ headers["Authorization"] = `Bearer ${tokens.access_token}`;
846
818
  fetchOpts.headers = headers;
847
819
  return request(method, path, body, { ...options, _retried: true });
848
820
  } catch (refreshError) {
@@ -927,9 +899,9 @@ var createAccountApi = (apiConfig) => {
927
899
  return {
928
900
  async updateAccount(params, options) {
929
901
  const payload = {};
930
- if (params.phoneNumbers !== void 0) payload.phoneNumbers = params.phoneNumbers;
902
+ if (params.phone_numbers !== void 0) payload.phone_numbers = params.phone_numbers;
931
903
  if (params.addresses !== void 0) payload.addresses = params.addresses;
932
- if (params.apiTokens !== void 0) payload.apiTokens = params.apiTokens;
904
+ if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
933
905
  return apiConfig.httpClient.put("/v1/accounts", payload, options);
934
906
  },
935
907
  async deleteAccount(params, options) {
@@ -958,8 +930,8 @@ var createAuthApi = (apiConfig) => {
958
930
  },
959
931
  async verify(params, options) {
960
932
  const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
961
- if (result?.accessToken) {
962
- apiConfig.setToken({ ...result, email: params.email, isVerified: true });
933
+ if (result?.access_token) {
934
+ apiConfig.setToken({ ...result, email: params.email, is_verified: true });
963
935
  }
964
936
  return result;
965
937
  },
@@ -971,8 +943,8 @@ var createAuthApi = (apiConfig) => {
971
943
  },
972
944
  async businessVerify(businessId, params, options) {
973
945
  const result = await apiConfig.httpClient.post(`/v1/businesses/${businessId}/auth/verify`, params, options);
974
- if (result?.accessToken) {
975
- apiConfig.setToken({ ...result, email: params.email, isVerified: true });
946
+ if (result?.access_token) {
947
+ apiConfig.setToken({ ...result, email: params.email, is_verified: true });
976
948
  }
977
949
  return result;
978
950
  },
@@ -1039,7 +1011,7 @@ var createBusinessApi = (apiConfig) => {
1039
1011
  },
1040
1012
  async removeMember(params, options) {
1041
1013
  return apiConfig.httpClient.delete(
1042
- `/v1/businesses/${apiConfig.businessId}/members/${params.accountId}`,
1014
+ `/v1/businesses/${apiConfig.businessId}/members/${params.account_id}`,
1043
1015
  options
1044
1016
  );
1045
1017
  },
@@ -1064,9 +1036,9 @@ var createBusinessApi = (apiConfig) => {
1064
1036
  if (params.cursor) queryParams.cursor = params.cursor;
1065
1037
  if (params.ids && params.ids.length > 0) queryParams.ids = params.ids.join(",");
1066
1038
  if (params.query) queryParams.query = params.query;
1067
- if (params.mimeType) queryParams.mimeType = params.mimeType;
1068
- if (params.sortField) queryParams.sortField = params.sortField;
1069
- if (params.sortDirection) queryParams.sortDirection = params.sortDirection;
1039
+ if (params.mime_type) queryParams.mime_type = params.mime_type;
1040
+ if (params.sort_field) queryParams.sort_field = params.sort_field;
1041
+ if (params.sort_direction) queryParams.sort_direction = params.sort_direction;
1070
1042
  return apiConfig.httpClient.get(`/v1/businesses/${params.id}/media`, {
1071
1043
  ...options,
1072
1044
  params: queryParams
@@ -1075,7 +1047,7 @@ var createBusinessApi = (apiConfig) => {
1075
1047
  async oauthConnect(params, options) {
1076
1048
  return apiConfig.httpClient.post(
1077
1049
  `/v1/businesses/${params.businessId}/oauth/connect`,
1078
- { provider: params.provider, code: params.code, redirectUri: params.redirectUri },
1050
+ { provider: params.provider, code: params.code, redirect_uri: params.redirect_uri },
1079
1051
  options
1080
1052
  );
1081
1053
  },
@@ -1173,7 +1145,7 @@ var createMediaApi = (apiConfig) => {
1173
1145
  method: "POST",
1174
1146
  body: formData,
1175
1147
  headers: {
1176
- Authorization: `Bearer ${tokens.accessToken}`
1148
+ Authorization: `Bearer ${tokens.access_token}`
1177
1149
  }
1178
1150
  });
1179
1151
  if (!response.ok) {
@@ -1189,21 +1161,21 @@ var createMediaApi = (apiConfig) => {
1189
1161
  );
1190
1162
  },
1191
1163
  async getBusinessMedia(params, options) {
1192
- const { businessId, cursor, limit, ids, query, mimeType, sortField, sortDirection } = params;
1164
+ const { businessId, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
1193
1165
  const targetBusinessId = businessId || apiConfig.businessId;
1194
1166
  const url = `${apiConfig.baseUrl}/v1/businesses/${targetBusinessId}/media`;
1195
1167
  const queryParams = { limit: String(limit) };
1196
1168
  if (cursor) queryParams.cursor = cursor;
1197
1169
  if (ids && ids.length > 0) queryParams.ids = ids.join(",");
1198
1170
  if (query) queryParams.query = query;
1199
- if (mimeType) queryParams.mimeType = mimeType;
1200
- if (sortField) queryParams.sortField = sortField;
1201
- if (sortDirection) queryParams.sortDirection = sortDirection;
1171
+ if (mime_type) queryParams.mime_type = mime_type;
1172
+ if (sort_field) queryParams.sort_field = sort_field;
1173
+ if (sort_direction) queryParams.sort_direction = sort_direction;
1202
1174
  const queryString = new URLSearchParams(queryParams).toString();
1203
1175
  const tokens = await apiConfig.getToken();
1204
1176
  const response = await fetch(`${url}?${queryString}`, {
1205
1177
  headers: {
1206
- Authorization: `Bearer ${tokens.accessToken}`
1178
+ Authorization: `Bearer ${tokens.access_token}`
1207
1179
  }
1208
1180
  });
1209
1181
  if (!response.ok) {
@@ -1229,7 +1201,7 @@ var createNotificationApi = (apiConfig) => {
1229
1201
  return {
1230
1202
  async trackEmailOpen(params, options) {
1231
1203
  return apiConfig.httpClient.get(
1232
- `/v1/notifications/track/pixel/${params.trackingPixelId}`,
1204
+ `/v1/notifications/track/pixel/${params.tracking_pixel_id}`,
1233
1205
  options
1234
1206
  );
1235
1207
  },
@@ -1441,18 +1413,18 @@ var createEshopApi = (apiConfig) => {
1441
1413
  },
1442
1414
  async getQuote(params, options) {
1443
1415
  const { location, ...rest } = params;
1444
- const shippingAddress = location ? {
1416
+ const shipping_address = location ? {
1445
1417
  country: location.country || "",
1446
1418
  state: location.state || "",
1447
1419
  city: location.city || "",
1448
- postalCode: location.postalCode || "",
1420
+ postal_code: location.postal_code || "",
1449
1421
  name: "",
1450
1422
  street1: "",
1451
1423
  street2: null
1452
1424
  } : void 0;
1453
1425
  return apiConfig.httpClient.post(
1454
1426
  `/v1/businesses/${apiConfig.businessId}/orders/quote`,
1455
- { ...rest, shippingAddress, market: apiConfig.market },
1427
+ { ...rest, shipping_address, market: apiConfig.market },
1456
1428
  options
1457
1429
  );
1458
1430
  },
@@ -1644,10 +1616,10 @@ var createBookingApi = (apiConfig) => {
1644
1616
  );
1645
1617
  },
1646
1618
  async cancelBookingItem(params, options) {
1647
- const { businessId, bookingId, itemId, ...payload } = params;
1619
+ const { businessId, booking_id, item_id, ...payload } = params;
1648
1620
  const targetBusinessId = businessId || apiConfig.businessId;
1649
1621
  return apiConfig.httpClient.post(
1650
- `/v1/businesses/${targetBusinessId}/bookings/${bookingId}/items/${itemId}/cancel`,
1622
+ `/v1/businesses/${targetBusinessId}/bookings/${booking_id}/items/${item_id}/cancel`,
1651
1623
  payload,
1652
1624
  options
1653
1625
  );
@@ -1777,7 +1749,7 @@ var createMarketApi = (apiConfig) => {
1777
1749
  var createActivityAdminApi = (apiConfig) => ({
1778
1750
  async timeline(params, options) {
1779
1751
  const businessId = params.businessId || apiConfig.businessId;
1780
- const queryParams = { customerId: params.customerId };
1752
+ const queryParams = { customer_id: params.customer_id };
1781
1753
  if (params.limit !== void 0) queryParams.limit = params.limit;
1782
1754
  if (params.cursor) queryParams.cursor = params.cursor;
1783
1755
  return apiConfig.httpClient.get(
@@ -1807,8 +1779,8 @@ var createCustomerApi = (apiConfig) => {
1807
1779
  if (params?.limit !== void 0) queryParams.limit = params.limit;
1808
1780
  if (params?.cursor) queryParams.cursor = params.cursor;
1809
1781
  if (params?.query) queryParams.query = params.query;
1810
- if (params?.sortField) queryParams.sortField = params.sortField;
1811
- if (params?.sortDirection) queryParams.sortDirection = params.sortDirection;
1782
+ if (params?.sort_field) queryParams.sort_field = params.sort_field;
1783
+ if (params?.sort_direction) queryParams.sort_direction = params.sort_direction;
1812
1784
  return apiConfig.httpClient.get(
1813
1785
  `/v1/businesses/${businessId}/customers`,
1814
1786
  {
@@ -1828,8 +1800,8 @@ var createCustomerApi = (apiConfig) => {
1828
1800
  async merge(params, options) {
1829
1801
  const businessId = params.businessId || apiConfig.businessId;
1830
1802
  return apiConfig.httpClient.post(
1831
- `/v1/businesses/${businessId}/customers/${params.targetId}/merge`,
1832
- { sourceId: params.sourceId, businessId },
1803
+ `/v1/businesses/${businessId}/customers/${params.target_id}/merge`,
1804
+ { source_id: params.source_id, businessId },
1833
1805
  options
1834
1806
  );
1835
1807
  },
@@ -1894,13 +1866,13 @@ var createCustomerApi = (apiConfig) => {
1894
1866
  async addSubscriber(params, options) {
1895
1867
  return apiConfig.httpClient.post(
1896
1868
  `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers`,
1897
- { customerId: params.customerId },
1869
+ { customer_id: params.customer_id },
1898
1870
  options
1899
1871
  );
1900
1872
  },
1901
1873
  async removeSubscriber(params, options) {
1902
1874
  return apiConfig.httpClient.delete(
1903
- `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers/${params.customerId}`,
1875
+ `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers/${params.customer_id}`,
1904
1876
  options
1905
1877
  );
1906
1878
  }
@@ -1953,9 +1925,9 @@ var createWorkflowApi = (apiConfig) => {
1953
1925
  },
1954
1926
  async getWorkflowExecutions(params, options) {
1955
1927
  const businessId = params.businessId || apiConfig.businessId;
1956
- const { businessId: _, workflowId, ...queryParams } = params;
1928
+ const { businessId: _, workflow_id, ...queryParams } = params;
1957
1929
  return apiConfig.httpClient.get(
1958
- `/v1/businesses/${businessId}/workflows/${workflowId}/executions`,
1930
+ `/v1/businesses/${businessId}/workflows/${workflow_id}/executions`,
1959
1931
  {
1960
1932
  ...options,
1961
1933
  params: Object.keys(queryParams).length > 0 ? queryParams : void 0
@@ -1965,7 +1937,7 @@ var createWorkflowApi = (apiConfig) => {
1965
1937
  async getWorkflowExecution(params, options) {
1966
1938
  const businessId = params.businessId || apiConfig.businessId;
1967
1939
  return apiConfig.httpClient.get(
1968
- `/v1/businesses/${businessId}/workflows/${params.workflowId}/executions/${params.executionId}`,
1940
+ `/v1/businesses/${businessId}/workflows/${params.workflow_id}/executions/${params.execution_id}`,
1969
1941
  options
1970
1942
  );
1971
1943
  }
@@ -1991,17 +1963,17 @@ var createPlatformApi = (apiConfig) => {
1991
1963
  var createShippingApi = (apiConfig) => {
1992
1964
  return {
1993
1965
  async getRates(params, options) {
1994
- const { orderId, ...payload } = params;
1966
+ const { order_id, ...payload } = params;
1995
1967
  return apiConfig.httpClient.post(
1996
- `/v1/businesses/${apiConfig.businessId}/orders/${orderId}/shipping/rates`,
1968
+ `/v1/businesses/${apiConfig.businessId}/orders/${order_id}/shipping/rates`,
1997
1969
  payload,
1998
1970
  options
1999
1971
  );
2000
1972
  },
2001
1973
  async ship(params, options) {
2002
- const { orderId, ...payload } = params;
1974
+ const { order_id, ...payload } = params;
2003
1975
  return apiConfig.httpClient.post(
2004
- `/v1/businesses/${apiConfig.businessId}/orders/${orderId}/ship`,
1976
+ `/v1/businesses/${apiConfig.businessId}/orders/${order_id}/ship`,
2005
1977
  payload,
2006
1978
  options
2007
1979
  );
@@ -2049,7 +2021,7 @@ var createAgentApi = (apiConfig) => {
2049
2021
  },
2050
2022
  async sendMessage(params, options) {
2051
2023
  const body = { message: params.message };
2052
- if (params.chatId) body.chatId = params.chatId;
2024
+ if (params.chat_id) body.chat_id = params.chat_id;
2053
2025
  if (params.direct) body.direct = params.direct;
2054
2026
  return apiConfig.httpClient.post(
2055
2027
  `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/messages`,
@@ -2071,13 +2043,13 @@ var createAgentApi = (apiConfig) => {
2071
2043
  },
2072
2044
  async getChat(params, options) {
2073
2045
  return apiConfig.httpClient.get(
2074
- `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}`,
2046
+ `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}`,
2075
2047
  options
2076
2048
  );
2077
2049
  },
2078
2050
  async updateChat(params, options) {
2079
2051
  return apiConfig.httpClient.put(
2080
- `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}`,
2052
+ `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}`,
2081
2053
  { status: params.status },
2082
2054
  options
2083
2055
  );
@@ -2086,7 +2058,7 @@ var createAgentApi = (apiConfig) => {
2086
2058
  const body = { rating: params.rating };
2087
2059
  if (params.comment) body.comment = params.comment;
2088
2060
  return apiConfig.httpClient.post(
2089
- `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/rate`,
2061
+ `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}/rate`,
2090
2062
  body,
2091
2063
  options
2092
2064
  );
@@ -2103,7 +2075,7 @@ var createAgentApi = (apiConfig) => {
2103
2075
  const queryParams = {};
2104
2076
  if (params.limit) queryParams.limit = String(params.limit);
2105
2077
  return apiConfig.httpClient.get(
2106
- `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/messages`,
2078
+ `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}/messages`,
2107
2079
  {
2108
2080
  ...options,
2109
2081
  params: Object.keys(queryParams).length > 0 ? queryParams : void 0
@@ -2344,6 +2316,7 @@ var createAnalyticsApi = (apiConfig) => {
2344
2316
 
2345
2317
  // src/utils/price.ts
2346
2318
  function formatCurrency(amount, currencyCode, locale = "en") {
2319
+ if (!currencyCode) return "";
2347
2320
  return new Intl.NumberFormat(locale, {
2348
2321
  style: "currency",
2349
2322
  currency: currencyCode.toUpperCase()
@@ -2385,6 +2358,7 @@ function getCurrencyName(currency) {
2385
2358
  }
2386
2359
  }
2387
2360
  function formatMinor(amountMinor, currency) {
2361
+ if (!currency) return "";
2388
2362
  return formatCurrency(convertToMajor(amountMinor, currency), currency);
2389
2363
  }
2390
2364
  function formatPayment(payment) {
@@ -2416,6 +2390,57 @@ function validatePhoneNumber(phone) {
2416
2390
  }
2417
2391
  return { isValid: true };
2418
2392
  }
2393
+ function createStores() {
2394
+ const $business = nanostores.atom(null);
2395
+ const $market = nanostores.atom(null);
2396
+ const $loading = nanostores.atom(false);
2397
+ const $error = nanostores.atom(null);
2398
+ const $initialized = nanostores.atom(false);
2399
+ const $currency = nanostores.computed($market, (m) => m?.currency);
2400
+ const $currencySymbol = nanostores.computed($market, (m) => {
2401
+ if (!m?.currency) return void 0;
2402
+ return new Intl.NumberFormat("en", {
2403
+ style: "currency",
2404
+ currency: m.currency.toUpperCase(),
2405
+ currencyDisplay: "narrowSymbol"
2406
+ }).formatToParts(0).find((p) => p.type === "currency")?.value || m.currency.toUpperCase();
2407
+ });
2408
+ const $paymentMethods = nanostores.computed(
2409
+ $market,
2410
+ (m) => (m?.payment_methods || []).map((pm) => pm.id)
2411
+ );
2412
+ const $paymentMethodObjects = nanostores.computed(
2413
+ $market,
2414
+ (m) => m?.payment_methods || []
2415
+ );
2416
+ const $paymentConfig = nanostores.computed([$business, $paymentMethods], (biz, methods) => {
2417
+ const payment = biz?.payment || null;
2418
+ const hasCreditCard = methods.includes("credit_card");
2419
+ return {
2420
+ provider: payment,
2421
+ enabled: hasCreditCard && !!payment
2422
+ };
2423
+ });
2424
+ const $zones = nanostores.computed($market, (m) => m?.zones || []);
2425
+ return {
2426
+ business: $business,
2427
+ market: $market,
2428
+ loading: $loading,
2429
+ error: $error,
2430
+ initialized: $initialized,
2431
+ currency: $currency,
2432
+ currencySymbol: $currencySymbol,
2433
+ paymentMethods: $paymentMethods,
2434
+ paymentMethodObjects: $paymentMethodObjects,
2435
+ paymentConfig: $paymentConfig,
2436
+ zones: $zones
2437
+ };
2438
+ }
2439
+ function populateStores(stores, data) {
2440
+ stores.business.set(data.business);
2441
+ stores.market.set(data.market);
2442
+ stores.initialized.set(true);
2443
+ }
2419
2444
 
2420
2445
  // src/utils/timezone.ts
2421
2446
  var tzGroups = [
@@ -2569,28 +2594,6 @@ function nameToKey(name) {
2569
2594
  return toKey(name);
2570
2595
  }
2571
2596
 
2572
- // src/utils/analytics.ts
2573
- function injectGA4Script(measurementId) {
2574
- if (typeof window === "undefined") return;
2575
- if (document.querySelector(`script[src*="${measurementId}"]`)) return;
2576
- window.dataLayer = window.dataLayer || [];
2577
- window.gtag = function gtag(...args) {
2578
- window.dataLayer.push(args);
2579
- };
2580
- window.gtag("js", /* @__PURE__ */ new Date());
2581
- window.gtag("config", measurementId);
2582
- const script = document.createElement("script");
2583
- script.async = true;
2584
- script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
2585
- document.head.appendChild(script);
2586
- }
2587
- function track(eventName, params) {
2588
- if (typeof window === "undefined") return;
2589
- if (window.gtag) {
2590
- window.gtag("event", eventName, params);
2591
- }
2592
- }
2593
-
2594
2597
  // src/utils/inventory.ts
2595
2598
  function getAvailableStock(variant) {
2596
2599
  if (!variant?.inventory) return 0;
@@ -2604,15 +2607,15 @@ function hasStock(variant, quantity = 1) {
2604
2607
  return getAvailableStock(variant) >= quantity;
2605
2608
  }
2606
2609
  function getInventoryAt(variant, locationId) {
2607
- return variant?.inventory?.find((inv) => inv.locationId === locationId);
2610
+ return variant?.inventory?.find((inv) => inv.location_id === locationId);
2608
2611
  }
2609
2612
  function getFirstAvailableFCId(variant, quantity = 1) {
2610
2613
  const inv = variant?.inventory?.find((i) => i.available >= quantity);
2611
- return inv?.locationId;
2614
+ return inv?.location_id;
2612
2615
  }
2613
2616
 
2614
2617
  // src/index.ts
2615
- var SDK_VERSION = "0.7.80";
2618
+ var SDK_VERSION = "0.7.85";
2616
2619
  var SUPPORTED_FRAMEWORKS = [
2617
2620
  "astro",
2618
2621
  "react",
@@ -2652,7 +2655,6 @@ function createUtilitySurface(apiConfig) {
2652
2655
  validateKey,
2653
2656
  toKey,
2654
2657
  nameToKey,
2655
- track,
2656
2658
  getAvailableStock,
2657
2659
  getReservedStock,
2658
2660
  hasStock,
@@ -2680,17 +2682,6 @@ async function createAdmin(config) {
2680
2682
  const authApi = createAuthApi(apiConfig);
2681
2683
  const businessApi = createBusinessApi(apiConfig);
2682
2684
  const platformApi = createPlatformApi(apiConfig);
2683
- if (typeof window !== "undefined" && apiConfig.businessId) {
2684
- businessApi.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
2685
- if (!configs) return;
2686
- for (const c of Array.isArray(configs) ? configs : [configs]) {
2687
- if (c.measurementId) {
2688
- injectGA4Script(c.measurementId);
2689
- }
2690
- }
2691
- }).catch(() => {
2692
- });
2693
- }
2694
2685
  const cmsApi = createCmsApi(apiConfig);
2695
2686
  const eshopApi = createEshopApi(apiConfig);
2696
2687
  const bookingApi = createBookingApi(apiConfig);
@@ -2849,7 +2840,6 @@ async function createAdmin(config) {
2849
2840
  }
2850
2841
  },
2851
2842
  analytics: {
2852
- track,
2853
2843
  query: analyticsApi.query
2854
2844
  },
2855
2845
  setBusinessId: (businessId) => {
@@ -2872,8 +2862,35 @@ async function createAdmin(config) {
2872
2862
  };
2873
2863
  return sdk;
2874
2864
  }
2875
- async function createStorefront(config) {
2865
+ var SESSION_CACHE_TTL = 36e5;
2866
+ function getCachedSession(businessId) {
2867
+ if (typeof window === "undefined") return null;
2868
+ try {
2869
+ const raw = localStorage.getItem(`arky_session_${businessId}`);
2870
+ if (!raw) return null;
2871
+ const parsed = JSON.parse(raw);
2872
+ if (Date.now() - (parsed.timestamp || 0) > SESSION_CACHE_TTL) {
2873
+ localStorage.removeItem(`arky_session_${businessId}`);
2874
+ return null;
2875
+ }
2876
+ return { business: parsed.business, market: parsed.market };
2877
+ } catch {
2878
+ return null;
2879
+ }
2880
+ }
2881
+ function setCachedSession(businessId, data) {
2882
+ if (typeof window === "undefined") return;
2883
+ try {
2884
+ localStorage.setItem(
2885
+ `arky_session_${businessId}`,
2886
+ JSON.stringify({ ...data, timestamp: Date.now() })
2887
+ );
2888
+ } catch {
2889
+ }
2890
+ }
2891
+ function createStorefront(config) {
2876
2892
  const locale = config.locale || "en";
2893
+ const market = config.market || "";
2877
2894
  const getToken = config.getToken || defaultGetToken;
2878
2895
  const setToken = config.setToken || defaultSetToken;
2879
2896
  const logout = config.logout || defaultLogout;
@@ -2889,44 +2906,67 @@ async function createStorefront(config) {
2889
2906
  httpClient,
2890
2907
  businessId: config.businessId,
2891
2908
  baseUrl: config.baseUrl,
2892
- market: config.market,
2909
+ market,
2893
2910
  locale,
2894
2911
  setToken,
2895
2912
  getToken
2896
2913
  };
2897
2914
  const storefrontApi = createStorefrontApi(apiConfig);
2898
- let sessionPromise = null;
2899
- function ensureSession() {
2900
- if (typeof window === "undefined") return Promise.resolve();
2901
- if (sessionPromise) return sessionPromise;
2902
- sessionPromise = (async () => {
2903
- const tokens = await apiConfig.getToken();
2904
- if (tokens.accessToken) return;
2905
- const result = await storefrontApi.crm.customer.initialize();
2906
- if (result?.accessToken) {
2907
- apiConfig.setToken(result);
2915
+ const stores = createStores();
2916
+ let initPromise = null;
2917
+ function init() {
2918
+ if (initPromise) return initPromise;
2919
+ initPromise = (async () => {
2920
+ stores.loading.set(true);
2921
+ stores.error.set(null);
2922
+ const cached = getCachedSession(config.businessId);
2923
+ const tokens = await getToken();
2924
+ const hasToken = !!tokens.access_token;
2925
+ if (hasToken && cached) {
2926
+ populateStores(stores, cached);
2927
+ stores.loading.set(false);
2928
+ return cached;
2908
2929
  }
2909
- })().finally(() => {
2910
- sessionPromise = null;
2930
+ if (hasToken) {
2931
+ const [business, allMarkets] = await Promise.all([
2932
+ storefrontApi.business.getBusiness(),
2933
+ storefrontApi.business.market.list().catch(() => [])
2934
+ ]);
2935
+ const marketData = market ? allMarkets.find((m) => m.key === market) || null : null;
2936
+ const session2 = { business, market: marketData };
2937
+ populateStores(stores, session2);
2938
+ setCachedSession(config.businessId, session2);
2939
+ stores.loading.set(false);
2940
+ return session2;
2941
+ }
2942
+ const result = await storefrontApi.crm.customer.initialize({
2943
+ market
2944
+ });
2945
+ if (result?.token?.access_token) {
2946
+ setToken(result.token);
2947
+ }
2948
+ const session = {
2949
+ business: result.business,
2950
+ market: result.market
2951
+ };
2952
+ populateStores(stores, session);
2953
+ setCachedSession(config.businessId, session);
2954
+ stores.loading.set(false);
2955
+ return session;
2956
+ })().catch((err) => {
2957
+ stores.error.set(err.message || "Initialization failed");
2958
+ stores.loading.set(false);
2959
+ initPromise = null;
2960
+ throw err;
2911
2961
  });
2912
- return sessionPromise;
2962
+ return initPromise;
2913
2963
  }
2914
- if (typeof window !== "undefined") {
2915
- ensureSession().catch(() => {
2916
- });
2917
- if (apiConfig.businessId) {
2918
- storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
2919
- if (!configs) return;
2920
- for (const c of Array.isArray(configs) ? configs : [configs]) {
2921
- if (c.measurementId) {
2922
- injectGA4Script(c.measurementId);
2923
- }
2924
- }
2925
- }).catch(() => {
2926
- });
2927
- }
2964
+ function setMarket(key) {
2965
+ apiConfig.market = key;
2928
2966
  }
2929
2967
  return {
2968
+ init,
2969
+ stores,
2930
2970
  business: storefrontApi.business,
2931
2971
  cms: storefrontApi.cms,
2932
2972
  eshop: storefrontApi.eshop,
@@ -2934,16 +2974,11 @@ async function createStorefront(config) {
2934
2974
  crm: storefrontApi.crm,
2935
2975
  activity: storefrontApi.activity,
2936
2976
  automation: storefrontApi.automation,
2937
- analytics: {
2938
- track
2939
- },
2940
2977
  setBusinessId: (businessId) => {
2941
2978
  apiConfig.businessId = businessId;
2942
2979
  },
2943
2980
  getBusinessId: () => apiConfig.businessId,
2944
- setMarket: (market) => {
2945
- apiConfig.market = market;
2946
- },
2981
+ setMarket,
2947
2982
  getMarket: () => apiConfig.market,
2948
2983
  setLocale: (locale2) => {
2949
2984
  apiConfig.locale = locale2;