@apiverve/zipdemographics 1.2.0 → 1.2.2
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/LICENSE +20 -20
- package/README.md +183 -169
- package/index.d.ts +46 -35
- package/index.js +209 -209
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 APIVerve and EvlarSoft LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,200 +1,214 @@
|
|
|
1
|
-
# ZIP Demographics API
|
|
2
|
-
|
|
3
|
-
ZIP Demographics
|
|
4
|
-
|
|
5
|
-
](https://www.npmjs.com/package/@apiverve/zipdemographics)
|
|
6
|
+
|
|
7
|
+
This is a JavaScript wrapper for the [ZIP Demographics API](https://apiverve.com/marketplace/zipdemographics?utm_source=npm&utm_medium=referral&utm_content=readme)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Using npm:
|
|
14
|
+
```shell
|
|
15
|
+
npm install @apiverve/zipdemographics
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Using yarn:
|
|
19
|
+
```shell
|
|
20
|
+
yarn add @apiverve/zipdemographics
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
Before using the ZIP Demographics API client, you have to setup your account and obtain your API Key.
|
|
28
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=referral&utm_content=readme)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
[Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=referral&utm_content=readme)
|
|
35
|
+
|
|
36
|
+
The ZIP Demographics API documentation is found here: [https://docs.apiverve.com/ref/zipdemographics](https://docs.apiverve.com/ref/zipdemographics?utm_source=npm&utm_medium=referral&utm_content=readme).
|
|
37
|
+
You can find parameters, example responses, and status codes documented here.
|
|
38
|
+
|
|
39
|
+
### Setup
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
const zipdemographicsAPI = require('@apiverve/zipdemographics');
|
|
43
|
+
const api = new zipdemographicsAPI({
|
|
44
|
+
api_key: '[YOUR_API_KEY]'
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### Perform Request
|
|
55
|
+
|
|
56
|
+
Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
62
59
|
var query = {
|
|
63
60
|
zip: "90210"
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
api.execute(query, function (error, data) {
|
|
67
|
-
if (error) {
|
|
68
|
-
return console.error(error);
|
|
69
|
-
} else {
|
|
70
|
-
console.log(data);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
### Using Promises
|
|
78
|
-
|
|
79
|
-
You can also use promises to make requests. The API returns a promise that you can use to handle the response.
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
api.execute(query, function (error, data) {
|
|
64
|
+
if (error) {
|
|
65
|
+
return console.error(error);
|
|
66
|
+
} else {
|
|
67
|
+
console.log(data);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### Using Promises
|
|
75
|
+
|
|
76
|
+
You can also use promises to make requests. The API returns a promise that you can use to handle the response.
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
82
79
|
var query = {
|
|
83
80
|
zip: "90210"
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
api.execute(query)
|
|
87
|
-
.then(data => {
|
|
88
|
-
console.log(data);
|
|
89
|
-
})
|
|
90
|
-
.catch(error => {
|
|
91
|
-
console.error(error);
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
### Using Async/Await
|
|
98
|
-
|
|
99
|
-
You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
|
|
100
|
-
|
|
101
|
-
```javascript
|
|
102
|
-
async function makeRequest() {
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
api.execute(query)
|
|
84
|
+
.then(data => {
|
|
85
|
+
console.log(data);
|
|
86
|
+
})
|
|
87
|
+
.catch(error => {
|
|
88
|
+
console.error(error);
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Using Async/Await
|
|
95
|
+
|
|
96
|
+
You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
async function makeRequest() {
|
|
103
100
|
var query = {
|
|
104
101
|
zip: "90210"
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
const data = await api.execute(query);
|
|
109
|
-
console.log(data);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.error(error);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## Example Response
|
|
119
|
-
|
|
120
|
-
```json
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const data = await api.execute(query);
|
|
106
|
+
console.log(data);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Example Response
|
|
116
|
+
|
|
117
|
+
```json
|
|
121
118
|
{
|
|
122
119
|
"status": "ok",
|
|
123
120
|
"error": null,
|
|
124
121
|
"data": {
|
|
125
122
|
"zip": "90210",
|
|
126
123
|
"name": "ZCTA5 90210",
|
|
127
|
-
"acsYear":
|
|
124
|
+
"acsYear": 2024,
|
|
128
125
|
"population": {
|
|
129
|
-
"total":
|
|
130
|
-
"male":
|
|
131
|
-
"female":
|
|
132
|
-
"medianAge":
|
|
126
|
+
"total": 19004,
|
|
127
|
+
"male": 9417,
|
|
128
|
+
"female": 9587,
|
|
129
|
+
"medianAge": 51
|
|
133
130
|
},
|
|
134
131
|
"income": {
|
|
135
|
-
"medianHousehold":
|
|
136
|
-
"perCapita":
|
|
132
|
+
"medianHousehold": 187801,
|
|
133
|
+
"perCapita": 147098
|
|
137
134
|
},
|
|
138
135
|
"housing": {
|
|
139
|
-
"medianHomeValue":
|
|
140
|
-
"medianRent":
|
|
141
|
-
"totalUnits":
|
|
142
|
-
"
|
|
136
|
+
"medianHomeValue": 2000001,
|
|
137
|
+
"medianRent": 3251,
|
|
138
|
+
"totalUnits": 9531,
|
|
139
|
+
"occupiedUnits": 8029,
|
|
140
|
+
"vacantUnits": 1502,
|
|
141
|
+
"ownerOccupied": 5679,
|
|
142
|
+
"renterOccupied": 2350,
|
|
143
|
+
"homeOwnershipRate": 70.7
|
|
143
144
|
},
|
|
144
145
|
"education": {
|
|
145
|
-
"collegeEducatedPct":
|
|
146
|
+
"collegeEducatedPct": 68.1,
|
|
147
|
+
"bachelors": 4837,
|
|
148
|
+
"masters": 2389,
|
|
149
|
+
"professional": 1962,
|
|
150
|
+
"doctorate": 929
|
|
146
151
|
},
|
|
147
152
|
"employment": {
|
|
148
|
-
"laborForce":
|
|
149
|
-
"
|
|
153
|
+
"laborForce": 9017,
|
|
154
|
+
"unemployed": 468,
|
|
155
|
+
"unemploymentRate": 5.2
|
|
150
156
|
},
|
|
151
157
|
"race": {
|
|
152
158
|
"white": {
|
|
153
|
-
"count":
|
|
154
|
-
"percent":
|
|
159
|
+
"count": 15147,
|
|
160
|
+
"percent": 79.7
|
|
161
|
+
},
|
|
162
|
+
"black": {
|
|
163
|
+
"count": 403,
|
|
164
|
+
"percent": 2.1
|
|
155
165
|
},
|
|
156
166
|
"asian": {
|
|
157
|
-
"count":
|
|
158
|
-
"percent":
|
|
167
|
+
"count": 1628,
|
|
168
|
+
"percent": 8.6
|
|
169
|
+
},
|
|
170
|
+
"hispanic": {
|
|
171
|
+
"count": 1138,
|
|
172
|
+
"percent": 6
|
|
159
173
|
}
|
|
160
174
|
},
|
|
161
175
|
"formatted": {
|
|
162
|
-
"medianHouseholdIncome": "$
|
|
163
|
-
"perCapitaIncome": "$
|
|
164
|
-
"medianHomeValue": "$2,
|
|
165
|
-
"medianRent": "$3,
|
|
176
|
+
"medianHouseholdIncome": "$187,801",
|
|
177
|
+
"perCapitaIncome": "$147,098",
|
|
178
|
+
"medianHomeValue": "$2,000,001",
|
|
179
|
+
"medianRent": "$3,251"
|
|
166
180
|
}
|
|
167
181
|
}
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
---
|
|
172
|
-
|
|
173
|
-
## Customer Support
|
|
174
|
-
|
|
175
|
-
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=readme).
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
## Updates
|
|
180
|
-
|
|
181
|
-
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
## Legal
|
|
186
|
-
|
|
187
|
-
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
## License
|
|
192
|
-
Licensed under the
|
|
193
|
-
|
|
194
|
-
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
195
|
-
|
|
196
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
197
|
-
|
|
198
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
199
|
-
|
|
200
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Customer Support
|
|
188
|
+
|
|
189
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=referral&utm_content=readme).
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Updates
|
|
194
|
+
|
|
195
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Legal
|
|
200
|
+
|
|
201
|
+
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=referral&utm_content=readme) and [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=referral&utm_content=readme).
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
Licensed under the MIT License (MIT)
|
|
207
|
+
|
|
208
|
+
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
209
|
+
|
|
210
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
211
|
+
|
|
212
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
213
|
+
|
|
214
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/index.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
declare module '@apiverve/zipdemographics' {
|
|
2
|
-
export interface zipdemographicsOptions {
|
|
3
|
-
api_key: string;
|
|
4
|
-
secure?: boolean;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Describes fields the current plan does not unlock. Locked fields arrive as null
|
|
9
|
-
* in `data`; `locked_fields` names them, using dot paths for nested fields.
|
|
10
|
-
* Absent when the plan unlocks everything.
|
|
11
|
-
*/
|
|
12
|
-
export interface PremiumInfo {
|
|
13
|
-
message: string;
|
|
14
|
-
upgrade_url: string;
|
|
15
|
-
locked_fields: string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface zipdemographicsResponse {
|
|
19
|
-
status: string;
|
|
20
|
-
error: string | null;
|
|
21
|
-
data: ZIPDemographicsData;
|
|
22
|
-
code?: number;
|
|
23
|
-
premium?: PremiumInfo;
|
|
24
|
-
}
|
|
25
|
-
|
|
1
|
+
declare module '@apiverve/zipdemographics' {
|
|
2
|
+
export interface zipdemographicsOptions {
|
|
3
|
+
api_key: string;
|
|
4
|
+
secure?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Describes fields the current plan does not unlock. Locked fields arrive as null
|
|
9
|
+
* in `data`; `locked_fields` names them, using dot paths for nested fields.
|
|
10
|
+
* Absent when the plan unlocks everything.
|
|
11
|
+
*/
|
|
12
|
+
export interface PremiumInfo {
|
|
13
|
+
message: string;
|
|
14
|
+
upgrade_url: string;
|
|
15
|
+
locked_fields: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface zipdemographicsResponse {
|
|
19
|
+
status: string;
|
|
20
|
+
error: string | null;
|
|
21
|
+
data: ZIPDemographicsData;
|
|
22
|
+
code?: number;
|
|
23
|
+
premium?: PremiumInfo;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
26
|
|
|
27
27
|
interface ZIPDemographicsData {
|
|
28
28
|
zip: null | string;
|
|
@@ -39,10 +39,15 @@ declare module '@apiverve/zipdemographics' {
|
|
|
39
39
|
|
|
40
40
|
interface Education {
|
|
41
41
|
collegeEducatedPct: number | null;
|
|
42
|
+
bachelors: number | null;
|
|
43
|
+
masters: number | null;
|
|
44
|
+
professional: number | null;
|
|
45
|
+
doctorate: number | null;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
interface Employment {
|
|
45
49
|
laborForce: number | null;
|
|
50
|
+
unemployed: number | null;
|
|
46
51
|
unemploymentRate: number | null;
|
|
47
52
|
}
|
|
48
53
|
|
|
@@ -57,6 +62,10 @@ declare module '@apiverve/zipdemographics' {
|
|
|
57
62
|
medianHomeValue: number | null;
|
|
58
63
|
medianRent: number | null;
|
|
59
64
|
totalUnits: number | null;
|
|
65
|
+
occupiedUnits: number | null;
|
|
66
|
+
vacantUnits: number | null;
|
|
67
|
+
ownerOccupied: number | null;
|
|
68
|
+
renterOccupied: number | null;
|
|
60
69
|
homeOwnershipRate: number | null;
|
|
61
70
|
}
|
|
62
71
|
|
|
@@ -73,8 +82,10 @@ declare module '@apiverve/zipdemographics' {
|
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
interface Race {
|
|
76
|
-
white:
|
|
77
|
-
|
|
85
|
+
white: Asian;
|
|
86
|
+
black: Asian;
|
|
87
|
+
asian: Asian;
|
|
88
|
+
hispanic: Asian;
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
interface Asian {
|
|
@@ -82,11 +93,11 @@ declare module '@apiverve/zipdemographics' {
|
|
|
82
93
|
percent: number | null;
|
|
83
94
|
}
|
|
84
95
|
|
|
85
|
-
export default class zipdemographicsWrapper {
|
|
86
|
-
constructor(options: zipdemographicsOptions);
|
|
87
|
-
|
|
88
|
-
execute(callback: (error: any, data: zipdemographicsResponse | null) => void): Promise<zipdemographicsResponse>;
|
|
89
|
-
execute(query: Record<string, any>, callback: (error: any, data: zipdemographicsResponse | null) => void): Promise<zipdemographicsResponse>;
|
|
90
|
-
execute(query?: Record<string, any>): Promise<zipdemographicsResponse>;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
96
|
+
export default class zipdemographicsWrapper {
|
|
97
|
+
constructor(options: zipdemographicsOptions);
|
|
98
|
+
|
|
99
|
+
execute(callback: (error: any, data: zipdemographicsResponse | null) => void): Promise<zipdemographicsResponse>;
|
|
100
|
+
execute(query: Record<string, any>, callback: (error: any, data: zipdemographicsResponse | null) => void): Promise<zipdemographicsResponse>;
|
|
101
|
+
execute(query?: Record<string, any>): Promise<zipdemographicsResponse>;
|
|
102
|
+
}
|
|
103
|
+
}
|
package/index.js
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
|
|
3
|
-
class zipdemographicsWrapper {
|
|
4
|
-
|
|
5
|
-
constructor(options) {
|
|
6
|
-
if (!options || typeof options !== 'object') {
|
|
7
|
-
throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/zipdemographics');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const { api_key, secure = true } = options;
|
|
11
|
-
|
|
12
|
-
if (!api_key || typeof api_key !== 'string') {
|
|
13
|
-
throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Validate API key format (GUID, prefixed keys like apv_xxx, or alphanumeric)
|
|
17
|
-
const apiKeyPattern = /^[a-zA-Z0-9_-]+$/;
|
|
18
|
-
if (!apiKeyPattern.test(api_key)) {
|
|
19
|
-
throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens and underscores. Get your API key at: https://apiverve.com');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof secure !== 'boolean') {
|
|
23
|
-
throw new Error('Secure parameter must be a boolean value.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this.APIKey = api_key;
|
|
27
|
-
this.IsSecure = secure;
|
|
28
|
-
|
|
29
|
-
// secure is deprecated, all requests must be made over HTTPS
|
|
30
|
-
this.baseURL = 'https://api.apiverve.com/v1/zipdemographics';
|
|
31
|
-
|
|
32
|
-
// Validation rules for parameters (generated from schema)
|
|
33
|
-
this.validationRules = {"zip":{"type":"string","required":true,"minLength":5,"maxLength":5}};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Validate query parameters against schema rules
|
|
38
|
-
* @param {Object} query - The query parameters to validate
|
|
39
|
-
* @throws {Error} - If validation fails
|
|
40
|
-
*/
|
|
41
|
-
validateParams(query) {
|
|
42
|
-
const errors = [];
|
|
43
|
-
|
|
44
|
-
for (const [paramName, rules] of Object.entries(this.validationRules)) {
|
|
45
|
-
const value = query[paramName];
|
|
46
|
-
|
|
47
|
-
// Check required
|
|
48
|
-
if (rules.required && (value === undefined || value === null || value === '')) {
|
|
49
|
-
errors.push(`Required parameter [${paramName}] is missing.`);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Skip validation if value is not provided and not required
|
|
54
|
-
if (value === undefined || value === null) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Type validation
|
|
59
|
-
if (rules.type === 'integer' || rules.type === 'number') {
|
|
60
|
-
const numValue = Number(value);
|
|
61
|
-
if (isNaN(numValue)) {
|
|
62
|
-
errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (rules.type === 'integer' && !Number.isInteger(numValue)) {
|
|
67
|
-
errors.push(`Parameter [${paramName}] must be an integer.`);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Min/max validation for numbers
|
|
72
|
-
if (rules.min !== undefined && numValue < rules.min) {
|
|
73
|
-
errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
|
|
74
|
-
}
|
|
75
|
-
if (rules.max !== undefined && numValue > rules.max) {
|
|
76
|
-
errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
|
|
77
|
-
}
|
|
78
|
-
} else if (rules.type === 'string') {
|
|
79
|
-
if (typeof value !== 'string') {
|
|
80
|
-
errors.push(`Parameter [${paramName}] must be a string.`);
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Length validation for strings
|
|
85
|
-
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
86
|
-
errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
|
|
87
|
-
}
|
|
88
|
-
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
89
|
-
errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Format validation
|
|
93
|
-
if (rules.format) {
|
|
94
|
-
const formatPatterns = {
|
|
95
|
-
'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
96
|
-
'url': /^https?:\/\/.+/i,
|
|
97
|
-
'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
|
|
98
|
-
'date': /^\d{4}-\d{2}-\d{2}$/,
|
|
99
|
-
'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
|
|
103
|
-
errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} else if (rules.type === 'boolean') {
|
|
107
|
-
if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
|
|
108
|
-
errors.push(`Parameter [${paramName}] must be a boolean.`);
|
|
109
|
-
}
|
|
110
|
-
} else if (rules.type === 'array') {
|
|
111
|
-
if (!Array.isArray(value)) {
|
|
112
|
-
errors.push(`Parameter [${paramName}] must be an array.`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Enum validation
|
|
117
|
-
if (rules.enum && Array.isArray(rules.enum)) {
|
|
118
|
-
if (!rules.enum.includes(value)) {
|
|
119
|
-
errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (errors.length > 0) {
|
|
125
|
-
throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/zipdemographics`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async execute(query, callback) {
|
|
130
|
-
// Handle different argument patterns
|
|
131
|
-
if(arguments.length === 0) {
|
|
132
|
-
// execute() - no args
|
|
133
|
-
query = {};
|
|
134
|
-
callback = null;
|
|
135
|
-
} else if(arguments.length === 1) {
|
|
136
|
-
if (typeof query === 'function') {
|
|
137
|
-
// execute(callback)
|
|
138
|
-
callback = query;
|
|
139
|
-
query = {};
|
|
140
|
-
} else {
|
|
141
|
-
// execute(query)
|
|
142
|
-
callback = null;
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
// execute(query, callback)
|
|
146
|
-
if (!query || typeof query !== 'object') {
|
|
147
|
-
throw new Error('Query parameters must be provided as an object.');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Validate parameters against schema rules
|
|
152
|
-
this.validateParams(query);
|
|
153
|
-
|
|
154
|
-
const method = 'GET';
|
|
155
|
-
const url = method === 'POST' ? this.baseURL : this.constructURL(query);
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
const response = await axios({
|
|
159
|
-
method,
|
|
160
|
-
url,
|
|
161
|
-
headers: {
|
|
162
|
-
'Content-Type': 'application/json',
|
|
163
|
-
'x-api-key': this.APIKey,
|
|
164
|
-
'auth-mode': 'npm-package'
|
|
165
|
-
},
|
|
166
|
-
data: method === 'POST' ? query : undefined
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const data = response.data;
|
|
170
|
-
if (callback) callback(null, data);
|
|
171
|
-
return data;
|
|
172
|
-
} catch (error) {
|
|
173
|
-
let apiError;
|
|
174
|
-
|
|
175
|
-
if (error.response && error.response.data) {
|
|
176
|
-
apiError = error.response.data;
|
|
177
|
-
} else if (error.message) {
|
|
178
|
-
apiError = { error: error.message, status: 'error' };
|
|
179
|
-
} else {
|
|
180
|
-
apiError = { error: 'An unknown error occurred', status: 'error' };
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (callback) {
|
|
184
|
-
callback(apiError, null);
|
|
185
|
-
return; // Don't throw if callback is provided
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
throw apiError;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
constructURL(query) {
|
|
193
|
-
let url = this.baseURL;
|
|
194
|
-
|
|
195
|
-
if(query && typeof query === 'object')
|
|
196
|
-
{
|
|
197
|
-
if (Object.keys(query).length > 0) {
|
|
198
|
-
const queryString = Object.keys(query)
|
|
199
|
-
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
|
|
200
|
-
.join('&');
|
|
201
|
-
url += `?${queryString}`;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return url;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
module.exports = zipdemographicsWrapper;
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
class zipdemographicsWrapper {
|
|
4
|
+
|
|
5
|
+
constructor(options) {
|
|
6
|
+
if (!options || typeof options !== 'object') {
|
|
7
|
+
throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/zipdemographics');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { api_key, secure = true } = options;
|
|
11
|
+
|
|
12
|
+
if (!api_key || typeof api_key !== 'string') {
|
|
13
|
+
throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Validate API key format (GUID, prefixed keys like apv_xxx, or alphanumeric)
|
|
17
|
+
const apiKeyPattern = /^[a-zA-Z0-9_-]+$/;
|
|
18
|
+
if (!apiKeyPattern.test(api_key)) {
|
|
19
|
+
throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens and underscores. Get your API key at: https://apiverve.com');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (typeof secure !== 'boolean') {
|
|
23
|
+
throw new Error('Secure parameter must be a boolean value.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.APIKey = api_key;
|
|
27
|
+
this.IsSecure = secure;
|
|
28
|
+
|
|
29
|
+
// secure is deprecated, all requests must be made over HTTPS
|
|
30
|
+
this.baseURL = 'https://api.apiverve.com/v1/zipdemographics';
|
|
31
|
+
|
|
32
|
+
// Validation rules for parameters (generated from schema)
|
|
33
|
+
this.validationRules = {"zip":{"type":"string","required":true,"minLength":5,"maxLength":5}};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Validate query parameters against schema rules
|
|
38
|
+
* @param {Object} query - The query parameters to validate
|
|
39
|
+
* @throws {Error} - If validation fails
|
|
40
|
+
*/
|
|
41
|
+
validateParams(query) {
|
|
42
|
+
const errors = [];
|
|
43
|
+
|
|
44
|
+
for (const [paramName, rules] of Object.entries(this.validationRules)) {
|
|
45
|
+
const value = query[paramName];
|
|
46
|
+
|
|
47
|
+
// Check required
|
|
48
|
+
if (rules.required && (value === undefined || value === null || value === '')) {
|
|
49
|
+
errors.push(`Required parameter [${paramName}] is missing.`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Skip validation if value is not provided and not required
|
|
54
|
+
if (value === undefined || value === null) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Type validation
|
|
59
|
+
if (rules.type === 'integer' || rules.type === 'number') {
|
|
60
|
+
const numValue = Number(value);
|
|
61
|
+
if (isNaN(numValue)) {
|
|
62
|
+
errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (rules.type === 'integer' && !Number.isInteger(numValue)) {
|
|
67
|
+
errors.push(`Parameter [${paramName}] must be an integer.`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Min/max validation for numbers
|
|
72
|
+
if (rules.min !== undefined && numValue < rules.min) {
|
|
73
|
+
errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
|
|
74
|
+
}
|
|
75
|
+
if (rules.max !== undefined && numValue > rules.max) {
|
|
76
|
+
errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
|
|
77
|
+
}
|
|
78
|
+
} else if (rules.type === 'string') {
|
|
79
|
+
if (typeof value !== 'string') {
|
|
80
|
+
errors.push(`Parameter [${paramName}] must be a string.`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Length validation for strings
|
|
85
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
86
|
+
errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
|
|
87
|
+
}
|
|
88
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
89
|
+
errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Format validation
|
|
93
|
+
if (rules.format) {
|
|
94
|
+
const formatPatterns = {
|
|
95
|
+
'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
96
|
+
'url': /^https?:\/\/.+/i,
|
|
97
|
+
'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
|
|
98
|
+
'date': /^\d{4}-\d{2}-\d{2}$/,
|
|
99
|
+
'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
|
|
103
|
+
errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else if (rules.type === 'boolean') {
|
|
107
|
+
if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
|
|
108
|
+
errors.push(`Parameter [${paramName}] must be a boolean.`);
|
|
109
|
+
}
|
|
110
|
+
} else if (rules.type === 'array') {
|
|
111
|
+
if (!Array.isArray(value)) {
|
|
112
|
+
errors.push(`Parameter [${paramName}] must be an array.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Enum validation
|
|
117
|
+
if (rules.enum && Array.isArray(rules.enum)) {
|
|
118
|
+
if (!rules.enum.includes(value)) {
|
|
119
|
+
errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (errors.length > 0) {
|
|
125
|
+
throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/zipdemographics`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async execute(query, callback) {
|
|
130
|
+
// Handle different argument patterns
|
|
131
|
+
if(arguments.length === 0) {
|
|
132
|
+
// execute() - no args
|
|
133
|
+
query = {};
|
|
134
|
+
callback = null;
|
|
135
|
+
} else if(arguments.length === 1) {
|
|
136
|
+
if (typeof query === 'function') {
|
|
137
|
+
// execute(callback)
|
|
138
|
+
callback = query;
|
|
139
|
+
query = {};
|
|
140
|
+
} else {
|
|
141
|
+
// execute(query)
|
|
142
|
+
callback = null;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
// execute(query, callback)
|
|
146
|
+
if (!query || typeof query !== 'object') {
|
|
147
|
+
throw new Error('Query parameters must be provided as an object.');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Validate parameters against schema rules
|
|
152
|
+
this.validateParams(query);
|
|
153
|
+
|
|
154
|
+
const method = 'GET';
|
|
155
|
+
const url = method === 'POST' ? this.baseURL : this.constructURL(query);
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
const response = await axios({
|
|
159
|
+
method,
|
|
160
|
+
url,
|
|
161
|
+
headers: {
|
|
162
|
+
'Content-Type': 'application/json',
|
|
163
|
+
'x-api-key': this.APIKey,
|
|
164
|
+
'auth-mode': 'npm-package'
|
|
165
|
+
},
|
|
166
|
+
data: method === 'POST' ? query : undefined
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const data = response.data;
|
|
170
|
+
if (callback) callback(null, data);
|
|
171
|
+
return data;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
let apiError;
|
|
174
|
+
|
|
175
|
+
if (error.response && error.response.data) {
|
|
176
|
+
apiError = error.response.data;
|
|
177
|
+
} else if (error.message) {
|
|
178
|
+
apiError = { error: error.message, status: 'error' };
|
|
179
|
+
} else {
|
|
180
|
+
apiError = { error: 'An unknown error occurred', status: 'error' };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (callback) {
|
|
184
|
+
callback(apiError, null);
|
|
185
|
+
return; // Don't throw if callback is provided
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
throw apiError;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
constructURL(query) {
|
|
193
|
+
let url = this.baseURL;
|
|
194
|
+
|
|
195
|
+
if(query && typeof query === 'object')
|
|
196
|
+
{
|
|
197
|
+
if (Object.keys(query).length > 0) {
|
|
198
|
+
const queryString = Object.keys(query)
|
|
199
|
+
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
|
|
200
|
+
.join('&');
|
|
201
|
+
url += `?${queryString}`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return url;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
module.exports = zipdemographicsWrapper;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apiverve/zipdemographics",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "ZIP Demographics
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "ZIP Demographics is a demographic data API for any US ZIP code, built on the US Census American Community Survey. Every plan gets total population and median household income, while paid plans add age, per-capita income, education, housing, employment, and racial composition.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"directory": "npm"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
|
-
"
|
|
26
|
+
"demographics api", "demographic data api", "zip code demographics", "demographics by zip code api", "census data api"
|
|
27
27
|
],
|
|
28
28
|
"author": {
|
|
29
29
|
"name": "APIVerve",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"bugs": {
|
|
35
35
|
"url": "https://github.com/apiverve/zipdemographics-api/issues"
|
|
36
36
|
},
|
|
37
|
-
"homepage": "https://apiverve.com/marketplace/zipdemographics?utm_source=npm&utm_medium=homepage",
|
|
37
|
+
"homepage": "https://apiverve.com/marketplace/zipdemographics?utm_source=npm&utm_medium=referral&utm_content=homepage",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"mocha": "^11.0.1",
|
|
40
40
|
"chai": "^5.1.2",
|