internetdata-web 1.7.0 → 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 Tor, relay, bot, 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:
33
+ **No API key needed to start.** Unlimited, the free plan, answers Tor, relay and anycast, 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
34
 
35
35
  ```js
36
36
  import { InternetData } from 'internetdata-web';
@@ -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), a paid plan answers every field: `is_vpn`, `is_hosting`, `is_cdn` and the four proxy flags as well, city-level location, the whois records, `user_agent` (whether a user agent you send is borne out by the address: see below) and the detail behind each flag. Its quotas 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:
51
+ Where the key stays private (see above), a paid plan answers every field: `is_vpn`, `is_hosting`, `is_cdn`, `is_bot`, `is_carrier`, `is_satellite`, the four proxy flags and the five service flags as well, city-level location, the whois records, `user_agent` (whether a user agent you send is borne out by the address: see below) and the detail behind each flag. Its quotas 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' });
@@ -283,11 +283,13 @@ The library is ES2022 and needs only what a browser has, `fetch` and, for PKCE,
283
283
 
284
284
  ### Absent is not false
285
285
 
286
- Unlimited leaves out `isVpn`, `isHosting`, `isCdn` and the four proxy flags, the detail behind them, `bot` (whose bot it is, behind `isBot`), 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".
286
+ Unlimited leaves out `isVpn`, `isHosting`, `isCdn`, `isBot`, `isCarrier`, `isSatellite`, the four proxy flags and the five service flags (`isSsh`, `isSmtp`, `isWeb`, `isDnsResolver` and `isBittorrent`), the detail behind them, `bot` (whose bot it is, behind `isBot`), 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". The one exception, until the next major release: `isCarrier`, `isSatellite` and the five service flags are typed `boolean`, so on Unlimited they read `false`, and `result.raw` shows they were not served.
287
287
 
288
288
  ```js
289
289
  result.isVpn ?? false // when you only want the flag
290
290
  result.isVpn === undefined // on Unlimited: not in your plan
291
+ result.isBot === undefined // likewise
292
+ result.isSsh === false // on Unlimited: read as false, though 'is_ssh' is not in result.raw
291
293
  result.trialExpired === true // a free-plan key's trial is spent
292
294
  result.capReached === true // a paid key is past its overage cap
293
295
  ```
@@ -164,41 +164,41 @@ export type LookupResponse = {
164
164
  */
165
165
  is_cdn?: boolean;
166
166
  /**
167
- * In Bot IP: an automated client's 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.
167
+ * In Bot IP: an automated client's 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. On a paid plan or the trial.
168
168
  */
169
- is_bot: boolean;
169
+ is_bot?: boolean;
170
170
  /**
171
171
  * In Anycast IP: announced from many places at once.
172
172
  */
173
173
  is_anycast: boolean;
174
174
  /**
175
- * In Carrier IP: a mobile carrier's address space.
175
+ * In Carrier IP: a mobile carrier's address space. On a paid plan or the trial.
176
176
  */
177
- is_carrier: boolean;
177
+ is_carrier?: boolean;
178
178
  /**
179
- * In Satellite IP: a satellite operator's address space.
179
+ * In Satellite IP: a satellite operator's address space. On a paid plan or the trial.
180
180
  */
181
- is_satellite: boolean;
181
+ is_satellite?: boolean;
182
182
  /**
183
- * In SSH IP: an SSH server answered here.
183
+ * In SSH IP: an SSH server answered here. On a paid plan or the trial.
184
184
  */
185
- is_ssh: boolean;
185
+ is_ssh?: boolean;
186
186
  /**
187
- * In SMTP IP: a mail server answered here.
187
+ * In SMTP IP: a mail server answered here. On a paid plan or the trial.
188
188
  */
189
- is_smtp: boolean;
189
+ is_smtp?: boolean;
190
190
  /**
191
- * In Web IP: a web server answered here on port 80 or 443.
191
+ * In Web IP: a web server answered here on port 80 or 443. On a paid plan or the trial.
192
192
  */
193
- is_web: boolean;
193
+ is_web?: boolean;
194
194
  /**
195
- * In DNS Resolver IP: an open DNS resolver answered here.
195
+ * In DNS Resolver IP: an open DNS resolver answered here. On a paid plan or the trial.
196
196
  */
197
- is_dns_resolver: boolean;
197
+ is_dns_resolver?: boolean;
198
198
  /**
199
- * In BitTorrent IP: a BitTorrent client was seen here in the last 90 days.
199
+ * In BitTorrent IP: a BitTorrent client was seen here in the last 90 days. On a paid plan or the trial.
200
200
  */
201
- is_bittorrent: boolean;
201
+ is_bittorrent?: boolean;
202
202
  /**
203
203
  * VPN IP's row, `{}` when `is_vpn` is false. On a paid plan or the trial.
204
204
  */
@@ -753,9 +753,9 @@ export type Asn = {
753
753
  */
754
754
  domain: string;
755
755
  /**
756
- * The kind of network it runs.
756
+ * The kind of network it runs. On a paid plan or the trial.
757
757
  */
758
- type: string;
758
+ type?: string;
759
759
  /**
760
760
  * The announced prefix covering the address.
761
761
  */
package/dist/shapes.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export declare const LOOKUP_MEMBERS: readonly ["ip", "is_bogon", "is_tor", "is_relay", "is_bot", "is_anycast", "is_carrier", "is_satellite", "is_ssh", "is_smtp", "is_web", "is_dns_resolver", "is_bittorrent", "tor", "relay", "location", "asn", "company", "hostname", "abuse"];
1
+ export declare const LOOKUP_MEMBERS: readonly ["ip", "is_bogon", "is_tor", "is_relay", "is_anycast", "tor", "relay", "location", "asn", "company", "hostname", "abuse"];
2
2
  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"];
3
3
  export declare const LOCATION_MEMBERS: readonly ["continent", "continent_name", "country", "country_name", "timezone", "currency_code", "currency_name", "currency_symbol", "flag_emoji", "flag_unicode"];
4
- export declare const ASN_MEMBERS: readonly ["asn", "name", "domain", "type", "prefix", "country", "rpki_status"];
4
+ export declare const ASN_MEMBERS: readonly ["asn", "name", "domain", "prefix", "country", "rpki_status"];
5
5
  export declare const COMPANY_MEMBERS: readonly ["name", "domain"];
6
6
  export declare const USER_AGENT_VERDICT_MEMBERS: readonly ["agent", "kind", "verdict"];
7
7
  export declare const ABUSE_CONTACT_MEMBERS: readonly ["email"];
@@ -30,6 +30,8 @@ export declare const ENTITLEMENT_MEMBERS: readonly ["org_id", "apikey", "plan",
30
30
  export declare const ENTITLEMENT_APIKEY_MEMBERS: readonly ["id", "allowed_cidrs"];
31
31
  export declare const ENTITLEMENT_PLAN_MEMBERS: readonly ["key", "name", "tier"];
32
32
  export declare const ENTITLEMENT_USAGE_MEMBERS: readonly ["requests", "quota", "window_start", "window_end"];
33
+ export declare const PAID_FLAGS: readonly ["is_bot", "is_carrier", "is_satellite", "is_ssh", "is_smtp", "is_web", "is_dns_resolver", "is_bittorrent"];
34
+ export declare const ASN_NOT_NULL: readonly ["type"];
33
35
  type Kind = 'string' | 'integer' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'date-time';
34
36
  export declare const LOOKUP_TYPES: Record<string, Kind>;
35
37
  export declare const CLASS_DETAIL_TYPES: Record<string, Kind>;
package/dist/shapes.js CHANGED
@@ -3,8 +3,7 @@
3
3
  // generated types, so a member the spec adds fails the suite until it is here.
4
4
  import { hasMembers } from './transport.js';
5
5
  export const LOOKUP_MEMBERS = [
6
- 'ip', 'is_bogon', 'is_tor', 'is_relay', 'is_bot', 'is_anycast', 'is_carrier', 'is_satellite', 'is_ssh',
7
- 'is_smtp', 'is_web', 'is_dns_resolver', 'is_bittorrent', 'tor', 'relay', 'location', 'asn', 'company',
6
+ 'ip', 'is_bogon', 'is_tor', 'is_relay', 'is_anycast', 'tor', 'relay', 'location', 'asn', 'company',
8
7
  'hostname', 'abuse',
9
8
  ];
10
9
  export const WEB_DETAIL_MEMBERS = [
@@ -15,7 +14,7 @@ export const LOCATION_MEMBERS = [
15
14
  'continent', 'continent_name', 'country', 'country_name', 'timezone', 'currency_code', 'currency_name',
16
15
  'currency_symbol', 'flag_emoji', 'flag_unicode',
17
16
  ];
18
- export const ASN_MEMBERS = ['asn', 'name', 'domain', 'type', 'prefix', 'country', 'rpki_status'];
17
+ export const ASN_MEMBERS = ['asn', 'name', 'domain', 'prefix', 'country', 'rpki_status'];
19
18
  export const COMPANY_MEMBERS = ['name', 'domain'];
20
19
  export const USER_AGENT_VERDICT_MEMBERS = ['agent', 'kind', 'verdict'];
21
20
  export const ABUSE_CONTACT_MEMBERS = ['email'];
@@ -50,6 +49,11 @@ export const ENTITLEMENT_MEMBERS = ['org_id', 'apikey', 'plan', 'usage'];
50
49
  export const ENTITLEMENT_APIKEY_MEMBERS = ['id', 'allowed_cidrs'];
51
50
  export const ENTITLEMENT_PLAN_MEMBERS = ['key', 'name', 'tier'];
52
51
  export const ENTITLEMENT_USAGE_MEMBERS = ['requests', 'quota', 'window_start', 'window_end'];
52
+ // Members the spec no longer requires, which an answer may omit and may never send as null.
53
+ export const PAID_FLAGS = [
54
+ 'is_bot', 'is_carrier', 'is_satellite', 'is_ssh', 'is_smtp', 'is_web', 'is_dns_resolver', 'is_bittorrent',
55
+ ];
56
+ export const ASN_NOT_NULL = ['type'];
53
57
  const FLAG = 'boolean';
54
58
  export const LOOKUP_TYPES = {
55
59
  ip: 'string', is_bogon: FLAG, is_vpn: FLAG, is_tor: FLAG, is_relay: FLAG, is_resproxy: FLAG, is_dcproxy: FLAG,
@@ -229,10 +233,17 @@ function isDay(year, month, day) {
229
233
  return date.getUTCFullYear() === Number(year) && date.getUTCMonth() === Number(month) - 1
230
234
  && date.getUTCDate() === Number(day);
231
235
  }
232
- function typed(value, required, types) {
236
+ // A member in `notNull` may be absent but never null, as one the spec once required.
237
+ function typed(value, required, types, notNull = []) {
233
238
  return hasMembers(value, required) && Object.entries(types).every(([member, kind]) => {
234
239
  const v = value[member];
235
- return v === undefined || v === null ? !required.includes(member) : isKind(v, kind);
240
+ if (v === undefined) {
241
+ return !required.includes(member);
242
+ }
243
+ if (v === null) {
244
+ return !required.includes(member) && !notNull.includes(member);
245
+ }
246
+ return isKind(v, kind);
236
247
  });
237
248
  }
238
249
  function every(value, valid) {
@@ -261,16 +272,16 @@ const DETAILS = [
261
272
  ];
262
273
  // Required where the lookup itself requires them, and optional otherwise.
263
274
  const SHARED = [
264
- ['location', LOCATION_MEMBERS, LOCATION_TYPES],
265
- ['asn', ASN_MEMBERS, ASN_TYPES],
266
- ['company', COMPANY_MEMBERS, COMPANY_TYPES],
267
- ['abuse', ABUSE_CONTACT_MEMBERS, ABUSE_CONTACT_TYPES],
268
- ['whois', WHOIS_MEMBERS, WHOIS_TYPES],
269
- ['rwhois', RWHOIS_MEMBERS, RWHOIS_TYPES],
270
- ['hosted_domains', HOSTED_DOMAINS_MEMBERS, HOSTED_DOMAINS_TYPES],
275
+ ['location', LOCATION_MEMBERS, LOCATION_TYPES, []],
276
+ ['asn', ASN_MEMBERS, ASN_TYPES, ASN_NOT_NULL],
277
+ ['company', COMPANY_MEMBERS, COMPANY_TYPES, []],
278
+ ['abuse', ABUSE_CONTACT_MEMBERS, ABUSE_CONTACT_TYPES, []],
279
+ ['whois', WHOIS_MEMBERS, WHOIS_TYPES, []],
280
+ ['rwhois', RWHOIS_MEMBERS, RWHOIS_TYPES, []],
281
+ ['hosted_domains', HOSTED_DOMAINS_MEMBERS, HOSTED_DOMAINS_TYPES, []],
271
282
  ];
272
283
  export function isLookup(data) {
273
- return typed(data, LOOKUP_MEMBERS, LOOKUP_TYPES)
284
+ return typed(data, LOOKUP_MEMBERS, LOOKUP_TYPES, PAID_FLAGS)
274
285
  && DETAILS.every(([member, types]) => optional(data[member], (detail) => typed(detail, [], types)))
275
286
  && optional(data['pubproxy'], (pubproxy) => lists(pubproxy, 'protocols', isString))
276
287
  && optional(data['bittorrent'], (bittorrent) => lists(bittorrent, 'clients', isString))
@@ -278,7 +289,7 @@ export function isLookup(data) {
278
289
  && optional(data['user_agent'], (verdict) => typed(verdict, USER_AGENT_VERDICT_MEMBERS, USER_AGENT_VERDICT_TYPES))
279
290
  && optional(data['web'], (web) => every(web, (row) => typed(row, WEB_DETAIL_MEMBERS, WEB_DETAIL_TYPES)))
280
291
  && optional(data['hosted_domains'], (hosted) => lists(hosted, 'domains', isString))
281
- && SHARED.every(([member, required, types]) => optional(data[member], (object) => typed(object, required, types)));
292
+ && SHARED.every(([member, required, types, notNull]) => optional(data[member], (object) => typed(object, required, types, notNull)));
282
293
  }
283
294
  export function isAsnLookup(data) {
284
295
  return typed(data, ASN_LOOKUP_MEMBERS, ASN_LOOKUP_TYPES)
@@ -303,7 +314,7 @@ export function isDomainLookup(data) {
303
314
  && optional(data['disposable'], (d) => typed(d, [], DISPOSABLE_DETAIL_TYPES)
304
315
  && lists(d, 'providers', isString))
305
316
  && optional(data['hosting'], (hosting) => every(hosting, (h) => typed(h, DOMAIN_HOST_MEMBERS, DOMAIN_HOST_TYPES)
306
- && typed(h['asn'], ASN_MEMBERS, ASN_TYPES)))
317
+ && typed(h['asn'], ASN_MEMBERS, ASN_TYPES, ASN_NOT_NULL)))
307
318
  && optional(data['cohosted_domains'], (c) => typed(c, COHOSTED_DOMAINS_MEMBERS, COHOSTED_DOMAINS_TYPES)
308
319
  && every(c['domains'], isString))
309
320
  && optional(data['web'], (web) => typed(web, DOMAIN_WEB_MEMBERS, DOMAIN_WEB_TYPES)
package/dist/types.d.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  import type { AbuseContact, Asn as WireAsn, AsnHostedDomains, AsnLookupResponse, AsnPrefix, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, Company, CohostedDomains, DisposableDetail, DnsAddressRecord, DnsCnameRecord, DnsMxRecord, DnsNsRecord, DnsResolverDetail, DomainBacklinks, DomainDns, DomainHost as WireDomainHost, DomainIpRange, DomainIpRanges, DomainLookupResponse as WireDomainLookupResponse, DomainRedirects, DomainWeb, DomainWebLinks, Entitlement, EntitlementApikey, EntitlementPlan, EntitlementUsage, HostedDomains, Location, LookupResponse as WireLookupResponse, ProxyDetail, PubproxyDetail, Rwhois, SatelliteDetail, SmtpDetail, SshDetail, UserAgentVerdict, WebDetail, Whois } from './generated/types.gen.js';
2
2
  export type { AbuseContact, AsnHostedDomains, AsnLookupResponse, AsnPrefix, BitTorrentDetail, BotDetail, CarrierDetail, ClassDetail, Company, CohostedDomains, DisposableDetail, DnsAddressRecord, DnsCnameRecord, DnsMxRecord, DnsNsRecord, DnsResolverDetail, DomainBacklinks, DomainDns, DomainIpRange, DomainIpRanges, DomainRedirects, DomainWeb, DomainWebLinks, Entitlement, EntitlementApikey, EntitlementPlan, EntitlementUsage, HostedDomains, Location, ProxyDetail, PubproxyDetail, Rwhois, SatelliteDetail, SmtpDetail, SshDetail, UserAgentVerdict, WebDetail, Whois, };
3
- /** The network 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. Every answer carries `is_bot`. */
6
- export type LookupResponse = Omit<WireLookupResponse, 'asn' | 'is_bot'> & {
3
+ type HeldFlag = 'is_carrier' | 'is_satellite' | 'is_ssh' | 'is_smtp' | 'is_web' | 'is_dns_resolver' | 'is_bittorrent';
4
+ /**
5
+ * The network announcing an address. Every answer carries `country` and `rpki_status`. `type` is a paid
6
+ * plan's: an Unlimited answer may omit it, though this type still says `string` until the next major.
7
+ */
8
+ export type Asn = Omit<WireAsn, 'country' | 'rpki_status' | 'type'> & Partial<Pick<WireAsn, 'country' | 'rpki_status'>> & Required<Pick<WireAsn, 'type'>>;
9
+ /**
10
+ * A lookup's answer as it came off the wire. `is_bot` is optional here, and the seven flags after it are
11
+ * typed `boolean` until the next major although an Unlimited answer omits them: read them from `Result`,
12
+ * where an absent one is `false`.
13
+ */
14
+ export type LookupResponse = Omit<WireLookupResponse, 'asn' | 'is_bot' | HeldFlag> & {
7
15
  asn: Asn;
8
- } & Partial<Pick<WireLookupResponse, 'is_bot'>>;
16
+ } & Partial<Pick<WireLookupResponse, 'is_bot'>> & Required<Pick<WireLookupResponse, HeldFlag>>;
9
17
  /** An address the domain resolves to, and the network announcing it. */
10
18
  export type DomainHost = Omit<WireDomainHost, 'asn'> & {
11
19
  asn: Asn;
@@ -43,11 +51,14 @@ export interface Result {
43
51
  isCdn?: boolean;
44
52
  /**
45
53
  * In Bot IP: an automated client's address, such as a search engine's or an AI
46
- * company's crawler. Every answer carries it, on every plan; `bot` says whose.
47
- * Optional in this type only so a `Result` written out by hand still compiles.
54
+ * company's crawler. On a paid plan or the trial; absent on Unlimited. `bot` says whose.
48
55
  */
49
56
  isBot?: boolean;
50
57
  isAnycast: boolean;
58
+ /**
59
+ * In Carrier IP, as the six flags after it are each in their own dataset: on a paid plan or the
60
+ * trial. Unlimited's answer omits them, and they read `false` there rather than absent until the next major.
61
+ */
51
62
  isCarrier: boolean;
52
63
  isSatellite: boolean;
53
64
  isSsh: boolean;
package/dist/types.js CHANGED
@@ -30,8 +30,17 @@ const DOMAIN_RESULT_NAMES = {
30
30
  web: 'web', redirects: 'redirects', backlinks: 'backlinks', trial_expired: 'trialExpired',
31
31
  cap_reached: 'capReached',
32
32
  };
33
+ // Typed `boolean` on `Result` until the next major, so an answer without one reads `false`, as every
34
+ // Unlimited answer said before 2026-11-26. `raw` still shows what was served.
35
+ const HELD_FLAGS = [
36
+ 'isCarrier', 'isSatellite', 'isSsh', 'isSmtp', 'isWeb', 'isDnsResolver', 'isBittorrent',
37
+ ];
33
38
  export function toResult(body) {
34
- return renamed(body, RESULT_NAMES);
39
+ const result = renamed(body, RESULT_NAMES);
40
+ for (const flag of HELD_FLAGS) {
41
+ result[flag] ??= false;
42
+ }
43
+ return result;
35
44
  }
36
45
  export function toAsnResult(body) {
37
46
  return renamed(body, ASN_RESULT_NAMES);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "internetdata-web",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
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",