UNPKG

@ideal-postcodes/address-finder

Version:

Address Finder JS library backed by the Ideal Postcodes UK address search API

769 lines (768 loc) 26.7 kB
import { AddressFormat } from "./controller"; import { Client } from "@ideal-postcodes/core-axios"; import { AddressSuggestion } from "@ideal-postcodes/jsutil"; export type QueryOptions = Record<string, string>; export type ResolveOptions = Record<string, string>; /** * @hidden */ type Suggestions = AddressSuggestion[] | Promise<AddressSuggestion[]>; /** * @hidden */ export declare class ApiCache { client: Client; cache: Record<string, Suggestions>; prefix: string; constructor(client: Client); key(query: string): string; retrieve(query: string): Suggestions | undefined; store(query: string, data: Suggestions): Suggestions; clear(): void; /** * Retrieve a list of address suggestions given a query * * Write and read from cache if previously requested */ query(query: string, options?: QueryOptions): Promise<AddressSuggestion[]>; resolve(suggestion: AddressSuggestion, format: AddressFormat, options?: ResolveOptions): Promise<{ id: string; dataset: "usps"; country: "United States" | "Guam" | "Puerto Rico"; country_iso: "USA" | "PRI" | "GUM"; country_iso_2: "US" | "PR" | "GU"; language: "en"; primary_number: string; secondary_number: string; plus_4_code: string; line_1: string; line_2: string; last_line: string; zip_code: string; zip_plus_4_code: string; update_key_number: string; record_type_code: "" | "S" | "G" | "H" | "F" | "P" | "R" | "M"; carrier_route_id: string; street_pre_directional_abbreviation: string; street_name: string; street_suffix_abbreviation: string; street_post_directional_abbreviation: string; building_or_firm_name: string; address_secondary_abbreviation: string; base_alternate_code: "" | "A" | "B"; lacs_status_indicator: "" | "L"; government_building_indicator: "" | "G" | "F" | "A" | "B" | "C" | "D" | "E"; state_abbreviation: string; state: string; municipality_city_state_key: string; urbanization_city_state_key: string; preferred_last_line_city_state_key: string; county: string; city: string; city_abbreviation: string; preferred_city: string; city_state_name_facility_code: "" | "S" | "P" | "B" | "C" | "N" | "U" | "Y"; zip_classification_code: "" | "P" | "M" | "U"; city_state_mailing_name_indicator: string; carrier_route_rate_sortation: string; finance_number: string | number; congressional_district_number: string | number; county_number: string | number; } | { id: string; dataset: "paf" | "mr" | "nyb" | "pafa" | "pafw" | "usps" | "ecaf" | "ecad"; country: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | "United States" | "Guam" | "Puerto Rico" | "Ireland"; country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM" | "IRL"; country_iso_2: "GB" | "IM" | "JE" | "GG" | "US" | "PR" | "GU" | "IE"; language: "en" | "cy" | "ga"; primary_number: ""; secondary_number: ""; plus_4_code: ""; line_1: string; line_2: string; last_line: ""; zip_code: string; zip_plus_4_code: string; update_key_number: ""; record_type_code: ""; carrier_route_id: ""; street_pre_directional_abbreviation: ""; street_name: ""; street_suffix_abbreviation: ""; street_post_directional_abbreviation: ""; building_or_firm_name: ""; address_secondary_abbreviation: ""; base_alternate_code: ""; lacs_status_indicator: ""; government_building_indicator: ""; state: string; state_abbreviation: string; municipality_city_state_key: ""; urbanization_city_state_key: ""; preferred_last_line_city_state_key: ""; county: string; city: string; city_abbreviation: string; preferred_city: ""; city_state_name_facility_code: ""; zip_classification_code: ""; city_state_mailing_name_indicator: ""; carrier_route_rate_sortation: ""; finance_number: ""; congressional_district_number: ""; county_number: ""; }> | Promise<({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; dataset?: "paf" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "mr" | undefined; country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "nyb" | undefined; country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "pafa" | undefined; country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "pafw" | undefined; country_iso?: "GBR" | undefined; country_iso_2?: "GB" | undefined; language?: "cy" | undefined; country?: "Wales" | undefined; }) | { id: string; dataset: "paf" | "mr" | "nyb" | "pafa" | "pafw" | "usps" | "ecaf" | "ecad"; country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM" | "IRL"; country_iso_2: "GB" | "IM" | "JE" | "GG" | "US" | "PR" | "GU" | "IE"; language: "en" | "cy" | "ga"; line_1: string; line_2: string; line_3: string; postcode: string; post_town: string; county: string; county_code: string; longitude: string | number; latitude: string | number; country: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | "United States" | "Guam" | "Puerto Rico" | "Ireland"; postcode_outward: ""; postcode_inward: ""; dependant_locality: ""; double_dependant_locality: ""; thoroughfare: ""; dependant_thoroughfare: ""; building_number: ""; building_name: ""; sub_building_name: ""; premise: ""; po_box: ""; department_name: ""; organisation_name: ""; udprn: ""; umprn: ""; postcode_type: ""; su_organisation_indicator: ""; delivery_point_suffix: ""; administrative_county: ""; postal_county: ""; traditional_county: ""; district: ""; ward: ""; eastings: ""; northings: ""; uprn: ""; }>; usaResolve(suggestion: AddressSuggestion, options?: ResolveOptions): Promise<{ id: string; dataset: "usps"; country: "United States" | "Guam" | "Puerto Rico"; country_iso: "USA" | "PRI" | "GUM"; country_iso_2: "US" | "PR" | "GU"; language: "en"; primary_number: string; secondary_number: string; plus_4_code: string; line_1: string; line_2: string; last_line: string; zip_code: string; zip_plus_4_code: string; update_key_number: string; record_type_code: "" | "S" | "G" | "H" | "F" | "P" | "R" | "M"; carrier_route_id: string; street_pre_directional_abbreviation: string; street_name: string; street_suffix_abbreviation: string; street_post_directional_abbreviation: string; building_or_firm_name: string; address_secondary_abbreviation: string; base_alternate_code: "" | "A" | "B"; lacs_status_indicator: "" | "L"; government_building_indicator: "" | "G" | "F" | "A" | "B" | "C" | "D" | "E"; state_abbreviation: string; state: string; municipality_city_state_key: string; urbanization_city_state_key: string; preferred_last_line_city_state_key: string; county: string; city: string; city_abbreviation: string; preferred_city: string; city_state_name_facility_code: "" | "S" | "P" | "B" | "C" | "N" | "U" | "Y"; zip_classification_code: "" | "P" | "M" | "U"; city_state_mailing_name_indicator: string; carrier_route_rate_sortation: string; finance_number: string | number; congressional_district_number: string | number; county_number: string | number; } | { id: string; dataset: "paf" | "mr" | "nyb" | "pafa" | "pafw" | "usps" | "ecaf" | "ecad"; country: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | "United States" | "Guam" | "Puerto Rico" | "Ireland"; country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM" | "IRL"; country_iso_2: "GB" | "IM" | "JE" | "GG" | "US" | "PR" | "GU" | "IE"; language: "en" | "cy" | "ga"; primary_number: ""; secondary_number: ""; plus_4_code: ""; line_1: string; line_2: string; last_line: ""; zip_code: string; zip_plus_4_code: string; update_key_number: ""; record_type_code: ""; carrier_route_id: ""; street_pre_directional_abbreviation: ""; street_name: ""; street_suffix_abbreviation: ""; street_post_directional_abbreviation: ""; building_or_firm_name: ""; address_secondary_abbreviation: ""; base_alternate_code: ""; lacs_status_indicator: ""; government_building_indicator: ""; state: string; state_abbreviation: string; municipality_city_state_key: ""; urbanization_city_state_key: ""; preferred_last_line_city_state_key: ""; county: string; city: string; city_abbreviation: string; preferred_city: ""; city_state_name_facility_code: ""; zip_classification_code: ""; city_state_mailing_name_indicator: ""; carrier_route_rate_sortation: ""; finance_number: ""; congressional_district_number: ""; county_number: ""; }>; gbrResolve(suggestion: AddressSuggestion, options?: ResolveOptions): Promise<({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; dataset?: "paf" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "mr" | undefined; country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "nyb" | undefined; country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "pafa" | undefined; country_iso?: "GBR" | "IMN" | "JEY" | "GGY" | undefined; country_iso_2?: "GB" | "IM" | "JE" | "GG" | undefined; language?: "en" | undefined; country?: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | undefined; }) | ({ id: string; dataset: string; country_iso: string; country_iso_2: string; country: string; language: string; line_1: string; line_2: string; line_3: string; post_town: string; postcode: string; county: string; county_code: string; uprn: string; udprn: number; umprn: string | number; postcode_outward: string; postcode_inward: string; dependant_locality: string; double_dependant_locality: string; thoroughfare: string; dependant_thoroughfare: string; building_number: string; building_name: string; sub_building_name: string; po_box: string; department_name: string; organisation_name: string; postcode_type: "S" | "L"; su_organisation_indicator: string; delivery_point_suffix: string; premise: string; administrative_county: string; postal_county: string; traditional_county: string; district: string; ward: string; longitude: string | number; latitude: string | number; eastings: string | number; northings: string | number; } & { dataset?: "pafw" | undefined; country_iso?: "GBR" | undefined; country_iso_2?: "GB" | undefined; language?: "cy" | undefined; country?: "Wales" | undefined; }) | { id: string; dataset: "paf" | "mr" | "nyb" | "pafa" | "pafw" | "usps" | "ecaf" | "ecad"; country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM" | "IRL"; country_iso_2: "GB" | "IM" | "JE" | "GG" | "US" | "PR" | "GU" | "IE"; language: "en" | "cy" | "ga"; line_1: string; line_2: string; line_3: string; postcode: string; post_town: string; county: string; county_code: string; longitude: string | number; latitude: string | number; country: "England" | "Scotland" | "Wales" | "Northern Ireland" | "Jersey" | "Guernsey" | "Isle of Man" | "United States" | "Guam" | "Puerto Rico" | "Ireland"; postcode_outward: ""; postcode_inward: ""; dependant_locality: ""; double_dependant_locality: ""; thoroughfare: ""; dependant_thoroughfare: ""; building_number: ""; building_name: ""; sub_building_name: ""; premise: ""; po_box: ""; department_name: ""; organisation_name: ""; udprn: ""; umprn: ""; postcode_type: ""; su_organisation_indicator: ""; delivery_point_suffix: ""; administrative_county: ""; postal_county: ""; traditional_county: ""; district: ""; ward: ""; eastings: ""; northings: ""; uprn: ""; }>; } export {};