@ecomiq/core 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.cjs +19 -5
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +19 -5
- package/dist/api.js.map +1 -1
- package/dist/client-4ZTG2RZ3.d.ts +195 -0
- package/dist/client-BpX4yR6S.d.cts +195 -0
- package/dist/client.cjs +320 -6
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +13 -84
- package/dist/client.d.ts +13 -84
- package/dist/client.js +320 -6
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +471 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +326 -323
- package/dist/index.d.ts +326 -323
- package/dist/index.js +440 -7
- package/dist/index.js.map +1 -1
- package/dist/models/collections.d.cts +4 -4
- package/dist/models/collections.d.ts +4 -4
- package/dist/models/customer-address.cjs +41 -0
- package/dist/models/customer-address.cjs.map +1 -0
- package/dist/models/customer-address.d.cts +160 -0
- package/dist/models/customer-address.d.ts +160 -0
- package/dist/models/customer-address.js +36 -0
- package/dist/models/customer-address.js.map +1 -0
- package/dist/models/customer-order.cjs +161 -0
- package/dist/models/customer-order.cjs.map +1 -0
- package/dist/models/customer-order.d.cts +896 -0
- package/dist/models/customer-order.d.ts +896 -0
- package/dist/models/customer-order.js +149 -0
- package/dist/models/customer-order.js.map +1 -0
- package/dist/models/customer-profile.cjs +126 -0
- package/dist/models/customer-profile.cjs.map +1 -0
- package/dist/models/customer-profile.d.cts +178 -0
- package/dist/models/customer-profile.d.ts +178 -0
- package/dist/models/customer-profile.js +118 -0
- package/dist/models/customer-profile.js.map +1 -0
- package/dist/models/geo.d.cts +14 -14
- package/dist/models/geo.d.ts +14 -14
- package/dist/models/products.d.cts +130 -130
- package/dist/models/products.d.ts +130 -130
- package/dist/models/search.d.cts +4 -4
- package/dist/models/search.d.ts +4 -4
- package/dist/models/settings.d.cts +798 -798
- package/dist/models/settings.d.ts +798 -798
- package/dist/models/storefront-cart.d.cts +80 -80
- package/dist/models/storefront-cart.d.ts +80 -80
- package/dist/models/storefront-checkout.d.cts +400 -400
- package/dist/models/storefront-checkout.d.ts +400 -400
- package/dist/models/storefront-reviews.d.cts +8 -8
- package/dist/models/storefront-reviews.d.ts +8 -8
- package/package.json +16 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,85 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
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
|
|
64
|
-
let body =
|
|
65
|
-
if (
|
|
64
|
+
const bodyText2 = await response.text().catch(() => void 0);
|
|
65
|
+
let body = bodyText2;
|
|
66
|
+
if (bodyText2) {
|
|
66
67
|
try {
|
|
67
|
-
body = JSON.parse(
|
|
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
|
|
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,6 +1166,266 @@ 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;
|
|
@@ -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;
|