@webdecoy/node 0.31.0 → 0.33.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/dist/index.mjs CHANGED
@@ -5,13 +5,13 @@ import {
5
5
  createFetchGuard,
6
6
  deriveAndArm,
7
7
  ipInCidr,
8
- ne,
9
8
  normalizeIp,
9
+ oe,
10
10
  resolveClientIp,
11
11
  resolveGateEnv,
12
12
  ruleBlockResponse,
13
13
  shouldSkipPath
14
- } from "./chunk-BBRVE4RC.mjs";
14
+ } from "./chunk-XFBXUBFG.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 {
@@ -2388,7 +2388,7 @@ export {
2388
2388
  BOT_REGISTRY,
2389
2389
  BotPolicy,
2390
2390
  BotRule,
2391
- ne as CLEARANCE_GATE_BUILD,
2391
+ oe as CLEARANCE_GATE_BUILD,
2392
2392
  CLIENT_SESSION_COOKIE,
2393
2393
  CLIENT_SESSION_HEADER,
2394
2394
  Captcha,
@@ -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.