unping 0.0.2 → 0.0.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 +27 -27
- package/dist/drivers/{http.cjs → web.cjs} +6 -6
- package/dist/drivers/web.d.ts +41 -0
- package/dist/drivers/{http.mjs → web.mjs} +4 -4
- package/package.json +1 -1
- package/dist/drivers/http.d.ts +0 -15
package/README.md
CHANGED
|
@@ -50,18 +50,18 @@ console.log(results[0]);
|
|
|
50
50
|
// { host: "google.com", alive: true, time: 5, sequence: 1 }
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
###
|
|
53
|
+
### Web Driver
|
|
54
54
|
|
|
55
|
-
Application layer health checks using HTTP HEAD/GET requests.
|
|
55
|
+
Application layer health checks using HTTP/HTTPS HEAD/GET requests.
|
|
56
56
|
|
|
57
57
|
```typescript
|
|
58
|
-
import
|
|
58
|
+
import webDriver from "unping/drivers/web";
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
driver:
|
|
60
|
+
const web = createPingManager({
|
|
61
|
+
driver: webDriver({ method: "HEAD" }),
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
const results = await
|
|
64
|
+
const results = await web.ping("example.com");
|
|
65
65
|
console.log(`HTTP Status: ${results[0].alive ? "Available" : "Unavailable"}`);
|
|
66
66
|
console.log(`Response Time: ${results[0].time}ms`);
|
|
67
67
|
```
|
|
@@ -112,10 +112,10 @@ Smart detection with automatic fallback between multiple drivers.
|
|
|
112
112
|
```typescript
|
|
113
113
|
import hybridDriver from "unping/drivers/hybrid";
|
|
114
114
|
import tcpDriver from "unping/drivers/tcp";
|
|
115
|
-
import
|
|
115
|
+
import webDriver from "unping/drivers/web";
|
|
116
116
|
import dnsDriver from "unping/drivers/dns";
|
|
117
117
|
|
|
118
|
-
// Use default driver configuration (TCP →
|
|
118
|
+
// Use default driver configuration (TCP → Web → DNS)
|
|
119
119
|
const hybrid = createPingManager({
|
|
120
120
|
driver: hybridDriver(),
|
|
121
121
|
});
|
|
@@ -125,7 +125,7 @@ const customHybrid = createPingManager({
|
|
|
125
125
|
driver: hybridDriver({
|
|
126
126
|
drivers: [
|
|
127
127
|
tcpDriver({ port: 443 }), // Try HTTPS first
|
|
128
|
-
|
|
128
|
+
webDriver({ method: "GET" }), // Then HTTP GET
|
|
129
129
|
dnsDriver({ type: "AAAA" }), // Then IPv6 DNS
|
|
130
130
|
],
|
|
131
131
|
}),
|
|
@@ -164,8 +164,8 @@ console.log(`Average Time: ${avgTime.toFixed(0)}ms`);
|
|
|
164
164
|
### Available Drivers
|
|
165
165
|
|
|
166
166
|
```typescript
|
|
167
|
-
//
|
|
168
|
-
import
|
|
167
|
+
// Web driver (application layer - HTTP/HTTPS)
|
|
168
|
+
import webDriver from "unping/drivers/web";
|
|
169
169
|
|
|
170
170
|
// TCP driver (port reachability)
|
|
171
171
|
import tcpDriver from "unping/drivers/tcp";
|
|
@@ -179,13 +179,13 @@ import hybridDriver from "unping/drivers/hybrid";
|
|
|
179
179
|
|
|
180
180
|
### Advanced Configuration
|
|
181
181
|
|
|
182
|
-
####
|
|
182
|
+
#### Web Driver Options
|
|
183
183
|
|
|
184
184
|
```typescript
|
|
185
|
-
import
|
|
185
|
+
import webDriver from "unping/drivers/web";
|
|
186
186
|
|
|
187
|
-
const
|
|
188
|
-
driver:
|
|
187
|
+
const web = createPingManager({
|
|
188
|
+
driver: webDriver({
|
|
189
189
|
method: "GET", // GET or HEAD (default: HEAD)
|
|
190
190
|
port: 8080, // Custom port
|
|
191
191
|
https: true, // Force HTTPS
|
|
@@ -229,13 +229,13 @@ const dns = createPingManager({
|
|
|
229
229
|
```typescript
|
|
230
230
|
import hybridDriver from "unping/drivers/hybrid";
|
|
231
231
|
import tcpDriver from "unping/drivers/tcp";
|
|
232
|
-
import
|
|
232
|
+
import webDriver from "unping/drivers/web";
|
|
233
233
|
|
|
234
234
|
const hybrid = createPingManager({
|
|
235
235
|
driver: hybridDriver({
|
|
236
236
|
drivers: [
|
|
237
237
|
tcpDriver({ port: 8080 }), // Custom TCP driver
|
|
238
|
-
|
|
238
|
+
webDriver({ method: "GET" }), // Custom Web driver
|
|
239
239
|
// Add more drivers as needed
|
|
240
240
|
],
|
|
241
241
|
}),
|
|
@@ -307,10 +307,10 @@ interface PingResult {
|
|
|
307
307
|
|
|
308
308
|
### Driver Options
|
|
309
309
|
|
|
310
|
-
####
|
|
310
|
+
#### WebDriverOptions
|
|
311
311
|
|
|
312
312
|
```typescript
|
|
313
|
-
interface
|
|
313
|
+
interface WebDriverOptions {
|
|
314
314
|
method?: "HEAD" | "GET"; // Request method (default: "HEAD")
|
|
315
315
|
port?: number; // Custom port (default: 80/443)
|
|
316
316
|
https?: boolean; // Force HTTPS (default: auto-detect)
|
|
@@ -350,27 +350,27 @@ interface HybridDriverOptions {
|
|
|
350
350
|
The Hybrid Driver provides intelligent network connectivity detection by trying multiple methods in order:
|
|
351
351
|
|
|
352
352
|
1. **TCP (First Priority)**: Fastest method, checks port reachability
|
|
353
|
-
2. **
|
|
353
|
+
2. **Web (Second Priority)**: Confirms application layer availability (HTTP/HTTPS)
|
|
354
354
|
3. **DNS (Last Priority)**: Basic DNS resolution capability as fallback
|
|
355
355
|
|
|
356
356
|
**Why this order?**
|
|
357
357
|
|
|
358
358
|
- **TCP First**: Closest to traditional ICMP ping, detects IP layer connectivity quickly (~1-5ms)
|
|
359
|
-
- **
|
|
359
|
+
- **Web Second**: Validates that the service is actually responding at application level (~100-300ms)
|
|
360
360
|
- **DNS Last**: Only checks if domain can be resolved, doesn't guarantee host reachability (~10-20ms)
|
|
361
361
|
|
|
362
362
|
**Custom Driver Configuration Example:**
|
|
363
363
|
|
|
364
364
|
```typescript
|
|
365
365
|
// For web service monitoring - prioritize HTTP
|
|
366
|
-
import
|
|
366
|
+
import webDriver from "unping/drivers/web";
|
|
367
367
|
import tcpDriver from "unping/drivers/tcp";
|
|
368
368
|
import dnsDriver from "unping/drivers/dns";
|
|
369
369
|
|
|
370
370
|
const webMonitor = createPingManager({
|
|
371
371
|
driver: hybridDriver({
|
|
372
372
|
drivers: [
|
|
373
|
-
|
|
373
|
+
webDriver({ method: "HEAD", path: "/health" }),
|
|
374
374
|
tcpDriver({ port: 80 }),
|
|
375
375
|
dnsDriver(),
|
|
376
376
|
],
|
|
@@ -383,7 +383,7 @@ const quickCheck = createPingManager({
|
|
|
383
383
|
drivers: [
|
|
384
384
|
tcpDriver({ port: 443 }),
|
|
385
385
|
dnsDriver(),
|
|
386
|
-
|
|
386
|
+
webDriver({ method: "GET" }),
|
|
387
387
|
],
|
|
388
388
|
}),
|
|
389
389
|
});
|
|
@@ -395,7 +395,7 @@ const quickCheck = createPingManager({
|
|
|
395
395
|
|
|
396
396
|
```typescript
|
|
397
397
|
const monitor = createPingManager({
|
|
398
|
-
driver:
|
|
398
|
+
driver: webDriver({ method: "HEAD", path: "/health" }),
|
|
399
399
|
});
|
|
400
400
|
|
|
401
401
|
setInterval(async () => {
|
|
@@ -427,14 +427,14 @@ for (const port of ports) {
|
|
|
427
427
|
```typescript
|
|
428
428
|
import hybridDriver from "unping/drivers/hybrid";
|
|
429
429
|
import tcpDriver from "unping/drivers/tcp";
|
|
430
|
-
import
|
|
430
|
+
import webDriver from "unping/drivers/web";
|
|
431
431
|
import dnsDriver from "unping/drivers/dns";
|
|
432
432
|
|
|
433
433
|
const diagnostic = createPingManager({
|
|
434
434
|
driver: hybridDriver({
|
|
435
435
|
drivers: [
|
|
436
436
|
tcpDriver({ port: 80 }),
|
|
437
|
-
|
|
437
|
+
webDriver({ method: "HEAD" }),
|
|
438
438
|
dnsDriver(),
|
|
439
439
|
],
|
|
440
440
|
}),
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
module.exports =
|
|
7
|
-
exports.
|
|
6
|
+
module.exports = webDriver;
|
|
7
|
+
exports.pingOnceWeb = pingOnceWeb;
|
|
8
8
|
var _ofetch = require("ofetch");
|
|
9
|
-
async function
|
|
9
|
+
async function pingOnceWeb(host, protocol, port, path, method, timeout, headers, sequence) {
|
|
10
10
|
const startTime = Date.now();
|
|
11
11
|
try {
|
|
12
12
|
const url = `${protocol}://${host}:${port}${path}`;
|
|
@@ -30,7 +30,7 @@ async function pingOnceHTTP(host, protocol, port, path, method, timeout, headers
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function webDriver(options = {}) {
|
|
34
34
|
const {
|
|
35
35
|
method = "HEAD",
|
|
36
36
|
path = "/",
|
|
@@ -43,7 +43,7 @@ function httpDriver(options = {}) {
|
|
|
43
43
|
const protocol = options.https ?? options.port === 443 ? "https" : "http";
|
|
44
44
|
const port = options.port || (protocol === "https" ? 443 : 80);
|
|
45
45
|
for (let i = 0; i < count; i++) {
|
|
46
|
-
const result = await
|
|
46
|
+
const result = await pingOnceWeb(host, protocol, port, path, method, timeout, headers, i + 1);
|
|
47
47
|
results.push(result);
|
|
48
48
|
if (i < count - 1 && opts?.interval) {
|
|
49
49
|
await new Promise(resolve => setTimeout(resolve, opts.interval));
|
|
@@ -52,7 +52,7 @@ function httpDriver(options = {}) {
|
|
|
52
52
|
return results;
|
|
53
53
|
};
|
|
54
54
|
return {
|
|
55
|
-
name: "
|
|
55
|
+
name: "web",
|
|
56
56
|
options,
|
|
57
57
|
ping
|
|
58
58
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Driver, DriverOptions, PingResult } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Web Driver Options
|
|
4
|
+
* Supports both HTTP and HTTPS protocols for host reachability detection
|
|
5
|
+
*/
|
|
6
|
+
export interface WebDriverOptions extends DriverOptions {
|
|
7
|
+
/** Request method (default: HEAD) */
|
|
8
|
+
method?: "HEAD" | "GET";
|
|
9
|
+
/** Custom port (default: 80/443) */
|
|
10
|
+
port?: number;
|
|
11
|
+
/** Force use HTTPS (default: auto-detect based on port, 443→true, 80→false) */
|
|
12
|
+
https?: boolean;
|
|
13
|
+
/** Request path (default: "/") */
|
|
14
|
+
path?: string;
|
|
15
|
+
/** Custom headers */
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
export declare function pingOnceWeb(host: string, protocol: string, port: number, path: string, method: string, timeout: number, headers: Record<string, string>, sequence: number): Promise<PingResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a Web Driver that supports both HTTP and HTTPS protocols
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Auto-detect protocol based on port
|
|
24
|
+
* webDriver() // HTTP:80
|
|
25
|
+
* webDriver({ port: 443 }) // HTTPS:443
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Explicit protocol control
|
|
29
|
+
* webDriver({ https: true }) // HTTPS:443
|
|
30
|
+
* webDriver({ https: true, port: 8443 }) // HTTPS:8443
|
|
31
|
+
* webDriver({ https: false }) // HTTP:80
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Custom request options
|
|
35
|
+
* webDriver({
|
|
36
|
+
* method: "GET",
|
|
37
|
+
* path: "/health",
|
|
38
|
+
* headers: { "User-Agent": "Custom-Pinger" }
|
|
39
|
+
* })
|
|
40
|
+
*/
|
|
41
|
+
export default function webDriver(options?: WebDriverOptions): Driver;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ofetch } from "ofetch";
|
|
2
|
-
export async function
|
|
2
|
+
export async function pingOnceWeb(host, protocol, port, path, method, timeout, headers, sequence) {
|
|
3
3
|
const startTime = Date.now();
|
|
4
4
|
try {
|
|
5
5
|
const url = `${protocol}://${host}:${port}${path}`;
|
|
@@ -23,7 +23,7 @@ export async function pingOnceHTTP(host, protocol, port, path, method, timeout,
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export default function
|
|
26
|
+
export default function webDriver(options = {}) {
|
|
27
27
|
const { method = "HEAD", path = "/", headers = {} } = options;
|
|
28
28
|
const ping = async (host, opts) => {
|
|
29
29
|
const count = opts?.count || 1;
|
|
@@ -32,7 +32,7 @@ export default function httpDriver(options = {}) {
|
|
|
32
32
|
const protocol = options.https ?? options.port === 443 ? "https" : "http";
|
|
33
33
|
const port = options.port || (protocol === "https" ? 443 : 80);
|
|
34
34
|
for (let i = 0; i < count; i++) {
|
|
35
|
-
const result = await
|
|
35
|
+
const result = await pingOnceWeb(
|
|
36
36
|
host,
|
|
37
37
|
protocol,
|
|
38
38
|
port,
|
|
@@ -50,7 +50,7 @@ export default function httpDriver(options = {}) {
|
|
|
50
50
|
return results;
|
|
51
51
|
};
|
|
52
52
|
return {
|
|
53
|
-
name: "
|
|
53
|
+
name: "web",
|
|
54
54
|
options,
|
|
55
55
|
ping
|
|
56
56
|
};
|
package/package.json
CHANGED
package/dist/drivers/http.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Driver, DriverOptions, PingResult } from "../types";
|
|
2
|
-
export interface HTTPDriverOptions extends DriverOptions {
|
|
3
|
-
/** Request method (default: HEAD) */
|
|
4
|
-
method?: "HEAD" | "GET";
|
|
5
|
-
/** Custom port (default: 80/443) */
|
|
6
|
-
port?: number;
|
|
7
|
-
/** Use HTTPS (default: auto detect) */
|
|
8
|
-
https?: boolean;
|
|
9
|
-
/** Request path (default: "/") */
|
|
10
|
-
path?: string;
|
|
11
|
-
/** Custom headers */
|
|
12
|
-
headers?: Record<string, string>;
|
|
13
|
-
}
|
|
14
|
-
export declare function pingOnceHTTP(host: string, protocol: string, port: number, path: string, method: string, timeout: number, headers: Record<string, string>, sequence: number): Promise<PingResult>;
|
|
15
|
-
export default function httpDriver(options?: HTTPDriverOptions): Driver;
|