@ideal-postcodes/address-finder
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -0,1 +1,13 @@ | ||
# [4.0.0](https://github.com/ideal-postcodes/address-finder/compare/3.1.0...4.0.0) (2022-08-09) | ||
### Features | ||
* **Countries:** Detect countries on Startup ([4992708](https://github.com/ideal-postcodes/address-finder/commit/4992708781200153662f0ac4216dad946455c7b2)) | ||
### BREAKING CHANGES | ||
* **Countries:** Local country will be detected by IP address | ||
# [3.1.0](https://github.com/ideal-postcodes/address-finder/compare/3.0.1...3.1.0) (2022-04-14) | ||
@@ -2,0 +14,0 @@ |
@@ -30,4 +30,6 @@ import { AddressFormat } from "./controller"; | ||
dataset: "usps"; | ||
country?: "United States" | "Guam" | "Puerto Rico" | undefined; | ||
country: "United States" | "Guam" | "Puerto Rico"; | ||
country_iso: "USA" | "PRI" | "GUM"; | ||
country_iso_2: "US" | "PR" | "GU"; | ||
language: "en"; | ||
primary_number: string; | ||
@@ -71,5 +73,7 @@ secondary_number: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country?: string | undefined; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
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: ""; | ||
@@ -111,7 +115,21 @@ secondary_number: ""; | ||
county_number: ""; | ||
}> | Promise<{ | ||
}> | 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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -127,13 +145,54 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
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; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -144,15 +203,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} | ({ | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -168,13 +243,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -185,17 +253,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
longitude: string | number; | ||
latitude: string | number; | ||
eastings: string | number; | ||
northings: string | number; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -211,13 +293,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -228,17 +303,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
}) | { | ||
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; | ||
postcode_outward: ""; | ||
postcode_inward: ""; | ||
post_town: string; | ||
county: string; | ||
county_code: string; | ||
uprn: string; | ||
udprn: number; | ||
umprn: string | number; | ||
postcode_outward: string; | ||
postcode_inward: string; | ||
dependant_locality: string; | ||
@@ -254,2 +343,50 @@ double_dependant_locality: 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: ""; | ||
@@ -260,21 +397,10 @@ umprn: ""; | ||
delivery_point_suffix: ""; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: ""; | ||
postal_county: ""; | ||
traditional_county: ""; | ||
district: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
district: ""; | ||
ward: ""; | ||
eastings: ""; | ||
northings: ""; | ||
uprn: ""; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
}>; | ||
@@ -284,4 +410,6 @@ usaResolve(suggestion: AddressSuggestion): Promise<{ | ||
dataset: "usps"; | ||
country?: "United States" | "Guam" | "Puerto Rico" | undefined; | ||
country: "United States" | "Guam" | "Puerto Rico"; | ||
country_iso: "USA" | "PRI" | "GUM"; | ||
country_iso_2: "US" | "PR" | "GU"; | ||
language: "en"; | ||
primary_number: string; | ||
@@ -325,5 +453,7 @@ secondary_number: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country?: string | undefined; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
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: ""; | ||
@@ -366,7 +496,21 @@ secondary_number: ""; | ||
}>; | ||
gbrResolve(suggestion: AddressSuggestion): Promise<{ | ||
gbrResolve(suggestion: AddressSuggestion): 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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -382,13 +526,54 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
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; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -399,15 +584,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} | ({ | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -423,13 +624,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -440,17 +634,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
longitude: string | number; | ||
latitude: string | number; | ||
eastings: string | number; | ||
northings: string | number; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -466,13 +674,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -483,17 +684,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
}) | { | ||
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; | ||
postcode_outward: ""; | ||
postcode_inward: ""; | ||
post_town: string; | ||
county: string; | ||
county_code: string; | ||
uprn: string; | ||
udprn: number; | ||
umprn: string | number; | ||
postcode_outward: string; | ||
postcode_inward: string; | ||
dependant_locality: string; | ||
@@ -509,2 +724,50 @@ double_dependant_locality: 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: ""; | ||
@@ -515,23 +778,12 @@ umprn: ""; | ||
delivery_point_suffix: ""; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: ""; | ||
postal_county: ""; | ||
traditional_county: ""; | ||
district: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
district: ""; | ||
ward: ""; | ||
eastings: ""; | ||
northings: ""; | ||
uprn: ""; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
}>; | ||
} | ||
export {}; |
@@ -1,14 +0,11 @@ | ||
export declare type Context = "GBR" | "USA"; | ||
export interface Details { | ||
name: string; | ||
icon: string; | ||
export interface ContextDetails { | ||
iso_2: string; | ||
iso_3: string; | ||
emoji: string; | ||
rgeo: boolean; | ||
description: string; | ||
} | ||
declare type ContextStore = Record<string, Details>; | ||
export declare type ContextStore = Record<string, ContextDetails>; | ||
export declare const defaultContexts: ContextStore; | ||
export interface ContextDetails { | ||
name: string; | ||
icon: string; | ||
code: string; | ||
} | ||
export declare const toContextList: (contexts: ContextStore, restrictCountries: string[]) => ContextDetails[]; | ||
export {}; | ||
export declare const toContextMap: (contexts: ContextDetails[]) => ContextStore; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toContextList = exports.defaultContexts = void 0; | ||
exports.toContextMap = exports.toContextList = exports.defaultContexts = void 0; | ||
exports.defaultContexts = { | ||
GBR: { | ||
name: "United Kingdom", | ||
icon: "🇬🇧", | ||
iso_2: "GB", | ||
iso_3: "GBR", | ||
emoji: "🇬🇧", | ||
rgeo: true, | ||
description: "United Kingdom", | ||
}, | ||
USA: { | ||
name: "United States", | ||
icon: "🇺🇸", | ||
iso_2: "US", | ||
iso_3: "USA", | ||
emoji: "🇺🇸", | ||
rgeo: false, | ||
description: "United States", | ||
}, | ||
@@ -21,8 +27,15 @@ }; | ||
continue; | ||
const { name, icon } = contexts[code]; | ||
result.push({ code, name, icon }); | ||
result.push(contexts[code]); | ||
} | ||
result.sort((b, a) => b.name.localeCompare(a.name)); | ||
result.sort((b, a) => b.description.localeCompare(a.description)); | ||
return result; | ||
}; | ||
exports.toContextList = toContextList; | ||
const toContextMap = (contexts) => { | ||
const result = {}; | ||
for (const context of contexts) { | ||
result[context.iso_3] = context; | ||
} | ||
return result; | ||
}; | ||
exports.toContextMap = toContextMap; |
@@ -6,3 +6,3 @@ /** | ||
import { Callbacks, Listener } from "./callbacks"; | ||
import { Context, Details, ContextDetails } from "./contexts"; | ||
import { ContextStore, ContextDetails } from "./contexts"; | ||
import { DebouncedFunc } from "lodash"; | ||
@@ -52,3 +52,3 @@ import { ApiCache, QueryOptions } from "./cache"; | ||
*/ | ||
defaultCountry?: Context; | ||
defaultCountry?: string; | ||
/** | ||
@@ -65,7 +65,7 @@ * Narrow the countries you wish to support | ||
*/ | ||
restrictCountries?: Context[]; | ||
restrictCountries?: string[]; | ||
/** | ||
* Provide a custom list of possible contexts to select a new country or context from | ||
*/ | ||
contexts?: Record<string, Details>; | ||
contexts?: Record<string, ContextDetails>; | ||
/** | ||
@@ -162,2 +162,7 @@ * Specify parent element for output fields to looking for them to narrow search area | ||
/** | ||
* Detects country based on IP address. | ||
* @default true | ||
*/ | ||
detectCountry?: boolean; | ||
/** | ||
* Inject stylesheet into DOM to style Address Finder with default theme. Default is `true` | ||
@@ -587,2 +592,3 @@ * | ||
init(): Promise<void>; | ||
updateContexts(contexts: ContextStore): void; | ||
/** | ||
@@ -669,3 +675,3 @@ * Render available country options | ||
*/ | ||
applyContext(details: ContextDetails): void; | ||
applyContext(details: ContextDetails, announce?: boolean): void; | ||
/** | ||
@@ -672,0 +678,0 @@ * Renders notification box |
@@ -52,2 +52,3 @@ "use strict"; | ||
hideToolbar: false, | ||
detectCountry: true, | ||
// Country | ||
@@ -146,3 +147,4 @@ defaultCountry: "GBR", | ||
this.suggestions = []; | ||
this.contextSuggestions = contexts_1.toContextList(this.options.contexts, this.options.restrictCountries); | ||
this.contextSuggestions = []; | ||
this.updateContexts(this.options.contexts); | ||
this.client = new core_axios_1.Client({ ...this.options, api_key: this.options.apiKey }); | ||
@@ -193,3 +195,3 @@ this.cache = new cache_1.ApiCache(this.client); | ||
this.countryIcon.className = "idpc_icon"; | ||
this.countryIcon.innerText = this.currentContext().icon; | ||
this.countryIcon.innerText = this.currentContext().emoji; | ||
this.countryMessage = this.options.document.createElement("span"); | ||
@@ -292,7 +294,6 @@ this.countryMessage.innerText = "Select Country"; | ||
const c = this.options.contexts[this.context]; | ||
return { | ||
code: this.context, | ||
name: c.name, | ||
icon: c.icon, | ||
}; | ||
if (c) | ||
return c; | ||
const first = Object.keys(this.options.contexts)[0]; | ||
return this.options.contexts[first]; | ||
} | ||
@@ -324,2 +325,17 @@ /** | ||
throw new Error("Key currently not usable"); | ||
this.updateContexts( | ||
// TODO: Remove cast when openapi updated | ||
contexts_1.toContextMap(response.contexts)); | ||
// Methods to apply context | ||
// 1. If detect country enabled and match, if no match | ||
// 2. Apply default context, if no match | ||
// 3. Apply first item of context list | ||
// If detect country enabled, set country to default | ||
const details = this.options.contexts[response.context]; | ||
if (this.options.detectCountry && details) { | ||
this.applyContext(details, false); | ||
} | ||
else { | ||
this.applyContext(this.currentContext(), false); | ||
} | ||
this.load(); | ||
@@ -334,2 +350,7 @@ resolve(); | ||
} | ||
// Updates lists of available contexts | ||
updateContexts(contexts) { | ||
this.contextSuggestions = contexts_1.toContextList(contexts, this.options.restrictCountries); | ||
this.options.contexts = contexts; | ||
} | ||
/** | ||
@@ -341,5 +362,5 @@ * Render available country options | ||
this.contextSuggestions.forEach((contextDetails, i) => { | ||
const { name } = contextDetails; | ||
const { description } = contextDetails; | ||
const li = this.options.document.createElement("li"); | ||
li.textContent = name; | ||
li.textContent = description; | ||
li.setAttribute("aria-selected", "false"); | ||
@@ -575,8 +596,9 @@ li.setAttribute("tabindex", "-1"); | ||
*/ | ||
applyContext(details) { | ||
const context = details.code; | ||
applyContext(details, announce = true) { | ||
const context = details.iso_3; | ||
this.context = context; | ||
this.cache.clear(); | ||
this.countryIcon.innerText = details.icon; | ||
this.announce(`Country switched to ${details.name}`); | ||
this.countryIcon.innerText = details.emoji; | ||
if (announce) | ||
this.announce(`Country switched to ${details.description}`); | ||
} | ||
@@ -583,0 +605,0 @@ /** |
@@ -238,3 +238,3 @@ "use strict"; | ||
c.applyContext(co); | ||
c.notification = `Country switched to ${co.name} ${co.icon}`; | ||
c.notification = `Country switched to ${co.description} ${co.emoji}`; | ||
}, | ||
@@ -241,0 +241,0 @@ /** |
@@ -30,4 +30,6 @@ import { AddressFormat } from "./controller"; | ||
dataset: "usps"; | ||
country?: "United States" | "Guam" | "Puerto Rico" | undefined; | ||
country: "United States" | "Guam" | "Puerto Rico"; | ||
country_iso: "USA" | "PRI" | "GUM"; | ||
country_iso_2: "US" | "PR" | "GU"; | ||
language: "en"; | ||
primary_number: string; | ||
@@ -71,5 +73,7 @@ secondary_number: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country?: string | undefined; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
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: ""; | ||
@@ -111,7 +115,21 @@ secondary_number: ""; | ||
county_number: ""; | ||
}> | Promise<{ | ||
}> | 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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -127,13 +145,54 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
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; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -144,15 +203,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} | ({ | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -168,13 +243,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -185,17 +253,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
longitude: string | number; | ||
latitude: string | number; | ||
eastings: string | number; | ||
northings: string | number; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -211,13 +293,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -228,17 +303,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
}) | { | ||
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; | ||
postcode_outward: ""; | ||
postcode_inward: ""; | ||
post_town: string; | ||
county: string; | ||
county_code: string; | ||
uprn: string; | ||
udprn: number; | ||
umprn: string | number; | ||
postcode_outward: string; | ||
postcode_inward: string; | ||
dependant_locality: string; | ||
@@ -254,2 +343,50 @@ double_dependant_locality: 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: ""; | ||
@@ -260,21 +397,10 @@ umprn: ""; | ||
delivery_point_suffix: ""; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: ""; | ||
postal_county: ""; | ||
traditional_county: ""; | ||
district: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
district: ""; | ||
ward: ""; | ||
eastings: ""; | ||
northings: ""; | ||
uprn: ""; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
}>; | ||
@@ -284,4 +410,6 @@ usaResolve(suggestion: AddressSuggestion): Promise<{ | ||
dataset: "usps"; | ||
country?: "United States" | "Guam" | "Puerto Rico" | undefined; | ||
country: "United States" | "Guam" | "Puerto Rico"; | ||
country_iso: "USA" | "PRI" | "GUM"; | ||
country_iso_2: "US" | "PR" | "GU"; | ||
language: "en"; | ||
primary_number: string; | ||
@@ -325,5 +453,7 @@ secondary_number: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country?: string | undefined; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
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: ""; | ||
@@ -366,7 +496,21 @@ secondary_number: ""; | ||
}>; | ||
gbrResolve(suggestion: AddressSuggestion): Promise<{ | ||
gbrResolve(suggestion: AddressSuggestion): 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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -382,13 +526,54 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
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; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -399,15 +584,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} | ({ | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -423,13 +624,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -440,17 +634,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: string; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
longitude: string | number; | ||
latitude: string | number; | ||
eastings: string | number; | ||
northings: string | number; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
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; | ||
post_town: string; | ||
dependant_locality: string; | ||
@@ -466,13 +674,6 @@ double_dependant_locality: string; | ||
organisation_name: string; | ||
udprn: number; | ||
umprn: number | ""; | ||
postcode_type: "S" | "L"; | ||
su_organisation_indicator: string; | ||
delivery_point_suffix: string; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: string; | ||
@@ -483,17 +684,31 @@ postal_county: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
eastings: number | ""; | ||
northings: number | ""; | ||
uprn: 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: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
} & { | ||
dataset?: "paf" | "mr" | "nyb" | "usps" | undefined; | ||
}) | { | ||
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; | ||
postcode_outward: ""; | ||
postcode_inward: ""; | ||
post_town: string; | ||
county: string; | ||
county_code: string; | ||
uprn: string; | ||
udprn: number; | ||
umprn: string | number; | ||
postcode_outward: string; | ||
postcode_inward: string; | ||
dependant_locality: string; | ||
@@ -509,2 +724,50 @@ double_dependant_locality: 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: ""; | ||
@@ -515,23 +778,12 @@ umprn: ""; | ||
delivery_point_suffix: ""; | ||
line_1: string; | ||
line_2: string; | ||
line_3: string; | ||
premise: string; | ||
country: string; | ||
county: string; | ||
administrative_county: ""; | ||
postal_county: ""; | ||
traditional_county: ""; | ||
district: string; | ||
ward: string; | ||
longitude: number | ""; | ||
latitude: number | ""; | ||
district: ""; | ||
ward: ""; | ||
eastings: ""; | ||
northings: ""; | ||
uprn: ""; | ||
id: string; | ||
dataset: "paf" | "mr" | "nyb" | "usps"; | ||
country_iso: "GBR" | "IMN" | "JEY" | "GGY" | "USA" | "PRI" | "GUM"; | ||
}>; | ||
} | ||
export {}; |
@@ -1,14 +0,11 @@ | ||
export declare type Context = "GBR" | "USA"; | ||
export interface Details { | ||
name: string; | ||
icon: string; | ||
export interface ContextDetails { | ||
iso_2: string; | ||
iso_3: string; | ||
emoji: string; | ||
rgeo: boolean; | ||
description: string; | ||
} | ||
declare type ContextStore = Record<string, Details>; | ||
export declare type ContextStore = Record<string, ContextDetails>; | ||
export declare const defaultContexts: ContextStore; | ||
export interface ContextDetails { | ||
name: string; | ||
icon: string; | ||
code: string; | ||
} | ||
export declare const toContextList: (contexts: ContextStore, restrictCountries: string[]) => ContextDetails[]; | ||
export {}; | ||
export declare const toContextMap: (contexts: ContextDetails[]) => ContextStore; |
export const defaultContexts = { | ||
GBR: { | ||
name: "United Kingdom", | ||
icon: "🇬🇧", | ||
iso_2: "GB", | ||
iso_3: "GBR", | ||
emoji: "🇬🇧", | ||
rgeo: true, | ||
description: "United Kingdom", | ||
}, | ||
USA: { | ||
name: "United States", | ||
icon: "🇺🇸", | ||
iso_2: "US", | ||
iso_3: "USA", | ||
emoji: "🇺🇸", | ||
rgeo: false, | ||
description: "United States", | ||
}, | ||
@@ -18,7 +24,13 @@ }; | ||
continue; | ||
const { name, icon } = contexts[code]; | ||
result.push({ code, name, icon }); | ||
result.push(contexts[code]); | ||
} | ||
result.sort((b, a) => b.name.localeCompare(a.name)); | ||
result.sort((b, a) => b.description.localeCompare(a.description)); | ||
return result; | ||
}; | ||
export const toContextMap = (contexts) => { | ||
const result = {}; | ||
for (const context of contexts) { | ||
result[context.iso_3] = context; | ||
} | ||
return result; | ||
}; |
@@ -6,3 +6,3 @@ /** | ||
import { Callbacks, Listener } from "./callbacks"; | ||
import { Context, Details, ContextDetails } from "./contexts"; | ||
import { ContextStore, ContextDetails } from "./contexts"; | ||
import { DebouncedFunc } from "lodash"; | ||
@@ -52,3 +52,3 @@ import { ApiCache, QueryOptions } from "./cache"; | ||
*/ | ||
defaultCountry?: Context; | ||
defaultCountry?: string; | ||
/** | ||
@@ -65,7 +65,7 @@ * Narrow the countries you wish to support | ||
*/ | ||
restrictCountries?: Context[]; | ||
restrictCountries?: string[]; | ||
/** | ||
* Provide a custom list of possible contexts to select a new country or context from | ||
*/ | ||
contexts?: Record<string, Details>; | ||
contexts?: Record<string, ContextDetails>; | ||
/** | ||
@@ -162,2 +162,7 @@ * Specify parent element for output fields to looking for them to narrow search area | ||
/** | ||
* Detects country based on IP address. | ||
* @default true | ||
*/ | ||
detectCountry?: boolean; | ||
/** | ||
* Inject stylesheet into DOM to style Address Finder with default theme. Default is `true` | ||
@@ -587,2 +592,3 @@ * | ||
init(): Promise<void>; | ||
updateContexts(contexts: ContextStore): void; | ||
/** | ||
@@ -669,3 +675,3 @@ * Render available country options | ||
*/ | ||
applyContext(details: ContextDetails): void; | ||
applyContext(details: ContextDetails, announce?: boolean): void; | ||
/** | ||
@@ -672,0 +678,0 @@ * Renders notification box |
@@ -7,3 +7,3 @@ /** | ||
import debounce from "lodash/debounce"; | ||
import { defaultContexts, toContextList, } from "./contexts"; | ||
import { toContextMap, defaultContexts, toContextList, } from "./contexts"; | ||
import { ApiCache } from "./cache"; | ||
@@ -46,2 +46,3 @@ import { addStyle, computeOffset } from "./css"; | ||
hideToolbar: false, | ||
detectCountry: true, | ||
// Country | ||
@@ -140,3 +141,4 @@ defaultCountry: "GBR", | ||
this.suggestions = []; | ||
this.contextSuggestions = toContextList(this.options.contexts, this.options.restrictCountries); | ||
this.contextSuggestions = []; | ||
this.updateContexts(this.options.contexts); | ||
this.client = new Client({ ...this.options, api_key: this.options.apiKey }); | ||
@@ -187,3 +189,3 @@ this.cache = new ApiCache(this.client); | ||
this.countryIcon.className = "idpc_icon"; | ||
this.countryIcon.innerText = this.currentContext().icon; | ||
this.countryIcon.innerText = this.currentContext().emoji; | ||
this.countryMessage = this.options.document.createElement("span"); | ||
@@ -286,7 +288,6 @@ this.countryMessage.innerText = "Select Country"; | ||
const c = this.options.contexts[this.context]; | ||
return { | ||
code: this.context, | ||
name: c.name, | ||
icon: c.icon, | ||
}; | ||
if (c) | ||
return c; | ||
const first = Object.keys(this.options.contexts)[0]; | ||
return this.options.contexts[first]; | ||
} | ||
@@ -318,2 +319,17 @@ /** | ||
throw new Error("Key currently not usable"); | ||
this.updateContexts( | ||
// TODO: Remove cast when openapi updated | ||
toContextMap(response.contexts)); | ||
// Methods to apply context | ||
// 1. If detect country enabled and match, if no match | ||
// 2. Apply default context, if no match | ||
// 3. Apply first item of context list | ||
// If detect country enabled, set country to default | ||
const details = this.options.contexts[response.context]; | ||
if (this.options.detectCountry && details) { | ||
this.applyContext(details, false); | ||
} | ||
else { | ||
this.applyContext(this.currentContext(), false); | ||
} | ||
this.load(); | ||
@@ -328,2 +344,7 @@ resolve(); | ||
} | ||
// Updates lists of available contexts | ||
updateContexts(contexts) { | ||
this.contextSuggestions = toContextList(contexts, this.options.restrictCountries); | ||
this.options.contexts = contexts; | ||
} | ||
/** | ||
@@ -335,5 +356,5 @@ * Render available country options | ||
this.contextSuggestions.forEach((contextDetails, i) => { | ||
const { name } = contextDetails; | ||
const { description } = contextDetails; | ||
const li = this.options.document.createElement("li"); | ||
li.textContent = name; | ||
li.textContent = description; | ||
li.setAttribute("aria-selected", "false"); | ||
@@ -569,8 +590,9 @@ li.setAttribute("tabindex", "-1"); | ||
*/ | ||
applyContext(details) { | ||
const context = details.code; | ||
applyContext(details, announce = true) { | ||
const context = details.iso_3; | ||
this.context = context; | ||
this.cache.clear(); | ||
this.countryIcon.innerText = details.icon; | ||
this.announce(`Country switched to ${details.name}`); | ||
this.countryIcon.innerText = details.emoji; | ||
if (announce) | ||
this.announce(`Country switched to ${details.description}`); | ||
} | ||
@@ -577,0 +599,0 @@ /** |
@@ -235,3 +235,3 @@ import { createMachine, interpret } from "@xstate/fsm"; | ||
c.applyContext(co); | ||
c.notification = `Country switched to ${co.name} ${co.icon}`; | ||
c.notification = `Country switched to ${co.description} ${co.emoji}`; | ||
}, | ||
@@ -238,0 +238,0 @@ /** |
{ | ||
"name": "@ideal-postcodes/address-finder", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Address Finder JS library backed by the Ideal Postcodes UK address search API", | ||
@@ -103,4 +103,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@ideal-postcodes/core-axios": "4.0.1", | ||
"@ideal-postcodes/jsutil": "6.0.0", | ||
"@ideal-postcodes/core-axios": "4.1.0", | ||
"@ideal-postcodes/jsutil": "6.1.0", | ||
"@xstate/fsm": "~1.6.0", | ||
@@ -114,7 +114,7 @@ "lodash": "~4.17.20" | ||
"@babel/preset-env": "~7.15.0", | ||
"@cablanchard/eslint-config": "~2.1.0", | ||
"@cablanchard/eslint-config": "~3.1.1", | ||
"@cablanchard/semantic-release": "~1.3.4", | ||
"@cablanchard/tsconfig": "~2.0.0", | ||
"@ideal-postcodes/api-fixtures": "~1.3.0", | ||
"@ideal-postcodes/openapi": "1.2.0-beta.4", | ||
"@ideal-postcodes/openapi": "3.1.0", | ||
"@ideal-postcodes/supported-browsers": "~2.5.0", | ||
@@ -155,3 +155,3 @@ "@rollup/plugin-commonjs": "~21.0.0", | ||
"rollup": "~2.70.0", | ||
"semantic-release": "~17.4.1", | ||
"semantic-release": "~19.0.3", | ||
"sinon": "~11.1.2", | ||
@@ -158,0 +158,0 @@ "ts-node": "~10.2.0", |
261661
6919
+ Added@ideal-postcodes/core-axios@4.1.0(transitive)
+ Added@ideal-postcodes/core-interface@3.2.0(transitive)
+ Added@ideal-postcodes/jsutil@6.1.0(transitive)
+ Added@ideal-postcodes/openapi@3.1.0(transitive)
- Removed@ideal-postcodes/core-axios@4.0.1(transitive)
- Removed@ideal-postcodes/core-interface@3.1.0(transitive)
- Removed@ideal-postcodes/jsutil@6.0.0(transitive)
- Removed@ideal-postcodes/openapi@1.2.0(transitive)