@apiverve/workingdays 1.1.9 → 1.1.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 APIVerve, and Evlar LLC
3
+ Copyright (c) 2025 APIVerve, and EvlarSoft LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Working Days API
2
- ============
1
+ # Working Days API
3
2
 
4
3
  Working Days is a simple tool for getting the number of working days in a month. It returns the number of working days in the given month.
5
4
 
@@ -7,56 +6,64 @@ Working Days is a simple tool for getting the number of working days in a month.
7
6
  ![Code Climate](https://img.shields.io/badge/maintainability-B-purple)
8
7
  ![Prod Ready](https://img.shields.io/badge/production-ready-blue)
9
8
 
10
- This is a Javascript Wrapper for the [Working Days API](https://apiverve.com/marketplace/api/workingdays)
9
+ This is a Javascript Wrapper for the [Working Days API](https://apiverve.com/marketplace/workingdays)
11
10
 
12
11
  ---
13
12
 
14
13
  ## Installation
15
- npm install @apiverve/workingdays --save
14
+
15
+ Using npm:
16
+ ```shell
17
+ npm install @apiverve/workingdays
18
+ ```
19
+
20
+ Using yarn:
21
+ ```shell
22
+ yarn add @apiverve/workingdays
23
+ ```
16
24
 
17
25
  ---
18
26
 
19
27
  ## Configuration
20
28
 
21
- Before using the workingdays API client, you have to setup your account and obtain your API Key.
29
+ Before using the Working Days API client, you have to setup your account and obtain your API Key.
22
30
  You can get it by signing up at [https://apiverve.com](https://apiverve.com)
23
31
 
24
32
  ---
25
33
 
26
- ## Usage
34
+ ## Quick Start
35
+
36
+ [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
27
37
 
28
- The Working Days API documentation is found here: [https://docs.apiverve.com/api/workingdays](https://docs.apiverve.com/api/workingdays).
38
+ The Working Days API documentation is found here: [https://docs.apiverve.com/ref/workingdays](https://docs.apiverve.com/ref/workingdays).
29
39
  You can find parameters, example responses, and status codes documented here.
30
40
 
31
41
  ### Setup
32
42
 
33
- ```
34
- var workingdaysAPI = require('@apiverve/workingdays');
35
- var api = new workingdaysAPI({
36
- api_key: [YOUR_API_KEY],
37
- secure: true //(Optional, defaults to true)
43
+ ```javascript
44
+ const workingdaysAPI = require('@apiverve/workingdays');
45
+ const api = new workingdaysAPI({
46
+ api_key: '[YOUR_API_KEY]'
38
47
  });
39
48
  ```
40
49
 
41
50
  ---
42
51
 
52
+ ## Usage
53
+
54
+ ---
43
55
 
44
56
  ### Perform Request
45
- Using the API client, you can perform requests to the API.
46
57
 
47
- ###### Define Query
58
+ 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.
48
59
 
49
- ```
60
+ ```javascript
50
61
  var query = {
51
62
  country: "US",
52
63
  year: 2023,
53
64
  month: 10
54
65
  };
55
- ```
56
-
57
- ###### Simple Request (using Callback)
58
66
 
59
- ```
60
67
  api.execute(query, function (error, data) {
61
68
  if (error) {
62
69
  return console.error(error);
@@ -66,112 +73,158 @@ api.execute(query, function (error, data) {
66
73
  });
67
74
  ```
68
75
 
69
- ###### Example Response
76
+ ---
77
+
78
+ ### Using Promises
79
+
80
+ You can also use promises to make requests. The API returns a promise that you can use to handle the response.
81
+
82
+ ```javascript
83
+ var query = {
84
+ country: "US",
85
+ year: 2023,
86
+ month: 10
87
+ };
88
+
89
+ api.execute(query)
90
+ .then(data => {
91
+ console.log(data);
92
+ })
93
+ .catch(error => {
94
+ console.error(error);
95
+ });
96
+ ```
97
+
98
+ ---
99
+
100
+ ### Using Async/Await
101
+
102
+ You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
70
103
 
104
+ ```javascript
105
+ async function makeRequest() {
106
+ var query = {
107
+ country: "US",
108
+ year: 2023,
109
+ month: 10
110
+ };
111
+
112
+ try {
113
+ const data = await api.execute(query);
114
+ console.log(data);
115
+ } catch (error) {
116
+ console.error(error);
117
+ }
118
+ }
71
119
  ```
72
- {
73
- "status": "ok",
74
- "error": null,
75
- "data": {
76
- "workingDaysCount": 21,
77
- "nonWorkingDaysCount": 10,
78
- "workingDays": [
79
- "2023-10-02",
80
- "2023-10-03",
81
- "2023-10-04",
82
- "2023-10-05",
83
- "2023-10-06",
84
- "2023-10-10",
85
- "2023-10-11",
86
- "2023-10-12",
87
- "2023-10-13",
88
- "2023-10-16",
89
- "2023-10-17",
90
- "2023-10-18",
91
- "2023-10-19",
92
- "2023-10-20",
93
- "2023-10-23",
94
- "2023-10-24",
95
- "2023-10-25",
96
- "2023-10-26",
97
- "2023-10-27",
98
- "2023-10-30",
99
- "2023-10-31"
100
- ],
101
- "nonWorkingDays": [
102
- {
103
- "date": "2023-10-01",
104
- "reasons": [
105
- "weekend"
106
- ],
107
- "holiday_name": null
108
- },
109
- {
110
- "date": "2023-10-07",
111
- "reasons": [
112
- "weekend"
113
- ],
114
- "holiday_name": null
115
- },
116
- {
117
- "date": "2023-10-08",
118
- "reasons": [
119
- "weekend"
120
- ],
121
- "holiday_name": null
122
- },
123
- {
124
- "date": "2023-10-09",
125
- "reasons": [
126
- "public holiday"
127
- ],
128
- "holiday_name": "Columbus Day"
129
- },
130
- {
131
- "date": "2023-10-14",
132
- "reasons": [
133
- "weekend"
134
- ],
135
- "holiday_name": null
136
- },
137
- {
138
- "date": "2023-10-15",
139
- "reasons": [
140
- "weekend"
141
- ],
142
- "holiday_name": null
143
- },
144
- {
145
- "date": "2023-10-21",
146
- "reasons": [
147
- "weekend"
148
- ],
149
- "holiday_name": null
150
- },
151
- {
152
- "date": "2023-10-22",
153
- "reasons": [
154
- "weekend"
155
- ],
156
- "holiday_name": null
157
- },
158
- {
159
- "date": "2023-10-28",
160
- "reasons": [
161
- "weekend"
162
- ],
163
- "holiday_name": null
164
- },
165
- {
166
- "date": "2023-10-29",
167
- "reasons": [
168
- "weekend"
169
- ],
170
- "holiday_name": null
171
- }
172
- ]
173
- },
174
- "code": 200
120
+
121
+ ---
122
+
123
+ ## Example Response
124
+
125
+ ```json
126
+ {
127
+ "status": "ok",
128
+ "error": null,
129
+ "data": {
130
+ "workingDaysCount": 21,
131
+ "nonWorkingDaysCount": 10,
132
+ "workingDays": [
133
+ "2023-10-02",
134
+ "2023-10-03",
135
+ "2023-10-04",
136
+ "2023-10-05",
137
+ "2023-10-06",
138
+ "2023-10-10",
139
+ "2023-10-11",
140
+ "2023-10-12",
141
+ "2023-10-13",
142
+ "2023-10-16",
143
+ "2023-10-17",
144
+ "2023-10-18",
145
+ "2023-10-19",
146
+ "2023-10-20",
147
+ "2023-10-23",
148
+ "2023-10-24",
149
+ "2023-10-25",
150
+ "2023-10-26",
151
+ "2023-10-27",
152
+ "2023-10-30",
153
+ "2023-10-31"
154
+ ],
155
+ "nonWorkingDays": [
156
+ {
157
+ "date": "2023-10-01",
158
+ "reasons": [
159
+ "weekend"
160
+ ],
161
+ "holiday_name": null
162
+ },
163
+ {
164
+ "date": "2023-10-07",
165
+ "reasons": [
166
+ "weekend"
167
+ ],
168
+ "holiday_name": null
169
+ },
170
+ {
171
+ "date": "2023-10-08",
172
+ "reasons": [
173
+ "weekend"
174
+ ],
175
+ "holiday_name": null
176
+ },
177
+ {
178
+ "date": "2023-10-09",
179
+ "reasons": [
180
+ "public holiday"
181
+ ],
182
+ "holiday_name": "Columbus Day"
183
+ },
184
+ {
185
+ "date": "2023-10-14",
186
+ "reasons": [
187
+ "weekend"
188
+ ],
189
+ "holiday_name": null
190
+ },
191
+ {
192
+ "date": "2023-10-15",
193
+ "reasons": [
194
+ "weekend"
195
+ ],
196
+ "holiday_name": null
197
+ },
198
+ {
199
+ "date": "2023-10-21",
200
+ "reasons": [
201
+ "weekend"
202
+ ],
203
+ "holiday_name": null
204
+ },
205
+ {
206
+ "date": "2023-10-22",
207
+ "reasons": [
208
+ "weekend"
209
+ ],
210
+ "holiday_name": null
211
+ },
212
+ {
213
+ "date": "2023-10-28",
214
+ "reasons": [
215
+ "weekend"
216
+ ],
217
+ "holiday_name": null
218
+ },
219
+ {
220
+ "date": "2023-10-29",
221
+ "reasons": [
222
+ "weekend"
223
+ ],
224
+ "holiday_name": null
225
+ }
226
+ ]
227
+ }
175
228
  }
176
229
  ```
177
230
 
@@ -184,6 +237,7 @@ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/c
184
237
  ---
185
238
 
186
239
  ## Updates
240
+
187
241
  Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
188
242
 
189
243
  ---
@@ -203,4 +257,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
203
257
 
204
258
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
205
259
 
206
- 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.
260
+ 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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Basic Example - Working Days API
3
+ *
4
+ * This example demonstrates how to use the Working Days API.
5
+ * Make sure to set your API key in the .env file or replace '[YOUR_API_KEY]' below.
6
+ */
7
+
8
+ require('dotenv').config();
9
+ const workingdaysAPI = require('../index.js');
10
+
11
+ // Initialize the API client
12
+ const api = new workingdaysAPI({
13
+ api_key: process.env.API_KEY || '[YOUR_API_KEY]'
14
+ });
15
+
16
+ // Example query
17
+ var query = {
18
+ country: "US",
19
+ year: 2023,
20
+ month: 10
21
+ };
22
+
23
+ // Make the API request using callback
24
+ console.log('Making request to Working Days API...\n');
25
+
26
+ api.execute(query, function (error, data) {
27
+ if (error) {
28
+ console.error('Error occurred:');
29
+ if (error.error) {
30
+ console.error('Message:', error.error);
31
+ console.error('Status:', error.status);
32
+ } else {
33
+ console.error(JSON.stringify(error, null, 2));
34
+ }
35
+ return;
36
+ }
37
+
38
+ console.log('Response:');
39
+ console.log(JSON.stringify(data, null, 2));
40
+ });
package/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ declare module '@apiverve/workingdays' {
2
+ export interface workingdaysOptions {
3
+ api_key: string;
4
+ secure?: boolean;
5
+ }
6
+
7
+ export interface workingdaysResponse {
8
+ status: string;
9
+ error: string | null;
10
+ data: any;
11
+ code?: number;
12
+ }
13
+
14
+ export default class workingdaysWrapper {
15
+ constructor(options: workingdaysOptions);
16
+
17
+ execute(callback: (error: any, data: workingdaysResponse | null) => void): Promise<workingdaysResponse>;
18
+ execute(query: Record<string, any>, callback: (error: any, data: workingdaysResponse | null) => void): Promise<workingdaysResponse>;
19
+ execute(query?: Record<string, any>): Promise<workingdaysResponse>;
20
+ }
21
+ }
package/index.js CHANGED
@@ -4,14 +4,27 @@ class workingdaysWrapper {
4
4
 
5
5
  constructor(options) {
6
6
  if (!options || typeof options !== 'object') {
7
- throw new Error('Options object must be provided.');
7
+ throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/workingdays');
8
8
  }
9
9
 
10
10
  const { api_key, secure = true } = options;
11
11
 
12
12
  if (!api_key || typeof api_key !== 'string') {
13
- throw new Error('API key must be provided as a non-empty string.');
13
+ throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
14
14
  }
15
+
16
+ // Validate API key format (GUID or alphanumeric with hyphens)
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. Get your API key at: https://apiverve.com');
20
+ }
21
+
22
+ // Check minimum length (GUIDs are typically 36 chars with hyphens, or 32 without)
23
+ const trimmedKey = api_key.replace(/-/g, '');
24
+ if (trimmedKey.length < 32) {
25
+ throw new Error('Invalid API key. API key appears to be too short. Get your API key at: https://apiverve.com');
26
+ }
27
+
15
28
  if (typeof secure !== 'boolean') {
16
29
  throw new Error('Secure parameter must be a boolean value.');
17
30
  }
@@ -24,20 +37,32 @@ class workingdaysWrapper {
24
37
  }
25
38
 
26
39
  async execute(query, callback) {
27
- if(arguments.length > 1) {
40
+ // Handle different argument patterns
41
+ if(arguments.length === 0) {
42
+ // execute() - no args
43
+ query = {};
44
+ callback = null;
45
+ } else if(arguments.length === 1) {
46
+ if (typeof query === 'function') {
47
+ // execute(callback)
48
+ callback = query;
49
+ query = {};
50
+ } else {
51
+ // execute(query)
52
+ callback = null;
53
+ }
54
+ } else {
55
+ // execute(query, callback)
28
56
  if (!query || typeof query !== 'object') {
29
57
  throw new Error('Query parameters must be provided as an object.');
30
58
  }
31
- } else {
32
- callback = query;
33
- query = {};
34
59
  }
35
60
 
36
- var requiredParams = ["country", "year"];
61
+ var requiredParams = ["country","year"];
37
62
  if (requiredParams.length > 0) {
38
63
  for (var i = 0; i < requiredParams.length; i++) {
39
64
  if (!query[requiredParams[i]]) {
40
- throw new Error(`Required parameter [${requiredParams[i]}] is missing.`);
65
+ throw new Error(`Required parameter [${requiredParams[i]}] is missing. See documentation: https://docs.apiverve.com/ref/workingdays`);
41
66
  }
42
67
  }
43
68
  }
@@ -58,16 +83,25 @@ class workingdaysWrapper {
58
83
  });
59
84
 
60
85
  const data = response.data;
61
- callback(null, data);
86
+ if (callback) callback(null, data);
62
87
  return data;
63
88
  } catch (error) {
64
- if (error.response.data) {
65
- callback(error.response.data, null);
66
- throw error.response.data;
89
+ let apiError;
90
+
91
+ if (error.response && error.response.data) {
92
+ apiError = error.response.data;
93
+ } else if (error.message) {
94
+ apiError = { error: error.message, status: 'error' };
67
95
  } else {
68
- callback(error, null);
69
- throw error;
70
- }
96
+ apiError = { error: 'An unknown error occurred', status: 'error' };
97
+ }
98
+
99
+ if (callback) {
100
+ callback(apiError, null);
101
+ return; // Don't throw if callback is provided
102
+ }
103
+
104
+ throw apiError;
71
105
  }
72
106
  }
73
107
 
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "@apiverve/workingdays",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "Working Days is a simple tool for getting the number of working days in a month. It returns the number of working days in the given month.",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "scripts": {
7
- "test": "mocha"
8
+ "test": "mocha",
9
+ "example": "node examples/basic.js"
8
10
  },
9
11
  "repository": {
10
12
  "type": "git",
11
13
  "url": "git+https://github.com/apiverve/workingdays-API.git"
12
14
  },
13
15
  "keywords": [
14
- "working days","working days api","working days tool","working days software","working days service"
16
+ "working days", "working days api", "working days tool", "working days software", "working days service"
15
17
  ],
16
18
  "author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
17
19
  "license": "MIT",
18
20
  "bugs": {
19
21
  "url": "https://github.com/apiverve/workingdays-API/issues"
20
22
  },
21
- "homepage": "https://apiverve.com/marketplace/api/workingdays?utm_source=npm",
23
+ "homepage": "https://apiverve.com/marketplace/workingdays?utm_source=npm",
22
24
  "devDependencies": {
23
25
  "mocha": "^11.0.1",
24
26
  "chai": "^5.1.2",
@@ -27,6 +29,6 @@
27
29
  "dependencies": {
28
30
  "node-fetch": "^3.3.2",
29
31
  "promise": "^8.3.0",
30
- "axios": "1.7.9"
32
+ "axios": "1.13.2"
31
33
  }
32
34
  }