ezlogs-nextjs 0.3.1 → 0.4.2

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.
Files changed (76) hide show
  1. package/README.md +149 -30
  2. package/bin/install-triggers.cjs +7 -2
  3. package/dist/actors/index.cjs +4 -4
  4. package/dist/actors/index.d.cts +1 -1
  5. package/dist/actors/index.d.ts +1 -1
  6. package/dist/actors/index.js +1 -1
  7. package/dist/{chunk-C5OSM557.js → chunk-FCFVIRQF.js} +7 -0
  8. package/dist/chunk-GI6BM4MR.js +443 -0
  9. package/dist/{chunk-YX2XPLOA.cjs → chunk-GMHOUAKD.cjs} +63 -34
  10. package/dist/{chunk-CU45I2WR.js → chunk-MHBS5FEP.js} +48 -20
  11. package/dist/chunk-MMLQXSSD.cjs +461 -0
  12. package/dist/{chunk-CE3R7DVB.js → chunk-NINIAL7M.js} +60 -384
  13. package/dist/{chunk-Y5NSHKWQ.cjs → chunk-NX4EL7BY.cjs} +57 -7
  14. package/dist/chunk-PS4U2GFJ.cjs +52 -0
  15. package/dist/chunk-R6IWVTX3.cjs +212 -0
  16. package/dist/{chunk-V5YNKKTG.cjs → chunk-TWTG5ILJ.cjs} +7 -0
  17. package/dist/chunk-U22T7QYY.js +200 -0
  18. package/dist/chunk-YMIGZYFH.js +48 -0
  19. package/dist/{chunk-WASXTDLW.cjs → chunk-YXZZNZG6.cjs} +71 -403
  20. package/dist/{chunk-DKRNNI4I.js → chunk-Z2TM3LGG.js} +53 -3
  21. package/dist/{configuration-OHLNivON.d.ts → configuration-CJ5yKVlP.d.cts} +14 -8
  22. package/dist/{configuration-OHLNivON.d.cts → configuration-CJ5yKVlP.d.ts} +14 -8
  23. package/dist/db/drizzle.cjs +5 -4
  24. package/dist/db/drizzle.js +3 -2
  25. package/dist/db/postgres-js.cjs +98 -0
  26. package/dist/db/postgres-js.d.cts +11 -0
  27. package/dist/db/postgres-js.d.ts +11 -0
  28. package/dist/db/postgres-js.js +95 -0
  29. package/dist/db/prisma.cjs +21 -20
  30. package/dist/db/prisma.d.cts +19 -2
  31. package/dist/db/prisma.d.ts +19 -2
  32. package/dist/db/prisma.js +6 -5
  33. package/dist/db/supabase.cjs +19 -12
  34. package/dist/db/supabase.d.cts +3 -2
  35. package/dist/db/supabase.d.ts +3 -2
  36. package/dist/db/supabase.js +11 -4
  37. package/dist/index.cjs +596 -165
  38. package/dist/index.d.cts +5 -3
  39. package/dist/index.d.ts +5 -3
  40. package/dist/index.js +492 -62
  41. package/dist/jobs/bullmq.cjs +63 -18
  42. package/dist/jobs/bullmq.d.cts +0 -4
  43. package/dist/jobs/bullmq.d.ts +0 -4
  44. package/dist/jobs/bullmq.js +59 -14
  45. package/dist/jobs/inngest.cjs +61 -24
  46. package/dist/jobs/inngest.d.cts +5 -1
  47. package/dist/jobs/inngest.d.ts +5 -1
  48. package/dist/jobs/inngest.js +55 -18
  49. package/dist/jobs/supabase-queues.cjs +17 -15
  50. package/dist/jobs/supabase-queues.d.cts +1 -1
  51. package/dist/jobs/supabase-queues.d.ts +1 -1
  52. package/dist/jobs/supabase-queues.js +15 -13
  53. package/dist/jobs/trigger.cjs +11 -12
  54. package/dist/jobs/trigger.d.cts +4 -3
  55. package/dist/jobs/trigger.d.ts +4 -3
  56. package/dist/jobs/trigger.js +7 -8
  57. package/dist/jobs/upstash-workflow.cjs +43 -35
  58. package/dist/jobs/upstash-workflow.d.cts +2 -8
  59. package/dist/jobs/upstash-workflow.d.ts +2 -8
  60. package/dist/jobs/upstash-workflow.js +38 -30
  61. package/dist/nextjs-plugin/index.cjs +39 -3
  62. package/dist/nextjs-plugin/index.d.cts +8 -1
  63. package/dist/nextjs-plugin/index.d.ts +8 -1
  64. package/dist/nextjs-plugin/index.js +39 -3
  65. package/dist/nextjs-plugin/loader.cjs +41 -3
  66. package/dist/nextjs-plugin/loader.d.cts +1 -0
  67. package/dist/nextjs-plugin/loader.d.ts +1 -0
  68. package/dist/nextjs-plugin/loader.js +42 -4
  69. package/dist/triggers/index.cjs +145 -92
  70. package/dist/triggers/index.d.cts +20 -5
  71. package/dist/triggers/index.d.ts +20 -5
  72. package/dist/triggers/index.js +125 -82
  73. package/package.json +11 -1
  74. package/sql/postgres/00_install.sql +1 -1
  75. package/dist/chunk-UQHEW6ER.js +0 -119
  76. package/dist/chunk-UWHYJH4M.cjs +0 -126
@@ -1,172 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkV5YNKKTG_cjs = require('./chunk-V5YNKKTG.cjs');
3
+ var chunkMMLQXSSD_cjs = require('./chunk-MMLQXSSD.cjs');
4
+ var chunkTWTG5ILJ_cjs = require('./chunk-TWTG5ILJ.cjs');
4
5
  var chunkZDSQYCYV_cjs = require('./chunk-ZDSQYCYV.cjs');
5
6
 
6
- // src/configuration.ts
7
- var DEFAULT_EXCLUDED_PATHS = Object.freeze([
8
- // Next.js / Vercel infrastructure noise
9
- "/_next/*",
10
- "/_vercel/*",
11
- "/__nextjs_*",
12
- // NextAuth.js / Auth.js — skip session-refresh polls and CSRF/provider
13
- // metadata GETs (high-frequency, no business meaning), but CAPTURE
14
- // POSTs (callbacks, signin, signout, register). The POSTs are the
15
- // actual auth events users care about; the GETs are pure plumbing.
16
- Object.freeze({ path: "/api/auth/*", methods: ["GET", "HEAD"] }),
17
- // Generic infrastructure
18
- "/health*",
19
- "/api/health",
20
- "/up",
21
- "/alive",
22
- "/ready",
23
- "/metrics",
24
- "/favicon.ico",
25
- "/.well-known*",
26
- "/robots.txt",
27
- "/sitemap.xml",
28
- "/*.hot-update.*",
29
- // Auth routes (common patterns across Clerk, NextAuth, custom auth)
30
- "*/login*",
31
- "*/logout*",
32
- "*/sign-in*",
33
- "*/sign-out*",
34
- "*/signin*",
35
- "*/signout*",
36
- "/session*"
37
- ]);
38
- var DEFAULT_EXCLUDED_EXTENSIONS = Object.freeze([
39
- ".js",
40
- ".css",
41
- ".map",
42
- ".png",
43
- ".jpg",
44
- ".jpeg",
45
- ".gif",
46
- ".svg",
47
- ".ico",
48
- ".webp",
49
- ".woff",
50
- ".woff2",
51
- ".ttf",
52
- ".eot",
53
- ".otf"
54
- ]);
55
- var DEFAULT_EXCLUDED_TABLES = Object.freeze([
56
- // Prisma migration ledger
57
- "_prisma_migrations",
58
- // Auth.js / NextAuth Prisma adapter — session/verification-token churn
59
- // is auth machinery, not business activity. Account/User stay captured.
60
- "Session",
61
- "VerificationToken",
62
- // Common cross-stack convention names for the same things
63
- "sessions",
64
- "session",
65
- "verification_tokens"
66
- ]);
67
- var DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
68
- var DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
69
- var Configuration = class {
70
- serverUrl = null;
71
- projectToken = null;
72
- captureHttp = true;
73
- captureDb = true;
74
- captureJobs = true;
75
- bufferSize = 1e4;
76
- /** Default 3000 ms — equivalent to Ruby's 3 seconds. */
77
- sendInterval = 3e3;
78
- retryAttempts = 3;
79
- logLevel = "warn";
80
- patchGlobalFetch = true;
81
- actorFromSupabase = true;
82
- allowInsecureTransport = false;
83
- excludedPaths = [];
84
- excludedTables = [];
85
- excludedJobClasses = [];
86
- excludedGraphqlOperations = [];
87
- excludedGraphqlVariableKeys = [];
88
- actorFromRequest = null;
89
- displayNameFor = {};
90
- isServerActionError = null;
91
- databaseReader = null;
92
- databaseUrl = null;
93
- /**
94
- * Tables that have the `ezlogs_audit` trigger attached. Detected once
95
- * at agent startup by reading `information_schema.triggers`. The
96
- * supabase / drizzle / prisma adapters use this to decide whether
97
- * their per-mutation emit is redundant: if the table is trigger-
98
- * tracked the audit-log reader will surface the same write with full
99
- * old/new state, so the adapter's emit is suppressed. Tables NOT in
100
- * this set fall through to the adapter so they're still captured.
101
- *
102
- * `null` means "detection hasn't run yet or failed" — in that state
103
- * `databaseReader`-wired apps suppress every adapter emit (the
104
- * original Phase 5 behavior). After detection completes the agent
105
- * gives the more accurate per-table answer.
106
- */
107
- triggerTrackedTables = null;
108
- apply(options) {
109
- this.serverUrl = options.serverUrl;
110
- this.projectToken = options.projectToken;
111
- if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
112
- if (options.captureDb !== void 0) this.captureDb = options.captureDb;
113
- if (options.captureJobs !== void 0) this.captureJobs = options.captureJobs;
114
- if (options.bufferSize !== void 0) this.bufferSize = options.bufferSize;
115
- if (options.sendInterval !== void 0) this.sendInterval = options.sendInterval;
116
- if (options.retryAttempts !== void 0) this.retryAttempts = options.retryAttempts;
117
- if (options.excludedPaths) this.excludedPaths = [...options.excludedPaths];
118
- if (options.excludedTables) this.excludedTables = [...options.excludedTables];
119
- if (options.excludedJobClasses) {
120
- this.excludedJobClasses = [...options.excludedJobClasses];
121
- }
122
- if (options.excludedGraphqlOperations) {
123
- this.excludedGraphqlOperations = [...options.excludedGraphqlOperations];
124
- }
125
- if (options.excludedGraphqlVariableKeys) {
126
- this.excludedGraphqlVariableKeys = [...options.excludedGraphqlVariableKeys];
127
- }
128
- if (options.actorFromRequest) this.actorFromRequest = options.actorFromRequest;
129
- if (options.displayNameFor) this.displayNameFor = { ...options.displayNameFor };
130
- if (options.isServerActionError) this.isServerActionError = options.isServerActionError;
131
- if (options.patchGlobalFetch !== void 0) {
132
- this.patchGlobalFetch = options.patchGlobalFetch;
133
- }
134
- if (options.allowInsecureTransport !== void 0) {
135
- this.allowInsecureTransport = options.allowInsecureTransport;
136
- }
137
- if (options.actorFromSupabase !== void 0) {
138
- this.actorFromSupabase = options.actorFromSupabase;
139
- }
140
- if (options.databaseReader !== void 0) {
141
- this.databaseReader = options.databaseReader;
142
- }
143
- if (options.databaseUrl !== void 0) {
144
- this.databaseUrl = options.databaseUrl;
145
- }
146
- if (options.logLevel) this.logLevel = options.logLevel;
147
- }
148
- allExcludedPaths() {
149
- return [...DEFAULT_EXCLUDED_PATHS, ...this.excludedPaths];
150
- }
151
- allExcludedTables() {
152
- return [...DEFAULT_EXCLUDED_TABLES, ...this.excludedTables];
153
- }
154
- allExcludedJobClasses() {
155
- return [...DEFAULT_EXCLUDED_JOB_CLASSES, ...this.excludedJobClasses];
156
- }
157
- allExcludedGraphqlOperations() {
158
- return [...DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, ...this.excludedGraphqlOperations];
159
- }
160
- };
161
- var GLOBAL_CONFIG_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:configuration");
162
- function configuration() {
163
- const g = globalThis;
164
- if (!g[GLOBAL_CONFIG_KEY]) {
165
- g[GLOBAL_CONFIG_KEY] = new Configuration();
166
- }
167
- return g[GLOBAL_CONFIG_KEY];
168
- }
169
-
170
7
  // src/pipeline/buffer.ts
171
8
  var buffer_exports = {};
172
9
  chunkZDSQYCYV_cjs.__export(buffer_exports, {
@@ -187,11 +24,11 @@ function pushEvent(event) {
187
24
  const max = maxSize();
188
25
  if (queue.length >= max) {
189
26
  queue.shift();
190
- chunkV5YNKKTG_cjs.logger.warn(`Buffer full (${max}), dropped oldest event`);
27
+ chunkTWTG5ILJ_cjs.logger.warn(`Buffer full (${max}), dropped oldest event`);
191
28
  }
192
29
  queue.push(event);
193
30
  } catch (error) {
194
- chunkV5YNKKTG_cjs.logger.error(`pushEvent failed: ${describe(error)}`);
31
+ chunkTWTG5ILJ_cjs.logger.error(`pushEvent failed: ${describe(error)}`);
195
32
  }
196
33
  }
197
34
  function drainEvents() {
@@ -200,7 +37,7 @@ function drainEvents() {
200
37
  if (queue.length === 0) return [];
201
38
  return queue.splice(0, queue.length);
202
39
  } catch (error) {
203
- chunkV5YNKKTG_cjs.logger.error(`drainEvents failed: ${describe(error)}`);
40
+ chunkTWTG5ILJ_cjs.logger.error(`drainEvents failed: ${describe(error)}`);
204
41
  return [];
205
42
  }
206
43
  }
@@ -213,7 +50,7 @@ function clearBuffer() {
213
50
  }
214
51
  function maxSize() {
215
52
  try {
216
- return configuration().bufferSize;
53
+ return chunkMMLQXSSD_cjs.configuration().bufferSize;
217
54
  } catch {
218
55
  return 1e4;
219
56
  }
@@ -223,156 +60,6 @@ function describe(error) {
223
60
  return String(error);
224
61
  }
225
62
 
226
- // src/edge-fallback.ts
227
- var ALS_CTOR = loadAsyncLocalStorage();
228
- function loadAsyncLocalStorage() {
229
- const fromGlobal = globalThis.AsyncLocalStorage;
230
- if (typeof fromGlobal === "function") return fromGlobal;
231
- try {
232
- const req = typeof chunkZDSQYCYV_cjs.__require !== "undefined" ? chunkZDSQYCYV_cjs.__require : (
233
- // In ESM, `createRequire` is the official escape hatch.
234
- // We pull it via globalThis to avoid a static `import`
235
- // that would itself be browser-bundled.
236
- void 0
237
- );
238
- if (typeof req === "function") {
239
- const moduleName = ["async", "hooks"].join("_");
240
- const mod = req("node:" + moduleName);
241
- if (typeof mod.AsyncLocalStorage === "function") return mod.AsyncLocalStorage;
242
- }
243
- } catch {
244
- }
245
- return null;
246
- }
247
- function makeAsyncContextCapture() {
248
- if (!ALS_CTOR) return null;
249
- const ctor = ALS_CTOR;
250
- if (typeof ctor.snapshot !== "function") return null;
251
- const snapshot = ctor.snapshot.bind(ctor);
252
- return () => {
253
- const runSnapshot = snapshot();
254
- return (fn) => runSnapshot(fn);
255
- };
256
- }
257
- function createScopedStorage(key = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:default-scoped-storage")) {
258
- const globalStore = globalThis;
259
- let entry = globalStore[key];
260
- if (!entry) {
261
- const als2 = (() => {
262
- if (!ALS_CTOR) return null;
263
- try {
264
- return new ALS_CTOR();
265
- } catch {
266
- return null;
267
- }
268
- })();
269
- entry = { als: als2, edgeFallback: null };
270
- globalStore[key] = entry;
271
- }
272
- const als = entry.als;
273
- const stateRef = entry;
274
- return {
275
- read() {
276
- if (als) return als.getStore()?.value ?? null;
277
- return stateRef.edgeFallback?.value ?? null;
278
- },
279
- run(value, callback) {
280
- if (als) return als.run({ value }, callback);
281
- const previous = stateRef.edgeFallback;
282
- stateRef.edgeFallback = { value };
283
- try {
284
- return callback();
285
- } finally {
286
- stateRef.edgeFallback = previous;
287
- }
288
- },
289
- update(value) {
290
- if (als) {
291
- const store = als.getStore();
292
- if (store) store.value = value;
293
- return;
294
- }
295
- stateRef.edgeFallback = { value };
296
- },
297
- _resetForTests() {
298
- stateRef.edgeFallback = null;
299
- },
300
- _isAsyncLocalStorage() {
301
- return als !== null;
302
- }
303
- };
304
- }
305
-
306
- // src/correlation.ts
307
- var CORRELATION_HEADER = "x-ezlogs-correlation-id";
308
- var PLATFORM_REQUEST_ID_HEADERS = [
309
- "x-vercel-id",
310
- "cf-ray",
311
- "x-request-id"
312
- ];
313
- var storage = createScopedStorage(
314
- /* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
315
- );
316
- function generate() {
317
- const ts = Date.now();
318
- const hex = randomHexBytes(4);
319
- return `ezl_${ts}_${hex}`;
320
- }
321
- function randomHexBytes(byteCount) {
322
- const buf = new Uint8Array(byteCount);
323
- globalThis.crypto.getRandomValues(buf);
324
- let out = "";
325
- for (let i = 0; i < buf.length; i++) {
326
- out += buf[i].toString(16).padStart(2, "0");
327
- }
328
- return out;
329
- }
330
- function resolveCorrelation(headers) {
331
- if (!headers) return generate();
332
- const ezlogs = safeRead(headers, CORRELATION_HEADER);
333
- if (ezlogs && isTrustedInboundId(ezlogs)) return ezlogs;
334
- for (const name of PLATFORM_REQUEST_ID_HEADERS) {
335
- const platformId = safeRead(headers, name);
336
- if (platformId) return wrapPlatformId(platformId);
337
- }
338
- return generate();
339
- }
340
- var INBOUND_ID = /^ezl_(\d{13})_[0-9a-f]{8}$/;
341
- var INBOUND_MAX_AGE_MS = 60 * 6e4;
342
- function isTrustedInboundId(id) {
343
- const match = INBOUND_ID.exec(id);
344
- if (!match) return false;
345
- const age = Date.now() - Number(match[1]);
346
- return age <= INBOUND_MAX_AGE_MS && age >= -3e5;
347
- }
348
- function safeRead(headers, name) {
349
- try {
350
- const value = headers.get(name);
351
- return typeof value === "string" && value.length > 0 ? value : null;
352
- } catch {
353
- return null;
354
- }
355
- }
356
- function wrapPlatformId(platformId) {
357
- const ts = Date.now();
358
- const hex = fnv1aHex(platformId);
359
- return `ezl_${ts}_${hex}`;
360
- }
361
- function fnv1aHex(input) {
362
- let hash = 2166136261;
363
- for (let i = 0; i < input.length; i++) {
364
- hash ^= input.charCodeAt(i);
365
- hash = Math.imul(hash, 16777619);
366
- }
367
- return (hash >>> 0).toString(16).padStart(8, "0");
368
- }
369
- function current() {
370
- return storage.read();
371
- }
372
- function runWithCorrelation(correlationId, callback) {
373
- return storage.run(correlationId, callback);
374
- }
375
-
376
63
  // src/event-builder.ts
377
64
  var SENSITIVE_KEYS = Object.freeze([
378
65
  "password",
@@ -572,71 +259,6 @@ var ArgError = class extends Error {
572
259
  }
573
260
  };
574
261
 
575
- // src/actor.ts
576
- var storage2 = createScopedStorage(
577
- /* @__PURE__ */ Symbol.for("ezlogs-nextjs:actor-storage")
578
- );
579
- function getCurrentActor() {
580
- return storage2.read();
581
- }
582
- function setActor(input) {
583
- const sanitized = validateActor(input);
584
- if (input != null && sanitized === null) {
585
- chunkV5YNKKTG_cjs.logger.debug(`Actor: invalid actor structure ignored: ${describe3(input)}`);
586
- }
587
- storage2.update(sanitized);
588
- return sanitized;
589
- }
590
- function runWithActorScope(callback) {
591
- return storage2.run(null, callback);
592
- }
593
- var VALID_KINDS = /* @__PURE__ */ new Set(["human", "agent", "system", "hybrid"]);
594
- function validateActor(input) {
595
- if (input === null || input === void 0) return null;
596
- if (typeof input !== "object") return null;
597
- if (Array.isArray(input)) return null;
598
- const obj = input;
599
- const rawId = obj.id;
600
- if (rawId === null || rawId === void 0) return null;
601
- const id = String(rawId);
602
- if (id === "") return null;
603
- const result = { id };
604
- if (obj.label !== void 0 && obj.label !== null) {
605
- result.label = String(obj.label);
606
- }
607
- if (obj.kind !== void 0 && obj.kind !== null) {
608
- const kind = String(obj.kind);
609
- if (VALID_KINDS.has(kind)) {
610
- result.kind = kind;
611
- }
612
- }
613
- const principal = sanitizePrincipal(obj.principal);
614
- if (principal) result.principal = principal;
615
- return result;
616
- }
617
- function sanitizePrincipal(input) {
618
- if (input === null || input === void 0) return null;
619
- if (typeof input !== "object") return null;
620
- if (Array.isArray(input)) return null;
621
- const obj = input;
622
- const rawId = obj.id;
623
- if (rawId === null || rawId === void 0) return null;
624
- const id = String(rawId);
625
- if (id === "") return null;
626
- const result = { id };
627
- if (obj.label !== void 0 && obj.label !== null) {
628
- result.label = String(obj.label);
629
- }
630
- return result;
631
- }
632
- function describe3(value) {
633
- try {
634
- return JSON.stringify(value);
635
- } catch {
636
- return Object.prototype.toString.call(value);
637
- }
638
- }
639
-
640
262
  // src/http/sanitize.ts
641
263
  var SENSITIVE_VARIABLE_PATTERNS = Object.freeze([
642
264
  "password",
@@ -814,7 +436,7 @@ function sanitizeArrayItem(item, depth, userPatterns) {
814
436
  if (Array.isArray(item)) return sanitizeArrayValue(item, depth + 1, userPatterns);
815
437
  return "[Object]";
816
438
  }
817
- function isSensitiveKey2(key, userPatterns) {
439
+ function isSensitiveKey2(key, userPatterns = []) {
818
440
  if (matchesSensitiveKey(key, SENSITIVE_VARIABLE_PATTERNS)) return true;
819
441
  const lower = key.toLowerCase();
820
442
  return userPatterns.some((p) => lower.includes(p.toLowerCase()));
@@ -827,6 +449,52 @@ function isPlainObject2(value) {
827
449
  const proto = Object.getPrototypeOf(value);
828
450
  return proto === Object.prototype || proto === null;
829
451
  }
452
+ var AUTH_PATH = /(^|\/)(api\/auth\/|auth\/(callback|confirm)|log-?in|log-?out|sign-?in|sign-?out|sign-?up|register|sessions?(\/|$))/i;
453
+ var AUTH_ACTION = /^(sign_?(in|up|out)|log_?(in|out)|register|verify|reset|magic|otp|auth)/i;
454
+ var AUTH_ONLY_KEY = /^(code|state|verificationcode|onetimecode|otp.*|pin|token.*)$/;
455
+ var REDIRECT_KEY = /^(callbackurl|redirect(url|uri|to)?|returnto|returnurl|next|continue|frompage)$/;
456
+ var SECRET_QUERY_PARAM = /token|code|state|otp|secret|password|key|sig|auth/i;
457
+ var normKey = (key) => key.toLowerCase().replace(/[_-]/g, "");
458
+ function isAuthPath(pathname) {
459
+ return AUTH_PATH.test(pathname);
460
+ }
461
+ function isAuthActionName(name) {
462
+ return AUTH_ACTION.test(name);
463
+ }
464
+ function maskAuthParams(params, onAuthRoute, depth = 0) {
465
+ if (depth > 4 || params === null || typeof params !== "object") return params;
466
+ if (Array.isArray(params)) return params.map((v) => maskAuthParams(v, onAuthRoute, depth + 1));
467
+ const out = {};
468
+ for (const [key, value] of Object.entries(params)) {
469
+ const k = normKey(key);
470
+ if (onAuthRoute && AUTH_ONLY_KEY.test(k) && value !== null && value !== void 0 && value !== "") {
471
+ out[key] = "[FILTERED]";
472
+ } else if (REDIRECT_KEY.test(k) && typeof value === "string") {
473
+ out[key] = maskUrlSecrets(value);
474
+ } else {
475
+ out[key] = maskAuthParams(value, onAuthRoute, depth + 1);
476
+ }
477
+ }
478
+ return out;
479
+ }
480
+ function maskUrlSecrets(value) {
481
+ if (!value.includes("?")) return value;
482
+ try {
483
+ const absolute = /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
484
+ const url = new URL(value, "http://localhost");
485
+ let changed = false;
486
+ for (const name of [...url.searchParams.keys()]) {
487
+ if (SECRET_QUERY_PARAM.test(name)) {
488
+ url.searchParams.set(name, "[FILTERED]");
489
+ changed = true;
490
+ }
491
+ }
492
+ if (!changed) return value;
493
+ return absolute ? url.toString() : `${url.pathname}${url.search}${url.hash}`;
494
+ } catch {
495
+ return value;
496
+ }
497
+ }
830
498
 
831
499
  // src/db/shared.ts
832
500
  var IGNORED_ATTRIBUTES = Object.freeze([
@@ -873,9 +541,12 @@ var DB_SENSITIVE_PATTERNS = Object.freeze([
873
541
  ]);
874
542
  function emitDbEvent(input) {
875
543
  try {
876
- const config = configuration();
544
+ const config = chunkMMLQXSSD_cjs.configuration();
877
545
  if (!config.captureDb) return;
878
- if (config.allExcludedTables().includes(input.modelClass)) return;
546
+ if (config.excludedTables.includes(input.modelClass)) return;
547
+ if (chunkMMLQXSSD_cjs.DEFAULT_EXCLUDED_TABLES.includes(input.modelClass) && !(input._fromTrigger && isBusinessSessionRow(input.modelClass, input.modelInstance))) {
548
+ return;
549
+ }
879
550
  if (config.databaseReader && !input._fromTrigger) {
880
551
  const tracked = config.triggerTrackedTables;
881
552
  if (tracked === null || tracked.has(input.table ?? input.modelClass)) return;
@@ -896,7 +567,7 @@ function emitDbEvent(input) {
896
567
  operation: input.operation
897
568
  },
898
569
  outcome: "success",
899
- correlation_id: current(),
570
+ correlation_id: chunkMMLQXSSD_cjs.current(),
900
571
  resource_ids: resourceIdStr === null ? [...related] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
901
572
  context,
902
573
  duration_ms: null,
@@ -904,12 +575,12 @@ function emitDbEvent(input) {
904
575
  });
905
576
  pushEvent(event);
906
577
  } catch (error) {
907
- chunkV5YNKKTG_cjs.logger.debug(`db emit failed: ${describeError(error)}`);
578
+ chunkTWTG5ILJ_cjs.logger.debug(`db emit failed: ${describeError(error)}`);
908
579
  }
909
580
  }
910
581
  function buildContext(input) {
911
582
  const context = {};
912
- const actor = getCurrentActor();
583
+ const actor = chunkMMLQXSSD_cjs.getCurrentActor();
913
584
  if (actor) context.actor = actor;
914
585
  if ((input.operation === "create" || input.operation === "destroy") && input.initialAttributes) {
915
586
  const filtered = filterMeaningfulAttributes(input.initialAttributes);
@@ -1063,11 +734,16 @@ function isPrismaDecimal(value) {
1063
734
  const obj = value;
1064
735
  return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
1065
736
  }
737
+ function isBusinessSessionRow(table, row) {
738
+ if (!chunkMMLQXSSD_cjs.AUTH_SESSION_TABLE_NAMES.test(table) || /verif/i.test(table) || !row) return false;
739
+ const columns = Object.keys(row);
740
+ return columns.length > 0 && !columns.some(chunkMMLQXSSD_cjs.isSessionStoreColumn);
741
+ }
1066
742
  var DISPLAY_NAME_COLUMNS = ["name", "title", "number", "label"];
1067
743
  var MAX_DISPLAY_NAME_LENGTH = 120;
1068
744
  function resolveDisplayName(modelClass, instance) {
1069
745
  try {
1070
- const config = configuration();
746
+ const config = chunkMMLQXSSD_cjs.configuration();
1071
747
  const resolver = config.displayNameFor[modelClass];
1072
748
  const resolved = applyResolver(resolver, instance);
1073
749
  if (resolved !== null) return resolved;
@@ -1127,25 +803,17 @@ function describeError(error) {
1127
803
  }
1128
804
 
1129
805
  exports.ArgError = ArgError;
1130
- exports.DEFAULT_EXCLUDED_EXTENSIONS = DEFAULT_EXCLUDED_EXTENSIONS;
1131
- exports.DEFAULT_EXCLUDED_TABLES = DEFAULT_EXCLUDED_TABLES;
1132
806
  exports.buffer_exports = buffer_exports;
1133
807
  exports.build = build;
1134
- exports.configuration = configuration;
1135
- exports.createScopedStorage = createScopedStorage;
1136
- exports.current = current;
1137
808
  exports.drainEvents = drainEvents;
1138
809
  exports.emitDbEvent = emitDbEvent;
1139
- exports.generate = generate;
1140
- exports.getCurrentActor = getCurrentActor;
1141
- exports.makeAsyncContextCapture = makeAsyncContextCapture;
810
+ exports.isAuthActionName = isAuthActionName;
811
+ exports.isAuthPath = isAuthPath;
812
+ exports.isSensitiveKey = isSensitiveKey2;
813
+ exports.maskAuthParams = maskAuthParams;
1142
814
  exports.passesLuhn = passesLuhn;
1143
815
  exports.pushEvent = pushEvent;
1144
- exports.resolveCorrelation = resolveCorrelation;
1145
816
  exports.resolveDisplayName = resolveDisplayName;
1146
- exports.runWithActorScope = runWithActorScope;
1147
- exports.runWithCorrelation = runWithCorrelation;
1148
817
  exports.sanitizeArgs = sanitizeArgs;
1149
818
  exports.sanitizeRequestParams = sanitizeRequestParams;
1150
819
  exports.scrubSecretsInText = scrubSecretsInText;
1151
- exports.setActor = setActor;
@@ -1,5 +1,5 @@
1
- import { getCurrentActor, current } from './chunk-CE3R7DVB.js';
2
- import { logger } from './chunk-C5OSM557.js';
1
+ import { makeAsyncContextCapture, getCurrentActor, current } from './chunk-GI6BM4MR.js';
2
+ import { logger } from './chunk-FCFVIRQF.js';
3
3
 
4
4
  // src/triggers/patch-pg.ts
5
5
  var txState = /* @__PURE__ */ new WeakMap();
@@ -8,6 +8,7 @@ function patchPgClient(pgModule) {
8
8
  logger.debug("patchPgClient: not a recognized pg module shape, skipping");
9
9
  return;
10
10
  }
11
+ patchPgPool(pgModule.Pool);
11
12
  const proto = pgModule.Client.prototype;
12
13
  if (proto._ezlogsPatched) return;
13
14
  const originalQuery = proto.query;
@@ -22,8 +23,44 @@ function patchPgClient(pgModule) {
22
23
  };
23
24
  proto._ezlogsPatched = true;
24
25
  }
26
+ function patchPgPool(Pool) {
27
+ const proto = Pool?.prototype;
28
+ if (!proto || typeof proto.connect !== "function" || proto._ezlogsPoolPatched) return;
29
+ const captureAndRun = makeAsyncContextCapture();
30
+ if (!captureAndRun) return;
31
+ const originalConnect = proto.connect;
32
+ proto.connect = function patchedConnect(...args) {
33
+ const cb = args[0];
34
+ if (typeof cb === "function") {
35
+ try {
36
+ const run = captureAndRun();
37
+ args[0] = (...cbArgs) => run(() => cb(...cbArgs));
38
+ } catch {
39
+ }
40
+ }
41
+ return originalConnect.apply(this, args);
42
+ };
43
+ proto._ezlogsPoolPatched = true;
44
+ }
25
45
  function runPatchedQuery(client, original, config, values, callback) {
26
46
  const state = ensureState(client);
47
+ if (state.busy) {
48
+ const queued = state.busy.then(
49
+ () => runPatchedQuery(client, original, config, values, callback)
50
+ );
51
+ if (isSubmittable(config)) {
52
+ queued.catch(() => {
53
+ });
54
+ return config;
55
+ }
56
+ const cb = typeof callback === "function" ? callback : typeof values === "function" ? values : null;
57
+ if (cb) {
58
+ queued.catch((err) => cb(err));
59
+ return void 0;
60
+ }
61
+ return queued;
62
+ }
63
+ if (isSubmittable(config)) return original.call(client, config, values, callback);
27
64
  const text = extractQueryText(config);
28
65
  const verb = leadingVerb(text);
29
66
  if (verb === "BEGIN" || verb === "START") {
@@ -141,6 +178,16 @@ function wrapInTx(client, original, config, values, callback, ctx) {
141
178
  throw err;
142
179
  }
143
180
  );
181
+ const done = wrapped.then(
182
+ () => {
183
+ },
184
+ () => {
185
+ }
186
+ );
187
+ state.busy = done;
188
+ void done.then(() => {
189
+ if (state.busy === done) state.busy = null;
190
+ });
144
191
  if (userCb) {
145
192
  wrapped.then(
146
193
  (result) => userCb(null, result),
@@ -153,11 +200,14 @@ function wrapInTx(client, original, config, values, callback, ctx) {
153
200
  function ensureState(client) {
154
201
  let s = txState.get(client);
155
202
  if (!s) {
156
- s = { inTx: false, injected: false };
203
+ s = { inTx: false, injected: false, busy: null };
157
204
  txState.set(client, s);
158
205
  }
159
206
  return s;
160
207
  }
208
+ function isSubmittable(config) {
209
+ return typeof config === "object" && config !== null && typeof config.submit === "function";
210
+ }
161
211
  function extractQueryText(config) {
162
212
  if (typeof config === "string") return config;
163
213
  if (config && typeof config === "object" && typeof config.text === "string") {