@reblu/site-blocks 0.30.0 → 0.31.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.
@@ -0,0 +1,140 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ShopCheckoutCopy, ShopCheckoutInput, ShopBillingInput } from '@reblu/site-contracts';
3
+
4
+ /** A heading level a caller can configure — `h1`…`h6`. */
5
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
6
+
7
+ /**
8
+ * `CheckoutTermsAcceptance` (REB-1198) — the mandatory, unticked box «He leído
9
+ * y acepto las {terms} de {tenant}» of the single-step checkout. Every text is
10
+ * the tenant's (`ShopConfig.checkout`, edited in nexus › Configuración ›
11
+ * Legal): `{terms}` becomes the link to the full document (text
12
+ * `termsLinkText`, target `termsLinkUrl` or the SITE's own `termsHref`, a new
13
+ * tab when `isTermsLinkNewTab`), `{tenant}` the site name. A label without
14
+ * `{terms}` gets the link appended.
15
+ *
16
+ * Renders nothing while the tenant has published no terms
17
+ * (`termsVersion: null`): there is nothing to accept and checkout does not
18
+ * ask. Send {@link toCheckoutTermsFields} with the checkout body; the server
19
+ * refuses without it (`TERMS_NOT_ACCEPTED`) or with an old version
20
+ * (`TERMS_VERSION_CHANGED`: reload the config and ask again).
21
+ */
22
+ type CheckoutTermsCopy = Pick<ShopCheckoutCopy, 'tenantName' | 'termsCheckboxLabel' | 'termsLinkText' | 'termsLinkUrl' | 'isTermsLinkNewTab' | 'termsVersion'>;
23
+ interface CheckoutTermsAcceptanceProps {
24
+ copy: CheckoutTermsCopy;
25
+ /** The SITE's route to its terms page, used when the tenant set no `termsLinkUrl`. */
26
+ termsHref: string;
27
+ checked: boolean;
28
+ onCheckedChange: (checked: boolean) => void;
29
+ /** E.g. «Debes aceptar las condiciones para continuar.» (the SITE's or the API's text). */
30
+ error?: string | null;
31
+ /** Appended inside the link when it opens a new tab (screen readers). @default '(se abre en una pestaña nueva)' */
32
+ newTabHint?: string;
33
+ /** The checkbox id (one box per page). @default 'checkout-terms' */
34
+ id?: string;
35
+ className?: string;
36
+ }
37
+ declare function CheckoutTermsAcceptance({ copy, termsHref, checked, onCheckedChange, error, newTabHint, id, className, }: CheckoutTermsAcceptanceProps): react_jsx_runtime.JSX.Element | null;
38
+ /**
39
+ * The checkout body fields for the terms box: `acceptsTerms` and the version
40
+ * shown (`termsVersionId`), or nothing when the tenant published no terms.
41
+ */
42
+ declare function toCheckoutTermsFields(copy: Pick<ShopCheckoutCopy, 'termsVersion'> | null | undefined, accepted: boolean): Pick<ShopCheckoutInput, 'acceptsTerms' | 'termsVersionId'>;
43
+
44
+ /**
45
+ * `FullInvoiceFields` — the shop checkout's full-invoice request, drop-in
46
+ * (REB-73). Fully controlled (`value`/`onChange`), no hooks, no fetch: the
47
+ * SITE owns the state and sends `toCheckoutInvoiceFields(value, overCap)`
48
+ * with its checkout body.
49
+ *
50
+ * The rule it presents (owner decision 15-Oct-2026): «Si quieren factura
51
+ * completa, si o si deben aportar el NIF, si no lo aportan se emite factura
52
+ * simplificada». The identifier is a Spanish NIF/NIE/CIF or, for a foreign
53
+ * buyer, an EU VAT id, a passport or an ID document of their country — with
54
+ * the country that issued it. Over the shop's simplified-invoice cap
55
+ * (`ShopConfig.simplifiedInvoiceCapCents`, see `isOverSimplifiedInvoiceCap`)
56
+ * a full invoice is the only legal one: pass `overCap` and the fields become
57
+ * required, without a toggle. The server validates the identifier and
58
+ * refuses with `BILLING_DATA_REQUIRED` what this form cannot prevent.
59
+ *
60
+ * A shop that issues no invoices (`ShopConfig.simplifiedInvoiceCapCents` is
61
+ * `null`, see `shopIssuesInvoices`) offers no opt-in: pass
62
+ * `issuesInvoices={false}` and the block renders nothing — the server would
63
+ * refuse `wantsFullInvoice: true` with `FULL_INVOICE_UNAVAILABLE`.
64
+ */
65
+ type FullInvoiceIdType = NonNullable<ShopBillingInput['billingIdType']>;
66
+ interface FullInvoiceValue {
67
+ wantsFullInvoice: boolean;
68
+ billingIdType: FullInvoiceIdType;
69
+ /** ISO 3166-1 alpha-2 country that issued a foreign document. */
70
+ billingIdCountry: string;
71
+ billingNif: string;
72
+ billingName: string;
73
+ street: string;
74
+ postalCode: string;
75
+ city: string;
76
+ /** ISO 3166-1 alpha-2 country of the billing address. */
77
+ country: string;
78
+ }
79
+ declare const EMPTY_FULL_INVOICE_VALUE: FullInvoiceValue;
80
+ type FullInvoiceErrors = Partial<Record<'billingIdType' | 'billingIdCountry' | 'billingNif' | 'billingName' | 'address', string>>;
81
+ interface FullInvoiceFieldsLabels {
82
+ toggle: string;
83
+ underCapNotice: string;
84
+ overCapNotice: string;
85
+ idType: string;
86
+ idCountry: string;
87
+ chooseCountry: string;
88
+ spanishNif: string;
89
+ documentNumber: string;
90
+ name: string;
91
+ street: string;
92
+ postalCode: string;
93
+ city: string;
94
+ country: string;
95
+ idTypeOptions: Record<FullInvoiceIdType, string>;
96
+ }
97
+ /** ISO 3166-1 alpha-2 countries offered by default: Spain, the EU and frequent others. */
98
+ declare const DEFAULT_INVOICE_COUNTRIES: ReadonlyArray<{
99
+ code: string;
100
+ name: string;
101
+ }>;
102
+ /**
103
+ * Whether the shop issues invoices at all, read from the field the contract
104
+ * defines for it: `ShopConfig.simplifiedInvoiceCapCents` is the effective cap
105
+ * while invoicing is on and `null` otherwise (absent on an older base-api,
106
+ * which accepts no opt-in either).
107
+ */
108
+ declare function shopIssuesInvoices(config: {
109
+ simplifiedInvoiceCapCents?: number | null;
110
+ }): boolean;
111
+ /** Whether a cart total (cents) is over the shop's simplified-invoice cap; `null` cap = no gate. */
112
+ declare function isOverSimplifiedInvoiceCap(totalCents: number, capCents: number | null): boolean;
113
+ /**
114
+ * The checkout body fields for the request: `wantsFullInvoice` and the
115
+ * `billing` block (identifier, its type and country, name and address). Empty
116
+ * when the buyer asks for no full invoice within the cap, and always empty
117
+ * when the shop issues no invoices (`issuesInvoices` false).
118
+ */
119
+ declare function toCheckoutInvoiceFields(value: FullInvoiceValue, overCap: boolean, issuesInvoices?: boolean): Pick<ShopCheckoutInput, 'wantsFullInvoice' | 'billing'>;
120
+ interface FullInvoiceFieldsProps {
121
+ value: FullInvoiceValue;
122
+ onChange: (next: FullInvoiceValue) => void;
123
+ /** The cart total is over `ShopConfig.simplifiedInvoiceCapCents`. */
124
+ overCap: boolean;
125
+ /**
126
+ * `false` when the shop issues no invoices (`shopIssuesInvoices(config)`):
127
+ * the block renders nothing. Defaults to `true`.
128
+ */
129
+ issuesInvoices?: boolean;
130
+ errors?: FullInvoiceErrors;
131
+ countries?: ReadonlyArray<{
132
+ code: string;
133
+ name: string;
134
+ }>;
135
+ labels?: Partial<FullInvoiceFieldsLabels>;
136
+ className?: string;
137
+ }
138
+ declare function FullInvoiceFields({ value, onChange, overCap, issuesInvoices, errors, countries, labels, className, }: FullInvoiceFieldsProps): react_jsx_runtime.JSX.Element | null;
139
+
140
+ export { type CheckoutTermsCopy as C, DEFAULT_INVOICE_COUNTRIES as D, EMPTY_FULL_INVOICE_VALUE as E, type FullInvoiceFieldsLabels as F, type HeadingLevel as H, type FullInvoiceValue as a, CheckoutTermsAcceptance as b, type CheckoutTermsAcceptanceProps as c, type FullInvoiceErrors as d, FullInvoiceFields as e, type FullInvoiceFieldsProps as f, type FullInvoiceIdType as g, toCheckoutTermsFields as h, isOverSimplifiedInvoiceCap as i, shopIssuesInvoices as s, toCheckoutInvoiceFields as t };
@@ -0,0 +1,140 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ShopCheckoutCopy, ShopCheckoutInput, ShopBillingInput } from '@reblu/site-contracts';
3
+
4
+ /** A heading level a caller can configure — `h1`…`h6`. */
5
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
6
+
7
+ /**
8
+ * `CheckoutTermsAcceptance` (REB-1198) — the mandatory, unticked box «He leído
9
+ * y acepto las {terms} de {tenant}» of the single-step checkout. Every text is
10
+ * the tenant's (`ShopConfig.checkout`, edited in nexus › Configuración ›
11
+ * Legal): `{terms}` becomes the link to the full document (text
12
+ * `termsLinkText`, target `termsLinkUrl` or the SITE's own `termsHref`, a new
13
+ * tab when `isTermsLinkNewTab`), `{tenant}` the site name. A label without
14
+ * `{terms}` gets the link appended.
15
+ *
16
+ * Renders nothing while the tenant has published no terms
17
+ * (`termsVersion: null`): there is nothing to accept and checkout does not
18
+ * ask. Send {@link toCheckoutTermsFields} with the checkout body; the server
19
+ * refuses without it (`TERMS_NOT_ACCEPTED`) or with an old version
20
+ * (`TERMS_VERSION_CHANGED`: reload the config and ask again).
21
+ */
22
+ type CheckoutTermsCopy = Pick<ShopCheckoutCopy, 'tenantName' | 'termsCheckboxLabel' | 'termsLinkText' | 'termsLinkUrl' | 'isTermsLinkNewTab' | 'termsVersion'>;
23
+ interface CheckoutTermsAcceptanceProps {
24
+ copy: CheckoutTermsCopy;
25
+ /** The SITE's route to its terms page, used when the tenant set no `termsLinkUrl`. */
26
+ termsHref: string;
27
+ checked: boolean;
28
+ onCheckedChange: (checked: boolean) => void;
29
+ /** E.g. «Debes aceptar las condiciones para continuar.» (the SITE's or the API's text). */
30
+ error?: string | null;
31
+ /** Appended inside the link when it opens a new tab (screen readers). @default '(se abre en una pestaña nueva)' */
32
+ newTabHint?: string;
33
+ /** The checkbox id (one box per page). @default 'checkout-terms' */
34
+ id?: string;
35
+ className?: string;
36
+ }
37
+ declare function CheckoutTermsAcceptance({ copy, termsHref, checked, onCheckedChange, error, newTabHint, id, className, }: CheckoutTermsAcceptanceProps): react_jsx_runtime.JSX.Element | null;
38
+ /**
39
+ * The checkout body fields for the terms box: `acceptsTerms` and the version
40
+ * shown (`termsVersionId`), or nothing when the tenant published no terms.
41
+ */
42
+ declare function toCheckoutTermsFields(copy: Pick<ShopCheckoutCopy, 'termsVersion'> | null | undefined, accepted: boolean): Pick<ShopCheckoutInput, 'acceptsTerms' | 'termsVersionId'>;
43
+
44
+ /**
45
+ * `FullInvoiceFields` — the shop checkout's full-invoice request, drop-in
46
+ * (REB-73). Fully controlled (`value`/`onChange`), no hooks, no fetch: the
47
+ * SITE owns the state and sends `toCheckoutInvoiceFields(value, overCap)`
48
+ * with its checkout body.
49
+ *
50
+ * The rule it presents (owner decision 15-Oct-2026): «Si quieren factura
51
+ * completa, si o si deben aportar el NIF, si no lo aportan se emite factura
52
+ * simplificada». The identifier is a Spanish NIF/NIE/CIF or, for a foreign
53
+ * buyer, an EU VAT id, a passport or an ID document of their country — with
54
+ * the country that issued it. Over the shop's simplified-invoice cap
55
+ * (`ShopConfig.simplifiedInvoiceCapCents`, see `isOverSimplifiedInvoiceCap`)
56
+ * a full invoice is the only legal one: pass `overCap` and the fields become
57
+ * required, without a toggle. The server validates the identifier and
58
+ * refuses with `BILLING_DATA_REQUIRED` what this form cannot prevent.
59
+ *
60
+ * A shop that issues no invoices (`ShopConfig.simplifiedInvoiceCapCents` is
61
+ * `null`, see `shopIssuesInvoices`) offers no opt-in: pass
62
+ * `issuesInvoices={false}` and the block renders nothing — the server would
63
+ * refuse `wantsFullInvoice: true` with `FULL_INVOICE_UNAVAILABLE`.
64
+ */
65
+ type FullInvoiceIdType = NonNullable<ShopBillingInput['billingIdType']>;
66
+ interface FullInvoiceValue {
67
+ wantsFullInvoice: boolean;
68
+ billingIdType: FullInvoiceIdType;
69
+ /** ISO 3166-1 alpha-2 country that issued a foreign document. */
70
+ billingIdCountry: string;
71
+ billingNif: string;
72
+ billingName: string;
73
+ street: string;
74
+ postalCode: string;
75
+ city: string;
76
+ /** ISO 3166-1 alpha-2 country of the billing address. */
77
+ country: string;
78
+ }
79
+ declare const EMPTY_FULL_INVOICE_VALUE: FullInvoiceValue;
80
+ type FullInvoiceErrors = Partial<Record<'billingIdType' | 'billingIdCountry' | 'billingNif' | 'billingName' | 'address', string>>;
81
+ interface FullInvoiceFieldsLabels {
82
+ toggle: string;
83
+ underCapNotice: string;
84
+ overCapNotice: string;
85
+ idType: string;
86
+ idCountry: string;
87
+ chooseCountry: string;
88
+ spanishNif: string;
89
+ documentNumber: string;
90
+ name: string;
91
+ street: string;
92
+ postalCode: string;
93
+ city: string;
94
+ country: string;
95
+ idTypeOptions: Record<FullInvoiceIdType, string>;
96
+ }
97
+ /** ISO 3166-1 alpha-2 countries offered by default: Spain, the EU and frequent others. */
98
+ declare const DEFAULT_INVOICE_COUNTRIES: ReadonlyArray<{
99
+ code: string;
100
+ name: string;
101
+ }>;
102
+ /**
103
+ * Whether the shop issues invoices at all, read from the field the contract
104
+ * defines for it: `ShopConfig.simplifiedInvoiceCapCents` is the effective cap
105
+ * while invoicing is on and `null` otherwise (absent on an older base-api,
106
+ * which accepts no opt-in either).
107
+ */
108
+ declare function shopIssuesInvoices(config: {
109
+ simplifiedInvoiceCapCents?: number | null;
110
+ }): boolean;
111
+ /** Whether a cart total (cents) is over the shop's simplified-invoice cap; `null` cap = no gate. */
112
+ declare function isOverSimplifiedInvoiceCap(totalCents: number, capCents: number | null): boolean;
113
+ /**
114
+ * The checkout body fields for the request: `wantsFullInvoice` and the
115
+ * `billing` block (identifier, its type and country, name and address). Empty
116
+ * when the buyer asks for no full invoice within the cap, and always empty
117
+ * when the shop issues no invoices (`issuesInvoices` false).
118
+ */
119
+ declare function toCheckoutInvoiceFields(value: FullInvoiceValue, overCap: boolean, issuesInvoices?: boolean): Pick<ShopCheckoutInput, 'wantsFullInvoice' | 'billing'>;
120
+ interface FullInvoiceFieldsProps {
121
+ value: FullInvoiceValue;
122
+ onChange: (next: FullInvoiceValue) => void;
123
+ /** The cart total is over `ShopConfig.simplifiedInvoiceCapCents`. */
124
+ overCap: boolean;
125
+ /**
126
+ * `false` when the shop issues no invoices (`shopIssuesInvoices(config)`):
127
+ * the block renders nothing. Defaults to `true`.
128
+ */
129
+ issuesInvoices?: boolean;
130
+ errors?: FullInvoiceErrors;
131
+ countries?: ReadonlyArray<{
132
+ code: string;
133
+ name: string;
134
+ }>;
135
+ labels?: Partial<FullInvoiceFieldsLabels>;
136
+ className?: string;
137
+ }
138
+ declare function FullInvoiceFields({ value, onChange, overCap, issuesInvoices, errors, countries, labels, className, }: FullInvoiceFieldsProps): react_jsx_runtime.JSX.Element | null;
139
+
140
+ export { type CheckoutTermsCopy as C, DEFAULT_INVOICE_COUNTRIES as D, EMPTY_FULL_INVOICE_VALUE as E, type FullInvoiceFieldsLabels as F, type HeadingLevel as H, type FullInvoiceValue as a, CheckoutTermsAcceptance as b, type CheckoutTermsAcceptanceProps as c, type FullInvoiceErrors as d, FullInvoiceFields as e, type FullInvoiceFieldsProps as f, type FullInvoiceIdType as g, toCheckoutTermsFields as h, isOverSimplifiedInvoiceCap as i, shopIssuesInvoices as s, toCheckoutInvoiceFields as t };