1 | |
2 | type Foxentry = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Validate location data |
7 | * This endpoint requires at least 1 query parameter and will check if the parameters and their combinations are valid. |
8 | */ |
9 | export async function main( |
10 | auth: Foxentry, |
11 | api_version: string | undefined, |
12 | foxentry_include_request_details: string | undefined, |
13 | body: { |
14 | request: { |
15 | customId?: string; |
16 | query: { |
17 | street?: string; |
18 | streetWithNumber?: string; |
19 | "number.full"?: string; |
20 | "number.part1"?: string; |
21 | "number.part1Number"?: string; |
22 | "number.part1Letter"?: string; |
23 | "number.part2"?: string; |
24 | "number.part2Number"?: string; |
25 | "number.part2Letter"?: string; |
26 | city?: string; |
27 | zip?: string; |
28 | full?: string; |
29 | country?: string; |
30 | }; |
31 | options?: { |
32 | dataScope?: "basic" | "full"; |
33 | dataSource?: string[]; |
34 | zipFormat?: false | true; |
35 | countryFormat?: |
36 | | "alpha2" |
37 | | "alpha3" |
38 | | "local" |
39 | | "localShortened" |
40 | | "international" |
41 | | "internationalShortened"; |
42 | cityFormat?: "basic" | "minimal" | "extended"; |
43 | } & { resultsLimit?: number; acceptPostOfficeAsCity?: false | true }; |
44 | client?: { |
45 | ip?: string; |
46 | country?: string; |
47 | location?: { lat?: number; lon?: number }; |
48 | }; |
49 | }; |
50 | }, |
51 | ) { |
52 | const url = new URL(`https://api.foxentry.com/location/validate`); |
53 |
|
54 | const headers: Record<string, string> = { |
55 | "Content-Type": "application/json", |
56 | Authorization: "Bearer " + auth.apiKey, |
57 | }; |
58 |
|
59 | if (api_version) { |
60 | headers["api-version"] = api_version; |
61 | } |
62 | if (foxentry_include_request_details) { |
63 | headers["foxentry-include-request-details"] = foxentry_include_request_details; |
64 | } |
65 |
|
66 | const response = await fetch(url, { |
67 | method: "POST", |
68 | headers, |
69 | body: JSON.stringify(body), |
70 | }); |
71 | if (!response.ok) { |
72 | const text = await response.text(); |
73 | throw new Error(`${response.status} ${text}`); |
74 | } |
75 | return await response.json(); |
76 | } |
77 |
|