@storepecker/storefront-core 2.9.1 → 2.10.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/address-BdIB6IuI.d.cts +42 -0
- package/dist/address-BdIB6IuI.d.ts +42 -0
- package/dist/api/index.cjs +16 -12
- package/dist/api/index.d.cts +13 -3
- package/dist/api/index.d.ts +13 -3
- package/dist/api/index.js +2 -2
- package/dist/{buy-now-BqVWXyy8.d.cts → buy-now-B_15RUVT.d.cts} +1 -1
- package/dist/{buy-now-DFdnuLjO.d.ts → buy-now-kII0KrhP.d.ts} +1 -1
- package/dist/checkout/index.cjs +108 -15
- package/dist/checkout/index.d.cts +25 -1
- package/dist/checkout/index.d.ts +25 -1
- package/dist/checkout/index.js +3 -2
- package/dist/{chunk-IG4BW3ZB.cjs → chunk-32X4SWN4.cjs} +3 -3
- package/dist/{chunk-RDUT4W3B.cjs → chunk-6APRQ2ED.cjs} +4 -1
- package/dist/{chunk-ICKTXS6B.js → chunk-6IXTFZFS.js} +3 -3
- package/dist/{chunk-7M5CVYZJ.js → chunk-A7EI7XLU.js} +8 -1
- package/dist/{chunk-CBKJ3Y2I.js → chunk-EWZ7TGI7.js} +11 -1
- package/dist/{chunk-5XVHYPOC.js → chunk-FF5N7PTB.js} +1 -1
- package/dist/{chunk-XFOUNOKO.cjs → chunk-KNG4OMS5.cjs} +8 -0
- package/dist/chunk-QED6QJZC.cjs +603 -0
- package/dist/{chunk-W6BDMNSU.js → chunk-QVO56X4E.js} +1 -1
- package/dist/{chunk-6LS5F4R3.cjs → chunk-SGJUMI3M.cjs} +11 -0
- package/dist/{chunk-YLLAP3H2.cjs → chunk-SGKLMS7W.cjs} +2 -2
- package/dist/{chunk-ZGMLOLTC.js → chunk-VRZRV2BR.js} +4 -1
- package/dist/{chunk-IVKJJLG7.cjs → chunk-WWJAPKRQ.cjs} +8 -8
- package/dist/chunk-Y4RNRPBC.js +545 -0
- package/dist/components/address-form.cjs +6 -6
- package/dist/components/address-form.d.cts +10 -6
- package/dist/components/address-form.d.ts +10 -6
- package/dist/components/address-form.js +5 -5
- package/dist/components/index.cjs +8 -8
- package/dist/components/index.d.cts +3 -3
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +6 -6
- package/dist/components/search-dropdown.d.cts +4 -4
- package/dist/components/search-dropdown.d.ts +4 -4
- package/dist/components/share-button.cjs +3 -3
- package/dist/components/share-button.js +2 -2
- package/dist/components/theme-data-initializer.d.cts +1 -1
- package/dist/components/theme-data-initializer.d.ts +1 -1
- package/dist/hooks/index.cjs +644 -20
- package/dist/hooks/index.d.cts +233 -9
- package/dist/hooks/index.d.ts +233 -9
- package/dist/hooks/index.js +624 -8
- package/dist/models/index.d.cts +3 -2
- package/dist/models/index.d.ts +3 -2
- package/dist/pincode-8u7yWLpQ.d.cts +29 -0
- package/dist/pincode-8u7yWLpQ.d.ts +29 -0
- package/dist/pincode-CHM-ZD3H.d.ts +179 -0
- package/dist/pincode-Ch3bZSJz.d.cts +179 -0
- package/dist/{pixelEvents-BtEO5QAR.d.cts → pixelEvents-COqZIgTu.d.cts} +1 -0
- package/dist/{pixelEvents-LsealscG.d.ts → pixelEvents-Ds6fwS9t.d.ts} +1 -0
- package/dist/store/index.d.cts +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/{useAddressForm-DGbEn91-.d.cts → useAddressForm-fMOb5Z-a.d.ts} +6 -1
- package/dist/{useAddressForm-cO3Au33k.d.ts → useAddressForm-wleIo78M.d.cts} +6 -1
- package/dist/utils/index.cjs +58 -54
- package/dist/utils/index.d.cts +12 -3
- package/dist/utils/index.d.ts +12 -3
- package/dist/utils/index.js +3 -3
- package/package.json +1 -1
- package/dist/address-DwBZHzbI.d.cts +0 -19
- package/dist/address-DwBZHzbI.d.ts +0 -19
- package/dist/chunk-34Y7Y5FU.cjs +0 -246
- package/dist/chunk-VPTN4YXD.js +0 -232
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare namespace Pincode {
|
|
2
|
+
/** One area sharing a postal code. `province` is the district for IN. */
|
|
3
|
+
interface Locality {
|
|
4
|
+
city: string;
|
|
5
|
+
state: string;
|
|
6
|
+
state_code: string;
|
|
7
|
+
province?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `GET /utils/pincode/`. A pincode that isn't found is a 200 with
|
|
11
|
+
* `valid: false` and `error_code: "INVALID_PINCODE"`, not a 4xx. When the
|
|
12
|
+
* store hasn't opted in, `validation_enabled` is false and nothing else is set.
|
|
13
|
+
*/
|
|
14
|
+
interface LookupResponse {
|
|
15
|
+
valid?: boolean;
|
|
16
|
+
validation_enabled?: boolean;
|
|
17
|
+
error_code?: string;
|
|
18
|
+
message?: string;
|
|
19
|
+
/** The district, e.g. "Kozhikode". */
|
|
20
|
+
province?: string;
|
|
21
|
+
/** A locality inside the district; smaller than `province`. */
|
|
22
|
+
city?: string;
|
|
23
|
+
state?: string;
|
|
24
|
+
state_code?: string;
|
|
25
|
+
localities?: Locality[];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { Pincode as P };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare namespace Pincode {
|
|
2
|
+
/** One area sharing a postal code. `province` is the district for IN. */
|
|
3
|
+
interface Locality {
|
|
4
|
+
city: string;
|
|
5
|
+
state: string;
|
|
6
|
+
state_code: string;
|
|
7
|
+
province?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `GET /utils/pincode/`. A pincode that isn't found is a 200 with
|
|
11
|
+
* `valid: false` and `error_code: "INVALID_PINCODE"`, not a 4xx. When the
|
|
12
|
+
* store hasn't opted in, `validation_enabled` is false and nothing else is set.
|
|
13
|
+
*/
|
|
14
|
+
interface LookupResponse {
|
|
15
|
+
valid?: boolean;
|
|
16
|
+
validation_enabled?: boolean;
|
|
17
|
+
error_code?: string;
|
|
18
|
+
message?: string;
|
|
19
|
+
/** The district, e.g. "Kozhikode". */
|
|
20
|
+
province?: string;
|
|
21
|
+
/** A locality inside the district; smaller than `province`. */
|
|
22
|
+
city?: string;
|
|
23
|
+
state?: string;
|
|
24
|
+
state_code?: string;
|
|
25
|
+
localities?: Locality[];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { Pincode as P };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
import { P as Pincode } from './pincode-8u7yWLpQ.js';
|
|
3
|
+
|
|
4
|
+
/** The fields we keep from Google's payload — the rest would only bloat localStorage. */
|
|
5
|
+
type RawAddressData = {
|
|
6
|
+
fmt?: string;
|
|
7
|
+
require?: string;
|
|
8
|
+
zip?: string;
|
|
9
|
+
zip_name_type?: string;
|
|
10
|
+
state_name_type?: string;
|
|
11
|
+
locality_name_type?: string;
|
|
12
|
+
};
|
|
13
|
+
type AddressFormat = {
|
|
14
|
+
countryCode: string;
|
|
15
|
+
hasPostal: boolean;
|
|
16
|
+
/** False when the metadata couldn't load: we can't tell if the country uses postcodes. */
|
|
17
|
+
postalRequired: boolean;
|
|
18
|
+
postalLabel: string;
|
|
19
|
+
postalPattern: RegExp | null;
|
|
20
|
+
/**
|
|
21
|
+
* Block submission when the postcode doesn't match. Only true where the
|
|
22
|
+
* pattern is known to be reliable; elsewhere a mismatch is just a hint, so an
|
|
23
|
+
* outdated regex can't stop a real order.
|
|
24
|
+
*/
|
|
25
|
+
postalStrict: boolean;
|
|
26
|
+
postalInputMode: "numeric" | "text";
|
|
27
|
+
postalMaxLength: number;
|
|
28
|
+
postalUppercase: boolean;
|
|
29
|
+
regionLabel: string;
|
|
30
|
+
cityLabel: string;
|
|
31
|
+
line1Label: string;
|
|
32
|
+
line2Label: string;
|
|
33
|
+
/** State before city (Japan, UAE); city first everywhere else. */
|
|
34
|
+
stateFirst: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Turns Google's raw data into a form format. `raw` is null when the metadata
|
|
38
|
+
* could not be loaded; the overrides plus generic labels still give a usable form.
|
|
39
|
+
*/
|
|
40
|
+
declare function buildAddressFormat(countryCode: string, raw: RawAddressData | null): AddressFormat;
|
|
41
|
+
/** Fetches (or reads from cache) and builds the format. Throws if Google is unreachable. */
|
|
42
|
+
declare function loadAddressFormat(countryCode: string): Promise<AddressFormat>;
|
|
43
|
+
/**
|
|
44
|
+
* Strips special characters from a pincode/postal-code entry, keeping only
|
|
45
|
+
* letters, digits and single spaces. Programmatic values like "N/A" are set via
|
|
46
|
+
* `setFieldValue` (not through an input handler) and are therefore untouched.
|
|
47
|
+
*/
|
|
48
|
+
declare function sanitizePincode(value: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Keeps letters, digits and single spaces, capped per country. Japan (no
|
|
51
|
+
* override, Google's pattern allows `100-0001`) and the US (ZIP+4) keep the hyphen.
|
|
52
|
+
*/
|
|
53
|
+
declare function normalizePostcode(format: AddressFormat, value: string): string;
|
|
54
|
+
/** A non-blocking warning for countries without a strict pattern. */
|
|
55
|
+
declare function getPostcodeHint(format: AddressFormat, value: string, message?: (postalLabel: string) => string): string | undefined;
|
|
56
|
+
declare function findStateByName(states: CountryModel.State1[], name: string): CountryModel.State1 | undefined;
|
|
57
|
+
/** The backend has one street field, so the optional second line is folded into it. */
|
|
58
|
+
declare function joinAddressLines(line1: string, line2: string): string;
|
|
59
|
+
declare const usableEmail: (value: unknown) => string;
|
|
60
|
+
/** "Town / city" → "town / city", but "PIN code" and "ZIP code" keep their capitals. */
|
|
61
|
+
declare const lowerLabel: (label: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Validation messages for `buildAddressSchema`. Label-dependent messages get
|
|
64
|
+
* the country's label already lower-cased (e.g. "PIN code", "town / city").
|
|
65
|
+
*/
|
|
66
|
+
type AddressSchemaMessages = {
|
|
67
|
+
nameRequired: string;
|
|
68
|
+
emailInvalid: string;
|
|
69
|
+
emailRequired: string;
|
|
70
|
+
phoneRequired: string;
|
|
71
|
+
phoneInvalid: string;
|
|
72
|
+
countryRequired: string;
|
|
73
|
+
line1Required: (label: string) => string;
|
|
74
|
+
cityRequired: (label: string) => string;
|
|
75
|
+
stateRequired: (label: string) => string;
|
|
76
|
+
postalRequired: (label: string) => string;
|
|
77
|
+
postalInvalid: (label: string) => string;
|
|
78
|
+
};
|
|
79
|
+
declare const DEFAULT_ADDRESS_SCHEMA_MESSAGES: AddressSchemaMessages;
|
|
80
|
+
/**
|
|
81
|
+
* The schema follows the country: no postcode rule where there is no
|
|
82
|
+
* postcode, no state rule where the backend has no states, and a strict
|
|
83
|
+
* postcode pattern only where we trust it.
|
|
84
|
+
*/
|
|
85
|
+
declare function buildAddressSchema(format: AddressFormat, { requireState, messages }: {
|
|
86
|
+
requireState: boolean;
|
|
87
|
+
messages?: Partial<AddressSchemaMessages>;
|
|
88
|
+
}): Yup.ObjectSchema<{
|
|
89
|
+
customer_name: string;
|
|
90
|
+
customer_email: string;
|
|
91
|
+
customer_phone: string;
|
|
92
|
+
country_obj: string;
|
|
93
|
+
address: string;
|
|
94
|
+
address_line_2: string | undefined;
|
|
95
|
+
city: string;
|
|
96
|
+
state_obj: Yup.Maybe<string | undefined>;
|
|
97
|
+
pincode: Yup.Maybe<string | undefined>;
|
|
98
|
+
}, Yup.AnyObject, {
|
|
99
|
+
customer_name: undefined;
|
|
100
|
+
customer_email: undefined;
|
|
101
|
+
customer_phone: undefined;
|
|
102
|
+
country_obj: undefined;
|
|
103
|
+
address: undefined;
|
|
104
|
+
address_line_2: undefined;
|
|
105
|
+
city: undefined;
|
|
106
|
+
state_obj: undefined;
|
|
107
|
+
pincode: undefined;
|
|
108
|
+
}, "">;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Server-side pincode validation (ported from theme-aspen / theme-oak).
|
|
112
|
+
*
|
|
113
|
+
* The merchant opts in (`pincode_validation_enabled` on theme_data). When it's
|
|
114
|
+
* on, the backend checks pincodes against a postal-code database and returns
|
|
115
|
+
* the district and state, which prefill the form. When it's off, there is no
|
|
116
|
+
* lookup and no prefill; the format check in the form's schema still applies.
|
|
117
|
+
*
|
|
118
|
+
* Checking the flag is the caller's job (`usePincodeLookup` takes it as an
|
|
119
|
+
* option and falls back to the `useThemeData` store); nothing here reads it.
|
|
120
|
+
*/
|
|
121
|
+
/** Pincode isn't real; the customer must correct it. */
|
|
122
|
+
declare const INVALID_PINCODE = "INVALID_PINCODE";
|
|
123
|
+
/** Provider down / quota exhausted. Transient, so invite a retry. */
|
|
124
|
+
declare const PINCODE_VALIDATION_UNAVAILABLE = "PINCODE_VALIDATION_UNAVAILABLE";
|
|
125
|
+
/** Placeholder the address forms use for countries with no postal code. */
|
|
126
|
+
declare const NO_POSTAL_CODE = "N/A";
|
|
127
|
+
/** Wait for a pause before looking up: the endpoint allows 20 req/min per IP. */
|
|
128
|
+
declare const PINCODE_DEBOUNCE_MS = 600;
|
|
129
|
+
/** Don't look up a half-typed value (countries without a strict format). */
|
|
130
|
+
declare const PINCODE_MIN_LENGTH = 4;
|
|
131
|
+
/** Location data from a recognised pincode, for prefilling the address. */
|
|
132
|
+
interface PincodeMatch {
|
|
133
|
+
/** The district, from the response's `province`. This fills City/District. */
|
|
134
|
+
district: string;
|
|
135
|
+
/** A locality inside the district; smaller than `district`. */
|
|
136
|
+
city: string;
|
|
137
|
+
state: string;
|
|
138
|
+
state_code: string;
|
|
139
|
+
/** Areas sharing this pincode; offered as suggestions when there's more than one. */
|
|
140
|
+
localities: Pincode.Locality[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* `invalid`: the backend says the pincode doesn't exist; blocks saving.
|
|
144
|
+
* `unknown`: feature off, outage, throttle or network error. Fails open,
|
|
145
|
+
* because the server validates again on save.
|
|
146
|
+
*/
|
|
147
|
+
type PincodeCheck = {
|
|
148
|
+
status: "valid";
|
|
149
|
+
match: PincodeMatch;
|
|
150
|
+
} | {
|
|
151
|
+
status: "invalid";
|
|
152
|
+
match: null;
|
|
153
|
+
} | {
|
|
154
|
+
status: "unknown";
|
|
155
|
+
match: null;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Validate a pincode against `GET /utils/pincode/`. Never throws. Only call it
|
|
159
|
+
* for stores with `pincode_validation_enabled`.
|
|
160
|
+
*
|
|
161
|
+
* @param pincode The value to check.
|
|
162
|
+
* @param countryCode ISO2 of the selected country.
|
|
163
|
+
*/
|
|
164
|
+
declare function validatePincode(pincode: string, countryCode?: string): Promise<PincodeCheck>;
|
|
165
|
+
/**
|
|
166
|
+
* Pull a pincode error out of a rejected `POST|PATCH /store/customer_address/`.
|
|
167
|
+
* Returns null for anything else, so callers fall through to their own handling.
|
|
168
|
+
*
|
|
169
|
+
* @param invalidMessage The wording for "doesn't exist", in the country's own label.
|
|
170
|
+
*/
|
|
171
|
+
declare function getPincodeError(error: unknown, invalidMessage: string): string | null;
|
|
172
|
+
/** Test helper: forget cached answers. */
|
|
173
|
+
declare function clearPincodeCache(): void;
|
|
174
|
+
/** The subdivision matching a lookup result, for the State dropdown. */
|
|
175
|
+
declare function findSubdivision(states: CountryModel.State1[], match: PincodeMatch): CountryModel.State1 | undefined;
|
|
176
|
+
/** Distinct locality names inside the district, when the pincode covers more than one. */
|
|
177
|
+
declare function getAreaOptions(match: PincodeMatch | null): string[];
|
|
178
|
+
|
|
179
|
+
export { type AddressFormat as A, DEFAULT_ADDRESS_SCHEMA_MESSAGES as D, INVALID_PINCODE as I, NO_POSTAL_CODE as N, PINCODE_DEBOUNCE_MS as P, type RawAddressData as R, type AddressSchemaMessages as a, PINCODE_MIN_LENGTH as b, PINCODE_VALIDATION_UNAVAILABLE as c, type PincodeCheck as d, type PincodeMatch as e, buildAddressFormat as f, buildAddressSchema as g, clearPincodeCache as h, findStateByName as i, findSubdivision as j, getAreaOptions as k, getPincodeError as l, getPostcodeHint as m, joinAddressLines as n, loadAddressFormat as o, lowerLabel as p, normalizePostcode as q, sanitizePincode as s, usableEmail as u, validatePincode as v };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
import { P as Pincode } from './pincode-8u7yWLpQ.cjs';
|
|
3
|
+
|
|
4
|
+
/** The fields we keep from Google's payload — the rest would only bloat localStorage. */
|
|
5
|
+
type RawAddressData = {
|
|
6
|
+
fmt?: string;
|
|
7
|
+
require?: string;
|
|
8
|
+
zip?: string;
|
|
9
|
+
zip_name_type?: string;
|
|
10
|
+
state_name_type?: string;
|
|
11
|
+
locality_name_type?: string;
|
|
12
|
+
};
|
|
13
|
+
type AddressFormat = {
|
|
14
|
+
countryCode: string;
|
|
15
|
+
hasPostal: boolean;
|
|
16
|
+
/** False when the metadata couldn't load: we can't tell if the country uses postcodes. */
|
|
17
|
+
postalRequired: boolean;
|
|
18
|
+
postalLabel: string;
|
|
19
|
+
postalPattern: RegExp | null;
|
|
20
|
+
/**
|
|
21
|
+
* Block submission when the postcode doesn't match. Only true where the
|
|
22
|
+
* pattern is known to be reliable; elsewhere a mismatch is just a hint, so an
|
|
23
|
+
* outdated regex can't stop a real order.
|
|
24
|
+
*/
|
|
25
|
+
postalStrict: boolean;
|
|
26
|
+
postalInputMode: "numeric" | "text";
|
|
27
|
+
postalMaxLength: number;
|
|
28
|
+
postalUppercase: boolean;
|
|
29
|
+
regionLabel: string;
|
|
30
|
+
cityLabel: string;
|
|
31
|
+
line1Label: string;
|
|
32
|
+
line2Label: string;
|
|
33
|
+
/** State before city (Japan, UAE); city first everywhere else. */
|
|
34
|
+
stateFirst: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Turns Google's raw data into a form format. `raw` is null when the metadata
|
|
38
|
+
* could not be loaded; the overrides plus generic labels still give a usable form.
|
|
39
|
+
*/
|
|
40
|
+
declare function buildAddressFormat(countryCode: string, raw: RawAddressData | null): AddressFormat;
|
|
41
|
+
/** Fetches (or reads from cache) and builds the format. Throws if Google is unreachable. */
|
|
42
|
+
declare function loadAddressFormat(countryCode: string): Promise<AddressFormat>;
|
|
43
|
+
/**
|
|
44
|
+
* Strips special characters from a pincode/postal-code entry, keeping only
|
|
45
|
+
* letters, digits and single spaces. Programmatic values like "N/A" are set via
|
|
46
|
+
* `setFieldValue` (not through an input handler) and are therefore untouched.
|
|
47
|
+
*/
|
|
48
|
+
declare function sanitizePincode(value: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Keeps letters, digits and single spaces, capped per country. Japan (no
|
|
51
|
+
* override, Google's pattern allows `100-0001`) and the US (ZIP+4) keep the hyphen.
|
|
52
|
+
*/
|
|
53
|
+
declare function normalizePostcode(format: AddressFormat, value: string): string;
|
|
54
|
+
/** A non-blocking warning for countries without a strict pattern. */
|
|
55
|
+
declare function getPostcodeHint(format: AddressFormat, value: string, message?: (postalLabel: string) => string): string | undefined;
|
|
56
|
+
declare function findStateByName(states: CountryModel.State1[], name: string): CountryModel.State1 | undefined;
|
|
57
|
+
/** The backend has one street field, so the optional second line is folded into it. */
|
|
58
|
+
declare function joinAddressLines(line1: string, line2: string): string;
|
|
59
|
+
declare const usableEmail: (value: unknown) => string;
|
|
60
|
+
/** "Town / city" → "town / city", but "PIN code" and "ZIP code" keep their capitals. */
|
|
61
|
+
declare const lowerLabel: (label: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Validation messages for `buildAddressSchema`. Label-dependent messages get
|
|
64
|
+
* the country's label already lower-cased (e.g. "PIN code", "town / city").
|
|
65
|
+
*/
|
|
66
|
+
type AddressSchemaMessages = {
|
|
67
|
+
nameRequired: string;
|
|
68
|
+
emailInvalid: string;
|
|
69
|
+
emailRequired: string;
|
|
70
|
+
phoneRequired: string;
|
|
71
|
+
phoneInvalid: string;
|
|
72
|
+
countryRequired: string;
|
|
73
|
+
line1Required: (label: string) => string;
|
|
74
|
+
cityRequired: (label: string) => string;
|
|
75
|
+
stateRequired: (label: string) => string;
|
|
76
|
+
postalRequired: (label: string) => string;
|
|
77
|
+
postalInvalid: (label: string) => string;
|
|
78
|
+
};
|
|
79
|
+
declare const DEFAULT_ADDRESS_SCHEMA_MESSAGES: AddressSchemaMessages;
|
|
80
|
+
/**
|
|
81
|
+
* The schema follows the country: no postcode rule where there is no
|
|
82
|
+
* postcode, no state rule where the backend has no states, and a strict
|
|
83
|
+
* postcode pattern only where we trust it.
|
|
84
|
+
*/
|
|
85
|
+
declare function buildAddressSchema(format: AddressFormat, { requireState, messages }: {
|
|
86
|
+
requireState: boolean;
|
|
87
|
+
messages?: Partial<AddressSchemaMessages>;
|
|
88
|
+
}): Yup.ObjectSchema<{
|
|
89
|
+
customer_name: string;
|
|
90
|
+
customer_email: string;
|
|
91
|
+
customer_phone: string;
|
|
92
|
+
country_obj: string;
|
|
93
|
+
address: string;
|
|
94
|
+
address_line_2: string | undefined;
|
|
95
|
+
city: string;
|
|
96
|
+
state_obj: Yup.Maybe<string | undefined>;
|
|
97
|
+
pincode: Yup.Maybe<string | undefined>;
|
|
98
|
+
}, Yup.AnyObject, {
|
|
99
|
+
customer_name: undefined;
|
|
100
|
+
customer_email: undefined;
|
|
101
|
+
customer_phone: undefined;
|
|
102
|
+
country_obj: undefined;
|
|
103
|
+
address: undefined;
|
|
104
|
+
address_line_2: undefined;
|
|
105
|
+
city: undefined;
|
|
106
|
+
state_obj: undefined;
|
|
107
|
+
pincode: undefined;
|
|
108
|
+
}, "">;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Server-side pincode validation (ported from theme-aspen / theme-oak).
|
|
112
|
+
*
|
|
113
|
+
* The merchant opts in (`pincode_validation_enabled` on theme_data). When it's
|
|
114
|
+
* on, the backend checks pincodes against a postal-code database and returns
|
|
115
|
+
* the district and state, which prefill the form. When it's off, there is no
|
|
116
|
+
* lookup and no prefill; the format check in the form's schema still applies.
|
|
117
|
+
*
|
|
118
|
+
* Checking the flag is the caller's job (`usePincodeLookup` takes it as an
|
|
119
|
+
* option and falls back to the `useThemeData` store); nothing here reads it.
|
|
120
|
+
*/
|
|
121
|
+
/** Pincode isn't real; the customer must correct it. */
|
|
122
|
+
declare const INVALID_PINCODE = "INVALID_PINCODE";
|
|
123
|
+
/** Provider down / quota exhausted. Transient, so invite a retry. */
|
|
124
|
+
declare const PINCODE_VALIDATION_UNAVAILABLE = "PINCODE_VALIDATION_UNAVAILABLE";
|
|
125
|
+
/** Placeholder the address forms use for countries with no postal code. */
|
|
126
|
+
declare const NO_POSTAL_CODE = "N/A";
|
|
127
|
+
/** Wait for a pause before looking up: the endpoint allows 20 req/min per IP. */
|
|
128
|
+
declare const PINCODE_DEBOUNCE_MS = 600;
|
|
129
|
+
/** Don't look up a half-typed value (countries without a strict format). */
|
|
130
|
+
declare const PINCODE_MIN_LENGTH = 4;
|
|
131
|
+
/** Location data from a recognised pincode, for prefilling the address. */
|
|
132
|
+
interface PincodeMatch {
|
|
133
|
+
/** The district, from the response's `province`. This fills City/District. */
|
|
134
|
+
district: string;
|
|
135
|
+
/** A locality inside the district; smaller than `district`. */
|
|
136
|
+
city: string;
|
|
137
|
+
state: string;
|
|
138
|
+
state_code: string;
|
|
139
|
+
/** Areas sharing this pincode; offered as suggestions when there's more than one. */
|
|
140
|
+
localities: Pincode.Locality[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* `invalid`: the backend says the pincode doesn't exist; blocks saving.
|
|
144
|
+
* `unknown`: feature off, outage, throttle or network error. Fails open,
|
|
145
|
+
* because the server validates again on save.
|
|
146
|
+
*/
|
|
147
|
+
type PincodeCheck = {
|
|
148
|
+
status: "valid";
|
|
149
|
+
match: PincodeMatch;
|
|
150
|
+
} | {
|
|
151
|
+
status: "invalid";
|
|
152
|
+
match: null;
|
|
153
|
+
} | {
|
|
154
|
+
status: "unknown";
|
|
155
|
+
match: null;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Validate a pincode against `GET /utils/pincode/`. Never throws. Only call it
|
|
159
|
+
* for stores with `pincode_validation_enabled`.
|
|
160
|
+
*
|
|
161
|
+
* @param pincode The value to check.
|
|
162
|
+
* @param countryCode ISO2 of the selected country.
|
|
163
|
+
*/
|
|
164
|
+
declare function validatePincode(pincode: string, countryCode?: string): Promise<PincodeCheck>;
|
|
165
|
+
/**
|
|
166
|
+
* Pull a pincode error out of a rejected `POST|PATCH /store/customer_address/`.
|
|
167
|
+
* Returns null for anything else, so callers fall through to their own handling.
|
|
168
|
+
*
|
|
169
|
+
* @param invalidMessage The wording for "doesn't exist", in the country's own label.
|
|
170
|
+
*/
|
|
171
|
+
declare function getPincodeError(error: unknown, invalidMessage: string): string | null;
|
|
172
|
+
/** Test helper: forget cached answers. */
|
|
173
|
+
declare function clearPincodeCache(): void;
|
|
174
|
+
/** The subdivision matching a lookup result, for the State dropdown. */
|
|
175
|
+
declare function findSubdivision(states: CountryModel.State1[], match: PincodeMatch): CountryModel.State1 | undefined;
|
|
176
|
+
/** Distinct locality names inside the district, when the pincode covers more than one. */
|
|
177
|
+
declare function getAreaOptions(match: PincodeMatch | null): string[];
|
|
178
|
+
|
|
179
|
+
export { type AddressFormat as A, DEFAULT_ADDRESS_SCHEMA_MESSAGES as D, INVALID_PINCODE as I, NO_POSTAL_CODE as N, PINCODE_DEBOUNCE_MS as P, type RawAddressData as R, type AddressSchemaMessages as a, PINCODE_MIN_LENGTH as b, PINCODE_VALIDATION_UNAVAILABLE as c, type PincodeCheck as d, type PincodeMatch as e, buildAddressFormat as f, buildAddressSchema as g, clearPincodeCache as h, findStateByName as i, findSubdivision as j, getAreaOptions as k, getPincodeError as l, getPostcodeHint as m, joinAddressLines as n, loadAddressFormat as o, lowerLabel as p, normalizePostcode as q, sanitizePincode as s, usableEmail as u, validatePincode as v };
|
|
@@ -94,6 +94,7 @@ type PageHeaderProps = Pick<PagePropsFull, "navbar" | "logo" | "store_name" | "s
|
|
|
94
94
|
popup_thank_you_message: string;
|
|
95
95
|
public_checkout_enabled: boolean;
|
|
96
96
|
buy_now_enabled: boolean;
|
|
97
|
+
pincode_validation_enabled?: boolean;
|
|
97
98
|
booking_success_message: string;
|
|
98
99
|
order_success_message: string;
|
|
99
100
|
};
|
|
@@ -94,6 +94,7 @@ type PageHeaderProps = Pick<PagePropsFull, "navbar" | "logo" | "store_name" | "s
|
|
|
94
94
|
popup_thank_you_message: string;
|
|
95
95
|
public_checkout_enabled: boolean;
|
|
96
96
|
buy_now_enabled: boolean;
|
|
97
|
+
pincode_validation_enabled?: boolean;
|
|
97
98
|
booking_success_message: string;
|
|
98
99
|
order_success_message: string;
|
|
99
100
|
};
|
package/dist/store/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import * as zustand from 'zustand';
|
|
|
2
2
|
import { a as CartState, C as Cart, U as User } from '../cart-DwMFBmpC.cjs';
|
|
3
3
|
import { f as ProductDetail, d as Product } from '../product-D9liEtl4.cjs';
|
|
4
4
|
import { W as Wishlist } from '../wishlist-BakHvIFN.cjs';
|
|
5
|
-
import { P as PageHeaderProps } from '../pixelEvents-
|
|
5
|
+
import { P as PageHeaderProps } from '../pixelEvents-COqZIgTu.cjs';
|
|
6
6
|
import 'react-toastify';
|
|
7
7
|
import '../collections-CXgOv5_G.cjs';
|
|
8
8
|
import '../orders-B3G4CyhH.cjs';
|
package/dist/store/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as zustand from 'zustand';
|
|
|
2
2
|
import { a as CartState, C as Cart, U as User } from '../cart-DZq1ZEnE.js';
|
|
3
3
|
import { f as ProductDetail, d as Product } from '../product-D9liEtl4.js';
|
|
4
4
|
import { W as Wishlist } from '../wishlist-Cj0sQxiY.js';
|
|
5
|
-
import { P as PageHeaderProps } from '../pixelEvents-
|
|
5
|
+
import { P as PageHeaderProps } from '../pixelEvents-Ds6fwS9t.js';
|
|
6
6
|
import 'react-toastify';
|
|
7
7
|
import '../collections-CNh2OGbl.js';
|
|
8
8
|
import '../orders-Bl-Slh72.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChangeEvent } from 'react';
|
|
2
2
|
import { useFormik } from 'formik';
|
|
3
|
-
import { A as Address } from './address-
|
|
3
|
+
import { A as Address } from './address-BdIB6IuI.js';
|
|
4
4
|
|
|
5
5
|
interface UseAddressFormOptions {
|
|
6
6
|
/** Existing address for edit mode. When provided, form prefills from this address. */
|
|
@@ -37,6 +37,11 @@ interface UseAddressFormReturn {
|
|
|
37
37
|
isSubmitting: boolean;
|
|
38
38
|
isEditing: boolean;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use `useCountryAwareAddressForm`: per-country address formats,
|
|
42
|
+
* postcode rules, pincode lookup, and it hands the payload back instead of
|
|
43
|
+
* saving it. This hook will be removed in 3.0.0.
|
|
44
|
+
*/
|
|
40
45
|
declare function useAddressForm(options?: UseAddressFormOptions): UseAddressFormReturn;
|
|
41
46
|
|
|
42
47
|
export { type UseAddressFormOptions as U, type UseAddressFormReturn as a, useAddressForm as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChangeEvent } from 'react';
|
|
2
2
|
import { useFormik } from 'formik';
|
|
3
|
-
import { A as Address } from './address-
|
|
3
|
+
import { A as Address } from './address-BdIB6IuI.cjs';
|
|
4
4
|
|
|
5
5
|
interface UseAddressFormOptions {
|
|
6
6
|
/** Existing address for edit mode. When provided, form prefills from this address. */
|
|
@@ -37,6 +37,11 @@ interface UseAddressFormReturn {
|
|
|
37
37
|
isSubmitting: boolean;
|
|
38
38
|
isEditing: boolean;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use `useCountryAwareAddressForm`: per-country address formats,
|
|
42
|
+
* postcode rules, pincode lookup, and it hands the payload back instead of
|
|
43
|
+
* saving it. This hook will be removed in 3.0.0.
|
|
44
|
+
*/
|
|
40
45
|
declare function useAddressForm(options?: UseAddressFormOptions): UseAddressFormReturn;
|
|
41
46
|
|
|
42
47
|
export { type UseAddressFormOptions as U, type UseAddressFormReturn as a, useAddressForm as u };
|