arky-sdk 0.7.111 → 0.7.113

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.
@@ -1,6 +1,6 @@
1
- import { BookingPayment, OrderPayment, InventoryLevel } from './types.js';
1
+ import { OrderPayment, InventoryLevel } from './types.cjs';
2
2
 
3
- type AnyPayment = Pick<BookingPayment, 'total' | 'currency'> | Pick<OrderPayment, 'total' | 'currency'>;
3
+ type AnyPayment = Pick<OrderPayment, 'total' | 'currency'>;
4
4
  declare function convertToMajor(minorAmount: number, currency: string): number;
5
5
  declare function convertToMinor(majorAmount: number, currency: string): number;
6
6
  declare function getCurrencySymbol(currency: string): string;
@@ -1,6 +1,6 @@
1
- import { BookingPayment, OrderPayment, InventoryLevel } from './types.cjs';
1
+ import { OrderPayment, InventoryLevel } from './types.js';
2
2
 
3
- type AnyPayment = Pick<BookingPayment, 'total' | 'currency'> | Pick<OrderPayment, 'total' | 'currency'>;
3
+ type AnyPayment = Pick<OrderPayment, 'total' | 'currency'>;
4
4
  declare function convertToMajor(minorAmount: number, currency: string): number;
5
5
  declare function convertToMinor(majorAmount: number, currency: string): number;
6
6
  declare function getCurrencySymbol(currency: string): string;
package/dist/index.cjs CHANGED
@@ -133,6 +133,30 @@ var getImageUrl = (imageBlock, isBlock = true) => {
133
133
  return imageBlock.resolutions?.original?.url || null;
134
134
  };
135
135
 
136
+ // src/utils/orderItems.ts
137
+ function normalizeOrderQuoteItems(items) {
138
+ return items.map((item) => {
139
+ if ("type" in item) {
140
+ return item;
141
+ }
142
+ if ("product_id" in item) {
143
+ return { type: "product", ...item };
144
+ }
145
+ return { type: "booking", ...item };
146
+ });
147
+ }
148
+ function normalizeOrderCheckoutItems(items) {
149
+ return items.map((item) => {
150
+ if ("type" in item) {
151
+ return item;
152
+ }
153
+ if ("product_id" in item) {
154
+ return { type: "product", ...item };
155
+ }
156
+ return { type: "booking", ...item };
157
+ });
158
+ }
159
+
136
160
  // src/api/storefront.ts
137
161
  var COMMON_ACTIVITY_TYPES = [
138
162
  "page_view",
@@ -143,7 +167,7 @@ var COMMON_ACTIVITY_TYPES = [
143
167
  "cart_removed",
144
168
  "checkout_started",
145
169
  "purchase",
146
- "booking_created",
170
+ "order_created",
147
171
  "signin",
148
172
  "signup",
149
173
  "verified_email",
@@ -163,24 +187,8 @@ var createActivityApi = (apiConfig) => ({
163
187
  }
164
188
  }
165
189
  });
166
- function groupCartToItems(cart) {
167
- const groups = /* @__PURE__ */ new Map();
168
- for (const slot of cart) {
169
- const key = `${slot.service_id}:${slot.provider_id}`;
170
- if (!groups.has(key)) {
171
- groups.set(key, {
172
- service_id: slot.service_id,
173
- provider_id: slot.provider_id,
174
- slots: []
175
- });
176
- }
177
- groups.get(key).slots.push({ from: slot.from, to: slot.to });
178
- }
179
- return [...groups.values()];
180
- }
181
190
  var createStorefrontApi = (apiConfig, updateCustomerSession) => {
182
191
  const base = (storeId = apiConfig.storeId) => `/v1/storefront/${storeId}`;
183
- let cart = [];
184
192
  return {
185
193
  store: {
186
194
  getStore(options) {
@@ -341,7 +349,7 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
341
349
  order: {
342
350
  getQuote(params, options) {
343
351
  const store_id = params.store_id || apiConfig.storeId;
344
- const { location, store_id: _store_id, ...rest } = params;
352
+ const { location, store_id: _store_id, items, market, ...rest } = params;
345
353
  const shipping_address = location ? {
346
354
  country: location.country || "",
347
355
  state: location.state || "",
@@ -350,19 +358,29 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
350
358
  name: "",
351
359
  street1: "",
352
360
  street2: null
353
- } : void 0;
361
+ } : rest.shipping_address;
354
362
  return apiConfig.httpClient.post(
355
363
  `${base(store_id)}/orders/quote`,
356
- { ...rest, shipping_address, market: apiConfig.market },
364
+ {
365
+ ...rest,
366
+ items: normalizeOrderQuoteItems(items),
367
+ shipping_address,
368
+ market: market || apiConfig.market
369
+ },
357
370
  options
358
371
  );
359
372
  },
360
373
  checkout(params, options) {
361
- const { store_id, ...rest } = params;
374
+ const { store_id, items, market, ...rest } = params;
362
375
  const target = store_id || apiConfig.storeId;
363
376
  return apiConfig.httpClient.post(
364
377
  `${base(target)}/orders/checkout`,
365
- { ...rest, store_id: target, market: apiConfig.market },
378
+ {
379
+ ...rest,
380
+ items: normalizeOrderCheckoutItems(items),
381
+ store_id: target,
382
+ market: market || apiConfig.market
383
+ },
366
384
  options
367
385
  );
368
386
  },
@@ -379,71 +397,15 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
379
397
  ...options,
380
398
  params: queryParams
381
399
  });
400
+ },
401
+ getAvailability(params, options) {
402
+ const { store_id, ...queryParams } = params;
403
+ const target_store_id = store_id || apiConfig.storeId;
404
+ return apiConfig.httpClient.get(
405
+ `${base(target_store_id)}/orders/availability`,
406
+ { ...options, params: queryParams }
407
+ );
382
408
  }
383
- }
384
- },
385
- booking: {
386
- addToCart(slot) {
387
- cart.push(slot);
388
- },
389
- removeFromCart(slotId) {
390
- cart = cart.filter((slot) => slot.id !== slotId);
391
- },
392
- getCart() {
393
- return [...cart];
394
- },
395
- clearCart() {
396
- cart = [];
397
- },
398
- checkout(params, options) {
399
- const { store_id, items: paramItems, ...payload } = params || {};
400
- const target_store_id = store_id || apiConfig.storeId;
401
- const items = paramItems || groupCartToItems(cart);
402
- return apiConfig.httpClient.post(
403
- `${base(target_store_id)}/bookings/checkout`,
404
- { market: apiConfig.market, ...payload, items },
405
- options
406
- );
407
- },
408
- get(params, options) {
409
- const store_id = params.store_id || apiConfig.storeId;
410
- return apiConfig.httpClient.get(
411
- `${base(store_id)}/bookings/${params.id}`,
412
- options
413
- );
414
- },
415
- find(params, options) {
416
- const { store_id, ...queryParams } = params;
417
- return apiConfig.httpClient.get(`${base(store_id)}/bookings`, {
418
- ...options,
419
- params: queryParams
420
- });
421
- },
422
- getQuote(params, options) {
423
- const { store_id, ...payload } = params;
424
- const target_store_id = store_id || apiConfig.storeId;
425
- return apiConfig.httpClient.post(
426
- `${base(target_store_id)}/bookings/quote`,
427
- { market: apiConfig.market, ...payload },
428
- options
429
- );
430
- },
431
- getAvailability(params, options) {
432
- const { store_id, ...queryParams } = params;
433
- const target_store_id = store_id || apiConfig.storeId;
434
- return apiConfig.httpClient.get(
435
- `${base(target_store_id)}/bookings/availability`,
436
- { ...options, params: queryParams }
437
- );
438
- },
439
- cancelItem(params, options) {
440
- const { store_id, booking_id, item_id, ...payload } = params;
441
- const target_store_id = store_id || apiConfig.storeId;
442
- return apiConfig.httpClient.post(
443
- `${base(target_store_id)}/bookings/${booking_id}/items/${item_id}/cancel`,
444
- payload,
445
- options
446
- );
447
409
  },
448
410
  service: {
449
411
  get(params, options) {
@@ -1359,6 +1321,13 @@ var createCmsApi = (apiConfig) => {
1359
1321
  };
1360
1322
 
1361
1323
  // src/api/eshop.ts
1324
+ var normalizeTaxonomyAliases = (payload) => {
1325
+ const { filters, ...rest } = payload;
1326
+ return {
1327
+ ...rest,
1328
+ ...!rest.taxonomies && filters ? { taxonomies: filters } : {}
1329
+ };
1330
+ };
1362
1331
  var createEshopApi = (apiConfig) => {
1363
1332
  return {
1364
1333
  async createProduct(params, options) {
@@ -1366,7 +1335,7 @@ var createEshopApi = (apiConfig) => {
1366
1335
  const target_store_id = store_id || apiConfig.storeId;
1367
1336
  return apiConfig.httpClient.post(
1368
1337
  `/v1/stores/${target_store_id}/products`,
1369
- payload,
1338
+ normalizeTaxonomyAliases(payload),
1370
1339
  options
1371
1340
  );
1372
1341
  },
@@ -1375,7 +1344,7 @@ var createEshopApi = (apiConfig) => {
1375
1344
  const target_store_id = store_id || apiConfig.storeId;
1376
1345
  return apiConfig.httpClient.put(
1377
1346
  `/v1/stores/${target_store_id}/products/${params.id}`,
1378
- payload,
1347
+ normalizeTaxonomyAliases(payload),
1379
1348
  options
1380
1349
  );
1381
1350
  },
@@ -1413,17 +1382,41 @@ var createEshopApi = (apiConfig) => {
1413
1382
  );
1414
1383
  },
1415
1384
  async createOrder(params, options) {
1416
- const { store_id, ...payload } = params;
1385
+ const { store_id, items, ...rest } = params;
1417
1386
  const target_store_id = store_id || apiConfig.storeId;
1387
+ const payload = {
1388
+ ...rest,
1389
+ market: rest.market || apiConfig.market,
1390
+ items: normalizeOrderCheckoutItems(items)
1391
+ };
1418
1392
  return apiConfig.httpClient.post(
1419
1393
  `/v1/stores/${target_store_id}/orders`,
1420
1394
  payload,
1421
1395
  options
1422
1396
  );
1423
1397
  },
1398
+ async checkoutOrder(params, options) {
1399
+ const { store_id, items, ...rest } = params;
1400
+ const target_store_id = store_id || apiConfig.storeId;
1401
+ const payload = {
1402
+ ...rest,
1403
+ store_id: target_store_id,
1404
+ market: rest.market || apiConfig.market,
1405
+ items: normalizeOrderCheckoutItems(items)
1406
+ };
1407
+ return apiConfig.httpClient.post(
1408
+ `/v1/stores/${target_store_id}/orders/checkout`,
1409
+ payload,
1410
+ options
1411
+ );
1412
+ },
1424
1413
  async updateOrder(params, options) {
1425
- const { store_id, ...payload } = params;
1414
+ const { store_id, items, ...rest } = params;
1426
1415
  const target_store_id = store_id || apiConfig.storeId;
1416
+ const payload = {
1417
+ ...rest,
1418
+ ...items ? { items: normalizeOrderCheckoutItems(items) } : {}
1419
+ };
1427
1420
  return apiConfig.httpClient.put(
1428
1421
  `/v1/stores/${target_store_id}/orders/${params.id}`,
1429
1422
  payload,
@@ -1449,7 +1442,8 @@ var createEshopApi = (apiConfig) => {
1449
1442
  );
1450
1443
  },
1451
1444
  async getQuote(params, options) {
1452
- const { location, ...rest } = params;
1445
+ const { location, store_id, items, ...rest } = params;
1446
+ const target_store_id = store_id || apiConfig.storeId;
1453
1447
  const shipping_address = location ? {
1454
1448
  country: location.country || "",
1455
1449
  state: location.state || "",
@@ -1458,13 +1452,26 @@ var createEshopApi = (apiConfig) => {
1458
1452
  name: "",
1459
1453
  street1: "",
1460
1454
  street2: null
1461
- } : void 0;
1455
+ } : rest.shipping_address;
1462
1456
  return apiConfig.httpClient.post(
1463
- `/v1/stores/${apiConfig.storeId}/orders/quote`,
1464
- { ...rest, shipping_address, market: apiConfig.market },
1457
+ `/v1/stores/${target_store_id}/orders/quote`,
1458
+ {
1459
+ ...rest,
1460
+ items: normalizeOrderQuoteItems(items),
1461
+ shipping_address,
1462
+ market: rest.market || apiConfig.market
1463
+ },
1465
1464
  options
1466
1465
  );
1467
1466
  },
1467
+ async getOrderAvailability(params, options) {
1468
+ const { store_id, ...queryParams } = params;
1469
+ const target_store_id = store_id || apiConfig.storeId;
1470
+ return apiConfig.httpClient.get(
1471
+ `/v1/stores/${target_store_id}/orders/availability`,
1472
+ { ...options, params: queryParams }
1473
+ );
1474
+ },
1468
1475
  async processRefund(params, options) {
1469
1476
  return apiConfig.httpClient.post(
1470
1477
  `/v1/stores/${apiConfig.storeId}/orders/${params.id}/refund`,
@@ -1475,87 +1482,22 @@ var createEshopApi = (apiConfig) => {
1475
1482
  };
1476
1483
  };
1477
1484
 
1478
- // src/api/booking.ts
1479
- var createBookingApi = (apiConfig) => {
1480
- let cart = [];
1485
+ // src/api/scheduling.ts
1486
+ var normalizeTaxonomyAliases2 = (payload) => {
1487
+ const { filters, ...rest } = payload;
1488
+ return {
1489
+ ...rest,
1490
+ ...!rest.taxonomies && filters ? { taxonomies: filters } : {}
1491
+ };
1492
+ };
1493
+ var createSchedulingApi = (apiConfig) => {
1481
1494
  return {
1482
- addToCart(slot) {
1483
- cart.push(slot);
1484
- },
1485
- removeFromCart(slotId) {
1486
- cart = cart.filter((s) => s.id !== slotId);
1487
- },
1488
- getCart() {
1489
- return [...cart];
1490
- },
1491
- clearCart() {
1492
- cart = [];
1493
- },
1494
- async createBooking(params, options) {
1495
- const { store_id, ...payload } = params;
1496
- const target_store_id = store_id || apiConfig.storeId;
1497
- return apiConfig.httpClient.post(
1498
- `/v1/stores/${target_store_id}/bookings`,
1499
- { market: apiConfig.market, ...payload },
1500
- options
1501
- );
1502
- },
1503
- async updateBooking(params, options) {
1504
- const { id, ...payload } = params;
1505
- return apiConfig.httpClient.put(
1506
- `/v1/stores/${apiConfig.storeId}/bookings/${id}`,
1507
- payload,
1508
- options
1509
- );
1510
- },
1511
- async getBooking(params, options) {
1512
- const target_store_id = params.store_id || apiConfig.storeId;
1513
- return apiConfig.httpClient.get(
1514
- `/v1/stores/${target_store_id}/bookings/${params.id}`,
1515
- options
1516
- );
1517
- },
1518
- async searchBookings(params, options) {
1519
- const { store_id, ...queryParams } = params;
1520
- const target_store_id = store_id || apiConfig.storeId;
1521
- return apiConfig.httpClient.get(
1522
- `/v1/stores/${target_store_id}/bookings`,
1523
- {
1524
- ...options,
1525
- params: queryParams
1526
- }
1527
- );
1528
- },
1529
- async getQuote(params, options) {
1530
- const { store_id, ...payload } = params;
1531
- const target_store_id = store_id || apiConfig.storeId;
1532
- return apiConfig.httpClient.post(
1533
- `/v1/stores/${target_store_id}/bookings/quote`,
1534
- { market: apiConfig.market, ...payload },
1535
- options
1536
- );
1537
- },
1538
- async processRefund(params, options) {
1539
- return apiConfig.httpClient.post(
1540
- `/v1/stores/${apiConfig.storeId}/bookings/${params.id}/refund`,
1541
- { amount: params.amount },
1542
- options
1543
- );
1544
- },
1545
- async getAvailability(params, options) {
1546
- const { store_id, ...query } = params;
1547
- const target_store_id = store_id || apiConfig.storeId;
1548
- return apiConfig.httpClient.get(
1549
- `/v1/stores/${target_store_id}/bookings/availability`,
1550
- { ...options, params: query }
1551
- );
1552
- },
1553
1495
  async createService(params, options) {
1554
1496
  const { store_id, ...payload } = params;
1555
1497
  const target_store_id = store_id || apiConfig.storeId;
1556
1498
  return apiConfig.httpClient.post(
1557
1499
  `/v1/stores/${target_store_id}/services`,
1558
- payload,
1500
+ normalizeTaxonomyAliases2(payload),
1559
1501
  options
1560
1502
  );
1561
1503
  },
@@ -1564,7 +1506,7 @@ var createBookingApi = (apiConfig) => {
1564
1506
  const target_store_id = store_id || apiConfig.storeId;
1565
1507
  return apiConfig.httpClient.put(
1566
1508
  `/v1/stores/${target_store_id}/services/${params.id}`,
1567
- payload,
1509
+ normalizeTaxonomyAliases2(payload),
1568
1510
  options
1569
1511
  );
1570
1512
  },
@@ -1606,7 +1548,7 @@ var createBookingApi = (apiConfig) => {
1606
1548
  const target_store_id = store_id || apiConfig.storeId;
1607
1549
  return apiConfig.httpClient.post(
1608
1550
  `/v1/stores/${target_store_id}/providers`,
1609
- payload,
1551
+ normalizeTaxonomyAliases2(payload),
1610
1552
  options
1611
1553
  );
1612
1554
  },
@@ -1615,7 +1557,7 @@ var createBookingApi = (apiConfig) => {
1615
1557
  const target_store_id = store_id || apiConfig.storeId;
1616
1558
  return apiConfig.httpClient.put(
1617
1559
  `/v1/stores/${target_store_id}/providers/${params.id}`,
1618
- payload,
1560
+ normalizeTaxonomyAliases2(payload),
1619
1561
  options
1620
1562
  );
1621
1563
  },
@@ -1652,15 +1594,6 @@ var createBookingApi = (apiConfig) => {
1652
1594
  }
1653
1595
  );
1654
1596
  },
1655
- async cancelBookingItem(params, options) {
1656
- const { store_id, booking_id, item_id, ...payload } = params;
1657
- const target_store_id = store_id || apiConfig.storeId;
1658
- return apiConfig.httpClient.post(
1659
- `/v1/stores/${target_store_id}/bookings/${booking_id}/items/${item_id}/cancel`,
1660
- payload,
1661
- options
1662
- );
1663
- },
1664
1597
  async findServiceProviders(params, options) {
1665
1598
  const { store_id, ...queryParams } = params;
1666
1599
  const target_store_id = store_id || apiConfig.storeId;
@@ -2649,7 +2582,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
2649
2582
  }
2650
2583
 
2651
2584
  // src/index.ts
2652
- var SDK_VERSION = "0.7.110";
2585
+ var SDK_VERSION = "0.7.112";
2653
2586
  var SUPPORTED_FRAMEWORKS = [
2654
2587
  "astro",
2655
2588
  "react",
@@ -2786,7 +2719,8 @@ function createAdmin(config) {
2786
2719
  const platformApi = createPlatformApi(apiConfig);
2787
2720
  const cmsApi = createCmsApi(apiConfig);
2788
2721
  const eshopApi = createEshopApi(apiConfig);
2789
- const bookingApi = createBookingApi(apiConfig);
2722
+ const schedulingApi = createSchedulingApi(apiConfig);
2723
+ const promoCodeApi = createPromoCodeApi(apiConfig);
2790
2724
  const crmApi = createCustomerApi(apiConfig);
2791
2725
  const locationApi = createLocationApi(apiConfig);
2792
2726
  const marketApi = createMarketApi(apiConfig);
@@ -2806,7 +2740,7 @@ function createAdmin(config) {
2806
2740
  },
2807
2741
  media: createMediaApi(apiConfig),
2808
2742
  notification: createNotificationApi(apiConfig),
2809
- promoCode: createPromoCodeApi(apiConfig),
2743
+ promoCode: promoCodeApi,
2810
2744
  platform: platformApi,
2811
2745
  shipping: createShippingApi(apiConfig),
2812
2746
  cms: {
@@ -2859,40 +2793,29 @@ function createAdmin(config) {
2859
2793
  get: eshopApi.getOrder,
2860
2794
  find: eshopApi.getOrders,
2861
2795
  getQuote: eshopApi.getQuote,
2796
+ checkout: eshopApi.checkoutOrder,
2797
+ getAvailability: eshopApi.getOrderAvailability,
2862
2798
  processRefund: eshopApi.processRefund
2863
- }
2864
- },
2865
- booking: {
2866
- addToCart: bookingApi.addToCart,
2867
- removeFromCart: bookingApi.removeFromCart,
2868
- getCart: bookingApi.getCart,
2869
- clearCart: bookingApi.clearCart,
2870
- create: bookingApi.createBooking,
2871
- update: bookingApi.updateBooking,
2872
- get: bookingApi.getBooking,
2873
- find: bookingApi.searchBookings,
2874
- getQuote: bookingApi.getQuote,
2875
- processRefund: bookingApi.processRefund,
2876
- getAvailability: bookingApi.getAvailability,
2877
- cancelItem: bookingApi.cancelBookingItem,
2799
+ },
2878
2800
  service: {
2879
- create: bookingApi.createService,
2880
- update: bookingApi.updateService,
2881
- delete: bookingApi.deleteService,
2882
- get: bookingApi.getService,
2883
- find: bookingApi.getServices,
2884
- findProviders: bookingApi.findServiceProviders,
2885
- createProvider: bookingApi.createServiceProvider,
2886
- updateProvider: bookingApi.updateServiceProvider,
2887
- deleteProvider: bookingApi.deleteServiceProvider
2801
+ create: schedulingApi.createService,
2802
+ update: schedulingApi.updateService,
2803
+ delete: schedulingApi.deleteService,
2804
+ get: schedulingApi.getService,
2805
+ find: schedulingApi.getServices,
2806
+ findProviders: schedulingApi.findServiceProviders,
2807
+ createProvider: schedulingApi.createServiceProvider,
2808
+ updateProvider: schedulingApi.updateServiceProvider,
2809
+ deleteProvider: schedulingApi.deleteServiceProvider
2888
2810
  },
2889
2811
  provider: {
2890
- create: bookingApi.createProvider,
2891
- update: bookingApi.updateProvider,
2892
- delete: bookingApi.deleteProvider,
2893
- get: bookingApi.getProvider,
2894
- find: bookingApi.getProviders
2895
- }
2812
+ create: schedulingApi.createProvider,
2813
+ update: schedulingApi.updateProvider,
2814
+ delete: schedulingApi.deleteProvider,
2815
+ get: schedulingApi.getProvider,
2816
+ find: schedulingApi.getProviders
2817
+ },
2818
+ promoCode: promoCodeApi
2896
2819
  },
2897
2820
  crm: {
2898
2821
  customer: {
@@ -3139,7 +3062,6 @@ function createStorefront(config) {
3139
3062
  store: storefrontApi.store,
3140
3063
  cms: storefrontApi.cms,
3141
3064
  eshop: storefrontApi.eshop,
3142
- booking: storefrontApi.booking,
3143
3065
  crm: storefrontApi.crm,
3144
3066
  activity: storefrontApi.activity,
3145
3067
  automation: storefrontApi.automation,