@webdecoy/node 0.1.0 → 0.1.1
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 +119 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
# @webdecoy/node
|
|
2
2
|
|
|
3
|
-
Core Web Decoy SDK for Node.js applications.
|
|
3
|
+
Core Web Decoy SDK for Node.js applications - Advanced bot detection with TLS fingerprinting.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@webdecoy/node)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
11
|
npm install @webdecoy/node
|
|
12
|
+
# or
|
|
13
|
+
yarn add @webdecoy/node
|
|
9
14
|
```
|
|
10
15
|
|
|
11
|
-
##
|
|
16
|
+
## Quick Start
|
|
12
17
|
|
|
13
18
|
```typescript
|
|
14
19
|
import { WebDecoy } from '@webdecoy/node';
|
|
@@ -21,20 +26,128 @@ const result = await webdecoy.protect({
|
|
|
21
26
|
method: 'GET',
|
|
22
27
|
path: '/api/data',
|
|
23
28
|
ip: '203.0.113.42',
|
|
24
|
-
user_agent:
|
|
25
|
-
headers:
|
|
29
|
+
user_agent: req.headers['user-agent'],
|
|
30
|
+
headers: req.headers,
|
|
26
31
|
timestamp: Date.now(),
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
if (!result.allowed) {
|
|
30
35
|
// Block the request
|
|
31
|
-
|
|
36
|
+
return res.status(403).json({ error: 'Access denied' });
|
|
32
37
|
}
|
|
33
38
|
```
|
|
34
39
|
|
|
40
|
+
## Configuration Options
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const webdecoy = new WebDecoy({
|
|
44
|
+
// Required: Your API key from the dashboard
|
|
45
|
+
apiKey: 'sk_live_xxxxx',
|
|
46
|
+
|
|
47
|
+
// Optional: API endpoint (defaults to production)
|
|
48
|
+
apiUrl: 'https://api.webdecoy.com',
|
|
49
|
+
|
|
50
|
+
// Optional: Enable TLS fingerprinting (default: true)
|
|
51
|
+
enableTLSFingerprinting: true,
|
|
52
|
+
|
|
53
|
+
// Optional: Threat score threshold for blocking (default: 80)
|
|
54
|
+
threatScoreThreshold: 70,
|
|
55
|
+
|
|
56
|
+
// Optional: Request timeout in milliseconds (default: 5000)
|
|
57
|
+
timeout: 5000,
|
|
58
|
+
|
|
59
|
+
// Optional: Enable debug logging (default: false)
|
|
60
|
+
debug: false,
|
|
61
|
+
|
|
62
|
+
// Optional: Reject unauthorized TLS certificates (default: true)
|
|
63
|
+
tlsRejectUnauthorized: true,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API Reference
|
|
68
|
+
|
|
69
|
+
### `WebDecoy`
|
|
70
|
+
|
|
71
|
+
Main SDK class for bot detection.
|
|
72
|
+
|
|
73
|
+
#### `protect(metadata: RequestMetadata, options?: ProtectOptions): Promise<ProtectResult>`
|
|
74
|
+
|
|
75
|
+
Analyze and protect a request.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const result = await webdecoy.protect({
|
|
79
|
+
method: 'GET',
|
|
80
|
+
path: '/api/data',
|
|
81
|
+
ip: '203.0.113.42',
|
|
82
|
+
user_agent: 'Mozilla/5.0...',
|
|
83
|
+
headers: { /* request headers */ },
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Returns:**
|
|
89
|
+
```typescript
|
|
90
|
+
interface ProtectResult {
|
|
91
|
+
allowed: boolean;
|
|
92
|
+
detection: {
|
|
93
|
+
decision: 'allow' | 'block' | 'challenge';
|
|
94
|
+
confidence: number; // 0-100 threat score
|
|
95
|
+
threat_level: 'MINIMAL' | 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
96
|
+
bot_detected: boolean;
|
|
97
|
+
bot_type?: string;
|
|
98
|
+
detection_id: string;
|
|
99
|
+
rule_enforced: boolean;
|
|
100
|
+
};
|
|
101
|
+
error?: string;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### `validateConfig(): Promise<{ valid: boolean; error?: string }>`
|
|
106
|
+
|
|
107
|
+
Validate your API key and configuration.
|
|
108
|
+
|
|
109
|
+
#### `getConfig(): Readonly<Required<WebDecoyConfig>>`
|
|
110
|
+
|
|
111
|
+
Get the current configuration.
|
|
112
|
+
|
|
113
|
+
## Types
|
|
114
|
+
|
|
115
|
+
All TypeScript types are exported:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import type {
|
|
119
|
+
WebDecoyConfig,
|
|
120
|
+
RequestMetadata,
|
|
121
|
+
SDKDetectionResponse,
|
|
122
|
+
ProtectResult,
|
|
123
|
+
ProtectOptions,
|
|
124
|
+
TLSInfo,
|
|
125
|
+
LocalAnalysis,
|
|
126
|
+
SDKDetectionRequest,
|
|
127
|
+
} from '@webdecoy/node';
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Framework Integrations
|
|
131
|
+
|
|
132
|
+
For Express.js, use the dedicated middleware package:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm install @webdecoy/express
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
See [@webdecoy/express](https://www.npmjs.com/package/@webdecoy/express) for details.
|
|
139
|
+
|
|
140
|
+
## Getting an API Key
|
|
141
|
+
|
|
142
|
+
1. Sign up at [app.webdecoy.com](https://app.webdecoy.com)
|
|
143
|
+
2. Create a new organization and property
|
|
144
|
+
3. Generate an API key in Settings
|
|
145
|
+
|
|
146
|
+
API keys start with `sk_live_` for production or `sk_test_` for testing.
|
|
147
|
+
|
|
35
148
|
## Documentation
|
|
36
149
|
|
|
37
|
-
|
|
150
|
+
For full documentation, visit the [GitHub repository](https://github.com/webdecoy/webdecoy-node).
|
|
38
151
|
|
|
39
152
|
## License
|
|
40
153
|
|