geocodio-library-node 1.7.0 → 1.9.1
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/lib/__tests__/geocodioLibraryNodeErrorHandling.test.js +1 -3
- package/lib/index.d.ts +215 -25
- package/lib/index.js +15 -19
- package/package.json +3 -3
|
@@ -19,9 +19,7 @@ describe("error handling", () => {
|
|
|
19
19
|
|
|
20
20
|
return geocoder.geocode(" ").catch(err => {
|
|
21
21
|
expect(err).toBeInstanceOf(Error);
|
|
22
|
-
expect(err.message).toEqual(
|
|
23
|
-
"Could not geocode address. No matches found."
|
|
24
|
-
);
|
|
22
|
+
expect(err.message).toEqual("Could not parse address");
|
|
25
23
|
});
|
|
26
24
|
});
|
|
27
25
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -2,8 +2,12 @@ declare module 'geocodio-library-node' {
|
|
|
2
2
|
export interface AddressComponents {
|
|
3
3
|
number?: string;
|
|
4
4
|
predirectional?: string;
|
|
5
|
+
prefix?: string;
|
|
5
6
|
street?: string;
|
|
6
7
|
suffix?: string;
|
|
8
|
+
postdirectional?: string;
|
|
9
|
+
secondaryunit?: string;
|
|
10
|
+
secondarynumber?: string;
|
|
7
11
|
formatted_street?: string;
|
|
8
12
|
city?: string;
|
|
9
13
|
county?: string;
|
|
@@ -15,32 +19,204 @@ declare module 'geocodio-library-node' {
|
|
|
15
19
|
|
|
16
20
|
export type GeocodeAccuracyType =
|
|
17
21
|
| 'rooftop'
|
|
18
|
-
| '
|
|
19
|
-
| '
|
|
20
|
-
| '
|
|
21
|
-
| '
|
|
22
|
-
| '
|
|
22
|
+
| 'point'
|
|
23
|
+
| 'range_interpolation'
|
|
24
|
+
| 'nearest_rooftop_match'
|
|
25
|
+
| 'street_center'
|
|
26
|
+
| 'place'
|
|
27
|
+
| 'state';
|
|
28
|
+
|
|
29
|
+
export interface Location {
|
|
30
|
+
lat: number;
|
|
31
|
+
lng: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Legislator {
|
|
35
|
+
type: string;
|
|
36
|
+
bio: {
|
|
37
|
+
last_name: string;
|
|
38
|
+
first_name: string;
|
|
39
|
+
birthday: string;
|
|
40
|
+
gender: string;
|
|
41
|
+
party: string;
|
|
42
|
+
};
|
|
43
|
+
contact: {
|
|
44
|
+
url: string;
|
|
45
|
+
address: string;
|
|
46
|
+
phone: string;
|
|
47
|
+
contact_form?: string;
|
|
48
|
+
};
|
|
49
|
+
social: {
|
|
50
|
+
rss_url?: string;
|
|
51
|
+
twitter?: string;
|
|
52
|
+
facebook?: string;
|
|
53
|
+
youtube?: string;
|
|
54
|
+
youtube_id?: string;
|
|
55
|
+
};
|
|
56
|
+
references: {
|
|
57
|
+
bioguide_id?: string;
|
|
58
|
+
thomas_id?: string;
|
|
59
|
+
opensecrets_id?: string;
|
|
60
|
+
lis_id?: string;
|
|
61
|
+
cspan_id?: string;
|
|
62
|
+
govtrack_id?: string;
|
|
63
|
+
votesmart_id?: string;
|
|
64
|
+
ballotpedia_id?: string;
|
|
65
|
+
washington_post_id?: string;
|
|
66
|
+
icpsr_id?: string;
|
|
67
|
+
wikipedia_id?: string;
|
|
68
|
+
};
|
|
69
|
+
source: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface CongressionalDistrict {
|
|
73
|
+
name: string;
|
|
74
|
+
district_number: number;
|
|
75
|
+
ocd_id: string;
|
|
76
|
+
congress_number: string;
|
|
77
|
+
congress_years: string;
|
|
78
|
+
proportion: number;
|
|
79
|
+
current_legislators: Legislator[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface StateLegislativeDistrict {
|
|
83
|
+
name: string;
|
|
84
|
+
district_number: string;
|
|
85
|
+
ocd_id: string;
|
|
86
|
+
is_upcoming_state_legislative_district: boolean;
|
|
87
|
+
proportion: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface StateLegislativeDistricts {
|
|
91
|
+
senate?: StateLegislativeDistrict[];
|
|
92
|
+
house?: StateLegislativeDistrict[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface SchoolDistrict {
|
|
96
|
+
name: string;
|
|
97
|
+
lea_code: string;
|
|
98
|
+
grade_low: string;
|
|
99
|
+
grade_high: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface SchoolDistricts {
|
|
103
|
+
elementary?: SchoolDistrict;
|
|
104
|
+
secondary?: SchoolDistrict;
|
|
105
|
+
unified?: SchoolDistrict;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface Timezone {
|
|
109
|
+
name: string;
|
|
110
|
+
utc_offset: number;
|
|
111
|
+
observes_dst: boolean;
|
|
112
|
+
abbreviation: string;
|
|
113
|
+
source: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface MetroArea {
|
|
117
|
+
name: string;
|
|
118
|
+
area_code: string;
|
|
119
|
+
type?: 'metropolitan' | 'micropolitan';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface StatisticalArea {
|
|
123
|
+
name: string;
|
|
124
|
+
area_code: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface Census {
|
|
128
|
+
census_year: number;
|
|
129
|
+
state_fips: string;
|
|
130
|
+
county_fips: string;
|
|
131
|
+
place_fips: string;
|
|
132
|
+
tract_code: string;
|
|
133
|
+
block_code: string;
|
|
134
|
+
block_group: string;
|
|
135
|
+
full_fips: string;
|
|
136
|
+
metro_micro_statistical_area?: MetroArea;
|
|
137
|
+
combined_statistical_area?: StatisticalArea;
|
|
138
|
+
metropolitan_division?: StatisticalArea;
|
|
139
|
+
source: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface RecordType {
|
|
143
|
+
code: string;
|
|
144
|
+
description: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface CarrierRoute {
|
|
148
|
+
id: string;
|
|
149
|
+
description: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface FacilityCode {
|
|
153
|
+
code: string;
|
|
154
|
+
description: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface Zip4 {
|
|
158
|
+
record_type: RecordType;
|
|
159
|
+
carrier_route: CarrierRoute;
|
|
160
|
+
building_or_firm_name: string;
|
|
161
|
+
plus4: string[];
|
|
162
|
+
zip9: string[];
|
|
163
|
+
government_building: boolean;
|
|
164
|
+
facility_code: FacilityCode;
|
|
165
|
+
city_delivery: boolean;
|
|
166
|
+
valid_delivery_area: boolean;
|
|
167
|
+
exact_match: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface Fields {
|
|
171
|
+
congressional_districts?: CongressionalDistrict[];
|
|
172
|
+
state_legislative_districts?: StateLegislativeDistricts;
|
|
173
|
+
school_districts?: SchoolDistricts;
|
|
174
|
+
timezone?: Timezone;
|
|
175
|
+
census?: Census;
|
|
176
|
+
zip4?: Zip4;
|
|
177
|
+
[key: string]: unknown;
|
|
178
|
+
}
|
|
23
179
|
|
|
24
180
|
export interface GeocodedAddress {
|
|
25
181
|
address_components: AddressComponents;
|
|
26
182
|
formatted_address: string;
|
|
27
|
-
location:
|
|
28
|
-
lat: number;
|
|
29
|
-
lng: number;
|
|
30
|
-
};
|
|
183
|
+
location: Location;
|
|
31
184
|
accuracy: number;
|
|
32
185
|
accuracy_type: GeocodeAccuracyType;
|
|
33
186
|
source?: string;
|
|
34
187
|
fields?: Fields;
|
|
35
188
|
}
|
|
36
189
|
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
190
|
+
export type FieldOption =
|
|
191
|
+
| 'cd'
|
|
192
|
+
| 'cd116'
|
|
193
|
+
| 'cd115'
|
|
194
|
+
| 'cd114'
|
|
195
|
+
| 'cd113'
|
|
196
|
+
| 'stateleg'
|
|
197
|
+
| 'school'
|
|
198
|
+
| 'timezone'
|
|
199
|
+
| 'census'
|
|
200
|
+
| 'census2000'
|
|
201
|
+
| 'census2010'
|
|
202
|
+
| 'census2011'
|
|
203
|
+
| 'census2012'
|
|
204
|
+
| 'census2013'
|
|
205
|
+
| 'census2014'
|
|
206
|
+
| 'census2015'
|
|
207
|
+
| 'census2016'
|
|
208
|
+
| 'census2017'
|
|
209
|
+
| 'census2018'
|
|
210
|
+
| 'census2019'
|
|
211
|
+
| 'census2020'
|
|
212
|
+
| 'provriding'
|
|
213
|
+
| 'riding'
|
|
214
|
+
| 'zip4'
|
|
215
|
+
| 'acs-demographics'
|
|
216
|
+
| 'acs-economics'
|
|
217
|
+
| 'acs-families'
|
|
218
|
+
| 'acs-housing'
|
|
219
|
+
| 'acs-social';
|
|
44
220
|
|
|
45
221
|
export interface SingleGeocodeResponse {
|
|
46
222
|
input: {
|
|
@@ -51,11 +227,25 @@ declare module 'geocodio-library-node' {
|
|
|
51
227
|
}
|
|
52
228
|
|
|
53
229
|
export interface BatchGeocodeResponse {
|
|
54
|
-
results: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
230
|
+
results: Array<{
|
|
231
|
+
query: string;
|
|
232
|
+
response: SingleGeocodeResponse;
|
|
233
|
+
}> | Record<string, {
|
|
234
|
+
response: SingleGeocodeResponse;
|
|
235
|
+
}>;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface ReverseGeocodeResponse {
|
|
239
|
+
results: GeocodedAddress[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface BatchReverseGeocodeResponse {
|
|
243
|
+
results: Array<{
|
|
244
|
+
query: string;
|
|
245
|
+
response: ReverseGeocodeResponse;
|
|
246
|
+
}> | Record<string, {
|
|
247
|
+
response: ReverseGeocodeResponse;
|
|
248
|
+
}>;
|
|
59
249
|
}
|
|
60
250
|
|
|
61
251
|
// List API types
|
|
@@ -69,11 +259,11 @@ declare module 'geocodio-library-node' {
|
|
|
69
259
|
export default class Geocodio {
|
|
70
260
|
constructor(apiKey?: string, hostname?: string, apiVersion?: string);
|
|
71
261
|
|
|
72
|
-
geocode(query: string | AddressComponents, fields?:
|
|
73
|
-
geocode(query: (string | AddressComponents)[] | Record<string, string | AddressComponents>, fields?:
|
|
262
|
+
geocode(query: string | AddressComponents, fields?: FieldOption[], limit?: number): Promise<SingleGeocodeResponse>;
|
|
263
|
+
geocode(query: (string | AddressComponents)[] | Record<string, string | AddressComponents>, fields?: FieldOption[], limit?: number): Promise<BatchGeocodeResponse>;
|
|
74
264
|
|
|
75
|
-
reverse(query: string | [number, number], fields?:
|
|
76
|
-
reverse(query: (string | [number, number])[], fields?:
|
|
265
|
+
reverse(query: string | [number, number], fields?: FieldOption[], limit?: number): Promise<ReverseGeocodeResponse>;
|
|
266
|
+
reverse(query: (string | [number, number])[] | Record<string, string | [number, number]>, fields?: FieldOption[], limit?: number): Promise<BatchReverseGeocodeResponse>;
|
|
77
267
|
|
|
78
268
|
list: {
|
|
79
269
|
create(filename: string, direction: string, format: string, callback: string): Promise<ListResponse>;
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,8 @@ class Geocodio {
|
|
|
15
15
|
this.BATCH_TIMEOUT_MS = 30 * 60 * 1000;
|
|
16
16
|
|
|
17
17
|
this.HTTP_HEADERS = {
|
|
18
|
-
"User-Agent": "geocodio-library-node/1.
|
|
18
|
+
"User-Agent": "geocodio-library-node/1.8.0",
|
|
19
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
this.ADDRESS_COMPONENT_PARAMETERS = [
|
|
@@ -41,7 +42,6 @@ class Geocodio {
|
|
|
41
42
|
const url = this.formatUrl(endpoint);
|
|
42
43
|
|
|
43
44
|
let queryParameters = {
|
|
44
|
-
api_key: this.apiKey,
|
|
45
45
|
fields: fields.join(",")
|
|
46
46
|
};
|
|
47
47
|
|
|
@@ -159,15 +159,19 @@ class Geocodio {
|
|
|
159
159
|
const form = new FormData();
|
|
160
160
|
form.append("file", fs.createReadStream(filename));
|
|
161
161
|
|
|
162
|
+
const headers = {
|
|
163
|
+
...this.HTTP_HEADERS,
|
|
164
|
+
...form.getHeaders()
|
|
165
|
+
};
|
|
166
|
+
|
|
162
167
|
return this.handleResponse(
|
|
163
168
|
axios.post(this.formatUrl("lists"), form, {
|
|
164
169
|
params: {
|
|
165
|
-
api_key: this.apiKey,
|
|
166
170
|
direction,
|
|
167
171
|
format,
|
|
168
172
|
callback
|
|
169
173
|
},
|
|
170
|
-
headers:
|
|
174
|
+
headers: headers
|
|
171
175
|
})
|
|
172
176
|
);
|
|
173
177
|
};
|
|
@@ -175,19 +179,15 @@ class Geocodio {
|
|
|
175
179
|
const status = listId => {
|
|
176
180
|
return this.handleResponse(
|
|
177
181
|
axios.get(this.formatUrl(`lists/${listId}`), {
|
|
178
|
-
|
|
179
|
-
api_key: this.apiKey
|
|
180
|
-
}
|
|
182
|
+
headers: this.HTTP_HEADERS
|
|
181
183
|
})
|
|
182
184
|
);
|
|
183
185
|
};
|
|
184
186
|
|
|
185
187
|
const all = () => {
|
|
186
|
-
return this.
|
|
188
|
+
return this.handleResponse(
|
|
187
189
|
axios.get(this.formatUrl(`lists`), {
|
|
188
|
-
|
|
189
|
-
api_key: this.apiKey
|
|
190
|
-
}
|
|
190
|
+
headers: this.HTTP_HEADERS
|
|
191
191
|
})
|
|
192
192
|
);
|
|
193
193
|
};
|
|
@@ -195,13 +195,11 @@ class Geocodio {
|
|
|
195
195
|
const download = (listId, output) => {
|
|
196
196
|
const writer = fs.createWriteStream(output);
|
|
197
197
|
|
|
198
|
-
return this.
|
|
198
|
+
return this.handleResponse(
|
|
199
199
|
axios({
|
|
200
200
|
method: "get",
|
|
201
201
|
url: this.formatUrl(`lists/${listId}/download`),
|
|
202
|
-
|
|
203
|
-
api_key: this.apiKey
|
|
204
|
-
},
|
|
202
|
+
headers: this.HTTP_HEADERS,
|
|
205
203
|
responseType: "stream"
|
|
206
204
|
}).then(response => {
|
|
207
205
|
return new Promise((resolve, reject) => {
|
|
@@ -223,11 +221,9 @@ class Geocodio {
|
|
|
223
221
|
};
|
|
224
222
|
|
|
225
223
|
const deleteList = listId => {
|
|
226
|
-
return this.
|
|
224
|
+
return this.handleResponse(
|
|
227
225
|
axios.delete(this.formatUrl(`lists/${listId}`), {
|
|
228
|
-
|
|
229
|
-
api_key: this.apiKey
|
|
230
|
-
}
|
|
226
|
+
headers: this.HTTP_HEADERS
|
|
231
227
|
})
|
|
232
228
|
);
|
|
233
229
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geocodio-library-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "geocod.io geocoding API library",
|
|
5
5
|
"homepage": "https://github.com/Geocodio/geocodio-library-node",
|
|
6
6
|
"author": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"eslint-config-xo": "^0.26.0",
|
|
29
29
|
"eslint-plugin-prettier": "^3.4.0",
|
|
30
30
|
"husky": "^3.1.0",
|
|
31
|
-
"jest": "^
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
32
|
"lint-staged": "^9.5.0",
|
|
33
33
|
"prettier": "^1.19.1"
|
|
34
34
|
},
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"license": "MIT",
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"axios": "^1.
|
|
80
|
+
"axios": "^1.7.4",
|
|
81
81
|
"form-data": "^4.0.0"
|
|
82
82
|
}
|
|
83
83
|
}
|