@apiverve/weatherforecast 1.1.14 → 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.
Files changed (5) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +332 -162
  3. package/index.d.ts +83 -37
  4. package/index.js +209 -209
  5. package/package.json +7 -8
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 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
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,174 +1,344 @@
1
- # Weather API
2
-
3
- Weather is a simple tool for getting the current weather. It returns the temperature, humidity, and more for a given location.
4
-
5
- ![Build Status](https://img.shields.io/badge/build-passing-green)
6
- ![Code Climate](https://img.shields.io/badge/maintainability-B-purple)
7
- ![Prod Ready](https://img.shields.io/badge/production-ready-blue)
8
- [![npm version](https://img.shields.io/npm/v/@apiverve/weatherforecast.svg)](https://www.npmjs.com/package/@apiverve/weatherforecast)
9
-
10
- This is a Javascript Wrapper for the [Weather API](https://weatherforecast.apiverve.com?utm_source=npm&utm_medium=readme)
11
-
12
- ---
13
-
14
- ## Installation
15
-
16
- Using npm:
17
- ```shell
18
- npm install @apiverve/weatherforecast
19
- ```
20
-
21
- Using yarn:
22
- ```shell
23
- yarn add @apiverve/weatherforecast
24
- ```
25
-
26
- ---
27
-
28
- ## Configuration
29
-
30
- Before using the Weather API client, you have to setup your account and obtain your API Key.
31
- You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=readme)
32
-
33
- ---
34
-
35
- ## Quick Start
36
-
37
- [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=readme)
38
-
39
- The Weather API documentation is found here: [https://docs.apiverve.com/ref/weatherforecast](https://docs.apiverve.com/ref/weatherforecast?utm_source=npm&utm_medium=readme).
40
- You can find parameters, example responses, and status codes documented here.
41
-
42
- ### Setup
43
-
44
- ```javascript
45
- const weatherforecastAPI = require('@apiverve/weatherforecast');
46
- const api = new weatherforecastAPI({
47
- api_key: '[YOUR_API_KEY]'
48
- });
49
- ```
50
-
51
- ---
52
-
53
- ## Usage
54
-
55
- ---
56
-
57
- ### Perform Request
58
-
59
- 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.
60
-
61
- ```javascript
1
+ # Weather API
2
+
3
+ Weather is a current weather API that reports conditions for any city name or zip code: real-time temperature and wind speed with compass direction, in both metric and imperial units. Paid plans add a 7-day forecast with daily highs, lows, rain chance and conditions for the week ahead.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@apiverve/weatherforecast.svg)](https://www.npmjs.com/package/@apiverve/weatherforecast)
6
+
7
+ This is a JavaScript wrapper for the [Weather API](https://apiverve.com/marketplace/weatherforecast?utm_source=npm&utm_medium=referral&utm_content=readme)
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ Using npm:
14
+ ```shell
15
+ npm install @apiverve/weatherforecast
16
+ ```
17
+
18
+ Using yarn:
19
+ ```shell
20
+ yarn add @apiverve/weatherforecast
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Configuration
26
+
27
+ Before using the Weather 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 Weather API documentation is found here: [https://docs.apiverve.com/ref/weatherforecast](https://docs.apiverve.com/ref/weatherforecast?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 weatherforecastAPI = require('@apiverve/weatherforecast');
43
+ const api = new weatherforecastAPI({
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
- city: "San Francisco"
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
60
+ city: "San Francisco",
61
+ forecast: true
62
+ };
63
+
64
+ api.execute(query, function (error, data) {
65
+ if (error) {
66
+ return console.error(error);
67
+ } else {
68
+ console.log(data);
69
+ }
70
+ });
71
+ ```
72
+
73
+ ---
74
+
75
+ ### Using Promises
76
+
77
+ You can also use promises to make requests. The API returns a promise that you can use to handle the response.
78
+
79
+ ```javascript
82
80
  var query = {
83
- city: "San Francisco"
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
+ city: "San Francisco",
82
+ forecast: true
83
+ };
84
+
85
+ api.execute(query)
86
+ .then(data => {
87
+ console.log(data);
88
+ })
89
+ .catch(error => {
90
+ console.error(error);
91
+ });
92
+ ```
93
+
94
+ ---
95
+
96
+ ### Using Async/Await
97
+
98
+ You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
99
+
100
+ ```javascript
101
+ async function makeRequest() {
103
102
  var query = {
104
- city: "San Francisco"
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
103
+ city: "San Francisco",
104
+ forecast: true
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
121
121
  {
122
122
  "status": "ok",
123
123
  "error": null,
124
124
  "data": {
125
- "tempC": 15.6,
126
- "tempF": 60.1,
127
- "windMph": 4.9,
128
- "windKph": 7.9,
129
- "windDegree": 315,
130
- "windDir": "NW",
131
- "pressureMb": 1021,
132
- "pressureIn": 30.16,
125
+ "tempC": 13.3,
126
+ "tempF": 55.9,
127
+ "windMph": 4.7,
128
+ "windKph": 7.6,
129
+ "windDegree": 273,
130
+ "windDir": "W",
131
+ "pressureMb": 1022,
132
+ "pressureIn": 30.17,
133
133
  "precipMm": 0,
134
134
  "precipIn": 0,
135
- "feelslikeC": 15.6,
136
- "feelslikeF": 60.1,
135
+ "feelslikeC": 13,
136
+ "feelslikeF": 55.3,
137
137
  "visKm": 16,
138
138
  "visMiles": 9,
139
- "gustMph": 6.6,
140
- "gustKph": 10.5
139
+ "gustMph": 7.2,
140
+ "gustKph": 11.6,
141
+ "forecast": [
142
+ {
143
+ "date": "2026-09-21",
144
+ "condition": "Sunny",
145
+ "maxtempC": 22.5,
146
+ "maxtempF": 72.5,
147
+ "mintempC": 13.3,
148
+ "mintempF": 56,
149
+ "avgtempC": 17.7,
150
+ "avgtempF": 63.9,
151
+ "maxwindMph": 4.7,
152
+ "maxwindKph": 7.6,
153
+ "avghumidity": 48,
154
+ "uv": 4,
155
+ "willItRain": 0,
156
+ "chanceOfRain": 4,
157
+ "willItSnow": 0,
158
+ "chanceOfSnow": 0,
159
+ "totalprecipMm": 0,
160
+ "totalprecipIn": 0,
161
+ "totalsnowCm": 0,
162
+ "avgvisKm": 10,
163
+ "avgvisMiles": 6
164
+ },
165
+ {
166
+ "date": "2026-09-22",
167
+ "condition": "Sunny",
168
+ "maxtempC": 22.8,
169
+ "maxtempF": 73,
170
+ "mintempC": 16.5,
171
+ "mintempF": 61.7,
172
+ "avgtempC": 19.7,
173
+ "avgtempF": 67.5,
174
+ "maxwindMph": 4.7,
175
+ "maxwindKph": 7.6,
176
+ "avghumidity": 63,
177
+ "uv": 3.9,
178
+ "willItRain": 0,
179
+ "chanceOfRain": 8,
180
+ "willItSnow": 0,
181
+ "chanceOfSnow": 0,
182
+ "totalprecipMm": 0.02,
183
+ "totalprecipIn": 0,
184
+ "totalsnowCm": 0,
185
+ "avgvisKm": 10,
186
+ "avgvisMiles": 6
187
+ },
188
+ {
189
+ "date": "2026-09-23",
190
+ "condition": "Overcast",
191
+ "maxtempC": 22.8,
192
+ "maxtempF": 73.1,
193
+ "mintempC": 14.1,
194
+ "mintempF": 57.4,
195
+ "avgtempC": 18.4,
196
+ "avgtempF": 65.2,
197
+ "maxwindMph": 15.7,
198
+ "maxwindKph": 25.2,
199
+ "avghumidity": 70,
200
+ "uv": 3.1,
201
+ "willItRain": 1,
202
+ "chanceOfRain": 76,
203
+ "willItSnow": 0,
204
+ "chanceOfSnow": 0,
205
+ "totalprecipMm": 5.97,
206
+ "totalprecipIn": 0.23,
207
+ "totalsnowCm": 0,
208
+ "avgvisKm": 9.9,
209
+ "avgvisMiles": 6
210
+ },
211
+ {
212
+ "date": "2026-09-24",
213
+ "condition": "Partly Cloudy",
214
+ "maxtempC": 18,
215
+ "maxtempF": 64.5,
216
+ "mintempC": 10.5,
217
+ "mintempF": 50.8,
218
+ "avgtempC": 14.3,
219
+ "avgtempF": 57.7,
220
+ "maxwindMph": 11,
221
+ "maxwindKph": 17.6,
222
+ "avghumidity": 64,
223
+ "uv": 3.5,
224
+ "willItRain": 0,
225
+ "chanceOfRain": 11,
226
+ "willItSnow": 0,
227
+ "chanceOfSnow": 0,
228
+ "totalprecipMm": 0.03,
229
+ "totalprecipIn": 0,
230
+ "totalsnowCm": 0,
231
+ "avgvisKm": 10,
232
+ "avgvisMiles": 6
233
+ },
234
+ {
235
+ "date": "2026-09-25",
236
+ "condition": "Sunny",
237
+ "maxtempC": 21.3,
238
+ "maxtempF": 70.3,
239
+ "mintempC": 12,
240
+ "mintempF": 53.6,
241
+ "avgtempC": 16,
242
+ "avgtempF": 60.8,
243
+ "maxwindMph": 6.5,
244
+ "maxwindKph": 10.4,
245
+ "avghumidity": 56,
246
+ "uv": 6,
247
+ "willItRain": 0,
248
+ "chanceOfRain": 4,
249
+ "willItSnow": 0,
250
+ "chanceOfSnow": 0,
251
+ "totalprecipMm": 0,
252
+ "totalprecipIn": 0,
253
+ "totalsnowCm": 0,
254
+ "avgvisKm": 10,
255
+ "avgvisMiles": 6
256
+ },
257
+ {
258
+ "date": "2026-09-26",
259
+ "condition": "Sunny",
260
+ "maxtempC": 22,
261
+ "maxtempF": 71.5,
262
+ "mintempC": 13,
263
+ "mintempF": 55.3,
264
+ "avgtempC": 17.1,
265
+ "avgtempF": 62.8,
266
+ "maxwindMph": 8.9,
267
+ "maxwindKph": 14.4,
268
+ "avghumidity": 62,
269
+ "uv": 6,
270
+ "willItRain": 0,
271
+ "chanceOfRain": 8,
272
+ "willItSnow": 0,
273
+ "chanceOfSnow": 0,
274
+ "totalprecipMm": 0,
275
+ "totalprecipIn": 0,
276
+ "totalsnowCm": 0,
277
+ "avgvisKm": 10,
278
+ "avgvisMiles": 6
279
+ },
280
+ {
281
+ "date": "2026-09-27",
282
+ "condition": "Overcast",
283
+ "maxtempC": 19.3,
284
+ "maxtempF": 66.8,
285
+ "mintempC": 12.8,
286
+ "mintempF": 55.1,
287
+ "avgtempC": 16.3,
288
+ "avgtempF": 61.3,
289
+ "maxwindMph": 6.9,
290
+ "maxwindKph": 11.2,
291
+ "avghumidity": 67,
292
+ "uv": 4,
293
+ "willItRain": 0,
294
+ "chanceOfRain": 36,
295
+ "willItSnow": 0,
296
+ "chanceOfSnow": 0,
297
+ "totalprecipMm": 0.32,
298
+ "totalprecipIn": 0.01,
299
+ "totalsnowCm": 0,
300
+ "avgvisKm": 10,
301
+ "avgvisMiles": 6
302
+ }
303
+ ],
304
+ "forecastSummary": {
305
+ "rainExpectedOn": "2026-09-23",
306
+ "daysWithRain": 1,
307
+ "tempTrend": "cooling",
308
+ "tempTrendC": -2.1,
309
+ "maxChanceOfRain": 76
310
+ }
141
311
  }
142
- }
143
- ```
144
-
145
- ---
146
-
147
- ## Customer Support
148
-
149
- Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=readme).
150
-
151
- ---
152
-
153
- ## Updates
154
-
155
- Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
156
-
157
- ---
158
-
159
- ## Legal
160
-
161
- 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=readme), [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=readme), and [Refund Policy](https://apiverve.com/refund?utm_source=npm&utm_medium=readme).
162
-
163
- ---
164
-
165
- ## License
166
- Licensed under the The MIT License (MIT)
167
-
168
- Copyright (©) 2026 APIVerve, and EvlarSoft LLC
169
-
170
- 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:
171
-
172
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
173
-
174
- 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.
312
+ }
313
+ ```
314
+
315
+ ---
316
+
317
+ ## Customer Support
318
+
319
+ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=referral&utm_content=readme).
320
+
321
+ ---
322
+
323
+ ## Updates
324
+
325
+ Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
326
+
327
+ ---
328
+
329
+ ## Legal
330
+
331
+ 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).
332
+
333
+ ---
334
+
335
+ ## License
336
+ Licensed under the MIT License (MIT)
337
+
338
+ Copyright (©) 2026 APIVerve, and EvlarSoft LLC
339
+
340
+ 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:
341
+
342
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
343
+
344
+ 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,41 +1,87 @@
1
- declare module '@apiverve/weatherforecast' {
2
- export interface weatherforecastOptions {
3
- api_key: string;
4
- secure?: boolean;
5
- }
6
-
7
- export interface weatherforecastResponse {
8
- status: string;
9
- error: string | null;
10
- data: WeatherData;
11
- code?: number;
12
- }
13
-
1
+ declare module '@apiverve/weatherforecast' {
2
+ export interface weatherforecastOptions {
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 weatherforecastResponse {
19
+ status: string;
20
+ error: string | null;
21
+ data: WeatherData;
22
+ code?: number;
23
+ premium?: PremiumInfo;
24
+ }
25
+
14
26
 
15
27
  interface WeatherData {
16
- tempC: number;
17
- tempF: number;
18
- windMph: number;
19
- windKph: number;
20
- windDegree: number;
21
- windDir: string;
22
- pressureMB: number;
23
- pressureIn: number;
24
- precipMm: number;
25
- precipIn: number;
26
- feelslikeC: number;
27
- feelslikeF: number;
28
- visKM: number;
29
- visMiles: number;
30
- gustMph: number;
31
- gustKph: number;
28
+ tempC: number | null;
29
+ tempF: number | null;
30
+ windMph: number | null;
31
+ windKph: number | null;
32
+ windDegree: number | null;
33
+ windDir: null | string;
34
+ pressureMB: number | null;
35
+ pressureIn: number | null;
36
+ precipMm: number | null;
37
+ precipIn: number | null;
38
+ feelslikeC: number | null;
39
+ feelslikeF: number | null;
40
+ visKM: number | null;
41
+ visMiles: number | null;
42
+ gustMph: number | null;
43
+ gustKph: number | null;
44
+ forecast: Forecast[];
45
+ forecastSummary: ForecastSummary;
46
+ }
47
+
48
+ interface Forecast {
49
+ date: Date | null;
50
+ condition: null | string;
51
+ maxtempC: number | null;
52
+ maxtempF: number | null;
53
+ mintempC: number | null;
54
+ mintempF: number | null;
55
+ avgtempC: number | null;
56
+ avgtempF: number | null;
57
+ maxwindMph: number | null;
58
+ maxwindKph: number | null;
59
+ avghumidity: number | null;
60
+ uv: number | null;
61
+ willItRain: number | null;
62
+ chanceOfRain: number | null;
63
+ willItSnow: number | null;
64
+ chanceOfSnow: number | null;
65
+ totalprecipMm: number | null;
66
+ totalprecipIn: number | null;
67
+ totalsnowCM: number | null;
68
+ avgvisKM: number | null;
69
+ avgvisMiles: number | null;
70
+ }
71
+
72
+ interface ForecastSummary {
73
+ rainExpectedOn: Date | null;
74
+ daysWithRain: number | null;
75
+ tempTrend: null | string;
76
+ tempTrendC: number | null;
77
+ maxChanceOfRain: number | null;
32
78
  }
33
79
 
34
- export default class weatherforecastWrapper {
35
- constructor(options: weatherforecastOptions);
36
-
37
- execute(callback: (error: any, data: weatherforecastResponse | null) => void): Promise<weatherforecastResponse>;
38
- execute(query: Record<string, any>, callback: (error: any, data: weatherforecastResponse | null) => void): Promise<weatherforecastResponse>;
39
- execute(query?: Record<string, any>): Promise<weatherforecastResponse>;
40
- }
41
- }
80
+ export default class weatherforecastWrapper {
81
+ constructor(options: weatherforecastOptions);
82
+
83
+ execute(callback: (error: any, data: weatherforecastResponse | null) => void): Promise<weatherforecastResponse>;
84
+ execute(query: Record<string, any>, callback: (error: any, data: weatherforecastResponse | null) => void): Promise<weatherforecastResponse>;
85
+ execute(query?: Record<string, any>): Promise<weatherforecastResponse>;
86
+ }
87
+ }
package/index.js CHANGED
@@ -1,209 +1,209 @@
1
- const axios = require('axios');
2
-
3
- class weatherforecastWrapper {
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/weatherforecast');
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/weatherforecast';
31
-
32
- // Validation rules for parameters (generated from schema)
33
- this.validationRules = {"city":{"type":"string","required":true}};
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/weatherforecast`);
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 = weatherforecastWrapper;
1
+ const axios = require('axios');
2
+
3
+ class weatherforecastWrapper {
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/weatherforecast');
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/weatherforecast';
31
+
32
+ // Validation rules for parameters (generated from schema)
33
+ this.validationRules = {"city":{"type":"string","required":true},"forecast":{"type":"boolean","required":false}};
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/weatherforecast`);
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 = weatherforecastWrapper;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@apiverve/weatherforecast",
3
- "version": "1.1.14",
4
- "description": "Weather is a simple tool for getting the current weather. It returns the temperature, humidity, and more for a given location.",
3
+ "version": "1.2.2",
4
+ "description": "Weather is a current weather API that reports conditions for any city name or zip code: real-time temperature and wind speed with compass direction, in both metric and imperial units. Paid plans add a 7-day forecast with daily highs, lows, rain chance and conditions for the week ahead.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "sideEffects": false,
8
8
  "engines": {
9
- "node": ">=14.0.0"
9
+ "node": ">=18.0.0"
10
10
  },
11
11
  "files": [
12
12
  "index.js",
@@ -23,7 +23,7 @@
23
23
  "directory": "npm"
24
24
  },
25
25
  "keywords": [
26
- ""
26
+ "weather api", "weather forecast api", "real time weather api", "current weather api", "weather data api"
27
27
  ],
28
28
  "author": {
29
29
  "name": "APIVerve",
@@ -34,15 +34,14 @@
34
34
  "bugs": {
35
35
  "url": "https://github.com/apiverve/weatherforecast-api/issues"
36
36
  },
37
- "homepage": "https://weatherforecast.apiverve.com?utm_source=npm&utm_medium=homepage",
37
+ "homepage": "https://apiverve.com/marketplace/weatherforecast?utm_source=npm&utm_medium=referral&utm_content=homepage",
38
38
  "devDependencies": {
39
39
  "mocha": "^11.0.1",
40
40
  "chai": "^5.1.2",
41
41
  "dotenv": "^16.4.7"
42
42
  },
43
43
  "dependencies": {
44
- "node-fetch": "^3.3.2",
45
- "promise": "^8.3.0",
46
- "axios": "1.13.2"
44
+ "axios": "1.13.2",
45
+ "form-data": "^4.0.1"
47
46
  }
48
47
  }