@apiverve/stateboundaries 1.1.7

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/index.js ADDED
@@ -0,0 +1,90 @@
1
+ const axios = require('axios');
2
+
3
+ class stateboundariesWrapper {
4
+
5
+ constructor(options) {
6
+ if (!options || typeof options !== 'object') {
7
+ throw new Error('Options object must be provided.');
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.');
14
+ }
15
+ if (typeof secure !== 'boolean') {
16
+ throw new Error('Secure parameter must be a boolean value.');
17
+ }
18
+
19
+ this.APIKey = api_key;
20
+ this.IsSecure = secure;
21
+
22
+ // secure is deprecated, all requests must be made over HTTPS
23
+ this.baseURL = 'https://api.apiverve.com/v1/stateboundaries';
24
+ }
25
+
26
+ async execute(query, callback) {
27
+ if(arguments.length > 1) {
28
+ if (!query || typeof query !== 'object') {
29
+ throw new Error('Query parameters must be provided as an object.');
30
+ }
31
+ } else {
32
+ callback = query;
33
+ query = {};
34
+ }
35
+
36
+ var requiredParams = ["state"];
37
+ if (requiredParams.length > 0) {
38
+ for (var i = 0; i < requiredParams.length; i++) {
39
+ if (!query[requiredParams[i]]) {
40
+ throw new Error(`Required parameter [${requiredParams[i]}] is missing.`);
41
+ }
42
+ }
43
+ }
44
+
45
+ const method = 'GET';
46
+ const url = method === 'POST' ? this.baseURL : this.constructURL(query);
47
+
48
+ try {
49
+ const response = await axios({
50
+ method,
51
+ url,
52
+ headers: {
53
+ 'Content-Type': 'application/json',
54
+ 'x-api-key': this.APIKey,
55
+ 'auth-mode': 'npm-package'
56
+ },
57
+ data: method === 'POST' ? query : undefined
58
+ });
59
+
60
+ const data = response.data;
61
+ callback(null, data);
62
+ return data;
63
+ } catch (error) {
64
+ if (error.response.data) {
65
+ callback(error.response.data, null);
66
+ throw error.response.data;
67
+ } else {
68
+ callback(error, null);
69
+ throw error;
70
+ }
71
+ }
72
+ }
73
+
74
+ constructURL(query) {
75
+ let url = this.baseURL;
76
+
77
+ if(query && typeof query === 'object')
78
+ {
79
+ if (Object.keys(query).length > 0) {
80
+ const queryString = Object.keys(query)
81
+ .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
82
+ .join('&');
83
+ url += `?${queryString}`;
84
+ }
85
+ }
86
+ return url;
87
+ }
88
+ }
89
+
90
+ module.exports = stateboundariesWrapper;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@apiverve/stateboundaries",
3
+ "version": "1.1.7",
4
+ "description": "State Boundaries is a simple tool for getting the boundaries of a specific state's border. It returns the shape of the specified state's border.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "mocha"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/apiverve/stateboundaries-API.git"
12
+ },
13
+ "keywords": [
14
+ "state boundaries","state boundaries api","state boundaries tool","state boundaries software","state boundaries service"
15
+ ],
16
+ "author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/apiverve/stateboundaries-API/issues"
20
+ },
21
+ "homepage": "https://apiverve.com/marketplace/api/stateboundaries?utm_source=npm",
22
+ "devDependencies": {
23
+ "mocha": "^11.0.1",
24
+ "chai": "^5.1.2",
25
+ "dotenv": "^16.4.7"
26
+ },
27
+ "dependencies": {
28
+ "node-fetch": "^3.3.2",
29
+ "promise": "^8.3.0",
30
+ "axios": "1.7.9"
31
+ }
32
+ }
package/tmp/build.dat ADDED
@@ -0,0 +1 @@
1
+ #