node-red-contrib-ipgeolocation 1.0.2 → 1.1.1

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` |
@@ -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
 
@@ -340,7 +340,33 @@ return msg;
340
340
 
341
341
  ### Geolocate the visitor in an HTTP flow
342
342
 
343
- Configure `ipgeo-lookup` with **IP / Domain** as a `msg` property pointing at `req.headers['x-forwarded-for']` (behind a proxy) or `req.connection.remoteAddress` (direct).
343
+ Give `ipgeo-lookup` one validated client IP. Do not map the raw `req.headers['x-forwarded-for']` chain: the node sends it as one value, for example `203.0.113.7, 10.0.0.2`, and any entry your own proxies did not add is whatever the client sent. Never let the input be empty either, because the API then looks up the caller's IP, which is your Node-RED server.
344
+
345
+ Read the address from `msg.req.ip`. The **http in** node runs on Express, which sets `msg.req.ip` to a single address:
346
+
347
+ - **Direct connection:** with the default settings, `msg.req.ip` is the socket's remote address.
348
+ - **Behind a reverse proxy:** list your proxies under `httpServerOptions` in Node-RED's `settings.js`. Express then reads `X-Forwarded-For` from right to left, skips the trusted proxies, and uses the first address it does not trust. Do not set `"trust proxy": true`, which trusts every entry, including ones the client wrote.
349
+
350
+ ```javascript
351
+ // settings.js: nginx on the same host as Node-RED, behind a load balancer at 10.0.0.2
352
+ httpServerOptions: {
353
+ "trust proxy": ["loopback", "10.0.0.2"],
354
+ },
355
+ ```
356
+
357
+ Add a Function node with two outputs between **http in** and `ipgeo-lookup`. Wire output 1 to `ipgeo-lookup` and output 2 to a fallback such as an **http response**, then set **IP / Domain** to the `msg` property `ipgeo_ip`:
358
+
359
+ ```javascript
360
+ let ip = msg.req.ip || "";
361
+ if (ip.startsWith("::ffff:")) ip = ip.slice(7); // IPv4 client on a dual-stack listener
362
+ if (!/^(\d{1,3}\.){3}\d{1,3}$|^[0-9a-f]*:[0-9a-f:.]+$/i.test(ip)) {
363
+ return [null, msg]; // not one IP address; an empty value would look up your server's IP
364
+ }
365
+ msg.ipgeo_ip = ip;
366
+ return [msg, null];
367
+ ```
368
+
369
+ If your proxy instead overwrites a dedicated header with the client address, for example nginx `proxy_set_header X-Real-IP $remote_addr;`, read `msg.req.headers['x-real-ip']` in the first line. Do this only when clients cannot reach Node-RED without passing through that proxy.
344
370
 
345
371
  ### Block proxies and VPNs at the edge
346
372
 
@@ -388,7 +414,7 @@ Tests use `mocha`, `node-red-node-test-helper`, `should`, and `nock`, with all H
388
414
 
389
415
  <details>
390
416
  <summary><strong>How do I get an IPGeolocation.io API key?</strong></summary>
391
- 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.
392
418
  </details>
393
419
 
394
420
  <details>
@@ -408,12 +434,12 @@ Use the <code>ipgeo-security</code> node, or enable the <code>security</code> in
408
434
 
409
435
  <details>
410
436
  <summary><strong>Does it work behind a reverse proxy?</strong></summary>
411
- Yes. Read the client IP address from <code>req.headers['x-forwarded-for']</code> and pass it to <code>ipgeo-lookup</code> as a dynamic <code>msg</code> input to geolocate the original client.
437
+ Yes. List your proxies under <code>"trust proxy"</code> in <code>httpServerOptions</code> in Node-RED's <code>settings.js</code>. Express then sets <code>msg.req.ip</code> to one client address selected through those trusted proxies; check it in a Function node and pass it to <code>ipgeo-lookup</code> as a dynamic <code>msg</code> input. Do not pass the raw <code>X-Forwarded-For</code> header, which can hold several addresses, some of them written by the client. The "Geolocate the visitor in an HTTP flow" recipe shows the full setup.
412
438
  </details>
413
439
 
414
440
  <details>
415
- <summary><strong>What happens when I hit a rate limit?</strong></summary>
416
- 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.
417
443
  </details>
418
444
 
419
445
 
@@ -100,6 +100,7 @@
100
100
  <option value="ko">Korean (ko)</option>
101
101
  <option value="fa">Persian (fa)</option>
102
102
  <option value="pt">Portuguese (pt)</option>
103
+ <option value="ar">Standard Arabic (ar)</option>
103
104
  </select>
104
105
  </div>
105
106
  <hr/>
@@ -184,6 +184,7 @@
184
184
  <option value="ko">Korean (ko)</option>
185
185
  <option value="fa">Persian (fa)</option>
186
186
  <option value="pt">Portuguese (pt)</option>
187
+ <option value="ar">Standard Arabic (ar)</option>
187
188
  </select>
188
189
  </div>
189
190
 
@@ -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.0.2",
3
+ "version": "1.1.1",
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",
@@ -74,11 +74,13 @@
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",
81
81
  "qs": "^6.17.0",
82
- "body-parser@^1": "^1.20.9"
82
+ "body-parser@^1": "^1.20.9",
83
+ "glob": "^14.0.2",
84
+ "minimatch": "^11.0.1"
83
85
  }
84
86
  }