@webdecoy/node 0.21.3 → 0.22.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
@@ -58,7 +58,7 @@ Behind a proxy, `req.socket.remoteAddress` is the proxy. Use `resolveClientIp()`
58
58
 
59
59
  `apiKey` is optional. Without it the SDK runs **local rules only** (tripwires by default, plus any rules you add), makes no network calls, and reports nothing to the dashboard. With it, the SDK also sends suspicious requests for server-side detection and reports rule hits to your dashboard.
60
60
 
61
- The SDK does **not** read `WEBDECOY_API_KEY` from the environment by itself. Pass it as `apiKey`, as above.
61
+ `new WebDecoy()` does **not** read `WEBDECOY_API_KEY` from the environment by itself (only the Vercel middleware does). Pass it as `apiKey`, as above.
62
62
 
63
63
  To get a key: sign up at [app.webdecoy.com](https://app.webdecoy.com), add your site, then create a key on the **API Keys** page. Keys start with `sk_live_` (production) or `sk_test_` (testing); any other prefix throws when the SDK is constructed. Keep the key on the server and out of committed files.
64
64
 
@@ -146,16 +146,35 @@ export default {
146
146
 
147
147
  Options: everything in [Configuration](#configuration), plus `mode` (default `'monitor'`), `skipPaths`, `trustProxy` (default `1`), `getIP`, `honeytoken` (default on when an `apiKey` is set; injects a hidden trap link into HTML through `decorate()`) and `onBlocked`.
148
148
 
149
- ## Clearance enforcement on Vercel
149
+ ## Vercel middleware: detection and clearance
150
150
 
151
- With a WebDecoy account, the paths you protect can require a clearance token, checked in Vercel Routing Middleware before the page renders. It follows the site's mode in WebDecoy (monitor until you switch it) and fails open.
151
+ One Routing Middleware file for Astro, SvelteKit, Nuxt, Remix or a static site on Vercel. It reports bots to WebDecoy and runs the clearance gate on the paths you protect, both configured from the project's environment.
152
152
 
153
153
  ```ts
154
- // middleware.ts (Astro, SvelteKit, Nuxt, Remix or a static site)
154
+ // middleware.ts (project root)
155
155
  export { default } from '@webdecoy/node/vercel';
156
+
157
+ export const config = {
158
+ // Everything but static assets. Keep /.well-known: the challenge uses it.
159
+ matcher: ['/((?!_astro/|_next/static/|favicon.ico|.*\\.(?:css|js|png|jpg|svg|webp|woff2?)$).*)'],
160
+ };
156
161
  ```
157
162
 
158
- Next.js sites use `withClearance()` from `@webdecoy/nextjs` instead. Set `WEBDECOY_SITE_KEY`, `WEBDECOY_SCANNER_ID` and `WEBDECOY_SENSOR_KEY` (a secret) from **Enforcement, Setup** in the dashboard. Guide: [Vercel middleware](https://docs.webdecoy.com/installation/vercel-middleware/).
163
+ | Variable | Turns on | Secret? |
164
+ |---|---|---|
165
+ | `WEBDECOY_API_KEY` | Detection: bots, tripwire hits and agents the bot registry names are reported to your dashboard. From the **API Keys** page. | Yes |
166
+ | `WEBDECOY_SITE_KEY`, `WEBDECOY_SCANNER_ID` | The clearance gate, with the sensor key. From **Enforcement, Setup**. | No |
167
+ | `WEBDECOY_SENSOR_KEY` | The clearance gate. From **Enforcement, Setup**. | Yes |
168
+
169
+ Either half works without the other; with neither, every request passes. Detection starts in monitor mode (the request is served and the verdict rides on the request as `x-webdecoy-decision`, `x-webdecoy-detection-id` and `x-webdecoy-would-block`), and the gate follows the site's mode in WebDecoy, monitor until you switch it. Every failure, WebDecoy unreachable included, lets the request through. Without `WEBDECOY_API_KEY` the middleware is the clearance gate alone, exactly as before.
170
+
171
+ To customize it, use `createVercelMiddleware(options)` from `@webdecoy/node/vercel`: it takes the core [Configuration](#configuration) options (`rules`, `threatScoreThreshold`, ...), `mode`, `skipPaths`, `trustProxy` and the gate's `siteKey`, `scannerId`, `sensorKey` and `ingest`, each defaulting to the environment. `clearanceMiddleware()` is the gate alone. Next.js sites use `@webdecoy/nextjs/vercel`, the same middleware in Next's types. Guide: [Vercel middleware](https://docs.webdecoy.com/installation/vercel-middleware/).
172
+
173
+ Verify it with the reserved test User-Agent; a detection labeled **Test** appears within a few seconds:
174
+
175
+ ```bash
176
+ curl -A "WebDecoy-Test/1.0" https://your-site.vercel.app/
177
+ ```
159
178
 
160
179
  ## Environment variables
161
180
 
@@ -163,11 +182,12 @@ The SDK reads only these, and only in the features named:
163
182
 
164
183
  | Variable | Read by |
165
184
  |---|---|
185
+ | `WEBDECOY_API_KEY` | The Vercel middleware (`@webdecoy/node/vercel`, `createDetectAndGate()`), when `apiKey` is not passed. |
166
186
  | `WEBDECOY_SITE_KEY`, `WEBDECOY_SCANNER_ID`, `WEBDECOY_SENSOR_KEY` | The clearance gate (`@webdecoy/node/vercel`, `createClearanceGate()`), when the matching option is not passed. |
167
187
  | `WEBDECOY_INGEST` | The clearance gate, to override its ingest endpoint. Optional. |
168
188
  | `NODE_ENV` | The self-hosted captcha: with `production`, a missing or default `secret` throws. |
169
189
 
170
- `WEBDECOY_API_KEY` is a naming convention used in these docs, not something the SDK reads.
190
+ Everywhere else `WEBDECOY_API_KEY` is a naming convention used in these docs: pass its value as `apiKey`.
171
191
 
172
192
  ## Configuration
173
193