@ecomiq/core 0.1.0

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 (68) hide show
  1. package/README.md +42 -0
  2. package/dist/api.cjs +99 -0
  3. package/dist/api.cjs.map +1 -0
  4. package/dist/api.d.cts +52 -0
  5. package/dist/api.d.ts +52 -0
  6. package/dist/api.js +93 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/client.cjs +1344 -0
  9. package/dist/client.cjs.map +1 -0
  10. package/dist/client.d.cts +82 -0
  11. package/dist/client.d.ts +82 -0
  12. package/dist/client.js +1341 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/index.cjs +1611 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.d.cts +1109 -0
  17. package/dist/index.d.ts +1109 -0
  18. package/dist/index.js +1450 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/models/collections.cjs +20 -0
  21. package/dist/models/collections.cjs.map +1 -0
  22. package/dist/models/collections.d.cts +56 -0
  23. package/dist/models/collections.d.ts +56 -0
  24. package/dist/models/collections.js +17 -0
  25. package/dist/models/collections.js.map +1 -0
  26. package/dist/models/geo.cjs +62 -0
  27. package/dist/models/geo.cjs.map +1 -0
  28. package/dist/models/geo.d.cts +279 -0
  29. package/dist/models/geo.d.ts +279 -0
  30. package/dist/models/geo.js +48 -0
  31. package/dist/models/geo.js.map +1 -0
  32. package/dist/models/products.cjs +212 -0
  33. package/dist/models/products.cjs.map +1 -0
  34. package/dist/models/products.d.cts +1421 -0
  35. package/dist/models/products.d.ts +1421 -0
  36. package/dist/models/products.js +187 -0
  37. package/dist/models/products.js.map +1 -0
  38. package/dist/models/search.cjs +200 -0
  39. package/dist/models/search.cjs.map +1 -0
  40. package/dist/models/search.d.cts +51 -0
  41. package/dist/models/search.d.ts +51 -0
  42. package/dist/models/search.js +196 -0
  43. package/dist/models/search.js.map +1 -0
  44. package/dist/models/settings.cjs +285 -0
  45. package/dist/models/settings.cjs.map +1 -0
  46. package/dist/models/settings.d.cts +7039 -0
  47. package/dist/models/settings.d.ts +7039 -0
  48. package/dist/models/settings.js +239 -0
  49. package/dist/models/settings.js.map +1 -0
  50. package/dist/models/storefront-cart.cjs +148 -0
  51. package/dist/models/storefront-cart.cjs.map +1 -0
  52. package/dist/models/storefront-cart.d.cts +747 -0
  53. package/dist/models/storefront-cart.d.ts +747 -0
  54. package/dist/models/storefront-cart.js +133 -0
  55. package/dist/models/storefront-cart.js.map +1 -0
  56. package/dist/models/storefront-checkout.cjs +307 -0
  57. package/dist/models/storefront-checkout.cjs.map +1 -0
  58. package/dist/models/storefront-checkout.d.cts +4122 -0
  59. package/dist/models/storefront-checkout.d.ts +4122 -0
  60. package/dist/models/storefront-checkout.js +288 -0
  61. package/dist/models/storefront-checkout.js.map +1 -0
  62. package/dist/models/storefront-reviews.cjs +223 -0
  63. package/dist/models/storefront-reviews.cjs.map +1 -0
  64. package/dist/models/storefront-reviews.d.cts +147 -0
  65. package/dist/models/storefront-reviews.d.ts +147 -0
  66. package/dist/models/storefront-reviews.js +218 -0
  67. package/dist/models/storefront-reviews.js.map +1 -0
  68. package/package.json +109 -0
@@ -0,0 +1,1344 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+
5
+ // src/libs/api.ts
6
+ var DEFAULT_API_BASE_URL = "https://storefront.ecomiq.pe";
7
+ var DEFAULT_API_VERSION = "v1";
8
+ var ApiError = class extends Error {
9
+ constructor(message, status, url, body) {
10
+ super(message);
11
+ this.status = status;
12
+ this.url = url;
13
+ this.body = body;
14
+ this.name = "ApiError";
15
+ }
16
+ status;
17
+ url;
18
+ body;
19
+ };
20
+ function resolveApiBaseUrl(baseUrl = DEFAULT_API_BASE_URL, version = DEFAULT_API_VERSION) {
21
+ const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
22
+ const segment = version.replace(/^\/+|\/+$/g, "");
23
+ return new URL(`${segment}/`, root).toString();
24
+ }
25
+ function createApi(options = {}) {
26
+ const {
27
+ baseUrl = DEFAULT_API_BASE_URL,
28
+ version = DEFAULT_API_VERSION,
29
+ headers: baseHeaders = {},
30
+ timeoutMs = 1e4
31
+ } = options;
32
+ const effectiveBaseUrl = resolveApiBaseUrl(baseUrl, version);
33
+ async function request(method, path, schema, opts = {}) {
34
+ const url = new URL(path.replace(/^\//, ""), effectiveBaseUrl);
35
+ for (const [key, value] of Object.entries(opts.query ?? {})) {
36
+ if (value !== void 0) url.searchParams.set(key, String(value));
37
+ }
38
+ const controller = new AbortController();
39
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
40
+ if (opts.signal) opts.signal.addEventListener("abort", () => controller.abort(), { once: true });
41
+ const isFormData = typeof FormData !== "undefined" && opts.body instanceof FormData;
42
+ let response;
43
+ try {
44
+ response = await fetch(url.toString(), {
45
+ method,
46
+ headers: {
47
+ accept: "application/json",
48
+ ...opts.body !== void 0 && !isFormData ? { "content-type": "application/json" } : {},
49
+ ...baseHeaders,
50
+ ...opts.headers
51
+ },
52
+ body: opts.body === void 0 ? void 0 : isFormData ? opts.body : JSON.stringify(opts.body),
53
+ signal: controller.signal
54
+ });
55
+ } catch (err) {
56
+ throw new ApiError(
57
+ err instanceof DOMException && err.name === "AbortError" ? `Timeout tras ${timeoutMs}ms: ${url}` : `No se pudo conectar con ${url}`,
58
+ 0,
59
+ url.toString()
60
+ );
61
+ } finally {
62
+ clearTimeout(timeout);
63
+ }
64
+ if (!response.ok) {
65
+ const bodyText = await response.text().catch(() => void 0);
66
+ let body = bodyText;
67
+ if (bodyText) {
68
+ try {
69
+ body = JSON.parse(bodyText);
70
+ } catch {
71
+ }
72
+ }
73
+ throw new ApiError(`${method} ${url} \u2192 ${response.status}`, response.status, url.toString(), body);
74
+ }
75
+ const json = await response.json();
76
+ const parsed = schema.safeParse(json);
77
+ if (!parsed.success) {
78
+ throw new ApiError(
79
+ `Respuesta inesperada de ${url}: ${parsed.error.issues[0]?.path.join(".")} ${parsed.error.issues[0]?.message}`,
80
+ response.status,
81
+ url.toString(),
82
+ json
83
+ );
84
+ }
85
+ return parsed.data;
86
+ }
87
+ return {
88
+ request,
89
+ get: (path, schema, opts) => request("GET", path, schema, opts),
90
+ post: (path, body, schema, opts) => request("POST", path, schema, { ...opts, body }),
91
+ postForm: (path, body, schema, opts) => request("POST", path, schema, { ...opts, body })
92
+ };
93
+ }
94
+ var CollectionSchema = zod.z.object({
95
+ id: zod.z.number(),
96
+ slug: zod.z.string(),
97
+ name: zod.z.string(),
98
+ description: zod.z.string().nullable().optional(),
99
+ imageUrl: zod.z.string().nullable().optional(),
100
+ type: zod.z.string(),
101
+ productCount: zod.z.number().optional()
102
+ });
103
+ var CollectionsSchema = zod.z.array(CollectionSchema);
104
+ var ProductPublicIdSchema = zod.z.union([
105
+ zod.z.string().regex(/^[1-9]\d*$/),
106
+ zod.z.number().int().safe().positive()
107
+ ]).transform(String);
108
+ var ProductSummarySchema = zod.z.object({
109
+ id: ProductPublicIdSchema,
110
+ name: zod.z.string(),
111
+ slug: zod.z.string(),
112
+ productType: zod.z.string(),
113
+ imageUrl: zod.z.string(),
114
+ price: zod.z.number().nonnegative(),
115
+ compareAtPrice: zod.z.number().nonnegative().nullable(),
116
+ variantCount: zod.z.number().int().nonnegative(),
117
+ isAvailable: zod.z.boolean(),
118
+ totalInventory: zod.z.number().int().nonnegative(),
119
+ bundleItemsCount: zod.z.number().int().nonnegative(),
120
+ brand: zod.z.string(),
121
+ category: zod.z.string(),
122
+ status: zod.z.string(),
123
+ collections: zod.z.array(zod.z.string()),
124
+ tags: zod.z.array(zod.z.string())
125
+ });
126
+ var ProductSummariesSchema = zod.z.array(ProductSummarySchema);
127
+ var FacetItemSchema = zod.z.object({
128
+ value: zod.z.string(),
129
+ count: zod.z.number().int().nonnegative(),
130
+ label: zod.z.string().nullable(),
131
+ selected: zod.z.boolean()
132
+ });
133
+ var SearchFilterSchema = zod.z.object({
134
+ id: zod.z.string(),
135
+ label: zod.z.string(),
136
+ type: zod.z.enum(["list", "price_range"]),
137
+ values: zod.z.array(FacetItemSchema),
138
+ min: zod.z.number().nonnegative().nullable(),
139
+ max: zod.z.number().nonnegative().nullable(),
140
+ selectedMin: zod.z.number().nonnegative().nullable(),
141
+ selectedMax: zod.z.number().nonnegative().nullable()
142
+ });
143
+ var ProductsResponseSchema = zod.z.object({
144
+ pageIndex: zod.z.number().int().positive(),
145
+ pageSize: zod.z.number().int().positive().max(100),
146
+ totalCount: zod.z.number().int().nonnegative(),
147
+ totalPages: zod.z.number().int().nonnegative(),
148
+ products: zod.z.array(ProductSummarySchema),
149
+ filters: zod.z.array(SearchFilterSchema)
150
+ });
151
+ var ProductSortSchema = zod.z.enum([
152
+ "price_asc",
153
+ "price_desc",
154
+ "name_asc",
155
+ "name_desc",
156
+ "newest"
157
+ ]);
158
+ var ProductsParamsSchema = zod.z.object({
159
+ page: zod.z.number().int().positive().default(1),
160
+ pageSize: zod.z.number().int().positive().max(100).default(24),
161
+ sort: ProductSortSchema.optional(),
162
+ sellerId: zod.z.string().uuid().optional(),
163
+ search: zod.z.string().optional(),
164
+ collection: zod.z.string().optional(),
165
+ collections: zod.z.array(zod.z.string()).optional(),
166
+ collectionId: ProductPublicIdSchema.optional(),
167
+ category: zod.z.string().optional(),
168
+ categories: zod.z.array(zod.z.string()).optional(),
169
+ brand: zod.z.string().optional(),
170
+ brands: zod.z.array(zod.z.string()).optional(),
171
+ productType: zod.z.string().optional(),
172
+ productTypes: zod.z.array(zod.z.string()).optional(),
173
+ tag: zod.z.string().optional(),
174
+ tags: zod.z.array(zod.z.string()).optional(),
175
+ filters: zod.z.array(zod.z.string()).optional(),
176
+ locationId: zod.z.string().uuid().optional(),
177
+ inStock: zod.z.boolean().optional(),
178
+ minPrice: zod.z.number().nonnegative().optional(),
179
+ maxPrice: zod.z.number().nonnegative().optional()
180
+ });
181
+ var ProductDetailParamsSchema = zod.z.object({
182
+ sellerId: zod.z.string().uuid().optional()
183
+ });
184
+ var RelatedProductsParamsSchema = zod.z.object({
185
+ productId: ProductPublicIdSchema,
186
+ limit: zod.z.number().int().positive().max(12).default(8),
187
+ sellerId: zod.z.string().uuid().optional()
188
+ });
189
+ var SpecItemSchema = zod.z.object({
190
+ key: zod.z.string(),
191
+ name: zod.z.string(),
192
+ value: zod.z.string()
193
+ });
194
+ var ProductImageSchema = zod.z.object({
195
+ url: zod.z.string(),
196
+ name: zod.z.string(),
197
+ order: zod.z.number().int().nonnegative()
198
+ });
199
+ var VariantItemSchema = zod.z.object({
200
+ id: zod.z.string().nullable(),
201
+ sku: zod.z.string(),
202
+ status: zod.z.string(),
203
+ price: zod.z.number().nonnegative(),
204
+ compareAtPrice: zod.z.number().nonnegative().nullable(),
205
+ quantity: zod.z.number().int().nonnegative(),
206
+ options: zod.z.array(SpecItemSchema),
207
+ images: zod.z.array(ProductImageSchema)
208
+ });
209
+ var ProductPriceTierSchema = zod.z.object({
210
+ variantId: zod.z.string(),
211
+ minQuantity: zod.z.number().int().positive(),
212
+ maxQuantity: zod.z.number().int().positive().nullable(),
213
+ unitPrice: zod.z.number().nonnegative()
214
+ });
215
+ var BundleItemSchema = zod.z.object({
216
+ productId: ProductPublicIdSchema,
217
+ variantId: ProductPublicIdSchema,
218
+ productName: zod.z.string(),
219
+ variantName: zod.z.string().nullable(),
220
+ sku: zod.z.string().nullable(),
221
+ brand: zod.z.string().nullable(),
222
+ imageUrl: zod.z.string().nullable(),
223
+ quantity: zod.z.number().int().positive(),
224
+ available: zod.z.number().int().nonnegative(),
225
+ allowBackorders: zod.z.boolean(),
226
+ requiresShipping: zod.z.boolean()
227
+ });
228
+ var SizeGuideMeasurementSchema = zod.z.object({
229
+ key: zod.z.string(),
230
+ name: zod.z.string(),
231
+ min: zod.z.number().nullable(),
232
+ max: zod.z.number().nullable(),
233
+ value: zod.z.number().nullable(),
234
+ description: zod.z.string().nullable()
235
+ });
236
+ var SizeGuideRowSchema = zod.z.object({
237
+ label: zod.z.string(),
238
+ sizeKey: zod.z.string(),
239
+ order: zod.z.number().int().nonnegative(),
240
+ measurements: zod.z.array(SizeGuideMeasurementSchema)
241
+ });
242
+ var SizeGuideSchema = zod.z.object({
243
+ id: zod.z.string(),
244
+ name: zod.z.string(),
245
+ slug: zod.z.string(),
246
+ description: zod.z.string().nullable(),
247
+ imageUrl: zod.z.string().nullable(),
248
+ gender: zod.z.string(),
249
+ measurementType: zod.z.string(),
250
+ unit: zod.z.string(),
251
+ notes: zod.z.string().nullable(),
252
+ rows: zod.z.array(SizeGuideRowSchema)
253
+ });
254
+ var ProductDetailSchema = zod.z.object({
255
+ id: ProductPublicIdSchema,
256
+ name: zod.z.string(),
257
+ slug: zod.z.string(),
258
+ description: zod.z.string(),
259
+ productType: zod.z.string(),
260
+ status: zod.z.string(),
261
+ imageUrl: zod.z.string(),
262
+ price: zod.z.number().nonnegative(),
263
+ compareAtPrice: zod.z.number().nonnegative().nullable(),
264
+ isAvailable: zod.z.boolean(),
265
+ totalInventory: zod.z.number().int().nonnegative(),
266
+ brand: zod.z.string(),
267
+ category: zod.z.string(),
268
+ categoryId: ProductPublicIdSchema.nullable(),
269
+ tags: zod.z.array(zod.z.string()),
270
+ specifications: zod.z.array(SpecItemSchema),
271
+ variants: zod.z.array(VariantItemSchema),
272
+ images: zod.z.array(ProductImageSchema),
273
+ bundleItems: zod.z.array(BundleItemSchema),
274
+ sizeGuide: SizeGuideSchema.nullable(),
275
+ priceTiers: zod.z.array(ProductPriceTierSchema),
276
+ createdAt: zod.z.string().datetime({ offset: true }).nullable(),
277
+ updatedAt: zod.z.string().datetime({ offset: true }).nullable()
278
+ });
279
+ var JsonElementSchema = zod.z.lazy(
280
+ () => zod.z.union([
281
+ zod.z.null(),
282
+ zod.z.boolean(),
283
+ zod.z.number().finite(),
284
+ zod.z.string(),
285
+ zod.z.array(JsonElementSchema),
286
+ zod.z.record(zod.z.string(), JsonElementSchema)
287
+ ])
288
+ );
289
+ var DateTimeOffsetSchema = zod.z.string().datetime({ offset: true });
290
+ var NullableDateTimeOffsetSchema = DateTimeOffsetSchema.nullable();
291
+ var NullableUuidSchema = zod.z.string().uuid().nullable();
292
+ var StoreTypeSchema = zod.z.enum([
293
+ "b2C",
294
+ "marketplace",
295
+ "retail",
296
+ "b2B",
297
+ "social",
298
+ "hub",
299
+ "restaurant"
300
+ ]);
301
+ var StoreVisibilitySchema = zod.z.enum(["public", "private"]);
302
+ var StoreThemeSettingsSchema = zod.z.object({
303
+ name: zod.z.string().nullable(),
304
+ mode: zod.z.string().nullable(),
305
+ colors: zod.z.record(zod.z.string(), zod.z.string()),
306
+ fonts: zod.z.record(zod.z.string(), zod.z.string()),
307
+ assets: zod.z.record(zod.z.string(), zod.z.string())
308
+ }).strict();
309
+ var StoreFeatureFlagsSchema = zod.z.object({
310
+ flags: zod.z.record(zod.z.string(), zod.z.boolean())
311
+ }).strict();
312
+ var StoreCheckoutGeneralSettingsSchema = zod.z.object({
313
+ allowGuestCheckout: zod.z.boolean(),
314
+ identityScope: zod.z.enum(["store", "tenant", "global"]),
315
+ signInMethods: zod.z.array(zod.z.enum(["password", "emailOtp", "google"])),
316
+ useSequentialOrderNumbers: zod.z.boolean(),
317
+ automaticallySelectFirstAddress: zod.z.boolean(),
318
+ alwaysRequestCustomerAddress: zod.z.boolean(),
319
+ requestCustomerDateOfBirth: zod.z.boolean(),
320
+ automaticallySelectBestPromotion: zod.z.boolean()
321
+ }).strict();
322
+ var StoreCheckoutShippingSettingsSchema = zod.z.object({
323
+ showDeliveryTime: zod.z.boolean(),
324
+ showDeliveryTimeInDays: zod.z.boolean(),
325
+ useBusinessDaysForDeliveryTime: zod.z.boolean(),
326
+ showEstimatedDeliveryDateInThankYouAndEmails: zod.z.boolean(),
327
+ showOriginalShippingPriceWhenFree: zod.z.boolean()
328
+ }).strict();
329
+ var StoreCheckoutCartPageSettingsSchema = zod.z.object({
330
+ showShippingCostCalculation: zod.z.boolean(),
331
+ allowProductLinks: zod.z.boolean(),
332
+ redirectToCartPage: zod.z.boolean()
333
+ }).strict();
334
+ var StoreCheckoutOrderBumpSettingsSchema = zod.z.object({
335
+ mergeOrderBumpOrders: zod.z.boolean(),
336
+ allowOnlyOneAdditionalOffer: zod.z.boolean(),
337
+ maxVisibleOffers: zod.z.number().int()
338
+ }).strict();
339
+ var StoreCheckoutOrdersAndPaymentsSettingsSchema = zod.z.object({
340
+ allowPurchasesFrom: zod.z.enum(["any", "individual", "company"]),
341
+ creditCardDailyOrderLimitPerIp: zod.z.number().int().nullable(),
342
+ maximumItemsPerOrder: zod.z.number().int().nullable(),
343
+ deliveryNoteText: zod.z.string().nullable(),
344
+ boletoPaymentNoteText: zod.z.string().nullable()
345
+ }).strict();
346
+ var StoreCheckoutSettingsSchema = zod.z.object({
347
+ general: StoreCheckoutGeneralSettingsSchema,
348
+ shipping: StoreCheckoutShippingSettingsSchema,
349
+ cartPage: StoreCheckoutCartPageSettingsSchema,
350
+ orderBumps: StoreCheckoutOrderBumpSettingsSchema,
351
+ ordersAndPayments: StoreCheckoutOrdersAndPaymentsSettingsSchema
352
+ }).strict();
353
+ var StorefrontStoreShape = {
354
+ id: zod.z.string().uuid(),
355
+ tenantId: zod.z.string().uuid(),
356
+ sellerId: NullableUuidSchema,
357
+ type: StoreTypeSchema,
358
+ isActive: zod.z.boolean(),
359
+ name: zod.z.string(),
360
+ description: zod.z.string(),
361
+ logo: zod.z.string().nullable(),
362
+ icon: zod.z.string().nullable(),
363
+ slug: zod.z.string().nullable(),
364
+ domain: zod.z.string().nullable(),
365
+ domains: zod.z.array(zod.z.string()),
366
+ timeZone: zod.z.string(),
367
+ currency: zod.z.string(),
368
+ language: zod.z.string(),
369
+ visibility: StoreVisibilitySchema,
370
+ themeConfig: StoreThemeSettingsSchema,
371
+ featuresEnabled: StoreFeatureFlagsSchema,
372
+ checkoutSettings: StoreCheckoutSettingsSchema
373
+ };
374
+ var StoreModelSchema = zod.z.object(StorefrontStoreShape).strict();
375
+ var CmsBrandingSettingsDtoSchema = zod.z.object({
376
+ logoUrl: zod.z.string().nullable(),
377
+ logoDarkUrl: zod.z.string().nullable(),
378
+ faviconUrl: zod.z.string().nullable(),
379
+ socialImageUrl: zod.z.string().nullable()
380
+ }).strict();
381
+ var CmsSeoSettingsDtoSchema = zod.z.object({
382
+ siteName: zod.z.string().nullable(),
383
+ metaTitle: zod.z.string().nullable(),
384
+ metaDescription: zod.z.string().nullable(),
385
+ titleTemplate: zod.z.string().nullable(),
386
+ robotsIndex: zod.z.boolean()
387
+ }).strict();
388
+ var CmsSocialLinksDtoSchema = zod.z.object({
389
+ instagram: zod.z.string().nullable(),
390
+ facebook: zod.z.string().nullable(),
391
+ tiktok: zod.z.string().nullable(),
392
+ youtube: zod.z.string().nullable(),
393
+ x: zod.z.string().nullable()
394
+ }).strict();
395
+ var CmsContactSettingsDtoSchema = zod.z.object({
396
+ supportEmail: zod.z.string().nullable(),
397
+ phone: zod.z.string().nullable(),
398
+ whatsapp: zod.z.string().nullable(),
399
+ address: zod.z.string().nullable(),
400
+ socialLinks: CmsSocialLinksDtoSchema
401
+ }).strict();
402
+ var CmsTrackingSettingsDtoSchema = zod.z.object({
403
+ googleAnalyticsMeasurementId: zod.z.string().nullable(),
404
+ metaPixelId: zod.z.string().nullable(),
405
+ googleTagManagerContainerId: zod.z.string().nullable()
406
+ }).strict();
407
+ var CmsCustomScriptsDtoSchema = zod.z.object({
408
+ enabled: zod.z.boolean(),
409
+ head: zod.z.string().nullable(),
410
+ bodyEnd: zod.z.string().nullable()
411
+ }).strict();
412
+ var CmsSiteSettingsDtoSchema = zod.z.object({
413
+ themeKey: zod.z.string(),
414
+ branding: CmsBrandingSettingsDtoSchema,
415
+ seo: CmsSeoSettingsDtoSchema,
416
+ contact: CmsContactSettingsDtoSchema,
417
+ tracking: CmsTrackingSettingsDtoSchema,
418
+ customScripts: CmsCustomScriptsDtoSchema,
419
+ updatedOn: NullableDateTimeOffsetSchema
420
+ }).strict();
421
+ var CmsMenuItemSchema = zod.z.lazy(
422
+ () => zod.z.object({
423
+ label: zod.z.string(),
424
+ url: zod.z.string(),
425
+ order: zod.z.number().int(),
426
+ target: zod.z.string().nullable(),
427
+ visible: zod.z.boolean().nullable(),
428
+ children: zod.z.array(CmsMenuItemSchema).nullable()
429
+ }).strict()
430
+ );
431
+ var CmsMenuDtoSchema = zod.z.object({
432
+ key: zod.z.string(),
433
+ name: zod.z.string(),
434
+ items: zod.z.array(CmsMenuItemSchema)
435
+ }).strict();
436
+ var CmsBlockDtoSchema = zod.z.object({
437
+ id: zod.z.string().uuid(),
438
+ type: zod.z.string(),
439
+ order: zod.z.number().int(),
440
+ settings: JsonElementSchema
441
+ }).strict();
442
+ var CmsSectionDtoSchema = zod.z.object({
443
+ id: zod.z.string().uuid(),
444
+ type: zod.z.string(),
445
+ order: zod.z.number().int(),
446
+ settings: JsonElementSchema,
447
+ blocks: zod.z.array(CmsBlockDtoSchema)
448
+ }).strict();
449
+ var CmsContentChannelSchema = zod.z.enum(["storefront", "pos"]);
450
+ var CmsPageStatusSchema = zod.z.enum(["draft", "published", "archived"]);
451
+ var CmsPageDetailsDtoSchema = zod.z.object({
452
+ id: zod.z.string().uuid(),
453
+ name: zod.z.string(),
454
+ slug: zod.z.string(),
455
+ channel: CmsContentChannelSchema,
456
+ layout: zod.z.string(),
457
+ version: zod.z.number().int().nullable(),
458
+ settings: JsonElementSchema,
459
+ sections: zod.z.array(CmsSectionDtoSchema),
460
+ status: CmsPageStatusSchema,
461
+ hasPublishedVersion: zod.z.boolean(),
462
+ publishedOn: NullableDateTimeOffsetSchema,
463
+ publishedBy: NullableUuidSchema,
464
+ createdOn: DateTimeOffsetSchema,
465
+ updatedOn: NullableDateTimeOffsetSchema,
466
+ createdBy: NullableUuidSchema,
467
+ updatedBy: NullableUuidSchema,
468
+ lastModifiedBy: zod.z.string().nullable()
469
+ }).strict();
470
+ var CmsSnapshotDtoSchema = zod.z.object({
471
+ settings: CmsSiteSettingsDtoSchema,
472
+ pages: zod.z.array(CmsPageDetailsDtoSchema),
473
+ menus: zod.z.array(CmsMenuDtoSchema)
474
+ }).strict();
475
+ var StoreSettingsSnapshotV1Schema = zod.z.object({
476
+ schemaVersion: zod.z.literal(1),
477
+ generatedAt: DateTimeOffsetSchema,
478
+ store: zod.z.object(StorefrontStoreShape),
479
+ cms: CmsSnapshotDtoSchema
480
+ }).strict();
481
+ var StoreSettingsSnapshotV2Schema = zod.z.object({
482
+ schemaVersion: zod.z.literal(2),
483
+ generatedAt: DateTimeOffsetSchema,
484
+ store: StoreModelSchema,
485
+ cms: CmsSnapshotDtoSchema
486
+ }).strict();
487
+ var StoreSettingsSnapshotDtoSchema = zod.z.discriminatedUnion(
488
+ "schemaVersion",
489
+ [StoreSettingsSnapshotV1Schema, StoreSettingsSnapshotV2Schema]
490
+ );
491
+ var StorefrontSettingsSchema = StoreSettingsSnapshotDtoSchema;
492
+
493
+ // src/services/product.service.ts
494
+ async function getProducts(api, params = {}) {
495
+ const input = ProductsParamsSchema.parse(params);
496
+ const query = new URLSearchParams();
497
+ query.set("page", String(input.page));
498
+ query.set("pageSize", String(input.pageSize));
499
+ if (input.sort) query.set("sort", input.sort);
500
+ if (input.sellerId) query.set("sellerId", input.sellerId);
501
+ if (input.search) query.set("search", input.search);
502
+ if (input.collection) query.set("collection", input.collection);
503
+ for (const collection of input.collections ?? []) {
504
+ query.append("collections", collection);
505
+ }
506
+ if (input.collectionId) query.set("collectionId", input.collectionId);
507
+ if (input.category) query.set("category", input.category);
508
+ for (const category of input.categories ?? []) {
509
+ query.append("categories", category);
510
+ }
511
+ if (input.brand) query.set("brand", input.brand);
512
+ for (const brand of input.brands ?? []) {
513
+ query.append("brands", brand);
514
+ }
515
+ if (input.productType) query.set("productType", input.productType);
516
+ for (const productType of input.productTypes ?? []) {
517
+ query.append("productTypes", productType);
518
+ }
519
+ if (input.tag) query.set("tag", input.tag);
520
+ for (const tag of input.tags ?? []) {
521
+ query.append("tags", tag);
522
+ }
523
+ for (const filter of input.filters ?? []) {
524
+ query.append("filters", filter);
525
+ }
526
+ if (input.locationId) query.set("locationId", input.locationId);
527
+ if (input.inStock !== void 0) query.set("inStock", String(input.inStock));
528
+ if (input.minPrice !== void 0) query.set("minPrice", String(input.minPrice));
529
+ if (input.maxPrice !== void 0) query.set("maxPrice", String(input.maxPrice));
530
+ return api.get(`products?${query.toString()}`, ProductsResponseSchema);
531
+ }
532
+ async function getProductBySlug(api, slug, params = {}) {
533
+ const input = ProductDetailParamsSchema.parse(params);
534
+ const query = new URLSearchParams();
535
+ if (input.sellerId) query.set("sellerId", input.sellerId);
536
+ const path = `products/${encodeURIComponent(slug)}`;
537
+ const search = query.toString();
538
+ if (search) {
539
+ return api.get(`${path}?${search}`, ProductDetailSchema);
540
+ }
541
+ return api.get(path, ProductDetailSchema);
542
+ }
543
+ async function getRelatedProducts(api, params) {
544
+ const input = RelatedProductsParamsSchema.parse(params);
545
+ return api.get(
546
+ `products/${encodeURIComponent(input.productId)}/related`,
547
+ ProductSummariesSchema,
548
+ {
549
+ query: {
550
+ limit: input.limit,
551
+ sellerId: input.sellerId
552
+ }
553
+ }
554
+ );
555
+ }
556
+ var ProductAutocompleteParamsSchema = zod.z.object({
557
+ search: zod.z.string().min(2).max(80),
558
+ limit: zod.z.number().int().positive().max(20).default(8),
559
+ sellerId: zod.z.string().uuid().optional()
560
+ });
561
+ var ProductSuggestionSchema = zod.z.object({
562
+ id: ProductPublicIdSchema,
563
+ name: zod.z.string(),
564
+ slug: zod.z.string(),
565
+ imageUrl: zod.z.string()
566
+ });
567
+ var ProductSuggestionsSchema = zod.z.array(ProductSuggestionSchema);
568
+
569
+ // src/services/search.service.ts
570
+ async function autocompleteProducts(api, params) {
571
+ const input = ProductAutocompleteParamsSchema.parse(params);
572
+ return api.get("search/autocomplete", ProductSuggestionsSchema, {
573
+ query: {
574
+ search: input.search,
575
+ limit: input.limit,
576
+ sellerId: input.sellerId
577
+ }
578
+ });
579
+ }
580
+ var StorefrontReviewSchema = zod.z.object({
581
+ id: ProductPublicIdSchema,
582
+ productId: ProductPublicIdSchema,
583
+ isVerifiedPurchase: zod.z.boolean(),
584
+ rating: zod.z.number().int().min(1).max(5),
585
+ title: zod.z.string().nullable(),
586
+ content: zod.z.string(),
587
+ reviewerName: zod.z.string().nullable(),
588
+ createdOn: zod.z.string().datetime({ offset: true })
589
+ });
590
+ var StorefrontReviewsSchema = zod.z.object({
591
+ data: zod.z.array(StorefrontReviewSchema),
592
+ hasNextPage: zod.z.boolean(),
593
+ nextCursor: zod.z.string().nullable(),
594
+ totalCount: zod.z.number().int().nonnegative().nullable()
595
+ });
596
+ var ListProductReviewsParamsSchema = zod.z.object({
597
+ productId: ProductPublicIdSchema,
598
+ limit: zod.z.number().int().min(1).max(200).optional(),
599
+ cursor: zod.z.string().optional(),
600
+ search: zod.z.string().optional(),
601
+ sortBy: zod.z.enum(["rating", "createdOn"]).optional(),
602
+ sortDirection: zod.z.enum(["asc", "desc"]).optional(),
603
+ rating: zod.z.number().int().min(1).max(5).optional()
604
+ });
605
+ var CreateProductReviewParamsSchema = zod.z.object({
606
+ productId: ProductPublicIdSchema,
607
+ rating: zod.z.number().int().min(1).max(5),
608
+ content: zod.z.string().min(1).max(4e3),
609
+ title: zod.z.string().max(200).optional(),
610
+ reviewerName: zod.z.string().min(1).max(200),
611
+ reviewerEmail: zod.z.string().email().max(320),
612
+ orderId: zod.z.number().int().safe().positive().optional()
613
+ });
614
+
615
+ // src/services/review.service.ts
616
+ async function listProductReviews(api, params) {
617
+ const input = ListProductReviewsParamsSchema.parse(params);
618
+ return api.get(
619
+ `products/${encodeURIComponent(input.productId)}/reviews`,
620
+ StorefrontReviewsSchema,
621
+ {
622
+ query: {
623
+ limit: input.limit,
624
+ cursor: input.cursor,
625
+ search: input.search,
626
+ sortBy: input.sortBy,
627
+ sortDirection: input.sortDirection,
628
+ rating: input.rating
629
+ }
630
+ }
631
+ );
632
+ }
633
+ async function createProductReview(api, params) {
634
+ const input = CreateProductReviewParamsSchema.parse(params);
635
+ return api.post(
636
+ `products/${encodeURIComponent(input.productId)}/reviews`,
637
+ {
638
+ rating: input.rating,
639
+ content: input.content,
640
+ title: input.title,
641
+ reviewerName: input.reviewerName,
642
+ reviewerEmail: input.reviewerEmail,
643
+ orderId: input.orderId
644
+ },
645
+ StorefrontReviewSchema
646
+ );
647
+ }
648
+ var StorefrontAddressSchema = zod.z.object({
649
+ name: zod.z.string().nullable(),
650
+ address1: zod.z.string(),
651
+ city: zod.z.string(),
652
+ countryCode: zod.z.string(),
653
+ company: zod.z.string().nullable(),
654
+ address2: zod.z.string().nullable(),
655
+ province: zod.z.string().nullable(),
656
+ postalCode: zod.z.string().nullable(),
657
+ district: zod.z.string().nullable(),
658
+ phone: zod.z.string().nullable(),
659
+ latitude: zod.z.number().nullable(),
660
+ longitude: zod.z.number().nullable()
661
+ });
662
+ var StorefrontCartBundleItemSchema = zod.z.object({
663
+ productId: zod.z.number().int().safe().nonnegative(),
664
+ variantId: zod.z.number().int().safe().nonnegative(),
665
+ productName: zod.z.string(),
666
+ variantName: zod.z.string().nullable(),
667
+ sku: zod.z.string().nullable(),
668
+ brand: zod.z.string().nullable(),
669
+ imageUrl: zod.z.string().nullable(),
670
+ quantity: zod.z.number().int().positive()
671
+ });
672
+ var StorefrontCartItemSchema = zod.z.object({
673
+ id: zod.z.string().uuid(),
674
+ productId: zod.z.number().int().safe().nonnegative(),
675
+ title: zod.z.string(),
676
+ variantLabel: zod.z.string().nullable(),
677
+ productHandle: zod.z.string().nullable(),
678
+ thumbnail: zod.z.string().nullable(),
679
+ quantity: zod.z.number().int().positive(),
680
+ variantId: zod.z.number().int().safe().nonnegative(),
681
+ variantSku: zod.z.string().nullable(),
682
+ unitPrice: zod.z.number(),
683
+ compareAtUnitPrice: zod.z.number().nullable(),
684
+ bundleItems: zod.z.array(StorefrontCartBundleItemSchema)
685
+ });
686
+ var StorefrontCartShippingMethodSchema = zod.z.object({
687
+ id: zod.z.string().uuid(),
688
+ shippingMethodId: zod.z.string().uuid().nullable(),
689
+ rateId: zod.z.string().uuid().nullable(),
690
+ name: zod.z.string(),
691
+ description: zod.z.string().nullable(),
692
+ total: zod.z.number(),
693
+ locationId: zod.z.string().uuid().nullable(),
694
+ estimatedDays: zod.z.number().int().nullable(),
695
+ pickupPointId: zod.z.string().uuid().nullable(),
696
+ scheduledDate: zod.z.string().nullable(),
697
+ scheduledTime: zod.z.string().nullable(),
698
+ serviceCode: zod.z.string().nullable(),
699
+ sellerId: zod.z.string().uuid().nullable(),
700
+ shippingProfileId: zod.z.string().uuid().nullable()
701
+ });
702
+ var StorefrontCartTotalsSchema = zod.z.object({
703
+ subtotal: zod.z.number(),
704
+ discountTotal: zod.z.number(),
705
+ shippingOriginalTotal: zod.z.number(),
706
+ shippingTotal: zod.z.number(),
707
+ taxTotal: zod.z.number(),
708
+ warrantyTotal: zod.z.number(),
709
+ total: zod.z.number()
710
+ });
711
+ var StorefrontCartStatusSchema = zod.z.enum([
712
+ "inProgress",
713
+ "pending",
714
+ "completed",
715
+ "abandoned",
716
+ "cancelled",
717
+ "expired",
718
+ "failed"
719
+ ]);
720
+ var StorefrontCartSchema = zod.z.object({
721
+ id: zod.z.string().uuid(),
722
+ cartNumber: zod.z.string(),
723
+ email: zod.z.string().nullable(),
724
+ phone: zod.z.string().nullable(),
725
+ firstName: zod.z.string().nullable(),
726
+ lastName: zod.z.string().nullable(),
727
+ currencyCode: zod.z.string(),
728
+ status: StorefrontCartStatusSchema,
729
+ completedAt: zod.z.string().datetime({ offset: true }).nullable(),
730
+ shippingAddress: StorefrontAddressSchema.nullable(),
731
+ billingAddress: StorefrontAddressSchema.nullable(),
732
+ promotionCodes: zod.z.array(zod.z.string()),
733
+ items: zod.z.array(StorefrontCartItemSchema),
734
+ shippingMethods: zod.z.array(StorefrontCartShippingMethodSchema),
735
+ totals: StorefrontCartTotalsSchema
736
+ });
737
+ var CreateCartParamsSchema = zod.z.object({
738
+ currencyCode: zod.z.string().length(3),
739
+ salesChannelId: zod.z.string().optional(),
740
+ email: zod.z.string().email().optional()
741
+ });
742
+ var GetCartParamsSchema = zod.z.object({
743
+ cartId: zod.z.string().uuid()
744
+ });
745
+ var CartItemModifierSchema = zod.z.object({
746
+ modifierGroupId: zod.z.number().int().safe().positive(),
747
+ optionIds: zod.z.array(zod.z.number().int().safe().positive()).min(1)
748
+ });
749
+ var AddCartItemParamsSchema = zod.z.object({
750
+ cartId: zod.z.string().uuid(),
751
+ variantId: zod.z.number().int().safe().positive(),
752
+ quantity: zod.z.number().int().positive(),
753
+ modifiers: zod.z.array(CartItemModifierSchema).optional()
754
+ });
755
+ var UpdateCartItemQuantityParamsSchema = zod.z.object({
756
+ cartId: zod.z.string().uuid(),
757
+ cartItemId: zod.z.string().uuid(),
758
+ quantity: zod.z.number().int().nonnegative()
759
+ });
760
+ var RemoveCartItemParamsSchema = zod.z.object({
761
+ cartId: zod.z.string().uuid(),
762
+ cartItemId: zod.z.string().uuid()
763
+ });
764
+
765
+ // src/services/cart.service.ts
766
+ async function createCart(api, params) {
767
+ const input = CreateCartParamsSchema.parse(params);
768
+ return api.post(
769
+ "carts",
770
+ {
771
+ currencyCode: input.currencyCode,
772
+ salesChannelId: input.salesChannelId,
773
+ email: input.email
774
+ },
775
+ StorefrontCartSchema
776
+ );
777
+ }
778
+ async function getCart(api, params) {
779
+ const input = GetCartParamsSchema.parse(params);
780
+ return api.get(
781
+ `carts/${encodeURIComponent(input.cartId)}`,
782
+ StorefrontCartSchema
783
+ );
784
+ }
785
+ async function addCartItem(api, params) {
786
+ const input = AddCartItemParamsSchema.parse(params);
787
+ return api.post(
788
+ `carts/${encodeURIComponent(input.cartId)}/items`,
789
+ {
790
+ variantId: input.variantId,
791
+ quantity: input.quantity,
792
+ modifiers: input.modifiers
793
+ },
794
+ StorefrontCartSchema
795
+ );
796
+ }
797
+ async function updateCartItemQuantity(api, params) {
798
+ const input = UpdateCartItemQuantityParamsSchema.parse(params);
799
+ return api.request(
800
+ "PATCH",
801
+ `carts/${encodeURIComponent(input.cartId)}/items/${encodeURIComponent(input.cartItemId)}`,
802
+ StorefrontCartSchema,
803
+ { body: { quantity: input.quantity } }
804
+ );
805
+ }
806
+ async function removeCartItem(api, params) {
807
+ const input = RemoveCartItemParamsSchema.parse(params);
808
+ return api.request(
809
+ "DELETE",
810
+ `carts/${encodeURIComponent(input.cartId)}/items/${encodeURIComponent(input.cartItemId)}`,
811
+ StorefrontCartSchema
812
+ );
813
+ }
814
+
815
+ // src/services/collection.service.ts
816
+ async function getCollections(api) {
817
+ return api.get("collections", CollectionsSchema);
818
+ }
819
+ async function getCollectionBySlug(api, collectionSlug) {
820
+ return api.get(`collections/${encodeURIComponent(collectionSlug)}`, CollectionSchema);
821
+ }
822
+ var CartBuyerParamsSchema = zod.z.object({
823
+ cartId: zod.z.string().uuid(),
824
+ email: zod.z.string().email(),
825
+ firstName: zod.z.string().min(1),
826
+ lastName: zod.z.string().min(1),
827
+ phone: zod.z.string().min(1)
828
+ });
829
+ var CartAddressWriteSchema = zod.z.object({
830
+ name: zod.z.string().min(1),
831
+ address1: zod.z.string().min(1),
832
+ city: zod.z.string().min(1),
833
+ countryCode: zod.z.string().length(2),
834
+ company: zod.z.string().nullable().optional(),
835
+ address2: zod.z.string().nullable().optional(),
836
+ province: zod.z.string().nullable().optional(),
837
+ postalCode: zod.z.string().nullable().optional(),
838
+ district: zod.z.string().nullable().optional(),
839
+ phone: zod.z.string().nullable().optional(),
840
+ latitude: zod.z.number().nullable().optional(),
841
+ longitude: zod.z.number().nullable().optional(),
842
+ geo: zod.z.object({
843
+ departmentCode: zod.z.string().nullable().optional(),
844
+ provinceCode: zod.z.string().nullable().optional(),
845
+ districtCode: zod.z.string().nullable().optional()
846
+ }).nullable().optional()
847
+ });
848
+ var CartAddressesParamsSchema = zod.z.object({
849
+ cartId: zod.z.string().uuid(),
850
+ shippingAddress: CartAddressWriteSchema,
851
+ billingAddress: CartAddressWriteSchema
852
+ });
853
+ var CartPaymentMethodSchema = zod.z.object({
854
+ code: zod.z.string(),
855
+ name: zod.z.string(),
856
+ description: zod.z.string().nullable().optional(),
857
+ kind: zod.z.string(),
858
+ providerMethodCode: zod.z.string().nullable().optional(),
859
+ isActive: zod.z.boolean(),
860
+ isDefault: zod.z.boolean(),
861
+ isManual: zod.z.boolean(),
862
+ sortOrder: zod.z.number(),
863
+ phoneNumber: zod.z.string().nullable().optional(),
864
+ accountHolder: zod.z.string().nullable().optional(),
865
+ qrImageUrl: zod.z.string().nullable().optional()
866
+ });
867
+ var StorefrontOrderBumpSchema = zod.z.object({
868
+ id: zod.z.string(),
869
+ productPublicId: zod.z.coerce.string(),
870
+ variantPublicId: zod.z.coerce.string(),
871
+ productName: zod.z.string(),
872
+ variantName: zod.z.string().nullable().optional(),
873
+ imageUrl: zod.z.string().nullable().optional(),
874
+ currencyCode: zod.z.string(),
875
+ regularPrice: zod.z.number(),
876
+ offerPrice: zod.z.number(),
877
+ badgeLabel: zod.z.string().nullable().optional(),
878
+ callToAction: zod.z.string(),
879
+ description: zod.z.string().nullable().optional()
880
+ });
881
+ var CartCheckoutReadParamsSchema = zod.z.object({
882
+ cartId: zod.z.string().uuid()
883
+ });
884
+ var CartCheckoutReadResponseSchema = zod.z.object({
885
+ cart: StorefrontCartSchema,
886
+ paymentMethods: zod.z.object({
887
+ methods: zod.z.array(CartPaymentMethodSchema)
888
+ }),
889
+ orderBumps: zod.z.array(StorefrontOrderBumpSchema).optional().default([])
890
+ });
891
+ var CartCheckoutPaymentActionSchema = zod.z.object({
892
+ publicConfiguration: zod.z.object({
893
+ publishableKey: zod.z.string().nullable().optional(),
894
+ checkoutMode: zod.z.string().nullable().optional(),
895
+ phoneNumber: zod.z.string().nullable().optional(),
896
+ accountHolder: zod.z.string().nullable().optional(),
897
+ qrImageUrl: zod.z.string().nullable().optional()
898
+ }).passthrough().nullable().optional(),
899
+ url: zod.z.string().nullable().optional(),
900
+ html: zod.z.string().nullable().optional(),
901
+ clientSecret: zod.z.string().nullable().optional(),
902
+ qrCode: zod.z.string().nullable().optional(),
903
+ expiresAt: zod.z.string().nullable().optional()
904
+ }).passthrough();
905
+ var CartCheckoutPaymentSchema = zod.z.object({
906
+ transactionId: zod.z.string(),
907
+ paymentMethodCode: zod.z.string(),
908
+ providerId: zod.z.string().nullable().optional(),
909
+ status: zod.z.string(),
910
+ amount: zod.z.number(),
911
+ reference: zod.z.string(),
912
+ actionType: zod.z.string(),
913
+ receiptUrl: zod.z.string().nullable().optional(),
914
+ action: CartCheckoutPaymentActionSchema.nullable().optional()
915
+ }).passthrough();
916
+ var CartCheckoutResponseSchema = zod.z.object({
917
+ publicKey: zod.z.string().optional(),
918
+ publishableKey: zod.z.string().optional(),
919
+ stripePublicKey: zod.z.string().optional(),
920
+ clientSecret: zod.z.string().optional(),
921
+ intentClientSecret: zod.z.string().optional(),
922
+ orderId: zod.z.coerce.string().optional(),
923
+ orderGroup: zod.z.string().optional(),
924
+ orderIds: zod.z.array(zod.z.coerce.string()).optional(),
925
+ payment: CartCheckoutPaymentSchema.optional(),
926
+ cart: StorefrontCartSchema.optional()
927
+ }).passthrough();
928
+ var CartCheckoutParamsSchema = zod.z.object({
929
+ cartId: zod.z.string().uuid(),
930
+ paymentMethodCode: zod.z.string().min(1),
931
+ externalRef: zod.z.string().min(1),
932
+ receiptUrl: zod.z.string().min(1).optional()
933
+ });
934
+ var ShippingRateSchema = zod.z.object({
935
+ shippingMethodId: zod.z.string(),
936
+ name: zod.z.string(),
937
+ displayName: zod.z.string().optional(),
938
+ type: zod.z.string().optional(),
939
+ price: zod.z.number(),
940
+ currency: zod.z.string().optional(),
941
+ sortOrder: zod.z.number().optional(),
942
+ rateId: zod.z.string(),
943
+ description: zod.z.string().nullable().optional(),
944
+ deliveryLocationId: zod.z.string().nullable().optional(),
945
+ deliveryLocationName: zod.z.string().nullable().optional(),
946
+ estimatedDeliveryDays: zod.z.number().nullable().optional(),
947
+ serviceCode: zod.z.string().nullable().optional(),
948
+ metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
949
+ }).passthrough();
950
+ var ShippingOptionGroupSchema = zod.z.object({
951
+ sellerId: zod.z.string(),
952
+ shippingProfileId: zod.z.string().nullable().optional(),
953
+ orderAmount: zod.z.number().optional(),
954
+ totalWeight: zod.z.number().optional(),
955
+ itemIds: zod.z.array(zod.z.string()).optional(),
956
+ rates: zod.z.array(ShippingRateSchema)
957
+ }).passthrough();
958
+ var ShippingOptionsResponseSchema = zod.z.object({
959
+ groups: zod.z.array(ShippingOptionGroupSchema)
960
+ });
961
+ var GetShippingOptionsParamsSchema = zod.z.object({
962
+ cartId: zod.z.string().uuid(),
963
+ postalCode: zod.z.string().min(1)
964
+ });
965
+ var PutShippingMethodParamsSchema = zod.z.object({
966
+ cartId: zod.z.string().uuid(),
967
+ rateId: zod.z.string().min(1),
968
+ shippingMethodId: zod.z.string().min(1),
969
+ serviceCode: zod.z.string().nullable().optional(),
970
+ sellerId: zod.z.string().nullable().optional(),
971
+ shippingProfileId: zod.z.string().nullable().optional(),
972
+ locationId: zod.z.string().nullable().optional(),
973
+ pickupPointId: zod.z.string().nullable().optional(),
974
+ scheduledDate: zod.z.string().nullable().optional(),
975
+ scheduledTime: zod.z.string().nullable().optional()
976
+ });
977
+ var CartPaymentReceiptResponseSchema = zod.z.object({
978
+ id: zod.z.string(),
979
+ url: zod.z.string()
980
+ });
981
+ var CartPromotionCodeParamsSchema = zod.z.object({
982
+ cartId: zod.z.string().uuid(),
983
+ code: zod.z.string().min(1)
984
+ });
985
+
986
+ // src/services/checkout.service.ts
987
+ async function getCartCheckout(api, params) {
988
+ const input = CartCheckoutReadParamsSchema.parse(params);
989
+ return api.get(
990
+ `carts/${encodeURIComponent(input.cartId)}/checkout`,
991
+ CartCheckoutReadResponseSchema
992
+ );
993
+ }
994
+ async function getShippingOptions(api, params) {
995
+ const input = GetShippingOptionsParamsSchema.parse(params);
996
+ return api.get(
997
+ `carts/${encodeURIComponent(input.cartId)}/shipping-options`,
998
+ ShippingOptionsResponseSchema,
999
+ { query: { postalCode: input.postalCode } }
1000
+ );
1001
+ }
1002
+ async function putCartShippingMethod(api, params) {
1003
+ const input = PutShippingMethodParamsSchema.parse(params);
1004
+ const { cartId, ...body } = input;
1005
+ return api.request(
1006
+ "PUT",
1007
+ `carts/${encodeURIComponent(cartId)}/shipping-method`,
1008
+ StorefrontCartSchema,
1009
+ { body }
1010
+ );
1011
+ }
1012
+ async function patchCartBuyer(api, params) {
1013
+ const input = CartBuyerParamsSchema.parse(params);
1014
+ const { cartId, ...body } = input;
1015
+ return api.request(
1016
+ "PATCH",
1017
+ `carts/${encodeURIComponent(cartId)}/buyer`,
1018
+ StorefrontCartSchema,
1019
+ { body }
1020
+ );
1021
+ }
1022
+ async function patchCartAddresses(api, params) {
1023
+ const input = CartAddressesParamsSchema.parse(params);
1024
+ const { cartId, shippingAddress, billingAddress } = input;
1025
+ return api.request(
1026
+ "PATCH",
1027
+ `carts/${encodeURIComponent(cartId)}/addresses`,
1028
+ StorefrontCartSchema,
1029
+ { body: { shippingAddress, billingAddress } }
1030
+ );
1031
+ }
1032
+ async function checkoutCart(api, params) {
1033
+ const input = CartCheckoutParamsSchema.parse(params);
1034
+ const { cartId, ...body } = input;
1035
+ return api.post(
1036
+ `carts/${encodeURIComponent(cartId)}/checkout`,
1037
+ body,
1038
+ CartCheckoutResponseSchema
1039
+ );
1040
+ }
1041
+ async function uploadPaymentReceipt(api, params) {
1042
+ const cartId = CartCheckoutReadParamsSchema.shape.cartId.parse(params.cartId);
1043
+ if (!(params.file instanceof Blob)) {
1044
+ throw new TypeError("uploadPaymentReceipt requiere un archivo (Blob/File)");
1045
+ }
1046
+ const form = new FormData();
1047
+ const name = params.fileName ?? (params.file instanceof File ? params.file.name : "receipt");
1048
+ form.append("file", params.file, name);
1049
+ return api.postForm(
1050
+ `carts/${encodeURIComponent(cartId)}/payment-receipt`,
1051
+ form,
1052
+ CartPaymentReceiptResponseSchema
1053
+ );
1054
+ }
1055
+ async function addCartPromotionCode(api, params) {
1056
+ const input = CartPromotionCodeParamsSchema.parse(params);
1057
+ return api.post(
1058
+ `carts/${encodeURIComponent(input.cartId)}/promotion-codes`,
1059
+ { code: input.code },
1060
+ StorefrontCartSchema
1061
+ );
1062
+ }
1063
+ async function removeCartPromotionCode(api, params) {
1064
+ const input = CartPromotionCodeParamsSchema.parse(params);
1065
+ return api.request(
1066
+ "DELETE",
1067
+ `carts/${encodeURIComponent(input.cartId)}/promotion-codes/${encodeURIComponent(input.code)}`,
1068
+ StorefrontCartSchema
1069
+ );
1070
+ }
1071
+ var CountrySchema = zod.z.object({
1072
+ code: zod.z.string().length(2),
1073
+ name: zod.z.string().min(1)
1074
+ }).strict();
1075
+ var CountriesSchema = zod.z.array(CountrySchema);
1076
+ var GeoDivisionTypeSchema = zod.z.enum(["level1", "level2", "level3"]);
1077
+ var GeoDivisionSchema = zod.z.object({
1078
+ id: zod.z.string().uuid(),
1079
+ countryCode: zod.z.string().length(2),
1080
+ type: GeoDivisionTypeSchema,
1081
+ code: zod.z.string().min(1),
1082
+ name: zod.z.string().min(1),
1083
+ parentId: zod.z.string().uuid().nullable(),
1084
+ source: zod.z.string().min(1)
1085
+ }).strict();
1086
+ var DepartmentSchema = GeoDivisionSchema;
1087
+ var DepartmentsSchema = zod.z.array(DepartmentSchema);
1088
+ var GetDepartmentsParamsSchema = zod.z.object({
1089
+ countryCode: zod.z.string().length(2),
1090
+ source: zod.z.string().min(1).default("inei"),
1091
+ search: zod.z.string().default(""),
1092
+ limit: zod.z.number().int().positive().max(500).default(200)
1093
+ });
1094
+ var ProvinceSchema = GeoDivisionSchema;
1095
+ var ProvincesSchema = zod.z.array(ProvinceSchema);
1096
+ var GetProvincesParamsSchema = zod.z.object({
1097
+ countryCode: zod.z.string().length(2),
1098
+ departmentCode: zod.z.string().min(1),
1099
+ source: zod.z.string().min(1).default("inei"),
1100
+ search: zod.z.string().default(""),
1101
+ limit: zod.z.number().int().positive().max(500).default(200)
1102
+ });
1103
+ var DistrictSchema = GeoDivisionSchema;
1104
+ var DistrictsSchema = zod.z.array(DistrictSchema);
1105
+ var GetDistrictsParamsSchema = zod.z.object({
1106
+ countryCode: zod.z.string().length(2),
1107
+ provinceCode: zod.z.string().min(1),
1108
+ source: zod.z.string().min(1).default("inei"),
1109
+ search: zod.z.string().default(""),
1110
+ limit: zod.z.number().int().positive().max(500).default(200)
1111
+ });
1112
+
1113
+ // src/services/geo.service.ts
1114
+ async function getCountries(api) {
1115
+ return api.get("geo/countries", CountriesSchema);
1116
+ }
1117
+ async function getDepartments(api, params) {
1118
+ const input = GetDepartmentsParamsSchema.parse(params);
1119
+ return api.get("geo/departments", DepartmentsSchema, {
1120
+ query: {
1121
+ countryCode: input.countryCode,
1122
+ source: input.source,
1123
+ search: input.search,
1124
+ limit: input.limit
1125
+ }
1126
+ });
1127
+ }
1128
+ async function getProvinces(api, params) {
1129
+ const input = GetProvincesParamsSchema.parse(params);
1130
+ return api.get("geo/provinces", ProvincesSchema, {
1131
+ query: {
1132
+ countryCode: input.countryCode,
1133
+ departmentCode: input.departmentCode,
1134
+ source: input.source,
1135
+ search: input.search,
1136
+ limit: input.limit
1137
+ }
1138
+ });
1139
+ }
1140
+ async function getDistricts(api, params) {
1141
+ const input = GetDistrictsParamsSchema.parse(params);
1142
+ return api.get("geo/districts", DistrictsSchema, {
1143
+ query: {
1144
+ countryCode: input.countryCode,
1145
+ provinceCode: input.provinceCode,
1146
+ source: input.source,
1147
+ search: input.search,
1148
+ limit: input.limit
1149
+ }
1150
+ });
1151
+ }
1152
+
1153
+ // src/client.ts
1154
+ var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
1155
+ function createClient(options) {
1156
+ const {
1157
+ slug,
1158
+ settingsCacheTtlMs = DEFAULT_SETTINGS_CACHE_TTL_MS,
1159
+ ...apiOptions
1160
+ } = options;
1161
+ if (!slug?.trim()) {
1162
+ throw new Error("createClient requiere `slug` (config.slug de ecomiq.config.js)");
1163
+ }
1164
+ if (!Number.isFinite(settingsCacheTtlMs) || settingsCacheTtlMs < 0) {
1165
+ throw new Error("settingsCacheTtlMs debe ser un n\xFAmero mayor o igual a 0");
1166
+ }
1167
+ const api = createApi(apiOptions);
1168
+ const apiClient = async () => {
1169
+ const storeId = await getStoreId();
1170
+ return createApi({
1171
+ ...apiOptions,
1172
+ headers: {
1173
+ ...apiOptions.headers,
1174
+ "x-Store-Id": storeId
1175
+ }
1176
+ });
1177
+ };
1178
+ let cache = null;
1179
+ let inflight = null;
1180
+ function clearCache() {
1181
+ cache = null;
1182
+ inflight = null;
1183
+ }
1184
+ async function getSettings() {
1185
+ const now = Date.now();
1186
+ if (cache && cache.expiresAt > now) return cache.data;
1187
+ if (inflight) return inflight;
1188
+ const previous = cache?.data;
1189
+ inflight = api.get("settings", StorefrontSettingsSchema, {
1190
+ headers: { "x-Store-Domain": slug }
1191
+ }).then((data) => {
1192
+ cache = { data, expiresAt: Date.now() + settingsCacheTtlMs };
1193
+ return data;
1194
+ }).catch((error) => {
1195
+ if (previous) return previous;
1196
+ throw error;
1197
+ }).finally(() => {
1198
+ inflight = null;
1199
+ });
1200
+ return inflight;
1201
+ }
1202
+ async function getStoreId() {
1203
+ const settings = await getSettings();
1204
+ return settings.store.id;
1205
+ }
1206
+ async function getCollections2() {
1207
+ const client = await apiClient();
1208
+ return getCollections(client);
1209
+ }
1210
+ async function getCollectionBySlug2(collectionSlug) {
1211
+ const client = await apiClient();
1212
+ return getCollectionBySlug(client, collectionSlug);
1213
+ }
1214
+ async function getProducts2(params = {}) {
1215
+ const client = await apiClient();
1216
+ return getProducts(client, params);
1217
+ }
1218
+ async function getProductBySlug2(productSlug, params = {}) {
1219
+ const client = await apiClient();
1220
+ return getProductBySlug(client, productSlug, params);
1221
+ }
1222
+ async function getRelatedProducts2(params) {
1223
+ const client = await apiClient();
1224
+ return getRelatedProducts(client, params);
1225
+ }
1226
+ async function autocompleteProducts2(params) {
1227
+ const client = await apiClient();
1228
+ return autocompleteProducts(client, params);
1229
+ }
1230
+ async function listProductReviews2(params) {
1231
+ const client = await apiClient();
1232
+ return listProductReviews(client, params);
1233
+ }
1234
+ async function createProductReview2(params) {
1235
+ const client = await apiClient();
1236
+ return createProductReview(client, params);
1237
+ }
1238
+ async function createCart2(params) {
1239
+ const client = await apiClient();
1240
+ return createCart(client, params);
1241
+ }
1242
+ async function getCart2(params) {
1243
+ const client = await apiClient();
1244
+ return getCart(client, params);
1245
+ }
1246
+ async function addCartItem2(params) {
1247
+ const client = await apiClient();
1248
+ return addCartItem(client, params);
1249
+ }
1250
+ async function updateCartItemQuantity2(params) {
1251
+ const client = await apiClient();
1252
+ return updateCartItemQuantity(client, params);
1253
+ }
1254
+ async function removeCartItem2(params) {
1255
+ const client = await apiClient();
1256
+ return removeCartItem(client, params);
1257
+ }
1258
+ async function getCartCheckout2(params) {
1259
+ const client = await apiClient();
1260
+ return getCartCheckout(client, params);
1261
+ }
1262
+ async function getShippingOptions2(params) {
1263
+ const client = await apiClient();
1264
+ return getShippingOptions(client, params);
1265
+ }
1266
+ async function putCartShippingMethod2(params) {
1267
+ const client = await apiClient();
1268
+ return putCartShippingMethod(client, params);
1269
+ }
1270
+ async function patchCartBuyer2(params) {
1271
+ const client = await apiClient();
1272
+ return patchCartBuyer(client, params);
1273
+ }
1274
+ async function patchCartAddresses2(params) {
1275
+ const client = await apiClient();
1276
+ return patchCartAddresses(client, params);
1277
+ }
1278
+ async function checkoutCart2(params) {
1279
+ const client = await apiClient();
1280
+ return checkoutCart(client, params);
1281
+ }
1282
+ async function uploadPaymentReceipt2(params) {
1283
+ const client = await apiClient();
1284
+ return uploadPaymentReceipt(client, params);
1285
+ }
1286
+ async function addCartPromotionCode2(params) {
1287
+ const client = await apiClient();
1288
+ return addCartPromotionCode(client, params);
1289
+ }
1290
+ async function removeCartPromotionCode2(params) {
1291
+ const client = await apiClient();
1292
+ return removeCartPromotionCode(client, params);
1293
+ }
1294
+ async function getCountries2() {
1295
+ return getCountries(api);
1296
+ }
1297
+ async function getDepartments2(params) {
1298
+ return getDepartments(api, params);
1299
+ }
1300
+ async function getProvinces2(params) {
1301
+ return getProvinces(api, params);
1302
+ }
1303
+ async function getDistricts2(params) {
1304
+ return getDistricts(api, params);
1305
+ }
1306
+ return {
1307
+ ...api,
1308
+ getSettings,
1309
+ getStoreId,
1310
+ getCollections: getCollections2,
1311
+ getCollectionBySlug: getCollectionBySlug2,
1312
+ clearCache,
1313
+ getProducts: getProducts2,
1314
+ getProductBySlug: getProductBySlug2,
1315
+ getRelatedProducts: getRelatedProducts2,
1316
+ autocompleteProducts: autocompleteProducts2,
1317
+ listProductReviews: listProductReviews2,
1318
+ createProductReview: createProductReview2,
1319
+ createCart: createCart2,
1320
+ getCart: getCart2,
1321
+ addCartItem: addCartItem2,
1322
+ updateCartItemQuantity: updateCartItemQuantity2,
1323
+ removeCartItem: removeCartItem2,
1324
+ getCartCheckout: getCartCheckout2,
1325
+ getShippingOptions: getShippingOptions2,
1326
+ putCartShippingMethod: putCartShippingMethod2,
1327
+ patchCartBuyer: patchCartBuyer2,
1328
+ patchCartAddresses: patchCartAddresses2,
1329
+ checkoutCart: checkoutCart2,
1330
+ uploadPaymentReceipt: uploadPaymentReceipt2,
1331
+ addCartPromotionCode: addCartPromotionCode2,
1332
+ removeCartPromotionCode: removeCartPromotionCode2,
1333
+ getCountries: getCountries2,
1334
+ getDepartments: getDepartments2,
1335
+ getProvinces: getProvinces2,
1336
+ getDistricts: getDistricts2
1337
+ };
1338
+ }
1339
+ var createStorefrontClient = createClient;
1340
+
1341
+ exports.createClient = createClient;
1342
+ exports.createStorefrontClient = createStorefrontClient;
1343
+ //# sourceMappingURL=client.cjs.map
1344
+ //# sourceMappingURL=client.cjs.map