@ecomiq/core 0.1.2 → 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 (39) 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 +324 -10
  8. package/dist/client.cjs.map +1 -1
  9. package/dist/client.d.cts +13 -83
  10. package/dist/client.d.ts +13 -83
  11. package/dist/client.js +324 -10
  12. package/dist/client.js.map +1 -1
  13. package/dist/index.cjs +475 -10
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +4 -1
  16. package/dist/index.d.ts +4 -1
  17. package/dist/index.js +444 -11
  18. package/dist/index.js.map +1 -1
  19. package/dist/models/customer-address.cjs +41 -0
  20. package/dist/models/customer-address.cjs.map +1 -0
  21. package/dist/models/customer-address.d.cts +160 -0
  22. package/dist/models/customer-address.d.ts +160 -0
  23. package/dist/models/customer-address.js +36 -0
  24. package/dist/models/customer-address.js.map +1 -0
  25. package/dist/models/customer-order.cjs +161 -0
  26. package/dist/models/customer-order.cjs.map +1 -0
  27. package/dist/models/customer-order.d.cts +896 -0
  28. package/dist/models/customer-order.d.ts +896 -0
  29. package/dist/models/customer-order.js +149 -0
  30. package/dist/models/customer-order.js.map +1 -0
  31. package/dist/models/customer-profile.cjs +126 -0
  32. package/dist/models/customer-profile.cjs.map +1 -0
  33. package/dist/models/customer-profile.d.cts +178 -0
  34. package/dist/models/customer-profile.d.ts +178 -0
  35. package/dist/models/customer-profile.js +118 -0
  36. package/dist/models/customer-profile.js.map +1 -0
  37. package/dist/models/settings.d.cts +284 -284
  38. package/dist/models/settings.d.ts +284 -284
  39. package/package.json +16 -1
package/dist/client.d.cts CHANGED
@@ -1,84 +1,14 @@
1
- import { CreateApiOptions, Api } from './api.cjs';
2
- import { Collections, Collection } from './models/collections.cjs';
3
- import { ProductsParamsInput, ProductsResponse, ProductDetailParams, ProductDetail, RelatedProductsParams, ProductSummary } from './models/products.cjs';
4
- import { ProductAutocompleteParams, ProductSuggestion } from './models/search.cjs';
5
- import { ListProductReviewsParams, StorefrontReviews, CreateProductReviewParams, StorefrontReview } from './models/storefront-reviews.cjs';
6
- import { CreateCartParams, StorefrontCart, GetCartParams, AddCartItemParams, UpdateCartItemQuantityParams, RemoveCartItemParams } from './models/storefront-cart.cjs';
7
- import { CartCheckoutReadParams, CartCheckoutReadResponse, GetShippingOptionsParams, ShippingOptionsResponse, PutShippingMethodParams, CartBuyerParams, CartAddressesParams, CartCheckoutParams, CartCheckoutResponse, UploadPaymentReceiptParams, CartPaymentReceiptResponse, CartPromotionCodeParams } from './models/storefront-checkout.cjs';
8
- import { Countries, GetDepartmentsParams, Departments, GetProvincesParams, Provinces, GetDistrictsParams, Districts } from './models/geo.cjs';
9
- import { StorefrontSettings, CmsPageDetailsDto } from './models/settings.cjs';
1
+ import './api.cjs';
2
+ import './models/collections.cjs';
3
+ import './models/products.cjs';
4
+ import './models/search.cjs';
5
+ import './models/storefront-reviews.cjs';
6
+ import './models/storefront-cart.cjs';
7
+ import './models/storefront-checkout.cjs';
8
+ import './models/geo.cjs';
9
+ import './models/customer-address.cjs';
10
+ export { C as CreateClientOptions, S as StorefrontClient, f as createClient, h as createStorefrontClient } from './client-BpX4yR6S.cjs';
11
+ import './models/customer-profile.cjs';
12
+ import './models/customer-order.cjs';
13
+ import './models/settings.cjs';
10
14
  import 'zod';
11
-
12
- interface CreateClientOptions extends CreateApiOptions {
13
- /**
14
- * Slug de la tienda (header x-Store-Domain).
15
- * Debe venir de ecomiq.config.js (`config.slug`).
16
- */
17
- slug: string;
18
- settingsCacheTtlMs?: number;
19
- }
20
- interface StorefrontClient extends Api {
21
- getSettings(): Promise<StorefrontSettings>;
22
- /** store.id desde settings (asegura cache). */
23
- getStoreId(): Promise<string>;
24
- /** GET /v1/collections */
25
- getCollections(): Promise<Collections>;
26
- /** GET /v1/collections/by-slug/:slug */
27
- getCollectionBySlug(slug: string): Promise<Collection>;
28
- /** GET /v1/pages/{slug} */
29
- getPageBySlug(slug: string): Promise<CmsPageDetailsDto>;
30
- /** Invalida el cache de settings. */
31
- clearCache(): void;
32
- getProducts(params?: ProductsParamsInput): Promise<ProductsResponse>;
33
- /** GET product by slug con x-Store-Id. */
34
- getProductBySlug(slug: string, params?: ProductDetailParams): Promise<ProductDetail>;
35
- getRelatedProducts(params: RelatedProductsParams): Promise<ProductSummary[]>;
36
- autocompleteProducts(params: ProductAutocompleteParams): Promise<ProductSuggestion[]>;
37
- listProductReviews(params: ListProductReviewsParams): Promise<StorefrontReviews>;
38
- createProductReview(params: CreateProductReviewParams): Promise<StorefrontReview>;
39
- createCart(params: CreateCartParams): Promise<StorefrontCart>;
40
- getCart(params: GetCartParams): Promise<StorefrontCart>;
41
- addCartItem(params: AddCartItemParams): Promise<StorefrontCart>;
42
- updateCartItemQuantity(params: UpdateCartItemQuantityParams): Promise<StorefrontCart>;
43
- removeCartItem(params: RemoveCartItemParams): Promise<StorefrontCart>;
44
- /** GET /v1/carts/{id}/checkout */
45
- getCartCheckout(params: CartCheckoutReadParams): Promise<CartCheckoutReadResponse>;
46
- /** GET /v1/carts/{id}/shipping-options */
47
- getShippingOptions(params: GetShippingOptionsParams): Promise<ShippingOptionsResponse>;
48
- /** PUT /v1/carts/{id}/shipping-method */
49
- putCartShippingMethod(params: PutShippingMethodParams): Promise<StorefrontCart>;
50
- /** PATCH /v1/carts/{id}/buyer */
51
- patchCartBuyer(params: CartBuyerParams): Promise<StorefrontCart>;
52
- /** PATCH /v1/carts/{id}/addresses */
53
- patchCartAddresses(params: CartAddressesParams): Promise<StorefrontCart>;
54
- /** POST /v1/carts/{id}/checkout */
55
- checkoutCart(params: CartCheckoutParams): Promise<CartCheckoutResponse>;
56
- /** POST /v1/carts/{id}/payment-receipt */
57
- uploadPaymentReceipt(params: UploadPaymentReceiptParams): Promise<CartPaymentReceiptResponse>;
58
- /** POST /v1/carts/{id}/promotion-codes */
59
- addCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
60
- /** DELETE /v1/carts/{id}/promotion-codes/{code} */
61
- removeCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
62
- /** GET /v1/geo/countries */
63
- getCountries(): Promise<Countries>;
64
- /** GET /v1/geo/departments */
65
- getDepartments(params: GetDepartmentsParams): Promise<Departments>;
66
- /** GET /v1/geo/provinces */
67
- getProvinces(params: GetProvincesParams): Promise<Provinces>;
68
- /** GET /v1/geo/districts */
69
- getDistricts(params: GetDistrictsParams): Promise<Districts>;
70
- }
71
- /**
72
- * Crea el cliente storefront de bajo nivel (requiere slug).
73
- * En apps Ecomiq usa `createClient()` de `@ecomiq/storefront`, que toma el slug del config.
74
- *
75
- * ```ts
76
- * const api = createClient({ slug: 'marketplace' })
77
- * const collections = await api.getCollections()
78
- * ```
79
- */
80
- declare function createClient(options: CreateClientOptions): StorefrontClient;
81
- /** @deprecated Usa createClient. Alias de compatibilidad con el plan. */
82
- declare const createStorefrontClient: typeof createClient;
83
-
84
- export { type CreateClientOptions, type StorefrontClient, createClient, createStorefrontClient };
package/dist/client.d.ts CHANGED
@@ -1,84 +1,14 @@
1
- import { CreateApiOptions, Api } from './api.js';
2
- import { Collections, Collection } from './models/collections.js';
3
- import { ProductsParamsInput, ProductsResponse, ProductDetailParams, ProductDetail, RelatedProductsParams, ProductSummary } from './models/products.js';
4
- import { ProductAutocompleteParams, ProductSuggestion } from './models/search.js';
5
- import { ListProductReviewsParams, StorefrontReviews, CreateProductReviewParams, StorefrontReview } from './models/storefront-reviews.js';
6
- import { CreateCartParams, StorefrontCart, GetCartParams, AddCartItemParams, UpdateCartItemQuantityParams, RemoveCartItemParams } from './models/storefront-cart.js';
7
- import { CartCheckoutReadParams, CartCheckoutReadResponse, GetShippingOptionsParams, ShippingOptionsResponse, PutShippingMethodParams, CartBuyerParams, CartAddressesParams, CartCheckoutParams, CartCheckoutResponse, UploadPaymentReceiptParams, CartPaymentReceiptResponse, CartPromotionCodeParams } from './models/storefront-checkout.js';
8
- import { Countries, GetDepartmentsParams, Departments, GetProvincesParams, Provinces, GetDistrictsParams, Districts } from './models/geo.js';
9
- import { StorefrontSettings, CmsPageDetailsDto } from './models/settings.js';
1
+ import './api.js';
2
+ import './models/collections.js';
3
+ import './models/products.js';
4
+ import './models/search.js';
5
+ import './models/storefront-reviews.js';
6
+ import './models/storefront-cart.js';
7
+ import './models/storefront-checkout.js';
8
+ import './models/geo.js';
9
+ import './models/customer-address.js';
10
+ export { C as CreateClientOptions, S as StorefrontClient, f as createClient, h as createStorefrontClient } from './client-4ZTG2RZ3.js';
11
+ import './models/customer-profile.js';
12
+ import './models/customer-order.js';
13
+ import './models/settings.js';
10
14
  import 'zod';
11
-
12
- interface CreateClientOptions extends CreateApiOptions {
13
- /**
14
- * Slug de la tienda (header x-Store-Domain).
15
- * Debe venir de ecomiq.config.js (`config.slug`).
16
- */
17
- slug: string;
18
- settingsCacheTtlMs?: number;
19
- }
20
- interface StorefrontClient extends Api {
21
- getSettings(): Promise<StorefrontSettings>;
22
- /** store.id desde settings (asegura cache). */
23
- getStoreId(): Promise<string>;
24
- /** GET /v1/collections */
25
- getCollections(): Promise<Collections>;
26
- /** GET /v1/collections/by-slug/:slug */
27
- getCollectionBySlug(slug: string): Promise<Collection>;
28
- /** GET /v1/pages/{slug} */
29
- getPageBySlug(slug: string): Promise<CmsPageDetailsDto>;
30
- /** Invalida el cache de settings. */
31
- clearCache(): void;
32
- getProducts(params?: ProductsParamsInput): Promise<ProductsResponse>;
33
- /** GET product by slug con x-Store-Id. */
34
- getProductBySlug(slug: string, params?: ProductDetailParams): Promise<ProductDetail>;
35
- getRelatedProducts(params: RelatedProductsParams): Promise<ProductSummary[]>;
36
- autocompleteProducts(params: ProductAutocompleteParams): Promise<ProductSuggestion[]>;
37
- listProductReviews(params: ListProductReviewsParams): Promise<StorefrontReviews>;
38
- createProductReview(params: CreateProductReviewParams): Promise<StorefrontReview>;
39
- createCart(params: CreateCartParams): Promise<StorefrontCart>;
40
- getCart(params: GetCartParams): Promise<StorefrontCart>;
41
- addCartItem(params: AddCartItemParams): Promise<StorefrontCart>;
42
- updateCartItemQuantity(params: UpdateCartItemQuantityParams): Promise<StorefrontCart>;
43
- removeCartItem(params: RemoveCartItemParams): Promise<StorefrontCart>;
44
- /** GET /v1/carts/{id}/checkout */
45
- getCartCheckout(params: CartCheckoutReadParams): Promise<CartCheckoutReadResponse>;
46
- /** GET /v1/carts/{id}/shipping-options */
47
- getShippingOptions(params: GetShippingOptionsParams): Promise<ShippingOptionsResponse>;
48
- /** PUT /v1/carts/{id}/shipping-method */
49
- putCartShippingMethod(params: PutShippingMethodParams): Promise<StorefrontCart>;
50
- /** PATCH /v1/carts/{id}/buyer */
51
- patchCartBuyer(params: CartBuyerParams): Promise<StorefrontCart>;
52
- /** PATCH /v1/carts/{id}/addresses */
53
- patchCartAddresses(params: CartAddressesParams): Promise<StorefrontCart>;
54
- /** POST /v1/carts/{id}/checkout */
55
- checkoutCart(params: CartCheckoutParams): Promise<CartCheckoutResponse>;
56
- /** POST /v1/carts/{id}/payment-receipt */
57
- uploadPaymentReceipt(params: UploadPaymentReceiptParams): Promise<CartPaymentReceiptResponse>;
58
- /** POST /v1/carts/{id}/promotion-codes */
59
- addCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
60
- /** DELETE /v1/carts/{id}/promotion-codes/{code} */
61
- removeCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
62
- /** GET /v1/geo/countries */
63
- getCountries(): Promise<Countries>;
64
- /** GET /v1/geo/departments */
65
- getDepartments(params: GetDepartmentsParams): Promise<Departments>;
66
- /** GET /v1/geo/provinces */
67
- getProvinces(params: GetProvincesParams): Promise<Provinces>;
68
- /** GET /v1/geo/districts */
69
- getDistricts(params: GetDistrictsParams): Promise<Districts>;
70
- }
71
- /**
72
- * Crea el cliente storefront de bajo nivel (requiere slug).
73
- * En apps Ecomiq usa `createClient()` de `@ecomiq/storefront`, que toma el slug del config.
74
- *
75
- * ```ts
76
- * const api = createClient({ slug: 'marketplace' })
77
- * const collections = await api.getCollections()
78
- * ```
79
- */
80
- declare function createClient(options: CreateClientOptions): StorefrontClient;
81
- /** @deprecated Usa createClient. Alias de compatibilidad con el plan. */
82
- declare const createStorefrontClient: typeof createClient;
83
-
84
- export { type CreateClientOptions, type StorefrontClient, createClient, createStorefrontClient };
package/dist/client.js CHANGED
@@ -18,6 +18,7 @@ var ApiError = class extends Error {
18
18
  function resolveApiBaseUrl(baseUrl = DEFAULT_API_BASE_URL, version = DEFAULT_API_VERSION) {
19
19
  const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
20
20
  const segment = version.replace(/^\/+|\/+$/g, "");
21
+ if (!segment) return root;
21
22
  return new URL(`${segment}/`, root).toString();
22
23
  }
23
24
  function createApi(options = {}) {
@@ -60,17 +61,30 @@ function createApi(options = {}) {
60
61
  clearTimeout(timeout);
61
62
  }
62
63
  if (!response.ok) {
63
- const bodyText = await response.text().catch(() => void 0);
64
- let body = bodyText;
65
- if (bodyText) {
64
+ const bodyText2 = await response.text().catch(() => void 0);
65
+ let body = bodyText2;
66
+ if (bodyText2) {
66
67
  try {
67
- body = JSON.parse(bodyText);
68
+ body = JSON.parse(bodyText2);
68
69
  } catch {
69
70
  }
70
71
  }
71
72
  throw new ApiError(`${method} ${url} \u2192 ${response.status}`, response.status, url.toString(), body);
72
73
  }
73
- const json = await response.json();
74
+ const bodyText = await response.text();
75
+ let json = null;
76
+ if (bodyText.trim()) {
77
+ try {
78
+ json = JSON.parse(bodyText);
79
+ } catch {
80
+ throw new ApiError(
81
+ `Respuesta no JSON de ${url}`,
82
+ response.status,
83
+ url.toString(),
84
+ bodyText
85
+ );
86
+ }
87
+ }
74
88
  const parsed = schema.safeParse(json);
75
89
  if (!parsed.success) {
76
90
  throw new ApiError(
@@ -1152,17 +1166,277 @@ async function getDistricts(api, params) {
1152
1166
  }
1153
1167
  });
1154
1168
  }
1169
+ var CustomerAddressUpsertInputSchema = z.object({
1170
+ addressKey: z.string().trim().min(1),
1171
+ countryIsoCode: z.string().trim().length(2),
1172
+ addressLine: z.string().trim().min(1),
1173
+ addressNumber: z.string().trim().min(1),
1174
+ department: z.string().trim().min(1),
1175
+ province: z.string().trim().min(1),
1176
+ district: z.string().trim().min(1),
1177
+ phone: z.string().trim(),
1178
+ cellPhone: z.string().trim(),
1179
+ postalCode: z.string().trim().min(1),
1180
+ reference: z.string().trim(),
1181
+ latitude: z.number().nullable(),
1182
+ longitude: z.number().nullable(),
1183
+ isDefault: z.boolean()
1184
+ });
1185
+ var CustomerAddressSchema = CustomerAddressUpsertInputSchema.extend({
1186
+ id: z.union([z.string(), z.number()]).transform(String).optional()
1187
+ });
1188
+ var CustomerAddressesSchema = z.array(CustomerAddressSchema);
1189
+
1190
+ // src/services/customer-address.service.ts
1191
+ var ADDRESSES_PATH = "customer/addresses";
1192
+ var CustomerAddressMutationResponseSchema = z.union([
1193
+ CustomerAddressSchema,
1194
+ z.object({
1195
+ id: z.union([z.string(), z.number()]).transform(String)
1196
+ }),
1197
+ z.null()
1198
+ ]);
1199
+ async function getCustomerAddresses(api, options = {}) {
1200
+ return api.get(ADDRESSES_PATH, CustomerAddressesSchema, {
1201
+ headers: options.headers,
1202
+ signal: options.signal
1203
+ });
1204
+ }
1205
+ async function createCustomerAddress(api, data, options = {}) {
1206
+ const payload = CustomerAddressUpsertInputSchema.parse(data);
1207
+ return api.post(ADDRESSES_PATH, payload, CustomerAddressMutationResponseSchema, {
1208
+ headers: options.headers,
1209
+ signal: options.signal
1210
+ });
1211
+ }
1212
+ async function updateCustomerAddress(api, addressId, data, options = {}) {
1213
+ const id = addressId.trim();
1214
+ if (!id) throw new Error("addressId requerido");
1215
+ const payload = CustomerAddressUpsertInputSchema.parse(data);
1216
+ return api.request(
1217
+ "PUT",
1218
+ `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1219
+ CustomerAddressMutationResponseSchema,
1220
+ {
1221
+ body: payload,
1222
+ headers: options.headers,
1223
+ signal: options.signal
1224
+ }
1225
+ );
1226
+ }
1227
+ async function deleteCustomerAddress(api, addressId, options = {}) {
1228
+ const id = addressId.trim();
1229
+ if (!id) throw new Error("addressId requerido");
1230
+ await api.request(
1231
+ "DELETE",
1232
+ `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1233
+ z.null(),
1234
+ {
1235
+ headers: options.headers,
1236
+ signal: options.signal
1237
+ }
1238
+ );
1239
+ }
1240
+ var DEFAULT_COUNTRY_CODE = "PE";
1241
+ z.object({
1242
+ email: z.string().email(),
1243
+ firstName: z.string().trim().min(1),
1244
+ lastName: z.string().trim().min(1),
1245
+ countryIsoCode: z.string().trim().length(2),
1246
+ password: z.string().min(1),
1247
+ phone: z.string().trim().min(1).optional()
1248
+ });
1249
+ var CustomerProfilePatchSchema = z.object({
1250
+ firstName: z.string().trim().min(1),
1251
+ lastName: z.string().trim().min(1),
1252
+ phone: z.string().trim(),
1253
+ identificationNumber: z.string().nullable(),
1254
+ identificationType: z.string().nullable(),
1255
+ entityName: z.string().nullable(),
1256
+ entityIdentificationNumber: z.string().nullable(),
1257
+ gender: z.string().nullable(),
1258
+ role: z.string().nullable(),
1259
+ companyName: z.string().nullable(),
1260
+ dateOfBirth: z.string().nullable(),
1261
+ consent: z.boolean(),
1262
+ countryIsoCode: z.string().trim().length(2)
1263
+ });
1264
+ z.object({
1265
+ firstName: z.string(),
1266
+ lastName: z.string(),
1267
+ phone: z.string(),
1268
+ email: z.string().email(),
1269
+ identificationNumber: z.string().nullable(),
1270
+ identificationType: z.string().nullable(),
1271
+ countryIsoCode: z.string(),
1272
+ consent: z.boolean(),
1273
+ entityName: z.string().nullable(),
1274
+ entityIdentificationNumber: z.string().nullable(),
1275
+ gender: z.string().nullable(),
1276
+ role: z.string().nullable(),
1277
+ companyName: z.string().nullable(),
1278
+ dateOfBirth: z.string().nullable()
1279
+ });
1280
+ var nullableString = z.string().nullable().optional().transform((v) => v ?? null);
1281
+ var CustomerMeSchema = z.object({
1282
+ id: z.union([z.string(), z.number()]),
1283
+ storeId: z.string().optional(),
1284
+ email: z.string().email(),
1285
+ firstName: z.string(),
1286
+ lastName: z.string(),
1287
+ phone: z.union([z.string(), z.null()]).optional().transform((v) => v ?? ""),
1288
+ identificationNumber: nullableString,
1289
+ identificationType: nullableString,
1290
+ entityName: nullableString,
1291
+ entityIdentificationNumber: nullableString,
1292
+ gender: nullableString,
1293
+ role: nullableString,
1294
+ companyName: nullableString,
1295
+ dateOfBirth: nullableString,
1296
+ countryIsoCode: z.string().optional().transform((v) => v?.trim().length === 2 ? v.trim() : DEFAULT_COUNTRY_CODE),
1297
+ consent: z.boolean().optional().transform((v) => v ?? false)
1298
+ }).passthrough();
1299
+
1300
+ // src/services/customer.service.ts
1301
+ var CUSTOMER_PATH = "customer";
1302
+ async function getCustomerMe(api, options = {}) {
1303
+ return api.get(CUSTOMER_PATH, CustomerMeSchema, {
1304
+ headers: options.headers,
1305
+ signal: options.signal
1306
+ });
1307
+ }
1308
+ async function patchCustomer(api, data, options = {}) {
1309
+ const payload = CustomerProfilePatchSchema.parse(data);
1310
+ await api.request("PATCH", CUSTOMER_PATH, z.null(), {
1311
+ body: payload,
1312
+ headers: options.headers,
1313
+ signal: options.signal
1314
+ });
1315
+ }
1316
+ var CustomerOrderShippingAddressSchema = z.object({
1317
+ name: z.string().nullable().optional(),
1318
+ company: z.string().nullable().optional(),
1319
+ address1: z.string(),
1320
+ address2: z.string().nullable().optional(),
1321
+ city: z.string().nullable().optional(),
1322
+ countryCode: z.string().min(2).max(2),
1323
+ province: z.string().nullable().optional(),
1324
+ postalCode: z.string().nullable().optional(),
1325
+ district: z.string().nullable().optional(),
1326
+ phone: z.string().nullable().optional(),
1327
+ latitude: z.number().nullable().optional(),
1328
+ longitude: z.number().nullable().optional(),
1329
+ metadata: z.record(z.unknown()).nullable().optional()
1330
+ }).passthrough();
1331
+ var CustomerOrderLineItemSchema = z.object({
1332
+ id: z.string(),
1333
+ orderId: z.coerce.string(),
1334
+ productId: z.coerce.string().nullable(),
1335
+ variantId: z.coerce.string().nullable(),
1336
+ title: z.string(),
1337
+ subtitle: z.string().nullable().optional(),
1338
+ thumbnail: z.string().nullable().optional(),
1339
+ variantTitle: z.string().nullable().optional(),
1340
+ productHandle: z.string().nullable().optional(),
1341
+ quantity: z.number(),
1342
+ unitPrice: z.number(),
1343
+ total: z.number(),
1344
+ status: z.string()
1345
+ });
1346
+ var CustomerOrderListItemSchema = z.object({
1347
+ orderId: z.coerce.string(),
1348
+ orderNumber: z.string(),
1349
+ orderGroup: z.string(),
1350
+ orderIds: z.array(z.coerce.string()),
1351
+ status: z.string(),
1352
+ total: z.number(),
1353
+ totalPaid: z.number(),
1354
+ currencyCode: z.string(),
1355
+ orderDate: z.string(),
1356
+ createdOn: z.string(),
1357
+ updatedOn: z.string().nullable().optional(),
1358
+ paymentAt: z.string().nullable().optional(),
1359
+ shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1360
+ shippingAddressSummary: z.string().nullable().optional(),
1361
+ items: z.array(CustomerOrderLineItemSchema)
1362
+ });
1363
+ var CustomerOrderListSchema = z.array(CustomerOrderListItemSchema);
1364
+ var CustomerOrderPaymentSchema = z.object({
1365
+ id: z.string(),
1366
+ paymentMethod: z.string(),
1367
+ paymentCode: z.string(),
1368
+ amount: z.number(),
1369
+ paymentStatus: z.string(),
1370
+ receiptUrl: z.string().nullable().optional(),
1371
+ createdOn: z.string()
1372
+ });
1373
+ var CustomerOrderStatusTimelineSchema = z.object({
1374
+ key: z.string(),
1375
+ label: z.string(),
1376
+ occurredAt: z.string(),
1377
+ description: z.string().nullable().optional(),
1378
+ status: z.string(),
1379
+ source: z.string()
1380
+ });
1381
+ var CustomerOrderDetailSchema = z.object({
1382
+ id: z.coerce.string(),
1383
+ orderNumber: z.string(),
1384
+ orderGroup: z.string(),
1385
+ status: z.string(),
1386
+ total: z.number(),
1387
+ totalPaid: z.number(),
1388
+ currencyCode: z.string(),
1389
+ orderDate: z.string(),
1390
+ createdOn: z.string(),
1391
+ updatedOn: z.string().nullable().optional(),
1392
+ paymentAt: z.string().nullable().optional(),
1393
+ subTotal: z.number(),
1394
+ discount: z.number(),
1395
+ shipping: z.number(),
1396
+ tax: z.number(),
1397
+ email: z.string(),
1398
+ phone: z.string(),
1399
+ firstName: z.string(),
1400
+ lastName: z.string(),
1401
+ shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1402
+ shippingAddressSummary: z.string().nullable().optional(),
1403
+ billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1404
+ items: z.array(CustomerOrderLineItemSchema),
1405
+ payments: z.array(CustomerOrderPaymentSchema),
1406
+ statusTimeline: z.array(CustomerOrderStatusTimelineSchema)
1407
+ });
1408
+
1409
+ // src/services/customer-order.service.ts
1410
+ var ORDERS_PATH = "customer/orders";
1411
+ async function getCustomerOrders(api, options = {}) {
1412
+ return api.get(ORDERS_PATH, CustomerOrderListSchema, {
1413
+ headers: options.headers,
1414
+ signal: options.signal
1415
+ });
1416
+ }
1417
+ async function getCustomerOrder(api, orderId, options = {}) {
1418
+ const id = orderId.trim();
1419
+ if (!id) throw new Error("orderId requerido");
1420
+ return api.get(
1421
+ `${ORDERS_PATH}/${encodeURIComponent(id)}`,
1422
+ CustomerOrderDetailSchema,
1423
+ {
1424
+ headers: options.headers,
1425
+ signal: options.signal
1426
+ }
1427
+ );
1428
+ }
1155
1429
 
1156
1430
  // src/client.ts
1157
1431
  var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
1158
1432
  function createClient(options) {
1159
1433
  const {
1160
- slug,
1434
+ domain,
1161
1435
  settingsCacheTtlMs = DEFAULT_SETTINGS_CACHE_TTL_MS,
1162
1436
  ...apiOptions
1163
1437
  } = options;
1164
- if (!slug?.trim()) {
1165
- throw new Error("createClient requiere `slug` (config.slug de ecomiq.config.js)");
1438
+ if (!domain?.trim()) {
1439
+ throw new Error("createClient requiere `domain` (config.domain de ecomiq.config.js)");
1166
1440
  }
1167
1441
  if (!Number.isFinite(settingsCacheTtlMs) || settingsCacheTtlMs < 0) {
1168
1442
  throw new Error("settingsCacheTtlMs debe ser un n\xFAmero mayor o igual a 0");
@@ -1190,7 +1464,7 @@ function createClient(options) {
1190
1464
  if (inflight) return inflight;
1191
1465
  const previous = cache?.data;
1192
1466
  inflight = api.get("settings", StorefrontSettingsSchema, {
1193
- headers: { "x-Store-Domain": slug }
1467
+ headers: { "x-Store-Domain": domain }
1194
1468
  }).then((data) => {
1195
1469
  cache = { data, expiresAt: Date.now() + settingsCacheTtlMs };
1196
1470
  return data;
@@ -1310,6 +1584,38 @@ function createClient(options) {
1310
1584
  async function getDistricts2(params) {
1311
1585
  return getDistricts(api, params);
1312
1586
  }
1587
+ async function getCustomerAddresses2(options2 = {}) {
1588
+ const client = await apiClient();
1589
+ return getCustomerAddresses(client, options2);
1590
+ }
1591
+ async function createCustomerAddress2(data, options2 = {}) {
1592
+ const client = await apiClient();
1593
+ return createCustomerAddress(client, data, options2);
1594
+ }
1595
+ async function updateCustomerAddress2(addressId, data, options2 = {}) {
1596
+ const client = await apiClient();
1597
+ return updateCustomerAddress(client, addressId, data, options2);
1598
+ }
1599
+ async function deleteCustomerAddress2(addressId, options2 = {}) {
1600
+ const client = await apiClient();
1601
+ return deleteCustomerAddress(client, addressId, options2);
1602
+ }
1603
+ async function getCustomerMe2(options2 = {}) {
1604
+ const client = await apiClient();
1605
+ return getCustomerMe(client, options2);
1606
+ }
1607
+ async function patchCustomer2(data, options2 = {}) {
1608
+ const client = await apiClient();
1609
+ return patchCustomer(client, data, options2);
1610
+ }
1611
+ async function getCustomerOrders2(options2 = {}) {
1612
+ const client = await apiClient();
1613
+ return getCustomerOrders(client, options2);
1614
+ }
1615
+ async function getCustomerOrder2(orderId, options2 = {}) {
1616
+ const client = await apiClient();
1617
+ return getCustomerOrder(client, orderId, options2);
1618
+ }
1313
1619
  return {
1314
1620
  ...api,
1315
1621
  getSettings,
@@ -1341,7 +1647,15 @@ function createClient(options) {
1341
1647
  getCountries: getCountries2,
1342
1648
  getDepartments: getDepartments2,
1343
1649
  getProvinces: getProvinces2,
1344
- getDistricts: getDistricts2
1650
+ getDistricts: getDistricts2,
1651
+ getCustomerAddresses: getCustomerAddresses2,
1652
+ createCustomerAddress: createCustomerAddress2,
1653
+ updateCustomerAddress: updateCustomerAddress2,
1654
+ deleteCustomerAddress: deleteCustomerAddress2,
1655
+ getCustomerMe: getCustomerMe2,
1656
+ patchCustomer: patchCustomer2,
1657
+ getCustomerOrders: getCustomerOrders2,
1658
+ getCustomerOrder: getCustomerOrder2
1345
1659
  };
1346
1660
  }
1347
1661
  var createStorefrontClient = createClient;