@asteby/storefront-react 0.23.0 → 0.25.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/fiscal.d.cts CHANGED
@@ -2,8 +2,8 @@ import * as react from 'react';
2
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-CZ3PleG6.cjs';
6
- export { a as FiscalErrorCode, e as FiscalIntent } from './types-CZ3PleG6.cjs';
5
+ import { f as FiscalReadError, d as FiscalFieldValues, c as FiscalFieldName, F as FiscalActionData, g as FiscalReason, b as FiscalExtractionSummary } from './types-Cgx_65eM.cjs';
6
+ export { a as FiscalErrorCode, e as FiscalIntent } from './types-Cgx_65eM.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`. */
@@ -136,6 +136,17 @@ type FiscalMessages = {
136
136
  windowBody: string;
137
137
  unavailableTitle: string;
138
138
  unavailableBody: string;
139
+ /** The server says the store has no invoicing active (`capabilities.invoicing.available: false`). */
140
+ notEnabledTitle: string;
141
+ notEnabledBody: string;
142
+ /** The server does not say (older server) or could not be asked: never claims the store does not invoice. */
143
+ unknownTitle: string;
144
+ unknownBody: string;
145
+ unreachableBody: string;
146
+ /** Invoicing in test mode (sandbox): invoices have no fiscal validity. */
147
+ sandbox: string;
148
+ /** `{days}`: how long after the purchase an invoice can be requested. */
149
+ windowNote: string;
139
150
  cancelledTitle: string;
140
151
  cancelledBody: string;
141
152
  /** `reason_code` -> cause for the buyer. `default` when unknown. */
@@ -357,14 +368,28 @@ type InvoiceToggleProps = {
357
368
  };
358
369
  declare function InvoiceToggle(props: InvoiceToggleProps): react.JSX.Element | null;
359
370
 
360
- type InvoiceCardState = 'not_requested' | 'awaiting_payment' | 'processing' | 'issued' | 'needs_data' | 'needs_review' | 'window_closed' | 'unavailable' | 'cancelled';
361
- /** Which of the card's states an invoice is in. `available: false` (the store does not invoice) wins over everything. */
362
- declare function invoiceCardState(invoice: InvoiceSummary | null | undefined, available?: boolean): InvoiceCardState;
371
+ type InvoiceCardState = 'not_requested' | 'awaiting_payment' | 'processing' | 'issued' | 'needs_data' | 'needs_review' | 'window_closed' | 'unavailable' | 'not_enabled' | 'unknown' | 'unreachable' | 'cancelled';
372
+ /**
373
+ * Which of the card's states an invoice is in.
374
+ *
375
+ * `available` / `reason` come from `loadFiscalContext`. Only a server that SAYS the store does not invoice
376
+ * (`reason` `off` / `no_region`) wins over the order: `not_enabled`. When the server says nothing (`unknown`, an older
377
+ * server), could not be asked (`unreachable`) or the caller gave no `reason`, the order's own summary still decides
378
+ * (an order that `can_request`, is being issued or already has its invoice is shown as such) and, with nothing to show,
379
+ * the card is neutral: it never claims that the store does not issue invoices.
380
+ */
381
+ declare function invoiceCardState(invoice: InvoiceSummary | null | undefined, available?: boolean, reason?: FiscalReason): InvoiceCardState;
363
382
  type InvoiceStatusCardClassNames = Partial<Record<'root' | 'title' | 'body' | 'actions' | 'primary' | 'secondary' | 'link' | 'meta', string>>;
364
383
  type InvoiceStatusCardProps = {
365
384
  invoice?: InvoiceSummary | null;
366
- /** `capabilities.invoicing.available`. `false`: "Invoice not available". */
385
+ /** `loadFiscalContext(...).available`. `false` alone is read as "unknown": see `availability`. */
367
386
  available?: boolean;
387
+ /** `loadFiscalContext(...).reason`: why it is (not) available. Lets the card say the true thing (not active / unknown / could not check). */
388
+ availability?: FiscalReason;
389
+ /** Invoicing is in test mode (sandbox): shows a badge saying invoices have no fiscal validity. */
390
+ testMode?: boolean;
391
+ /** `capabilities.invoicing.window_days`: shown next to the request button. */
392
+ windowDays?: number;
368
393
  /** The buyer taps "Request invoice". Shown when `invoice.can_request !== false`. Without it, `requestHref` is a link. */
369
394
  onRequest?: () => void;
370
395
  requestHref?: string;
package/dist/fiscal.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as react from 'react';
2
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-CZ3PleG6.js';
6
- export { a as FiscalErrorCode, e as FiscalIntent } from './types-CZ3PleG6.js';
5
+ import { f as FiscalReadError, d as FiscalFieldValues, c as FiscalFieldName, F as FiscalActionData, g as FiscalReason, b as FiscalExtractionSummary } from './types-Cgx_65eM.js';
6
+ export { a as FiscalErrorCode, e as FiscalIntent } from './types-Cgx_65eM.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`. */
@@ -136,6 +136,17 @@ type FiscalMessages = {
136
136
  windowBody: string;
137
137
  unavailableTitle: string;
138
138
  unavailableBody: string;
139
+ /** The server says the store has no invoicing active (`capabilities.invoicing.available: false`). */
140
+ notEnabledTitle: string;
141
+ notEnabledBody: string;
142
+ /** The server does not say (older server) or could not be asked: never claims the store does not invoice. */
143
+ unknownTitle: string;
144
+ unknownBody: string;
145
+ unreachableBody: string;
146
+ /** Invoicing in test mode (sandbox): invoices have no fiscal validity. */
147
+ sandbox: string;
148
+ /** `{days}`: how long after the purchase an invoice can be requested. */
149
+ windowNote: string;
139
150
  cancelledTitle: string;
140
151
  cancelledBody: string;
141
152
  /** `reason_code` -> cause for the buyer. `default` when unknown. */
@@ -357,14 +368,28 @@ type InvoiceToggleProps = {
357
368
  };
358
369
  declare function InvoiceToggle(props: InvoiceToggleProps): react.JSX.Element | null;
359
370
 
360
- type InvoiceCardState = 'not_requested' | 'awaiting_payment' | 'processing' | 'issued' | 'needs_data' | 'needs_review' | 'window_closed' | 'unavailable' | 'cancelled';
361
- /** Which of the card's states an invoice is in. `available: false` (the store does not invoice) wins over everything. */
362
- declare function invoiceCardState(invoice: InvoiceSummary | null | undefined, available?: boolean): InvoiceCardState;
371
+ type InvoiceCardState = 'not_requested' | 'awaiting_payment' | 'processing' | 'issued' | 'needs_data' | 'needs_review' | 'window_closed' | 'unavailable' | 'not_enabled' | 'unknown' | 'unreachable' | 'cancelled';
372
+ /**
373
+ * Which of the card's states an invoice is in.
374
+ *
375
+ * `available` / `reason` come from `loadFiscalContext`. Only a server that SAYS the store does not invoice
376
+ * (`reason` `off` / `no_region`) wins over the order: `not_enabled`. When the server says nothing (`unknown`, an older
377
+ * server), could not be asked (`unreachable`) or the caller gave no `reason`, the order's own summary still decides
378
+ * (an order that `can_request`, is being issued or already has its invoice is shown as such) and, with nothing to show,
379
+ * the card is neutral: it never claims that the store does not issue invoices.
380
+ */
381
+ declare function invoiceCardState(invoice: InvoiceSummary | null | undefined, available?: boolean, reason?: FiscalReason): InvoiceCardState;
363
382
  type InvoiceStatusCardClassNames = Partial<Record<'root' | 'title' | 'body' | 'actions' | 'primary' | 'secondary' | 'link' | 'meta', string>>;
364
383
  type InvoiceStatusCardProps = {
365
384
  invoice?: InvoiceSummary | null;
366
- /** `capabilities.invoicing.available`. `false`: "Invoice not available". */
385
+ /** `loadFiscalContext(...).available`. `false` alone is read as "unknown": see `availability`. */
367
386
  available?: boolean;
387
+ /** `loadFiscalContext(...).reason`: why it is (not) available. Lets the card say the true thing (not active / unknown / could not check). */
388
+ availability?: FiscalReason;
389
+ /** Invoicing is in test mode (sandbox): shows a badge saying invoices have no fiscal validity. */
390
+ testMode?: boolean;
391
+ /** `capabilities.invoicing.window_days`: shown next to the request button. */
392
+ windowDays?: number;
368
393
  /** The buyer taps "Request invoice". Shown when `invoice.can_request !== false`. Without it, `requestHref` is a link. */
369
394
  onRequest?: () => void;
370
395
  requestHref?: string;
package/dist/fiscal.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { personTypeResolver, validateFiscalValues, regimesFor, usesFor, normalizeTaxId, entryLabel, suggestInvoiceUse, summarizeExtraction, toInvoiceRequest, maskTaxId } from './chunk-D5L7UZIA.js';
2
2
  export { entryLabel, maskTaxId, normalizeTaxId, personTypeByLength, personTypeFromPatterns, personTypeResolver, postalCodeProblem, regimesFor, suggestInvoiceUse, summarizeExtraction, taxIdProblem, toInvoiceRequest, usesFor, validateFiscalValues } from './chunk-D5L7UZIA.js';
3
3
  import { useModalDialog } from './chunk-ZBH7JYU4.js';
4
- import { fiscalMessages, fill } from './chunk-VE7WQPMY.js';
5
- export { fiscalMessages } from './chunk-VE7WQPMY.js';
4
+ import { fiscalMessages, fill } from './chunk-5XYQLOE3.js';
5
+ export { fiscalMessages } from './chunk-5XYQLOE3.js';
6
6
  import { CheckoutField, ErrorSummary } from './chunk-DFGLCIEG.js';
7
7
  import { useResolvedLocale } from './chunk-T52H5HL3.js';
8
8
  import './chunk-DQBL2DFJ.js';
@@ -988,8 +988,7 @@ function labelOf(list, code, locale) {
988
988
  const e = list?.find((x) => x.code === code);
989
989
  return e ? `${e.code} \xB7 ${entryLabel(e, locale)}` : code;
990
990
  }
991
- function invoiceCardState(invoice, available = true) {
992
- if (!available) return "unavailable";
991
+ function orderState(invoice) {
993
992
  if (!invoice) return "not_requested";
994
993
  const stage = invoice.stage ?? "";
995
994
  const blocked = invoice.blocked_reason ?? "";
@@ -1004,11 +1003,18 @@ function invoiceCardState(invoice, available = true) {
1004
1003
  if (invoice.can_request === false && blocked) return "unavailable";
1005
1004
  return "not_requested";
1006
1005
  }
1006
+ function invoiceCardState(invoice, available = true, reason) {
1007
+ if (available) return orderState(invoice);
1008
+ if (reason === "off" || reason === "no_region") return "not_enabled";
1009
+ const own = orderState(invoice);
1010
+ if (invoice && (own !== "not_requested" || invoice.can_request === true || invoice.action === "request")) return own;
1011
+ return reason === "unreachable" ? "unreachable" : "unknown";
1012
+ }
1007
1013
  function InvoiceStatusCard(props) {
1008
- const { invoice, available = true, onRequest, requestHref, onCorrect, correctHref, onRefresh, refreshMs = 1e4, refreshForMs = 6e4, contact, messages, classNames: cx = {}, headingLevel = 3 } = props;
1014
+ const { invoice, available = true, availability, testMode, windowDays, onRequest, requestHref, onCorrect, correctHref, onRefresh, refreshMs = 1e4, refreshForMs = 6e4, contact, messages, classNames: cx = {}, headingLevel = 3 } = props;
1009
1015
  const locale = useResolvedLocale(props.locale);
1010
1016
  const m = fiscalMessages(locale, messages).status;
1011
- const state = invoiceCardState(invoice, available);
1017
+ const state = invoiceCardState(invoice, available, availability);
1012
1018
  const titleId = `sf-invoice-card-${useId().replace(/:/g, "")}`;
1013
1019
  const [tired, setTired] = useState(false);
1014
1020
  const refresh = useRef(onRefresh);
@@ -1041,7 +1047,10 @@ function InvoiceStatusCard(props) {
1041
1047
  switch (state) {
1042
1048
  case "not_requested": {
1043
1049
  title = m.title;
1044
- body = /* @__PURE__ */ jsx("p", { className: cx.body, children: m.requestHelp });
1050
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
1051
+ /* @__PURE__ */ jsx("p", { className: cx.body, children: m.requestHelp }),
1052
+ windowDays && windowDays > 0 ? /* @__PURE__ */ jsx("p", { className: cx.meta, "data-sf-invoice-window": true, children: fill(m.windowNote, { days: windowDays }) }) : null
1053
+ ] });
1045
1054
  const can = invoice?.can_request !== false;
1046
1055
  if (can && (onRequest || requestHref)) {
1047
1056
  actions = onRequest ? /* @__PURE__ */ jsx("button", { type: "button", className: cx.primary, onClick: onRequest, "data-sf-invoice-request": true, children: m.request }) : /* @__PURE__ */ jsx("a", { href: requestHref, className: cx.primary, "data-sf-invoice-request": true, children: m.request });
@@ -1099,6 +1108,18 @@ function InvoiceStatusCard(props) {
1099
1108
  title = m.cancelledTitle;
1100
1109
  body = /* @__PURE__ */ jsx("p", { className: cx.body, children: m.cancelledBody });
1101
1110
  break;
1111
+ case "not_enabled":
1112
+ case "unknown":
1113
+ case "unreachable": {
1114
+ title = state === "not_enabled" ? m.notEnabledTitle : m.unknownTitle;
1115
+ body = /* @__PURE__ */ jsx("p", { className: cx.body, children: state === "not_enabled" ? m.notEnabledBody : state === "unreachable" ? m.unreachableBody : m.unknownBody });
1116
+ const mail = contact?.url ?? (contact?.email ? `mailto:${contact.email}` : null);
1117
+ actions = /* @__PURE__ */ jsxs(Fragment, { children: [
1118
+ state === "unreachable" && onRefresh ? /* @__PURE__ */ jsx("button", { type: "button", className: cx.secondary, onClick: manualRefresh, "data-sf-invoice-refresh": true, children: m.refresh }) : null,
1119
+ mail ? /* @__PURE__ */ jsx("a", { href: mail, className: cx.secondary, "data-sf-invoice-contact": true, children: m.contact }) : null
1120
+ ] });
1121
+ break;
1122
+ }
1102
1123
  default:
1103
1124
  title = m.unavailableTitle;
1104
1125
  body = /* @__PURE__ */ jsx("p", { className: cx.body, children: m.unavailableBody });
@@ -1110,6 +1131,7 @@ function InvoiceStatusCard(props) {
1110
1131
  title
1111
1132
  ] }),
1112
1133
  /* @__PURE__ */ jsx("div", { "aria-live": live || state === "issued" ? "polite" : void 0, "data-sf-invoice-live": true, children: body }),
1134
+ testMode ? /* @__PURE__ */ jsx("p", { className: cx.meta, "data-sf-invoice-sandbox": true, children: m.sandbox }) : null,
1113
1135
  actions ? /* @__PURE__ */ jsx("div", { className: cx.actions, "data-sf-invoice-actions": true, children: actions }) : null
1114
1136
  ] });
1115
1137
  }
@@ -1122,6 +1144,9 @@ var ICON = {
1122
1144
  needs_review: "\u25D0",
1123
1145
  window_closed: "\u2013",
1124
1146
  unavailable: "\u2013",
1147
+ not_enabled: "\u2013",
1148
+ unknown: "?",
1149
+ unreachable: "?",
1125
1150
  cancelled: "\xD7"
1126
1151
  };
1127
1152