@webdecoy/node 0.31.0 → 0.32.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
@@ -200,6 +200,8 @@ Local rules decide the request before the SDK reports their events. With an API
200
200
 
201
201
  For a long-lived SDK instance, call `getViolationDeliveryStats()` for counts of events acknowledged by ingest, failed batches, discarded events, and events waiting for an attempt. Call `await sdk.destroy()` during graceful shutdown to finish an in-flight send and attempt the remaining queue. Reporting has a fixed in-memory buffer. When the client pauses after a failure, unattempted events stay buffered. An attempted batch with an uncertain acknowledgment is discarded to avoid replaying its server-side effects.
202
202
 
203
+ Each event carries a unique `eventId`. Ingest stores an event once per id, so a batch that reaches it twice, for example through a proxy retry, adds no second violation and no second detection, and the repeat is still acknowledged. If the process exits without `destroy()`, the reporter keeps it open for at most one flush interval plus the request timeout to attempt the events it holds. It never keeps the process open while the client is paused after a failure. The Fastify plugin sends its remaining events when `fastify.close()` runs, and the Hono middleware hands each send to `executionCtx.waitUntil` on runtimes that provide one, such as Cloudflare Workers.
204
+
203
205
  ## Fetch runtimes (Bun, Deno, Workers, Astro, SvelteKit, Remix)
204
206
 
205
207
  `createFetchGuard()` wraps the SDK for any runtime that hands you a WHATWG `Request`. It is the same implementation `@webdecoy/hono` uses.
@@ -3224,6 +3224,7 @@ var ViolationReporter = class {
3224
3224
  this.maxBufferSize = config.maxBufferSize ?? 50;
3225
3225
  this.debug = config.debug ?? false;
3226
3226
  const flushInterval = config.flushInterval ?? 5e3;
3227
+ this.flushInterval = flushInterval;
3227
3228
  this.flushTimer = setInterval(() => void this.flush(), flushInterval);
3228
3229
  if (this.flushTimer.unref) {
3229
3230
  this.flushTimer.unref();
@@ -3233,7 +3234,9 @@ var ViolationReporter = class {
3233
3234
  * Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
3234
3235
  */
3235
3236
  report(violations) {
3236
- this.buffer.push(...violations);
3237
+ for (const violation of violations) {
3238
+ this.buffer.push(violation.eventId ? violation : { ...violation, eventId: crypto.randomUUID() });
3239
+ }
3237
3240
  if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
3238
3241
  const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
3239
3242
  this.buffer.splice(0, overflow);
@@ -3242,8 +3245,32 @@ var ViolationReporter = class {
3242
3245
  if (this.buffer.length >= this.maxBufferSize) {
3243
3246
  this.flush().catch(() => {
3244
3247
  });
3248
+ } else {
3249
+ this.scheduleDelivery();
3245
3250
  }
3246
3251
  }
3252
+ /**
3253
+ * Give buffered events one delivery attempt before the process can exit.
3254
+ *
3255
+ * The interval above is unref'd so an idle reporter never holds a process
3256
+ * open. On its own that meant a server shut down gracefully (Express after
3257
+ * server.close(), Fastify after close(), Hono on Node) exited with its last
3258
+ * events unsent and uncounted. This one-shot timer is left ref'd, so a
3259
+ * natural exit waits at most one flush interval plus the request timeout.
3260
+ * It is not re-armed while the client is paused, so an outage cannot keep
3261
+ * the process alive.
3262
+ */
3263
+ cancelDelivery() {
3264
+ clearTimeout(this.deliveryTimer);
3265
+ this.deliveryTimer = void 0;
3266
+ }
3267
+ scheduleDelivery() {
3268
+ if (this.deliveryTimer) return;
3269
+ this.deliveryTimer = setTimeout(() => {
3270
+ this.deliveryTimer = void 0;
3271
+ void this.flush();
3272
+ }, this.flushInterval);
3273
+ }
3247
3274
  /** Flush the buffer, coalescing requests that arrive during an active send. */
3248
3275
  flush() {
3249
3276
  if (this.queuedFlush) return this.queuedFlush;
@@ -3259,6 +3286,7 @@ var ViolationReporter = class {
3259
3286
  const size = this.buffer.length;
3260
3287
  this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
3261
3288
  this.flushPromise = void 0;
3289
+ if (this.buffer.length === 0) this.cancelDelivery();
3262
3290
  });
3263
3291
  return this.flushPromise;
3264
3292
  }
@@ -3288,6 +3316,7 @@ var ViolationReporter = class {
3288
3316
  /** Stop the timer and give remaining events one final flush. */
3289
3317
  async destroy() {
3290
3318
  clearInterval(this.flushTimer);
3319
+ this.cancelDelivery();
3291
3320
  if (this.flushPromise) await this.flushPromise;
3292
3321
  await this.flush();
3293
3322
  this.droppedEvents += this.buffer.length;
@@ -4,7 +4,7 @@ import {
4
4
  isInjectableHtml,
5
5
  siteHoneytoken,
6
6
  tripwire
7
- } from "./chunk-IGSPJVI6.mjs";
7
+ } from "./chunk-CUAZKMMQ.mjs";
8
8
 
9
9
  // src/client-ip.ts
10
10
  var IPV4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
@@ -1468,7 +1468,7 @@ function createFetchGuard(options = {}) {
1468
1468
  skips(pathname) {
1469
1469
  return shouldSkipPath(pathname, options.skipPaths);
1470
1470
  },
1471
- async check(request, peer) {
1471
+ async check(request, peer, lifecycle) {
1472
1472
  const url = new URL(request.url);
1473
1473
  const headers = headerRecord(request.headers);
1474
1474
  if (!headers.host && !headers[":authority"]) headers.host = url.host;
@@ -1485,7 +1485,7 @@ function createFetchGuard(options = {}) {
1485
1485
  threshold: options.threshold,
1486
1486
  skipLocalAnalysis: options.skipLocalAnalysis,
1487
1487
  metadata: options.metadata,
1488
- violationReporting: { mode }
1488
+ violationReporting: { mode, waitUntil: lifecycle?.waitUntil }
1489
1489
  });
1490
1490
  if (decision.allowed || mode !== "enforce") return { decision };
1491
1491
  return { decision, response: await onBlocked(request, decision) };
@@ -1,4 +1,4 @@
1
- import { j as WebDecoyConfig, k as ProtectOptions, D as Decision, W as WebDecoy } from './sdk-DveMEqxl.mjs';
1
+ import { j as WebDecoyConfig, k as ProtectOptions, D as Decision, W as WebDecoy } from './sdk-Gay_Ddzy.mjs';
2
2
 
3
3
  /**
4
4
  * Resolving the client IP address behind a proxy.
@@ -223,9 +223,18 @@ interface GuardOutcome {
223
223
  */
224
224
  response?: Response;
225
225
  }
226
+ /** The host runtime's request lifecycle, where it has one. */
227
+ interface GuardLifecycle {
228
+ /**
229
+ * Keeps violation delivery alive after the response, as Workers'
230
+ * `ctx.waitUntil`. Without it a runtime that freezes after responding can
231
+ * drop the report.
232
+ */
233
+ waitUntil?: (delivery: Promise<void>) => void;
234
+ }
226
235
  interface FetchGuard {
227
236
  /** Evaluate one request. */
228
- check(request: Request, peer?: string): Promise<GuardOutcome>;
237
+ check(request: Request, peer?: string, lifecycle?: GuardLifecycle): Promise<GuardOutcome>;
229
238
  /**
230
239
  * Rewrite an HTML response to carry the honeytoken link. Returns the response
231
240
  * unchanged when there is no token yet, or the body is not injectable HTML.
@@ -310,4 +319,4 @@ interface DetectAndGateOutcome {
310
319
  */
311
320
  declare function createDetectAndGate(options?: DetectAndGateOptions): (request: Request, context?: ClearanceContext) => Promise<DetectAndGateOutcome>;
312
321
 
313
- export { BUILD as B, type ClearanceContext as C, type DetectAndGateOptions as D, type FetchGuard as F, type GateEnv as G, type HeaderSource as H, type ResolveClientIpOptions as R, type TrustedProxies as T, type ClearanceGateOptions as a, type DetectAndGateOutcome as b, type FetchGuardOptions as c, type GateOutcome as d, type GuardOutcome as e, createClearanceGate as f, createDetectAndGate as g, createFetchGuard as h, ipInCidr as i, resolveGateEnv as j, normalizeIp as n, resolveClientIp as r };
322
+ export { BUILD as B, type ClearanceContext as C, type DetectAndGateOptions as D, type FetchGuard as F, type GateEnv as G, type HeaderSource as H, type ResolveClientIpOptions as R, type TrustedProxies as T, type ClearanceGateOptions as a, type DetectAndGateOutcome as b, type FetchGuardOptions as c, type GateOutcome as d, type GuardLifecycle as e, type GuardOutcome as f, createClearanceGate as g, createDetectAndGate as h, createFetchGuard as i, ipInCidr as j, resolveGateEnv as k, normalizeIp as n, resolveClientIp as r };
@@ -1,4 +1,4 @@
1
- import { j as WebDecoyConfig, k as ProtectOptions, D as Decision, W as WebDecoy } from './sdk-DveMEqxl.js';
1
+ import { j as WebDecoyConfig, k as ProtectOptions, D as Decision, W as WebDecoy } from './sdk-Gay_Ddzy.js';
2
2
 
3
3
  /**
4
4
  * Resolving the client IP address behind a proxy.
@@ -223,9 +223,18 @@ interface GuardOutcome {
223
223
  */
224
224
  response?: Response;
225
225
  }
226
+ /** The host runtime's request lifecycle, where it has one. */
227
+ interface GuardLifecycle {
228
+ /**
229
+ * Keeps violation delivery alive after the response, as Workers'
230
+ * `ctx.waitUntil`. Without it a runtime that freezes after responding can
231
+ * drop the report.
232
+ */
233
+ waitUntil?: (delivery: Promise<void>) => void;
234
+ }
226
235
  interface FetchGuard {
227
236
  /** Evaluate one request. */
228
- check(request: Request, peer?: string): Promise<GuardOutcome>;
237
+ check(request: Request, peer?: string, lifecycle?: GuardLifecycle): Promise<GuardOutcome>;
229
238
  /**
230
239
  * Rewrite an HTML response to carry the honeytoken link. Returns the response
231
240
  * unchanged when there is no token yet, or the body is not injectable HTML.
@@ -310,4 +319,4 @@ interface DetectAndGateOutcome {
310
319
  */
311
320
  declare function createDetectAndGate(options?: DetectAndGateOptions): (request: Request, context?: ClearanceContext) => Promise<DetectAndGateOutcome>;
312
321
 
313
- export { BUILD as B, type ClearanceContext as C, type DetectAndGateOptions as D, type FetchGuard as F, type GateEnv as G, type HeaderSource as H, type ResolveClientIpOptions as R, type TrustedProxies as T, type ClearanceGateOptions as a, type DetectAndGateOutcome as b, type FetchGuardOptions as c, type GateOutcome as d, type GuardOutcome as e, createClearanceGate as f, createDetectAndGate as g, createFetchGuard as h, ipInCidr as i, resolveGateEnv as j, normalizeIp as n, resolveClientIp as r };
322
+ export { BUILD as B, type ClearanceContext as C, type DetectAndGateOptions as D, type FetchGuard as F, type GateEnv as G, type HeaderSource as H, type ResolveClientIpOptions as R, type TrustedProxies as T, type ClearanceGateOptions as a, type DetectAndGateOutcome as b, type FetchGuardOptions as c, type GateOutcome as d, type GuardLifecycle as e, type GuardOutcome as f, createClearanceGate as g, createDetectAndGate as h, createFetchGuard as i, ipInCidr as j, resolveGateEnv as k, normalizeIp as n, resolveClientIp as r };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, D as Decision, j as WebDecoyConfig, k as ProtectOptions, l as AgentVerifierOptions, m as AgentRequestInput, n as AgentVerdict, S as SignedAgentDirectory } from './sdk-DveMEqxl.mjs';
2
- export { o as AgentStatus, p as BOT_CATEGORIES, q as BOT_REGISTRY, r as BotVerdict, C as Characteristic, s as Conclusion, t as CreatedHoneyCredential, u as DEFAULT_CHARACTERISTICS, v as DecisionCache, w as DecisionCacheOptions, x as DecisionInit, y as DecisionMode, E as EDGE_CLASS_HEADER, z as EDGE_CLEARANCE_HEADER, G as EdgeClass, H as EdgeVerdict, I as FrameworkEvidenceObservation, J as HoneyCredentialHandle, K as HoneyCredentialOptions, L as HoneyCredentialPresentationResult, M as HoneyCredentialReceipt, N as IPEnrichmentData, O as LocalAnalysis, Q as LogFields, U as Logger, V as MemoryRateLimitStore, X as OffensiveToolFamily, Y as OffensiveToolInvocation, Z as OffensiveToolchainEvidence, _ as OffensiveToolchainEvidenceInput, $ as OffensiveToolchainObservation, a0 as RequestMetadata, a1 as RuleOutcome, a2 as RuleState, a3 as SDKDetectionRequest, a4 as SDKDetectionResponse, a5 as SSRFCanary, a6 as SSRFCanaryOptions, a7 as SSRFInitiationReceipt, a8 as Span, a9 as SyncRateLimitStore, aa as TLSInfo, ab as Tracer, ac as ViolationDeliveryStats, ad as ViolationEvent, ae as classifyUserAgent, af as consoleLogger, ag as createOffensiveToolchainEvidence, ah as deriveKey, ai as fromPino, aj as matchUserAgent, ak as newDecisionId, al as readEdgeVerdict, am as silentLogger } from './sdk-DveMEqxl.mjs';
3
- import { T as TrustedProxies } from './detect-and-gate-DWOUDUSY.mjs';
4
- export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, f as createClearanceGate, g as createDetectAndGate, h as createFetchGuard, i as ipInCidr, n as normalizeIp, r as resolveClientIp, j as resolveGateEnv } from './detect-and-gate-DWOUDUSY.mjs';
1
+ import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, D as Decision, j as WebDecoyConfig, k as ProtectOptions, l as AgentVerifierOptions, m as AgentRequestInput, n as AgentVerdict, S as SignedAgentDirectory } from './sdk-Gay_Ddzy.mjs';
2
+ export { o as AgentStatus, p as BOT_CATEGORIES, q as BOT_REGISTRY, r as BotVerdict, C as Characteristic, s as Conclusion, t as CreatedHoneyCredential, u as DEFAULT_CHARACTERISTICS, v as DecisionCache, w as DecisionCacheOptions, x as DecisionInit, y as DecisionMode, E as EDGE_CLASS_HEADER, z as EDGE_CLEARANCE_HEADER, G as EdgeClass, H as EdgeVerdict, I as FrameworkEvidenceObservation, J as HoneyCredentialHandle, K as HoneyCredentialOptions, L as HoneyCredentialPresentationResult, M as HoneyCredentialReceipt, N as IPEnrichmentData, O as LocalAnalysis, Q as LogFields, U as Logger, V as MemoryRateLimitStore, X as OffensiveToolFamily, Y as OffensiveToolInvocation, Z as OffensiveToolchainEvidence, _ as OffensiveToolchainEvidenceInput, $ as OffensiveToolchainObservation, a0 as RequestMetadata, a1 as RuleOutcome, a2 as RuleState, a3 as SDKDetectionRequest, a4 as SDKDetectionResponse, a5 as SSRFCanary, a6 as SSRFCanaryOptions, a7 as SSRFInitiationReceipt, a8 as Span, a9 as SyncRateLimitStore, aa as TLSInfo, ab as Tracer, ac as ViolationDeliveryStats, ad as ViolationEvent, ae as classifyUserAgent, af as consoleLogger, ag as createOffensiveToolchainEvidence, ah as deriveKey, ai as fromPino, aj as matchUserAgent, ak as newDecisionId, al as readEdgeVerdict, am as silentLogger } from './sdk-Gay_Ddzy.mjs';
3
+ import { T as TrustedProxies } from './detect-and-gate-DtE2PPTM.mjs';
4
+ export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardLifecycle, f as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, g as createClearanceGate, h as createDetectAndGate, i as createFetchGuard, j as ipInCidr, n as normalizeIp, r as resolveClientIp, k as resolveGateEnv } from './detect-and-gate-DtE2PPTM.mjs';
5
5
 
6
6
  /**
7
7
  * The reserved test trigger.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, D as Decision, j as WebDecoyConfig, k as ProtectOptions, l as AgentVerifierOptions, m as AgentRequestInput, n as AgentVerdict, S as SignedAgentDirectory } from './sdk-DveMEqxl.js';
2
- export { o as AgentStatus, p as BOT_CATEGORIES, q as BOT_REGISTRY, r as BotVerdict, C as Characteristic, s as Conclusion, t as CreatedHoneyCredential, u as DEFAULT_CHARACTERISTICS, v as DecisionCache, w as DecisionCacheOptions, x as DecisionInit, y as DecisionMode, E as EDGE_CLASS_HEADER, z as EDGE_CLEARANCE_HEADER, G as EdgeClass, H as EdgeVerdict, I as FrameworkEvidenceObservation, J as HoneyCredentialHandle, K as HoneyCredentialOptions, L as HoneyCredentialPresentationResult, M as HoneyCredentialReceipt, N as IPEnrichmentData, O as LocalAnalysis, Q as LogFields, U as Logger, V as MemoryRateLimitStore, X as OffensiveToolFamily, Y as OffensiveToolInvocation, Z as OffensiveToolchainEvidence, _ as OffensiveToolchainEvidenceInput, $ as OffensiveToolchainObservation, a0 as RequestMetadata, a1 as RuleOutcome, a2 as RuleState, a3 as SDKDetectionRequest, a4 as SDKDetectionResponse, a5 as SSRFCanary, a6 as SSRFCanaryOptions, a7 as SSRFInitiationReceipt, a8 as Span, a9 as SyncRateLimitStore, aa as TLSInfo, ab as Tracer, ac as ViolationDeliveryStats, ad as ViolationEvent, ae as classifyUserAgent, af as consoleLogger, ag as createOffensiveToolchainEvidence, ah as deriveKey, ai as fromPino, aj as matchUserAgent, ak as newDecisionId, al as readEdgeVerdict, am as silentLogger } from './sdk-DveMEqxl.js';
3
- import { T as TrustedProxies } from './detect-and-gate-BfL39HDb.js';
4
- export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, f as createClearanceGate, g as createDetectAndGate, h as createFetchGuard, i as ipInCidr, n as normalizeIp, r as resolveClientIp, j as resolveGateEnv } from './detect-and-gate-BfL39HDb.js';
1
+ import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, D as Decision, j as WebDecoyConfig, k as ProtectOptions, l as AgentVerifierOptions, m as AgentRequestInput, n as AgentVerdict, S as SignedAgentDirectory } from './sdk-Gay_Ddzy.js';
2
+ export { o as AgentStatus, p as BOT_CATEGORIES, q as BOT_REGISTRY, r as BotVerdict, C as Characteristic, s as Conclusion, t as CreatedHoneyCredential, u as DEFAULT_CHARACTERISTICS, v as DecisionCache, w as DecisionCacheOptions, x as DecisionInit, y as DecisionMode, E as EDGE_CLASS_HEADER, z as EDGE_CLEARANCE_HEADER, G as EdgeClass, H as EdgeVerdict, I as FrameworkEvidenceObservation, J as HoneyCredentialHandle, K as HoneyCredentialOptions, L as HoneyCredentialPresentationResult, M as HoneyCredentialReceipt, N as IPEnrichmentData, O as LocalAnalysis, Q as LogFields, U as Logger, V as MemoryRateLimitStore, X as OffensiveToolFamily, Y as OffensiveToolInvocation, Z as OffensiveToolchainEvidence, _ as OffensiveToolchainEvidenceInput, $ as OffensiveToolchainObservation, a0 as RequestMetadata, a1 as RuleOutcome, a2 as RuleState, a3 as SDKDetectionRequest, a4 as SDKDetectionResponse, a5 as SSRFCanary, a6 as SSRFCanaryOptions, a7 as SSRFInitiationReceipt, a8 as Span, a9 as SyncRateLimitStore, aa as TLSInfo, ab as Tracer, ac as ViolationDeliveryStats, ad as ViolationEvent, ae as classifyUserAgent, af as consoleLogger, ag as createOffensiveToolchainEvidence, ah as deriveKey, ai as fromPino, aj as matchUserAgent, ak as newDecisionId, al as readEdgeVerdict, am as silentLogger } from './sdk-Gay_Ddzy.js';
3
+ import { T as TrustedProxies } from './detect-and-gate-neuBgxUB.js';
4
+ export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardLifecycle, f as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, g as createClearanceGate, h as createDetectAndGate, i as createFetchGuard, j as ipInCidr, n as normalizeIp, r as resolveClientIp, k as resolveGateEnv } from './detect-and-gate-neuBgxUB.js';
5
5
 
6
6
  /**
7
7
  * The reserved test trigger.
package/dist/index.js CHANGED
@@ -2345,6 +2345,7 @@ var ViolationReporter = class {
2345
2345
  this.maxBufferSize = config.maxBufferSize ?? 50;
2346
2346
  this.debug = config.debug ?? false;
2347
2347
  const flushInterval = config.flushInterval ?? 5e3;
2348
+ this.flushInterval = flushInterval;
2348
2349
  this.flushTimer = setInterval(() => void this.flush(), flushInterval);
2349
2350
  if (this.flushTimer.unref) {
2350
2351
  this.flushTimer.unref();
@@ -2354,7 +2355,9 @@ var ViolationReporter = class {
2354
2355
  * Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
2355
2356
  */
2356
2357
  report(violations) {
2357
- this.buffer.push(...violations);
2358
+ for (const violation of violations) {
2359
+ this.buffer.push(violation.eventId ? violation : { ...violation, eventId: crypto.randomUUID() });
2360
+ }
2358
2361
  if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
2359
2362
  const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
2360
2363
  this.buffer.splice(0, overflow);
@@ -2363,8 +2366,32 @@ var ViolationReporter = class {
2363
2366
  if (this.buffer.length >= this.maxBufferSize) {
2364
2367
  this.flush().catch(() => {
2365
2368
  });
2369
+ } else {
2370
+ this.scheduleDelivery();
2366
2371
  }
2367
2372
  }
2373
+ /**
2374
+ * Give buffered events one delivery attempt before the process can exit.
2375
+ *
2376
+ * The interval above is unref'd so an idle reporter never holds a process
2377
+ * open. On its own that meant a server shut down gracefully (Express after
2378
+ * server.close(), Fastify after close(), Hono on Node) exited with its last
2379
+ * events unsent and uncounted. This one-shot timer is left ref'd, so a
2380
+ * natural exit waits at most one flush interval plus the request timeout.
2381
+ * It is not re-armed while the client is paused, so an outage cannot keep
2382
+ * the process alive.
2383
+ */
2384
+ cancelDelivery() {
2385
+ clearTimeout(this.deliveryTimer);
2386
+ this.deliveryTimer = void 0;
2387
+ }
2388
+ scheduleDelivery() {
2389
+ if (this.deliveryTimer) return;
2390
+ this.deliveryTimer = setTimeout(() => {
2391
+ this.deliveryTimer = void 0;
2392
+ void this.flush();
2393
+ }, this.flushInterval);
2394
+ }
2368
2395
  /** Flush the buffer, coalescing requests that arrive during an active send. */
2369
2396
  flush() {
2370
2397
  if (this.queuedFlush) return this.queuedFlush;
@@ -2380,6 +2407,7 @@ var ViolationReporter = class {
2380
2407
  const size = this.buffer.length;
2381
2408
  this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
2382
2409
  this.flushPromise = void 0;
2410
+ if (this.buffer.length === 0) this.cancelDelivery();
2383
2411
  });
2384
2412
  return this.flushPromise;
2385
2413
  }
@@ -2409,6 +2437,7 @@ var ViolationReporter = class {
2409
2437
  /** Stop the timer and give remaining events one final flush. */
2410
2438
  async destroy() {
2411
2439
  clearInterval(this.flushTimer);
2440
+ this.cancelDelivery();
2412
2441
  if (this.flushPromise) await this.flushPromise;
2413
2442
  await this.flush();
2414
2443
  this.droppedEvents += this.buffer.length;
@@ -5733,7 +5762,7 @@ function createFetchGuard(options = {}) {
5733
5762
  skips(pathname) {
5734
5763
  return shouldSkipPath(pathname, options.skipPaths);
5735
5764
  },
5736
- async check(request, peer) {
5765
+ async check(request, peer, lifecycle) {
5737
5766
  const url = new URL(request.url);
5738
5767
  const headers = headerRecord(request.headers);
5739
5768
  if (!headers.host && !headers[":authority"]) headers.host = url.host;
@@ -5750,7 +5779,7 @@ function createFetchGuard(options = {}) {
5750
5779
  threshold: options.threshold,
5751
5780
  skipLocalAnalysis: options.skipLocalAnalysis,
5752
5781
  metadata: options.metadata,
5753
- violationReporting: { mode }
5782
+ violationReporting: { mode, waitUntil: lifecycle?.waitUntil }
5754
5783
  });
5755
5784
  if (decision.allowed || mode !== "enforce") return { decision };
5756
5785
  return { decision, response: await onBlocked(request, decision) };
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  resolveGateEnv,
12
12
  ruleBlockResponse,
13
13
  shouldSkipPath
14
- } from "./chunk-BBRVE4RC.mjs";
14
+ } from "./chunk-S7GDCKKB.mjs";
15
15
  import {
16
16
  ATTACK_SIGNATURE_IDS,
17
17
  AgentVerifier,
@@ -69,7 +69,7 @@ import {
69
69
  tripwire,
70
70
  upstashRateLimitStore,
71
71
  webBotAuth
72
- } from "./chunk-IGSPJVI6.mjs";
72
+ } from "./chunk-CUAZKMMQ.mjs";
73
73
 
74
74
  // src/client-signals.ts
75
75
  var MemoryClientSignalStore = class {
@@ -1287,6 +1287,12 @@ interface ViolationEvent {
1287
1287
  dryRun: boolean;
1288
1288
  /** When the violation occurred (ISO 8601) */
1289
1289
  timestamp: string;
1290
+ /**
1291
+ * Unique id for this event (a UUID), assigned by the reporter when absent.
1292
+ * Ingest stores an event once per id, so a batch that reaches it twice adds
1293
+ * no second violation and no second tripwire detection.
1294
+ */
1295
+ eventId?: string;
1290
1296
  }
1291
1297
  /**
1292
1298
  * IP enrichment data from the WebDecoy API
@@ -1464,6 +1470,8 @@ declare class ViolationReporter {
1464
1470
  private client;
1465
1471
  private buffer;
1466
1472
  private flushTimer;
1473
+ private deliveryTimer;
1474
+ private flushInterval;
1467
1475
  private maxBufferSize;
1468
1476
  private debug;
1469
1477
  private flushPromise;
@@ -1476,6 +1484,19 @@ declare class ViolationReporter {
1476
1484
  * Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
1477
1485
  */
1478
1486
  report(violations: ViolationEvent[]): void;
1487
+ /**
1488
+ * Give buffered events one delivery attempt before the process can exit.
1489
+ *
1490
+ * The interval above is unref'd so an idle reporter never holds a process
1491
+ * open. On its own that meant a server shut down gracefully (Express after
1492
+ * server.close(), Fastify after close(), Hono on Node) exited with its last
1493
+ * events unsent and uncounted. This one-shot timer is left ref'd, so a
1494
+ * natural exit waits at most one flush interval plus the request timeout.
1495
+ * It is not re-armed while the client is paused, so an outage cannot keep
1496
+ * the process alive.
1497
+ */
1498
+ private cancelDelivery;
1499
+ private scheduleDelivery;
1479
1500
  /** Flush the buffer, coalescing requests that arrive during an active send. */
1480
1501
  flush(): Promise<void>;
1481
1502
  private flushBatches;
@@ -1287,6 +1287,12 @@ interface ViolationEvent {
1287
1287
  dryRun: boolean;
1288
1288
  /** When the violation occurred (ISO 8601) */
1289
1289
  timestamp: string;
1290
+ /**
1291
+ * Unique id for this event (a UUID), assigned by the reporter when absent.
1292
+ * Ingest stores an event once per id, so a batch that reaches it twice adds
1293
+ * no second violation and no second tripwire detection.
1294
+ */
1295
+ eventId?: string;
1290
1296
  }
1291
1297
  /**
1292
1298
  * IP enrichment data from the WebDecoy API
@@ -1464,6 +1470,8 @@ declare class ViolationReporter {
1464
1470
  private client;
1465
1471
  private buffer;
1466
1472
  private flushTimer;
1473
+ private deliveryTimer;
1474
+ private flushInterval;
1467
1475
  private maxBufferSize;
1468
1476
  private debug;
1469
1477
  private flushPromise;
@@ -1476,6 +1484,19 @@ declare class ViolationReporter {
1476
1484
  * Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
1477
1485
  */
1478
1486
  report(violations: ViolationEvent[]): void;
1487
+ /**
1488
+ * Give buffered events one delivery attempt before the process can exit.
1489
+ *
1490
+ * The interval above is unref'd so an idle reporter never holds a process
1491
+ * open. On its own that meant a server shut down gracefully (Express after
1492
+ * server.close(), Fastify after close(), Hono on Node) exited with its last
1493
+ * events unsent and uncounted. This one-shot timer is left ref'd, so a
1494
+ * natural exit waits at most one flush interval plus the request timeout.
1495
+ * It is not re-armed while the client is paused, so an outage cannot keep
1496
+ * the process alive.
1497
+ */
1498
+ private cancelDelivery;
1499
+ private scheduleDelivery;
1479
1500
  /** Flush the buffer, coalescing requests that arrive during an active send. */
1480
1501
  flush(): Promise<void>;
1481
1502
  private flushBatches;
@@ -1,4 +1,4 @@
1
- import { j as WebDecoyConfig, a0 as RequestMetadata, W as WebDecoy, P as ProtectResult, a2 as RuleState } from './sdk-DveMEqxl.mjs';
1
+ import { j as WebDecoyConfig, a0 as RequestMetadata, W as WebDecoy, P as ProtectResult, a2 as RuleState } from './sdk-Gay_Ddzy.mjs';
2
2
 
3
3
  /**
4
4
  * Testing utilities, for the application's test suite rather than ours.
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { j as WebDecoyConfig, a0 as RequestMetadata, W as WebDecoy, P as ProtectResult, a2 as RuleState } from './sdk-DveMEqxl.js';
1
+ import { j as WebDecoyConfig, a0 as RequestMetadata, W as WebDecoy, P as ProtectResult, a2 as RuleState } from './sdk-Gay_Ddzy.js';
2
2
 
3
3
  /**
4
4
  * Testing utilities, for the application's test suite rather than ours.
package/dist/testing.js CHANGED
@@ -1115,6 +1115,7 @@ var ViolationReporter = class {
1115
1115
  this.maxBufferSize = config.maxBufferSize ?? 50;
1116
1116
  this.debug = config.debug ?? false;
1117
1117
  const flushInterval = config.flushInterval ?? 5e3;
1118
+ this.flushInterval = flushInterval;
1118
1119
  this.flushTimer = setInterval(() => void this.flush(), flushInterval);
1119
1120
  if (this.flushTimer.unref) {
1120
1121
  this.flushTimer.unref();
@@ -1124,7 +1125,9 @@ var ViolationReporter = class {
1124
1125
  * Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
1125
1126
  */
1126
1127
  report(violations) {
1127
- this.buffer.push(...violations);
1128
+ for (const violation of violations) {
1129
+ this.buffer.push(violation.eventId ? violation : { ...violation, eventId: crypto.randomUUID() });
1130
+ }
1128
1131
  if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
1129
1132
  const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
1130
1133
  this.buffer.splice(0, overflow);
@@ -1133,8 +1136,32 @@ var ViolationReporter = class {
1133
1136
  if (this.buffer.length >= this.maxBufferSize) {
1134
1137
  this.flush().catch(() => {
1135
1138
  });
1139
+ } else {
1140
+ this.scheduleDelivery();
1136
1141
  }
1137
1142
  }
1143
+ /**
1144
+ * Give buffered events one delivery attempt before the process can exit.
1145
+ *
1146
+ * The interval above is unref'd so an idle reporter never holds a process
1147
+ * open. On its own that meant a server shut down gracefully (Express after
1148
+ * server.close(), Fastify after close(), Hono on Node) exited with its last
1149
+ * events unsent and uncounted. This one-shot timer is left ref'd, so a
1150
+ * natural exit waits at most one flush interval plus the request timeout.
1151
+ * It is not re-armed while the client is paused, so an outage cannot keep
1152
+ * the process alive.
1153
+ */
1154
+ cancelDelivery() {
1155
+ clearTimeout(this.deliveryTimer);
1156
+ this.deliveryTimer = void 0;
1157
+ }
1158
+ scheduleDelivery() {
1159
+ if (this.deliveryTimer) return;
1160
+ this.deliveryTimer = setTimeout(() => {
1161
+ this.deliveryTimer = void 0;
1162
+ void this.flush();
1163
+ }, this.flushInterval);
1164
+ }
1138
1165
  /** Flush the buffer, coalescing requests that arrive during an active send. */
1139
1166
  flush() {
1140
1167
  if (this.queuedFlush) return this.queuedFlush;
@@ -1150,6 +1177,7 @@ var ViolationReporter = class {
1150
1177
  const size = this.buffer.length;
1151
1178
  this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
1152
1179
  this.flushPromise = void 0;
1180
+ if (this.buffer.length === 0) this.cancelDelivery();
1153
1181
  });
1154
1182
  return this.flushPromise;
1155
1183
  }
@@ -1179,6 +1207,7 @@ var ViolationReporter = class {
1179
1207
  /** Stop the timer and give remaining events one final flush. */
1180
1208
  async destroy() {
1181
1209
  clearInterval(this.flushTimer);
1210
+ this.cancelDelivery();
1182
1211
  if (this.flushPromise) await this.flushPromise;
1183
1212
  await this.flush();
1184
1213
  this.droppedEvents += this.buffer.length;
package/dist/testing.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WebDecoy,
3
3
  silentLogger
4
- } from "./chunk-IGSPJVI6.mjs";
4
+ } from "./chunk-CUAZKMMQ.mjs";
5
5
 
6
6
  // src/testing.ts
7
7
  function request(over = {}) {
package/dist/vercel.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-DWOUDUSY.mjs';
2
- import './sdk-DveMEqxl.mjs';
1
+ import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-DtE2PPTM.mjs';
2
+ import './sdk-Gay_Ddzy.mjs';
3
3
 
4
4
  /**
5
5
  * WebDecoy for Vercel Routing Middleware, any framework.
package/dist/vercel.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-BfL39HDb.js';
2
- import './sdk-DveMEqxl.js';
1
+ import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-neuBgxUB.js';
2
+ import './sdk-Gay_Ddzy.js';
3
3
 
4
4
  /**
5
5
  * WebDecoy for Vercel Routing Middleware, any framework.
package/dist/vercel.js CHANGED
@@ -2549,6 +2549,7 @@ var ViolationReporter = class {
2549
2549
  this.maxBufferSize = config.maxBufferSize ?? 50;
2550
2550
  this.debug = config.debug ?? false;
2551
2551
  const flushInterval = config.flushInterval ?? 5e3;
2552
+ this.flushInterval = flushInterval;
2552
2553
  this.flushTimer = setInterval(() => void this.flush(), flushInterval);
2553
2554
  if (this.flushTimer.unref) {
2554
2555
  this.flushTimer.unref();
@@ -2558,7 +2559,9 @@ var ViolationReporter = class {
2558
2559
  * Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
2559
2560
  */
2560
2561
  report(violations) {
2561
- this.buffer.push(...violations);
2562
+ for (const violation of violations) {
2563
+ this.buffer.push(violation.eventId ? violation : { ...violation, eventId: crypto.randomUUID() });
2564
+ }
2562
2565
  if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
2563
2566
  const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
2564
2567
  this.buffer.splice(0, overflow);
@@ -2567,8 +2570,32 @@ var ViolationReporter = class {
2567
2570
  if (this.buffer.length >= this.maxBufferSize) {
2568
2571
  this.flush().catch(() => {
2569
2572
  });
2573
+ } else {
2574
+ this.scheduleDelivery();
2570
2575
  }
2571
2576
  }
2577
+ /**
2578
+ * Give buffered events one delivery attempt before the process can exit.
2579
+ *
2580
+ * The interval above is unref'd so an idle reporter never holds a process
2581
+ * open. On its own that meant a server shut down gracefully (Express after
2582
+ * server.close(), Fastify after close(), Hono on Node) exited with its last
2583
+ * events unsent and uncounted. This one-shot timer is left ref'd, so a
2584
+ * natural exit waits at most one flush interval plus the request timeout.
2585
+ * It is not re-armed while the client is paused, so an outage cannot keep
2586
+ * the process alive.
2587
+ */
2588
+ cancelDelivery() {
2589
+ clearTimeout(this.deliveryTimer);
2590
+ this.deliveryTimer = void 0;
2591
+ }
2592
+ scheduleDelivery() {
2593
+ if (this.deliveryTimer) return;
2594
+ this.deliveryTimer = setTimeout(() => {
2595
+ this.deliveryTimer = void 0;
2596
+ void this.flush();
2597
+ }, this.flushInterval);
2598
+ }
2572
2599
  /** Flush the buffer, coalescing requests that arrive during an active send. */
2573
2600
  flush() {
2574
2601
  if (this.queuedFlush) return this.queuedFlush;
@@ -2584,6 +2611,7 @@ var ViolationReporter = class {
2584
2611
  const size = this.buffer.length;
2585
2612
  this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
2586
2613
  this.flushPromise = void 0;
2614
+ if (this.buffer.length === 0) this.cancelDelivery();
2587
2615
  });
2588
2616
  return this.flushPromise;
2589
2617
  }
@@ -2613,6 +2641,7 @@ var ViolationReporter = class {
2613
2641
  /** Stop the timer and give remaining events one final flush. */
2614
2642
  async destroy() {
2615
2643
  clearInterval(this.flushTimer);
2644
+ this.cancelDelivery();
2616
2645
  if (this.flushPromise) await this.flushPromise;
2617
2646
  await this.flush();
2618
2647
  this.droppedEvents += this.buffer.length;
@@ -4548,7 +4577,7 @@ function createFetchGuard(options = {}) {
4548
4577
  skips(pathname) {
4549
4578
  return shouldSkipPath(pathname, options.skipPaths);
4550
4579
  },
4551
- async check(request, peer) {
4580
+ async check(request, peer, lifecycle) {
4552
4581
  const url = new URL(request.url);
4553
4582
  const headers = headerRecord(request.headers);
4554
4583
  if (!headers.host && !headers[":authority"]) headers.host = url.host;
@@ -4565,7 +4594,7 @@ function createFetchGuard(options = {}) {
4565
4594
  threshold: options.threshold,
4566
4595
  skipLocalAnalysis: options.skipLocalAnalysis,
4567
4596
  metadata: options.metadata,
4568
- violationReporting: { mode }
4597
+ violationReporting: { mode, waitUntil: lifecycle?.waitUntil }
4569
4598
  });
4570
4599
  if (decision.allowed || mode !== "enforce") return { decision };
4571
4600
  return { decision, response: await onBlocked(request, decision) };
package/dist/vercel.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createClearanceGate,
3
3
  createDetectAndGate
4
- } from "./chunk-BBRVE4RC.mjs";
5
- import "./chunk-IGSPJVI6.mjs";
4
+ } from "./chunk-S7GDCKKB.mjs";
5
+ import "./chunk-CUAZKMMQ.mjs";
6
6
 
7
7
  // src/vercel.ts
8
8
  function toMiddlewareResponse(outcome) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/node",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "Bot detection and AI agent verification for Node.js and edge runtimes. Local honeypot tripwires, rate limiting and AI crawler policies, with optional WebDecoy dashboard reporting.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",