arky-sdk 0.3.28 → 0.3.31

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
@@ -517,6 +517,21 @@ var createAnalyticsApi = (apiConfig) => {
517
517
  };
518
518
  };
519
519
 
520
+ // src/utils/slug.ts
521
+ var isUuid = (str) => {
522
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
523
+ return uuidRegex.test(str);
524
+ };
525
+ var formatIdOrSlug = (id, apiConfig) => {
526
+ if (isUuid(id)) {
527
+ return id;
528
+ }
529
+ if (id.includes(":")) {
530
+ return id;
531
+ }
532
+ return `${apiConfig.businessId}:${apiConfig.locale}:${id}`;
533
+ };
534
+
520
535
  // src/api/cms.ts
521
536
  var createCmsApi = (apiConfig) => {
522
537
  return {
@@ -542,8 +557,9 @@ var createCmsApi = (apiConfig) => {
542
557
  );
543
558
  },
544
559
  async getCollection(params, options) {
560
+ const formattedId = formatIdOrSlug(params.id, apiConfig);
545
561
  return apiConfig.httpClient.get(
546
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
562
+ `/v1/businesses/${apiConfig.businessId}/collections/${formattedId}`,
547
563
  options
548
564
  );
549
565
  },
@@ -607,8 +623,9 @@ var createCmsApi = (apiConfig) => {
607
623
  );
608
624
  },
609
625
  async getCollectionEntry(params, options) {
626
+ const formattedId = formatIdOrSlug(params.id, apiConfig);
610
627
  return apiConfig.httpClient.get(
611
- `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
628
+ `/v1/businesses/${apiConfig.businessId}/entries/${formattedId}`,
612
629
  options
613
630
  );
614
631
  },
@@ -633,8 +650,9 @@ var createCmsApi = (apiConfig) => {
633
650
  },
634
651
  // ===== COLLECTION SUBSCRIPTIONS =====
635
652
  async getCollectionSubscribers(params, options) {
653
+ const formattedId = formatIdOrSlug(params.id, apiConfig);
636
654
  return apiConfig.httpClient.get(
637
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}/subscribers`,
655
+ `/v1/businesses/${apiConfig.businessId}/collections/${formattedId}/subscribers`,
638
656
  options
639
657
  );
640
658
  },
@@ -650,10 +668,13 @@ var createCmsApi = (apiConfig) => {
650
668
  );
651
669
  },
652
670
  async unsubscribeFromCollection(params, options) {
653
- return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/collections/unsubscribe`, {
654
- ...options,
655
- params
656
- });
671
+ return apiConfig.httpClient.get(
672
+ `/v1/businesses/${apiConfig.businessId}/collections/unsubscribe`,
673
+ {
674
+ ...options,
675
+ params
676
+ }
677
+ );
657
678
  }
658
679
  };
659
680
  };
@@ -683,8 +704,9 @@ var createEshopApi = (apiConfig) => {
683
704
  );
684
705
  },
685
706
  async getProduct(params, options) {
707
+ const formattedId = formatIdOrSlug(params.id, apiConfig);
686
708
  return apiConfig.httpClient.get(
687
- `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
709
+ `/v1/businesses/${apiConfig.businessId}/products/${formattedId}`,
688
710
  options
689
711
  );
690
712
  },
@@ -755,7 +777,9 @@ var createEshopApi = (apiConfig) => {
755
777
  currency: params.currency,
756
778
  paymentMethod: params.paymentMethod,
757
779
  lines,
758
- ...params.shippingMethodId && { shippingMethodId: params.shippingMethodId },
780
+ ...params.shippingMethodId && {
781
+ shippingMethodId: params.shippingMethodId
782
+ },
759
783
  ...params.promoCode && { promoCode: params.promoCode }
760
784
  };
761
785
  return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
@@ -793,7 +817,11 @@ var createReservationApi = (apiConfig) => {
793
817
  },
794
818
  async updateReservation(params, options) {
795
819
  const { id, ...payload } = params;
796
- return apiConfig.httpClient.put(`/v1/reservations/${id}`, payload, options);
820
+ return apiConfig.httpClient.put(
821
+ `/v1/reservations/${id}`,
822
+ payload,
823
+ options
824
+ );
797
825
  },
798
826
  async checkout(params, options) {
799
827
  const payload = {
@@ -804,7 +832,11 @@ var createReservationApi = (apiConfig) => {
804
832
  ...params.paymentMethod && { paymentMethod: params.paymentMethod },
805
833
  ...params.promoCode && { promoCode: params.promoCode }
806
834
  };
807
- return apiConfig.httpClient.post(`/v1/reservations/checkout`, payload, options);
835
+ return apiConfig.httpClient.post(
836
+ `/v1/reservations/checkout`,
837
+ payload,
838
+ options
839
+ );
808
840
  },
809
841
  async getReservation(params, options) {
810
842
  return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
@@ -872,8 +904,9 @@ var createReservationApi = (apiConfig) => {
872
904
  );
873
905
  },
874
906
  async getService(params, options) {
907
+ const formattedId = formatIdOrSlug(params.id, apiConfig);
875
908
  return apiConfig.httpClient.get(
876
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
909
+ `/v1/businesses/${apiConfig.businessId}/services/${formattedId}`,
877
910
  options
878
911
  );
879
912
  },
@@ -1140,16 +1173,6 @@ var getImageUrl = (imageBlock, isBlock = true, storageUrl = "https://storage.ark
1140
1173
  }
1141
1174
  return null;
1142
1175
  };
1143
- function getGalleryThumbnail(gallery) {
1144
- if (!gallery?.length) return null;
1145
- const item = gallery.find((g) => g.settings.isThumbnail) || gallery[0];
1146
- const res = item.media.resolutions.thumbnail || item.media.resolutions.original;
1147
- return res?.url || null;
1148
- }
1149
- function thumbnailUrl(service, storageUrl = "") {
1150
- const path = getGalleryThumbnail(service.gallery);
1151
- return path ? `${storageUrl}/${path}` : null;
1152
- }
1153
1176
 
1154
1177
  // src/utils/currency.ts
1155
1178
  function getCurrencySymbol(currency) {
@@ -1499,7 +1522,7 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1499
1522
  }
1500
1523
 
1501
1524
  // src/index.ts
1502
- var SDK_VERSION = "0.3.28";
1525
+ var SDK_VERSION = "0.3.30";
1503
1526
  var SUPPORTED_FRAMEWORKS = [
1504
1527
  "astro",
1505
1528
  "react",
@@ -1508,8 +1531,9 @@ var SUPPORTED_FRAMEWORKS = [
1508
1531
  "vanilla"
1509
1532
  ];
1510
1533
  function createArkySDK(config) {
1534
+ const locale = config.locale || "en";
1511
1535
  console.log(
1512
- `[Arky SDK v${SDK_VERSION}] Initializing with market: ${config.market}, businessId: ${config.businessId}`
1536
+ `[Arky SDK v${SDK_VERSION}] Initializing with market: ${config.market}, businessId: ${config.businessId}, locale: ${locale}`
1513
1537
  );
1514
1538
  const httpClient = createHttpClient(config);
1515
1539
  const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
@@ -1519,6 +1543,7 @@ function createArkySDK(config) {
1519
1543
  storageUrl,
1520
1544
  baseUrl: config.baseUrl,
1521
1545
  market: config.market,
1546
+ locale,
1522
1547
  setToken: config.setToken,
1523
1548
  getToken: config.getToken
1524
1549
  };
@@ -1544,14 +1569,16 @@ function createArkySDK(config) {
1544
1569
  apiConfig.market = market;
1545
1570
  },
1546
1571
  getMarket: () => apiConfig.market,
1572
+ setLocale: (locale2) => {
1573
+ apiConfig.locale = locale2;
1574
+ },
1575
+ getLocale: () => apiConfig.locale,
1547
1576
  isAuthenticated: config.isAuthenticated || (() => false),
1548
1577
  logout: config.logout,
1549
1578
  setToken: config.setToken,
1550
1579
  utils: {
1551
1580
  // Block utilities
1552
1581
  getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
1553
- thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
1554
- getGalleryThumbnail,
1555
1582
  getBlockValue,
1556
1583
  getBlockValues,
1557
1584
  getBlockLabel,