@kasuvia/sdk 0.0.2 → 0.0.5

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.
Files changed (77) hide show
  1. package/dist/hooks/index.d.mts +430 -0
  2. package/dist/hooks/index.d.ts +430 -0
  3. package/dist/hooks/index.js +3073 -0
  4. package/dist/hooks/index.js.map +1 -0
  5. package/dist/hooks/index.mjs +2962 -0
  6. package/dist/hooks/index.mjs.map +1 -0
  7. package/dist/index-CxNLI4nw.d.ts +786 -0
  8. package/dist/index-CzVMyUs4.d.mts +492 -0
  9. package/dist/index-CzVMyUs4.d.ts +492 -0
  10. package/dist/index-Dowl5224.d.mts +786 -0
  11. package/dist/index.d.mts +48 -1739
  12. package/dist/index.d.ts +48 -1739
  13. package/dist/index.js +1544 -2359
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +1527 -2258
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/sdk-context-BuarJbeb.d.ts +75 -0
  18. package/dist/sdk-context-Db8kf1Tv.d.mts +75 -0
  19. package/dist/services/index.d.mts +2 -0
  20. package/dist/services/index.d.ts +2 -0
  21. package/dist/services/index.js +2369 -0
  22. package/dist/services/index.js.map +1 -0
  23. package/dist/services/index.mjs +2252 -0
  24. package/dist/services/index.mjs.map +1 -0
  25. package/package.json +11 -2
  26. package/src/config/index.ts +10 -91
  27. package/src/constants.ts +13 -0
  28. package/src/context/sdk-context.tsx +70 -0
  29. package/src/graphql/collections.graphql.ts +2 -10
  30. package/src/graphql/products.graphql.ts +215 -65
  31. package/src/graphql/wishlist.graphql.ts +7 -6
  32. package/src/hooks/index.ts +2 -0
  33. package/src/hooks/use-auth.ts +82 -158
  34. package/src/hooks/use-bespoke-availability.ts +25 -8
  35. package/src/hooks/use-cart.ts +222 -119
  36. package/src/hooks/use-cms.ts +179 -86
  37. package/src/hooks/use-collections.ts +52 -15
  38. package/src/hooks/use-consultation-stream.ts +4 -3
  39. package/src/hooks/use-consultations.ts +120 -51
  40. package/src/hooks/use-countries.ts +35 -13
  41. package/src/hooks/use-currencies.ts +26 -13
  42. package/src/hooks/use-google-translate.ts +22 -8
  43. package/src/hooks/use-languages.ts +40 -20
  44. package/src/hooks/use-mobile.ts +23 -0
  45. package/src/hooks/use-order-stream.ts +9 -5
  46. package/src/hooks/use-orders.ts +99 -44
  47. package/src/hooks/use-payment.ts +108 -40
  48. package/src/hooks/use-products.ts +251 -53
  49. package/src/hooks/use-service-booking.ts +152 -90
  50. package/src/hooks/use-states.ts +35 -15
  51. package/src/hooks/use-wishlist.ts +92 -91
  52. package/src/index.ts +26 -30
  53. package/src/services/auth.service.ts +209 -167
  54. package/src/services/bespoke.service.ts +12 -4
  55. package/src/services/cart.service.ts +172 -70
  56. package/src/services/cms.service.ts +70 -35
  57. package/src/services/collection.service.ts +22 -5
  58. package/src/services/config.service.ts +34 -14
  59. package/src/services/consultation.service.ts +72 -18
  60. package/src/services/logistics.service.ts +35 -11
  61. package/src/services/notifications.service.ts +27 -12
  62. package/src/services/order.service.ts +74 -15
  63. package/src/services/payment.service.ts +86 -31
  64. package/src/services/product.service.ts +279 -39
  65. package/src/services/service-booking.service.ts +98 -26
  66. package/src/services/wishlist.service.ts +69 -25
  67. package/src/types/auth/index.ts +6 -4
  68. package/src/types/business/index.ts +7 -2
  69. package/src/types/payments/index.ts +3 -3
  70. package/src/types/services/index.ts +2 -5
  71. package/src/types/store/index.ts +38 -3
  72. package/src/utils/error-handler.ts +10 -5
  73. package/src/utils/storage.ts +48 -26
  74. package/src/utils/validators.ts +85 -0
  75. package/src/client/authClient.ts +0 -135
  76. package/src/client/graphqlClient.ts +0 -53
  77. package/src/client/httpClient.ts +0 -298
@@ -0,0 +1,2369 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/services/index.ts
21
+ var services_exports = {};
22
+ __export(services_exports, {
23
+ acceptQuote: () => acceptQuote,
24
+ addToCart: () => addToCart,
25
+ addToGuestCart: () => addToGuestCart,
26
+ addToWishlist: () => addToWishlist,
27
+ approveDeliverable: () => approveDeliverable,
28
+ bespokeService: () => bespokeService,
29
+ bookAppointment: () => bookAppointment,
30
+ cancelAppointment: () => cancelAppointment,
31
+ cancelOrder: () => cancelOrder,
32
+ checkAvailability: () => checkAvailability,
33
+ checkInWishlist: () => checkInWishlist,
34
+ clearCart: () => clearCart,
35
+ clearGuestCart: () => clearGuestCart,
36
+ clearTokens: () => clearTokens,
37
+ configService: () => configService,
38
+ consultationService: () => consultationService,
39
+ createCmsEntry: () => createCmsEntry,
40
+ createConsultation: () => createConsultation,
41
+ createDedicatedAccount: () => createDedicatedAccount,
42
+ createOrder: () => createOrder,
43
+ deleteCmsEntry: () => deleteCmsEntry,
44
+ findOrder: () => findOrder,
45
+ findOrderByToken: () => findOrderByToken,
46
+ getAppointment: () => getAppointment,
47
+ getAppointments: () => getAppointments,
48
+ getAuthUser: () => getAuthUser,
49
+ getAvailableSlots: () => getAvailableSlots,
50
+ getBusinessConfig: () => getBusinessConfig,
51
+ getCart: () => getCart,
52
+ getCmsEntry: () => getCmsEntry,
53
+ getConsultation: () => getConsultation,
54
+ getConsultations: () => getConsultations,
55
+ getDeliverables: () => getDeliverables,
56
+ getFeaturedProducts: () => getFeaturedProducts,
57
+ getGuestCart: () => getGuestCart,
58
+ getGuestCartCount: () => getGuestCartCount,
59
+ getGuestCartProductType: () => getGuestCartProductType,
60
+ getGuestCartSubtotal: () => getGuestCartSubtotal,
61
+ getLatestProducts: () => getLatestProducts,
62
+ getLowStockProducts: () => getLowStockProducts,
63
+ getMe: () => getMe,
64
+ getNewProducts: () => getNewProducts,
65
+ getOnSaleProducts: () => getOnSaleProducts,
66
+ getOrders: () => getOrders,
67
+ getPopularProducts: () => getPopularProducts,
68
+ getRecommendedProducts: () => getRecommendedProducts,
69
+ getSellerShippingAddress: () => getSellerShippingAddress,
70
+ getShippingRates: () => getShippingRates,
71
+ getStoredTokens: () => getStoredTokens,
72
+ getStorefrontCollectionBySlug: () => getStorefrontCollectionBySlug,
73
+ getStorefrontCollections: () => getStorefrontCollections,
74
+ getStorefrontProductBySlug: () => getStorefrontProductBySlug,
75
+ getStorefrontProducts: () => getStorefrontProducts,
76
+ getSupportedCurrencies: () => getSupportedCurrencies,
77
+ getSupportedLanguages: () => getSupportedLanguages,
78
+ getTransactionStatus: () => getTransactionStatus,
79
+ getWishlist: () => getWishlist,
80
+ googleTranslate: () => googleTranslate,
81
+ initiatePayment: () => initiatePayment,
82
+ listCmsEntries: () => listCmsEntries,
83
+ loginCustomer: () => loginCustomer,
84
+ logisticsService: () => logisticsService,
85
+ logout: () => logout,
86
+ mapAuthUserToCustomer: () => mapAuthUserToCustomer,
87
+ mergeGuestCart: () => mergeGuestCart,
88
+ mergeGuestCartIfPresent: () => mergeGuestCartIfPresent,
89
+ notificationsService: () => notificationsService,
90
+ paymentService: () => paymentService,
91
+ refreshToken: () => refreshToken,
92
+ registerCustomer: () => registerCustomer,
93
+ rejectQuote: () => rejectQuote,
94
+ removeFromCart: () => removeFromCart,
95
+ removeFromGuestCart: () => removeFromGuestCart,
96
+ removeFromWishlist: () => removeFromWishlist,
97
+ removeProductFromWishlist: () => removeProductFromWishlist,
98
+ requestQuote: () => requestQuote,
99
+ requestRevision: () => requestRevision,
100
+ sendContactConfirmation: () => sendContactConfirmation,
101
+ sendContactEmail: () => sendContactEmail,
102
+ sendMessage: () => sendMessage,
103
+ serviceBookingService: () => serviceBookingService,
104
+ silentRefresh: () => silentRefresh,
105
+ storeTokens: () => storeTokens,
106
+ trackOrder: () => trackOrder,
107
+ updateCartItem: () => updateCartItem,
108
+ updateCmsEntry: () => updateCmsEntry,
109
+ updateGuestCartItemQuantity: () => updateGuestCartItemQuantity,
110
+ updateProfile: () => updateProfile,
111
+ validateShippingAddress: () => validateShippingAddress,
112
+ verifySocialToken: () => verifySocialToken,
113
+ verifyTransaction: () => verifyTransaction
114
+ });
115
+ module.exports = __toCommonJS(services_exports);
116
+
117
+ // src/services/cart.service.ts
118
+ function parseItems(items) {
119
+ return items.map((item) => ({
120
+ ...item,
121
+ variant_attributes: item.variant_attributes && typeof item.variant_attributes === "string" ? JSON.parse(item.variant_attributes) : item.variant_attributes
122
+ }));
123
+ }
124
+ async function getGuestCart(config, guestSessionId) {
125
+ if (!guestSessionId) return [];
126
+ try {
127
+ const response = await fetch(`${config.backendUrls.store}/cart/`, {
128
+ headers: {
129
+ "X-Storefront-Key": config.storefrontApiKey,
130
+ "X-Business-ID": config.businessId,
131
+ "X-Guest-Session": guestSessionId
132
+ }
133
+ });
134
+ if (!response.ok) return [];
135
+ const data = await response.json();
136
+ return parseItems(data.items || []);
137
+ } catch {
138
+ return [];
139
+ }
140
+ }
141
+ async function addToGuestCart(config, guestSessionId, item) {
142
+ if (!guestSessionId) return [];
143
+ const payload = {
144
+ product_id: item.product_id,
145
+ product_slug: item.product_slug,
146
+ product_name: item.product_name,
147
+ image: item.image,
148
+ variant_id: item.variant_id,
149
+ variant_attributes: typeof item.variant_attributes === "string" ? item.variant_attributes : JSON.stringify(item.variant_attributes),
150
+ unit_price: item.unit_price,
151
+ quantity: item.quantity,
152
+ custom_measurements: item.custom_measurements,
153
+ is_bespoke: item.is_bespoke
154
+ };
155
+ const response = await fetch(`${config.backendUrls.store}/cart/`, {
156
+ method: "POST",
157
+ headers: {
158
+ "Content-Type": "application/json",
159
+ "X-Storefront-Key": config.storefrontApiKey,
160
+ "X-Business-ID": config.businessId,
161
+ "X-Guest-Session": guestSessionId
162
+ },
163
+ body: JSON.stringify(payload)
164
+ });
165
+ if (!response.ok) return [];
166
+ const data = await response.json();
167
+ return parseItems(data.items || []);
168
+ }
169
+ async function updateGuestCartItemQuantity(config, guestSessionId, itemId, quantity) {
170
+ if (!guestSessionId) return [];
171
+ const response = await fetch(`${config.backendUrls.store}/cart/${itemId}`, {
172
+ method: "PATCH",
173
+ headers: {
174
+ "Content-Type": "application/json",
175
+ "X-Storefront-Key": config.storefrontApiKey,
176
+ "X-Business-ID": config.businessId,
177
+ "X-Guest-Session": guestSessionId
178
+ },
179
+ body: JSON.stringify({ quantity })
180
+ });
181
+ if (!response.ok) return [];
182
+ const data = await response.json();
183
+ return parseItems(data.items || []);
184
+ }
185
+ async function removeFromGuestCart(config, guestSessionId, itemId) {
186
+ if (!guestSessionId) return [];
187
+ await fetch(`${config.backendUrls.store}/cart/${itemId}`, {
188
+ method: "DELETE",
189
+ headers: {
190
+ "X-Storefront-Key": config.storefrontApiKey,
191
+ "X-Business-ID": config.businessId,
192
+ "X-Guest-Session": guestSessionId
193
+ }
194
+ });
195
+ return getGuestCart(config, guestSessionId);
196
+ }
197
+ async function clearGuestCart(config, guestSessionId) {
198
+ if (!guestSessionId) return;
199
+ await fetch(`${config.backendUrls.store}/cart/clear`, {
200
+ method: "DELETE",
201
+ headers: {
202
+ "X-Storefront-Key": config.storefrontApiKey,
203
+ "X-Business-ID": config.businessId,
204
+ "X-Guest-Session": guestSessionId
205
+ }
206
+ });
207
+ }
208
+ async function getCart(config, accessToken) {
209
+ if (!accessToken) {
210
+ return { id: "", items: [], subtotal: 0, total: 0, product_type: "physical" };
211
+ }
212
+ const response = await fetch(`${config.backendUrls.store}/cart/`, {
213
+ headers: {
214
+ "Authorization": `Bearer ${accessToken}`,
215
+ "X-Storefront-Key": config.storefrontApiKey,
216
+ "X-Business-ID": config.businessId
217
+ }
218
+ });
219
+ if (!response.ok) throw new Error("Failed to fetch cart");
220
+ const data = await response.json();
221
+ const parsedItems = parseItems(data.items || []);
222
+ return { ...data, items: parsedItems };
223
+ }
224
+ async function addToCart(config, accessToken, item) {
225
+ const response = await fetch(`${config.backendUrls.store}/cart/`, {
226
+ method: "POST",
227
+ headers: {
228
+ "Content-Type": "application/json",
229
+ "Authorization": `Bearer ${accessToken}`,
230
+ "X-Storefront-Key": config.storefrontApiKey,
231
+ "X-Business-ID": config.businessId
232
+ },
233
+ body: JSON.stringify(item)
234
+ });
235
+ if (!response.ok) throw new Error("Failed to add to cart");
236
+ const data = await response.json();
237
+ const parsedItems = parseItems(data.items || []);
238
+ return { ...data, items: parsedItems };
239
+ }
240
+ async function updateCartItem(config, accessToken, itemId, quantity) {
241
+ const response = await fetch(`${config.backendUrls.store}/cart/${itemId}`, {
242
+ method: "PATCH",
243
+ headers: {
244
+ "Content-Type": "application/json",
245
+ "Authorization": `Bearer ${accessToken}`,
246
+ "X-Storefront-Key": config.storefrontApiKey,
247
+ "X-Business-ID": config.businessId
248
+ },
249
+ body: JSON.stringify({ quantity })
250
+ });
251
+ if (!response.ok) throw new Error("Failed to update cart item");
252
+ const data = await response.json();
253
+ const parsedItems = parseItems(data.items || []);
254
+ return { ...data, items: parsedItems };
255
+ }
256
+ async function removeFromCart(config, accessToken, itemId) {
257
+ await fetch(`${config.backendUrls.store}/cart/${itemId}`, {
258
+ method: "DELETE",
259
+ headers: {
260
+ "Authorization": `Bearer ${accessToken}`,
261
+ "X-Storefront-Key": config.storefrontApiKey,
262
+ "X-Business-ID": config.businessId
263
+ }
264
+ });
265
+ return getCart(config, accessToken);
266
+ }
267
+ async function clearCart(config, accessToken) {
268
+ await fetch(`${config.backendUrls.store}/cart/clear`, {
269
+ method: "DELETE",
270
+ headers: {
271
+ "Authorization": `Bearer ${accessToken}`,
272
+ "X-Storefront-Key": config.storefrontApiKey,
273
+ "X-Business-ID": config.businessId
274
+ }
275
+ });
276
+ }
277
+ async function mergeGuestCart(config, accessToken, guestSessionId) {
278
+ const guestItems = guestSessionId ? await getGuestCart(config, guestSessionId) : [];
279
+ if (guestItems.length === 0) {
280
+ return getCart(config, accessToken);
281
+ }
282
+ const payloadItems = guestItems.map((item) => ({
283
+ product_id: item.product_id,
284
+ product_slug: item.product_slug,
285
+ product_name: item.product_name,
286
+ image: item.image,
287
+ variant_id: item.variant_id,
288
+ variant_attributes: typeof item.variant_attributes === "string" ? item.variant_attributes : JSON.stringify(item.variant_attributes ?? {}),
289
+ unit_price: item.unit_price,
290
+ quantity: item.quantity,
291
+ custom_measurements: typeof item.custom_measurements === "string" ? item.custom_measurements : JSON.stringify(item.custom_measurements ?? {}),
292
+ is_bespoke: item.is_bespoke
293
+ }));
294
+ const headers = {
295
+ "Content-Type": "application/json",
296
+ "Authorization": `Bearer ${accessToken}`,
297
+ "X-Storefront-Key": config.storefrontApiKey,
298
+ "X-Business-ID": config.businessId
299
+ };
300
+ if (guestSessionId) {
301
+ headers["X-Guest-Session"] = guestSessionId;
302
+ }
303
+ const response = await fetch(`${config.backendUrls.store}/cart/merge`, {
304
+ method: "POST",
305
+ headers,
306
+ body: JSON.stringify({ items: payloadItems })
307
+ });
308
+ if (!response.ok) throw new Error("Failed to merge guest cart");
309
+ const data = await response.json();
310
+ return { ...data, items: parseItems(data.items || []) };
311
+ }
312
+ async function mergeGuestCartIfPresent(config, accessToken, guestSessionId) {
313
+ try {
314
+ const guestItems = await getGuestCart(config, guestSessionId);
315
+ if (guestItems.length === 0) return;
316
+ await mergeGuestCart(config, accessToken, guestSessionId);
317
+ } catch (error) {
318
+ console.warn("[Cart] Failed to merge guest cart:", error);
319
+ }
320
+ }
321
+ function getGuestCartCount() {
322
+ return 0;
323
+ }
324
+ function getGuestCartSubtotal() {
325
+ return 0;
326
+ }
327
+ function getGuestCartProductType() {
328
+ return "physical";
329
+ }
330
+
331
+ // src/services/order.service.ts
332
+ function deriveCustomerName(raw) {
333
+ if (raw.customer_name) return raw.customer_name;
334
+ if (raw.guest_name) return raw.guest_name;
335
+ const addr = typeof raw.shipping_address === "object" && raw.shipping_address !== null ? raw.shipping_address : null;
336
+ if (addr) {
337
+ const full = `${addr.first_name ?? ""} ${addr.last_name ?? ""}`.trim();
338
+ if (full) return full;
339
+ }
340
+ const email = raw.guest_email ?? raw.customer_email ?? "";
341
+ if (email) return email.split("@")[0];
342
+ return "";
343
+ }
344
+ function normaliseStorefrontOrder(raw) {
345
+ const items = (raw.items ?? []).map((item) => ({
346
+ id: item.id,
347
+ productName: item.product_name ?? item.productName ?? "",
348
+ image: item.image ?? "",
349
+ quantity: item.quantity ?? 1,
350
+ price: item.unit_price ?? item.price ?? 0
351
+ }));
352
+ const addr = typeof raw.shipping_address === "object" && raw.shipping_address !== null ? raw.shipping_address : null;
353
+ return {
354
+ id: raw.id,
355
+ display_id: raw.display_id,
356
+ items,
357
+ total: raw.total_amount ?? raw.total ?? 0,
358
+ status: raw.status,
359
+ customerEmail: raw.guest_email ?? raw.customer_email ?? "",
360
+ customerName: deriveCustomerName(raw),
361
+ createdAt: raw.created_at ? new Date(raw.created_at).getTime() : Date.now(),
362
+ updatedAt: raw.updated_at ? new Date(raw.updated_at).getTime() : Date.now(),
363
+ deliveryMethod: raw.delivery_method,
364
+ trackingNumber: raw.tracking_number,
365
+ deliveryAddress: typeof raw.shipping_address === "string" ? raw.shipping_address : addr ? `${addr.street}, ${addr.city}, ${addr.state}, ${addr.country}` : void 0,
366
+ shippingAddress: addr ? {
367
+ first_name: addr.first_name ?? "",
368
+ last_name: addr.last_name ?? "",
369
+ phone: addr.phone ?? "",
370
+ street: addr.street ?? "",
371
+ city: addr.city ?? "",
372
+ state: addr.state ?? "",
373
+ lga: addr.lga ?? "",
374
+ country: addr.country ?? "",
375
+ postal: addr.postal ?? ""
376
+ } : void 0,
377
+ cancellationReason: raw.cancellation_reason,
378
+ hasBespoke: raw.product_type === "bespoke",
379
+ bespokeStage: raw.bespoke_stage,
380
+ bespokeBrief: raw.bespoke_brief,
381
+ deliveryStatus: raw.delivery_status,
382
+ carrierName: raw.carrier_name,
383
+ terminalShipmentId: raw.terminal_shipment_id,
384
+ guestToken: raw.guest_token,
385
+ guestEmail: raw.guest_email,
386
+ guestPhone: raw.guest_phone,
387
+ guestName: raw.guest_name
388
+ };
389
+ }
390
+ async function createOrder(config, accessToken, payload) {
391
+ const response = await fetch(`${config.backendUrls.store}/orders/storefront`, {
392
+ method: "POST",
393
+ headers: {
394
+ "Content-Type": "application/json",
395
+ "Authorization": `Bearer ${accessToken}`,
396
+ "X-Storefront-Key": config.storefrontApiKey,
397
+ "X-Business-ID": config.businessId
398
+ },
399
+ body: JSON.stringify(payload)
400
+ });
401
+ if (!response.ok) throw new Error("Failed to create order");
402
+ const data = await response.json();
403
+ return normaliseStorefrontOrder(data);
404
+ }
405
+ async function findOrder(config, params) {
406
+ const queryParams = new URLSearchParams();
407
+ if (params.email) queryParams.set("email", params.email);
408
+ if (params.order_id) queryParams.set("order_id", params.order_id);
409
+ if (params.guest_token) queryParams.set("guest_token", params.guest_token);
410
+ const response = await fetch(`${config.backendUrls.store}/orders/find/?${queryParams.toString()}`, {
411
+ headers: {
412
+ "X-Storefront-Key": config.storefrontApiKey,
413
+ "X-Business-ID": config.businessId
414
+ }
415
+ });
416
+ if (!response.ok) throw new Error("Failed to find order");
417
+ const data = await response.json();
418
+ return normaliseStorefrontOrder(data);
419
+ }
420
+ async function findOrderByToken(config, token) {
421
+ const response = await fetch(`${config.backendUrls.store}/orders/find/?guest_token=${token}`, {
422
+ headers: {
423
+ "X-Storefront-Key": config.storefrontApiKey,
424
+ "X-Business-ID": config.businessId
425
+ }
426
+ });
427
+ if (!response.ok) throw new Error("Failed to find order by token");
428
+ const data = await response.json();
429
+ return normaliseStorefrontOrder(data);
430
+ }
431
+ async function getOrders(config, accessToken, params) {
432
+ const queryParams = new URLSearchParams();
433
+ if (params?.email) queryParams.set("email", params.email);
434
+ if (params?.page) queryParams.set("page", params.page.toString());
435
+ if (params?.page_size) queryParams.set("page_size", params.page_size.toString());
436
+ const response = await fetch(`${config.backendUrls.store}/orders/?${queryParams.toString()}`, {
437
+ headers: {
438
+ "Authorization": `Bearer ${accessToken}`,
439
+ "X-Storefront-Key": config.storefrontApiKey,
440
+ "X-Business-ID": config.businessId
441
+ }
442
+ });
443
+ if (!response.ok) throw new Error("Failed to get orders");
444
+ const data = await response.json();
445
+ const items = Array.isArray(data) ? data : data.items ?? [];
446
+ return items.map(normaliseStorefrontOrder);
447
+ }
448
+ async function cancelOrder(config, accessToken, orderId, reason) {
449
+ const response = await fetch(`${config.backendUrls.store}/orders/${orderId}/cancel/`, {
450
+ method: "POST",
451
+ headers: {
452
+ "Content-Type": "application/json",
453
+ "Authorization": `Bearer ${accessToken}`,
454
+ "X-Storefront-Key": config.storefrontApiKey,
455
+ "X-Business-ID": config.businessId
456
+ },
457
+ body: JSON.stringify({ reason })
458
+ });
459
+ if (!response.ok) throw new Error("Failed to cancel order");
460
+ const data = await response.json();
461
+ return normaliseStorefrontOrder(data);
462
+ }
463
+ async function trackOrder(config, orderId, token) {
464
+ const queryParams = token ? `?token=${token}` : "";
465
+ const response = await fetch(`${config.backendUrls.store}/orders/track/${orderId}${queryParams}`, {
466
+ headers: {
467
+ "X-Storefront-Key": config.storefrontApiKey,
468
+ "X-Business-ID": config.businessId
469
+ }
470
+ });
471
+ if (!response.ok) throw new Error("Failed to track order");
472
+ const data = await response.json();
473
+ return normaliseStorefrontOrder(data);
474
+ }
475
+
476
+ // src/constants.ts
477
+ var STORAGE_KEYS = {
478
+ ACCESS_TOKEN: "kasuvia_access_token",
479
+ REFRESH_TOKEN: "kasuvia_refresh_token",
480
+ CHECKOUT_STATE: "kasuvia_checkout_state",
481
+ ORDERS_LINKED: "kasuvia_orders_linked",
482
+ STOREFRONT_STATE: "storefront_state_v3"
483
+ };
484
+
485
+ // src/services/auth.service.ts
486
+ async function loginCustomer(config, payload) {
487
+ const response = await fetch(`${config.backendUrls.auth}/auth/login/customer/`, {
488
+ method: "POST",
489
+ headers: {
490
+ "Content-Type": "application/json",
491
+ "X-Storefront-Key": config.storefrontApiKey,
492
+ "X-Business-ID": config.businessId
493
+ },
494
+ body: JSON.stringify({
495
+ ...payload,
496
+ tenant_id: config.businessId
497
+ })
498
+ });
499
+ if (!response.ok) {
500
+ throw new Error("Login failed");
501
+ }
502
+ const data = await response.json();
503
+ return data;
504
+ }
505
+ async function registerCustomer(config, payload) {
506
+ const response = await fetch(`${config.backendUrls.auth}/auth/register/customer/`, {
507
+ method: "POST",
508
+ headers: {
509
+ "Content-Type": "application/json",
510
+ "X-Storefront-Key": config.storefrontApiKey,
511
+ "X-Business-ID": config.businessId
512
+ },
513
+ body: JSON.stringify({
514
+ ...payload,
515
+ tenant_id: config.businessId
516
+ })
517
+ });
518
+ if (!response.ok) {
519
+ throw new Error("Registration failed");
520
+ }
521
+ const data = await response.json();
522
+ return data;
523
+ }
524
+ async function refreshToken(config, refresh) {
525
+ const response = await fetch(`${config.backendUrls.auth}/auth/token/refresh/`, {
526
+ method: "POST",
527
+ headers: {
528
+ "Content-Type": "application/json"
529
+ },
530
+ body: JSON.stringify({ refresh })
531
+ });
532
+ if (!response.ok) {
533
+ throw new Error("Token refresh failed");
534
+ }
535
+ const data = await response.json();
536
+ return data;
537
+ }
538
+ async function logout(config, refresh) {
539
+ const payload = refresh ? { refresh } : {};
540
+ try {
541
+ await fetch(`${config.backendUrls.auth}/auth/logout/`, {
542
+ method: "POST",
543
+ headers: {
544
+ "Content-Type": "application/json"
545
+ },
546
+ body: JSON.stringify(payload)
547
+ });
548
+ } catch {
549
+ }
550
+ }
551
+ async function verifySocialToken(config, provider, token) {
552
+ const response = await fetch(`${config.backendUrls.auth}/auth/social/verify/${provider}/`, {
553
+ method: "POST",
554
+ headers: {
555
+ "Content-Type": "application/json"
556
+ },
557
+ body: JSON.stringify({
558
+ id_token: token,
559
+ storefront_key: config.storefrontApiKey
560
+ })
561
+ });
562
+ if (!response.ok) {
563
+ throw new Error("Social token verification failed");
564
+ }
565
+ const data = await response.json();
566
+ return data;
567
+ }
568
+ function parseJwtPayload(token) {
569
+ try {
570
+ return JSON.parse(atob(token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")));
571
+ } catch {
572
+ return {};
573
+ }
574
+ }
575
+ function resolveProvider(data) {
576
+ if (data.is_google_auth_enabled) return "google";
577
+ if (data.is_facebook_auth_enabled) return "facebook";
578
+ return "email";
579
+ }
580
+ function resolveAvatar(profilePicture) {
581
+ if (!profilePicture) return null;
582
+ if (typeof profilePicture === "string") return profilePicture;
583
+ if (typeof profilePicture === "object" && profilePicture !== null && "url" in profilePicture) {
584
+ const url = profilePicture.url;
585
+ return typeof url === "string" ? url : null;
586
+ }
587
+ return null;
588
+ }
589
+ function mapAuthUserToCustomer(data, provider) {
590
+ const firstname = data.profile?.firstname?.trim() || void 0;
591
+ const lastname = data.profile?.lastname?.trim() || void 0;
592
+ const phone = data.profile?.phone?.trim() || void 0;
593
+ return {
594
+ id: String(data.id),
595
+ email: data.email,
596
+ firstname,
597
+ lastname,
598
+ phone,
599
+ full_name: buildFullName(firstname, lastname),
600
+ avatar: resolveAvatar(data.profile?.profile_picture),
601
+ provider: provider ?? resolveProvider(data)
602
+ };
603
+ }
604
+ function buildCustomerFromClaims(claims) {
605
+ const provider = claims.is_google_auth_enabled ? "google" : claims.is_facebook_auth_enabled ? "facebook" : "email";
606
+ const jwtFullName = String(claims.full_name ?? claims.name ?? "").trim() || void 0;
607
+ const { firstname: splitFirst, lastname: splitLast } = splitFullName(jwtFullName);
608
+ return {
609
+ id: String(claims.user_id ?? claims.sub ?? ""),
610
+ email: String(claims.email ?? ""),
611
+ firstname: splitFirst || void 0,
612
+ lastname: splitLast || void 0,
613
+ phone: String(claims.phone ?? "").trim() || void 0,
614
+ full_name: jwtFullName,
615
+ avatar: claims.avatar,
616
+ provider
617
+ };
618
+ }
619
+ async function getMe(config, accessToken) {
620
+ if (!config || !accessToken) {
621
+ const response2 = await fetch("/api/auth/me", { credentials: "include" });
622
+ if (!response2.ok) throw new Error("Failed to fetch profile");
623
+ const data2 = await response2.json();
624
+ return data2.user;
625
+ }
626
+ const response = await fetch(`${config.backendUrls.auth}/auth/profile/`, {
627
+ headers: {
628
+ "Authorization": `Bearer ${accessToken}`
629
+ }
630
+ });
631
+ if (!response.ok) {
632
+ throw new Error("Failed to fetch profile");
633
+ }
634
+ const data = await response.json();
635
+ return mapAuthUserToCustomer(data);
636
+ }
637
+ async function getAuthUser(config, accessToken) {
638
+ if (!config || !accessToken) {
639
+ const response2 = await fetch("/api/auth/me", { credentials: "include" });
640
+ if (!response2.ok) throw new Error("Failed to fetch auth user");
641
+ const data2 = await response2.json();
642
+ return data2.user;
643
+ }
644
+ const response = await fetch(`${config.backendUrls.auth}/auth/profile/`, {
645
+ headers: {
646
+ "Authorization": `Bearer ${accessToken}`
647
+ }
648
+ });
649
+ if (!response.ok) {
650
+ throw new Error("Failed to fetch auth user");
651
+ }
652
+ const data = await response.json();
653
+ return data;
654
+ }
655
+ async function updateProfile(configOrPayload, accessTokenOrPayload, payloadParam) {
656
+ const isArg1Config = typeof configOrPayload === "object" && configOrPayload !== null && "businessId" in configOrPayload;
657
+ if (!isArg1Config) {
658
+ const payload2 = configOrPayload;
659
+ const response2 = await fetch("/api/auth/profile", {
660
+ method: "PUT",
661
+ headers: { "Content-Type": "application/json" },
662
+ credentials: "include",
663
+ body: JSON.stringify(payload2)
664
+ });
665
+ if (!response2.ok) throw new Error("Failed to update profile");
666
+ return response2.json();
667
+ }
668
+ const config = configOrPayload;
669
+ const accessToken = accessTokenOrPayload;
670
+ const payload = payloadParam;
671
+ const response = await fetch(`${config.backendUrls.auth}/auth/profile/`, {
672
+ method: "PUT",
673
+ headers: {
674
+ "Content-Type": "application/json",
675
+ "Authorization": `Bearer ${accessToken}`
676
+ },
677
+ body: JSON.stringify(payload)
678
+ });
679
+ if (!response.ok) {
680
+ throw new Error("Failed to update profile");
681
+ }
682
+ const data = await response.json();
683
+ return mapAuthUserToCustomer(data);
684
+ }
685
+ async function silentRefresh(config, refresh) {
686
+ try {
687
+ const data = await refreshToken(config, refresh);
688
+ if (!data.access || !data.refresh) {
689
+ return null;
690
+ }
691
+ const claims = parseJwtPayload(data.access);
692
+ const user = buildCustomerFromClaims(claims);
693
+ const provider = user.provider;
694
+ return { user, provider, newAccessToken: data.access, newRefreshToken: data.refresh };
695
+ } catch {
696
+ return null;
697
+ }
698
+ }
699
+ function buildFullName(firstname, lastname) {
700
+ if (firstname && lastname) return `${firstname} ${lastname}`;
701
+ return firstname || lastname || "";
702
+ }
703
+ function splitFullName(fullName) {
704
+ if (!fullName) return { firstname: "", lastname: "" };
705
+ const parts = fullName.trim().split(/\s+/);
706
+ if (parts.length === 1) {
707
+ return { firstname: parts[0], lastname: "" };
708
+ }
709
+ return {
710
+ firstname: parts[0],
711
+ lastname: parts.slice(1).join(" ")
712
+ };
713
+ }
714
+ function storeTokens(accessToken, refreshToken2) {
715
+ if (typeof window !== "undefined") {
716
+ localStorage.setItem(STORAGE_KEYS.ACCESS_TOKEN, accessToken);
717
+ localStorage.setItem(STORAGE_KEYS.REFRESH_TOKEN, refreshToken2);
718
+ }
719
+ }
720
+ function clearTokens() {
721
+ if (typeof window !== "undefined") {
722
+ localStorage.removeItem(STORAGE_KEYS.ACCESS_TOKEN);
723
+ localStorage.removeItem(STORAGE_KEYS.REFRESH_TOKEN);
724
+ }
725
+ }
726
+ function getStoredTokens() {
727
+ if (typeof window === "undefined") {
728
+ return { accessToken: null, refreshToken: null };
729
+ }
730
+ return {
731
+ accessToken: localStorage.getItem(STORAGE_KEYS.ACCESS_TOKEN),
732
+ refreshToken: localStorage.getItem(STORAGE_KEYS.REFRESH_TOKEN)
733
+ };
734
+ }
735
+
736
+ // src/services/product.service.ts
737
+ var import_graphql_request = require("graphql-request");
738
+ function createGraphQLClient(config) {
739
+ const headers = {
740
+ "Content-Type": "application/json",
741
+ "Accept": "application/json",
742
+ "X-Storefront-Key": config.storefrontApiKey,
743
+ "X-Business-ID": config.businessId
744
+ };
745
+ return new import_graphql_request.GraphQLClient(`${config.backendUrls.store}/graphql`, { headers });
746
+ }
747
+ var GET_STOREFRONT_PRODUCTS = `
748
+ query GetStorefrontProducts($page: Int!, $pageSize: Int!, $collectionSlug: String, $search: String) {
749
+ storefront_products(page: $page, pageSize: $pageSize, collectionSlug: $collectionSlug, search: $search) {
750
+ items {
751
+ id
752
+ business_id
753
+ name
754
+ slug
755
+ description
756
+ brand
757
+ product_type
758
+ requires_shipping
759
+ is_consumable
760
+ is_bespoke
761
+ base_price
762
+ currency
763
+ images
764
+ tags
765
+ custom_fields { label unit required }
766
+ is_published
767
+ is_featured
768
+ is_popular
769
+ is_new
770
+ is_temporary
771
+ digital_file_key
772
+ download_limit
773
+ download_expires_at
774
+ weight_kg
775
+ length_cm
776
+ width_cm
777
+ height_cm
778
+ created_at
779
+ updated_at
780
+ variants {
781
+ id
782
+ product_id
783
+ sku
784
+ attributes
785
+ price
786
+ images
787
+ weight_kg
788
+ is_active
789
+ inventory {
790
+ id
791
+ product_id
792
+ variant_id
793
+ quantity
794
+ reserved
795
+ reorder_point
796
+ reorder_quantity
797
+ track_quantity
798
+ allow_backorder
799
+ available
800
+ is_in_stock
801
+ is_low_stock
802
+ updated_at
803
+ }
804
+ created_at
805
+ updated_at
806
+ }
807
+ collections {
808
+ id
809
+ business_id
810
+ name
811
+ slug
812
+ description
813
+ image
814
+ collection_type
815
+ rules
816
+ status
817
+ sort_order
818
+ created_at
819
+ updated_at
820
+ }
821
+ }
822
+ total
823
+ page
824
+ page_size
825
+ total_pages
826
+ }
827
+ }
828
+ `;
829
+ var GET_STOREFRONT_PRODUCT_BY_SLUG = `
830
+ query GetStorefrontProductBySlug($slug: String!) {
831
+ storefront_product_by_slug(slug: $slug) {
832
+ id
833
+ business_id
834
+ name
835
+ slug
836
+ description
837
+ brand
838
+ product_type
839
+ requires_shipping
840
+ is_consumable
841
+ is_bespoke
842
+ base_price
843
+ currency
844
+ images
845
+ tags
846
+ custom_fields { label unit required }
847
+ is_published
848
+ is_featured
849
+ is_popular
850
+ is_new
851
+ is_temporary
852
+ digital_file_key
853
+ download_limit
854
+ download_expires_at
855
+ weight_kg
856
+ length_cm
857
+ width_cm
858
+ height_cm
859
+ created_at
860
+ updated_at
861
+ variants {
862
+ id
863
+ product_id
864
+ sku
865
+ attributes
866
+ price
867
+ images
868
+ weight_kg
869
+ is_active
870
+ inventory {
871
+ id
872
+ product_id
873
+ variant_id
874
+ quantity
875
+ reserved
876
+ reorder_point
877
+ reorder_quantity
878
+ track_quantity
879
+ allow_backorder
880
+ available
881
+ is_in_stock
882
+ is_low_stock
883
+ updated_at
884
+ }
885
+ created_at
886
+ updated_at
887
+ }
888
+ collections {
889
+ id
890
+ business_id
891
+ name
892
+ slug
893
+ description
894
+ image
895
+ collection_type
896
+ rules
897
+ status
898
+ sort_order
899
+ created_at
900
+ updated_at
901
+ }
902
+ }
903
+ }
904
+ `;
905
+ var GET_STOREFRONT_LATEST = `
906
+ query GetStorefrontLatest($page: Int!, $pageSize: Int!) {
907
+ storefront_latest(page: $page, pageSize: $pageSize) {
908
+ items {
909
+ id
910
+ business_id
911
+ name
912
+ slug
913
+ description
914
+ brand
915
+ product_type
916
+ requires_shipping
917
+ is_consumable
918
+ is_bespoke
919
+ base_price
920
+ currency
921
+ images
922
+ tags
923
+ custom_fields { label unit required }
924
+ is_published
925
+ is_featured
926
+ is_popular
927
+ is_new
928
+ is_temporary
929
+ digital_file_key
930
+ download_limit
931
+ download_expires_at
932
+ weight_kg
933
+ length_cm
934
+ width_cm
935
+ height_cm
936
+ created_at
937
+ updated_at
938
+ variants {
939
+ id
940
+ product_id
941
+ sku
942
+ attributes
943
+ price
944
+ images
945
+ weight_kg
946
+ is_active
947
+ inventory {
948
+ id
949
+ product_id
950
+ variant_id
951
+ quantity
952
+ reserved
953
+ reorder_point
954
+ reorder_quantity
955
+ track_quantity
956
+ allow_backorder
957
+ available
958
+ is_in_stock
959
+ is_low_stock
960
+ updated_at
961
+ }
962
+ created_at
963
+ updated_at
964
+ }
965
+ collections {
966
+ id
967
+ business_id
968
+ name
969
+ slug
970
+ description
971
+ image
972
+ collection_type
973
+ rules
974
+ status
975
+ sort_order
976
+ created_at
977
+ updated_at
978
+ }
979
+ }
980
+ total
981
+ page
982
+ page_size
983
+ total_pages
984
+ }
985
+ }
986
+ `;
987
+ var GET_STOREFRONT_POPULAR = `
988
+ query GetStorefrontPopular($page: Int!, $pageSize: Int!) {
989
+ storefront_popular(page: $page, pageSize: $pageSize) {
990
+ items {
991
+ id
992
+ business_id
993
+ name
994
+ slug
995
+ description
996
+ brand
997
+ product_type
998
+ requires_shipping
999
+ is_consumable
1000
+ is_bespoke
1001
+ base_price
1002
+ currency
1003
+ images
1004
+ tags
1005
+ custom_fields { label unit required }
1006
+ is_published
1007
+ is_featured
1008
+ is_popular
1009
+ is_new
1010
+ is_temporary
1011
+ digital_file_key
1012
+ download_limit
1013
+ download_expires_at
1014
+ weight_kg
1015
+ length_cm
1016
+ width_cm
1017
+ height_cm
1018
+ created_at
1019
+ updated_at
1020
+ variants {
1021
+ id
1022
+ product_id
1023
+ sku
1024
+ attributes
1025
+ price
1026
+ images
1027
+ weight_kg
1028
+ is_active
1029
+ inventory {
1030
+ id
1031
+ product_id
1032
+ variant_id
1033
+ quantity
1034
+ reserved
1035
+ reorder_point
1036
+ reorder_quantity
1037
+ track_quantity
1038
+ allow_backorder
1039
+ available
1040
+ is_in_stock
1041
+ is_low_stock
1042
+ updated_at
1043
+ }
1044
+ created_at
1045
+ updated_at
1046
+ }
1047
+ collections {
1048
+ id
1049
+ business_id
1050
+ name
1051
+ slug
1052
+ description
1053
+ image
1054
+ collection_type
1055
+ rules
1056
+ status
1057
+ sort_order
1058
+ created_at
1059
+ updated_at
1060
+ }
1061
+ }
1062
+ total
1063
+ page
1064
+ page_size
1065
+ total_pages
1066
+ }
1067
+ }
1068
+ `;
1069
+ var GET_STOREFRONT_FEATURED = `
1070
+ query GetStorefrontFeatured($page: Int!, $pageSize: Int!) {
1071
+ storefront_featured(page: $page, pageSize: $pageSize) {
1072
+ items {
1073
+ id
1074
+ business_id
1075
+ name
1076
+ slug
1077
+ description
1078
+ brand
1079
+ product_type
1080
+ requires_shipping
1081
+ is_consumable
1082
+ is_bespoke
1083
+ base_price
1084
+ currency
1085
+ images
1086
+ tags
1087
+ custom_fields { label unit required }
1088
+ is_published
1089
+ is_featured
1090
+ is_popular
1091
+ is_new
1092
+ is_temporary
1093
+ digital_file_key
1094
+ download_limit
1095
+ download_expires_at
1096
+ weight_kg
1097
+ length_cm
1098
+ width_cm
1099
+ height_cm
1100
+ created_at
1101
+ updated_at
1102
+ variants {
1103
+ id
1104
+ product_id
1105
+ sku
1106
+ attributes
1107
+ price
1108
+ images
1109
+ weight_kg
1110
+ is_active
1111
+ inventory {
1112
+ id
1113
+ product_id
1114
+ variant_id
1115
+ quantity
1116
+ reserved
1117
+ reorder_point
1118
+ reorder_quantity
1119
+ track_quantity
1120
+ allow_backorder
1121
+ available
1122
+ is_in_stock
1123
+ is_low_stock
1124
+ updated_at
1125
+ }
1126
+ created_at
1127
+ updated_at
1128
+ }
1129
+ collections {
1130
+ id
1131
+ business_id
1132
+ name
1133
+ slug
1134
+ description
1135
+ image
1136
+ collection_type
1137
+ rules
1138
+ status
1139
+ sort_order
1140
+ created_at
1141
+ updated_at
1142
+ }
1143
+ }
1144
+ total
1145
+ page
1146
+ page_size
1147
+ total_pages
1148
+ }
1149
+ }
1150
+ `;
1151
+ var GET_STOREFRONT_NEW = `
1152
+ query GetStorefrontNew($page: Int!, $pageSize: Int!) {
1153
+ storefront_new(page: $page, pageSize: $pageSize) {
1154
+ items {
1155
+ id
1156
+ business_id
1157
+ name
1158
+ slug
1159
+ description
1160
+ brand
1161
+ product_type
1162
+ requires_shipping
1163
+ is_consumable
1164
+ is_bespoke
1165
+ base_price
1166
+ currency
1167
+ sale_price
1168
+ sale_start
1169
+ sale_end
1170
+ images
1171
+ tags
1172
+ custom_fields { label unit required }
1173
+ is_published
1174
+ is_featured
1175
+ is_popular
1176
+ is_new
1177
+ is_temporary
1178
+ digital_file_key
1179
+ download_limit
1180
+ download_expires_at
1181
+ weight_kg
1182
+ length_cm
1183
+ width_cm
1184
+ height_cm
1185
+ created_at
1186
+ updated_at
1187
+ variants {
1188
+ id
1189
+ product_id
1190
+ sku
1191
+ attributes
1192
+ price
1193
+ images
1194
+ weight_kg
1195
+ is_active
1196
+ inventory {
1197
+ id
1198
+ product_id
1199
+ variant_id
1200
+ quantity
1201
+ reserved
1202
+ reorder_point
1203
+ reorder_quantity
1204
+ track_quantity
1205
+ allow_backorder
1206
+ available
1207
+ is_in_stock
1208
+ is_low_stock
1209
+ updated_at
1210
+ }
1211
+ created_at
1212
+ updated_at
1213
+ }
1214
+ collections {
1215
+ id
1216
+ business_id
1217
+ name
1218
+ slug
1219
+ description
1220
+ image
1221
+ collection_type
1222
+ rules
1223
+ status
1224
+ sort_order
1225
+ created_at
1226
+ updated_at
1227
+ }
1228
+ }
1229
+ total
1230
+ page
1231
+ page_size
1232
+ total_pages
1233
+ }
1234
+ }
1235
+ `;
1236
+ var GET_STOREFRONT_ON_SALE = `
1237
+ query GetStorefrontOnSale($page: Int!, $pageSize: Int!) {
1238
+ storefront_on_sale(page: $page, pageSize: $pageSize) {
1239
+ items {
1240
+ id
1241
+ business_id
1242
+ name
1243
+ slug
1244
+ description
1245
+ brand
1246
+ product_type
1247
+ requires_shipping
1248
+ is_consumable
1249
+ is_bespoke
1250
+ base_price
1251
+ currency
1252
+ sale_price
1253
+ sale_start
1254
+ sale_end
1255
+ images
1256
+ tags
1257
+ custom_fields { label unit required }
1258
+ is_published
1259
+ is_featured
1260
+ is_popular
1261
+ is_new
1262
+ is_temporary
1263
+ digital_file_key
1264
+ download_limit
1265
+ download_expires_at
1266
+ weight_kg
1267
+ length_cm
1268
+ width_cm
1269
+ height_cm
1270
+ created_at
1271
+ updated_at
1272
+ variants {
1273
+ id
1274
+ product_id
1275
+ sku
1276
+ attributes
1277
+ price
1278
+ images
1279
+ weight_kg
1280
+ is_active
1281
+ inventory {
1282
+ id
1283
+ product_id
1284
+ variant_id
1285
+ quantity
1286
+ reserved
1287
+ reorder_point
1288
+ reorder_quantity
1289
+ track_quantity
1290
+ allow_backorder
1291
+ available
1292
+ is_in_stock
1293
+ is_low_stock
1294
+ updated_at
1295
+ }
1296
+ created_at
1297
+ updated_at
1298
+ }
1299
+ collections {
1300
+ id
1301
+ business_id
1302
+ name
1303
+ slug
1304
+ description
1305
+ image
1306
+ collection_type
1307
+ rules
1308
+ status
1309
+ sort_order
1310
+ created_at
1311
+ updated_at
1312
+ }
1313
+ }
1314
+ total
1315
+ page
1316
+ page_size
1317
+ total_pages
1318
+ }
1319
+ }
1320
+ `;
1321
+ var GET_STOREFRONT_LOW_STOCK = `
1322
+ query GetStorefrontLowStock($page: Int!, $pageSize: Int!) {
1323
+ storefront_low_stock(page: $page, pageSize: $pageSize) {
1324
+ items {
1325
+ id
1326
+ business_id
1327
+ name
1328
+ slug
1329
+ description
1330
+ brand
1331
+ product_type
1332
+ requires_shipping
1333
+ is_consumable
1334
+ is_bespoke
1335
+ base_price
1336
+ currency
1337
+ sale_price
1338
+ sale_start
1339
+ sale_end
1340
+ images
1341
+ tags
1342
+ custom_fields { label unit required }
1343
+ is_published
1344
+ is_featured
1345
+ is_popular
1346
+ is_new
1347
+ is_temporary
1348
+ digital_file_key
1349
+ download_limit
1350
+ download_expires_at
1351
+ weight_kg
1352
+ length_cm
1353
+ width_cm
1354
+ height_cm
1355
+ created_at
1356
+ updated_at
1357
+ variants {
1358
+ id
1359
+ product_id
1360
+ sku
1361
+ attributes
1362
+ price
1363
+ images
1364
+ weight_kg
1365
+ is_active
1366
+ inventory {
1367
+ id
1368
+ product_id
1369
+ variant_id
1370
+ quantity
1371
+ reserved
1372
+ reorder_point
1373
+ reorder_quantity
1374
+ track_quantity
1375
+ allow_backorder
1376
+ available
1377
+ is_in_stock
1378
+ is_low_stock
1379
+ updated_at
1380
+ }
1381
+ created_at
1382
+ updated_at
1383
+ }
1384
+ collections {
1385
+ id
1386
+ business_id
1387
+ name
1388
+ slug
1389
+ description
1390
+ image
1391
+ collection_type
1392
+ rules
1393
+ status
1394
+ sort_order
1395
+ created_at
1396
+ updated_at
1397
+ }
1398
+ }
1399
+ total
1400
+ page
1401
+ page_size
1402
+ total_pages
1403
+ }
1404
+ }
1405
+ `;
1406
+ var GET_STOREFRONT_RECOMMENDED = `
1407
+ query GetStorefrontRecommended($page: Int!, $pageSize: Int!, $excludeProductId: String) {
1408
+ storefront_recommended(page: $page, pageSize: $pageSize, excludeProductId: $excludeProductId) {
1409
+ items {
1410
+ id
1411
+ business_id
1412
+ name
1413
+ slug
1414
+ description
1415
+ brand
1416
+ product_type
1417
+ requires_shipping
1418
+ is_consumable
1419
+ is_bespoke
1420
+ base_price
1421
+ currency
1422
+ images
1423
+ tags
1424
+ custom_fields { label unit required }
1425
+ is_published
1426
+ is_featured
1427
+ is_popular
1428
+ is_new
1429
+ is_temporary
1430
+ digital_file_key
1431
+ download_limit
1432
+ download_expires_at
1433
+ weight_kg
1434
+ length_cm
1435
+ width_cm
1436
+ height_cm
1437
+ created_at
1438
+ updated_at
1439
+ variants {
1440
+ id
1441
+ product_id
1442
+ sku
1443
+ attributes
1444
+ price
1445
+ images
1446
+ weight_kg
1447
+ is_active
1448
+ inventory {
1449
+ id
1450
+ product_id
1451
+ variant_id
1452
+ quantity
1453
+ reserved
1454
+ reorder_point
1455
+ reorder_quantity
1456
+ track_quantity
1457
+ allow_backorder
1458
+ available
1459
+ is_in_stock
1460
+ is_low_stock
1461
+ updated_at
1462
+ }
1463
+ created_at
1464
+ updated_at
1465
+ }
1466
+ collections {
1467
+ id
1468
+ business_id
1469
+ name
1470
+ slug
1471
+ description
1472
+ image
1473
+ collection_type
1474
+ rules
1475
+ status
1476
+ sort_order
1477
+ created_at
1478
+ updated_at
1479
+ }
1480
+ }
1481
+ total
1482
+ page
1483
+ page_size
1484
+ total_pages
1485
+ }
1486
+ }
1487
+ `;
1488
+ async function getStorefrontProducts(config, params) {
1489
+ const client = createGraphQLClient(config);
1490
+ const variables = {
1491
+ page: params?.page || 1,
1492
+ pageSize: params?.pageSize || 20,
1493
+ collectionSlug: params?.collectionSlug,
1494
+ search: params?.search
1495
+ };
1496
+ const data = await client.request(GET_STOREFRONT_PRODUCTS, variables);
1497
+ return data.storefront_products;
1498
+ }
1499
+ async function getStorefrontProductBySlug(config, slug) {
1500
+ const client = createGraphQLClient(config);
1501
+ const data = await client.request(GET_STOREFRONT_PRODUCT_BY_SLUG, { slug });
1502
+ return data.storefront_product_by_slug;
1503
+ }
1504
+ async function getLatestProducts(config, params) {
1505
+ const client = createGraphQLClient(config);
1506
+ const variables = {
1507
+ page: params?.page || 1,
1508
+ pageSize: params?.pageSize || 4
1509
+ };
1510
+ const data = await client.request(GET_STOREFRONT_LATEST, variables);
1511
+ return data.storefront_latest;
1512
+ }
1513
+ async function getPopularProducts(config, params) {
1514
+ const client = createGraphQLClient(config);
1515
+ const variables = {
1516
+ page: params?.page || 1,
1517
+ pageSize: params?.pageSize || 4
1518
+ };
1519
+ const data = await client.request(GET_STOREFRONT_POPULAR, variables);
1520
+ return data.storefront_popular;
1521
+ }
1522
+ async function getFeaturedProducts(config, params) {
1523
+ const client = createGraphQLClient(config);
1524
+ const variables = {
1525
+ page: params?.page || 1,
1526
+ pageSize: params?.pageSize || 4
1527
+ };
1528
+ const data = await client.request(GET_STOREFRONT_FEATURED, variables);
1529
+ return data.storefront_featured;
1530
+ }
1531
+ async function getNewProducts(config, params) {
1532
+ const client = createGraphQLClient(config);
1533
+ const variables = {
1534
+ page: params?.page || 1,
1535
+ pageSize: params?.pageSize || 4
1536
+ };
1537
+ const data = await client.request(GET_STOREFRONT_NEW, variables);
1538
+ return data.storefront_new;
1539
+ }
1540
+ async function getOnSaleProducts(config, params) {
1541
+ const client = createGraphQLClient(config);
1542
+ const variables = {
1543
+ page: params?.page || 1,
1544
+ pageSize: params?.pageSize || 4
1545
+ };
1546
+ const data = await client.request(GET_STOREFRONT_ON_SALE, variables);
1547
+ return data.storefront_on_sale;
1548
+ }
1549
+ async function getLowStockProducts(config, params) {
1550
+ const client = createGraphQLClient(config);
1551
+ const variables = {
1552
+ page: params?.page || 1,
1553
+ pageSize: params?.pageSize || 4
1554
+ };
1555
+ const data = await client.request(GET_STOREFRONT_LOW_STOCK, variables);
1556
+ return data.storefront_low_stock;
1557
+ }
1558
+ async function getRecommendedProducts(config, params) {
1559
+ const client = createGraphQLClient(config);
1560
+ const variables = {
1561
+ page: params?.page || 1,
1562
+ pageSize: params?.pageSize || 4,
1563
+ excludeProductId: params?.excludeProductId
1564
+ };
1565
+ const data = await client.request(GET_STOREFRONT_RECOMMENDED, variables);
1566
+ return data.storefront_recommended;
1567
+ }
1568
+
1569
+ // src/services/collection.service.ts
1570
+ var import_graphql_request2 = require("graphql-request");
1571
+ var GET_STOREFRONT_COLLECTIONS = `
1572
+ query GetStorefrontCollections($page: Int!, $pageSize: Int!) {
1573
+ storefront_collections(page: $page, pageSize: $pageSize) {
1574
+ items {
1575
+ id
1576
+ business_id
1577
+ name
1578
+ slug
1579
+ description
1580
+ image
1581
+ collection_type
1582
+ rules
1583
+ status
1584
+ sort_order
1585
+ created_at
1586
+ updated_at
1587
+ }
1588
+ total
1589
+ page
1590
+ page_size
1591
+ total_pages
1592
+ }
1593
+ }
1594
+ `;
1595
+ var GET_STOREFRONT_COLLECTION_BY_SLUG = `
1596
+ query GetStorefrontCollectionBySlug($slug: String!) {
1597
+ storefront_collection_by_slug(slug: $slug) {
1598
+ id
1599
+ business_id
1600
+ name
1601
+ slug
1602
+ description
1603
+ image
1604
+ collection_type
1605
+ rules
1606
+ status
1607
+ sort_order
1608
+ created_at
1609
+ updated_at
1610
+ }
1611
+ }
1612
+ `;
1613
+ function createGraphQLClient2(config) {
1614
+ const headers = {
1615
+ "Content-Type": "application/json",
1616
+ "Accept": "application/json",
1617
+ "X-Storefront-Key": config.storefrontApiKey,
1618
+ "X-Business-ID": config.businessId
1619
+ };
1620
+ return new import_graphql_request2.GraphQLClient(`${config.backendUrls.store}/graphql`, { headers });
1621
+ }
1622
+ async function getStorefrontCollections(config, params) {
1623
+ const client = createGraphQLClient2(config);
1624
+ const variables = {
1625
+ page: params?.page || 1,
1626
+ pageSize: params?.pageSize || 20
1627
+ };
1628
+ const data = await client.request(GET_STOREFRONT_COLLECTIONS, variables);
1629
+ return data.storefront_collections;
1630
+ }
1631
+ async function getStorefrontCollectionBySlug(config, slug) {
1632
+ const client = createGraphQLClient2(config);
1633
+ const data = await client.request(GET_STOREFRONT_COLLECTION_BY_SLUG, { slug });
1634
+ return data.storefront_collection_by_slug;
1635
+ }
1636
+
1637
+ // src/services/wishlist.service.ts
1638
+ var import_graphql_request3 = require("graphql-request");
1639
+ var GET_STOREFRONT_WISHLIST = `
1640
+ query GetStorefrontWishlist($page: Int!, $pageSize: Int!) {
1641
+ storefront_wishlist(page: $page, pageSize: $pageSize) {
1642
+ items {
1643
+ id
1644
+ product_id
1645
+ notes
1646
+ created_at
1647
+ product_name
1648
+ product_slug
1649
+ product_price
1650
+ currency
1651
+ product_image
1652
+ }
1653
+ total
1654
+ page
1655
+ page_size
1656
+ total_pages
1657
+ }
1658
+ }
1659
+ `;
1660
+ var CHECK_IN_STOREFRONT_WISHLIST = `
1661
+ query CheckInStorefrontWishlist($productId: String!) {
1662
+ check_in_storefront_wishlist(productId: $productId) {
1663
+ in_wishlist
1664
+ }
1665
+ }
1666
+ `;
1667
+ function createGraphQLClient3(config, accessToken) {
1668
+ const headers = {
1669
+ "Content-Type": "application/json",
1670
+ "Accept": "application/json",
1671
+ "X-Storefront-Key": config.storefrontApiKey,
1672
+ "X-Business-ID": config.businessId
1673
+ };
1674
+ if (accessToken) {
1675
+ headers["Authorization"] = `Bearer ${accessToken}`;
1676
+ }
1677
+ return new import_graphql_request3.GraphQLClient(`${config.backendUrls.store}/graphql`, { headers });
1678
+ }
1679
+ async function getWishlist(config, accessToken, params) {
1680
+ const client = createGraphQLClient3(config, accessToken);
1681
+ const variables = {
1682
+ page: params?.page || 1,
1683
+ pageSize: params?.pageSize || 20
1684
+ };
1685
+ const data = await client.request(GET_STOREFRONT_WISHLIST, variables);
1686
+ return data.storefront_wishlist;
1687
+ }
1688
+ async function checkInWishlist(config, accessToken, productId) {
1689
+ const client = createGraphQLClient3(config, accessToken);
1690
+ const data = await client.request(CHECK_IN_STOREFRONT_WISHLIST, { productId });
1691
+ return data.check_in_storefront_wishlist;
1692
+ }
1693
+ async function addToWishlist(config, accessToken, productId, notes) {
1694
+ const response = await fetch(`${config.backendUrls.store}/wishlist/`, {
1695
+ method: "POST",
1696
+ headers: {
1697
+ "Content-Type": "application/json",
1698
+ "Authorization": `Bearer ${accessToken}`,
1699
+ "X-Storefront-Key": config.storefrontApiKey,
1700
+ "X-Business-ID": config.businessId
1701
+ },
1702
+ body: JSON.stringify({
1703
+ product_id: productId,
1704
+ notes: notes || void 0
1705
+ })
1706
+ });
1707
+ if (!response.ok) throw new Error("Failed to add to wishlist");
1708
+ return response.json();
1709
+ }
1710
+ async function removeFromWishlist(config, accessToken, itemId) {
1711
+ const response = await fetch(`${config.backendUrls.store}/wishlist/${itemId}`, {
1712
+ method: "DELETE",
1713
+ headers: {
1714
+ "Authorization": `Bearer ${accessToken}`,
1715
+ "X-Storefront-Key": config.storefrontApiKey,
1716
+ "X-Business-ID": config.businessId
1717
+ }
1718
+ });
1719
+ if (!response.ok) throw new Error("Failed to remove from wishlist");
1720
+ }
1721
+ async function removeProductFromWishlist(config, accessToken, productId) {
1722
+ const response = await fetch(`${config.backendUrls.store}/wishlist/product/${productId}`, {
1723
+ method: "DELETE",
1724
+ headers: {
1725
+ "Authorization": `Bearer ${accessToken}`,
1726
+ "X-Storefront-Key": config.storefrontApiKey,
1727
+ "X-Business-ID": config.businessId
1728
+ }
1729
+ });
1730
+ if (!response.ok) throw new Error("Failed to remove product from wishlist");
1731
+ }
1732
+
1733
+ // src/services/payment.service.ts
1734
+ async function createDedicatedAccount(config, accessToken, request) {
1735
+ const isValidUUID = (str) => {
1736
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1737
+ return uuidRegex.test(str);
1738
+ };
1739
+ const response = await fetch(`${config.backendUrls.payment}/payments/dedicated-account`, {
1740
+ method: "POST",
1741
+ headers: {
1742
+ "Content-Type": "application/json",
1743
+ "Authorization": `Bearer ${accessToken}`,
1744
+ "X-Storefront-Key": config.storefrontApiKey,
1745
+ "X-Business-ID": config.businessId
1746
+ },
1747
+ body: JSON.stringify({
1748
+ order_id: request.order_id && isValidUUID(request.order_id) ? request.order_id : void 0,
1749
+ amount: request.amount,
1750
+ customer_email: request.customer_email,
1751
+ customer_name: request.customer_name,
1752
+ currency: request.currency,
1753
+ idempotency_key: request.idempotency_key
1754
+ })
1755
+ });
1756
+ if (!response.ok) throw new Error("Failed to create dedicated account");
1757
+ const data = await response.json();
1758
+ return data;
1759
+ }
1760
+ async function initiatePayment(config, accessToken, request) {
1761
+ const isValidUUID = (str) => {
1762
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1763
+ return uuidRegex.test(str);
1764
+ };
1765
+ const validOrderId = request.order_id && isValidUUID(request.order_id) ? request.order_id : void 0;
1766
+ const response = await fetch(`${config.backendUrls.payment}/payments/storefront/initiate`, {
1767
+ method: "POST",
1768
+ headers: {
1769
+ "Content-Type": "application/json",
1770
+ "Authorization": `Bearer ${accessToken}`,
1771
+ "X-Storefront-Key": config.storefrontApiKey,
1772
+ "X-Business-ID": config.businessId
1773
+ },
1774
+ body: JSON.stringify({
1775
+ amount: request.amount,
1776
+ currency: request.currency,
1777
+ order_id: validOrderId,
1778
+ quote_id: request.quote_id,
1779
+ metadata_json: {
1780
+ customer_email: request.customer_email,
1781
+ customer_name: request.customer_name ?? "",
1782
+ order_id: validOrderId,
1783
+ ...request.metadata ?? {}
1784
+ },
1785
+ idempotency_key: request.idempotency_key
1786
+ })
1787
+ });
1788
+ if (!response.ok) throw new Error("Failed to initiate payment");
1789
+ const data = await response.json();
1790
+ return {
1791
+ id: data.id,
1792
+ gateway_ref: data.gateway_ref,
1793
+ gateway: data.gateway,
1794
+ status: data.status,
1795
+ checkout_url: data.metadata_json?.checkout_url ?? ""
1796
+ };
1797
+ }
1798
+ async function requestQuote(config, amount) {
1799
+ const response = await fetch(`${config.backendUrls.payment}/payments/quote`, {
1800
+ method: "POST",
1801
+ headers: {
1802
+ "Content-Type": "application/json",
1803
+ "X-Storefront-Key": config.storefrontApiKey,
1804
+ "X-Business-ID": config.businessId
1805
+ },
1806
+ body: JSON.stringify({ amount })
1807
+ });
1808
+ if (!response.ok) throw new Error("Failed to request quote");
1809
+ const data = await response.json();
1810
+ return data;
1811
+ }
1812
+ async function verifyTransaction(configOrReference, reference) {
1813
+ if (typeof configOrReference === "string") {
1814
+ const ref2 = configOrReference;
1815
+ const response2 = await fetch(`/api/payments/verify/${ref2}`, {
1816
+ method: "POST",
1817
+ headers: { "Content-Type": "application/json" }
1818
+ });
1819
+ if (!response2.ok) throw new Error("Failed to verify transaction");
1820
+ return response2.json();
1821
+ }
1822
+ const config = configOrReference;
1823
+ const ref = reference || "";
1824
+ const response = await fetch(`${config.backendUrls.payment}/payments/verify/${ref}`, {
1825
+ method: "POST",
1826
+ headers: {
1827
+ "Content-Type": "application/json",
1828
+ "X-Storefront-Key": config.storefrontApiKey,
1829
+ "X-Business-ID": config.businessId
1830
+ }
1831
+ });
1832
+ if (!response.ok) throw new Error("Failed to verify transaction");
1833
+ const data = await response.json();
1834
+ return data;
1835
+ }
1836
+ async function getTransactionStatus(config, transactionId) {
1837
+ const response = await fetch(`${config.backendUrls.payment}/payments/transactions/${transactionId}`, {
1838
+ headers: {
1839
+ "X-Storefront-Key": config.storefrontApiKey,
1840
+ "X-Business-ID": config.businessId
1841
+ }
1842
+ });
1843
+ if (!response.ok) throw new Error("Failed to get transaction status");
1844
+ const data = await response.json();
1845
+ return data;
1846
+ }
1847
+ var paymentService = {
1848
+ createDedicatedAccount,
1849
+ initiatePayment,
1850
+ requestQuote,
1851
+ verifyTransaction,
1852
+ getTransactionStatus
1853
+ };
1854
+
1855
+ // src/services/consultation.service.ts
1856
+ async function createConsultation(config, accessToken, payload) {
1857
+ const response = await fetch(`${config.backendUrls.store}/social/consultations/`, {
1858
+ method: "POST",
1859
+ headers: {
1860
+ "Content-Type": "application/json",
1861
+ "Authorization": `Bearer ${accessToken}`,
1862
+ "X-Storefront-Key": config.storefrontApiKey,
1863
+ "X-Business-ID": config.businessId
1864
+ },
1865
+ body: JSON.stringify(payload)
1866
+ });
1867
+ if (!response.ok) throw new Error("Failed to create consultation");
1868
+ return response.json();
1869
+ }
1870
+ async function getConsultations(config, accessToken) {
1871
+ const response = await fetch(`${config.backendUrls.store}/social/consultations/`, {
1872
+ headers: {
1873
+ "Authorization": `Bearer ${accessToken}`,
1874
+ "X-Storefront-Key": config.storefrontApiKey,
1875
+ "X-Business-ID": config.businessId
1876
+ }
1877
+ });
1878
+ if (!response.ok) throw new Error("Failed to get consultations");
1879
+ return response.json();
1880
+ }
1881
+ async function getConsultation(config, accessToken, id) {
1882
+ const response = await fetch(`${config.backendUrls.store}/social/consultations/${id}`, {
1883
+ headers: {
1884
+ "Authorization": `Bearer ${accessToken}`,
1885
+ "X-Storefront-Key": config.storefrontApiKey,
1886
+ "X-Business-ID": config.businessId
1887
+ }
1888
+ });
1889
+ if (!response.ok) throw new Error("Failed to get consultation");
1890
+ return response.json();
1891
+ }
1892
+ async function sendMessage(config, accessToken, id, payload) {
1893
+ await fetch(`${config.backendUrls.store}/social/consultations/${id}/messages`, {
1894
+ method: "POST",
1895
+ headers: {
1896
+ "Content-Type": "application/json",
1897
+ "Authorization": `Bearer ${accessToken}`,
1898
+ "X-Storefront-Key": config.storefrontApiKey,
1899
+ "X-Business-ID": config.businessId
1900
+ },
1901
+ body: JSON.stringify(payload)
1902
+ });
1903
+ }
1904
+ async function acceptQuote(config, accessToken, id, payload) {
1905
+ const response = await fetch(`${config.backendUrls.store}/social/consultations/${id}/accept-quote`, {
1906
+ method: "POST",
1907
+ headers: {
1908
+ "Content-Type": "application/json",
1909
+ "Authorization": `Bearer ${accessToken}`,
1910
+ "X-Storefront-Key": config.storefrontApiKey,
1911
+ "X-Business-ID": config.businessId
1912
+ },
1913
+ body: JSON.stringify(payload)
1914
+ });
1915
+ if (!response.ok) throw new Error("Failed to accept quote");
1916
+ return response.json();
1917
+ }
1918
+ async function rejectQuote(config, accessToken, id, reason) {
1919
+ const response = await fetch(`${config.backendUrls.store}/social/consultations/${id}/reject-quote`, {
1920
+ method: "POST",
1921
+ headers: {
1922
+ "Content-Type": "application/json",
1923
+ "Authorization": `Bearer ${accessToken}`,
1924
+ "X-Storefront-Key": config.storefrontApiKey,
1925
+ "X-Business-ID": config.businessId
1926
+ },
1927
+ body: JSON.stringify({ reason })
1928
+ });
1929
+ if (!response.ok) throw new Error("Failed to reject quote");
1930
+ return response.json();
1931
+ }
1932
+ var consultationService = {
1933
+ createConsultation,
1934
+ getConsultations,
1935
+ getConsultation,
1936
+ sendMessage,
1937
+ acceptQuote,
1938
+ rejectQuote
1939
+ };
1940
+
1941
+ // src/services/logistics.service.ts
1942
+ async function getShippingRates(config, payload) {
1943
+ const response = await fetch(`${config.backendUrls.store}/logistics/shipping/rates`, {
1944
+ method: "POST",
1945
+ headers: {
1946
+ "Content-Type": "application/json",
1947
+ "X-Storefront-Key": config.storefrontApiKey,
1948
+ "X-Business-ID": config.businessId
1949
+ },
1950
+ body: JSON.stringify(payload)
1951
+ });
1952
+ if (!response.ok) throw new Error("Failed to get shipping rates");
1953
+ return response.json();
1954
+ }
1955
+ async function getSellerShippingAddress(config) {
1956
+ const response = await fetch(`${config.backendUrls.store}/logistics/shipping-address`, {
1957
+ headers: {
1958
+ "X-Storefront-Key": config.storefrontApiKey,
1959
+ "X-Business-ID": config.businessId
1960
+ }
1961
+ });
1962
+ if (!response.ok) throw new Error("Failed to get seller shipping address");
1963
+ return response.json();
1964
+ }
1965
+ async function validateShippingAddress(config, payload) {
1966
+ const response = await fetch(`${config.backendUrls.store}/logistics/shipping-address/validate`, {
1967
+ method: "POST",
1968
+ headers: {
1969
+ "Content-Type": "application/json",
1970
+ "X-Storefront-Key": config.storefrontApiKey,
1971
+ "X-Business-ID": config.businessId
1972
+ },
1973
+ body: JSON.stringify(payload)
1974
+ });
1975
+ if (!response.ok) throw new Error("Failed to validate shipping address");
1976
+ return response.json();
1977
+ }
1978
+ var logisticsService = {
1979
+ getShippingRates,
1980
+ getSellerShippingAddress,
1981
+ validateShippingAddress
1982
+ };
1983
+
1984
+ // src/services/bespoke.service.ts
1985
+ async function checkAvailability(config, product_id) {
1986
+ const response = await fetch(`${config.backendUrls.store}/bespoke/availability/${product_id}`, {
1987
+ headers: {
1988
+ "X-Storefront-Key": config.storefrontApiKey,
1989
+ "X-Business-ID": config.businessId
1990
+ }
1991
+ });
1992
+ if (!response.ok) throw new Error("Failed to check bespoke availability");
1993
+ return response.json();
1994
+ }
1995
+ var bespokeService = {
1996
+ checkAvailability
1997
+ };
1998
+
1999
+ // src/services/service-booking.service.ts
2000
+ async function getAvailableSlots(config, product_id, date_from, date_to) {
2001
+ const response = await fetch(
2002
+ `${config.backendUrls.store}/service/available-slots/${product_id}?date_from=${date_from}&date_to=${date_to}`,
2003
+ {
2004
+ headers: {
2005
+ "X-Storefront-Key": config.storefrontApiKey,
2006
+ "X-Business-ID": config.businessId
2007
+ }
2008
+ }
2009
+ );
2010
+ if (!response.ok) throw new Error("Failed to get available slots");
2011
+ return response.json();
2012
+ }
2013
+ async function bookAppointment(config, accessToken, payload) {
2014
+ const response = await fetch(`${config.backendUrls.store}/service/appointments/`, {
2015
+ method: "POST",
2016
+ headers: {
2017
+ "Content-Type": "application/json",
2018
+ "Authorization": `Bearer ${accessToken}`,
2019
+ "X-Storefront-Key": config.storefrontApiKey,
2020
+ "X-Business-ID": config.businessId
2021
+ },
2022
+ body: JSON.stringify(payload)
2023
+ });
2024
+ if (!response.ok) throw new Error("Failed to book appointment");
2025
+ return response.json();
2026
+ }
2027
+ async function getAppointments(config, accessToken) {
2028
+ const response = await fetch(`${config.backendUrls.store}/service/bookings/my`, {
2029
+ headers: {
2030
+ "Authorization": `Bearer ${accessToken}`,
2031
+ "X-Storefront-Key": config.storefrontApiKey,
2032
+ "X-Business-ID": config.businessId
2033
+ }
2034
+ });
2035
+ if (!response.ok) throw new Error("Failed to get appointments");
2036
+ return response.json();
2037
+ }
2038
+ async function getAppointment(config, accessToken, id) {
2039
+ const response = await fetch(`${config.backendUrls.store}/service/bookings/${id}`, {
2040
+ headers: {
2041
+ "Authorization": `Bearer ${accessToken}`,
2042
+ "X-Storefront-Key": config.storefrontApiKey,
2043
+ "X-Business-ID": config.businessId
2044
+ }
2045
+ });
2046
+ if (!response.ok) throw new Error("Failed to get appointment");
2047
+ return response.json();
2048
+ }
2049
+ async function cancelAppointment(config, accessToken, id) {
2050
+ await fetch(`${config.backendUrls.store}/service/bookings/${id}`, {
2051
+ method: "DELETE",
2052
+ headers: {
2053
+ "Authorization": `Bearer ${accessToken}`,
2054
+ "X-Storefront-Key": config.storefrontApiKey,
2055
+ "X-Business-ID": config.businessId
2056
+ }
2057
+ });
2058
+ }
2059
+ async function getDeliverables(config, accessToken, order_id) {
2060
+ const response = await fetch(`${config.backendUrls.store}/service/projects/${order_id}/deliverables/`, {
2061
+ headers: {
2062
+ "Authorization": `Bearer ${accessToken}`,
2063
+ "X-Storefront-Key": config.storefrontApiKey,
2064
+ "X-Business-ID": config.businessId
2065
+ }
2066
+ });
2067
+ if (!response.ok) throw new Error("Failed to get deliverables");
2068
+ return response.json();
2069
+ }
2070
+ async function approveDeliverable(config, accessToken, order_id, deliverable_id) {
2071
+ const response = await fetch(
2072
+ `${config.backendUrls.store}/service/projects/${order_id}/deliverables/${deliverable_id}/approve`,
2073
+ {
2074
+ method: "POST",
2075
+ headers: {
2076
+ "Content-Type": "application/json",
2077
+ "Authorization": `Bearer ${accessToken}`,
2078
+ "X-Storefront-Key": config.storefrontApiKey,
2079
+ "X-Business-ID": config.businessId
2080
+ },
2081
+ body: JSON.stringify({ approved: true })
2082
+ }
2083
+ );
2084
+ if (!response.ok) throw new Error("Failed to approve deliverable");
2085
+ return response.json();
2086
+ }
2087
+ async function requestRevision(config, accessToken, order_id, deliverable_id, feedback) {
2088
+ const response = await fetch(
2089
+ `${config.backendUrls.store}/service/projects/${order_id}/deliverables/${deliverable_id}/revision`,
2090
+ {
2091
+ method: "POST",
2092
+ headers: {
2093
+ "Content-Type": "application/json",
2094
+ "Authorization": `Bearer ${accessToken}`,
2095
+ "X-Storefront-Key": config.storefrontApiKey,
2096
+ "X-Business-ID": config.businessId
2097
+ },
2098
+ body: JSON.stringify({ approved: false, feedback })
2099
+ }
2100
+ );
2101
+ if (!response.ok) throw new Error("Failed to request revision");
2102
+ return response.json();
2103
+ }
2104
+ var serviceBookingService = {
2105
+ getAvailableSlots,
2106
+ bookAppointment,
2107
+ getAppointments,
2108
+ getAppointment,
2109
+ cancelAppointment,
2110
+ getDeliverables,
2111
+ approveDeliverable,
2112
+ requestRevision
2113
+ };
2114
+
2115
+ // src/services/notifications.service.ts
2116
+ async function sendContactEmail(config, payload) {
2117
+ const response = await fetch(`${config.backendUrls.notifications}/contact/send-contact-email`, {
2118
+ method: "POST",
2119
+ headers: {
2120
+ "Content-Type": "application/json",
2121
+ "X-Storefront-Key": config.storefrontApiKey,
2122
+ "X-Business-ID": config.businessId
2123
+ },
2124
+ body: JSON.stringify(payload)
2125
+ });
2126
+ if (!response.ok) throw new Error("Failed to send contact email");
2127
+ return response.json();
2128
+ }
2129
+ async function sendContactConfirmation(config, payload) {
2130
+ const response = await fetch(`${config.backendUrls.notifications}/contact/send-contact-confirmation`, {
2131
+ method: "POST",
2132
+ headers: {
2133
+ "Content-Type": "application/json",
2134
+ "X-Storefront-Key": config.storefrontApiKey,
2135
+ "X-Business-ID": config.businessId
2136
+ },
2137
+ body: JSON.stringify(payload)
2138
+ });
2139
+ if (!response.ok) throw new Error("Failed to send contact confirmation");
2140
+ return response.json();
2141
+ }
2142
+ var notificationsService = {
2143
+ sendContactEmail,
2144
+ sendContactConfirmation
2145
+ };
2146
+
2147
+ // src/services/app.service.ts
2148
+ async function googleTranslate(text, target, source = "en") {
2149
+ if (!text || target === source) return text;
2150
+ try {
2151
+ const url = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=${source}&tl=${target}&dt=t&q=${encodeURIComponent(text)}`;
2152
+ const res = await fetch(url);
2153
+ const data = await res.json();
2154
+ return (data?.[0] || []).map((s) => s[0]).join("");
2155
+ } catch {
2156
+ return text;
2157
+ }
2158
+ }
2159
+
2160
+ // src/services/config.service.ts
2161
+ async function getSupportedLanguages(config) {
2162
+ const response = await fetch(`${config.backendUrls.payment}/config/supported-languages`, {
2163
+ headers: {
2164
+ "X-Storefront-Key": config.storefrontApiKey,
2165
+ "X-Business-ID": config.businessId
2166
+ }
2167
+ });
2168
+ if (!response.ok) throw new Error("Failed to get supported languages");
2169
+ return response.json();
2170
+ }
2171
+ async function getSupportedCurrencies(config) {
2172
+ const response = await fetch(`${config.backendUrls.payment}/config/supported-currencies`, {
2173
+ headers: {
2174
+ "X-Storefront-Key": config.storefrontApiKey,
2175
+ "X-Business-ID": config.businessId
2176
+ }
2177
+ });
2178
+ if (!response.ok) throw new Error("Failed to get supported currencies");
2179
+ return response.json();
2180
+ }
2181
+ async function getBusinessConfig(config) {
2182
+ const response = await fetch(`${config.backendUrls.auth}/internal/businesses/${config.businessId}/`, {
2183
+ headers: {
2184
+ "X-Storefront-Key": config.storefrontApiKey,
2185
+ "X-Business-ID": config.businessId
2186
+ }
2187
+ });
2188
+ if (!response.ok) throw new Error("Failed to get business config");
2189
+ return response.json();
2190
+ }
2191
+ var configService = {
2192
+ getSupportedLanguages,
2193
+ getSupportedCurrencies,
2194
+ getBusinessConfig
2195
+ };
2196
+
2197
+ // src/services/cms.service.ts
2198
+ async function listCmsEntries(config, modelSlug, params) {
2199
+ const queryParams = new URLSearchParams();
2200
+ queryParams.set("page", (params?.page || 1).toString());
2201
+ queryParams.set("page_size", (params?.page_size || 50).toString());
2202
+ const response = await fetch(
2203
+ `${config.backendUrls.cms}/sdk/${config.businessId}/${modelSlug}/entries?${queryParams.toString()}`,
2204
+ {
2205
+ headers: {
2206
+ "X-Storefront-Key": config.storefrontApiKey,
2207
+ "X-Business-ID": config.businessId
2208
+ }
2209
+ }
2210
+ );
2211
+ if (!response.ok) throw new Error("Failed to list CMS entries");
2212
+ return response.json();
2213
+ }
2214
+ async function getCmsEntry(config, modelSlug, entryId) {
2215
+ const response = await fetch(
2216
+ `${config.backendUrls.cms}/sdk/${config.businessId}/${modelSlug}/entries/${entryId}`,
2217
+ {
2218
+ headers: {
2219
+ "X-Storefront-Key": config.storefrontApiKey,
2220
+ "X-Business-ID": config.businessId
2221
+ }
2222
+ }
2223
+ );
2224
+ if (!response.ok) throw new Error("Failed to get CMS entry");
2225
+ return response.json();
2226
+ }
2227
+ async function createCmsEntry(config, accessToken, modelSlug, params) {
2228
+ const response = await fetch(
2229
+ `${config.backendUrls.cms}/sdk/${config.businessId}/${modelSlug}/entries`,
2230
+ {
2231
+ method: "POST",
2232
+ headers: {
2233
+ "Content-Type": "application/json",
2234
+ "Authorization": `Bearer ${accessToken}`,
2235
+ "X-Storefront-Key": config.storefrontApiKey,
2236
+ "X-Business-ID": config.businessId
2237
+ },
2238
+ body: JSON.stringify(params)
2239
+ }
2240
+ );
2241
+ if (!response.ok) throw new Error("Failed to create CMS entry");
2242
+ return response.json();
2243
+ }
2244
+ async function updateCmsEntry(config, accessToken, modelSlug, entryId, params) {
2245
+ const response = await fetch(
2246
+ `${config.backendUrls.cms}/sdk/${config.businessId}/${modelSlug}/entries/${entryId}`,
2247
+ {
2248
+ method: "PUT",
2249
+ headers: {
2250
+ "Content-Type": "application/json",
2251
+ "Authorization": `Bearer ${accessToken}`,
2252
+ "X-Storefront-Key": config.storefrontApiKey,
2253
+ "X-Business-ID": config.businessId
2254
+ },
2255
+ body: JSON.stringify(params)
2256
+ }
2257
+ );
2258
+ if (!response.ok) throw new Error("Failed to update CMS entry");
2259
+ return response.json();
2260
+ }
2261
+ async function deleteCmsEntry(config, accessToken, modelSlug, entryId) {
2262
+ const response = await fetch(
2263
+ `${config.backendUrls.cms}/sdk/${config.businessId}/${modelSlug}/entries/${entryId}`,
2264
+ {
2265
+ method: "DELETE",
2266
+ headers: {
2267
+ "Authorization": `Bearer ${accessToken}`,
2268
+ "X-Storefront-Key": config.storefrontApiKey,
2269
+ "X-Business-ID": config.businessId
2270
+ }
2271
+ }
2272
+ );
2273
+ if (!response.ok) throw new Error("Failed to delete CMS entry");
2274
+ }
2275
+ // Annotate the CommonJS export names for ESM import in node:
2276
+ 0 && (module.exports = {
2277
+ acceptQuote,
2278
+ addToCart,
2279
+ addToGuestCart,
2280
+ addToWishlist,
2281
+ approveDeliverable,
2282
+ bespokeService,
2283
+ bookAppointment,
2284
+ cancelAppointment,
2285
+ cancelOrder,
2286
+ checkAvailability,
2287
+ checkInWishlist,
2288
+ clearCart,
2289
+ clearGuestCart,
2290
+ clearTokens,
2291
+ configService,
2292
+ consultationService,
2293
+ createCmsEntry,
2294
+ createConsultation,
2295
+ createDedicatedAccount,
2296
+ createOrder,
2297
+ deleteCmsEntry,
2298
+ findOrder,
2299
+ findOrderByToken,
2300
+ getAppointment,
2301
+ getAppointments,
2302
+ getAuthUser,
2303
+ getAvailableSlots,
2304
+ getBusinessConfig,
2305
+ getCart,
2306
+ getCmsEntry,
2307
+ getConsultation,
2308
+ getConsultations,
2309
+ getDeliverables,
2310
+ getFeaturedProducts,
2311
+ getGuestCart,
2312
+ getGuestCartCount,
2313
+ getGuestCartProductType,
2314
+ getGuestCartSubtotal,
2315
+ getLatestProducts,
2316
+ getLowStockProducts,
2317
+ getMe,
2318
+ getNewProducts,
2319
+ getOnSaleProducts,
2320
+ getOrders,
2321
+ getPopularProducts,
2322
+ getRecommendedProducts,
2323
+ getSellerShippingAddress,
2324
+ getShippingRates,
2325
+ getStoredTokens,
2326
+ getStorefrontCollectionBySlug,
2327
+ getStorefrontCollections,
2328
+ getStorefrontProductBySlug,
2329
+ getStorefrontProducts,
2330
+ getSupportedCurrencies,
2331
+ getSupportedLanguages,
2332
+ getTransactionStatus,
2333
+ getWishlist,
2334
+ googleTranslate,
2335
+ initiatePayment,
2336
+ listCmsEntries,
2337
+ loginCustomer,
2338
+ logisticsService,
2339
+ logout,
2340
+ mapAuthUserToCustomer,
2341
+ mergeGuestCart,
2342
+ mergeGuestCartIfPresent,
2343
+ notificationsService,
2344
+ paymentService,
2345
+ refreshToken,
2346
+ registerCustomer,
2347
+ rejectQuote,
2348
+ removeFromCart,
2349
+ removeFromGuestCart,
2350
+ removeFromWishlist,
2351
+ removeProductFromWishlist,
2352
+ requestQuote,
2353
+ requestRevision,
2354
+ sendContactConfirmation,
2355
+ sendContactEmail,
2356
+ sendMessage,
2357
+ serviceBookingService,
2358
+ silentRefresh,
2359
+ storeTokens,
2360
+ trackOrder,
2361
+ updateCartItem,
2362
+ updateCmsEntry,
2363
+ updateGuestCartItemQuantity,
2364
+ updateProfile,
2365
+ validateShippingAddress,
2366
+ verifySocialToken,
2367
+ verifyTransaction
2368
+ });
2369
+ //# sourceMappingURL=index.js.map