internetdata-web 1.3.1 → 1.3.3
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 +6 -4
- package/dist/client.d.ts +6 -3
- package/dist/client.js +6 -2
- package/dist/generated/types.gen.d.ts +19 -19
- package/dist/oauth.d.ts +2 -3
- package/dist/oauth.js +2 -3
- package/dist/store.d.ts +6 -0
- package/dist/store.js +13 -1
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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
|
|
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:
|
|
52
52
|
|
|
53
53
|
```js
|
|
54
54
|
const client = new InternetData({ apiKey: 'your-api-key' });
|
|
@@ -141,6 +141,8 @@ const client = new InternetData({ cache: { max: 50_000, ttlMs: 6 * 60 * 60 * 100
|
|
|
141
141
|
const clientNoCache = new InternetData({ cache: false });
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
An answer with `trialExpired` or `capReached` true is cached for a minute at most, in memory and in a `store`, so a renewed trial or a raised cap reaches you within a minute.
|
|
145
|
+
|
|
144
146
|
### Keeping answers across a reload
|
|
145
147
|
|
|
146
148
|
The in-memory cache lasts as long as the client, so a page reload starts with an empty one, and so does an extension's service worker, which the browser stops once it sits idle. Give the cache a `store` and answers outlive the client: it is read when the in-memory cache misses, before the network, and written after each answer the API serves. In a page, `sessionStorage` keeps them for the tab:
|
|
@@ -253,7 +255,7 @@ const token = await client.oauth.exchangeAuthorizationCode('your-client-id', cod
|
|
|
253
255
|
|
|
254
256
|
Check that `state` came back as you sent it before you exchange `code`, which works once. The client ID can also be the https URL of a client metadata document your app serves, and such an app is never handed a key, so `token.apikey` stays absent.
|
|
255
257
|
|
|
256
|
-
`createPkce` and `pkceChallenge` return promises, as Web Crypto does, and need a secure context: a page served over https or from localhost, or an extension. `exchangeRefreshToken` trades the refresh token for a new pair, and `revoke` with it signs the person out. The sign-in is at `https://internetdata.io`, the apex of the API's host.
|
|
258
|
+
`createPkce` and `pkceChallenge` return promises, as Web Crypto does, and need a secure context: a page served over https or from localhost, or an extension. `exchangeRefreshToken` trades the refresh token for a new pair, and `revoke` with it signs the person out. The sign-in is at `https://internetdata.io`, the apex of the API's host. Any app can sign people in this way without asking us first: its client ID is the https URL of a client metadata document it serves.
|
|
257
259
|
|
|
258
260
|
### Browser support
|
|
259
261
|
|
|
@@ -261,12 +263,12 @@ The library is ES2022 and needs only what a browser has, `fetch` and, for PKCE,
|
|
|
261
263
|
|
|
262
264
|
### Absent is not false
|
|
263
265
|
|
|
264
|
-
Unlimited leaves out `isVpn`, `isHosting`, `isCdn` and the four proxy flags, the detail behind them, 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
|
|
266
|
+
Unlimited leaves out `isVpn`, `isHosting`, `isCdn` and the four proxy flags, the detail behind them, 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".
|
|
265
267
|
|
|
266
268
|
```js
|
|
267
269
|
result.isVpn ?? false // when you only want the flag
|
|
268
270
|
result.isVpn === undefined // on Unlimited: not in your plan
|
|
269
|
-
result.trialExpired === true // a free-plan key's
|
|
271
|
+
result.trialExpired === true // a free-plan key's trial is spent
|
|
270
272
|
result.capReached === true // a paid key is past its overage cap
|
|
271
273
|
```
|
|
272
274
|
|
package/dist/client.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export declare const DEFAULT_BASE_URL = "https://api.internetdata.io";
|
|
|
7
7
|
export interface CacheOptions {
|
|
8
8
|
/** Maximum number of addresses held in memory. Default 10000. */
|
|
9
9
|
max?: number;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* How long an answer stays fresh, in milliseconds. Default 1 hour. An answer
|
|
12
|
+
* marked `trialExpired` or `capReached` stays a minute at most.
|
|
13
|
+
*/
|
|
11
14
|
ttlMs?: number;
|
|
12
15
|
/**
|
|
13
16
|
* Where answers outlive this client: read after the in-memory cache misses and
|
|
@@ -18,8 +21,8 @@ export interface CacheOptions {
|
|
|
18
21
|
}
|
|
19
22
|
export interface Options {
|
|
20
23
|
/**
|
|
21
|
-
* Your API key. Without one a lookup is on Unlimited, the free plan,
|
|
22
|
-
*
|
|
24
|
+
* Your API key. Without one a lookup is on Unlimited, the free plan, with no
|
|
25
|
+
* daily or monthly cap, and no `Authorization` header is sent at all. A
|
|
23
26
|
* batch needs a key on a paid plan.
|
|
24
27
|
* A key in a web page is readable by anyone who opens the page.
|
|
25
28
|
*/
|
package/dist/client.js
CHANGED
|
@@ -6,7 +6,7 @@ import { bogonResult, isAddress, isBogon, unmapped } from './bogon.js';
|
|
|
6
6
|
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
|
-
import { isCacheStore, storeScope, StoreTier } from './store.js';
|
|
9
|
+
import { isCacheStore, lifeMs, storeScope, StoreTier } from './store.js';
|
|
10
10
|
import { asError, checkConcurrency, checkRetries, checkTimeout, deadline, readable, withRetry, } from './transport.js';
|
|
11
11
|
import { toAsnResult, toDomainResult, toResult, } from './types.js';
|
|
12
12
|
export const DEFAULT_BASE_URL = 'https://api.internetdata.io';
|
|
@@ -63,7 +63,11 @@ export class InternetData {
|
|
|
63
63
|
// Concurrent misses for one address share one request: every
|
|
64
64
|
// `fetch()` while it is in flight gets the same promise, and a
|
|
65
65
|
// failure rejects them all and is cached for none.
|
|
66
|
-
fetchMethod: (_ip, _stale, { context }) =>
|
|
66
|
+
fetchMethod: async (_ip, _stale, { context, options }) => {
|
|
67
|
+
const result = await context();
|
|
68
|
+
options.ttl = lifeMs(result, ttlMs);
|
|
69
|
+
return result;
|
|
70
|
+
},
|
|
67
71
|
// An eviction must not fail the callers awaiting a request.
|
|
68
72
|
ignoreFetchAbort: true,
|
|
69
73
|
});
|
|
@@ -271,7 +271,7 @@ export type LookupResponse = {
|
|
|
271
271
|
rwhois?: Rwhois;
|
|
272
272
|
hosted_domains?: HostedDomains;
|
|
273
273
|
/**
|
|
274
|
-
* On every answer to a key on the free plan, and on no other: `false` while
|
|
274
|
+
* On every answer to a key on the free plan, and on no other: `false` while its organization's trial of every field lasts, `true` once the answer has Unlimited's fields.
|
|
275
275
|
*/
|
|
276
276
|
trial_expired?: boolean;
|
|
277
277
|
/**
|
|
@@ -693,11 +693,11 @@ export type Asn = {
|
|
|
693
693
|
*/
|
|
694
694
|
prefix: string;
|
|
695
695
|
/**
|
|
696
|
-
* The country its registry assigned it to.
|
|
696
|
+
* The country its registry assigned it to.
|
|
697
697
|
*/
|
|
698
698
|
country?: string;
|
|
699
699
|
/**
|
|
700
|
-
* The announcement's RPKI status.
|
|
700
|
+
* The announcement's RPKI status.
|
|
701
701
|
*/
|
|
702
702
|
rpki_status?: string;
|
|
703
703
|
};
|
|
@@ -955,7 +955,7 @@ export type AsnLookupResponse = {
|
|
|
955
955
|
downstreams?: Array<number>;
|
|
956
956
|
hosted_domains?: AsnHostedDomains;
|
|
957
957
|
/**
|
|
958
|
-
* On every answer to a key on the free plan, and on no other: `false` while
|
|
958
|
+
* On every answer to a key on the free plan, and on no other: `false` while its organization's trial of every field lasts, `true` once the answer has Unlimited's fields.
|
|
959
959
|
*/
|
|
960
960
|
trial_expired?: boolean;
|
|
961
961
|
/**
|
|
@@ -1036,7 +1036,7 @@ export type DomainLookupResponse = {
|
|
|
1036
1036
|
*/
|
|
1037
1037
|
disposable?: DisposableDetail;
|
|
1038
1038
|
/**
|
|
1039
|
-
* On every answer to a key on the free plan, and on no other: `false` while
|
|
1039
|
+
* On every answer to a key on the free plan, and on no other: `false` while its organization's trial of every field lasts, `true` once the answer has Unlimited's fields.
|
|
1040
1040
|
*/
|
|
1041
1041
|
trial_expired?: boolean;
|
|
1042
1042
|
/**
|
|
@@ -1233,8 +1233,8 @@ export type EntitlementPlan = {
|
|
|
1233
1233
|
/**
|
|
1234
1234
|
* The plan the organization is on, as an identifier that is never
|
|
1235
1235
|
* renamed or reused: `free` for the free plan, or a paid plan's key.
|
|
1236
|
-
* Compare against it and show `name`. On `free`, usage counts
|
|
1237
|
-
*
|
|
1236
|
+
* Compare against it and show `name`. On `free`, usage counts its
|
|
1237
|
+
* trial, the lookups answered with every field.
|
|
1238
1238
|
*
|
|
1239
1239
|
*/
|
|
1240
1240
|
key: string;
|
|
@@ -1376,9 +1376,9 @@ export type LookupIpErrors = {
|
|
|
1376
1376
|
*/
|
|
1377
1377
|
403: LookupError;
|
|
1378
1378
|
/**
|
|
1379
|
-
* A rate limit, always with `Retry-After`: this API protecting itself, or Unlimited
|
|
1380
|
-
*
|
|
1381
|
-
*
|
|
1379
|
+
* A rate limit, always with `Retry-After`: this API protecting itself, or a burst of Unlimited
|
|
1380
|
+
* lookups. A paid plan's overage cap is never a `429`: it answers `200` with Unlimited's
|
|
1381
|
+
* fields and `cap_reached` `true`.
|
|
1382
1382
|
*
|
|
1383
1383
|
*/
|
|
1384
1384
|
429: LookupError;
|
|
@@ -1413,9 +1413,9 @@ export type LookupMyIpErrors = {
|
|
|
1413
1413
|
*/
|
|
1414
1414
|
403: LookupError;
|
|
1415
1415
|
/**
|
|
1416
|
-
* A rate limit, always with `Retry-After`: this API protecting itself, or Unlimited
|
|
1417
|
-
*
|
|
1418
|
-
*
|
|
1416
|
+
* A rate limit, always with `Retry-After`: this API protecting itself, or a burst of Unlimited
|
|
1417
|
+
* lookups. A paid plan's overage cap is never a `429`: it answers `200` with Unlimited's
|
|
1418
|
+
* fields and `cap_reached` `true`.
|
|
1419
1419
|
*
|
|
1420
1420
|
*/
|
|
1421
1421
|
429: LookupError;
|
|
@@ -1459,9 +1459,9 @@ export type LookupAsnErrors = {
|
|
|
1459
1459
|
*/
|
|
1460
1460
|
403: LookupError;
|
|
1461
1461
|
/**
|
|
1462
|
-
* A rate limit, always with `Retry-After`: this API protecting itself, or Unlimited
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1462
|
+
* A rate limit, always with `Retry-After`: this API protecting itself, or a burst of Unlimited
|
|
1463
|
+
* lookups. A paid plan's overage cap is never a `429`: it answers `200` with Unlimited's
|
|
1464
|
+
* fields and `cap_reached` `true`.
|
|
1465
1465
|
*
|
|
1466
1466
|
*/
|
|
1467
1467
|
429: LookupError;
|
|
@@ -1505,9 +1505,9 @@ export type LookupDomainErrors = {
|
|
|
1505
1505
|
*/
|
|
1506
1506
|
403: LookupError;
|
|
1507
1507
|
/**
|
|
1508
|
-
* A rate limit, always with `Retry-After`: this API protecting itself, or Unlimited
|
|
1509
|
-
*
|
|
1510
|
-
*
|
|
1508
|
+
* A rate limit, always with `Retry-After`: this API protecting itself, or a burst of Unlimited
|
|
1509
|
+
* lookups. A paid plan's overage cap is never a `429`: it answers `200` with Unlimited's
|
|
1510
|
+
* fields and `cap_reached` `true`.
|
|
1511
1511
|
*
|
|
1512
1512
|
*/
|
|
1513
1513
|
429: LookupError;
|
package/dist/oauth.d.ts
CHANGED
|
@@ -68,9 +68,8 @@ export interface TokenResponse {
|
|
|
68
68
|
* authorization server is: `https://api.internetdata.io` signs in at
|
|
69
69
|
* `https://internetdata.io`.
|
|
70
70
|
*
|
|
71
|
-
* Every call takes a client ID
|
|
72
|
-
*
|
|
73
|
-
* serves. None of these requests carries the client's API key, and none needs one.
|
|
71
|
+
* Every call takes a client ID, the https URL of a client metadata document the app
|
|
72
|
+
* serves, which any app can use without asking us first. None of these requests carries the client's API key, and none needs one.
|
|
74
73
|
*/
|
|
75
74
|
export declare class OauthApi {
|
|
76
75
|
private readonly client;
|
package/dist/oauth.js
CHANGED
|
@@ -8,9 +8,8 @@ import { checkTimeout, deadline, noResponse, withRetry } from './transport.js';
|
|
|
8
8
|
* authorization server is: `https://api.internetdata.io` signs in at
|
|
9
9
|
* `https://internetdata.io`.
|
|
10
10
|
*
|
|
11
|
-
* Every call takes a client ID
|
|
12
|
-
*
|
|
13
|
-
* serves. None of these requests carries the client's API key, and none needs one.
|
|
11
|
+
* Every call takes a client ID, the https URL of a client metadata document the app
|
|
12
|
+
* serves, which any app can use without asking us first. None of these requests carries the client's API key, and none needs one.
|
|
14
13
|
*/
|
|
15
14
|
export class OauthApi {
|
|
16
15
|
client;
|
package/dist/store.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export declare class StoreTier {
|
|
|
29
29
|
set(ip: string, result: Result): Promise<void>;
|
|
30
30
|
private keyFor;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
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
|
|
35
|
+
* cached, so a busy page past its trial does not send every repeat to the API.
|
|
36
|
+
*/
|
|
37
|
+
export declare function lifeMs(result: Result, ttlMs: number): number;
|
|
32
38
|
/**
|
|
33
39
|
* What tells one client's entries from another's: FNV-1a over the base URL and the
|
|
34
40
|
* key, as 16 hex digits. It tells keys apart and keeps the key itself out of the
|
package/dist/store.js
CHANGED
|
@@ -32,7 +32,7 @@ export class StoreTier {
|
|
|
32
32
|
}
|
|
33
33
|
async set(ip, result) {
|
|
34
34
|
try {
|
|
35
|
-
await this.store.set(this.keyFor(ip), result, this.ttlMs);
|
|
35
|
+
await this.store.set(this.keyFor(ip), result, lifeMs(result, this.ttlMs));
|
|
36
36
|
}
|
|
37
37
|
catch {
|
|
38
38
|
// Costs a request on the next miss, nothing more.
|
|
@@ -42,6 +42,18 @@ export class StoreTier {
|
|
|
42
42
|
return `${this.scope}:${ip}`;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
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
|
|
48
|
+
* cached, so a busy page past its trial does not send every repeat to the API.
|
|
49
|
+
*/
|
|
50
|
+
export function lifeMs(result, ttlMs) {
|
|
51
|
+
if (result.trialExpired === true || result.capReached === true) {
|
|
52
|
+
return Math.min(ttlMs, REDUCED_TTL_MS);
|
|
53
|
+
}
|
|
54
|
+
return ttlMs;
|
|
55
|
+
}
|
|
56
|
+
const REDUCED_TTL_MS = 60_000;
|
|
45
57
|
const FNV_OFFSET = 0xcbf29ce484222325n;
|
|
46
58
|
const FNV_PRIME = 0x100000001b3n;
|
|
47
59
|
const MASK_64 = (1n << 64n) - 1n;
|
package/dist/types.d.ts
CHANGED
|
@@ -36,8 +36,8 @@ export interface Result {
|
|
|
36
36
|
isDnsResolver: boolean;
|
|
37
37
|
isBittorrent: boolean;
|
|
38
38
|
/**
|
|
39
|
-
* On answers to a key on the free plan only: `false` while
|
|
40
|
-
* every field lasts, `true` once the answer has Unlimited's.
|
|
39
|
+
* On answers to a key on the free plan only: `false` while its organization's
|
|
40
|
+
* trial of every field lasts, `true` once the answer has Unlimited's.
|
|
41
41
|
*/
|
|
42
42
|
trialExpired?: boolean;
|
|
43
43
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "internetdata-web",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
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",
|