vpndetection-web 1.6.1 → 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 `ip`, `is_vpn`, Tor and relay detection, `is_anycast`, `hostname` (the reverse DNS name), country-level `location` and `asn` with the AS's country and RPKI status, 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 `ip`, `is_vpn`, Tor and relay detection, `is_bot` (whether a bot such as a crawler uses the address), `is_anycast`, `hostname` (the reverse DNS name), country-level `location` and `asn` with the AS's country and RPKI status, 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 { VPNDetection } from 'vpndetection-web';
@@ -48,7 +48,7 @@ console.log(result.asn?.name); // who runs the announcing network
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_hosting`, `is_cdn` and the four proxy flags as well, the carrier and satellite flags, the five service flags (SSH, SMTP, web, DNS resolver and BitTorrent), city-level `location`, the `company` and the `abuse` contact, and the provider (its ID and its name), confidence and last-seen 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.vpndetection.io), then pass it in:
51
+ Where the key stays private (see above), every paid plan answers every field: `is_hosting`, `is_cdn` and the four proxy flags as well, the carrier and satellite flags, the five service flags (SSH, SMTP, web, DNS resolver and BitTorrent), `bot` (whose bot it is and whether its operator vouches for the address), `user_agent` (whether a user agent you send is borne out by the address: see below), city-level `location`, the `company` and the `abuse` contact, and the provider (its ID and its name), confidence and last-seen 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.vpndetection.io), then pass it in:
52
52
 
53
53
  ```js
54
54
  const client = new VPNDetection({ apiKey: 'your-api-key' });
@@ -70,6 +70,25 @@ console.log(result.ip); // the address we saw this call come from: in a page,
70
70
 
71
71
  It is never cached, since which address the browser is calling from is the question, and a laptop moves between networks.
72
72
 
73
+ ### A visitor's user agent
74
+
75
+ 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.
76
+
77
+ ```js
78
+ const result = await client.lookup('66.249.66.1', {
79
+ userAgent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
80
+ });
81
+ console.log(result.userAgent); // { agent: 'Googlebot', kind: 'bot', verdict: 'verified' }
82
+
83
+ const mine = await client.myIp({ userAgent: navigator.userAgent });
84
+
85
+ const results = await client.lookupBatch(['66.249.66.1', '45.83.91.1'], {
86
+ userAgents: { '66.249.66.1': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' },
87
+ });
88
+ ```
89
+
90
+ `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.
91
+
73
92
  ### Your plan and usage
74
93
 
75
94
  ```js
@@ -122,7 +141,7 @@ const result2 = await client.lookup('45.83.91.1');
122
141
  console.log(result2.isVpn); // true, no API request, result was cached
123
142
  ```
124
143
 
125
- You can change the default cache variables (max size, TTL, etc) on initialization, or even disable it:
144
+ You can change the default cache variables (max size, TTL, etc) on initialization, or even disable it. Each is a whole number from 1:
126
145
 
127
146
  ```js
128
147
  const client = new VPNDetection({ cache: { max: 50_000, ttlMs: 6 * 60 * 60 * 1000 } });
@@ -166,7 +185,7 @@ const store = {
166
185
  const client = new VPNDetection({ cache: { store: store } });
167
186
  ```
168
187
 
169
- `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` and `myEntitlement` 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.
188
+ `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` and `myEntitlement` 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.
170
189
 
171
190
  ### Private and reserved addresses
172
191
 
@@ -251,7 +270,7 @@ The library is ES2022 and needs only what a browser has, `fetch` and, for PKCE,
251
270
 
252
271
  ### Absent is not false
253
272
 
254
- Unlimited leaves out `isHosting`, `isCdn`, the four proxy flags, the carrier, satellite and service flags, `company` and `abuse`, and of the detail behind each flag it answers only Tor's and relay's; a free-plan key's answer carries `trialExpired`, true once its trial is spent, and a paid key's carries `capReached`, true once its organization's overage cap is reached and the answer has Unlimited's. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no".
273
+ Unlimited leaves out `isHosting`, `isCdn`, the four proxy flags, the carrier, satellite and service flags, `bot`, `company` and `abuse`, and of the detail behind each flag it answers only Tor's and relay's; a free-plan key's answer carries `trialExpired`, true once its trial is spent, and a paid key's carries `capReached`, true once its organization's overage cap is reached and the answer has Unlimited's. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no".
255
274
 
256
275
  ```js
257
276
  result.isHosting ?? false // when you only want the flag
package/dist/bogon.js CHANGED
@@ -64,6 +64,7 @@ export function bogonResult(ip) {
64
64
  isWeb: false,
65
65
  isDnsResolver: false,
66
66
  isBittorrent: false,
67
+ isBot: false,
67
68
  vpn: {},
68
69
  hosting: {},
69
70
  relay: {},
@@ -80,6 +81,7 @@ export function bogonResult(ip) {
80
81
  web: [],
81
82
  dnsResolver: {},
82
83
  bittorrent: {},
84
+ bot: {},
83
85
  location: {
84
86
  continent: '',
85
87
  continent_name: '',
package/dist/client.d.ts CHANGED
@@ -43,17 +43,32 @@ export interface Options {
43
43
  /** Override the HTTP implementation, mostly for tests. Defaults to the global `fetch`. */
44
44
  fetch?: typeof globalThis.fetch;
45
45
  }
46
- /** Per-call overrides for a single lookup. Anything omitted falls back to the client's setting. */
47
- export interface LookupOptions {
46
+ /** Per-call overrides for one call. Anything omitted falls back to the client's setting. */
47
+ export interface CallOptions {
48
48
  /** Retry attempts for a transient failure, a whole number from 0. */
49
49
  retries?: number;
50
50
  /** How long one attempt may take before it is abandoned, in milliseconds. */
51
51
  timeoutMs?: number;
52
52
  }
53
+ /** Per-call options for `lookup` and `myIp`. */
54
+ export interface LookupOptions extends CallOptions {
55
+ /**
56
+ * The `User-Agent` of the client that came from this address. With every field, on a paid
57
+ * plan or the trial, the answer's `userAgent` then names the agent it claims to be and whether
58
+ * this address bears that out. The empty string sends none, and a longer one than the API's
59
+ * 1024 characters is sent whole for the API to cut.
60
+ */
61
+ userAgent?: string;
62
+ }
53
63
  /** Per-call overrides for one batch. Anything omitted falls back to the client's setting. */
54
- export interface BatchOptions extends LookupOptions {
64
+ export interface BatchOptions extends CallOptions {
55
65
  /** Concurrent batch requests for THIS batch only. */
56
66
  concurrency?: number;
67
+ /**
68
+ * Each address's `User-Agent`, keyed by the address as you pass it in `ips`, sent as
69
+ * `lookup`'s `userAgent` is. An address left out, or given the empty string, sends none.
70
+ */
71
+ userAgents?: Readonly<Record<string, string>> | ReadonlyMap<string, string>;
57
72
  }
58
73
  /**
59
74
  * A client for the VPNDetection API, for a browser: a page's own scripts, a web
@@ -96,6 +111,10 @@ export declare class VPNDetection {
96
111
  * call that led it. An IPv4-mapped address (`::ffff:8.8.8.8`) is the IPv4
97
112
  * address it carries: judged, sent and cached as that, so the answer names
98
113
  * `8.8.8.8`.
114
+ *
115
+ * With `userAgent`, the answer is cached, stored and shared on the address and
116
+ * that agent together: apart from the address's plain answer and from another
117
+ * agent's. A bogon's answer carries no `userAgent`.
99
118
  */
100
119
  lookup(ip: string, options?: LookupOptions): Promise<Result>;
101
120
  private answer;
@@ -111,7 +130,8 @@ export declare class VPNDetection {
111
130
  *
112
131
  * Deliberately NOT cached. The cache is keyed by address, and which
113
132
  * address this is IS the question: a device that moves between networks
114
- * would otherwise be told where it used to be.
133
+ * would otherwise be told where it used to be. `userAgent` is sent as
134
+ * `lookup` sends it.
115
135
  */
116
136
  myIp(options?: LookupOptions): Promise<Result>;
117
137
  /**
@@ -133,7 +153,7 @@ export declare class VPNDetection {
133
153
  * Deliberately NOT cached: the whole point is what has been spent, and a
134
154
  * cached answer is a wrong one within seconds of the next request.
135
155
  */
136
- myEntitlement(options?: LookupOptions): Promise<Entitlement>;
156
+ myEntitlement(options?: CallOptions): Promise<Entitlement>;
137
157
  /**
138
158
  * Classify many addresses in as few requests as possible.
139
159
  *
@@ -155,6 +175,12 @@ export declare class VPNDetection {
155
175
  * `unauthorized` error, and a free-plan key's request of two or more a
156
176
  * `bad_request` (HTTP 402). A request of one address is answered as its
157
177
  * lookup would be.
178
+ *
179
+ * `userAgents` sends each address's agent, as `user_agents` keyed by the address
180
+ * as the request sends it (an IPv4-mapped one as the IPv4 address it carries),
181
+ * and only in a request where one of its addresses has one. Each address's
182
+ * answer is cached, stored and shared on the address and its agent together,
183
+ * as `lookup`'s is.
158
184
  */
159
185
  lookupBatch(ips: Iterable<string>, options?: BatchOptions): Promise<Map<string, Result | VPNDetectionError>>;
160
186
  private unstored;
package/dist/client.js CHANGED
@@ -7,7 +7,7 @@ import { errorFromEntry, VPNDetectionError } from './errors.js';
7
7
  import { OauthApi } from './oauth.js';
8
8
  import { isBatch, isBatchError, 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 { toResult } from './types.js';
12
12
  export const DEFAULT_BASE_URL = 'https://api.vpndetection.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 VPNDetection {
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;
@@ -100,35 +102,42 @@ export class VPNDetection {
100
102
  * call that led it. An IPv4-mapped address (`::ffff:8.8.8.8`) is the IPv4
101
103
  * address it carries: judged, sent and cached as that, so the answer names
102
104
  * `8.8.8.8`.
105
+ *
106
+ * With `userAgent`, the answer is cached, stored and shared on the address and
107
+ * that agent together: apart from the address's plain answer and from another
108
+ * agent's. A bogon's answer carries no `userAgent`.
103
109
  */
104
110
  async lookup(ip, options = {}) {
105
111
  // First, or a bogon and a cached address would answer any value.
106
112
  checkTimeout(options.timeoutMs);
107
113
  checkRetries(options.retries);
114
+ const agent = checkUserAgent(options.userAgent);
108
115
  const addr = unmapped(ip);
109
116
  if (isBogon(addr)) {
110
117
  return bogonResult(addr);
111
118
  }
112
119
  if (this.cache === null) {
113
- return this.serve(addr, options);
120
+ return this.serve(addr, agent, options);
114
121
  }
115
- return (await this.cache.fetch(addr, { context: () => this.answer(addr, options) }));
122
+ return (await this.cache.fetch(cacheKey(addr, agent), {
123
+ context: () => this.answer(addr, agent, options),
124
+ }));
116
125
  }
117
126
  // A miss in memory: the store's answer if it holds one, else the API's, kept.
118
- async answer(ip, options) {
119
- const stored = await this.store?.get(ip);
127
+ async answer(ip, agent, options) {
128
+ const stored = await this.store?.get(ip, agent);
120
129
  if (stored !== undefined) {
121
130
  return stored;
122
131
  }
123
- const served = await this.serve(ip, options);
124
- await this.store?.set(ip, served);
132
+ const served = await this.serve(ip, agent, options);
133
+ await this.store?.set(ip, agent, served);
125
134
  return served;
126
135
  }
127
- async serve(ip, options) {
136
+ async serve(ip, agent, options) {
128
137
  const timeoutMs = options.timeoutMs ?? this.timeoutMs;
129
138
  return withRetry(options.retries ?? this.retries, async () => {
130
139
  const res = await deadline(timeoutMs, (signal) => lookupIp({
131
- client: this.client, path: { ip: ip }, signal: signal,
140
+ client: this.client, path: { ip: ip }, signal: signal, ...agentQuery(agent),
132
141
  }));
133
142
  return toResult(readable(res, isLookup));
134
143
  });
@@ -144,13 +153,16 @@ export class VPNDetection {
144
153
  *
145
154
  * Deliberately NOT cached. The cache is keyed by address, and which
146
155
  * address this is IS the question: a device that moves between networks
147
- * would otherwise be told where it used to be.
156
+ * would otherwise be told where it used to be. `userAgent` is sent as
157
+ * `lookup` sends it.
148
158
  */
149
159
  async myIp(options = {}) {
150
160
  const timeoutMs = checkTimeout(options.timeoutMs) ?? this.timeoutMs;
151
- return withRetry(checkRetries(options.retries) ?? this.retries, async () => {
161
+ const retries = checkRetries(options.retries) ?? this.retries;
162
+ const agent = checkUserAgent(options.userAgent);
163
+ return withRetry(retries, async () => {
152
164
  const res = await deadline(timeoutMs, (signal) => lookupMyIp({
153
- client: this.client, signal: signal,
165
+ client: this.client, signal: signal, ...agentQuery(agent),
154
166
  }));
155
167
  return toResult(readable(res, isLookup));
156
168
  });
@@ -204,11 +216,18 @@ export class VPNDetection {
204
216
  * `unauthorized` error, and a free-plan key's request of two or more a
205
217
  * `bad_request` (HTTP 402). A request of one address is answered as its
206
218
  * lookup would be.
219
+ *
220
+ * `userAgents` sends each address's agent, as `user_agents` keyed by the address
221
+ * as the request sends it (an IPv4-mapped one as the IPv4 address it carries),
222
+ * and only in a request where one of its addresses has one. Each address's
223
+ * answer is cached, stored and shared on the address and its agent together,
224
+ * as `lookup`'s is.
207
225
  */
208
226
  async lookupBatch(ips, options = {}) {
209
227
  const concurrency = checkConcurrency(options.concurrency);
210
228
  checkTimeout(options.timeoutMs);
211
229
  checkRetries(options.retries);
230
+ const agents = checkUserAgents(options.userAgents);
212
231
  const asked = [...new Set(ips)];
213
232
  const unique = [...new Set(asked.map(unmapped))];
214
233
  const out = new Map();
@@ -224,7 +243,8 @@ export class VPNDetection {
224
243
  out.set(ip, bogonResult(ip));
225
244
  continue;
226
245
  }
227
- const hit = this.cache?.get(ip);
246
+ const key = cacheKey(ip, agents.get(ip));
247
+ const hit = this.cache?.get(key);
228
248
  if (hit !== undefined) {
229
249
  out.set(ip, hit);
230
250
  continue;
@@ -233,7 +253,7 @@ export class VPNDetection {
233
253
  pending.push(ip);
234
254
  continue;
235
255
  }
236
- shared.push([ip, this.cache.fetch(ip, {
256
+ shared.push([ip, this.cache.fetch(key, {
237
257
  context: () => {
238
258
  const landing = deferred();
239
259
  led.set(ip, landing);
@@ -242,7 +262,7 @@ export class VPNDetection {
242
262
  },
243
263
  })]);
244
264
  }
245
- const sending = this.store === null ? pending : await this.unstored(pending, led);
265
+ const sending = this.store === null ? pending : await this.unstored(pending, agents, led);
246
266
  // A per-call concurrency gets its own limiter; without one the call
247
267
  // would share the instance's budget and silently ignore the override.
248
268
  const limit = concurrency === undefined ? this.limit : pLimit(concurrency);
@@ -253,7 +273,7 @@ export class VPNDetection {
253
273
  await Promise.all([
254
274
  ...chunks.map((chunk) => limit(async () => {
255
275
  const kept = [];
256
- for (const [ip, answer] of await this.lookupChunk(chunk, options)) {
276
+ for (const [ip, answer] of await this.lookupChunk(chunk, agents, options)) {
257
277
  const landing = led.get(ip);
258
278
  if (landing === undefined) {
259
279
  out.set(ip, answer);
@@ -265,7 +285,7 @@ export class VPNDetection {
265
285
  landing.resolve(answer);
266
286
  }
267
287
  if (this.store !== null && !(answer instanceof VPNDetectionError)) {
268
- kept.push(this.store.set(ip, answer));
288
+ kept.push(this.store.set(ip, agents.get(ip), answer));
269
289
  }
270
290
  }
271
291
  await Promise.all(kept);
@@ -286,8 +306,8 @@ export class VPNDetection {
286
306
  }
287
307
  // The addresses this batch leads that the store does not hold, in the order
288
308
  // given. One the store holds lands at once, as a request's answer would.
289
- async unstored(ips, led) {
290
- const stored = await Promise.all(ips.map((ip) => this.store.get(ip)));
309
+ async unstored(ips, agents, led) {
310
+ const stored = await Promise.all(ips.map((ip) => this.store.get(ip, agents.get(ip))));
291
311
  return ips.filter((ip, i) => {
292
312
  const hit = stored[i];
293
313
  if (hit === undefined) {
@@ -301,14 +321,15 @@ export class VPNDetection {
301
321
  // chunk-level failure - the call refused, the transport failing, the
302
322
  // retries exhausted - becomes every address's error, exactly as it would
303
323
  // have been had each been looked up alone.
304
- async lookupChunk(chunk, options) {
324
+ async lookupChunk(chunk, agents, options) {
305
325
  const out = new Map();
306
326
  const timeoutMs = options.timeoutMs ?? this.timeoutMs;
327
+ const request = batchRequest(chunk, agents);
307
328
  let body;
308
329
  try {
309
330
  body = await withRetry(options.retries ?? this.retries, async () => {
310
331
  const res = await deadline(timeoutMs, (signal) => lookupBatch({
311
- client: this.client, body: { ips: chunk }, signal: signal,
332
+ client: this.client, body: request, signal: signal,
312
333
  }));
313
334
  return readable(res, isBatch);
314
335
  });
@@ -388,6 +409,63 @@ function checkCacheOption(name, value) {
388
409
  }
389
410
  return value;
390
411
  }
412
+ /** The agent a call sends, `undefined` for none: the empty string is none, as the API reads `user_agent=`. */
413
+ function checkUserAgent(userAgent) {
414
+ if (userAgent === undefined || userAgent === null || userAgent === '') {
415
+ return undefined;
416
+ }
417
+ if (typeof userAgent !== 'string') {
418
+ throw new VPNDetectionError('bad_request', `userAgent must be a string, got ${typeof userAgent}`);
419
+ }
420
+ return userAgent;
421
+ }
422
+ /** A batch's user agents, keyed by each address as the batch sends it, every empty one dropped. */
423
+ function checkUserAgents(userAgents) {
424
+ const agents = new Map();
425
+ if (userAgents === undefined || userAgents === null) {
426
+ return agents;
427
+ }
428
+ if (typeof userAgents !== 'object') {
429
+ throw new VPNDetectionError('bad_request', `userAgents must map addresses to agents, got ${typeof userAgents}`);
430
+ }
431
+ const entries = userAgents instanceof Map ? [...userAgents.entries()] : Object.entries(userAgents);
432
+ for (const [ip, agent] of entries) {
433
+ const checked = checkUserAgent(agent);
434
+ if (checked !== undefined) {
435
+ agents.set(unmapped(String(ip)), checked);
436
+ }
437
+ }
438
+ return agents;
439
+ }
440
+ // An answer to an address with an agent carries that agent's verdict, so it is
441
+ // never served for the address alone or for another agent. The address alone
442
+ // stays the key of a lookup sending none.
443
+ function cacheKey(ip, agent) {
444
+ return agent === undefined ? ip : JSON.stringify([ip, agent]);
445
+ }
446
+ /**
447
+ * One chunk's body: `user_agents` only when an address of THIS chunk has one, never
448
+ * `{}`, keyed by each address exactly as `ips` sends it.
449
+ */
450
+ function batchRequest(chunk, agents) {
451
+ const sent = chunk.filter((ip) => agents.has(ip)).map((ip) => [ip, agents.get(ip)]);
452
+ return sent.length === 0 ? { ips: chunk } : { ips: chunk, user_agents: Object.fromEntries(sent) };
453
+ }
454
+ /**
455
+ * The query a lookup sends its agent in, every reserved character percent-encoded,
456
+ * `+` among them, which a server reads as a space. Set by hand, so nothing checks
457
+ * the spec's 1024-character bound before the API cuts it.
458
+ */
459
+ function agentQuery(agent) {
460
+ if (agent === undefined) {
461
+ return {};
462
+ }
463
+ return { query: { user_agent: agent }, querySerializer: strictQuery };
464
+ }
465
+ function strictQuery(query) {
466
+ return Object.entries(query).filter(([, value]) => value !== undefined && value !== null)
467
+ .map(([name, value]) => `${strictEncode(name)}=${strictEncode(String(value))}`).join('&');
468
+ }
391
469
  function unreadableEntry(ip) {
392
470
  return new VPNDetectionError('server_error', `unreadable batch answer for ${ip}, status 200`, 200);
393
471
  }
@@ -1,2 +1,2 @@
1
1
  export { lookupBatch, lookupIp, lookupMyIp, myEntitlement, oauthMetadata, oauthRevoke, oauthToken, type Options } from './sdk.gen.js';
2
- export type { AbuseContact, Asn, BatchLookupError, BatchLookupRequest, BatchLookupResponse, BitTorrentDetail, CarrierDetail, ClassDetail, ClientOptions, Company, DnsResolverDetail, Entitlement, EntitlementApikey, EntitlementError, EntitlementPlan, EntitlementUsage, Location, LookupBatchData, LookupBatchError, LookupBatchErrors, LookupBatchResponse, LookupBatchResponses, LookupError, LookupIpData, LookupIpError, LookupIpErrors, LookupIpResponse, LookupIpResponses, LookupMyIpData, LookupMyIpError, LookupMyIpErrors, LookupMyIpResponse, LookupMyIpResponses, LookupResponse, MyEntitlementData, MyEntitlementError, MyEntitlementErrors, MyEntitlementResponse, MyEntitlementResponses, OauthError, OauthMetadata, OauthMetadataData, OauthMetadataResponse, OauthMetadataResponses, OauthRevokeData, OauthRevokeResponse, OauthRevokeResponses, OauthTokenData, OauthTokenError, OauthTokenErrors, OauthTokenResponse, OauthTokenResponses, ProxyDetail, PubproxyDetail, RevokeRequest, SatelliteDetail, SmtpDetail, SshDetail, TokenRequest, TokenResponse, VpnDetail, WebDetail } from './types.gen.js';
2
+ export type { AbuseContact, Asn, BatchLookupError, BatchLookupRequest, BatchLookupResponse, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, ClientOptions, Company, DnsResolverDetail, Entitlement, EntitlementApikey, EntitlementError, EntitlementPlan, EntitlementUsage, Location, LookupBatchData, LookupBatchError, LookupBatchErrors, LookupBatchResponse, LookupBatchResponses, LookupError, LookupIpData, LookupIpError, LookupIpErrors, LookupIpResponse, LookupIpResponses, LookupMyIpData, LookupMyIpError, LookupMyIpErrors, LookupMyIpResponse, LookupMyIpResponses, LookupResponse, MyEntitlementData, MyEntitlementError, MyEntitlementErrors, MyEntitlementResponse, MyEntitlementResponses, OauthError, OauthMetadata, OauthMetadataData, OauthMetadataResponse, OauthMetadataResponses, OauthRevokeData, OauthRevokeResponse, OauthRevokeResponses, OauthTokenData, OauthTokenError, OauthTokenErrors, OauthTokenResponse, OauthTokenResponses, ProxyDetail, PubproxyDetail, RevokeRequest, SatelliteDetail, SmtpDetail, SshDetail, TokenRequest, TokenResponse, UserAgentVerdict, VpnDetail, WebDetail } from './types.gen.js';
@@ -45,6 +45,10 @@ export type LookupResponse = {
45
45
  * Whether the address belongs to a CDN. Paid plans.
46
46
  */
47
47
  is_cdn?: boolean;
48
+ /**
49
+ * Whether an automated client uses the 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. Every answer, with or without a key.
50
+ */
51
+ is_bot?: boolean;
48
52
  /**
49
53
  * Whether the address was seen in a residential proxy pool. Paid plans.
50
54
  */
@@ -117,6 +121,10 @@ export type LookupResponse = {
117
121
  * Detail for `is_cdn`. Empty when false. Paid plans.
118
122
  */
119
123
  cdn?: ClassDetail;
124
+ /**
125
+ * Detail for `is_bot`. Empty when false. Paid plans.
126
+ */
127
+ bot?: BotDetail;
120
128
  /**
121
129
  * Detail for `is_resproxy`. Empty when false. Paid plans.
122
130
  */
@@ -169,6 +177,12 @@ export type LookupResponse = {
169
177
  */
170
178
  hostname?: string;
171
179
  abuse?: AbuseContact;
180
+ /**
181
+ * When the request sent `user_agent`, with every field: the agent it
182
+ * names and whether this address bears it out. Absent otherwise.
183
+ *
184
+ */
185
+ user_agent?: UserAgentVerdict;
172
186
  /**
173
187
  * On every answer to a key on the free plan, and on no other: `false`
174
188
  * while its organization's trial of every field lasts, `true` once the
@@ -193,6 +207,15 @@ export type BatchLookupRequest = {
193
207
  *
194
208
  */
195
209
  ips: Array<string>;
210
+ /**
211
+ * Each address's `User-Agent`, keyed by the string it is sent as in
212
+ * `ips`. With every field, that address's answer then carries
213
+ * `user_agent`, as a single lookup's does. Never kept.
214
+ *
215
+ */
216
+ user_agents?: {
217
+ [key: string]: string;
218
+ };
196
219
  };
197
220
  export type BatchLookupResponse = {
198
221
  /**
@@ -514,11 +537,78 @@ export type Asn = {
514
537
  /**
515
538
  * The country the AS's registry assigned it to.
516
539
  */
517
- country?: string;
540
+ country: string;
518
541
  /**
519
542
  * The announcement's RPKI status: valid, invalid or not_found.
520
543
  */
521
- rpki_status?: string;
544
+ rpki_status: string;
545
+ };
546
+ export type UserAgentVerdict = {
547
+ /**
548
+ * The agent the user agent names, such as `Googlebot` or `Chrome`; `Unknown` where it names none.
549
+ */
550
+ agent: string;
551
+ /**
552
+ * `browser`, `inapp`, `automation`, `bot`, `ai-bot`, `http-client` or
553
+ * `unknown`: what kind of client the user agent says it is.
554
+ *
555
+ */
556
+ kind: string;
557
+ /**
558
+ * `verified`: the agent's operator vouches for this address as it.
559
+ * `spoofed`: the operator of a bot that publishes its addresses, or
560
+ * whose registered space it uses, does not vouch for this one, or this
561
+ * address posed as the bot before. `unverifiable`: a bot no published
562
+ * list or registered space can confirm. `not_bot`: a browser, an app or
563
+ * a script.
564
+ *
565
+ */
566
+ verdict: 'verified' | 'spoofed' | 'unverifiable' | 'not_bot';
567
+ };
568
+ /**
569
+ * Bot IP's row: whose bot uses the address, the bots it serves or claimed to be, what they do, and how that is known.
570
+ */
571
+ export type BotDetail = {
572
+ /**
573
+ * The bot operator's ID; for an address that is not verified, the operator its claim named. Empty where no operator is known.
574
+ */
575
+ provider?: string;
576
+ /**
577
+ * That operator's name, empty where no operator is known.
578
+ */
579
+ provider_name?: string;
580
+ /**
581
+ * The bots the address serves, as their user agents name them (`Googlebot`, `GPTBot`); for an address that is not verified, the bots it claimed to be. One address can serve several, and `[]` means none is named.
582
+ */
583
+ agents?: Array<string>;
584
+ /**
585
+ * What those bots do: `search_engine`, `ai_training`, `ai_search`, `ai_assistant`, `ai_agent`, `seo`, `ads`, `preview`, `feed`, `monitoring`, `archiver`, `scanner`, `link_security`, `webhook` or `other`; `[]` where unknown.
586
+ */
587
+ categories?: Array<string>;
588
+ /**
589
+ * Whether the operator vouches for the address, so the bots in `agents` really are its.
590
+ */
591
+ verified?: boolean;
592
+ /**
593
+ * `verified` (the operator vouches for the address), `declared` (it names itself a bot that cannot be verified), `spoofed` (it claimed a bot whose operator vouches for other addresses) or `undeclared` (it hides as a browser and behaves as automation).
594
+ */
595
+ identity?: string;
596
+ /**
597
+ * How a verified address verified: `list` (the operator publishes it), `rdns` (its reverse DNS name ends in a suffix the operator documents and resolves back) or `owner` (the operator's own space, seen claiming its bot); empty when not verified.
598
+ */
599
+ verified_by?: string;
600
+ /**
601
+ * `high`, `medium` or `low`: how sure we are the address is what the row says.
602
+ */
603
+ confidence?: string;
604
+ /**
605
+ * The first day the address was seen as such.
606
+ */
607
+ first_seen?: string;
608
+ /**
609
+ * The last day it was.
610
+ */
611
+ last_seen?: string;
522
612
  };
523
613
  /**
524
614
  * The mobile network whose space the address is, from our Carrier IP
@@ -1066,7 +1156,16 @@ export type LookupIpData = {
1066
1156
  */
1067
1157
  ip: string;
1068
1158
  };
1069
- query?: never;
1159
+ query?: {
1160
+ /**
1161
+ * The `User-Agent` header of the request you are deciding on. With
1162
+ * every field, on a paid plan or the trial, the answer then carries
1163
+ * `user_agent`: the agent it names, and whether this address bears
1164
+ * that out. Never kept, and nothing sent with a lookup feeds our data.
1165
+ *
1166
+ */
1167
+ user_agent?: string;
1168
+ };
1070
1169
  url: '/{ip}';
1071
1170
  };
1072
1171
  export type LookupIpErrors = {
@@ -1112,7 +1211,16 @@ export type LookupIpResponse = LookupIpResponses[keyof LookupIpResponses];
1112
1211
  export type LookupMyIpData = {
1113
1212
  body?: never;
1114
1213
  path?: never;
1115
- query?: never;
1214
+ query?: {
1215
+ /**
1216
+ * The `User-Agent` header of the request you are deciding on. With
1217
+ * every field, on a paid plan or the trial, the answer then carries
1218
+ * `user_agent`: the agent it names, and whether this address bears
1219
+ * that out. Never kept, and nothing sent with a lookup feeds our data.
1220
+ *
1221
+ */
1222
+ user_agent?: string;
1223
+ };
1116
1224
  url: '/myip';
1117
1225
  };
1118
1226
  export type LookupMyIpErrors = {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export { VPNDetection, 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';
6
6
  export { isBogon } from './bogon.js';
7
7
  export { VPNDetectionError, OauthError, OauthAccessDeniedError, OauthExpiredTokenError, } from './errors.js';
8
8
  export type { ErrorKind } from './errors.js';
9
- export type { Result, VpnDetail, ClassDetail, ProxyDetail, PubproxyDetail, CarrierDetail, SatelliteDetail, SshDetail, SmtpDetail, WebDetail, DnsResolverDetail, BitTorrentDetail, Location, Asn, Company, AbuseContact, LookupResponse, } from './types.js';
9
+ export type { Result, VpnDetail, ClassDetail, ProxyDetail, PubproxyDetail, CarrierDetail, SatelliteDetail, SshDetail, SmtpDetail, WebDetail, DnsResolverDetail, BitTorrentDetail, BotDetail, UserAgentVerdict, Location, Asn, Company, AbuseContact, LookupResponse, } from './types.js';
10
10
  export type { Entitlement, EntitlementApikey, EntitlementPlan, EntitlementUsage, } from './generated/types.gen.js';
package/dist/shapes.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare const LOOKUP_MEMBERS: readonly ["ip", "is_vpn"];
2
2
  export declare const LOCATION_MEMBERS: readonly ["continent", "continent_name", "country", "country_name", "timezone", "currency_code", "currency_name", "currency_symbol", "flag_emoji", "flag_unicode"];
3
- export declare const ASN_MEMBERS: readonly ["asn", "name", "domain", "type", "prefix"];
3
+ export declare const ASN_MEMBERS: readonly ["asn", "name", "domain", "type", "prefix", "country", "rpki_status"];
4
4
  export declare const COMPANY_MEMBERS: readonly ["name", "domain"];
5
5
  export declare const ABUSE_CONTACT_MEMBERS: readonly ["email"];
6
6
  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"];
@@ -10,12 +10,15 @@ export declare const ENTITLEMENT_MEMBERS: readonly ["org_id", "apikey", "plan",
10
10
  export declare const ENTITLEMENT_APIKEY_MEMBERS: readonly ["id", "allowed_cidrs"];
11
11
  export declare const ENTITLEMENT_PLAN_MEMBERS: readonly ["key", "name", "tier"];
12
12
  export declare const ENTITLEMENT_USAGE_MEMBERS: readonly ["requests", "quota", "window_start", "window_end"];
13
+ export declare const USER_AGENT_MEMBERS: readonly ["agent", "kind", "verdict"];
13
14
  type Kind = 'string' | 'integer' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'date-time';
14
15
  export declare const LOOKUP_TYPES: Record<string, Kind>;
15
16
  export declare const VPN_DETAIL_TYPES: Record<string, Kind>;
16
17
  export declare const CLASS_DETAIL_TYPES: Record<string, Kind>;
17
18
  export declare const PROXY_DETAIL_TYPES: Record<string, Kind>;
18
19
  export declare const PUBPROXY_DETAIL_TYPES: Record<string, Kind>;
20
+ export declare const BOT_DETAIL_TYPES: Record<string, Kind>;
21
+ export declare const USER_AGENT_TYPES: Record<string, Kind>;
19
22
  export declare const CARRIER_DETAIL_TYPES: Record<string, Kind>;
20
23
  export declare const SATELLITE_DETAIL_TYPES: Record<string, Kind>;
21
24
  export declare const SSH_DETAIL_TYPES: Record<string, Kind>;
package/dist/shapes.js CHANGED
@@ -7,7 +7,7 @@ export const LOCATION_MEMBERS = [
7
7
  'continent', 'continent_name', 'country', 'country_name', 'timezone', 'currency_code', 'currency_name',
8
8
  'currency_symbol', 'flag_emoji', 'flag_unicode',
9
9
  ];
10
- export const ASN_MEMBERS = ['asn', 'name', 'domain', 'type', 'prefix'];
10
+ export const ASN_MEMBERS = ['asn', 'name', 'domain', 'type', 'prefix', 'country', 'rpki_status'];
11
11
  export const COMPANY_MEMBERS = ['name', 'domain'];
12
12
  export const ABUSE_CONTACT_MEMBERS = ['email'];
13
13
  export const WEB_DETAIL_MEMBERS = [
@@ -20,6 +20,7 @@ export const ENTITLEMENT_MEMBERS = ['org_id', 'apikey', 'plan', 'usage'];
20
20
  export const ENTITLEMENT_APIKEY_MEMBERS = ['id', 'allowed_cidrs'];
21
21
  export const ENTITLEMENT_PLAN_MEMBERS = ['key', 'name', 'tier'];
22
22
  export const ENTITLEMENT_USAGE_MEMBERS = ['requests', 'quota', 'window_start', 'window_end'];
23
+ export const USER_AGENT_MEMBERS = ['agent', 'kind', 'verdict'];
23
24
  export const LOOKUP_TYPES = {
24
25
  ip: 'string', is_bogon: 'boolean', is_vpn: 'boolean', is_hosting: 'boolean', is_relay: 'boolean', is_tor: 'boolean',
25
26
  is_cdn: 'boolean', is_resproxy: 'boolean', is_dcproxy: 'boolean', is_mobproxy: 'boolean',
@@ -29,6 +30,7 @@ export const LOOKUP_TYPES = {
29
30
  mobproxy: 'object', pubproxy: 'object', carrier: 'object', satellite: 'object', ssh: 'object', smtp: 'object',
30
31
  web: 'array', dns_resolver: 'object', bittorrent: 'object', location: 'object', asn: 'object',
31
32
  company: 'object', hostname: 'string', abuse: 'object', trial_expired: 'boolean', cap_reached: 'boolean',
33
+ is_bot: 'boolean', bot: 'object', user_agent: 'object',
32
34
  };
33
35
  export const VPN_DETAIL_TYPES = {
34
36
  provider: 'string', provider_name: 'string', last_seen: 'date', confidence: 'string', method: 'string',
@@ -44,6 +46,12 @@ export const PUBPROXY_DETAIL_TYPES = {
44
46
  entry: 'boolean', exit: 'boolean', protocols: 'array', num_ports: 'integer', num_proxies: 'integer',
45
47
  last_seen: 'date', last_usable: 'string',
46
48
  };
49
+ export const BOT_DETAIL_TYPES = {
50
+ provider: 'string', provider_name: 'string', agents: 'array', categories: 'array', verified: 'boolean',
51
+ identity: 'string', verified_by: 'string', confidence: 'string', first_seen: 'date', last_seen: 'date',
52
+ };
53
+ // `verdict` is read as any string, so a verdict the API adds comes back as served.
54
+ export const USER_AGENT_TYPES = { agent: 'string', kind: 'string', verdict: 'string' };
47
55
  export const CARRIER_DETAIL_TYPES = {
48
56
  name: 'string', mcc: 'string', mnc: 'string', country: 'string', confidence: 'string',
49
57
  };
@@ -52,24 +60,24 @@ export const SATELLITE_DETAIL_TYPES = {
52
60
  asn: 'integer', confidence: 'string',
53
61
  };
54
62
  export const SSH_DETAIL_TYPES = {
55
- port: 'integer', banner: 'string', host_key_fp: 'string', session_ok: 'boolean', first_seen: 'string',
56
- last_seen: 'string',
63
+ port: 'integer', banner: 'string', host_key_fp: 'string', session_ok: 'boolean', first_seen: 'date',
64
+ last_seen: 'date',
57
65
  };
58
66
  export const SMTP_DETAIL_TYPES = {
59
- port: 'integer', banner: 'string', session_ok: 'boolean', first_seen: 'string', last_seen: 'string',
67
+ port: 'integer', banner: 'string', session_ok: 'boolean', first_seen: 'date', last_seen: 'date',
60
68
  };
61
69
  export const WEB_DETAIL_TYPES = {
62
70
  port: 'integer', tls_ok: 'boolean', session_ok: 'boolean', status_code: 'integer', server: 'string',
63
71
  location: 'string', title: 'string', cert_subject_cn: 'string', cert_subject_o: 'string',
64
- cert_issuer_dn: 'string', cert_browser_trusted: 'boolean', tls_version: 'string', first_seen: 'string',
65
- last_seen: 'string',
72
+ cert_issuer_dn: 'string', cert_browser_trusted: 'boolean', tls_version: 'string', first_seen: 'date',
73
+ last_seen: 'date',
66
74
  };
67
75
  export const DNS_RESOLVER_DETAIL_TYPES = {
68
76
  port: 'integer', recursion_available: 'boolean', rcode: 'integer', answer_correct: 'boolean',
69
- first_seen: 'string', last_seen: 'string',
77
+ first_seen: 'date', last_seen: 'date',
70
78
  };
71
79
  export const BITTORRENT_DETAIL_TYPES = {
72
- verified: 'boolean', id_matches_ip: 'boolean', first_seen: 'string', last_seen: 'string',
80
+ verified: 'boolean', id_matches_ip: 'boolean', first_seen: 'date', last_seen: 'date',
73
81
  last_reachable: 'string', days_seen: 'integer', num_ports: 'integer', peak_num_ports: 'integer',
74
82
  indexer: 'boolean', clients: 'array',
75
83
  };
@@ -166,19 +174,21 @@ const DETAILS = [
166
174
  ['dcproxy', PROXY_DETAIL_TYPES], ['mobproxy', PROXY_DETAIL_TYPES], ['pubproxy', PUBPROXY_DETAIL_TYPES],
167
175
  ['carrier', CARRIER_DETAIL_TYPES], ['satellite', SATELLITE_DETAIL_TYPES], ['ssh', SSH_DETAIL_TYPES],
168
176
  ['smtp', SMTP_DETAIL_TYPES], ['dns_resolver', DNS_RESOLVER_DETAIL_TYPES],
169
- ['bittorrent', BITTORRENT_DETAIL_TYPES],
177
+ ['bittorrent', BITTORRENT_DETAIL_TYPES], ['bot', BOT_DETAIL_TYPES],
170
178
  ];
171
179
  const SHARED = [
172
180
  ['location', LOCATION_MEMBERS, LOCATION_TYPES],
173
181
  ['asn', ASN_MEMBERS, ASN_TYPES],
174
182
  ['company', COMPANY_MEMBERS, COMPANY_TYPES],
175
183
  ['abuse', ABUSE_CONTACT_MEMBERS, ABUSE_CONTACT_TYPES],
184
+ ['user_agent', USER_AGENT_MEMBERS, USER_AGENT_TYPES],
176
185
  ];
177
186
  export function isLookup(data) {
178
187
  return typed(data, LOOKUP_MEMBERS, LOOKUP_TYPES)
179
188
  && DETAILS.every(([member, types]) => optional(data[member], (detail) => typed(detail, [], types)))
180
189
  && optional(data['pubproxy'], (pubproxy) => lists(pubproxy, 'protocols', isString))
181
190
  && optional(data['bittorrent'], (bittorrent) => lists(bittorrent, 'clients', isString))
191
+ && optional(data['bot'], (bot) => lists(bot, 'agents', isString) && lists(bot, 'categories', isString))
182
192
  && optional(data['web'], (web) => every(web, (row) => typed(row, WEB_DETAIL_MEMBERS, WEB_DETAIL_TYPES)))
183
193
  && SHARED.every(([member, required, types]) => optional(data[member], (o) => typed(o, required, types)));
184
194
  }
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
  /**
@@ -44,4 +44,9 @@ export declare function checkConcurrency(concurrency: number | null | undefined)
44
44
  */
45
45
  export declare function deadline<T>(timeoutMs: number, fn: (signal: AbortSignal) => Promise<T>): Promise<T>;
46
46
  export declare function withRetry<T>(retries: number, fn: () => Promise<T>): Promise<T>;
47
+ /**
48
+ * `encodeURIComponent`, and `!'()*` too, so every reserved character goes out
49
+ * percent-encoded: `+` among them, which a server reads as a space.
50
+ */
51
+ export declare function strictEncode(value: string): string;
47
52
  export declare function asError(err: unknown): VPNDetectionError;
package/dist/transport.js CHANGED
@@ -131,6 +131,13 @@ export async function withRetry(retries, fn) {
131
131
  throw asError(err);
132
132
  }
133
133
  }
134
+ /**
135
+ * `encodeURIComponent`, and `!'()*` too, so every reserved character goes out
136
+ * percent-encoded: `+` among them, which a server reads as a space.
137
+ */
138
+ export function strictEncode(value) {
139
+ return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
140
+ }
134
141
  export function asError(err) {
135
142
  if (err instanceof VPNDetectionError) {
136
143
  return err;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- import type { AbuseContact, Asn, BitTorrentDetail, CarrierDetail, ClassDetail, Company, DnsResolverDetail, Location, LookupResponse, ProxyDetail, PubproxyDetail, SatelliteDetail, SmtpDetail, SshDetail, VpnDetail, WebDetail } from './generated/types.gen.js';
2
- export type { AbuseContact, Asn, BitTorrentDetail, CarrierDetail, ClassDetail, Company, DnsResolverDetail, Location, LookupResponse, ProxyDetail, PubproxyDetail, SatelliteDetail, SmtpDetail, SshDetail, VpnDetail, WebDetail, };
1
+ import type { AbuseContact, Asn as WireAsn, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, Company, DnsResolverDetail, Location, LookupResponse as WireLookupResponse, ProxyDetail, PubproxyDetail, SatelliteDetail, SmtpDetail, SshDetail, UserAgentVerdict, VpnDetail, WebDetail } from './generated/types.gen.js';
2
+ export type { AbuseContact, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, Company, DnsResolverDetail, Location, ProxyDetail, PubproxyDetail, SatelliteDetail, SmtpDetail, SshDetail, UserAgentVerdict, VpnDetail, WebDetail, };
3
+ /** The AS 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. */
6
+ export type LookupResponse = Omit<WireLookupResponse, 'asn'> & {
7
+ asn?: Asn;
8
+ };
3
9
  /**
4
10
  * What a lookup answers.
5
11
  *
@@ -39,6 +45,11 @@ export interface Result {
39
45
  isWeb?: boolean;
40
46
  isDnsResolver?: boolean;
41
47
  isBittorrent?: boolean;
48
+ /**
49
+ * Whether an automated client uses the address, such as a search engine's or an AI company's
50
+ * crawler, an uptime monitor or a webhook sender. Every plan includes this; `bot` says whose.
51
+ */
52
+ isBot?: boolean;
42
53
  /**
43
54
  * On answers to a key on the free plan only: `false` while its organization's trial of every
44
55
  * field lasts, `true` once the answer has Unlimited's.
@@ -67,6 +78,17 @@ export interface Result {
67
78
  web?: WebDetail[];
68
79
  dnsResolver?: DnsResolverDetail;
69
80
  bittorrent?: BitTorrentDetail;
81
+ /**
82
+ * Whose bot uses the address, what it does and whether its operator vouches for the address.
83
+ * Paid plans. `agents` and `categories` keep the API's order.
84
+ */
85
+ bot?: BotDetail;
86
+ /**
87
+ * The agent the lookup's `userAgent` names, and whether this address bears it out: `verified`,
88
+ * `spoofed`, `unverifiable` or `not_bot`. Only when the lookup sent a user agent, with every
89
+ * field; never on a bogon, which is answered locally.
90
+ */
91
+ userAgent?: UserAgentVerdict;
70
92
  /**
71
93
  * Where the address is, on every answer, with or without a key: every key present, empty
72
94
  * strings where it is not known. The region, city, postal code, coordinates and the rest
package/dist/types.js CHANGED
@@ -7,7 +7,7 @@ const RESULT_NAMES = {
7
7
  is_resproxy: 'isResproxy', is_dcproxy: 'isDcproxy', is_mobproxy: 'isMobproxy', is_pubproxy: 'isPubproxy',
8
8
  is_anycast: 'isAnycast', is_carrier: 'isCarrier', is_satellite: 'isSatellite', is_ssh: 'isSsh',
9
9
  is_smtp: 'isSmtp', is_web: 'isWeb', is_dns_resolver: 'isDnsResolver', is_bittorrent: 'isBittorrent',
10
- trial_expired: 'trialExpired', cap_reached: 'capReached',
10
+ is_bot: 'isBot', trial_expired: 'trialExpired', cap_reached: 'capReached', bot: 'bot', user_agent: 'userAgent',
11
11
  vpn: 'vpn', hosting: 'hosting', relay: 'relay', tor: 'tor', cdn: 'cdn', resproxy: 'resproxy', dcproxy: 'dcproxy',
12
12
  mobproxy: 'mobproxy', pubproxy: 'pubproxy', carrier: 'carrier', satellite: 'satellite', ssh: 'ssh', smtp: 'smtp',
13
13
  web: 'web', dns_resolver: 'dnsResolver', bittorrent: 'bittorrent', location: 'location', asn: 'asn',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vpndetection-web",
3
- "version": "1.6.1",
3
+ "version": "1.8.0",
4
4
  "description": "Official browser client library for the VPNDetection API. Detect VPNs, proxies, Tor, hosting and CDN IPs.",
5
5
  "type": "module",
6
6
  "license": "MIT",