@ecomiq/core 0.1.3 → 0.1.6
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 +331 -12
- 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 +331 -12
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +484 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +327 -324
- package/dist/index.d.ts +327 -324
- package/dist/index.js +451 -13
- 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.cjs +13 -6
- package/dist/models/settings.cjs.map +1 -1
- package/dist/models/settings.d.cts +844 -841
- package/dist/models/settings.d.ts +844 -841
- package/dist/models/settings.js +12 -7
- package/dist/models/settings.js.map +1 -1
- 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.cjs
CHANGED
|
@@ -25,6 +25,7 @@ var ApiError = class extends Error {
|
|
|
25
25
|
function resolveApiBaseUrl(baseUrl = DEFAULT_API_BASE_URL, version = DEFAULT_API_VERSION) {
|
|
26
26
|
const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
27
27
|
const segment = version.replace(/^\/+|\/+$/g, "");
|
|
28
|
+
if (!segment) return root;
|
|
28
29
|
return new URL(`${segment}/`, root).toString();
|
|
29
30
|
}
|
|
30
31
|
function createApi(options = {}) {
|
|
@@ -67,17 +68,30 @@ function createApi(options = {}) {
|
|
|
67
68
|
clearTimeout(timeout);
|
|
68
69
|
}
|
|
69
70
|
if (!response.ok) {
|
|
70
|
-
const
|
|
71
|
-
let body =
|
|
72
|
-
if (
|
|
71
|
+
const bodyText2 = await response.text().catch(() => void 0);
|
|
72
|
+
let body = bodyText2;
|
|
73
|
+
if (bodyText2) {
|
|
73
74
|
try {
|
|
74
|
-
body = JSON.parse(
|
|
75
|
+
body = JSON.parse(bodyText2);
|
|
75
76
|
} catch {
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
throw new ApiError(`${method} ${url} \u2192 ${response.status}`, response.status, url.toString(), body);
|
|
79
80
|
}
|
|
80
|
-
const
|
|
81
|
+
const bodyText = await response.text();
|
|
82
|
+
let json = null;
|
|
83
|
+
if (bodyText.trim()) {
|
|
84
|
+
try {
|
|
85
|
+
json = JSON.parse(bodyText);
|
|
86
|
+
} catch {
|
|
87
|
+
throw new ApiError(
|
|
88
|
+
`Respuesta no JSON de ${url}`,
|
|
89
|
+
response.status,
|
|
90
|
+
url.toString(),
|
|
91
|
+
bodyText
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
81
95
|
const parsed = schema.safeParse(json);
|
|
82
96
|
if (!parsed.success) {
|
|
83
97
|
throw new ApiError(
|
|
@@ -299,6 +313,11 @@ var JsonElementSchema = zod.z.lazy(
|
|
|
299
313
|
var DateTimeOffsetSchema = zod.z.string().datetime({ offset: true });
|
|
300
314
|
var NullableDateTimeOffsetSchema = DateTimeOffsetSchema.nullable();
|
|
301
315
|
var NullableUuidSchema = zod.z.string().uuid().nullable();
|
|
316
|
+
var EntityIdSchema = zod.z.union([
|
|
317
|
+
zod.z.string().uuid(),
|
|
318
|
+
zod.z.string().regex(/^\d+$/, "Expected numeric id")
|
|
319
|
+
]);
|
|
320
|
+
var NullableEntityIdSchema = EntityIdSchema.nullable();
|
|
302
321
|
var StoreTypeSchema = zod.z.enum([
|
|
303
322
|
"b2C",
|
|
304
323
|
"marketplace",
|
|
@@ -361,9 +380,9 @@ var StoreCheckoutSettingsSchema = zod.z.object({
|
|
|
361
380
|
ordersAndPayments: StoreCheckoutOrdersAndPaymentsSettingsSchema
|
|
362
381
|
}).strict();
|
|
363
382
|
var StorefrontStoreShape = {
|
|
364
|
-
id:
|
|
365
|
-
tenantId:
|
|
366
|
-
sellerId:
|
|
383
|
+
id: EntityIdSchema,
|
|
384
|
+
tenantId: EntityIdSchema,
|
|
385
|
+
sellerId: NullableEntityIdSchema,
|
|
367
386
|
type: StoreTypeSchema,
|
|
368
387
|
isActive: zod.z.boolean(),
|
|
369
388
|
name: zod.z.string(),
|
|
@@ -444,13 +463,13 @@ var CmsMenuDtoSchema = zod.z.object({
|
|
|
444
463
|
items: zod.z.array(CmsMenuItemSchema)
|
|
445
464
|
}).strict();
|
|
446
465
|
var CmsBlockDtoSchema = zod.z.object({
|
|
447
|
-
id:
|
|
466
|
+
id: EntityIdSchema,
|
|
448
467
|
type: zod.z.string(),
|
|
449
468
|
order: zod.z.number().int(),
|
|
450
469
|
settings: JsonElementSchema
|
|
451
470
|
}).strict();
|
|
452
471
|
var CmsSectionDtoSchema = zod.z.object({
|
|
453
|
-
id:
|
|
472
|
+
id: EntityIdSchema,
|
|
454
473
|
type: zod.z.string(),
|
|
455
474
|
order: zod.z.number().int(),
|
|
456
475
|
settings: JsonElementSchema,
|
|
@@ -459,7 +478,7 @@ var CmsSectionDtoSchema = zod.z.object({
|
|
|
459
478
|
var CmsContentChannelSchema = zod.z.enum(["storefront", "pos"]);
|
|
460
479
|
var CmsPageStatusSchema = zod.z.enum(["draft", "published", "archived"]);
|
|
461
480
|
var CmsPageDetailsDtoSchema = zod.z.object({
|
|
462
|
-
id:
|
|
481
|
+
id: EntityIdSchema,
|
|
463
482
|
name: zod.z.string(),
|
|
464
483
|
slug: zod.z.string(),
|
|
465
484
|
channel: CmsContentChannelSchema,
|
|
@@ -1193,6 +1212,385 @@ async function getDistricts(api, params) {
|
|
|
1193
1212
|
}
|
|
1194
1213
|
});
|
|
1195
1214
|
}
|
|
1215
|
+
var CustomerAddressUpsertInputSchema = zod.z.object({
|
|
1216
|
+
addressKey: zod.z.string().trim().min(1),
|
|
1217
|
+
countryIsoCode: zod.z.string().trim().length(2),
|
|
1218
|
+
addressLine: zod.z.string().trim().min(1),
|
|
1219
|
+
addressNumber: zod.z.string().trim().min(1),
|
|
1220
|
+
department: zod.z.string().trim().min(1),
|
|
1221
|
+
province: zod.z.string().trim().min(1),
|
|
1222
|
+
district: zod.z.string().trim().min(1),
|
|
1223
|
+
phone: zod.z.string().trim(),
|
|
1224
|
+
cellPhone: zod.z.string().trim(),
|
|
1225
|
+
postalCode: zod.z.string().trim().min(1),
|
|
1226
|
+
reference: zod.z.string().trim(),
|
|
1227
|
+
latitude: zod.z.number().nullable(),
|
|
1228
|
+
longitude: zod.z.number().nullable(),
|
|
1229
|
+
isDefault: zod.z.boolean()
|
|
1230
|
+
});
|
|
1231
|
+
var CustomerAddressSchema = CustomerAddressUpsertInputSchema.extend({
|
|
1232
|
+
id: zod.z.union([zod.z.string(), zod.z.number()]).transform(String).optional()
|
|
1233
|
+
});
|
|
1234
|
+
var CustomerAddressesSchema = zod.z.array(CustomerAddressSchema);
|
|
1235
|
+
function toCustomerSavedAddresses(addresses) {
|
|
1236
|
+
const saved = [];
|
|
1237
|
+
for (const address of addresses) {
|
|
1238
|
+
if (!address.id?.trim()) continue;
|
|
1239
|
+
const { id, ...rest } = address;
|
|
1240
|
+
saved.push({ id: id.trim(), ...rest });
|
|
1241
|
+
}
|
|
1242
|
+
return saved;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
// src/services/customer-address.service.ts
|
|
1246
|
+
var ADDRESSES_PATH = "customer/addresses";
|
|
1247
|
+
var CustomerAddressMutationResponseSchema = zod.z.union([
|
|
1248
|
+
CustomerAddressSchema,
|
|
1249
|
+
zod.z.object({
|
|
1250
|
+
id: zod.z.union([zod.z.string(), zod.z.number()]).transform(String)
|
|
1251
|
+
}),
|
|
1252
|
+
zod.z.null()
|
|
1253
|
+
]);
|
|
1254
|
+
async function getCustomerAddresses(api, options = {}) {
|
|
1255
|
+
return api.get(ADDRESSES_PATH, CustomerAddressesSchema, {
|
|
1256
|
+
headers: options.headers,
|
|
1257
|
+
signal: options.signal
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
async function createCustomerAddress(api, data, options = {}) {
|
|
1261
|
+
const payload = CustomerAddressUpsertInputSchema.parse(data);
|
|
1262
|
+
return api.post(ADDRESSES_PATH, payload, CustomerAddressMutationResponseSchema, {
|
|
1263
|
+
headers: options.headers,
|
|
1264
|
+
signal: options.signal
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
async function updateCustomerAddress(api, addressId, data, options = {}) {
|
|
1268
|
+
const id = addressId.trim();
|
|
1269
|
+
if (!id) throw new Error("addressId requerido");
|
|
1270
|
+
const payload = CustomerAddressUpsertInputSchema.parse(data);
|
|
1271
|
+
return api.request(
|
|
1272
|
+
"PUT",
|
|
1273
|
+
`${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
|
|
1274
|
+
CustomerAddressMutationResponseSchema,
|
|
1275
|
+
{
|
|
1276
|
+
body: payload,
|
|
1277
|
+
headers: options.headers,
|
|
1278
|
+
signal: options.signal
|
|
1279
|
+
}
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
async function deleteCustomerAddress(api, addressId, options = {}) {
|
|
1283
|
+
const id = addressId.trim();
|
|
1284
|
+
if (!id) throw new Error("addressId requerido");
|
|
1285
|
+
await api.request(
|
|
1286
|
+
"DELETE",
|
|
1287
|
+
`${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
|
|
1288
|
+
zod.z.null(),
|
|
1289
|
+
{
|
|
1290
|
+
headers: options.headers,
|
|
1291
|
+
signal: options.signal
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
var DEFAULT_COUNTRY_CODE = "PE";
|
|
1296
|
+
var CustomerRegisterRequestSchema = zod.z.object({
|
|
1297
|
+
email: zod.z.string().email(),
|
|
1298
|
+
firstName: zod.z.string().trim().min(1),
|
|
1299
|
+
lastName: zod.z.string().trim().min(1),
|
|
1300
|
+
countryIsoCode: zod.z.string().trim().length(2),
|
|
1301
|
+
password: zod.z.string().min(1),
|
|
1302
|
+
phone: zod.z.string().trim().min(1).optional()
|
|
1303
|
+
});
|
|
1304
|
+
var CustomerProfilePatchSchema = zod.z.object({
|
|
1305
|
+
firstName: zod.z.string().trim().min(1),
|
|
1306
|
+
lastName: zod.z.string().trim().min(1),
|
|
1307
|
+
phone: zod.z.string().trim(),
|
|
1308
|
+
identificationNumber: zod.z.string().nullable(),
|
|
1309
|
+
identificationType: zod.z.string().nullable(),
|
|
1310
|
+
entityName: zod.z.string().nullable(),
|
|
1311
|
+
entityIdentificationNumber: zod.z.string().nullable(),
|
|
1312
|
+
gender: zod.z.string().nullable(),
|
|
1313
|
+
role: zod.z.string().nullable(),
|
|
1314
|
+
companyName: zod.z.string().nullable(),
|
|
1315
|
+
dateOfBirth: zod.z.string().nullable(),
|
|
1316
|
+
consent: zod.z.boolean(),
|
|
1317
|
+
countryIsoCode: zod.z.string().trim().length(2)
|
|
1318
|
+
});
|
|
1319
|
+
var CustomerProfileSchema = zod.z.object({
|
|
1320
|
+
firstName: zod.z.string(),
|
|
1321
|
+
lastName: zod.z.string(),
|
|
1322
|
+
phone: zod.z.string(),
|
|
1323
|
+
email: zod.z.string().email(),
|
|
1324
|
+
identificationNumber: zod.z.string().nullable(),
|
|
1325
|
+
identificationType: zod.z.string().nullable(),
|
|
1326
|
+
countryIsoCode: zod.z.string(),
|
|
1327
|
+
consent: zod.z.boolean(),
|
|
1328
|
+
entityName: zod.z.string().nullable(),
|
|
1329
|
+
entityIdentificationNumber: zod.z.string().nullable(),
|
|
1330
|
+
gender: zod.z.string().nullable(),
|
|
1331
|
+
role: zod.z.string().nullable(),
|
|
1332
|
+
companyName: zod.z.string().nullable(),
|
|
1333
|
+
dateOfBirth: zod.z.string().nullable()
|
|
1334
|
+
});
|
|
1335
|
+
var nullableString = zod.z.string().nullable().optional().transform((v) => v ?? null);
|
|
1336
|
+
var CustomerMeSchema = zod.z.object({
|
|
1337
|
+
id: zod.z.union([zod.z.string(), zod.z.number()]),
|
|
1338
|
+
storeId: zod.z.string().optional(),
|
|
1339
|
+
email: zod.z.string().email(),
|
|
1340
|
+
firstName: zod.z.string(),
|
|
1341
|
+
lastName: zod.z.string(),
|
|
1342
|
+
phone: zod.z.union([zod.z.string(), zod.z.null()]).optional().transform((v) => v ?? ""),
|
|
1343
|
+
identificationNumber: nullableString,
|
|
1344
|
+
identificationType: nullableString,
|
|
1345
|
+
entityName: nullableString,
|
|
1346
|
+
entityIdentificationNumber: nullableString,
|
|
1347
|
+
gender: nullableString,
|
|
1348
|
+
role: nullableString,
|
|
1349
|
+
companyName: nullableString,
|
|
1350
|
+
dateOfBirth: nullableString,
|
|
1351
|
+
countryIsoCode: zod.z.string().optional().transform((v) => v?.trim().length === 2 ? v.trim() : DEFAULT_COUNTRY_CODE),
|
|
1352
|
+
consent: zod.z.boolean().optional().transform((v) => v ?? false)
|
|
1353
|
+
}).passthrough();
|
|
1354
|
+
function customerMeToProfile(me) {
|
|
1355
|
+
return CustomerProfileSchema.parse({
|
|
1356
|
+
firstName: me.firstName,
|
|
1357
|
+
lastName: me.lastName,
|
|
1358
|
+
phone: me.phone,
|
|
1359
|
+
email: me.email,
|
|
1360
|
+
identificationNumber: me.identificationNumber,
|
|
1361
|
+
identificationType: me.identificationType,
|
|
1362
|
+
countryIsoCode: me.countryIsoCode,
|
|
1363
|
+
consent: me.consent,
|
|
1364
|
+
entityName: me.entityName,
|
|
1365
|
+
entityIdentificationNumber: me.entityIdentificationNumber,
|
|
1366
|
+
gender: me.gender,
|
|
1367
|
+
role: me.role,
|
|
1368
|
+
companyName: me.companyName,
|
|
1369
|
+
dateOfBirth: me.dateOfBirth
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
function customerMeToProfilePatch(me) {
|
|
1373
|
+
return CustomerProfilePatchSchema.parse({
|
|
1374
|
+
firstName: me.firstName,
|
|
1375
|
+
lastName: me.lastName,
|
|
1376
|
+
phone: me.phone,
|
|
1377
|
+
identificationNumber: me.identificationNumber,
|
|
1378
|
+
identificationType: me.identificationType,
|
|
1379
|
+
entityName: me.entityName,
|
|
1380
|
+
entityIdentificationNumber: me.entityIdentificationNumber,
|
|
1381
|
+
gender: me.gender,
|
|
1382
|
+
role: me.role,
|
|
1383
|
+
companyName: me.companyName,
|
|
1384
|
+
dateOfBirth: me.dateOfBirth,
|
|
1385
|
+
consent: me.consent,
|
|
1386
|
+
countryIsoCode: me.countryIsoCode || DEFAULT_COUNTRY_CODE
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
function customerProfileToPatch(profile) {
|
|
1390
|
+
return CustomerProfilePatchSchema.parse({
|
|
1391
|
+
firstName: profile.firstName,
|
|
1392
|
+
lastName: profile.lastName,
|
|
1393
|
+
phone: profile.phone,
|
|
1394
|
+
identificationNumber: profile.identificationNumber,
|
|
1395
|
+
identificationType: profile.identificationType,
|
|
1396
|
+
entityName: profile.entityName,
|
|
1397
|
+
entityIdentificationNumber: profile.entityIdentificationNumber,
|
|
1398
|
+
gender: profile.gender,
|
|
1399
|
+
role: profile.role,
|
|
1400
|
+
companyName: profile.companyName,
|
|
1401
|
+
dateOfBirth: profile.dateOfBirth,
|
|
1402
|
+
consent: profile.consent,
|
|
1403
|
+
countryIsoCode: profile.countryIsoCode || DEFAULT_COUNTRY_CODE
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// src/services/customer.service.ts
|
|
1408
|
+
var CUSTOMER_PATH = "customer";
|
|
1409
|
+
var CUSTOMER_REGISTER_PATH = "customer/register";
|
|
1410
|
+
async function registerCustomer(api, data, options = {}) {
|
|
1411
|
+
const payload = CustomerRegisterRequestSchema.parse(data);
|
|
1412
|
+
return api.post(CUSTOMER_REGISTER_PATH, payload, zod.z.unknown(), {
|
|
1413
|
+
headers: options.headers,
|
|
1414
|
+
signal: options.signal
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
async function getCustomerMe(api, options = {}) {
|
|
1418
|
+
return api.get(CUSTOMER_PATH, CustomerMeSchema, {
|
|
1419
|
+
headers: options.headers,
|
|
1420
|
+
signal: options.signal
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
async function patchCustomer(api, data, options = {}) {
|
|
1424
|
+
const payload = CustomerProfilePatchSchema.parse(data);
|
|
1425
|
+
await api.request("PATCH", CUSTOMER_PATH, zod.z.null(), {
|
|
1426
|
+
body: payload,
|
|
1427
|
+
headers: options.headers,
|
|
1428
|
+
signal: options.signal
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
var CustomerOrderShippingAddressSchema = zod.z.object({
|
|
1432
|
+
name: zod.z.string().nullable().optional(),
|
|
1433
|
+
company: zod.z.string().nullable().optional(),
|
|
1434
|
+
address1: zod.z.string(),
|
|
1435
|
+
address2: zod.z.string().nullable().optional(),
|
|
1436
|
+
city: zod.z.string().nullable().optional(),
|
|
1437
|
+
countryCode: zod.z.string().min(2).max(2),
|
|
1438
|
+
province: zod.z.string().nullable().optional(),
|
|
1439
|
+
postalCode: zod.z.string().nullable().optional(),
|
|
1440
|
+
district: zod.z.string().nullable().optional(),
|
|
1441
|
+
phone: zod.z.string().nullable().optional(),
|
|
1442
|
+
latitude: zod.z.number().nullable().optional(),
|
|
1443
|
+
longitude: zod.z.number().nullable().optional(),
|
|
1444
|
+
metadata: zod.z.record(zod.z.unknown()).nullable().optional()
|
|
1445
|
+
}).passthrough();
|
|
1446
|
+
var CustomerOrderLineItemSchema = zod.z.object({
|
|
1447
|
+
id: zod.z.string(),
|
|
1448
|
+
orderId: zod.z.coerce.string(),
|
|
1449
|
+
productId: zod.z.coerce.string().nullable(),
|
|
1450
|
+
variantId: zod.z.coerce.string().nullable(),
|
|
1451
|
+
title: zod.z.string(),
|
|
1452
|
+
subtitle: zod.z.string().nullable().optional(),
|
|
1453
|
+
thumbnail: zod.z.string().nullable().optional(),
|
|
1454
|
+
variantTitle: zod.z.string().nullable().optional(),
|
|
1455
|
+
productHandle: zod.z.string().nullable().optional(),
|
|
1456
|
+
quantity: zod.z.number(),
|
|
1457
|
+
unitPrice: zod.z.number(),
|
|
1458
|
+
total: zod.z.number(),
|
|
1459
|
+
status: zod.z.string()
|
|
1460
|
+
});
|
|
1461
|
+
var CustomerOrderListItemSchema = zod.z.object({
|
|
1462
|
+
orderId: zod.z.coerce.string(),
|
|
1463
|
+
orderNumber: zod.z.string(),
|
|
1464
|
+
orderGroup: zod.z.string(),
|
|
1465
|
+
orderIds: zod.z.array(zod.z.coerce.string()),
|
|
1466
|
+
status: zod.z.string(),
|
|
1467
|
+
total: zod.z.number(),
|
|
1468
|
+
totalPaid: zod.z.number(),
|
|
1469
|
+
currencyCode: zod.z.string(),
|
|
1470
|
+
orderDate: zod.z.string(),
|
|
1471
|
+
createdOn: zod.z.string(),
|
|
1472
|
+
updatedOn: zod.z.string().nullable().optional(),
|
|
1473
|
+
paymentAt: zod.z.string().nullable().optional(),
|
|
1474
|
+
shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1475
|
+
shippingAddressSummary: zod.z.string().nullable().optional(),
|
|
1476
|
+
items: zod.z.array(CustomerOrderLineItemSchema)
|
|
1477
|
+
});
|
|
1478
|
+
var CustomerOrderListSchema = zod.z.array(CustomerOrderListItemSchema);
|
|
1479
|
+
var CustomerOrderPaymentSchema = zod.z.object({
|
|
1480
|
+
id: zod.z.string(),
|
|
1481
|
+
paymentMethod: zod.z.string(),
|
|
1482
|
+
paymentCode: zod.z.string(),
|
|
1483
|
+
amount: zod.z.number(),
|
|
1484
|
+
paymentStatus: zod.z.string(),
|
|
1485
|
+
receiptUrl: zod.z.string().nullable().optional(),
|
|
1486
|
+
createdOn: zod.z.string()
|
|
1487
|
+
});
|
|
1488
|
+
var CustomerOrderStatusTimelineSchema = zod.z.object({
|
|
1489
|
+
key: zod.z.string(),
|
|
1490
|
+
label: zod.z.string(),
|
|
1491
|
+
occurredAt: zod.z.string(),
|
|
1492
|
+
description: zod.z.string().nullable().optional(),
|
|
1493
|
+
status: zod.z.string(),
|
|
1494
|
+
source: zod.z.string()
|
|
1495
|
+
});
|
|
1496
|
+
var CustomerOrderDetailSchema = zod.z.object({
|
|
1497
|
+
id: zod.z.coerce.string(),
|
|
1498
|
+
orderNumber: zod.z.string(),
|
|
1499
|
+
orderGroup: zod.z.string(),
|
|
1500
|
+
status: zod.z.string(),
|
|
1501
|
+
total: zod.z.number(),
|
|
1502
|
+
totalPaid: zod.z.number(),
|
|
1503
|
+
currencyCode: zod.z.string(),
|
|
1504
|
+
orderDate: zod.z.string(),
|
|
1505
|
+
createdOn: zod.z.string(),
|
|
1506
|
+
updatedOn: zod.z.string().nullable().optional(),
|
|
1507
|
+
paymentAt: zod.z.string().nullable().optional(),
|
|
1508
|
+
subTotal: zod.z.number(),
|
|
1509
|
+
discount: zod.z.number(),
|
|
1510
|
+
shipping: zod.z.number(),
|
|
1511
|
+
tax: zod.z.number(),
|
|
1512
|
+
email: zod.z.string(),
|
|
1513
|
+
phone: zod.z.string(),
|
|
1514
|
+
firstName: zod.z.string(),
|
|
1515
|
+
lastName: zod.z.string(),
|
|
1516
|
+
shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1517
|
+
shippingAddressSummary: zod.z.string().nullable().optional(),
|
|
1518
|
+
billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1519
|
+
items: zod.z.array(CustomerOrderLineItemSchema),
|
|
1520
|
+
payments: zod.z.array(CustomerOrderPaymentSchema),
|
|
1521
|
+
statusTimeline: zod.z.array(CustomerOrderStatusTimelineSchema)
|
|
1522
|
+
});
|
|
1523
|
+
var ORDER_STATUS_LABELS = {
|
|
1524
|
+
New: "Pedido realizado",
|
|
1525
|
+
Confirmed: "Confirmado",
|
|
1526
|
+
Processing: "En preparaci\xF3n",
|
|
1527
|
+
InTransit: "En camino",
|
|
1528
|
+
Delivered: "Entregado",
|
|
1529
|
+
Cancelled: "Cancelado",
|
|
1530
|
+
Canceled: "Cancelado",
|
|
1531
|
+
Refunded: "Reembolsado",
|
|
1532
|
+
Pending: "Pendiente",
|
|
1533
|
+
PendingToConfirm: "Pendiente de confirmaci\xF3n",
|
|
1534
|
+
Paid: "Pagado",
|
|
1535
|
+
Captured: "Pago confirmado"
|
|
1536
|
+
};
|
|
1537
|
+
function formatCustomerOrderStatus(status) {
|
|
1538
|
+
const trimmed = status.trim();
|
|
1539
|
+
if (!trimmed) return "Desconocido";
|
|
1540
|
+
return ORDER_STATUS_LABELS[trimmed] ?? trimmed.replace(/([A-Z])/g, " $1").trim();
|
|
1541
|
+
}
|
|
1542
|
+
function customerOrderStatusTone(status) {
|
|
1543
|
+
const s = status.toLowerCase();
|
|
1544
|
+
if (s.includes("cancel") || s.includes("refund")) return "danger";
|
|
1545
|
+
if (s.includes("deliver")) return "success";
|
|
1546
|
+
if (s.includes("transit") || s.includes("ship")) return "info";
|
|
1547
|
+
if (s.includes("confirm") || s.includes("paid") || s.includes("capture"))
|
|
1548
|
+
return "success";
|
|
1549
|
+
if (s.includes("pending") || s.includes("new") || s.includes("process"))
|
|
1550
|
+
return "warning";
|
|
1551
|
+
return "default";
|
|
1552
|
+
}
|
|
1553
|
+
function formatOrderDate(iso, locale = "es-PE") {
|
|
1554
|
+
const d = new Date(iso);
|
|
1555
|
+
if (Number.isNaN(d.getTime())) return iso;
|
|
1556
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1557
|
+
day: "numeric",
|
|
1558
|
+
month: "long",
|
|
1559
|
+
year: "numeric"
|
|
1560
|
+
}).format(d);
|
|
1561
|
+
}
|
|
1562
|
+
function formatOrderDateTime(iso, locale = "es-PE") {
|
|
1563
|
+
const d = new Date(iso);
|
|
1564
|
+
if (Number.isNaN(d.getTime())) return iso;
|
|
1565
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1566
|
+
day: "numeric",
|
|
1567
|
+
month: "short",
|
|
1568
|
+
year: "numeric",
|
|
1569
|
+
hour: "2-digit",
|
|
1570
|
+
minute: "2-digit"
|
|
1571
|
+
}).format(d);
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
// src/services/customer-order.service.ts
|
|
1575
|
+
var ORDERS_PATH = "customer/orders";
|
|
1576
|
+
async function getCustomerOrders(api, options = {}) {
|
|
1577
|
+
return api.get(ORDERS_PATH, CustomerOrderListSchema, {
|
|
1578
|
+
headers: options.headers,
|
|
1579
|
+
signal: options.signal
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
async function getCustomerOrder(api, orderId, options = {}) {
|
|
1583
|
+
const id = orderId.trim();
|
|
1584
|
+
if (!id) throw new Error("orderId requerido");
|
|
1585
|
+
return api.get(
|
|
1586
|
+
`${ORDERS_PATH}/${encodeURIComponent(id)}`,
|
|
1587
|
+
CustomerOrderDetailSchema,
|
|
1588
|
+
{
|
|
1589
|
+
headers: options.headers,
|
|
1590
|
+
signal: options.signal
|
|
1591
|
+
}
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1196
1594
|
|
|
1197
1595
|
// src/client.ts
|
|
1198
1596
|
var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
|
|
@@ -1351,6 +1749,38 @@ function createClient(options) {
|
|
|
1351
1749
|
async function getDistricts2(params) {
|
|
1352
1750
|
return getDistricts(api, params);
|
|
1353
1751
|
}
|
|
1752
|
+
async function getCustomerAddresses2(options2 = {}) {
|
|
1753
|
+
const client = await apiClient();
|
|
1754
|
+
return getCustomerAddresses(client, options2);
|
|
1755
|
+
}
|
|
1756
|
+
async function createCustomerAddress2(data, options2 = {}) {
|
|
1757
|
+
const client = await apiClient();
|
|
1758
|
+
return createCustomerAddress(client, data, options2);
|
|
1759
|
+
}
|
|
1760
|
+
async function updateCustomerAddress2(addressId, data, options2 = {}) {
|
|
1761
|
+
const client = await apiClient();
|
|
1762
|
+
return updateCustomerAddress(client, addressId, data, options2);
|
|
1763
|
+
}
|
|
1764
|
+
async function deleteCustomerAddress2(addressId, options2 = {}) {
|
|
1765
|
+
const client = await apiClient();
|
|
1766
|
+
return deleteCustomerAddress(client, addressId, options2);
|
|
1767
|
+
}
|
|
1768
|
+
async function getCustomerMe2(options2 = {}) {
|
|
1769
|
+
const client = await apiClient();
|
|
1770
|
+
return getCustomerMe(client, options2);
|
|
1771
|
+
}
|
|
1772
|
+
async function patchCustomer2(data, options2 = {}) {
|
|
1773
|
+
const client = await apiClient();
|
|
1774
|
+
return patchCustomer(client, data, options2);
|
|
1775
|
+
}
|
|
1776
|
+
async function getCustomerOrders2(options2 = {}) {
|
|
1777
|
+
const client = await apiClient();
|
|
1778
|
+
return getCustomerOrders(client, options2);
|
|
1779
|
+
}
|
|
1780
|
+
async function getCustomerOrder2(orderId, options2 = {}) {
|
|
1781
|
+
const client = await apiClient();
|
|
1782
|
+
return getCustomerOrder(client, orderId, options2);
|
|
1783
|
+
}
|
|
1354
1784
|
return {
|
|
1355
1785
|
...api,
|
|
1356
1786
|
getSettings,
|
|
@@ -1382,7 +1812,15 @@ function createClient(options) {
|
|
|
1382
1812
|
getCountries: getCountries2,
|
|
1383
1813
|
getDepartments: getDepartments2,
|
|
1384
1814
|
getProvinces: getProvinces2,
|
|
1385
|
-
getDistricts: getDistricts2
|
|
1815
|
+
getDistricts: getDistricts2,
|
|
1816
|
+
getCustomerAddresses: getCustomerAddresses2,
|
|
1817
|
+
createCustomerAddress: createCustomerAddress2,
|
|
1818
|
+
updateCustomerAddress: updateCustomerAddress2,
|
|
1819
|
+
deleteCustomerAddress: deleteCustomerAddress2,
|
|
1820
|
+
getCustomerMe: getCustomerMe2,
|
|
1821
|
+
patchCustomer: patchCustomer2,
|
|
1822
|
+
getCustomerOrders: getCustomerOrders2,
|
|
1823
|
+
getCustomerOrder: getCustomerOrder2
|
|
1386
1824
|
};
|
|
1387
1825
|
}
|
|
1388
1826
|
var createStorefrontClient = createClient;
|
|
@@ -1498,12 +1936,28 @@ exports.CountriesSchema = CountriesSchema;
|
|
|
1498
1936
|
exports.CountrySchema = CountrySchema;
|
|
1499
1937
|
exports.CreateCartParamsSchema = CreateCartParamsSchema;
|
|
1500
1938
|
exports.CreateProductReviewParamsSchema = CreateProductReviewParamsSchema;
|
|
1939
|
+
exports.CustomerAddressMutationResponseSchema = CustomerAddressMutationResponseSchema;
|
|
1940
|
+
exports.CustomerAddressSchema = CustomerAddressSchema;
|
|
1941
|
+
exports.CustomerAddressUpsertInputSchema = CustomerAddressUpsertInputSchema;
|
|
1942
|
+
exports.CustomerAddressesSchema = CustomerAddressesSchema;
|
|
1943
|
+
exports.CustomerMeSchema = CustomerMeSchema;
|
|
1944
|
+
exports.CustomerOrderDetailSchema = CustomerOrderDetailSchema;
|
|
1945
|
+
exports.CustomerOrderLineItemSchema = CustomerOrderLineItemSchema;
|
|
1946
|
+
exports.CustomerOrderListItemSchema = CustomerOrderListItemSchema;
|
|
1947
|
+
exports.CustomerOrderListSchema = CustomerOrderListSchema;
|
|
1948
|
+
exports.CustomerOrderPaymentSchema = CustomerOrderPaymentSchema;
|
|
1949
|
+
exports.CustomerOrderShippingAddressSchema = CustomerOrderShippingAddressSchema;
|
|
1950
|
+
exports.CustomerOrderStatusTimelineSchema = CustomerOrderStatusTimelineSchema;
|
|
1951
|
+
exports.CustomerProfilePatchSchema = CustomerProfilePatchSchema;
|
|
1952
|
+
exports.CustomerProfileSchema = CustomerProfileSchema;
|
|
1953
|
+
exports.CustomerRegisterRequestSchema = CustomerRegisterRequestSchema;
|
|
1501
1954
|
exports.DEFAULT_API_BASE_URL = DEFAULT_API_BASE_URL;
|
|
1502
1955
|
exports.DEFAULT_API_VERSION = DEFAULT_API_VERSION;
|
|
1503
1956
|
exports.DepartmentSchema = DepartmentSchema;
|
|
1504
1957
|
exports.DepartmentsSchema = DepartmentsSchema;
|
|
1505
1958
|
exports.DistrictSchema = DistrictSchema;
|
|
1506
1959
|
exports.DistrictsSchema = DistrictsSchema;
|
|
1960
|
+
exports.EntityIdSchema = EntityIdSchema;
|
|
1507
1961
|
exports.FacetItemSchema = FacetItemSchema;
|
|
1508
1962
|
exports.FacetSchema = FacetSchema;
|
|
1509
1963
|
exports.GeoDivisionSchema = GeoDivisionSchema;
|
|
@@ -1515,6 +1969,7 @@ exports.GetProvincesParamsSchema = GetProvincesParamsSchema;
|
|
|
1515
1969
|
exports.GetShippingOptionsParamsSchema = GetShippingOptionsParamsSchema;
|
|
1516
1970
|
exports.JsonElementSchema = JsonElementSchema;
|
|
1517
1971
|
exports.ListProductReviewsParamsSchema = ListProductReviewsParamsSchema;
|
|
1972
|
+
exports.NullableEntityIdSchema = NullableEntityIdSchema;
|
|
1518
1973
|
exports.PriceTierSchema = PriceTierSchema;
|
|
1519
1974
|
exports.ProductAutocompleteParamsSchema = ProductAutocompleteParamsSchema;
|
|
1520
1975
|
exports.ProductDetailParamsSchema = ProductDetailParamsSchema;
|
|
@@ -1593,11 +2048,24 @@ exports.checkoutCart = checkoutCart;
|
|
|
1593
2048
|
exports.createApi = createApi;
|
|
1594
2049
|
exports.createCart = createCart;
|
|
1595
2050
|
exports.createClient = createClient;
|
|
2051
|
+
exports.createCustomerAddress = createCustomerAddress;
|
|
1596
2052
|
exports.createProductReview = createProductReview;
|
|
1597
2053
|
exports.createStorefrontClient = createStorefrontClient;
|
|
2054
|
+
exports.customerMeToProfile = customerMeToProfile;
|
|
2055
|
+
exports.customerMeToProfilePatch = customerMeToProfilePatch;
|
|
2056
|
+
exports.customerOrderStatusTone = customerOrderStatusTone;
|
|
2057
|
+
exports.customerProfileToPatch = customerProfileToPatch;
|
|
2058
|
+
exports.deleteCustomerAddress = deleteCustomerAddress;
|
|
2059
|
+
exports.formatCustomerOrderStatus = formatCustomerOrderStatus;
|
|
2060
|
+
exports.formatOrderDate = formatOrderDate;
|
|
2061
|
+
exports.formatOrderDateTime = formatOrderDateTime;
|
|
1598
2062
|
exports.getCart = getCart;
|
|
1599
2063
|
exports.getCartCheckout = getCartCheckout;
|
|
1600
2064
|
exports.getCountries = getCountries;
|
|
2065
|
+
exports.getCustomerAddresses = getCustomerAddresses;
|
|
2066
|
+
exports.getCustomerMe = getCustomerMe;
|
|
2067
|
+
exports.getCustomerOrder = getCustomerOrder;
|
|
2068
|
+
exports.getCustomerOrders = getCustomerOrders;
|
|
1601
2069
|
exports.getDepartments = getDepartments;
|
|
1602
2070
|
exports.getDistricts = getDistricts;
|
|
1603
2071
|
exports.getMenuItems = getMenuItems;
|
|
@@ -1610,13 +2078,17 @@ exports.getShippingOptions = getShippingOptions;
|
|
|
1610
2078
|
exports.listProductReviews = listProductReviews;
|
|
1611
2079
|
exports.patchCartAddresses = patchCartAddresses;
|
|
1612
2080
|
exports.patchCartBuyer = patchCartBuyer;
|
|
2081
|
+
exports.patchCustomer = patchCustomer;
|
|
1613
2082
|
exports.putCartShippingMethod = putCartShippingMethod;
|
|
2083
|
+
exports.registerCustomer = registerCustomer;
|
|
1614
2084
|
exports.removeCartItem = removeCartItem;
|
|
1615
2085
|
exports.removeCartPromotionCode = removeCartPromotionCode;
|
|
1616
2086
|
exports.resolveApiBaseUrl = resolveApiBaseUrl;
|
|
1617
2087
|
exports.sanitizeHtml = sanitizeHtml;
|
|
1618
2088
|
exports.stripHtml = stripHtml;
|
|
2089
|
+
exports.toCustomerSavedAddresses = toCustomerSavedAddresses;
|
|
1619
2090
|
exports.updateCartItemQuantity = updateCartItemQuantity;
|
|
2091
|
+
exports.updateCustomerAddress = updateCustomerAddress;
|
|
1620
2092
|
exports.uploadPaymentReceipt = uploadPaymentReceipt;
|
|
1621
2093
|
//# sourceMappingURL=index.cjs.map
|
|
1622
2094
|
//# sourceMappingURL=index.cjs.map
|