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.
@@ -126,6 +126,30 @@ var getImageUrl = (imageBlock, isBlock = true) => {
126
126
  return imageBlock.resolutions?.original?.url || null;
127
127
  };
128
128
 
129
+ // src/utils/orderItems.ts
130
+ function normalizeOrderQuoteItems(items) {
131
+ return items.map((item) => {
132
+ if ("type" in item) {
133
+ return item;
134
+ }
135
+ if ("product_id" in item) {
136
+ return { type: "product", ...item };
137
+ }
138
+ return { type: "booking", ...item };
139
+ });
140
+ }
141
+ function normalizeOrderCheckoutItems(items) {
142
+ return items.map((item) => {
143
+ if ("type" in item) {
144
+ return item;
145
+ }
146
+ if ("product_id" in item) {
147
+ return { type: "product", ...item };
148
+ }
149
+ return { type: "booking", ...item };
150
+ });
151
+ }
152
+
129
153
  // src/api/storefront.ts
130
154
  var COMMON_ACTIVITY_TYPES = [
131
155
  "page_view",
@@ -136,7 +160,7 @@ var COMMON_ACTIVITY_TYPES = [
136
160
  "cart_removed",
137
161
  "checkout_started",
138
162
  "purchase",
139
- "booking_created",
163
+ "order_created",
140
164
  "signin",
141
165
  "signup",
142
166
  "verified_email",
@@ -156,24 +180,8 @@ var createActivityApi = (apiConfig) => ({
156
180
  }
157
181
  }
158
182
  });
159
- function groupCartToItems(cart) {
160
- const groups = /* @__PURE__ */ new Map();
161
- for (const slot of cart) {
162
- const key = `${slot.service_id}:${slot.provider_id}`;
163
- if (!groups.has(key)) {
164
- groups.set(key, {
165
- service_id: slot.service_id,
166
- provider_id: slot.provider_id,
167
- slots: []
168
- });
169
- }
170
- groups.get(key).slots.push({ from: slot.from, to: slot.to });
171
- }
172
- return [...groups.values()];
173
- }
174
183
  var createStorefrontApi = (apiConfig, updateCustomerSession) => {
175
184
  const base = (storeId = apiConfig.storeId) => `/v1/storefront/${storeId}`;
176
- let cart = [];
177
185
  return {
178
186
  store: {
179
187
  getStore(options) {
@@ -334,7 +342,7 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
334
342
  order: {
335
343
  getQuote(params, options) {
336
344
  const store_id = params.store_id || apiConfig.storeId;
337
- const { location, store_id: _store_id, ...rest } = params;
345
+ const { location, store_id: _store_id, items, market, ...rest } = params;
338
346
  const shipping_address = location ? {
339
347
  country: location.country || "",
340
348
  state: location.state || "",
@@ -343,19 +351,29 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
343
351
  name: "",
344
352
  street1: "",
345
353
  street2: null
346
- } : void 0;
354
+ } : rest.shipping_address;
347
355
  return apiConfig.httpClient.post(
348
356
  `${base(store_id)}/orders/quote`,
349
- { ...rest, shipping_address, market: apiConfig.market },
357
+ {
358
+ ...rest,
359
+ items: normalizeOrderQuoteItems(items),
360
+ shipping_address,
361
+ market: market || apiConfig.market
362
+ },
350
363
  options
351
364
  );
352
365
  },
353
366
  checkout(params, options) {
354
- const { store_id, ...rest } = params;
367
+ const { store_id, items, market, ...rest } = params;
355
368
  const target = store_id || apiConfig.storeId;
356
369
  return apiConfig.httpClient.post(
357
370
  `${base(target)}/orders/checkout`,
358
- { ...rest, store_id: target, market: apiConfig.market },
371
+ {
372
+ ...rest,
373
+ items: normalizeOrderCheckoutItems(items),
374
+ store_id: target,
375
+ market: market || apiConfig.market
376
+ },
359
377
  options
360
378
  );
361
379
  },
@@ -372,71 +390,15 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
372
390
  ...options,
373
391
  params: queryParams
374
392
  });
393
+ },
394
+ getAvailability(params, options) {
395
+ const { store_id, ...queryParams } = params;
396
+ const target_store_id = store_id || apiConfig.storeId;
397
+ return apiConfig.httpClient.get(
398
+ `${base(target_store_id)}/orders/availability`,
399
+ { ...options, params: queryParams }
400
+ );
375
401
  }
376
- }
377
- },
378
- booking: {
379
- addToCart(slot) {
380
- cart.push(slot);
381
- },
382
- removeFromCart(slotId) {
383
- cart = cart.filter((slot) => slot.id !== slotId);
384
- },
385
- getCart() {
386
- return [...cart];
387
- },
388
- clearCart() {
389
- cart = [];
390
- },
391
- checkout(params, options) {
392
- const { store_id, items: paramItems, ...payload } = params || {};
393
- const target_store_id = store_id || apiConfig.storeId;
394
- const items = paramItems || groupCartToItems(cart);
395
- return apiConfig.httpClient.post(
396
- `${base(target_store_id)}/bookings/checkout`,
397
- { market: apiConfig.market, ...payload, items },
398
- options
399
- );
400
- },
401
- get(params, options) {
402
- const store_id = params.store_id || apiConfig.storeId;
403
- return apiConfig.httpClient.get(
404
- `${base(store_id)}/bookings/${params.id}`,
405
- options
406
- );
407
- },
408
- find(params, options) {
409
- const { store_id, ...queryParams } = params;
410
- return apiConfig.httpClient.get(`${base(store_id)}/bookings`, {
411
- ...options,
412
- params: queryParams
413
- });
414
- },
415
- getQuote(params, options) {
416
- const { store_id, ...payload } = params;
417
- const target_store_id = store_id || apiConfig.storeId;
418
- return apiConfig.httpClient.post(
419
- `${base(target_store_id)}/bookings/quote`,
420
- { market: apiConfig.market, ...payload },
421
- options
422
- );
423
- },
424
- getAvailability(params, options) {
425
- const { store_id, ...queryParams } = params;
426
- const target_store_id = store_id || apiConfig.storeId;
427
- return apiConfig.httpClient.get(
428
- `${base(target_store_id)}/bookings/availability`,
429
- { ...options, params: queryParams }
430
- );
431
- },
432
- cancelItem(params, options) {
433
- const { store_id, booking_id, item_id, ...payload } = params;
434
- const target_store_id = store_id || apiConfig.storeId;
435
- return apiConfig.httpClient.post(
436
- `${base(target_store_id)}/bookings/${booking_id}/items/${item_id}/cancel`,
437
- payload,
438
- options
439
- );
440
402
  },
441
403
  service: {
442
404
  get(params, options) {
@@ -1316,7 +1278,6 @@ function createStorefront(config) {
1316
1278
  store: storefrontApi.store,
1317
1279
  cms: storefrontApi.cms,
1318
1280
  eshop: storefrontApi.eshop,
1319
- booking: storefrontApi.booking,
1320
1281
  crm: storefrontApi.crm,
1321
1282
  activity: storefrontApi.activity,
1322
1283
  automation: storefrontApi.automation,