@asteby/storefront-react 0.22.0 → 0.23.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/account.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fill } from './chunk-PPQEUTXJ.js';
1
+ import { fill } from './chunk-VE7WQPMY.js';
2
2
  import { barcodeGeometry, voucherOf, barcodeValue } from './chunk-TXEYBDFG.js';
3
3
  export { barcodeGeometry, barcodeValue, code128Modules, voucherOf } from './chunk-TXEYBDFG.js';
4
4
  import { useFieldErrors, CheckoutField, ErrorSummary } from './chunk-DFGLCIEG.js';
@@ -34,6 +34,26 @@ function personTypeByLength(lengths) {
34
34
  return Object.keys(lengths).find((t) => lengths[t] === n) ?? null;
35
35
  };
36
36
  }
37
+ function personTypeFromPatterns(fid, taxId) {
38
+ const patterns = fid?.person_patterns;
39
+ if (!patterns) return null;
40
+ const v = normalizeTaxId(taxId);
41
+ for (const type of Object.keys(patterns).sort()) {
42
+ const re = compile(patterns[type]);
43
+ if (re?.test(v)) return type;
44
+ }
45
+ return null;
46
+ }
47
+ function personTypeResolver(fid, override) {
48
+ return override ?? ((taxId) => personTypeFromPatterns(fid, taxId));
49
+ }
50
+ function suggestInvoiceUse(fid, regime) {
51
+ if (!fid || !regime) return null;
52
+ const allowed = usesFor(fid, regime);
53
+ const preferred = fid.default_invoice_use;
54
+ if (preferred && allowed.some((u) => u.code === preferred)) return preferred;
55
+ return allowed.find((u) => u.suggested_for_regimes?.includes(regime))?.code ?? null;
56
+ }
37
57
  function regimesFor(fid, personType) {
38
58
  const all = fid?.regimes ?? [];
39
59
  if (!personType) return all;
@@ -44,8 +64,9 @@ function usesFor(fid, regime) {
44
64
  if (!regime) return all;
45
65
  return all.filter((u) => !u.allowed_regimes || u.allowed_regimes.length === 0 || u.allowed_regimes.includes(regime));
46
66
  }
47
- function validateFiscalValues(region, v, personTypeOf) {
67
+ function validateFiscalValues(region, v, personTypeOverride) {
48
68
  const fid = region.fiscal_id;
69
+ const personTypeOf = personTypeResolver(fid, personTypeOverride);
49
70
  const out = {};
50
71
  const tax = taxIdProblem(fid, v.tax_id ?? "");
51
72
  if (tax) out.tax_id = tax;
@@ -117,6 +138,6 @@ function summarizeExtraction(x, evidence, validRegimes) {
117
138
  };
118
139
  }
119
140
 
120
- export { entryLabel, maskTaxId, normalizeTaxId, personTypeByLength, postalCodeProblem, regimesFor, summarizeExtraction, taxIdProblem, toInvoiceRequest, usesFor, validateFiscalValues };
121
- //# sourceMappingURL=chunk-Q7UTJIKY.js.map
122
- //# sourceMappingURL=chunk-Q7UTJIKY.js.map
141
+ export { entryLabel, maskTaxId, normalizeTaxId, personTypeByLength, personTypeFromPatterns, personTypeResolver, postalCodeProblem, regimesFor, suggestInvoiceUse, summarizeExtraction, taxIdProblem, toInvoiceRequest, usesFor, validateFiscalValues };
142
+ //# sourceMappingURL=chunk-D5L7UZIA.js.map
143
+ //# sourceMappingURL=chunk-D5L7UZIA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fiscal/format.ts","../src/fiscal/extraction.ts"],"names":[],"mappings":";AAUO,SAAS,eAAe,GAAA,EAAqB;AAClD,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,UAAA,EAAY,EAAE,EAAE,WAAA,EAAY;AACjD;AAGO,SAAS,UAAU,KAAA,EAAuB;AAC/C,EAAA,MAAM,CAAA,GAAI,MAAM,IAAA,EAAK;AACrB,EAAA,OAAO,CAAA,CAAE,MAAA,IAAU,CAAA,GAAI,GAAA,CAAI,MAAA,CAAO,EAAE,MAAM,CAAA,GAAI,CAAA,EAAG,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,EAAG,GAAA,CAAI,MAAA,CAAO,CAAA,CAAE,MAAA,GAAS,CAAC,CAAC,CAAA,EAAG,CAAA,CAAE,KAAA,CAAM,EAAE,CAAC,CAAA,CAAA;AACzG;AAEA,IAAM,OAAA,GAAU,CAAC,OAAA,K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AC,CAAC,CAAA;AACrG,EAAA,MAAM,SAA4C,EAAC;AACnD,EAAA,MAAM,OAA0B,EAAC;AACjC,EAAA,MAAM,GAAA,GAAM,CAAC,IAAA,EAAuB,CAAA,KAAc;AAChD,IAAA,IAAI,CAAC,CAAA,EAAG;AACR,IAAA,MAAA,CAAO,IAAI,CAAA,GAAI,CAAA;AACf,IAAA,IAAA,CAAK,KAAK,IAAI,CAAA;AAAA,EAChB,CAAA;AACA,EAAA,GAAA,CAAI,UAAU,cAAA,CAAe,KAAA,CAAM,CAAA,CAAE,MAAM,CAAC,CAAC,CAAA;AAC7C,EAAA,GAAA,CAAI,cAAc,KAAA,CAAM,CAAA,CAAE,UAAU,CAAA,CAAE,MAAM,CAAA;AAC5C,EAAA,GAAA,CAAI,eAAe,KAAA,CAAM,CAAA,CAAE,WAAW,CAAA,CAAE,MAAM,CAAA;AAC9C,EAAA,IAAI,WAAW,MAAA,KAAW,CAAA,MAAO,YAAA,EAAc,UAAA,CAAW,CAAC,CAAE,CAAA;AAAA,OAAA,IACpD,UAAA,CAAW,MAAA,GAAS,CAAA,EAAG,IAAA,CAAK,KAAK,YAAY,CAAA;AACtD,EAAA,OAAO;AAAA,IACL,MAAM,CAAA,CAAE,IAAA;AAAA,IACR,MAAA;AAAA,IACA,iBAAA,EAAmB,UAAA;AAAA,IACnB,aAAA,EAAe,IAAA;AAAA,IACf,QAAA,EAAU,EAAE,EAAA,CAAG,KAAA;AAAA,IACf,OAAO,CAAA,CAAE,KAAA;AAAA,IACT,UAAU,CAAA,CAAE,QAAA;AAAA,IACZ,OAAA,EAAS,CAAC,GAAG,CAAA,CAAE,OAAO,CAAA;AAAA,IACtB;AAAA,GACF;AACF","file":"chunk-D5L7UZIA.js","sourcesContent":["/**\n * Pure helpers over the region's fiscal catalog (`Region.fiscal_id`). They know no country: the tax id format, the\n * regimes, the invoice uses and the postal code format are all data.\n */\nimport type { InvoiceRequest, Region, RegionFiscalEntry, RegionFiscalId } from '@asteby/storefront'\nimport type { FiscalFieldName, FiscalFieldValues } from './types.js'\n\nexport type FiscalRegion = Pick<Region, 'address'> & { fiscal_id?: RegionFiscalId }\n\n/** Uppercase, no spaces, hyphens or dots: how a tax id is compared and sent. */\nexport function normalizeTaxId(raw: string): string {\n return raw.replace(/[\\s\\-.]/g, '').toUpperCase()\n}\n\n/** Masks a tax id for display and logs: first 2 and last 3 characters stay (`PE********ABC`). */\nexport function maskTaxId(taxId: string): string {\n const v = taxId.trim()\n return v.length <= 5 ? '*'.repeat(v.length) : `${v.slice(0, 2)}${'*'.repeat(v.length - 5)}${v.slice(-3)}`\n}\n\nconst compile = (pattern: string | undefined): RegExp | null => {\n if (!pattern) return null\n try {\n return new RegExp(pattern)\n } catch {\n return null\n }\n}\n\n/** `null` when the tax id is valid for the region (its pattern or one of its generic ids); otherwise why not. */\nexport function taxIdProblem(fid: RegionFiscalId | undefined, raw: string): 'required' | 'format' | null {\n const v = normalizeTaxId(raw)\n if (!v) return 'required'\n if (!fid) return null\n if (fid.generic_ids.includes(v)) return null\n const re = compile(fid.pattern)\n return re && !re.test(v) ? 'format' : null\n}\n\nexport function postalCodeProblem(region: FiscalRegion, raw: string): 'required' | 'format' | null {\n const v = raw.trim()\n if (!v) return 'required'\n const re = compile(region.address?.postal_code?.pattern)\n return re && !re.test(v) ? 'format' : null\n}\n\n/**\n * Builds the function that tells a person type from a tax id when the region does not publish one. Pass the length\n * of the tax id per type, e.g. `personTypeByLength({ individual: 13, company: 12 })`. Without a function the regimes\n * are not narrowed by person type (the server still checks the combination).\n */\nexport function personTypeByLength(lengths: Record<string, number>): (taxId: string) => string | null {\n return (taxId) => {\n const n = normalizeTaxId(taxId).length\n return Object.keys(lengths).find((t) => lengths[t] === n) ?? null\n }\n}\n\n/**\n * Tells a person type from a tax id with the region's own patterns (`fiscal_id.person_patterns`, DATA of the region\n * pack). `null` when the region publishes none or none matches. A pattern that does not compile is ignored.\n */\nexport function personTypeFromPatterns(fid: RegionFiscalId | undefined, taxId: string): string | null {\n const patterns = fid?.person_patterns\n if (!patterns) return null\n const v = normalizeTaxId(taxId)\n for (const type of Object.keys(patterns).sort()) {\n const re = compile(patterns[type])\n if (re?.test(v)) return type\n }\n return null\n}\n\n/** The function to use for the person type: the store's override, else the region's patterns. */\nexport function personTypeResolver(fid: RegionFiscalId | undefined, override?: (taxId: string) => string | null): (taxId: string) => string | null {\n return override ?? ((taxId) => personTypeFromPatterns(fid, taxId))\n}\n\n/**\n * The invoice use to suggest for a regime, from region data only: the organization's `default_invoice_use` when the\n * regime admits it, else the first use whose `suggested_for_regimes` lists the regime (and whose `allowed_regimes`\n * admits it). `null` when the region suggests nothing: then nothing is preselected. A suggestion, never a rule.\n */\nexport function suggestInvoiceUse(fid: RegionFiscalId | undefined, regime: string | null | undefined): string | null {\n if (!fid || !regime) return null\n const allowed = usesFor(fid, regime)\n const preferred = fid.default_invoice_use\n if (preferred && allowed.some((u) => u.code === preferred)) return preferred\n return allowed.find((u) => u.suggested_for_regimes?.includes(regime))?.code ?? null\n}\n\n/** Regimes that fit a person type (all when the type is unknown). */\nexport function regimesFor(fid: RegionFiscalId | undefined, personType: string | null): RegionFiscalEntry[] {\n const all = fid?.regimes ?? []\n if (!personType) return all\n return all.filter((r) => r.person_types.length === 0 || r.person_types.includes(personType))\n}\n\n/** Invoice uses a regime admits (all when no regime is chosen yet). */\nexport function usesFor(fid: RegionFiscalId | undefined, regime: string | null | undefined): RegionFiscalEntry[] {\n const all = fid?.invoice_uses ?? []\n if (!regime) return all\n return all.filter((u) => !u.allowed_regimes || u.allowed_regimes.length === 0 || u.allowed_regimes.includes(regime))\n}\n\nexport type FiscalProblem = 'required' | 'format' | 'unknown' | 'person_type' | 'use_not_allowed'\n\n/** Client-side check of the whole form against the region; the server stays the authority. */\nexport function validateFiscalValues(\n region: FiscalRegion,\n v: Partial<FiscalFieldValues>,\n personTypeOverride?: (taxId: string) => string | null,\n): Partial<Record<FiscalFieldName, FiscalProblem>> {\n const fid = region.fiscal_id\n const personTypeOf = personTypeResolver(fid, personTypeOverride)\n const out: Partial<Record<FiscalFieldName, FiscalProblem>> = {}\n const tax = taxIdProblem(fid, v.tax_id ?? '')\n if (tax) out.tax_id = tax\n if (!(v.legal_name ?? '').trim()) out.legal_name = 'required'\n if (postalCodeProblem(region, v.postal_code ?? '')) out.postal_code = postalCodeProblem(region, v.postal_code ?? '')!\n const regime = v.tax_regime ?? ''\n if (!regime) out.tax_regime = 'required'\n else if (fid) {\n const entry = fid.regimes.find((r) => r.code === regime)\n if (!entry) out.tax_regime = 'unknown'\n else if (!tax && !fid.generic_ids.includes(normalizeTaxId(v.tax_id ?? ''))) {\n const person = personTypeOf?.(v.tax_id ?? '') ?? null\n if (person && entry.person_types.length > 0 && !entry.person_types.includes(person)) out.tax_regime = 'person_type'\n }\n }\n const use = v.use ?? ''\n if (!use) out.use = 'required'\n else if (fid) {\n const entry = fid.invoice_uses.find((u) => u.code === use)\n if (!entry) out.use = 'unknown'\n else if (regime && entry.allowed_regimes && entry.allowed_regimes.length > 0 && !entry.allowed_regimes.includes(regime)) out.use = 'use_not_allowed'\n }\n return out\n}\n\n/** Form values -> the API's `InvoiceRequest` (without `document`). */\nexport function toInvoiceRequest(v: Partial<FiscalFieldValues>, countryCode?: string): InvoiceRequest {\n return {\n requested: true,\n tax_id: normalizeTaxId(v.tax_id ?? ''),\n legal_name: (v.legal_name ?? '').trim(),\n tax_regime: v.tax_regime ?? '',\n use: v.use ?? '',\n postal_code: (v.postal_code ?? '').trim(),\n ...(countryCode ? { country_code: countryCode } : {}),\n }\n}\n\n/** `label_en` for English locales when the region has it. */\nexport function entryLabel(e: RegionFiscalEntry, locale?: string | null): string {\n return (locale ?? 'es-MX').toLowerCase().startsWith('en') && e.label_en ? e.label_en : e.label\n}\n","/** Turns what the engine read into what the UI shows. Shared by the browser reader and the server upload. */\nimport type { FiscalDocumentEvidence } from '@asteby/storefront'\nimport type { IdentityExtraction } from '@asteby/storefront/fiscal-document'\nimport { normalizeTaxId } from './format.js'\nimport type { FiscalExtractionSummary, FiscalFieldName } from './types.js'\n\nconst first = (v: string | string[] | undefined): string => (Array.isArray(v) ? (v[0] ?? '') : (v ?? ''))\n\n/** `evidence` comes from `buildDocumentEvidence`. Only the conventional fields are kept: nothing else can leak. */\nexport function summarizeExtraction(x: IdentityExtraction, evidence: FiscalDocumentEvidence, validRegimes?: Iterable<string>): FiscalExtractionSummary {\n const f = x.fields\n const valid = validRegimes ? new Set(validRegimes) : null\n const raw = f.tax_regime\n const candidates = (Array.isArray(raw) ? raw : raw ? [raw] : []).filter((c) => !valid || valid.has(c))\n const values: FiscalExtractionSummary['values'] = {}\n const from: FiscalFieldName[] = []\n const put = (name: FiscalFieldName, v: string) => {\n if (!v) return\n values[name] = v\n from.push(name)\n }\n put('tax_id', normalizeTaxId(first(f.tax_id)))\n put('legal_name', first(f.legal_name).trim())\n put('postal_code', first(f.postal_code).trim())\n if (candidates.length === 1) put('tax_regime', candidates[0]!)\n else if (candidates.length > 1) from.push('tax_regime')\n return {\n kind: x.kind,\n values,\n regime_candidates: candidates,\n from_document: from,\n qr_match: x.qr.match,\n stale: x.stale,\n age_days: x.age_days,\n missing: [...x.missing],\n evidence,\n }\n}\n"]}
@@ -16,6 +16,7 @@ var ES = {
16
16
  useHint: "Solo mostramos los usos que admite tu r\xE9gimen.",
17
17
  useChoose: "Elige el uso",
18
18
  fromDocument: "De tu {document}",
19
+ suggested: "Sugerido",
19
20
  errors: {
20
21
  required: "Completa este campo.",
21
22
  taxIdFormat: "Revisa el formato: {kind} no v\xE1lido.",
@@ -48,14 +49,34 @@ var ES = {
48
49
  qrMismatch: "El c\xF3digo QR de tu documento no coincide con los datos le\xEDdos. Revisa con calma tu RFC y tu nombre.",
49
50
  stale: "Tu documento tiene {days} d\xEDas de emitido. Si algo cambi\xF3 en tu registro, descarga uno nuevo.",
50
51
  regimeMissing: "No pudimos detectar tu r\xE9gimen. El\xEDgelo de la lista.",
51
- fieldsMissing: "No encontramos algunos datos en el documento. Compl\xE9talos para continuar."
52
+ fieldsMissing: "No encontramos algunos datos en el documento. Compl\xE9talos para continuar.",
53
+ qrPartial: "Del c\xF3digo QR solo le\xEDmos tu identificador fiscal. Completa los dem\xE1s datos o sube el PDF."
54
+ },
55
+ scan: {
56
+ title: "Escanea tu {document}",
57
+ photo: "Tomar foto del QR",
58
+ photoHint: "Enfoca el c\xF3digo QR de tu documento.",
59
+ camera: "Escanear con la c\xE1mara",
60
+ cameraTitle: "Apunta al c\xF3digo QR",
61
+ cameraGuide: "Centra el c\xF3digo QR dentro del marco.",
62
+ cameraStarting: "Abriendo la c\xE1mara\u2026",
63
+ cameraRead: "C\xF3digo le\xEDdo",
64
+ cameraDenied: "No pudimos usar la c\xE1mara. Elige una foto o sube el PDF.",
65
+ cameraUnavailable: "Este dispositivo no permite usar la c\xE1mara aqu\xED. Elige una foto o sube el PDF.",
66
+ closeCamera: "Cerrar la c\xE1mara",
67
+ choosePhoto: "Elegir una foto",
68
+ open: "Escanear {document}",
69
+ manual: "Capturar a mano",
70
+ close: "Cerrar"
52
71
  },
53
72
  errors: {
54
73
  not_pdf: "Ese archivo no es un PDF. Sube el PDF que descargaste o captura tus datos a mano.",
55
74
  too_large: "El archivo pesa m\xE1s de {size}. Sube el PDF original o captura tus datos a mano.",
56
75
  no_text: "Este PDF parece una imagen escaneada y no podemos leerlo. Captura tus datos a mano.",
57
76
  password: "Este PDF tiene contrase\xF1a y no podemos abrirlo. Desc\xE1rgalo de nuevo sin contrase\xF1a o captura tus datos a mano.",
58
- unreadable: "No pudimos leer este archivo. Int\xE9ntalo con otro o captura tus datos a mano."
77
+ unreadable: "No pudimos leer este archivo. Int\xE9ntalo con otro o captura tus datos a mano.",
78
+ no_qr: "No encontramos el c\xF3digo QR en la foto. Ac\xE9rcate, evita reflejos o sube el PDF.",
79
+ not_image: "Ese archivo no es una foto que podamos leer. Toma otra foto o sube el PDF."
59
80
  },
60
81
  summaryTitleOne: "Revisa 1 campo para continuar",
61
82
  summaryTitleMany: "Revisa {n} campos para continuar"
@@ -135,6 +156,7 @@ var EN = {
135
156
  useHint: "We only list the uses your regime admits.",
136
157
  useChoose: "Choose the use",
137
158
  fromDocument: "From your {document}",
159
+ suggested: "Suggested",
138
160
  errors: {
139
161
  required: "Fill in this field.",
140
162
  taxIdFormat: "Check the format: not a valid {kind}.",
@@ -167,14 +189,34 @@ var EN = {
167
189
  qrMismatch: "The QR code of your document does not match what we read. Check your tax ID and name carefully.",
168
190
  stale: "Your document was issued {days} days ago. If something changed in your registration, download a new one.",
169
191
  regimeMissing: "We could not detect your regime. Choose it from the list.",
170
- fieldsMissing: "We did not find some details in the document. Fill them in to continue."
192
+ fieldsMissing: "We did not find some details in the document. Fill them in to continue.",
193
+ qrPartial: "The QR code only gave us your tax ID. Fill in the rest or upload the PDF."
194
+ },
195
+ scan: {
196
+ title: "Scan your {document}",
197
+ photo: "Take a photo of the QR",
198
+ photoHint: "Point at the QR code of your document.",
199
+ camera: "Scan with the camera",
200
+ cameraTitle: "Point at the QR code",
201
+ cameraGuide: "Center the QR code inside the frame.",
202
+ cameraStarting: "Opening the camera\u2026",
203
+ cameraRead: "Code read",
204
+ cameraDenied: "We could not use the camera. Choose a photo or upload the PDF.",
205
+ cameraUnavailable: "This device does not allow the camera here. Choose a photo or upload the PDF.",
206
+ closeCamera: "Close the camera",
207
+ choosePhoto: "Choose a photo",
208
+ open: "Scan {document}",
209
+ manual: "Enter by hand",
210
+ close: "Close"
171
211
  },
172
212
  errors: {
173
213
  not_pdf: "That file is not a PDF. Upload the PDF you downloaded or enter your details by hand.",
174
214
  too_large: "The file is larger than {size}. Upload the original PDF or enter your details by hand.",
175
215
  no_text: "This PDF looks like a scanned image and we cannot read it. Enter your details by hand.",
176
216
  password: "This PDF is password protected and we cannot open it. Download it again without a password or enter your details by hand.",
177
- unreadable: "We could not read this file. Try another one or enter your details by hand."
217
+ unreadable: "We could not read this file. Try another one or enter your details by hand.",
218
+ no_qr: "We could not find the QR code in the photo. Move closer, avoid glare or upload the PDF.",
219
+ not_image: "That file is not a photo we can read. Take another photo or upload the PDF."
178
220
  },
179
221
  summaryTitleOne: "Check 1 field to continue",
180
222
  summaryTitleMany: "Check {n} fields to continue"
@@ -256,5 +298,5 @@ function fill(template, vars) {
256
298
  }
257
299
 
258
300
  export { fill, fiscalMessages };
259
- //# sourceMappingURL=chunk-PPQEUTXJ.js.map
260
- //# sourceMappingURL=chunk-PPQEUTXJ.js.map
301
+ //# sourceMappingURL=chunk-VE7WQPMY.js.map
302
+ //# sourceMappingURL=chunk-VE7WQPMY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fiscal/messages.ts"],"names":[],"mappings":";AA8HA,IAAM,EAAA,GAAqB;AAAA,EACzB,MAAA,EAAQ;AAAA,IACN,MAAA,EAAQ,gBAAA;AAAA,IACR,KAAA,EAAO,KAAA;AAAA,IACP,SAAA,EAAW,6CAAA;AAAA,IACX,SAAA,EAAW,0BAAA;AAAA,IACX,aAAA,EAAe,sDAAA;AAAA,IACf,UAAA,EAAY,yBAAA;AAAA,IACZ,cAAA,EAAgB,kEAAA;AAAA,IAChB,MAAA,EAAQ,mBAAA;AAAA,IACR,UAAA,EAAY,sDAAA;AAAA,IACZ,YAAA,EAAc,qBAAA;AAAA,IACd,kBAAA,EAAoB,0FAAA;AAAA,IACpB,GAAA,EAAK,mBAAA;AAAA,IACL,OAAA,EAAS,mDAAA;AAAA,IACT,SAAA,EAAW,cAAA;AAAA,IACX,YAAA,EAAc,kBAAA;AAAA,IACd,SAAA,EAAW,UAAA;AAAA,IACX,MAAA,EAAQ;AAAA,MACN,QAAA,EAAU,sBAAA;AAAA,MACV,WAAA,EAAa,yCAAA;AAAA,MACb,YAAA,EAAc,+DAAA;AAAA,MACd,OAAA,EAAS,kCAAA;AAAA,MACT,UAAA,EAAY,sDAAA;AAAA,MACZ,aAAA,EAAe;AAAA;AACjB,GACF;AAAA,EACA,MAAA,EAAQ;AAAA,IACN,KAAA,EAAO,oBAAA;AAA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A,KAAA,MAAW,CAAC,CAAA,EAAG,CAAC,KAAK,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AACzC,IAAA,IAAI,MAAM,MAAA,EAAW;AACrB,IAAA,MAAM,CAAA,GAAI,KAAK,CAAC,CAAA;AAChB,IAAA,GAAA,CAAI,CAAC,IAAI,OAAO,CAAA,KAAM,YAAY,CAAA,KAAM,IAAA,IAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,IAAK,OAAO,MAAM,QAAA,IAAY,CAAA,KAAM,OAAO,KAAA,CAAM,CAAA,EAA8B,CAAyC,CAAA,GAAI,CAAA;AAAA,EAC9L;AACA,EAAA,OAAO,GAAA;AACT,CAAA;AAGO,SAAS,cAAA,CAAe,QAAwB,SAAA,EAAgE;AACrH,EAAA,MAAM,IAAA,GAAA,CAAQ,UAAU,OAAA,EAAS,WAAA,GAAc,UAAA,CAAW,IAAI,IAAI,EAAA,GAAK,EAAA;AACvE,EAAA,OAAO,SAAA,GAAY,KAAA,CAAM,IAAA,EAAM,SAAS,CAAA,GAAI,IAAA;AAC9C;AAGO,SAAS,IAAA,CAAK,UAAkB,IAAA,EAA+C;AACpF,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,YAAA,EAAc,CAAC,CAAA,EAAG,CAAA,KAAe,CAAA,IAAK,IAAA,GAAO,MAAA,CAAO,IAAA,CAAK,CAAC,CAAC,IAAI,CAAE,CAAA;AAC3F","file":"chunk-VE7WQPMY.js","sourcesContent":["/** Texts of the fiscal components. Spanish (es-MX) by default, English with `en*`, any locale with `messages`. */\nimport type { FiscalReadError } from './types.js'\n\nexport type DeepPartial<T> = { [K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K] }\n\nexport type FiscalMessages = {\n fields: {\n legend: string\n taxId: string\n taxIdHint: string\n legalName: string\n /** Used when the region publishes no help for the legal name. */\n legalNameHint: string\n postalCode: string\n postalCodeHint: string\n regime: string\n regimeHint: string\n regimeChoose: string\n regimeFromDocument: string\n use: string\n useHint: string\n useChoose: string\n /** `{document}` = the document's name. */\n fromDocument: string\n /** Mark on an invoice use the region suggested (an editable preselection). */\n suggested: string\n errors: {\n required: string\n taxIdFormat: string\n postalFormat: string\n unknown: string\n personType: string\n useNotAllowed: string\n }\n }\n reader: {\n /** `{document}`. */\n title: string\n dropHint: string\n dropActive: string\n choose: string\n obtain: string\n privacyBrowser: string\n privacyServer: string\n uploadServer: string\n manual: string\n reading: string\n cancel: string\n done: string\n reviewTitle: string\n reviewHint: string\n confirm: string\n changeFile: string\n saveToAccount: string\n saveConsent: string\n warnings: { qrMismatch: string; stale: string; regimeMissing: string; fieldsMissing: string; qrPartial: string }\n /** Reading a photo or the camera (the region's `image_mode`). `{document}` where noted. */\n scan: {\n title: string\n photo: string\n photoHint: string\n camera: string\n cameraTitle: string\n cameraGuide: string\n cameraStarting: string\n cameraRead: string\n cameraDenied: string\n cameraUnavailable: string\n closeCamera: string\n choosePhoto: string\n /** Button that opens the sheet; `{document}` is the document's label. */\n open: string\n manual: string\n close: string\n }\n errors: Record<FiscalReadError, string>\n summaryTitleOne: string\n summaryTitleMany: string\n }\n toggle: {\n label: string\n payDefault: string\n payAndInvoice: string\n profileTitle: string\n change: string\n useOther: string\n useSaved: string\n manualTitle: string\n unavailable: string\n privacy: string\n fieldsOf: { taxId: string; legalName: string; postalCode: string; regime: string; use: string }\n }\n status: {\n title: string\n request: string\n requestHelp: string\n awaitingTitle: string\n awaitingBody: string\n processingTitle: string\n processingBody: string\n processingSlow: string\n refresh: string\n issuedTitle: string\n issuedBody: string\n folio: string\n pdf: string\n xml: string\n needsDataTitle: string\n needsDataBody: string\n correct: string\n reviewTitle: string\n reviewBody: string\n contact: string\n contactBy: string\n windowTitle: string\n windowBody: string\n unavailableTitle: string\n unavailableBody: string\n cancelledTitle: string\n cancelledBody: string\n /** `reason_code` -> cause for the buyer. `default` when unknown. */\n reasons: Record<string, string>\n }\n server: { errors: Record<string, string> }\n}\n\nconst ES: FiscalMessages = {\n fields: {\n legend: 'Datos fiscales',\n taxId: 'RFC',\n taxIdHint: 'Se escribe en mayúsculas y sin espacios.',\n legalName: 'Nombre o razón social',\n legalNameHint: 'Escríbelo tal como aparece en tu registro fiscal.',\n postalCode: 'Código postal fiscal',\n postalCodeHint: 'El de tu domicilio fiscal, que puede ser distinto al de entrega.',\n regime: 'Régimen fiscal',\n regimeHint: 'Solo mostramos los que aplican a tu tipo de persona.',\n regimeChoose: 'Elige tu régimen',\n regimeFromDocument: 'Tu documento menciona más de un régimen. Elige el que usarás para esta factura.',\n use: 'Uso de la factura',\n useHint: 'Solo mostramos los usos que admite tu régimen.',\n useChoose: 'Elige el uso',\n fromDocument: 'De tu {document}',\n suggested: 'Sugerido',\n errors: {\n required: 'Completa este campo.',\n taxIdFormat: 'Revisa el formato: {kind} no válido.',\n postalFormat: 'Escribe un código postal válido, por ejemplo {example}.',\n unknown: 'Elige una opción de la lista.',\n personType: 'Este régimen no corresponde a tu tipo de persona.',\n useNotAllowed: 'Este uso no está disponible con el régimen elegido.',\n },\n },\n reader: {\n title: 'Sube tu {document}',\n dropHint: 'Arrastra el PDF aquí o toca para elegirlo',\n dropActive: 'Suelta el archivo para leerlo',\n choose: 'Elegir archivo',\n obtain: 'Descárgala aquí',\n privacyBrowser: 'La leemos en tu dispositivo. No guardamos el archivo, solo los datos que confirmes.',\n privacyServer: 'La procesamos y la descartamos al terminar. Solo guardamos los datos que confirmes.',\n uploadServer: 'Leer mi archivo',\n manual: 'Captura tus datos a mano',\n reading: 'Leyendo tu {document}…',\n cancel: 'Cancelar',\n done: 'Listo. Revisa tus datos.',\n reviewTitle: 'Revisa tus datos',\n reviewHint: 'Puedes corregir cualquier campo antes de continuar.',\n confirm: 'Usar estos datos',\n changeFile: 'Subir otro archivo',\n saveToAccount: 'Guardar en mi cuenta para la próxima',\n saveConsent: 'Guardaremos estos datos en tu cuenta para facturar más rápido. Puedes borrarlos cuando quieras.',\n warnings: {\n qrMismatch: 'El código QR de tu documento no coincide con los datos leídos. Revisa con calma tu RFC y tu nombre.',\n stale: 'Tu documento tiene {days} días de emitido. Si algo cambió en tu registro, descarga uno nuevo.',\n regimeMissing: 'No pudimos detectar tu régimen. Elígelo de la lista.',\n fieldsMissing: 'No encontramos algunos datos en el documento. Complétalos para continuar.',\n qrPartial: 'Del código QR solo leímos tu identificador fiscal. Completa los demás datos o sube el PDF.',\n },\n scan: {\n title: 'Escanea tu {document}',\n photo: 'Tomar foto del QR',\n photoHint: 'Enfoca el código QR de tu documento.',\n camera: 'Escanear con la cámara',\n cameraTitle: 'Apunta al código QR',\n cameraGuide: 'Centra el código QR dentro del marco.',\n cameraStarting: 'Abriendo la cámara…',\n cameraRead: 'Código leído',\n cameraDenied: 'No pudimos usar la cámara. Elige una foto o sube el PDF.',\n cameraUnavailable: 'Este dispositivo no permite usar la cámara aquí. Elige una foto o sube el PDF.',\n closeCamera: 'Cerrar la cámara',\n choosePhoto: 'Elegir una foto',\n open: 'Escanear {document}',\n manual: 'Capturar a mano',\n close: 'Cerrar',\n },\n errors: {\n not_pdf: 'Ese archivo no es un PDF. Sube el PDF que descargaste o captura tus datos a mano.',\n too_large: 'El archivo pesa más de {size}. Sube el PDF original o captura tus datos a mano.',\n no_text: 'Este PDF parece una imagen escaneada y no podemos leerlo. Captura tus datos a mano.',\n password: 'Este PDF tiene contraseña y no podemos abrirlo. Descárgalo de nuevo sin contraseña o captura tus datos a mano.',\n unreadable: 'No pudimos leer este archivo. Inténtalo con otro o captura tus datos a mano.',\n no_qr: 'No encontramos el código QR en la foto. Acércate, evita reflejos o sube el PDF.',\n not_image: 'Ese archivo no es una foto que podamos leer. Toma otra foto o sube el PDF.',\n },\n summaryTitleOne: 'Revisa 1 campo para continuar',\n summaryTitleMany: 'Revisa {n} campos para continuar',\n },\n toggle: {\n label: 'Necesito factura (CFDI)',\n payDefault: 'Pagar',\n payAndInvoice: 'Pagar y facturar',\n profileTitle: 'Facturaremos con estos datos',\n change: 'Cambiar',\n useOther: 'Usar otros datos',\n useSaved: 'Usar mis datos guardados',\n manualTitle: 'Datos de facturación',\n unavailable: 'Esta tienda todavía no factura en línea.',\n privacy: 'Usamos estos datos solo para emitir tu factura.',\n fieldsOf: { taxId: 'RFC', legalName: 'Nombre o razón social', postalCode: 'Código postal fiscal', regime: 'Régimen', use: 'Uso' },\n },\n status: {\n title: 'Factura',\n request: 'Solicitar factura',\n requestHelp: '¿Necesitas factura de este pedido?',\n awaitingTitle: 'Esperando tu pago',\n awaitingBody: 'Cuando se acredite tu pago emitimos la factura. Con OXXO o transferencia puede tardar un poco.',\n processingTitle: 'Estamos generando tu factura',\n processingBody: 'Suele tardar menos de un minuto. Esta página se actualiza sola.',\n processingSlow: 'Sigue en proceso. Puedes cerrar esta página: tu factura aparecerá aquí cuando esté lista.',\n refresh: 'Actualizar',\n issuedTitle: 'Tu factura está lista',\n issuedBody: 'Descárgala cuando la necesites. Los enlaces vencen en 15 minutos; vuelve a abrir esta página para generar nuevos.',\n folio: 'Folio fiscal',\n pdf: 'Descargar PDF',\n xml: 'Descargar XML',\n needsDataTitle: 'Faltan datos para tu factura',\n needsDataBody: 'No pudimos emitirla con los datos que nos diste.',\n correct: 'Corregir y reintentar',\n reviewTitle: 'La tienda está revisando tu factura',\n reviewBody: 'Necesita una revisión del negocio. No tienes que hacer nada más; si tarda, escríbenos.',\n contact: 'Contactar a la tienda',\n contactBy: 'Escríbenos a {contact} con tu número de pedido.',\n windowTitle: 'Ya pasó el plazo para facturar',\n windowBody: 'Este pedido está fuera del plazo para pedir factura. Si necesitas ayuda, contacta a la tienda.',\n unavailableTitle: 'Factura no disponible',\n unavailableBody: 'Esta tienda no emite factura de este pedido. Si la necesitas, contáctala.',\n cancelledTitle: 'Factura cancelada',\n cancelledBody: 'Esta factura fue cancelada. Si necesitas una nueva, contacta a la tienda.',\n reasons: {\n 'invoice.tax_id': 'El RFC no es válido.',\n 'invoice.legal_name': 'El nombre o la razón social no coincide con tu registro.',\n 'invoice.tax_regime': 'El régimen fiscal no es válido para tus datos.',\n 'invoice.postal_code': 'El código postal fiscal no es válido.',\n 'invoice.use': 'El uso de la factura no es válido con tu régimen.',\n default: 'Revisa tus datos fiscales y vuelve a intentarlo.',\n },\n },\n server: {\n errors: {\n validation: 'Revisa este campo.',\n required: 'Completa este campo.',\n invalid: 'El valor no es válido.',\n },\n },\n}\n\nconst EN: FiscalMessages = {\n fields: {\n legend: 'Tax details',\n taxId: 'Tax ID',\n taxIdHint: 'Uppercase, without spaces.',\n legalName: 'Legal name',\n legalNameHint: 'Write it as it appears in your tax registration.',\n postalCode: 'Tax postal code',\n postalCodeHint: 'The one of your tax address, which can differ from the delivery address.',\n regime: 'Tax regime',\n regimeHint: 'We only list the ones that apply to your kind of taxpayer.',\n regimeChoose: 'Choose your regime',\n regimeFromDocument: 'Your document lists more than one regime. Choose the one for this invoice.',\n use: 'Invoice use',\n useHint: 'We only list the uses your regime admits.',\n useChoose: 'Choose the use',\n fromDocument: 'From your {document}',\n suggested: 'Suggested',\n errors: {\n required: 'Fill in this field.',\n taxIdFormat: 'Check the format: not a valid {kind}.',\n postalFormat: 'Enter a valid postal code, like {example}.',\n unknown: 'Choose an option from the list.',\n personType: 'This regime does not match your kind of taxpayer.',\n useNotAllowed: 'This use is not available with the chosen regime.',\n },\n },\n reader: {\n title: 'Upload your {document}',\n dropHint: 'Drag the PDF here or tap to choose it',\n dropActive: 'Drop the file to read it',\n choose: 'Choose file',\n obtain: 'Get it here',\n privacyBrowser: 'We read it on your device. We do not keep the file, only the details you confirm.',\n privacyServer: 'We process it and discard it when done. We only keep the details you confirm.',\n uploadServer: 'Read my file',\n manual: 'Enter your details by hand',\n reading: 'Reading your {document}…',\n cancel: 'Cancel',\n done: 'Done. Review your details.',\n reviewTitle: 'Review your details',\n reviewHint: 'You can fix any field before continuing.',\n confirm: 'Use these details',\n changeFile: 'Upload another file',\n saveToAccount: 'Save to my account for next time',\n saveConsent: 'We will save these details to your account to invoice faster. You can delete them any time.',\n warnings: {\n qrMismatch: 'The QR code of your document does not match what we read. Check your tax ID and name carefully.',\n stale: 'Your document was issued {days} days ago. If something changed in your registration, download a new one.',\n regimeMissing: 'We could not detect your regime. Choose it from the list.',\n fieldsMissing: 'We did not find some details in the document. Fill them in to continue.',\n qrPartial: 'The QR code only gave us your tax ID. Fill in the rest or upload the PDF.',\n },\n scan: {\n title: 'Scan your {document}',\n photo: 'Take a photo of the QR',\n photoHint: 'Point at the QR code of your document.',\n camera: 'Scan with the camera',\n cameraTitle: 'Point at the QR code',\n cameraGuide: 'Center the QR code inside the frame.',\n cameraStarting: 'Opening the camera…',\n cameraRead: 'Code read',\n cameraDenied: 'We could not use the camera. Choose a photo or upload the PDF.',\n cameraUnavailable: 'This device does not allow the camera here. Choose a photo or upload the PDF.',\n closeCamera: 'Close the camera',\n choosePhoto: 'Choose a photo',\n open: 'Scan {document}',\n manual: 'Enter by hand',\n close: 'Close',\n },\n errors: {\n not_pdf: 'That file is not a PDF. Upload the PDF you downloaded or enter your details by hand.',\n too_large: 'The file is larger than {size}. Upload the original PDF or enter your details by hand.',\n no_text: 'This PDF looks like a scanned image and we cannot read it. Enter your details by hand.',\n password: 'This PDF is password protected and we cannot open it. Download it again without a password or enter your details by hand.',\n unreadable: 'We could not read this file. Try another one or enter your details by hand.',\n no_qr: 'We could not find the QR code in the photo. Move closer, avoid glare or upload the PDF.',\n not_image: 'That file is not a photo we can read. Take another photo or upload the PDF.',\n },\n summaryTitleOne: 'Check 1 field to continue',\n summaryTitleMany: 'Check {n} fields to continue',\n },\n toggle: {\n label: 'I need an invoice',\n payDefault: 'Pay',\n payAndInvoice: 'Pay and invoice',\n profileTitle: 'We will invoice with these details',\n change: 'Change',\n useOther: 'Use other details',\n useSaved: 'Use my saved details',\n manualTitle: 'Invoice details',\n unavailable: 'This store does not invoice online yet.',\n privacy: 'We only use these details to issue your invoice.',\n fieldsOf: { taxId: 'Tax ID', legalName: 'Legal name', postalCode: 'Tax postal code', regime: 'Regime', use: 'Use' },\n },\n status: {\n title: 'Invoice',\n request: 'Request invoice',\n requestHelp: 'Do you need an invoice for this order?',\n awaitingTitle: 'Waiting for your payment',\n awaitingBody: 'We issue the invoice once your payment clears. Cash and bank transfers can take a while.',\n processingTitle: 'We are generating your invoice',\n processingBody: 'It usually takes under a minute. This page updates by itself.',\n processingSlow: 'Still in progress. You can close this page: your invoice will show up here when it is ready.',\n refresh: 'Refresh',\n issuedTitle: 'Your invoice is ready',\n issuedBody: 'Download it whenever you need. The links expire in 15 minutes; reopen this page for new ones.',\n folio: 'Tax folio',\n pdf: 'Download PDF',\n xml: 'Download XML',\n needsDataTitle: 'Your invoice needs more details',\n needsDataBody: 'We could not issue it with the details you gave us.',\n correct: 'Fix and retry',\n reviewTitle: 'The store is reviewing your invoice',\n reviewBody: 'It needs a review by the business. You do not need to do anything else; if it takes long, write to us.',\n contact: 'Contact the store',\n contactBy: 'Write to {contact} with your order number.',\n windowTitle: 'The invoicing period has ended',\n windowBody: 'This order is outside the period to request an invoice. If you need help, contact the store.',\n unavailableTitle: 'Invoice not available',\n unavailableBody: 'This store does not issue an invoice for this order. If you need one, contact them.',\n cancelledTitle: 'Invoice cancelled',\n cancelledBody: 'This invoice was cancelled. If you need a new one, contact the store.',\n reasons: {\n 'invoice.tax_id': 'The tax ID is not valid.',\n 'invoice.legal_name': 'The legal name does not match your registration.',\n 'invoice.tax_regime': 'The tax regime is not valid for your details.',\n 'invoice.postal_code': 'The tax postal code is not valid.',\n 'invoice.use': 'The invoice use is not valid with your regime.',\n default: 'Check your tax details and try again.',\n },\n },\n server: {\n errors: {\n validation: 'Check this field.',\n required: 'Fill in this field.',\n invalid: 'The value is not valid.',\n },\n },\n}\n\nconst merge = <T extends Record<string, unknown>>(base: T, over: DeepPartial<T> | undefined): T => {\n if (!over) return base\n const out: Record<string, unknown> = { ...base }\n for (const [k, v] of Object.entries(over)) {\n if (v === undefined) continue\n const b = base[k]\n out[k] = typeof v === 'object' && v !== null && !Array.isArray(v) && typeof b === 'object' && b !== null ? merge(b as Record<string, unknown>, v as DeepPartial<Record<string, unknown>>) : v\n }\n return out as T\n}\n\n/** Messages for a locale (`es*` default, `en*`), with optional overrides (merged level by level). */\nexport function fiscalMessages(locale?: string | null, overrides?: DeepPartial<FiscalMessages> | null): FiscalMessages {\n const base = (locale ?? 'es-MX').toLowerCase().startsWith('en') ? EN : ES\n return overrides ? merge(base, overrides) : base\n}\n\n/** `{name}` placeholders. */\nexport function fill(template: string, vars: Record<string, string | number>): string {\n return template.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m))\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/fiscal/format.ts","../src/fiscal/extraction.ts","../src/fiscal/server-extract.ts","../src/fiscal/server.ts"],"names":["IdentityDocumentError","readPdfText","extractIdentityDocument","catalogsFromRegion","buildDocumentEvidence","repairPath","isStorefrontError"],"mappings":";;;;;;;;AAUO,SAAS,eAAe,GAAA,EAAqB;AAClD,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,UAAA,EAAY,EAAE,EAAE,WAAA,EAAY;AACjD;;;ACNA,IAAM,KAAA,GAAQ,CAAC,CAAA,KAA8C,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,GAAK,CAAA,CAAE,CAAC,CAAA,IAAK,EAAA,GAAO,CAAA,IAAK,EAAA;AAG9F,SAAS,mBAAA,CAAoB,CAAA,EAAuB,QAAA,EAAkC,YAAA,EAA0D;AACrJ,EAAA,MAAM,IAAI,CAAA,CAAE,MAAA;AACZ,EAAA,MAAM,KAAA,GAAQ,YAAA,GAAe,IAAI,GAAA,CAAI,YAAY,CAAA,GAAI,IAAA;AACrD,EAAA,MAAM,MAAM,CAAA,CAAE,UAAA;AACd,EAAA,MAAM,UAAA,GAAA,CAAc,MAAM,OAAA,CAAQ,GAAG,IAAI,GAAA,GAAM,GAAA,GAAM,CAAC,GAAG,CAAA,GAAI,EAAC,EAAG,MAAA,CAAO,CAAC,CA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AM,MAAA,EAAQ,IAAA,EAAM,UAAU,UAAA,EAAW;AAAA,UACxD,SAAS,GAAA,EAAK;AACZ,YAAA,MAAM,OAAQ,GAAA,EAAkC,IAAA;AAChD,YAAA,MAAM,QAA2B,CAAC,SAAA,EAAW,WAAA,EAAa,SAAA,EAAW,YAAY,YAAY,CAAA;AAE7F,YAAA,OAAO,KAAK,MAAA,EAAQ,KAAA,CAAM,SAAS,IAAuB,CAAA,GAAK,OAA2B,YAAY,CAAA;AAAA,UACxG;AAAA,QACF;AAAA,QACA;AACE,UAAA,OAAO,IAAA,CAAK,QAAW,YAAY,CAAA;AAAA;AACvC,IACF,SAAS,GAAA,EAAK;AACZ,MAAA,OAAO,UAAU,GAAA,EAAK,MAAA,EAAQ,QAAQ,MAAA,KAAW,eAAA,GAAkB,SAAY,IAAI,CAAA;AAAA,IACrF;AAAA,EACF,CAAA;AACF","file":"fiscal-server.cjs","sourcesContent":["/**\n * Pure helpers over the region's fiscal catalog (`Region.fiscal_id`). They know no country: the tax id format, the\n * regimes, the invoice uses and the postal code format are all data.\n */\nimport type { InvoiceRequest, Region, RegionFiscalEntry, RegionFiscalId } from '@asteby/storefront'\nimport type { FiscalFieldName, FiscalFieldValues } from './types.js'\n\nexport type FiscalRegion = Pick<Region, 'address'> & { fiscal_id?: RegionFiscalId }\n\n/** Uppercase, no spaces, hyphens or dots: how a tax id is compared and sent. */\nexport function normalizeTaxId(raw: string): string {\n return raw.replace(/[\\s\\-.]/g, '').toUpperCase()\n}\n\n/** Masks a tax id for display and logs: first 2 and last 3 characters stay (`PE********ABC`). */\nexport function maskTaxId(taxId: string): string {\n const v = taxId.trim()\n return v.length <= 5 ? '*'.repeat(v.length) : `${v.slice(0, 2)}${'*'.repeat(v.length - 5)}${v.slice(-3)}`\n}\n\nconst compile = (pattern: string | undefined): RegExp | null => {\n if (!pattern) return null\n try {\n return new RegExp(pattern)\n } catch {\n return null\n }\n}\n\n/** `null` when the tax id is valid for the region (its pattern or one of its generic ids); otherwise why not. */\nexport function taxIdProblem(fid: RegionFiscalId | undefined, raw: string): 'required' | 'format' | null {\n const v = normalizeTaxId(raw)\n if (!v) return 'required'\n if (!fid) return null\n if (fid.generic_ids.includes(v)) return null\n const re = compile(fid.pattern)\n return re && !re.test(v) ? 'format' : null\n}\n\nexport function postalCodeProblem(region: FiscalRegion, raw: string): 'required' | 'format' | null {\n const v = raw.trim()\n if (!v) return 'required'\n const re = compile(region.address?.postal_code?.pattern)\n return re && !re.test(v) ? 'format' : null\n}\n\n/**\n * Builds the function that tells a person type from a tax id when the region does not publish one. Pass the length\n * of the tax id per type, e.g. `personTypeByLength({ individual: 13, company: 12 })`. Without a function the regimes\n * are not narrowed by person type (the server still checks the combination).\n */\nexport function personTypeByLength(lengths: Record<string, number>): (taxId: string) => string | null {\n return (taxId) => {\n const n = normalizeTaxId(taxId).length\n return Object.keys(lengths).find((t) => lengths[t] === n) ?? null\n }\n}\n\n/** Regimes that fit a person type (all when the type is unknown). */\nexport function regimesFor(fid: RegionFiscalId | undefined, personType: string | null): RegionFiscalEntry[] {\n const all = fid?.regimes ?? []\n if (!personType) return all\n return all.filter((r) => r.person_types.length === 0 || r.person_types.includes(personType))\n}\n\n/** Invoice uses a regime admits (all when no regime is chosen yet). */\nexport function usesFor(fid: RegionFiscalId | undefined, regime: string | null | undefined): RegionFiscalEntry[] {\n const all = fid?.invoice_uses ?? []\n if (!regime) return all\n return all.filter((u) => !u.allowed_regimes || u.allowed_regimes.length === 0 || u.allowed_regimes.includes(regime))\n}\n\nexport type FiscalProblem = 'required' | 'format' | 'unknown' | 'person_type' | 'use_not_allowed'\n\n/** Client-side check of the whole form against the region; the server stays the authority. */\nexport function validateFiscalValues(\n region: FiscalRegion,\n v: Partial<FiscalFieldValues>,\n personTypeOf?: (taxId: string) => string | null,\n): Partial<Record<FiscalFieldName, FiscalProblem>> {\n const fid = region.fiscal_id\n const out: Partial<Record<FiscalFieldName, FiscalProblem>> = {}\n const tax = taxIdProblem(fid, v.tax_id ?? '')\n if (tax) out.tax_id = tax\n if (!(v.legal_name ?? '').trim()) out.legal_name = 'required'\n if (postalCodeProblem(region, v.postal_code ?? '')) out.postal_code = postalCodeProblem(region, v.postal_code ?? '')!\n const regime = v.tax_regime ?? ''\n if (!regime) out.tax_regime = 'required'\n else if (fid) {\n const entry = fid.regimes.find((r) => r.code === regime)\n if (!entry) out.tax_regime = 'unknown'\n else if (!tax && !fid.generic_ids.includes(normalizeTaxId(v.tax_id ?? ''))) {\n const person = personTypeOf?.(v.tax_id ?? '') ?? null\n if (person && entry.person_types.length > 0 && !entry.person_types.includes(person)) out.tax_regime = 'person_type'\n }\n }\n const use = v.use ?? ''\n if (!use) out.use = 'required'\n else if (fid) {\n const entry = fid.invoice_uses.find((u) => u.code === use)\n if (!entry) out.use = 'unknown'\n else if (regime && entry.allowed_regimes && entry.allowed_regimes.length > 0 && !entry.allowed_regimes.includes(regime)) out.use = 'use_not_allowed'\n }\n return out\n}\n\n/** Form values -> the API's `InvoiceRequest` (without `document`). */\nexport function toInvoiceRequest(v: Partial<FiscalFieldValues>, countryCode?: string): InvoiceRequest {\n return {\n requested: true,\n tax_id: normalizeTaxId(v.tax_id ?? ''),\n legal_name: (v.legal_name ?? '').trim(),\n tax_regime: v.tax_regime ?? '',\n use: v.use ?? '',\n postal_code: (v.postal_code ?? '').trim(),\n ...(countryCode ? { country_code: countryCode } : {}),\n }\n}\n\n/** `label_en` for English locales when the region has it. */\nexport function entryLabel(e: RegionFiscalEntry, locale?: string | null): string {\n return (locale ?? 'es-MX').toLowerCase().startsWith('en') && e.label_en ? e.label_en : e.label\n}\n","/** Turns what the engine read into what the UI shows. Shared by the browser reader and the server upload. */\nimport type { FiscalDocumentEvidence } from '@asteby/storefront'\nimport type { IdentityExtraction } from '@asteby/storefront/fiscal-document'\nimport { normalizeTaxId } from './format.js'\nimport type { FiscalExtractionSummary, FiscalFieldName } from './types.js'\n\nconst first = (v: string | string[] | undefined): string => (Array.isArray(v) ? (v[0] ?? '') : (v ?? ''))\n\n/** `evidence` comes from `buildDocumentEvidence`. Only the conventional fields are kept: nothing else can leak. */\nexport function summarizeExtraction(x: IdentityExtraction, evidence: FiscalDocumentEvidence, validRegimes?: Iterable<string>): FiscalExtractionSummary {\n const f = x.fields\n const valid = validRegimes ? new Set(validRegimes) : null\n const raw = f.tax_regime\n const candidates = (Array.isArray(raw) ? raw : raw ? [raw] : []).filter((c) => !valid || valid.has(c))\n const values: FiscalExtractionSummary['values'] = {}\n const from: FiscalFieldName[] = []\n const put = (name: FiscalFieldName, v: string) => {\n if (!v) return\n values[name] = v\n from.push(name)\n }\n put('tax_id', normalizeTaxId(first(f.tax_id)))\n put('legal_name', first(f.legal_name).trim())\n put('postal_code', first(f.postal_code).trim())\n if (candidates.length === 1) put('tax_regime', candidates[0]!)\n else if (candidates.length > 1) from.push('tax_regime')\n return {\n kind: x.kind,\n values,\n regime_candidates: candidates,\n from_document: from,\n qr_match: x.qr.match,\n stale: x.stale,\n age_days: x.age_days,\n missing: [...x.missing],\n evidence,\n }\n}\n","/**\n * Reads a tax document uploaded without JavaScript, on the server, with the same engine the browser uses. In memory\n * only: the bytes are never written to disk, never logged and are dropped when this returns.\n */\nimport type { IdentityDocumentSpec, Region } from '@asteby/storefront'\nimport { IdentityDocumentError, buildDocumentEvidence, catalogsFromRegion, extractIdentityDocument, readPdfText } from '@asteby/storefront/fiscal-document'\nimport { summarizeExtraction } from './extraction.js'\nimport type { FiscalExtractionSummary } from './types.js'\n\nexport type UploadLimits = { maxBytes: number; maxPages: number; timeoutMs: number }\n\n/** 5 MiB, 6 pages, 3 s: the same as the browser reader. */\nexport const UPLOAD_LIMITS: Readonly<UploadLimits> = Object.freeze({ maxBytes: 5 * 1024 * 1024, maxPages: 6, timeoutMs: 3000 })\n\nconst PDF_MAGIC = [0x25, 0x50, 0x44, 0x46, 0x2d] // %PDF-\n\nexport async function extractUploadedDocument(\n file: Blob,\n spec: IdentityDocumentSpec,\n region: Pick<Region, 'fiscal_id'>,\n options: { limits?: Partial<UploadLimits>; now?: Date } = {},\n): Promise<FiscalExtractionSummary> {\n const lim = { ...UPLOAD_LIMITS, ...options.limits }\n // The region can only lower the limits.\n const maxBytes = Math.min(lim.maxBytes, spec.max_bytes || lim.maxBytes)\n const maxPages = Math.min(lim.maxPages, spec.max_pages || lim.maxPages)\n if (file.size > maxBytes) throw new IdentityDocumentError('too_large', 'file over the size limit', { reason: 'bytes' })\n const bytes = new Uint8Array(await file.arrayBuffer())\n if (!PDF_MAGIC.every((b, i) => bytes[i] === b)) throw new IdentityDocumentError('not_pdf', 'not a PDF')\n // The engine is the only reader. QR cross-check needs a canvas, which a server does not have: `qr_match` stays null.\n const { text, sha256 } = await readPdfText(bytes, { maxBytes, maxPages, timeoutMs: lim.timeoutMs })\n const x = extractIdentityDocument(text, spec, {\n catalogs: region.fiscal_id ? catalogsFromRegion(region.fiscal_id) : {},\n ...(options.now ? { now: options.now } : {}),\n })\n return summarizeExtraction(x, buildDocumentEvidence(x, { sha256, source: 'pdf_server' }), region.fiscal_id?.regimes.map((r) => r.code))\n}\n","/**\n * Server side of the fiscal components (`@asteby/storefront-react/fiscal/server`): `loadFiscalContext` for the loader and\n * `createInvoiceAction` for the action. No React, no router: Web `Request`/`Response` only, so any framework mounts it.\n *\n * The browser never talks to OPS. The action uses the store's `sk_` client and the buyer's session token (read from the\n * store's cookie). A tax document uploaded WITHOUT JavaScript is read in memory here with the same engine the browser\n * uses, and discarded: no disk, no logs, no copy.\n */\nimport {\n isStorefrontError,\n repairPath,\n type FiscalDocumentEvidence,\n type FiscalIdentityInput,\n type InvoiceRequest,\n type InvoicingCapabilities,\n type Region,\n type StorefrontClient,\n} from '@asteby/storefront'\nimport { normalizeTaxId } from './format.js'\nimport { extractUploadedDocument, UPLOAD_LIMITS, type UploadLimits } from './server-extract.js'\nimport type { FiscalActionData, FiscalErrorCode, FiscalIntent } from './types.js'\n\nexport type { FiscalActionData, FiscalErrorCode, FiscalIntent } from './types.js'\nexport { UPLOAD_LIMITS, extractUploadedDocument } from './server-extract.js'\nexport type { UploadLimits } from './server-extract.js'\n\n// ---- context ---------------------------------------------------------------------------------------------------------\n\nexport type FiscalContext = {\n /** The store can invoice: it has a region with a fiscal catalog and `capabilities.invoicing.available`. */\n available: boolean\n region: Region | null\n invoicing: InvoicingCapabilities | null\n}\n\n/** What is assumed when the store cannot be asked: no invoicing, nothing breaks. */\nexport const NO_FISCAL_CONTEXT: Readonly<FiscalContext> = Object.freeze({ available: false, region: null, invoicing: null })\n\nconst FAILURE_TTL_MS = 5_000\nconst cache = new WeakMap<object, { at: number; ok: boolean; value: FiscalContext }>()\n\nexport type LoadFiscalContextOptions = {\n /** How long a good answer is reused per client (default 60 s). `0` disables the cache. */\n ttlMs?: number\n signal?: AbortSignal\n now?: () => number\n}\n\n/**\n * Asks the store for its region and what invoicing it offers, with a short cache per client. It NEVER throws: when OPS\n * does not answer (older server, outage, token without scope) it returns `NO_FISCAL_CONTEXT` and retries after a few\n * seconds, so a checkout without invoicing keeps working. Use it as the loader: `loader = () => loadFiscalContext(sf)`.\n */\nexport async function loadFiscalContext(sf: StorefrontClient, options: LoadFiscalContextOptions = {}): Promise<FiscalContext> {\n const now = options.now ?? Date.now\n const ttl = options.ttlMs ?? 60_000\n const hit = cache.get(sf)\n if (hit && now() - hit.at < (hit.ok ? ttl : FAILURE_TTL_MS)) return hit.value\n const opt = options.signal ? { signal: options.signal } : undefined\n const [region, caps] = await Promise.allSettled([sf.region(opt), sf.customer.capabilities(opt)])\n const reg = region.status === 'fulfilled' ? region.value : null\n const invoicing = caps.status === 'fulfilled' ? (caps.value?.invoicing ?? null) : null\n const ok = region.status === 'fulfilled' && caps.status === 'fulfilled'\n const value: FiscalContext = {\n available: !!reg?.fiscal_id && !!invoicing?.available,\n region: reg,\n invoicing: invoicing?.available ? invoicing : null,\n }\n cache.set(sf, { at: now(), ok, value: ok ? value : value.available ? value : NO_FISCAL_CONTEXT })\n return ok || value.available ? value : NO_FISCAL_CONTEXT\n}\n\n// ---- action ----------------------------------------------------------------------------------------------------------\n\n/** What the action needs of a cookie to read the buyer's session. React Router's `createCookie(...)` fits as it is. */\nexport type SessionCookie = { parse(header: string | null): unknown }\n\nexport type CreateInvoiceActionOptions = {\n storefront: StorefrontClient\n /** The store's cookie for the buyer session token (`createCookie('sf_customer', ...)`), to know who is asking. */\n customerCookie?: SessionCookie\n /** Alternative to `customerCookie`: returns the buyer's session token, or `null` for a guest. */\n readCustomerToken?: (request: Request) => string | null | undefined | Promise<string | null | undefined>\n /** Shopper IP for the per-shopper rate limit (see `clientIp` of the client). */\n clientIp?: (request: Request) => string | null | undefined\n /** Region + capabilities source, for tests or a shared cache (default `loadFiscalContext`). */\n context?: (sf: StorefrontClient) => Promise<FiscalContext>\n /** Limits of the no-JS upload (defaults: 5 MiB, 6 pages, 3 s). The region's own limits can only lower them. */\n limits?: Partial<UploadLimits>\n /** Clock, for the freshness check. */\n now?: () => Date\n /** Rejects cross-site posts (default `true`): `Origin` and `Sec-Fetch-Site` must match the site. */\n sameSiteOnly?: boolean\n /** Prefix of the form fields (default `invoice`). */\n namePrefix?: string\n}\n\nconst EVIDENCE_SOURCES = new Set(['pdf_client', 'pdf_server', 'qr', 'manual'])\n\n/** Reads the evidence the reader put in the form, keeping only the known keys (a form is untrusted input). */\nexport function parseEvidence(raw: unknown): FiscalDocumentEvidence | undefined {\n if (typeof raw !== 'string' || !raw || raw.length > 4096) return undefined\n let o: unknown\n try {\n o = JSON.parse(raw)\n } catch {\n return undefined\n }\n if (typeof o !== 'object' || o === null) return undefined\n const e = o as Record<string, unknown>\n if (typeof e.kind !== 'string' || !e.kind || typeof e.source !== 'string' || !EVIDENCE_SOURCES.has(e.source)) return undefined\n const str = (v: unknown, max: number) => (typeof v === 'string' && v.length <= max ? v : null)\n return {\n kind: e.kind.slice(0, 64),\n document_id: str(e.document_id, 64),\n issued_on: str(e.issued_on, 32),\n sha256: typeof e.sha256 === 'string' && /^[0-9a-f]{64}$/.test(e.sha256) ? e.sha256 : null,\n ...(typeof e.extractor === 'string' ? { extractor: e.extractor.slice(0, 64) } : {}),\n source: e.source as FiscalDocumentEvidence['source'],\n qr_match: typeof e.qr_match === 'boolean' ? e.qr_match : null,\n }\n}\n\n/** Reads the `invoice.*` fields of a form into the API's `InvoiceRequest`. */\nexport function invoiceFromForm(form: FormData, prefix = 'invoice'): InvoiceRequest {\n const text = (k: string) => {\n const v = form.get(`${prefix}.${k}`)\n return typeof v === 'string' ? v.trim() : ''\n }\n const evidence = parseEvidence(form.get(`${prefix}.document`))\n const out: InvoiceRequest = {\n requested: true,\n tax_id: normalizeTaxId(text('tax_id')),\n legal_name: text('legal_name'),\n tax_regime: text('tax_regime'),\n use: text('use'),\n postal_code: text('postal_code'),\n }\n if (evidence) out.document = evidence\n if (form.get(`${prefix}.save`)) out.save = true\n return out\n}\n\nconst fail = (intent: FiscalIntent | undefined, code: FiscalErrorCode, extra: Partial<FiscalActionData> = {}): FiscalActionData => ({\n ok: false,\n ...(intent ? { intent } : {}),\n ...extra,\n error: { code, ...(extra.error?.field ? { field: extra.error.field } : {}), ...(extra.error?.blocked ? { blocked: extra.error.blocked } : {}) },\n})\n\nconst LOG_EVERY_MS = 60_000\nlet lastLogAt = -Infinity\nfunction logMisconfigured(scopes: readonly string[]): void {\n const t = Date.now()\n if (t - lastLogAt < LOG_EVERY_MS) return\n lastLogAt = t\n console.error(\n `[@asteby/storefront-react] La credencial de la tienda no tiene permisos${scopes.length ? ` (${scopes.join(', ')})` : ''}; ` +\n `la facturación no funciona hasta repararlo en ${repairPath()}.`,\n )\n}\n\n/** `fiscal.tax_regime` (profile) and `invoice.tax_regime` (cart, order) both name the same form control. */\nconst formField = (field: string | undefined, prefix: string) => (field ? field.replace(/^(fiscal|invoice)\\./, `${prefix}.`) : undefined)\n\nfunction toFailure(err: unknown, intent: FiscalIntent, prefix: string, values?: Partial<FiscalActionData['values']>): FiscalActionData {\n const carry: Partial<FiscalActionData> = values ? { values } : {}\n if (!isStorefrontError(err)) return fail(intent, 'unavailable', carry)\n if (err.code === 'insufficient_scope') {\n logMisconfigured(err.requiredScopes)\n return fail(intent, 'store_misconfigured', carry)\n }\n const details = (err.details ?? {}) as { reason?: unknown; blocked_reason?: unknown }\n switch (err.status) {\n case 401:\n return fail(intent, 'unauthorized', carry)\n case 404:\n return fail(intent, 'not_found', carry)\n case 409: {\n const why = typeof details.reason === 'string' ? details.reason : typeof details.blocked_reason === 'string' ? details.blocked_reason : ''\n return fail(intent, why === 'already_checked_out' ? 'not_found' : 'blocked', { ...carry, ...(why ? { error: { code: 'blocked', blocked: why } } : {}) })\n }\n case 422:\n case 400: {\n const field = formField(err.field, prefix)\n return fail(intent, 'validation', {\n ...carry,\n ...(field ? { fieldErrors: { [field]: err.message || 'invalid' }, error: { code: 'validation', field } } : {}),\n })\n }\n case 429:\n return fail(intent, 'rate_limited', carry)\n case 403:\n return fail(intent, 'unsupported', carry)\n default:\n return fail(intent, 'unavailable', carry)\n }\n}\n\nfunction sameSite(request: Request): boolean {\n const site = request.headers.get('sec-fetch-site')\n if (site && site !== 'same-origin' && site !== 'same-site' && site !== 'none') return false\n const origin = request.headers.get('origin')\n if (!origin) return true\n try {\n const host = request.headers.get('x-forwarded-host') ?? request.headers.get('host') ?? new URL(request.url).host\n return new URL(origin).host === host.split(',')[0]!.trim()\n } catch {\n return false\n }\n}\n\n/**\n * The invoicing action: one `POST` form with an `intent` field.\n *\n * | intent | fields | does |\n * | ------------------ | --------------------------------------------------- | ---------------------------------------------------------- |\n * | `set-invoice` | cart_id, invoice.* (`invoice.want` unset withdraws) | `carts.setInvoice`: validates against the region BEFORE paying |\n * | `save-profile` | invoice.*, consent | `customer.update({ fiscal })`, needs a session and consent |\n * | `request-invoice` | order_id, invoice.* | `customer.requestInvoice` (invoice after the purchase) |\n * | `clear-profile` | - | `customer.update({ fiscal: null })` (the buyer's right to delete) |\n * | `extract-document` | document (file), document_kind? | reads the file in memory, discards it, `step: 'review'` |\n *\n * It never redirects: it returns a `FiscalActionData` for the page to render (`<InvoiceToggle data={...}>`), with 422s\n * mapped to the field (`fieldErrors['invoice.tax_regime']`). The tax id of the buyer is never logged.\n */\nexport function createInvoiceAction(options: CreateInvoiceActionOptions) {\n const { storefront: sf } = options\n const prefix = options.namePrefix ?? 'invoice'\n const loadContext = options.context ?? ((c: StorefrontClient) => loadFiscalContext(c))\n const limits: UploadLimits = { ...UPLOAD_LIMITS, ...options.limits }\n\n async function sessionToken(request: Request): Promise<string | null> {\n if (options.readCustomerToken) return (await options.readCustomerToken(request)) || null\n if (!options.customerCookie) return null\n const v = await options.customerCookie.parse(request.headers.get('cookie'))\n return typeof v === 'string' && v ? v : null\n }\n\n return async function invoiceAction({ request }: { request: Request }): Promise<FiscalActionData> {\n if (options.sameSiteOnly !== false && !sameSite(request)) return fail(undefined, 'unsupported')\n // A file bigger than the limit is refused before it is buffered.\n const declared = Number(request.headers.get('content-length') ?? 0)\n if (declared > limits.maxBytes + 256 * 1024) return fail('extract-document', 'too_large')\n const form = await request.formData().catch(() => null)\n if (!form) return fail(undefined, 'validation')\n const intent = form.get('intent') as FiscalIntent\n const ip = options.clientIp?.(request)\n const token = await sessionToken(request)\n const w = { ...(ip ? { clientIp: ip } : {}), ...(token ? { customerToken: token } : {}) }\n const invoice = invoiceFromForm(form, prefix)\n const echo = { tax_id: invoice.tax_id ?? '', legal_name: invoice.legal_name ?? '', postal_code: invoice.postal_code ?? '', tax_regime: invoice.tax_regime ?? '', use: invoice.use ?? '' }\n const text = (name: string) => {\n const v = form.get(name)\n return typeof v === 'string' ? v.trim() : ''\n }\n\n try {\n switch (intent) {\n case 'set-invoice': {\n const cartId = text('cart_id')\n if (!cartId) return fail(intent, 'validation')\n if (!form.get(`${prefix}.want`) && !form.get(`${prefix}.requested`)) {\n await sf.carts.setInvoice(cartId, null, w)\n return { ok: true, intent, step: 'cleared' }\n }\n await sf.carts.setInvoice(cartId, invoice, w)\n return { ok: true, intent, step: 'saved', values: echo }\n }\n case 'save-profile': {\n if (!token) return fail(intent, 'unauthorized', { values: echo })\n if (!form.get('consent')) return fail(intent, 'consent_required', { values: echo })\n const fiscal: FiscalIdentityInput = {\n tax_id: invoice.tax_id ?? '',\n legal_name: invoice.legal_name ?? '',\n tax_regime: invoice.tax_regime ?? '',\n postal_code: invoice.postal_code ?? '',\n invoice_use: invoice.use ?? '',\n ...(invoice.document ? { document: invoice.document } : {}),\n }\n await sf.customer.update({ fiscal }, w)\n return { ok: true, intent, step: 'saved', values: echo }\n }\n case 'clear-profile': {\n if (!token) return fail(intent, 'unauthorized')\n await sf.customer.update({ fiscal: null }, w)\n return { ok: true, intent, step: 'cleared' }\n }\n case 'request-invoice': {\n if (!token) return fail(intent, 'unauthorized', { values: echo })\n const orderId = text('order_id')\n if (!orderId) return fail(intent, 'validation')\n const result = await sf.customer.requestInvoice(orderId, invoice, w)\n return { ok: true, intent, step: result.status === 'issued' ? 'issued' : 'pending', result, ...(result.invoice ? { invoice: result.invoice } : {}) }\n }\n case 'extract-document': {\n const ctx = await loadContext(sf)\n const region = ctx.region\n const kind = text('document_kind')\n const specs = region?.fiscal_id?.documents ?? []\n const spec = (kind ? specs.find((d) => d.kind === kind) : specs[0]) ?? undefined\n if (!ctx.available || !region || !spec) return fail(intent, 'unsupported')\n const file = form.get('document')\n if (!file || typeof file === 'string' || file.size === 0) return fail(intent, 'not_pdf')\n try {\n const extraction = await extractUploadedDocument(file, spec, region, { limits, ...(options.now ? { now: options.now() } : {}) })\n return { ok: true, intent, step: 'review', extraction }\n } catch (err) {\n const code = (err as { code?: string } | null)?.code\n const known: FiscalErrorCode[] = ['not_pdf', 'too_large', 'no_text', 'password', 'unreadable']\n // Never log the error: it can carry text from the document.\n return fail(intent, known.includes(code as FiscalErrorCode) ? (code as FiscalErrorCode) : 'unreadable')\n }\n }\n default:\n return fail(undefined, 'validation')\n }\n } catch (err) {\n return toFailure(err, intent, prefix, intent === 'clear-profile' ? undefined : echo)\n }\n }\n}\n\nexport type InvoiceAction = ReturnType<typeof createInvoiceAction>\n"]}
1
+ {"version":3,"sources":["../src/fiscal/format.ts","../src/fiscal/extraction.ts","../src/fiscal/server-extract.ts","../src/fiscal/server.ts"],"names":["IdentityDocumentError","readPdfText","extractIdentityDocument","catalogsFromRegion","buildDocumentEvidence","repairPath","isStorefrontError"],"mappings":";;;;;;;;AAUO,SAAS,eAAe,GAAA,EAAqB;AAClD,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,UAAA,EAAY,EAAE,EAAE,WAAA,EAAY;AACjD;;;ACNA,IAAM,KAAA,GAAQ,CAAC,CAAA,KAA8C,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,GAAK,CAAA,CAAE,CAAC,CAAA,IAAK,EAAA,GAAO,CAAA,IAAK,EAAA;AAG9F,SAAS,mBAAA,CAAoB,CAAA,EAAuB,QAAA,EAAkC,YAAA,EAA0D;AACrJ,EAAA,MAAM,IAAI,CAAA,CAAE,MAAA;AACZ,EAAA,MAAM,KAAA,GAAQ,YAAA,GAAe,IAAI,GAAA,CAAI,YAAY,CAAA,GAAI,IAAA;AACrD,EAAA,MAAM,MAAM,CAAA,CAAE,UAAA;AACd,EAAA,MAAM,UAAA,GAAA,CAAc,MAAM,OAAA,CAAQ,GAAG,IAAI,GAAA,GAAM,GAAA,GAAM,CAAC,GAAG,CAAA,GAAI,EAAC,EAAG,MAAA,CAAO,CAAC,CAAA,KAAM,CAAC,SAAS,KAAA,CAAM,GAAA,CAAI,CAAC,CAAC,CAAA;AACrG,EAAA,MAAM,SAA4C,EAAC;AACnD,EAAA,MAAM,OAA0B,EAAC;AACjC,EAAA,MAAM,GAAA,GAAM,CAAC,IAAA,EAAuB,CAAA,KAAc;AAChD,IAAA,IAAI,CAAC,CAAA,EAAG;AACR,IAAA,MAAA,CAAO,IAAI,CAAA,GAAI,CAAA;AACf,IAAA,IAAA,CAAK,KAAK,IAAI,CAAA;AAAA,EAChB,CAAA;AACA,EAAA,GAAA,CAAI,UAAU,cAAA,CAAe,K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AAY,CAAA;AAAA;AACvC,IACF,SAAS,GAAA,EAAK;AACZ,MAAA,OAAO,UAAU,GAAA,EAAK,MAAA,EAAQ,QAAQ,MAAA,KAAW,eAAA,GAAkB,SAAY,IAAI,CAAA;AAAA,IACrF;AAAA,EACF,CAAA;AACF","file":"fiscal-server.cjs","sourcesContent":["/**\n * Pure helpers over the region's fiscal catalog (`Region.fiscal_id`). They know no country: the tax id format, the\n * regimes, the invoice uses and the postal code format are all data.\n */\nimport type { InvoiceRequest, Region, RegionFiscalEntry, RegionFiscalId } from '@asteby/storefront'\nimport type { FiscalFieldName, FiscalFieldValues } from './types.js'\n\nexport type FiscalRegion = Pick<Region, 'address'> & { fiscal_id?: RegionFiscalId }\n\n/** Uppercase, no spaces, hyphens or dots: how a tax id is compared and sent. */\nexport function normalizeTaxId(raw: string): string {\n return raw.replace(/[\\s\\-.]/g, '').toUpperCase()\n}\n\n/** Masks a tax id for display and logs: first 2 and last 3 characters stay (`PE********ABC`). */\nexport function maskTaxId(taxId: string): string {\n const v = taxId.trim()\n return v.length <= 5 ? '*'.repeat(v.length) : `${v.slice(0, 2)}${'*'.repeat(v.length - 5)}${v.slice(-3)}`\n}\n\nconst compile = (pattern: string | undefined): RegExp | null => {\n if (!pattern) return null\n try {\n return new RegExp(pattern)\n } catch {\n return null\n }\n}\n\n/** `null` when the tax id is valid for the region (its pattern or one of its generic ids); otherwise why not. */\nexport function taxIdProblem(fid: RegionFiscalId | undefined, raw: string): 'required' | 'format' | null {\n const v = normalizeTaxId(raw)\n if (!v) return 'required'\n if (!fid) return null\n if (fid.generic_ids.includes(v)) return null\n const re = compile(fid.pattern)\n return re && !re.test(v) ? 'format' : null\n}\n\nexport function postalCodeProblem(region: FiscalRegion, raw: string): 'required' | 'format' | null {\n const v = raw.trim()\n if (!v) return 'required'\n const re = compile(region.address?.postal_code?.pattern)\n return re && !re.test(v) ? 'format' : null\n}\n\n/**\n * Builds the function that tells a person type from a tax id when the region does not publish one. Pass the length\n * of the tax id per type, e.g. `personTypeByLength({ individual: 13, company: 12 })`. Without a function the regimes\n * are not narrowed by person type (the server still checks the combination).\n */\nexport function personTypeByLength(lengths: Record<string, number>): (taxId: string) => string | null {\n return (taxId) => {\n const n = normalizeTaxId(taxId).length\n return Object.keys(lengths).find((t) => lengths[t] === n) ?? null\n }\n}\n\n/**\n * Tells a person type from a tax id with the region's own patterns (`fiscal_id.person_patterns`, DATA of the region\n * pack). `null` when the region publishes none or none matches. A pattern that does not compile is ignored.\n */\nexport function personTypeFromPatterns(fid: RegionFiscalId | undefined, taxId: string): string | null {\n const patterns = fid?.person_patterns\n if (!patterns) return null\n const v = normalizeTaxId(taxId)\n for (const type of Object.keys(patterns).sort()) {\n const re = compile(patterns[type])\n if (re?.test(v)) return type\n }\n return null\n}\n\n/** The function to use for the person type: the store's override, else the region's patterns. */\nexport function personTypeResolver(fid: RegionFiscalId | undefined, override?: (taxId: string) => string | null): (taxId: string) => string | null {\n return override ?? ((taxId) => personTypeFromPatterns(fid, taxId))\n}\n\n/**\n * The invoice use to suggest for a regime, from region data only: the organization's `default_invoice_use` when the\n * regime admits it, else the first use whose `suggested_for_regimes` lists the regime (and whose `allowed_regimes`\n * admits it). `null` when the region suggests nothing: then nothing is preselected. A suggestion, never a rule.\n */\nexport function suggestInvoiceUse(fid: RegionFiscalId | undefined, regime: string | null | undefined): string | null {\n if (!fid || !regime) return null\n const allowed = usesFor(fid, regime)\n const preferred = fid.default_invoice_use\n if (preferred && allowed.some((u) => u.code === preferred)) return preferred\n return allowed.find((u) => u.suggested_for_regimes?.includes(regime))?.code ?? null\n}\n\n/** Regimes that fit a person type (all when the type is unknown). */\nexport function regimesFor(fid: RegionFiscalId | undefined, personType: string | null): RegionFiscalEntry[] {\n const all = fid?.regimes ?? []\n if (!personType) return all\n return all.filter((r) => r.person_types.length === 0 || r.person_types.includes(personType))\n}\n\n/** Invoice uses a regime admits (all when no regime is chosen yet). */\nexport function usesFor(fid: RegionFiscalId | undefined, regime: string | null | undefined): RegionFiscalEntry[] {\n const all = fid?.invoice_uses ?? []\n if (!regime) return all\n return all.filter((u) => !u.allowed_regimes || u.allowed_regimes.length === 0 || u.allowed_regimes.includes(regime))\n}\n\nexport type FiscalProblem = 'required' | 'format' | 'unknown' | 'person_type' | 'use_not_allowed'\n\n/** Client-side check of the whole form against the region; the server stays the authority. */\nexport function validateFiscalValues(\n region: FiscalRegion,\n v: Partial<FiscalFieldValues>,\n personTypeOverride?: (taxId: string) => string | null,\n): Partial<Record<FiscalFieldName, FiscalProblem>> {\n const fid = region.fiscal_id\n const personTypeOf = personTypeResolver(fid, personTypeOverride)\n const out: Partial<Record<FiscalFieldName, FiscalProblem>> = {}\n const tax = taxIdProblem(fid, v.tax_id ?? '')\n if (tax) out.tax_id = tax\n if (!(v.legal_name ?? '').trim()) out.legal_name = 'required'\n if (postalCodeProblem(region, v.postal_code ?? '')) out.postal_code = postalCodeProblem(region, v.postal_code ?? '')!\n const regime = v.tax_regime ?? ''\n if (!regime) out.tax_regime = 'required'\n else if (fid) {\n const entry = fid.regimes.find((r) => r.code === regime)\n if (!entry) out.tax_regime = 'unknown'\n else if (!tax && !fid.generic_ids.includes(normalizeTaxId(v.tax_id ?? ''))) {\n const person = personTypeOf?.(v.tax_id ?? '') ?? null\n if (person && entry.person_types.length > 0 && !entry.person_types.includes(person)) out.tax_regime = 'person_type'\n }\n }\n const use = v.use ?? ''\n if (!use) out.use = 'required'\n else if (fid) {\n const entry = fid.invoice_uses.find((u) => u.code === use)\n if (!entry) out.use = 'unknown'\n else if (regime && entry.allowed_regimes && entry.allowed_regimes.length > 0 && !entry.allowed_regimes.includes(regime)) out.use = 'use_not_allowed'\n }\n return out\n}\n\n/** Form values -> the API's `InvoiceRequest` (without `document`). */\nexport function toInvoiceRequest(v: Partial<FiscalFieldValues>, countryCode?: string): InvoiceRequest {\n return {\n requested: true,\n tax_id: normalizeTaxId(v.tax_id ?? ''),\n legal_name: (v.legal_name ?? '').trim(),\n tax_regime: v.tax_regime ?? '',\n use: v.use ?? '',\n postal_code: (v.postal_code ?? '').trim(),\n ...(countryCode ? { country_code: countryCode } : {}),\n }\n}\n\n/** `label_en` for English locales when the region has it. */\nexport function entryLabel(e: RegionFiscalEntry, locale?: string | null): string {\n return (locale ?? 'es-MX').toLowerCase().startsWith('en') && e.label_en ? e.label_en : e.label\n}\n","/** Turns what the engine read into what the UI shows. Shared by the browser reader and the server upload. */\nimport type { FiscalDocumentEvidence } from '@asteby/storefront'\nimport type { IdentityExtraction } from '@asteby/storefront/fiscal-document'\nimport { normalizeTaxId } from './format.js'\nimport type { FiscalExtractionSummary, FiscalFieldName } from './types.js'\n\nconst first = (v: string | string[] | undefined): string => (Array.isArray(v) ? (v[0] ?? '') : (v ?? ''))\n\n/** `evidence` comes from `buildDocumentEvidence`. Only the conventional fields are kept: nothing else can leak. */\nexport function summarizeExtraction(x: IdentityExtraction, evidence: FiscalDocumentEvidence, validRegimes?: Iterable<string>): FiscalExtractionSummary {\n const f = x.fields\n const valid = validRegimes ? new Set(validRegimes) : null\n const raw = f.tax_regime\n const candidates = (Array.isArray(raw) ? raw : raw ? [raw] : []).filter((c) => !valid || valid.has(c))\n const values: FiscalExtractionSummary['values'] = {}\n const from: FiscalFieldName[] = []\n const put = (name: FiscalFieldName, v: string) => {\n if (!v) return\n values[name] = v\n from.push(name)\n }\n put('tax_id', normalizeTaxId(first(f.tax_id)))\n put('legal_name', first(f.legal_name).trim())\n put('postal_code', first(f.postal_code).trim())\n if (candidates.length === 1) put('tax_regime', candidates[0]!)\n else if (candidates.length > 1) from.push('tax_regime')\n return {\n kind: x.kind,\n values,\n regime_candidates: candidates,\n from_document: from,\n qr_match: x.qr.match,\n stale: x.stale,\n age_days: x.age_days,\n missing: [...x.missing],\n evidence,\n }\n}\n","/**\n * Reads a tax document uploaded without JavaScript, on the server, with the same engine the browser uses. In memory\n * only: the bytes are never written to disk, never logged and are dropped when this returns.\n */\nimport type { IdentityDocumentSpec, Region } from '@asteby/storefront'\nimport { IdentityDocumentError, buildDocumentEvidence, catalogsFromRegion, extractIdentityDocument, readPdfText } from '@asteby/storefront/fiscal-document'\nimport { summarizeExtraction } from './extraction.js'\nimport type { FiscalExtractionSummary } from './types.js'\n\nexport type UploadLimits = { maxBytes: number; maxPages: number; timeoutMs: number }\n\n/** 5 MiB, 6 pages, 3 s: the same as the browser reader. */\nexport const UPLOAD_LIMITS: Readonly<UploadLimits> = Object.freeze({ maxBytes: 5 * 1024 * 1024, maxPages: 6, timeoutMs: 3000 })\n\nconst PDF_MAGIC = [0x25, 0x50, 0x44, 0x46, 0x2d] // %PDF-\n\nexport async function extractUploadedDocument(\n file: Blob,\n spec: IdentityDocumentSpec,\n region: Pick<Region, 'fiscal_id'>,\n options: { limits?: Partial<UploadLimits>; now?: Date } = {},\n): Promise<FiscalExtractionSummary> {\n const lim = { ...UPLOAD_LIMITS, ...options.limits }\n // The region can only lower the limits.\n const maxBytes = Math.min(lim.maxBytes, spec.max_bytes || lim.maxBytes)\n const maxPages = Math.min(lim.maxPages, spec.max_pages || lim.maxPages)\n if (file.size > maxBytes) throw new IdentityDocumentError('too_large', 'file over the size limit', { reason: 'bytes' })\n const bytes = new Uint8Array(await file.arrayBuffer())\n if (!PDF_MAGIC.every((b, i) => bytes[i] === b)) throw new IdentityDocumentError('not_pdf', 'not a PDF')\n // The engine is the only reader. QR cross-check needs a canvas, which a server does not have: `qr_match` stays null.\n const { text, sha256 } = await readPdfText(bytes, { maxBytes, maxPages, timeoutMs: lim.timeoutMs })\n const x = extractIdentityDocument(text, spec, {\n catalogs: region.fiscal_id ? catalogsFromRegion(region.fiscal_id) : {},\n ...(options.now ? { now: options.now } : {}),\n })\n return summarizeExtraction(x, buildDocumentEvidence(x, { sha256, source: 'pdf_server' }), region.fiscal_id?.regimes.map((r) => r.code))\n}\n","/**\n * Server side of the fiscal components (`@asteby/storefront-react/fiscal/server`): `loadFiscalContext` for the loader and\n * `createInvoiceAction` for the action. No React, no router: Web `Request`/`Response` only, so any framework mounts it.\n *\n * The browser never talks to OPS. The action uses the store's `sk_` client and the buyer's session token (read from the\n * store's cookie). A tax document uploaded WITHOUT JavaScript is read in memory here with the same engine the browser\n * uses, and discarded: no disk, no logs, no copy.\n */\nimport {\n isStorefrontError,\n repairPath,\n type FiscalDocumentEvidence,\n type FiscalIdentityInput,\n type InvoiceRequest,\n type InvoicingCapabilities,\n type Region,\n type StorefrontClient,\n} from '@asteby/storefront'\nimport { normalizeTaxId } from './format.js'\nimport { extractUploadedDocument, UPLOAD_LIMITS, type UploadLimits } from './server-extract.js'\nimport type { FiscalActionData, FiscalErrorCode, FiscalIntent } from './types.js'\n\nexport type { FiscalActionData, FiscalErrorCode, FiscalIntent } from './types.js'\nexport { UPLOAD_LIMITS, extractUploadedDocument } from './server-extract.js'\nexport type { UploadLimits } from './server-extract.js'\n\n// ---- context ---------------------------------------------------------------------------------------------------------\n\nexport type FiscalContext = {\n /** The store can invoice: it has a region with a fiscal catalog and `capabilities.invoicing.available`. */\n available: boolean\n region: Region | null\n invoicing: InvoicingCapabilities | null\n}\n\n/** What is assumed when the store cannot be asked: no invoicing, nothing breaks. */\nexport const NO_FISCAL_CONTEXT: Readonly<FiscalContext> = Object.freeze({ available: false, region: null, invoicing: null })\n\nconst FAILURE_TTL_MS = 5_000\nconst cache = new WeakMap<object, { at: number; ok: boolean; value: FiscalContext }>()\n\nexport type LoadFiscalContextOptions = {\n /** How long a good answer is reused per client (default 60 s). `0` disables the cache. */\n ttlMs?: number\n signal?: AbortSignal\n now?: () => number\n}\n\n/**\n * Asks the store for its region and what invoicing it offers, with a short cache per client. It NEVER throws: when OPS\n * does not answer (older server, outage, token without scope) it returns `NO_FISCAL_CONTEXT` and retries after a few\n * seconds, so a checkout without invoicing keeps working. Use it as the loader: `loader = () => loadFiscalContext(sf)`.\n */\nexport async function loadFiscalContext(sf: StorefrontClient, options: LoadFiscalContextOptions = {}): Promise<FiscalContext> {\n const now = options.now ?? Date.now\n const ttl = options.ttlMs ?? 60_000\n const hit = cache.get(sf)\n if (hit && now() - hit.at < (hit.ok ? ttl : FAILURE_TTL_MS)) return hit.value\n const opt = options.signal ? { signal: options.signal } : undefined\n const [region, caps] = await Promise.allSettled([sf.region(opt), sf.customer.capabilities(opt)])\n const reg = region.status === 'fulfilled' ? region.value : null\n const invoicing = caps.status === 'fulfilled' ? (caps.value?.invoicing ?? null) : null\n const ok = region.status === 'fulfilled' && caps.status === 'fulfilled'\n const value: FiscalContext = {\n available: !!reg?.fiscal_id && !!invoicing?.available,\n region: reg,\n invoicing: invoicing?.available ? invoicing : null,\n }\n cache.set(sf, { at: now(), ok, value: ok ? value : value.available ? value : NO_FISCAL_CONTEXT })\n return ok || value.available ? value : NO_FISCAL_CONTEXT\n}\n\n// ---- action ----------------------------------------------------------------------------------------------------------\n\n/** What the action needs of a cookie to read the buyer's session. React Router's `createCookie(...)` fits as it is. */\nexport type SessionCookie = { parse(header: string | null): unknown }\n\nexport type CreateInvoiceActionOptions = {\n storefront: StorefrontClient\n /** The store's cookie for the buyer session token (`createCookie('sf_customer', ...)`), to know who is asking. */\n customerCookie?: SessionCookie\n /** Alternative to `customerCookie`: returns the buyer's session token, or `null` for a guest. */\n readCustomerToken?: (request: Request) => string | null | undefined | Promise<string | null | undefined>\n /** Shopper IP for the per-shopper rate limit (see `clientIp` of the client). */\n clientIp?: (request: Request) => string | null | undefined\n /** Region + capabilities source, for tests or a shared cache (default `loadFiscalContext`). */\n context?: (sf: StorefrontClient) => Promise<FiscalContext>\n /** Limits of the no-JS upload (defaults: 5 MiB, 6 pages, 3 s). The region's own limits can only lower them. */\n limits?: Partial<UploadLimits>\n /** Clock, for the freshness check. */\n now?: () => Date\n /** Rejects cross-site posts (default `true`): `Origin` and `Sec-Fetch-Site` must match the site. */\n sameSiteOnly?: boolean\n /** Prefix of the form fields (default `invoice`). */\n namePrefix?: string\n}\n\nconst EVIDENCE_SOURCES = new Set(['pdf_client', 'pdf_server', 'qr', 'manual'])\n\n/** Reads the evidence the reader put in the form, keeping only the known keys (a form is untrusted input). */\nexport function parseEvidence(raw: unknown): FiscalDocumentEvidence | undefined {\n if (typeof raw !== 'string' || !raw || raw.length > 4096) return undefined\n let o: unknown\n try {\n o = JSON.parse(raw)\n } catch {\n return undefined\n }\n if (typeof o !== 'object' || o === null) return undefined\n const e = o as Record<string, unknown>\n if (typeof e.kind !== 'string' || !e.kind || typeof e.source !== 'string' || !EVIDENCE_SOURCES.has(e.source)) return undefined\n const str = (v: unknown, max: number) => (typeof v === 'string' && v.length <= max ? v : null)\n return {\n kind: e.kind.slice(0, 64),\n document_id: str(e.document_id, 64),\n issued_on: str(e.issued_on, 32),\n sha256: typeof e.sha256 === 'string' && /^[0-9a-f]{64}$/.test(e.sha256) ? e.sha256 : null,\n ...(typeof e.extractor === 'string' ? { extractor: e.extractor.slice(0, 64) } : {}),\n source: e.source as FiscalDocumentEvidence['source'],\n qr_match: typeof e.qr_match === 'boolean' ? e.qr_match : null,\n }\n}\n\n/** Reads the `invoice.*` fields of a form into the API's `InvoiceRequest`. */\nexport function invoiceFromForm(form: FormData, prefix = 'invoice'): InvoiceRequest {\n const text = (k: string) => {\n const v = form.get(`${prefix}.${k}`)\n return typeof v === 'string' ? v.trim() : ''\n }\n const evidence = parseEvidence(form.get(`${prefix}.document`))\n const out: InvoiceRequest = {\n requested: true,\n tax_id: normalizeTaxId(text('tax_id')),\n legal_name: text('legal_name'),\n tax_regime: text('tax_regime'),\n use: text('use'),\n postal_code: text('postal_code'),\n }\n if (evidence) out.document = evidence\n if (form.get(`${prefix}.save`)) out.save = true\n return out\n}\n\nconst fail = (intent: FiscalIntent | undefined, code: FiscalErrorCode, extra: Partial<FiscalActionData> = {}): FiscalActionData => ({\n ok: false,\n ...(intent ? { intent } : {}),\n ...extra,\n error: { code, ...(extra.error?.field ? { field: extra.error.field } : {}), ...(extra.error?.blocked ? { blocked: extra.error.blocked } : {}) },\n})\n\nconst LOG_EVERY_MS = 60_000\nlet lastLogAt = -Infinity\nfunction logMisconfigured(scopes: readonly string[]): void {\n const t = Date.now()\n if (t - lastLogAt < LOG_EVERY_MS) return\n lastLogAt = t\n console.error(\n `[@asteby/storefront-react] La credencial de la tienda no tiene permisos${scopes.length ? ` (${scopes.join(', ')})` : ''}; ` +\n `la facturación no funciona hasta repararlo en ${repairPath()}.`,\n )\n}\n\n/** `fiscal.tax_regime` (profile) and `invoice.tax_regime` (cart, order) both name the same form control. */\nconst formField = (field: string | undefined, prefix: string) => (field ? field.replace(/^(fiscal|invoice)\\./, `${prefix}.`) : undefined)\n\nfunction toFailure(err: unknown, intent: FiscalIntent, prefix: string, values?: Partial<FiscalActionData['values']>): FiscalActionData {\n const carry: Partial<FiscalActionData> = values ? { values } : {}\n if (!isStorefrontError(err)) return fail(intent, 'unavailable', carry)\n if (err.code === 'insufficient_scope') {\n logMisconfigured(err.requiredScopes)\n return fail(intent, 'store_misconfigured', carry)\n }\n const details = (err.details ?? {}) as { reason?: unknown; blocked_reason?: unknown }\n switch (err.status) {\n case 401:\n return fail(intent, 'unauthorized', carry)\n case 404:\n return fail(intent, 'not_found', carry)\n case 409: {\n const why = typeof details.reason === 'string' ? details.reason : typeof details.blocked_reason === 'string' ? details.blocked_reason : ''\n return fail(intent, why === 'already_checked_out' ? 'not_found' : 'blocked', { ...carry, ...(why ? { error: { code: 'blocked', blocked: why } } : {}) })\n }\n case 422:\n case 400: {\n const field = formField(err.field, prefix)\n return fail(intent, 'validation', {\n ...carry,\n ...(field ? { fieldErrors: { [field]: err.message || 'invalid' }, error: { code: 'validation', field } } : {}),\n })\n }\n case 429:\n return fail(intent, 'rate_limited', carry)\n case 403:\n return fail(intent, 'unsupported', carry)\n default:\n return fail(intent, 'unavailable', carry)\n }\n}\n\nfunction sameSite(request: Request): boolean {\n const site = request.headers.get('sec-fetch-site')\n if (site && site !== 'same-origin' && site !== 'same-site' && site !== 'none') return false\n const origin = request.headers.get('origin')\n if (!origin) return true\n try {\n const host = request.headers.get('x-forwarded-host') ?? request.headers.get('host') ?? new URL(request.url).host\n return new URL(origin).host === host.split(',')[0]!.trim()\n } catch {\n return false\n }\n}\n\n/**\n * The invoicing action: one `POST` form with an `intent` field.\n *\n * | intent | fields | does |\n * | ------------------ | --------------------------------------------------- | ---------------------------------------------------------- |\n * | `set-invoice` | cart_id, invoice.* (`invoice.want` unset withdraws) | `carts.setInvoice`: validates against the region BEFORE paying |\n * | `save-profile` | invoice.*, consent | `customer.update({ fiscal })`, needs a session and consent |\n * | `request-invoice` | order_id, invoice.* | `customer.requestInvoice` (invoice after the purchase) |\n * | `clear-profile` | - | `customer.update({ fiscal: null })` (the buyer's right to delete) |\n * | `extract-document` | document (file), document_kind? | reads the file in memory, discards it, `step: 'review'` |\n *\n * It never redirects: it returns a `FiscalActionData` for the page to render (`<InvoiceToggle data={...}>`), with 422s\n * mapped to the field (`fieldErrors['invoice.tax_regime']`). The tax id of the buyer is never logged.\n */\nexport function createInvoiceAction(options: CreateInvoiceActionOptions) {\n const { storefront: sf } = options\n const prefix = options.namePrefix ?? 'invoice'\n const loadContext = options.context ?? ((c: StorefrontClient) => loadFiscalContext(c))\n const limits: UploadLimits = { ...UPLOAD_LIMITS, ...options.limits }\n\n async function sessionToken(request: Request): Promise<string | null> {\n if (options.readCustomerToken) return (await options.readCustomerToken(request)) || null\n if (!options.customerCookie) return null\n const v = await options.customerCookie.parse(request.headers.get('cookie'))\n return typeof v === 'string' && v ? v : null\n }\n\n return async function invoiceAction({ request }: { request: Request }): Promise<FiscalActionData> {\n if (options.sameSiteOnly !== false && !sameSite(request)) return fail(undefined, 'unsupported')\n // A file bigger than the limit is refused before it is buffered.\n const declared = Number(request.headers.get('content-length') ?? 0)\n if (declared > limits.maxBytes + 256 * 1024) return fail('extract-document', 'too_large')\n const form = await request.formData().catch(() => null)\n if (!form) return fail(undefined, 'validation')\n const intent = form.get('intent') as FiscalIntent\n const ip = options.clientIp?.(request)\n const token = await sessionToken(request)\n const w = { ...(ip ? { clientIp: ip } : {}), ...(token ? { customerToken: token } : {}) }\n const invoice = invoiceFromForm(form, prefix)\n const echo = { tax_id: invoice.tax_id ?? '', legal_name: invoice.legal_name ?? '', postal_code: invoice.postal_code ?? '', tax_regime: invoice.tax_regime ?? '', use: invoice.use ?? '' }\n const text = (name: string) => {\n const v = form.get(name)\n return typeof v === 'string' ? v.trim() : ''\n }\n\n try {\n switch (intent) {\n case 'set-invoice': {\n const cartId = text('cart_id')\n if (!cartId) return fail(intent, 'validation')\n if (!form.get(`${prefix}.want`) && !form.get(`${prefix}.requested`)) {\n await sf.carts.setInvoice(cartId, null, w)\n return { ok: true, intent, step: 'cleared' }\n }\n await sf.carts.setInvoice(cartId, invoice, w)\n return { ok: true, intent, step: 'saved', values: echo }\n }\n case 'save-profile': {\n if (!token) return fail(intent, 'unauthorized', { values: echo })\n if (!form.get('consent')) return fail(intent, 'consent_required', { values: echo })\n const fiscal: FiscalIdentityInput = {\n tax_id: invoice.tax_id ?? '',\n legal_name: invoice.legal_name ?? '',\n tax_regime: invoice.tax_regime ?? '',\n postal_code: invoice.postal_code ?? '',\n invoice_use: invoice.use ?? '',\n ...(invoice.document ? { document: invoice.document } : {}),\n }\n await sf.customer.update({ fiscal }, w)\n return { ok: true, intent, step: 'saved', values: echo }\n }\n case 'clear-profile': {\n if (!token) return fail(intent, 'unauthorized')\n await sf.customer.update({ fiscal: null }, w)\n return { ok: true, intent, step: 'cleared' }\n }\n case 'request-invoice': {\n if (!token) return fail(intent, 'unauthorized', { values: echo })\n const orderId = text('order_id')\n if (!orderId) return fail(intent, 'validation')\n const result = await sf.customer.requestInvoice(orderId, invoice, w)\n return { ok: true, intent, step: result.status === 'issued' ? 'issued' : 'pending', result, ...(result.invoice ? { invoice: result.invoice } : {}) }\n }\n case 'extract-document': {\n const ctx = await loadContext(sf)\n const region = ctx.region\n const kind = text('document_kind')\n const specs = region?.fiscal_id?.documents ?? []\n const spec = (kind ? specs.find((d) => d.kind === kind) : specs[0]) ?? undefined\n if (!ctx.available || !region || !spec) return fail(intent, 'unsupported')\n const file = form.get('document')\n if (!file || typeof file === 'string' || file.size === 0) return fail(intent, 'not_pdf')\n try {\n const extraction = await extractUploadedDocument(file, spec, region, { limits, ...(options.now ? { now: options.now() } : {}) })\n return { ok: true, intent, step: 'review', extraction }\n } catch (err) {\n const code = (err as { code?: string } | null)?.code\n const known: FiscalErrorCode[] = ['not_pdf', 'too_large', 'no_text', 'password', 'unreadable']\n // Never log the error: it can carry text from the document.\n return fail(intent, known.includes(code as FiscalErrorCode) ? (code as FiscalErrorCode) : 'unreadable')\n }\n }\n default:\n return fail(undefined, 'validation')\n }\n } catch (err) {\n return toFailure(err, intent, prefix, intent === 'clear-profile' ? undefined : echo)\n }\n }\n}\n\nexport type InvoiceAction = ReturnType<typeof createInvoiceAction>\n"]}
@@ -1,6 +1,6 @@
1
1
  import { IdentityDocumentSpec, Region, StorefrontClient, InvoicingCapabilities, InvoiceRequest, FiscalDocumentEvidence } from '@asteby/storefront';
2
- import { b as FiscalExtractionSummary, F as FiscalActionData } from './types-BnvSbV6t.cjs';
3
- export { a as FiscalErrorCode, e as FiscalIntent } from './types-BnvSbV6t.cjs';
2
+ import { b as FiscalExtractionSummary, F as FiscalActionData } from './types-CZ3PleG6.cjs';
3
+ export { a as FiscalErrorCode, e as FiscalIntent } from './types-CZ3PleG6.cjs';
4
4
 
5
5
  /**
6
6
  * Reads a tax document uploaded without JavaScript, on the server, with the same engine the browser uses. In memory
@@ -1,6 +1,6 @@
1
1
  import { IdentityDocumentSpec, Region, StorefrontClient, InvoicingCapabilities, InvoiceRequest, FiscalDocumentEvidence } from '@asteby/storefront';
2
- import { b as FiscalExtractionSummary, F as FiscalActionData } from './types-BnvSbV6t.js';
3
- export { a as FiscalErrorCode, e as FiscalIntent } from './types-BnvSbV6t.js';
2
+ import { b as FiscalExtractionSummary, F as FiscalActionData } from './types-CZ3PleG6.js';
3
+ export { a as FiscalErrorCode, e as FiscalIntent } from './types-CZ3PleG6.js';
4
4
 
5
5
  /**
6
6
  * Reads a tax document uploaded without JavaScript, on the server, with the same engine the browser uses. In memory
@@ -1,4 +1,4 @@
1
- import { summarizeExtraction, normalizeTaxId } from './chunk-Q7UTJIKY.js';
1
+ import { summarizeExtraction, normalizeTaxId } from './chunk-D5L7UZIA.js';
2
2
  import { isStorefrontError, repairPath } from '@asteby/storefront';
3
3
  import { IdentityDocumentError, readPdfText, extractIdentityDocument, catalogsFromRegion, buildDocumentEvidence } from '@asteby/storefront/fiscal-document';
4
4