@apiverve/earthquake 1.1.9 → 1.1.12

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
- Worldwide Earthquakes API
2
- ============
1
+ # Worldwide Earthquakes API
3
2
 
4
3
  Earthquake is a simple tool for getting earthquake data. It returns the earthquake data for the past hour.
5
4
 
@@ -7,52 +6,60 @@ Earthquake is a simple tool for getting earthquake data. It returns the earthqua
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 [Worldwide Earthquakes API](https://apiverve.com/marketplace/api/earthquake)
9
+ This is a Javascript Wrapper for the [Worldwide Earthquakes API](https://apiverve.com/marketplace/earthquake)
11
10
 
12
11
  ---
13
12
 
14
13
  ## Installation
15
- npm install @apiverve/earthquake --save
14
+
15
+ Using npm:
16
+ ```shell
17
+ npm install @apiverve/earthquake
18
+ ```
19
+
20
+ Using yarn:
21
+ ```shell
22
+ yarn add @apiverve/earthquake
23
+ ```
16
24
 
17
25
  ---
18
26
 
19
27
  ## Configuration
20
28
 
21
- Before using the earthquake API client, you have to setup your account and obtain your API Key.
29
+ Before using the Worldwide Earthquakes 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
27
35
 
28
- The Worldwide Earthquakes API documentation is found here: [https://docs.apiverve.com/api/earthquake](https://docs.apiverve.com/api/earthquake).
36
+ [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
37
+
38
+ The Worldwide Earthquakes API documentation is found here: [https://docs.apiverve.com/ref/earthquake](https://docs.apiverve.com/ref/earthquake).
29
39
  You can find parameters, example responses, and status codes documented here.
30
40
 
31
41
  ### Setup
32
42
 
33
- ```
34
- var earthquakeAPI = require('@apiverve/earthquake');
35
- var api = new earthquakeAPI({
36
- api_key: [YOUR_API_KEY],
37
- secure: true //(Optional, defaults to true)
43
+ ```javascript
44
+ const earthquakeAPI = require('@apiverve/earthquake');
45
+ const api = new earthquakeAPI({
46
+ api_key: '[YOUR_API_KEY]'
38
47
  });
39
48
  ```
40
49
 
41
50
  ---
42
51
 
52
+ ## Usage
43
53
 
44
- ### Perform Request
45
- Using the API client, you can perform requests to the API.
54
+ ---
46
55
 
47
- ###### Define Query
56
+ ### Perform Request
48
57
 
49
- ```
50
- This API does not require a Query
51
- ```
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.
52
59
 
53
- ###### Simple Request (using Callback)
60
+ ```javascript
61
+ // This API does not require a Query
54
62
 
55
- ```
56
63
  api.execute(function (error, data) {
57
64
  if (error) {
58
65
  return console.error(error);
@@ -62,286 +69,324 @@ api.execute(function (error, data) {
62
69
  });
63
70
  ```
64
71
 
65
- ###### Example Response
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.
66
77
 
78
+ ```javascript
79
+ // This API does not require a Query
80
+
81
+ api.execute(query)
82
+ .then(data => {
83
+ console.log(data);
84
+ })
85
+ .catch(error => {
86
+ console.error(error);
87
+ });
88
+ ```
89
+
90
+ ---
91
+
92
+ ### Using Async/Await
93
+
94
+ You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
95
+
96
+ ```javascript
97
+ async function makeRequest() {
98
+ // This API does not require a Query
99
+
100
+ try {
101
+ const data = await api.execute(query);
102
+ console.log(data);
103
+ } catch (error) {
104
+ console.error(error);
105
+ }
106
+ }
67
107
  ```
68
- {
69
- "status": "ok",
70
- "error": null,
71
- "data": {
72
- "earthquakes_LastUpdated": 1740085202,
73
- "earthquakes_LastHour": 13,
74
- "earthquakes": [
75
- {
76
- "mag": 1.63,
77
- "place": "4 km SSW of Home Gardens, CA",
78
- "time": 1740084740320,
79
- "status": "automatic",
80
- "tsunami": 0,
81
- "sig": 41,
82
- "net": "ci",
83
- "types": ",nearby-cities,origin,phase-data,scitech-link,",
84
- "nst": 30,
85
- "dmin": 0.07665,
86
- "rms": 0.16,
87
- "gap": 212,
88
- "magType": "ml",
89
- "type": "earthquake",
90
- "title": "M 1.6 - 4 km SSW of Home Gardens, CA",
91
- "coordinates": [
92
- -117.5313333,
93
- 33.8441667
94
- ]
95
- },
96
- {
97
- "mag": 1.53,
98
- "place": "3 km of The Geysers, CA",
99
- "time": 1740084398050,
100
- "status": "automatic",
101
- "tsunami": 0,
102
- "sig": 36,
103
- "net": "nc",
104
- "types": ",focal-mechanism,nearby-cities,origin,phase-data,",
105
- "nst": 31,
106
- "dmin": 0.01013,
107
- "rms": 0.04,
108
- "gap": 61,
109
- "magType": "md",
110
- "type": "earthquake",
111
- "title": "M 1.5 - 3 km of The Geysers, CA",
112
- "coordinates": [
113
- -122.770835876465,
114
- 38.8066673278809
115
- ]
116
- },
117
- {
118
- "mag": 1.5,
119
- "place": "36 km SSW of Los Ybanez, Texas",
120
- "time": 1740083760065,
121
- "status": "automatic",
122
- "tsunami": 0,
123
- "sig": 35,
124
- "net": "tx",
125
- "types": ",origin,phase-data,",
126
- "nst": 21,
127
- "dmin": 0,
128
- "rms": 0.5,
129
- "gap": 98,
130
- "magType": "ml",
131
- "type": "earthquake",
132
- "title": "M 1.5 - 36 km SSW of Los Ybanez, Texas",
133
- "coordinates": [
134
- -102.118,
135
- 32.437
136
- ]
137
- },
138
- {
139
- "mag": 1.28,
140
- "place": "2 km NNE of Rancho San Diego, CA",
141
- "time": 1740083416660,
142
- "status": "automatic",
143
- "tsunami": 0,
144
- "sig": 25,
145
- "net": "ci",
146
- "types": ",nearby-cities,origin,phase-data,scitech-link,",
147
- "nst": 18,
148
- "dmin": 0.02613,
149
- "rms": 0.18,
150
- "gap": 117,
151
- "magType": "ml",
152
- "type": "earthquake",
153
- "title": "M 1.3 - 2 km NNE of Rancho San Diego, CA",
154
- "coordinates": [
155
- -116.9288333,
156
- 32.7591667
157
- ]
158
- },
159
- {
160
- "mag": 1.3,
161
- "place": "2 km N of The Geysers, CA",
162
- "time": 1740083145550,
163
- "status": "automatic",
164
- "tsunami": 0,
165
- "sig": 26,
166
- "net": "nc",
167
- "types": ",nearby-cities,origin,phase-data,",
168
- "nst": 17,
169
- "dmin": 0.008002,
170
- "rms": 0.02,
171
- "gap": 75,
172
- "magType": "md",
173
- "type": "earthquake",
174
- "title": "M 1.3 - 2 km N of The Geysers, CA",
175
- "coordinates": [
176
- -122.758499145508,
177
- 38.792667388916
178
- ]
179
- },
180
- {
181
- "mag": 2.03,
182
- "place": "23 km NE of San Ardo, CA",
183
- "time": 1740083087170,
184
- "status": "automatic",
185
- "tsunami": 0,
186
- "sig": 63,
187
- "net": "nc",
188
- "types": ",nearby-cities,origin,phase-data,",
189
- "nst": 24,
190
- "dmin": 0.04482,
191
- "rms": 0.08,
192
- "gap": 78,
193
- "magType": "md",
194
- "type": "earthquake",
195
- "title": "M 2.0 - 23 km NE of San Ardo, CA",
196
- "coordinates": [
197
- -120.757835388184,
198
- 36.1879997253418
199
- ]
200
- },
201
- {
202
- "mag": 1.5,
203
- "place": "18 km N of Nellis Air Force Base, Nevada",
204
- "time": 1740082632669,
205
- "status": "automatic",
206
- "tsunami": 0,
207
- "sig": 35,
208
- "net": "nn",
209
- "types": ",origin,phase-data,",
210
- "nst": 12,
211
- "dmin": 0.142,
212
- "rms": 0.352,
213
- "gap": 324.6699999999999,
214
- "magType": "ml",
215
- "type": "earthquake",
216
- "title": "M 1.5 - 18 km N of Nellis Air Force Base, Nevada",
217
- "coordinates": [
218
- -115.0204,
219
- 36.4137
220
- ]
221
- },
222
- {
223
- "mag": 2.4,
224
- "place": "42 km ENE of Susitna North, Alaska",
225
- "time": 1740082487421,
226
- "status": "automatic",
227
- "tsunami": 0,
228
- "sig": 89,
229
- "net": "ak",
230
- "types": ",origin,phase-data,",
231
- "rms": 0.58,
232
- "magType": "ml",
233
- "type": "earthquake",
234
- "title": "M 2.4 - 42 km ENE of Susitna North, Alaska",
235
- "coordinates": [
236
- -149.1448,
237
- 62.358
238
- ]
239
- },
240
- {
241
- "mag": 0.58,
242
- "place": "0 km of The Geysers, CA",
243
- "time": 1740082396860,
244
- "status": "automatic",
245
- "tsunami": 0,
246
- "sig": 5,
247
- "net": "nc",
248
- "types": ",nearby-cities,origin,phase-data,",
249
- "nst": 8,
250
- "dmin": 0.01016,
251
- "rms": 0.04,
252
- "gap": 122,
253
- "magType": "md",
254
- "type": "earthquake",
255
- "title": "M 0.6 - 0 km of The Geysers, CA",
256
- "coordinates": [
257
- -122.75666809082,
258
- 38.7779998779297
259
- ]
260
- },
261
- {
262
- "mag": 0.77,
263
- "place": "4 km NNW of The Geysers, CA",
264
- "time": 1740082221410,
265
- "status": "automatic",
266
- "tsunami": 0,
267
- "sig": 9,
268
- "net": "nc",
269
- "types": ",nearby-cities,origin,phase-data,",
270
- "nst": 7,
271
- "dmin": 0.006593,
272
- "rms": 0.01,
273
- "gap": 141,
274
- "magType": "md",
275
- "type": "earthquake",
276
- "title": "M 0.8 - 4 km NNW of The Geysers, CA",
277
- "coordinates": [
278
- -122.78116607666,
279
- 38.8066673278809
280
- ]
281
- },
282
- {
283
- "mag": 0.76,
284
- "place": "9 km NW of The Geysers, CA",
285
- "time": 1740082075350,
286
- "status": "automatic",
287
- "tsunami": 0,
288
- "sig": 9,
289
- "net": "nc",
290
- "types": ",nearby-cities,origin,phase-data,",
291
- "nst": 12,
292
- "dmin": 0.005851,
293
- "rms": 0.02,
294
- "gap": 80,
295
- "magType": "md",
296
- "type": "earthquake",
297
- "title": "M 0.8 - 9 km NW of The Geysers, CA",
298
- "coordinates": [
299
- -122.842498779297,
300
- 38.8226661682129
301
- ]
302
- },
303
- {
304
- "mag": 1.8,
305
- "place": "47 km ENE of Susitna North, Alaska",
306
- "time": 1740081957855,
307
- "status": "automatic",
308
- "tsunami": 0,
309
- "sig": 50,
310
- "net": "ak",
311
- "types": ",origin,phase-data,",
312
- "rms": 0.79,
313
- "magType": "ml",
314
- "type": "earthquake",
315
- "title": "M 1.8 - 47 km ENE of Susitna North, Alaska",
316
- "coordinates": [
317
- -149.0437,
318
- 62.3668
319
- ]
320
- },
321
- {
322
- "mag": 3.14,
323
- "place": "73 km N of Brenas, Puerto Rico",
324
- "time": 1740081663500,
325
- "status": "reviewed",
326
- "tsunami": 0,
327
- "sig": 152,
328
- "net": "pr",
329
- "types": ",origin,phase-data,",
330
- "nst": 10,
331
- "dmin": 0.8083,
332
- "rms": 0.23,
333
- "gap": 271,
334
- "magType": "md",
335
- "type": "earthquake",
336
- "title": "M 3.1 - 73 km N of Brenas, Puerto Rico",
337
- "coordinates": [
338
- -66.3835,
339
- 19.1311666666667
340
- ]
341
- }
342
- ]
343
- },
344
- "code": 200
108
+
109
+ ---
110
+
111
+ ## Example Response
112
+
113
+ ```json
114
+ {
115
+ "status": "ok",
116
+ "error": null,
117
+ "data": {
118
+ "earthquakes_LastUpdated": 1740085202,
119
+ "earthquakes_LastHour": 13,
120
+ "earthquakes": [
121
+ {
122
+ "mag": 1.63,
123
+ "place": "4 km SSW of Home Gardens, CA",
124
+ "time": 1740084740320,
125
+ "status": "automatic",
126
+ "tsunami": 0,
127
+ "sig": 41,
128
+ "net": "ci",
129
+ "types": ",nearby-cities,origin,phase-data,scitech-link,",
130
+ "nst": 30,
131
+ "dmin": 0.07665,
132
+ "rms": 0.16,
133
+ "gap": 212,
134
+ "magType": "ml",
135
+ "type": "earthquake",
136
+ "title": "M 1.6 - 4 km SSW of Home Gardens, CA",
137
+ "coordinates": [
138
+ -117.5313333,
139
+ 33.8441667
140
+ ]
141
+ },
142
+ {
143
+ "mag": 1.53,
144
+ "place": "3 km of The Geysers, CA",
145
+ "time": 1740084398050,
146
+ "status": "automatic",
147
+ "tsunami": 0,
148
+ "sig": 36,
149
+ "net": "nc",
150
+ "types": ",focal-mechanism,nearby-cities,origin,phase-data,",
151
+ "nst": 31,
152
+ "dmin": 0.01013,
153
+ "rms": 0.04,
154
+ "gap": 61,
155
+ "magType": "md",
156
+ "type": "earthquake",
157
+ "title": "M 1.5 - 3 km of The Geysers, CA",
158
+ "coordinates": [
159
+ -122.770835876465,
160
+ 38.8066673278809
161
+ ]
162
+ },
163
+ {
164
+ "mag": 1.5,
165
+ "place": "36 km SSW of Los Ybanez, Texas",
166
+ "time": 1740083760065,
167
+ "status": "automatic",
168
+ "tsunami": 0,
169
+ "sig": 35,
170
+ "net": "tx",
171
+ "types": ",origin,phase-data,",
172
+ "nst": 21,
173
+ "dmin": 0,
174
+ "rms": 0.5,
175
+ "gap": 98,
176
+ "magType": "ml",
177
+ "type": "earthquake",
178
+ "title": "M 1.5 - 36 km SSW of Los Ybanez, Texas",
179
+ "coordinates": [
180
+ -102.118,
181
+ 32.437
182
+ ]
183
+ },
184
+ {
185
+ "mag": 1.28,
186
+ "place": "2 km NNE of Rancho San Diego, CA",
187
+ "time": 1740083416660,
188
+ "status": "automatic",
189
+ "tsunami": 0,
190
+ "sig": 25,
191
+ "net": "ci",
192
+ "types": ",nearby-cities,origin,phase-data,scitech-link,",
193
+ "nst": 18,
194
+ "dmin": 0.02613,
195
+ "rms": 0.18,
196
+ "gap": 117,
197
+ "magType": "ml",
198
+ "type": "earthquake",
199
+ "title": "M 1.3 - 2 km NNE of Rancho San Diego, CA",
200
+ "coordinates": [
201
+ -116.9288333,
202
+ 32.7591667
203
+ ]
204
+ },
205
+ {
206
+ "mag": 1.3,
207
+ "place": "2 km N of The Geysers, CA",
208
+ "time": 1740083145550,
209
+ "status": "automatic",
210
+ "tsunami": 0,
211
+ "sig": 26,
212
+ "net": "nc",
213
+ "types": ",nearby-cities,origin,phase-data,",
214
+ "nst": 17,
215
+ "dmin": 0.008002,
216
+ "rms": 0.02,
217
+ "gap": 75,
218
+ "magType": "md",
219
+ "type": "earthquake",
220
+ "title": "M 1.3 - 2 km N of The Geysers, CA",
221
+ "coordinates": [
222
+ -122.758499145508,
223
+ 38.792667388916
224
+ ]
225
+ },
226
+ {
227
+ "mag": 2.03,
228
+ "place": "23 km NE of San Ardo, CA",
229
+ "time": 1740083087170,
230
+ "status": "automatic",
231
+ "tsunami": 0,
232
+ "sig": 63,
233
+ "net": "nc",
234
+ "types": ",nearby-cities,origin,phase-data,",
235
+ "nst": 24,
236
+ "dmin": 0.04482,
237
+ "rms": 0.08,
238
+ "gap": 78,
239
+ "magType": "md",
240
+ "type": "earthquake",
241
+ "title": "M 2.0 - 23 km NE of San Ardo, CA",
242
+ "coordinates": [
243
+ -120.757835388184,
244
+ 36.1879997253418
245
+ ]
246
+ },
247
+ {
248
+ "mag": 1.5,
249
+ "place": "18 km N of Nellis Air Force Base, Nevada",
250
+ "time": 1740082632669,
251
+ "status": "automatic",
252
+ "tsunami": 0,
253
+ "sig": 35,
254
+ "net": "nn",
255
+ "types": ",origin,phase-data,",
256
+ "nst": 12,
257
+ "dmin": 0.142,
258
+ "rms": 0.352,
259
+ "gap": 324.6699999999999,
260
+ "magType": "ml",
261
+ "type": "earthquake",
262
+ "title": "M 1.5 - 18 km N of Nellis Air Force Base, Nevada",
263
+ "coordinates": [
264
+ -115.0204,
265
+ 36.4137
266
+ ]
267
+ },
268
+ {
269
+ "mag": 2.4,
270
+ "place": "42 km ENE of Susitna North, Alaska",
271
+ "time": 1740082487421,
272
+ "status": "automatic",
273
+ "tsunami": 0,
274
+ "sig": 89,
275
+ "net": "ak",
276
+ "types": ",origin,phase-data,",
277
+ "rms": 0.58,
278
+ "magType": "ml",
279
+ "type": "earthquake",
280
+ "title": "M 2.4 - 42 km ENE of Susitna North, Alaska",
281
+ "coordinates": [
282
+ -149.1448,
283
+ 62.358
284
+ ]
285
+ },
286
+ {
287
+ "mag": 0.58,
288
+ "place": "0 km of The Geysers, CA",
289
+ "time": 1740082396860,
290
+ "status": "automatic",
291
+ "tsunami": 0,
292
+ "sig": 5,
293
+ "net": "nc",
294
+ "types": ",nearby-cities,origin,phase-data,",
295
+ "nst": 8,
296
+ "dmin": 0.01016,
297
+ "rms": 0.04,
298
+ "gap": 122,
299
+ "magType": "md",
300
+ "type": "earthquake",
301
+ "title": "M 0.6 - 0 km of The Geysers, CA",
302
+ "coordinates": [
303
+ -122.75666809082,
304
+ 38.7779998779297
305
+ ]
306
+ },
307
+ {
308
+ "mag": 0.77,
309
+ "place": "4 km NNW of The Geysers, CA",
310
+ "time": 1740082221410,
311
+ "status": "automatic",
312
+ "tsunami": 0,
313
+ "sig": 9,
314
+ "net": "nc",
315
+ "types": ",nearby-cities,origin,phase-data,",
316
+ "nst": 7,
317
+ "dmin": 0.006593,
318
+ "rms": 0.01,
319
+ "gap": 141,
320
+ "magType": "md",
321
+ "type": "earthquake",
322
+ "title": "M 0.8 - 4 km NNW of The Geysers, CA",
323
+ "coordinates": [
324
+ -122.78116607666,
325
+ 38.8066673278809
326
+ ]
327
+ },
328
+ {
329
+ "mag": 0.76,
330
+ "place": "9 km NW of The Geysers, CA",
331
+ "time": 1740082075350,
332
+ "status": "automatic",
333
+ "tsunami": 0,
334
+ "sig": 9,
335
+ "net": "nc",
336
+ "types": ",nearby-cities,origin,phase-data,",
337
+ "nst": 12,
338
+ "dmin": 0.005851,
339
+ "rms": 0.02,
340
+ "gap": 80,
341
+ "magType": "md",
342
+ "type": "earthquake",
343
+ "title": "M 0.8 - 9 km NW of The Geysers, CA",
344
+ "coordinates": [
345
+ -122.842498779297,
346
+ 38.8226661682129
347
+ ]
348
+ },
349
+ {
350
+ "mag": 1.8,
351
+ "place": "47 km ENE of Susitna North, Alaska",
352
+ "time": 1740081957855,
353
+ "status": "automatic",
354
+ "tsunami": 0,
355
+ "sig": 50,
356
+ "net": "ak",
357
+ "types": ",origin,phase-data,",
358
+ "rms": 0.79,
359
+ "magType": "ml",
360
+ "type": "earthquake",
361
+ "title": "M 1.8 - 47 km ENE of Susitna North, Alaska",
362
+ "coordinates": [
363
+ -149.0437,
364
+ 62.3668
365
+ ]
366
+ },
367
+ {
368
+ "mag": 3.14,
369
+ "place": "73 km N of Brenas, Puerto Rico",
370
+ "time": 1740081663500,
371
+ "status": "reviewed",
372
+ "tsunami": 0,
373
+ "sig": 152,
374
+ "net": "pr",
375
+ "types": ",origin,phase-data,",
376
+ "nst": 10,
377
+ "dmin": 0.8083,
378
+ "rms": 0.23,
379
+ "gap": 271,
380
+ "magType": "md",
381
+ "type": "earthquake",
382
+ "title": "M 3.1 - 73 km N of Brenas, Puerto Rico",
383
+ "coordinates": [
384
+ -66.3835,
385
+ 19.1311666666667
386
+ ]
387
+ }
388
+ ]
389
+ }
345
390
  }
346
391
  ```
347
392
 
@@ -354,6 +399,7 @@ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/c
354
399
  ---
355
400
 
356
401
  ## Updates
402
+
357
403
  Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
358
404
 
359
405
  ---
@@ -373,4 +419,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
373
419
 
374
420
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
375
421
 
376
- 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.
422
+ 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,36 @@
1
+ /**
2
+ * Basic Example - Worldwide Earthquakes API
3
+ *
4
+ * This example demonstrates how to use the Worldwide Earthquakes 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 earthquakeAPI = require('../index.js');
10
+
11
+ // Initialize the API client
12
+ const api = new earthquakeAPI({
13
+ api_key: process.env.API_KEY || '[YOUR_API_KEY]'
14
+ });
15
+
16
+ // Example query
17
+ // This API does not require a Query
18
+
19
+ // Make the API request using callback
20
+ console.log('Making request to Worldwide Earthquakes API...\n');
21
+
22
+ api.execute(function (error, data) {
23
+ if (error) {
24
+ console.error('Error occurred:');
25
+ if (error.error) {
26
+ console.error('Message:', error.error);
27
+ console.error('Status:', error.status);
28
+ } else {
29
+ console.error(JSON.stringify(error, null, 2));
30
+ }
31
+ return;
32
+ }
33
+
34
+ console.log('Response:');
35
+ console.log(JSON.stringify(data, null, 2));
36
+ });
package/index.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ declare module '@apiverve/earthquake' {
2
+ export interface earthquakeOptions {
3
+ api_key: string;
4
+ secure?: boolean;
5
+ }
6
+
7
+ export interface earthquakeResponse {
8
+ status: string;
9
+ error: string | null;
10
+ data: WorldwideEarthquakesData;
11
+ code?: number;
12
+ }
13
+
14
+
15
+ interface WorldwideEarthquakesData {
16
+ earthquakesLastUpdated: number;
17
+ earthquakesLastHour: number;
18
+ earthquakes: Earthquake[];
19
+ }
20
+
21
+ interface Earthquake {
22
+ mag: number;
23
+ place: string;
24
+ time: number;
25
+ status: Status;
26
+ tsunami: number;
27
+ sig: number;
28
+ net: string;
29
+ types: string;
30
+ nst?: number;
31
+ dmin?: number;
32
+ rms: number;
33
+ gap?: number;
34
+ magType: MagType;
35
+ type: Type;
36
+ title: string;
37
+ coordinates: number[];
38
+ }
39
+
40
+ enum MagType {
41
+ Md = "md",
42
+ Ml = "ml",
43
+ }
44
+
45
+ enum Status {
46
+ Automatic = "automatic",
47
+ Reviewed = "reviewed",
48
+ }
49
+
50
+ enum Type {
51
+ Earthquake = "earthquake",
52
+ }
53
+
54
+ export default class earthquakeWrapper {
55
+ constructor(options: earthquakeOptions);
56
+
57
+ execute(callback: (error: any, data: earthquakeResponse | null) => void): Promise<earthquakeResponse>;
58
+ execute(query: Record<string, any>, callback: (error: any, data: earthquakeResponse | null) => void): Promise<earthquakeResponse>;
59
+ execute(query?: Record<string, any>): Promise<earthquakeResponse>;
60
+ }
61
+ }
package/index.js CHANGED
@@ -4,14 +4,27 @@ class earthquakeWrapper {
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/earthquake');
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 earthquakeWrapper {
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
61
  var requiredParams = [];
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/earthquake`);
41
66
  }
42
67
  }
43
68
  }
@@ -58,16 +83,25 @@ class earthquakeWrapper {
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,27 @@
1
1
  {
2
2
  "name": "@apiverve/earthquake",
3
- "version": "1.1.9",
3
+ "version": "1.1.12",
4
4
  "description": "Earthquake is a simple tool for getting earthquake data. It returns the earthquake data for the past hour.",
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
- "url": "git+https://github.com/apiverve/earthquake-API.git"
13
+ "url": "git+https://github.com/apiverve/earthquake-api.git",
14
+ "directory": "npm"
12
15
  },
13
16
  "keywords": [
14
- "earthquake","earthquake api","earthquake tool","earthquake software","earthquake service"
17
+ "earthquake", "earthquake api", "earthquake tool", "earthquake software", "earthquake service"
15
18
  ],
16
19
  "author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
17
20
  "license": "MIT",
18
21
  "bugs": {
19
- "url": "https://github.com/apiverve/earthquake-API/issues"
22
+ "url": "https://github.com/apiverve/earthquake-api/issues"
20
23
  },
21
- "homepage": "https://apiverve.com/marketplace/api/earthquake?utm_source=npm",
24
+ "homepage": "https://apiverve.com/marketplace/earthquake?utm_source=npm",
22
25
  "devDependencies": {
23
26
  "mocha": "^11.0.1",
24
27
  "chai": "^5.1.2",
@@ -27,6 +30,6 @@
27
30
  "dependencies": {
28
31
  "node-fetch": "^3.3.2",
29
32
  "promise": "^8.3.0",
30
- "axios": "1.7.9"
33
+ "axios": "1.13.2"
31
34
  }
32
35
  }