geocodio-library-node 1.6.1 → 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/README.md CHANGED
@@ -41,7 +41,7 @@ $ yarn add geocodio-library-node
41
41
  ```javascript
42
42
  const Geocodio = require('geocodio-library-node');
43
43
  const geocoder = new Geocodio('YOUR_API_KEY');
44
- // const geocoder = new Geocodio('YOUR_API_KEY', 'api-hipaa.geocod.io'); // optionally overwrite the API hostname
44
+ // const geocoder = new Geocodio('YOUR_API_KEY', 'api.enterprise.geocod.io'); // optionally overwrite the API hostname
45
45
 
46
46
  geocoder
47
47
  .geocode('1109 N Highland St, Arlington, VA')
@@ -311,5 +311,5 @@ If you discover any security related issues, please email security@geocod.io ins
311
311
 
312
312
  The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
313
313
 
314
- [npm-image]: https://badge.fury.io/js/geocodio-library-node.svg
314
+ [npm-image]: https://img.shields.io/npm/v/geocodio-library-node
315
315
  [npm-url]: https://npmjs.org/package/geocodio-library-node
@@ -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 ADDED
@@ -0,0 +1,277 @@
1
+ declare module 'geocodio-library-node' {
2
+ export interface AddressComponents {
3
+ number?: string;
4
+ predirectional?: string;
5
+ prefix?: string;
6
+ street?: string;
7
+ suffix?: string;
8
+ postdirectional?: string;
9
+ secondaryunit?: string;
10
+ secondarynumber?: string;
11
+ formatted_street?: string;
12
+ city?: string;
13
+ county?: string;
14
+ state?: string;
15
+ zip?: string;
16
+ country?: string;
17
+ postal_code?: string; // Alternative to zip used in some API calls
18
+ }
19
+
20
+ export type GeocodeAccuracyType =
21
+ | 'rooftop'
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
+ }
179
+
180
+ export interface GeocodedAddress {
181
+ address_components: AddressComponents;
182
+ formatted_address: string;
183
+ location: Location;
184
+ accuracy: number;
185
+ accuracy_type: GeocodeAccuracyType;
186
+ source?: string;
187
+ fields?: Fields;
188
+ }
189
+
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';
220
+
221
+ export interface SingleGeocodeResponse {
222
+ input: {
223
+ address_components: AddressComponents;
224
+ formatted_address: string;
225
+ };
226
+ results: GeocodedAddress[];
227
+ }
228
+
229
+ export interface BatchGeocodeResponse {
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
+ }>;
249
+ }
250
+
251
+ // List API types
252
+ export interface ListResponse {
253
+ id: number;
254
+ file: {
255
+ filename: string;
256
+ };
257
+ }
258
+
259
+ export default class Geocodio {
260
+ constructor(apiKey?: string, hostname?: string, apiVersion?: string);
261
+
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>;
264
+
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>;
267
+
268
+ list: {
269
+ create(filename: string, direction: string, format: string, callback: string): Promise<ListResponse>;
270
+ status(listId: number): Promise<unknown>;
271
+ all(): Promise<unknown>;
272
+ download(listId: number, output: string): Promise<unknown>;
273
+ delete(listId: number): Promise<unknown>;
274
+ deleteList(listId: number): Promise<unknown>; // Alias for delete
275
+ };
276
+ }
277
+ }
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.3.0"
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: form.getHeaders()
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
- params: {
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.handleRequest(
188
+ return this.handleResponse(
187
189
  axios.get(this.formatUrl(`lists`), {
188
- params: {
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.handleRequest(
198
+ return this.handleResponse(
199
199
  axios({
200
200
  method: "get",
201
201
  url: this.formatUrl(`lists/${listId}/download`),
202
- params: {
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.handleRequest(
224
+ return this.handleResponse(
227
225
  axios.delete(this.formatUrl(`lists/${listId}`), {
228
- params: {
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.6.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": {
@@ -12,6 +12,7 @@
12
12
  "lib"
13
13
  ],
14
14
  "main": "lib/index.js",
15
+ "types": "lib/index.d.ts",
15
16
  "keywords": [
16
17
  "geocoding",
17
18
  "geocode",
@@ -27,7 +28,7 @@
27
28
  "eslint-config-xo": "^0.26.0",
28
29
  "eslint-plugin-prettier": "^3.4.0",
29
30
  "husky": "^3.1.0",
30
- "jest": "^26.6.3",
31
+ "jest": "^29.7.0",
31
32
  "lint-staged": "^9.5.0",
32
33
  "prettier": "^1.19.1"
33
34
  },
@@ -76,7 +77,7 @@
76
77
  },
77
78
  "license": "MIT",
78
79
  "dependencies": {
79
- "axios": "^1.6.7",
80
+ "axios": "^1.7.4",
80
81
  "form-data": "^4.0.0"
81
82
  }
82
83
  }