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