node-red-contrib-ipgeolocation 1.1.0 → 1.1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # node-red-contrib-ipgeolocation
2
2
 
3
- Node-RED nodes for the [IPGeolocation.io](https://ipgeolocation.io) v3 API: IP geolocation, security and threat intelligence, VPN and proxy detection, abuse contacts, ASN lookup, bulk IP processing, timezone, astronomy, and user-agent parsing.
3
+ Node-RED nodes for the [IPGeolocation.io](https://ipgeolocation.io) v3 API: IP geolocation, security and threat intelligence, VPN and proxy detection, abuse contacts, ASN lookup, bulk IP processing, time zone, astronomy, and user-agent parsing.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/node-red-contrib-ipgeolocation.svg)](https://www.npmjs.com/package/node-red-contrib-ipgeolocation)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/node-red-contrib-ipgeolocation.svg)](https://www.npmjs.com/package/node-red-contrib-ipgeolocation)
@@ -8,7 +8,7 @@
8
8
  [![Node.js](https://img.shields.io/badge/node-%3E%3D14-43853d.svg)](https://nodejs.org)
9
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
10
10
 
11
- A complete, production-ready set of **Node-RED IP geolocation nodes**. Look up the country, city, latitude, and longitude of any IP address or domain, score IPs for proxy, VPN, Tor, and bot risk, resolve ASN and abuse-contact data, parse user-agent strings, and fetch timezone and astronomy data, all from low-code Node-RED flows.
11
+ A complete, production-ready set of **Node-RED IP geolocation nodes**. Look up the country, city, latitude, and longitude of any IP address or domain, score IPs for proxy, VPN, Tor, and bot risk, resolve ASN and abuse-contact data, parse user-agent strings, and fetch time zone and astronomy data, all from low-code Node-RED flows.
12
12
 
13
13
  ---
14
14
 
@@ -35,13 +35,13 @@ A complete, production-ready set of **Node-RED IP geolocation nodes**. Look up t
35
35
 
36
36
  ## Features
37
37
 
38
- - **Single IP geolocation:** resolve country, region, city, latitude, longitude, currency, and timezone for any IPv4, IPv6, or domain.
38
+ - **Single IP geolocation:** resolve country, region, city, latitude, longitude, currency, and time zone for any IPv4, IPv6, or domain.
39
39
  - **Bulk IP geolocation:** process up to 50,000 IP addresses in one request.
40
40
  - **IP security and threat intelligence:** detect proxy, VPN, Tor, bot, and threat scores for fraud prevention and access control.
41
41
  - **Bulk security lookup:** score large IP lists in a single call.
42
42
  - **Abuse contact lookup:** retrieve the abuse email, phone, and owning organization for an IP.
43
43
  - **ASN lookup:** resolve Autonomous System details by IP or AS number.
44
- - **Time Zone API:** get timezone data by name, IP, coordinates, city, IATA code, ICAO code, or UN/LOCODE.
44
+ - **Time Zone API:** get time zone data by name, IP, coordinates, city, IATA code, ICAO code, or UN/LOCODE.
45
45
  - **Astronomy API:** sunrise, sunset, moonrise, moonset, twilight phases, moon phase, and solar and lunar positions by coordinates, address, or IP.
46
46
  - **User-agent parser:** identify browser, device, OS, and engine from a user-agent string.
47
47
  - **Developer friendly:** dynamic `msg`, `flow`, and `global` inputs, an optional dedicated error output, automatic retries with exponential backoff, secure credential storage, and per-request credit reporting.
@@ -145,7 +145,7 @@ Uncheck **Use second output** to collapse to a single output and handle failures
145
145
  | `ipgeo-bulk-security` | `POST /v3/security-bulk` | Bulk security, up to 50,000 IPs |
146
146
  | `ipgeo-abuse` | `GET /v3/abuse` | Abuse contact details |
147
147
  | `ipgeo-asn` | `GET /v3/asn` | ASN details by IP or AS number |
148
- | `ipgeo-timezone` | `GET /v3/timezone` | Timezone by name, IP, coords, city, IATA, ICAO, UN/LOCODE |
148
+ | `ipgeo-timezone` | `GET /v3/timezone` | Time zone by name, IP, coords, city, IATA, ICAO, UN/LOCODE |
149
149
  | `ipgeo-astronomy` | `GET /v3/astronomy` | Sun and moon data |
150
150
  | `ipgeo-useragent` | `GET /v3/user-agent` | User-agent parsing |
151
151
 
@@ -226,7 +226,7 @@ Seven lookup modes:
226
226
 
227
227
  | Mode | Parameter sent | Example |
228
228
  |------|----------------|---------|
229
- | Timezone name | `tz` | `America/New_York` |
229
+ | Time zone name | `tz` | `America/New_York` |
230
230
  | IP address | `ip` | `8.8.8.8` |
231
231
  | Address / city | `location` | `Paris, France` |
232
232
  | Coordinates | `lat` + `long` | `48.8566`, `2.3522` |
@@ -257,7 +257,7 @@ Optional parameters (all modes):
257
257
  |--------|-----------|-------------|
258
258
  | Date | `date` | `YYYY-MM-DD`; defaults to today at the location |
259
259
  | Time zone | `time_zone` | IANA name; converts all event times into this zone |
260
- | Elevation | `elevation` | meters above sea level, 0 to 10000; defaults to 0 |
260
+ | Elevation | `elevation` | Elevation above sea level in meters. Negative values are allowed. The maximum is 10,000 meters. Leave it blank to use the nearest known city's elevation, or 0 if no elevation data is available. |
261
261
  | Language | `lang` | language for the `location` object (paid plans) |
262
262
 
263
263
  The response nests results under an `astronomy` object alongside a `location` object, so read values such as `payload.astronomy.sunrise` and `payload.location.city`.
@@ -291,20 +291,20 @@ On failure, the node sets `msg.error` with a typed `code`, a readable `message`,
291
291
  | `NO_API_KEY` | Config node missing or key empty |
292
292
  | `BAD_REQUEST` | Invalid parameters (HTTP 400) |
293
293
  | `AUTH_FAILED` | Invalid or missing API key (HTTP 401) |
294
- | `FORBIDDEN` | Plan restriction or origin not whitelisted (HTTP 403) |
294
+ | `FORBIDDEN` | Caller's IP is not on the API key's IP allow-list (HTTP 403) |
295
295
  | `NOT_FOUND` | Endpoint or resource not found (HTTP 404) |
296
- | `VALIDATION` | Validation error (HTTP 422) |
297
296
  | `LOCKED` | Private or bogon IP address (HTTP 423). Check that the input is a valid public IP and that your application resolved the visitor's address correctly. Localhost and private-network addresses cannot be geolocated. |
298
- | `RATE_LIMITED` | Too many requests (HTTP 429) |
297
+ | `RATE_LIMITED` | No credits left (HTTP 429). The API has no per-second rate limits |
299
298
  | `SERVER_ERROR` | API internal error (HTTP 500) |
300
299
  | `HTTP_ERROR` | Any other non-2xx status |
300
+ | `REQUEST_ERROR` | Request setup failed, or a redirect to another server was blocked. |
301
301
  | `TIMEOUT` | Request timed out |
302
302
  | `NETWORK_ERROR` | DNS or connectivity failure |
303
303
  | `NO_RESPONSE` | Request sent but no response received |
304
304
  | `INVALID_INPUT` / `INVALID_MODE` | Missing or malformed node input |
305
305
  | `TOO_MANY_IPS` | Bulk request over the 50,000-IP limit |
306
306
 
307
- **Automatic retries.** Transient failures (HTTP 429, 500, 502, 503, 504, timeouts, and network errors) are retried up to 3 times with exponential backoff (500 ms, 1 s, 2 s). For HTTP 429, the `Retry-After` header is honored when present. The default request timeout is 10 seconds, and 30 seconds for the bulk endpoints.
307
+ **Automatic retries.** Transient failures (HTTP 500, 502, 503, 504, timeouts, and network errors) are retried up to 3 times with exponential backoff (500 ms, 1 s, 2 s). HTTP 429 is not retried: it means no credits are left, and a retry cannot add credits. The default request timeout is 10 seconds, and 30 seconds for the bulk endpoints.
308
308
 
309
309
  ---
310
310
 
@@ -414,7 +414,7 @@ Tests use `mocha`, `node-red-node-test-helper`, `should`, and `nock`, with all H
414
414
 
415
415
  <details>
416
416
  <summary><strong>How do I get an IPGeolocation.io API key?</strong></summary>
417
- Sign up for a free account at <code>app.ipgeolocation.io/signup</code>. The free plan covers the lookup, timezone, astronomy, and user-agent nodes, within free-plan fields and options. Bulk, security, dedicated ASN, and abuse nodes require a paid plan.
417
+ Sign up for a free account at <code>app.ipgeolocation.io/signup</code>. The free plan covers the lookup, time zone, astronomy, and user-agent nodes, within free-plan fields and options. Bulk, security, dedicated ASN, and abuse nodes require a paid plan.
418
418
  </details>
419
419
 
420
420
  <details>
@@ -438,8 +438,8 @@ Yes. List your proxies under <code>"trust proxy"</code> in <code>httpServerOptio
438
438
  </details>
439
439
 
440
440
  <details>
441
- <summary><strong>What happens when I hit a rate limit?</strong></summary>
442
- The nodes automatically retry requests using exponential backoff and honor the <code>Retry-After</code> response header when provided. If the rate limit persists, the operation fails with a <code>RATE_LIMITED</code> error on the error output.
441
+ <summary><strong>What happens when I run out of credits?</strong></summary>
442
+ The API has no per-second rate limits. It returns HTTP 429 when no credits are left: the free plan's daily credits, or a paid plan's credits with overage off or at its cap. The nodes do not retry a 429, because a retry cannot add credits. The operation fails with a <code>RATE_LIMITED</code> error on the error output.
443
443
  </details>
444
444
 
445
445
 
@@ -152,7 +152,7 @@
152
152
  <!-- Optional elevation -->
153
153
  <div class="form-row">
154
154
  <label for="node-input-elevationValue"><i class="fa fa-mountain"></i>&nbsp;Elevation</label>
155
- <input type="text" id="node-input-elevationValue" placeholder="metres, 0 to 10000 (optional)" style="width:70%"/>
155
+ <input type="text" id="node-input-elevationValue" placeholder="Elevation in meters (optional)" style="width:70%"/>
156
156
  <input type="hidden" id="node-input-elevationType"/>
157
157
  </div>
158
158
 
@@ -209,7 +209,7 @@
209
209
  <dt class="optional">Time zone <span class="property-type">string</span></dt>
210
210
  <dd>IANA name; converts event times into this zone.</dd>
211
211
  <dt class="optional">Elevation <span class="property-type">number | string</span></dt>
212
- <dd>Metres above sea level, 0 to 10000. Defaults to 0.</dd>
212
+ <dd>Elevation above sea level in meters. Negative values are allowed. The maximum is 10,000 meters. Leave it blank to use the nearest known city's elevation, or 0 if no elevation data is available.</dd>
213
213
  <dt class="optional">Language <span class="property-type">string</span></dt>
214
214
  <dd>Language for the <code>location</code> object (paid plans).</dd>
215
215
  </dl>
@@ -20,7 +20,7 @@
20
20
  * ──────────────────────────
21
21
  * date — "YYYY-MM-DD"; defaults to today at the location
22
22
  * time_zone — IANA timezone name; event times are converted to it
23
- * elevation — metres above sea level (0 to 10000); default 0
23
+ * elevation — meters above sea level, up to 10000; negatives allowed; blank = nearest known city's elevation (0 if none)
24
24
  * lang — response language for the location object (paid plans)
25
25
  *
26
26
  * Every value can be static (node config) or sourced dynamically from
@@ -67,7 +67,7 @@ module.exports = function (RED) {
67
67
  this.tzType = config.tzType || 'str';
68
68
  this.tzValue = config.tzValue || ''; // empty = API determines tz
69
69
  this.elevationType = config.elevationType || 'str';
70
- this.elevationValue = config.elevationValue || ''; // empty = API default (0)
70
+ this.elevationValue = config.elevationValue || ''; // empty = API uses the nearest known city's elevation
71
71
  this.langType = config.langType || 'str';
72
72
  this.langValue = config.langValue || ''; // empty = API default (en)
73
73
  this.outputProp = config.outputProp || 'payload';
@@ -185,7 +185,7 @@
185
185
  <li>Leave <em>IP Address</em> empty to look up the caller's IP address.</li>
186
186
  <li>
187
187
  <strong>Domain names are not accepted</strong> — only IPv4/IPv6
188
- addresses. Passing a domain returns a 401 from the API.
188
+ addresses. Passing a domain returns a 400 from the API.
189
189
  </li>
190
190
  <li>Every successful lookup costs a flat <strong>2 credits</strong>, regardless of fields/excludes used.</li>
191
191
  <li>
@@ -198,7 +198,7 @@
198
198
  top-level <code>ip</code> field is always present and cannot be excluded.
199
199
  </li>
200
200
  <li>
201
- Bogon/private/malformed IPs are rejected with HTTP 423 and are not billed.
201
+ Bogon and private IPs are rejected with HTTP 423, malformed IPs with HTTP 400. Neither is billed.
202
202
  </li>
203
203
  <li>Failed requests are retried up to 3 times with exponential back-off.</li>
204
204
  </ul>
@@ -8,7 +8,6 @@
8
8
  * • Single Axios instance with base URL and sensible timeouts
9
9
  * • Exponential-backoff retry for transient errors (5xx, ECONNRESET, ETIMEDOUT)
10
10
  * • Structured error objects that every node can map to Node-RED status/done(err)
11
- * • Rate-limit awareness (HTTP 429 → honour Retry-After header when present)
12
11
  * • Credit-charge extraction from response headers
13
12
  */
14
13
 
@@ -23,8 +22,9 @@ const DEFAULT_TIMEOUT = 10_000; // 10 s
23
22
  const MAX_RETRIES = 3;
24
23
  const RETRY_DELAY_MS = 500; // base delay; doubles each attempt
25
24
 
26
- // HTTP status codes that are safe to retry (server-side transient faults)
27
- const RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);
25
+ // HTTP status codes that are safe to retry (server-side transient faults).
26
+ // 429 is not one: it means no credits are left, and a retry cannot add credits.
27
+ const RETRYABLE_STATUS = new Set([500, 502, 503, 504]);
28
28
 
29
29
  // ─── Error Classes ───────────────────────────────────────────────────────────
30
30
 
@@ -60,6 +60,10 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
60
60
  * @returns {IPGeoError}
61
61
  */
62
62
  function mapAxiosError(err) {
63
+ if (err.code === 'ERR_FR_REDIRECTION_FAILURE') {
64
+ return new IPGeoError('Request redirect was blocked.', 'REQUEST_ERROR');
65
+ }
66
+
63
67
  if (err.response) {
64
68
  const { status, data } = err.response;
65
69
  const apiMsg = (data && (data.message || data.error)) || '';
@@ -70,7 +74,7 @@ function mapAxiosError(err) {
70
74
  case 401: return new IPGeoError(
71
75
  `Authentication failed: ${apiMsg || 'Invalid or missing API key'}`, 'AUTH_FAILED', 401, data);
72
76
  case 403: return new IPGeoError(
73
- `Forbidden: ${apiMsg || 'Access denied (check plan limits or IP whitelist)'}`, 'FORBIDDEN', 403, data);
77
+ `Forbidden: ${apiMsg || "This server's IP is not on the API key's IP allow-list"}`, 'FORBIDDEN', 403, data);
74
78
  case 404: return new IPGeoError(
75
79
  `Resource not found: ${apiMsg || 'Endpoint does not exist'}`, 'NOT_FOUND', 404, data);
76
80
  case 422: return new IPGeoError(
@@ -78,7 +82,7 @@ function mapAxiosError(err) {
78
82
  case 423: return new IPGeoError(
79
83
  `Private or bogon IP address: ${apiMsg || 'Localhost and private-network addresses cannot be geolocated'}`, 'LOCKED', 423, data);
80
84
  case 429: return new IPGeoError(
81
- `Rate limit exceeded: ${apiMsg || 'Too many requests'}`, 'RATE_LIMITED', 429, data);
85
+ `No credits left: ${apiMsg || "the free plan's daily credits, or a paid plan's credits with overage off or at its cap"}`, 'RATE_LIMITED', 429, data);
82
86
  case 500: return new IPGeoError(
83
87
  `API server error (500): ${apiMsg || 'Internal server error'}`, 'SERVER_ERROR', 500, data);
84
88
  default: return new IPGeoError(
@@ -147,6 +151,12 @@ async function request(options) {
147
151
  ...headers,
148
152
  },
149
153
  timeout,
154
+ beforeRedirect: (_options, response, previous) => {
155
+ const destination = new URL(response.headers.location, previous.url);
156
+ if (destination.origin !== new URL(url).origin) {
157
+ throw new Error('Request redirect was blocked.');
158
+ }
159
+ },
150
160
  validateStatus: null, // We handle all status codes ourselves
151
161
  });
152
162
 
@@ -160,15 +170,7 @@ async function request(options) {
160
170
 
161
171
  // Handle retryable server-side errors
162
172
  if (RETRYABLE_STATUS.has(response.status) && attempt < maxRetries) {
163
- let delay = RETRY_DELAY_MS * Math.pow(2, attempt);
164
-
165
- // Honour Retry-After header for 429 responses
166
- if (response.status === 429) {
167
- const retryAfter = response.headers['retry-after'];
168
- if (retryAfter) {
169
- delay = Math.max(delay, Number(retryAfter) * 1000);
170
- }
171
- }
173
+ const delay = RETRY_DELAY_MS * Math.pow(2, attempt);
172
174
 
173
175
  attempt++;
174
176
  await sleep(delay);
@@ -22,7 +22,7 @@ const STATUS = {
22
22
  OK: { fill: 'green', shape: 'dot', text: 'ok' },
23
23
  ERROR: { fill: 'red', shape: 'ring', text: 'error' },
24
24
  NO_KEY: { fill: 'red', shape: 'ring', text: 'no API key' },
25
- RATE_LIM: { fill: 'yellow', shape: 'ring', text: 'rate limited' },
25
+ RATE_LIM: { fill: 'yellow', shape: 'ring', text: 'no credits left' },
26
26
  };
27
27
 
28
28
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-ipgeolocation",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Node-RED nodes for the IPGeolocation.io v3 API: IP geolocation, security and threat intelligence (VPN, proxy, and TOR detection), abuse contacts, ASN lookup, bulk IP processing, timezone, astronomy, and user-agent parsing.",
5
5
  "keywords": [
6
6
  "node-red",
@@ -47,10 +47,10 @@
47
47
  "axios": "^1.21.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@node-red/editor-client": "^4.1.17",
50
+ "@node-red/editor-client": "^4.1.18",
51
51
  "mocha": "^12.0.2",
52
52
  "nock": "^13.5.6",
53
- "node-red": "^4.1.17",
53
+ "node-red": "^4.1.18",
54
54
  "node-red-node-test-helper": "^0.3.6",
55
55
  "nyc": "^18.0.0",
56
56
  "should": "^13.2.3",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "overrides": {
76
76
  "@node-red/registry": {
77
- "npm": "^11.21.1"
77
+ "npm": "11.21.2"
78
78
  },
79
79
  "multer": "^2.5.0",
80
80
  "express": "^4.22.3",