internetdata-web 0.0.0-stage → 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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -2
  3. package/dist/bogon.d.ts +31 -0
  4. package/dist/bogon.js +214 -0
  5. package/dist/bogons.gen.d.ts +2 -0
  6. package/dist/bogons.gen.js +87 -0
  7. package/dist/client.d.ts +183 -0
  8. package/dist/client.js +446 -0
  9. package/dist/errors.d.ts +66 -0
  10. package/dist/errors.js +185 -0
  11. package/dist/generated/client/client.gen.d.ts +2 -0
  12. package/dist/generated/client/client.gen.js +216 -0
  13. package/dist/generated/client/index.d.ts +10 -0
  14. package/dist/generated/client/index.js +6 -0
  15. package/dist/generated/client/types.gen.d.ts +120 -0
  16. package/dist/generated/client/types.gen.js +2 -0
  17. package/dist/generated/client/utils.gen.d.ts +37 -0
  18. package/dist/generated/client/utils.gen.js +228 -0
  19. package/dist/generated/client.gen.d.ts +12 -0
  20. package/dist/generated/client.gen.js +3 -0
  21. package/dist/generated/core/auth.gen.d.ts +25 -0
  22. package/dist/generated/core/auth.gen.js +14 -0
  23. package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
  24. package/dist/generated/core/bodySerializer.gen.js +57 -0
  25. package/dist/generated/core/params.gen.d.ts +43 -0
  26. package/dist/generated/core/params.gen.js +109 -0
  27. package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
  28. package/dist/generated/core/pathSerializer.gen.js +106 -0
  29. package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
  30. package/dist/generated/core/queryKeySerializer.gen.js +92 -0
  31. package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
  32. package/dist/generated/core/serverSentEvents.gen.js +132 -0
  33. package/dist/generated/core/types.gen.d.ts +83 -0
  34. package/dist/generated/core/types.gen.js +2 -0
  35. package/dist/generated/core/utils.gen.d.ts +19 -0
  36. package/dist/generated/core/utils.gen.js +87 -0
  37. package/dist/generated/index.d.ts +2 -0
  38. package/dist/generated/index.js +2 -0
  39. package/dist/generated/sdk.gen.d.ts +117 -0
  40. package/dist/generated/sdk.gen.js +251 -0
  41. package/dist/generated/types.gen.d.ts +1527 -0
  42. package/dist/generated/types.gen.js +2 -0
  43. package/dist/index.d.ts +9 -0
  44. package/dist/index.js +4 -0
  45. package/dist/oauth.d.ts +119 -0
  46. package/dist/oauth.js +247 -0
  47. package/dist/shapes.d.ts +68 -0
  48. package/dist/shapes.js +284 -0
  49. package/dist/store.d.ts +39 -0
  50. package/dist/store.js +64 -0
  51. package/dist/transport.d.ts +51 -0
  52. package/dist/transport.js +147 -0
  53. package/dist/types.d.ts +115 -0
  54. package/dist/types.js +46 -0
  55. package/package.json +65 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mslm Dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,283 @@
1
- # Temporary Holding Version
1
+ # [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="28"/>](https://internetdata.io/) InternetData Web Client Library
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/internetdata-web.svg)](https://www.npmjs.com/package/internetdata-web)
4
+ [![license](https://img.shields.io/npm/l/internetdata-web.svg)](LICENSE)
5
+
6
+ The official browser client library for the [InternetData](https://internetdata.io) API, for a page's own scripts and for browser extensions.
7
+
8
+ It looks up what every InternetData database says about an IP address, an AS or a domain.
9
+
10
+ ## Getting Started
11
+
12
+ **An API key in a web page is public.** Anyone who opens the page can read it from the page's source or its network requests and use it as you would: spend your plan's lookups and, if the key may download databases, download every database your organization is licensed for. In a page, use no key, or call the API from your own server and hand the page its answer. A key belongs only where the person it belongs to is the only one who can read it, such as their own browser extension or an internal tool, and there a key that may only look up.
13
+
14
+ ```bash
15
+ npm install internetdata-web
16
+ ```
17
+
18
+ Or, with no build step, import it from jsDelivr in a module script:
19
+
20
+ ```html
21
+ <script type="module">
22
+ import { InternetData } from 'https://cdn.jsdelivr.net/npm/internetdata-web@1/+esm';
23
+
24
+ const me = await new InternetData().myIp();
25
+ console.log(me.location.country);
26
+ </script>
27
+ ```
28
+
29
+ It runs in Chrome and Edge 109, Firefox 115 ESR and Safari 16.4 or newer. TypeScript types are included.
30
+
31
+ ## Usage
32
+
33
+ **No API key needed to start.** Unlimited, the free plan, answers Tor, relay, anycast, carrier, satellite and the five service flags (SSH, SMTP, web, DNS resolver and BitTorrent), reverse DNS, country-level `location`, `asn`, the company's name and domain and the abuse email, with no daily or monthly cap, with a key or without one. In a page the address calling is the visitor's, so `myIp` tells you about the visitor:
34
+
35
+ ```js
36
+ import { InternetData } from 'internetdata-web';
37
+
38
+ const client = new InternetData();
39
+
40
+ const me = await client.myIp();
41
+ console.log(me.location.country); // where this visitor is
42
+
43
+ const result = await client.lookup('146.70.116.130');
44
+ console.log(result.isTor); // false
45
+ console.log(result.location.country); // the ISO 3166 country code
46
+ console.log(result.company.name); // who the address belongs to
47
+ ```
48
+
49
+ ### With an API key
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, 100 lookups a day. Create a key in the [console](https://app.internetdata.io), then pass it in:
52
+
53
+ ```js
54
+ const client = new InternetData({ apiKey: 'your-api-key' });
55
+
56
+ const result = await client.lookup('146.70.116.130');
57
+ console.log(result.isVpn); // on a paid plan
58
+ console.log(result.vpn?.provider); // on a paid plan
59
+ console.log(result.location.city); // on a paid plan
60
+ ```
61
+
62
+ An extension can sign its user in rather than ask them to paste a key: see Sign in with OAuth below.
63
+
64
+ ### An AS or a domain
65
+
66
+ ```js
67
+ const asn = await client.lookupAsn(9009);
68
+ console.log(asn.name); // M247 Europe SRL
69
+ console.log(asn.prefixes); // on a paid plan
70
+
71
+ const domain = await client.lookupDomain('example.com');
72
+ console.log(domain.isRegistered); // true
73
+ console.log(domain.dns?.mx); // on a paid plan
74
+ ```
75
+
76
+ Unlimited answers an AS's registration, and whether a domain is registered and which record types it has. A paid plan adds the AS's whois record and prefixes, and the domain's records, IP ranges and whether it is disposable. Neither lookup is cached or batched, and `lookup` refuses an AS or a domain before sending it.
77
+
78
+ ### Your own address
79
+
80
+ ```js
81
+ const result = await client.myIp();
82
+ console.log(result.ip); // the address we saw this call come from: in a page, the visitor's
83
+ ```
84
+
85
+ It is never cached, since which address the browser is calling from is the question, and a laptop moves between networks.
86
+
87
+ ### Your plan and usage
88
+
89
+ ```js
90
+ const ent = await client.myEntitlement();
91
+ console.log(ent.plan.key); // starter
92
+ console.log(ent.usage.requests); // 580
93
+ console.log(ent.usage.window_end); // when the allowance resets
94
+ ```
95
+
96
+ 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.
97
+
98
+ ### Batch lookup
99
+
100
+ 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 a paid plan:
101
+
102
+ ```js
103
+ const results = await client.lookupBatch(['146.70.116.130', '8.8.8.8', '1.1.1.1']);
104
+
105
+ for (const [ip, result] of results) {
106
+ if (result instanceof Error) {
107
+ console.log(`${ip}: ${result.message}`);
108
+ continue;
109
+ }
110
+ console.log(`${ip}: ${result.isVpn}`);
111
+ }
112
+ ```
113
+
114
+ Results are keyed by address, in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own.
115
+
116
+ How many chunks are in flight at once, how many times a failed chunk is retried, and how long each request may take are configurable per call:
117
+
118
+ ```js
119
+ const results = await client.lookupBatch(manyIps, { concurrency: 4, retries: 4, timeoutMs: 10_000 });
120
+ ```
121
+
122
+ ### Caching
123
+
124
+ Answers are cached in memory by default, so repeat lookups of the same address are free, and lookups of one address made at the same moment share a single request:
125
+
126
+ ```js
127
+ const client = new InternetData();
128
+
129
+ const result = await client.lookup('146.70.116.130');
130
+ console.log(result.isTor); // false, API request
131
+
132
+ const result2 = await client.lookup('146.70.116.130');
133
+ console.log(result2.isTor); // false, no API request, result was cached
134
+ ```
135
+
136
+ You can change the default cache variables (max size, TTL, etc) on initialization, or even disable it:
137
+
138
+ ```js
139
+ const client = new InternetData({ cache: { max: 50_000, ttlMs: 6 * 60 * 60 * 1000 } });
140
+ const clientNoCache = new InternetData({ cache: false });
141
+ ```
142
+
143
+ ### Keeping answers across a reload
144
+
145
+ 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:
146
+
147
+ ```js
148
+ const store = {
149
+ get(key) {
150
+ const saved = JSON.parse(sessionStorage.getItem(`internetdata:${key}`) ?? 'null');
151
+ return saved !== null && saved.expires > Date.now() ? saved.result : undefined;
152
+ },
153
+ set(key, result, ttlMs) {
154
+ const saved = { result: result, expires: Date.now() + ttlMs };
155
+ sessionStorage.setItem(`internetdata:${key}`, JSON.stringify(saved));
156
+ },
157
+ };
158
+
159
+ const client = new InternetData({ cache: { store: store } });
160
+ ```
161
+
162
+ In an extension's service worker, `chrome.storage.session` does the same. A store's methods may return promises, as these do:
163
+
164
+ ```js
165
+ const store = {
166
+ async get(key) {
167
+ const saved = (await chrome.storage.session.get(key))[key];
168
+ return saved !== undefined && saved.expires > Date.now() ? saved.result : undefined;
169
+ },
170
+ async set(key, result, ttlMs) {
171
+ await chrome.storage.session.set({ [key]: { result: result, expires: Date.now() + ttlMs } });
172
+ },
173
+ };
174
+
175
+ const client = new InternetData({ cache: { store: store } });
176
+ ```
177
+
178
+ `set` is told how long the answer stays fresh, and dropping it after that is the store's job. Each `key` carries a hash of the client's API key and base URL beside the address, so clients holding different keys can share one store without reading each other's answers. Bogons, errors, `myIp`, `myEntitlement` and the AS and domain lookups are never stored, and a store that fails costs a request, never an answer: a `get` that throws reads as a miss, and a `set` that throws is ignored.
179
+
180
+ ### Private and reserved addresses
181
+
182
+ Private, loopback, link-local, documentation and multicast addresses (and their IPv6 equivalents, including the 6to4 and Teredo ranges) are answered locally, so they cost no request and no quota. Each gets the answer the API gives one, every flag false bar `is_bogon` and every other field empty:
183
+
184
+ ```js
185
+ const result = await client.lookup('192.168.1.1');
186
+ result.isBogon; // true
187
+ result.isVpn; // false
188
+ ```
189
+
190
+ The check is available on the client, which is handy when your inputs are addresses anyway:
191
+
192
+ ```js
193
+ client.isBogon('10.0.0.1'); // true
194
+ client.isBogon('8.8.8.8'); // false
195
+ ```
196
+
197
+ It is also importable on its own, if you want it without a client:
198
+
199
+ ```js
200
+ import { isBogon } from 'internetdata-web';
201
+
202
+ isBogon('10.0.0.1'); // true
203
+ ```
204
+
205
+ ### Errors
206
+
207
+ Failures throw an `InternetDataError` carrying a `kind` and a `retryable` flag:
208
+
209
+ ```js
210
+ import { InternetDataError } from 'internetdata-web';
211
+
212
+ try {
213
+ await client.lookup('1.1.1.1');
214
+ } catch (err) {
215
+ if (err instanceof InternetDataError) {
216
+ console.error(err.kind, err.retryable);
217
+ }
218
+ }
219
+ ```
220
+
221
+ `kind` is one of `bad_request`, `unauthorized`, `forbidden`, `rate_limited`, `quota_exceeded`, `server_error` or `network`.
222
+
223
+ 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.
224
+
225
+ 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.
226
+
227
+ ### Timeouts
228
+
229
+ A request that hasn't finished after 30 seconds is abandoned and surfaces as a retryable `network` error. The limit applies to each attempt, so a call that gets retried can take longer in total. Set it for the client, or for a single lookup:
230
+
231
+ ```js
232
+ const client = new InternetData({ timeoutMs: 10_000 });
233
+
234
+ const result = await client.lookup('146.70.116.130', { timeoutMs: 2000 });
235
+ ```
236
+
237
+ ### Sign in with OAuth (authorization code)
238
+
239
+ An app or an extension that can take a browser redirect signs the person in there, with a PKCE pair made for that one sign-in:
240
+
241
+ ```js
242
+ const client = new InternetData();
243
+ const redirectUri = 'https://your-app.example/callback';
244
+ const pkce = await client.oauth.createPkce();
245
+
246
+ const url = client.oauth.authorizationUrl('your-client-id', redirectUri, pkce.challenge, {
247
+ scope: 'apikeys.use', state: 'your-state',
248
+ });
249
+ // Send the browser to url. Its redirect to redirectUri carries code and state.
250
+ const token = await client.oauth.exchangeAuthorizationCode('your-client-id', code, pkce.verifier, redirectUri);
251
+ ```
252
+
253
+ 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.
254
+
255
+ `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. Client IDs are issued on request from support@internetdata.io.
256
+
257
+ ### Browser support
258
+
259
+ The library is ES2022 and needs only what a browser has, `fetch` and, for PKCE, Web Crypto, so it runs in Chrome and Edge 109, Firefox 115 ESR and Safari 16.4 or newer: in a page, a web worker, or an extension's service worker. Every endpoint it calls answers CORS for any origin, so a page needs nothing from your server. A page whose Content-Security-Policy restricts `connect-src` must allow `https://api.internetdata.io`, and `https://internetdata.io` to sign in. For Node.js, use [@internetdata/internetdata](https://www.npmjs.com/package/@internetdata/internetdata) instead.
260
+
261
+ ### Absent is not false
262
+
263
+ 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 daily trial is spent. A field your key does not include is `undefined`, which means "not in your plan" rather than "checked, and no".
264
+
265
+ ```js
266
+ result.isVpn ?? false // when you only want the flag
267
+ result.isVpn === undefined // on Unlimited: not in your plan
268
+ result.trialExpired === true // a free-plan key's daily trial is spent
269
+ ```
270
+
271
+ ## Other Libraries
272
+
273
+ There are official InternetData client libraries available for many languages including PHP, Python, Go, Java, and Ruby. See our GitHub at https://github.com/internetdata for more.
274
+
275
+ ## About InternetData
276
+
277
+ Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, as an API and as databases you download and query yourself.
278
+
279
+ [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="64"/>](https://internetdata.io/)
280
+
281
+ ## License
282
+
283
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,31 @@
1
+ import { type Result } from './types.js';
2
+ /**
3
+ * Whether an address is a bogon: private, loopback, link-local, documentation,
4
+ * multicast or otherwise not routable on the public internet, including the
5
+ * IPv6 equivalents and the 6to4 and Teredo ranges that wrap them.
6
+ *
7
+ * The API answers one from the address alone, so the client answers them
8
+ * itself and they never cost a request. An IPv4-mapped address
9
+ * (`::ffff:8.8.8.8`) is judged as the IPv4 address it carries.
10
+ */
11
+ export declare function isBogon(ip: string): boolean;
12
+ /** Whether a string is an IPv4 or an IPv6 address, as `isBogon` reads one. */
13
+ export declare function isAddress(ip: string): boolean;
14
+ /**
15
+ * The IPv4 address an IPv4-mapped IPv6 address carries, dotted, and any other
16
+ * string as given. A server listening on `::` sees every IPv4 visitor in the
17
+ * mapped form, which is inside `::ffff:0:0/96` and so read whole would answer
18
+ * every one of them as a bogon, with no request made.
19
+ */
20
+ export declare function unmapped(ip: string): string;
21
+ /**
22
+ * The answer a bogon gets, in the shape the API answers one on a paid plan:
23
+ * every flag present and false, every detail object present and empty (Web
24
+ * IP's list empty), `location`, `asn`, `company`, `abuse`, `whois` and `rwhois`
25
+ * with every key empty, `hostname` empty, `hosted_domains` 0 with no domains, and
26
+ * `is_bogon` true, as the API serves it.
27
+ *
28
+ * Note this is the WIDEST shape regardless of your plan, so do not infer which
29
+ * fields your plan includes from a bogon answer.
30
+ */
31
+ export declare function bogonResult(ip: string): Result;
package/dist/bogon.js ADDED
@@ -0,0 +1,214 @@
1
+ import { BOGON_V4, BOGON_V6 } from './bogons.gen.js';
2
+ import { toResult } from './types.js';
3
+ /**
4
+ * Whether an address is a bogon: private, loopback, link-local, documentation,
5
+ * multicast or otherwise not routable on the public internet, including the
6
+ * IPv6 equivalents and the 6to4 and Teredo ranges that wrap them.
7
+ *
8
+ * The API answers one from the address alone, so the client answers them
9
+ * itself and they never cost a request. An IPv4-mapped address
10
+ * (`::ffff:8.8.8.8`) is judged as the IPv4 address it carries.
11
+ */
12
+ export function isBogon(ip) {
13
+ const addr = unmapped(ip);
14
+ if (addr.includes(':')) {
15
+ const a = v6ToInt(addr);
16
+ return a === null ? false : v6().some((r) => (a & r.mask) === r.net);
17
+ }
18
+ const a = v4ToInt(addr);
19
+ return a === null ? false : v4().some((r) => (a & r.mask) >>> 0 === r.net);
20
+ }
21
+ /** Whether a string is an IPv4 or an IPv6 address, as `isBogon` reads one. */
22
+ export function isAddress(ip) {
23
+ return ip.includes(':') ? v6ToInt(ip) !== null : v4ToInt(ip) !== null;
24
+ }
25
+ /**
26
+ * The IPv4 address an IPv4-mapped IPv6 address carries, dotted, and any other
27
+ * string as given. A server listening on `::` sees every IPv4 visitor in the
28
+ * mapped form, which is inside `::ffff:0:0/96` and so read whole would answer
29
+ * every one of them as a bogon, with no request made.
30
+ */
31
+ export function unmapped(ip) {
32
+ if (!ip.includes(':')) {
33
+ return ip;
34
+ }
35
+ const a = v6ToInt(ip);
36
+ if (a === null || a >> 32n !== 0xffffn) {
37
+ return ip;
38
+ }
39
+ const n = Number(a & 0xffffffffn);
40
+ return [n >>> 24, (n >>> 16) & 0xff, (n >>> 8) & 0xff, n & 0xff].join('.');
41
+ }
42
+ /**
43
+ * The answer a bogon gets, in the shape the API answers one on a paid plan:
44
+ * every flag present and false, every detail object present and empty (Web
45
+ * IP's list empty), `location`, `asn`, `company`, `abuse`, `whois` and `rwhois`
46
+ * with every key empty, `hostname` empty, `hosted_domains` 0 with no domains, and
47
+ * `is_bogon` true, as the API serves it.
48
+ *
49
+ * Note this is the WIDEST shape regardless of your plan, so do not infer which
50
+ * fields your plan includes from a bogon answer.
51
+ */
52
+ export function bogonResult(ip) {
53
+ return toResult(bogonAnswer(ip));
54
+ }
55
+ function bogonAnswer(ip) {
56
+ return {
57
+ ip: ip,
58
+ is_bogon: true,
59
+ is_vpn: false,
60
+ is_tor: false,
61
+ is_relay: false,
62
+ is_resproxy: false,
63
+ is_dcproxy: false,
64
+ is_mobproxy: false,
65
+ is_pubproxy: false,
66
+ is_hosting: false,
67
+ is_cdn: false,
68
+ is_anycast: false,
69
+ is_carrier: false,
70
+ is_satellite: false,
71
+ is_ssh: false,
72
+ is_smtp: false,
73
+ is_web: false,
74
+ is_dns_resolver: false,
75
+ is_bittorrent: false,
76
+ vpn: {},
77
+ tor: {},
78
+ relay: {},
79
+ resproxy: {},
80
+ dcproxy: {},
81
+ mobproxy: {},
82
+ pubproxy: {},
83
+ hosting: {},
84
+ cdn: {},
85
+ carrier: {},
86
+ satellite: {},
87
+ ssh: {},
88
+ smtp: {},
89
+ web: [],
90
+ dns_resolver: {},
91
+ bittorrent: {},
92
+ location: {
93
+ continent: '',
94
+ continent_name: '',
95
+ country: '',
96
+ country_name: '',
97
+ timezone: '',
98
+ currency_code: '',
99
+ currency_name: '',
100
+ currency_symbol: '',
101
+ flag_emoji: '',
102
+ flag_unicode: '',
103
+ region: '',
104
+ region_code: '',
105
+ city: '',
106
+ postal_code: '',
107
+ latitude: 0,
108
+ longitude: 0,
109
+ accuracy_radius: 0,
110
+ geoname_id: '',
111
+ dma_code: '',
112
+ last_changed: '',
113
+ },
114
+ asn: { asn: 0, name: '', domain: '', type: '', prefix: '', country: '', rpki_status: '' },
115
+ company: { name: '', domain: '', type: '', country: '' },
116
+ hostname: '',
117
+ abuse: {
118
+ email: '',
119
+ name: '',
120
+ phone: '',
121
+ address: '',
122
+ country: '',
123
+ network: '',
124
+ validated: false,
125
+ unvalidated_since: '',
126
+ },
127
+ whois: {
128
+ id: '', name: '', org: '', country: '', status: '', source: '', domain: '', abuse_email: '', asn: 0,
129
+ },
130
+ rwhois: { id: '', name: '', country: '', source: '', domain: '', abuse_email: '' },
131
+ hosted_domains: { total: 0, domains: [] },
132
+ };
133
+ }
134
+ // Parsed once on first use rather than at import: a consumer that never looks
135
+ // up an address should not pay for the table, and module-scope work is what
136
+ // makes a library expensive to import.
137
+ let v4Cache = null;
138
+ let v6Cache = null;
139
+ function v4() {
140
+ if (!v4Cache) {
141
+ v4Cache = BOGON_V4.map((c) => {
142
+ const [net, bits] = c.split('/');
143
+ const mask = bits === '0' ? 0 : (~0 << (32 - Number(bits))) >>> 0;
144
+ return { net: (v4ToInt(net) & mask) >>> 0, mask: mask };
145
+ });
146
+ }
147
+ return v4Cache;
148
+ }
149
+ function v6() {
150
+ if (!v6Cache) {
151
+ v6Cache = BOGON_V6.map((c) => {
152
+ const [net, bits] = c.split('/');
153
+ const mask = bits === '0' ? 0n : (~0n << BigInt(128 - Number(bits))) & MAX128;
154
+ return { net: v6ToInt(net) & mask, mask: mask };
155
+ });
156
+ }
157
+ return v6Cache;
158
+ }
159
+ const MAX128 = (1n << 128n) - 1n;
160
+ function v4ToInt(ip) {
161
+ const p = ip.split('.');
162
+ if (p.length !== 4) {
163
+ return null;
164
+ }
165
+ let n = 0;
166
+ for (const part of p) {
167
+ const b = Number(part);
168
+ if (!Number.isInteger(b) || b < 0 || b > 255 || part === '') {
169
+ return null;
170
+ }
171
+ n = ((n << 8) | b) >>> 0;
172
+ }
173
+ return n;
174
+ }
175
+ // Handles the `::` run and a trailing IPv4 literal (::ffff:1.2.3.4), which
176
+ // several of the canonical ranges use.
177
+ function v6ToInt(ip) {
178
+ let a = ip;
179
+ const v4Tail = a.match(/(\d+\.\d+\.\d+\.\d+)$/);
180
+ if (v4Tail) {
181
+ const n = v4ToInt(v4Tail[1]);
182
+ if (n === null) {
183
+ return null;
184
+ }
185
+ const hi = (n >>> 16).toString(16).padStart(4, '0');
186
+ const lo = (n & 0xffff).toString(16).padStart(4, '0');
187
+ a = `${a.slice(0, v4Tail.index)}${hi}:${lo}`;
188
+ }
189
+ const dbl = a.indexOf('::');
190
+ let groups;
191
+ if (dbl === -1) {
192
+ groups = a.split(':');
193
+ if (groups.length !== 8) {
194
+ return null;
195
+ }
196
+ }
197
+ else {
198
+ const head = a.slice(0, dbl).split(':').filter((g) => g !== '');
199
+ const tail = a.slice(dbl + 2).split(':').filter((g) => g !== '');
200
+ const fill = 8 - head.length - tail.length;
201
+ if (fill < 0) {
202
+ return null;
203
+ }
204
+ groups = [...head, ...Array(fill).fill('0'), ...tail];
205
+ }
206
+ let n = 0n;
207
+ for (const g of groups) {
208
+ if (!/^[0-9a-fA-F]{1,4}$/.test(g)) {
209
+ return null;
210
+ }
211
+ n = (n << 16n) | BigInt(parseInt(g, 16));
212
+ }
213
+ return n;
214
+ }
@@ -0,0 +1,2 @@
1
+ export declare const BOGON_V4: readonly string[];
2
+ export declare const BOGON_V6: readonly string[];
@@ -0,0 +1,87 @@
1
+ // Generated. Do not edit: a regeneration overwrites it.
2
+ // The list is checked against both upstream definitions on every
3
+ // regeneration.
4
+ export const BOGON_V4 = [
5
+ '0.0.0.0/8',
6
+ '10.0.0.0/8',
7
+ '100.64.0.0/10',
8
+ '127.0.0.0/8',
9
+ '169.254.0.0/16',
10
+ '172.16.0.0/12',
11
+ '192.0.0.0/24',
12
+ '192.0.2.0/24',
13
+ '192.88.99.2/32',
14
+ '192.168.0.0/16',
15
+ '198.18.0.0/15',
16
+ '198.51.100.0/24',
17
+ '203.0.113.0/24',
18
+ '224.0.0.0/4',
19
+ '255.255.255.255/32',
20
+ '240.0.0.0/4',
21
+ ];
22
+ export const BOGON_V6 = [
23
+ '::/128',
24
+ '::1/128',
25
+ '::ffff:0:0/96',
26
+ '::/96',
27
+ '64:ff9b::/96',
28
+ '64:ff9b:1::/48',
29
+ '100::/64',
30
+ '100:0:0:1::/64',
31
+ '2001:2::/48',
32
+ '2001:10::/28',
33
+ '2001:db8::/32',
34
+ '3fff::/20',
35
+ '5f00::/16',
36
+ 'fc00::/7',
37
+ 'fe80::/10',
38
+ 'fec0::/10',
39
+ 'ff00::/8',
40
+ '2002::/24',
41
+ '2002:a00::/24',
42
+ '2002:6440::/26',
43
+ '2002:7f00::/24',
44
+ '2002:a9fe::/32',
45
+ '2002:ac10::/28',
46
+ '2002:c000::/40',
47
+ '2002:c000:200::/40',
48
+ '2002:c058:6302::/48',
49
+ '2002:c0a8::/32',
50
+ '2002:c612::/31',
51
+ '2002:c633:6400::/40',
52
+ '2002:cb00:7100::/40',
53
+ '2002:e000::/20',
54
+ '2002:ffff:ffff::/48',
55
+ '2002:f000::/20',
56
+ '2001::/40',
57
+ '2001:0:a00::/40',
58
+ '2001:0:6440::/42',
59
+ '2001:0:7f00::/40',
60
+ '2001:0:a9fe::/48',
61
+ '2001:0:ac10::/44',
62
+ '2001:0:c000::/56',
63
+ '2001:0:c000:200::/56',
64
+ '2001:0:c058:6302::/64',
65
+ '2001:0:c0a8::/48',
66
+ '2001:0:c612::/47',
67
+ '2001:0:c633:6400::/56',
68
+ '2001:0:cb00:7100::/56',
69
+ '2001:0:e000::/36',
70
+ '2001:0:ffff:ffff::/64',
71
+ '2001:0:f000::/36',
72
+ '2001:1::/32',
73
+ '2001:2::/31',
74
+ '2001:4::/30',
75
+ '2001:8::/29',
76
+ '2001:20::/27',
77
+ '2001:40::/26',
78
+ '2001:80::/25',
79
+ '2001:100::/24',
80
+ '::/3',
81
+ '4000::/3',
82
+ '6000::/3',
83
+ '8000::/3',
84
+ 'a000::/3',
85
+ 'c000::/3',
86
+ 'e000::/3',
87
+ ];