import type { AddressToken, ResolvedAddressField, ResolvedAddressSchema } from '@evershop/evershop/lib/address/types'; import type { AddressGraphql } from '@evershop/evershop/types/address'; /** * The form's pure logic (spec § 3.9), kept free of React and the DOM so it is * unit-tested directly: field naming, row grouping, the country-swap clearing * rule, initial values from a stored address, the schema-driven re-quote * parameters and the shipping-methods gate, and the live preview. */ /** `shippingAddress.locality`, or `locality` when the form has no prefix. */ export declare function fieldName(namePrefix: string, id: string): string; /** Fields grouped by `row`, rows in ascending order, fields in schema order. */ export declare function rowsOf(schema: ResolvedAddressSchema): ResolvedAddressField[][]; /** What makes a field "the same field" across two countries (spec § 3.9, country swap). */ export declare function fieldSignature(field: ResolvedAddressField): string; export interface CountrySwapPlan { /** Present in both schemas but with a different type, option source or pattern: value cleared. */ clear: string[]; /** Present only in the previous schema: value removed from the form. */ remove: string[]; /** Present in both with the same signature: value kept. */ keep: string[]; } /** * Spec § 3.9: on a country change, clear a field when it is absent from the * new schema or when its `(type, optionSource, pattern.regex)` differs; keep * everything else. An option-sourced field (`regions`) always clears: its * option set is parameterised by the country, so a kept key would be another * country's region and fail `region_invalid` on save. `country` itself is * never touched. */ export declare function countrySwapPlan(previous: ResolvedAddressSchema | undefined, next: ResolvedAddressSchema): CountrySwapPlan; /** The chain of enumerated parents of `field`, outermost first (`dependsOn` links). */ export declare function parentChain(schema: ResolvedAddressSchema, field: ResolvedAddressField): ResolvedAddressField[]; /** Every field whose `dependsOn` chain includes `id` (cleared when `id` changes). */ export declare function dependentsOf(schema: ResolvedAddressSchema, id: string): string[]; /** * Initial form values for a stored address, keyed by field id: columns from * the camelCase GraphQL shape (region levels by `key`, the country by code), * registered extras from `extra`. In split mode (spec § 3.12 rule 3) a legacy * row with `recipient` but no parts pre-fills the two inputs with the labelled * lossy split so the customer sees the guess and corrects it. */ export declare function initialValuesFor(address: AddressGraphql | null | undefined, schema: ResolvedAddressSchema): Record; /** * What the server's normalization does to a telephone before it validates * (`normalizeTelephone` in the customer services), minus the dial-code step * the client cannot do: separators (spaces, dots, dashes, parentheses) are * removed and an international `00` prefix becomes `+`. The client tests a * country's telephone pattern against this form, so "0912 345 678" passes the * same regex the server will apply. Anything else is returned trimmed. */ export declare function normalizeTelephoneInput(value: unknown): string; /** Tokens whose value changes what a carrier quotes (spec § 3.10): the geographic levels and the postal code. */ export declare const REQUOTE_TOKENS: readonly AddressToken[]; export interface RequoteParams { country: string; administrativeArea?: string; locality?: string; dependentLocality?: string; postalCode?: string; } /** * The shipping-quote destination derived from the schema's own geographic * tokens plus the country, instead of three hard-coded field names. `null` * until a country is chosen. Name, telephone and street lines never appear, * so changing them never re-quotes. */ export declare function requoteParamsFor(schema: ResolvedAddressSchema | undefined, values: Record | undefined): RequoteParams | null; /** A stable key for "did anything a carrier quotes on change?": sorted entries, so field order never matters. */ export declare function requoteKey(params: RequoteParams | null): string | null; /** The re-quote parameters of a stored (GraphQL-shaped) address, for the "nothing changed yet" baseline. */ export declare function storedRequoteParams(address: AddressGraphql | null | undefined): RequoteParams | null; /** Shipping methods are worth asking for once the country and every REQUIRED geographic field are filled (HK has no postal code). */ export declare function geographicFieldsReady(schema: ResolvedAddressSchema | undefined, values: Record | undefined): boolean; /** * Live preview lines (spec § 3.6, client side): the same `formatAddress` the * server uses, with option labels for selects where known. Country excluded. */ export declare function previewLines(schema: ResolvedAddressSchema, values: Record | undefined, optionLabels?: Record>): string[]; /** * Field-targeted server errors (spec § 3.8) onto the form: every error with a * `field` lands on `.`; returns the messages that had no field. */ export declare function serverAddressErrors(error: unknown, namePrefix: string, setError: (name: string, error: { type: string; message: string; }) => void): { applied: number; unassigned: string[]; };