@ecomiq/core 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.cjs +19 -5
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +19 -5
- package/dist/api.js.map +1 -1
- package/dist/client-4ZTG2RZ3.d.ts +195 -0
- package/dist/client-BpX4yR6S.d.cts +195 -0
- package/dist/client.cjs +320 -6
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +13 -84
- package/dist/client.d.ts +13 -84
- package/dist/client.js +320 -6
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +471 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +326 -323
- package/dist/index.d.ts +326 -323
- package/dist/index.js +440 -7
- package/dist/index.js.map +1 -1
- package/dist/models/collections.d.cts +4 -4
- package/dist/models/collections.d.ts +4 -4
- package/dist/models/customer-address.cjs +41 -0
- package/dist/models/customer-address.cjs.map +1 -0
- package/dist/models/customer-address.d.cts +160 -0
- package/dist/models/customer-address.d.ts +160 -0
- package/dist/models/customer-address.js +36 -0
- package/dist/models/customer-address.js.map +1 -0
- package/dist/models/customer-order.cjs +161 -0
- package/dist/models/customer-order.cjs.map +1 -0
- package/dist/models/customer-order.d.cts +896 -0
- package/dist/models/customer-order.d.ts +896 -0
- package/dist/models/customer-order.js +149 -0
- package/dist/models/customer-order.js.map +1 -0
- package/dist/models/customer-profile.cjs +126 -0
- package/dist/models/customer-profile.cjs.map +1 -0
- package/dist/models/customer-profile.d.cts +178 -0
- package/dist/models/customer-profile.d.ts +178 -0
- package/dist/models/customer-profile.js +118 -0
- package/dist/models/customer-profile.js.map +1 -0
- package/dist/models/geo.d.cts +14 -14
- package/dist/models/geo.d.ts +14 -14
- package/dist/models/products.d.cts +130 -130
- package/dist/models/products.d.ts +130 -130
- package/dist/models/search.d.cts +4 -4
- package/dist/models/search.d.ts +4 -4
- package/dist/models/settings.d.cts +798 -798
- package/dist/models/settings.d.ts +798 -798
- package/dist/models/storefront-cart.d.cts +80 -80
- package/dist/models/storefront-cart.d.ts +80 -80
- package/dist/models/storefront-checkout.d.cts +400 -400
- package/dist/models/storefront-checkout.d.ts +400 -400
- package/dist/models/storefront-reviews.d.cts +8 -8
- package/dist/models/storefront-reviews.d.ts +8 -8
- package/package.json +16 -1
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ var ApiError = class extends Error {
|
|
|
19
19
|
function resolveApiBaseUrl(baseUrl = DEFAULT_API_BASE_URL, version = DEFAULT_API_VERSION) {
|
|
20
20
|
const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
21
21
|
const segment = version.replace(/^\/+|\/+$/g, "");
|
|
22
|
+
if (!segment) return root;
|
|
22
23
|
return new URL(`${segment}/`, root).toString();
|
|
23
24
|
}
|
|
24
25
|
function createApi(options = {}) {
|
|
@@ -61,17 +62,30 @@ function createApi(options = {}) {
|
|
|
61
62
|
clearTimeout(timeout);
|
|
62
63
|
}
|
|
63
64
|
if (!response.ok) {
|
|
64
|
-
const
|
|
65
|
-
let body =
|
|
66
|
-
if (
|
|
65
|
+
const bodyText2 = await response.text().catch(() => void 0);
|
|
66
|
+
let body = bodyText2;
|
|
67
|
+
if (bodyText2) {
|
|
67
68
|
try {
|
|
68
|
-
body = JSON.parse(
|
|
69
|
+
body = JSON.parse(bodyText2);
|
|
69
70
|
} catch {
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
throw new ApiError(`${method} ${url} \u2192 ${response.status}`, response.status, url.toString(), body);
|
|
73
74
|
}
|
|
74
|
-
const
|
|
75
|
+
const bodyText = await response.text();
|
|
76
|
+
let json = null;
|
|
77
|
+
if (bodyText.trim()) {
|
|
78
|
+
try {
|
|
79
|
+
json = JSON.parse(bodyText);
|
|
80
|
+
} catch {
|
|
81
|
+
throw new ApiError(
|
|
82
|
+
`Respuesta no JSON de ${url}`,
|
|
83
|
+
response.status,
|
|
84
|
+
url.toString(),
|
|
85
|
+
bodyText
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
75
89
|
const parsed = schema.safeParse(json);
|
|
76
90
|
if (!parsed.success) {
|
|
77
91
|
throw new ApiError(
|
|
@@ -1187,6 +1201,385 @@ async function getDistricts(api, params) {
|
|
|
1187
1201
|
}
|
|
1188
1202
|
});
|
|
1189
1203
|
}
|
|
1204
|
+
var CustomerAddressUpsertInputSchema = z.object({
|
|
1205
|
+
addressKey: z.string().trim().min(1),
|
|
1206
|
+
countryIsoCode: z.string().trim().length(2),
|
|
1207
|
+
addressLine: z.string().trim().min(1),
|
|
1208
|
+
addressNumber: z.string().trim().min(1),
|
|
1209
|
+
department: z.string().trim().min(1),
|
|
1210
|
+
province: z.string().trim().min(1),
|
|
1211
|
+
district: z.string().trim().min(1),
|
|
1212
|
+
phone: z.string().trim(),
|
|
1213
|
+
cellPhone: z.string().trim(),
|
|
1214
|
+
postalCode: z.string().trim().min(1),
|
|
1215
|
+
reference: z.string().trim(),
|
|
1216
|
+
latitude: z.number().nullable(),
|
|
1217
|
+
longitude: z.number().nullable(),
|
|
1218
|
+
isDefault: z.boolean()
|
|
1219
|
+
});
|
|
1220
|
+
var CustomerAddressSchema = CustomerAddressUpsertInputSchema.extend({
|
|
1221
|
+
id: z.union([z.string(), z.number()]).transform(String).optional()
|
|
1222
|
+
});
|
|
1223
|
+
var CustomerAddressesSchema = z.array(CustomerAddressSchema);
|
|
1224
|
+
function toCustomerSavedAddresses(addresses) {
|
|
1225
|
+
const saved = [];
|
|
1226
|
+
for (const address of addresses) {
|
|
1227
|
+
if (!address.id?.trim()) continue;
|
|
1228
|
+
const { id, ...rest } = address;
|
|
1229
|
+
saved.push({ id: id.trim(), ...rest });
|
|
1230
|
+
}
|
|
1231
|
+
return saved;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// src/services/customer-address.service.ts
|
|
1235
|
+
var ADDRESSES_PATH = "customer/addresses";
|
|
1236
|
+
var CustomerAddressMutationResponseSchema = z.union([
|
|
1237
|
+
CustomerAddressSchema,
|
|
1238
|
+
z.object({
|
|
1239
|
+
id: z.union([z.string(), z.number()]).transform(String)
|
|
1240
|
+
}),
|
|
1241
|
+
z.null()
|
|
1242
|
+
]);
|
|
1243
|
+
async function getCustomerAddresses(api, options = {}) {
|
|
1244
|
+
return api.get(ADDRESSES_PATH, CustomerAddressesSchema, {
|
|
1245
|
+
headers: options.headers,
|
|
1246
|
+
signal: options.signal
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
async function createCustomerAddress(api, data, options = {}) {
|
|
1250
|
+
const payload = CustomerAddressUpsertInputSchema.parse(data);
|
|
1251
|
+
return api.post(ADDRESSES_PATH, payload, CustomerAddressMutationResponseSchema, {
|
|
1252
|
+
headers: options.headers,
|
|
1253
|
+
signal: options.signal
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
async function updateCustomerAddress(api, addressId, data, options = {}) {
|
|
1257
|
+
const id = addressId.trim();
|
|
1258
|
+
if (!id) throw new Error("addressId requerido");
|
|
1259
|
+
const payload = CustomerAddressUpsertInputSchema.parse(data);
|
|
1260
|
+
return api.request(
|
|
1261
|
+
"PUT",
|
|
1262
|
+
`${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
|
|
1263
|
+
CustomerAddressMutationResponseSchema,
|
|
1264
|
+
{
|
|
1265
|
+
body: payload,
|
|
1266
|
+
headers: options.headers,
|
|
1267
|
+
signal: options.signal
|
|
1268
|
+
}
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
async function deleteCustomerAddress(api, addressId, options = {}) {
|
|
1272
|
+
const id = addressId.trim();
|
|
1273
|
+
if (!id) throw new Error("addressId requerido");
|
|
1274
|
+
await api.request(
|
|
1275
|
+
"DELETE",
|
|
1276
|
+
`${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
|
|
1277
|
+
z.null(),
|
|
1278
|
+
{
|
|
1279
|
+
headers: options.headers,
|
|
1280
|
+
signal: options.signal
|
|
1281
|
+
}
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
var DEFAULT_COUNTRY_CODE = "PE";
|
|
1285
|
+
var CustomerRegisterRequestSchema = z.object({
|
|
1286
|
+
email: z.string().email(),
|
|
1287
|
+
firstName: z.string().trim().min(1),
|
|
1288
|
+
lastName: z.string().trim().min(1),
|
|
1289
|
+
countryIsoCode: z.string().trim().length(2),
|
|
1290
|
+
password: z.string().min(1),
|
|
1291
|
+
phone: z.string().trim().min(1).optional()
|
|
1292
|
+
});
|
|
1293
|
+
var CustomerProfilePatchSchema = z.object({
|
|
1294
|
+
firstName: z.string().trim().min(1),
|
|
1295
|
+
lastName: z.string().trim().min(1),
|
|
1296
|
+
phone: z.string().trim(),
|
|
1297
|
+
identificationNumber: z.string().nullable(),
|
|
1298
|
+
identificationType: z.string().nullable(),
|
|
1299
|
+
entityName: z.string().nullable(),
|
|
1300
|
+
entityIdentificationNumber: z.string().nullable(),
|
|
1301
|
+
gender: z.string().nullable(),
|
|
1302
|
+
role: z.string().nullable(),
|
|
1303
|
+
companyName: z.string().nullable(),
|
|
1304
|
+
dateOfBirth: z.string().nullable(),
|
|
1305
|
+
consent: z.boolean(),
|
|
1306
|
+
countryIsoCode: z.string().trim().length(2)
|
|
1307
|
+
});
|
|
1308
|
+
var CustomerProfileSchema = z.object({
|
|
1309
|
+
firstName: z.string(),
|
|
1310
|
+
lastName: z.string(),
|
|
1311
|
+
phone: z.string(),
|
|
1312
|
+
email: z.string().email(),
|
|
1313
|
+
identificationNumber: z.string().nullable(),
|
|
1314
|
+
identificationType: z.string().nullable(),
|
|
1315
|
+
countryIsoCode: z.string(),
|
|
1316
|
+
consent: z.boolean(),
|
|
1317
|
+
entityName: z.string().nullable(),
|
|
1318
|
+
entityIdentificationNumber: z.string().nullable(),
|
|
1319
|
+
gender: z.string().nullable(),
|
|
1320
|
+
role: z.string().nullable(),
|
|
1321
|
+
companyName: z.string().nullable(),
|
|
1322
|
+
dateOfBirth: z.string().nullable()
|
|
1323
|
+
});
|
|
1324
|
+
var nullableString = z.string().nullable().optional().transform((v) => v ?? null);
|
|
1325
|
+
var CustomerMeSchema = z.object({
|
|
1326
|
+
id: z.union([z.string(), z.number()]),
|
|
1327
|
+
storeId: z.string().optional(),
|
|
1328
|
+
email: z.string().email(),
|
|
1329
|
+
firstName: z.string(),
|
|
1330
|
+
lastName: z.string(),
|
|
1331
|
+
phone: z.union([z.string(), z.null()]).optional().transform((v) => v ?? ""),
|
|
1332
|
+
identificationNumber: nullableString,
|
|
1333
|
+
identificationType: nullableString,
|
|
1334
|
+
entityName: nullableString,
|
|
1335
|
+
entityIdentificationNumber: nullableString,
|
|
1336
|
+
gender: nullableString,
|
|
1337
|
+
role: nullableString,
|
|
1338
|
+
companyName: nullableString,
|
|
1339
|
+
dateOfBirth: nullableString,
|
|
1340
|
+
countryIsoCode: z.string().optional().transform((v) => v?.trim().length === 2 ? v.trim() : DEFAULT_COUNTRY_CODE),
|
|
1341
|
+
consent: z.boolean().optional().transform((v) => v ?? false)
|
|
1342
|
+
}).passthrough();
|
|
1343
|
+
function customerMeToProfile(me) {
|
|
1344
|
+
return CustomerProfileSchema.parse({
|
|
1345
|
+
firstName: me.firstName,
|
|
1346
|
+
lastName: me.lastName,
|
|
1347
|
+
phone: me.phone,
|
|
1348
|
+
email: me.email,
|
|
1349
|
+
identificationNumber: me.identificationNumber,
|
|
1350
|
+
identificationType: me.identificationType,
|
|
1351
|
+
countryIsoCode: me.countryIsoCode,
|
|
1352
|
+
consent: me.consent,
|
|
1353
|
+
entityName: me.entityName,
|
|
1354
|
+
entityIdentificationNumber: me.entityIdentificationNumber,
|
|
1355
|
+
gender: me.gender,
|
|
1356
|
+
role: me.role,
|
|
1357
|
+
companyName: me.companyName,
|
|
1358
|
+
dateOfBirth: me.dateOfBirth
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
function customerMeToProfilePatch(me) {
|
|
1362
|
+
return CustomerProfilePatchSchema.parse({
|
|
1363
|
+
firstName: me.firstName,
|
|
1364
|
+
lastName: me.lastName,
|
|
1365
|
+
phone: me.phone,
|
|
1366
|
+
identificationNumber: me.identificationNumber,
|
|
1367
|
+
identificationType: me.identificationType,
|
|
1368
|
+
entityName: me.entityName,
|
|
1369
|
+
entityIdentificationNumber: me.entityIdentificationNumber,
|
|
1370
|
+
gender: me.gender,
|
|
1371
|
+
role: me.role,
|
|
1372
|
+
companyName: me.companyName,
|
|
1373
|
+
dateOfBirth: me.dateOfBirth,
|
|
1374
|
+
consent: me.consent,
|
|
1375
|
+
countryIsoCode: me.countryIsoCode || DEFAULT_COUNTRY_CODE
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
function customerProfileToPatch(profile) {
|
|
1379
|
+
return CustomerProfilePatchSchema.parse({
|
|
1380
|
+
firstName: profile.firstName,
|
|
1381
|
+
lastName: profile.lastName,
|
|
1382
|
+
phone: profile.phone,
|
|
1383
|
+
identificationNumber: profile.identificationNumber,
|
|
1384
|
+
identificationType: profile.identificationType,
|
|
1385
|
+
entityName: profile.entityName,
|
|
1386
|
+
entityIdentificationNumber: profile.entityIdentificationNumber,
|
|
1387
|
+
gender: profile.gender,
|
|
1388
|
+
role: profile.role,
|
|
1389
|
+
companyName: profile.companyName,
|
|
1390
|
+
dateOfBirth: profile.dateOfBirth,
|
|
1391
|
+
consent: profile.consent,
|
|
1392
|
+
countryIsoCode: profile.countryIsoCode || DEFAULT_COUNTRY_CODE
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// src/services/customer.service.ts
|
|
1397
|
+
var CUSTOMER_PATH = "customer";
|
|
1398
|
+
var CUSTOMER_REGISTER_PATH = "customer/register";
|
|
1399
|
+
async function registerCustomer(api, data, options = {}) {
|
|
1400
|
+
const payload = CustomerRegisterRequestSchema.parse(data);
|
|
1401
|
+
return api.post(CUSTOMER_REGISTER_PATH, payload, z.unknown(), {
|
|
1402
|
+
headers: options.headers,
|
|
1403
|
+
signal: options.signal
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
async function getCustomerMe(api, options = {}) {
|
|
1407
|
+
return api.get(CUSTOMER_PATH, CustomerMeSchema, {
|
|
1408
|
+
headers: options.headers,
|
|
1409
|
+
signal: options.signal
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
async function patchCustomer(api, data, options = {}) {
|
|
1413
|
+
const payload = CustomerProfilePatchSchema.parse(data);
|
|
1414
|
+
await api.request("PATCH", CUSTOMER_PATH, z.null(), {
|
|
1415
|
+
body: payload,
|
|
1416
|
+
headers: options.headers,
|
|
1417
|
+
signal: options.signal
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
var CustomerOrderShippingAddressSchema = z.object({
|
|
1421
|
+
name: z.string().nullable().optional(),
|
|
1422
|
+
company: z.string().nullable().optional(),
|
|
1423
|
+
address1: z.string(),
|
|
1424
|
+
address2: z.string().nullable().optional(),
|
|
1425
|
+
city: z.string().nullable().optional(),
|
|
1426
|
+
countryCode: z.string().min(2).max(2),
|
|
1427
|
+
province: z.string().nullable().optional(),
|
|
1428
|
+
postalCode: z.string().nullable().optional(),
|
|
1429
|
+
district: z.string().nullable().optional(),
|
|
1430
|
+
phone: z.string().nullable().optional(),
|
|
1431
|
+
latitude: z.number().nullable().optional(),
|
|
1432
|
+
longitude: z.number().nullable().optional(),
|
|
1433
|
+
metadata: z.record(z.unknown()).nullable().optional()
|
|
1434
|
+
}).passthrough();
|
|
1435
|
+
var CustomerOrderLineItemSchema = z.object({
|
|
1436
|
+
id: z.string(),
|
|
1437
|
+
orderId: z.coerce.string(),
|
|
1438
|
+
productId: z.coerce.string().nullable(),
|
|
1439
|
+
variantId: z.coerce.string().nullable(),
|
|
1440
|
+
title: z.string(),
|
|
1441
|
+
subtitle: z.string().nullable().optional(),
|
|
1442
|
+
thumbnail: z.string().nullable().optional(),
|
|
1443
|
+
variantTitle: z.string().nullable().optional(),
|
|
1444
|
+
productHandle: z.string().nullable().optional(),
|
|
1445
|
+
quantity: z.number(),
|
|
1446
|
+
unitPrice: z.number(),
|
|
1447
|
+
total: z.number(),
|
|
1448
|
+
status: z.string()
|
|
1449
|
+
});
|
|
1450
|
+
var CustomerOrderListItemSchema = z.object({
|
|
1451
|
+
orderId: z.coerce.string(),
|
|
1452
|
+
orderNumber: z.string(),
|
|
1453
|
+
orderGroup: z.string(),
|
|
1454
|
+
orderIds: z.array(z.coerce.string()),
|
|
1455
|
+
status: z.string(),
|
|
1456
|
+
total: z.number(),
|
|
1457
|
+
totalPaid: z.number(),
|
|
1458
|
+
currencyCode: z.string(),
|
|
1459
|
+
orderDate: z.string(),
|
|
1460
|
+
createdOn: z.string(),
|
|
1461
|
+
updatedOn: z.string().nullable().optional(),
|
|
1462
|
+
paymentAt: z.string().nullable().optional(),
|
|
1463
|
+
shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1464
|
+
shippingAddressSummary: z.string().nullable().optional(),
|
|
1465
|
+
items: z.array(CustomerOrderLineItemSchema)
|
|
1466
|
+
});
|
|
1467
|
+
var CustomerOrderListSchema = z.array(CustomerOrderListItemSchema);
|
|
1468
|
+
var CustomerOrderPaymentSchema = z.object({
|
|
1469
|
+
id: z.string(),
|
|
1470
|
+
paymentMethod: z.string(),
|
|
1471
|
+
paymentCode: z.string(),
|
|
1472
|
+
amount: z.number(),
|
|
1473
|
+
paymentStatus: z.string(),
|
|
1474
|
+
receiptUrl: z.string().nullable().optional(),
|
|
1475
|
+
createdOn: z.string()
|
|
1476
|
+
});
|
|
1477
|
+
var CustomerOrderStatusTimelineSchema = z.object({
|
|
1478
|
+
key: z.string(),
|
|
1479
|
+
label: z.string(),
|
|
1480
|
+
occurredAt: z.string(),
|
|
1481
|
+
description: z.string().nullable().optional(),
|
|
1482
|
+
status: z.string(),
|
|
1483
|
+
source: z.string()
|
|
1484
|
+
});
|
|
1485
|
+
var CustomerOrderDetailSchema = z.object({
|
|
1486
|
+
id: z.coerce.string(),
|
|
1487
|
+
orderNumber: z.string(),
|
|
1488
|
+
orderGroup: z.string(),
|
|
1489
|
+
status: z.string(),
|
|
1490
|
+
total: z.number(),
|
|
1491
|
+
totalPaid: z.number(),
|
|
1492
|
+
currencyCode: z.string(),
|
|
1493
|
+
orderDate: z.string(),
|
|
1494
|
+
createdOn: z.string(),
|
|
1495
|
+
updatedOn: z.string().nullable().optional(),
|
|
1496
|
+
paymentAt: z.string().nullable().optional(),
|
|
1497
|
+
subTotal: z.number(),
|
|
1498
|
+
discount: z.number(),
|
|
1499
|
+
shipping: z.number(),
|
|
1500
|
+
tax: z.number(),
|
|
1501
|
+
email: z.string(),
|
|
1502
|
+
phone: z.string(),
|
|
1503
|
+
firstName: z.string(),
|
|
1504
|
+
lastName: z.string(),
|
|
1505
|
+
shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1506
|
+
shippingAddressSummary: z.string().nullable().optional(),
|
|
1507
|
+
billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1508
|
+
items: z.array(CustomerOrderLineItemSchema),
|
|
1509
|
+
payments: z.array(CustomerOrderPaymentSchema),
|
|
1510
|
+
statusTimeline: z.array(CustomerOrderStatusTimelineSchema)
|
|
1511
|
+
});
|
|
1512
|
+
var ORDER_STATUS_LABELS = {
|
|
1513
|
+
New: "Pedido realizado",
|
|
1514
|
+
Confirmed: "Confirmado",
|
|
1515
|
+
Processing: "En preparaci\xF3n",
|
|
1516
|
+
InTransit: "En camino",
|
|
1517
|
+
Delivered: "Entregado",
|
|
1518
|
+
Cancelled: "Cancelado",
|
|
1519
|
+
Canceled: "Cancelado",
|
|
1520
|
+
Refunded: "Reembolsado",
|
|
1521
|
+
Pending: "Pendiente",
|
|
1522
|
+
PendingToConfirm: "Pendiente de confirmaci\xF3n",
|
|
1523
|
+
Paid: "Pagado",
|
|
1524
|
+
Captured: "Pago confirmado"
|
|
1525
|
+
};
|
|
1526
|
+
function formatCustomerOrderStatus(status) {
|
|
1527
|
+
const trimmed = status.trim();
|
|
1528
|
+
if (!trimmed) return "Desconocido";
|
|
1529
|
+
return ORDER_STATUS_LABELS[trimmed] ?? trimmed.replace(/([A-Z])/g, " $1").trim();
|
|
1530
|
+
}
|
|
1531
|
+
function customerOrderStatusTone(status) {
|
|
1532
|
+
const s = status.toLowerCase();
|
|
1533
|
+
if (s.includes("cancel") || s.includes("refund")) return "danger";
|
|
1534
|
+
if (s.includes("deliver")) return "success";
|
|
1535
|
+
if (s.includes("transit") || s.includes("ship")) return "info";
|
|
1536
|
+
if (s.includes("confirm") || s.includes("paid") || s.includes("capture"))
|
|
1537
|
+
return "success";
|
|
1538
|
+
if (s.includes("pending") || s.includes("new") || s.includes("process"))
|
|
1539
|
+
return "warning";
|
|
1540
|
+
return "default";
|
|
1541
|
+
}
|
|
1542
|
+
function formatOrderDate(iso, locale = "es-PE") {
|
|
1543
|
+
const d = new Date(iso);
|
|
1544
|
+
if (Number.isNaN(d.getTime())) return iso;
|
|
1545
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1546
|
+
day: "numeric",
|
|
1547
|
+
month: "long",
|
|
1548
|
+
year: "numeric"
|
|
1549
|
+
}).format(d);
|
|
1550
|
+
}
|
|
1551
|
+
function formatOrderDateTime(iso, locale = "es-PE") {
|
|
1552
|
+
const d = new Date(iso);
|
|
1553
|
+
if (Number.isNaN(d.getTime())) return iso;
|
|
1554
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1555
|
+
day: "numeric",
|
|
1556
|
+
month: "short",
|
|
1557
|
+
year: "numeric",
|
|
1558
|
+
hour: "2-digit",
|
|
1559
|
+
minute: "2-digit"
|
|
1560
|
+
}).format(d);
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
// src/services/customer-order.service.ts
|
|
1564
|
+
var ORDERS_PATH = "customer/orders";
|
|
1565
|
+
async function getCustomerOrders(api, options = {}) {
|
|
1566
|
+
return api.get(ORDERS_PATH, CustomerOrderListSchema, {
|
|
1567
|
+
headers: options.headers,
|
|
1568
|
+
signal: options.signal
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
async function getCustomerOrder(api, orderId, options = {}) {
|
|
1572
|
+
const id = orderId.trim();
|
|
1573
|
+
if (!id) throw new Error("orderId requerido");
|
|
1574
|
+
return api.get(
|
|
1575
|
+
`${ORDERS_PATH}/${encodeURIComponent(id)}`,
|
|
1576
|
+
CustomerOrderDetailSchema,
|
|
1577
|
+
{
|
|
1578
|
+
headers: options.headers,
|
|
1579
|
+
signal: options.signal
|
|
1580
|
+
}
|
|
1581
|
+
);
|
|
1582
|
+
}
|
|
1190
1583
|
|
|
1191
1584
|
// src/client.ts
|
|
1192
1585
|
var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
|
|
@@ -1345,6 +1738,38 @@ function createClient(options) {
|
|
|
1345
1738
|
async function getDistricts2(params) {
|
|
1346
1739
|
return getDistricts(api, params);
|
|
1347
1740
|
}
|
|
1741
|
+
async function getCustomerAddresses2(options2 = {}) {
|
|
1742
|
+
const client = await apiClient();
|
|
1743
|
+
return getCustomerAddresses(client, options2);
|
|
1744
|
+
}
|
|
1745
|
+
async function createCustomerAddress2(data, options2 = {}) {
|
|
1746
|
+
const client = await apiClient();
|
|
1747
|
+
return createCustomerAddress(client, data, options2);
|
|
1748
|
+
}
|
|
1749
|
+
async function updateCustomerAddress2(addressId, data, options2 = {}) {
|
|
1750
|
+
const client = await apiClient();
|
|
1751
|
+
return updateCustomerAddress(client, addressId, data, options2);
|
|
1752
|
+
}
|
|
1753
|
+
async function deleteCustomerAddress2(addressId, options2 = {}) {
|
|
1754
|
+
const client = await apiClient();
|
|
1755
|
+
return deleteCustomerAddress(client, addressId, options2);
|
|
1756
|
+
}
|
|
1757
|
+
async function getCustomerMe2(options2 = {}) {
|
|
1758
|
+
const client = await apiClient();
|
|
1759
|
+
return getCustomerMe(client, options2);
|
|
1760
|
+
}
|
|
1761
|
+
async function patchCustomer2(data, options2 = {}) {
|
|
1762
|
+
const client = await apiClient();
|
|
1763
|
+
return patchCustomer(client, data, options2);
|
|
1764
|
+
}
|
|
1765
|
+
async function getCustomerOrders2(options2 = {}) {
|
|
1766
|
+
const client = await apiClient();
|
|
1767
|
+
return getCustomerOrders(client, options2);
|
|
1768
|
+
}
|
|
1769
|
+
async function getCustomerOrder2(orderId, options2 = {}) {
|
|
1770
|
+
const client = await apiClient();
|
|
1771
|
+
return getCustomerOrder(client, orderId, options2);
|
|
1772
|
+
}
|
|
1348
1773
|
return {
|
|
1349
1774
|
...api,
|
|
1350
1775
|
getSettings,
|
|
@@ -1376,7 +1801,15 @@ function createClient(options) {
|
|
|
1376
1801
|
getCountries: getCountries2,
|
|
1377
1802
|
getDepartments: getDepartments2,
|
|
1378
1803
|
getProvinces: getProvinces2,
|
|
1379
|
-
getDistricts: getDistricts2
|
|
1804
|
+
getDistricts: getDistricts2,
|
|
1805
|
+
getCustomerAddresses: getCustomerAddresses2,
|
|
1806
|
+
createCustomerAddress: createCustomerAddress2,
|
|
1807
|
+
updateCustomerAddress: updateCustomerAddress2,
|
|
1808
|
+
deleteCustomerAddress: deleteCustomerAddress2,
|
|
1809
|
+
getCustomerMe: getCustomerMe2,
|
|
1810
|
+
patchCustomer: patchCustomer2,
|
|
1811
|
+
getCustomerOrders: getCustomerOrders2,
|
|
1812
|
+
getCustomerOrder: getCustomerOrder2
|
|
1380
1813
|
};
|
|
1381
1814
|
}
|
|
1382
1815
|
var createStorefrontClient = createClient;
|
|
@@ -1455,6 +1888,6 @@ function stripHtml(html) {
|
|
|
1455
1888
|
return html.replace(/<br\s*\/?>/gi, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
1456
1889
|
}
|
|
1457
1890
|
|
|
1458
|
-
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, getPageBySlug, getProductBySlug, getProducts, getProvinces, getRelatedProducts, getShippingOptions, listProductReviews, patchCartAddresses, patchCartBuyer, putCartShippingMethod, removeCartItem, removeCartPromotionCode, resolveApiBaseUrl, sanitizeHtml, stripHtml, updateCartItemQuantity, uploadPaymentReceipt };
|
|
1891
|
+
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, CustomerAddressMutationResponseSchema, CustomerAddressSchema, CustomerAddressUpsertInputSchema, CustomerAddressesSchema, CustomerMeSchema, CustomerOrderDetailSchema, CustomerOrderLineItemSchema, CustomerOrderListItemSchema, CustomerOrderListSchema, CustomerOrderPaymentSchema, CustomerOrderShippingAddressSchema, CustomerOrderStatusTimelineSchema, CustomerProfilePatchSchema, CustomerProfileSchema, CustomerRegisterRequestSchema, 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, createCustomerAddress, createProductReview, createStorefrontClient, customerMeToProfile, customerMeToProfilePatch, customerOrderStatusTone, customerProfileToPatch, deleteCustomerAddress, formatCustomerOrderStatus, formatOrderDate, formatOrderDateTime, getCart, getCartCheckout, getCountries, getCustomerAddresses, getCustomerMe, getCustomerOrder, getCustomerOrders, getDepartments, getDistricts, getMenuItems, getPageBySlug, getProductBySlug, getProducts, getProvinces, getRelatedProducts, getShippingOptions, listProductReviews, patchCartAddresses, patchCartBuyer, patchCustomer, putCartShippingMethod, registerCustomer, removeCartItem, removeCartPromotionCode, resolveApiBaseUrl, sanitizeHtml, stripHtml, toCustomerSavedAddresses, updateCartItemQuantity, updateCustomerAddress, uploadPaymentReceipt };
|
|
1459
1892
|
//# sourceMappingURL=index.js.map
|
|
1460
1893
|
//# sourceMappingURL=index.js.map
|