ezlogs-nextjs 0.3.0 → 0.3.1
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 +15 -2
- package/bin/install-triggers.cjs +33 -5
- package/dist/actors/index.cjs +5 -37
- package/dist/actors/index.js +2 -34
- package/dist/chunk-C5OSM557.js +39 -0
- package/dist/chunk-CE3R7DVB.js +1127 -0
- package/dist/chunk-CU45I2WR.js +498 -0
- package/dist/chunk-DKRNNI4I.js +180 -0
- package/dist/chunk-SIAA4J6H.js +17 -0
- package/dist/chunk-UQHEW6ER.js +119 -0
- package/dist/chunk-UWHYJH4M.cjs +126 -0
- package/dist/chunk-V5YNKKTG.cjs +42 -0
- package/dist/chunk-WASXTDLW.cjs +1151 -0
- package/dist/chunk-Y5NSHKWQ.cjs +182 -0
- package/dist/chunk-YX2XPLOA.cjs +508 -0
- package/dist/chunk-ZDSQYCYV.cjs +21 -0
- package/dist/db/drizzle.cjs +6 -821
- package/dist/db/drizzle.js +5 -820
- package/dist/db/prisma.cjs +28 -853
- package/dist/db/prisma.js +14 -839
- package/dist/db/supabase.cjs +21 -836
- package/dist/db/supabase.js +14 -829
- package/dist/index.cjs +132 -2362
- package/dist/index.js +34 -2270
- package/dist/jobs/bullmq.cjs +13 -1465
- package/dist/jobs/bullmq.js +7 -1459
- package/dist/jobs/inngest.cjs +14 -1422
- package/dist/jobs/inngest.js +8 -1416
- package/dist/jobs/supabase-queues.cjs +15 -1467
- package/dist/jobs/supabase-queues.js +10 -1462
- package/dist/jobs/trigger.cjs +9 -1454
- package/dist/jobs/trigger.js +5 -1450
- package/dist/jobs/upstash-workflow.cjs +30 -1456
- package/dist/jobs/upstash-workflow.d.cts +2 -1
- package/dist/jobs/upstash-workflow.d.ts +2 -1
- package/dist/jobs/upstash-workflow.js +27 -1453
- package/dist/nextjs-plugin/index.cjs +1 -1
- package/dist/nextjs-plugin/index.js +1 -1
- package/dist/nextjs-plugin/loader.cjs +21 -25
- package/dist/nextjs-plugin/loader.js +1 -5
- package/dist/triggers/index.cjs +40 -1434
- package/dist/triggers/index.js +6 -1421
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,1596 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
-
});
|
|
11
|
-
var __esm = (fn, res) => function __init() {
|
|
12
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
-
};
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all)
|
|
16
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// src/configuration.ts
|
|
20
|
-
function configuration() {
|
|
21
|
-
const g = globalThis;
|
|
22
|
-
if (!g[GLOBAL_CONFIG_KEY]) {
|
|
23
|
-
g[GLOBAL_CONFIG_KEY] = new Configuration();
|
|
24
|
-
}
|
|
25
|
-
return g[GLOBAL_CONFIG_KEY];
|
|
26
|
-
}
|
|
27
|
-
var DEFAULT_EXCLUDED_PATHS, DEFAULT_EXCLUDED_EXTENSIONS, DEFAULT_EXCLUDED_TABLES, DEFAULT_EXCLUDED_JOB_CLASSES, DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, Configuration, GLOBAL_CONFIG_KEY;
|
|
28
|
-
var init_configuration = __esm({
|
|
29
|
-
"src/configuration.ts"() {
|
|
30
|
-
DEFAULT_EXCLUDED_PATHS = Object.freeze([
|
|
31
|
-
// Next.js / Vercel infrastructure noise
|
|
32
|
-
"/_next/*",
|
|
33
|
-
"/_vercel/*",
|
|
34
|
-
"/__nextjs_*",
|
|
35
|
-
// NextAuth.js / Auth.js — skip session-refresh polls and CSRF/provider
|
|
36
|
-
// metadata GETs (high-frequency, no business meaning), but CAPTURE
|
|
37
|
-
// POSTs (callbacks, signin, signout, register). The POSTs are the
|
|
38
|
-
// actual auth events users care about; the GETs are pure plumbing.
|
|
39
|
-
Object.freeze({ path: "/api/auth/*", methods: ["GET", "HEAD"] }),
|
|
40
|
-
// Generic infrastructure
|
|
41
|
-
"/health*",
|
|
42
|
-
"/api/health",
|
|
43
|
-
"/up",
|
|
44
|
-
"/alive",
|
|
45
|
-
"/ready",
|
|
46
|
-
"/metrics",
|
|
47
|
-
"/favicon.ico",
|
|
48
|
-
"/.well-known*",
|
|
49
|
-
"/robots.txt",
|
|
50
|
-
"/sitemap.xml",
|
|
51
|
-
"/*.hot-update.*",
|
|
52
|
-
// Auth routes (common patterns across Clerk, NextAuth, custom auth)
|
|
53
|
-
"*/login*",
|
|
54
|
-
"*/logout*",
|
|
55
|
-
"*/sign-in*",
|
|
56
|
-
"*/sign-out*",
|
|
57
|
-
"*/signin*",
|
|
58
|
-
"*/signout*",
|
|
59
|
-
"/session*"
|
|
60
|
-
]);
|
|
61
|
-
DEFAULT_EXCLUDED_EXTENSIONS = Object.freeze([
|
|
62
|
-
".js",
|
|
63
|
-
".css",
|
|
64
|
-
".map",
|
|
65
|
-
".png",
|
|
66
|
-
".jpg",
|
|
67
|
-
".jpeg",
|
|
68
|
-
".gif",
|
|
69
|
-
".svg",
|
|
70
|
-
".ico",
|
|
71
|
-
".webp",
|
|
72
|
-
".woff",
|
|
73
|
-
".woff2",
|
|
74
|
-
".ttf",
|
|
75
|
-
".eot",
|
|
76
|
-
".otf"
|
|
77
|
-
]);
|
|
78
|
-
DEFAULT_EXCLUDED_TABLES = Object.freeze([
|
|
79
|
-
// Prisma migration ledger
|
|
80
|
-
"_prisma_migrations",
|
|
81
|
-
// Auth.js / NextAuth Prisma adapter — session/verification-token churn
|
|
82
|
-
// is auth machinery, not business activity. Account/User stay captured.
|
|
83
|
-
"Session",
|
|
84
|
-
"VerificationToken",
|
|
85
|
-
// Common cross-stack convention names for the same things
|
|
86
|
-
"sessions",
|
|
87
|
-
"session",
|
|
88
|
-
"verification_tokens"
|
|
89
|
-
]);
|
|
90
|
-
DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
|
|
91
|
-
DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
|
|
92
|
-
Configuration = class {
|
|
93
|
-
serverUrl = null;
|
|
94
|
-
projectToken = null;
|
|
95
|
-
captureHttp = true;
|
|
96
|
-
captureDb = true;
|
|
97
|
-
captureJobs = true;
|
|
98
|
-
bufferSize = 1e4;
|
|
99
|
-
/** Default 3000 ms — equivalent to Ruby's 3 seconds. */
|
|
100
|
-
sendInterval = 3e3;
|
|
101
|
-
retryAttempts = 3;
|
|
102
|
-
logLevel = "warn";
|
|
103
|
-
patchGlobalFetch = true;
|
|
104
|
-
actorFromSupabase = true;
|
|
105
|
-
allowInsecureTransport = false;
|
|
106
|
-
excludedPaths = [];
|
|
107
|
-
excludedTables = [];
|
|
108
|
-
excludedJobClasses = [];
|
|
109
|
-
excludedGraphqlOperations = [];
|
|
110
|
-
excludedGraphqlVariableKeys = [];
|
|
111
|
-
actorFromRequest = null;
|
|
112
|
-
displayNameFor = {};
|
|
113
|
-
isServerActionError = null;
|
|
114
|
-
databaseReader = null;
|
|
115
|
-
databaseUrl = null;
|
|
116
|
-
/**
|
|
117
|
-
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
118
|
-
* at agent startup by reading `information_schema.triggers`. The
|
|
119
|
-
* supabase / drizzle / prisma adapters use this to decide whether
|
|
120
|
-
* their per-mutation emit is redundant: if the table is trigger-
|
|
121
|
-
* tracked the audit-log reader will surface the same write with full
|
|
122
|
-
* old/new state, so the adapter's emit is suppressed. Tables NOT in
|
|
123
|
-
* this set fall through to the adapter so they're still captured.
|
|
124
|
-
*
|
|
125
|
-
* `null` means "detection hasn't run yet or failed" — in that state
|
|
126
|
-
* `databaseReader`-wired apps suppress every adapter emit (the
|
|
127
|
-
* original Phase 5 behavior). After detection completes the agent
|
|
128
|
-
* gives the more accurate per-table answer.
|
|
129
|
-
*/
|
|
130
|
-
triggerTrackedTables = null;
|
|
131
|
-
apply(options) {
|
|
132
|
-
this.serverUrl = options.serverUrl;
|
|
133
|
-
this.projectToken = options.projectToken;
|
|
134
|
-
if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
|
|
135
|
-
if (options.captureDb !== void 0) this.captureDb = options.captureDb;
|
|
136
|
-
if (options.captureJobs !== void 0) this.captureJobs = options.captureJobs;
|
|
137
|
-
if (options.bufferSize !== void 0) this.bufferSize = options.bufferSize;
|
|
138
|
-
if (options.sendInterval !== void 0) this.sendInterval = options.sendInterval;
|
|
139
|
-
if (options.retryAttempts !== void 0) this.retryAttempts = options.retryAttempts;
|
|
140
|
-
if (options.excludedPaths) this.excludedPaths = [...options.excludedPaths];
|
|
141
|
-
if (options.excludedTables) this.excludedTables = [...options.excludedTables];
|
|
142
|
-
if (options.excludedJobClasses) {
|
|
143
|
-
this.excludedJobClasses = [...options.excludedJobClasses];
|
|
144
|
-
}
|
|
145
|
-
if (options.excludedGraphqlOperations) {
|
|
146
|
-
this.excludedGraphqlOperations = [...options.excludedGraphqlOperations];
|
|
147
|
-
}
|
|
148
|
-
if (options.excludedGraphqlVariableKeys) {
|
|
149
|
-
this.excludedGraphqlVariableKeys = [...options.excludedGraphqlVariableKeys];
|
|
150
|
-
}
|
|
151
|
-
if (options.actorFromRequest) this.actorFromRequest = options.actorFromRequest;
|
|
152
|
-
if (options.displayNameFor) this.displayNameFor = { ...options.displayNameFor };
|
|
153
|
-
if (options.isServerActionError) this.isServerActionError = options.isServerActionError;
|
|
154
|
-
if (options.patchGlobalFetch !== void 0) {
|
|
155
|
-
this.patchGlobalFetch = options.patchGlobalFetch;
|
|
156
|
-
}
|
|
157
|
-
if (options.allowInsecureTransport !== void 0) {
|
|
158
|
-
this.allowInsecureTransport = options.allowInsecureTransport;
|
|
159
|
-
}
|
|
160
|
-
if (options.actorFromSupabase !== void 0) {
|
|
161
|
-
this.actorFromSupabase = options.actorFromSupabase;
|
|
162
|
-
}
|
|
163
|
-
if (options.databaseReader !== void 0) {
|
|
164
|
-
this.databaseReader = options.databaseReader;
|
|
165
|
-
}
|
|
166
|
-
if (options.databaseUrl !== void 0) {
|
|
167
|
-
this.databaseUrl = options.databaseUrl;
|
|
168
|
-
}
|
|
169
|
-
if (options.logLevel) this.logLevel = options.logLevel;
|
|
170
|
-
}
|
|
171
|
-
allExcludedPaths() {
|
|
172
|
-
return [...DEFAULT_EXCLUDED_PATHS, ...this.excludedPaths];
|
|
173
|
-
}
|
|
174
|
-
allExcludedTables() {
|
|
175
|
-
return [...DEFAULT_EXCLUDED_TABLES, ...this.excludedTables];
|
|
176
|
-
}
|
|
177
|
-
allExcludedJobClasses() {
|
|
178
|
-
return [...DEFAULT_EXCLUDED_JOB_CLASSES, ...this.excludedJobClasses];
|
|
179
|
-
}
|
|
180
|
-
allExcludedGraphqlOperations() {
|
|
181
|
-
return [...DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, ...this.excludedGraphqlOperations];
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
GLOBAL_CONFIG_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:configuration");
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// src/logger.ts
|
|
189
|
-
function readLevel() {
|
|
190
|
-
const g = globalThis;
|
|
191
|
-
return g[LEVEL_KEY] ?? "warn";
|
|
192
|
-
}
|
|
193
|
-
function setLogLevel(level) {
|
|
194
|
-
globalThis[LEVEL_KEY] = level;
|
|
195
|
-
}
|
|
196
|
-
function shouldLog(level) {
|
|
197
|
-
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
198
|
-
}
|
|
199
|
-
function safeWrite(level, message) {
|
|
200
|
-
try {
|
|
201
|
-
if (!shouldLog(level)) return;
|
|
202
|
-
const line = `[ezlogs] ${message}`;
|
|
203
|
-
if (level === "error" || level === "warn") {
|
|
204
|
-
console.error(line);
|
|
205
|
-
} else {
|
|
206
|
-
console.log(line);
|
|
207
|
-
}
|
|
208
|
-
} catch {
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
var LEVEL_RANK, LEVEL_KEY, logger;
|
|
212
|
-
var init_logger = __esm({
|
|
213
|
-
"src/logger.ts"() {
|
|
214
|
-
LEVEL_RANK = {
|
|
215
|
-
debug: 10,
|
|
216
|
-
info: 20,
|
|
217
|
-
warn: 30,
|
|
218
|
-
error: 40,
|
|
219
|
-
silent: 100
|
|
220
|
-
};
|
|
221
|
-
LEVEL_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:log-level");
|
|
222
|
-
logger = {
|
|
223
|
-
debug: (message) => safeWrite("debug", message),
|
|
224
|
-
info: (message) => safeWrite("info", message),
|
|
225
|
-
warn: (message) => safeWrite("warn", message),
|
|
226
|
-
error: (message) => safeWrite("error", message)
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// src/pipeline/buffer.ts
|
|
232
|
-
var buffer_exports = {};
|
|
233
|
-
__export(buffer_exports, {
|
|
234
|
-
bufferSize: () => bufferSize,
|
|
235
|
-
clearBuffer: () => clearBuffer,
|
|
236
|
-
drainEvents: () => drainEvents,
|
|
237
|
-
pushEvent: () => pushEvent
|
|
238
|
-
});
|
|
239
|
-
function getQueue() {
|
|
240
|
-
const g = globalThis;
|
|
241
|
-
if (!g[GLOBAL_QUEUE_KEY]) g[GLOBAL_QUEUE_KEY] = [];
|
|
242
|
-
return g[GLOBAL_QUEUE_KEY];
|
|
243
|
-
}
|
|
244
|
-
function pushEvent(event) {
|
|
245
|
-
try {
|
|
246
|
-
const queue = getQueue();
|
|
247
|
-
const max = maxSize();
|
|
248
|
-
if (queue.length >= max) {
|
|
249
|
-
queue.shift();
|
|
250
|
-
logger.warn(`Buffer full (${max}), dropped oldest event`);
|
|
251
|
-
}
|
|
252
|
-
queue.push(event);
|
|
253
|
-
} catch (error) {
|
|
254
|
-
logger.error(`pushEvent failed: ${describe(error)}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function drainEvents() {
|
|
258
|
-
try {
|
|
259
|
-
const queue = getQueue();
|
|
260
|
-
if (queue.length === 0) return [];
|
|
261
|
-
return queue.splice(0, queue.length);
|
|
262
|
-
} catch (error) {
|
|
263
|
-
logger.error(`drainEvents failed: ${describe(error)}`);
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function bufferSize() {
|
|
268
|
-
return getQueue().length;
|
|
269
|
-
}
|
|
270
|
-
function clearBuffer() {
|
|
271
|
-
const queue = getQueue();
|
|
272
|
-
queue.length = 0;
|
|
273
|
-
}
|
|
274
|
-
function maxSize() {
|
|
275
|
-
try {
|
|
276
|
-
return configuration().bufferSize;
|
|
277
|
-
} catch {
|
|
278
|
-
return 1e4;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
function describe(error) {
|
|
282
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
283
|
-
return String(error);
|
|
284
|
-
}
|
|
285
|
-
var GLOBAL_QUEUE_KEY;
|
|
286
|
-
var init_buffer = __esm({
|
|
287
|
-
"src/pipeline/buffer.ts"() {
|
|
288
|
-
init_configuration();
|
|
289
|
-
init_logger();
|
|
290
|
-
GLOBAL_QUEUE_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:buffer-queue");
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// src/edge-fallback.ts
|
|
295
|
-
function loadAsyncLocalStorage() {
|
|
296
|
-
const fromGlobal = globalThis.AsyncLocalStorage;
|
|
297
|
-
if (typeof fromGlobal === "function") return fromGlobal;
|
|
298
|
-
try {
|
|
299
|
-
const req = typeof __require !== "undefined" ? __require : (
|
|
300
|
-
// In ESM, `createRequire` is the official escape hatch.
|
|
301
|
-
// We pull it via globalThis to avoid a static `import`
|
|
302
|
-
// that would itself be browser-bundled.
|
|
303
|
-
void 0
|
|
304
|
-
);
|
|
305
|
-
if (typeof req === "function") {
|
|
306
|
-
const moduleName = ["async", "hooks"].join("_");
|
|
307
|
-
const mod = req("node:" + moduleName);
|
|
308
|
-
if (typeof mod.AsyncLocalStorage === "function") return mod.AsyncLocalStorage;
|
|
309
|
-
}
|
|
310
|
-
} catch {
|
|
311
|
-
}
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
function createScopedStorage(key = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:default-scoped-storage")) {
|
|
315
|
-
const globalStore = globalThis;
|
|
316
|
-
let entry = globalStore[key];
|
|
317
|
-
if (!entry) {
|
|
318
|
-
const als2 = (() => {
|
|
319
|
-
if (!ALS_CTOR) return null;
|
|
320
|
-
try {
|
|
321
|
-
return new ALS_CTOR();
|
|
322
|
-
} catch {
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
})();
|
|
326
|
-
entry = { als: als2, edgeFallback: null };
|
|
327
|
-
globalStore[key] = entry;
|
|
328
|
-
}
|
|
329
|
-
const als = entry.als;
|
|
330
|
-
const stateRef = entry;
|
|
331
|
-
return {
|
|
332
|
-
read() {
|
|
333
|
-
if (als) return als.getStore()?.value ?? null;
|
|
334
|
-
return stateRef.edgeFallback?.value ?? null;
|
|
335
|
-
},
|
|
336
|
-
run(value, callback) {
|
|
337
|
-
if (als) return als.run({ value }, callback);
|
|
338
|
-
const previous = stateRef.edgeFallback;
|
|
339
|
-
stateRef.edgeFallback = { value };
|
|
340
|
-
try {
|
|
341
|
-
return callback();
|
|
342
|
-
} finally {
|
|
343
|
-
stateRef.edgeFallback = previous;
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
update(value) {
|
|
347
|
-
if (als) {
|
|
348
|
-
const store = als.getStore();
|
|
349
|
-
if (store) store.value = value;
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
stateRef.edgeFallback = { value };
|
|
353
|
-
},
|
|
354
|
-
_resetForTests() {
|
|
355
|
-
stateRef.edgeFallback = null;
|
|
356
|
-
},
|
|
357
|
-
_isAsyncLocalStorage() {
|
|
358
|
-
return als !== null;
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
var ALS_CTOR;
|
|
363
|
-
var init_edge_fallback = __esm({
|
|
364
|
-
"src/edge-fallback.ts"() {
|
|
365
|
-
ALS_CTOR = loadAsyncLocalStorage();
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
// src/correlation.ts
|
|
370
|
-
function generate() {
|
|
371
|
-
const ts = Date.now();
|
|
372
|
-
const hex = randomHexBytes(4);
|
|
373
|
-
return `ezl_${ts}_${hex}`;
|
|
374
|
-
}
|
|
375
|
-
function randomHexBytes(byteCount) {
|
|
376
|
-
const buf = new Uint8Array(byteCount);
|
|
377
|
-
globalThis.crypto.getRandomValues(buf);
|
|
378
|
-
let out = "";
|
|
379
|
-
for (let i = 0; i < buf.length; i++) {
|
|
380
|
-
out += buf[i].toString(16).padStart(2, "0");
|
|
381
|
-
}
|
|
382
|
-
return out;
|
|
383
|
-
}
|
|
384
|
-
function resolveCorrelation(headers) {
|
|
385
|
-
if (!headers) return generate();
|
|
386
|
-
const ezlogs2 = safeRead(headers, CORRELATION_HEADER);
|
|
387
|
-
if (ezlogs2 && isTrustedInboundId(ezlogs2)) return ezlogs2;
|
|
388
|
-
for (const name of PLATFORM_REQUEST_ID_HEADERS) {
|
|
389
|
-
const platformId = safeRead(headers, name);
|
|
390
|
-
if (platformId) return wrapPlatformId(platformId);
|
|
391
|
-
}
|
|
392
|
-
return generate();
|
|
393
|
-
}
|
|
394
|
-
function isTrustedInboundId(id) {
|
|
395
|
-
const match = INBOUND_ID.exec(id);
|
|
396
|
-
if (!match) return false;
|
|
397
|
-
const age = Date.now() - Number(match[1]);
|
|
398
|
-
return age <= INBOUND_MAX_AGE_MS && age >= -INBOUND_MAX_SKEW_MS;
|
|
399
|
-
}
|
|
400
|
-
function safeRead(headers, name) {
|
|
401
|
-
try {
|
|
402
|
-
const value = headers.get(name);
|
|
403
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
404
|
-
} catch {
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function wrapPlatformId(platformId) {
|
|
409
|
-
const ts = Date.now();
|
|
410
|
-
const hex = fnv1aHex(platformId);
|
|
411
|
-
return `ezl_${ts}_${hex}`;
|
|
412
|
-
}
|
|
413
|
-
function fnv1aHex(input) {
|
|
414
|
-
let hash = 2166136261;
|
|
415
|
-
for (let i = 0; i < input.length; i++) {
|
|
416
|
-
hash ^= input.charCodeAt(i);
|
|
417
|
-
hash = Math.imul(hash, 16777619);
|
|
418
|
-
}
|
|
419
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
420
|
-
}
|
|
421
|
-
function current() {
|
|
422
|
-
return storage.read();
|
|
423
|
-
}
|
|
424
|
-
function runWithCorrelation(correlationId, callback) {
|
|
425
|
-
return storage.run(correlationId, callback);
|
|
426
|
-
}
|
|
427
|
-
var CORRELATION_HEADER, PLATFORM_REQUEST_ID_HEADERS, storage, INBOUND_ID, INBOUND_MAX_AGE_MS, INBOUND_MAX_SKEW_MS;
|
|
428
|
-
var init_correlation = __esm({
|
|
429
|
-
"src/correlation.ts"() {
|
|
430
|
-
init_edge_fallback();
|
|
431
|
-
CORRELATION_HEADER = "x-ezlogs-correlation-id";
|
|
432
|
-
PLATFORM_REQUEST_ID_HEADERS = [
|
|
433
|
-
"x-vercel-id",
|
|
434
|
-
"cf-ray",
|
|
435
|
-
"x-request-id"
|
|
436
|
-
];
|
|
437
|
-
storage = createScopedStorage(
|
|
438
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
|
|
439
|
-
);
|
|
440
|
-
INBOUND_ID = /^ezl_(\d{13})_[0-9a-f]{8}$/;
|
|
441
|
-
INBOUND_MAX_AGE_MS = 60 * 6e4;
|
|
442
|
-
INBOUND_MAX_SKEW_MS = 5 * 6e4;
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
// src/actor.ts
|
|
447
|
-
function getCurrentActor() {
|
|
448
|
-
return storage2.read();
|
|
449
|
-
}
|
|
450
|
-
function setActor(input) {
|
|
451
|
-
const sanitized = validateActor(input);
|
|
452
|
-
if (input != null && sanitized === null) {
|
|
453
|
-
logger.debug(`Actor: invalid actor structure ignored: ${describe2(input)}`);
|
|
454
|
-
}
|
|
455
|
-
storage2.update(sanitized);
|
|
456
|
-
return sanitized;
|
|
457
|
-
}
|
|
458
|
-
function runWithActorScope(callback) {
|
|
459
|
-
return storage2.run(null, callback);
|
|
460
|
-
}
|
|
461
|
-
function validateActor(input) {
|
|
462
|
-
if (input === null || input === void 0) return null;
|
|
463
|
-
if (typeof input !== "object") return null;
|
|
464
|
-
if (Array.isArray(input)) return null;
|
|
465
|
-
const obj = input;
|
|
466
|
-
const rawId = obj.id;
|
|
467
|
-
if (rawId === null || rawId === void 0) return null;
|
|
468
|
-
const id = String(rawId);
|
|
469
|
-
if (id === "") return null;
|
|
470
|
-
const result = { id };
|
|
471
|
-
if (obj.label !== void 0 && obj.label !== null) {
|
|
472
|
-
result.label = String(obj.label);
|
|
473
|
-
}
|
|
474
|
-
if (obj.kind !== void 0 && obj.kind !== null) {
|
|
475
|
-
const kind = String(obj.kind);
|
|
476
|
-
if (VALID_KINDS.has(kind)) {
|
|
477
|
-
result.kind = kind;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
const principal = sanitizePrincipal(obj.principal);
|
|
481
|
-
if (principal) result.principal = principal;
|
|
482
|
-
return result;
|
|
483
|
-
}
|
|
484
|
-
function sanitizePrincipal(input) {
|
|
485
|
-
if (input === null || input === void 0) return null;
|
|
486
|
-
if (typeof input !== "object") return null;
|
|
487
|
-
if (Array.isArray(input)) return null;
|
|
488
|
-
const obj = input;
|
|
489
|
-
const rawId = obj.id;
|
|
490
|
-
if (rawId === null || rawId === void 0) return null;
|
|
491
|
-
const id = String(rawId);
|
|
492
|
-
if (id === "") return null;
|
|
493
|
-
const result = { id };
|
|
494
|
-
if (obj.label !== void 0 && obj.label !== null) {
|
|
495
|
-
result.label = String(obj.label);
|
|
496
|
-
}
|
|
497
|
-
return result;
|
|
498
|
-
}
|
|
499
|
-
function describe2(value) {
|
|
500
|
-
try {
|
|
501
|
-
return JSON.stringify(value);
|
|
502
|
-
} catch {
|
|
503
|
-
return Object.prototype.toString.call(value);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
var storage2, VALID_KINDS;
|
|
507
|
-
var init_actor = __esm({
|
|
508
|
-
"src/actor.ts"() {
|
|
509
|
-
init_logger();
|
|
510
|
-
init_edge_fallback();
|
|
511
|
-
storage2 = createScopedStorage(
|
|
512
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:actor-storage")
|
|
513
|
-
);
|
|
514
|
-
VALID_KINDS = /* @__PURE__ */ new Set(["human", "agent", "system", "hybrid"]);
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
// src/event-builder.ts
|
|
519
|
-
function build(input) {
|
|
520
|
-
const source_type = validateSourceType(input.source_type);
|
|
521
|
-
const source_data_raw = validateSourceData(input.source_data);
|
|
522
|
-
const outcome = validateOutcome(input.outcome);
|
|
523
|
-
const timestamp = validateTimestamp(input.timestamp ?? null);
|
|
524
|
-
const resource_ids = validateResourceIds(input.resource_ids ?? []);
|
|
525
|
-
const context_raw = validateContext(input.context ?? null);
|
|
526
|
-
const duration_ms = validateDurationMs(input.duration_ms ?? null);
|
|
527
|
-
const error_message = input.error_message ?? null;
|
|
528
|
-
validateOutcomeErrorConsistency(outcome, error_message);
|
|
529
|
-
const source_data = sanitizeRecord(source_data_raw);
|
|
530
|
-
const context = context_raw === null ? null : sanitizeRecord(context_raw);
|
|
531
|
-
const correlation_id = input.correlation_id ?? null;
|
|
532
|
-
const event = {
|
|
533
|
-
timestamp,
|
|
534
|
-
source_type,
|
|
535
|
-
source_data,
|
|
536
|
-
outcome,
|
|
537
|
-
correlation_id,
|
|
538
|
-
resource_ids,
|
|
539
|
-
context,
|
|
540
|
-
duration_ms,
|
|
541
|
-
error_message
|
|
542
|
-
};
|
|
543
|
-
return event;
|
|
544
|
-
}
|
|
545
|
-
function validateSourceType(value) {
|
|
546
|
-
if (value === null || value === void 0) {
|
|
547
|
-
throw new exports.ArgError("source_type is required");
|
|
548
|
-
}
|
|
549
|
-
const normalized = String(value);
|
|
550
|
-
if (!VALID_SOURCE_TYPES.includes(normalized)) {
|
|
551
|
-
throw new exports.ArgError(
|
|
552
|
-
`source_type must be one of ${VALID_SOURCE_TYPES.join(", ")}, got: ${normalized}`
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
return normalized;
|
|
556
|
-
}
|
|
557
|
-
function validateSourceData(value) {
|
|
558
|
-
if (value === null || value === void 0) {
|
|
559
|
-
throw new exports.ArgError("source_data is required");
|
|
560
|
-
}
|
|
561
|
-
if (!isPlainObject(value)) {
|
|
562
|
-
throw new exports.ArgError(
|
|
563
|
-
`source_data must be an object, got: ${describe3(value)}`
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
return value;
|
|
567
|
-
}
|
|
568
|
-
function validateOutcome(value) {
|
|
569
|
-
if (value === null || value === void 0) {
|
|
570
|
-
throw new exports.ArgError("outcome is required");
|
|
571
|
-
}
|
|
572
|
-
const normalized = String(value);
|
|
573
|
-
if (!VALID_OUTCOMES.includes(normalized)) {
|
|
574
|
-
throw new exports.ArgError(
|
|
575
|
-
`outcome must be one of ${VALID_OUTCOMES.join(", ")}, got: ${normalized}`
|
|
576
|
-
);
|
|
577
|
-
}
|
|
578
|
-
return normalized;
|
|
579
|
-
}
|
|
580
|
-
function validateTimestamp(value) {
|
|
581
|
-
if (value === null) {
|
|
582
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
583
|
-
}
|
|
584
|
-
if (typeof value === "string") {
|
|
585
|
-
const parsed = new Date(value);
|
|
586
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
587
|
-
throw new exports.ArgError(
|
|
588
|
-
`timestamp must be valid ISO 8601 format, got: ${value}`
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
return value;
|
|
592
|
-
}
|
|
593
|
-
if (value instanceof Date) {
|
|
594
|
-
if (Number.isNaN(value.getTime())) {
|
|
595
|
-
throw new exports.ArgError("timestamp must be a valid Date");
|
|
596
|
-
}
|
|
597
|
-
return value.toISOString();
|
|
598
|
-
}
|
|
599
|
-
throw new exports.ArgError(
|
|
600
|
-
`timestamp must be a string or Date, got: ${describe3(value)}`
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
function validateResourceIds(value) {
|
|
604
|
-
if (!Array.isArray(value)) {
|
|
605
|
-
throw new exports.ArgError(`resource_ids must be an array, got: ${describe3(value)}`);
|
|
606
|
-
}
|
|
607
|
-
value.forEach((entry, index) => {
|
|
608
|
-
if (!isPlainObject(entry)) {
|
|
609
|
-
throw new exports.ArgError(
|
|
610
|
-
`resource_ids[${index}] must be an object, got: ${describe3(entry)}`
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
const e = entry;
|
|
614
|
-
if (!("resource_type" in e) || !("resource_id" in e)) {
|
|
615
|
-
throw new exports.ArgError(
|
|
616
|
-
`resource_ids[${index}] must have resource_type and resource_id keys, got: ${Object.keys(e).join(", ")}`
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
|
-
if (typeof e.resource_type !== "string") {
|
|
620
|
-
throw new exports.ArgError(
|
|
621
|
-
`resource_ids[${index}].resource_type must be a string, got: ${describe3(e.resource_type)}`
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
if (typeof e.resource_id !== "string") {
|
|
625
|
-
throw new exports.ArgError(
|
|
626
|
-
`resource_ids[${index}].resource_id must be a string, got: ${describe3(e.resource_id)}`
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
return value;
|
|
631
|
-
}
|
|
632
|
-
function validateContext(value) {
|
|
633
|
-
if (value === null) return null;
|
|
634
|
-
if (!isPlainObject(value)) {
|
|
635
|
-
throw new exports.ArgError(
|
|
636
|
-
`context must be an object or null, got: ${describe3(value)}`
|
|
637
|
-
);
|
|
638
|
-
}
|
|
639
|
-
return value;
|
|
640
|
-
}
|
|
641
|
-
function validateDurationMs(value) {
|
|
642
|
-
if (value === null || value === void 0) return null;
|
|
643
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
644
|
-
throw new exports.ArgError(`duration_ms must be a number, got: ${describe3(value)}`);
|
|
645
|
-
}
|
|
646
|
-
if (!Number.isInteger(value)) {
|
|
647
|
-
throw new exports.ArgError(`duration_ms must be an integer, got: ${value}`);
|
|
648
|
-
}
|
|
649
|
-
if (value < 0) {
|
|
650
|
-
throw new exports.ArgError(`duration_ms must be >= 0, got: ${value}`);
|
|
651
|
-
}
|
|
652
|
-
return value;
|
|
653
|
-
}
|
|
654
|
-
function validateOutcomeErrorConsistency(outcome, error_message) {
|
|
655
|
-
if (outcome === "failure") {
|
|
656
|
-
if (error_message === null || error_message === "") {
|
|
657
|
-
throw new exports.ArgError("error_message is required when outcome is 'failure'");
|
|
658
|
-
}
|
|
659
|
-
} else if (outcome === "success") {
|
|
660
|
-
if (error_message !== null) {
|
|
661
|
-
throw new exports.ArgError("error_message must be null when outcome is 'success'");
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function sanitizeRecord(input) {
|
|
666
|
-
const result = {};
|
|
667
|
-
for (const key of Object.keys(input)) {
|
|
668
|
-
const value = input[key];
|
|
669
|
-
if (isSensitiveKey(key)) {
|
|
670
|
-
result[key] = "[FILTERED]";
|
|
671
|
-
} else if (isPlainObject(value)) {
|
|
672
|
-
result[key] = sanitizeRecord(value);
|
|
673
|
-
} else if (Array.isArray(value)) {
|
|
674
|
-
result[key] = value.map(
|
|
675
|
-
(item) => isPlainObject(item) ? sanitizeRecord(item) : item
|
|
676
|
-
);
|
|
677
|
-
} else {
|
|
678
|
-
result[key] = value;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
return result;
|
|
682
|
-
}
|
|
683
|
-
function isSensitiveKey(key) {
|
|
684
|
-
const lower = key.toLowerCase();
|
|
685
|
-
return SENSITIVE_KEYS.some((p) => lower.includes(p));
|
|
686
|
-
}
|
|
687
|
-
function isPlainObject(value) {
|
|
688
|
-
if (value === null || typeof value !== "object") return false;
|
|
689
|
-
const proto = Object.getPrototypeOf(value);
|
|
690
|
-
return proto === Object.prototype || proto === null;
|
|
691
|
-
}
|
|
692
|
-
function describe3(value) {
|
|
693
|
-
if (value === null) return "null";
|
|
694
|
-
if (Array.isArray(value)) return "Array";
|
|
695
|
-
return typeof value;
|
|
696
|
-
}
|
|
697
|
-
var SENSITIVE_KEYS, VALID_SOURCE_TYPES, VALID_OUTCOMES; exports.ArgError = void 0;
|
|
698
|
-
var init_event_builder = __esm({
|
|
699
|
-
"src/event-builder.ts"() {
|
|
700
|
-
SENSITIVE_KEYS = Object.freeze([
|
|
701
|
-
"password",
|
|
702
|
-
"token",
|
|
703
|
-
"secret",
|
|
704
|
-
"api_key",
|
|
705
|
-
"credit_card"
|
|
706
|
-
]);
|
|
707
|
-
VALID_SOURCE_TYPES = [
|
|
708
|
-
"http_request",
|
|
709
|
-
"background_job",
|
|
710
|
-
"database_callback"
|
|
711
|
-
];
|
|
712
|
-
VALID_OUTCOMES = ["success", "failure"];
|
|
713
|
-
exports.ArgError = class extends Error {
|
|
714
|
-
constructor(message) {
|
|
715
|
-
super(message);
|
|
716
|
-
this.name = "ArgError";
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
// src/http/sanitize.ts
|
|
723
|
-
function snakeLower(key) {
|
|
724
|
-
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
725
|
-
}
|
|
726
|
-
function matchesSensitiveKey(key, substringPatterns) {
|
|
727
|
-
const lower = key.toLowerCase();
|
|
728
|
-
const snake = snakeLower(key);
|
|
729
|
-
if (substringPatterns.some((p) => lower.includes(p) || snake.includes(p))) {
|
|
730
|
-
return true;
|
|
731
|
-
}
|
|
732
|
-
const words = snake.split(/[^a-z0-9]+/);
|
|
733
|
-
return SENSITIVE_WORD_PATTERNS.some((w) => words.includes(w));
|
|
734
|
-
}
|
|
735
|
-
function sanitizeRequestParams(params, userPatterns = []) {
|
|
736
|
-
if (params === null || params === void 0) return null;
|
|
737
|
-
if (!isPlainObject2(params)) return null;
|
|
738
|
-
const obj = params;
|
|
739
|
-
const cleaned = {};
|
|
740
|
-
for (const key of Object.keys(obj)) {
|
|
741
|
-
if (FRAMEWORK_INTERNAL_KEYS.has(key)) continue;
|
|
742
|
-
cleaned[key] = obj[key];
|
|
743
|
-
}
|
|
744
|
-
if (Object.keys(cleaned).length === 0) return null;
|
|
745
|
-
const out = {};
|
|
746
|
-
for (const key of Object.keys(cleaned)) {
|
|
747
|
-
out[key] = sanitizeValue(key, cleaned[key], 0, userPatterns);
|
|
748
|
-
}
|
|
749
|
-
return out;
|
|
750
|
-
}
|
|
751
|
-
function passesLuhn(digits) {
|
|
752
|
-
let sum = 0;
|
|
753
|
-
for (let i = 0; i < digits.length; i += 1) {
|
|
754
|
-
let d = Number(digits[digits.length - 1 - i]);
|
|
755
|
-
if (i % 2 === 1) {
|
|
756
|
-
d *= 2;
|
|
757
|
-
if (d > 9) d -= 9;
|
|
758
|
-
}
|
|
759
|
-
sum += d;
|
|
760
|
-
}
|
|
761
|
-
return sum % 10 === 0;
|
|
762
|
-
}
|
|
763
|
-
function scrubSecretsInText(text, options = {}) {
|
|
764
|
-
let out = text;
|
|
765
|
-
for (const pattern of SECRET_TEXT_PATTERNS) out = out.replace(pattern, "[FILTERED]");
|
|
766
|
-
out = out.replace(/\b(Bearer|Basic)\s+[\w.~+/=-]+/gi, "$1 [FILTERED]").replace(/\b\d(?:[ -]?\d){12,18}\b/g, (match) => {
|
|
767
|
-
const digits = match.replace(/[ -]/g, "");
|
|
768
|
-
return (digits.length === 15 || digits.length === 16) && passesLuhn(digits) ? "[FILTERED]" : match;
|
|
769
|
-
});
|
|
770
|
-
return options.emails ? out.replace(EMAIL, "[FILTERED]") : out;
|
|
771
|
-
}
|
|
772
|
-
function sanitizeValue(key, value, depth, userPatterns) {
|
|
773
|
-
if (isSensitiveKey2(key, userPatterns)) return "[FILTERED]";
|
|
774
|
-
if (isPlainObject2(value)) {
|
|
775
|
-
return sanitizeNestedObject(value, depth, userPatterns);
|
|
776
|
-
}
|
|
777
|
-
if (Array.isArray(value)) {
|
|
778
|
-
return sanitizeArrayValue(value, depth, userPatterns);
|
|
779
|
-
}
|
|
780
|
-
return value;
|
|
781
|
-
}
|
|
782
|
-
function sanitizeNestedObject(hash, depth, userPatterns) {
|
|
783
|
-
if (depth >= MAX_NESTING_DEPTH) return "[Object]";
|
|
784
|
-
if (Object.keys(hash).length === 0) return {};
|
|
785
|
-
const out = {};
|
|
786
|
-
for (const k of Object.keys(hash)) {
|
|
787
|
-
out[k] = sanitizeValue(k, hash[k], depth + 1, userPatterns);
|
|
788
|
-
}
|
|
789
|
-
return out;
|
|
790
|
-
}
|
|
791
|
-
function sanitizeArrayValue(array, depth, userPatterns) {
|
|
792
|
-
if (array.length === 0) return [];
|
|
793
|
-
const allPrimitive = array.every(isPrimitive);
|
|
794
|
-
if (allPrimitive) {
|
|
795
|
-
if (array.length <= MAX_ARRAY_DISPLAY_SIZE) return array;
|
|
796
|
-
const preview = array.slice(0, MAX_ARRAY_DISPLAY_SIZE);
|
|
797
|
-
return `${JSON.stringify(preview)}... (${array.length} total)`;
|
|
798
|
-
}
|
|
799
|
-
if (array.length <= MAX_ARRAY_DISPLAY_SIZE) {
|
|
800
|
-
return array.map((item) => sanitizeArrayItem(item, depth, userPatterns));
|
|
801
|
-
}
|
|
802
|
-
return {
|
|
803
|
-
_truncated: true,
|
|
804
|
-
_count: array.length,
|
|
805
|
-
_preview: array.slice(0, MAX_ARRAY_DISPLAY_SIZE).map((item) => sanitizeArrayItem(item, depth, userPatterns))
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
function sanitizeArrayItem(item, depth, userPatterns) {
|
|
809
|
-
if (isPrimitive(item)) return item;
|
|
810
|
-
if (isPlainObject2(item)) {
|
|
811
|
-
return sanitizeNestedObject(item, depth + 1, userPatterns);
|
|
812
|
-
}
|
|
813
|
-
if (Array.isArray(item)) return sanitizeArrayValue(item, depth + 1, userPatterns);
|
|
814
|
-
return "[Object]";
|
|
815
|
-
}
|
|
816
|
-
function isSensitiveKey2(key, userPatterns) {
|
|
817
|
-
if (matchesSensitiveKey(key, SENSITIVE_VARIABLE_PATTERNS)) return true;
|
|
818
|
-
const lower = key.toLowerCase();
|
|
819
|
-
return userPatterns.some((p) => lower.includes(p.toLowerCase()));
|
|
820
|
-
}
|
|
821
|
-
function isPrimitive(value) {
|
|
822
|
-
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
823
|
-
}
|
|
824
|
-
function isPlainObject2(value) {
|
|
825
|
-
if (value === null || typeof value !== "object") return false;
|
|
826
|
-
const proto = Object.getPrototypeOf(value);
|
|
827
|
-
return proto === Object.prototype || proto === null;
|
|
828
|
-
}
|
|
829
|
-
var SENSITIVE_VARIABLE_PATTERNS, SENSITIVE_WORD_PATTERNS, MAX_NESTING_DEPTH, MAX_ARRAY_DISPLAY_SIZE, FRAMEWORK_INTERNAL_KEYS, SECRET_TEXT_PATTERNS, EMAIL;
|
|
830
|
-
var init_sanitize = __esm({
|
|
831
|
-
"src/http/sanitize.ts"() {
|
|
832
|
-
SENSITIVE_VARIABLE_PATTERNS = Object.freeze([
|
|
833
|
-
"password",
|
|
834
|
-
"passwd",
|
|
835
|
-
"pwd",
|
|
836
|
-
"token",
|
|
837
|
-
"access_token",
|
|
838
|
-
"refresh_token",
|
|
839
|
-
"api_token",
|
|
840
|
-
"auth_token",
|
|
841
|
-
"secret",
|
|
842
|
-
"api_secret",
|
|
843
|
-
"client_secret",
|
|
844
|
-
"api_key",
|
|
845
|
-
"apikey",
|
|
846
|
-
"private_key",
|
|
847
|
-
"privatekey",
|
|
848
|
-
"public_key",
|
|
849
|
-
"signing_key",
|
|
850
|
-
"secret_key",
|
|
851
|
-
"secretkey",
|
|
852
|
-
"credential",
|
|
853
|
-
"auth",
|
|
854
|
-
"authorization",
|
|
855
|
-
"encrypted",
|
|
856
|
-
"encrypted_data",
|
|
857
|
-
"ssn",
|
|
858
|
-
"social_security",
|
|
859
|
-
"credit_card",
|
|
860
|
-
"card_number",
|
|
861
|
-
"cvv",
|
|
862
|
-
"cvc",
|
|
863
|
-
// Crypto-material patterns — aligned with DB_SENSITIVE_PATTERNS
|
|
864
|
-
// (PR #45). Request bodies can carry the same key material as DB
|
|
865
|
-
// columns (a webhook POST containing a `signature` field, an HMAC
|
|
866
|
-
// header echoed into a JSON body, a `pem`-encoded cert blob, etc).
|
|
867
|
-
"pem",
|
|
868
|
-
"cipher",
|
|
869
|
-
"nonce",
|
|
870
|
-
"salt",
|
|
871
|
-
"digest",
|
|
872
|
-
"signature",
|
|
873
|
-
"hmac",
|
|
874
|
-
// 0.2.0 additions (not yet in the Rails gem's list).
|
|
875
|
-
"passcode",
|
|
876
|
-
"cardnumber"
|
|
877
|
-
]);
|
|
878
|
-
SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
879
|
-
"pin",
|
|
880
|
-
"otp",
|
|
881
|
-
"totp",
|
|
882
|
-
"iban",
|
|
883
|
-
"mfa",
|
|
884
|
-
"passphrase"
|
|
885
|
-
]);
|
|
886
|
-
MAX_NESTING_DEPTH = 3;
|
|
887
|
-
MAX_ARRAY_DISPLAY_SIZE = 5;
|
|
888
|
-
FRAMEWORK_INTERNAL_KEYS = /* @__PURE__ */ new Set([
|
|
889
|
-
// Rails leftovers — kept for parity since users may funnel through a
|
|
890
|
-
// proxy that adds them, e.g. via a NextAuth credentials provider that
|
|
891
|
-
// forwards CSRF tokens.
|
|
892
|
-
"controller",
|
|
893
|
-
"action",
|
|
894
|
-
"format",
|
|
895
|
-
"authenticity_token",
|
|
896
|
-
"_method",
|
|
897
|
-
// Next.js / common JS conventions
|
|
898
|
-
"csrfToken",
|
|
899
|
-
"_csrf",
|
|
900
|
-
"_next"
|
|
901
|
-
]);
|
|
902
|
-
SECRET_TEXT_PATTERNS = [
|
|
903
|
-
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
|
|
904
|
-
/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g,
|
|
905
|
-
/\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]+/g,
|
|
906
|
-
/\bsk-[A-Za-z0-9_-]{16,}/g,
|
|
907
|
-
/\bgh[pousr]_[A-Za-z0-9]{20,}/g,
|
|
908
|
-
/\bxox[abposr]-[A-Za-z0-9-]+/g,
|
|
909
|
-
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g
|
|
910
|
-
];
|
|
911
|
-
EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
912
|
-
}
|
|
913
|
-
});
|
|
914
|
-
|
|
915
|
-
// src/db/shared.ts
|
|
916
|
-
function emitDbEvent(input) {
|
|
917
|
-
try {
|
|
918
|
-
const config = configuration();
|
|
919
|
-
if (!config.captureDb) return;
|
|
920
|
-
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
921
|
-
if (config.databaseReader && !input._fromTrigger) {
|
|
922
|
-
const tracked = config.triggerTrackedTables;
|
|
923
|
-
if (tracked === null || tracked.has(input.table ?? input.modelClass)) return;
|
|
924
|
-
}
|
|
925
|
-
if (input.operation === "update") {
|
|
926
|
-
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
927
|
-
if (meaningful.length === 0) return;
|
|
928
|
-
}
|
|
929
|
-
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
930
|
-
const related = resourceIdStr === null ? input.relatedResourceIds ?? [] : [];
|
|
931
|
-
const context = buildContext(
|
|
932
|
-
related.length > 0 ? { ...input, displayName: null, modelInstance: null } : input
|
|
933
|
-
);
|
|
934
|
-
const event = build({
|
|
935
|
-
source_type: "database_callback",
|
|
936
|
-
source_data: {
|
|
937
|
-
model_class: input.modelClass,
|
|
938
|
-
operation: input.operation
|
|
939
|
-
},
|
|
940
|
-
outcome: "success",
|
|
941
|
-
correlation_id: current(),
|
|
942
|
-
resource_ids: resourceIdStr === null ? [...related] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
943
|
-
context,
|
|
944
|
-
duration_ms: null,
|
|
945
|
-
timestamp: input.timestamp ?? null
|
|
946
|
-
});
|
|
947
|
-
pushEvent(event);
|
|
948
|
-
} catch (error) {
|
|
949
|
-
logger.debug(`db emit failed: ${describeError5(error)}`);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
function buildContext(input) {
|
|
953
|
-
const context = {};
|
|
954
|
-
const actor = getCurrentActor();
|
|
955
|
-
if (actor) context.actor = actor;
|
|
956
|
-
if ((input.operation === "create" || input.operation === "destroy") && input.initialAttributes) {
|
|
957
|
-
const filtered = filterMeaningfulAttributes(input.initialAttributes);
|
|
958
|
-
if (filtered !== null) context.initial_attributes = filtered;
|
|
959
|
-
}
|
|
960
|
-
if (input.operation === "update" && input.changes) {
|
|
961
|
-
const filtered = filterMeaningfulChanges(input.changes);
|
|
962
|
-
if (filtered.length > 0) {
|
|
963
|
-
context.changes = filtered.map((c) => {
|
|
964
|
-
const out = {
|
|
965
|
-
attribute: c.attribute,
|
|
966
|
-
to: formatForJson(c.to)
|
|
967
|
-
};
|
|
968
|
-
if (c.from !== void 0) out.from = formatForJson(c.from);
|
|
969
|
-
return out;
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
const displayName = input.displayName ?? (input.modelInstance ? resolveDisplayName(input.modelClass, input.modelInstance) : null);
|
|
974
|
-
if (displayName !== null) context.display_name = displayName;
|
|
975
|
-
return Object.keys(context).length === 0 ? null : context;
|
|
976
|
-
}
|
|
977
|
-
function filterMeaningfulAttributes(attrs) {
|
|
978
|
-
const out = {};
|
|
979
|
-
for (const key of Object.keys(attrs)) {
|
|
980
|
-
if (!isMeaningfulAttribute(key)) continue;
|
|
981
|
-
const value = attrs[key];
|
|
982
|
-
if (value === null || value === void 0) continue;
|
|
983
|
-
if (!isScalar(value)) continue;
|
|
984
|
-
out[key] = formatForJson(value);
|
|
985
|
-
}
|
|
986
|
-
return Object.keys(out).length === 0 ? null : out;
|
|
987
|
-
}
|
|
988
|
-
function filterMeaningfulChanges(changes) {
|
|
989
|
-
return flattenNestedChanges(changes).filter((c) => {
|
|
990
|
-
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
991
|
-
if (!isScalar(c.to)) return false;
|
|
992
|
-
if (c.from === void 0) return true;
|
|
993
|
-
if (!isScalar(c.from)) return false;
|
|
994
|
-
return valuesActuallyChanged(c.from, c.to);
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
function flattenNestedChanges(changes) {
|
|
998
|
-
if (!changes.some((c) => isPlainRecord(c.to) || isPlainRecord(c.from))) return changes;
|
|
999
|
-
const out = [];
|
|
1000
|
-
for (const c of changes) {
|
|
1001
|
-
if (!isPlainRecord(c.to) && !isPlainRecord(c.from)) {
|
|
1002
|
-
out.push(c);
|
|
1003
|
-
continue;
|
|
1004
|
-
}
|
|
1005
|
-
if (!isMeaningfulAttribute(c.attribute)) continue;
|
|
1006
|
-
const leaves = [];
|
|
1007
|
-
collectLeafChanges(c.attribute, c.from, c.to, 1, leaves);
|
|
1008
|
-
const cap = c.from === void 0 ? MAX_UNKNOWN_FROM_LEAVES : MAX_NESTED_LEAVES;
|
|
1009
|
-
out.push(...leaves.slice(0, cap).map(scrubLeaf));
|
|
1010
|
-
}
|
|
1011
|
-
return out;
|
|
1012
|
-
}
|
|
1013
|
-
function collectLeafChanges(path, from, to, depth, out) {
|
|
1014
|
-
if (out.length > MAX_NESTED_LEAVES) return;
|
|
1015
|
-
const fromObj = isPlainRecord(from);
|
|
1016
|
-
const toObj = isPlainRecord(to);
|
|
1017
|
-
if ((fromObj || toObj) && depth <= MAX_NESTED_DEPTH && (fromObj || from == null) && (toObj || to == null)) {
|
|
1018
|
-
const f = fromObj ? from : {};
|
|
1019
|
-
const t = toObj ? to : {};
|
|
1020
|
-
for (const key of /* @__PURE__ */ new Set([...Object.keys(f), ...Object.keys(t)])) {
|
|
1021
|
-
const before = from === void 0 ? void 0 : f[key] ?? null;
|
|
1022
|
-
collectLeafChanges(`${path}.${key}`, before, t[key] ?? null, depth + 1, out);
|
|
1023
|
-
}
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
if (from !== void 0 && sameJson(from, to)) return;
|
|
1027
|
-
out.push(from === void 0 ? { attribute: path, to } : { attribute: path, from, to });
|
|
1028
|
-
}
|
|
1029
|
-
function scrubLeaf(change) {
|
|
1030
|
-
const scrub = (v) => typeof v === "string" ? scrubSecretsInText(v) : v;
|
|
1031
|
-
const out = { attribute: change.attribute, to: scrub(change.to) };
|
|
1032
|
-
if (change.from !== void 0) out.from = scrub(change.from);
|
|
1033
|
-
return out;
|
|
1034
|
-
}
|
|
1035
|
-
function isPlainRecord(value) {
|
|
1036
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1037
|
-
const proto = Object.getPrototypeOf(value);
|
|
1038
|
-
return proto === Object.prototype || proto === null;
|
|
1039
|
-
}
|
|
1040
|
-
function sameJson(a, b) {
|
|
1041
|
-
if (a === b) return true;
|
|
1042
|
-
try {
|
|
1043
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
1044
|
-
} catch {
|
|
1045
|
-
return false;
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
function isMeaningfulAttribute(name) {
|
|
1049
|
-
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
1050
|
-
if (isDbSensitive(name)) return false;
|
|
1051
|
-
return true;
|
|
1052
|
-
}
|
|
1053
|
-
function isDbSensitive(name) {
|
|
1054
|
-
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
1055
|
-
}
|
|
1056
|
-
function isScalar(value) {
|
|
1057
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
1058
|
-
return true;
|
|
1059
|
-
}
|
|
1060
|
-
if (isPrismaDecimal(value)) return true;
|
|
1061
|
-
if (Buffer.isBuffer?.(value)) return false;
|
|
1062
|
-
if (Array.isArray(value)) return value.every((v) => isScalar(v));
|
|
1063
|
-
return false;
|
|
1064
|
-
}
|
|
1065
|
-
function valuesActuallyChanged(from, to) {
|
|
1066
|
-
if (from === null && to === null) return false;
|
|
1067
|
-
if (from instanceof Date && to instanceof Date) {
|
|
1068
|
-
return from.getTime() !== to.getTime();
|
|
1069
|
-
}
|
|
1070
|
-
return from !== to;
|
|
1071
|
-
}
|
|
1072
|
-
function formatForJson(value) {
|
|
1073
|
-
if (value === null || value === void 0) return value;
|
|
1074
|
-
if (value instanceof Date) return value.toISOString();
|
|
1075
|
-
if (typeof value === "bigint") return value.toString();
|
|
1076
|
-
if (isPrismaDecimal(value)) return Number(value.toString());
|
|
1077
|
-
if (Array.isArray(value)) return value.map(formatForJson);
|
|
1078
|
-
return value;
|
|
1079
|
-
}
|
|
1080
|
-
function isPrismaDecimal(value) {
|
|
1081
|
-
if (value === null || typeof value !== "object") return false;
|
|
1082
|
-
const obj = value;
|
|
1083
|
-
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
1084
|
-
}
|
|
1085
|
-
function resolveDisplayName(modelClass, instance) {
|
|
1086
|
-
try {
|
|
1087
|
-
const config = configuration();
|
|
1088
|
-
const resolver = config.displayNameFor[modelClass];
|
|
1089
|
-
const resolved = applyResolver(resolver, instance);
|
|
1090
|
-
if (resolved !== null) return resolved;
|
|
1091
|
-
const columns = /* @__PURE__ */ new Map();
|
|
1092
|
-
for (const key of Object.keys(instance)) {
|
|
1093
|
-
if (isDbSensitive(key)) continue;
|
|
1094
|
-
const norm = key.toLowerCase().replace(/_/g, "");
|
|
1095
|
-
if (!columns.has(norm)) columns.set(norm, instance[key]);
|
|
1096
|
-
}
|
|
1097
|
-
const text = (norm) => {
|
|
1098
|
-
const value = columns.get(norm);
|
|
1099
|
-
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
1100
|
-
return null;
|
|
1101
|
-
}
|
|
1102
|
-
const str = String(value).trim();
|
|
1103
|
-
return str.length > 0 ? str.slice(0, MAX_DISPLAY_NAME_LENGTH) : null;
|
|
1104
|
-
};
|
|
1105
|
-
for (const column of DISPLAY_NAME_COLUMNS) {
|
|
1106
|
-
const value = text(column);
|
|
1107
|
-
if (value !== null) return value;
|
|
1108
|
-
}
|
|
1109
|
-
return text(`${singularNorm(modelClass)}number`);
|
|
1110
|
-
} catch {
|
|
1111
|
-
}
|
|
1112
|
-
return null;
|
|
1113
|
-
}
|
|
1114
|
-
function singularNorm(modelClass) {
|
|
1115
|
-
const norm = modelClass.toLowerCase().replace(/_/g, "");
|
|
1116
|
-
if (norm.endsWith("ies")) return norm.slice(0, -3) + "y";
|
|
1117
|
-
if (/(ss|us|is)$/.test(norm)) return norm;
|
|
1118
|
-
if (/(xes|ches|shes|sses)$/.test(norm)) return norm.slice(0, -2);
|
|
1119
|
-
return norm.endsWith("s") ? norm.slice(0, -1) : norm;
|
|
1120
|
-
}
|
|
1121
|
-
function applyResolver(resolver, instance) {
|
|
1122
|
-
if (typeof resolver === "string") {
|
|
1123
|
-
const value = instance[resolver];
|
|
1124
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
1125
|
-
return String(value);
|
|
1126
|
-
}
|
|
1127
|
-
return null;
|
|
1128
|
-
}
|
|
1129
|
-
if (typeof resolver === "function") {
|
|
1130
|
-
try {
|
|
1131
|
-
const value = resolver(instance);
|
|
1132
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
1133
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
1134
|
-
return String(value);
|
|
1135
|
-
}
|
|
1136
|
-
} catch {
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
return null;
|
|
1140
|
-
}
|
|
1141
|
-
function describeError5(error) {
|
|
1142
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1143
|
-
return String(error);
|
|
1144
|
-
}
|
|
1145
|
-
var IGNORED_ATTRIBUTES, DB_SENSITIVE_PATTERNS, MAX_NESTED_DEPTH, MAX_NESTED_LEAVES, MAX_UNKNOWN_FROM_LEAVES, DISPLAY_NAME_COLUMNS, MAX_DISPLAY_NAME_LENGTH;
|
|
1146
|
-
var init_shared = __esm({
|
|
1147
|
-
"src/db/shared.ts"() {
|
|
1148
|
-
init_configuration();
|
|
1149
|
-
init_logger();
|
|
1150
|
-
init_event_builder();
|
|
1151
|
-
init_buffer();
|
|
1152
|
-
init_correlation();
|
|
1153
|
-
init_actor();
|
|
1154
|
-
init_sanitize();
|
|
1155
|
-
IGNORED_ATTRIBUTES = Object.freeze([
|
|
1156
|
-
"id",
|
|
1157
|
-
"createdAt",
|
|
1158
|
-
"created_at",
|
|
1159
|
-
"updatedAt",
|
|
1160
|
-
"updated_at",
|
|
1161
|
-
// Auth.js / NextAuth standard columns
|
|
1162
|
-
"emailVerified",
|
|
1163
|
-
"expires"
|
|
1164
|
-
]);
|
|
1165
|
-
DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
1166
|
-
"password",
|
|
1167
|
-
"token",
|
|
1168
|
-
"secret",
|
|
1169
|
-
"api_key",
|
|
1170
|
-
"credit_card",
|
|
1171
|
-
"ssn",
|
|
1172
|
-
"social_security",
|
|
1173
|
-
"encrypted",
|
|
1174
|
-
"private_key",
|
|
1175
|
-
"public_key",
|
|
1176
|
-
"signing_key",
|
|
1177
|
-
"pem",
|
|
1178
|
-
"cipher",
|
|
1179
|
-
"nonce",
|
|
1180
|
-
"salt",
|
|
1181
|
-
"digest",
|
|
1182
|
-
"signature",
|
|
1183
|
-
"hmac",
|
|
1184
|
-
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
1185
|
-
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
1186
|
-
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
1187
|
-
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
1188
|
-
"credential",
|
|
1189
|
-
"passwd",
|
|
1190
|
-
"passcode",
|
|
1191
|
-
"apikey",
|
|
1192
|
-
"card_number",
|
|
1193
|
-
"cardnumber",
|
|
1194
|
-
"cvv",
|
|
1195
|
-
"cvc"
|
|
1196
|
-
]);
|
|
1197
|
-
MAX_NESTED_DEPTH = 3;
|
|
1198
|
-
MAX_NESTED_LEAVES = 20;
|
|
1199
|
-
MAX_UNKNOWN_FROM_LEAVES = 5;
|
|
1200
|
-
DISPLAY_NAME_COLUMNS = ["name", "title", "number", "label"];
|
|
1201
|
-
MAX_DISPLAY_NAME_LENGTH = 120;
|
|
1202
|
-
}
|
|
1203
|
-
});
|
|
1204
|
-
|
|
1205
|
-
// src/db/supabase.ts
|
|
1206
|
-
var supabase_exports = {};
|
|
1207
|
-
__export(supabase_exports, {
|
|
1208
|
-
tryExtractSupabaseActor: () => tryExtractSupabaseActor,
|
|
1209
|
-
wrapSupabase: () => wrapSupabase
|
|
1210
|
-
});
|
|
1211
|
-
function triggerPathWillCapture(table) {
|
|
1212
|
-
const config = configuration();
|
|
1213
|
-
if (!config.databaseReader) return false;
|
|
1214
|
-
const tracked = config.triggerTrackedTables;
|
|
1215
|
-
if (tracked === null) return false;
|
|
1216
|
-
return tracked.has(table);
|
|
1217
|
-
}
|
|
1218
|
-
function wrapSupabase(client) {
|
|
1219
|
-
if (client === null || typeof client !== "object") return client;
|
|
1220
|
-
const obj = client;
|
|
1221
|
-
if (obj.__ezlogsWrapped) return client;
|
|
1222
|
-
if (typeof obj.from !== "function") return client;
|
|
1223
|
-
const originalFrom = obj.from.bind(obj);
|
|
1224
|
-
const prereadRow = async (table, filters) => {
|
|
1225
|
-
try {
|
|
1226
|
-
const queryBuilder = originalFrom(table);
|
|
1227
|
-
if (typeof queryBuilder.select !== "function") return null;
|
|
1228
|
-
let chain = queryBuilder.select("*");
|
|
1229
|
-
for (const f of filters) {
|
|
1230
|
-
if (typeof chain.eq !== "function") return null;
|
|
1231
|
-
chain = chain.eq(
|
|
1232
|
-
f.column,
|
|
1233
|
-
f.value
|
|
1234
|
-
);
|
|
1235
|
-
}
|
|
1236
|
-
if (typeof chain.maybeSingle === "function") {
|
|
1237
|
-
chain = chain.maybeSingle();
|
|
1238
|
-
} else if (typeof chain.limit === "function") {
|
|
1239
|
-
chain = chain.limit(
|
|
1240
|
-
1
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
const result = await chain;
|
|
1244
|
-
if (!result || result.error) return null;
|
|
1245
|
-
if (Array.isArray(result.data)) {
|
|
1246
|
-
const first = result.data[0];
|
|
1247
|
-
return isPlainObject4(first) ? first : null;
|
|
1248
|
-
}
|
|
1249
|
-
return isPlainObject4(result.data) ? result.data : null;
|
|
1250
|
-
} catch {
|
|
1251
|
-
return null;
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
obj.from = ((table) => {
|
|
1255
|
-
const builder = originalFrom(table);
|
|
1256
|
-
return wrapBuilder(builder, table, prereadRow);
|
|
1257
|
-
});
|
|
1258
|
-
Object.defineProperty(obj, "__ezlogsWrapped", {
|
|
1259
|
-
value: true,
|
|
1260
|
-
enumerable: false,
|
|
1261
|
-
configurable: false
|
|
1262
|
-
});
|
|
1263
|
-
registerActorSource(obj);
|
|
1264
|
-
return client;
|
|
1265
|
-
}
|
|
1266
|
-
function registerActorSource(client) {
|
|
1267
|
-
try {
|
|
1268
|
-
const g = globalThis;
|
|
1269
|
-
g[GLOBAL_CLIENT_KEY] = client;
|
|
1270
|
-
} catch {
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
async function tryExtractSupabaseActor() {
|
|
1274
|
-
const g = globalThis;
|
|
1275
|
-
const client = g[GLOBAL_CLIENT_KEY];
|
|
1276
|
-
if (!client || typeof client.auth?.getUser !== "function") return null;
|
|
1277
|
-
try {
|
|
1278
|
-
const { data } = await client.auth.getUser();
|
|
1279
|
-
const user = data?.user;
|
|
1280
|
-
if (!user || typeof user.id !== "string" || !user.id) return null;
|
|
1281
|
-
const label = user.user_metadata?.full_name ?? user.user_metadata?.name ?? user.email ?? void 0;
|
|
1282
|
-
return label ? { id: user.id, label } : { id: user.id };
|
|
1283
|
-
} catch {
|
|
1284
|
-
return null;
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
function wrapBuilder(builder, table, preread) {
|
|
1288
|
-
if (typeof builder.insert === "function") {
|
|
1289
|
-
builder.insert = wrapMutation(
|
|
1290
|
-
builder.insert.bind(builder),
|
|
1291
|
-
{ table, operation: "create" },
|
|
1292
|
-
preread
|
|
1293
|
-
);
|
|
1294
|
-
}
|
|
1295
|
-
if (typeof builder.upsert === "function") {
|
|
1296
|
-
builder.upsert = wrapMutation(
|
|
1297
|
-
builder.upsert.bind(builder),
|
|
1298
|
-
{ table, operation: "update" },
|
|
1299
|
-
// supabase upsert is conceptually update-with-fallback
|
|
1300
|
-
preread
|
|
1301
|
-
);
|
|
1302
|
-
}
|
|
1303
|
-
if (typeof builder.update === "function") {
|
|
1304
|
-
builder.update = wrapMutation(
|
|
1305
|
-
builder.update.bind(builder),
|
|
1306
|
-
{ table, operation: "update" },
|
|
1307
|
-
preread
|
|
1308
|
-
);
|
|
1309
|
-
}
|
|
1310
|
-
if (typeof builder.delete === "function") {
|
|
1311
|
-
builder.delete = wrapDeleteMutation(
|
|
1312
|
-
builder.delete.bind(builder),
|
|
1313
|
-
table,
|
|
1314
|
-
preread
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
return builder;
|
|
1318
|
-
}
|
|
1319
|
-
function wrapMutation(original, ctx, preread) {
|
|
1320
|
-
return (values, options) => {
|
|
1321
|
-
const filterBuilder = original(values, options);
|
|
1322
|
-
const filters = trackFilterChain(filterBuilder);
|
|
1323
|
-
const beforeRowRef = { row: null };
|
|
1324
|
-
return instrumentFilterBuilder(
|
|
1325
|
-
filterBuilder,
|
|
1326
|
-
(result) => emitFromMutation(ctx, values, result, filters, beforeRowRef.row),
|
|
1327
|
-
async () => {
|
|
1328
|
-
if (ctx.operation !== "update") return;
|
|
1329
|
-
if (triggerPathWillCapture(ctx.table)) return;
|
|
1330
|
-
const prereadFilters = prereadFiltersFromCaptured(filters);
|
|
1331
|
-
if (prereadFilters !== null) {
|
|
1332
|
-
beforeRowRef.row = await preread(ctx.table, prereadFilters);
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
);
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
function wrapDeleteMutation(original, table, preread) {
|
|
1339
|
-
return (options) => {
|
|
1340
|
-
const filterBuilder = original(options);
|
|
1341
|
-
const filters = trackFilterChain(filterBuilder);
|
|
1342
|
-
const beforeRowRef = { row: null };
|
|
1343
|
-
return instrumentFilterBuilder(
|
|
1344
|
-
filterBuilder,
|
|
1345
|
-
(result) => emitFromDelete(table, result, filters, beforeRowRef.row),
|
|
1346
|
-
async () => {
|
|
1347
|
-
if (triggerPathWillCapture(table)) return;
|
|
1348
|
-
const prereadFilters = prereadFiltersFromCaptured(filters);
|
|
1349
|
-
if (prereadFilters !== null) {
|
|
1350
|
-
beforeRowRef.row = await preread(table, prereadFilters);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
);
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
function trackFilterChain(builder) {
|
|
1357
|
-
const captured = { equals: {}, inLists: {} };
|
|
1358
|
-
if (!builder || typeof builder !== "object") return captured;
|
|
1359
|
-
const builderObj = builder;
|
|
1360
|
-
const wrapEq = (orig) => {
|
|
1361
|
-
if (typeof orig !== "function") return orig;
|
|
1362
|
-
return function patchedEq(column, value) {
|
|
1363
|
-
try {
|
|
1364
|
-
if (typeof column === "string") captured.equals[column] = value;
|
|
1365
|
-
} catch {
|
|
1366
|
-
}
|
|
1367
|
-
return orig.call(this, column, value);
|
|
1368
|
-
};
|
|
1369
|
-
};
|
|
1370
|
-
const wrapIn = (orig) => {
|
|
1371
|
-
if (typeof orig !== "function") return orig;
|
|
1372
|
-
return function patchedIn(column, values) {
|
|
1373
|
-
try {
|
|
1374
|
-
if (typeof column === "string" && Array.isArray(values)) {
|
|
1375
|
-
captured.inLists[column] = values;
|
|
1376
|
-
}
|
|
1377
|
-
} catch {
|
|
1378
|
-
}
|
|
1379
|
-
return orig.call(this, column, values);
|
|
1380
|
-
};
|
|
1381
|
-
};
|
|
1382
|
-
const wrapMatch = (orig) => {
|
|
1383
|
-
if (typeof orig !== "function") return orig;
|
|
1384
|
-
return function patchedMatch(query) {
|
|
1385
|
-
try {
|
|
1386
|
-
if (isPlainObject4(query)) {
|
|
1387
|
-
for (const [k, v] of Object.entries(query)) {
|
|
1388
|
-
captured.equals[k] = v;
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
} catch {
|
|
1392
|
-
}
|
|
1393
|
-
return orig.call(this, query);
|
|
1394
|
-
};
|
|
1395
|
-
};
|
|
1396
|
-
if ("eq" in builderObj) builderObj.eq = wrapEq(builderObj.eq);
|
|
1397
|
-
if ("in" in builderObj) builderObj.in = wrapIn(builderObj.in);
|
|
1398
|
-
if ("match" in builderObj) builderObj.match = wrapMatch(builderObj.match);
|
|
1399
|
-
return captured;
|
|
1400
|
-
}
|
|
1401
|
-
function instrumentFilterBuilder(builder, onResolved, beforeFire) {
|
|
1402
|
-
if (!builder || typeof builder !== "object") return builder;
|
|
1403
|
-
const originalThen = builder.then?.bind(builder);
|
|
1404
|
-
if (typeof originalThen !== "function") return builder;
|
|
1405
|
-
const wrappedThen = function ezlogsThen(onfulfilled, onrejected) {
|
|
1406
|
-
return new Promise((resolve, reject) => {
|
|
1407
|
-
const proceed = () => {
|
|
1408
|
-
originalThen(
|
|
1409
|
-
(raw) => {
|
|
1410
|
-
const result = raw;
|
|
1411
|
-
try {
|
|
1412
|
-
if (!result?.error) onResolved(result);
|
|
1413
|
-
} catch (error) {
|
|
1414
|
-
logger.debug(`supabase capture failed: ${describeError6(error)}`);
|
|
1415
|
-
}
|
|
1416
|
-
try {
|
|
1417
|
-
const passthrough = onfulfilled ? onfulfilled(raw) : raw;
|
|
1418
|
-
resolve(passthrough);
|
|
1419
|
-
} catch (e) {
|
|
1420
|
-
reject(e);
|
|
1421
|
-
}
|
|
1422
|
-
},
|
|
1423
|
-
(reason) => {
|
|
1424
|
-
try {
|
|
1425
|
-
const passthrough = onrejected ? onrejected(reason) : Promise.reject(reason);
|
|
1426
|
-
resolve(passthrough);
|
|
1427
|
-
} catch (e) {
|
|
1428
|
-
reject(e);
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
);
|
|
1432
|
-
};
|
|
1433
|
-
if (beforeFire) {
|
|
1434
|
-
beforeFire().then(proceed, () => proceed());
|
|
1435
|
-
} else {
|
|
1436
|
-
proceed();
|
|
1437
|
-
}
|
|
1438
|
-
});
|
|
1439
|
-
};
|
|
1440
|
-
builder.then = wrappedThen;
|
|
1441
|
-
return builder;
|
|
1442
|
-
}
|
|
1443
|
-
function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
1444
|
-
if (Array.isArray(values)) {
|
|
1445
|
-
const resultRows = pickResultRows(result);
|
|
1446
|
-
values.forEach((row, index) => {
|
|
1447
|
-
if (!isPlainObject4(row)) return;
|
|
1448
|
-
emitOneRow(ctx, row, resultRows[index] ?? null, filters, null);
|
|
1449
|
-
});
|
|
1450
|
-
return;
|
|
1451
|
-
}
|
|
1452
|
-
if (!isPlainObject4(values)) {
|
|
1453
|
-
emitDbEvent({
|
|
1454
|
-
modelClass: ctx.table,
|
|
1455
|
-
operation: ctx.operation,
|
|
1456
|
-
resourceId: idFromFilters(filters)
|
|
1457
|
-
});
|
|
1458
|
-
return;
|
|
1459
|
-
}
|
|
1460
|
-
const valueObj = values;
|
|
1461
|
-
const resultRow = pickFirstResultRow(result);
|
|
1462
|
-
emitOneRow(ctx, valueObj, resultRow, filters, beforeRow);
|
|
1463
|
-
}
|
|
1464
|
-
function emitOneRow(ctx, values, resultRow, filters, beforeRow) {
|
|
1465
|
-
const resourceId = resultRow?.id ?? values.id ?? idFromFilters(filters) ?? null;
|
|
1466
|
-
const merged = beforeRow ?? resultRow ?? values;
|
|
1467
|
-
const displayName = resolveDisplayName(ctx.table, merged);
|
|
1468
|
-
if (ctx.operation === "create") {
|
|
1469
|
-
emitDbEvent({
|
|
1470
|
-
modelClass: ctx.table,
|
|
1471
|
-
operation: "create",
|
|
1472
|
-
resourceId,
|
|
1473
|
-
initialAttributes: values,
|
|
1474
|
-
displayName,
|
|
1475
|
-
modelInstance: merged
|
|
1476
|
-
});
|
|
1477
|
-
return;
|
|
1478
|
-
}
|
|
1479
|
-
if (ctx.operation === "update") {
|
|
1480
|
-
const changes = buildUpdateChanges(values, beforeRow);
|
|
1481
|
-
emitDbEvent({
|
|
1482
|
-
modelClass: ctx.table,
|
|
1483
|
-
operation: "update",
|
|
1484
|
-
resourceId,
|
|
1485
|
-
changes,
|
|
1486
|
-
displayName,
|
|
1487
|
-
modelInstance: merged
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
function emitFromDelete(table, result, filters, beforeRow) {
|
|
1492
|
-
const resultRow = pickFirstResultRow(result);
|
|
1493
|
-
const resourceId = resultRow?.id ?? beforeRow?.id ?? idFromFilters(filters) ?? null;
|
|
1494
|
-
const richestRow = resultRow ?? beforeRow;
|
|
1495
|
-
const displayName = richestRow ? resolveDisplayName(table, richestRow) : null;
|
|
1496
|
-
emitDbEvent({
|
|
1497
|
-
modelClass: table,
|
|
1498
|
-
operation: "destroy",
|
|
1499
|
-
resourceId,
|
|
1500
|
-
displayName,
|
|
1501
|
-
modelInstance: richestRow
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
function prereadFiltersFromCaptured(filters) {
|
|
1505
|
-
const idValue = filters.equals["id"];
|
|
1506
|
-
if (!isScalarFilterValue(idValue)) return null;
|
|
1507
|
-
const out = [];
|
|
1508
|
-
for (const column of Object.keys(filters.equals)) {
|
|
1509
|
-
const value = filters.equals[column];
|
|
1510
|
-
if (!isScalarFilterValue(value)) continue;
|
|
1511
|
-
out.push({ column, value });
|
|
1512
|
-
}
|
|
1513
|
-
return out;
|
|
1514
|
-
}
|
|
1515
|
-
function idFromFilters(filters) {
|
|
1516
|
-
const value = filters.equals["id"];
|
|
1517
|
-
return isScalarFilterValue(value) ? value : null;
|
|
1518
|
-
}
|
|
1519
|
-
function isScalarFilterValue(value) {
|
|
1520
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "bigint";
|
|
1521
|
-
}
|
|
1522
|
-
function buildUpdateChanges(values, beforeRow) {
|
|
1523
|
-
return Object.keys(values).map((attribute) => {
|
|
1524
|
-
const change = {
|
|
1525
|
-
attribute,
|
|
1526
|
-
to: values[attribute]
|
|
1527
|
-
};
|
|
1528
|
-
if (beforeRow && Object.prototype.hasOwnProperty.call(beforeRow, attribute)) {
|
|
1529
|
-
change.from = beforeRow[attribute];
|
|
1530
|
-
}
|
|
1531
|
-
return change;
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
function pickFirstResultRow(result) {
|
|
1535
|
-
if (!result || result.error) return null;
|
|
1536
|
-
if (Array.isArray(result.data)) {
|
|
1537
|
-
const first = result.data[0];
|
|
1538
|
-
return isPlainObject4(first) ? first : null;
|
|
1539
|
-
}
|
|
1540
|
-
if (isPlainObject4(result.data)) return result.data;
|
|
1541
|
-
return null;
|
|
1542
|
-
}
|
|
1543
|
-
function pickResultRows(result) {
|
|
1544
|
-
if (!result || result.error || !Array.isArray(result.data)) return [];
|
|
1545
|
-
return result.data.map(
|
|
1546
|
-
(row) => isPlainObject4(row) ? row : void 0
|
|
1547
|
-
);
|
|
1548
|
-
}
|
|
1549
|
-
function isPlainObject4(value) {
|
|
1550
|
-
if (value === null || typeof value !== "object") return false;
|
|
1551
|
-
if (Array.isArray(value)) return false;
|
|
1552
|
-
if (value instanceof Date) return false;
|
|
1553
|
-
return true;
|
|
1554
|
-
}
|
|
1555
|
-
function describeError6(error) {
|
|
1556
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1557
|
-
return String(error);
|
|
1558
|
-
}
|
|
1559
|
-
var GLOBAL_CLIENT_KEY;
|
|
1560
|
-
var init_supabase = __esm({
|
|
1561
|
-
"src/db/supabase.ts"() {
|
|
1562
|
-
init_logger();
|
|
1563
|
-
init_configuration();
|
|
1564
|
-
init_shared();
|
|
1565
|
-
GLOBAL_CLIENT_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:supabase-current-client");
|
|
1566
|
-
}
|
|
1567
|
-
});
|
|
1568
|
-
|
|
1569
|
-
// src/index.ts
|
|
1570
|
-
init_configuration();
|
|
1571
|
-
init_logger();
|
|
1572
|
-
init_buffer();
|
|
1573
|
-
|
|
1574
|
-
// src/pipeline/flush-scheduler.ts
|
|
1575
|
-
init_configuration();
|
|
1576
|
-
init_logger();
|
|
1577
|
-
init_buffer();
|
|
1578
|
-
|
|
1579
|
-
// src/pipeline/retry-sender.ts
|
|
1580
|
-
init_configuration();
|
|
1581
|
-
init_logger();
|
|
3
|
+
var chunkY5NSHKWQ_cjs = require('./chunk-Y5NSHKWQ.cjs');
|
|
4
|
+
var chunkYX2XPLOA_cjs = require('./chunk-YX2XPLOA.cjs');
|
|
5
|
+
var chunkWASXTDLW_cjs = require('./chunk-WASXTDLW.cjs');
|
|
6
|
+
var chunkV5YNKKTG_cjs = require('./chunk-V5YNKKTG.cjs');
|
|
7
|
+
require('./chunk-ZDSQYCYV.cjs');
|
|
1582
8
|
|
|
1583
9
|
// src/pipeline/transport.ts
|
|
1584
|
-
init_configuration();
|
|
1585
|
-
init_logger();
|
|
1586
10
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
1587
11
|
var transport = {
|
|
1588
12
|
async send(events) {
|
|
1589
13
|
if (!events || events.length === 0) return "success";
|
|
1590
|
-
const config = configuration();
|
|
14
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
1591
15
|
const serverUrl = config.serverUrl;
|
|
1592
16
|
if (!serverUrl) {
|
|
1593
|
-
logger.error("Transport: serverUrl not configured");
|
|
17
|
+
chunkV5YNKKTG_cjs.logger.error("Transport: serverUrl not configured");
|
|
1594
18
|
return "failure";
|
|
1595
19
|
}
|
|
1596
20
|
const url = `${stripTrailingSlash(serverUrl)}/api/events`;
|
|
@@ -1610,14 +34,14 @@ var transport = {
|
|
|
1610
34
|
signal: controller.signal
|
|
1611
35
|
});
|
|
1612
36
|
if (response.status >= 200 && response.status < 300) {
|
|
1613
|
-
logger.debug(`Transport send succeeded (${response.status})`);
|
|
37
|
+
chunkV5YNKKTG_cjs.logger.debug(`Transport send succeeded (${response.status})`);
|
|
1614
38
|
return "success";
|
|
1615
39
|
}
|
|
1616
|
-
logger.error(`Transport send failed (${response.status})`);
|
|
40
|
+
chunkV5YNKKTG_cjs.logger.error(`Transport send failed (${response.status})`);
|
|
1617
41
|
return "failure";
|
|
1618
42
|
} catch (error) {
|
|
1619
43
|
const desc = describeError(error);
|
|
1620
|
-
logger.error(`Transport send failed: ${desc}`);
|
|
44
|
+
chunkV5YNKKTG_cjs.logger.error(`Transport send failed: ${desc}`);
|
|
1621
45
|
return "failure";
|
|
1622
46
|
} finally {
|
|
1623
47
|
clearTimeout(timer);
|
|
@@ -1652,7 +76,7 @@ var retrySender = {
|
|
|
1652
76
|
await sleepBeforeRetry(attempt);
|
|
1653
77
|
attempt += 1;
|
|
1654
78
|
}
|
|
1655
|
-
logger.error(
|
|
79
|
+
chunkV5YNKKTG_cjs.logger.error(
|
|
1656
80
|
`RetrySender: failed after ${maxAttempts} attempts, dropping ${events.length} events`
|
|
1657
81
|
);
|
|
1658
82
|
return "failure";
|
|
@@ -1662,7 +86,7 @@ async function attemptSend(events, attempt, maxAttempts) {
|
|
|
1662
86
|
try {
|
|
1663
87
|
return await transport.send(events);
|
|
1664
88
|
} catch (error) {
|
|
1665
|
-
logger.error(
|
|
89
|
+
chunkV5YNKKTG_cjs.logger.error(
|
|
1666
90
|
`RetrySender: transport raised (attempt ${attempt}/${maxAttempts}): ${describeError2(error)}`
|
|
1667
91
|
);
|
|
1668
92
|
return "failure";
|
|
@@ -1679,7 +103,7 @@ function applyJitter(base) {
|
|
|
1679
103
|
}
|
|
1680
104
|
function retryAttempts() {
|
|
1681
105
|
try {
|
|
1682
|
-
const value = configuration().retryAttempts;
|
|
106
|
+
const value = chunkWASXTDLW_cjs.configuration().retryAttempts;
|
|
1683
107
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
1684
108
|
return 3;
|
|
1685
109
|
}
|
|
@@ -1713,7 +137,7 @@ var flushScheduler = {
|
|
|
1713
137
|
if (typeof s.timer === "object" && s.timer !== null && "unref" in s.timer) {
|
|
1714
138
|
s.timer.unref();
|
|
1715
139
|
}
|
|
1716
|
-
logger.debug(`FlushScheduler started (interval ${interval}ms)`);
|
|
140
|
+
chunkV5YNKKTG_cjs.logger.debug(`FlushScheduler started (interval ${interval}ms)`);
|
|
1717
141
|
},
|
|
1718
142
|
async stop() {
|
|
1719
143
|
const s = state();
|
|
@@ -1721,7 +145,7 @@ var flushScheduler = {
|
|
|
1721
145
|
clearInterval(s.timer);
|
|
1722
146
|
s.timer = null;
|
|
1723
147
|
await tick();
|
|
1724
|
-
logger.debug("FlushScheduler stopped");
|
|
148
|
+
chunkV5YNKKTG_cjs.logger.debug("FlushScheduler stopped");
|
|
1725
149
|
},
|
|
1726
150
|
isRunning() {
|
|
1727
151
|
return state().timer !== null;
|
|
@@ -1736,18 +160,18 @@ async function tick() {
|
|
|
1736
160
|
if (s.inFlight) return;
|
|
1737
161
|
s.inFlight = true;
|
|
1738
162
|
try {
|
|
1739
|
-
const events = drainEvents();
|
|
163
|
+
const events = chunkWASXTDLW_cjs.drainEvents();
|
|
1740
164
|
if (events.length === 0) return;
|
|
1741
165
|
await retrySender.send(events);
|
|
1742
166
|
} catch (error) {
|
|
1743
|
-
logger.error(`FlushScheduler tick failed: ${describeError3(error)}`);
|
|
167
|
+
chunkV5YNKKTG_cjs.logger.error(`FlushScheduler tick failed: ${describeError3(error)}`);
|
|
1744
168
|
} finally {
|
|
1745
169
|
s.inFlight = false;
|
|
1746
170
|
}
|
|
1747
171
|
}
|
|
1748
172
|
function sendInterval() {
|
|
1749
173
|
try {
|
|
1750
|
-
const value = configuration().sendInterval;
|
|
174
|
+
const value = chunkWASXTDLW_cjs.configuration().sendInterval;
|
|
1751
175
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
1752
176
|
return 5e3;
|
|
1753
177
|
}
|
|
@@ -1762,8 +186,6 @@ function describeError3(error) {
|
|
|
1762
186
|
}
|
|
1763
187
|
|
|
1764
188
|
// src/http/outgoing-fetch.ts
|
|
1765
|
-
init_correlation();
|
|
1766
|
-
init_logger();
|
|
1767
189
|
var HEADER = "x-correlation-id";
|
|
1768
190
|
var originalFetch = null;
|
|
1769
191
|
var patched = false;
|
|
@@ -1772,13 +194,13 @@ function patchGlobalFetch() {
|
|
|
1772
194
|
if (typeof globalThis.fetch !== "function") return;
|
|
1773
195
|
originalFetch = globalThis.fetch;
|
|
1774
196
|
const wrapped = (input, init) => {
|
|
1775
|
-
const id = current();
|
|
197
|
+
const id = chunkWASXTDLW_cjs.current();
|
|
1776
198
|
if (!id) return originalFetch.call(globalThis, input, init);
|
|
1777
199
|
try {
|
|
1778
200
|
const enriched = injectHeader(input, init, id);
|
|
1779
201
|
return originalFetch.call(globalThis, enriched.input, enriched.init);
|
|
1780
202
|
} catch (error) {
|
|
1781
|
-
logger.debug(`outgoing-fetch injection failed: ${describeError4(error)}`);
|
|
203
|
+
chunkV5YNKKTG_cjs.logger.debug(`outgoing-fetch injection failed: ${describeError4(error)}`);
|
|
1782
204
|
return originalFetch.call(globalThis, input, init);
|
|
1783
205
|
}
|
|
1784
206
|
};
|
|
@@ -1814,653 +236,6 @@ function describeError4(error) {
|
|
|
1814
236
|
return String(error);
|
|
1815
237
|
}
|
|
1816
238
|
|
|
1817
|
-
// src/triggers/patch-pg.ts
|
|
1818
|
-
init_actor();
|
|
1819
|
-
init_correlation();
|
|
1820
|
-
init_logger();
|
|
1821
|
-
var txState = /* @__PURE__ */ new WeakMap();
|
|
1822
|
-
function patchPgClient(pgModule) {
|
|
1823
|
-
if (!pgModule || !pgModule.Client || !pgModule.Client.prototype) {
|
|
1824
|
-
logger.debug("patchPgClient: not a recognized pg module shape, skipping");
|
|
1825
|
-
return;
|
|
1826
|
-
}
|
|
1827
|
-
const proto = pgModule.Client.prototype;
|
|
1828
|
-
if (proto._ezlogsPatched) return;
|
|
1829
|
-
const originalQuery = proto.query;
|
|
1830
|
-
proto.query = function patchedQuery(config, values, callback) {
|
|
1831
|
-
return runPatchedQuery(
|
|
1832
|
-
this,
|
|
1833
|
-
originalQuery,
|
|
1834
|
-
config,
|
|
1835
|
-
values,
|
|
1836
|
-
callback
|
|
1837
|
-
);
|
|
1838
|
-
};
|
|
1839
|
-
proto._ezlogsPatched = true;
|
|
1840
|
-
}
|
|
1841
|
-
function runPatchedQuery(client, original, config, values, callback) {
|
|
1842
|
-
const state2 = ensureState(client);
|
|
1843
|
-
const text = extractQueryText(config);
|
|
1844
|
-
const verb = leadingVerb(text);
|
|
1845
|
-
if (verb === "BEGIN" || verb === "START") {
|
|
1846
|
-
state2.inTx = true;
|
|
1847
|
-
state2.injected = false;
|
|
1848
|
-
return original.call(client, config, values, callback);
|
|
1849
|
-
}
|
|
1850
|
-
if (verb === "COMMIT" || verb === "ROLLBACK" || verb === "END") {
|
|
1851
|
-
const result = original.call(client, config, values, callback);
|
|
1852
|
-
state2.inTx = false;
|
|
1853
|
-
state2.injected = false;
|
|
1854
|
-
return result;
|
|
1855
|
-
}
|
|
1856
|
-
if (state2.inTx) {
|
|
1857
|
-
if (state2.injected) {
|
|
1858
|
-
return original.call(client, config, values, callback);
|
|
1859
|
-
}
|
|
1860
|
-
const ctx2 = snapshotContext();
|
|
1861
|
-
if (!ctx2.actorId && !ctx2.correlationId) {
|
|
1862
|
-
state2.injected = true;
|
|
1863
|
-
return original.call(client, config, values, callback);
|
|
1864
|
-
}
|
|
1865
|
-
state2.injected = true;
|
|
1866
|
-
return injectAndRun(client, original, config, values, callback, ctx2);
|
|
1867
|
-
}
|
|
1868
|
-
const ctx = snapshotContext();
|
|
1869
|
-
if (!ctx.actorId && !ctx.correlationId) {
|
|
1870
|
-
return original.call(client, config, values, callback);
|
|
1871
|
-
}
|
|
1872
|
-
return wrapInTx(client, original, config, values, callback, ctx);
|
|
1873
|
-
}
|
|
1874
|
-
function snapshotContext() {
|
|
1875
|
-
const actor = getCurrentActor();
|
|
1876
|
-
return {
|
|
1877
|
-
actorId: actor && actor.id ? actor.id : null,
|
|
1878
|
-
correlationId: current()
|
|
1879
|
-
};
|
|
1880
|
-
}
|
|
1881
|
-
async function injectAndRun(client, original, config, values, callback, ctx) {
|
|
1882
|
-
if (ctx.actorId) {
|
|
1883
|
-
await safeSet(client, original, {
|
|
1884
|
-
text: "SELECT set_config('ezlogs.actor_id', $1, true)",
|
|
1885
|
-
values: [ctx.actorId]
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
if (ctx.correlationId) {
|
|
1889
|
-
await safeSet(client, original, {
|
|
1890
|
-
text: "SELECT set_config('ezlogs.correlation_id', $1, true)",
|
|
1891
|
-
values: [ctx.correlationId]
|
|
1892
|
-
});
|
|
1893
|
-
}
|
|
1894
|
-
return original.call(client, config, values, callback);
|
|
1895
|
-
}
|
|
1896
|
-
async function safeSet(client, original, cfg) {
|
|
1897
|
-
try {
|
|
1898
|
-
const result = original.call(client, cfg);
|
|
1899
|
-
if (result && typeof result.then === "function") {
|
|
1900
|
-
await result;
|
|
1901
|
-
}
|
|
1902
|
-
} catch (err) {
|
|
1903
|
-
logger.debug(
|
|
1904
|
-
`patchPgClient: SET LOCAL failed (continuing): ${err instanceof Error ? err.message : String(err)}`
|
|
1905
|
-
);
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
function wrapInTx(client, original, config, values, callback, ctx) {
|
|
1909
|
-
const state2 = ensureState(client);
|
|
1910
|
-
let userCb = null;
|
|
1911
|
-
let realValues = values;
|
|
1912
|
-
if (typeof callback === "function") {
|
|
1913
|
-
userCb = callback;
|
|
1914
|
-
} else if (typeof values === "function") {
|
|
1915
|
-
userCb = values;
|
|
1916
|
-
realValues = void 0;
|
|
1917
|
-
}
|
|
1918
|
-
const begin = original.call(client, "BEGIN");
|
|
1919
|
-
if (!begin || typeof begin.then !== "function") {
|
|
1920
|
-
return original.call(client, config, values, callback);
|
|
1921
|
-
}
|
|
1922
|
-
const wrapped = begin.then(async () => {
|
|
1923
|
-
state2.inTx = true;
|
|
1924
|
-
state2.injected = true;
|
|
1925
|
-
if (ctx.actorId) {
|
|
1926
|
-
await original.call(client, {
|
|
1927
|
-
text: "SELECT set_config('ezlogs.actor_id', $1, true)",
|
|
1928
|
-
values: [ctx.actorId]
|
|
1929
|
-
});
|
|
1930
|
-
}
|
|
1931
|
-
if (ctx.correlationId) {
|
|
1932
|
-
await original.call(client, {
|
|
1933
|
-
text: "SELECT set_config('ezlogs.correlation_id', $1, true)",
|
|
1934
|
-
values: [ctx.correlationId]
|
|
1935
|
-
});
|
|
1936
|
-
}
|
|
1937
|
-
}).then(
|
|
1938
|
-
() => (
|
|
1939
|
-
// Run the user's actual query in promise mode — DO NOT forward
|
|
1940
|
-
// the caller's callback. See comment above.
|
|
1941
|
-
original.call(client, config, realValues)
|
|
1942
|
-
)
|
|
1943
|
-
).then(
|
|
1944
|
-
async (result) => {
|
|
1945
|
-
await original.call(client, "COMMIT");
|
|
1946
|
-
state2.inTx = false;
|
|
1947
|
-
state2.injected = false;
|
|
1948
|
-
return result;
|
|
1949
|
-
},
|
|
1950
|
-
async (err) => {
|
|
1951
|
-
try {
|
|
1952
|
-
await original.call(client, "ROLLBACK");
|
|
1953
|
-
} catch {
|
|
1954
|
-
}
|
|
1955
|
-
state2.inTx = false;
|
|
1956
|
-
state2.injected = false;
|
|
1957
|
-
throw err;
|
|
1958
|
-
}
|
|
1959
|
-
);
|
|
1960
|
-
if (userCb) {
|
|
1961
|
-
wrapped.then(
|
|
1962
|
-
(result) => userCb(null, result),
|
|
1963
|
-
(err) => userCb(err instanceof Error ? err : new Error(String(err)))
|
|
1964
|
-
);
|
|
1965
|
-
return void 0;
|
|
1966
|
-
}
|
|
1967
|
-
return wrapped;
|
|
1968
|
-
}
|
|
1969
|
-
function ensureState(client) {
|
|
1970
|
-
let s = txState.get(client);
|
|
1971
|
-
if (!s) {
|
|
1972
|
-
s = { inTx: false, injected: false };
|
|
1973
|
-
txState.set(client, s);
|
|
1974
|
-
}
|
|
1975
|
-
return s;
|
|
1976
|
-
}
|
|
1977
|
-
function extractQueryText(config) {
|
|
1978
|
-
if (typeof config === "string") return config;
|
|
1979
|
-
if (config && typeof config === "object" && typeof config.text === "string") {
|
|
1980
|
-
return config.text;
|
|
1981
|
-
}
|
|
1982
|
-
return "";
|
|
1983
|
-
}
|
|
1984
|
-
function leadingVerb(text) {
|
|
1985
|
-
let s = text;
|
|
1986
|
-
while (true) {
|
|
1987
|
-
const before = s.length;
|
|
1988
|
-
s = s.replace(/^\s+/, "");
|
|
1989
|
-
s = s.replace(/^--[^\n]*\n?/, "");
|
|
1990
|
-
if (s.length === before) break;
|
|
1991
|
-
}
|
|
1992
|
-
const m = /^[A-Za-z]+/.exec(s);
|
|
1993
|
-
return m ? m[0].toUpperCase() : "";
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
// src/triggers/reader.ts
|
|
1997
|
-
init_logger();
|
|
1998
|
-
init_shared();
|
|
1999
|
-
init_correlation();
|
|
2000
|
-
init_actor();
|
|
2001
|
-
|
|
2002
|
-
// src/triggers/emit-dedup.ts
|
|
2003
|
-
init_edge_fallback();
|
|
2004
|
-
var storage3 = createScopedStorage(
|
|
2005
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:audit-emitted-ids-storage")
|
|
2006
|
-
);
|
|
2007
|
-
function currentEmittedAuditIds() {
|
|
2008
|
-
return storage3.read();
|
|
2009
|
-
}
|
|
2010
|
-
function runWithEmittedAuditIdsScope(callback) {
|
|
2011
|
-
const existing = storage3.read();
|
|
2012
|
-
if (existing !== null) return callback();
|
|
2013
|
-
return storage3.run(/* @__PURE__ */ new Set(), callback);
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
// src/triggers/reader.ts
|
|
2017
|
-
var COLUMNS = "id, table_name, op, old_row, new_row, resource_id, correlation_id, txid, captured_at";
|
|
2018
|
-
var ORPHAN_AGE = "5 minutes";
|
|
2019
|
-
var PRUNE_AGE = "24 hours";
|
|
2020
|
-
var SWEEP_BATCH = 100;
|
|
2021
|
-
var PRUNE_BATCH = 2e3;
|
|
2022
|
-
var SWEEP_INTERVAL_MS = 1e4;
|
|
2023
|
-
var PRUNE_INTERVAL_MS = 10 * 6e4;
|
|
2024
|
-
var lastSweepAt = 0;
|
|
2025
|
-
var lastPruneAt = 0;
|
|
2026
|
-
var deleteDenied = false;
|
|
2027
|
-
var txCorrelation = /* @__PURE__ */ new Map();
|
|
2028
|
-
async function readAuditRows(exec, correlationId, since = null) {
|
|
2029
|
-
const where = since ? "correlation_id = $1 AND captured_at >= $2" : "correlation_id = $1";
|
|
2030
|
-
const params = since ? [correlationId, since.toISOString()] : [correlationId];
|
|
2031
|
-
try {
|
|
2032
|
-
if (!deleteDenied) {
|
|
2033
|
-
try {
|
|
2034
|
-
return sortById(
|
|
2035
|
-
extractRows(
|
|
2036
|
-
await exec(
|
|
2037
|
-
`DELETE FROM ezlogs_audit_log WHERE ${where} RETURNING ${COLUMNS}`,
|
|
2038
|
-
params
|
|
2039
|
-
)
|
|
2040
|
-
).map(normalizeAuditRow)
|
|
2041
|
-
);
|
|
2042
|
-
} catch (err) {
|
|
2043
|
-
if (!isPermissionDenied(err)) throw err;
|
|
2044
|
-
deleteDenied = true;
|
|
2045
|
-
logger.warn(
|
|
2046
|
-
"the database role used by the agent cannot DELETE from ezlogs_audit_log. Rows will not be cleaned up after they are sent; grant DELETE or schedule `DELETE FROM ezlogs_audit_log WHERE captured_at < now() - interval '24 hours'`."
|
|
2047
|
-
);
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
const result = await exec(
|
|
2051
|
-
`SELECT ${COLUMNS} FROM ezlogs_audit_log WHERE ${where} ORDER BY id ASC`,
|
|
2052
|
-
params
|
|
2053
|
-
);
|
|
2054
|
-
return extractRows(result).map(normalizeAuditRow);
|
|
2055
|
-
} catch (err) {
|
|
2056
|
-
logger.debug(
|
|
2057
|
-
`readAuditRows failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2058
|
-
);
|
|
2059
|
-
return [];
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
async function sweepAuditLog(exec) {
|
|
2063
|
-
if (deleteDenied) return 0;
|
|
2064
|
-
try {
|
|
2065
|
-
const rows = sortById(
|
|
2066
|
-
extractRows(
|
|
2067
|
-
await exec(
|
|
2068
|
-
`DELETE FROM ezlogs_audit_log
|
|
2069
|
-
WHERE id IN (
|
|
2070
|
-
SELECT id FROM ezlogs_audit_log
|
|
2071
|
-
WHERE (correlation_id IS NULL
|
|
2072
|
-
OR captured_at < now() - interval '${ORPHAN_AGE}')
|
|
2073
|
-
-- Never resurface history: past the retention cap a
|
|
2074
|
-
-- row is pruned, not sent as new activity.
|
|
2075
|
-
AND captured_at > now() - interval '${PRUNE_AGE}'
|
|
2076
|
-
ORDER BY id
|
|
2077
|
-
LIMIT ${SWEEP_BATCH}
|
|
2078
|
-
FOR UPDATE SKIP LOCKED)
|
|
2079
|
-
RETURNING ${COLUMNS}`,
|
|
2080
|
-
[]
|
|
2081
|
-
)
|
|
2082
|
-
).map(normalizeAuditRow)
|
|
2083
|
-
);
|
|
2084
|
-
await loadTableMeta(exec, rows);
|
|
2085
|
-
for (const row of rows) {
|
|
2086
|
-
const correlationId = row.correlation_id ?? correlationForTx(row.txid);
|
|
2087
|
-
runWithCorrelation(
|
|
2088
|
-
correlationId,
|
|
2089
|
-
() => runWithActorScope(() => emitOne(row))
|
|
2090
|
-
);
|
|
2091
|
-
}
|
|
2092
|
-
return rows.length;
|
|
2093
|
-
} catch (err) {
|
|
2094
|
-
logger.debug(
|
|
2095
|
-
`sweepAuditLog failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2096
|
-
);
|
|
2097
|
-
return 0;
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
async function pruneAuditLog(exec) {
|
|
2101
|
-
if (deleteDenied) return;
|
|
2102
|
-
try {
|
|
2103
|
-
await exec(
|
|
2104
|
-
`DELETE FROM ezlogs_audit_log
|
|
2105
|
-
WHERE id IN (
|
|
2106
|
-
SELECT id FROM ezlogs_audit_log
|
|
2107
|
-
WHERE captured_at < now() - interval '${PRUNE_AGE}'
|
|
2108
|
-
LIMIT ${PRUNE_BATCH})`,
|
|
2109
|
-
[]
|
|
2110
|
-
);
|
|
2111
|
-
} catch (err) {
|
|
2112
|
-
logger.debug(
|
|
2113
|
-
`pruneAuditLog failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2114
|
-
);
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
async function auditLogInstalled(exec) {
|
|
2118
|
-
try {
|
|
2119
|
-
const rows = extractRows(
|
|
2120
|
-
await exec(
|
|
2121
|
-
`SELECT to_regclass('public.ezlogs_audit_log') IS NOT NULL AS installed`,
|
|
2122
|
-
[]
|
|
2123
|
-
)
|
|
2124
|
-
);
|
|
2125
|
-
const installed = rows[0]?.installed;
|
|
2126
|
-
return typeof installed === "boolean" ? installed : null;
|
|
2127
|
-
} catch {
|
|
2128
|
-
return null;
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
async function checkAuditLogAccess(exec) {
|
|
2132
|
-
try {
|
|
2133
|
-
const rows = extractRows(
|
|
2134
|
-
await exec(
|
|
2135
|
-
`SELECT current_user AS role
|
|
2136
|
-
FROM pg_class c
|
|
2137
|
-
JOIN pg_roles r ON r.rolname = current_user
|
|
2138
|
-
WHERE c.oid = 'public.ezlogs_audit_log'::regclass
|
|
2139
|
-
AND c.relrowsecurity
|
|
2140
|
-
AND NOT r.rolsuper
|
|
2141
|
-
AND NOT r.rolbypassrls
|
|
2142
|
-
AND NOT pg_has_role(current_user, c.relowner, 'MEMBER')
|
|
2143
|
-
AND NOT EXISTS (SELECT 1 FROM pg_policies p
|
|
2144
|
-
WHERE p.schemaname = 'public'
|
|
2145
|
-
AND p.tablename = 'ezlogs_audit_log')`,
|
|
2146
|
-
[]
|
|
2147
|
-
)
|
|
2148
|
-
);
|
|
2149
|
-
const role = rows[0]?.role;
|
|
2150
|
-
if (typeof role !== "string") return false;
|
|
2151
|
-
logger.warn(
|
|
2152
|
-
`the database role "${role}" is not the owner of ezlogs_audit_log, which has row-level security, so the agent reads 0 rows and no DB changes are sent. As the table owner, run: GRANT SELECT, DELETE ON ezlogs_audit_log TO "${role}"; CREATE POLICY ezlogs_reader ON ezlogs_audit_log TO "${role}" USING (true);`
|
|
2153
|
-
);
|
|
2154
|
-
return true;
|
|
2155
|
-
} catch {
|
|
2156
|
-
return false;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
async function detectTriggerTrackedTables(exec) {
|
|
2160
|
-
try {
|
|
2161
|
-
const result = await exec(
|
|
2162
|
-
`SELECT event_object_table AS table_name
|
|
2163
|
-
FROM information_schema.triggers
|
|
2164
|
-
WHERE trigger_name = 'ezlogs_audit'
|
|
2165
|
-
AND trigger_schema = 'public'`,
|
|
2166
|
-
[]
|
|
2167
|
-
);
|
|
2168
|
-
const rows = extractRows(result);
|
|
2169
|
-
const tables = /* @__PURE__ */ new Set();
|
|
2170
|
-
for (const row of rows) {
|
|
2171
|
-
const r = row ?? {};
|
|
2172
|
-
if (typeof r.table_name === "string" && r.table_name.length > 0) {
|
|
2173
|
-
tables.add(r.table_name);
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
return tables;
|
|
2177
|
-
} catch (err) {
|
|
2178
|
-
logger.debug(
|
|
2179
|
-
`detectTriggerTrackedTables failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2180
|
-
);
|
|
2181
|
-
return null;
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
function emitAuditRows(rows) {
|
|
2185
|
-
for (const row of rows) {
|
|
2186
|
-
emitOne(row);
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
async function flushAuditLog(exec, options = {}) {
|
|
2190
|
-
if (!exec) return;
|
|
2191
|
-
const correlationId = current();
|
|
2192
|
-
if (!correlationId) return;
|
|
2193
|
-
const rows = await readAuditRows(exec, correlationId, options.since ?? null);
|
|
2194
|
-
await loadTableMeta(exec, rows);
|
|
2195
|
-
emitFresh(rows);
|
|
2196
|
-
const now = Date.now();
|
|
2197
|
-
if (now - lastPruneAt >= PRUNE_INTERVAL_MS) {
|
|
2198
|
-
lastPruneAt = now;
|
|
2199
|
-
await pruneAuditLog(exec);
|
|
2200
|
-
}
|
|
2201
|
-
if (now - lastSweepAt >= SWEEP_INTERVAL_MS) {
|
|
2202
|
-
lastSweepAt = now;
|
|
2203
|
-
await sweepAuditLog(exec);
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
2206
|
-
var tableMeta = /* @__PURE__ */ new Map();
|
|
2207
|
-
var META_RETRY_MS = 6e4;
|
|
2208
|
-
var metaRetryAt = 0;
|
|
2209
|
-
async function loadTableMeta(exec, rows) {
|
|
2210
|
-
if (Date.now() < metaRetryAt) return;
|
|
2211
|
-
const tables = [
|
|
2212
|
-
...new Set(rows.map((r) => r.table_name).filter((t) => t !== "" && !t.includes(",") && !tableMeta.has(t)))
|
|
2213
|
-
];
|
|
2214
|
-
if (tables.length === 0) return;
|
|
2215
|
-
const list = tables.join(",");
|
|
2216
|
-
try {
|
|
2217
|
-
const fkRows = extractRows(
|
|
2218
|
-
await exec(
|
|
2219
|
-
`SELECT cl.relname AS table_name, a.attname AS column_name, rf.relname AS ref_table
|
|
2220
|
-
FROM pg_constraint c
|
|
2221
|
-
JOIN pg_class cl ON cl.oid = c.conrelid
|
|
2222
|
-
JOIN pg_namespace n ON n.oid = cl.relnamespace
|
|
2223
|
-
JOIN pg_class rf ON rf.oid = c.confrelid
|
|
2224
|
-
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = c.conkey[1]
|
|
2225
|
-
WHERE c.contype = 'f'
|
|
2226
|
-
AND n.nspname = 'public'
|
|
2227
|
-
AND array_length(c.conkey, 1) = 1
|
|
2228
|
-
AND cl.relname = ANY(string_to_array($1, ','))
|
|
2229
|
-
ORDER BY cl.relname, a.attnum`,
|
|
2230
|
-
[list]
|
|
2231
|
-
)
|
|
2232
|
-
);
|
|
2233
|
-
const tsRows = extractRows(
|
|
2234
|
-
await exec(
|
|
2235
|
-
`SELECT cl.relname AS table_name, a.attname AS column_name
|
|
2236
|
-
FROM pg_attribute a
|
|
2237
|
-
JOIN pg_class cl ON cl.oid = a.attrelid
|
|
2238
|
-
JOIN pg_namespace n ON n.oid = cl.relnamespace
|
|
2239
|
-
WHERE n.nspname = 'public'
|
|
2240
|
-
AND cl.relname = ANY(string_to_array($1, ','))
|
|
2241
|
-
AND a.attnum > 0
|
|
2242
|
-
AND NOT a.attisdropped
|
|
2243
|
-
AND a.atttypid = 'timestamp'::regtype`,
|
|
2244
|
-
[list]
|
|
2245
|
-
)
|
|
2246
|
-
);
|
|
2247
|
-
const fks = /* @__PURE__ */ new Map();
|
|
2248
|
-
for (const raw of fkRows) {
|
|
2249
|
-
const r = raw ?? {};
|
|
2250
|
-
if (typeof r.table_name !== "string" || typeof r.column_name !== "string" || typeof r.ref_table !== "string") {
|
|
2251
|
-
continue;
|
|
2252
|
-
}
|
|
2253
|
-
fks.set(r.table_name, [...fks.get(r.table_name) ?? [], { column: r.column_name, refTable: r.ref_table }]);
|
|
2254
|
-
}
|
|
2255
|
-
const timestamps = /* @__PURE__ */ new Map();
|
|
2256
|
-
for (const raw of tsRows) {
|
|
2257
|
-
const r = raw ?? {};
|
|
2258
|
-
if (typeof r.table_name !== "string" || typeof r.column_name !== "string") continue;
|
|
2259
|
-
timestamps.set(r.table_name, (timestamps.get(r.table_name) ?? /* @__PURE__ */ new Set()).add(r.column_name));
|
|
2260
|
-
}
|
|
2261
|
-
for (const table of tables) {
|
|
2262
|
-
tableMeta.set(table, { fks: fks.get(table) ?? [], naiveTimestamps: timestamps.get(table) ?? /* @__PURE__ */ new Set() });
|
|
2263
|
-
}
|
|
2264
|
-
} catch (err) {
|
|
2265
|
-
metaRetryAt = Date.now() + META_RETRY_MS;
|
|
2266
|
-
logger.debug(`table metadata lookup failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
function relatedResourceIds(table, row) {
|
|
2270
|
-
const out = [];
|
|
2271
|
-
for (const fk of tableMeta.get(table)?.fks ?? []) {
|
|
2272
|
-
const value = row[fk.column];
|
|
2273
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
2274
|
-
out.push({ resource_type: fk.refTable, resource_id: String(value) });
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
return out;
|
|
2278
|
-
}
|
|
2279
|
-
function emitFresh(rows) {
|
|
2280
|
-
if (rows.length === 0) return;
|
|
2281
|
-
const emitted = currentEmittedAuditIds();
|
|
2282
|
-
if (emitted === null) {
|
|
2283
|
-
emitAuditRows(rows);
|
|
2284
|
-
return;
|
|
2285
|
-
}
|
|
2286
|
-
const fresh = [];
|
|
2287
|
-
for (const row of rows) {
|
|
2288
|
-
if (row.id === "" || emitted.has(row.id)) continue;
|
|
2289
|
-
emitted.add(row.id);
|
|
2290
|
-
fresh.push(row);
|
|
2291
|
-
}
|
|
2292
|
-
emitAuditRows(fresh);
|
|
2293
|
-
}
|
|
2294
|
-
function correlationForTx(txid) {
|
|
2295
|
-
if (!txid) return generate();
|
|
2296
|
-
let id = txCorrelation.get(txid);
|
|
2297
|
-
if (!id) {
|
|
2298
|
-
if (txCorrelation.size >= 1e3) txCorrelation.clear();
|
|
2299
|
-
id = generate();
|
|
2300
|
-
txCorrelation.set(txid, id);
|
|
2301
|
-
}
|
|
2302
|
-
return id;
|
|
2303
|
-
}
|
|
2304
|
-
function isPermissionDenied(err) {
|
|
2305
|
-
return err?.code === "42501";
|
|
2306
|
-
}
|
|
2307
|
-
function sortById(rows) {
|
|
2308
|
-
return rows.sort(
|
|
2309
|
-
(a, b) => a.id.length !== b.id.length ? a.id.length - b.id.length : a.id < b.id ? -1 : a.id > b.id ? 1 : 0
|
|
2310
|
-
);
|
|
2311
|
-
}
|
|
2312
|
-
function emitOne(row) {
|
|
2313
|
-
const op = mapOp(row.op);
|
|
2314
|
-
if (!op) return;
|
|
2315
|
-
const naive = tableMeta.get(row.table_name)?.naiveTimestamps ?? null;
|
|
2316
|
-
const oldRow = withUtcTimestamps(coerceJsonb(row.old_row), naive);
|
|
2317
|
-
const newRow = withUtcTimestamps(coerceJsonb(row.new_row), naive);
|
|
2318
|
-
const related = row.resource_id === null ? relatedResourceIds(row.table_name, newRow ?? oldRow ?? {}) : null;
|
|
2319
|
-
if (op === "create" && newRow) {
|
|
2320
|
-
emitDbEvent({
|
|
2321
|
-
modelClass: row.table_name,
|
|
2322
|
-
operation: "create",
|
|
2323
|
-
resourceId: row.resource_id,
|
|
2324
|
-
initialAttributes: newRow,
|
|
2325
|
-
modelInstance: newRow,
|
|
2326
|
-
displayName: null,
|
|
2327
|
-
timestamp: row.captured_at ?? null,
|
|
2328
|
-
relatedResourceIds: related,
|
|
2329
|
-
_fromTrigger: true
|
|
2330
|
-
});
|
|
2331
|
-
return;
|
|
2332
|
-
}
|
|
2333
|
-
if (op === "update" && oldRow && newRow) {
|
|
2334
|
-
const changes = computeChanges(oldRow, newRow);
|
|
2335
|
-
if (changes.length === 0) {
|
|
2336
|
-
return;
|
|
2337
|
-
}
|
|
2338
|
-
emitDbEvent({
|
|
2339
|
-
modelClass: row.table_name,
|
|
2340
|
-
operation: "update",
|
|
2341
|
-
resourceId: row.resource_id,
|
|
2342
|
-
changes,
|
|
2343
|
-
// Prefer the post-state for the display name — that's what the
|
|
2344
|
-
// user just told the system to call this row.
|
|
2345
|
-
modelInstance: newRow,
|
|
2346
|
-
displayName: null,
|
|
2347
|
-
timestamp: row.captured_at ?? null,
|
|
2348
|
-
relatedResourceIds: related,
|
|
2349
|
-
_fromTrigger: true
|
|
2350
|
-
});
|
|
2351
|
-
return;
|
|
2352
|
-
}
|
|
2353
|
-
if (op === "destroy" && oldRow) {
|
|
2354
|
-
emitDbEvent({
|
|
2355
|
-
modelClass: row.table_name,
|
|
2356
|
-
operation: "destroy",
|
|
2357
|
-
resourceId: row.resource_id,
|
|
2358
|
-
initialAttributes: oldRow,
|
|
2359
|
-
modelInstance: oldRow,
|
|
2360
|
-
displayName: null,
|
|
2361
|
-
timestamp: row.captured_at ?? null,
|
|
2362
|
-
relatedResourceIds: related,
|
|
2363
|
-
_fromTrigger: true
|
|
2364
|
-
});
|
|
2365
|
-
return;
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
var NAIVE_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/;
|
|
2369
|
-
function withUtcTimestamps(row, naiveColumns) {
|
|
2370
|
-
if (!row) return row;
|
|
2371
|
-
const out = {};
|
|
2372
|
-
for (const [key, value] of Object.entries(row)) {
|
|
2373
|
-
const isNaiveColumn = naiveColumns ? naiveColumns.has(key) : /(_at|At)$/.test(key);
|
|
2374
|
-
out[key] = isNaiveColumn && typeof value === "string" && NAIVE_TIMESTAMP.test(value) ? `${value}Z` : value;
|
|
2375
|
-
}
|
|
2376
|
-
return out;
|
|
2377
|
-
}
|
|
2378
|
-
function mapOp(op) {
|
|
2379
|
-
if (op === "INSERT") return "create";
|
|
2380
|
-
if (op === "UPDATE") return "update";
|
|
2381
|
-
if (op === "DELETE") return "destroy";
|
|
2382
|
-
return null;
|
|
2383
|
-
}
|
|
2384
|
-
function computeChanges(oldRow, newRow) {
|
|
2385
|
-
const out = [];
|
|
2386
|
-
for (const key of Object.keys(newRow)) {
|
|
2387
|
-
const before = oldRow[key];
|
|
2388
|
-
const after = newRow[key];
|
|
2389
|
-
if (deepEqual(before, after)) continue;
|
|
2390
|
-
out.push({ attribute: key, from: before, to: after });
|
|
2391
|
-
}
|
|
2392
|
-
return out;
|
|
2393
|
-
}
|
|
2394
|
-
function deepEqual(a, b) {
|
|
2395
|
-
if (a === b) return true;
|
|
2396
|
-
if (a === null || b === null) return false;
|
|
2397
|
-
if (typeof a !== typeof b) return false;
|
|
2398
|
-
if (typeof a !== "object") return false;
|
|
2399
|
-
try {
|
|
2400
|
-
return stableStringify(a) === stableStringify(b);
|
|
2401
|
-
} catch {
|
|
2402
|
-
return false;
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
function stableStringify(value) {
|
|
2406
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
2407
|
-
if (Array.isArray(value)) {
|
|
2408
|
-
return "[" + value.map((v) => stableStringify(v)).join(",") + "]";
|
|
2409
|
-
}
|
|
2410
|
-
const entries = Object.keys(value).sort().map((k) => JSON.stringify(k) + ":" + stableStringify(value[k]));
|
|
2411
|
-
return "{" + entries.join(",") + "}";
|
|
2412
|
-
}
|
|
2413
|
-
function extractRows(result) {
|
|
2414
|
-
if (!result) return [];
|
|
2415
|
-
if (Array.isArray(result)) return result;
|
|
2416
|
-
if (typeof result === "object" && Array.isArray(result.rows)) {
|
|
2417
|
-
return result.rows;
|
|
2418
|
-
}
|
|
2419
|
-
return [];
|
|
2420
|
-
}
|
|
2421
|
-
function toDate(value) {
|
|
2422
|
-
if (value == null) return null;
|
|
2423
|
-
const d = value instanceof Date ? value : new Date(String(value));
|
|
2424
|
-
return Number.isNaN(d.getTime()) ? null : d;
|
|
2425
|
-
}
|
|
2426
|
-
function normalizeAuditRow(raw) {
|
|
2427
|
-
const r = raw ?? {};
|
|
2428
|
-
return {
|
|
2429
|
-
id: r.id == null ? "" : String(r.id),
|
|
2430
|
-
table_name: String(r.table_name ?? ""),
|
|
2431
|
-
op: r.op,
|
|
2432
|
-
old_row: r.old_row ?? null,
|
|
2433
|
-
new_row: r.new_row ?? null,
|
|
2434
|
-
resource_id: r.resource_id == null ? null : String(r.resource_id),
|
|
2435
|
-
correlation_id: r.correlation_id == null ? null : String(r.correlation_id),
|
|
2436
|
-
txid: r.txid == null ? null : String(r.txid),
|
|
2437
|
-
captured_at: toDate(r.captured_at)
|
|
2438
|
-
};
|
|
2439
|
-
}
|
|
2440
|
-
function coerceJsonb(value) {
|
|
2441
|
-
if (value === null || value === void 0) return null;
|
|
2442
|
-
if (typeof value === "string") {
|
|
2443
|
-
try {
|
|
2444
|
-
const parsed = JSON.parse(value);
|
|
2445
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
2446
|
-
} catch {
|
|
2447
|
-
return null;
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
if (typeof value === "object" && !Array.isArray(value)) return value;
|
|
2451
|
-
return null;
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
// src/index.ts
|
|
2455
|
-
init_logger();
|
|
2456
|
-
init_event_builder();
|
|
2457
|
-
|
|
2458
|
-
// src/http/capture.ts
|
|
2459
|
-
init_configuration();
|
|
2460
|
-
init_logger();
|
|
2461
|
-
init_event_builder();
|
|
2462
|
-
init_buffer();
|
|
2463
|
-
|
|
2464
239
|
// src/pipeline/serverless.ts
|
|
2465
240
|
var cachedFlag = null;
|
|
2466
241
|
function isServerless() {
|
|
@@ -2480,9 +255,6 @@ function detect() {
|
|
|
2480
255
|
return false;
|
|
2481
256
|
}
|
|
2482
257
|
|
|
2483
|
-
// src/http/capture.ts
|
|
2484
|
-
init_actor();
|
|
2485
|
-
|
|
2486
258
|
// src/user-agent-detector.ts
|
|
2487
259
|
var PATTERNS = [
|
|
2488
260
|
{ prefix: "claude-", vendor: "claude", label: "Claude" },
|
|
@@ -2506,10 +278,6 @@ function classifyUserAgent(userAgent) {
|
|
|
2506
278
|
};
|
|
2507
279
|
}
|
|
2508
280
|
|
|
2509
|
-
// src/http/capture.ts
|
|
2510
|
-
init_correlation();
|
|
2511
|
-
init_sanitize();
|
|
2512
|
-
|
|
2513
281
|
// src/http/path-matcher.ts
|
|
2514
282
|
function pathMatches(path, pattern) {
|
|
2515
283
|
const startsWithStar = pattern.startsWith("*");
|
|
@@ -2533,11 +301,7 @@ function hasExcludedExtension(path, extensions) {
|
|
|
2533
301
|
return extensions.some((ext) => path.endsWith(ext));
|
|
2534
302
|
}
|
|
2535
303
|
|
|
2536
|
-
// src/http/capture.ts
|
|
2537
|
-
init_configuration();
|
|
2538
|
-
|
|
2539
304
|
// src/http/source-data.ts
|
|
2540
|
-
init_sanitize();
|
|
2541
305
|
function buildHttpSourceData(input) {
|
|
2542
306
|
const { controller, action } = resolveControllerAction(input);
|
|
2543
307
|
const source = {
|
|
@@ -2566,7 +330,7 @@ function buildHttpSourceData(input) {
|
|
|
2566
330
|
source.graphql_variables = input.graphql.graphql_variables;
|
|
2567
331
|
}
|
|
2568
332
|
} else {
|
|
2569
|
-
const params = sanitizeRequestParams(input.rawParams, input.excludedVariableKeys);
|
|
333
|
+
const params = chunkWASXTDLW_cjs.sanitizeRequestParams(input.rawParams, input.excludedVariableKeys);
|
|
2570
334
|
if (params !== null) source.request_params = params;
|
|
2571
335
|
}
|
|
2572
336
|
return compact(source);
|
|
@@ -2711,14 +475,13 @@ function determineOutcome(statusCode, exception, graphqlResponseErrors, response
|
|
|
2711
475
|
}
|
|
2712
476
|
|
|
2713
477
|
// src/http/graphql.ts
|
|
2714
|
-
init_sanitize();
|
|
2715
478
|
var QUERY_PREFIXES = ["Get", "Fetch", "List", "Find", "Load", "Search", "Query"];
|
|
2716
479
|
var MUTATION_PREFIXES = ["Create", "Update", "Delete", "Remove", "Add", "Set", "Upsert"];
|
|
2717
480
|
function isGraphqlPath(path) {
|
|
2718
481
|
return path === "/graphql" || path.startsWith("/graphql/");
|
|
2719
482
|
}
|
|
2720
483
|
function parseGraphqlBody(body, excludedOperations, excludedVariableKeys) {
|
|
2721
|
-
if (!
|
|
484
|
+
if (!isPlainObject(body)) return { metadata: null };
|
|
2722
485
|
const obj = body;
|
|
2723
486
|
const queryString = typeof obj.query === "string" ? obj.query : null;
|
|
2724
487
|
let operationName = typeof obj.operationName === "string" ? obj.operationName : null;
|
|
@@ -2729,7 +492,7 @@ function parseGraphqlBody(body, excludedOperations, excludedVariableKeys) {
|
|
|
2729
492
|
return { metadata: "skip" };
|
|
2730
493
|
}
|
|
2731
494
|
const operationType = inferOperationTypeFromQuery(queryString) ?? inferOperationTypeFromName(operationName);
|
|
2732
|
-
const sanitizedVariables = sanitizeRequestParams(obj.variables, excludedVariableKeys);
|
|
495
|
+
const sanitizedVariables = chunkWASXTDLW_cjs.sanitizeRequestParams(obj.variables, excludedVariableKeys);
|
|
2733
496
|
return {
|
|
2734
497
|
metadata: {
|
|
2735
498
|
graphql_operation: operationName ?? "anonymous",
|
|
@@ -2765,14 +528,14 @@ function isExcludedOperation(name, patterns) {
|
|
|
2765
528
|
});
|
|
2766
529
|
}
|
|
2767
530
|
function extractGraphqlErrorsFromBody(parsed) {
|
|
2768
|
-
if (!
|
|
531
|
+
if (!isPlainObject(parsed)) return null;
|
|
2769
532
|
const errors = parsed.errors;
|
|
2770
533
|
if (!Array.isArray(errors) || errors.length === 0) return null;
|
|
2771
|
-
const messages = errors.map((err) =>
|
|
534
|
+
const messages = errors.map((err) => isPlainObject(err) ? err.message : null).filter((m) => typeof m === "string" && m.length > 0);
|
|
2772
535
|
if (messages.length === 0) return null;
|
|
2773
536
|
return messages.length === 1 ? messages[0] : messages.join("; ");
|
|
2774
537
|
}
|
|
2775
|
-
function
|
|
538
|
+
function isPlainObject(value) {
|
|
2776
539
|
if (value === null || typeof value !== "object") return false;
|
|
2777
540
|
const proto = Object.getPrototypeOf(value);
|
|
2778
541
|
return proto === Object.prototype || proto === null;
|
|
@@ -2787,7 +550,7 @@ function captureRoute(handler, context = {}) {
|
|
|
2787
550
|
return handler(...invokeArgs);
|
|
2788
551
|
};
|
|
2789
552
|
try {
|
|
2790
|
-
if (!configuration().captureHttp) {
|
|
553
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) {
|
|
2791
554
|
return Promise.resolve(runHandler(...args));
|
|
2792
555
|
}
|
|
2793
556
|
const request = args[0];
|
|
@@ -2797,8 +560,8 @@ function captureRoute(handler, context = {}) {
|
|
|
2797
560
|
const snapshot = await snapshotRequest(request);
|
|
2798
561
|
if (snapshot === null) return Promise.resolve(runHandler(...args));
|
|
2799
562
|
snapshot.rawParams = mergeRouteParams(snapshot.rawParams, await readRouteParams(args[1]));
|
|
2800
|
-
const correlationId = resolveCorrelation(request.headers ?? null);
|
|
2801
|
-
return await runWithCorrelation(
|
|
563
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation(request.headers ?? null);
|
|
564
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2802
565
|
correlationId,
|
|
2803
566
|
() => runWithActorAndAuditScope(async () => {
|
|
2804
567
|
await maybeRunActorHook(request);
|
|
@@ -2846,14 +609,14 @@ function captureRoute(handler, context = {}) {
|
|
|
2846
609
|
);
|
|
2847
610
|
} catch (preCaptureError) {
|
|
2848
611
|
if (handlerInvoked) throw preCaptureError;
|
|
2849
|
-
logger.warn(
|
|
2850
|
-
`captureRoute pre-handler setup failed (${
|
|
612
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
613
|
+
`captureRoute pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this request`
|
|
2851
614
|
);
|
|
2852
615
|
return Promise.resolve(handler(...args));
|
|
2853
616
|
}
|
|
2854
617
|
};
|
|
2855
618
|
}
|
|
2856
|
-
var
|
|
619
|
+
var CORRELATION_HEADER = "x-ezlogs-correlation-id";
|
|
2857
620
|
function withMiddlewareCapture(middleware) {
|
|
2858
621
|
return async (request, ...rest) => {
|
|
2859
622
|
let middlewareInvoked = false;
|
|
@@ -2862,12 +625,12 @@ function withMiddlewareCapture(middleware) {
|
|
|
2862
625
|
return middleware(req, ...mRest);
|
|
2863
626
|
};
|
|
2864
627
|
try {
|
|
2865
|
-
const correlationId = resolveCorrelation(request.headers);
|
|
628
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation(request.headers);
|
|
2866
629
|
try {
|
|
2867
|
-
request.headers.set(
|
|
630
|
+
request.headers.set(CORRELATION_HEADER, correlationId);
|
|
2868
631
|
} catch {
|
|
2869
632
|
}
|
|
2870
|
-
return await runWithCorrelation(
|
|
633
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2871
634
|
correlationId,
|
|
2872
635
|
() => runWithActorAndAuditScope(async () => {
|
|
2873
636
|
const startMs = Date.now();
|
|
@@ -2875,7 +638,7 @@ function withMiddlewareCapture(middleware) {
|
|
|
2875
638
|
const response = await Promise.resolve(runMiddleware(request, ...rest));
|
|
2876
639
|
try {
|
|
2877
640
|
if (response?.headers && typeof response.headers.set === "function") {
|
|
2878
|
-
response.headers.set(
|
|
641
|
+
response.headers.set(CORRELATION_HEADER, correlationId);
|
|
2879
642
|
}
|
|
2880
643
|
} catch {
|
|
2881
644
|
}
|
|
@@ -2891,15 +654,15 @@ function withMiddlewareCapture(middleware) {
|
|
|
2891
654
|
});
|
|
2892
655
|
}
|
|
2893
656
|
} catch (error) {
|
|
2894
|
-
logger.debug(`page navigation capture failed: ${
|
|
657
|
+
chunkV5YNKKTG_cjs.logger.debug(`page navigation capture failed: ${describeError5(error)}`);
|
|
2895
658
|
}
|
|
2896
659
|
return response;
|
|
2897
660
|
})
|
|
2898
661
|
);
|
|
2899
662
|
} catch (preCaptureError) {
|
|
2900
663
|
if (middlewareInvoked) throw preCaptureError;
|
|
2901
|
-
logger.warn(
|
|
2902
|
-
`withMiddlewareCapture pre-handler setup failed (${
|
|
664
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
665
|
+
`withMiddlewareCapture pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this request`
|
|
2903
666
|
);
|
|
2904
667
|
return await Promise.resolve(middleware(request, ...rest));
|
|
2905
668
|
}
|
|
@@ -2939,27 +702,27 @@ async function emitPageNavigationEvent(input) {
|
|
|
2939
702
|
userAgent,
|
|
2940
703
|
remoteIp,
|
|
2941
704
|
contentType: null,
|
|
2942
|
-
excludedVariableKeys: configuration().excludedGraphqlVariableKeys
|
|
705
|
+
excludedVariableKeys: chunkWASXTDLW_cjs.configuration().excludedGraphqlVariableKeys
|
|
2943
706
|
});
|
|
2944
707
|
const { outcome, error_message } = determineOutcome(
|
|
2945
708
|
input.statusCode,
|
|
2946
709
|
null,
|
|
2947
710
|
null
|
|
2948
711
|
);
|
|
2949
|
-
const event = build({
|
|
712
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
2950
713
|
source_type: "http_request",
|
|
2951
714
|
source_data: sourceData,
|
|
2952
715
|
outcome,
|
|
2953
|
-
correlation_id: current(),
|
|
716
|
+
correlation_id: chunkWASXTDLW_cjs.current(),
|
|
2954
717
|
resource_ids: [],
|
|
2955
|
-
context: getCurrentActor() ? { actor: getCurrentActor() } : null,
|
|
718
|
+
context: chunkWASXTDLW_cjs.getCurrentActor() ? { actor: chunkWASXTDLW_cjs.getCurrentActor() } : null,
|
|
2956
719
|
duration_ms: input.durationMs,
|
|
2957
720
|
error_message,
|
|
2958
721
|
timestamp: input.startedAt
|
|
2959
722
|
});
|
|
2960
|
-
pushEvent(event);
|
|
723
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
2961
724
|
} catch (error) {
|
|
2962
|
-
logger.error(`page navigation emit failed: ${
|
|
725
|
+
chunkV5YNKKTG_cjs.logger.error(`page navigation emit failed: ${describeError5(error)}`);
|
|
2963
726
|
}
|
|
2964
727
|
}
|
|
2965
728
|
function pageControllerFromPath(pathname) {
|
|
@@ -2982,7 +745,7 @@ function capturePagesApi(handler, context = {}) {
|
|
|
2982
745
|
return handler(...invokeArgs);
|
|
2983
746
|
};
|
|
2984
747
|
try {
|
|
2985
|
-
if (!configuration().captureHttp) {
|
|
748
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) {
|
|
2986
749
|
return Promise.resolve(runHandler(...args));
|
|
2987
750
|
}
|
|
2988
751
|
const req = args[0];
|
|
@@ -2990,10 +753,10 @@ function capturePagesApi(handler, context = {}) {
|
|
|
2990
753
|
if (!req || !res) return Promise.resolve(runHandler(...args));
|
|
2991
754
|
const snapshot = snapshotPagesRequest(req);
|
|
2992
755
|
if (snapshot === null) return Promise.resolve(runHandler(...args));
|
|
2993
|
-
const correlationId = resolveCorrelation({
|
|
756
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation({
|
|
2994
757
|
get: (name) => readPagesHeader(req, name)
|
|
2995
758
|
});
|
|
2996
|
-
return await runWithCorrelation(
|
|
759
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2997
760
|
correlationId,
|
|
2998
761
|
() => runWithActorAndAuditScope(async () => {
|
|
2999
762
|
await maybeRunActorHookFromPages(req);
|
|
@@ -3024,8 +787,8 @@ function capturePagesApi(handler, context = {}) {
|
|
|
3024
787
|
);
|
|
3025
788
|
} catch (preCaptureError) {
|
|
3026
789
|
if (handlerInvoked) throw preCaptureError;
|
|
3027
|
-
logger.warn(
|
|
3028
|
-
`capturePagesApi pre-handler setup failed (${
|
|
790
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
791
|
+
`capturePagesApi pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this request`
|
|
3029
792
|
);
|
|
3030
793
|
return Promise.resolve(handler(...args));
|
|
3031
794
|
}
|
|
@@ -3039,12 +802,12 @@ function captureServerAction(action, actionName) {
|
|
|
3039
802
|
return action(...invokeArgs);
|
|
3040
803
|
};
|
|
3041
804
|
try {
|
|
3042
|
-
if (!configuration().captureHttp) {
|
|
805
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) {
|
|
3043
806
|
return Promise.resolve(runAction(...args));
|
|
3044
807
|
}
|
|
3045
808
|
const headersAdapter = await readNextHeadersAsAdapter();
|
|
3046
|
-
const correlationId = resolveCorrelation(headersAdapter);
|
|
3047
|
-
return await runWithCorrelation(
|
|
809
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation(headersAdapter);
|
|
810
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
3048
811
|
correlationId,
|
|
3049
812
|
() => runWithActorAndAuditScope(async () => {
|
|
3050
813
|
const startMs = Date.now();
|
|
@@ -3103,8 +866,8 @@ function captureServerAction(action, actionName) {
|
|
|
3103
866
|
);
|
|
3104
867
|
} catch (preCaptureError) {
|
|
3105
868
|
if (actionInvoked) throw preCaptureError;
|
|
3106
|
-
logger.warn(
|
|
3107
|
-
`captureServerAction pre-handler setup failed (${
|
|
869
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
870
|
+
`captureServerAction pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this action`
|
|
3108
871
|
);
|
|
3109
872
|
return Promise.resolve(action(...args));
|
|
3110
873
|
}
|
|
@@ -3125,7 +888,7 @@ async function __ezlogs_run_inline_server_action(actionName, body) {
|
|
|
3125
888
|
return wrapped();
|
|
3126
889
|
}
|
|
3127
890
|
function classifyServerActionResult(result) {
|
|
3128
|
-
const classifier = configuration().isServerActionError;
|
|
891
|
+
const classifier = chunkWASXTDLW_cjs.configuration().isServerActionError;
|
|
3129
892
|
if (classifier) {
|
|
3130
893
|
try {
|
|
3131
894
|
const verdict = classifier(result);
|
|
@@ -3136,7 +899,7 @@ function classifyServerActionResult(result) {
|
|
|
3136
899
|
return verdict;
|
|
3137
900
|
}
|
|
3138
901
|
} catch (error) {
|
|
3139
|
-
logger.debug(`isServerActionError classifier threw: ${
|
|
902
|
+
chunkV5YNKKTG_cjs.logger.debug(`isServerActionError classifier threw: ${describeError5(error)}`);
|
|
3140
903
|
}
|
|
3141
904
|
}
|
|
3142
905
|
if (Array.isArray(result) && result.length === 2 && result[0] === null && isZsaError(result[1])) {
|
|
@@ -3297,27 +1060,27 @@ async function emitServerActionEvent(input) {
|
|
|
3297
1060
|
userAgent,
|
|
3298
1061
|
remoteIp: extractRemoteIp(await readNextHeadersAsAdapter()),
|
|
3299
1062
|
contentType: null,
|
|
3300
|
-
excludedVariableKeys: configuration().excludedGraphqlVariableKeys
|
|
1063
|
+
excludedVariableKeys: chunkWASXTDLW_cjs.configuration().excludedGraphqlVariableKeys
|
|
3301
1064
|
});
|
|
3302
1065
|
const { outcome, error_message } = determineOutcome(
|
|
3303
1066
|
input.statusCode,
|
|
3304
1067
|
input.exception,
|
|
3305
1068
|
null
|
|
3306
1069
|
);
|
|
3307
|
-
const event = build({
|
|
1070
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
3308
1071
|
source_type: "http_request",
|
|
3309
1072
|
source_data: sourceData,
|
|
3310
1073
|
outcome,
|
|
3311
|
-
correlation_id: current(),
|
|
1074
|
+
correlation_id: chunkWASXTDLW_cjs.current(),
|
|
3312
1075
|
resource_ids: [],
|
|
3313
|
-
context: getCurrentActor() ? { actor: getCurrentActor() } : null,
|
|
1076
|
+
context: chunkWASXTDLW_cjs.getCurrentActor() ? { actor: chunkWASXTDLW_cjs.getCurrentActor() } : null,
|
|
3314
1077
|
duration_ms: input.durationMs,
|
|
3315
1078
|
error_message,
|
|
3316
1079
|
timestamp: input.startedAt
|
|
3317
1080
|
});
|
|
3318
|
-
pushEvent(event);
|
|
1081
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
3319
1082
|
} catch (error) {
|
|
3320
|
-
logger.error(`server-action capture emit failed: ${
|
|
1083
|
+
chunkV5YNKKTG_cjs.logger.error(`server-action capture emit failed: ${describeError5(error)}`);
|
|
3321
1084
|
}
|
|
3322
1085
|
}
|
|
3323
1086
|
function extractServerActionArgs(args, actionName) {
|
|
@@ -3398,7 +1161,7 @@ function actionWords(name) {
|
|
|
3398
1161
|
return name.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([a-zA-Z])(\d)/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
3399
1162
|
}
|
|
3400
1163
|
function looksLikeCardNumber(digits, paymentAction) {
|
|
3401
|
-
if (digits.length < 13 || digits.length > 19 || !passesLuhn(digits)) return false;
|
|
1164
|
+
if (digits.length < 13 || digits.length > 19 || !chunkWASXTDLW_cjs.passesLuhn(digits)) return false;
|
|
3402
1165
|
return paymentAction || digits.length === 15 || digits.length === 16;
|
|
3403
1166
|
}
|
|
3404
1167
|
function maskPositional(value, flags) {
|
|
@@ -3486,7 +1249,7 @@ function serializeArgValue(value) {
|
|
|
3486
1249
|
return void 0;
|
|
3487
1250
|
}
|
|
3488
1251
|
async function captureHttpEvent(input) {
|
|
3489
|
-
if (!configuration().captureHttp) return;
|
|
1252
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) return;
|
|
3490
1253
|
const snapshot = await snapshotRequest(input.request);
|
|
3491
1254
|
if (snapshot === null) return;
|
|
3492
1255
|
let graphqlErrorMessage = null;
|
|
@@ -3547,59 +1310,59 @@ async function snapshotRequest(request) {
|
|
|
3547
1310
|
}
|
|
3548
1311
|
}
|
|
3549
1312
|
} catch (error) {
|
|
3550
|
-
logger.debug(`http snapshot body-parse failed: ${
|
|
1313
|
+
chunkV5YNKKTG_cjs.logger.debug(`http snapshot body-parse failed: ${describeError5(error)}`);
|
|
3551
1314
|
}
|
|
3552
1315
|
return { method, url, userAgent, remoteIp, contentType, rawParams, graphqlBody, serverActionId };
|
|
3553
1316
|
}
|
|
3554
1317
|
async function maybeRunActorHook(request) {
|
|
3555
|
-
const hook = configuration().actorFromRequest;
|
|
1318
|
+
const hook = chunkWASXTDLW_cjs.configuration().actorFromRequest;
|
|
3556
1319
|
let hookResult = null;
|
|
3557
1320
|
if (hook) {
|
|
3558
1321
|
try {
|
|
3559
1322
|
hookResult = await Promise.resolve(hook(request));
|
|
3560
1323
|
} catch (error) {
|
|
3561
|
-
logger.debug(`actorFromRequest hook failed: ${
|
|
1324
|
+
chunkV5YNKKTG_cjs.logger.debug(`actorFromRequest hook failed: ${describeError5(error)}`);
|
|
3562
1325
|
}
|
|
3563
1326
|
}
|
|
3564
1327
|
const userAgent = safeGetHeader(request.headers, "user-agent");
|
|
3565
1328
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
3566
1329
|
}
|
|
3567
1330
|
async function maybeRunActorHookFromPages(req) {
|
|
3568
|
-
const hook = configuration().actorFromRequest;
|
|
1331
|
+
const hook = chunkWASXTDLW_cjs.configuration().actorFromRequest;
|
|
3569
1332
|
let hookResult = null;
|
|
3570
1333
|
if (hook) {
|
|
3571
1334
|
try {
|
|
3572
1335
|
hookResult = await Promise.resolve(hook(req));
|
|
3573
1336
|
} catch (error) {
|
|
3574
|
-
logger.debug(`actorFromRequest hook (pages) failed: ${
|
|
1337
|
+
chunkV5YNKKTG_cjs.logger.debug(`actorFromRequest hook (pages) failed: ${describeError5(error)}`);
|
|
3575
1338
|
}
|
|
3576
1339
|
}
|
|
3577
1340
|
const userAgent = readPagesHeader(req, "user-agent");
|
|
3578
1341
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
3579
1342
|
}
|
|
3580
1343
|
async function maybeRunActorHookFromServerAction() {
|
|
3581
|
-
const hook = configuration().actorFromRequest;
|
|
1344
|
+
const hook = chunkWASXTDLW_cjs.configuration().actorFromRequest;
|
|
3582
1345
|
const headers = await loadNextHeaders();
|
|
3583
1346
|
if (!hook && !headers) {
|
|
3584
|
-
logger.debug("actorFromRequest (server action): no hook + no next/headers");
|
|
1347
|
+
chunkV5YNKKTG_cjs.logger.debug("actorFromRequest (server action): no hook + no next/headers");
|
|
3585
1348
|
return;
|
|
3586
1349
|
}
|
|
3587
1350
|
let hookResult = null;
|
|
3588
1351
|
if (hook) {
|
|
3589
1352
|
if (!headers) {
|
|
3590
|
-
logger.debug(
|
|
1353
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
3591
1354
|
"actorFromRequest hook (server action): skipped, no next/headers available"
|
|
3592
1355
|
);
|
|
3593
1356
|
} else {
|
|
3594
1357
|
const facade = { headers, method: "POST", url: "" };
|
|
3595
1358
|
try {
|
|
3596
1359
|
hookResult = await Promise.resolve(hook(facade));
|
|
3597
|
-
logger.debug(
|
|
1360
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
3598
1361
|
hookResult ? `actorFromRequest hook (server action): set actor id=${hookResult.id ?? "?"}` : "actorFromRequest hook (server action): returned null/undefined"
|
|
3599
1362
|
);
|
|
3600
1363
|
} catch (error) {
|
|
3601
|
-
logger.debug(
|
|
3602
|
-
`actorFromRequest hook (server action) failed: ${
|
|
1364
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
1365
|
+
`actorFromRequest hook (server action) failed: ${describeError5(error)}`
|
|
3603
1366
|
);
|
|
3604
1367
|
}
|
|
3605
1368
|
}
|
|
@@ -3608,15 +1371,15 @@ async function maybeRunActorHookFromServerAction() {
|
|
|
3608
1371
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
3609
1372
|
}
|
|
3610
1373
|
async function maybeExtractSupabaseActor() {
|
|
3611
|
-
const config = configuration();
|
|
1374
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3612
1375
|
if (!config.actorFromSupabase) return;
|
|
3613
|
-
if (getCurrentActor()) return;
|
|
1376
|
+
if (chunkWASXTDLW_cjs.getCurrentActor()) return;
|
|
3614
1377
|
try {
|
|
3615
|
-
const mod = await
|
|
1378
|
+
const mod = await import('./db/supabase.cjs');
|
|
3616
1379
|
const actor = await mod.tryExtractSupabaseActor();
|
|
3617
|
-
if (actor) setActor(actor);
|
|
1380
|
+
if (actor) chunkWASXTDLW_cjs.setActor(actor);
|
|
3618
1381
|
} catch (error) {
|
|
3619
|
-
logger.debug(`actorFromSupabase failed: ${
|
|
1382
|
+
chunkV5YNKKTG_cjs.logger.debug(`actorFromSupabase failed: ${describeError5(error)}`);
|
|
3620
1383
|
}
|
|
3621
1384
|
}
|
|
3622
1385
|
function snapshotPagesRequest(req) {
|
|
@@ -3693,7 +1456,7 @@ async function loadNextHeaders() {
|
|
|
3693
1456
|
try {
|
|
3694
1457
|
return await Promise.resolve(mod.headers());
|
|
3695
1458
|
} catch (error) {
|
|
3696
|
-
logger.debug(`loadNextHeaders mod.headers() failed: ${
|
|
1459
|
+
chunkV5YNKKTG_cjs.logger.debug(`loadNextHeaders mod.headers() failed: ${describeError5(error)}`);
|
|
3697
1460
|
return null;
|
|
3698
1461
|
}
|
|
3699
1462
|
}
|
|
@@ -3704,8 +1467,8 @@ async function tryLoadNextHeadersModule() {
|
|
|
3704
1467
|
try {
|
|
3705
1468
|
return await import('next/headers.js');
|
|
3706
1469
|
} catch (secondError) {
|
|
3707
|
-
logger.debug(
|
|
3708
|
-
`loadNextHeaders: neither "next/headers" nor "next/headers.js" resolved (${
|
|
1470
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
1471
|
+
`loadNextHeaders: neither "next/headers" nor "next/headers.js" resolved (${describeError5(firstError)}; ${describeError5(secondError)})`
|
|
3709
1472
|
);
|
|
3710
1473
|
return null;
|
|
3711
1474
|
}
|
|
@@ -3723,7 +1486,7 @@ function readPagesHeader(req, name) {
|
|
|
3723
1486
|
async function emitEvent(input) {
|
|
3724
1487
|
try {
|
|
3725
1488
|
await flushTriggerAuditLog();
|
|
3726
|
-
const config = configuration();
|
|
1489
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3727
1490
|
let graphql = null;
|
|
3728
1491
|
if (input.snapshot.graphqlBody !== null) {
|
|
3729
1492
|
const parsed = parseGraphqlBody(
|
|
@@ -3755,43 +1518,43 @@ async function emitEvent(input) {
|
|
|
3755
1518
|
input.graphqlErrorMessage,
|
|
3756
1519
|
input.responseErrorMessage ?? null
|
|
3757
1520
|
);
|
|
3758
|
-
const contextValue =
|
|
3759
|
-
const event = build({
|
|
1521
|
+
const contextValue = buildContext();
|
|
1522
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
3760
1523
|
source_type: "http_request",
|
|
3761
1524
|
source_data: sourceData,
|
|
3762
1525
|
outcome,
|
|
3763
|
-
correlation_id: current(),
|
|
1526
|
+
correlation_id: chunkWASXTDLW_cjs.current(),
|
|
3764
1527
|
resource_ids: [],
|
|
3765
1528
|
context: contextValue,
|
|
3766
1529
|
duration_ms: input.durationMs,
|
|
3767
1530
|
error_message,
|
|
3768
1531
|
timestamp: input.startedAt
|
|
3769
1532
|
});
|
|
3770
|
-
pushEvent(event);
|
|
1533
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
3771
1534
|
} catch (error) {
|
|
3772
|
-
const cid = current();
|
|
1535
|
+
const cid = chunkWASXTDLW_cjs.current();
|
|
3773
1536
|
const cidLabel = cid ? ` (correlation_id=${cid})` : "";
|
|
3774
|
-
logger.error(`http capture emit failed${cidLabel}: ${
|
|
1537
|
+
chunkV5YNKKTG_cjs.logger.error(`http capture emit failed${cidLabel}: ${describeError5(error)}`);
|
|
3775
1538
|
}
|
|
3776
1539
|
}
|
|
3777
|
-
function
|
|
3778
|
-
const currentActor = getCurrentActor();
|
|
1540
|
+
function buildContext() {
|
|
1541
|
+
const currentActor = chunkWASXTDLW_cjs.getCurrentActor();
|
|
3779
1542
|
if (!currentActor) return null;
|
|
3780
1543
|
return { actor: currentActor };
|
|
3781
1544
|
}
|
|
3782
1545
|
async function flushTriggerAuditLog() {
|
|
3783
|
-
const reader = configuration().databaseReader;
|
|
1546
|
+
const reader = chunkWASXTDLW_cjs.configuration().databaseReader;
|
|
3784
1547
|
if (!reader) return;
|
|
3785
|
-
await flushAuditLog(reader);
|
|
1548
|
+
await chunkYX2XPLOA_cjs.flushAuditLog(reader);
|
|
3786
1549
|
}
|
|
3787
1550
|
function runWithActorAndAuditScope(callback) {
|
|
3788
|
-
if (configuration().databaseReader == null) {
|
|
3789
|
-
return runWithActorScope(callback);
|
|
1551
|
+
if (chunkWASXTDLW_cjs.configuration().databaseReader == null) {
|
|
1552
|
+
return chunkWASXTDLW_cjs.runWithActorScope(callback);
|
|
3790
1553
|
}
|
|
3791
|
-
return runWithActorScope(() => runWithEmittedAuditIdsScope(callback));
|
|
1554
|
+
return chunkWASXTDLW_cjs.runWithActorScope(() => chunkYX2XPLOA_cjs.runWithEmittedAuditIdsScope(callback));
|
|
3792
1555
|
}
|
|
3793
1556
|
function isExcludedPath(path, method) {
|
|
3794
|
-
const config = configuration();
|
|
1557
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3795
1558
|
const normalizedMethod = (method ?? "").toUpperCase();
|
|
3796
1559
|
for (const pattern of config.allExcludedPaths()) {
|
|
3797
1560
|
if (typeof pattern === "string") {
|
|
@@ -3803,7 +1566,7 @@ function isExcludedPath(path, method) {
|
|
|
3803
1566
|
return true;
|
|
3804
1567
|
}
|
|
3805
1568
|
}
|
|
3806
|
-
if (hasExcludedExtension(path, DEFAULT_EXCLUDED_EXTENSIONS)) return true;
|
|
1569
|
+
if (hasExcludedExtension(path, chunkWASXTDLW_cjs.DEFAULT_EXCLUDED_EXTENSIONS)) return true;
|
|
3807
1570
|
return false;
|
|
3808
1571
|
}
|
|
3809
1572
|
function extractRemoteIp(headers) {
|
|
@@ -3854,7 +1617,7 @@ async function readResponseErrorMessage(response) {
|
|
|
3854
1617
|
const raw = [body.error, body.message, nested?.message].find(
|
|
3855
1618
|
(v) => typeof v === "string" && v.trim().length > 0
|
|
3856
1619
|
);
|
|
3857
|
-
return raw ? truncate(scrubSecretsInText(raw.trim(), { emails: true })) : null;
|
|
1620
|
+
return raw ? truncate(chunkWASXTDLW_cjs.scrubSecretsInText(raw.trim(), { emails: true })) : null;
|
|
3858
1621
|
} catch {
|
|
3859
1622
|
return null;
|
|
3860
1623
|
}
|
|
@@ -3870,7 +1633,7 @@ async function readGraphqlErrors(response) {
|
|
|
3870
1633
|
return null;
|
|
3871
1634
|
}
|
|
3872
1635
|
}
|
|
3873
|
-
function
|
|
1636
|
+
function describeError5(error) {
|
|
3874
1637
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
3875
1638
|
return String(error);
|
|
3876
1639
|
}
|
|
@@ -3878,23 +1641,23 @@ function applyActorFromHookAndUa(hookResult, userAgent) {
|
|
|
3878
1641
|
const uaMatch = classifyUserAgent(userAgent);
|
|
3879
1642
|
if (hookResult != null && typeof hookResult === "object" && !Array.isArray(hookResult)) {
|
|
3880
1643
|
if (uaMatch === null) {
|
|
3881
|
-
setActor(hookResult);
|
|
1644
|
+
chunkWASXTDLW_cjs.setActor(hookResult);
|
|
3882
1645
|
return;
|
|
3883
1646
|
}
|
|
3884
1647
|
const hookObj = hookResult;
|
|
3885
1648
|
const existingKind = hookObj.kind;
|
|
3886
1649
|
if (typeof existingKind === "string" && existingKind.length > 0) {
|
|
3887
|
-
setActor(hookObj);
|
|
1650
|
+
chunkWASXTDLW_cjs.setActor(hookObj);
|
|
3888
1651
|
return;
|
|
3889
1652
|
}
|
|
3890
|
-
setActor({ ...hookObj, kind: uaMatch.kind });
|
|
1653
|
+
chunkWASXTDLW_cjs.setActor({ ...hookObj, kind: uaMatch.kind });
|
|
3891
1654
|
return;
|
|
3892
1655
|
}
|
|
3893
1656
|
if (uaMatch !== null) {
|
|
3894
|
-
setActor(synthesizeAgentActor(uaMatch));
|
|
1657
|
+
chunkWASXTDLW_cjs.setActor(synthesizeAgentActor(uaMatch));
|
|
3895
1658
|
return;
|
|
3896
1659
|
}
|
|
3897
|
-
setActor(null);
|
|
1660
|
+
chunkWASXTDLW_cjs.setActor(null);
|
|
3898
1661
|
}
|
|
3899
1662
|
function synthesizeAgentActor(detection) {
|
|
3900
1663
|
return {
|
|
@@ -3922,9 +1685,9 @@ function markBeforeExitInstalled() {
|
|
|
3922
1685
|
}
|
|
3923
1686
|
var ezlogs = {
|
|
3924
1687
|
init(options) {
|
|
3925
|
-
const config = configuration();
|
|
1688
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3926
1689
|
config.apply(options);
|
|
3927
|
-
if (options.logLevel) setLogLevel(options.logLevel);
|
|
1690
|
+
if (options.logLevel) chunkV5YNKKTG_cjs.setLogLevel(options.logLevel);
|
|
3928
1691
|
warnIfInsecureServerUrl(config.serverUrl, config.allowInsecureTransport);
|
|
3929
1692
|
flushScheduler.start();
|
|
3930
1693
|
if (config.patchGlobalFetch) patchGlobalFetch();
|
|
@@ -3940,7 +1703,7 @@ var ezlogs = {
|
|
|
3940
1703
|
}
|
|
3941
1704
|
});
|
|
3942
1705
|
} else if (options.patchDatabaseClient) {
|
|
3943
|
-
patchPgClient(
|
|
1706
|
+
chunkY5NSHKWQ_cjs.patchPgClient(
|
|
3944
1707
|
options.patchDatabaseClient
|
|
3945
1708
|
);
|
|
3946
1709
|
}
|
|
@@ -3987,7 +1750,7 @@ function detectDatabaseUrlFromEnv() {
|
|
|
3987
1750
|
return null;
|
|
3988
1751
|
}
|
|
3989
1752
|
async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
3990
|
-
const config = configuration();
|
|
1753
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3991
1754
|
let pg;
|
|
3992
1755
|
try {
|
|
3993
1756
|
const dynImport = new Function(
|
|
@@ -3996,7 +1759,7 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
|
3996
1759
|
);
|
|
3997
1760
|
pg = await dynImport("pg");
|
|
3998
1761
|
} catch {
|
|
3999
|
-
logger.warn(
|
|
1762
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
4000
1763
|
"a Postgres URL is configured but the `pg` package is not installed, so trigger-based DB capture is off. Run `npm i pg` and `npx ezlogs-nextjs install-triggers`, or use a per-ORM adapter (docs/database.md)."
|
|
4001
1764
|
);
|
|
4002
1765
|
return;
|
|
@@ -4006,7 +1769,7 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
|
4006
1769
|
max: 4
|
|
4007
1770
|
});
|
|
4008
1771
|
const reader = (sql, params) => pool.query(sql, params);
|
|
4009
|
-
if (await auditLogInstalled(reader) === false) {
|
|
1772
|
+
if (await chunkYX2XPLOA_cjs.auditLogInstalled(reader) === false) {
|
|
4010
1773
|
warnAuditLogMissing();
|
|
4011
1774
|
void pool.end?.().catch(() => {
|
|
4012
1775
|
});
|
|
@@ -4015,43 +1778,43 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
|
4015
1778
|
if (config.databaseReader === null) {
|
|
4016
1779
|
config.databaseReader = reader;
|
|
4017
1780
|
}
|
|
4018
|
-
patchPgClient(pg);
|
|
4019
|
-
void checkAuditLogAccess(reader);
|
|
1781
|
+
chunkY5NSHKWQ_cjs.patchPgClient(pg);
|
|
1782
|
+
void chunkYX2XPLOA_cjs.checkAuditLogAccess(reader);
|
|
4020
1783
|
runTriggerTrackedTablesDetection();
|
|
4021
1784
|
}
|
|
4022
1785
|
function applyDatabaseReaderDefaults() {
|
|
4023
|
-
const config = configuration();
|
|
1786
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
4024
1787
|
const reader = config.databaseReader;
|
|
4025
1788
|
if (!reader) return;
|
|
4026
|
-
auditLogInstalled(reader).then((installed) => {
|
|
1789
|
+
chunkYX2XPLOA_cjs.auditLogInstalled(reader).then((installed) => {
|
|
4027
1790
|
if (installed === false && config.databaseReader === reader) {
|
|
4028
1791
|
config.databaseReader = null;
|
|
4029
1792
|
warnAuditLogMissing();
|
|
4030
1793
|
return;
|
|
4031
1794
|
}
|
|
4032
|
-
if (installed === true) void checkAuditLogAccess(reader);
|
|
1795
|
+
if (installed === true) void chunkYX2XPLOA_cjs.checkAuditLogAccess(reader);
|
|
4033
1796
|
runTriggerTrackedTablesDetection();
|
|
4034
1797
|
}).catch(() => {
|
|
4035
1798
|
});
|
|
4036
1799
|
}
|
|
4037
1800
|
function warnAuditLogMissing() {
|
|
4038
|
-
logger.warn(
|
|
1801
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
4039
1802
|
"table `ezlogs_audit_log` was not found, so trigger-based DB capture is off. Run `npx ezlogs-nextjs install-triggers` against this database and restart."
|
|
4040
1803
|
);
|
|
4041
1804
|
}
|
|
4042
1805
|
function runTriggerTrackedTablesDetection() {
|
|
4043
|
-
const config = configuration();
|
|
1806
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
4044
1807
|
if (!config.databaseReader) return;
|
|
4045
1808
|
if (config.triggerTrackedTables !== null) return;
|
|
4046
|
-
detectTriggerTrackedTables(config.databaseReader).then((tables) => {
|
|
1809
|
+
chunkYX2XPLOA_cjs.detectTriggerTrackedTables(config.databaseReader).then((tables) => {
|
|
4047
1810
|
if (tables === null) {
|
|
4048
|
-
logger.debug(
|
|
1811
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
4049
1812
|
"[ezlogs] trigger-tracked-table detection failed; falling back to suppress-all on `databaseReader` paths. Untracked tables will not appear in the dashboard until detection succeeds or the table is added with `SELECT ezlogs_track('table_name')`."
|
|
4050
1813
|
);
|
|
4051
1814
|
return;
|
|
4052
1815
|
}
|
|
4053
1816
|
config.triggerTrackedTables = tables;
|
|
4054
|
-
logger.debug(
|
|
1817
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
4055
1818
|
`[ezlogs] trigger-tracked tables: ${tables.size === 0 ? "(none)" : Array.from(tables).sort().join(", ")}`
|
|
4056
1819
|
);
|
|
4057
1820
|
}).catch(() => {
|
|
@@ -4083,13 +1846,20 @@ function warnIfInsecureServerUrl(serverUrl, allowInsecure) {
|
|
|
4083
1846
|
);
|
|
4084
1847
|
}
|
|
4085
1848
|
function _internalsForTests() {
|
|
4086
|
-
return { buffer: buffer_exports, flushScheduler };
|
|
1849
|
+
return { buffer: chunkWASXTDLW_cjs.buffer_exports, flushScheduler };
|
|
4087
1850
|
}
|
|
4088
1851
|
|
|
1852
|
+
Object.defineProperty(exports, "ArgError", {
|
|
1853
|
+
enumerable: true,
|
|
1854
|
+
get: function () { return chunkWASXTDLW_cjs.ArgError; }
|
|
1855
|
+
});
|
|
1856
|
+
Object.defineProperty(exports, "buildEvent", {
|
|
1857
|
+
enumerable: true,
|
|
1858
|
+
get: function () { return chunkWASXTDLW_cjs.build; }
|
|
1859
|
+
});
|
|
4089
1860
|
exports.__ezlogs_run_inline_server_action = __ezlogs_run_inline_server_action;
|
|
4090
1861
|
exports._detectDatabaseUrlFromEnvForTests = _detectDatabaseUrlFromEnvForTests;
|
|
4091
1862
|
exports._internalsForTests = _internalsForTests;
|
|
4092
|
-
exports.buildEvent = build;
|
|
4093
1863
|
exports.captureHttpEvent = captureHttpEvent;
|
|
4094
1864
|
exports.capturePagesApi = capturePagesApi;
|
|
4095
1865
|
exports.captureRoute = captureRoute;
|