@asteby/storefront 0.12.0 → 0.14.0
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 +27 -1
- package/dist/chunk-IPUAZ3LQ.js +646 -0
- package/dist/chunk-IPUAZ3LQ.js.map +1 -0
- package/dist/cli.js +40 -1
- package/dist/fiscal-document.d.cts +2 -2
- package/dist/fiscal-document.d.ts +2 -2
- package/dist/index.cjs +204 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -4
- package/dist/index.d.ts +68 -4
- package/dist/index.js +73 -310
- package/dist/index.js.map +1 -1
- package/dist/mock.cjs +417 -39
- package/dist/mock.cjs.map +1 -1
- package/dist/mock.d.cts +3 -1
- package/dist/mock.d.ts +3 -1
- package/dist/mock.js +272 -23
- package/dist/mock.js.map +1 -1
- package/dist/mockup.d.cts +1 -1
- package/dist/mockup.d.ts +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/dist/{types-C_rsJRCl.d.ts → types-BeTemDg6.d.ts} +209 -1
- package/dist/{types-BQ3S6VjF.d.cts → types-BuKb-zbi.d.cts} +209 -1
- package/package.json +1 -1
- package/dist/chunk-HBSB7XS2.js +0 -220
- package/dist/chunk-HBSB7XS2.js.map +0 -1
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var StorefrontError = class extends Error {
|
|
3
|
+
name = "StorefrontError";
|
|
4
|
+
status;
|
|
5
|
+
code;
|
|
6
|
+
field;
|
|
7
|
+
details;
|
|
8
|
+
url;
|
|
9
|
+
/** Scopes a `403 insufficient_scope` says the route needs (empty for any other error). */
|
|
10
|
+
requiredScopes;
|
|
11
|
+
/** `true`: repeating the request (same idempotency key) can succeed. `false`: not until someone fixes something. `undefined`: OPS did not say. */
|
|
12
|
+
retryable;
|
|
13
|
+
/** Seconds OPS asks to wait before retrying. */
|
|
14
|
+
retryAfter;
|
|
15
|
+
/** Checkout that a refused cart write can resume. */
|
|
16
|
+
checkoutId;
|
|
17
|
+
/** Current cart cost sent with a `price_mismatch` (untrusted shape). */
|
|
18
|
+
cost;
|
|
19
|
+
/** English version of `message`, when OPS sent one. */
|
|
20
|
+
messageEn;
|
|
21
|
+
constructor(init) {
|
|
22
|
+
super(init.message, init.cause === void 0 ? void 0 : { cause: init.cause });
|
|
23
|
+
this.status = init.status;
|
|
24
|
+
this.code = init.code;
|
|
25
|
+
this.field = init.field;
|
|
26
|
+
this.details = init.details;
|
|
27
|
+
this.url = init.url;
|
|
28
|
+
this.requiredScopes = init.requiredScopes ?? [];
|
|
29
|
+
this.retryable = init.retryable;
|
|
30
|
+
this.retryAfter = init.retryAfter;
|
|
31
|
+
this.checkoutId = init.checkoutId;
|
|
32
|
+
this.cost = init.cost;
|
|
33
|
+
this.messageEn = init.messageEn;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Affected lines of a `409 insufficient_stock` (empty for any other error or a
|
|
37
|
+
* server older than contract 1.1). The cart is untouched: show the lines and
|
|
38
|
+
* let the buyer adjust or remove them.
|
|
39
|
+
*/
|
|
40
|
+
get stockLines() {
|
|
41
|
+
const lines = this.details?.lines;
|
|
42
|
+
if (this.code !== "insufficient_stock" || !Array.isArray(lines)) return [];
|
|
43
|
+
return lines.filter((l) => typeof l === "object" && l !== null && typeof l.sku === "string");
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
name: this.name,
|
|
48
|
+
status: this.status,
|
|
49
|
+
code: this.code,
|
|
50
|
+
message: this.message,
|
|
51
|
+
field: this.field,
|
|
52
|
+
...this.requiredScopes.length ? { requiredScopes: this.requiredScopes } : {},
|
|
53
|
+
...this.retryable !== void 0 ? { retryable: this.retryable } : {},
|
|
54
|
+
...this.retryAfter !== void 0 ? { retryAfter: this.retryAfter } : {},
|
|
55
|
+
...this.checkoutId ? { checkoutId: this.checkoutId } : {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function isStorefrontError(err) {
|
|
60
|
+
return err instanceof StorefrontError || typeof err === "object" && err !== null && err.name === "StorefrontError";
|
|
61
|
+
}
|
|
62
|
+
var STATUS_CODES = {
|
|
63
|
+
400: "validation",
|
|
64
|
+
401: "unauthorized",
|
|
65
|
+
403: "forbidden",
|
|
66
|
+
404: "not_found",
|
|
67
|
+
409: "conflict",
|
|
68
|
+
422: "invalid_state",
|
|
69
|
+
429: "rate_limited"
|
|
70
|
+
};
|
|
71
|
+
function defaultCodeForStatus(status) {
|
|
72
|
+
return STATUS_CODES[status] ?? (status >= 500 ? "server_error" : "invalid_response");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/availability.ts
|
|
76
|
+
var ES = {
|
|
77
|
+
"status.in_stock": "Disponible",
|
|
78
|
+
"status.low_stock": "Pocas piezas",
|
|
79
|
+
"status.low_stock_n": "Quedan {n}",
|
|
80
|
+
"status.out_of_stock": "Agotado",
|
|
81
|
+
"status.backorder": "Bajo pedido",
|
|
82
|
+
"status.preorder": "Preventa",
|
|
83
|
+
"sub.backorder_eta": "Se env\xEDa a partir del {date}",
|
|
84
|
+
"sub.preorder_date": "Sale a la venta el {date}",
|
|
85
|
+
"cta.add": "Agregar al carrito",
|
|
86
|
+
"cta.out_of_stock": "Agotado",
|
|
87
|
+
"cta.backorder": "Pedir bajo pedido",
|
|
88
|
+
"cta.preorder": "Apartar en preventa",
|
|
89
|
+
"sr.in_stock": "Disponible",
|
|
90
|
+
"sr.low_stock": "Quedan pocas piezas",
|
|
91
|
+
"sr.low_stock_n": "Quedan solo {n} piezas",
|
|
92
|
+
"sr.out_of_stock": "Producto agotado",
|
|
93
|
+
"sr.backorder": "Disponible bajo pedido",
|
|
94
|
+
"sr.preorder": "Disponible en preventa",
|
|
95
|
+
"option.sold_out": "agotado",
|
|
96
|
+
"option.backorder": "bajo pedido",
|
|
97
|
+
"option.preorder": "preventa",
|
|
98
|
+
max_per_order: "M\xE1ximo {n} por pedido",
|
|
99
|
+
"notify.title": "Av\xEDsame cuando vuelva",
|
|
100
|
+
"notify.email": "Correo electr\xF3nico",
|
|
101
|
+
"notify.phone": "WhatsApp o tel\xE9fono",
|
|
102
|
+
"notify.consent": "Acepto recibir un aviso cuando vuelva a estar disponible",
|
|
103
|
+
"notify.submit": "Av\xEDsame",
|
|
104
|
+
"notify.done": "Listo. Te avisaremos cuando vuelva a estar disponible.",
|
|
105
|
+
"notify.error": "No pudimos guardar tu aviso. Revisa tus datos e int\xE9ntalo de nuevo.",
|
|
106
|
+
"problem.out_of_stock": "Ya no hay existencias",
|
|
107
|
+
"problem.insufficient_stock": "No hay suficientes piezas para esta cantidad",
|
|
108
|
+
"problem.insufficient_stock_n": "Solo puedes llevar {n}",
|
|
109
|
+
"problem.adjust": "Ajustar a {n}",
|
|
110
|
+
"problem.remove": "Quitar",
|
|
111
|
+
"conflict.title": "Algunos productos cambiaron de existencias",
|
|
112
|
+
"conflict.body": "Revisa las l\xEDneas marcadas. Tu carrito y tus datos se conservaron; ajusta o quita lo que ya no est\xE1 disponible y contin\xFAa.",
|
|
113
|
+
"conflict.dismiss": "Entendido"
|
|
114
|
+
};
|
|
115
|
+
var EN = {
|
|
116
|
+
"status.in_stock": "In stock",
|
|
117
|
+
"status.low_stock": "Low stock",
|
|
118
|
+
"status.low_stock_n": "Only {n} left",
|
|
119
|
+
"status.out_of_stock": "Sold out",
|
|
120
|
+
"status.backorder": "Made to order",
|
|
121
|
+
"status.preorder": "Pre-order",
|
|
122
|
+
"sub.backorder_eta": "Ships from {date}",
|
|
123
|
+
"sub.preorder_date": "Available on {date}",
|
|
124
|
+
"cta.add": "Add to cart",
|
|
125
|
+
"cta.out_of_stock": "Sold out",
|
|
126
|
+
"cta.backorder": "Order now, ships later",
|
|
127
|
+
"cta.preorder": "Pre-order",
|
|
128
|
+
"sr.in_stock": "In stock",
|
|
129
|
+
"sr.low_stock": "Low stock",
|
|
130
|
+
"sr.low_stock_n": "Only {n} left in stock",
|
|
131
|
+
"sr.out_of_stock": "Sold out",
|
|
132
|
+
"sr.backorder": "Available to order, ships later",
|
|
133
|
+
"sr.preorder": "Available for pre-order",
|
|
134
|
+
"option.sold_out": "sold out",
|
|
135
|
+
"option.backorder": "made to order",
|
|
136
|
+
"option.preorder": "pre-order",
|
|
137
|
+
max_per_order: "Maximum {n} per order",
|
|
138
|
+
"notify.title": "Notify me when it is back",
|
|
139
|
+
"notify.email": "Email",
|
|
140
|
+
"notify.phone": "WhatsApp or phone",
|
|
141
|
+
"notify.consent": "I agree to receive a notice when it is back in stock",
|
|
142
|
+
"notify.submit": "Notify me",
|
|
143
|
+
"notify.done": "Done. We will let you know when it is back in stock.",
|
|
144
|
+
"notify.error": "We could not save your request. Check your details and try again.",
|
|
145
|
+
"problem.out_of_stock": "No longer in stock",
|
|
146
|
+
"problem.insufficient_stock": "Not enough stock for this quantity",
|
|
147
|
+
"problem.insufficient_stock_n": "You can take up to {n}",
|
|
148
|
+
"problem.adjust": "Adjust to {n}",
|
|
149
|
+
"problem.remove": "Remove",
|
|
150
|
+
"conflict.title": "Some items changed stock",
|
|
151
|
+
"conflict.body": "Review the marked lines. Your cart and your details were kept; adjust or remove what is no longer available and continue.",
|
|
152
|
+
"conflict.dismiss": "Got it"
|
|
153
|
+
};
|
|
154
|
+
var CATALOG = { es: ES, en: EN };
|
|
155
|
+
function availabilityLocale(locale) {
|
|
156
|
+
return (locale ?? "").toLowerCase().startsWith("en") ? "en" : "es";
|
|
157
|
+
}
|
|
158
|
+
function availabilityMessages(locale, overrides) {
|
|
159
|
+
const base = CATALOG[availabilityLocale(locale)];
|
|
160
|
+
if (!overrides) return base;
|
|
161
|
+
const out = { ...base };
|
|
162
|
+
for (const [k, v] of Object.entries(overrides)) if (typeof v === "string" && k in base) out[k] = v;
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
function formatAvailabilityMessage(template, values = {}) {
|
|
166
|
+
return template.replace(/\{(\w+)\}/g, (m, k) => k in values ? String(values[k]) : m);
|
|
167
|
+
}
|
|
168
|
+
function formatDate(value, locale) {
|
|
169
|
+
if (!value) return null;
|
|
170
|
+
const d = /^\d{4}-\d{2}-\d{2}$/.test(value) ? /* @__PURE__ */ new Date(`${value}T00:00:00Z`) : new Date(value);
|
|
171
|
+
if (Number.isNaN(d.getTime())) return null;
|
|
172
|
+
try {
|
|
173
|
+
return new Intl.DateTimeFormat(locale || "es", { dateStyle: "long", timeZone: "UTC" }).format(d);
|
|
174
|
+
} catch {
|
|
175
|
+
return value.slice(0, 10);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function resolveAvailability(source, options = {}) {
|
|
179
|
+
const a = source.availability;
|
|
180
|
+
if (a && typeof a === "object" && typeof a.status === "string") return a;
|
|
181
|
+
const qty = typeof source.quantity_available === "number" ? source.quantity_available : null;
|
|
182
|
+
const sellable = source.available_for_sale && (qty === null || qty > 0);
|
|
183
|
+
const threshold = options.lowStockThreshold;
|
|
184
|
+
const low = sellable && qty !== null && typeof threshold === "number" && threshold > 0 && qty <= threshold;
|
|
185
|
+
const status = !sellable ? "out_of_stock" : low ? "low_stock" : "in_stock";
|
|
186
|
+
return {
|
|
187
|
+
status,
|
|
188
|
+
quantity: sellable ? qty : null,
|
|
189
|
+
max_per_order: sellable ? qty : null,
|
|
190
|
+
restock_eta: null,
|
|
191
|
+
preorder_release_at: null,
|
|
192
|
+
// Old servers have no subscription route: never offer a form that cannot work.
|
|
193
|
+
notify_available: false
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
var TONES = {
|
|
197
|
+
in_stock: "success",
|
|
198
|
+
low_stock: "warning",
|
|
199
|
+
out_of_stock: "danger",
|
|
200
|
+
backorder: "info",
|
|
201
|
+
preorder: "info"
|
|
202
|
+
};
|
|
203
|
+
function availabilityView(availability, locale, options = {}) {
|
|
204
|
+
const m = availabilityMessages(locale, options.messages);
|
|
205
|
+
const known = ["in_stock", "low_stock", "out_of_stock", "backorder", "preorder"].includes(availability.status);
|
|
206
|
+
const status = known ? availability.status : "out_of_stock";
|
|
207
|
+
const qty = typeof availability.quantity === "number" && availability.quantity > 0 ? availability.quantity : null;
|
|
208
|
+
const f = formatAvailabilityMessage;
|
|
209
|
+
let label;
|
|
210
|
+
let sr;
|
|
211
|
+
let cta;
|
|
212
|
+
let sublabel = null;
|
|
213
|
+
let enabled = true;
|
|
214
|
+
switch (status) {
|
|
215
|
+
case "in_stock":
|
|
216
|
+
label = m["status.in_stock"];
|
|
217
|
+
sr = m["sr.in_stock"];
|
|
218
|
+
cta = m["cta.add"];
|
|
219
|
+
break;
|
|
220
|
+
case "low_stock":
|
|
221
|
+
label = qty !== null ? f(m["status.low_stock_n"], { n: qty }) : m["status.low_stock"];
|
|
222
|
+
sr = qty !== null ? f(m["sr.low_stock_n"], { n: qty }) : m["sr.low_stock"];
|
|
223
|
+
cta = m["cta.add"];
|
|
224
|
+
break;
|
|
225
|
+
case "backorder": {
|
|
226
|
+
label = m["status.backorder"];
|
|
227
|
+
sr = m["sr.backorder"];
|
|
228
|
+
cta = m["cta.backorder"];
|
|
229
|
+
const date = formatDate(availability.restock_eta, locale);
|
|
230
|
+
if (date) sublabel = f(m["sub.backorder_eta"], { date });
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "preorder": {
|
|
234
|
+
label = m["status.preorder"];
|
|
235
|
+
sr = m["sr.preorder"];
|
|
236
|
+
cta = m["cta.preorder"];
|
|
237
|
+
const date = formatDate(availability.preorder_release_at ?? availability.restock_eta, locale);
|
|
238
|
+
if (date) sublabel = f(m["sub.preorder_date"], { date });
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
default:
|
|
242
|
+
label = m["status.out_of_stock"];
|
|
243
|
+
sr = m["sr.out_of_stock"];
|
|
244
|
+
cta = m["cta.out_of_stock"];
|
|
245
|
+
enabled = false;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
status,
|
|
249
|
+
tone: TONES[status],
|
|
250
|
+
label,
|
|
251
|
+
sublabel,
|
|
252
|
+
ctaLabel: cta,
|
|
253
|
+
ctaEnabled: enabled,
|
|
254
|
+
showNotify: status === "out_of_stock" && availability.notify_available === true,
|
|
255
|
+
srText: sublabel ? `${sr}. ${sublabel}` : sr,
|
|
256
|
+
maxPerOrder: typeof availability.max_per_order === "number" && availability.max_per_order > 0 ? availability.max_per_order : null,
|
|
257
|
+
showOnCard: status !== "in_stock"
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function cartLineProblemView(problem, locale, options = {}) {
|
|
261
|
+
const m = availabilityMessages(locale, options.messages);
|
|
262
|
+
const code = "code" in problem ? problem.code : problem.status === "out_of_stock" ? "out_of_stock" : "insufficient_stock";
|
|
263
|
+
const max = typeof problem.max_quantity === "number" && problem.max_quantity >= 0 ? problem.max_quantity : null;
|
|
264
|
+
const canAdjust = max !== null && max > 0 && (options.lineQuantity === void 0 || max !== options.lineQuantity);
|
|
265
|
+
const message = code === "out_of_stock" || max === 0 ? m["problem.out_of_stock"] : max !== null ? formatAvailabilityMessage(m["problem.insufficient_stock_n"], { n: max }) : m["problem.insufficient_stock"];
|
|
266
|
+
return {
|
|
267
|
+
code,
|
|
268
|
+
message,
|
|
269
|
+
adjustTo: canAdjust ? max : null,
|
|
270
|
+
adjustLabel: canAdjust ? formatAvailabilityMessage(m["problem.adjust"], { n: max }) : null,
|
|
271
|
+
removeLabel: m["problem.remove"]
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
var SCHEMA_AVAILABILITY = {
|
|
275
|
+
in_stock: "https://schema.org/InStock",
|
|
276
|
+
low_stock: "https://schema.org/LimitedAvailability",
|
|
277
|
+
out_of_stock: "https://schema.org/OutOfStock",
|
|
278
|
+
backorder: "https://schema.org/BackOrder",
|
|
279
|
+
preorder: "https://schema.org/PreOrder"
|
|
280
|
+
};
|
|
281
|
+
function schemaAvailability(status) {
|
|
282
|
+
return SCHEMA_AVAILABILITY[status] ?? SCHEMA_AVAILABILITY.out_of_stock;
|
|
283
|
+
}
|
|
284
|
+
function productAvailability(product, options = {}) {
|
|
285
|
+
if (product.availability) return product.availability;
|
|
286
|
+
const all = product.variants.map((v) => resolveAvailability(v, options));
|
|
287
|
+
const rank = ["in_stock", "low_stock", "backorder", "preorder", "out_of_stock"];
|
|
288
|
+
const best = all.slice().sort((a, b) => rank.indexOf(a.status) - rank.indexOf(b.status))[0];
|
|
289
|
+
return best ?? resolveAvailability(product, options);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/payments.ts
|
|
293
|
+
var ES2 = {
|
|
294
|
+
"decline.insufficient_funds": "Tu tarjeta no tiene saldo suficiente. Prueba con otra tarjeta o paga en efectivo.",
|
|
295
|
+
"decline.invalid_cvc": "El c\xF3digo de seguridad no es correcto. Rev\xEDsalo e intenta de nuevo.",
|
|
296
|
+
"decline.invalid_expiry": "La fecha de vencimiento no es correcta.",
|
|
297
|
+
"decline.invalid_card_data": "Revisa los datos de tu tarjeta.",
|
|
298
|
+
"decline.call_issuer": "Tu banco necesita que autorices este pago. Llama al n\xFAmero al reverso de tu tarjeta y vuelve a intentarlo.",
|
|
299
|
+
"decline.card_disabled": "Tu tarjeta no est\xE1 activa. Act\xEDvala con tu banco o usa otra.",
|
|
300
|
+
"decline.duplicate": "Ya hiciste un pago igual hace un momento. Revisa tu correo antes de volver a pagar.",
|
|
301
|
+
"decline.max_attempts": "Llegaste al l\xEDmite de intentos con esta tarjeta. Usa otra o paga en efectivo.",
|
|
302
|
+
"decline.authentication_failed": "Tu banco no pudo verificar el pago. Intenta de nuevo o usa otra tarjeta.",
|
|
303
|
+
"decline.declined": "Tu banco rechaz\xF3 el pago. Usa otra tarjeta o paga en efectivo.",
|
|
304
|
+
"state.loading": "Cargando pago seguro\u2026",
|
|
305
|
+
"state.processing": "Procesando pago\u2026",
|
|
306
|
+
"state.approved": "\xA1Pago aprobado!",
|
|
307
|
+
"state.in_review": "Tu pago est\xE1 en revisi\xF3n. Te avisamos por correo en m\xE1ximo 2 d\xEDas h\xE1biles. No vuelvas a pagar.",
|
|
308
|
+
"state.voucher": "Tu ficha de pago est\xE1 lista. El pedido se confirma cuando pagues.",
|
|
309
|
+
"state.challenge": "Tu banco necesita verificar el pago. Termina la verificaci\xF3n para continuar.",
|
|
310
|
+
"state.expired": "La ficha venci\xF3. Vuelve a armar tu carrito para pagar.",
|
|
311
|
+
"state.cancelled": "El pago se cancel\xF3. Puedes intentarlo de nuevo.",
|
|
312
|
+
"state.redirect": "Te llevamos a la p\xE1gina de pago\u2026",
|
|
313
|
+
"state.fallback": "No pudimos cargar el formulario seguro de tarjeta. Puedes pagar con tarjeta en el sitio del proveedor y regresar aqu\xED.",
|
|
314
|
+
"error.network": "No pudimos conectar. Revisa tu conexi\xF3n e intenta de nuevo; no se te cobrar\xE1 dos veces.",
|
|
315
|
+
"error.card_data": "Revisa los datos de tu tarjeta.",
|
|
316
|
+
"error.price_mismatch": "El total cambi\xF3. Revisa el nuevo total y vuelve a pagar.",
|
|
317
|
+
"error.payment_in_progress": "Ya hay un pago en proceso para este pedido. No vuelvas a pagar; revisa tu correo.",
|
|
318
|
+
"error.expired": "Tu apartado venci\xF3. Vuelve a armar tu carrito.",
|
|
319
|
+
"error.too_many_attempts": "Por seguridad no podemos intentar con m\xE1s tarjetas. Paga en efectivo o escr\xEDbenos.",
|
|
320
|
+
"error.generic": "No pudimos procesar tu pago. Intenta de nuevo.",
|
|
321
|
+
"action.retry": "Reintentar",
|
|
322
|
+
"action.try_again": "Intentar de nuevo",
|
|
323
|
+
"action.pay": "Pagar",
|
|
324
|
+
"action.cancel": "Cancelar",
|
|
325
|
+
"voucher.title": "Ficha de pago",
|
|
326
|
+
"voucher.point": "Punto de pago",
|
|
327
|
+
"voucher.reference": "Referencia",
|
|
328
|
+
"voucher.amount": "Monto exacto",
|
|
329
|
+
"voucher.expires": "Vence el {date}",
|
|
330
|
+
"voucher.clabe": "CLABE",
|
|
331
|
+
"voucher.barcode": "C\xF3digo de barras",
|
|
332
|
+
"voucher.open": "Ver o imprimir ficha",
|
|
333
|
+
"voucher.email": "Tambi\xE9n te la enviamos a tu correo.",
|
|
334
|
+
"form.label": "Datos de tu tarjeta",
|
|
335
|
+
"challenge.title": "Verificaci\xF3n de tu banco",
|
|
336
|
+
"challenge.escape": "Cancelar y volver al pago",
|
|
337
|
+
"challenge.escape_hint": "\xBFTarda demasiado? Puedes cerrar la verificaci\xF3n. Si ya la aprobaste en tu banco, el pago a\xFAn puede completarse: te confirmamos aqu\xED antes de dejarte pagar de nuevo.",
|
|
338
|
+
"challenge.left": "Cerraste la verificaci\xF3n. Estamos confirmando con tu banco si el pago se complet\xF3; no vuelvas a pagar todav\xEDa."
|
|
339
|
+
};
|
|
340
|
+
var EN2 = {
|
|
341
|
+
"decline.insufficient_funds": "Your card has insufficient funds. Try another card or pay in cash.",
|
|
342
|
+
"decline.invalid_cvc": "The security code is not correct. Check it and try again.",
|
|
343
|
+
"decline.invalid_expiry": "The expiry date is not correct.",
|
|
344
|
+
"decline.invalid_card_data": "Check your card details.",
|
|
345
|
+
"decline.call_issuer": "Your bank needs you to authorize this payment. Call the number on the back of your card and try again.",
|
|
346
|
+
"decline.card_disabled": "Your card is not active. Activate it with your bank or use another one.",
|
|
347
|
+
"decline.duplicate": "You already made the same payment a moment ago. Check your email before paying again.",
|
|
348
|
+
"decline.max_attempts": "You reached the attempt limit for this card. Use another card or pay in cash.",
|
|
349
|
+
"decline.authentication_failed": "Your bank could not verify the payment. Try again or use another card.",
|
|
350
|
+
"decline.declined": "Your bank declined the payment. Use another card or pay in cash.",
|
|
351
|
+
"state.loading": "Loading secure payment\u2026",
|
|
352
|
+
"state.processing": "Processing payment\u2026",
|
|
353
|
+
"state.approved": "Payment approved!",
|
|
354
|
+
"state.in_review": "Your payment is under review. We will email you within 2 business days. Do not pay again.",
|
|
355
|
+
"state.voucher": "Your payment voucher is ready. The order is confirmed once you pay.",
|
|
356
|
+
"state.challenge": "Your bank needs to verify the payment. Finish the verification to continue.",
|
|
357
|
+
"state.expired": "The voucher expired. Rebuild your cart to pay.",
|
|
358
|
+
"state.cancelled": "The payment was cancelled. You can try again.",
|
|
359
|
+
"state.redirect": "Taking you to the payment page\u2026",
|
|
360
|
+
"state.fallback": "We could not load the secure card form. You can pay by card on the provider site and come back here.",
|
|
361
|
+
"error.network": "We could not connect. Check your connection and try again; you will not be charged twice.",
|
|
362
|
+
"error.card_data": "Check your card details.",
|
|
363
|
+
"error.price_mismatch": "The total changed. Review the new total and pay again.",
|
|
364
|
+
"error.payment_in_progress": "A payment is already in progress for this order. Do not pay again; check your email.",
|
|
365
|
+
"error.expired": "Your reservation expired. Rebuild your cart.",
|
|
366
|
+
"error.too_many_attempts": "For security we cannot try more cards. Pay in cash or contact us.",
|
|
367
|
+
"error.generic": "We could not process your payment. Please try again.",
|
|
368
|
+
"action.retry": "Retry",
|
|
369
|
+
"action.try_again": "Try again",
|
|
370
|
+
"action.pay": "Pay",
|
|
371
|
+
"action.cancel": "Cancel",
|
|
372
|
+
"voucher.title": "Payment voucher",
|
|
373
|
+
"voucher.point": "Payment point",
|
|
374
|
+
"voucher.reference": "Reference",
|
|
375
|
+
"voucher.amount": "Exact amount",
|
|
376
|
+
"voucher.expires": "Expires on {date}",
|
|
377
|
+
"voucher.clabe": "CLABE",
|
|
378
|
+
"voucher.barcode": "Barcode",
|
|
379
|
+
"voucher.open": "View or print voucher",
|
|
380
|
+
"voucher.email": "We also emailed it to you.",
|
|
381
|
+
"form.label": "Your card details",
|
|
382
|
+
"challenge.title": "Your bank verification",
|
|
383
|
+
"challenge.escape": "Cancel and go back to payment",
|
|
384
|
+
"challenge.escape_hint": "Taking too long? You can close the verification. If you already approved it with your bank the payment may still go through: we confirm here before letting you pay again.",
|
|
385
|
+
"challenge.left": "You closed the verification. We are checking with your bank whether the payment went through; do not pay again yet."
|
|
386
|
+
};
|
|
387
|
+
var CATALOG2 = { es: ES2, en: EN2 };
|
|
388
|
+
function paymentMessages(locale, overrides) {
|
|
389
|
+
const base = CATALOG2[availabilityLocale(locale)];
|
|
390
|
+
if (!overrides) return base;
|
|
391
|
+
const out = { ...base };
|
|
392
|
+
for (const [k, v] of Object.entries(overrides)) if (typeof v === "string" && k in base) out[k] = v;
|
|
393
|
+
return out;
|
|
394
|
+
}
|
|
395
|
+
var DECLINE_CODES = /* @__PURE__ */ new Set([
|
|
396
|
+
"insufficient_funds",
|
|
397
|
+
"invalid_cvc",
|
|
398
|
+
"invalid_expiry",
|
|
399
|
+
"invalid_card_data",
|
|
400
|
+
"call_issuer",
|
|
401
|
+
"card_disabled",
|
|
402
|
+
"duplicate",
|
|
403
|
+
"max_attempts",
|
|
404
|
+
"authentication_failed",
|
|
405
|
+
"declined"
|
|
406
|
+
]);
|
|
407
|
+
function declineMessageKey(code) {
|
|
408
|
+
return `decline.${code && DECLINE_CODES.has(code) ? code : "declined"}`;
|
|
409
|
+
}
|
|
410
|
+
function declineMessage(code, locale, overrides) {
|
|
411
|
+
return paymentMessages(locale, overrides)[declineMessageKey(code)];
|
|
412
|
+
}
|
|
413
|
+
function safeHttpsUrl(value) {
|
|
414
|
+
if (typeof value !== "string" || value.length > 2048) return null;
|
|
415
|
+
try {
|
|
416
|
+
const u = new URL(value);
|
|
417
|
+
if (u.protocol !== "https:" || u.username || u.password) return null;
|
|
418
|
+
return u.toString();
|
|
419
|
+
} catch {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
var NEXT_STEP = {
|
|
424
|
+
insufficient_funds: "use_other_card",
|
|
425
|
+
invalid_cvc: "fix_card_data",
|
|
426
|
+
invalid_expiry: "fix_card_data",
|
|
427
|
+
invalid_card_data: "fix_card_data",
|
|
428
|
+
call_issuer: "contact_issuer",
|
|
429
|
+
card_disabled: "use_other_card",
|
|
430
|
+
duplicate: "check_email",
|
|
431
|
+
max_attempts: "use_other_card",
|
|
432
|
+
authentication_failed: "retry",
|
|
433
|
+
declined: "use_other_card"
|
|
434
|
+
};
|
|
435
|
+
function voucherMoney(v) {
|
|
436
|
+
const a = v.amount;
|
|
437
|
+
if (a && typeof a === "object" && typeof a.amount === "string") return a;
|
|
438
|
+
const text = typeof a === "number" ? String(a) : typeof a === "string" ? a : "";
|
|
439
|
+
if (!text || !/^\d+(\.\d+)?$/.test(text) || !v.currency) return null;
|
|
440
|
+
return { amount: text.includes(".") ? text : `${text}.00`, currency_code: v.currency };
|
|
441
|
+
}
|
|
442
|
+
function paymentOutcome(result, locale, overrides) {
|
|
443
|
+
const m = paymentMessages(locale, overrides);
|
|
444
|
+
const p = result.payment;
|
|
445
|
+
const action = p.action ?? null;
|
|
446
|
+
const base = {
|
|
447
|
+
decline_code: null,
|
|
448
|
+
retryable: false,
|
|
449
|
+
redirect_url: null,
|
|
450
|
+
challenge: null,
|
|
451
|
+
voucher: null,
|
|
452
|
+
attempts_left: typeof result.attempts_left === "number" ? result.attempts_left : null,
|
|
453
|
+
next_step: p.next_step ?? null
|
|
454
|
+
};
|
|
455
|
+
const out = (kind, message, extra = {}) => ({ ...base, kind, message, ...extra });
|
|
456
|
+
if (p.status === "paid") return out("approved", m["state.approved"]);
|
|
457
|
+
if (p.status === "failed") {
|
|
458
|
+
const code = p.decline_code ?? "declined";
|
|
459
|
+
const known = DECLINE_CODES.has(code) ? code : "declined";
|
|
460
|
+
return out("rejected", m[declineMessageKey(code)], {
|
|
461
|
+
decline_code: known,
|
|
462
|
+
next_step: p.next_step ?? NEXT_STEP[known],
|
|
463
|
+
retryable: p.retryable !== false && base.attempts_left !== 0
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
if (p.status === "expired") return out("expired", m["state.expired"], { next_step: "rebuild_cart" });
|
|
467
|
+
if (p.status === "cancelled") return out("cancelled", m["state.cancelled"], { retryable: true, next_step: "rebuild_cart" });
|
|
468
|
+
if (action?.type === "redirect") {
|
|
469
|
+
const url = safeHttpsUrl(action.redirect_url);
|
|
470
|
+
if (url) return out("redirect", m["state.redirect"], { redirect_url: url });
|
|
471
|
+
}
|
|
472
|
+
if (p.status === "requires_action" || p.status === "pending") {
|
|
473
|
+
if (action?.type === "voucher" && action.voucher) {
|
|
474
|
+
const { amount: _a, currency: _c, voucher_url, ...rest } = action.voucher;
|
|
475
|
+
return out("voucher", m["state.voucher"], {
|
|
476
|
+
next_step: "pay_cash",
|
|
477
|
+
voucher: { ...rest, voucher_url: safeHttpsUrl(voucher_url), amount: voucherMoney(action.voucher) }
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
if (action?.type === "challenge" && action.challenge) {
|
|
481
|
+
return out("challenge", m["state.challenge"], {
|
|
482
|
+
challenge: { url: safeHttpsUrl(action.challenge.url), creq: typeof action.challenge.creq === "string" ? action.challenge.creq : null }
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return out("in_review", m["state.in_review"]);
|
|
487
|
+
}
|
|
488
|
+
function paymentErrorView(err, locale, overrides) {
|
|
489
|
+
const m = paymentMessages(locale, overrides);
|
|
490
|
+
const e = err ?? {};
|
|
491
|
+
const status = typeof e.status === "number" ? e.status : 0;
|
|
492
|
+
const code = typeof e.code === "string" ? e.code : "";
|
|
493
|
+
if (code === "price_mismatch") {
|
|
494
|
+
return { kind: "price_mismatch", message: m["error.price_mismatch"], retrySameAttempt: false, canRetry: true };
|
|
495
|
+
}
|
|
496
|
+
if (status === 409 && code === "expired") return { kind: "expired", message: m["error.expired"], retrySameAttempt: false, canRetry: false };
|
|
497
|
+
if (status === 409 && code === "payment_in_progress") {
|
|
498
|
+
return { kind: "payment_in_progress", message: m["error.payment_in_progress"], retrySameAttempt: false, canRetry: false };
|
|
499
|
+
}
|
|
500
|
+
if (status === 409) return { kind: "generic", message: m["error.generic"], retrySameAttempt: false, canRetry: true };
|
|
501
|
+
if (status === 429 || code === "too_many_attempts") {
|
|
502
|
+
return { kind: "too_many_attempts", message: m["error.too_many_attempts"], retrySameAttempt: false, canRetry: false };
|
|
503
|
+
}
|
|
504
|
+
const declared = e.retryable;
|
|
505
|
+
if (status >= 500 && declared === false) return { kind: "generic", message: m["error.generic"], retrySameAttempt: false, canRetry: true };
|
|
506
|
+
if (status === 0 || status === 502 || status === 503 || status === 504 || code === "network" || code === "timeout" || status >= 500) {
|
|
507
|
+
return { kind: "network", message: m["error.network"], retrySameAttempt: true, canRetry: true };
|
|
508
|
+
}
|
|
509
|
+
return { kind: "generic", message: m["error.generic"], retrySameAttempt: false, canRetry: true };
|
|
510
|
+
}
|
|
511
|
+
function formatVoucherExpiry(expiresAt, locale, overrides) {
|
|
512
|
+
if (!expiresAt) return null;
|
|
513
|
+
const d = new Date(expiresAt);
|
|
514
|
+
if (Number.isNaN(d.getTime())) return null;
|
|
515
|
+
let date;
|
|
516
|
+
try {
|
|
517
|
+
date = new Intl.DateTimeFormat(locale ?? void 0, { dateStyle: "long", timeStyle: "short" }).format(d);
|
|
518
|
+
} catch {
|
|
519
|
+
date = d.toISOString();
|
|
520
|
+
}
|
|
521
|
+
return formatAvailabilityMessage(paymentMessages(locale, overrides)["voucher.expires"], { date });
|
|
522
|
+
}
|
|
523
|
+
function paymentIdempotencyKey(checkoutId, attempt) {
|
|
524
|
+
return `pay-${checkoutId}-${attempt}`;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/order-progress.ts
|
|
528
|
+
var SHIPPING_STEPS = ["paid", "preparing", "shipped", "in_transit", "delivered"];
|
|
529
|
+
var PICKUP_STEPS = ["paid", "preparing", "ready_for_pickup", "delivered"];
|
|
530
|
+
var SHIPMENT_PROBLEMS = { exception: "delivery_exception", returned: "returned", lost: "lost" };
|
|
531
|
+
var RANK = { pending: 0, label_created: 1, in_transit: 2, out_for_delivery: 3, delivered: 4 };
|
|
532
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
533
|
+
function isTestShipment(s) {
|
|
534
|
+
return !!s && (s.test_mode === true || s.environment === "sandbox");
|
|
535
|
+
}
|
|
536
|
+
function isTestInvoice(d) {
|
|
537
|
+
return !!d && (d.test_mode === true || d.environment === "sandbox");
|
|
538
|
+
}
|
|
539
|
+
function safeTrackingUrl(value) {
|
|
540
|
+
return safeHttpsUrl(value);
|
|
541
|
+
}
|
|
542
|
+
function time(iso) {
|
|
543
|
+
const t = iso ? Date.parse(iso) : NaN;
|
|
544
|
+
return Number.isNaN(t) ? -Infinity : t;
|
|
545
|
+
}
|
|
546
|
+
function sortTrackingEvents(events, limit = 50) {
|
|
547
|
+
if (!Array.isArray(events)) return [];
|
|
548
|
+
return events.filter(isRecord).map((e, i) => ({ e, i })).sort((a, b) => time(b.e.occurred_at) - time(a.e.occurred_at) || a.i - b.i).slice(0, Math.max(0, limit)).map((x) => x.e);
|
|
549
|
+
}
|
|
550
|
+
function orderShipments(order) {
|
|
551
|
+
const list = Array.isArray(order?.shipments) ? order.shipments.filter(isRecord) : [];
|
|
552
|
+
return [...list.filter((s) => s.kind !== "return"), ...list.filter((s) => s.kind === "return")];
|
|
553
|
+
}
|
|
554
|
+
function validProgress(p) {
|
|
555
|
+
return isRecord(p) && typeof p.stage === "string" && Array.isArray(p.steps);
|
|
556
|
+
}
|
|
557
|
+
var validStep = (s) => isRecord(s) && typeof s.key === "string" && typeof s.state === "string";
|
|
558
|
+
function cleanProgress(p) {
|
|
559
|
+
if (p.steps.every(validStep) && (p.problem === void 0 || p.problem === null || isRecord(p.problem) && typeof p.problem.code === "string")) return p;
|
|
560
|
+
const problem = isRecord(p.problem) && typeof p.problem.code === "string" ? p.problem : null;
|
|
561
|
+
return { stage: p.stage, problem, steps: p.steps.filter(validStep) };
|
|
562
|
+
}
|
|
563
|
+
var liveShipments = (shipments) => shipments.filter((s) => s.kind !== "return" && !isTestShipment(s));
|
|
564
|
+
function legacyStage(order, shipments) {
|
|
565
|
+
const status = typeof order.status === "string" ? order.status.toLowerCase() : "";
|
|
566
|
+
const pickup = order.delivery_method === "pickup";
|
|
567
|
+
if (status === "cancelled" || status === "canceled") return "cancelled";
|
|
568
|
+
if (status === "refunded") return "refunded";
|
|
569
|
+
if (status === "pending_payment" || order.payment_status === "pending") return "pending_payment";
|
|
570
|
+
if (status === "delivered" || status === "fulfilled") return "delivered";
|
|
571
|
+
const live = liveShipments(shipments);
|
|
572
|
+
const ranked = live.filter((s) => RANK[s.status] !== void 0);
|
|
573
|
+
const least = ranked.reduce((acc, s) => acc === null || RANK[s.status] < RANK[acc] ? s.status : acc, null);
|
|
574
|
+
if (least === "delivered") return "delivered";
|
|
575
|
+
if (least === "out_for_delivery") return "out_for_delivery";
|
|
576
|
+
if (least === "in_transit") return "in_transit";
|
|
577
|
+
if (status === "ready_for_pickup" || status === "ready" && pickup) return "ready_for_pickup";
|
|
578
|
+
const onlySandbox = shipments.some((s) => s.kind !== "return") && live.length === 0;
|
|
579
|
+
if (status === "shipped" && !onlySandbox || least === "label_created") return "shipped";
|
|
580
|
+
if (status === "fulfilling" || status === "accepted" || status === "ready" || status === "shipped") return "preparing";
|
|
581
|
+
return "paid";
|
|
582
|
+
}
|
|
583
|
+
var STAGE_TO_STEP = {
|
|
584
|
+
paid: "paid",
|
|
585
|
+
preparing: "preparing",
|
|
586
|
+
ready_for_pickup: "ready_for_pickup",
|
|
587
|
+
shipped: "shipped",
|
|
588
|
+
in_transit: "in_transit",
|
|
589
|
+
out_for_delivery: "in_transit",
|
|
590
|
+
delivered: "delivered"
|
|
591
|
+
};
|
|
592
|
+
function paidAt(order) {
|
|
593
|
+
const paid = Array.isArray(order.payments) ? order.payments.find((p) => isRecord(p) && typeof p.paid_at === "string" && p.paid_at) : void 0;
|
|
594
|
+
return paid?.paid_at ?? null;
|
|
595
|
+
}
|
|
596
|
+
function orderProgress(order) {
|
|
597
|
+
if (validProgress(order.progress)) return cleanProgress(order.progress);
|
|
598
|
+
const shipments = orderShipments(order);
|
|
599
|
+
const stage = legacyStage(order, shipments);
|
|
600
|
+
const keys = order.delivery_method === "pickup" ? PICKUP_STEPS : SHIPPING_STEPS;
|
|
601
|
+
const dead = stage === "cancelled" || stage === "refunded";
|
|
602
|
+
const awaiting = stage === "pending_payment";
|
|
603
|
+
const current = STAGE_TO_STEP[stage] ?? "paid";
|
|
604
|
+
const at = keys.indexOf(current);
|
|
605
|
+
const failed = liveShipments(shipments).find((s) => SHIPMENT_PROBLEMS[s.status]);
|
|
606
|
+
const problem = failed ? { code: SHIPMENT_PROBLEMS[failed.status], at: sortTrackingEvents(failed.events)[0]?.occurred_at ?? null } : order.payment_status === "failed" ? { code: "payment_failed" } : null;
|
|
607
|
+
const steps = dead ? [] : keys.map((key, i) => {
|
|
608
|
+
if (awaiting) return { key, state: "pending", at: null };
|
|
609
|
+
const state = i < at || stage === "delivered" ? "done" : i === at ? problem && i >= keys.indexOf("shipped") ? "problem" : "current" : "pending";
|
|
610
|
+
return { key, state, at: key === "paid" && state === "done" ? paidAt(order) : null };
|
|
611
|
+
});
|
|
612
|
+
return { stage, problem, steps };
|
|
613
|
+
}
|
|
614
|
+
function nextAction(order) {
|
|
615
|
+
if (order.next_action === null) return { kind: "none", href: null, ref: null };
|
|
616
|
+
if (isRecord(order.next_action) && typeof order.next_action.kind === "string") {
|
|
617
|
+
const href = safeTrackingUrl(order.next_action.href);
|
|
618
|
+
return { kind: order.next_action.kind, href, ref: typeof order.next_action.ref === "string" ? order.next_action.ref : null };
|
|
619
|
+
}
|
|
620
|
+
const progress = orderProgress(order);
|
|
621
|
+
if (progress.stage === "pending_payment") return { kind: "pay", href: null, ref: null };
|
|
622
|
+
if (progress.stage === "cancelled" || progress.stage === "refunded") return { kind: "none", href: null, ref: null };
|
|
623
|
+
const live = orderShipments(order).find((s) => s.kind !== "return" && !isTestShipment(s) && s.status !== "delivered" && s.status !== "cancelled");
|
|
624
|
+
const trackUrl = safeTrackingUrl(live?.tracking_url);
|
|
625
|
+
if (live && trackUrl) return { kind: "track", href: trackUrl, ref: live.id };
|
|
626
|
+
if (progress.stage === "ready_for_pickup") return { kind: "pickup", href: null, ref: null };
|
|
627
|
+
const inv = isRecord(order.invoice) ? order.invoice : void 0;
|
|
628
|
+
if (inv?.action === "download" || inv?.action === void 0 && inv?.stage === "issued") {
|
|
629
|
+
const docs = Array.isArray(order.invoices) ? order.invoices.filter((d) => isRecord(d) && d.kind === "invoice" && d.status !== "cancelled") : [];
|
|
630
|
+
const real = docs.find((d) => !isTestInvoice(d));
|
|
631
|
+
if (docs.length === 0 || real) return { kind: "download_invoice", href: null, ref: real?.id ?? null };
|
|
632
|
+
}
|
|
633
|
+
if (inv?.action === "correct_data") return { kind: "correct_invoice_data", href: null, ref: null };
|
|
634
|
+
if (inv?.action === "contact_store") return { kind: "contact_store", href: null, ref: null };
|
|
635
|
+
if (inv?.can_request === true && inv.stage !== "requested") return { kind: "request_invoice", href: null, ref: null };
|
|
636
|
+
return { kind: "none", href: null, ref: null };
|
|
637
|
+
}
|
|
638
|
+
function shipmentsStatus(order) {
|
|
639
|
+
if (order.shipments_summary && typeof order.shipments_summary.status === "string") return order.shipments_summary.status;
|
|
640
|
+
const live = orderShipments(order).filter((s) => s.kind !== "return" && !isTestShipment(s));
|
|
641
|
+
return live.length ? live[0].status : null;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export { PICKUP_STEPS, SHIPPING_STEPS, StorefrontError, availabilityLocale, availabilityMessages, availabilityView, cartLineProblemView, declineMessage, declineMessageKey, defaultCodeForStatus, formatAvailabilityMessage, formatVoucherExpiry, isStorefrontError, isTestInvoice, isTestShipment, nextAction, orderProgress, orderShipments, paymentErrorView, paymentIdempotencyKey, paymentMessages, paymentOutcome, productAvailability, resolveAvailability, safeHttpsUrl, safeTrackingUrl, schemaAvailability, shipmentsStatus, sortTrackingEvents };
|
|
645
|
+
//# sourceMappingURL=chunk-IPUAZ3LQ.js.map
|
|
646
|
+
//# sourceMappingURL=chunk-IPUAZ3LQ.js.map
|