@flopay/shared 1.3.1 → 1.3.2

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/index.d.cts CHANGED
@@ -1312,7 +1312,7 @@ declare function getConfiguredBillingApiUrl(): string;
1312
1312
  declare function getFloPayEnvironment(): FloPayEnvironment;
1313
1313
 
1314
1314
  /** Current SDK version. */
1315
- declare const SDK_VERSION = "1.3.1";
1315
+ declare const SDK_VERSION = "1.3.2";
1316
1316
  /**
1317
1317
  * HTTP header the SDK sends on `POST /v1/checkouts/sessions` so the backend
1318
1318
  * can decide whether to embed the vault capture block (the hosted PCI card
@@ -1746,24 +1746,33 @@ declare function getStateFromPostalCode(country: string, postalCode: string): st
1746
1746
 
1747
1747
  /**
1748
1748
  * True when `validator` has an authoritative postcode pattern for the country
1749
- * (ISO 3166-1 alpha-2, case-insensitive). Supported countries validate the
1750
- * postcode format; unsupported / no-postcode countries fail open.
1749
+ * (normalized to ISO 3166-1 alpha-2 via {@link normalizeCountryToIso2}).
1750
+ * Supported countries validate the postcode format; unsupported / no-postcode /
1751
+ * unresolvable countries fail open. Note the 2-letter passthrough means `UK`
1752
+ * (an unsupported `validator` locale) returns `false` here — matching the
1753
+ * backend; use the full name `United Kingdom` for `GB` semantics.
1751
1754
  */
1752
1755
  declare function isPostalCodeSupported(country: string): boolean;
1753
1756
  /**
1754
- * Validate a postcode against the country's expected format.
1757
+ * Validate a postcode against the country's expected format. A faithful mirror
1758
+ * of the backend's `isPostalCodeValidForCountry`, so the SDK never blocks a
1759
+ * value the server would accept, nor opens the submit gate on one it would
1760
+ * reject. Fail-open (returns `true`) in exactly the backend's three cases:
1755
1761
  *
1756
- * - Unsupported / no-postcode country → `true` (fail open; never block).
1757
- * - Supported country → `validator`'s `isPostalCode(zip, locale)` on the
1758
- * trimmed value. An empty string is not a valid postcode, so a supported
1759
- * country with an empty value returns `false`; callers that distinguish
1760
- * "required" (empty) from "malformed" (format) should check emptiness first.
1762
+ * - `postalCode` is blank / whitespace-only;
1763
+ * - the country can't be normalized to an ISO-2 locale;
1764
+ * - the ISO-2 locale isn't one `validator` recognises.
1765
+ *
1766
+ * Otherwise returns `validator`'s `isPostalCode(zip.trim(), locale)`. Callers
1767
+ * that distinguish "required" (empty) from "malformed" (bad format) must check
1768
+ * emptiness themselves — an empty value fails open here, as it does server-side.
1761
1769
  */
1762
1770
  declare function isValidPostalCode(country: string, postalCode: string): boolean;
1763
1771
  /**
1764
- * A curated example postcode for the country (e.g. US `12345 or 12345-6789`,
1765
- * GB `SW1A 1AA`, CA `A1A 1A1`), or `undefined` when there is no curated example
1766
- * (unsupported country, or a supported country not in the map).
1772
+ * The example postcode the backend would embed in its 400 message for the
1773
+ * country (e.g. US `12345 or 12345-6789`, GB `SW1A 1AA`, CA `A1A 1A1`), or
1774
+ * `undefined` when there is none (unresolvable country, or a supported country
1775
+ * absent from {@link POSTAL_CODE_EXAMPLES}).
1767
1776
  */
1768
1777
  declare function getPostalCodeExample(country: string): string | undefined;
1769
1778
 
package/dist/index.d.ts CHANGED
@@ -1312,7 +1312,7 @@ declare function getConfiguredBillingApiUrl(): string;
1312
1312
  declare function getFloPayEnvironment(): FloPayEnvironment;
1313
1313
 
1314
1314
  /** Current SDK version. */
1315
- declare const SDK_VERSION = "1.3.1";
1315
+ declare const SDK_VERSION = "1.3.2";
1316
1316
  /**
1317
1317
  * HTTP header the SDK sends on `POST /v1/checkouts/sessions` so the backend
1318
1318
  * can decide whether to embed the vault capture block (the hosted PCI card
@@ -1746,24 +1746,33 @@ declare function getStateFromPostalCode(country: string, postalCode: string): st
1746
1746
 
1747
1747
  /**
1748
1748
  * True when `validator` has an authoritative postcode pattern for the country
1749
- * (ISO 3166-1 alpha-2, case-insensitive). Supported countries validate the
1750
- * postcode format; unsupported / no-postcode countries fail open.
1749
+ * (normalized to ISO 3166-1 alpha-2 via {@link normalizeCountryToIso2}).
1750
+ * Supported countries validate the postcode format; unsupported / no-postcode /
1751
+ * unresolvable countries fail open. Note the 2-letter passthrough means `UK`
1752
+ * (an unsupported `validator` locale) returns `false` here — matching the
1753
+ * backend; use the full name `United Kingdom` for `GB` semantics.
1751
1754
  */
1752
1755
  declare function isPostalCodeSupported(country: string): boolean;
1753
1756
  /**
1754
- * Validate a postcode against the country's expected format.
1757
+ * Validate a postcode against the country's expected format. A faithful mirror
1758
+ * of the backend's `isPostalCodeValidForCountry`, so the SDK never blocks a
1759
+ * value the server would accept, nor opens the submit gate on one it would
1760
+ * reject. Fail-open (returns `true`) in exactly the backend's three cases:
1755
1761
  *
1756
- * - Unsupported / no-postcode country → `true` (fail open; never block).
1757
- * - Supported country → `validator`'s `isPostalCode(zip, locale)` on the
1758
- * trimmed value. An empty string is not a valid postcode, so a supported
1759
- * country with an empty value returns `false`; callers that distinguish
1760
- * "required" (empty) from "malformed" (format) should check emptiness first.
1762
+ * - `postalCode` is blank / whitespace-only;
1763
+ * - the country can't be normalized to an ISO-2 locale;
1764
+ * - the ISO-2 locale isn't one `validator` recognises.
1765
+ *
1766
+ * Otherwise returns `validator`'s `isPostalCode(zip.trim(), locale)`. Callers
1767
+ * that distinguish "required" (empty) from "malformed" (bad format) must check
1768
+ * emptiness themselves — an empty value fails open here, as it does server-side.
1761
1769
  */
1762
1770
  declare function isValidPostalCode(country: string, postalCode: string): boolean;
1763
1771
  /**
1764
- * A curated example postcode for the country (e.g. US `12345 or 12345-6789`,
1765
- * GB `SW1A 1AA`, CA `A1A 1A1`), or `undefined` when there is no curated example
1766
- * (unsupported country, or a supported country not in the map).
1772
+ * The example postcode the backend would embed in its 400 message for the
1773
+ * country (e.g. US `12345 or 12345-6789`, GB `SW1A 1AA`, CA `A1A 1A1`), or
1774
+ * `undefined` when there is none (unresolvable country, or a supported country
1775
+ * absent from {@link POSTAL_CODE_EXAMPLES}).
1767
1776
  */
1768
1777
  declare function getPostalCodeExample(country: string): string | undefined;
1769
1778
 
package/dist/index.mjs CHANGED
@@ -79,7 +79,7 @@ var PAYMENT_METHOD_LOGOS = {
79
79
  };
80
80
 
81
81
  // src/constants.ts
82
- var SDK_VERSION = "1.3.1";
82
+ var SDK_VERSION = "1.3.2";
83
83
  var FLO_SDK_VERSION_HEADER = "x-flo-sdk-version";
84
84
  var BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
85
85
  var BILLING_API_URL_PRODUCTION = "https://api.flopay.com";
@@ -1868,53 +1868,93 @@ if (typeof isPostalCode !== "function") {
1868
1868
  var SUPPORTED_LOCALES = new Set(
1869
1869
  mod.locales.map((code) => code.toUpperCase())
1870
1870
  );
1871
- var LOCALE_ALIASES = {
1872
- UK: "GB"
1871
+ var COUNTRY_ALIASES = {
1872
+ AUSTRALIA: "AU",
1873
+ BRAZIL: "BR",
1874
+ CANADA: "CA",
1875
+ CH: "CH",
1876
+ DENMARK: "DK",
1877
+ DE: "DE",
1878
+ DEUTSCHLAND: "DE",
1879
+ FRANCE: "FR",
1880
+ GB: "GB",
1881
+ GERMANY: "DE",
1882
+ GREATBRITAIN: "GB",
1883
+ GREAT_BRITAIN: "GB",
1884
+ INDIA: "IN",
1885
+ IRELAND: "IE",
1886
+ ITALY: "IT",
1887
+ JAPAN: "JP",
1888
+ MEXICO: "MX",
1889
+ NETHERLANDS: "NL",
1890
+ NEWZEALAND: "NZ",
1891
+ NORWAY: "NO",
1892
+ POLAND: "PL",
1893
+ PORTUGAL: "PT",
1894
+ SINGAPORE: "SG",
1895
+ SOUTHAFRICA: "ZA",
1896
+ SPAIN: "ES",
1897
+ SWEDEN: "SE",
1898
+ SWITZERLAND: "CH",
1899
+ UK: "GB",
1900
+ UNITEDKINGDOM: "GB",
1901
+ UNITEDSTATES: "US",
1902
+ US: "US",
1903
+ USA: "US",
1904
+ "UNITED STATES": "US",
1905
+ "UNITED KINGDOM": "GB",
1906
+ "GREAT BRITAIN": "GB",
1907
+ ENGLAND: "GB"
1873
1908
  };
1874
- function normalizeCountry(country) {
1875
- const upper = country.trim().toUpperCase();
1876
- return LOCALE_ALIASES[upper] ?? upper;
1909
+ function normalizeCountryToIso2(country) {
1910
+ const upper = (country ?? "").trim().toUpperCase();
1911
+ if (!upper) return null;
1912
+ if (upper.length === 2) return upper;
1913
+ return COUNTRY_ALIASES[upper] ?? null;
1877
1914
  }
1878
1915
  var POSTAL_CODE_EXAMPLES = {
1879
- US: "12345 or 12345-6789",
1880
- GB: "SW1A 1AA",
1881
- CA: "A1A 1A1",
1882
1916
  AU: "2000",
1883
- NZ: "6011",
1884
- IE: "D02 AF30",
1917
+ BR: "01000-000",
1918
+ CA: "A1A 1A1",
1919
+ CH: "8001",
1885
1920
  DE: "10115",
1886
- FR: "75008",
1887
- NL: "1011 AB",
1921
+ DK: "1050",
1888
1922
  ES: "28001",
1889
- IT: "00100",
1923
+ FR: "75008",
1924
+ GB: "SW1A 1AA",
1925
+ IE: "D02 X285",
1890
1926
  IN: "110001",
1927
+ IT: "00118",
1891
1928
  JP: "100-0001",
1892
- BR: "01310-100",
1893
- MX: "01000",
1894
- SE: "114 55",
1895
- CH: "8001",
1929
+ MX: "06500",
1930
+ NL: "1012 JS",
1931
+ NO: "0150",
1932
+ NZ: "6011",
1896
1933
  PL: "00-001",
1897
- PT: "1000-001",
1898
- SG: "570150",
1899
- ZA: "0001",
1900
- NO: "0001",
1901
- DK: "1050",
1902
- FI: "00100",
1903
- AT: "1010",
1904
- BE: "1000",
1905
- CZ: "100 00"
1934
+ PT: "1100-148",
1935
+ SE: "111 22",
1936
+ SG: "018989",
1937
+ US: "12345 or 12345-6789",
1938
+ ZA: "8001"
1906
1939
  };
1907
1940
  function isPostalCodeSupported(country) {
1908
- if (!country) return false;
1909
- return SUPPORTED_LOCALES.has(normalizeCountry(country));
1941
+ const iso2 = normalizeCountryToIso2(country);
1942
+ return iso2 !== null && SUPPORTED_LOCALES.has(iso2);
1910
1943
  }
1911
1944
  function isValidPostalCode(country, postalCode) {
1912
- if (!isPostalCodeSupported(country)) return true;
1913
- return isPostalCode(postalCode.trim(), normalizeCountry(country));
1945
+ const trimmed = (postalCode ?? "").trim();
1946
+ if (!trimmed) return true;
1947
+ const iso2 = normalizeCountryToIso2(country);
1948
+ if (iso2 === null || !SUPPORTED_LOCALES.has(iso2)) return true;
1949
+ try {
1950
+ return isPostalCode(trimmed, iso2);
1951
+ } catch {
1952
+ return true;
1953
+ }
1914
1954
  }
1915
1955
  function getPostalCodeExample(country) {
1916
- if (!country) return void 0;
1917
- return POSTAL_CODE_EXAMPLES[normalizeCountry(country)];
1956
+ const iso2 = normalizeCountryToIso2(country);
1957
+ return iso2 ? POSTAL_CODE_EXAMPLES[iso2] : void 0;
1918
1958
  }
1919
1959
 
1920
1960
  // src/checkout-payload.ts