@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.
Files changed (53) hide show
  1. package/dist/api.cjs +19 -5
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.js +19 -5
  4. package/dist/api.js.map +1 -1
  5. package/dist/client-4ZTG2RZ3.d.ts +195 -0
  6. package/dist/client-BpX4yR6S.d.cts +195 -0
  7. package/dist/client.cjs +320 -6
  8. package/dist/client.cjs.map +1 -1
  9. package/dist/client.d.cts +13 -84
  10. package/dist/client.d.ts +13 -84
  11. package/dist/client.js +320 -6
  12. package/dist/client.js.map +1 -1
  13. package/dist/index.cjs +471 -6
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +326 -323
  16. package/dist/index.d.ts +326 -323
  17. package/dist/index.js +440 -7
  18. package/dist/index.js.map +1 -1
  19. package/dist/models/collections.d.cts +4 -4
  20. package/dist/models/collections.d.ts +4 -4
  21. package/dist/models/customer-address.cjs +41 -0
  22. package/dist/models/customer-address.cjs.map +1 -0
  23. package/dist/models/customer-address.d.cts +160 -0
  24. package/dist/models/customer-address.d.ts +160 -0
  25. package/dist/models/customer-address.js +36 -0
  26. package/dist/models/customer-address.js.map +1 -0
  27. package/dist/models/customer-order.cjs +161 -0
  28. package/dist/models/customer-order.cjs.map +1 -0
  29. package/dist/models/customer-order.d.cts +896 -0
  30. package/dist/models/customer-order.d.ts +896 -0
  31. package/dist/models/customer-order.js +149 -0
  32. package/dist/models/customer-order.js.map +1 -0
  33. package/dist/models/customer-profile.cjs +126 -0
  34. package/dist/models/customer-profile.cjs.map +1 -0
  35. package/dist/models/customer-profile.d.cts +178 -0
  36. package/dist/models/customer-profile.d.ts +178 -0
  37. package/dist/models/customer-profile.js +118 -0
  38. package/dist/models/customer-profile.js.map +1 -0
  39. package/dist/models/geo.d.cts +14 -14
  40. package/dist/models/geo.d.ts +14 -14
  41. package/dist/models/products.d.cts +130 -130
  42. package/dist/models/products.d.ts +130 -130
  43. package/dist/models/search.d.cts +4 -4
  44. package/dist/models/search.d.ts +4 -4
  45. package/dist/models/settings.d.cts +798 -798
  46. package/dist/models/settings.d.ts +798 -798
  47. package/dist/models/storefront-cart.d.cts +80 -80
  48. package/dist/models/storefront-cart.d.ts +80 -80
  49. package/dist/models/storefront-checkout.d.cts +400 -400
  50. package/dist/models/storefront-checkout.d.ts +400 -400
  51. package/dist/models/storefront-reviews.d.cts +8 -8
  52. package/dist/models/storefront-reviews.d.ts +8 -8
  53. package/package.json +16 -1
package/dist/client.cjs CHANGED
@@ -20,6 +20,7 @@ var ApiError = class extends Error {
20
20
  function resolveApiBaseUrl(baseUrl = DEFAULT_API_BASE_URL, version = DEFAULT_API_VERSION) {
21
21
  const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
22
22
  const segment = version.replace(/^\/+|\/+$/g, "");
23
+ if (!segment) return root;
23
24
  return new URL(`${segment}/`, root).toString();
24
25
  }
25
26
  function createApi(options = {}) {
@@ -62,17 +63,30 @@ function createApi(options = {}) {
62
63
  clearTimeout(timeout);
63
64
  }
64
65
  if (!response.ok) {
65
- const bodyText = await response.text().catch(() => void 0);
66
- let body = bodyText;
67
- if (bodyText) {
66
+ const bodyText2 = await response.text().catch(() => void 0);
67
+ let body = bodyText2;
68
+ if (bodyText2) {
68
69
  try {
69
- body = JSON.parse(bodyText);
70
+ body = JSON.parse(bodyText2);
70
71
  } catch {
71
72
  }
72
73
  }
73
74
  throw new ApiError(`${method} ${url} \u2192 ${response.status}`, response.status, url.toString(), body);
74
75
  }
75
- const json = await response.json();
76
+ const bodyText = await response.text();
77
+ let json = null;
78
+ if (bodyText.trim()) {
79
+ try {
80
+ json = JSON.parse(bodyText);
81
+ } catch {
82
+ throw new ApiError(
83
+ `Respuesta no JSON de ${url}`,
84
+ response.status,
85
+ url.toString(),
86
+ bodyText
87
+ );
88
+ }
89
+ }
76
90
  const parsed = schema.safeParse(json);
77
91
  if (!parsed.success) {
78
92
  throw new ApiError(
@@ -1154,6 +1168,266 @@ async function getDistricts(api, params) {
1154
1168
  }
1155
1169
  });
1156
1170
  }
1171
+ var CustomerAddressUpsertInputSchema = zod.z.object({
1172
+ addressKey: zod.z.string().trim().min(1),
1173
+ countryIsoCode: zod.z.string().trim().length(2),
1174
+ addressLine: zod.z.string().trim().min(1),
1175
+ addressNumber: zod.z.string().trim().min(1),
1176
+ department: zod.z.string().trim().min(1),
1177
+ province: zod.z.string().trim().min(1),
1178
+ district: zod.z.string().trim().min(1),
1179
+ phone: zod.z.string().trim(),
1180
+ cellPhone: zod.z.string().trim(),
1181
+ postalCode: zod.z.string().trim().min(1),
1182
+ reference: zod.z.string().trim(),
1183
+ latitude: zod.z.number().nullable(),
1184
+ longitude: zod.z.number().nullable(),
1185
+ isDefault: zod.z.boolean()
1186
+ });
1187
+ var CustomerAddressSchema = CustomerAddressUpsertInputSchema.extend({
1188
+ id: zod.z.union([zod.z.string(), zod.z.number()]).transform(String).optional()
1189
+ });
1190
+ var CustomerAddressesSchema = zod.z.array(CustomerAddressSchema);
1191
+
1192
+ // src/services/customer-address.service.ts
1193
+ var ADDRESSES_PATH = "customer/addresses";
1194
+ var CustomerAddressMutationResponseSchema = zod.z.union([
1195
+ CustomerAddressSchema,
1196
+ zod.z.object({
1197
+ id: zod.z.union([zod.z.string(), zod.z.number()]).transform(String)
1198
+ }),
1199
+ zod.z.null()
1200
+ ]);
1201
+ async function getCustomerAddresses(api, options = {}) {
1202
+ return api.get(ADDRESSES_PATH, CustomerAddressesSchema, {
1203
+ headers: options.headers,
1204
+ signal: options.signal
1205
+ });
1206
+ }
1207
+ async function createCustomerAddress(api, data, options = {}) {
1208
+ const payload = CustomerAddressUpsertInputSchema.parse(data);
1209
+ return api.post(ADDRESSES_PATH, payload, CustomerAddressMutationResponseSchema, {
1210
+ headers: options.headers,
1211
+ signal: options.signal
1212
+ });
1213
+ }
1214
+ async function updateCustomerAddress(api, addressId, data, options = {}) {
1215
+ const id = addressId.trim();
1216
+ if (!id) throw new Error("addressId requerido");
1217
+ const payload = CustomerAddressUpsertInputSchema.parse(data);
1218
+ return api.request(
1219
+ "PUT",
1220
+ `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1221
+ CustomerAddressMutationResponseSchema,
1222
+ {
1223
+ body: payload,
1224
+ headers: options.headers,
1225
+ signal: options.signal
1226
+ }
1227
+ );
1228
+ }
1229
+ async function deleteCustomerAddress(api, addressId, options = {}) {
1230
+ const id = addressId.trim();
1231
+ if (!id) throw new Error("addressId requerido");
1232
+ await api.request(
1233
+ "DELETE",
1234
+ `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1235
+ zod.z.null(),
1236
+ {
1237
+ headers: options.headers,
1238
+ signal: options.signal
1239
+ }
1240
+ );
1241
+ }
1242
+ var DEFAULT_COUNTRY_CODE = "PE";
1243
+ zod.z.object({
1244
+ email: zod.z.string().email(),
1245
+ firstName: zod.z.string().trim().min(1),
1246
+ lastName: zod.z.string().trim().min(1),
1247
+ countryIsoCode: zod.z.string().trim().length(2),
1248
+ password: zod.z.string().min(1),
1249
+ phone: zod.z.string().trim().min(1).optional()
1250
+ });
1251
+ var CustomerProfilePatchSchema = zod.z.object({
1252
+ firstName: zod.z.string().trim().min(1),
1253
+ lastName: zod.z.string().trim().min(1),
1254
+ phone: zod.z.string().trim(),
1255
+ identificationNumber: zod.z.string().nullable(),
1256
+ identificationType: zod.z.string().nullable(),
1257
+ entityName: zod.z.string().nullable(),
1258
+ entityIdentificationNumber: zod.z.string().nullable(),
1259
+ gender: zod.z.string().nullable(),
1260
+ role: zod.z.string().nullable(),
1261
+ companyName: zod.z.string().nullable(),
1262
+ dateOfBirth: zod.z.string().nullable(),
1263
+ consent: zod.z.boolean(),
1264
+ countryIsoCode: zod.z.string().trim().length(2)
1265
+ });
1266
+ zod.z.object({
1267
+ firstName: zod.z.string(),
1268
+ lastName: zod.z.string(),
1269
+ phone: zod.z.string(),
1270
+ email: zod.z.string().email(),
1271
+ identificationNumber: zod.z.string().nullable(),
1272
+ identificationType: zod.z.string().nullable(),
1273
+ countryIsoCode: zod.z.string(),
1274
+ consent: zod.z.boolean(),
1275
+ entityName: zod.z.string().nullable(),
1276
+ entityIdentificationNumber: zod.z.string().nullable(),
1277
+ gender: zod.z.string().nullable(),
1278
+ role: zod.z.string().nullable(),
1279
+ companyName: zod.z.string().nullable(),
1280
+ dateOfBirth: zod.z.string().nullable()
1281
+ });
1282
+ var nullableString = zod.z.string().nullable().optional().transform((v) => v ?? null);
1283
+ var CustomerMeSchema = zod.z.object({
1284
+ id: zod.z.union([zod.z.string(), zod.z.number()]),
1285
+ storeId: zod.z.string().optional(),
1286
+ email: zod.z.string().email(),
1287
+ firstName: zod.z.string(),
1288
+ lastName: zod.z.string(),
1289
+ phone: zod.z.union([zod.z.string(), zod.z.null()]).optional().transform((v) => v ?? ""),
1290
+ identificationNumber: nullableString,
1291
+ identificationType: nullableString,
1292
+ entityName: nullableString,
1293
+ entityIdentificationNumber: nullableString,
1294
+ gender: nullableString,
1295
+ role: nullableString,
1296
+ companyName: nullableString,
1297
+ dateOfBirth: nullableString,
1298
+ countryIsoCode: zod.z.string().optional().transform((v) => v?.trim().length === 2 ? v.trim() : DEFAULT_COUNTRY_CODE),
1299
+ consent: zod.z.boolean().optional().transform((v) => v ?? false)
1300
+ }).passthrough();
1301
+
1302
+ // src/services/customer.service.ts
1303
+ var CUSTOMER_PATH = "customer";
1304
+ async function getCustomerMe(api, options = {}) {
1305
+ return api.get(CUSTOMER_PATH, CustomerMeSchema, {
1306
+ headers: options.headers,
1307
+ signal: options.signal
1308
+ });
1309
+ }
1310
+ async function patchCustomer(api, data, options = {}) {
1311
+ const payload = CustomerProfilePatchSchema.parse(data);
1312
+ await api.request("PATCH", CUSTOMER_PATH, zod.z.null(), {
1313
+ body: payload,
1314
+ headers: options.headers,
1315
+ signal: options.signal
1316
+ });
1317
+ }
1318
+ var CustomerOrderShippingAddressSchema = zod.z.object({
1319
+ name: zod.z.string().nullable().optional(),
1320
+ company: zod.z.string().nullable().optional(),
1321
+ address1: zod.z.string(),
1322
+ address2: zod.z.string().nullable().optional(),
1323
+ city: zod.z.string().nullable().optional(),
1324
+ countryCode: zod.z.string().min(2).max(2),
1325
+ province: zod.z.string().nullable().optional(),
1326
+ postalCode: zod.z.string().nullable().optional(),
1327
+ district: zod.z.string().nullable().optional(),
1328
+ phone: zod.z.string().nullable().optional(),
1329
+ latitude: zod.z.number().nullable().optional(),
1330
+ longitude: zod.z.number().nullable().optional(),
1331
+ metadata: zod.z.record(zod.z.unknown()).nullable().optional()
1332
+ }).passthrough();
1333
+ var CustomerOrderLineItemSchema = zod.z.object({
1334
+ id: zod.z.string(),
1335
+ orderId: zod.z.coerce.string(),
1336
+ productId: zod.z.coerce.string().nullable(),
1337
+ variantId: zod.z.coerce.string().nullable(),
1338
+ title: zod.z.string(),
1339
+ subtitle: zod.z.string().nullable().optional(),
1340
+ thumbnail: zod.z.string().nullable().optional(),
1341
+ variantTitle: zod.z.string().nullable().optional(),
1342
+ productHandle: zod.z.string().nullable().optional(),
1343
+ quantity: zod.z.number(),
1344
+ unitPrice: zod.z.number(),
1345
+ total: zod.z.number(),
1346
+ status: zod.z.string()
1347
+ });
1348
+ var CustomerOrderListItemSchema = zod.z.object({
1349
+ orderId: zod.z.coerce.string(),
1350
+ orderNumber: zod.z.string(),
1351
+ orderGroup: zod.z.string(),
1352
+ orderIds: zod.z.array(zod.z.coerce.string()),
1353
+ status: zod.z.string(),
1354
+ total: zod.z.number(),
1355
+ totalPaid: zod.z.number(),
1356
+ currencyCode: zod.z.string(),
1357
+ orderDate: zod.z.string(),
1358
+ createdOn: zod.z.string(),
1359
+ updatedOn: zod.z.string().nullable().optional(),
1360
+ paymentAt: zod.z.string().nullable().optional(),
1361
+ shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1362
+ shippingAddressSummary: zod.z.string().nullable().optional(),
1363
+ items: zod.z.array(CustomerOrderLineItemSchema)
1364
+ });
1365
+ var CustomerOrderListSchema = zod.z.array(CustomerOrderListItemSchema);
1366
+ var CustomerOrderPaymentSchema = zod.z.object({
1367
+ id: zod.z.string(),
1368
+ paymentMethod: zod.z.string(),
1369
+ paymentCode: zod.z.string(),
1370
+ amount: zod.z.number(),
1371
+ paymentStatus: zod.z.string(),
1372
+ receiptUrl: zod.z.string().nullable().optional(),
1373
+ createdOn: zod.z.string()
1374
+ });
1375
+ var CustomerOrderStatusTimelineSchema = zod.z.object({
1376
+ key: zod.z.string(),
1377
+ label: zod.z.string(),
1378
+ occurredAt: zod.z.string(),
1379
+ description: zod.z.string().nullable().optional(),
1380
+ status: zod.z.string(),
1381
+ source: zod.z.string()
1382
+ });
1383
+ var CustomerOrderDetailSchema = zod.z.object({
1384
+ id: zod.z.coerce.string(),
1385
+ orderNumber: zod.z.string(),
1386
+ orderGroup: zod.z.string(),
1387
+ status: zod.z.string(),
1388
+ total: zod.z.number(),
1389
+ totalPaid: zod.z.number(),
1390
+ currencyCode: zod.z.string(),
1391
+ orderDate: zod.z.string(),
1392
+ createdOn: zod.z.string(),
1393
+ updatedOn: zod.z.string().nullable().optional(),
1394
+ paymentAt: zod.z.string().nullable().optional(),
1395
+ subTotal: zod.z.number(),
1396
+ discount: zod.z.number(),
1397
+ shipping: zod.z.number(),
1398
+ tax: zod.z.number(),
1399
+ email: zod.z.string(),
1400
+ phone: zod.z.string(),
1401
+ firstName: zod.z.string(),
1402
+ lastName: zod.z.string(),
1403
+ shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1404
+ shippingAddressSummary: zod.z.string().nullable().optional(),
1405
+ billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1406
+ items: zod.z.array(CustomerOrderLineItemSchema),
1407
+ payments: zod.z.array(CustomerOrderPaymentSchema),
1408
+ statusTimeline: zod.z.array(CustomerOrderStatusTimelineSchema)
1409
+ });
1410
+
1411
+ // src/services/customer-order.service.ts
1412
+ var ORDERS_PATH = "customer/orders";
1413
+ async function getCustomerOrders(api, options = {}) {
1414
+ return api.get(ORDERS_PATH, CustomerOrderListSchema, {
1415
+ headers: options.headers,
1416
+ signal: options.signal
1417
+ });
1418
+ }
1419
+ async function getCustomerOrder(api, orderId, options = {}) {
1420
+ const id = orderId.trim();
1421
+ if (!id) throw new Error("orderId requerido");
1422
+ return api.get(
1423
+ `${ORDERS_PATH}/${encodeURIComponent(id)}`,
1424
+ CustomerOrderDetailSchema,
1425
+ {
1426
+ headers: options.headers,
1427
+ signal: options.signal
1428
+ }
1429
+ );
1430
+ }
1157
1431
 
1158
1432
  // src/client.ts
1159
1433
  var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
@@ -1312,6 +1586,38 @@ function createClient(options) {
1312
1586
  async function getDistricts2(params) {
1313
1587
  return getDistricts(api, params);
1314
1588
  }
1589
+ async function getCustomerAddresses2(options2 = {}) {
1590
+ const client = await apiClient();
1591
+ return getCustomerAddresses(client, options2);
1592
+ }
1593
+ async function createCustomerAddress2(data, options2 = {}) {
1594
+ const client = await apiClient();
1595
+ return createCustomerAddress(client, data, options2);
1596
+ }
1597
+ async function updateCustomerAddress2(addressId, data, options2 = {}) {
1598
+ const client = await apiClient();
1599
+ return updateCustomerAddress(client, addressId, data, options2);
1600
+ }
1601
+ async function deleteCustomerAddress2(addressId, options2 = {}) {
1602
+ const client = await apiClient();
1603
+ return deleteCustomerAddress(client, addressId, options2);
1604
+ }
1605
+ async function getCustomerMe2(options2 = {}) {
1606
+ const client = await apiClient();
1607
+ return getCustomerMe(client, options2);
1608
+ }
1609
+ async function patchCustomer2(data, options2 = {}) {
1610
+ const client = await apiClient();
1611
+ return patchCustomer(client, data, options2);
1612
+ }
1613
+ async function getCustomerOrders2(options2 = {}) {
1614
+ const client = await apiClient();
1615
+ return getCustomerOrders(client, options2);
1616
+ }
1617
+ async function getCustomerOrder2(orderId, options2 = {}) {
1618
+ const client = await apiClient();
1619
+ return getCustomerOrder(client, orderId, options2);
1620
+ }
1315
1621
  return {
1316
1622
  ...api,
1317
1623
  getSettings,
@@ -1343,7 +1649,15 @@ function createClient(options) {
1343
1649
  getCountries: getCountries2,
1344
1650
  getDepartments: getDepartments2,
1345
1651
  getProvinces: getProvinces2,
1346
- getDistricts: getDistricts2
1652
+ getDistricts: getDistricts2,
1653
+ getCustomerAddresses: getCustomerAddresses2,
1654
+ createCustomerAddress: createCustomerAddress2,
1655
+ updateCustomerAddress: updateCustomerAddress2,
1656
+ deleteCustomerAddress: deleteCustomerAddress2,
1657
+ getCustomerMe: getCustomerMe2,
1658
+ patchCustomer: patchCustomer2,
1659
+ getCustomerOrders: getCustomerOrders2,
1660
+ getCustomerOrder: getCustomerOrder2
1347
1661
  };
1348
1662
  }
1349
1663
  var createStorefrontClient = createClient;