internetdata-web 1.6.0 → 1.8.0

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
@@ -30,7 +30,7 @@ It runs in Chrome and Edge 109, Firefox 115 ESR and Safari 16.4 or newer. TypeSc
30
30
 
31
31
  ## Usage
32
32
 
33
- **No API key needed to start.** Unlimited, the free plan, answers Tor, relay, bot, anycast, carrier, satellite and the five service flags (SSH, SMTP, web, DNS resolver and BitTorrent), reverse DNS, country-level `location`, `asn`, the company's name and domain and the abuse email, with no daily or monthly cap, with a key or without one. In a page the address calling is the visitor's, so `myIp` tells you about the visitor:
33
+ **No API key needed to start.** Unlimited, the free plan, answers Tor, relay and anycast, reverse DNS, country-level `location`, `asn`, the company's name and domain and the abuse email, with no daily or monthly cap, with a key or without one. In a page the address calling is the visitor's, so `myIp` tells you about the visitor:
34
34
 
35
35
  ```js
36
36
  import { InternetData } from 'internetdata-web';
@@ -48,7 +48,7 @@ console.log(result.company.name); // who the address belongs to
48
48
 
49
49
  ### With an API key
50
50
 
51
- Where the key stays private (see above), every paid plan answers every field: `is_vpn`, `is_hosting`, `is_cdn` and the four proxy flags as well, city-level location, the whois records and the detail behind each flag. The plans differ only in how many lookups they include, and a free account tries every field. Create a key in the [console](https://app.internetdata.io), then pass it in:
51
+ Where the key stays private (see above), a paid plan answers every field: `is_vpn`, `is_hosting`, `is_cdn`, `is_bot`, `is_carrier`, `is_satellite`, the four proxy flags and the five service flags as well, city-level location, the whois records, `user_agent` (whether a user agent you send is borne out by the address: see below) and the detail behind each flag. Its quotas differ only in how many lookups they include, and a free account tries every field. Create a key in the [console](https://app.internetdata.io), then pass it in:
52
52
 
53
53
  ```js
54
54
  const client = new InternetData({ apiKey: 'your-api-key' });
@@ -85,12 +85,31 @@ console.log(result.ip); // the address we saw this call come from: in a page,
85
85
 
86
86
  It is never cached, since which address the browser is calling from is the question, and a laptop moves between networks.
87
87
 
88
+ ### A visitor's user agent
89
+
90
+ Pass the `User-Agent` of the client you are deciding on, and on a paid plan or the trial the answer's `userAgent` names the agent it claims to be and whether this address bears that out: `verified` when the agent's operator vouches for the address, `spoofed` when it does not, `unverifiable` for a bot nothing can confirm, `not_bot` for a browser, an app or a script. Check for the values you know: one the API adds later comes back as the string it served.
91
+
92
+ ```js
93
+ const result = await client.lookup('66.249.66.1', {
94
+ userAgent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
95
+ });
96
+ console.log(result.userAgent); // { agent: 'Googlebot', kind: 'bot', verdict: 'verified' }
97
+
98
+ const mine = await client.myIp({ userAgent: navigator.userAgent });
99
+
100
+ const results = await client.lookupBatch(['66.249.66.1', '146.70.116.130'], {
101
+ userAgents: { '66.249.66.1': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' },
102
+ });
103
+ ```
104
+
105
+ `userAgents` is keyed by each address as you pass it in the list, as an object or a `Map`. An empty user agent sends none, a long one is sent whole, and the agent is never kept. An answer to a user agent is cached apart from the address's plain answer and from another agent's. A private or reserved address is still answered locally and carries no `userAgent`; neither does an answer without every field.
106
+
88
107
  ### Your plan and usage
89
108
 
90
109
  ```js
91
110
  const ent = await client.myEntitlement();
92
- console.log(ent.plan.key); // starter
93
- console.log(ent.plan.name); // Starter, the name to show
111
+ console.log(ent.plan.key); // data_4
112
+ console.log(ent.plan.name); // Data, the name to show
94
113
  console.log(ent.usage.requests); // 580
95
114
  console.log(ent.usage.window_end); // when the allowance resets
96
115
  ```
@@ -179,7 +198,7 @@ const store = {
179
198
  const client = new InternetData({ cache: { store: store } });
180
199
  ```
181
200
 
182
- `set` is told how long the answer stays fresh, and dropping it after that is the store's job. Each `key` carries a hash of the client's API key and base URL beside the address, so clients holding different keys can share one store without reading each other's answers. Bogons, errors, `myIp`, `myEntitlement` and the AS and domain lookups are never stored, and a store that fails costs a request, never an answer: a `get` that throws reads as a miss, and a `set` that throws is ignored.
201
+ `set` is told how long the answer stays fresh, and dropping it after that is the store's job. Each `key` carries a hash of the client's API key and base URL beside the address, and the user agent sent with it, if any, so clients holding different keys can share one store without reading each other's answers. Bogons, errors, `myIp`, `myEntitlement` and the AS and domain lookups are never stored, and a store that fails costs a request, never an answer: a `get` that throws reads as a miss, and a `set` that throws is ignored.
183
202
 
184
203
  ### Private and reserved addresses
185
204
 
@@ -264,11 +283,13 @@ The library is ES2022 and needs only what a browser has, `fetch` and, for PKCE,
264
283
 
265
284
  ### Absent is not false
266
285
 
267
- Unlimited leaves out `isVpn`, `isHosting`, `isCdn` and the four proxy flags, the detail behind them, `bot` (whose bot it is, behind `isBot`), and the paid members inside `location`, `asn`, `company` and `abuse`, such as `location.city`; a free-plan key's answer carries `trialExpired`, true once its trial is spent. A paid key's carries `capReached`, true once its organization's overage cap is reached, when the answer has Unlimited's fields and isn't billed. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no".
286
+ Unlimited leaves out `isVpn`, `isHosting`, `isCdn`, `isBot`, `isCarrier`, `isSatellite`, the four proxy flags and the five service flags (`isSsh`, `isSmtp`, `isWeb`, `isDnsResolver` and `isBittorrent`), the detail behind them, `bot` (whose bot it is, behind `isBot`), and the paid members inside `location`, `asn`, `company` and `abuse`, such as `location.city`; a free-plan key's answer carries `trialExpired`, true once its trial is spent. A paid key's carries `capReached`, true once its organization's overage cap is reached, when the answer has Unlimited's fields and isn't billed. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no". The one exception, until the next major release: `isCarrier`, `isSatellite` and the five service flags are typed `boolean`, so on Unlimited they read `false`, and `result.raw` shows they were not served.
268
287
 
269
288
  ```js
270
289
  result.isVpn ?? false // when you only want the flag
271
290
  result.isVpn === undefined // on Unlimited: not in your plan
291
+ result.isBot === undefined // likewise
292
+ result.isSsh === false // on Unlimited: read as false, though 'is_ssh' is not in result.raw
272
293
  result.trialExpired === true // a free-plan key's trial is spent
273
294
  result.capReached === true // a paid key is past its overage cap
274
295
  ```
@@ -279,9 +300,9 @@ There are official InternetData client libraries available for many languages in
279
300
 
280
301
  ## About InternetData
281
302
 
282
- Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, as an API and as databases you download and query yourself.
303
+ Geolocation, anonymity, ownership, network, service and domain data for any IP address, AS or domain, by API or as databases you download.
283
304
 
284
- [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="64"/>](https://internetdata.io/)
305
+ [<picture><source media="(prefers-color-scheme: dark)" srcset="https://s3.internetdata.io/internetdata-public/brand/logo-dark.svg"><img src="https://s3.internetdata.io/internetdata-public/brand/logo.svg" alt="InternetData" height="40"/></picture>](https://internetdata.io/)
285
306
 
286
307
  ## License
287
308
 
package/dist/client.d.ts CHANGED
@@ -47,17 +47,32 @@ export interface Options {
47
47
  /** Override the HTTP implementation, mostly for tests. Defaults to the global `fetch`. */
48
48
  fetch?: typeof globalThis.fetch;
49
49
  }
50
- /** Per-call overrides for a single lookup. Anything omitted falls back to the client's setting. */
51
- export interface LookupOptions {
50
+ /** Per-call overrides for one call. Anything omitted falls back to the client's setting. */
51
+ export interface CallOptions {
52
52
  /** Retry attempts for a transient failure, a whole number from 0. */
53
53
  retries?: number;
54
54
  /** How long one attempt may take before it is abandoned, in milliseconds. */
55
55
  timeoutMs?: number;
56
56
  }
57
+ /** Per-call options for `lookup` and `myIp`. */
58
+ export interface LookupOptions extends CallOptions {
59
+ /**
60
+ * The `User-Agent` of the client that came from this address. With every field, on a paid
61
+ * plan or the trial, the answer's `userAgent` then names the agent it claims to be and whether
62
+ * this address bears that out. The empty string sends none, and a longer one than the API's
63
+ * 1024 characters is sent whole for the API to cut.
64
+ */
65
+ userAgent?: string;
66
+ }
57
67
  /** Per-call overrides for one batch. Anything omitted falls back to the client's setting. */
58
- export interface BatchOptions extends LookupOptions {
68
+ export interface BatchOptions extends CallOptions {
59
69
  /** Concurrent batch requests for THIS batch only. */
60
70
  concurrency?: number;
71
+ /**
72
+ * Each address's `User-Agent`, keyed by the address as you pass it in `ips`, sent as
73
+ * `lookup`'s `userAgent` is. An address left out, or given the empty string, sends none.
74
+ */
75
+ userAgents?: Readonly<Record<string, string>> | ReadonlyMap<string, string>;
61
76
  }
62
77
  /**
63
78
  * A client for the InternetData API, for a browser: a page's own scripts, a web
@@ -101,6 +116,10 @@ export declare class InternetData {
101
116
  * address it carries: judged, sent and cached as that, so the answer names
102
117
  * `8.8.8.8`. Anything that is not an IP address is refused as `bad_request`
103
118
  * before it is sent: an AS is `lookupAsn`'s, and a domain `lookupDomain`'s.
119
+ *
120
+ * With `userAgent`, the answer is cached, stored and shared on the address and
121
+ * that agent together: apart from the address's plain answer and from another
122
+ * agent's. A bogon's answer carries no `userAgent`.
104
123
  */
105
124
  lookup(ip: string, options?: LookupOptions): Promise<Result>;
106
125
  private answer;
@@ -116,7 +135,8 @@ export declare class InternetData {
116
135
  *
117
136
  * Deliberately NOT cached. The cache is keyed by address, and which
118
137
  * address this is IS the question: a device that moves between networks
119
- * would otherwise be told where it used to be.
138
+ * would otherwise be told where it used to be. `userAgent` is sent as
139
+ * `lookup` sends it.
120
140
  */
121
141
  myIp(options?: LookupOptions): Promise<Result>;
122
142
  /**
@@ -127,7 +147,7 @@ export declare class InternetData {
127
147
  * Sent as given and not cached. The API refuses a number it cannot read as
128
148
  * `bad_request`.
129
149
  */
130
- lookupAsn(asn: number, options?: LookupOptions): Promise<AsnResult>;
150
+ lookupAsn(asn: number, options?: CallOptions): Promise<AsnResult>;
131
151
  /**
132
152
  * What InternetData knows about one domain: on every plan whether it is
133
153
  * registered and which DNS record types it has, and on a paid one the
@@ -137,7 +157,7 @@ export declare class InternetData {
137
157
  * Sent as given and not cached. The API refuses a name it cannot read as
138
158
  * `bad_request`.
139
159
  */
140
- lookupDomain(domain: string, options?: LookupOptions): Promise<DomainResult>;
160
+ lookupDomain(domain: string, options?: CallOptions): Promise<DomainResult>;
141
161
  /**
142
162
  * What this client's key is entitled to, and how much of it has been used.
143
163
  *
@@ -157,7 +177,7 @@ export declare class InternetData {
157
177
  * Deliberately NOT cached: the whole point is what has been spent, and a
158
178
  * cached answer is a wrong one within seconds of the next request.
159
179
  */
160
- myEntitlement(options?: LookupOptions): Promise<Entitlement>;
180
+ myEntitlement(options?: CallOptions): Promise<Entitlement>;
161
181
  /**
162
182
  * Look many addresses up in as few requests as possible.
163
183
  *
@@ -179,6 +199,12 @@ export declare class InternetData {
179
199
  * `unauthorized` error, and a free-plan key's request of two or more a
180
200
  * `bad_request` (HTTP 402). A request of one address is answered as its
181
201
  * lookup would be.
202
+ *
203
+ * `userAgents` sends each address's agent, as `user_agents` keyed by the address
204
+ * as the request sends it (an IPv4-mapped one as the IPv4 address it carries),
205
+ * and only in a request where one of its addresses has one. Each address's
206
+ * answer is cached, stored and shared on the address and its agent together,
207
+ * as `lookup`'s is.
182
208
  */
183
209
  lookupBatch(ips: Iterable<string>, options?: BatchOptions): Promise<Map<string, Result | InternetDataError>>;
184
210
  private unstored;
package/dist/client.js CHANGED
@@ -7,7 +7,7 @@ import { errorFromEntry, InternetDataError } from './errors.js';
7
7
  import { OauthApi } from './oauth.js';
8
8
  import { isAsnLookup, isBatch, isBatchError, isDomainLookup, isEntitlement, isLookup } from './shapes.js';
9
9
  import { isCacheStore, lifeMs, storeScope, StoreTier } from './store.js';
10
- import { asError, checkConcurrency, checkRetries, checkTimeout, deadline, readable, withRetry, } from './transport.js';
10
+ import { asError, checkConcurrency, checkRetries, checkTimeout, deadline, readable, strictEncode, withRetry, } from './transport.js';
11
11
  import { toAsnResult, toDomainResult, toResult, } from './types.js';
12
12
  export const DEFAULT_BASE_URL = 'https://api.internetdata.io';
13
13
  // fetch has no whole-request limit of its own, so without this a hung API would
@@ -25,9 +25,11 @@ const BATCH_MAX = 1000;
25
25
  */
26
26
  export class InternetData {
27
27
  client;
28
- // Keyed by address. The context is how a call sends the request when the
29
- // address has none in flight: `fetch()` runs it synchronously, so a batch
30
- // knows which addresses it leads before it builds a chunk.
28
+ // Keyed by address, and by the user agent sent with it (`cacheKey`): an
29
+ // answer to one carries that agent's verdict. The context is how a call
30
+ // sends the request when the key has none in flight: `fetch()` runs it
31
+ // synchronously, so a batch knows which addresses it leads before it builds
32
+ // a chunk.
31
33
  cache;
32
34
  store;
33
35
  limit;
@@ -106,11 +108,16 @@ export class InternetData {
106
108
  * address it carries: judged, sent and cached as that, so the answer names
107
109
  * `8.8.8.8`. Anything that is not an IP address is refused as `bad_request`
108
110
  * before it is sent: an AS is `lookupAsn`'s, and a domain `lookupDomain`'s.
111
+ *
112
+ * With `userAgent`, the answer is cached, stored and shared on the address and
113
+ * that agent together: apart from the address's plain answer and from another
114
+ * agent's. A bogon's answer carries no `userAgent`.
109
115
  */
110
116
  async lookup(ip, options = {}) {
111
117
  // First, or a bogon and a cached address would answer any value.
112
118
  checkTimeout(options.timeoutMs);
113
119
  checkRetries(options.retries);
120
+ const agent = checkUserAgent(options.userAgent);
114
121
  // The API answers an AS or a domain at this path too, in a shape this
115
122
  // call cannot read, so one sent here would fail as three retried server errors.
116
123
  if (typeof ip !== 'string' || !isAddress(unmapped(ip))) {
@@ -122,25 +129,27 @@ export class InternetData {
122
129
  return bogonResult(addr);
123
130
  }
124
131
  if (this.cache === null) {
125
- return this.serve(addr, options);
132
+ return this.serve(addr, agent, options);
126
133
  }
127
- return (await this.cache.fetch(addr, { context: () => this.answer(addr, options) }));
134
+ return (await this.cache.fetch(cacheKey(addr, agent), {
135
+ context: () => this.answer(addr, agent, options),
136
+ }));
128
137
  }
129
138
  // A miss in memory: the store's answer if it holds one, else the API's, kept.
130
- async answer(ip, options) {
131
- const stored = await this.store?.get(ip);
139
+ async answer(ip, agent, options) {
140
+ const stored = await this.store?.get(ip, agent);
132
141
  if (stored !== undefined) {
133
142
  return stored;
134
143
  }
135
- const served = await this.serve(ip, options);
136
- await this.store?.set(ip, served);
144
+ const served = await this.serve(ip, agent, options);
145
+ await this.store?.set(ip, agent, served);
137
146
  return served;
138
147
  }
139
- async serve(ip, options) {
148
+ async serve(ip, agent, options) {
140
149
  const timeoutMs = options.timeoutMs ?? this.timeoutMs;
141
150
  return withRetry(options.retries ?? this.retries, async () => {
142
151
  const res = await deadline(timeoutMs, (signal) => lookupIp({
143
- client: this.client, path: { ip: ip }, signal: signal,
152
+ client: this.client, path: { ip: ip }, signal: signal, ...agentQuery(agent),
144
153
  }));
145
154
  return toResult(readable(res, isLookup));
146
155
  });
@@ -156,13 +165,16 @@ export class InternetData {
156
165
  *
157
166
  * Deliberately NOT cached. The cache is keyed by address, and which
158
167
  * address this is IS the question: a device that moves between networks
159
- * would otherwise be told where it used to be.
168
+ * would otherwise be told where it used to be. `userAgent` is sent as
169
+ * `lookup` sends it.
160
170
  */
161
171
  async myIp(options = {}) {
162
172
  const timeoutMs = checkTimeout(options.timeoutMs) ?? this.timeoutMs;
163
- return withRetry(checkRetries(options.retries) ?? this.retries, async () => {
173
+ const retries = checkRetries(options.retries) ?? this.retries;
174
+ const agent = checkUserAgent(options.userAgent);
175
+ return withRetry(retries, async () => {
164
176
  const res = await deadline(timeoutMs, (signal) => lookupMyIp({
165
- client: this.client, signal: signal,
177
+ client: this.client, signal: signal, ...agentQuery(agent),
166
178
  }));
167
179
  return toResult(readable(res, isLookup));
168
180
  });
@@ -251,11 +263,18 @@ export class InternetData {
251
263
  * `unauthorized` error, and a free-plan key's request of two or more a
252
264
  * `bad_request` (HTTP 402). A request of one address is answered as its
253
265
  * lookup would be.
266
+ *
267
+ * `userAgents` sends each address's agent, as `user_agents` keyed by the address
268
+ * as the request sends it (an IPv4-mapped one as the IPv4 address it carries),
269
+ * and only in a request where one of its addresses has one. Each address's
270
+ * answer is cached, stored and shared on the address and its agent together,
271
+ * as `lookup`'s is.
254
272
  */
255
273
  async lookupBatch(ips, options = {}) {
256
274
  const concurrency = checkConcurrency(options.concurrency);
257
275
  checkTimeout(options.timeoutMs);
258
276
  checkRetries(options.retries);
277
+ const agents = checkUserAgents(options.userAgents);
259
278
  const asked = [...new Set(ips)];
260
279
  const unique = [...new Set(asked.map(unmapped))];
261
280
  const out = new Map();
@@ -271,7 +290,8 @@ export class InternetData {
271
290
  out.set(ip, bogonResult(ip));
272
291
  continue;
273
292
  }
274
- const hit = this.cache?.get(ip);
293
+ const key = cacheKey(ip, agents.get(ip));
294
+ const hit = this.cache?.get(key);
275
295
  if (hit !== undefined) {
276
296
  out.set(ip, hit);
277
297
  continue;
@@ -280,7 +300,7 @@ export class InternetData {
280
300
  pending.push(ip);
281
301
  continue;
282
302
  }
283
- shared.push([ip, this.cache.fetch(ip, {
303
+ shared.push([ip, this.cache.fetch(key, {
284
304
  context: () => {
285
305
  const landing = deferred();
286
306
  led.set(ip, landing);
@@ -289,7 +309,7 @@ export class InternetData {
289
309
  },
290
310
  })]);
291
311
  }
292
- const sending = this.store === null ? pending : await this.unstored(pending, led);
312
+ const sending = this.store === null ? pending : await this.unstored(pending, agents, led);
293
313
  // A per-call concurrency gets its own limiter; without one the call
294
314
  // would share the instance's budget and silently ignore the override.
295
315
  const limit = concurrency === undefined ? this.limit : pLimit(concurrency);
@@ -300,7 +320,7 @@ export class InternetData {
300
320
  await Promise.all([
301
321
  ...chunks.map((chunk) => limit(async () => {
302
322
  const kept = [];
303
- for (const [ip, answer] of await this.lookupChunk(chunk, options)) {
323
+ for (const [ip, answer] of await this.lookupChunk(chunk, agents, options)) {
304
324
  const landing = led.get(ip);
305
325
  if (landing === undefined) {
306
326
  out.set(ip, answer);
@@ -312,7 +332,7 @@ export class InternetData {
312
332
  landing.resolve(answer);
313
333
  }
314
334
  if (this.store !== null && !(answer instanceof InternetDataError)) {
315
- kept.push(this.store.set(ip, answer));
335
+ kept.push(this.store.set(ip, agents.get(ip), answer));
316
336
  }
317
337
  }
318
338
  await Promise.all(kept);
@@ -333,8 +353,8 @@ export class InternetData {
333
353
  }
334
354
  // The addresses this batch leads that the store does not hold, in the order
335
355
  // given. One the store holds lands at once, as a request's answer would.
336
- async unstored(ips, led) {
337
- const stored = await Promise.all(ips.map((ip) => this.store.get(ip)));
356
+ async unstored(ips, agents, led) {
357
+ const stored = await Promise.all(ips.map((ip) => this.store.get(ip, agents.get(ip))));
338
358
  return ips.filter((ip, i) => {
339
359
  const hit = stored[i];
340
360
  if (hit === undefined) {
@@ -348,14 +368,15 @@ export class InternetData {
348
368
  // chunk-level failure - the call refused, the transport failing, the
349
369
  // retries exhausted - becomes every address's error, exactly as it would
350
370
  // have been had each been looked up alone.
351
- async lookupChunk(chunk, options) {
371
+ async lookupChunk(chunk, agents, options) {
352
372
  const out = new Map();
353
373
  const timeoutMs = options.timeoutMs ?? this.timeoutMs;
374
+ const request = batchRequest(chunk, agents);
354
375
  let body;
355
376
  try {
356
377
  body = await withRetry(options.retries ?? this.retries, async () => {
357
378
  const res = await deadline(timeoutMs, (signal) => lookupBatch({
358
- client: this.client, body: { ips: chunk }, signal: signal,
379
+ client: this.client, body: request, signal: signal,
359
380
  }));
360
381
  return readable(res, isBatch);
361
382
  });
@@ -445,6 +466,63 @@ function checkCacheOption(name, value) {
445
466
  }
446
467
  return value;
447
468
  }
469
+ /** The agent a call sends, `undefined` for none: the empty string is none, as the API reads `user_agent=`. */
470
+ function checkUserAgent(userAgent) {
471
+ if (userAgent === undefined || userAgent === null || userAgent === '') {
472
+ return undefined;
473
+ }
474
+ if (typeof userAgent !== 'string') {
475
+ throw new InternetDataError('bad_request', `userAgent must be a string, got ${typeof userAgent}`);
476
+ }
477
+ return userAgent;
478
+ }
479
+ /** A batch's user agents, keyed by each address as the batch sends it, every empty one dropped. */
480
+ function checkUserAgents(userAgents) {
481
+ const agents = new Map();
482
+ if (userAgents === undefined || userAgents === null) {
483
+ return agents;
484
+ }
485
+ if (typeof userAgents !== 'object') {
486
+ throw new InternetDataError('bad_request', `userAgents must map addresses to agents, got ${typeof userAgents}`);
487
+ }
488
+ const entries = userAgents instanceof Map ? [...userAgents.entries()] : Object.entries(userAgents);
489
+ for (const [ip, agent] of entries) {
490
+ const checked = checkUserAgent(agent);
491
+ if (checked !== undefined) {
492
+ agents.set(unmapped(String(ip)), checked);
493
+ }
494
+ }
495
+ return agents;
496
+ }
497
+ // An answer to an address with an agent carries that agent's verdict, so it is
498
+ // never served for the address alone or for another agent. The address alone
499
+ // stays the key of a lookup sending none.
500
+ function cacheKey(ip, agent) {
501
+ return agent === undefined ? ip : JSON.stringify([ip, agent]);
502
+ }
503
+ /**
504
+ * One chunk's body: `user_agents` only when an address of THIS chunk has one, never
505
+ * `{}`, keyed by each address exactly as `ips` sends it.
506
+ */
507
+ function batchRequest(chunk, agents) {
508
+ const sent = chunk.filter((ip) => agents.has(ip)).map((ip) => [ip, agents.get(ip)]);
509
+ return sent.length === 0 ? { ips: chunk } : { ips: chunk, user_agents: Object.fromEntries(sent) };
510
+ }
511
+ /**
512
+ * The query a lookup sends its agent in, every reserved character percent-encoded,
513
+ * `+` among them, which a server reads as a space. Set by hand, so nothing checks
514
+ * the spec's 1024-character bound before the API cuts it.
515
+ */
516
+ function agentQuery(agent) {
517
+ if (agent === undefined) {
518
+ return {};
519
+ }
520
+ return { query: { user_agent: agent }, querySerializer: strictQuery };
521
+ }
522
+ function strictQuery(query) {
523
+ return Object.entries(query).filter(([, value]) => value !== undefined && value !== null)
524
+ .map(([name, value]) => `${strictEncode(name)}=${strictEncode(String(value))}`).join('&');
525
+ }
448
526
  function unreadableEntry(ip) {
449
527
  return new InternetDataError('server_error', `unreadable batch answer for ${ip}, status 200`, 200);
450
528
  }
@@ -128,7 +128,7 @@ export type LookupResponse = {
128
128
  */
129
129
  is_bogon: boolean;
130
130
  /**
131
- * In VPN IP: a VPN service's server. Paid plans and the trial.
131
+ * In VPN IP: a VPN service's server. On a paid plan or the trial.
132
132
  */
133
133
  is_vpn?: boolean;
134
134
  /**
@@ -140,67 +140,67 @@ export type LookupResponse = {
140
140
  */
141
141
  is_relay: boolean;
142
142
  /**
143
- * In Residential Proxy IP's 90-day window: a residential proxy exit. Paid plans and the trial.
143
+ * In Residential Proxy IP's 90-day window: a residential proxy exit. On a paid plan or the trial.
144
144
  */
145
145
  is_resproxy?: boolean;
146
146
  /**
147
- * In Datacenter Proxy IP's 90-day window. Paid plans and the trial.
147
+ * In Datacenter Proxy IP's 90-day window. On a paid plan or the trial.
148
148
  */
149
149
  is_dcproxy?: boolean;
150
150
  /**
151
- * In Mobile Proxy IP's 90-day window. Paid plans and the trial.
151
+ * In Mobile Proxy IP's 90-day window. On a paid plan or the trial.
152
152
  */
153
153
  is_mobproxy?: boolean;
154
154
  /**
155
- * In Public Proxy IP: a public proxy listens here, or its traffic left from here. Paid plans and the trial.
155
+ * In Public Proxy IP: a public proxy listens here, or its traffic left from here. On a paid plan or the trial.
156
156
  */
157
157
  is_pubproxy?: boolean;
158
158
  /**
159
- * In Hosting IP: a hosting or cloud network. Paid plans and the trial.
159
+ * In Hosting IP: a hosting or cloud network. On a paid plan or the trial.
160
160
  */
161
161
  is_hosting?: boolean;
162
162
  /**
163
- * In CDN IP: a content delivery network. Paid plans and the trial.
163
+ * In CDN IP: a content delivery network. On a paid plan or the trial.
164
164
  */
165
165
  is_cdn?: boolean;
166
166
  /**
167
- * In Bot IP: an automated client's address, such as a search engine's or an AI company's crawler, an uptime monitor, an internet scanner or a webhook sender. `bot` says whose, what it does and whether its operator vouches for the address.
167
+ * In Bot IP: an automated client's address, such as a search engine's or an AI company's crawler, an uptime monitor, an internet scanner or a webhook sender. `bot` says whose, what it does and whether its operator vouches for the address. On a paid plan or the trial.
168
168
  */
169
- is_bot: boolean;
169
+ is_bot?: boolean;
170
170
  /**
171
171
  * In Anycast IP: announced from many places at once.
172
172
  */
173
173
  is_anycast: boolean;
174
174
  /**
175
- * In Carrier IP: a mobile carrier's address space.
175
+ * In Carrier IP: a mobile carrier's address space. On a paid plan or the trial.
176
176
  */
177
- is_carrier: boolean;
177
+ is_carrier?: boolean;
178
178
  /**
179
- * In Satellite IP: a satellite operator's address space.
179
+ * In Satellite IP: a satellite operator's address space. On a paid plan or the trial.
180
180
  */
181
- is_satellite: boolean;
181
+ is_satellite?: boolean;
182
182
  /**
183
- * In SSH IP: an SSH server answered here.
183
+ * In SSH IP: an SSH server answered here. On a paid plan or the trial.
184
184
  */
185
- is_ssh: boolean;
185
+ is_ssh?: boolean;
186
186
  /**
187
- * In SMTP IP: a mail server answered here.
187
+ * In SMTP IP: a mail server answered here. On a paid plan or the trial.
188
188
  */
189
- is_smtp: boolean;
189
+ is_smtp?: boolean;
190
190
  /**
191
- * In Web IP: a web server answered here on port 80 or 443.
191
+ * In Web IP: a web server answered here on port 80 or 443. On a paid plan or the trial.
192
192
  */
193
- is_web: boolean;
193
+ is_web?: boolean;
194
194
  /**
195
- * In DNS Resolver IP: an open DNS resolver answered here.
195
+ * In DNS Resolver IP: an open DNS resolver answered here. On a paid plan or the trial.
196
196
  */
197
- is_dns_resolver: boolean;
197
+ is_dns_resolver?: boolean;
198
198
  /**
199
- * In BitTorrent IP: a BitTorrent client was seen here in the last 90 days.
199
+ * In BitTorrent IP: a BitTorrent client was seen here in the last 90 days. On a paid plan or the trial.
200
200
  */
201
- is_bittorrent: boolean;
201
+ is_bittorrent?: boolean;
202
202
  /**
203
- * VPN IP's row, `{}` when `is_vpn` is false. Paid plans and the trial.
203
+ * VPN IP's row, `{}` when `is_vpn` is false. On a paid plan or the trial.
204
204
  */
205
205
  vpn?: ClassDetail;
206
206
  /**
@@ -212,59 +212,59 @@ export type LookupResponse = {
212
212
  */
213
213
  relay: ClassDetail;
214
214
  /**
215
- * `{}` when `is_resproxy` is false. Paid plans and the trial.
215
+ * `{}` when `is_resproxy` is false. On a paid plan or the trial.
216
216
  */
217
217
  resproxy?: ProxyDetail;
218
218
  /**
219
- * `{}` when `is_dcproxy` is false. Paid plans and the trial.
219
+ * `{}` when `is_dcproxy` is false. On a paid plan or the trial.
220
220
  */
221
221
  dcproxy?: ProxyDetail;
222
222
  /**
223
- * `{}` when `is_mobproxy` is false. Paid plans and the trial.
223
+ * `{}` when `is_mobproxy` is false. On a paid plan or the trial.
224
224
  */
225
225
  mobproxy?: ProxyDetail;
226
226
  /**
227
- * `{}` when `is_pubproxy` is false. Paid plans and the trial.
227
+ * `{}` when `is_pubproxy` is false. On a paid plan or the trial.
228
228
  */
229
229
  pubproxy?: PubproxyDetail;
230
230
  /**
231
- * `{}` when `is_hosting` is false. Paid plans and the trial.
231
+ * `{}` when `is_hosting` is false. On a paid plan or the trial.
232
232
  */
233
233
  hosting?: ClassDetail;
234
234
  /**
235
- * `{}` when `is_cdn` is false. Paid plans and the trial.
235
+ * `{}` when `is_cdn` is false. On a paid plan or the trial.
236
236
  */
237
237
  cdn?: ClassDetail;
238
238
  /**
239
- * `{}` when `is_bot` is false. Paid plans and the trial.
239
+ * `{}` when `is_bot` is false. On a paid plan or the trial.
240
240
  */
241
241
  bot?: BotDetail;
242
242
  /**
243
- * `{}` when `is_carrier` is false. Paid plans and the trial.
243
+ * `{}` when `is_carrier` is false. On a paid plan or the trial.
244
244
  */
245
245
  carrier?: CarrierDetail;
246
246
  /**
247
- * `{}` when `is_satellite` is false. Paid plans and the trial.
247
+ * `{}` when `is_satellite` is false. On a paid plan or the trial.
248
248
  */
249
249
  satellite?: SatelliteDetail;
250
250
  /**
251
- * `{}` when `is_ssh` is false. Paid plans and the trial.
251
+ * `{}` when `is_ssh` is false. On a paid plan or the trial.
252
252
  */
253
253
  ssh?: SshDetail;
254
254
  /**
255
- * `{}` when `is_smtp` is false. Paid plans and the trial.
255
+ * `{}` when `is_smtp` is false. On a paid plan or the trial.
256
256
  */
257
257
  smtp?: SmtpDetail;
258
258
  /**
259
- * A row per port that answered, lowest first; `[]` when `is_web` is false. Paid plans and the trial.
259
+ * A row per port that answered, lowest first; `[]` when `is_web` is false. On a paid plan or the trial.
260
260
  */
261
261
  web?: Array<WebDetail>;
262
262
  /**
263
- * `{}` when `is_dns_resolver` is false. Paid plans and the trial.
263
+ * `{}` when `is_dns_resolver` is false. On a paid plan or the trial.
264
264
  */
265
265
  dns_resolver?: DnsResolverDetail;
266
266
  /**
267
- * `{}` when `is_bittorrent` is false. Paid plans and the trial.
267
+ * `{}` when `is_bittorrent` is false. On a paid plan or the trial.
268
268
  */
269
269
  bittorrent?: BitTorrentDetail;
270
270
  location: Location;
@@ -696,43 +696,43 @@ export type Location = {
696
696
  */
697
697
  flag_unicode: string;
698
698
  /**
699
- * Region (state or province). Paid plans and the trial.
699
+ * Region (state or province). On a paid plan or the trial.
700
700
  */
701
701
  region?: string;
702
702
  /**
703
- * ISO 3166-2 region code. Paid plans and the trial.
703
+ * ISO 3166-2 region code. On a paid plan or the trial.
704
704
  */
705
705
  region_code?: string;
706
706
  /**
707
- * City. Paid plans and the trial.
707
+ * City. On a paid plan or the trial.
708
708
  */
709
709
  city?: string;
710
710
  /**
711
- * Postal code. Paid plans and the trial.
711
+ * Postal code. On a paid plan or the trial.
712
712
  */
713
713
  postal_code?: string;
714
714
  /**
715
- * Latitude of the city. Paid plans and the trial.
715
+ * Latitude of the city. On a paid plan or the trial.
716
716
  */
717
717
  latitude?: number;
718
718
  /**
719
- * Longitude of the city. Paid plans and the trial.
719
+ * Longitude of the city. On a paid plan or the trial.
720
720
  */
721
721
  longitude?: number;
722
722
  /**
723
- * Radius in km holding the true location with 67% confidence. Paid plans and the trial.
723
+ * Radius in km holding the true location with 67% confidence. On a paid plan or the trial.
724
724
  */
725
725
  accuracy_radius?: number;
726
726
  /**
727
- * GeoNames ID of the city. Paid plans and the trial.
727
+ * GeoNames ID of the city. On a paid plan or the trial.
728
728
  */
729
729
  geoname_id?: string;
730
730
  /**
731
- * US TV market (DMA) code. Paid plans and the trial.
731
+ * US TV market (DMA) code. On a paid plan or the trial.
732
732
  */
733
733
  dma_code?: string;
734
734
  /**
735
- * The day the range's location last changed. Paid plans and the trial.
735
+ * The day the range's location last changed. On a paid plan or the trial.
736
736
  */
737
737
  last_changed?: string;
738
738
  };
@@ -753,9 +753,9 @@ export type Asn = {
753
753
  */
754
754
  domain: string;
755
755
  /**
756
- * The kind of network it runs.
756
+ * The kind of network it runs. On a paid plan or the trial.
757
757
  */
758
- type: string;
758
+ type?: string;
759
759
  /**
760
760
  * The announced prefix covering the address.
761
761
  */
@@ -782,11 +782,11 @@ export type Company = {
782
782
  */
783
783
  domain: string;
784
784
  /**
785
- * What kind of organization: hosting, isp, business, education, government. Paid plans and the trial.
785
+ * What kind of organization: hosting, isp, business, education, government. On a paid plan or the trial.
786
786
  */
787
787
  type?: string;
788
788
  /**
789
- * ISO 3166 country code. Paid plans and the trial.
789
+ * ISO 3166 country code. On a paid plan or the trial.
790
790
  */
791
791
  country?: string;
792
792
  };
@@ -799,36 +799,36 @@ export type AbuseContact = {
799
799
  */
800
800
  email: string;
801
801
  /**
802
- * The contact. Paid plans and the trial.
802
+ * The contact. On a paid plan or the trial.
803
803
  */
804
804
  name?: string;
805
805
  /**
806
- * Its phone number. Paid plans and the trial.
806
+ * Its phone number. On a paid plan or the trial.
807
807
  */
808
808
  phone?: string;
809
809
  /**
810
- * Its postal address. Paid plans and the trial.
810
+ * Its postal address. On a paid plan or the trial.
811
811
  */
812
812
  address?: string;
813
813
  /**
814
- * ISO 3166 country code. Paid plans and the trial.
814
+ * ISO 3166 country code. On a paid plan or the trial.
815
815
  */
816
816
  country?: string;
817
817
  /**
818
- * The registry block it was derived from. Paid plans and the trial.
818
+ * The registry block it was derived from. On a paid plan or the trial.
819
819
  */
820
820
  network?: string;
821
821
  /**
822
- * ARIN reports the contact answered its yearly validation. Paid plans and the trial.
822
+ * ARIN reports the contact answered its yearly validation. On a paid plan or the trial.
823
823
  */
824
824
  validated?: boolean;
825
825
  /**
826
- * Since when it has not. Paid plans and the trial.
826
+ * Since when it has not. On a paid plan or the trial.
827
827
  */
828
828
  unvalidated_since?: string;
829
829
  };
830
830
  /**
831
- * IP Whois's most specific record covering the address. Paid plans and the trial.
831
+ * IP Whois's most specific record covering the address. On a paid plan or the trial.
832
832
  */
833
833
  export type Whois = {
834
834
  /**
@@ -869,7 +869,7 @@ export type Whois = {
869
869
  asn: number;
870
870
  };
871
871
  /**
872
- * IP RWHOIS's most specific network covering the address. Paid plans and the trial.
872
+ * IP RWHOIS's most specific network covering the address. On a paid plan or the trial.
873
873
  */
874
874
  export type Rwhois = {
875
875
  /**
@@ -898,7 +898,7 @@ export type Rwhois = {
898
898
  abuse_email: string;
899
899
  };
900
900
  /**
901
- * From IP Hosted Domains: how many registered domains resolve to the address, and the 10 most popular. Its database lists up to 1,000 an address. Paid plans and the trial.
901
+ * From IP Hosted Domains: how many registered domains resolve to the address, and the 10 most popular. Its database lists up to 1,000 an address. On a paid plan or the trial.
902
902
  */
903
903
  export type HostedDomains = {
904
904
  /**
@@ -911,7 +911,7 @@ export type HostedDomains = {
911
911
  domains?: Array<string>;
912
912
  };
913
913
  /**
914
- * From ASN Hosted Domains: how many registered domains the AS hosts, and the 10 most popular. Its database lists up to 1,000 an AS. Paid plans and the trial.
914
+ * From ASN Hosted Domains: how many registered domains the AS hosts, and the 10 most popular. Its database lists up to 1,000 an AS. On a paid plan or the trial.
915
915
  */
916
916
  export type AsnHostedDomains = {
917
917
  /**
@@ -952,73 +952,73 @@ export type AsnLookupResponse = {
952
952
  */
953
953
  domain: string;
954
954
  /**
955
- * The kind of network it runs. Paid plans and the trial.
955
+ * The kind of network it runs. On a paid plan or the trial.
956
956
  */
957
957
  type?: string;
958
958
  /**
959
- * IPv4 addresses it announces. Paid plans and the trial.
959
+ * IPv4 addresses it announces. On a paid plan or the trial.
960
960
  */
961
961
  num_ips?: number;
962
962
  /**
963
- * IPv4 prefixes it announces. Paid plans and the trial.
963
+ * IPv4 prefixes it announces. On a paid plan or the trial.
964
964
  */
965
965
  num_prefixes4?: number;
966
966
  /**
967
- * IPv6 prefixes it announces. Paid plans and the trial.
967
+ * IPv6 prefixes it announces. On a paid plan or the trial.
968
968
  */
969
969
  num_prefixes6?: number;
970
970
  /**
971
- * Its announcements RPKI calls valid. Paid plans and the trial.
971
+ * Its announcements RPKI calls valid. On a paid plan or the trial.
972
972
  */
973
973
  rpki_valid?: number;
974
974
  /**
975
- * Invalid. Paid plans and the trial.
975
+ * Invalid. On a paid plan or the trial.
976
976
  */
977
977
  rpki_invalid?: number;
978
978
  /**
979
- * With no RPKI record. Paid plans and the trial.
979
+ * With no RPKI record. On a paid plan or the trial.
980
980
  */
981
981
  rpki_not_found?: number;
982
982
  /**
983
- * Its ASN Whois record, every column, empty where the registry states nothing. Paid plans and the trial.
983
+ * Its ASN Whois record, every column, empty where the registry states nothing. On a paid plan or the trial.
984
984
  */
985
985
  whois?: {
986
986
  [key: string]: string;
987
987
  };
988
988
  /**
989
- * What it announces, IPv4 then IPv6, up to 20000 a family. Paid plans and the trial.
989
+ * What it announces, IPv4 then IPv6, up to 20000 a family. On a paid plan or the trial.
990
990
  */
991
991
  prefixes?: Array<AsnPrefix>;
992
992
  /**
993
- * Its rank in ASN Extended, by customer cone, 1 the largest; `0` for an AS seen in no AS path. Paid plans and the trial.
993
+ * Its rank in ASN Extended, by customer cone, 1 the largest; `0` for an AS seen in no AS path. On a paid plan or the trial.
994
994
  */
995
995
  rank?: number;
996
996
  /**
997
- * Whether it is one of the transit-free networks at the top of the hierarchy, which get transit from no one and peer with each other. Paid plans and the trial.
997
+ * Whether it is one of the transit-free networks at the top of the hierarchy, which get transit from no one and peer with each other. On a paid plan or the trial.
998
998
  */
999
999
  tier1?: boolean;
1000
1000
  /**
1001
- * How many AS numbers it gets transit from. Paid plans and the trial.
1001
+ * How many AS numbers it gets transit from. On a paid plan or the trial.
1002
1002
  */
1003
1003
  num_upstreams?: number;
1004
1004
  /**
1005
- * Those AS numbers, ascending, up to 20000. Paid plans and the trial.
1005
+ * Those AS numbers, ascending, up to 20000. On a paid plan or the trial.
1006
1006
  */
1007
1007
  upstreams?: Array<number>;
1008
1008
  /**
1009
- * How many AS numbers it exchanges its own and its customers' routes with. Paid plans and the trial.
1009
+ * How many AS numbers it exchanges its own and its customers' routes with. On a paid plan or the trial.
1010
1010
  */
1011
1011
  num_peers?: number;
1012
1012
  /**
1013
- * Those AS numbers, ascending, up to 20000. Paid plans and the trial.
1013
+ * Those AS numbers, ascending, up to 20000. On a paid plan or the trial.
1014
1014
  */
1015
1015
  peers?: Array<number>;
1016
1016
  /**
1017
- * How many AS numbers it provides transit to. Paid plans and the trial.
1017
+ * How many AS numbers it provides transit to. On a paid plan or the trial.
1018
1018
  */
1019
1019
  num_downstreams?: number;
1020
1020
  /**
1021
- * Those AS numbers, ascending, up to 20000. Paid plans and the trial.
1021
+ * Those AS numbers, ascending, up to 20000. On a paid plan or the trial.
1022
1022
  */
1023
1023
  downstreams?: Array<number>;
1024
1024
  hosted_domains?: AsnHostedDomains;
@@ -1074,7 +1074,7 @@ export type DomainLookupResponse = {
1074
1074
  */
1075
1075
  is_registered: boolean;
1076
1076
  /**
1077
- * In Disposable Domain. Paid plans and the trial.
1077
+ * In Disposable Domain. On a paid plan or the trial.
1078
1078
  */
1079
1079
  is_disposable?: boolean;
1080
1080
  /**
@@ -1099,13 +1099,13 @@ export type DomainLookupResponse = {
1099
1099
  has_cname: boolean;
1100
1100
  dns?: DomainDns;
1101
1101
  /**
1102
- * The network announcing each address in `dns.a` and then `dns.aaaa`, from IP ASN; `[]` where it resolves to none. Paid plans and the trial.
1102
+ * The network announcing each address in `dns.a` and then `dns.aaaa`, from IP ASN; `[]` where it resolves to none. On a paid plan or the trial.
1103
1103
  */
1104
1104
  hosting?: Array<DomainHost>;
1105
1105
  cohosted_domains?: CohostedDomains;
1106
1106
  ip_ranges?: DomainIpRanges;
1107
1107
  /**
1108
- * `{}` when `is_disposable` is false. Paid plans and the trial.
1108
+ * `{}` when `is_disposable` is false. On a paid plan or the trial.
1109
1109
  */
1110
1110
  disposable?: DisposableDetail;
1111
1111
  web?: DomainWeb;
@@ -1134,7 +1134,7 @@ export type DomainHost = {
1134
1134
  asn: Asn;
1135
1135
  };
1136
1136
  /**
1137
- * From IP Hosted Domains: the other registered domains on the domain's first IPv4 address, how many and the 10 most popular. Paid plans and the trial.
1137
+ * From IP Hosted Domains: the other registered domains on the domain's first IPv4 address, how many and the 10 most popular. On a paid plan or the trial.
1138
1138
  */
1139
1139
  export type CohostedDomains = {
1140
1140
  /**
@@ -1151,7 +1151,7 @@ export type CohostedDomains = {
1151
1151
  domains: Array<string>;
1152
1152
  };
1153
1153
  /**
1154
- * What our crawl last read of the domain's own home page, every member empty where it holds none. Paid plans and the trial.
1154
+ * What our crawl last read of the domain's own home page, every member empty where it holds none. On a paid plan or the trial.
1155
1155
  */
1156
1156
  export type DomainWeb = {
1157
1157
  /**
@@ -1186,7 +1186,7 @@ export type DomainWebLinks = {
1186
1186
  hosts: Array<string>;
1187
1187
  };
1188
1188
  /**
1189
- * The registered domains whose home page redirects to this one, how many and the 10 most popular. Paid plans and the trial.
1189
+ * The registered domains whose home page redirects to this one, how many and the 10 most popular. On a paid plan or the trial.
1190
1190
  */
1191
1191
  export type DomainRedirects = {
1192
1192
  /**
@@ -1199,7 +1199,7 @@ export type DomainRedirects = {
1199
1199
  domains: Array<string>;
1200
1200
  };
1201
1201
  /**
1202
- * The registered domains whose home page links to this one, how many and the 10 most popular. Paid plans and the trial.
1202
+ * The registered domains whose home page links to this one, how many and the 10 most popular. On a paid plan or the trial.
1203
1203
  */
1204
1204
  export type DomainBacklinks = {
1205
1205
  /**
@@ -1212,7 +1212,7 @@ export type DomainBacklinks = {
1212
1212
  domains: Array<string>;
1213
1213
  };
1214
1214
  /**
1215
- * Its records in Domain DNS, up to 100 a type. Paid plans and the trial.
1215
+ * Its records in Domain DNS, up to 100 a type. On a paid plan or the trial.
1216
1216
  */
1217
1217
  export type DomainDns = {
1218
1218
  a: Array<DnsAddressRecord>;
@@ -1266,7 +1266,7 @@ export type DnsCnameRecord = {
1266
1266
  last_seen: string;
1267
1267
  };
1268
1268
  /**
1269
- * The organization's IP ranges, from Domain IP Ranges. Paid plans and the trial.
1269
+ * The organization's IP ranges, from Domain IP Ranges. On a paid plan or the trial.
1270
1270
  */
1271
1271
  export type DomainIpRanges = {
1272
1272
  /**
@@ -1407,7 +1407,8 @@ export type EntitlementPlan = {
1407
1407
  * The plan the organization is on, as an identifier that is never
1408
1408
  * renamed or reused: `free` for the free plan, or a paid plan's key.
1409
1409
  * Compare against it and show `name`. On `free`, usage counts its
1410
- * trial, the lookups answered with every field.
1410
+ * trial, the lookups answered with every field. The Data plan is a key
1411
+ * per quota, `data_1` to `data_7`, each named Data.
1411
1412
  *
1412
1413
  */
1413
1414
  key: string;
@@ -1450,11 +1451,15 @@ export type EntitlementUsage = {
1450
1451
  */
1451
1452
  hard_limit: number | null;
1452
1453
  /**
1453
- * When the current allowance period began.
1454
+ * When the current allowance period began. On the free plan, when
1455
+ * its trial began, or now before a first lookup starts it.
1456
+ *
1454
1457
  */
1455
1458
  window_start: string;
1456
1459
  /**
1457
- * When the allowance next resets.
1460
+ * When the allowance next resets. On the free plan, when its trial
1461
+ * ends, which it does once.
1462
+ *
1458
1463
  */
1459
1464
  window_end: string;
1460
1465
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { InternetData, DEFAULT_BASE_URL } from './client.js';
2
- export type { Options, CacheOptions, LookupOptions, BatchOptions } from './client.js';
2
+ export type { Options, CacheOptions, CallOptions, LookupOptions, BatchOptions } from './client.js';
3
3
  export type { CacheStore } from './store.js';
4
4
  export { OauthApi } from './oauth.js';
5
5
  export type { OauthOptions, AuthorizationUrlOptions, OauthMetadata, TokenResponse, Pkce } from './oauth.js';
package/dist/shapes.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export declare const LOOKUP_MEMBERS: readonly ["ip", "is_bogon", "is_tor", "is_relay", "is_bot", "is_anycast", "is_carrier", "is_satellite", "is_ssh", "is_smtp", "is_web", "is_dns_resolver", "is_bittorrent", "tor", "relay", "location", "asn", "company", "hostname", "abuse"];
1
+ export declare const LOOKUP_MEMBERS: readonly ["ip", "is_bogon", "is_tor", "is_relay", "is_anycast", "tor", "relay", "location", "asn", "company", "hostname", "abuse"];
2
2
  export declare const WEB_DETAIL_MEMBERS: readonly ["port", "tls_ok", "session_ok", "status_code", "server", "location", "title", "cert_subject_cn", "cert_subject_o", "cert_issuer_dn", "cert_browser_trusted", "tls_version", "first_seen", "last_seen"];
3
3
  export declare const LOCATION_MEMBERS: readonly ["continent", "continent_name", "country", "country_name", "timezone", "currency_code", "currency_name", "currency_symbol", "flag_emoji", "flag_unicode"];
4
- export declare const ASN_MEMBERS: readonly ["asn", "name", "domain", "type", "prefix", "country", "rpki_status"];
4
+ export declare const ASN_MEMBERS: readonly ["asn", "name", "domain", "prefix", "country", "rpki_status"];
5
5
  export declare const COMPANY_MEMBERS: readonly ["name", "domain"];
6
6
  export declare const USER_AGENT_VERDICT_MEMBERS: readonly ["agent", "kind", "verdict"];
7
7
  export declare const ABUSE_CONTACT_MEMBERS: readonly ["email"];
@@ -30,6 +30,8 @@ export declare const ENTITLEMENT_MEMBERS: readonly ["org_id", "apikey", "plan",
30
30
  export declare const ENTITLEMENT_APIKEY_MEMBERS: readonly ["id", "allowed_cidrs"];
31
31
  export declare const ENTITLEMENT_PLAN_MEMBERS: readonly ["key", "name", "tier"];
32
32
  export declare const ENTITLEMENT_USAGE_MEMBERS: readonly ["requests", "quota", "window_start", "window_end"];
33
+ export declare const PAID_FLAGS: readonly ["is_bot", "is_carrier", "is_satellite", "is_ssh", "is_smtp", "is_web", "is_dns_resolver", "is_bittorrent"];
34
+ export declare const ASN_NOT_NULL: readonly ["type"];
33
35
  type Kind = 'string' | 'integer' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'date-time';
34
36
  export declare const LOOKUP_TYPES: Record<string, Kind>;
35
37
  export declare const CLASS_DETAIL_TYPES: Record<string, Kind>;
package/dist/shapes.js CHANGED
@@ -3,8 +3,7 @@
3
3
  // generated types, so a member the spec adds fails the suite until it is here.
4
4
  import { hasMembers } from './transport.js';
5
5
  export const LOOKUP_MEMBERS = [
6
- 'ip', 'is_bogon', 'is_tor', 'is_relay', 'is_bot', 'is_anycast', 'is_carrier', 'is_satellite', 'is_ssh',
7
- 'is_smtp', 'is_web', 'is_dns_resolver', 'is_bittorrent', 'tor', 'relay', 'location', 'asn', 'company',
6
+ 'ip', 'is_bogon', 'is_tor', 'is_relay', 'is_anycast', 'tor', 'relay', 'location', 'asn', 'company',
8
7
  'hostname', 'abuse',
9
8
  ];
10
9
  export const WEB_DETAIL_MEMBERS = [
@@ -15,7 +14,7 @@ export const LOCATION_MEMBERS = [
15
14
  'continent', 'continent_name', 'country', 'country_name', 'timezone', 'currency_code', 'currency_name',
16
15
  'currency_symbol', 'flag_emoji', 'flag_unicode',
17
16
  ];
18
- export const ASN_MEMBERS = ['asn', 'name', 'domain', 'type', 'prefix', 'country', 'rpki_status'];
17
+ export const ASN_MEMBERS = ['asn', 'name', 'domain', 'prefix', 'country', 'rpki_status'];
19
18
  export const COMPANY_MEMBERS = ['name', 'domain'];
20
19
  export const USER_AGENT_VERDICT_MEMBERS = ['agent', 'kind', 'verdict'];
21
20
  export const ABUSE_CONTACT_MEMBERS = ['email'];
@@ -50,6 +49,11 @@ export const ENTITLEMENT_MEMBERS = ['org_id', 'apikey', 'plan', 'usage'];
50
49
  export const ENTITLEMENT_APIKEY_MEMBERS = ['id', 'allowed_cidrs'];
51
50
  export const ENTITLEMENT_PLAN_MEMBERS = ['key', 'name', 'tier'];
52
51
  export const ENTITLEMENT_USAGE_MEMBERS = ['requests', 'quota', 'window_start', 'window_end'];
52
+ // Members the spec no longer requires, which an answer may omit and may never send as null.
53
+ export const PAID_FLAGS = [
54
+ 'is_bot', 'is_carrier', 'is_satellite', 'is_ssh', 'is_smtp', 'is_web', 'is_dns_resolver', 'is_bittorrent',
55
+ ];
56
+ export const ASN_NOT_NULL = ['type'];
53
57
  const FLAG = 'boolean';
54
58
  export const LOOKUP_TYPES = {
55
59
  ip: 'string', is_bogon: FLAG, is_vpn: FLAG, is_tor: FLAG, is_relay: FLAG, is_resproxy: FLAG, is_dcproxy: FLAG,
@@ -229,10 +233,17 @@ function isDay(year, month, day) {
229
233
  return date.getUTCFullYear() === Number(year) && date.getUTCMonth() === Number(month) - 1
230
234
  && date.getUTCDate() === Number(day);
231
235
  }
232
- function typed(value, required, types) {
236
+ // A member in `notNull` may be absent but never null, as one the spec once required.
237
+ function typed(value, required, types, notNull = []) {
233
238
  return hasMembers(value, required) && Object.entries(types).every(([member, kind]) => {
234
239
  const v = value[member];
235
- return v === undefined || v === null ? !required.includes(member) : isKind(v, kind);
240
+ if (v === undefined) {
241
+ return !required.includes(member);
242
+ }
243
+ if (v === null) {
244
+ return !required.includes(member) && !notNull.includes(member);
245
+ }
246
+ return isKind(v, kind);
236
247
  });
237
248
  }
238
249
  function every(value, valid) {
@@ -261,16 +272,16 @@ const DETAILS = [
261
272
  ];
262
273
  // Required where the lookup itself requires them, and optional otherwise.
263
274
  const SHARED = [
264
- ['location', LOCATION_MEMBERS, LOCATION_TYPES],
265
- ['asn', ASN_MEMBERS, ASN_TYPES],
266
- ['company', COMPANY_MEMBERS, COMPANY_TYPES],
267
- ['abuse', ABUSE_CONTACT_MEMBERS, ABUSE_CONTACT_TYPES],
268
- ['whois', WHOIS_MEMBERS, WHOIS_TYPES],
269
- ['rwhois', RWHOIS_MEMBERS, RWHOIS_TYPES],
270
- ['hosted_domains', HOSTED_DOMAINS_MEMBERS, HOSTED_DOMAINS_TYPES],
275
+ ['location', LOCATION_MEMBERS, LOCATION_TYPES, []],
276
+ ['asn', ASN_MEMBERS, ASN_TYPES, ASN_NOT_NULL],
277
+ ['company', COMPANY_MEMBERS, COMPANY_TYPES, []],
278
+ ['abuse', ABUSE_CONTACT_MEMBERS, ABUSE_CONTACT_TYPES, []],
279
+ ['whois', WHOIS_MEMBERS, WHOIS_TYPES, []],
280
+ ['rwhois', RWHOIS_MEMBERS, RWHOIS_TYPES, []],
281
+ ['hosted_domains', HOSTED_DOMAINS_MEMBERS, HOSTED_DOMAINS_TYPES, []],
271
282
  ];
272
283
  export function isLookup(data) {
273
- return typed(data, LOOKUP_MEMBERS, LOOKUP_TYPES)
284
+ return typed(data, LOOKUP_MEMBERS, LOOKUP_TYPES, PAID_FLAGS)
274
285
  && DETAILS.every(([member, types]) => optional(data[member], (detail) => typed(detail, [], types)))
275
286
  && optional(data['pubproxy'], (pubproxy) => lists(pubproxy, 'protocols', isString))
276
287
  && optional(data['bittorrent'], (bittorrent) => lists(bittorrent, 'clients', isString))
@@ -278,7 +289,7 @@ export function isLookup(data) {
278
289
  && optional(data['user_agent'], (verdict) => typed(verdict, USER_AGENT_VERDICT_MEMBERS, USER_AGENT_VERDICT_TYPES))
279
290
  && optional(data['web'], (web) => every(web, (row) => typed(row, WEB_DETAIL_MEMBERS, WEB_DETAIL_TYPES)))
280
291
  && optional(data['hosted_domains'], (hosted) => lists(hosted, 'domains', isString))
281
- && SHARED.every(([member, required, types]) => optional(data[member], (object) => typed(object, required, types)));
292
+ && SHARED.every(([member, required, types, notNull]) => optional(data[member], (object) => typed(object, required, types, notNull)));
282
293
  }
283
294
  export function isAsnLookup(data) {
284
295
  return typed(data, ASN_LOOKUP_MEMBERS, ASN_LOOKUP_TYPES)
@@ -303,7 +314,7 @@ export function isDomainLookup(data) {
303
314
  && optional(data['disposable'], (d) => typed(d, [], DISPOSABLE_DETAIL_TYPES)
304
315
  && lists(d, 'providers', isString))
305
316
  && optional(data['hosting'], (hosting) => every(hosting, (h) => typed(h, DOMAIN_HOST_MEMBERS, DOMAIN_HOST_TYPES)
306
- && typed(h['asn'], ASN_MEMBERS, ASN_TYPES)))
317
+ && typed(h['asn'], ASN_MEMBERS, ASN_TYPES, ASN_NOT_NULL)))
307
318
  && optional(data['cohosted_domains'], (c) => typed(c, COHOSTED_DOMAINS_MEMBERS, COHOSTED_DOMAINS_TYPES)
308
319
  && every(c['domains'], isString))
309
320
  && optional(data['web'], (web) => typed(web, DOMAIN_WEB_MEMBERS, DOMAIN_WEB_TYPES)
package/dist/store.d.ts CHANGED
@@ -6,7 +6,9 @@ import { type Result } from './types.js';
6
6
  *
7
7
  * `key` is the address with a hash of the client's API key and base URL in front of
8
8
  * it, so clients holding different keys, and so entitled to different fields, can
9
- * share one store without ever reading each other's answers. `set` is handed how long
9
+ * share one store without ever reading each other's answers. A lookup sending a user
10
+ * agent appends it, `?user_agent=` and the agent percent-encoded, since its answer
11
+ * carries that agent's verdict. `set` is handed how long
10
12
  * the answer stays fresh; dropping it once that has passed is the store's job.
11
13
  */
12
14
  export interface CacheStore {
@@ -25,8 +27,8 @@ export declare class StoreTier {
25
27
  private readonly scope;
26
28
  private readonly ttlMs;
27
29
  constructor(store: CacheStore, scope: string, ttlMs: number);
28
- get(ip: string): Promise<Result | undefined>;
29
- set(ip: string, result: Result): Promise<void>;
30
+ get(ip: string, agent: string | undefined): Promise<Result | undefined>;
31
+ set(ip: string, agent: string | undefined, result: Result): Promise<void>;
30
32
  private keyFor;
31
33
  }
32
34
  /**
package/dist/store.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isLookup } from './shapes.js';
2
+ import { strictEncode } from './transport.js';
2
3
  import { toResult } from './types.js';
3
4
  /**
4
5
  * The client's side of a `CacheStore`. A store is a cache, never a source of
@@ -16,10 +17,10 @@ export class StoreTier {
16
17
  this.scope = scope;
17
18
  this.ttlMs = ttlMs;
18
19
  }
19
- async get(ip) {
20
+ async get(ip, agent) {
20
21
  let stored;
21
22
  try {
22
- stored = await this.store.get(this.keyFor(ip));
23
+ stored = await this.store.get(this.keyFor(ip, agent));
23
24
  }
24
25
  catch {
25
26
  return undefined;
@@ -30,16 +31,17 @@ export class StoreTier {
30
31
  const raw = stored.raw;
31
32
  return isLookup(raw) ? toResult(raw) : undefined;
32
33
  }
33
- async set(ip, result) {
34
+ async set(ip, agent, result) {
34
35
  try {
35
- await this.store.set(this.keyFor(ip), result, lifeMs(result, this.ttlMs));
36
+ await this.store.set(this.keyFor(ip, agent), result, lifeMs(result, this.ttlMs));
36
37
  }
37
38
  catch {
38
39
  // Costs a request on the next miss, nothing more.
39
40
  }
40
41
  }
41
- keyFor(ip) {
42
- return `${this.scope}:${ip}`;
42
+ keyFor(ip, agent) {
43
+ const key = `${this.scope}:${ip}`;
44
+ return agent === undefined ? key : `${key}?user_agent=${strictEncode(agent)}`;
43
45
  }
44
46
  }
45
47
  /**
@@ -48,4 +48,9 @@ export declare function checkConcurrency(concurrency: number | null | undefined)
48
48
  */
49
49
  export declare function deadline<T>(timeoutMs: number, fn: (signal: AbortSignal) => Promise<T>): Promise<T>;
50
50
  export declare function withRetry<T>(retries: number, fn: () => Promise<T>): Promise<T>;
51
+ /**
52
+ * `encodeURIComponent`, and `!'()*` too, so every reserved character goes out
53
+ * percent-encoded: `+` among them, which a server reads as a space.
54
+ */
55
+ export declare function strictEncode(value: string): string;
51
56
  export declare function asError(err: unknown): InternetDataError;
package/dist/transport.js CHANGED
@@ -135,6 +135,13 @@ export async function withRetry(retries, fn) {
135
135
  throw asError(err);
136
136
  }
137
137
  }
138
+ /**
139
+ * `encodeURIComponent`, and `!'()*` too, so every reserved character goes out
140
+ * percent-encoded: `+` among them, which a server reads as a space.
141
+ */
142
+ export function strictEncode(value) {
143
+ return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
144
+ }
138
145
  export function asError(err) {
139
146
  if (err instanceof InternetDataError) {
140
147
  return err;
package/dist/types.d.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  import type { AbuseContact, Asn as WireAsn, AsnHostedDomains, AsnLookupResponse, AsnPrefix, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, Company, CohostedDomains, DisposableDetail, DnsAddressRecord, DnsCnameRecord, DnsMxRecord, DnsNsRecord, DnsResolverDetail, DomainBacklinks, DomainDns, DomainHost as WireDomainHost, DomainIpRange, DomainIpRanges, DomainLookupResponse as WireDomainLookupResponse, DomainRedirects, DomainWeb, DomainWebLinks, Entitlement, EntitlementApikey, EntitlementPlan, EntitlementUsage, HostedDomains, Location, LookupResponse as WireLookupResponse, ProxyDetail, PubproxyDetail, Rwhois, SatelliteDetail, SmtpDetail, SshDetail, UserAgentVerdict, WebDetail, Whois } from './generated/types.gen.js';
2
2
  export type { AbuseContact, AsnHostedDomains, AsnLookupResponse, AsnPrefix, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, Company, CohostedDomains, DisposableDetail, DnsAddressRecord, DnsCnameRecord, DnsMxRecord, DnsNsRecord, DnsResolverDetail, DomainBacklinks, DomainDns, DomainIpRange, DomainIpRanges, DomainRedirects, DomainWeb, DomainWebLinks, Entitlement, EntitlementApikey, EntitlementPlan, EntitlementUsage, HostedDomains, Location, ProxyDetail, PubproxyDetail, Rwhois, SatelliteDetail, SmtpDetail, SshDetail, UserAgentVerdict, WebDetail, Whois, };
3
- /** The network announcing an address. Every answer carries `country` and `rpki_status`. */
4
- export type Asn = Omit<WireAsn, 'country' | 'rpki_status'> & Partial<Pick<WireAsn, 'country' | 'rpki_status'>>;
5
- /** A lookup's answer as it came off the wire. Every answer carries `is_bot`. */
6
- export type LookupResponse = Omit<WireLookupResponse, 'asn' | 'is_bot'> & {
3
+ type HeldFlag = 'is_carrier' | 'is_satellite' | 'is_ssh' | 'is_smtp' | 'is_web' | 'is_dns_resolver' | 'is_bittorrent';
4
+ /**
5
+ * The network announcing an address. Every answer carries `country` and `rpki_status`. `type` is a paid
6
+ * plan's: an Unlimited answer may omit it, though this type still says `string` until the next major.
7
+ */
8
+ export type Asn = Omit<WireAsn, 'country' | 'rpki_status' | 'type'> & Partial<Pick<WireAsn, 'country' | 'rpki_status'>> & Required<Pick<WireAsn, 'type'>>;
9
+ /**
10
+ * A lookup's answer as it came off the wire. `is_bot` is optional here, and the seven flags after it are
11
+ * typed `boolean` until the next major although an Unlimited answer omits them: read them from `Result`,
12
+ * where an absent one is `false`.
13
+ */
14
+ export type LookupResponse = Omit<WireLookupResponse, 'asn' | 'is_bot' | HeldFlag> & {
7
15
  asn: Asn;
8
- } & Partial<Pick<WireLookupResponse, 'is_bot'>>;
16
+ } & Partial<Pick<WireLookupResponse, 'is_bot'>> & Required<Pick<WireLookupResponse, HeldFlag>>;
9
17
  /** An address the domain resolves to, and the network announcing it. */
10
18
  export type DomainHost = Omit<WireDomainHost, 'asn'> & {
11
19
  asn: Asn;
@@ -43,11 +51,14 @@ export interface Result {
43
51
  isCdn?: boolean;
44
52
  /**
45
53
  * In Bot IP: an automated client's address, such as a search engine's or an AI
46
- * company's crawler. Every answer carries it, on every plan; `bot` says whose.
47
- * Optional in this type only so a `Result` written out by hand still compiles.
54
+ * company's crawler. On a paid plan or the trial; absent on Unlimited. `bot` says whose.
48
55
  */
49
56
  isBot?: boolean;
50
57
  isAnycast: boolean;
58
+ /**
59
+ * In Carrier IP, as the six flags after it are each in their own dataset: on a paid plan or the
60
+ * trial. Unlimited's answer omits them, and they read `false` there rather than absent until the next major.
61
+ */
51
62
  isCarrier: boolean;
52
63
  isSatellite: boolean;
53
64
  isSsh: boolean;
package/dist/types.js CHANGED
@@ -30,8 +30,17 @@ const DOMAIN_RESULT_NAMES = {
30
30
  web: 'web', redirects: 'redirects', backlinks: 'backlinks', trial_expired: 'trialExpired',
31
31
  cap_reached: 'capReached',
32
32
  };
33
+ // Typed `boolean` on `Result` until the next major, so an answer without one reads `false`, as every
34
+ // Unlimited answer said before 2026-11-26. `raw` still shows what was served.
35
+ const HELD_FLAGS = [
36
+ 'isCarrier', 'isSatellite', 'isSsh', 'isSmtp', 'isWeb', 'isDnsResolver', 'isBittorrent',
37
+ ];
33
38
  export function toResult(body) {
34
- return renamed(body, RESULT_NAMES);
39
+ const result = renamed(body, RESULT_NAMES);
40
+ for (const flag of HELD_FLAGS) {
41
+ result[flag] ??= false;
42
+ }
43
+ return result;
35
44
  }
36
45
  export function toAsnResult(body) {
37
46
  return renamed(body, ASN_RESULT_NAMES);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "internetdata-web",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Official browser client library for the InternetData API. Look up IP addresses, ASNs and domains from a page or a browser extension.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -53,8 +53,8 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@hey-api/openapi-ts": "^0.99.0",
56
- "@mslmio/eslint-config": "^1.1.0",
57
- "eslint": "^10.10.0",
56
+ "@mslmio/eslint-config": "^2.6.2",
57
+ "eslint": "^10.15.0",
58
58
  "playwright-core": "1.62.1",
59
59
  "typescript": "^6.0.3"
60
60
  },