vpndetection-web 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,7 +80,7 @@ console.log(ent.usage.requests); // 580
80
80
  console.log(ent.usage.window_end); // when the allowance resets
81
81
  ```
82
82
 
83
- Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against the UTC day on the free plan; it is the same number a lookup is gated on. `hard_limit` is null on an uncapped plan, which is not the same as zero. It needs a key, so it belongs where a key does.
83
+ Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against the trial on the free plan; it is the same number a lookup is gated on. `hard_limit` is null on an uncapped plan, which is not the same as zero. It needs a key, so it belongs where a key does.
84
84
 
85
85
  Show `plan.name` and compare against `plan.key`: a plan's name can change, and its key never does. A `tier` the API adds later comes back as the string it served, so check for the values you know rather than assuming the list is complete.
86
86
 
package/dist/client.d.ts CHANGED
@@ -5,10 +5,10 @@ import { type CacheStore } from './store.js';
5
5
  import { type Result } from './types.js';
6
6
  export declare const DEFAULT_BASE_URL = "https://api.vpndetection.io";
7
7
  export interface CacheOptions {
8
- /** Maximum number of addresses held in memory. Default 10000. */
8
+ /** Maximum number of addresses held in memory, a whole number from 1. Default 10000. */
9
9
  max?: number;
10
10
  /**
11
- * How long an answer stays fresh, in milliseconds. Default 1 hour. An answer
11
+ * How long an answer stays fresh, in whole milliseconds from 1. Default 1 hour. An answer
12
12
  * marked `trialExpired` or `capReached` stays a minute at most.
13
13
  */
14
14
  ttlMs?: number;
@@ -126,7 +126,7 @@ export declare class VPNDetection {
126
126
  *
127
127
  * Usage counts against the ALLOWANCE WINDOW - on a paid plan the
128
128
  * anniversary of the subscription, not the calendar month and not the
129
- * billing period, and on the free plan the UTC day - and it is the same
129
+ * billing period, and on the free plan the trial - and it is the same
130
130
  * number a lookup is gated on. It can lag by a few seconds, because
131
131
  * requests are counted in memory and flushed in aggregate.
132
132
  *
package/dist/client.js CHANGED
@@ -54,9 +54,9 @@ export class VPNDetection {
54
54
  this.timeoutMs = checkTimeout(options.timeoutMs) ?? DEFAULT_TIMEOUT_MS;
55
55
  this.limit = pLimit(checkConcurrency(options.concurrency) ?? 8);
56
56
  const cache = options.cache === false ? null : (options.cache ?? {});
57
- const ttlMs = cache?.ttlMs ?? 60 * 60 * 1000;
57
+ const ttlMs = checkCacheOption('ttlMs', cache?.ttlMs) ?? 60 * 60 * 1000;
58
58
  this.cache = cache === null ? null : new LRUCache({
59
- max: cache.max ?? 10_000,
59
+ max: checkCacheOption('max', cache.max) ?? 10_000,
60
60
  ttl: ttlMs,
61
61
  // Concurrent misses for one address share one request: every
62
62
  // `fetch()` while it is in flight gets the same promise, and a
@@ -167,7 +167,7 @@ export class VPNDetection {
167
167
  *
168
168
  * Usage counts against the ALLOWANCE WINDOW - on a paid plan the
169
169
  * anniversary of the subscription, not the calendar month and not the
170
- * billing period, and on the free plan the UTC day - and it is the same
170
+ * billing period, and on the free plan the trial - and it is the same
171
171
  * number a lookup is gated on. It can lag by a few seconds, because
172
172
  * requests are counted in memory and flushed in aggregate.
173
173
  *
@@ -373,6 +373,21 @@ function checkApiKey(apiKey) {
373
373
  }
374
374
  return key === '' ? undefined : key;
375
375
  }
376
+ /**
377
+ * A cache size or TTL refused where it is set, `null` reading as unset. lru-cache
378
+ * reads a zero or NaN TTL as none, which would keep every answer for good, a spent
379
+ * trial's included, and a zero size as no bound; anything else not whole it throws
380
+ * a bare TypeError for.
381
+ */
382
+ function checkCacheOption(name, value) {
383
+ if (value === undefined || value === null) {
384
+ return undefined;
385
+ }
386
+ if (!(typeof value === 'number' && Number.isSafeInteger(value) && value >= 1)) {
387
+ throw new VPNDetectionError('bad_request', `cache.${name} must be a whole number from 1, got ${String(value)}`);
388
+ }
389
+ return value;
390
+ }
376
391
  function unreadableEntry(ip) {
377
392
  return new VPNDetectionError('server_error', `unreadable batch answer for ${ip}, status 200`, 200);
378
393
  }
package/dist/store.d.ts CHANGED
@@ -31,7 +31,7 @@ export declare class StoreTier {
31
31
  }
32
32
  /**
33
33
  * How long an answer stays cached: the TTL, or at most a minute for one marked
34
- * `trialExpired` or `capReached`, which a new UTC day or a raised cap ends. Still
34
+ * `trialExpired` or `capReached`, which a renewed trial or a raised cap ends. Still
35
35
  * cached, so a busy page past its trial does not send every repeat to the API.
36
36
  */
37
37
  export declare function lifeMs(result: Result, ttlMs: number): number;
package/dist/store.js CHANGED
@@ -44,7 +44,7 @@ export class StoreTier {
44
44
  }
45
45
  /**
46
46
  * How long an answer stays cached: the TTL, or at most a minute for one marked
47
- * `trialExpired` or `capReached`, which a new UTC day or a raised cap ends. Still
47
+ * `trialExpired` or `capReached`, which a renewed trial or a raised cap ends. Still
48
48
  * cached, so a busy page past its trial does not send every repeat to the API.
49
49
  */
50
50
  export function lifeMs(result, ttlMs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vpndetection-web",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
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",