@flopay/shared 1.3.0 → 1.3.1
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/README.md +25 -0
- package/dist/index.cjs +79 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -2
- package/dist/index.d.ts +25 -2
- package/dist/index.mjs +65 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -175,3 +175,28 @@ throw validationError('Email is required', 'email');
|
|
|
175
175
|
| `getCurrencyByCountry(countryCode)` | Returns `CurrencyInfo` for a country code, falls back to USD |
|
|
176
176
|
| `isValidPublishableKey(key)` | Returns `true` if the key matches `pk_(test|live)_...` |
|
|
177
177
|
| `isValidSecretKey(key)` | Returns `true` if the key matches `sk_(test|live)_...` |
|
|
178
|
+
|
|
179
|
+
### Postal Code Helpers
|
|
180
|
+
|
|
181
|
+
Country-aware postcode format validation, backed by the [`validator`](https://www.npmjs.com/package/validator) package's `isPostalCode` (the same library the billing API uses, so client and server rules agree). `@flopay/react`'s AVS block uses these to block a malformed postcode before the card is captured and to show the expected format inline.
|
|
182
|
+
|
|
183
|
+
| Export | Description |
|
|
184
|
+
|--------|-------------|
|
|
185
|
+
| `getPostalCodeLabel(countryCode)` | Country-appropriate field label (`'ZIP Code'`, `'Postcode'`, `'Eircode'`, …); defaults to `'Postal Code'` |
|
|
186
|
+
| `isPostalCodeSupported(country)` | `true` when `validator` has a postcode pattern for the (ISO 3166-1 alpha-2, case-insensitive; `UK`→`GB`) country. Unsupported / no-postcode countries return `false` |
|
|
187
|
+
| `isValidPostalCode(country, postalCode)` | `true` when the (trimmed) postcode matches the country's format. **Fails open** — unsupported / no-postcode countries always return `true`, so callers never block them. A supported country with an empty value returns `false`; check emptiness first to distinguish "required" from "malformed" |
|
|
188
|
+
| `getPostalCodeExample(country)` | A curated example postcode for the field hint (US `12345 or 12345-6789`, GB `SW1A 1AA`, CA `A1A 1A1`, …), or `undefined` when there is no curated example |
|
|
189
|
+
| `getStateFromPostalCode(country, postalCode)` | Derives a US state / CA province code from a postcode for AVS enrichment; `null` for other countries or a malformed code |
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { isPostalCodeSupported, isValidPostalCode, getPostalCodeExample } from '@flopay/shared';
|
|
193
|
+
|
|
194
|
+
isPostalCodeSupported('US'); // true
|
|
195
|
+
isPostalCodeSupported('AE'); // false — UAE has no postcodes
|
|
196
|
+
isValidPostalCode('GB', 'SW1A 1AA'); // true
|
|
197
|
+
isValidPostalCode('GB', '12345'); // false — US shape in GB
|
|
198
|
+
isValidPostalCode('AE', ''); // true — fail open, never blocks
|
|
199
|
+
getPostalCodeExample('CA'); // 'A1A 1A1'
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
> **Runtime dependency.** Unlike the rest of `@flopay/shared`, these helpers pull in `validator` (imported via the `validator/lib/isPostalCode.js` submodule so bundlers only include the one check). It installs transitively when you depend on `@flopay/shared`.
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,7 +17,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
18
|
-
var
|
|
20
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
26
|
+
mod2
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
@@ -75,6 +85,7 @@ __export(index_exports, {
|
|
|
75
85
|
getCountryByCode: () => getCountryByCode,
|
|
76
86
|
getCurrencyByCountry: () => getCurrencyByCountry,
|
|
77
87
|
getFloPayEnvironment: () => getFloPayEnvironment,
|
|
88
|
+
getPostalCodeExample: () => getPostalCodeExample,
|
|
78
89
|
getPostalCodeLabel: () => getPostalCodeLabel,
|
|
79
90
|
getStateFromPostalCode: () => getStateFromPostalCode,
|
|
80
91
|
getStateLabel: () => getStateLabel,
|
|
@@ -83,7 +94,9 @@ __export(index_exports, {
|
|
|
83
94
|
hasVendoredStripeMethodLogo: () => hasVendoredStripeMethodLogo,
|
|
84
95
|
isAVSEnabled: () => isAVSEnabled,
|
|
85
96
|
isAVSFieldVisible: () => isAVSFieldVisible,
|
|
97
|
+
isPostalCodeSupported: () => isPostalCodeSupported,
|
|
86
98
|
isSetupIntentClientSecret: () => isSetupIntentClientSecret,
|
|
99
|
+
isValidPostalCode: () => isValidPostalCode,
|
|
87
100
|
isValidPublishableKey: () => isValidPublishableKey,
|
|
88
101
|
isValidSecretKey: () => isValidSecretKey,
|
|
89
102
|
needsStripeMethodExplicitConfirm: () => needsStripeMethodExplicitConfirm,
|
|
@@ -183,7 +196,7 @@ var PAYMENT_METHOD_LOGOS = {
|
|
|
183
196
|
};
|
|
184
197
|
|
|
185
198
|
// src/constants.ts
|
|
186
|
-
var SDK_VERSION = "1.3.
|
|
199
|
+
var SDK_VERSION = "1.3.1";
|
|
187
200
|
var FLO_SDK_VERSION_HEADER = "x-flo-sdk-version";
|
|
188
201
|
var BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
|
|
189
202
|
var BILLING_API_URL_PRODUCTION = "https://api.flopay.com";
|
|
@@ -1960,6 +1973,67 @@ function getStateFromPostalCode(country, postalCode) {
|
|
|
1960
1973
|
}
|
|
1961
1974
|
}
|
|
1962
1975
|
|
|
1976
|
+
// src/postal-code-validation.ts
|
|
1977
|
+
var isPostalCodeModule = __toESM(require("validator/lib/isPostalCode.js"), 1);
|
|
1978
|
+
var mod = isPostalCodeModule;
|
|
1979
|
+
var isPostalCode = typeof mod.default === "function" ? mod.default : mod.default?.default;
|
|
1980
|
+
if (typeof isPostalCode !== "function") {
|
|
1981
|
+
throw new Error(
|
|
1982
|
+
"validator/lib/isPostalCode.js interop failed: unexpected module shape. This likely means the bundler's CJS/ESM interop changed."
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
var SUPPORTED_LOCALES = new Set(
|
|
1986
|
+
mod.locales.map((code) => code.toUpperCase())
|
|
1987
|
+
);
|
|
1988
|
+
var LOCALE_ALIASES = {
|
|
1989
|
+
UK: "GB"
|
|
1990
|
+
};
|
|
1991
|
+
function normalizeCountry(country) {
|
|
1992
|
+
const upper = country.trim().toUpperCase();
|
|
1993
|
+
return LOCALE_ALIASES[upper] ?? upper;
|
|
1994
|
+
}
|
|
1995
|
+
var POSTAL_CODE_EXAMPLES = {
|
|
1996
|
+
US: "12345 or 12345-6789",
|
|
1997
|
+
GB: "SW1A 1AA",
|
|
1998
|
+
CA: "A1A 1A1",
|
|
1999
|
+
AU: "2000",
|
|
2000
|
+
NZ: "6011",
|
|
2001
|
+
IE: "D02 AF30",
|
|
2002
|
+
DE: "10115",
|
|
2003
|
+
FR: "75008",
|
|
2004
|
+
NL: "1011 AB",
|
|
2005
|
+
ES: "28001",
|
|
2006
|
+
IT: "00100",
|
|
2007
|
+
IN: "110001",
|
|
2008
|
+
JP: "100-0001",
|
|
2009
|
+
BR: "01310-100",
|
|
2010
|
+
MX: "01000",
|
|
2011
|
+
SE: "114 55",
|
|
2012
|
+
CH: "8001",
|
|
2013
|
+
PL: "00-001",
|
|
2014
|
+
PT: "1000-001",
|
|
2015
|
+
SG: "570150",
|
|
2016
|
+
ZA: "0001",
|
|
2017
|
+
NO: "0001",
|
|
2018
|
+
DK: "1050",
|
|
2019
|
+
FI: "00100",
|
|
2020
|
+
AT: "1010",
|
|
2021
|
+
BE: "1000",
|
|
2022
|
+
CZ: "100 00"
|
|
2023
|
+
};
|
|
2024
|
+
function isPostalCodeSupported(country) {
|
|
2025
|
+
if (!country) return false;
|
|
2026
|
+
return SUPPORTED_LOCALES.has(normalizeCountry(country));
|
|
2027
|
+
}
|
|
2028
|
+
function isValidPostalCode(country, postalCode) {
|
|
2029
|
+
if (!isPostalCodeSupported(country)) return true;
|
|
2030
|
+
return isPostalCode(postalCode.trim(), normalizeCountry(country));
|
|
2031
|
+
}
|
|
2032
|
+
function getPostalCodeExample(country) {
|
|
2033
|
+
if (!country) return void 0;
|
|
2034
|
+
return POSTAL_CODE_EXAMPLES[normalizeCountry(country)];
|
|
2035
|
+
}
|
|
2036
|
+
|
|
1963
2037
|
// src/checkout-payload.ts
|
|
1964
2038
|
function nonBlank(value) {
|
|
1965
2039
|
if (typeof value !== "string") return void 0;
|
|
@@ -2217,6 +2291,7 @@ function isSetupIntentClientSecret(clientSecret) {
|
|
|
2217
2291
|
getCountryByCode,
|
|
2218
2292
|
getCurrencyByCountry,
|
|
2219
2293
|
getFloPayEnvironment,
|
|
2294
|
+
getPostalCodeExample,
|
|
2220
2295
|
getPostalCodeLabel,
|
|
2221
2296
|
getStateFromPostalCode,
|
|
2222
2297
|
getStateLabel,
|
|
@@ -2225,7 +2300,9 @@ function isSetupIntentClientSecret(clientSecret) {
|
|
|
2225
2300
|
hasVendoredStripeMethodLogo,
|
|
2226
2301
|
isAVSEnabled,
|
|
2227
2302
|
isAVSFieldVisible,
|
|
2303
|
+
isPostalCodeSupported,
|
|
2228
2304
|
isSetupIntentClientSecret,
|
|
2305
|
+
isValidPostalCode,
|
|
2229
2306
|
isValidPublishableKey,
|
|
2230
2307
|
isValidSecretKey,
|
|
2231
2308
|
needsStripeMethodExplicitConfirm,
|