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