-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
132 lines (117 loc) · 3.61 KB
/
index.js
File metadata and controls
132 lines (117 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import Client from './lib/Client.js';
// Import all method wrappers
import infoMethod from './lib/methods/info.js';
import whoisMethod from './lib/methods/whois.js';
import pingMethod from './lib/methods/ping.js';
import dnsMethod from './lib/methods/dns.js';
import tcpMethod from './lib/methods/tcp.js';
import udpMethod from './lib/methods/udp.js';
import httpMethod from './lib/methods/http.js';
import mtrMethod from './lib/methods/mtr.js';
import locationsMethod from './lib/methods/locations.js';
import reportMethod from './lib/methods/report.js';
import myipMethod from './lib/methods/myip.js';
import ogImageMethod from './lib/methods/og_image.js';
import countryMapMethod from './lib/methods/country_map.js';
/**
* Main CheckHost API Client Class.
*/
export default class CheckHost {
/**
* Initializes the Check-Host API client.
* @param {Object} [options]
* @param {string} [options.apikey] - Your API key for higher limits.
*
* @example
* import CheckHost from 'check-host-api';
* const api = new CheckHost({ apikey: 'YOUR_API_KEY_HERE' });
*/
constructor(options) {
this.client = new Client(options);
}
/**
* Retrieves detailed geolocation data, ISP info, and ASN details.
*/
async info(target) {
return infoMethod(this.client, target);
}
/**
* Performs a WHOIS registry lookup.
*/
async whois(target) {
return whoisMethod(this.client, target);
}
/**
* Dispatches ICMP echo requests to accurately measure network latency.
*/
async ping(target, options) {
return pingMethod(this.client, target, options);
}
/**
* Queries global nameservers for specific DNS records.
*/
async dns(target, options) {
return dnsMethod(this.client, target, options);
}
/**
* Attempts to establish a 3-way TCP handshake.
*/
async tcp(target, port, options) {
return tcpMethod(this.client, target, port, options);
}
/**
* Sends UDP packets to verify service responsiveness.
*/
async udp(target, port, options) {
return udpMethod(this.client, target, port, options);
}
/**
* Executes an HTTP/HTTPS request to measure Time-to-First-Byte and latency.
*/
async http(target, options) {
return httpMethod(this.client, target, options);
}
/**
* Initiates an MTR diagnostic (ping + traceroute).
*/
async mtr(target, options) {
return mtrMethod(this.client, target, options);
}
/**
* Fetches a list of all currently active monitoring nodes.
*/
async locations() {
return locationsMethod(this.client);
}
/**
* Fetches the compiled report and real-time statuses from a check UUID.
*/
async report(uuid) {
return reportMethod(this.client, uuid);
}
/**
* Lightweight endpoint to return the requesting client's public IP.
*/
async myip() {
return myipMethod(this.client);
}
/**
* Fetches the dynamic 1200x630 PNG status map for a check UUID.
* @param {string} uuid
* @returns {Promise<Uint8Array>} Raw PNG bytes.
*/
async ogImage(uuid) {
return ogImageMethod(this.client, uuid);
}
/**
* Fetches the per-country world map for a check UUID.
* @param {string} uuid
* @param {Object} [options]
* @param {'svg'|'png'} [options.format='svg']
* @param {'low'|'med'|'high'} [options.resolution='med']
* @returns {Promise<Uint8Array>}
*/
async countryMap(uuid, options) {
return countryMapMethod(this.client, uuid, options);
}
}