@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.
Files changed (57) 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 +331 -12
  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 +331 -12
  12. package/dist/client.js.map +1 -1
  13. package/dist/index.cjs +484 -12
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +327 -324
  16. package/dist/index.d.ts +327 -324
  17. package/dist/index.js +451 -13
  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.cjs +13 -6
  46. package/dist/models/settings.cjs.map +1 -1
  47. package/dist/models/settings.d.cts +844 -841
  48. package/dist/models/settings.d.ts +844 -841
  49. package/dist/models/settings.js +12 -7
  50. package/dist/models/settings.js.map +1 -1
  51. package/dist/models/storefront-cart.d.cts +80 -80
  52. package/dist/models/storefront-cart.d.ts +80 -80
  53. package/dist/models/storefront-checkout.d.cts +400 -400
  54. package/dist/models/storefront-checkout.d.ts +400 -400
  55. package/dist/models/storefront-reviews.d.cts +8 -8
  56. package/dist/models/storefront-reviews.d.ts +8 -8
  57. package/package.json +16 -1
package/dist/client.d.cts CHANGED
@@ -1,85 +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
- * Dominio/slug de la tienda (header x-Store-Domain).
15
- * Debe venir de ecomiq.config.js (`config.domain`).
16
- * Acepta `marketplace`, `marketplace.ecomiq.app` o `marketplace.pe`.
17
- */
18
- domain: string;
19
- settingsCacheTtlMs?: number;
20
- }
21
- interface StorefrontClient extends Api {
22
- getSettings(): Promise<StorefrontSettings>;
23
- /** store.id desde settings (asegura cache). */
24
- getStoreId(): Promise<string>;
25
- /** GET /v1/collections */
26
- getCollections(): Promise<Collections>;
27
- /** GET /v1/collections/by-slug/:slug */
28
- getCollectionBySlug(slug: string): Promise<Collection>;
29
- /** GET /v1/pages/{slug} */
30
- getPageBySlug(slug: string): Promise<CmsPageDetailsDto>;
31
- /** Invalida el cache de settings. */
32
- clearCache(): void;
33
- getProducts(params?: ProductsParamsInput): Promise<ProductsResponse>;
34
- /** GET product by slug con x-Store-Id. */
35
- getProductBySlug(slug: string, params?: ProductDetailParams): Promise<ProductDetail>;
36
- getRelatedProducts(params: RelatedProductsParams): Promise<ProductSummary[]>;
37
- autocompleteProducts(params: ProductAutocompleteParams): Promise<ProductSuggestion[]>;
38
- listProductReviews(params: ListProductReviewsParams): Promise<StorefrontReviews>;
39
- createProductReview(params: CreateProductReviewParams): Promise<StorefrontReview>;
40
- createCart(params: CreateCartParams): Promise<StorefrontCart>;
41
- getCart(params: GetCartParams): Promise<StorefrontCart>;
42
- addCartItem(params: AddCartItemParams): Promise<StorefrontCart>;
43
- updateCartItemQuantity(params: UpdateCartItemQuantityParams): Promise<StorefrontCart>;
44
- removeCartItem(params: RemoveCartItemParams): Promise<StorefrontCart>;
45
- /** GET /v1/carts/{id}/checkout */
46
- getCartCheckout(params: CartCheckoutReadParams): Promise<CartCheckoutReadResponse>;
47
- /** GET /v1/carts/{id}/shipping-options */
48
- getShippingOptions(params: GetShippingOptionsParams): Promise<ShippingOptionsResponse>;
49
- /** PUT /v1/carts/{id}/shipping-method */
50
- putCartShippingMethod(params: PutShippingMethodParams): Promise<StorefrontCart>;
51
- /** PATCH /v1/carts/{id}/buyer */
52
- patchCartBuyer(params: CartBuyerParams): Promise<StorefrontCart>;
53
- /** PATCH /v1/carts/{id}/addresses */
54
- patchCartAddresses(params: CartAddressesParams): Promise<StorefrontCart>;
55
- /** POST /v1/carts/{id}/checkout */
56
- checkoutCart(params: CartCheckoutParams): Promise<CartCheckoutResponse>;
57
- /** POST /v1/carts/{id}/payment-receipt */
58
- uploadPaymentReceipt(params: UploadPaymentReceiptParams): Promise<CartPaymentReceiptResponse>;
59
- /** POST /v1/carts/{id}/promotion-codes */
60
- addCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
61
- /** DELETE /v1/carts/{id}/promotion-codes/{code} */
62
- removeCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
63
- /** GET /v1/geo/countries */
64
- getCountries(): Promise<Countries>;
65
- /** GET /v1/geo/departments */
66
- getDepartments(params: GetDepartmentsParams): Promise<Departments>;
67
- /** GET /v1/geo/provinces */
68
- getProvinces(params: GetProvincesParams): Promise<Provinces>;
69
- /** GET /v1/geo/districts */
70
- getDistricts(params: GetDistrictsParams): Promise<Districts>;
71
- }
72
- /**
73
- * Crea el cliente storefront de bajo nivel (requiere domain).
74
- * En apps Ecomiq usa `createClient()` de `@ecomiq/storefront`, que toma el domain del config.
75
- *
76
- * ```ts
77
- * const api = createClient({ domain: 'marketplace' })
78
- * const collections = await api.getCollections()
79
- * ```
80
- */
81
- declare function createClient(options: CreateClientOptions): StorefrontClient;
82
- /** @deprecated Usa createClient. Alias de compatibilidad con el plan. */
83
- declare const createStorefrontClient: typeof createClient;
84
-
85
- export { type CreateClientOptions, type StorefrontClient, createClient, createStorefrontClient };
package/dist/client.d.ts CHANGED
@@ -1,85 +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
- * Dominio/slug de la tienda (header x-Store-Domain).
15
- * Debe venir de ecomiq.config.js (`config.domain`).
16
- * Acepta `marketplace`, `marketplace.ecomiq.app` o `marketplace.pe`.
17
- */
18
- domain: string;
19
- settingsCacheTtlMs?: number;
20
- }
21
- interface StorefrontClient extends Api {
22
- getSettings(): Promise<StorefrontSettings>;
23
- /** store.id desde settings (asegura cache). */
24
- getStoreId(): Promise<string>;
25
- /** GET /v1/collections */
26
- getCollections(): Promise<Collections>;
27
- /** GET /v1/collections/by-slug/:slug */
28
- getCollectionBySlug(slug: string): Promise<Collection>;
29
- /** GET /v1/pages/{slug} */
30
- getPageBySlug(slug: string): Promise<CmsPageDetailsDto>;
31
- /** Invalida el cache de settings. */
32
- clearCache(): void;
33
- getProducts(params?: ProductsParamsInput): Promise<ProductsResponse>;
34
- /** GET product by slug con x-Store-Id. */
35
- getProductBySlug(slug: string, params?: ProductDetailParams): Promise<ProductDetail>;
36
- getRelatedProducts(params: RelatedProductsParams): Promise<ProductSummary[]>;
37
- autocompleteProducts(params: ProductAutocompleteParams): Promise<ProductSuggestion[]>;
38
- listProductReviews(params: ListProductReviewsParams): Promise<StorefrontReviews>;
39
- createProductReview(params: CreateProductReviewParams): Promise<StorefrontReview>;
40
- createCart(params: CreateCartParams): Promise<StorefrontCart>;
41
- getCart(params: GetCartParams): Promise<StorefrontCart>;
42
- addCartItem(params: AddCartItemParams): Promise<StorefrontCart>;
43
- updateCartItemQuantity(params: UpdateCartItemQuantityParams): Promise<StorefrontCart>;
44
- removeCartItem(params: RemoveCartItemParams): Promise<StorefrontCart>;
45
- /** GET /v1/carts/{id}/checkout */
46
- getCartCheckout(params: CartCheckoutReadParams): Promise<CartCheckoutReadResponse>;
47
- /** GET /v1/carts/{id}/shipping-options */
48
- getShippingOptions(params: GetShippingOptionsParams): Promise<ShippingOptionsResponse>;
49
- /** PUT /v1/carts/{id}/shipping-method */
50
- putCartShippingMethod(params: PutShippingMethodParams): Promise<StorefrontCart>;
51
- /** PATCH /v1/carts/{id}/buyer */
52
- patchCartBuyer(params: CartBuyerParams): Promise<StorefrontCart>;
53
- /** PATCH /v1/carts/{id}/addresses */
54
- patchCartAddresses(params: CartAddressesParams): Promise<StorefrontCart>;
55
- /** POST /v1/carts/{id}/checkout */
56
- checkoutCart(params: CartCheckoutParams): Promise<CartCheckoutResponse>;
57
- /** POST /v1/carts/{id}/payment-receipt */
58
- uploadPaymentReceipt(params: UploadPaymentReceiptParams): Promise<CartPaymentReceiptResponse>;
59
- /** POST /v1/carts/{id}/promotion-codes */
60
- addCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
61
- /** DELETE /v1/carts/{id}/promotion-codes/{code} */
62
- removeCartPromotionCode(params: CartPromotionCodeParams): Promise<StorefrontCart>;
63
- /** GET /v1/geo/countries */
64
- getCountries(): Promise<Countries>;
65
- /** GET /v1/geo/departments */
66
- getDepartments(params: GetDepartmentsParams): Promise<Departments>;
67
- /** GET /v1/geo/provinces */
68
- getProvinces(params: GetProvincesParams): Promise<Provinces>;
69
- /** GET /v1/geo/districts */
70
- getDistricts(params: GetDistrictsParams): Promise<Districts>;
71
- }
72
- /**
73
- * Crea el cliente storefront de bajo nivel (requiere domain).
74
- * En apps Ecomiq usa `createClient()` de `@ecomiq/storefront`, que toma el domain del config.
75
- *
76
- * ```ts
77
- * const api = createClient({ domain: 'marketplace' })
78
- * const collections = await api.getCollections()
79
- * ```
80
- */
81
- declare function createClient(options: CreateClientOptions): StorefrontClient;
82
- /** @deprecated Usa createClient. Alias de compatibilidad con el plan. */
83
- declare const createStorefrontClient: typeof createClient;
84
-
85
- 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(
@@ -287,6 +301,11 @@ var JsonElementSchema = z.lazy(
287
301
  var DateTimeOffsetSchema = z.string().datetime({ offset: true });
288
302
  var NullableDateTimeOffsetSchema = DateTimeOffsetSchema.nullable();
289
303
  var NullableUuidSchema = z.string().uuid().nullable();
304
+ var EntityIdSchema = z.union([
305
+ z.string().uuid(),
306
+ z.string().regex(/^\d+$/, "Expected numeric id")
307
+ ]);
308
+ var NullableEntityIdSchema = EntityIdSchema.nullable();
290
309
  var StoreTypeSchema = z.enum([
291
310
  "b2C",
292
311
  "marketplace",
@@ -349,9 +368,9 @@ var StoreCheckoutSettingsSchema = z.object({
349
368
  ordersAndPayments: StoreCheckoutOrdersAndPaymentsSettingsSchema
350
369
  }).strict();
351
370
  var StorefrontStoreShape = {
352
- id: z.string().uuid(),
353
- tenantId: z.string().uuid(),
354
- sellerId: NullableUuidSchema,
371
+ id: EntityIdSchema,
372
+ tenantId: EntityIdSchema,
373
+ sellerId: NullableEntityIdSchema,
355
374
  type: StoreTypeSchema,
356
375
  isActive: z.boolean(),
357
376
  name: z.string(),
@@ -432,13 +451,13 @@ var CmsMenuDtoSchema = z.object({
432
451
  items: z.array(CmsMenuItemSchema)
433
452
  }).strict();
434
453
  var CmsBlockDtoSchema = z.object({
435
- id: z.string().uuid(),
454
+ id: EntityIdSchema,
436
455
  type: z.string(),
437
456
  order: z.number().int(),
438
457
  settings: JsonElementSchema
439
458
  }).strict();
440
459
  var CmsSectionDtoSchema = z.object({
441
- id: z.string().uuid(),
460
+ id: EntityIdSchema,
442
461
  type: z.string(),
443
462
  order: z.number().int(),
444
463
  settings: JsonElementSchema,
@@ -447,7 +466,7 @@ var CmsSectionDtoSchema = z.object({
447
466
  var CmsContentChannelSchema = z.enum(["storefront", "pos"]);
448
467
  var CmsPageStatusSchema = z.enum(["draft", "published", "archived"]);
449
468
  var CmsPageDetailsDtoSchema = z.object({
450
- id: z.string().uuid(),
469
+ id: EntityIdSchema,
451
470
  name: z.string(),
452
471
  slug: z.string(),
453
472
  channel: CmsContentChannelSchema,
@@ -1152,6 +1171,266 @@ async function getDistricts(api, params) {
1152
1171
  }
1153
1172
  });
1154
1173
  }
1174
+ var CustomerAddressUpsertInputSchema = z.object({
1175
+ addressKey: z.string().trim().min(1),
1176
+ countryIsoCode: z.string().trim().length(2),
1177
+ addressLine: z.string().trim().min(1),
1178
+ addressNumber: z.string().trim().min(1),
1179
+ department: z.string().trim().min(1),
1180
+ province: z.string().trim().min(1),
1181
+ district: z.string().trim().min(1),
1182
+ phone: z.string().trim(),
1183
+ cellPhone: z.string().trim(),
1184
+ postalCode: z.string().trim().min(1),
1185
+ reference: z.string().trim(),
1186
+ latitude: z.number().nullable(),
1187
+ longitude: z.number().nullable(),
1188
+ isDefault: z.boolean()
1189
+ });
1190
+ var CustomerAddressSchema = CustomerAddressUpsertInputSchema.extend({
1191
+ id: z.union([z.string(), z.number()]).transform(String).optional()
1192
+ });
1193
+ var CustomerAddressesSchema = z.array(CustomerAddressSchema);
1194
+
1195
+ // src/services/customer-address.service.ts
1196
+ var ADDRESSES_PATH = "customer/addresses";
1197
+ var CustomerAddressMutationResponseSchema = z.union([
1198
+ CustomerAddressSchema,
1199
+ z.object({
1200
+ id: z.union([z.string(), z.number()]).transform(String)
1201
+ }),
1202
+ z.null()
1203
+ ]);
1204
+ async function getCustomerAddresses(api, options = {}) {
1205
+ return api.get(ADDRESSES_PATH, CustomerAddressesSchema, {
1206
+ headers: options.headers,
1207
+ signal: options.signal
1208
+ });
1209
+ }
1210
+ async function createCustomerAddress(api, data, options = {}) {
1211
+ const payload = CustomerAddressUpsertInputSchema.parse(data);
1212
+ return api.post(ADDRESSES_PATH, payload, CustomerAddressMutationResponseSchema, {
1213
+ headers: options.headers,
1214
+ signal: options.signal
1215
+ });
1216
+ }
1217
+ async function updateCustomerAddress(api, addressId, data, options = {}) {
1218
+ const id = addressId.trim();
1219
+ if (!id) throw new Error("addressId requerido");
1220
+ const payload = CustomerAddressUpsertInputSchema.parse(data);
1221
+ return api.request(
1222
+ "PUT",
1223
+ `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1224
+ CustomerAddressMutationResponseSchema,
1225
+ {
1226
+ body: payload,
1227
+ headers: options.headers,
1228
+ signal: options.signal
1229
+ }
1230
+ );
1231
+ }
1232
+ async function deleteCustomerAddress(api, addressId, options = {}) {
1233
+ const id = addressId.trim();
1234
+ if (!id) throw new Error("addressId requerido");
1235
+ await api.request(
1236
+ "DELETE",
1237
+ `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1238
+ z.null(),
1239
+ {
1240
+ headers: options.headers,
1241
+ signal: options.signal
1242
+ }
1243
+ );
1244
+ }
1245
+ var DEFAULT_COUNTRY_CODE = "PE";
1246
+ z.object({
1247
+ email: z.string().email(),
1248
+ firstName: z.string().trim().min(1),
1249
+ lastName: z.string().trim().min(1),
1250
+ countryIsoCode: z.string().trim().length(2),
1251
+ password: z.string().min(1),
1252
+ phone: z.string().trim().min(1).optional()
1253
+ });
1254
+ var CustomerProfilePatchSchema = z.object({
1255
+ firstName: z.string().trim().min(1),
1256
+ lastName: z.string().trim().min(1),
1257
+ phone: z.string().trim(),
1258
+ identificationNumber: z.string().nullable(),
1259
+ identificationType: z.string().nullable(),
1260
+ entityName: z.string().nullable(),
1261
+ entityIdentificationNumber: z.string().nullable(),
1262
+ gender: z.string().nullable(),
1263
+ role: z.string().nullable(),
1264
+ companyName: z.string().nullable(),
1265
+ dateOfBirth: z.string().nullable(),
1266
+ consent: z.boolean(),
1267
+ countryIsoCode: z.string().trim().length(2)
1268
+ });
1269
+ z.object({
1270
+ firstName: z.string(),
1271
+ lastName: z.string(),
1272
+ phone: z.string(),
1273
+ email: z.string().email(),
1274
+ identificationNumber: z.string().nullable(),
1275
+ identificationType: z.string().nullable(),
1276
+ countryIsoCode: z.string(),
1277
+ consent: z.boolean(),
1278
+ entityName: z.string().nullable(),
1279
+ entityIdentificationNumber: z.string().nullable(),
1280
+ gender: z.string().nullable(),
1281
+ role: z.string().nullable(),
1282
+ companyName: z.string().nullable(),
1283
+ dateOfBirth: z.string().nullable()
1284
+ });
1285
+ var nullableString = z.string().nullable().optional().transform((v) => v ?? null);
1286
+ var CustomerMeSchema = z.object({
1287
+ id: z.union([z.string(), z.number()]),
1288
+ storeId: z.string().optional(),
1289
+ email: z.string().email(),
1290
+ firstName: z.string(),
1291
+ lastName: z.string(),
1292
+ phone: z.union([z.string(), z.null()]).optional().transform((v) => v ?? ""),
1293
+ identificationNumber: nullableString,
1294
+ identificationType: nullableString,
1295
+ entityName: nullableString,
1296
+ entityIdentificationNumber: nullableString,
1297
+ gender: nullableString,
1298
+ role: nullableString,
1299
+ companyName: nullableString,
1300
+ dateOfBirth: nullableString,
1301
+ countryIsoCode: z.string().optional().transform((v) => v?.trim().length === 2 ? v.trim() : DEFAULT_COUNTRY_CODE),
1302
+ consent: z.boolean().optional().transform((v) => v ?? false)
1303
+ }).passthrough();
1304
+
1305
+ // src/services/customer.service.ts
1306
+ var CUSTOMER_PATH = "customer";
1307
+ async function getCustomerMe(api, options = {}) {
1308
+ return api.get(CUSTOMER_PATH, CustomerMeSchema, {
1309
+ headers: options.headers,
1310
+ signal: options.signal
1311
+ });
1312
+ }
1313
+ async function patchCustomer(api, data, options = {}) {
1314
+ const payload = CustomerProfilePatchSchema.parse(data);
1315
+ await api.request("PATCH", CUSTOMER_PATH, z.null(), {
1316
+ body: payload,
1317
+ headers: options.headers,
1318
+ signal: options.signal
1319
+ });
1320
+ }
1321
+ var CustomerOrderShippingAddressSchema = z.object({
1322
+ name: z.string().nullable().optional(),
1323
+ company: z.string().nullable().optional(),
1324
+ address1: z.string(),
1325
+ address2: z.string().nullable().optional(),
1326
+ city: z.string().nullable().optional(),
1327
+ countryCode: z.string().min(2).max(2),
1328
+ province: z.string().nullable().optional(),
1329
+ postalCode: z.string().nullable().optional(),
1330
+ district: z.string().nullable().optional(),
1331
+ phone: z.string().nullable().optional(),
1332
+ latitude: z.number().nullable().optional(),
1333
+ longitude: z.number().nullable().optional(),
1334
+ metadata: z.record(z.unknown()).nullable().optional()
1335
+ }).passthrough();
1336
+ var CustomerOrderLineItemSchema = z.object({
1337
+ id: z.string(),
1338
+ orderId: z.coerce.string(),
1339
+ productId: z.coerce.string().nullable(),
1340
+ variantId: z.coerce.string().nullable(),
1341
+ title: z.string(),
1342
+ subtitle: z.string().nullable().optional(),
1343
+ thumbnail: z.string().nullable().optional(),
1344
+ variantTitle: z.string().nullable().optional(),
1345
+ productHandle: z.string().nullable().optional(),
1346
+ quantity: z.number(),
1347
+ unitPrice: z.number(),
1348
+ total: z.number(),
1349
+ status: z.string()
1350
+ });
1351
+ var CustomerOrderListItemSchema = z.object({
1352
+ orderId: z.coerce.string(),
1353
+ orderNumber: z.string(),
1354
+ orderGroup: z.string(),
1355
+ orderIds: z.array(z.coerce.string()),
1356
+ status: z.string(),
1357
+ total: z.number(),
1358
+ totalPaid: z.number(),
1359
+ currencyCode: z.string(),
1360
+ orderDate: z.string(),
1361
+ createdOn: z.string(),
1362
+ updatedOn: z.string().nullable().optional(),
1363
+ paymentAt: z.string().nullable().optional(),
1364
+ shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1365
+ shippingAddressSummary: z.string().nullable().optional(),
1366
+ items: z.array(CustomerOrderLineItemSchema)
1367
+ });
1368
+ var CustomerOrderListSchema = z.array(CustomerOrderListItemSchema);
1369
+ var CustomerOrderPaymentSchema = z.object({
1370
+ id: z.string(),
1371
+ paymentMethod: z.string(),
1372
+ paymentCode: z.string(),
1373
+ amount: z.number(),
1374
+ paymentStatus: z.string(),
1375
+ receiptUrl: z.string().nullable().optional(),
1376
+ createdOn: z.string()
1377
+ });
1378
+ var CustomerOrderStatusTimelineSchema = z.object({
1379
+ key: z.string(),
1380
+ label: z.string(),
1381
+ occurredAt: z.string(),
1382
+ description: z.string().nullable().optional(),
1383
+ status: z.string(),
1384
+ source: z.string()
1385
+ });
1386
+ var CustomerOrderDetailSchema = z.object({
1387
+ id: z.coerce.string(),
1388
+ orderNumber: z.string(),
1389
+ orderGroup: z.string(),
1390
+ status: z.string(),
1391
+ total: z.number(),
1392
+ totalPaid: z.number(),
1393
+ currencyCode: z.string(),
1394
+ orderDate: z.string(),
1395
+ createdOn: z.string(),
1396
+ updatedOn: z.string().nullable().optional(),
1397
+ paymentAt: z.string().nullable().optional(),
1398
+ subTotal: z.number(),
1399
+ discount: z.number(),
1400
+ shipping: z.number(),
1401
+ tax: z.number(),
1402
+ email: z.string(),
1403
+ phone: z.string(),
1404
+ firstName: z.string(),
1405
+ lastName: z.string(),
1406
+ shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1407
+ shippingAddressSummary: z.string().nullable().optional(),
1408
+ billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1409
+ items: z.array(CustomerOrderLineItemSchema),
1410
+ payments: z.array(CustomerOrderPaymentSchema),
1411
+ statusTimeline: z.array(CustomerOrderStatusTimelineSchema)
1412
+ });
1413
+
1414
+ // src/services/customer-order.service.ts
1415
+ var ORDERS_PATH = "customer/orders";
1416
+ async function getCustomerOrders(api, options = {}) {
1417
+ return api.get(ORDERS_PATH, CustomerOrderListSchema, {
1418
+ headers: options.headers,
1419
+ signal: options.signal
1420
+ });
1421
+ }
1422
+ async function getCustomerOrder(api, orderId, options = {}) {
1423
+ const id = orderId.trim();
1424
+ if (!id) throw new Error("orderId requerido");
1425
+ return api.get(
1426
+ `${ORDERS_PATH}/${encodeURIComponent(id)}`,
1427
+ CustomerOrderDetailSchema,
1428
+ {
1429
+ headers: options.headers,
1430
+ signal: options.signal
1431
+ }
1432
+ );
1433
+ }
1155
1434
 
1156
1435
  // src/client.ts
1157
1436
  var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
@@ -1310,6 +1589,38 @@ function createClient(options) {
1310
1589
  async function getDistricts2(params) {
1311
1590
  return getDistricts(api, params);
1312
1591
  }
1592
+ async function getCustomerAddresses2(options2 = {}) {
1593
+ const client = await apiClient();
1594
+ return getCustomerAddresses(client, options2);
1595
+ }
1596
+ async function createCustomerAddress2(data, options2 = {}) {
1597
+ const client = await apiClient();
1598
+ return createCustomerAddress(client, data, options2);
1599
+ }
1600
+ async function updateCustomerAddress2(addressId, data, options2 = {}) {
1601
+ const client = await apiClient();
1602
+ return updateCustomerAddress(client, addressId, data, options2);
1603
+ }
1604
+ async function deleteCustomerAddress2(addressId, options2 = {}) {
1605
+ const client = await apiClient();
1606
+ return deleteCustomerAddress(client, addressId, options2);
1607
+ }
1608
+ async function getCustomerMe2(options2 = {}) {
1609
+ const client = await apiClient();
1610
+ return getCustomerMe(client, options2);
1611
+ }
1612
+ async function patchCustomer2(data, options2 = {}) {
1613
+ const client = await apiClient();
1614
+ return patchCustomer(client, data, options2);
1615
+ }
1616
+ async function getCustomerOrders2(options2 = {}) {
1617
+ const client = await apiClient();
1618
+ return getCustomerOrders(client, options2);
1619
+ }
1620
+ async function getCustomerOrder2(orderId, options2 = {}) {
1621
+ const client = await apiClient();
1622
+ return getCustomerOrder(client, orderId, options2);
1623
+ }
1313
1624
  return {
1314
1625
  ...api,
1315
1626
  getSettings,
@@ -1341,7 +1652,15 @@ function createClient(options) {
1341
1652
  getCountries: getCountries2,
1342
1653
  getDepartments: getDepartments2,
1343
1654
  getProvinces: getProvinces2,
1344
- getDistricts: getDistricts2
1655
+ getDistricts: getDistricts2,
1656
+ getCustomerAddresses: getCustomerAddresses2,
1657
+ createCustomerAddress: createCustomerAddress2,
1658
+ updateCustomerAddress: updateCustomerAddress2,
1659
+ deleteCustomerAddress: deleteCustomerAddress2,
1660
+ getCustomerMe: getCustomerMe2,
1661
+ patchCustomer: patchCustomer2,
1662
+ getCustomerOrders: getCustomerOrders2,
1663
+ getCustomerOrder: getCustomerOrder2
1345
1664
  };
1346
1665
  }
1347
1666
  var createStorefrontClient = createClient;