@webdecoy/nextjs 0.25.2 → 0.27.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
@@ -77,6 +77,8 @@ To get a key: sign up at [app.webdecoy.com](https://app.webdecoy.com), add your
77
77
 
78
78
  ### Monitor mode
79
79
 
80
+ When Next.js supplies a middleware event, `withWebDecoy` uses its `waitUntil` hook to send rule violations after the request decision. Pass that event through if you wrap the middleware with your own function.
81
+
80
82
  `withWebDecoy` starts in **monitor mode**: it serves every request and passes the verdict to your app as request headers, which route handlers and server components can read:
81
83
 
82
84
  | Request header | Value |
package/dist/index.d.mts CHANGED
@@ -93,11 +93,11 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
93
93
  * };
94
94
  * ```
95
95
  */
96
- declare function withWebDecoy(config: WebDecoyConfig & WebDecoyMiddlewareOptions): (req: NextRequest) => Promise<NextResponse>;
96
+ declare function withWebDecoy(config: WebDecoyConfig & WebDecoyMiddlewareOptions): (req: NextRequest, event?: Pick<NextFetchEvent, 'waitUntil'>) => Promise<NextResponse>;
97
97
  interface WithBotProtectionOptions extends WebDecoyMiddlewareOptions {
98
98
  /**
99
- * Block threshold (0-100). Requests with scores above this are blocked.
100
- * Default: 80
99
+ * Minimum confidence (0–100) required to act on a cloud verdict.
100
+ * Defaults to 80 in legacy mode. Unified mode uses ingest's confidence gates.
101
101
  */
102
102
  blockThreshold?: number;
103
103
  }
package/dist/index.d.ts CHANGED
@@ -93,11 +93,11 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
93
93
  * };
94
94
  * ```
95
95
  */
96
- declare function withWebDecoy(config: WebDecoyConfig & WebDecoyMiddlewareOptions): (req: NextRequest) => Promise<NextResponse>;
96
+ declare function withWebDecoy(config: WebDecoyConfig & WebDecoyMiddlewareOptions): (req: NextRequest, event?: Pick<NextFetchEvent, 'waitUntil'>) => Promise<NextResponse>;
97
97
  interface WithBotProtectionOptions extends WebDecoyMiddlewareOptions {
98
98
  /**
99
- * Block threshold (0-100). Requests with scores above this are blocked.
100
- * Default: 80
99
+ * Minimum confidence (0–100) required to act on a cloud verdict.
100
+ * Defaults to 80 in legacy mode. Unified mode uses ingest's confidence gates.
101
101
  */
102
102
  blockThreshold?: number;
103
103
  }
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ function withWebDecoy(config) {
56
56
  const mode = config.mode ?? "monitor";
57
57
  const onError = config.onError || defaultOnError;
58
58
  const skipPaths = config.skipPaths;
59
- return async (req) => {
59
+ return async (req, event) => {
60
60
  try {
61
61
  const pathname = req.nextUrl.pathname;
62
62
  if ((0, import_node.shouldSkipPath)(pathname, skipPaths)) {
@@ -80,7 +80,8 @@ function withWebDecoy(config) {
80
80
  const result = await sdk.protect(metadata, {
81
81
  threshold: config.threshold,
82
82
  skipLocalAnalysis: config.skipLocalAnalysis,
83
- metadata: config.metadata
83
+ metadata: config.metadata,
84
+ violationReporting: { mode, waitUntil: event?.waitUntil?.bind(event) }
84
85
  });
85
86
  if (mode === "monitor") {
86
87
  const monitorHeaders = new Headers(req.headers);
@@ -124,7 +125,7 @@ function withWebDecoy(config) {
124
125
  }
125
126
  function withBotProtection(handler, config) {
126
127
  const sdk = new import_node.WebDecoy(config);
127
- const threshold = config.blockThreshold ?? 80;
128
+ const threshold = config.blockThreshold ?? (config.decisionMode === "unified_v1" ? void 0 : 80);
128
129
  const mode = config.mode ?? "monitor";
129
130
  return (async (...args) => {
130
131
  const [req, res] = args;
@@ -145,7 +146,8 @@ function withBotProtection(handler, config) {
145
146
  const result = await sdk.protect(metadata, {
146
147
  threshold,
147
148
  skipLocalAnalysis: config.skipLocalAnalysis,
148
- metadata: config.metadata
149
+ metadata: config.metadata,
150
+ violationReporting: { mode }
149
151
  });
150
152
  if (!result.allowed && mode === "enforce") {
151
153
  const block = (0, import_node.ruleBlockResponse)(result);
package/dist/index.mjs CHANGED
@@ -31,7 +31,7 @@ function withWebDecoy(config) {
31
31
  const mode = config.mode ?? "monitor";
32
32
  const onError = config.onError || defaultOnError;
33
33
  const skipPaths = config.skipPaths;
34
- return async (req) => {
34
+ return async (req, event) => {
35
35
  try {
36
36
  const pathname = req.nextUrl.pathname;
37
37
  if (shouldSkipPath(pathname, skipPaths)) {
@@ -55,7 +55,8 @@ function withWebDecoy(config) {
55
55
  const result = await sdk.protect(metadata, {
56
56
  threshold: config.threshold,
57
57
  skipLocalAnalysis: config.skipLocalAnalysis,
58
- metadata: config.metadata
58
+ metadata: config.metadata,
59
+ violationReporting: { mode, waitUntil: event?.waitUntil?.bind(event) }
59
60
  });
60
61
  if (mode === "monitor") {
61
62
  const monitorHeaders = new Headers(req.headers);
@@ -99,7 +100,7 @@ function withWebDecoy(config) {
99
100
  }
100
101
  function withBotProtection(handler, config) {
101
102
  const sdk = new WebDecoy(config);
102
- const threshold = config.blockThreshold ?? 80;
103
+ const threshold = config.blockThreshold ?? (config.decisionMode === "unified_v1" ? void 0 : 80);
103
104
  const mode = config.mode ?? "monitor";
104
105
  return (async (...args) => {
105
106
  const [req, res] = args;
@@ -120,7 +121,8 @@ function withBotProtection(handler, config) {
120
121
  const result = await sdk.protect(metadata, {
121
122
  threshold,
122
123
  skipLocalAnalysis: config.skipLocalAnalysis,
123
- metadata: config.metadata
124
+ metadata: config.metadata,
125
+ violationReporting: { mode }
124
126
  });
125
127
  if (!result.allowed && mode === "enforce") {
126
128
  const block = ruleBlockResponse(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/nextjs",
3
- "version": "0.25.2",
3
+ "version": "0.27.0",
4
4
  "description": "Web Decoy middleware for Next.js",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  "url": "https://github.com/WebDecoy/node/issues"
55
55
  },
56
56
  "dependencies": {
57
- "@webdecoy/node": "^0.25.2"
57
+ "@webdecoy/node": "^0.27.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "next": ">=13.0.0"