@ecomiq/storefront 0.1.2 → 1.0.1
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/README.md +211 -59
- package/dist/chunk-PCTSWSTB.js +346 -0
- package/dist/chunk-PCTSWSTB.js.map +1 -0
- package/dist/chunk-PDK2VYWD.js +1598 -0
- package/dist/chunk-PDK2VYWD.js.map +1 -0
- package/dist/chunk-Q762YXCQ.js +175 -0
- package/dist/chunk-Q762YXCQ.js.map +1 -0
- package/dist/chunks/client.d.ts +8563 -0
- package/dist/chunks/client.js +2046 -0
- package/dist/chunks/client.js.map +1 -0
- package/dist/chunks/config.js +3 -0
- package/dist/chunks/config.js.map +1 -0
- package/dist/chunks/server-nextjs.d.ts +33 -0
- package/dist/chunks/server-nextjs.js +30 -0
- package/dist/chunks/server-nextjs.js.map +1 -0
- package/dist/chunks/server-tanstack.d.ts +22 -0
- package/dist/chunks/server-tanstack.js +30 -0
- package/dist/chunks/server-tanstack.js.map +1 -0
- package/dist/ecomiq-shell-ui-SWIFLQVM.js +8 -0
- package/dist/ecomiq-shell-ui-SWIFLQVM.js.map +1 -0
- package/dist/format-currency-oJD9jGYW.d.ts +6751 -0
- package/dist/index.d.ts +20 -30
- package/dist/index.js +11 -103
- package/dist/index.js.map +1 -1
- package/dist/index.server.d.ts +8 -0
- package/dist/index.server.js +7 -0
- package/dist/index.server.js.map +1 -0
- package/dist/nextjs/api.d.ts +10 -14
- package/dist/nextjs/api.js +8 -148
- package/dist/nextjs/api.js.map +1 -1
- package/dist/nextjs.d.ts +13 -3213
- package/dist/nextjs.js +11 -1793
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.server.d.ts +1 -0
- package/dist/nextjs.server.js +1 -0
- package/dist/nextjs.server.js.map +1 -0
- package/dist/store-proxy-handler-CNzKlTFA.d.ts +10 -0
- package/dist/tanstack/api.d.ts +41 -0
- package/dist/tanstack/api.js +28 -0
- package/dist/tanstack/api.js.map +1 -0
- package/dist/tanstack.d.ts +13 -0
- package/dist/tanstack.js +11 -0
- package/dist/tanstack.js.map +1 -0
- package/dist/tanstack.server.d.ts +1 -0
- package/dist/tanstack.server.js +1 -0
- package/dist/tanstack.server.js.map +1 -0
- package/package.json +33 -13
- package/dist/collection-anMkdWa7.d.ts +0 -4333
- package/dist/core.d.ts +0 -3396
- package/dist/core.js +0 -1239
- package/dist/core.js.map +0 -1
- package/dist/find-storefront-cms-page-DNwLo1iV.d.ts +0 -178
- package/dist/react.d.ts +0 -964
- package/dist/react.js +0 -2670
- package/dist/react.js.map +0 -1
- /package/dist/{..d.ts → chunks/config.d.ts} +0 -0
package/dist/nextjs.js
CHANGED
|
@@ -1,1793 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { join } from 'path';
|
|
13
|
-
import React2, { createContext, useEffect, useState, useMemo, useCallback, useRef } from 'react';
|
|
14
|
-
import { QueryClient, useMutation, useQuery, QueryClientProvider, useQueryClient, useInfiniteQuery } from '@tanstack/react-query';
|
|
15
|
-
import { create } from 'zustand';
|
|
16
|
-
|
|
17
|
-
var __defProp = Object.defineProperty;
|
|
18
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
19
|
-
var __esm = (fn, res) => function __init() {
|
|
20
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
21
|
-
};
|
|
22
|
-
var __export = (target, all) => {
|
|
23
|
-
for (var name in all)
|
|
24
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/core/client/store-api-client.ts
|
|
28
|
-
function setServerRequestOrigin(getter) {
|
|
29
|
-
serverRequestOriginGetter = getter;
|
|
30
|
-
}
|
|
31
|
-
function setServerStoreId(storeId) {
|
|
32
|
-
serverStoreIdGetter = storeId?.trim() || null;
|
|
33
|
-
}
|
|
34
|
-
function setClientStoreId(storeId) {
|
|
35
|
-
if (typeof window === "undefined") return;
|
|
36
|
-
clientStoreIdGetter = storeId?.trim() || null;
|
|
37
|
-
}
|
|
38
|
-
async function getStoreApiBaseUrl() {
|
|
39
|
-
if (typeof window !== "undefined") {
|
|
40
|
-
return STORE_API_PATH;
|
|
41
|
-
}
|
|
42
|
-
if (serverRequestOriginGetter) {
|
|
43
|
-
return `${serverRequestOriginGetter.replace(/\/$/, "")}/${STORE_API_PATH.replace(/^\//, "")}`;
|
|
44
|
-
}
|
|
45
|
-
return STORE_API_PATH;
|
|
46
|
-
}
|
|
47
|
-
function createStoreApiClient(baseUrl) {
|
|
48
|
-
return new StoreApiClient(baseUrl);
|
|
49
|
-
}
|
|
50
|
-
async function getStoreApiClient() {
|
|
51
|
-
const baseUrl = await getStoreApiBaseUrl();
|
|
52
|
-
return new StoreApiClient(baseUrl);
|
|
53
|
-
}
|
|
54
|
-
var STORE_API_PATH, serverRequestOriginGetter, serverStoreIdGetter, clientStoreIdGetter, StoreApiClient, storeApiClient;
|
|
55
|
-
var init_store_api_client = __esm({
|
|
56
|
-
"src/core/client/store-api-client.ts"() {
|
|
57
|
-
STORE_API_PATH = "/api/store";
|
|
58
|
-
serverRequestOriginGetter = null;
|
|
59
|
-
serverStoreIdGetter = null;
|
|
60
|
-
clientStoreIdGetter = null;
|
|
61
|
-
StoreApiClient = class {
|
|
62
|
-
baseUrl;
|
|
63
|
-
constructor(baseUrl = STORE_API_PATH) {
|
|
64
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
65
|
-
}
|
|
66
|
-
async request(path, init, options) {
|
|
67
|
-
const pathNorm = path.replace(/^\/+/, "");
|
|
68
|
-
const url = path.startsWith("http") ? path : `${this.baseUrl}/${pathNorm}`;
|
|
69
|
-
const headers3 = new Headers(init.headers ?? {});
|
|
70
|
-
headers3.set("Content-Type", "application/json");
|
|
71
|
-
headers3.set("Accept-Encoding", "identity");
|
|
72
|
-
const explicitStoreId = options?.xStoreId?.trim();
|
|
73
|
-
const runtimeStoreId = explicitStoreId || (typeof window === "undefined" ? serverStoreIdGetter : clientStoreIdGetter);
|
|
74
|
-
if (runtimeStoreId && !headers3.has("x-store-id")) {
|
|
75
|
-
headers3.set("X-Store-Id", runtimeStoreId);
|
|
76
|
-
}
|
|
77
|
-
if (options?.xStoreDomain) {
|
|
78
|
-
headers3.set("X-Store-Domain", options.xStoreDomain);
|
|
79
|
-
}
|
|
80
|
-
if (options?.xCartId) {
|
|
81
|
-
headers3.set("X-Cart-Token", options.xCartId);
|
|
82
|
-
}
|
|
83
|
-
const bearer = typeof options?.bearerToken === "string" && options.bearerToken.trim().length > 0 ? options.bearerToken.trim() : void 0;
|
|
84
|
-
if (bearer) {
|
|
85
|
-
headers3.set(
|
|
86
|
-
"Authorization",
|
|
87
|
-
bearer.toLowerCase().startsWith("bearer ") ? bearer : `Bearer ${bearer}`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
const isServer = typeof window === "undefined";
|
|
91
|
-
const res = await fetch(url, {
|
|
92
|
-
...init,
|
|
93
|
-
headers: headers3,
|
|
94
|
-
credentials: isServer ? "same-origin" : "include",
|
|
95
|
-
...options?.noStore ? { cache: "no-store" } : {},
|
|
96
|
-
...options?.cacheKey && isServer && !options?.noStore ? {
|
|
97
|
-
next: {
|
|
98
|
-
revalidate: 60,
|
|
99
|
-
tags: [options.cacheKey]
|
|
100
|
-
}
|
|
101
|
-
} : {}
|
|
102
|
-
});
|
|
103
|
-
if (!res.ok) {
|
|
104
|
-
let body;
|
|
105
|
-
try {
|
|
106
|
-
const errorText = await res.text();
|
|
107
|
-
body = errorText ? JSON.parse(errorText) : void 0;
|
|
108
|
-
} catch {
|
|
109
|
-
body = void 0;
|
|
110
|
-
}
|
|
111
|
-
const msg = typeof body === "object" && body !== null && "title" in body && typeof body.title === "string" ? body.title : res.statusText || "Store API error";
|
|
112
|
-
const err = new Error(msg);
|
|
113
|
-
err.status = res.status;
|
|
114
|
-
err.body = body;
|
|
115
|
-
throw err;
|
|
116
|
-
}
|
|
117
|
-
const text = await res.text();
|
|
118
|
-
if (!text) return void 0;
|
|
119
|
-
return JSON.parse(text);
|
|
120
|
-
}
|
|
121
|
-
get(path, options) {
|
|
122
|
-
return this.request(path, { method: "GET" }, options);
|
|
123
|
-
}
|
|
124
|
-
post(path, data, options) {
|
|
125
|
-
return this.request(
|
|
126
|
-
path,
|
|
127
|
-
{
|
|
128
|
-
method: "POST",
|
|
129
|
-
body: data != null ? JSON.stringify(data) : void 0
|
|
130
|
-
},
|
|
131
|
-
options
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
patch(path, data, options) {
|
|
135
|
-
return this.request(path, {
|
|
136
|
-
method: "PATCH",
|
|
137
|
-
body: data != null ? JSON.stringify(data) : void 0
|
|
138
|
-
}, options);
|
|
139
|
-
}
|
|
140
|
-
put(path, data, options) {
|
|
141
|
-
return this.request(
|
|
142
|
-
path,
|
|
143
|
-
{
|
|
144
|
-
method: "PUT",
|
|
145
|
-
body: data != null ? JSON.stringify(data) : void 0
|
|
146
|
-
},
|
|
147
|
-
options
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
delete(path, options) {
|
|
151
|
-
return this.request(path, { method: "DELETE" }, options);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
storeApiClient = new StoreApiClient(STORE_API_PATH);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
function customerMeToProfilePatch(me) {
|
|
158
|
-
return {
|
|
159
|
-
firstName: me.firstName,
|
|
160
|
-
lastName: me.lastName,
|
|
161
|
-
phone: me.phone ?? "",
|
|
162
|
-
identificationNumber: me.identificationNumber,
|
|
163
|
-
identificationType: me.identificationType,
|
|
164
|
-
entityName: me.entityName,
|
|
165
|
-
entityIdentificationNumber: me.entityIdentificationNumber,
|
|
166
|
-
gender: me.gender,
|
|
167
|
-
role: me.role,
|
|
168
|
-
companyName: me.companyName,
|
|
169
|
-
dateOfBirth: me.dateOfBirth,
|
|
170
|
-
consent: me.consent,
|
|
171
|
-
countryIsoCode: me.countryIsoCode || "PE"
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function customerAuthOptions(accessToken) {
|
|
175
|
-
const token = typeof accessToken === "string" && accessToken.trim().length > 0 ? accessToken.trim() : void 0;
|
|
176
|
-
return token ? { bearerToken: token } : {};
|
|
177
|
-
}
|
|
178
|
-
async function registerCustomer(data) {
|
|
179
|
-
const payload = CustomerRegisterRequestSchema.parse(data);
|
|
180
|
-
const client = await getStoreApiClient();
|
|
181
|
-
return client.post("customer/register", payload);
|
|
182
|
-
}
|
|
183
|
-
async function getCustomerAddresses(accessToken) {
|
|
184
|
-
const client = await getStoreApiClient();
|
|
185
|
-
const token = typeof accessToken === "string" && accessToken.trim().length > 0 ? accessToken.trim() : void 0;
|
|
186
|
-
const response = await client.get("customer/addresses", {
|
|
187
|
-
...token ? { bearerToken: token } : {}
|
|
188
|
-
});
|
|
189
|
-
return z.array(CustomerAddressSchema).parse(response);
|
|
190
|
-
}
|
|
191
|
-
async function createCustomerAddress(data, accessToken) {
|
|
192
|
-
const client = await getStoreApiClient();
|
|
193
|
-
const token = typeof accessToken === "string" && accessToken.trim().length > 0 ? accessToken.trim() : void 0;
|
|
194
|
-
const payload = CustomerAddressUpsertSchema.parse(data);
|
|
195
|
-
return client.post("customer/addresses", payload, {
|
|
196
|
-
...token ? { bearerToken: token } : {}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async function updateCustomerAddress(addressId, data, accessToken) {
|
|
200
|
-
const client = await getStoreApiClient();
|
|
201
|
-
const token = typeof accessToken === "string" && accessToken.trim().length > 0 ? accessToken.trim() : void 0;
|
|
202
|
-
const payload = CustomerAddressUpsertSchema.parse(data);
|
|
203
|
-
const id = addressId.trim();
|
|
204
|
-
if (!id) throw new Error("addressId requerido");
|
|
205
|
-
return client.put(`customer/addresses/${encodeURIComponent(id)}`, payload, {
|
|
206
|
-
...token ? { bearerToken: token } : {}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
async function deleteCustomerAddress(addressId, accessToken) {
|
|
210
|
-
const client = await getStoreApiClient();
|
|
211
|
-
const token = typeof accessToken === "string" && accessToken.trim().length > 0 ? accessToken.trim() : void 0;
|
|
212
|
-
const id = addressId.trim();
|
|
213
|
-
if (!id) throw new Error("addressId requerido");
|
|
214
|
-
return client.delete(`customer/addresses/${encodeURIComponent(id)}`, {
|
|
215
|
-
...token ? { bearerToken: token } : {}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
async function getCustomerMe(accessToken) {
|
|
219
|
-
const client = await getStoreApiClient();
|
|
220
|
-
const response = await client.get("customer", customerAuthOptions(accessToken));
|
|
221
|
-
return CustomerMeSchema.parse(response);
|
|
222
|
-
}
|
|
223
|
-
async function patchCustomer(data, accessToken) {
|
|
224
|
-
const client = await getStoreApiClient();
|
|
225
|
-
const payload = CustomerProfilePatchSchema.parse(data);
|
|
226
|
-
await client.patch("customer", payload, customerAuthOptions(accessToken));
|
|
227
|
-
}
|
|
228
|
-
var CustomerRegisterRequestSchema, CustomerAddressSchema, CustomerAddressUpsertSchema, CustomerMeSchema, CustomerProfilePatchSchema;
|
|
229
|
-
var init_store_api_customer_service = __esm({
|
|
230
|
-
"src/core/client/store-api-customer.service.ts"() {
|
|
231
|
-
init_store_api_client();
|
|
232
|
-
CustomerRegisterRequestSchema = z.object({
|
|
233
|
-
email: z.string().email(),
|
|
234
|
-
firstName: z.string().trim().min(1),
|
|
235
|
-
lastName: z.string().trim().min(1),
|
|
236
|
-
countryIsoCode: z.string().trim().length(2),
|
|
237
|
-
password: z.string(),
|
|
238
|
-
phone: z.string().trim().optional()
|
|
239
|
-
});
|
|
240
|
-
CustomerAddressSchema = z.object({
|
|
241
|
-
/** Presente en listados cuando el upstream expone el id para PUT/DELETE. */
|
|
242
|
-
id: z.string().optional(),
|
|
243
|
-
addressKey: z.string(),
|
|
244
|
-
countryIsoCode: z.string(),
|
|
245
|
-
addressLine: z.string(),
|
|
246
|
-
addressNumber: z.string(),
|
|
247
|
-
department: z.string(),
|
|
248
|
-
province: z.string(),
|
|
249
|
-
district: z.string(),
|
|
250
|
-
phone: z.string(),
|
|
251
|
-
cellPhone: z.string(),
|
|
252
|
-
postalCode: z.string(),
|
|
253
|
-
reference: z.string(),
|
|
254
|
-
latitude: z.number().nullable(),
|
|
255
|
-
longitude: z.number().nullable(),
|
|
256
|
-
isDefault: z.boolean()
|
|
257
|
-
});
|
|
258
|
-
CustomerAddressUpsertSchema = CustomerAddressSchema.omit({ id: true });
|
|
259
|
-
CustomerMeSchema = z.object({
|
|
260
|
-
id: z.string(),
|
|
261
|
-
storeId: z.string(),
|
|
262
|
-
email: z.string().email(),
|
|
263
|
-
firstName: z.string(),
|
|
264
|
-
lastName: z.string(),
|
|
265
|
-
phone: z.string(),
|
|
266
|
-
identificationNumber: z.string().nullable(),
|
|
267
|
-
identificationType: z.string().nullable(),
|
|
268
|
-
entityName: z.string().nullable(),
|
|
269
|
-
dateOfBirth: z.string().nullable(),
|
|
270
|
-
gender: z.string().nullable(),
|
|
271
|
-
countryIsoCode: z.string(),
|
|
272
|
-
role: z.string().nullable(),
|
|
273
|
-
companyName: z.string().nullable(),
|
|
274
|
-
consent: z.boolean(),
|
|
275
|
-
userId: z.string(),
|
|
276
|
-
customerType: z.string(),
|
|
277
|
-
status: z.string(),
|
|
278
|
-
entityIdentificationNumber: z.string().nullable(),
|
|
279
|
-
defaultAddressId: z.string().nullable(),
|
|
280
|
-
metadata: z.unknown().nullable(),
|
|
281
|
-
totalOrders: z.number(),
|
|
282
|
-
avgOrders: z.number(),
|
|
283
|
-
lastOrderId: z.string().nullable(),
|
|
284
|
-
lastOrderDate: z.string().nullable(),
|
|
285
|
-
loyaltyPoints: z.number(),
|
|
286
|
-
addresses: z.array(CustomerAddressSchema),
|
|
287
|
-
createdOn: z.string(),
|
|
288
|
-
updatedOn: z.string().nullable()
|
|
289
|
-
});
|
|
290
|
-
CustomerProfilePatchSchema = z.object({
|
|
291
|
-
firstName: z.string().trim().min(1),
|
|
292
|
-
lastName: z.string().trim().min(1),
|
|
293
|
-
phone: z.string().trim(),
|
|
294
|
-
identificationNumber: z.string().nullable(),
|
|
295
|
-
identificationType: z.string().nullable(),
|
|
296
|
-
entityName: z.string().nullable(),
|
|
297
|
-
entityIdentificationNumber: z.string().nullable(),
|
|
298
|
-
gender: z.string().nullable(),
|
|
299
|
-
role: z.string().nullable(),
|
|
300
|
-
companyName: z.string().nullable(),
|
|
301
|
-
dateOfBirth: z.string().nullable(),
|
|
302
|
-
consent: z.boolean(),
|
|
303
|
-
countryIsoCode: z.string().trim().length(2)
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
var ModalsFactory;
|
|
308
|
-
var init_modals_factory = __esm({
|
|
309
|
-
"src/react/shell/components/modals-factory.tsx"() {
|
|
310
|
-
"use client";
|
|
311
|
-
init_store_api_customer_service();
|
|
312
|
-
ModalsFactory = () => {
|
|
313
|
-
const cart = useCart();
|
|
314
|
-
const store = useStore$1();
|
|
315
|
-
const authClient = useStorefrontAuthClient();
|
|
316
|
-
const { refetch } = useStorefrontSession();
|
|
317
|
-
const handlerLogin = async (values) => {
|
|
318
|
-
try {
|
|
319
|
-
await signInWithEcomiqCredentials(authClient, store.data, values);
|
|
320
|
-
const me = await getCustomerMe();
|
|
321
|
-
const displayName = `${me.firstName} ${me.lastName}`.trim() || me.email;
|
|
322
|
-
const updateUserResponse = await authClient.$fetch("/update-user", {
|
|
323
|
-
method: "POST",
|
|
324
|
-
body: {
|
|
325
|
-
name: displayName,
|
|
326
|
-
firstName: me.firstName,
|
|
327
|
-
lastName: me.lastName,
|
|
328
|
-
phone: me.phone
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
if (updateUserResponse.error) {
|
|
332
|
-
throw new Error(updateUserResponse.error?.message ?? "No se pudo sincronizar el perfil");
|
|
333
|
-
}
|
|
334
|
-
if (me.email) {
|
|
335
|
-
cart.setCheckoutCustomerLocal({
|
|
336
|
-
email: me.email,
|
|
337
|
-
firstName: me.firstName,
|
|
338
|
-
lastName: me.lastName,
|
|
339
|
-
phone: me.phone ?? ""
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
await refetch();
|
|
343
|
-
toast.success("Sesi\xF3n iniciada correctamente");
|
|
344
|
-
store.closeModal("login");
|
|
345
|
-
} catch (error) {
|
|
346
|
-
console.error("Error al iniciar sesion:", error);
|
|
347
|
-
toast.error("Error al iniciar sesion");
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const handlerSignup = async (values) => {
|
|
351
|
-
try {
|
|
352
|
-
await registerCustomer({
|
|
353
|
-
email: values.email,
|
|
354
|
-
firstName: values.firstName,
|
|
355
|
-
lastName: values.lastName,
|
|
356
|
-
countryIsoCode: values.countryIsoCode,
|
|
357
|
-
password: values.password,
|
|
358
|
-
phone: values.phone
|
|
359
|
-
});
|
|
360
|
-
toast.success("Cuenta creada correctamente");
|
|
361
|
-
store.closeModal("signup");
|
|
362
|
-
setTimeout(() => {
|
|
363
|
-
store.openModal("login");
|
|
364
|
-
}, 1e3);
|
|
365
|
-
} catch (error) {
|
|
366
|
-
console.error("Error al registrarse:", error);
|
|
367
|
-
toast.error("Error al registrarse");
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
return /* @__PURE__ */ jsxs(
|
|
371
|
-
Modal,
|
|
372
|
-
{
|
|
373
|
-
isOpen: store.modals.login || store.modals.signup,
|
|
374
|
-
onClose: () => store.closeAllModals(),
|
|
375
|
-
children: [
|
|
376
|
-
store.modals.login && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
377
|
-
/* @__PURE__ */ jsx(SignInForm, { onSubmit: (values) => handlerLogin(values) }),
|
|
378
|
-
/* @__PURE__ */ jsxs("div", { className: "flex justify-center items-center mt-4", children: [
|
|
379
|
-
/* @__PURE__ */ jsx("p", { className: "text-gray-500", children: "No tienes cuenta?" }),
|
|
380
|
-
/* @__PURE__ */ jsx(
|
|
381
|
-
"button",
|
|
382
|
-
{
|
|
383
|
-
type: "button",
|
|
384
|
-
onClick: () => store.openModal("signup"),
|
|
385
|
-
className: "text-primary hover:underline ml-2 cursor-pointer",
|
|
386
|
-
children: "Registrate"
|
|
387
|
-
}
|
|
388
|
-
)
|
|
389
|
-
] })
|
|
390
|
-
] }),
|
|
391
|
-
store.modals.signup && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
392
|
-
/* @__PURE__ */ jsx(SignUpForm, { onSubmit: (values) => handlerSignup(values) }),
|
|
393
|
-
/* @__PURE__ */ jsxs("div", { className: "flex justify-center items-center mt-4", children: [
|
|
394
|
-
/* @__PURE__ */ jsx("p", { className: "text-gray-500", children: "Ya tienes cuenta?" }),
|
|
395
|
-
/* @__PURE__ */ jsx(
|
|
396
|
-
"button",
|
|
397
|
-
{
|
|
398
|
-
type: "button",
|
|
399
|
-
onClick: () => store.openModal("login"),
|
|
400
|
-
className: "text-primary hover:underline ml-2 cursor-pointer",
|
|
401
|
-
children: "Inicia sesion"
|
|
402
|
-
}
|
|
403
|
-
)
|
|
404
|
-
] })
|
|
405
|
-
] })
|
|
406
|
-
]
|
|
407
|
-
}
|
|
408
|
-
);
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
var Toaster;
|
|
413
|
-
var init_Toaster = __esm({
|
|
414
|
-
"src/react/shell/components/Toaster.tsx"() {
|
|
415
|
-
"use client";
|
|
416
|
-
Toaster = ({ ...props }) => {
|
|
417
|
-
const { theme = "system" } = useTheme();
|
|
418
|
-
return /* @__PURE__ */ jsx(
|
|
419
|
-
Toaster$1,
|
|
420
|
-
{
|
|
421
|
-
theme,
|
|
422
|
-
className: "toaster group",
|
|
423
|
-
style: {
|
|
424
|
-
"--normal-bg": "var(--popover)",
|
|
425
|
-
"--normal-text": "var(--popover-foreground)",
|
|
426
|
-
"--normal-border": "var(--border)"
|
|
427
|
-
},
|
|
428
|
-
...props
|
|
429
|
-
}
|
|
430
|
-
);
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
// src/react/shell/providers/ecomiq-shell-ui.tsx
|
|
436
|
-
var ecomiq_shell_ui_exports = {};
|
|
437
|
-
__export(ecomiq_shell_ui_exports, {
|
|
438
|
-
EcomiqShellUi: () => EcomiqShellUi
|
|
439
|
-
});
|
|
440
|
-
function EcomiqShellUi() {
|
|
441
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
442
|
-
/* @__PURE__ */ jsx(ModalsFactory, {}),
|
|
443
|
-
/* @__PURE__ */ jsx(Toaster, { position: "bottom-right" })
|
|
444
|
-
] });
|
|
445
|
-
}
|
|
446
|
-
var init_ecomiq_shell_ui = __esm({
|
|
447
|
-
"src/react/shell/providers/ecomiq-shell-ui.tsx"() {
|
|
448
|
-
"use client";
|
|
449
|
-
init_modals_factory();
|
|
450
|
-
init_Toaster();
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
// src/react/nextjs/actions/getHostName.ts
|
|
455
|
-
init_store_api_client();
|
|
456
|
-
async function getHostname() {
|
|
457
|
-
const hd = await headers();
|
|
458
|
-
const host = hd.get("host");
|
|
459
|
-
const hostname = host?.replace(/^www\./, "") ?? null;
|
|
460
|
-
const proto = hd.get("x-forwarded-proto") ?? hd.get("x-forwarded-ssl") ?? "http";
|
|
461
|
-
const secure = proto === "https" || (hd.get("x-forwarded-ssl") ?? "") === "on";
|
|
462
|
-
setServerRequestOrigin(`${secure ? "https" : "http"}://${hostname}`);
|
|
463
|
-
return hostname;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// src/core/client/store-api-store.service.ts
|
|
467
|
-
init_store_api_client();
|
|
468
|
-
async function getStorefrontSettings(subdomain, cacheKey) {
|
|
469
|
-
const client = await getStoreApiClient();
|
|
470
|
-
const response = await client.get("settings", {
|
|
471
|
-
xStoreDomain: subdomain?.trim() || void 0,
|
|
472
|
-
cacheKey,
|
|
473
|
-
noStore: true
|
|
474
|
-
});
|
|
475
|
-
return StorefrontSettingsSchema.parse(response);
|
|
476
|
-
}
|
|
477
|
-
var ECOMIQ_CLIENTS_STORE_KV_BINDING = "ecomiq_clients_store";
|
|
478
|
-
var ECOMIQ_APP_APEX = "ecomiq.app";
|
|
479
|
-
var ECOMIQ_APP_SUFFIX = [`.${ECOMIQ_APP_APEX}`, `.localhost`];
|
|
480
|
-
function normalizeStoreHost(hostHeader) {
|
|
481
|
-
let h = hostHeader.trim().toLowerCase();
|
|
482
|
-
const colon = h.indexOf(":");
|
|
483
|
-
if (colon !== -1) h = h.slice(0, colon);
|
|
484
|
-
if (h.startsWith("www.")) h = h.slice(4);
|
|
485
|
-
return h;
|
|
486
|
-
}
|
|
487
|
-
function resolveStorefrontSettingsHost(hostHeader) {
|
|
488
|
-
const host = normalizeStoreHost(hostHeader);
|
|
489
|
-
if (!host) {
|
|
490
|
-
throw Object.assign(new Error("Host inv\xE1lido para tienda"), { status: 400 });
|
|
491
|
-
}
|
|
492
|
-
if (host === ECOMIQ_APP_APEX) {
|
|
493
|
-
throw Object.assign(new Error("Host apex ecomiq.app sin slug de tienda"), { status: 400 });
|
|
494
|
-
}
|
|
495
|
-
if (ECOMIQ_APP_SUFFIX.some((suffix) => host.endsWith(suffix))) {
|
|
496
|
-
const slug = host.slice(0, -(ECOMIQ_APP_SUFFIX.find((suffix) => host.endsWith(suffix))?.length ?? 0));
|
|
497
|
-
if (!slug) {
|
|
498
|
-
throw Object.assign(new Error("Host sin slug para ecomiq.app"), { status: 400 });
|
|
499
|
-
}
|
|
500
|
-
return slug;
|
|
501
|
-
}
|
|
502
|
-
return host;
|
|
503
|
-
}
|
|
504
|
-
function buildStorefrontKvSnapshotKeyFromStoreKey(storeKey) {
|
|
505
|
-
const key = storeKey.trim();
|
|
506
|
-
if (!key) {
|
|
507
|
-
throw Object.assign(new Error("Store key vac\xEDo para KV"), { status: 400 });
|
|
508
|
-
}
|
|
509
|
-
return `storefront:snapshots:store:${key}`;
|
|
510
|
-
}
|
|
511
|
-
function buildStorefrontKvSnapshotKey(hostHeader) {
|
|
512
|
-
return buildStorefrontKvSnapshotKeyFromStoreKey(
|
|
513
|
-
resolveStorefrontSettingsHost(hostHeader)
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
function getKvNamespace(env) {
|
|
517
|
-
if (!env || typeof env !== "object") return void 0;
|
|
518
|
-
const ns = env[ECOMIQ_CLIENTS_STORE_KV_BINDING];
|
|
519
|
-
if (!ns || typeof ns !== "object" || typeof ns.get !== "function") {
|
|
520
|
-
return void 0;
|
|
521
|
-
}
|
|
522
|
-
return ns;
|
|
523
|
-
}
|
|
524
|
-
async function getStorefrontSettingsFromKvByStoreKey(storeKey) {
|
|
525
|
-
const { env } = await getCloudflareContext({ async: true });
|
|
526
|
-
const kv = getKvNamespace(env);
|
|
527
|
-
if (!kv) {
|
|
528
|
-
const err = new Error(
|
|
529
|
-
`Binding KV "${ECOMIQ_CLIENTS_STORE_KV_BINDING}" no encontrado. Configura kv_namespaces en wrangler.`
|
|
530
|
-
);
|
|
531
|
-
throw Object.assign(err, { status: 500 });
|
|
532
|
-
}
|
|
533
|
-
const cacheKey = buildStorefrontKvSnapshotKeyFromStoreKey(storeKey);
|
|
534
|
-
const raw = await kv.get(cacheKey, { type: "json" });
|
|
535
|
-
if (raw == null) {
|
|
536
|
-
const err = new Error("Store settings not found in KV");
|
|
537
|
-
throw Object.assign(err, { status: 404 });
|
|
538
|
-
}
|
|
539
|
-
return StorefrontSettingsSchema.parse(raw);
|
|
540
|
-
}
|
|
541
|
-
async function getStorefrontSettingsFromKv(hostHeader) {
|
|
542
|
-
return getStorefrontSettingsFromKvByStoreKey(
|
|
543
|
-
resolveStorefrontSettingsHost(hostHeader)
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
var CONFIG_FILENAMES = [
|
|
547
|
-
"ecomiq.config.js",
|
|
548
|
-
"ecomiq.config.cjs",
|
|
549
|
-
"ecomiq.config.mjs"
|
|
550
|
-
];
|
|
551
|
-
var EcomiqConfigSchema = z.object({
|
|
552
|
-
/**
|
|
553
|
-
* Slug de tienda en Ecomiq (p. ej. `mi-tienda` para `mi-tienda.ecomiq.app`).
|
|
554
|
-
* Si está definido, tiene prioridad sobre el `Host` de la request (útil en `localhost`).
|
|
555
|
-
*/
|
|
556
|
-
slugStore: z.string().min(1).optional()
|
|
557
|
-
});
|
|
558
|
-
var cachedConfig;
|
|
559
|
-
function parseExportedConfig(raw) {
|
|
560
|
-
const candidate = raw && typeof raw === "object" && "default" in raw ? raw.default : raw;
|
|
561
|
-
const parsed = EcomiqConfigSchema.safeParse(candidate);
|
|
562
|
-
if (!parsed.success) {
|
|
563
|
-
console.warn(
|
|
564
|
-
"[ecomiq] ecomiq.config.* inv\xE1lido:",
|
|
565
|
-
parsed.error.flatten().fieldErrors
|
|
566
|
-
);
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
569
|
-
const slugStore = parsed.data.slugStore?.trim();
|
|
570
|
-
return slugStore ? { slugStore } : {};
|
|
571
|
-
}
|
|
572
|
-
function loadEcomiqConfig(cwd = process.cwd()) {
|
|
573
|
-
if (cachedConfig !== void 0) return cachedConfig;
|
|
574
|
-
for (const filename of CONFIG_FILENAMES) {
|
|
575
|
-
const configPath = join(cwd, filename);
|
|
576
|
-
if (!existsSync(configPath)) continue;
|
|
577
|
-
try {
|
|
578
|
-
const requireFromApp = createRequire(join(cwd, "package.json"));
|
|
579
|
-
const loaded = requireFromApp(configPath);
|
|
580
|
-
const parsed = parseExportedConfig(loaded);
|
|
581
|
-
cachedConfig = parsed;
|
|
582
|
-
return cachedConfig;
|
|
583
|
-
} catch (error) {
|
|
584
|
-
console.warn(`[ecomiq] No se pudo cargar ${configPath}:`, error);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
cachedConfig = null;
|
|
588
|
-
return null;
|
|
589
|
-
}
|
|
590
|
-
function resolvePublicStoreKey(hostHeader, cwd) {
|
|
591
|
-
const slugFromConfig = loadEcomiqConfig(cwd)?.slugStore?.trim();
|
|
592
|
-
if (slugFromConfig) return slugFromConfig;
|
|
593
|
-
if (!hostHeader?.trim()) {
|
|
594
|
-
throw Object.assign(
|
|
595
|
-
new Error(
|
|
596
|
-
"Host is required, o define slugStore en ecomiq.config.js en la ra\xEDz del proyecto"
|
|
597
|
-
),
|
|
598
|
-
{ status: 400 }
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
return resolveStorefrontSettingsHost(hostHeader);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// src/react/shell/lib/public-store-settings-source.ts
|
|
605
|
-
var ENV_PUBLIC_STORE_SETTINGS_SOURCE = "PUBLIC_STORE_SETTINGS_SOURCE";
|
|
606
|
-
function resolvePublicStoreSettingsSource(envValue = process.env[ENV_PUBLIC_STORE_SETTINGS_SOURCE]) {
|
|
607
|
-
const v = (envValue ?? "api").trim().toLowerCase();
|
|
608
|
-
return v === "kv" ? "kv" : "api";
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// src/react/nextjs/actions/getPublicStore.ts
|
|
612
|
-
init_store_api_client();
|
|
613
|
-
async function getPublicStore(options) {
|
|
614
|
-
const headerList = await headers();
|
|
615
|
-
const host = headerList.get("host");
|
|
616
|
-
let storeKey;
|
|
617
|
-
try {
|
|
618
|
-
storeKey = resolvePublicStoreKey(host);
|
|
619
|
-
} catch (error) {
|
|
620
|
-
const err = error;
|
|
621
|
-
return {
|
|
622
|
-
data: null,
|
|
623
|
-
error: {
|
|
624
|
-
message: err.message ?? "Host is required",
|
|
625
|
-
statusCode: err.status ?? 400,
|
|
626
|
-
isNotFound: true,
|
|
627
|
-
subdomain: void 0
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
if (host?.trim()) {
|
|
632
|
-
const proto = headerList.get("x-forwarded-proto") ?? headerList.get("x-forwarded-ssl") ?? "http";
|
|
633
|
-
const secure = proto === "https" || (headerList.get("x-forwarded-ssl") ?? "") === "on";
|
|
634
|
-
setServerRequestOrigin(`${secure ? "https" : "http"}://${host}`);
|
|
635
|
-
}
|
|
636
|
-
const source = options?.source ?? resolvePublicStoreSettingsSource();
|
|
637
|
-
try {
|
|
638
|
-
setServerStoreId(null);
|
|
639
|
-
const data = source === "kv" ? await getStorefrontSettingsFromKvByStoreKey(storeKey) : await getStorefrontSettings(
|
|
640
|
-
storeKey,
|
|
641
|
-
`storefront-settings-${storeKey}`
|
|
642
|
-
);
|
|
643
|
-
setServerStoreId(data.store.id);
|
|
644
|
-
return { data, error: null };
|
|
645
|
-
} catch (error) {
|
|
646
|
-
const err = error;
|
|
647
|
-
const statusCode = err.status ?? 500;
|
|
648
|
-
return {
|
|
649
|
-
data: null,
|
|
650
|
-
error: {
|
|
651
|
-
message: err.message ?? "Error fetching store settings",
|
|
652
|
-
statusCode,
|
|
653
|
-
isNotFound: statusCode === 404,
|
|
654
|
-
subdomain: storeKey
|
|
655
|
-
}
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
var StorefrontAuthContext = createContext(null);
|
|
660
|
-
function StorefrontAuthProvider({
|
|
661
|
-
authClient,
|
|
662
|
-
children
|
|
663
|
-
}) {
|
|
664
|
-
return /* @__PURE__ */ jsx(StorefrontAuthContext.Provider, { value: authClient, children });
|
|
665
|
-
}
|
|
666
|
-
var useStore = create()(
|
|
667
|
-
(set) => ({
|
|
668
|
-
data: null,
|
|
669
|
-
drawers: {
|
|
670
|
-
cart: false,
|
|
671
|
-
search: false,
|
|
672
|
-
menu: false,
|
|
673
|
-
filter: false
|
|
674
|
-
},
|
|
675
|
-
openDrawer: (drawer) => set((state) => ({
|
|
676
|
-
drawers: {
|
|
677
|
-
...state.drawers,
|
|
678
|
-
[drawer]: true
|
|
679
|
-
}
|
|
680
|
-
})),
|
|
681
|
-
closeDrawer: (drawer) => set((state) => ({
|
|
682
|
-
drawers: {
|
|
683
|
-
...state.drawers,
|
|
684
|
-
[drawer]: false
|
|
685
|
-
}
|
|
686
|
-
})),
|
|
687
|
-
toggleDrawer: (drawer) => set((state) => ({
|
|
688
|
-
drawers: {
|
|
689
|
-
...state.drawers,
|
|
690
|
-
[drawer]: !state.drawers[drawer]
|
|
691
|
-
}
|
|
692
|
-
})),
|
|
693
|
-
closeAllDrawers: () => set((state) => ({
|
|
694
|
-
drawers: Object.keys(state.drawers).reduce(
|
|
695
|
-
(acc, key) => ({ ...acc, [key]: false }),
|
|
696
|
-
{}
|
|
697
|
-
)
|
|
698
|
-
})),
|
|
699
|
-
modals: {
|
|
700
|
-
login: false,
|
|
701
|
-
signup: false
|
|
702
|
-
},
|
|
703
|
-
openModal: (modal) => set((state) => ({
|
|
704
|
-
modals: {
|
|
705
|
-
...state.modals,
|
|
706
|
-
login: false,
|
|
707
|
-
signup: false,
|
|
708
|
-
[modal]: true
|
|
709
|
-
}
|
|
710
|
-
})),
|
|
711
|
-
closeModal: (modal) => set((state) => ({
|
|
712
|
-
modals: {
|
|
713
|
-
...state.modals,
|
|
714
|
-
login: false,
|
|
715
|
-
signup: false,
|
|
716
|
-
[modal]: false
|
|
717
|
-
}
|
|
718
|
-
})),
|
|
719
|
-
toggleModal: (modal) => set((state) => ({
|
|
720
|
-
modals: {
|
|
721
|
-
...state.modals,
|
|
722
|
-
[modal]: !state.modals[modal]
|
|
723
|
-
}
|
|
724
|
-
})),
|
|
725
|
-
closeAllModals: () => set((state) => ({
|
|
726
|
-
modals: Object.keys(state.modals).reduce(
|
|
727
|
-
(acc, key) => ({ ...acc, [key]: false }),
|
|
728
|
-
{}
|
|
729
|
-
)
|
|
730
|
-
}))
|
|
731
|
-
})
|
|
732
|
-
);
|
|
733
|
-
|
|
734
|
-
// src/react/shell/providers/EcomiqProvider.tsx
|
|
735
|
-
init_store_api_client();
|
|
736
|
-
function EcomiqProvider({
|
|
737
|
-
store,
|
|
738
|
-
authClient,
|
|
739
|
-
children,
|
|
740
|
-
withShellUi = false
|
|
741
|
-
}) {
|
|
742
|
-
useStore.setState({ data: store ?? null });
|
|
743
|
-
useEffect(() => {
|
|
744
|
-
setClientStoreId(store?.store.id ?? null);
|
|
745
|
-
return () => setClientStoreId(null);
|
|
746
|
-
}, [store]);
|
|
747
|
-
const [queryClient] = useState(() => new QueryClient());
|
|
748
|
-
const tree = /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
|
|
749
|
-
children,
|
|
750
|
-
withShellUi ? /* @__PURE__ */ jsx(EcomiqShellUi2, {}) : null
|
|
751
|
-
] });
|
|
752
|
-
if (!authClient) return tree;
|
|
753
|
-
return /* @__PURE__ */ jsx(StorefrontAuthProvider, { authClient, children: tree });
|
|
754
|
-
}
|
|
755
|
-
function EcomiqShellUi2() {
|
|
756
|
-
const [ui, setUi] = useState(null);
|
|
757
|
-
useEffect(() => {
|
|
758
|
-
void Promise.resolve().then(() => (init_ecomiq_shell_ui(), ecomiq_shell_ui_exports)).then((mod) => setUi(() => mod.EcomiqShellUi));
|
|
759
|
-
}, []);
|
|
760
|
-
return ui ? React2.createElement(ui) : null;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// src/core/client/store-api-errors.ts
|
|
764
|
-
function isCartNotActiveApiError(error) {
|
|
765
|
-
if (!error || typeof error !== "object") return false;
|
|
766
|
-
const e = error;
|
|
767
|
-
if (e.status !== 400) return false;
|
|
768
|
-
const body = e.body;
|
|
769
|
-
const keys = body?.errors ? Object.keys(body.errors) : [];
|
|
770
|
-
return keys.includes("Carts.NotActive");
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
// src/core/client/index.ts
|
|
774
|
-
init_store_api_client();
|
|
775
|
-
|
|
776
|
-
// src/core/client/store-api-product.service.ts
|
|
777
|
-
init_store_api_client();
|
|
778
|
-
async function getStorefrontProducts(params, cacheKey) {
|
|
779
|
-
const parsed = StorefrontProductsParamsSchema.parse(params ?? {});
|
|
780
|
-
const searchParams = new URLSearchParams();
|
|
781
|
-
searchParams.set("page", String(parsed.page));
|
|
782
|
-
searchParams.set("pageSize", String(parsed.pageSize));
|
|
783
|
-
if (parsed.sort) searchParams.set("sort", parsed.sort);
|
|
784
|
-
if (parsed.sellerId) searchParams.set("sellerId", parsed.sellerId);
|
|
785
|
-
if (parsed.search) searchParams.set("search", parsed.search);
|
|
786
|
-
if (parsed.collection) searchParams.set("collection", parsed.collection);
|
|
787
|
-
if (parsed.category) searchParams.set("category", parsed.category);
|
|
788
|
-
if (parsed.brand) searchParams.set("brand", parsed.brand);
|
|
789
|
-
if (parsed.productType) searchParams.set("productType", parsed.productType);
|
|
790
|
-
if (parsed.inStock != null) searchParams.set("inStock", String(parsed.inStock));
|
|
791
|
-
if (parsed.minPrice != null) searchParams.set("minPrice", String(parsed.minPrice));
|
|
792
|
-
if (parsed.maxPrice != null) searchParams.set("maxPrice", String(parsed.maxPrice));
|
|
793
|
-
const path = `products?${searchParams.toString()}`;
|
|
794
|
-
const client = await getStoreApiClient();
|
|
795
|
-
const response = await client.get(path, {
|
|
796
|
-
cacheKey
|
|
797
|
-
});
|
|
798
|
-
return StorefrontProductsResponseSchema.parse(response);
|
|
799
|
-
}
|
|
800
|
-
async function getStorefrontProductBySlug(slug) {
|
|
801
|
-
const path = `products/${encodeURIComponent(slug)}`;
|
|
802
|
-
const client = await getStoreApiClient();
|
|
803
|
-
const response = await client.get(path);
|
|
804
|
-
return StorefrontProductDetailSchema.parse(response);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
// src/core/client/store-api-collection.service.ts
|
|
808
|
-
init_store_api_client();
|
|
809
|
-
async function getStorefrontCollections() {
|
|
810
|
-
const client = await getStoreApiClient();
|
|
811
|
-
const response = await client.get("collections");
|
|
812
|
-
return StorefrontCollectionsResponseSchema.parse(response);
|
|
813
|
-
}
|
|
814
|
-
async function getStorefrontCollectionBySlug(slug) {
|
|
815
|
-
const client = await getStoreApiClient();
|
|
816
|
-
const response = await client.get(
|
|
817
|
-
`collections/by-slug/${encodeURIComponent(slug)}`
|
|
818
|
-
);
|
|
819
|
-
return StorefrontCollectionDetailSchema.parse(response);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// src/core/client/store-api-pages.service.ts
|
|
823
|
-
init_store_api_client();
|
|
824
|
-
async function getStorefrontPages() {
|
|
825
|
-
const client = await getStoreApiClient();
|
|
826
|
-
const response = await client.get("pages");
|
|
827
|
-
return z.array(StorefrontPageListItemSchema).parse(response);
|
|
828
|
-
}
|
|
829
|
-
async function getStorefrontPageBySlug(slug) {
|
|
830
|
-
const path = `pages/${encodeURIComponent(slug)}`;
|
|
831
|
-
const client = await getStoreApiClient();
|
|
832
|
-
const response = await client.get(path);
|
|
833
|
-
return StorefrontPageDetailSchema.parse(response);
|
|
834
|
-
}
|
|
835
|
-
async function getStorefrontPagePreview(slug, token) {
|
|
836
|
-
const path = `pages/${encodeURIComponent(slug)}/preview?token=${encodeURIComponent(token)}`;
|
|
837
|
-
const client = await getStoreApiClient();
|
|
838
|
-
const response = await client.get(path);
|
|
839
|
-
return StorefrontPageDetailSchema.parse(response);
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
// src/core/client/store-api-cart.service.ts
|
|
843
|
-
init_store_api_client();
|
|
844
|
-
async function createCart(data) {
|
|
845
|
-
const payload = CartCreateRequestSchema.parse(data);
|
|
846
|
-
const client = await getStoreApiClient();
|
|
847
|
-
const response = await client.post("carts", payload);
|
|
848
|
-
return CartResponseSchema.parse(response);
|
|
849
|
-
}
|
|
850
|
-
async function getCart(cartId) {
|
|
851
|
-
if (!cartId) throw new Error("cartId is required");
|
|
852
|
-
const client = await getStoreApiClient();
|
|
853
|
-
const response = await client.get(`carts/${cartId}`);
|
|
854
|
-
return CartResponseSchema.parse(response);
|
|
855
|
-
}
|
|
856
|
-
async function addCartItem(data, cartId) {
|
|
857
|
-
if (!cartId) throw new Error("cartId is required");
|
|
858
|
-
const payload = CartItemRequestSchema.parse(data);
|
|
859
|
-
const variantId = Number(payload.variantId);
|
|
860
|
-
if (!Number.isSafeInteger(variantId) || variantId <= 0) {
|
|
861
|
-
throw new Error("variantId must be a valid public id");
|
|
862
|
-
}
|
|
863
|
-
const modifiers = payload.modifiers?.map((modifier) => {
|
|
864
|
-
const modifierGroupId = Number(modifier.modifierGroupId);
|
|
865
|
-
const optionIds = modifier.optionIds.map((optionId) => Number(optionId));
|
|
866
|
-
if (!Number.isSafeInteger(modifierGroupId) || modifierGroupId <= 0 || optionIds.some((optionId) => !Number.isSafeInteger(optionId) || optionId <= 0)) {
|
|
867
|
-
throw new Error("modifiers must use valid public ids");
|
|
868
|
-
}
|
|
869
|
-
return { modifierGroupId, optionIds };
|
|
870
|
-
});
|
|
871
|
-
const client = await getStoreApiClient();
|
|
872
|
-
const response = await client.post(`carts/${cartId}/items`, {
|
|
873
|
-
...payload,
|
|
874
|
-
variantId,
|
|
875
|
-
...modifiers ? { modifiers } : {}
|
|
876
|
-
});
|
|
877
|
-
return CartResponseSchema.parse(response);
|
|
878
|
-
}
|
|
879
|
-
async function patchCartBuyer(data, cartId) {
|
|
880
|
-
if (!cartId) throw new Error("cartId is required");
|
|
881
|
-
const payload = CartBuyerRequestSchema.parse(data);
|
|
882
|
-
const client = await getStoreApiClient();
|
|
883
|
-
const response = await client.patch(
|
|
884
|
-
`carts/${cartId}/buyer`,
|
|
885
|
-
payload
|
|
886
|
-
);
|
|
887
|
-
return CartResponseSchema.parse(response);
|
|
888
|
-
}
|
|
889
|
-
async function patchCartAddresses(data, cartId) {
|
|
890
|
-
if (!cartId) throw new Error("cartId is required");
|
|
891
|
-
const payload = CartAddressesRequestSchema.parse(data);
|
|
892
|
-
const client = await getStoreApiClient();
|
|
893
|
-
const response = await client.patch(
|
|
894
|
-
`carts/${cartId}/addresses`,
|
|
895
|
-
payload
|
|
896
|
-
);
|
|
897
|
-
return CartResponseSchema.parse(response);
|
|
898
|
-
}
|
|
899
|
-
async function addCartCoupon(cartId, data) {
|
|
900
|
-
if (!cartId) throw new Error("cartId is required");
|
|
901
|
-
const payload = CartCouponRequestSchema.parse(data);
|
|
902
|
-
const client = await getStoreApiClient();
|
|
903
|
-
const response = await client.post(
|
|
904
|
-
`carts/${cartId}/promotion-codes`,
|
|
905
|
-
payload
|
|
906
|
-
);
|
|
907
|
-
return CartResponseSchema.parse(response);
|
|
908
|
-
}
|
|
909
|
-
async function removeCartCoupon(cartId, code) {
|
|
910
|
-
if (!cartId) throw new Error("cartId is required");
|
|
911
|
-
if (!code.trim()) throw new Error("code is required");
|
|
912
|
-
const client = await getStoreApiClient();
|
|
913
|
-
const response = await client.delete(
|
|
914
|
-
`carts/${cartId}/promotion-codes/${encodeURIComponent(code.trim())}`
|
|
915
|
-
);
|
|
916
|
-
return CartResponseSchema.parse(response);
|
|
917
|
-
}
|
|
918
|
-
async function checkoutCart(data, cartId) {
|
|
919
|
-
if (!cartId) throw new Error("cartId is required");
|
|
920
|
-
const payload = CartCheckoutRequestSchema.parse(data);
|
|
921
|
-
const client = await getStoreApiClient();
|
|
922
|
-
const response = await client.post(
|
|
923
|
-
`carts/${cartId}/checkout`,
|
|
924
|
-
payload
|
|
925
|
-
);
|
|
926
|
-
return CartCheckoutResponseSchema.parse(response);
|
|
927
|
-
}
|
|
928
|
-
async function uploadPaymentReceipt(cartId, file) {
|
|
929
|
-
if (!cartId) throw new Error("cartId is required");
|
|
930
|
-
const baseUrl = await getStoreApiBaseUrl();
|
|
931
|
-
const form = new FormData();
|
|
932
|
-
form.set("file", file);
|
|
933
|
-
const response = await fetch(
|
|
934
|
-
`${baseUrl.replace(/\/$/, "")}/carts/${encodeURIComponent(cartId)}/payment-receipt`,
|
|
935
|
-
{
|
|
936
|
-
method: "POST",
|
|
937
|
-
body: form,
|
|
938
|
-
...typeof window === "undefined" && { cache: "no-store" }
|
|
939
|
-
}
|
|
940
|
-
);
|
|
941
|
-
if (!response.ok) {
|
|
942
|
-
let body;
|
|
943
|
-
try {
|
|
944
|
-
const errorText = await response.text();
|
|
945
|
-
body = errorText ? JSON.parse(errorText) : void 0;
|
|
946
|
-
} catch {
|
|
947
|
-
body = void 0;
|
|
948
|
-
}
|
|
949
|
-
const message = typeof body === "object" && body !== null && "title" in body && typeof body.title === "string" ? body.title : response.statusText || "Store API error";
|
|
950
|
-
const error = new Error(message);
|
|
951
|
-
error.status = response.status;
|
|
952
|
-
error.body = body;
|
|
953
|
-
throw error;
|
|
954
|
-
}
|
|
955
|
-
return CartPaymentReceiptResponseSchema.parse(await response.json());
|
|
956
|
-
}
|
|
957
|
-
async function getCartCheckout(cartId) {
|
|
958
|
-
if (!cartId) throw new Error("cartId is required");
|
|
959
|
-
const client = await getStoreApiClient();
|
|
960
|
-
const response = await client.get(`carts/${cartId}/checkout`);
|
|
961
|
-
return CartCheckoutReadResponseSchema.parse(response);
|
|
962
|
-
}
|
|
963
|
-
async function getShippingOptions(cartId, postalCode) {
|
|
964
|
-
if (!cartId) throw new Error("cartId is required");
|
|
965
|
-
if (!postalCode?.trim()) throw new Error("postalCode is required");
|
|
966
|
-
const client = await getStoreApiClient();
|
|
967
|
-
const q = new URLSearchParams({ postalCode: postalCode.trim() });
|
|
968
|
-
const response = await client.get(
|
|
969
|
-
`carts/${cartId}/shipping-options?${q.toString()}`
|
|
970
|
-
);
|
|
971
|
-
return ShippingOptionsResponseSchema.parse(response);
|
|
972
|
-
}
|
|
973
|
-
async function putCartShippingMethod(cartId, data) {
|
|
974
|
-
if (!cartId) throw new Error("cartId is required");
|
|
975
|
-
const payload = CartShippingMethodPutRequestSchema.parse(data);
|
|
976
|
-
const client = await getStoreApiClient();
|
|
977
|
-
const response = await client.put(
|
|
978
|
-
`carts/${cartId}/shipping-method`,
|
|
979
|
-
payload
|
|
980
|
-
);
|
|
981
|
-
return CartResponseSchema.parse(response);
|
|
982
|
-
}
|
|
983
|
-
async function getCartPaymentMethods(cartId) {
|
|
984
|
-
if (!cartId) throw new Error("cartId is required");
|
|
985
|
-
const { paymentMethods } = await getCartCheckout(cartId);
|
|
986
|
-
return paymentMethods;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
// src/core/client/index.ts
|
|
990
|
-
init_store_api_customer_service();
|
|
991
|
-
|
|
992
|
-
// src/core/client/store-api-customer-order.service.ts
|
|
993
|
-
init_store_api_client();
|
|
994
|
-
var CustomerOrderShippingAddressSchema = z.object({
|
|
995
|
-
name: z.string().nullable().optional(),
|
|
996
|
-
company: z.string().nullable().optional(),
|
|
997
|
-
address1: z.string(),
|
|
998
|
-
address2: z.string().nullable().optional(),
|
|
999
|
-
city: z.string().nullable().optional(),
|
|
1000
|
-
countryCode: z.string(),
|
|
1001
|
-
province: z.string().nullable().optional(),
|
|
1002
|
-
postalCode: z.string().nullable().optional(),
|
|
1003
|
-
district: z.string().nullable().optional(),
|
|
1004
|
-
phone: z.string().nullable().optional(),
|
|
1005
|
-
latitude: z.number().nullable().optional(),
|
|
1006
|
-
longitude: z.number().nullable().optional(),
|
|
1007
|
-
metadata: z.record(z.unknown()).nullable().optional()
|
|
1008
|
-
}).passthrough();
|
|
1009
|
-
var CustomerOrderLineItemSchema = z.object({
|
|
1010
|
-
id: z.string(),
|
|
1011
|
-
orderId: z.coerce.string(),
|
|
1012
|
-
productId: z.coerce.string().nullable(),
|
|
1013
|
-
variantId: z.coerce.string().nullable(),
|
|
1014
|
-
title: z.string(),
|
|
1015
|
-
subtitle: z.string().nullable().optional(),
|
|
1016
|
-
thumbnail: z.string().nullable().optional(),
|
|
1017
|
-
variantTitle: z.string().nullable().optional(),
|
|
1018
|
-
productHandle: z.string().nullable().optional(),
|
|
1019
|
-
quantity: z.number(),
|
|
1020
|
-
unitPrice: z.number(),
|
|
1021
|
-
total: z.number(),
|
|
1022
|
-
status: z.string()
|
|
1023
|
-
});
|
|
1024
|
-
var CustomerOrderListItemSchema = z.object({
|
|
1025
|
-
orderId: z.coerce.string(),
|
|
1026
|
-
orderNumber: z.string(),
|
|
1027
|
-
orderGroup: z.string(),
|
|
1028
|
-
orderIds: z.array(z.coerce.string()),
|
|
1029
|
-
status: z.string(),
|
|
1030
|
-
total: z.number(),
|
|
1031
|
-
totalPaid: z.number(),
|
|
1032
|
-
currencyCode: z.string(),
|
|
1033
|
-
orderDate: z.string(),
|
|
1034
|
-
createdOn: z.string(),
|
|
1035
|
-
updatedOn: z.string().nullable().optional(),
|
|
1036
|
-
paymentAt: z.string().nullable().optional(),
|
|
1037
|
-
shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1038
|
-
shippingAddressSummary: z.string().nullable().optional(),
|
|
1039
|
-
items: z.array(CustomerOrderLineItemSchema)
|
|
1040
|
-
});
|
|
1041
|
-
var CustomerOrderPaymentSchema = z.object({
|
|
1042
|
-
id: z.string(),
|
|
1043
|
-
paymentMethod: z.string(),
|
|
1044
|
-
paymentCode: z.string(),
|
|
1045
|
-
amount: z.number(),
|
|
1046
|
-
paymentStatus: z.string(),
|
|
1047
|
-
receiptUrl: z.string().nullable().optional(),
|
|
1048
|
-
createdOn: z.string()
|
|
1049
|
-
});
|
|
1050
|
-
var CustomerOrderStatusTimelineSchema = z.object({
|
|
1051
|
-
key: z.string(),
|
|
1052
|
-
label: z.string(),
|
|
1053
|
-
occurredAt: z.string(),
|
|
1054
|
-
description: z.string().nullable().optional(),
|
|
1055
|
-
status: z.string(),
|
|
1056
|
-
source: z.string()
|
|
1057
|
-
});
|
|
1058
|
-
var CustomerOrderDetailSchema = z.object({
|
|
1059
|
-
id: z.coerce.string(),
|
|
1060
|
-
orderNumber: z.string(),
|
|
1061
|
-
orderGroup: z.string(),
|
|
1062
|
-
status: z.string(),
|
|
1063
|
-
total: z.number(),
|
|
1064
|
-
totalPaid: z.number(),
|
|
1065
|
-
currencyCode: z.string(),
|
|
1066
|
-
orderDate: z.string(),
|
|
1067
|
-
createdOn: z.string(),
|
|
1068
|
-
updatedOn: z.string().nullable().optional(),
|
|
1069
|
-
paymentAt: z.string().nullable().optional(),
|
|
1070
|
-
subTotal: z.number(),
|
|
1071
|
-
discount: z.number(),
|
|
1072
|
-
shipping: z.number(),
|
|
1073
|
-
tax: z.number(),
|
|
1074
|
-
email: z.string(),
|
|
1075
|
-
phone: z.string(),
|
|
1076
|
-
firstName: z.string(),
|
|
1077
|
-
lastName: z.string(),
|
|
1078
|
-
shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1079
|
-
shippingAddressSummary: z.string().nullable().optional(),
|
|
1080
|
-
billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
|
|
1081
|
-
items: z.array(CustomerOrderLineItemSchema),
|
|
1082
|
-
payments: z.array(CustomerOrderPaymentSchema),
|
|
1083
|
-
statusTimeline: z.array(CustomerOrderStatusTimelineSchema)
|
|
1084
|
-
});
|
|
1085
|
-
function authOptions(accessToken) {
|
|
1086
|
-
const token = typeof accessToken === "string" && accessToken.trim().length > 0 ? accessToken.trim() : void 0;
|
|
1087
|
-
return token ? { bearerToken: token } : {};
|
|
1088
|
-
}
|
|
1089
|
-
async function getCustomerOrders(accessToken) {
|
|
1090
|
-
const client = await getStoreApiClient();
|
|
1091
|
-
const response = await client.get("customer/orders", authOptions(accessToken));
|
|
1092
|
-
return z.array(CustomerOrderListItemSchema).parse(response);
|
|
1093
|
-
}
|
|
1094
|
-
async function getCustomerOrder(orderId, accessToken) {
|
|
1095
|
-
const client = await getStoreApiClient();
|
|
1096
|
-
const id = orderId.trim();
|
|
1097
|
-
if (!id) throw new Error("orderId requerido");
|
|
1098
|
-
const response = await client.get(
|
|
1099
|
-
`customer/orders/${encodeURIComponent(id)}`,
|
|
1100
|
-
authOptions(accessToken)
|
|
1101
|
-
);
|
|
1102
|
-
return CustomerOrderDetailSchema.parse(response);
|
|
1103
|
-
}
|
|
1104
|
-
var StorefrontOrderAddressSchema = z.object({
|
|
1105
|
-
address1: z.string().optional(),
|
|
1106
|
-
address2: z.string().optional(),
|
|
1107
|
-
city: z.string().optional(),
|
|
1108
|
-
province: z.string().optional(),
|
|
1109
|
-
country: z.string().optional(),
|
|
1110
|
-
zip: z.string().optional(),
|
|
1111
|
-
phone: z.string().optional(),
|
|
1112
|
-
firstName: z.string().optional(),
|
|
1113
|
-
lastName: z.string().optional()
|
|
1114
|
-
}).passthrough();
|
|
1115
|
-
var OrderDraftItemSchema = z.object({
|
|
1116
|
-
id: z.string(),
|
|
1117
|
-
productId: z.coerce.string().nullable().optional(),
|
|
1118
|
-
sellerId: z.string().nullable().optional(),
|
|
1119
|
-
shippingProfileId: z.string().nullable().optional(),
|
|
1120
|
-
variantId: z.coerce.string().nullable().optional(),
|
|
1121
|
-
title: z.string(),
|
|
1122
|
-
subtitle: z.string().nullable().optional(),
|
|
1123
|
-
thumbnail: z.string().nullable().optional(),
|
|
1124
|
-
quantity: z.number().optional().default(1),
|
|
1125
|
-
unitPrice: z.number().optional().default(0),
|
|
1126
|
-
subTotal: z.number().optional().default(0),
|
|
1127
|
-
discount: z.number().optional().default(0),
|
|
1128
|
-
shipping: z.number().optional().default(0),
|
|
1129
|
-
tax: z.number().optional().default(0),
|
|
1130
|
-
warranty: z.number().optional().default(0),
|
|
1131
|
-
total: z.number().optional().default(0),
|
|
1132
|
-
requiresShipping: z.boolean().optional().default(true),
|
|
1133
|
-
isTaxInclusive: z.boolean().optional().default(true),
|
|
1134
|
-
metadata: z.record(z.unknown()).optional().default({})
|
|
1135
|
-
});
|
|
1136
|
-
var OrderDraftShippingMethodSchema = z.object({
|
|
1137
|
-
id: z.string(),
|
|
1138
|
-
name: z.string().optional().default(""),
|
|
1139
|
-
description: z.string().nullable().optional(),
|
|
1140
|
-
subtotal: z.number().optional().default(0),
|
|
1141
|
-
discountTotal: z.number().optional().default(0),
|
|
1142
|
-
taxTotal: z.number().optional().default(0),
|
|
1143
|
-
total: z.number().optional().default(0),
|
|
1144
|
-
isTaxInclusive: z.boolean().optional().default(true),
|
|
1145
|
-
sellerId: z.string().nullable().optional(),
|
|
1146
|
-
shippingProfileId: z.string().nullable().optional(),
|
|
1147
|
-
shippingMethodId: z.string().nullable().optional(),
|
|
1148
|
-
connectionId: z.string().nullable().optional(),
|
|
1149
|
-
providerName: z.string().nullable().optional(),
|
|
1150
|
-
trackingCode: z.string().nullable().optional(),
|
|
1151
|
-
estimatedDays: z.number().nullable().optional(),
|
|
1152
|
-
zoneCode: z.string().nullable().optional(),
|
|
1153
|
-
locationId: z.string().nullable().optional(),
|
|
1154
|
-
pickupPointId: z.string().nullable().optional(),
|
|
1155
|
-
scheduledDate: z.string().nullable().optional(),
|
|
1156
|
-
scheduledTime: z.string().nullable().optional(),
|
|
1157
|
-
data: z.record(z.unknown()).optional().default({})
|
|
1158
|
-
});
|
|
1159
|
-
var OrderDraftSchema = z.object({
|
|
1160
|
-
id: z.string(),
|
|
1161
|
-
storeId: z.string().optional(),
|
|
1162
|
-
customerId: z.coerce.string().nullable().optional(),
|
|
1163
|
-
cartId: z.string().nullable().optional(),
|
|
1164
|
-
draftNumber: z.string(),
|
|
1165
|
-
currencyCode: z.string().optional().default("PEN"),
|
|
1166
|
-
source: z.string().nullable().optional(),
|
|
1167
|
-
notes: z.string().nullable().optional(),
|
|
1168
|
-
email: z.string().nullable().optional(),
|
|
1169
|
-
phone: z.string().nullable().optional(),
|
|
1170
|
-
firstName: z.string().nullable().optional(),
|
|
1171
|
-
lastName: z.string().nullable().optional(),
|
|
1172
|
-
identificationType: z.string().nullable().optional(),
|
|
1173
|
-
identificationNumber: z.string().nullable().optional(),
|
|
1174
|
-
entityTaxId: z.string().nullable().optional(),
|
|
1175
|
-
entityName: z.string().nullable().optional(),
|
|
1176
|
-
status: z.string(),
|
|
1177
|
-
draftDate: z.string().nullable().optional(),
|
|
1178
|
-
sentAt: z.string().nullable().optional(),
|
|
1179
|
-
viewedAt: z.string().nullable().optional(),
|
|
1180
|
-
acceptedAt: z.string().nullable().optional(),
|
|
1181
|
-
rejectedAt: z.string().nullable().optional(),
|
|
1182
|
-
expiredAt: z.string().nullable().optional(),
|
|
1183
|
-
cancelledAt: z.string().nullable().optional(),
|
|
1184
|
-
convertedAt: z.string().nullable().optional(),
|
|
1185
|
-
shareToken: z.string().nullable().optional(),
|
|
1186
|
-
shareExpiresAt: z.string().nullable().optional(),
|
|
1187
|
-
allowAnonymousShareAccess: z.boolean().optional().default(false),
|
|
1188
|
-
sharedAt: z.string().nullable().optional(),
|
|
1189
|
-
billingAddress: StorefrontOrderAddressSchema.optional().nullable(),
|
|
1190
|
-
shippingAddress: StorefrontOrderAddressSchema.optional().nullable(),
|
|
1191
|
-
metadata: z.record(z.unknown()).optional().default({}),
|
|
1192
|
-
subTotal: z.number().optional().default(0),
|
|
1193
|
-
discount: z.number().optional().default(0),
|
|
1194
|
-
shipping: z.number().optional().default(0),
|
|
1195
|
-
tax: z.number().optional().default(0),
|
|
1196
|
-
warranty: z.number().optional().default(0),
|
|
1197
|
-
total: z.number().optional().default(0),
|
|
1198
|
-
paymentMethod: z.string().optional().default(""),
|
|
1199
|
-
paymentCode: z.string().optional().default(""),
|
|
1200
|
-
items: z.array(OrderDraftItemSchema).optional().default([]),
|
|
1201
|
-
shippingMethods: z.array(OrderDraftShippingMethodSchema).optional().default([]),
|
|
1202
|
-
createdOn: z.string().optional(),
|
|
1203
|
-
updatedOn: z.string().nullable().optional()
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
// src/core/client/store-api-order-draft.service.ts
|
|
1207
|
-
init_store_api_client();
|
|
1208
|
-
async function getSharedOrderDraft(shareToken) {
|
|
1209
|
-
const client = await getStoreApiClient();
|
|
1210
|
-
const response = await client.get(
|
|
1211
|
-
`order-drafts/share/${encodeURIComponent(shareToken)}`,
|
|
1212
|
-
{ noStore: true }
|
|
1213
|
-
);
|
|
1214
|
-
return OrderDraftSchema.parse(response);
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
// src/npm/nextjs.ts
|
|
1218
|
-
init_store_api_customer_service();
|
|
1219
|
-
var StorefrontCheckoutSettingsSchema = z.object({
|
|
1220
|
-
allowGuestCheckout: z.boolean().optional(),
|
|
1221
|
-
identityScope: z.enum(["store", "tenant", "global"]).optional(),
|
|
1222
|
-
signInMethods: z.array(z.string()).optional()
|
|
1223
|
-
});
|
|
1224
|
-
var looseRecord = z.record(z.string(), z.unknown());
|
|
1225
|
-
var StorefrontThemeConfigSchema = z.object({
|
|
1226
|
-
name: z.string().nullable().optional(),
|
|
1227
|
-
mode: z.string().nullable().optional(),
|
|
1228
|
-
colors: looseRecord.optional(),
|
|
1229
|
-
fonts: looseRecord.optional(),
|
|
1230
|
-
assets: looseRecord.optional()
|
|
1231
|
-
}).passthrough();
|
|
1232
|
-
var StorefrontFeaturesEnabledSchema = z.object({
|
|
1233
|
-
flags: looseRecord.optional()
|
|
1234
|
-
}).passthrough();
|
|
1235
|
-
var StorefrontCmsBrandingSchema = z.object({
|
|
1236
|
-
logoUrl: z.string().nullable().optional(),
|
|
1237
|
-
logoDarkUrl: z.string().nullable().optional(),
|
|
1238
|
-
faviconUrl: z.string().nullable().optional(),
|
|
1239
|
-
socialImageUrl: z.string().nullable().optional()
|
|
1240
|
-
});
|
|
1241
|
-
var StorefrontCmsSeoSchema = z.object({
|
|
1242
|
-
siteName: z.string().nullable().optional(),
|
|
1243
|
-
metaTitle: z.string().nullable().optional(),
|
|
1244
|
-
metaDescription: z.string().nullable().optional(),
|
|
1245
|
-
titleTemplate: z.string().nullable().optional(),
|
|
1246
|
-
robotsIndex: z.boolean().optional()
|
|
1247
|
-
});
|
|
1248
|
-
var StorefrontCmsSocialLinksSchema = z.object({
|
|
1249
|
-
instagram: z.string().nullable().optional(),
|
|
1250
|
-
facebook: z.string().nullable().optional(),
|
|
1251
|
-
tiktok: z.string().nullable().optional(),
|
|
1252
|
-
youtube: z.string().nullable().optional(),
|
|
1253
|
-
x: z.string().nullable().optional()
|
|
1254
|
-
});
|
|
1255
|
-
var StorefrontCmsContactSchema = z.object({
|
|
1256
|
-
supportEmail: z.string().nullable().optional(),
|
|
1257
|
-
phone: z.string().nullable().optional(),
|
|
1258
|
-
whatsapp: z.string().nullable().optional(),
|
|
1259
|
-
address: z.string().nullable().optional(),
|
|
1260
|
-
socialLinks: StorefrontCmsSocialLinksSchema.optional()
|
|
1261
|
-
});
|
|
1262
|
-
var StorefrontCmsTrackingSchema = z.object({
|
|
1263
|
-
googleAnalyticsMeasurementId: z.string().nullable().optional(),
|
|
1264
|
-
metaPixelId: z.string().nullable().optional(),
|
|
1265
|
-
googleTagManagerContainerId: z.string().nullable().optional()
|
|
1266
|
-
});
|
|
1267
|
-
var StorefrontCmsCustomScriptsSchema = z.object({
|
|
1268
|
-
enabled: z.boolean().optional(),
|
|
1269
|
-
head: z.string().nullable().optional(),
|
|
1270
|
-
bodyEnd: z.string().nullable().optional()
|
|
1271
|
-
});
|
|
1272
|
-
var StorefrontCmsSettingsSchema = z.object({
|
|
1273
|
-
themeKey: z.string().optional(),
|
|
1274
|
-
branding: StorefrontCmsBrandingSchema.optional(),
|
|
1275
|
-
seo: StorefrontCmsSeoSchema.optional(),
|
|
1276
|
-
contact: StorefrontCmsContactSchema.optional(),
|
|
1277
|
-
tracking: StorefrontCmsTrackingSchema.optional(),
|
|
1278
|
-
customScripts: StorefrontCmsCustomScriptsSchema.optional(),
|
|
1279
|
-
updatedOn: z.string().nullable().optional()
|
|
1280
|
-
});
|
|
1281
|
-
var StorefrontCmsPageSchema = z.object({
|
|
1282
|
-
id: z.string(),
|
|
1283
|
-
name: z.string(),
|
|
1284
|
-
slug: z.string(),
|
|
1285
|
-
layout: z.string().optional(),
|
|
1286
|
-
version: z.number().optional(),
|
|
1287
|
-
settings: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
1288
|
-
sections: z.array(z.unknown()).optional(),
|
|
1289
|
-
status: z.string().optional(),
|
|
1290
|
-
hasPublishedVersion: z.boolean().optional(),
|
|
1291
|
-
publishedOn: z.string().nullable().optional(),
|
|
1292
|
-
publishedBy: z.string().nullable().optional(),
|
|
1293
|
-
createdOn: z.string().nullable().optional(),
|
|
1294
|
-
updatedOn: z.string().nullable().optional(),
|
|
1295
|
-
createdBy: z.string().nullable().optional(),
|
|
1296
|
-
updatedBy: z.string().nullable().optional(),
|
|
1297
|
-
lastModifiedBy: z.string().nullable().optional()
|
|
1298
|
-
}).passthrough();
|
|
1299
|
-
var StorefrontSettingsLegacyFlatSchema = z.object({
|
|
1300
|
-
id: z.coerce.string(),
|
|
1301
|
-
tenantId: z.string().nullable().optional(),
|
|
1302
|
-
name: z.string(),
|
|
1303
|
-
slug: z.coerce.string().optional(),
|
|
1304
|
-
description: z.string().nullable().optional(),
|
|
1305
|
-
visibility: z.string().nullable().optional(),
|
|
1306
|
-
logo: z.string().nullable().optional(),
|
|
1307
|
-
favicon: z.string().nullable().optional(),
|
|
1308
|
-
icon: z.string().nullable().optional(),
|
|
1309
|
-
currency: z.string().nullable().optional(),
|
|
1310
|
-
language: z.string().nullable().optional(),
|
|
1311
|
-
themeConfig: z.unknown().optional().nullable(),
|
|
1312
|
-
featuresEnabled: z.unknown().optional().nullable(),
|
|
1313
|
-
checkoutSettings: StorefrontCheckoutSettingsSchema.optional().nullable()
|
|
1314
|
-
}).passthrough();
|
|
1315
|
-
function unwrapSettingsResponseBody(v) {
|
|
1316
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return v;
|
|
1317
|
-
const o = v;
|
|
1318
|
-
if ("data" in o && o.data != null && typeof o.data === "object" && !Array.isArray(o.data)) {
|
|
1319
|
-
return o.data;
|
|
1320
|
-
}
|
|
1321
|
-
return v;
|
|
1322
|
-
}
|
|
1323
|
-
function isLegacyFlatSettingsPayload(v) {
|
|
1324
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
1325
|
-
const o = v;
|
|
1326
|
-
if ("store" in o || "schemaVersion" in o || "cms" in o) return false;
|
|
1327
|
-
return (typeof o.id === "string" || typeof o.id === "number") && typeof o.name === "string";
|
|
1328
|
-
}
|
|
1329
|
-
function normalizeStorefrontSettingsPayload(v) {
|
|
1330
|
-
const body = unwrapSettingsResponseBody(v);
|
|
1331
|
-
if (!isLegacyFlatSettingsPayload(body)) return body;
|
|
1332
|
-
const raw = body;
|
|
1333
|
-
const parsed = StorefrontSettingsLegacyFlatSchema.safeParse(raw);
|
|
1334
|
-
if (!parsed.success) return body;
|
|
1335
|
-
const l = parsed.data;
|
|
1336
|
-
const currency = l.currency?.trim() ? l.currency : "PEN";
|
|
1337
|
-
const language = l.language?.trim() ? l.language : "es";
|
|
1338
|
-
const slug = l.slug?.trim() ? l.slug : l.id;
|
|
1339
|
-
return {
|
|
1340
|
-
schemaVersion: 0,
|
|
1341
|
-
generatedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1342
|
-
store: {
|
|
1343
|
-
id: l.id,
|
|
1344
|
-
tenantId: l.tenantId ?? void 0,
|
|
1345
|
-
name: l.name,
|
|
1346
|
-
slug,
|
|
1347
|
-
description: l.description ?? null,
|
|
1348
|
-
logo: l.logo ?? null,
|
|
1349
|
-
icon: l.icon ?? null,
|
|
1350
|
-
visibility: l.visibility ?? void 0,
|
|
1351
|
-
currency,
|
|
1352
|
-
language,
|
|
1353
|
-
themeConfig: l.themeConfig ?? void 0,
|
|
1354
|
-
featuresEnabled: l.featuresEnabled ?? void 0,
|
|
1355
|
-
checkoutSettings: l.checkoutSettings ?? void 0
|
|
1356
|
-
},
|
|
1357
|
-
cms: {
|
|
1358
|
-
settings: {
|
|
1359
|
-
branding: {
|
|
1360
|
-
faviconUrl: l.favicon ?? null,
|
|
1361
|
-
logoUrl: l.logo ?? null,
|
|
1362
|
-
logoDarkUrl: null,
|
|
1363
|
-
socialImageUrl: null
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
pages: []
|
|
1367
|
-
}
|
|
1368
|
-
};
|
|
1369
|
-
}
|
|
1370
|
-
var StorefrontStoreSchema = z.object({
|
|
1371
|
-
id: z.string(),
|
|
1372
|
-
tenantId: z.string().optional(),
|
|
1373
|
-
sellerId: z.string().optional(),
|
|
1374
|
-
plan: z.string().optional(),
|
|
1375
|
-
storageLimitBytes: z.number().optional(),
|
|
1376
|
-
monthlyTransferLimitBytes: z.number().optional(),
|
|
1377
|
-
maxUploadSizeBytes: z.number().optional(),
|
|
1378
|
-
maxStores: z.number().optional(),
|
|
1379
|
-
maxMembers: z.number().optional(),
|
|
1380
|
-
maxProducts: z.number().optional(),
|
|
1381
|
-
maxCategories: z.number().optional(),
|
|
1382
|
-
maxBrands: z.number().optional(),
|
|
1383
|
-
maxAttributes: z.number().optional(),
|
|
1384
|
-
maxCollections: z.number().optional(),
|
|
1385
|
-
enableApi: z.boolean().optional(),
|
|
1386
|
-
isActive: z.boolean().optional(),
|
|
1387
|
-
name: z.string(),
|
|
1388
|
-
description: z.string().nullable().optional(),
|
|
1389
|
-
avatarUrl: z.string().nullable().optional(),
|
|
1390
|
-
logo: z.string().nullable().optional(),
|
|
1391
|
-
icon: z.string().nullable().optional(),
|
|
1392
|
-
slug: z.string(),
|
|
1393
|
-
domain: z.string().nullable().optional(),
|
|
1394
|
-
domains: z.array(z.string()).optional(),
|
|
1395
|
-
timeZone: z.string().nullable().optional(),
|
|
1396
|
-
currency: z.string(),
|
|
1397
|
-
language: z.string(),
|
|
1398
|
-
visibility: z.string().optional(),
|
|
1399
|
-
privateAccessHash: z.string().nullable().optional(),
|
|
1400
|
-
privateAccessVersion: z.number().optional(),
|
|
1401
|
-
themeConfig: StorefrontThemeConfigSchema.optional(),
|
|
1402
|
-
featuresEnabled: StorefrontFeaturesEnabledSchema.optional(),
|
|
1403
|
-
checkoutSettings: StorefrontCheckoutSettingsSchema.optional().nullable()
|
|
1404
|
-
}).passthrough();
|
|
1405
|
-
var StorefrontSettingsEnvelopeSchema = z.object({
|
|
1406
|
-
schemaVersion: z.number(),
|
|
1407
|
-
generatedAt: z.string(),
|
|
1408
|
-
store: StorefrontStoreSchema,
|
|
1409
|
-
cms: z.object({
|
|
1410
|
-
settings: StorefrontCmsSettingsSchema,
|
|
1411
|
-
pages: z.array(StorefrontCmsPageSchema)
|
|
1412
|
-
})
|
|
1413
|
-
}).passthrough();
|
|
1414
|
-
z.preprocess(
|
|
1415
|
-
normalizeStorefrontSettingsPayload,
|
|
1416
|
-
StorefrontSettingsEnvelopeSchema
|
|
1417
|
-
);
|
|
1418
|
-
function storefrontStoreRecord(settings) {
|
|
1419
|
-
return settings?.store ?? null;
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
// src/core/lib/ecomiq-oauth-identity.ts
|
|
1423
|
-
function buildEcomiqOAuthIdentityHeaders(settings) {
|
|
1424
|
-
const record = storefrontStoreRecord(settings);
|
|
1425
|
-
if (!record?.id) {
|
|
1426
|
-
throw new Error("Tienda no disponible para iniciar sesi\xF3n");
|
|
1427
|
-
}
|
|
1428
|
-
const checkout = record.checkoutSettings;
|
|
1429
|
-
const identityScope = checkout?.identityScope === "tenant" ? "tenant" : "store";
|
|
1430
|
-
const headers3 = {
|
|
1431
|
-
"x-Identity-Scope": identityScope,
|
|
1432
|
-
"x-Store-Id": record.id
|
|
1433
|
-
};
|
|
1434
|
-
if (record.tenantId) headers3["x-Tenant-Id"] = record.tenantId;
|
|
1435
|
-
return headers3;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
// src/react/auth/ecomiq-storefront-sign-in.ts
|
|
1439
|
-
async function signInWithEcomiqCredentials2(authClient, settings, credentials) {
|
|
1440
|
-
const response = await authClient.$fetch("/ecomiq-oauth/sign-in", {
|
|
1441
|
-
method: "POST",
|
|
1442
|
-
headers: buildEcomiqOAuthIdentityHeaders(settings),
|
|
1443
|
-
body: credentials
|
|
1444
|
-
});
|
|
1445
|
-
if (response.error) {
|
|
1446
|
-
throw new Error(response.error.message ?? "Error al iniciar sesi\xF3n");
|
|
1447
|
-
}
|
|
1448
|
-
return response;
|
|
1449
|
-
}
|
|
1450
|
-
function useStoreProducts() {
|
|
1451
|
-
const useStorefrontProductsList = (params) => {
|
|
1452
|
-
return useQuery({
|
|
1453
|
-
queryKey: ["storefront", "products", params],
|
|
1454
|
-
queryFn: () => getStorefrontProducts(params)
|
|
1455
|
-
});
|
|
1456
|
-
};
|
|
1457
|
-
const useStorefrontInfiniteProducts = (params) => {
|
|
1458
|
-
return useInfiniteQuery({
|
|
1459
|
-
queryKey: ["storefront", "products", "infinite", params],
|
|
1460
|
-
queryFn: ({ pageParam = 1 }) => getStorefrontProducts({ ...params, page: pageParam }),
|
|
1461
|
-
getNextPageParam: (lastPage) => lastPage.pageIndex < lastPage.totalPages ? lastPage.pageIndex + 1 : void 0,
|
|
1462
|
-
initialPageParam: 1
|
|
1463
|
-
});
|
|
1464
|
-
};
|
|
1465
|
-
const useProductBySlug = (slug) => {
|
|
1466
|
-
return useQuery({
|
|
1467
|
-
queryKey: ["storefront", "product", "slug", slug],
|
|
1468
|
-
queryFn: () => getStorefrontProductBySlug(slug),
|
|
1469
|
-
enabled: !!slug
|
|
1470
|
-
});
|
|
1471
|
-
};
|
|
1472
|
-
const useRefreshStorefrontProducts = () => {
|
|
1473
|
-
const queryClient = useQueryClient();
|
|
1474
|
-
return useMutation({
|
|
1475
|
-
mutationFn: (params) => getStorefrontProducts(params),
|
|
1476
|
-
onSuccess: () => {
|
|
1477
|
-
queryClient.invalidateQueries({ queryKey: ["storefront", "products"] });
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
};
|
|
1481
|
-
return {
|
|
1482
|
-
useStorefrontProductsList,
|
|
1483
|
-
useStorefrontInfiniteProducts,
|
|
1484
|
-
useProductBySlug,
|
|
1485
|
-
useRefreshStorefrontProducts
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1488
|
-
function useStoreCollections() {
|
|
1489
|
-
const useStorefrontCollectionsList = () => {
|
|
1490
|
-
return useQuery({
|
|
1491
|
-
queryKey: ["storefront", "collections"],
|
|
1492
|
-
queryFn: () => getStorefrontCollections()
|
|
1493
|
-
});
|
|
1494
|
-
};
|
|
1495
|
-
const useCollectionBySlug = (slug) => {
|
|
1496
|
-
return useQuery({
|
|
1497
|
-
queryKey: ["storefront", "collection", "slug", slug],
|
|
1498
|
-
queryFn: () => getStorefrontCollectionBySlug(slug),
|
|
1499
|
-
enabled: !!slug
|
|
1500
|
-
});
|
|
1501
|
-
};
|
|
1502
|
-
const useRefreshStorefrontCollections = () => {
|
|
1503
|
-
const queryClient = useQueryClient();
|
|
1504
|
-
return useMutation({
|
|
1505
|
-
mutationFn: () => getStorefrontCollections(),
|
|
1506
|
-
onSuccess: () => {
|
|
1507
|
-
queryClient.invalidateQueries({ queryKey: ["storefront", "collections"] });
|
|
1508
|
-
}
|
|
1509
|
-
});
|
|
1510
|
-
};
|
|
1511
|
-
return {
|
|
1512
|
-
useStorefrontCollectionsList,
|
|
1513
|
-
useCollectionBySlug,
|
|
1514
|
-
useRefreshStorefrontCollections
|
|
1515
|
-
};
|
|
1516
|
-
}
|
|
1517
|
-
function useStorePages() {
|
|
1518
|
-
const useStorefrontPagesList = () => {
|
|
1519
|
-
return useQuery({
|
|
1520
|
-
queryKey: ["storefront", "pages"],
|
|
1521
|
-
queryFn: () => getStorefrontPages()
|
|
1522
|
-
});
|
|
1523
|
-
};
|
|
1524
|
-
const usePageBySlug = (slug) => {
|
|
1525
|
-
return useQuery({
|
|
1526
|
-
queryKey: ["storefront", "page", "slug", slug],
|
|
1527
|
-
queryFn: () => getStorefrontPageBySlug(slug),
|
|
1528
|
-
enabled: !!slug
|
|
1529
|
-
});
|
|
1530
|
-
};
|
|
1531
|
-
const useRefreshStorefrontPages = () => {
|
|
1532
|
-
const queryClient = useQueryClient();
|
|
1533
|
-
return useMutation({
|
|
1534
|
-
mutationFn: () => getStorefrontPages(),
|
|
1535
|
-
onSuccess: () => {
|
|
1536
|
-
queryClient.invalidateQueries({ queryKey: ["storefront", "pages"] });
|
|
1537
|
-
}
|
|
1538
|
-
});
|
|
1539
|
-
};
|
|
1540
|
-
return {
|
|
1541
|
-
useStorefrontPagesList,
|
|
1542
|
-
usePageBySlug,
|
|
1543
|
-
useRefreshStorefrontPages
|
|
1544
|
-
};
|
|
1545
|
-
}
|
|
1546
|
-
function useStoreCart() {
|
|
1547
|
-
const useGetCart = (cartId) => useQuery({
|
|
1548
|
-
queryKey: ["storefront", "cart", cartId ?? null],
|
|
1549
|
-
queryFn: () => getCart(cartId ?? void 0),
|
|
1550
|
-
// Si devuelve 404 no reintentar; para otros errores solo un intento adicional como máximo.
|
|
1551
|
-
retry: (failureCount, error) => {
|
|
1552
|
-
const status = error.status;
|
|
1553
|
-
if (status === 404) return false;
|
|
1554
|
-
return failureCount < 1;
|
|
1555
|
-
},
|
|
1556
|
-
// Evitar refetch automático al enfocar la ventana; el carrito se carga una sola vez aquí.
|
|
1557
|
-
refetchOnWindowFocus: false,
|
|
1558
|
-
enabled: !!cartId
|
|
1559
|
-
});
|
|
1560
|
-
const useCreateCart = () => useMutation({
|
|
1561
|
-
mutationFn: (data) => createCart(data)
|
|
1562
|
-
});
|
|
1563
|
-
const useUpdateCartBuyer = () => useMutation({
|
|
1564
|
-
mutationFn: ({ data, cartId }) => patchCartBuyer(data, cartId)
|
|
1565
|
-
});
|
|
1566
|
-
const useUpdateCartAddresses = () => useMutation({
|
|
1567
|
-
mutationFn: ({ data, cartId }) => patchCartAddresses(data, cartId)
|
|
1568
|
-
});
|
|
1569
|
-
const useAddCartItem = () => useMutation({
|
|
1570
|
-
mutationFn: ({ cartId, ...data }) => addCartItem(data, cartId)
|
|
1571
|
-
});
|
|
1572
|
-
const useCheckoutCart = () => useMutation({
|
|
1573
|
-
mutationFn: ({ data, cartId }) => checkoutCart(data, cartId)
|
|
1574
|
-
});
|
|
1575
|
-
const useUploadPaymentReceipt = () => useMutation({
|
|
1576
|
-
mutationFn: ({ cartId, file }) => uploadPaymentReceipt(cartId, file)
|
|
1577
|
-
});
|
|
1578
|
-
const useGetCartCheckout = (cartId) => {
|
|
1579
|
-
const inactiveHandledRef = useRef(null);
|
|
1580
|
-
const query = useQuery({
|
|
1581
|
-
queryKey: ["storefront", "cart", cartId ?? null, "checkout"],
|
|
1582
|
-
queryFn: () => getCartCheckout(cartId),
|
|
1583
|
-
retry: (failureCount, error) => {
|
|
1584
|
-
const status = error.status;
|
|
1585
|
-
if (status === 404) return false;
|
|
1586
|
-
if (status === 400 && isCartNotActiveApiError(error)) return false;
|
|
1587
|
-
return failureCount < 1;
|
|
1588
|
-
},
|
|
1589
|
-
/** Evita GET repetidos al cambiar de paso / re-render; `refetch()` sigue forzando actualización tras mutaciones. */
|
|
1590
|
-
staleTime: 6e4,
|
|
1591
|
-
refetchOnMount: false,
|
|
1592
|
-
refetchOnReconnect: false,
|
|
1593
|
-
refetchOnWindowFocus: false,
|
|
1594
|
-
enabled: !!cartId
|
|
1595
|
-
});
|
|
1596
|
-
useEffect(() => {
|
|
1597
|
-
inactiveHandledRef.current = null;
|
|
1598
|
-
}, [cartId]);
|
|
1599
|
-
useEffect(() => {
|
|
1600
|
-
if (!cartId) return;
|
|
1601
|
-
if (!query.isError || !query.error) return;
|
|
1602
|
-
if (!isCartNotActiveApiError(query.error)) return;
|
|
1603
|
-
if (inactiveHandledRef.current === cartId) return;
|
|
1604
|
-
inactiveHandledRef.current = cartId;
|
|
1605
|
-
toast.error(
|
|
1606
|
-
"Este carrito ya no est\xE1 disponible. Se ha vaciado tu bolsa para que puedas empezar de nuevo."
|
|
1607
|
-
);
|
|
1608
|
-
useCart.getState().clearCartSession();
|
|
1609
|
-
}, [cartId, query.isError, query.error]);
|
|
1610
|
-
return query;
|
|
1611
|
-
};
|
|
1612
|
-
const useGetCartPaymentMethods = (cartId) => useQuery({
|
|
1613
|
-
queryKey: ["storefront", "cart", cartId ?? null, "payment-methods"],
|
|
1614
|
-
queryFn: () => getCartPaymentMethods(cartId ?? void 0),
|
|
1615
|
-
retry: (failureCount, error) => {
|
|
1616
|
-
const status = error.status;
|
|
1617
|
-
if (status === 404) return false;
|
|
1618
|
-
return failureCount < 1;
|
|
1619
|
-
},
|
|
1620
|
-
refetchOnWindowFocus: false,
|
|
1621
|
-
enabled: !!cartId
|
|
1622
|
-
});
|
|
1623
|
-
const useGetShippingOptions = (cartId, postalCode, enabled) => useQuery({
|
|
1624
|
-
queryKey: [
|
|
1625
|
-
"storefront",
|
|
1626
|
-
"cart",
|
|
1627
|
-
cartId ?? null,
|
|
1628
|
-
"shipping-options",
|
|
1629
|
-
postalCode ?? ""
|
|
1630
|
-
],
|
|
1631
|
-
queryFn: () => getShippingOptions(cartId, postalCode),
|
|
1632
|
-
retry: (failureCount, error) => {
|
|
1633
|
-
const status = error.status;
|
|
1634
|
-
if (status === 404) return false;
|
|
1635
|
-
return failureCount < 1;
|
|
1636
|
-
},
|
|
1637
|
-
refetchOnWindowFocus: false,
|
|
1638
|
-
enabled: !!cartId && !!postalCode?.trim() && enabled
|
|
1639
|
-
});
|
|
1640
|
-
const usePutCartShippingMethod = () => useMutation({
|
|
1641
|
-
mutationFn: ({ cartId, data }) => putCartShippingMethod(cartId, data)
|
|
1642
|
-
});
|
|
1643
|
-
const useAddCartCoupon = () => useMutation({
|
|
1644
|
-
mutationFn: ({ cartId, data }) => addCartCoupon(cartId, data)
|
|
1645
|
-
});
|
|
1646
|
-
const useRemoveCartCoupon = () => useMutation({
|
|
1647
|
-
mutationFn: ({ cartId, code }) => removeCartCoupon(cartId, code)
|
|
1648
|
-
});
|
|
1649
|
-
return {
|
|
1650
|
-
useCreateCart,
|
|
1651
|
-
useGetCart,
|
|
1652
|
-
useGetCartCheckout,
|
|
1653
|
-
useUpdateCartBuyer,
|
|
1654
|
-
useUpdateCartAddresses,
|
|
1655
|
-
useAddCartItem,
|
|
1656
|
-
useCheckoutCart,
|
|
1657
|
-
useUploadPaymentReceipt,
|
|
1658
|
-
useGetCartPaymentMethods,
|
|
1659
|
-
useGetShippingOptions,
|
|
1660
|
-
usePutCartShippingMethod,
|
|
1661
|
-
useAddCartCoupon,
|
|
1662
|
-
useRemoveCartCoupon
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
function isRenderableCmsPage(p) {
|
|
1666
|
-
if (!p.status) return true;
|
|
1667
|
-
return p.status === "published";
|
|
1668
|
-
}
|
|
1669
|
-
function findStorefrontCmsPageBySlug(settings, slug) {
|
|
1670
|
-
const pages = settings?.cms?.pages;
|
|
1671
|
-
if (!pages?.length) return null;
|
|
1672
|
-
const raw = pages.find(
|
|
1673
|
-
(p) => p.slug === slug && isRenderableCmsPage(p)
|
|
1674
|
-
);
|
|
1675
|
-
if (!raw) return null;
|
|
1676
|
-
const parsed = StorefrontPageDetailSchema$1.safeParse(raw);
|
|
1677
|
-
return parsed.success ? parsed.data : null;
|
|
1678
|
-
}
|
|
1679
|
-
function buildOptionGroups(variants) {
|
|
1680
|
-
const map = /* @__PURE__ */ new Map();
|
|
1681
|
-
for (const v of variants) {
|
|
1682
|
-
for (const opt of v.options ?? []) {
|
|
1683
|
-
const key = opt.key;
|
|
1684
|
-
const name = opt.name ?? key;
|
|
1685
|
-
if (!map.has(key)) map.set(key, /* @__PURE__ */ new Map());
|
|
1686
|
-
map.get(key).set(opt.value, name);
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
return Array.from(map.entries()).map(([key, valueMap]) => ({
|
|
1690
|
-
key,
|
|
1691
|
-
name: Array.from(valueMap.values())[0] ?? key,
|
|
1692
|
-
values: Array.from(valueMap.keys())
|
|
1693
|
-
}));
|
|
1694
|
-
}
|
|
1695
|
-
function findVariant(variants, selected, hasConfigurableOptions) {
|
|
1696
|
-
if (!hasConfigurableOptions && variants.length > 0) {
|
|
1697
|
-
return variants[0] ?? null;
|
|
1698
|
-
}
|
|
1699
|
-
if (Object.keys(selected).length === 0) return null;
|
|
1700
|
-
for (const v of variants) {
|
|
1701
|
-
const opts = v.options ?? [];
|
|
1702
|
-
const match = opts.length > 0 && opts.every((o) => selected[o.key] === o.value);
|
|
1703
|
-
if (match) return v;
|
|
1704
|
-
}
|
|
1705
|
-
return null;
|
|
1706
|
-
}
|
|
1707
|
-
function getInitialOptions(variants, optionGroups) {
|
|
1708
|
-
const first = variants[0];
|
|
1709
|
-
if (!first) return {};
|
|
1710
|
-
const opts = first.options ?? [];
|
|
1711
|
-
const selected = {};
|
|
1712
|
-
for (const g of optionGroups) {
|
|
1713
|
-
const o = opts.find((x) => x.key === g.key);
|
|
1714
|
-
if (o) selected[g.key] = o.value;
|
|
1715
|
-
}
|
|
1716
|
-
return selected;
|
|
1717
|
-
}
|
|
1718
|
-
function ProductVariantSelector({
|
|
1719
|
-
product,
|
|
1720
|
-
currency = "USD",
|
|
1721
|
-
features = [],
|
|
1722
|
-
onVariantChange,
|
|
1723
|
-
children
|
|
1724
|
-
}) {
|
|
1725
|
-
const variants = useMemo(() => product.variants ?? [], [product.variants]);
|
|
1726
|
-
const optionGroups = useMemo(() => buildOptionGroups(variants), [variants]);
|
|
1727
|
-
const hasConfigurableOptions = optionGroups.length > 0;
|
|
1728
|
-
const [selectedOptions, setSelectedOptions] = useState(
|
|
1729
|
-
() => getInitialOptions(variants, optionGroups)
|
|
1730
|
-
);
|
|
1731
|
-
const selectedVariant = useMemo(
|
|
1732
|
-
() => findVariant(variants, selectedOptions, hasConfigurableOptions),
|
|
1733
|
-
[variants, selectedOptions, hasConfigurableOptions]
|
|
1734
|
-
);
|
|
1735
|
-
const displayPrice = selectedVariant?.price ?? product.price ?? 0;
|
|
1736
|
-
const compareAtPrice = selectedVariant?.compareAtPrice ?? product.compareAtPrice;
|
|
1737
|
-
const isAvailable = (selectedVariant ? (selectedVariant.quantity ?? 0) > 0 : product.isAvailable) ?? true;
|
|
1738
|
-
useEffect(() => {
|
|
1739
|
-
onVariantChange?.(selectedVariant, displayPrice);
|
|
1740
|
-
}, [selectedVariant, displayPrice, onVariantChange]);
|
|
1741
|
-
const setOption = useCallback((key, value) => {
|
|
1742
|
-
setSelectedOptions((prev) => ({ ...prev, [key]: value }));
|
|
1743
|
-
}, []);
|
|
1744
|
-
const hasVariants = hasConfigurableOptions;
|
|
1745
|
-
return /* @__PURE__ */ jsxs("div", { className: "space-y-5", children: [
|
|
1746
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-baseline gap-2 flex-wrap", children: [
|
|
1747
|
-
/* @__PURE__ */ jsx(
|
|
1748
|
-
"span",
|
|
1749
|
-
{
|
|
1750
|
-
className: "inline-flex items-center rounded-md bg-primary/10 px-2.5 py-0.5 text-base font-semibold text-primary",
|
|
1751
|
-
"data-testid": "product-display-price",
|
|
1752
|
-
children: formatCurrency(displayPrice, currency)
|
|
1753
|
-
}
|
|
1754
|
-
),
|
|
1755
|
-
compareAtPrice != null && compareAtPrice > displayPrice && /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground line-through", children: formatCurrency(compareAtPrice, currency) })
|
|
1756
|
-
] }),
|
|
1757
|
-
hasVariants && optionGroups.map((group) => /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
1758
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: group.name }),
|
|
1759
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: group.values.map((value) => {
|
|
1760
|
-
const isSelected = selectedOptions[group.key] === value;
|
|
1761
|
-
const isColorLike = group.key.toLowerCase().includes("color") || group.key.toLowerCase().includes("colour");
|
|
1762
|
-
return /* @__PURE__ */ jsx(
|
|
1763
|
-
"button",
|
|
1764
|
-
{
|
|
1765
|
-
type: "button",
|
|
1766
|
-
onClick: () => setOption(group.key, value),
|
|
1767
|
-
className: isColorLike ? `min-w-[72px] rounded-md border-2 px-3 py-2 text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${isSelected ? "border-primary bg-primary text-foreground" : "border-border bg-muted/30 text-foreground hover:border-muted-foreground/50"}` : `rounded-md border px-3 py-2 text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${isSelected ? "border-primary bg-muted ring-1 ring-primary" : "border-border bg-transparent text-muted-foreground hover:border-muted-foreground/50 hover:text-foreground"}`,
|
|
1768
|
-
style: isColorLike && isSelected && value.toLowerCase() === "black" ? { backgroundColor: "#1a1a1a", borderColor: "#1a1a1a", color: "#fff" } : isColorLike && value.toLowerCase() === "white" ? { backgroundColor: "#fafafa", color: "#1a1a1a", borderColor: "#e5e5e5" } : void 0,
|
|
1769
|
-
"data-testid": `variant-option-${group.key}-${value}`,
|
|
1770
|
-
children: value
|
|
1771
|
-
},
|
|
1772
|
-
value
|
|
1773
|
-
);
|
|
1774
|
-
}) })
|
|
1775
|
-
] }, group.key)),
|
|
1776
|
-
features.length > 0 && /* @__PURE__ */ jsx("ul", { className: "list-disc list-inside space-y-1 text-sm text-muted-foreground", children: features.map((f, i) => /* @__PURE__ */ jsx("li", { children: f }, i)) }),
|
|
1777
|
-
children?.({
|
|
1778
|
-
product,
|
|
1779
|
-
selectedVariant,
|
|
1780
|
-
displayPrice,
|
|
1781
|
-
compareAtPrice,
|
|
1782
|
-
isAvailable,
|
|
1783
|
-
selectedOptions
|
|
1784
|
-
})
|
|
1785
|
-
] });
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
// src/npm/nextjs.ts
|
|
1789
|
-
var usePublicStore = () => useStore.getState().data;
|
|
1790
|
-
|
|
1791
|
-
export { CustomerAddressSchema, CustomerAddressUpsertSchema, CustomerMeSchema, CustomerOrderDetailSchema, CustomerOrderListItemSchema, CustomerProfilePatchSchema, CustomerRegisterRequestSchema, ECOMIQ_CLIENTS_STORE_KV_BINDING, EcomiqProvider, ProductVariantSelector, StoreApiClient, addCartCoupon, buildStorefrontKvSnapshotKey, buildStorefrontKvSnapshotKeyFromStoreKey, checkoutCart, createCart, createCustomerAddress, createStoreApiClient, customerMeToProfilePatch, deleteCustomerAddress, findStorefrontCmsPageBySlug, getCart, getCartCheckout, getCartPaymentMethods, getCustomerAddresses, getCustomerMe, getCustomerOrder, getCustomerOrders, getHostname, getPublicStore, getSharedOrderDraft, getShippingOptions, getStoreApiBaseUrl, getStoreApiClient, getStorefrontCollectionBySlug, getStorefrontCollections, getStorefrontPageBySlug, getStorefrontPagePreview, getStorefrontPages, getStorefrontProductBySlug, getStorefrontProducts, getStorefrontSettings, getStorefrontSettingsFromKv, getStorefrontSettingsFromKvByStoreKey, isCartNotActiveApiError, normalizeStoreHost, patchCartAddresses, patchCartBuyer, patchCustomer, putCartShippingMethod, registerCustomer, removeCartCoupon, resolvePublicStoreSettingsSource, resolveStorefrontSettingsHost, setClientStoreId, setServerRequestOrigin, setServerStoreId, signInWithEcomiqCredentials2 as signInWithEcomiqCredentials, storeApiClient, updateCustomerAddress, uploadPaymentReceipt, usePublicStore, useStore, useStoreCart, useStoreCollections, useStorePages, useStoreProducts };
|
|
1792
|
-
//# sourceMappingURL=nextjs.js.map
|
|
1793
|
-
//# sourceMappingURL=nextjs.js.map
|
|
1
|
+
export {
|
|
2
|
+
EcomiqProvider,
|
|
3
|
+
useStoreProducts,
|
|
4
|
+
useStoreCollections,
|
|
5
|
+
useStorePages,
|
|
6
|
+
useStoreCart,
|
|
7
|
+
useStore,
|
|
8
|
+
useCart,
|
|
9
|
+
useStorefrontSession,
|
|
10
|
+
useStorefrontAuthClient,
|
|
11
|
+
} from "./chunks/client.js";
|