@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/dist/index.js CHANGED
@@ -1,81 +1,7 @@
1
- import { availabilityLocale, formatAvailabilityMessage } from './chunk-HBSB7XS2.js';
2
- export { availabilityLocale, availabilityMessages, availabilityView, cartLineProblemView, formatAvailabilityMessage, productAvailability, resolveAvailability, schemaAvailability } from './chunk-HBSB7XS2.js';
1
+ import { isStorefrontError, availabilityLocale, StorefrontError, formatAvailabilityMessage, defaultCodeForStatus } from './chunk-IPUAZ3LQ.js';
2
+ export { PICKUP_STEPS, SHIPPING_STEPS, StorefrontError, availabilityLocale, availabilityMessages, availabilityView, cartLineProblemView, declineMessage, declineMessageKey, formatAvailabilityMessage, formatVoucherExpiry, isStorefrontError, isTestInvoice, isTestShipment, nextAction, orderProgress, orderShipments, paymentErrorView, paymentIdempotencyKey, paymentMessages, paymentOutcome, productAvailability, resolveAvailability, safeHttpsUrl, safeTrackingUrl, schemaAvailability, shipmentsStatus, sortTrackingEvents } from './chunk-IPUAZ3LQ.js';
3
3
  import { isValidPoint } from './chunk-45R47HYO.js';
4
4
 
5
- // src/errors.ts
6
- var StorefrontError = class extends Error {
7
- name = "StorefrontError";
8
- status;
9
- code;
10
- field;
11
- details;
12
- url;
13
- /** Scopes a `403 insufficient_scope` says the route needs (empty for any other error). */
14
- requiredScopes;
15
- /** `true`: repeating the request (same idempotency key) can succeed. `false`: not until someone fixes something. `undefined`: OPS did not say. */
16
- retryable;
17
- /** Seconds OPS asks to wait before retrying. */
18
- retryAfter;
19
- /** Checkout that a refused cart write can resume. */
20
- checkoutId;
21
- /** Current cart cost sent with a `price_mismatch` (untrusted shape). */
22
- cost;
23
- /** English version of `message`, when OPS sent one. */
24
- messageEn;
25
- constructor(init) {
26
- super(init.message, init.cause === void 0 ? void 0 : { cause: init.cause });
27
- this.status = init.status;
28
- this.code = init.code;
29
- this.field = init.field;
30
- this.details = init.details;
31
- this.url = init.url;
32
- this.requiredScopes = init.requiredScopes ?? [];
33
- this.retryable = init.retryable;
34
- this.retryAfter = init.retryAfter;
35
- this.checkoutId = init.checkoutId;
36
- this.cost = init.cost;
37
- this.messageEn = init.messageEn;
38
- }
39
- /**
40
- * Affected lines of a `409 insufficient_stock` (empty for any other error or a
41
- * server older than contract 1.1). The cart is untouched: show the lines and
42
- * let the buyer adjust or remove them.
43
- */
44
- get stockLines() {
45
- const lines = this.details?.lines;
46
- if (this.code !== "insufficient_stock" || !Array.isArray(lines)) return [];
47
- return lines.filter((l) => typeof l === "object" && l !== null && typeof l.sku === "string");
48
- }
49
- toJSON() {
50
- return {
51
- name: this.name,
52
- status: this.status,
53
- code: this.code,
54
- message: this.message,
55
- field: this.field,
56
- ...this.requiredScopes.length ? { requiredScopes: this.requiredScopes } : {},
57
- ...this.retryable !== void 0 ? { retryable: this.retryable } : {},
58
- ...this.retryAfter !== void 0 ? { retryAfter: this.retryAfter } : {},
59
- ...this.checkoutId ? { checkoutId: this.checkoutId } : {}
60
- };
61
- }
62
- };
63
- function isStorefrontError(err) {
64
- return err instanceof StorefrontError || typeof err === "object" && err !== null && err.name === "StorefrontError";
65
- }
66
- var STATUS_CODES = {
67
- 400: "validation",
68
- 401: "unauthorized",
69
- 403: "forbidden",
70
- 404: "not_found",
71
- 409: "conflict",
72
- 422: "invalid_state",
73
- 429: "rate_limited"
74
- };
75
- function defaultCodeForStatus(status) {
76
- return STATUS_CODES[status] ?? (status >= 500 ? "server_error" : "invalid_response");
77
- }
78
-
79
5
  // src/money.ts
80
6
  function parseMoney(money) {
81
7
  if (money == null) return 0;
@@ -171,6 +97,7 @@ function joinUrl(baseUrl, path) {
171
97
  return baseUrl.replace(/\/+$/, "") + path;
172
98
  }
173
99
  function enc(segment) {
100
+ if (typeof segment !== "string" || /^(?:\.|%2e){1,2}$/i.test(segment)) throw new TypeError(`Invalid path segment: ${String(segment)}`);
174
101
  return encodeURIComponent(segment);
175
102
  }
176
103
  function linkSignals(signals) {
@@ -267,6 +194,7 @@ function createStorefrontClient(config) {
267
194
  const linked = linkSignals([options.signal, timeoutController?.signal]);
268
195
  const init = {
269
196
  ...passthrough,
197
+ ...spec.noRedirect ? { redirect: "error" } : {},
270
198
  method: spec.method,
271
199
  headers,
272
200
  ...spec.body !== void 0 ? { body: JSON.stringify(spec.body) } : {},
@@ -292,6 +220,10 @@ function createStorefrontClient(config) {
292
220
  linked.cleanup();
293
221
  }
294
222
  if (config.onResponse) await config.onResponse({ ...ctx, response: res, durationMs: Date.now() - started });
223
+ if (spec.noRedirect && res.redirected) {
224
+ await res.text().catch(() => void 0);
225
+ throw new StorefrontError({ status: 502, code: "invalid_response", message: "The answer was redirected; it is refused", url });
226
+ }
295
227
  if (res.status === 404 && spec.nullOn404) {
296
228
  await res.text().catch(() => void 0);
297
229
  return null;
@@ -477,6 +409,39 @@ function createStorefrontClient(config) {
477
409
  order: (id, options) => getOrNull(`/storefront/customer/orders/${enc(id)}`, void 0, options),
478
410
  requestReturn: (orderId, input, options) => write("POST", `/storefront/customer/orders/${enc(orderId)}/returns`, input, options),
479
411
  requestInvoice: (orderId, input, options) => write("POST", `/storefront/customer/orders/${enc(orderId)}/invoice`, input, options),
412
+ /**
413
+ * Checkouts waiting for their payment (cash voucher: OXXO, SPEI). They are not orders yet; once the payment
414
+ * confirms they leave this list and show up in `orders`.
415
+ */
416
+ pendingPayments: async (params, options) => (
417
+ // An OPS older than the route answers 404: it has no pending payments to list (a 401 still throws).
418
+ await getOrNull("/storefront/customer/pending-payments", params, options) ?? {
419
+ nodes: [],
420
+ page_info: { has_next_page: false, end_cursor: null },
421
+ total_count: 0
422
+ }
423
+ ),
424
+ /**
425
+ * Reads one file (`pdf` | `xml`) of an invoice or credit note of the buyer's order, through the authenticated
426
+ * route (`order_invoice_file`): the answer is the file itself (base64), never a URL, so neither the buyer token
427
+ * nor a link of the PAC reaches the browser. Call it from YOUR server and stream the bytes
428
+ * (`invoiceFileBytes`). `null` when the order, the document or the file does not exist or is not the buyer's.
429
+ */
430
+ invoiceFile: async (orderId, invoiceId, kind, options) => {
431
+ if (kind !== "pdf" && kind !== "xml") throw new TypeError("invoiceFile: kind must be 'pdf' or 'xml'");
432
+ const file = await request({
433
+ method: "GET",
434
+ path: `/storefront/customer/orders/${enc(orderId)}/invoices/${enc(invoiceId)}/${kind}`,
435
+ options: { ...options, cache: "no-store" },
436
+ nullOn404: true,
437
+ noRedirect: true
438
+ });
439
+ if (file === null) return null;
440
+ if (!file || typeof file.content_base64 !== "string" || typeof file.filename !== "string" || typeof file.content_type !== "string") {
441
+ throw new StorefrontError({ status: 502, code: "invalid_response", message: "The invoice file answer is not a file" });
442
+ }
443
+ return { filename: file.filename, content_type: file.content_type, content_base64: file.content_base64 };
444
+ },
480
445
  addresses: {
481
446
  list: (options) => get("/storefront/customer/addresses", void 0, options),
482
447
  create: (address, options) => write("POST", "/storefront/customer/addresses", address, options),
@@ -571,237 +536,8 @@ async function diagnose(client, options = {}) {
571
536
  }
572
537
  }
573
538
 
574
- // src/payments.ts
575
- var ES = {
576
- "decline.insufficient_funds": "Tu tarjeta no tiene saldo suficiente. Prueba con otra tarjeta o paga en efectivo.",
577
- "decline.invalid_cvc": "El c\xF3digo de seguridad no es correcto. Rev\xEDsalo e intenta de nuevo.",
578
- "decline.invalid_expiry": "La fecha de vencimiento no es correcta.",
579
- "decline.invalid_card_data": "Revisa los datos de tu tarjeta.",
580
- "decline.call_issuer": "Tu banco necesita que autorices este pago. Llama al n\xFAmero al reverso de tu tarjeta y vuelve a intentarlo.",
581
- "decline.card_disabled": "Tu tarjeta no est\xE1 activa. Act\xEDvala con tu banco o usa otra.",
582
- "decline.duplicate": "Ya hiciste un pago igual hace un momento. Revisa tu correo antes de volver a pagar.",
583
- "decline.max_attempts": "Llegaste al l\xEDmite de intentos con esta tarjeta. Usa otra o paga en efectivo.",
584
- "decline.authentication_failed": "Tu banco no pudo verificar el pago. Intenta de nuevo o usa otra tarjeta.",
585
- "decline.declined": "Tu banco rechaz\xF3 el pago. Usa otra tarjeta o paga en efectivo.",
586
- "state.loading": "Cargando pago seguro\u2026",
587
- "state.processing": "Procesando pago\u2026",
588
- "state.approved": "\xA1Pago aprobado!",
589
- "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.",
590
- "state.voucher": "Tu ficha de pago est\xE1 lista. El pedido se confirma cuando pagues.",
591
- "state.challenge": "Tu banco necesita verificar el pago. Termina la verificaci\xF3n para continuar.",
592
- "state.expired": "La ficha venci\xF3. Vuelve a armar tu carrito para pagar.",
593
- "state.cancelled": "El pago se cancel\xF3. Puedes intentarlo de nuevo.",
594
- "state.redirect": "Te llevamos a la p\xE1gina de pago\u2026",
595
- "state.fallback": "No pudimos cargar el formulario seguro de tarjeta. Puedes pagar con tarjeta en el sitio del proveedor y regresar aqu\xED.",
596
- "error.network": "No pudimos conectar. Revisa tu conexi\xF3n e intenta de nuevo; no se te cobrar\xE1 dos veces.",
597
- "error.card_data": "Revisa los datos de tu tarjeta.",
598
- "error.price_mismatch": "El total cambi\xF3. Revisa el nuevo total y vuelve a pagar.",
599
- "error.payment_in_progress": "Ya hay un pago en proceso para este pedido. No vuelvas a pagar; revisa tu correo.",
600
- "error.expired": "Tu apartado venci\xF3. Vuelve a armar tu carrito.",
601
- "error.too_many_attempts": "Por seguridad no podemos intentar con m\xE1s tarjetas. Paga en efectivo o escr\xEDbenos.",
602
- "error.generic": "No pudimos procesar tu pago. Intenta de nuevo.",
603
- "action.retry": "Reintentar",
604
- "action.try_again": "Intentar de nuevo",
605
- "action.pay": "Pagar",
606
- "action.cancel": "Cancelar",
607
- "voucher.title": "Ficha de pago",
608
- "voucher.point": "Punto de pago",
609
- "voucher.reference": "Referencia",
610
- "voucher.amount": "Monto exacto",
611
- "voucher.expires": "Vence el {date}",
612
- "voucher.clabe": "CLABE",
613
- "voucher.barcode": "C\xF3digo de barras",
614
- "voucher.open": "Ver o imprimir ficha",
615
- "voucher.email": "Tambi\xE9n te la enviamos a tu correo.",
616
- "form.label": "Datos de tu tarjeta",
617
- "challenge.title": "Verificaci\xF3n de tu banco"
618
- };
619
- var EN = {
620
- "decline.insufficient_funds": "Your card has insufficient funds. Try another card or pay in cash.",
621
- "decline.invalid_cvc": "The security code is not correct. Check it and try again.",
622
- "decline.invalid_expiry": "The expiry date is not correct.",
623
- "decline.invalid_card_data": "Check your card details.",
624
- "decline.call_issuer": "Your bank needs you to authorize this payment. Call the number on the back of your card and try again.",
625
- "decline.card_disabled": "Your card is not active. Activate it with your bank or use another one.",
626
- "decline.duplicate": "You already made the same payment a moment ago. Check your email before paying again.",
627
- "decline.max_attempts": "You reached the attempt limit for this card. Use another card or pay in cash.",
628
- "decline.authentication_failed": "Your bank could not verify the payment. Try again or use another card.",
629
- "decline.declined": "Your bank declined the payment. Use another card or pay in cash.",
630
- "state.loading": "Loading secure payment\u2026",
631
- "state.processing": "Processing payment\u2026",
632
- "state.approved": "Payment approved!",
633
- "state.in_review": "Your payment is under review. We will email you within 2 business days. Do not pay again.",
634
- "state.voucher": "Your payment voucher is ready. The order is confirmed once you pay.",
635
- "state.challenge": "Your bank needs to verify the payment. Finish the verification to continue.",
636
- "state.expired": "The voucher expired. Rebuild your cart to pay.",
637
- "state.cancelled": "The payment was cancelled. You can try again.",
638
- "state.redirect": "Taking you to the payment page\u2026",
639
- "state.fallback": "We could not load the secure card form. You can pay by card on the provider site and come back here.",
640
- "error.network": "We could not connect. Check your connection and try again; you will not be charged twice.",
641
- "error.card_data": "Check your card details.",
642
- "error.price_mismatch": "The total changed. Review the new total and pay again.",
643
- "error.payment_in_progress": "A payment is already in progress for this order. Do not pay again; check your email.",
644
- "error.expired": "Your reservation expired. Rebuild your cart.",
645
- "error.too_many_attempts": "For security we cannot try more cards. Pay in cash or contact us.",
646
- "error.generic": "We could not process your payment. Please try again.",
647
- "action.retry": "Retry",
648
- "action.try_again": "Try again",
649
- "action.pay": "Pay",
650
- "action.cancel": "Cancel",
651
- "voucher.title": "Payment voucher",
652
- "voucher.point": "Payment point",
653
- "voucher.reference": "Reference",
654
- "voucher.amount": "Exact amount",
655
- "voucher.expires": "Expires on {date}",
656
- "voucher.clabe": "CLABE",
657
- "voucher.barcode": "Barcode",
658
- "voucher.open": "View or print voucher",
659
- "voucher.email": "We also emailed it to you.",
660
- "form.label": "Your card details",
661
- "challenge.title": "Your bank verification"
662
- };
663
- var CATALOG = { es: ES, en: EN };
664
- function paymentMessages(locale, overrides) {
665
- const base = CATALOG[availabilityLocale(locale)];
666
- if (!overrides) return base;
667
- const out = { ...base };
668
- for (const [k, v] of Object.entries(overrides)) if (typeof v === "string" && k in base) out[k] = v;
669
- return out;
670
- }
671
- var DECLINE_CODES = /* @__PURE__ */ new Set([
672
- "insufficient_funds",
673
- "invalid_cvc",
674
- "invalid_expiry",
675
- "invalid_card_data",
676
- "call_issuer",
677
- "card_disabled",
678
- "duplicate",
679
- "max_attempts",
680
- "authentication_failed",
681
- "declined"
682
- ]);
683
- function declineMessageKey(code) {
684
- return `decline.${code && DECLINE_CODES.has(code) ? code : "declined"}`;
685
- }
686
- function declineMessage(code, locale, overrides) {
687
- return paymentMessages(locale, overrides)[declineMessageKey(code)];
688
- }
689
- function safeHttpsUrl(value) {
690
- if (typeof value !== "string" || value.length > 2048) return null;
691
- try {
692
- const u = new URL(value);
693
- if (u.protocol !== "https:" || u.username || u.password) return null;
694
- return u.toString();
695
- } catch {
696
- return null;
697
- }
698
- }
699
- var NEXT_STEP = {
700
- insufficient_funds: "use_other_card",
701
- invalid_cvc: "fix_card_data",
702
- invalid_expiry: "fix_card_data",
703
- invalid_card_data: "fix_card_data",
704
- call_issuer: "contact_issuer",
705
- card_disabled: "use_other_card",
706
- duplicate: "check_email",
707
- max_attempts: "use_other_card",
708
- authentication_failed: "retry",
709
- declined: "use_other_card"
710
- };
711
- function voucherMoney(v) {
712
- const a = v.amount;
713
- if (a && typeof a === "object" && typeof a.amount === "string") return a;
714
- const text = typeof a === "number" ? String(a) : typeof a === "string" ? a : "";
715
- if (!text || !/^\d+(\.\d+)?$/.test(text) || !v.currency) return null;
716
- return { amount: text.includes(".") ? text : `${text}.00`, currency_code: v.currency };
717
- }
718
- function paymentOutcome(result, locale, overrides) {
719
- const m = paymentMessages(locale, overrides);
720
- const p = result.payment;
721
- const action = p.action ?? null;
722
- const base = {
723
- decline_code: null,
724
- retryable: false,
725
- redirect_url: null,
726
- challenge: null,
727
- voucher: null,
728
- attempts_left: typeof result.attempts_left === "number" ? result.attempts_left : null,
729
- next_step: p.next_step ?? null
730
- };
731
- const out = (kind, message, extra = {}) => ({ ...base, kind, message, ...extra });
732
- if (p.status === "paid") return out("approved", m["state.approved"]);
733
- if (p.status === "failed") {
734
- const code = p.decline_code ?? "declined";
735
- const known = DECLINE_CODES.has(code) ? code : "declined";
736
- return out("rejected", m[declineMessageKey(code)], {
737
- decline_code: known,
738
- next_step: p.next_step ?? NEXT_STEP[known],
739
- retryable: p.retryable !== false && base.attempts_left !== 0
740
- });
741
- }
742
- if (p.status === "expired") return out("expired", m["state.expired"], { next_step: "rebuild_cart" });
743
- if (p.status === "cancelled") return out("cancelled", m["state.cancelled"], { retryable: true, next_step: "rebuild_cart" });
744
- if (action?.type === "redirect") {
745
- const url = safeHttpsUrl(action.redirect_url);
746
- if (url) return out("redirect", m["state.redirect"], { redirect_url: url });
747
- }
748
- if (p.status === "requires_action" || p.status === "pending") {
749
- if (action?.type === "voucher" && action.voucher) {
750
- const { amount: _a, currency: _c, voucher_url, ...rest } = action.voucher;
751
- return out("voucher", m["state.voucher"], {
752
- next_step: "pay_cash",
753
- voucher: { ...rest, voucher_url: safeHttpsUrl(voucher_url), amount: voucherMoney(action.voucher) }
754
- });
755
- }
756
- if (action?.type === "challenge" && action.challenge) {
757
- return out("challenge", m["state.challenge"], {
758
- challenge: { url: safeHttpsUrl(action.challenge.url), creq: typeof action.challenge.creq === "string" ? action.challenge.creq : null }
759
- });
760
- }
761
- }
762
- return out("in_review", m["state.in_review"]);
763
- }
764
- function paymentErrorView(err, locale, overrides) {
765
- const m = paymentMessages(locale, overrides);
766
- const e = err ?? {};
767
- const status = typeof e.status === "number" ? e.status : 0;
768
- const code = typeof e.code === "string" ? e.code : "";
769
- if (code === "price_mismatch") {
770
- return { kind: "price_mismatch", message: m["error.price_mismatch"], retrySameAttempt: false, canRetry: true };
771
- }
772
- if (status === 409 && code === "expired") return { kind: "expired", message: m["error.expired"], retrySameAttempt: false, canRetry: false };
773
- if (status === 409 && code === "payment_in_progress") {
774
- return { kind: "payment_in_progress", message: m["error.payment_in_progress"], retrySameAttempt: false, canRetry: false };
775
- }
776
- if (status === 409) return { kind: "generic", message: m["error.generic"], retrySameAttempt: false, canRetry: true };
777
- if (status === 429 || code === "too_many_attempts") {
778
- return { kind: "too_many_attempts", message: m["error.too_many_attempts"], retrySameAttempt: false, canRetry: false };
779
- }
780
- const declared = e.retryable;
781
- if (status >= 500 && declared === false) return { kind: "generic", message: m["error.generic"], retrySameAttempt: false, canRetry: true };
782
- if (status === 0 || status === 502 || status === 503 || status === 504 || code === "network" || code === "timeout" || status >= 500) {
783
- return { kind: "network", message: m["error.network"], retrySameAttempt: true, canRetry: true };
784
- }
785
- return { kind: "generic", message: m["error.generic"], retrySameAttempt: false, canRetry: true };
786
- }
787
- function formatVoucherExpiry(expiresAt, locale, overrides) {
788
- if (!expiresAt) return null;
789
- const d = new Date(expiresAt);
790
- if (Number.isNaN(d.getTime())) return null;
791
- let date;
792
- try {
793
- date = new Intl.DateTimeFormat(locale ?? void 0, { dateStyle: "long", timeStyle: "short" }).format(d);
794
- } catch {
795
- date = d.toISOString();
796
- }
797
- return formatAvailabilityMessage(paymentMessages(locale, overrides)["voucher.expires"], { date });
798
- }
799
- function paymentIdempotencyKey(checkoutId, attempt) {
800
- return `pay-${checkoutId}-${attempt}`;
801
- }
802
-
803
539
  // src/promotions.ts
804
- var ES2 = {
540
+ var ES = {
805
541
  "discount.next": "A\xF1ade {remaining} para activar tu descuento autom\xE1tico",
806
542
  "discount.next_upgrade": "A\xF1ade {remaining} para subir a {reward}",
807
543
  "discount.applied": "\xA1Tienes {reward} de descuento!",
@@ -852,7 +588,7 @@ var ES2 = {
852
588
  "note.error": "No se pudo guardar la nota. Intenta de nuevo.",
853
589
  "note.counter": "{n} de {max} caracteres"
854
590
  };
855
- var EN2 = {
591
+ var EN = {
856
592
  "discount.next": "Add {remaining} to unlock your automatic discount",
857
593
  "discount.next_upgrade": "Add {remaining} to move up to {reward}",
858
594
  "discount.applied": "You have {reward} off!",
@@ -903,9 +639,9 @@ var EN2 = {
903
639
  "note.error": "The note could not be saved. Please try again.",
904
640
  "note.counter": "{n} of {max} characters"
905
641
  };
906
- var CATALOG2 = { es: ES2, en: EN2 };
642
+ var CATALOG = { es: ES, en: EN };
907
643
  function promotionMessages(locale, overrides) {
908
- const base = CATALOG2[availabilityLocale(locale)];
644
+ const base = CATALOG[availabilityLocale(locale)];
909
645
  if (!overrides) return base;
910
646
  const out = { ...base };
911
647
  for (const [k, v] of Object.entries(overrides)) if (typeof v === "string" && k in base) out[k] = v;
@@ -1052,6 +788,33 @@ function hreflangLinks(markets, path, defaultMarket, protocol = "https") {
1052
788
  return links;
1053
789
  }
1054
790
 
791
+ // src/invoice-docs.ts
792
+ function groupInvoiceDocs(docs) {
793
+ const list = Array.isArray(docs) ? docs.filter((d) => !!d && typeof d === "object") : [];
794
+ const groups = list.filter((d) => d.kind !== "credit_note").map((invoice) => ({ invoice, creditNotes: [] }));
795
+ const orphans = [];
796
+ for (const d of list) {
797
+ if (d.kind !== "credit_note") continue;
798
+ const group = d.related_to ? groups.find((g) => g.invoice.id === d.related_to) : void 0;
799
+ if (group) group.creditNotes.push(d);
800
+ else orphans.push(d);
801
+ }
802
+ return { groups, orphans };
803
+ }
804
+ function invoiceFileBytes(file) {
805
+ const raw = typeof file.content_base64 === "string" ? file.content_base64.replace(/\s+/g, "") : "";
806
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(raw) || raw.length % 4 === 1) throw new TypeError("invoice file is not valid base64");
807
+ const bin = atob(raw);
808
+ const out = new Uint8Array(bin.length);
809
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
810
+ return out;
811
+ }
812
+ function safeInvoiceFilename(name, fallback = "factura") {
813
+ const base = typeof name === "string" ? name.split(/[\\/]/).pop() ?? "" : "";
814
+ const clean = base.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^\.+/, "").slice(0, 80);
815
+ return clean || fallback;
816
+ }
817
+
1055
818
  // src/delivery.ts
1056
819
  function parseDelivery(value) {
1057
820
  const raw = (value ?? "").trim();
@@ -1078,6 +841,6 @@ function deliveryNotices(delivery) {
1078
841
  };
1079
842
  }
1080
843
 
1081
- export { CLIENT_IP_HEADER, COUNTRY_HEADERS, MISSING_WEIGHT, NOTE_MAX_LENGTH, PAYMENT_CHOICE_REFUSED_FIELD, StorefrontError, appendParams, clampPercent, classifyPaymentError, createStorefrontClient, declineMessage, declineMessageKey, deliveryInput, deliveryNotices, diagnose, formatMoney, formatVoucherExpiry, generateIdempotencyKey, hreflangLinks, isStorefrontError, isTokenPublishable, maskToken, negotiateLocale, normalizeClientIp, normalizeNote, opsSaysNotRetryable, parseDelivery, parseMoney, parseProductFilters, paymentErrorView, paymentIdempotencyKey, paymentMessages, paymentOutcome, preferredLanguages, productListQuery, promoProgressView, promotionMessages, repairPath, rewardLabel, safeHttpsUrl, storefrontDomainHeader, suggestMarket, toMoney, visitorCountry };
844
+ export { CLIENT_IP_HEADER, COUNTRY_HEADERS, MISSING_WEIGHT, NOTE_MAX_LENGTH, PAYMENT_CHOICE_REFUSED_FIELD, appendParams, clampPercent, classifyPaymentError, createStorefrontClient, deliveryInput, deliveryNotices, diagnose, formatMoney, generateIdempotencyKey, groupInvoiceDocs, hreflangLinks, invoiceFileBytes, isTokenPublishable, maskToken, negotiateLocale, normalizeClientIp, normalizeNote, opsSaysNotRetryable, parseDelivery, parseMoney, parseProductFilters, preferredLanguages, productListQuery, promoProgressView, promotionMessages, repairPath, rewardLabel, safeInvoiceFilename, storefrontDomainHeader, suggestMarket, toMoney, visitorCountry };
1082
845
  //# sourceMappingURL=index.js.map
1083
846
  //# sourceMappingURL=index.js.map