@simplybusiness/mobius 6.3.3 → 6.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8f5b73a: pass in filters record to LoqateAddressLookupService to support US state filtering
8
+
3
9
  ## 6.3.3
4
10
 
5
11
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -1888,14 +1888,21 @@ var LoqateAddressLookupService = class {
1888
1888
  * 2 or 3 character ISO country codes
1889
1889
  */
1890
1890
  #countries;
1891
+ /**
1892
+ * Optional filters for the Loqate API
1893
+ * E.g., { AdministrativeArea: "CA", PostalCode: "90210" }
1894
+ */
1895
+ #filters;
1891
1896
  constructor({
1892
1897
  baseUrl,
1893
1898
  apiKey,
1894
- countries
1899
+ countries,
1900
+ filters
1895
1901
  }) {
1896
1902
  this.#apiKey = apiKey;
1897
1903
  this.#baseUrl = baseUrl || LOQATE_BASE_URL;
1898
1904
  this.#countries = countries || DEFAULT_COUNTRIES;
1905
+ this.#filters = filters;
1899
1906
  }
1900
1907
  fetchFromApi(url) {
1901
1908
  return fetch(`${this.#baseUrl}${url}`).then((response) => response.json()).then((json) => {
@@ -1905,12 +1912,28 @@ var LoqateAddressLookupService = class {
1905
1912
  return json;
1906
1913
  });
1907
1914
  }
1915
+ /**
1916
+ * Builds the Filters query parameter for Loqate API requests.
1917
+ * - Filter keys (e.g., "AdministrativeArea", "PostalCode") are predefined by Loqate API (no need to encode)
1918
+ * - Filter values (e.g., "New York", "90210") contain user input that may have special characters (need encoding)
1919
+ *
1920
+ * @returns Empty string if no filters, otherwise "&Filters=key1:value1&key2:value2" (Loqate's expected format for Filters)
1921
+ */
1922
+ buildFiltersQuery() {
1923
+ if (!this.#filters || Object.keys(this.#filters).length === 0) {
1924
+ return "";
1925
+ }
1926
+ const encodedFilters = Object.entries(this.#filters).map(([key, value]) => `${key}:${encodeURIComponent(value)}`).join("&");
1927
+ return `&Filters=${encodedFilters}`;
1928
+ }
1908
1929
  search(searchTerm) {
1909
- const url = `${LOQATE_FIND_URL}?Key=${this.#apiKey}&Text=${searchTerm}&Countries=${this.#countries?.join(",")}`;
1930
+ let url = `${LOQATE_FIND_URL}?Key=${this.#apiKey}&Text=${searchTerm}&Countries=${this.#countries?.join(",")}`;
1931
+ url += this.buildFiltersQuery();
1910
1932
  return this.fetchFromApi(url);
1911
1933
  }
1912
1934
  findById(id) {
1913
- const url = `${LOQATE_FIND_URL}?Key=${this.#apiKey}&Container=${id}&Countries=${this.#countries?.join(",")}`;
1935
+ let url = `${LOQATE_FIND_URL}?Key=${this.#apiKey}&Container=${id}&Countries=${this.#countries?.join(",")}`;
1936
+ url += this.buildFiltersQuery();
1914
1937
  return this.fetchFromApi(url);
1915
1938
  }
1916
1939
  async get(id) {