@asteby/storefront-react 0.21.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.cjs.map +1 -1
- package/dist/account.js +1 -1
- package/dist/checkout.cjs +74 -6
- package/dist/checkout.cjs.map +1 -1
- package/dist/checkout.d.cts +9 -2
- package/dist/checkout.d.ts +9 -2
- package/dist/checkout.js +74 -6
- package/dist/checkout.js.map +1 -1
- package/dist/{chunk-Q7UTJIKY.js → chunk-D5L7UZIA.js} +25 -4
- package/dist/chunk-D5L7UZIA.js.map +1 -0
- package/dist/{chunk-PPQEUTXJ.js → chunk-VE7WQPMY.js} +48 -6
- package/dist/chunk-VE7WQPMY.js.map +1 -0
- package/dist/fiscal-server.cjs.map +1 -1
- package/dist/fiscal-server.d.cts +2 -2
- package/dist/fiscal-server.d.ts +2 -2
- package/dist/fiscal-server.js +1 -1
- package/dist/fiscal.cjs +418 -17
- package/dist/fiscal.cjs.map +1 -1
- package/dist/fiscal.css +103 -0
- package/dist/fiscal.d.cts +91 -7
- package/dist/fiscal.d.ts +91 -7
- package/dist/fiscal.js +296 -18
- package/dist/fiscal.js.map +1 -1
- package/dist/{types-BnvSbV6t.d.cts → types-CZ3PleG6.d.cts} +1 -1
- package/dist/{types-BnvSbV6t.d.ts → types-CZ3PleG6.d.ts} +1 -1
- package/package.json +2 -2
- package/dist/chunk-PPQEUTXJ.js.map +0 -1
- package/dist/chunk-Q7UTJIKY.js.map +0 -1
package/dist/fiscal.css
CHANGED
|
@@ -341,3 +341,106 @@
|
|
|
341
341
|
[data-sf-invoice-actions] {
|
|
342
342
|
align-items: center;
|
|
343
343
|
}
|
|
344
|
+
|
|
345
|
+
/* ---- Scan a tax document: entry buttons, bottom sheet and live viewfinder ---- */
|
|
346
|
+
[data-sf-scan] {
|
|
347
|
+
display: grid;
|
|
348
|
+
gap: 0.75rem;
|
|
349
|
+
}
|
|
350
|
+
[data-sf-scan-open],
|
|
351
|
+
[data-sf-scan-manual],
|
|
352
|
+
[data-sf-reader-scan] button {
|
|
353
|
+
min-height: 44px;
|
|
354
|
+
}
|
|
355
|
+
[data-sf-reader-scan] {
|
|
356
|
+
display: flex;
|
|
357
|
+
flex-wrap: wrap;
|
|
358
|
+
gap: 0.75rem;
|
|
359
|
+
}
|
|
360
|
+
[data-sf-scan-sheet] {
|
|
361
|
+
position: fixed;
|
|
362
|
+
inset: auto 0 0 0;
|
|
363
|
+
margin: 0;
|
|
364
|
+
width: 100%;
|
|
365
|
+
max-width: none;
|
|
366
|
+
max-height: 92dvh;
|
|
367
|
+
padding: 0;
|
|
368
|
+
border: 0;
|
|
369
|
+
border-radius: 1.25rem 1.25rem 0 0;
|
|
370
|
+
overflow: auto;
|
|
371
|
+
background: var(--sf-fiscal-sheet-bg, Canvas);
|
|
372
|
+
color: var(--sf-fiscal-sheet-fg, CanvasText);
|
|
373
|
+
box-shadow: 0 -8px 32px color-mix(in srgb, #000 22%, transparent);
|
|
374
|
+
animation: sf-scan-rise 180ms ease-out;
|
|
375
|
+
}
|
|
376
|
+
[data-sf-scan-sheet]::backdrop {
|
|
377
|
+
background: color-mix(in srgb, #000 45%, transparent);
|
|
378
|
+
}
|
|
379
|
+
@media (min-width: 40rem) {
|
|
380
|
+
[data-sf-scan-sheet] {
|
|
381
|
+
inset: 50% auto auto 50%;
|
|
382
|
+
transform: translate(-50%, -50%);
|
|
383
|
+
width: min(32rem, calc(100vw - 2rem));
|
|
384
|
+
border-radius: 1.25rem;
|
|
385
|
+
animation: none;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
[data-sf-scan-panel] {
|
|
389
|
+
display: grid;
|
|
390
|
+
gap: 1rem;
|
|
391
|
+
padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
|
|
392
|
+
}
|
|
393
|
+
[data-sf-scan-header] {
|
|
394
|
+
display: flex;
|
|
395
|
+
align-items: center;
|
|
396
|
+
justify-content: space-between;
|
|
397
|
+
gap: 1rem;
|
|
398
|
+
}
|
|
399
|
+
[data-sf-scan-title] {
|
|
400
|
+
margin: 0;
|
|
401
|
+
font-size: 1.125rem;
|
|
402
|
+
}
|
|
403
|
+
[data-sf-scan-close] {
|
|
404
|
+
min-width: 44px;
|
|
405
|
+
min-height: 44px;
|
|
406
|
+
border: 0;
|
|
407
|
+
background: transparent;
|
|
408
|
+
color: inherit;
|
|
409
|
+
font: inherit;
|
|
410
|
+
cursor: pointer;
|
|
411
|
+
}
|
|
412
|
+
[data-sf-reader-viewfinder] {
|
|
413
|
+
position: relative;
|
|
414
|
+
overflow: hidden;
|
|
415
|
+
border-radius: 1rem;
|
|
416
|
+
background: #000;
|
|
417
|
+
aspect-ratio: 4 / 3;
|
|
418
|
+
}
|
|
419
|
+
[data-sf-reader-video] {
|
|
420
|
+
display: block;
|
|
421
|
+
width: 100%;
|
|
422
|
+
height: 100%;
|
|
423
|
+
object-fit: cover;
|
|
424
|
+
}
|
|
425
|
+
[data-sf-reader-frame] {
|
|
426
|
+
position: absolute;
|
|
427
|
+
inset: 18%;
|
|
428
|
+
border: 3px solid #fff;
|
|
429
|
+
border-radius: 0.75rem;
|
|
430
|
+
box-shadow: 0 0 0 9999px color-mix(in srgb, #000 35%, transparent);
|
|
431
|
+
pointer-events: none;
|
|
432
|
+
}
|
|
433
|
+
[data-sf-suggested] {
|
|
434
|
+
font-weight: 600;
|
|
435
|
+
}
|
|
436
|
+
@keyframes sf-scan-rise {
|
|
437
|
+
from {
|
|
438
|
+
transform: translateY(24px);
|
|
439
|
+
opacity: 0;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
@media (prefers-reduced-motion: reduce) {
|
|
443
|
+
[data-sf-scan-sheet] {
|
|
444
|
+
animation: none;
|
|
445
|
+
}
|
|
446
|
+
}
|
package/dist/fiscal.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, RefObject } from 'react';
|
|
3
3
|
import { F as FieldErrors, a as CheckoutFieldClassNames } from './fields-vnMUi2HB.cjs';
|
|
4
4
|
import { Region, RegionFiscalId, RegionFiscalEntry, InvoiceRequest, FiscalDocumentEvidence, IdentityDocumentSpec, InvoicingCapabilities, FiscalIdentity, InvoiceSummary } from '@asteby/storefront';
|
|
5
|
-
import { f as FiscalReadError, d as FiscalFieldValues, c as FiscalFieldName, F as FiscalActionData, b as FiscalExtractionSummary } from './types-
|
|
6
|
-
export { a as FiscalErrorCode, e as FiscalIntent } from './types-
|
|
5
|
+
import { f as FiscalReadError, d as FiscalFieldValues, c as FiscalFieldName, F as FiscalActionData, b as FiscalExtractionSummary } from './types-CZ3PleG6.cjs';
|
|
6
|
+
export { a as FiscalErrorCode, e as FiscalIntent } from './types-CZ3PleG6.cjs';
|
|
7
7
|
import { IdentityExtraction } from '@asteby/storefront/fiscal-document';
|
|
8
8
|
|
|
9
9
|
/** Texts of the fiscal components. Spanish (es-MX) by default, English with `en*`, any locale with `messages`. */
|
|
@@ -30,6 +30,8 @@ type FiscalMessages = {
|
|
|
30
30
|
useChoose: string;
|
|
31
31
|
/** `{document}` = the document's name. */
|
|
32
32
|
fromDocument: string;
|
|
33
|
+
/** Mark on an invoice use the region suggested (an editable preselection). */
|
|
34
|
+
suggested: string;
|
|
33
35
|
errors: {
|
|
34
36
|
required: string;
|
|
35
37
|
taxIdFormat: string;
|
|
@@ -64,6 +66,26 @@ type FiscalMessages = {
|
|
|
64
66
|
stale: string;
|
|
65
67
|
regimeMissing: string;
|
|
66
68
|
fieldsMissing: string;
|
|
69
|
+
qrPartial: string;
|
|
70
|
+
};
|
|
71
|
+
/** Reading a photo or the camera (the region's `image_mode`). `{document}` where noted. */
|
|
72
|
+
scan: {
|
|
73
|
+
title: string;
|
|
74
|
+
photo: string;
|
|
75
|
+
photoHint: string;
|
|
76
|
+
camera: string;
|
|
77
|
+
cameraTitle: string;
|
|
78
|
+
cameraGuide: string;
|
|
79
|
+
cameraStarting: string;
|
|
80
|
+
cameraRead: string;
|
|
81
|
+
cameraDenied: string;
|
|
82
|
+
cameraUnavailable: string;
|
|
83
|
+
closeCamera: string;
|
|
84
|
+
choosePhoto: string;
|
|
85
|
+
/** Button that opens the sheet; `{document}` is the document's label. */
|
|
86
|
+
open: string;
|
|
87
|
+
manual: string;
|
|
88
|
+
close: string;
|
|
67
89
|
};
|
|
68
90
|
errors: Record<FiscalReadError, string>;
|
|
69
91
|
summaryTitleOne: string;
|
|
@@ -147,13 +169,26 @@ declare function postalCodeProblem(region: FiscalRegion, raw: string): 'required
|
|
|
147
169
|
* are not narrowed by person type (the server still checks the combination).
|
|
148
170
|
*/
|
|
149
171
|
declare function personTypeByLength(lengths: Record<string, number>): (taxId: string) => string | null;
|
|
172
|
+
/**
|
|
173
|
+
* Tells a person type from a tax id with the region's own patterns (`fiscal_id.person_patterns`, DATA of the region
|
|
174
|
+
* pack). `null` when the region publishes none or none matches. A pattern that does not compile is ignored.
|
|
175
|
+
*/
|
|
176
|
+
declare function personTypeFromPatterns(fid: RegionFiscalId | undefined, taxId: string): string | null;
|
|
177
|
+
/** The function to use for the person type: the store's override, else the region's patterns. */
|
|
178
|
+
declare function personTypeResolver(fid: RegionFiscalId | undefined, override?: (taxId: string) => string | null): (taxId: string) => string | null;
|
|
179
|
+
/**
|
|
180
|
+
* The invoice use to suggest for a regime, from region data only: the organization's `default_invoice_use` when the
|
|
181
|
+
* regime admits it, else the first use whose `suggested_for_regimes` lists the regime (and whose `allowed_regimes`
|
|
182
|
+
* admits it). `null` when the region suggests nothing: then nothing is preselected. A suggestion, never a rule.
|
|
183
|
+
*/
|
|
184
|
+
declare function suggestInvoiceUse(fid: RegionFiscalId | undefined, regime: string | null | undefined): string | null;
|
|
150
185
|
/** Regimes that fit a person type (all when the type is unknown). */
|
|
151
186
|
declare function regimesFor(fid: RegionFiscalId | undefined, personType: string | null): RegionFiscalEntry[];
|
|
152
187
|
/** Invoice uses a regime admits (all when no regime is chosen yet). */
|
|
153
188
|
declare function usesFor(fid: RegionFiscalId | undefined, regime: string | null | undefined): RegionFiscalEntry[];
|
|
154
189
|
type FiscalProblem = 'required' | 'format' | 'unknown' | 'person_type' | 'use_not_allowed';
|
|
155
190
|
/** Client-side check of the whole form against the region; the server stays the authority. */
|
|
156
|
-
declare function validateFiscalValues(region: FiscalRegion, v: Partial<FiscalFieldValues>,
|
|
191
|
+
declare function validateFiscalValues(region: FiscalRegion, v: Partial<FiscalFieldValues>, personTypeOverride?: (taxId: string) => string | null): Partial<Record<FiscalFieldName, FiscalProblem>>;
|
|
157
192
|
/** Form values -> the API's `InvoiceRequest` (without `document`). */
|
|
158
193
|
declare function toInvoiceRequest(v: Partial<FiscalFieldValues>, countryCode?: string): InvoiceRequest;
|
|
159
194
|
/** `label_en` for English locales when the region has it. */
|
|
@@ -176,8 +211,13 @@ type FiscalIdentityFieldsProps = {
|
|
|
176
211
|
namePrefix?: string;
|
|
177
212
|
/** Prefix of the control ids (default: generated). */
|
|
178
213
|
idPrefix?: string;
|
|
179
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Overrides how a person type is told from a tax id (to narrow the regimes). Default: the region's own patterns
|
|
216
|
+
* (`fiscal_id.person_patterns`); with neither, the regimes are not narrowed (the server still checks).
|
|
217
|
+
*/
|
|
180
218
|
personTypeOf?: (taxId: string) => string | null;
|
|
219
|
+
/** The invoice use in `values` came from the region's suggestion (a document was read): it gets the "Suggested" mark. */
|
|
220
|
+
suggestedUse?: string | null;
|
|
181
221
|
disabled?: boolean;
|
|
182
222
|
locale?: string;
|
|
183
223
|
messages?: DeepPartial<FiscalMessages>;
|
|
@@ -185,7 +225,7 @@ type FiscalIdentityFieldsProps = {
|
|
|
185
225
|
/** Hides the fieldset legend (when the caller already has a heading). */
|
|
186
226
|
hideLegend?: boolean;
|
|
187
227
|
};
|
|
188
|
-
declare function FiscalIdentityFields({ region, values, onChange, fromDocument, documentName, regimeCandidates, errors, namePrefix, idPrefix, personTypeOf, disabled, locale: localeProp, messages, classNames: cx, hideLegend, }: FiscalIdentityFieldsProps): react.JSX.Element;
|
|
228
|
+
declare function FiscalIdentityFields({ region, values, onChange, fromDocument, documentName, regimeCandidates, errors, namePrefix, idPrefix, personTypeOf: personTypeOverride, suggestedUse, disabled, locale: localeProp, messages, classNames: cx, hideLegend, }: FiscalIdentityFieldsProps): react.JSX.Element;
|
|
189
229
|
|
|
190
230
|
type FiscalReaderResult = {
|
|
191
231
|
values: FiscalFieldValues;
|
|
@@ -230,6 +270,50 @@ type IdentityDocumentReaderProps = {
|
|
|
230
270
|
};
|
|
231
271
|
declare function IdentityDocumentReader(props: IdentityDocumentReaderProps): react.JSX.Element | null;
|
|
232
272
|
|
|
273
|
+
type ScanTaxDocumentClassNames = IdentityDocumentReaderProps['classNames'] & Partial<Record<'actions' | 'trigger' | 'manual' | 'sheet' | 'sheetPanel' | 'sheetHeader' | 'sheetTitle' | 'sheetClose', string>>;
|
|
274
|
+
type ScanTaxDocumentProps = Omit<IdentityDocumentReaderProps, 'onConfirm' | 'onManual' | 'classNames' | 'confirmLabel'> & {
|
|
275
|
+
/** The buyer confirmed the reviewed data (the sheet is already closed). */
|
|
276
|
+
onConfirm: (result: FiscalReaderResult) => void;
|
|
277
|
+
/** The buyer chose to type their data (the sheet is already closed). */
|
|
278
|
+
onManual: () => void;
|
|
279
|
+
/** Label of the confirm button inside the sheet. */
|
|
280
|
+
confirmLabel?: ReactNode;
|
|
281
|
+
classNames?: ScanTaxDocumentClassNames;
|
|
282
|
+
};
|
|
283
|
+
declare function ScanTaxDocument(props: ScanTaxDocumentProps): react.JSX.Element | null;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Live QR reading with the device camera. Nothing is recorded or stored: the frames are read in memory by
|
|
287
|
+
* `decodeImageQr` (loaded on demand, so a page that never opens the camera pays 0 bytes for it) and the stream is
|
|
288
|
+
* stopped when the scanner closes, when the component unmounts or when the page is hidden.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
type CameraQrStatus =
|
|
292
|
+
/** Not running. */
|
|
293
|
+
'idle'
|
|
294
|
+
/** Waiting for the permission or for the first frame. */
|
|
295
|
+
| 'starting' | 'scanning'
|
|
296
|
+
/** The buyer (or the browser) refused the camera. */
|
|
297
|
+
| 'denied'
|
|
298
|
+
/** No `getUserMedia` here (old browser, insecure page). */
|
|
299
|
+
| 'unsupported';
|
|
300
|
+
type UseCameraQrOptions = {
|
|
301
|
+
/** Start (true) or stop (false) the camera. */
|
|
302
|
+
active: boolean;
|
|
303
|
+
/** The QR text read. Called once; the camera stops right after. */
|
|
304
|
+
onCode: (text: string) => void;
|
|
305
|
+
/** Milliseconds between two reading attempts (default 250). */
|
|
306
|
+
intervalMs?: number;
|
|
307
|
+
};
|
|
308
|
+
type UseCameraQr = {
|
|
309
|
+
videoRef: RefObject<HTMLVideoElement | null>;
|
|
310
|
+
status: CameraQrStatus;
|
|
311
|
+
/** Stops the stream now. */
|
|
312
|
+
stop: () => void;
|
|
313
|
+
};
|
|
314
|
+
declare function cameraSupported(): boolean;
|
|
315
|
+
declare function useCameraQr({ active, onCode, intervalMs }: UseCameraQrOptions): UseCameraQr;
|
|
316
|
+
|
|
233
317
|
type InvoiceToggleState = {
|
|
234
318
|
requested: boolean;
|
|
235
319
|
/** The data to send as `CheckoutInput.invoice` / `carts.setInvoice`; `null` when none is requested or it is not ready. */
|
|
@@ -310,4 +394,4 @@ declare function InvoiceStatusCard(props: InvoiceStatusCardProps): react.JSX.Ele
|
|
|
310
394
|
/** `evidence` comes from `buildDocumentEvidence`. Only the conventional fields are kept: nothing else can leak. */
|
|
311
395
|
declare function summarizeExtraction(x: IdentityExtraction, evidence: FiscalDocumentEvidence, validRegimes?: Iterable<string>): FiscalExtractionSummary;
|
|
312
396
|
|
|
313
|
-
export { type DeepPartial, FiscalActionData, FiscalExtractionSummary, FiscalFieldName, FiscalFieldValues, FiscalIdentityFields, type FiscalIdentityFieldsClassNames, type FiscalIdentityFieldsProps, type FiscalMessages, type FiscalProblem, FiscalReadError, type FiscalReaderResult, type FiscalRegion, IdentityDocumentReader, type IdentityDocumentReaderClassNames, type IdentityDocumentReaderProps, type InvoiceCardState, InvoiceStatusCard, type InvoiceStatusCardClassNames, type InvoiceStatusCardProps, InvoiceToggle, type InvoiceToggleClassNames, type InvoiceToggleProps, type InvoiceToggleState, entryLabel, fiscalMessages, invoiceCardState, maskTaxId, normalizeTaxId, personTypeByLength, postalCodeProblem, regimesFor, summarizeExtraction, taxIdProblem, toInvoiceRequest, usesFor, validateFiscalValues };
|
|
397
|
+
export { type CameraQrStatus, type DeepPartial, FiscalActionData, FiscalExtractionSummary, FiscalFieldName, FiscalFieldValues, FiscalIdentityFields, type FiscalIdentityFieldsClassNames, type FiscalIdentityFieldsProps, type FiscalMessages, type FiscalProblem, FiscalReadError, type FiscalReaderResult, type FiscalRegion, IdentityDocumentReader, type IdentityDocumentReaderClassNames, type IdentityDocumentReaderProps, type InvoiceCardState, InvoiceStatusCard, type InvoiceStatusCardClassNames, type InvoiceStatusCardProps, InvoiceToggle, type InvoiceToggleClassNames, type InvoiceToggleProps, type InvoiceToggleState, ScanTaxDocument, type ScanTaxDocumentClassNames, type ScanTaxDocumentProps, type UseCameraQr, type UseCameraQrOptions, cameraSupported, entryLabel, fiscalMessages, invoiceCardState, maskTaxId, normalizeTaxId, personTypeByLength, personTypeFromPatterns, personTypeResolver, postalCodeProblem, regimesFor, suggestInvoiceUse, summarizeExtraction, taxIdProblem, toInvoiceRequest, useCameraQr, usesFor, validateFiscalValues };
|
package/dist/fiscal.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, RefObject } from 'react';
|
|
3
3
|
import { F as FieldErrors, a as CheckoutFieldClassNames } from './fields-vnMUi2HB.js';
|
|
4
4
|
import { Region, RegionFiscalId, RegionFiscalEntry, InvoiceRequest, FiscalDocumentEvidence, IdentityDocumentSpec, InvoicingCapabilities, FiscalIdentity, InvoiceSummary } from '@asteby/storefront';
|
|
5
|
-
import { f as FiscalReadError, d as FiscalFieldValues, c as FiscalFieldName, F as FiscalActionData, b as FiscalExtractionSummary } from './types-
|
|
6
|
-
export { a as FiscalErrorCode, e as FiscalIntent } from './types-
|
|
5
|
+
import { f as FiscalReadError, d as FiscalFieldValues, c as FiscalFieldName, F as FiscalActionData, b as FiscalExtractionSummary } from './types-CZ3PleG6.js';
|
|
6
|
+
export { a as FiscalErrorCode, e as FiscalIntent } from './types-CZ3PleG6.js';
|
|
7
7
|
import { IdentityExtraction } from '@asteby/storefront/fiscal-document';
|
|
8
8
|
|
|
9
9
|
/** Texts of the fiscal components. Spanish (es-MX) by default, English with `en*`, any locale with `messages`. */
|
|
@@ -30,6 +30,8 @@ type FiscalMessages = {
|
|
|
30
30
|
useChoose: string;
|
|
31
31
|
/** `{document}` = the document's name. */
|
|
32
32
|
fromDocument: string;
|
|
33
|
+
/** Mark on an invoice use the region suggested (an editable preselection). */
|
|
34
|
+
suggested: string;
|
|
33
35
|
errors: {
|
|
34
36
|
required: string;
|
|
35
37
|
taxIdFormat: string;
|
|
@@ -64,6 +66,26 @@ type FiscalMessages = {
|
|
|
64
66
|
stale: string;
|
|
65
67
|
regimeMissing: string;
|
|
66
68
|
fieldsMissing: string;
|
|
69
|
+
qrPartial: string;
|
|
70
|
+
};
|
|
71
|
+
/** Reading a photo or the camera (the region's `image_mode`). `{document}` where noted. */
|
|
72
|
+
scan: {
|
|
73
|
+
title: string;
|
|
74
|
+
photo: string;
|
|
75
|
+
photoHint: string;
|
|
76
|
+
camera: string;
|
|
77
|
+
cameraTitle: string;
|
|
78
|
+
cameraGuide: string;
|
|
79
|
+
cameraStarting: string;
|
|
80
|
+
cameraRead: string;
|
|
81
|
+
cameraDenied: string;
|
|
82
|
+
cameraUnavailable: string;
|
|
83
|
+
closeCamera: string;
|
|
84
|
+
choosePhoto: string;
|
|
85
|
+
/** Button that opens the sheet; `{document}` is the document's label. */
|
|
86
|
+
open: string;
|
|
87
|
+
manual: string;
|
|
88
|
+
close: string;
|
|
67
89
|
};
|
|
68
90
|
errors: Record<FiscalReadError, string>;
|
|
69
91
|
summaryTitleOne: string;
|
|
@@ -147,13 +169,26 @@ declare function postalCodeProblem(region: FiscalRegion, raw: string): 'required
|
|
|
147
169
|
* are not narrowed by person type (the server still checks the combination).
|
|
148
170
|
*/
|
|
149
171
|
declare function personTypeByLength(lengths: Record<string, number>): (taxId: string) => string | null;
|
|
172
|
+
/**
|
|
173
|
+
* Tells a person type from a tax id with the region's own patterns (`fiscal_id.person_patterns`, DATA of the region
|
|
174
|
+
* pack). `null` when the region publishes none or none matches. A pattern that does not compile is ignored.
|
|
175
|
+
*/
|
|
176
|
+
declare function personTypeFromPatterns(fid: RegionFiscalId | undefined, taxId: string): string | null;
|
|
177
|
+
/** The function to use for the person type: the store's override, else the region's patterns. */
|
|
178
|
+
declare function personTypeResolver(fid: RegionFiscalId | undefined, override?: (taxId: string) => string | null): (taxId: string) => string | null;
|
|
179
|
+
/**
|
|
180
|
+
* The invoice use to suggest for a regime, from region data only: the organization's `default_invoice_use` when the
|
|
181
|
+
* regime admits it, else the first use whose `suggested_for_regimes` lists the regime (and whose `allowed_regimes`
|
|
182
|
+
* admits it). `null` when the region suggests nothing: then nothing is preselected. A suggestion, never a rule.
|
|
183
|
+
*/
|
|
184
|
+
declare function suggestInvoiceUse(fid: RegionFiscalId | undefined, regime: string | null | undefined): string | null;
|
|
150
185
|
/** Regimes that fit a person type (all when the type is unknown). */
|
|
151
186
|
declare function regimesFor(fid: RegionFiscalId | undefined, personType: string | null): RegionFiscalEntry[];
|
|
152
187
|
/** Invoice uses a regime admits (all when no regime is chosen yet). */
|
|
153
188
|
declare function usesFor(fid: RegionFiscalId | undefined, regime: string | null | undefined): RegionFiscalEntry[];
|
|
154
189
|
type FiscalProblem = 'required' | 'format' | 'unknown' | 'person_type' | 'use_not_allowed';
|
|
155
190
|
/** Client-side check of the whole form against the region; the server stays the authority. */
|
|
156
|
-
declare function validateFiscalValues(region: FiscalRegion, v: Partial<FiscalFieldValues>,
|
|
191
|
+
declare function validateFiscalValues(region: FiscalRegion, v: Partial<FiscalFieldValues>, personTypeOverride?: (taxId: string) => string | null): Partial<Record<FiscalFieldName, FiscalProblem>>;
|
|
157
192
|
/** Form values -> the API's `InvoiceRequest` (without `document`). */
|
|
158
193
|
declare function toInvoiceRequest(v: Partial<FiscalFieldValues>, countryCode?: string): InvoiceRequest;
|
|
159
194
|
/** `label_en` for English locales when the region has it. */
|
|
@@ -176,8 +211,13 @@ type FiscalIdentityFieldsProps = {
|
|
|
176
211
|
namePrefix?: string;
|
|
177
212
|
/** Prefix of the control ids (default: generated). */
|
|
178
213
|
idPrefix?: string;
|
|
179
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Overrides how a person type is told from a tax id (to narrow the regimes). Default: the region's own patterns
|
|
216
|
+
* (`fiscal_id.person_patterns`); with neither, the regimes are not narrowed (the server still checks).
|
|
217
|
+
*/
|
|
180
218
|
personTypeOf?: (taxId: string) => string | null;
|
|
219
|
+
/** The invoice use in `values` came from the region's suggestion (a document was read): it gets the "Suggested" mark. */
|
|
220
|
+
suggestedUse?: string | null;
|
|
181
221
|
disabled?: boolean;
|
|
182
222
|
locale?: string;
|
|
183
223
|
messages?: DeepPartial<FiscalMessages>;
|
|
@@ -185,7 +225,7 @@ type FiscalIdentityFieldsProps = {
|
|
|
185
225
|
/** Hides the fieldset legend (when the caller already has a heading). */
|
|
186
226
|
hideLegend?: boolean;
|
|
187
227
|
};
|
|
188
|
-
declare function FiscalIdentityFields({ region, values, onChange, fromDocument, documentName, regimeCandidates, errors, namePrefix, idPrefix, personTypeOf, disabled, locale: localeProp, messages, classNames: cx, hideLegend, }: FiscalIdentityFieldsProps): react.JSX.Element;
|
|
228
|
+
declare function FiscalIdentityFields({ region, values, onChange, fromDocument, documentName, regimeCandidates, errors, namePrefix, idPrefix, personTypeOf: personTypeOverride, suggestedUse, disabled, locale: localeProp, messages, classNames: cx, hideLegend, }: FiscalIdentityFieldsProps): react.JSX.Element;
|
|
189
229
|
|
|
190
230
|
type FiscalReaderResult = {
|
|
191
231
|
values: FiscalFieldValues;
|
|
@@ -230,6 +270,50 @@ type IdentityDocumentReaderProps = {
|
|
|
230
270
|
};
|
|
231
271
|
declare function IdentityDocumentReader(props: IdentityDocumentReaderProps): react.JSX.Element | null;
|
|
232
272
|
|
|
273
|
+
type ScanTaxDocumentClassNames = IdentityDocumentReaderProps['classNames'] & Partial<Record<'actions' | 'trigger' | 'manual' | 'sheet' | 'sheetPanel' | 'sheetHeader' | 'sheetTitle' | 'sheetClose', string>>;
|
|
274
|
+
type ScanTaxDocumentProps = Omit<IdentityDocumentReaderProps, 'onConfirm' | 'onManual' | 'classNames' | 'confirmLabel'> & {
|
|
275
|
+
/** The buyer confirmed the reviewed data (the sheet is already closed). */
|
|
276
|
+
onConfirm: (result: FiscalReaderResult) => void;
|
|
277
|
+
/** The buyer chose to type their data (the sheet is already closed). */
|
|
278
|
+
onManual: () => void;
|
|
279
|
+
/** Label of the confirm button inside the sheet. */
|
|
280
|
+
confirmLabel?: ReactNode;
|
|
281
|
+
classNames?: ScanTaxDocumentClassNames;
|
|
282
|
+
};
|
|
283
|
+
declare function ScanTaxDocument(props: ScanTaxDocumentProps): react.JSX.Element | null;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Live QR reading with the device camera. Nothing is recorded or stored: the frames are read in memory by
|
|
287
|
+
* `decodeImageQr` (loaded on demand, so a page that never opens the camera pays 0 bytes for it) and the stream is
|
|
288
|
+
* stopped when the scanner closes, when the component unmounts or when the page is hidden.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
type CameraQrStatus =
|
|
292
|
+
/** Not running. */
|
|
293
|
+
'idle'
|
|
294
|
+
/** Waiting for the permission or for the first frame. */
|
|
295
|
+
| 'starting' | 'scanning'
|
|
296
|
+
/** The buyer (or the browser) refused the camera. */
|
|
297
|
+
| 'denied'
|
|
298
|
+
/** No `getUserMedia` here (old browser, insecure page). */
|
|
299
|
+
| 'unsupported';
|
|
300
|
+
type UseCameraQrOptions = {
|
|
301
|
+
/** Start (true) or stop (false) the camera. */
|
|
302
|
+
active: boolean;
|
|
303
|
+
/** The QR text read. Called once; the camera stops right after. */
|
|
304
|
+
onCode: (text: string) => void;
|
|
305
|
+
/** Milliseconds between two reading attempts (default 250). */
|
|
306
|
+
intervalMs?: number;
|
|
307
|
+
};
|
|
308
|
+
type UseCameraQr = {
|
|
309
|
+
videoRef: RefObject<HTMLVideoElement | null>;
|
|
310
|
+
status: CameraQrStatus;
|
|
311
|
+
/** Stops the stream now. */
|
|
312
|
+
stop: () => void;
|
|
313
|
+
};
|
|
314
|
+
declare function cameraSupported(): boolean;
|
|
315
|
+
declare function useCameraQr({ active, onCode, intervalMs }: UseCameraQrOptions): UseCameraQr;
|
|
316
|
+
|
|
233
317
|
type InvoiceToggleState = {
|
|
234
318
|
requested: boolean;
|
|
235
319
|
/** The data to send as `CheckoutInput.invoice` / `carts.setInvoice`; `null` when none is requested or it is not ready. */
|
|
@@ -310,4 +394,4 @@ declare function InvoiceStatusCard(props: InvoiceStatusCardProps): react.JSX.Ele
|
|
|
310
394
|
/** `evidence` comes from `buildDocumentEvidence`. Only the conventional fields are kept: nothing else can leak. */
|
|
311
395
|
declare function summarizeExtraction(x: IdentityExtraction, evidence: FiscalDocumentEvidence, validRegimes?: Iterable<string>): FiscalExtractionSummary;
|
|
312
396
|
|
|
313
|
-
export { type DeepPartial, FiscalActionData, FiscalExtractionSummary, FiscalFieldName, FiscalFieldValues, FiscalIdentityFields, type FiscalIdentityFieldsClassNames, type FiscalIdentityFieldsProps, type FiscalMessages, type FiscalProblem, FiscalReadError, type FiscalReaderResult, type FiscalRegion, IdentityDocumentReader, type IdentityDocumentReaderClassNames, type IdentityDocumentReaderProps, type InvoiceCardState, InvoiceStatusCard, type InvoiceStatusCardClassNames, type InvoiceStatusCardProps, InvoiceToggle, type InvoiceToggleClassNames, type InvoiceToggleProps, type InvoiceToggleState, entryLabel, fiscalMessages, invoiceCardState, maskTaxId, normalizeTaxId, personTypeByLength, postalCodeProblem, regimesFor, summarizeExtraction, taxIdProblem, toInvoiceRequest, usesFor, validateFiscalValues };
|
|
397
|
+
export { type CameraQrStatus, type DeepPartial, FiscalActionData, FiscalExtractionSummary, FiscalFieldName, FiscalFieldValues, FiscalIdentityFields, type FiscalIdentityFieldsClassNames, type FiscalIdentityFieldsProps, type FiscalMessages, type FiscalProblem, FiscalReadError, type FiscalReaderResult, type FiscalRegion, IdentityDocumentReader, type IdentityDocumentReaderClassNames, type IdentityDocumentReaderProps, type InvoiceCardState, InvoiceStatusCard, type InvoiceStatusCardClassNames, type InvoiceStatusCardProps, InvoiceToggle, type InvoiceToggleClassNames, type InvoiceToggleProps, type InvoiceToggleState, ScanTaxDocument, type ScanTaxDocumentClassNames, type ScanTaxDocumentProps, type UseCameraQr, type UseCameraQrOptions, cameraSupported, entryLabel, fiscalMessages, invoiceCardState, maskTaxId, normalizeTaxId, personTypeByLength, personTypeFromPatterns, personTypeResolver, postalCodeProblem, regimesFor, suggestInvoiceUse, summarizeExtraction, taxIdProblem, toInvoiceRequest, useCameraQr, usesFor, validateFiscalValues };
|