vpndetection-web 1.0.0 → 1.1.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.** Without a key, a lookup answers `ip` and `is_vpn`, up to 1,000 a day per source address. In a page that address is the visitor's, so each visitor's lookups count against their own allowance, and `myIp` tells you about the visitor:
33
+ **No API key needed to start.** Without a key a lookup answers `ip`, `is_vpn`, Tor and relay detection, `location` and `asn`, with no daily or monthly cap: up to 60 lookups a minute from each address. In a page that address is the visitor's, so each visitor's lookups count against their own limit, and `myIp` tells you about the visitor:
34
34
 
35
35
  ```js
36
36
  import { VPNDetection } from 'vpndetection-web';
@@ -41,22 +41,22 @@ const me = await client.myIp();
41
41
  console.log(me.isVpn); // is this visitor on a VPN?
42
42
 
43
43
  const result = await client.lookup('45.83.91.1');
44
- console.log(result.isVpn); // true
44
+ console.log(result.isVpn); // true
45
+ console.log(result.location?.country); // the ISO 3166 country code
46
+ console.log(result.asn?.name); // who runs the announcing network
45
47
  ```
46
48
 
47
49
  ### With an API key
48
50
 
49
- Where the key stays private (see above), a free key adds Tor and relay detection, where the address is and the AS that announces it. Every paid plan answers every field, the same on each, and the plans differ only in how many lookups they include. Create a key in the [console](https://app.vpndetection.io), then pass it in:
51
+ Where the key stays private (see above), a free key adds every other flag, `is_hosting`, `is_cdn` and the four proxy flags, at 50,000 lookups a month, and every paid plan answers every field, the provider, confidence and last-seen detail behind each flag included. The paid plans differ only in how many lookups they include. Batch lookups need a key. Create one in the [console](https://app.vpndetection.io), then pass it in:
50
52
 
51
53
  ```js
52
54
  const client = new VPNDetection({ apiKey: 'your-api-key' });
53
55
 
54
56
  const result = await client.lookup('45.83.91.1');
55
57
  console.log(result.isVpn); // true
56
- console.log(result.location?.country); // the ISO 3166 country code
57
- console.log(result.asn?.name); // who runs the announcing network
58
+ console.log(result.isHosting); // with any key, a free one included
58
59
  console.log(result.vpn?.provider); // on a paid plan
59
- console.log(result.isHosting); // on a paid plan
60
60
  ```
61
61
 
62
62
  An extension can sign its user in rather than ask them to paste a key: see Sign in with OAuth below.
@@ -83,7 +83,7 @@ Usage counts against the anniversary of your subscription, not the calendar mont
83
83
 
84
84
  ### Batch lookup
85
85
 
86
- Look up as many addresses as you like in one call. Bogons and cached answers are handled locally, and the rest go to the batch endpoint in chunks of up to 1000, in parallel:
86
+ Look up as many addresses as you like in one call. Bogons and cached answers are handled locally, and the rest go to the batch endpoint in chunks of up to 1000, in parallel. The batch endpoint needs an API key, a free one included:
87
87
 
88
88
  ```js
89
89
  const results = await client.lookupBatch(['45.83.91.1', '8.8.8.8', '1.1.1.1']);
@@ -206,7 +206,7 @@ try {
206
206
 
207
207
  `kind` is one of `bad_request`, `unauthorized`, `forbidden`, `rate_limited`, `quota_exceeded`, `server_error` or `network`.
208
208
 
209
- Note that `rate_limited` and `quota_exceeded` both arrive as HTTP 429 and are not the same thing. A rate limit is when the API faces extreme traffic bursts and so retrying later works; but a spent quota needs your allowance raised or the window to roll over. The library retries rate limits for you, but not if your quota is exceeded.
209
+ Note that `rate_limited` and `quota_exceeded` both arrive as HTTP 429 and are not the same thing. A rate limit is when the API faces extreme traffic bursts, or a lookup without a key passes 60 a minute, and so retrying later works; but a spent quota needs your allowance raised or the window to roll over. The library retries rate limits for you, but not if your quota is exceeded.
210
210
 
211
211
  A request the browser never got an answer to is a retryable `network` error carrying what the browser said: offline, blocked by an extension, or refused by the page's Content-Security-Policy.
212
212
 
@@ -246,11 +246,12 @@ The library is ES2022 and needs only what a browser has, `fetch` and, for PKCE,
246
246
 
247
247
  ### Absent is not false
248
248
 
249
- Without a key only `ip` and `isVpn` come back, and a free key adds Tor, relay, `location` and `asn`. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no".
249
+ Without a key a lookup leaves out `isHosting`, `isCdn` and the four proxy flags, and a free key leaves out `vpn` and the detail behind each flag. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no".
250
250
 
251
251
  ```js
252
252
  result.isHosting ?? false // when you only want the flag
253
- result.isHosting === undefined // not in your plan
253
+ result.isHosting === undefined // without a key: not in your plan
254
+ result.vpn === undefined // on a free key: not in your plan
254
255
  ```
255
256
 
256
257
  ## Other Libraries
package/dist/client.d.ts CHANGED
@@ -18,8 +18,9 @@ export interface CacheOptions {
18
18
  }
19
19
  export interface Options {
20
20
  /**
21
- * Your API key. Omit it entirely to use the free tier, which answers
22
- * `ip` and `is_vpn` and allows 1000 requests per day per source address.
21
+ * Your API key. Omit it to look up without one: a lookup then answers
22
+ * `ip`, `is_vpn`, the Tor and relay members, `location` and `asn`, up to
23
+ * 60 a minute from each address, and a batch is refused as `unauthorized`.
23
24
  * A key in a web page is readable by anyone who opens the page.
24
25
  */
25
26
  apiKey?: string;
@@ -145,7 +146,9 @@ export declare class VPNDetection {
145
146
  * and a chunk that fails as a whole marks every address in it. A per-call
146
147
  * `concurrency` below 1 is refused as `bad_request` before anything is sent.
147
148
  * An IPv4-mapped address is looked up as the IPv4 address it carries, and its
148
- * answer keyed as you passed it.
149
+ * answer keyed as you passed it. The batch endpoint needs an API key, a free
150
+ * one included: without one, every address sent to it carries an
151
+ * `unauthorized` error.
149
152
  */
150
153
  lookupBatch(ips: Iterable<string>, options?: BatchOptions): Promise<Map<string, Result | VPNDetectionError>>;
151
154
  private unstored;
package/dist/client.js CHANGED
@@ -194,7 +194,9 @@ export class VPNDetection {
194
194
  * and a chunk that fails as a whole marks every address in it. A per-call
195
195
  * `concurrency` below 1 is refused as `bad_request` before anything is sent.
196
196
  * An IPv4-mapped address is looked up as the IPv4 address it carries, and its
197
- * answer keyed as you passed it.
197
+ * answer keyed as you passed it. The batch endpoint needs an API key, a free
198
+ * one included: without one, every address sent to it carries an
199
+ * `unauthorized` error.
198
200
  */
199
201
  async lookupBatch(ips, options = {}) {
200
202
  const concurrency = checkConcurrency(options.concurrency);
package/dist/errors.d.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  * Why a request failed.
3
3
  *
4
4
  * `rate_limited` and `quota_exceeded` both arrive as HTTP 429 and are NOT the
5
- * same thing. A rate limit is the API protecting itself and carries
6
- * `Retry-After`; retrying works. A spent quota carries no such header and
7
- * retrying will not help until the window rolls over or the limit is raised.
8
- * The header is the only thing that distinguishes them.
5
+ * same thing. A rate limit is the API protecting itself, or a lookup without
6
+ * a key past 60 a minute, and carries `Retry-After`; retrying works. A spent
7
+ * quota carries no such header and retrying will not help until the window
8
+ * rolls over or the limit is raised. The header is the only thing that
9
+ * distinguishes them.
9
10
  */
10
11
  export type ErrorKind = 'bad_request' | 'unauthorized' | 'forbidden' | 'rate_limited' | 'quota_exceeded' | 'server_error' | 'network';
11
12
  export declare class VPNDetectionError extends Error {
@@ -18,7 +18,7 @@ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends
18
18
  *
19
19
  * Answers what is known about a single IPv4 or IPv6 address. Which fields
20
20
  * come back is decided by the presented key; with no key the answer is
21
- * `ip` and `is_vpn`.
21
+ * `ip`, `is_vpn`, the Tor and relay members, `location` and `asn`.
22
22
  *
23
23
  */
24
24
  export declare const lookupIp: <ThrowOnError extends boolean = false>(options: Options<LookupIpData, ThrowOnError>) => RequestResult<LookupIpResponses, LookupIpErrors, ThrowOnError>;
@@ -28,7 +28,7 @@ export declare const lookupIp: <ThrowOnError extends boolean = false>(options: O
28
28
  * Answers what is known about the address this request came from, which is
29
29
  * the same answer `GET /{ip}` gives for that address: the presented key
30
30
  * decides which fields come back, and the request counts against the same
31
- * allowance.
31
+ * limit or allowance.
32
32
  *
33
33
  * The address is the one our edge observed, so a request through a proxy
34
34
  * or a VPN reports the exit it left through rather than the machine that
@@ -57,6 +57,9 @@ export declare const lookupMyIp: <ThrowOnError extends boolean = false>(options?
57
57
  * whole by the rate limit, so a per-entry `429` is always a spent
58
58
  * allowance and never a throttle.
59
59
  *
60
+ * A batch needs an API key, a free one included: without one the call is
61
+ * refused with `401`. Keyless lookups are one address at a time.
62
+ *
60
63
  */
61
64
  export declare const lookupBatch: <ThrowOnError extends boolean = false>(options: Options<LookupBatchData, ThrowOnError>) => RequestResult<LookupBatchResponses, LookupBatchErrors, ThrowOnError>;
62
65
  /**
@@ -82,7 +85,8 @@ export declare const oauthMetadata: <ThrowOnError extends boolean = false>(optio
82
85
  /**
83
86
  * Token
84
87
  *
85
- * Three grant types.
88
+ * Issues tokens for three grant types: a device code, an authorization
89
+ * code and a refresh token.
86
90
  *
87
91
  * `urn:ietf:params:oauth:grant-type:device_code` polls a device
88
92
  * authorization. Until the person approves it answers
@@ -104,11 +108,10 @@ export declare const oauthToken: <ThrowOnError extends boolean = false>(options:
104
108
  /**
105
109
  * Revoke
106
110
  *
107
- * RFC 7009. Always answers 200, including for a token that was never
108
- * valid - an endpoint that distinguished the two would be a way to test
109
- * whether a stolen string is a live credential.
111
+ * RFC 7009. Always answers 200, even for a token that was never valid, so
112
+ * it can't be used to test whether a token is live.
110
113
  *
111
- * Revoking a REFRESH token ends the whole authorization and takes its
114
+ * Revoking a refresh token ends the whole authorization and takes its
112
115
  * access tokens with it. Revoking an access token affects only that token.
113
116
  *
114
117
  */
@@ -6,7 +6,7 @@ import { urlSearchParamsBodySerializer } from './client/index.js';
6
6
  *
7
7
  * Answers what is known about a single IPv4 or IPv6 address. Which fields
8
8
  * come back is decided by the presented key; with no key the answer is
9
- * `ip` and `is_vpn`.
9
+ * `ip`, `is_vpn`, the Tor and relay members, `location` and `asn`.
10
10
  *
11
11
  */
12
12
  export const lookupIp = (options) => (options.client ?? client).get({
@@ -28,7 +28,7 @@ export const lookupIp = (options) => (options.client ?? client).get({
28
28
  * Answers what is known about the address this request came from, which is
29
29
  * the same answer `GET /{ip}` gives for that address: the presented key
30
30
  * decides which fields come back, and the request counts against the same
31
- * allowance.
31
+ * limit or allowance.
32
32
  *
33
33
  * The address is the one our edge observed, so a request through a proxy
34
34
  * or a VPN reports the exit it left through rather than the machine that
@@ -69,6 +69,9 @@ export const lookupMyIp = (options) => (options?.client ?? client).get({
69
69
  * whole by the rate limit, so a per-entry `429` is always a spent
70
70
  * allowance and never a throttle.
71
71
  *
72
+ * A batch needs an API key, a free one included: without one the call is
73
+ * refused with `401`. Keyless lookups are one address at a time.
74
+ *
72
75
  */
73
76
  export const lookupBatch = (options) => (options.client ?? client).post({
74
77
  security: [
@@ -122,7 +125,8 @@ export const oauthMetadata = (options) => (options?.client ?? client).get({ url:
122
125
  /**
123
126
  * Token
124
127
  *
125
- * Three grant types.
128
+ * Issues tokens for three grant types: a device code, an authorization
129
+ * code and a refresh token.
126
130
  *
127
131
  * `urn:ietf:params:oauth:grant-type:device_code` polls a device
128
132
  * authorization. Until the person approves it answers
@@ -152,11 +156,10 @@ export const oauthToken = (options) => (options.client ?? client).post({
152
156
  /**
153
157
  * Revoke
154
158
  *
155
- * RFC 7009. Always answers 200, including for a token that was never
156
- * valid - an endpoint that distinguished the two would be a way to test
157
- * whether a stolen string is a live credential.
159
+ * RFC 7009. Always answers 200, even for a token that was never valid, so
160
+ * it can't be used to test whether a token is live.
158
161
  *
159
- * Revoking a REFRESH token ends the whole authorization and takes its
162
+ * Revoking a refresh token ends the whole authorization and takes its
160
163
  * access tokens with it. Revoking an access token affects only that token.
161
164
  *
162
165
  */
@@ -2,8 +2,9 @@ export type ClientOptions = {
2
2
  baseUrl: 'https://api.vpndetection.io' | (string & {});
3
3
  };
4
4
  /**
5
- * The union of every plan's answer. Only `ip` and `is_vpn` are guaranteed;
6
- * each remaining field is present when your plan includes it, and absent
5
+ * The union of every plan's answer. Every answer carries `ip`, `is_vpn`,
6
+ * the Tor and relay members, `location` and `asn`, with or without a key;
7
+ * each remaining field is present when your key includes it, and absent
7
8
  * otherwise. A client that must work across plans should treat an absent
8
9
  * flag as unknown rather than as `false`.
9
10
  *
@@ -21,35 +22,35 @@ export type LookupResponse = {
21
22
  */
22
23
  is_vpn: boolean;
23
24
  /**
24
- * Whether the address belongs to a hosting or cloud provider. Paid plans.
25
+ * Whether the address belongs to a hosting or cloud provider. Free and paid plans.
25
26
  */
26
27
  is_hosting?: boolean;
27
28
  /**
28
- * Whether the address is privacy relay or enterprise web gateway egress, such as iCloud Private Relay or Zscaler. Free and paid plans.
29
+ * Whether the address is privacy relay or enterprise web gateway egress, such as iCloud Private Relay or Zscaler. Every answer, with or without a key.
29
30
  */
30
31
  is_relay?: boolean;
31
32
  /**
32
- * Whether the address is a Tor node. Free and paid plans.
33
+ * Whether the address is a Tor node. Every answer, with or without a key.
33
34
  */
34
35
  is_tor?: boolean;
35
36
  /**
36
- * Whether the address belongs to a CDN. Paid plans.
37
+ * Whether the address belongs to a CDN. Free and paid plans.
37
38
  */
38
39
  is_cdn?: boolean;
39
40
  /**
40
- * Whether the address was seen in a residential proxy pool. Paid plans.
41
+ * Whether the address was seen in a residential proxy pool. Free and paid plans.
41
42
  */
42
43
  is_resproxy?: boolean;
43
44
  /**
44
- * Whether the address was seen in a datacenter proxy pool. Paid plans.
45
+ * Whether the address is one a datacenter proxy service sells or runs on, a proxy company's own ranges included. Free and paid plans.
45
46
  */
46
47
  is_dcproxy?: boolean;
47
48
  /**
48
- * Whether the address was seen in a mobile proxy pool. Paid plans.
49
+ * Whether the address was seen in a mobile proxy pool. Free and paid plans.
49
50
  */
50
51
  is_mobproxy?: boolean;
51
52
  /**
52
- * Whether a public proxy, one anyone can connect through, listens on the address or sends its traffic out from it. Paid plans.
53
+ * Whether a public proxy, one anyone can connect through, listens on the address or sends its traffic out from it. Free and paid plans.
53
54
  */
54
55
  is_pubproxy?: boolean;
55
56
  /**
@@ -62,12 +63,13 @@ export type LookupResponse = {
62
63
  */
63
64
  hosting?: ClassDetail;
64
65
  /**
65
- * Detail for `is_relay`. Empty when false. Free and paid plans.
66
+ * Detail for `is_relay`. Empty when false. Every answer, with or without a key.
66
67
  */
67
68
  relay?: ClassDetail;
68
69
  /**
69
- * Detail for `is_tor`. Empty when false. Free and paid plans. The tor
70
- * dataset carries no provider, so `provider` is always an empty string.
70
+ * Detail for `is_tor`. Empty when false. Every answer, with or without a
71
+ * key. The tor dataset carries no provider, so `provider` is always an
72
+ * empty string.
71
73
  *
72
74
  */
73
75
  tor?: ClassDetail;
@@ -286,9 +288,9 @@ export type PubproxyDetail = {
286
288
  };
287
289
  /**
288
290
  * Where the address is, to the country: the fields of our IP Country
289
- * database. Free and paid plans. Each field is present whenever the
290
- * object is, so an address in no country, or a private one, answers
291
- * empty strings.
291
+ * database. Every answer, with or without a key. Each field is present
292
+ * whenever the object is, so an address in no country, or a private one,
293
+ * answers empty strings.
292
294
  *
293
295
  */
294
296
  export type Location = {
@@ -334,7 +336,8 @@ export type Location = {
334
336
  flag_unicode: string;
335
337
  };
336
338
  /**
337
- * The autonomous system that announces the address. Free and paid plans.
339
+ * The autonomous system that announces the address. Every answer, with or
340
+ * without a key.
338
341
  * Each field is present whenever the object is: `asn` is 0 and the rest
339
342
  * empty where no announcement covers the address.
340
343
  *
@@ -583,9 +586,9 @@ export type LookupIpErrors = {
583
586
  */
584
587
  403: LookupError;
585
588
  /**
586
- * Either a transient rate limit or a spent allowance. `Retry-After` is
587
- * present for the former and absent for the latter, and is the only
588
- * way to tell them apart.
589
+ * Either a rate limit or a spent allowance. `Retry-After` is present
590
+ * for the former and absent for the latter, and is the only way to
591
+ * tell them apart.
589
592
  *
590
593
  */
591
594
  429: LookupError;
@@ -624,9 +627,9 @@ export type LookupMyIpErrors = {
624
627
  */
625
628
  403: LookupError;
626
629
  /**
627
- * Either a transient rate limit or a spent allowance. `Retry-After` is
628
- * present for the former and absent for the latter, and is the only
629
- * way to tell them apart.
630
+ * Either a rate limit or a spent allowance. `Retry-After` is present
631
+ * for the former and absent for the latter, and is the only way to
632
+ * tell them apart.
630
633
  *
631
634
  */
632
635
  429: LookupError;
@@ -657,7 +660,7 @@ export type LookupBatchErrors = {
657
660
  */
658
661
  400: LookupError;
659
662
  /**
660
- * The presented API key is unknown, revoked, or expired.
663
+ * No API key was presented, or the one presented is unknown, revoked, or expired.
661
664
  */
662
665
  401: LookupError;
663
666
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vpndetection-web",
3
- "version": "1.0.0",
3
+ "version": "1.1.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",