ezlogs-nextjs 0.2.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 +53 -16
- package/bin/install-triggers.cjs +73 -11
- 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 -713
- package/dist/db/drizzle.js +5 -712
- package/dist/db/prisma.cjs +52 -763
- package/dist/db/prisma.d.cts +3 -1
- package/dist/db/prisma.d.ts +3 -1
- package/dist/db/prisma.js +38 -749
- package/dist/db/supabase.cjs +21 -728
- package/dist/db/supabase.js +14 -721
- package/dist/index.cjs +204 -2181
- package/dist/index.js +107 -2090
- package/dist/jobs/bullmq.cjs +61 -552
- package/dist/jobs/bullmq.d.cts +8 -3
- package/dist/jobs/bullmq.d.ts +8 -3
- package/dist/jobs/bullmq.js +58 -549
- package/dist/jobs/inngest.cjs +23 -561
- package/dist/jobs/inngest.d.cts +7 -5
- package/dist/jobs/inngest.d.ts +7 -5
- package/dist/jobs/inngest.js +19 -557
- package/dist/jobs/supabase-queues.cjs +17 -603
- package/dist/jobs/supabase-queues.js +12 -598
- package/dist/jobs/trigger.cjs +18 -587
- package/dist/jobs/trigger.js +16 -585
- package/dist/jobs/upstash-workflow.cjs +62 -584
- package/dist/jobs/upstash-workflow.d.cts +17 -2
- package/dist/jobs/upstash-workflow.d.ts +17 -2
- package/dist/jobs/upstash-workflow.js +59 -582
- 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 -1234
- package/dist/triggers/index.d.cts +7 -2
- package/dist/triggers/index.d.ts +7 -2
- package/dist/triggers/index.js +6 -1221
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1,1488 +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 sanitizeValue(key, value, depth, userPatterns) {
|
|
752
|
-
if (isSensitiveKey2(key, userPatterns)) return "[FILTERED]";
|
|
753
|
-
if (isPlainObject2(value)) {
|
|
754
|
-
return sanitizeNestedObject(value, depth, userPatterns);
|
|
755
|
-
}
|
|
756
|
-
if (Array.isArray(value)) {
|
|
757
|
-
return sanitizeArrayValue(value, depth, userPatterns);
|
|
758
|
-
}
|
|
759
|
-
return value;
|
|
760
|
-
}
|
|
761
|
-
function sanitizeNestedObject(hash, depth, userPatterns) {
|
|
762
|
-
if (depth >= MAX_NESTING_DEPTH) return "[Object]";
|
|
763
|
-
if (Object.keys(hash).length === 0) return {};
|
|
764
|
-
const out = {};
|
|
765
|
-
for (const k of Object.keys(hash)) {
|
|
766
|
-
out[k] = sanitizeValue(k, hash[k], depth + 1, userPatterns);
|
|
767
|
-
}
|
|
768
|
-
return out;
|
|
769
|
-
}
|
|
770
|
-
function sanitizeArrayValue(array, depth, userPatterns) {
|
|
771
|
-
if (array.length === 0) return [];
|
|
772
|
-
const allPrimitive = array.every(isPrimitive);
|
|
773
|
-
if (allPrimitive) {
|
|
774
|
-
if (array.length <= MAX_ARRAY_DISPLAY_SIZE) return array;
|
|
775
|
-
const preview = array.slice(0, MAX_ARRAY_DISPLAY_SIZE);
|
|
776
|
-
return `${JSON.stringify(preview)}... (${array.length} total)`;
|
|
777
|
-
}
|
|
778
|
-
if (array.length <= MAX_ARRAY_DISPLAY_SIZE) {
|
|
779
|
-
return array.map((item) => sanitizeArrayItem(item, depth, userPatterns));
|
|
780
|
-
}
|
|
781
|
-
return {
|
|
782
|
-
_truncated: true,
|
|
783
|
-
_count: array.length,
|
|
784
|
-
_preview: array.slice(0, MAX_ARRAY_DISPLAY_SIZE).map((item) => sanitizeArrayItem(item, depth, userPatterns))
|
|
785
|
-
};
|
|
786
|
-
}
|
|
787
|
-
function sanitizeArrayItem(item, depth, userPatterns) {
|
|
788
|
-
if (isPrimitive(item)) return item;
|
|
789
|
-
if (isPlainObject2(item)) {
|
|
790
|
-
return sanitizeNestedObject(item, depth + 1, userPatterns);
|
|
791
|
-
}
|
|
792
|
-
if (Array.isArray(item)) return sanitizeArrayValue(item, depth + 1, userPatterns);
|
|
793
|
-
return "[Object]";
|
|
794
|
-
}
|
|
795
|
-
function isSensitiveKey2(key, userPatterns) {
|
|
796
|
-
if (matchesSensitiveKey(key, SENSITIVE_VARIABLE_PATTERNS)) return true;
|
|
797
|
-
const lower = key.toLowerCase();
|
|
798
|
-
return userPatterns.some((p) => lower.includes(p.toLowerCase()));
|
|
799
|
-
}
|
|
800
|
-
function isPrimitive(value) {
|
|
801
|
-
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
802
|
-
}
|
|
803
|
-
function isPlainObject2(value) {
|
|
804
|
-
if (value === null || typeof value !== "object") return false;
|
|
805
|
-
const proto = Object.getPrototypeOf(value);
|
|
806
|
-
return proto === Object.prototype || proto === null;
|
|
807
|
-
}
|
|
808
|
-
var SENSITIVE_VARIABLE_PATTERNS, SENSITIVE_WORD_PATTERNS, MAX_NESTING_DEPTH, MAX_ARRAY_DISPLAY_SIZE, FRAMEWORK_INTERNAL_KEYS;
|
|
809
|
-
var init_sanitize = __esm({
|
|
810
|
-
"src/http/sanitize.ts"() {
|
|
811
|
-
SENSITIVE_VARIABLE_PATTERNS = Object.freeze([
|
|
812
|
-
"password",
|
|
813
|
-
"passwd",
|
|
814
|
-
"pwd",
|
|
815
|
-
"token",
|
|
816
|
-
"access_token",
|
|
817
|
-
"refresh_token",
|
|
818
|
-
"api_token",
|
|
819
|
-
"auth_token",
|
|
820
|
-
"secret",
|
|
821
|
-
"api_secret",
|
|
822
|
-
"client_secret",
|
|
823
|
-
"api_key",
|
|
824
|
-
"apikey",
|
|
825
|
-
"private_key",
|
|
826
|
-
"privatekey",
|
|
827
|
-
"public_key",
|
|
828
|
-
"signing_key",
|
|
829
|
-
"secret_key",
|
|
830
|
-
"secretkey",
|
|
831
|
-
"credential",
|
|
832
|
-
"auth",
|
|
833
|
-
"authorization",
|
|
834
|
-
"encrypted",
|
|
835
|
-
"encrypted_data",
|
|
836
|
-
"ssn",
|
|
837
|
-
"social_security",
|
|
838
|
-
"credit_card",
|
|
839
|
-
"card_number",
|
|
840
|
-
"cvv",
|
|
841
|
-
"cvc",
|
|
842
|
-
// Crypto-material patterns — aligned with DB_SENSITIVE_PATTERNS
|
|
843
|
-
// (PR #45). Request bodies can carry the same key material as DB
|
|
844
|
-
// columns (a webhook POST containing a `signature` field, an HMAC
|
|
845
|
-
// header echoed into a JSON body, a `pem`-encoded cert blob, etc).
|
|
846
|
-
"pem",
|
|
847
|
-
"cipher",
|
|
848
|
-
"nonce",
|
|
849
|
-
"salt",
|
|
850
|
-
"digest",
|
|
851
|
-
"signature",
|
|
852
|
-
"hmac",
|
|
853
|
-
// 0.2.0 additions (not yet in the Rails gem's list).
|
|
854
|
-
"passcode",
|
|
855
|
-
"cardnumber"
|
|
856
|
-
]);
|
|
857
|
-
SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
858
|
-
"pin",
|
|
859
|
-
"otp",
|
|
860
|
-
"totp",
|
|
861
|
-
"iban",
|
|
862
|
-
"mfa",
|
|
863
|
-
"passphrase"
|
|
864
|
-
]);
|
|
865
|
-
MAX_NESTING_DEPTH = 3;
|
|
866
|
-
MAX_ARRAY_DISPLAY_SIZE = 5;
|
|
867
|
-
FRAMEWORK_INTERNAL_KEYS = /* @__PURE__ */ new Set([
|
|
868
|
-
// Rails leftovers — kept for parity since users may funnel through a
|
|
869
|
-
// proxy that adds them, e.g. via a NextAuth credentials provider that
|
|
870
|
-
// forwards CSRF tokens.
|
|
871
|
-
"controller",
|
|
872
|
-
"action",
|
|
873
|
-
"format",
|
|
874
|
-
"authenticity_token",
|
|
875
|
-
"_method",
|
|
876
|
-
// Next.js / common JS conventions
|
|
877
|
-
"csrfToken",
|
|
878
|
-
"_csrf",
|
|
879
|
-
"_next"
|
|
880
|
-
]);
|
|
881
|
-
}
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
// src/db/shared.ts
|
|
885
|
-
function emitDbEvent(input) {
|
|
886
|
-
try {
|
|
887
|
-
const config = configuration();
|
|
888
|
-
if (!config.captureDb) return;
|
|
889
|
-
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
890
|
-
if (config.databaseReader && !input._fromTrigger) {
|
|
891
|
-
const tracked = config.triggerTrackedTables;
|
|
892
|
-
if (tracked === null || tracked.has(input.modelClass)) return;
|
|
893
|
-
}
|
|
894
|
-
if (input.operation === "update") {
|
|
895
|
-
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
896
|
-
if (meaningful.length === 0) return;
|
|
897
|
-
}
|
|
898
|
-
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
899
|
-
const context = buildContext(input);
|
|
900
|
-
const event = build({
|
|
901
|
-
source_type: "database_callback",
|
|
902
|
-
source_data: {
|
|
903
|
-
model_class: input.modelClass,
|
|
904
|
-
operation: input.operation
|
|
905
|
-
},
|
|
906
|
-
outcome: "success",
|
|
907
|
-
correlation_id: current(),
|
|
908
|
-
resource_ids: resourceIdStr === null ? [] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
909
|
-
context,
|
|
910
|
-
duration_ms: null,
|
|
911
|
-
timestamp: input.timestamp ?? null
|
|
912
|
-
});
|
|
913
|
-
pushEvent(event);
|
|
914
|
-
} catch (error) {
|
|
915
|
-
logger.debug(`db emit failed: ${describeError5(error)}`);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
function buildContext(input) {
|
|
919
|
-
const context = {};
|
|
920
|
-
const actor = getCurrentActor();
|
|
921
|
-
if (actor) context.actor = actor;
|
|
922
|
-
if ((input.operation === "create" || input.operation === "destroy") && input.initialAttributes) {
|
|
923
|
-
const filtered = filterMeaningfulAttributes(input.initialAttributes);
|
|
924
|
-
if (filtered !== null) context.initial_attributes = filtered;
|
|
925
|
-
}
|
|
926
|
-
if (input.operation === "update" && input.changes) {
|
|
927
|
-
const filtered = filterMeaningfulChanges(input.changes);
|
|
928
|
-
if (filtered.length > 0) {
|
|
929
|
-
context.changes = filtered.map((c) => {
|
|
930
|
-
const out = {
|
|
931
|
-
attribute: c.attribute,
|
|
932
|
-
to: formatForJson(c.to)
|
|
933
|
-
};
|
|
934
|
-
if (c.from !== void 0) out.from = formatForJson(c.from);
|
|
935
|
-
return out;
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
const displayName = input.displayName ?? (input.modelInstance ? resolveDisplayName(input.modelClass, input.modelInstance) : null);
|
|
940
|
-
if (displayName !== null) context.display_name = displayName;
|
|
941
|
-
return Object.keys(context).length === 0 ? null : context;
|
|
942
|
-
}
|
|
943
|
-
function filterMeaningfulAttributes(attrs) {
|
|
944
|
-
const out = {};
|
|
945
|
-
for (const key of Object.keys(attrs)) {
|
|
946
|
-
if (!isMeaningfulAttribute(key)) continue;
|
|
947
|
-
const value = attrs[key];
|
|
948
|
-
if (value === null || value === void 0) continue;
|
|
949
|
-
if (!isScalar(value)) continue;
|
|
950
|
-
out[key] = formatForJson(value);
|
|
951
|
-
}
|
|
952
|
-
return Object.keys(out).length === 0 ? null : out;
|
|
953
|
-
}
|
|
954
|
-
function filterMeaningfulChanges(changes) {
|
|
955
|
-
return changes.filter((c) => {
|
|
956
|
-
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
957
|
-
if (!isScalar(c.to)) return false;
|
|
958
|
-
if (c.from === void 0) return true;
|
|
959
|
-
if (!isScalar(c.from)) return false;
|
|
960
|
-
return valuesActuallyChanged(c.from, c.to);
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
function isMeaningfulAttribute(name) {
|
|
964
|
-
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
965
|
-
if (isDbSensitive(name)) return false;
|
|
966
|
-
return true;
|
|
967
|
-
}
|
|
968
|
-
function isDbSensitive(name) {
|
|
969
|
-
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
970
|
-
}
|
|
971
|
-
function isScalar(value) {
|
|
972
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
973
|
-
return true;
|
|
974
|
-
}
|
|
975
|
-
if (isPrismaDecimal(value)) return true;
|
|
976
|
-
if (Buffer.isBuffer?.(value)) return false;
|
|
977
|
-
if (Array.isArray(value)) return value.every((v) => isScalar(v));
|
|
978
|
-
return false;
|
|
979
|
-
}
|
|
980
|
-
function valuesActuallyChanged(from, to) {
|
|
981
|
-
if (from === null && to === null) return false;
|
|
982
|
-
if (from instanceof Date && to instanceof Date) {
|
|
983
|
-
return from.getTime() !== to.getTime();
|
|
984
|
-
}
|
|
985
|
-
return from !== to;
|
|
986
|
-
}
|
|
987
|
-
function formatForJson(value) {
|
|
988
|
-
if (value === null || value === void 0) return value;
|
|
989
|
-
if (value instanceof Date) return value.toISOString();
|
|
990
|
-
if (typeof value === "bigint") return value.toString();
|
|
991
|
-
if (isPrismaDecimal(value)) return Number(value.toString());
|
|
992
|
-
if (Array.isArray(value)) return value.map(formatForJson);
|
|
993
|
-
return value;
|
|
994
|
-
}
|
|
995
|
-
function isPrismaDecimal(value) {
|
|
996
|
-
if (value === null || typeof value !== "object") return false;
|
|
997
|
-
const obj = value;
|
|
998
|
-
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
999
|
-
}
|
|
1000
|
-
function resolveDisplayName(modelClass, instance) {
|
|
1001
|
-
try {
|
|
1002
|
-
const config = configuration();
|
|
1003
|
-
const resolver = config.displayNameFor[modelClass];
|
|
1004
|
-
const resolved = applyResolver(resolver, instance);
|
|
1005
|
-
if (resolved !== null) return resolved;
|
|
1006
|
-
for (const field of ["name", "title", "number"]) {
|
|
1007
|
-
const value = instance[field];
|
|
1008
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
1009
|
-
return String(value);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
} catch {
|
|
1013
|
-
}
|
|
1014
|
-
return null;
|
|
1015
|
-
}
|
|
1016
|
-
function applyResolver(resolver, instance) {
|
|
1017
|
-
if (typeof resolver === "string") {
|
|
1018
|
-
const value = instance[resolver];
|
|
1019
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
1020
|
-
return String(value);
|
|
1021
|
-
}
|
|
1022
|
-
return null;
|
|
1023
|
-
}
|
|
1024
|
-
if (typeof resolver === "function") {
|
|
1025
|
-
try {
|
|
1026
|
-
const value = resolver(instance);
|
|
1027
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
1028
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
1029
|
-
return String(value);
|
|
1030
|
-
}
|
|
1031
|
-
} catch {
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
return null;
|
|
1035
|
-
}
|
|
1036
|
-
function describeError5(error) {
|
|
1037
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1038
|
-
return String(error);
|
|
1039
|
-
}
|
|
1040
|
-
var IGNORED_ATTRIBUTES, DB_SENSITIVE_PATTERNS;
|
|
1041
|
-
var init_shared = __esm({
|
|
1042
|
-
"src/db/shared.ts"() {
|
|
1043
|
-
init_configuration();
|
|
1044
|
-
init_logger();
|
|
1045
|
-
init_event_builder();
|
|
1046
|
-
init_buffer();
|
|
1047
|
-
init_correlation();
|
|
1048
|
-
init_actor();
|
|
1049
|
-
init_sanitize();
|
|
1050
|
-
IGNORED_ATTRIBUTES = Object.freeze([
|
|
1051
|
-
"id",
|
|
1052
|
-
"createdAt",
|
|
1053
|
-
"created_at",
|
|
1054
|
-
"updatedAt",
|
|
1055
|
-
"updated_at",
|
|
1056
|
-
"deletedAt",
|
|
1057
|
-
"deleted_at",
|
|
1058
|
-
// Auth.js / NextAuth standard columns
|
|
1059
|
-
"emailVerified",
|
|
1060
|
-
"expires"
|
|
1061
|
-
]);
|
|
1062
|
-
DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
1063
|
-
"password",
|
|
1064
|
-
"token",
|
|
1065
|
-
"secret",
|
|
1066
|
-
"api_key",
|
|
1067
|
-
"credit_card",
|
|
1068
|
-
"ssn",
|
|
1069
|
-
"social_security",
|
|
1070
|
-
"encrypted",
|
|
1071
|
-
"private_key",
|
|
1072
|
-
"public_key",
|
|
1073
|
-
"signing_key",
|
|
1074
|
-
"pem",
|
|
1075
|
-
"cipher",
|
|
1076
|
-
"nonce",
|
|
1077
|
-
"salt",
|
|
1078
|
-
"digest",
|
|
1079
|
-
"signature",
|
|
1080
|
-
"hmac",
|
|
1081
|
-
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
1082
|
-
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
1083
|
-
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
1084
|
-
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
1085
|
-
"credential",
|
|
1086
|
-
"passwd",
|
|
1087
|
-
"passcode",
|
|
1088
|
-
"apikey",
|
|
1089
|
-
"card_number",
|
|
1090
|
-
"cardnumber",
|
|
1091
|
-
"cvv",
|
|
1092
|
-
"cvc"
|
|
1093
|
-
]);
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
|
|
1097
|
-
// src/db/supabase.ts
|
|
1098
|
-
var supabase_exports = {};
|
|
1099
|
-
__export(supabase_exports, {
|
|
1100
|
-
tryExtractSupabaseActor: () => tryExtractSupabaseActor,
|
|
1101
|
-
wrapSupabase: () => wrapSupabase
|
|
1102
|
-
});
|
|
1103
|
-
function triggerPathWillCapture(table) {
|
|
1104
|
-
const config = configuration();
|
|
1105
|
-
if (!config.databaseReader) return false;
|
|
1106
|
-
const tracked = config.triggerTrackedTables;
|
|
1107
|
-
if (tracked === null) return false;
|
|
1108
|
-
return tracked.has(table);
|
|
1109
|
-
}
|
|
1110
|
-
function wrapSupabase(client) {
|
|
1111
|
-
if (client === null || typeof client !== "object") return client;
|
|
1112
|
-
const obj = client;
|
|
1113
|
-
if (obj.__ezlogsWrapped) return client;
|
|
1114
|
-
if (typeof obj.from !== "function") return client;
|
|
1115
|
-
const originalFrom = obj.from.bind(obj);
|
|
1116
|
-
const prereadRow = async (table, filters) => {
|
|
1117
|
-
try {
|
|
1118
|
-
const queryBuilder = originalFrom(table);
|
|
1119
|
-
if (typeof queryBuilder.select !== "function") return null;
|
|
1120
|
-
let chain = queryBuilder.select("*");
|
|
1121
|
-
for (const f of filters) {
|
|
1122
|
-
if (typeof chain.eq !== "function") return null;
|
|
1123
|
-
chain = chain.eq(
|
|
1124
|
-
f.column,
|
|
1125
|
-
f.value
|
|
1126
|
-
);
|
|
1127
|
-
}
|
|
1128
|
-
if (typeof chain.maybeSingle === "function") {
|
|
1129
|
-
chain = chain.maybeSingle();
|
|
1130
|
-
} else if (typeof chain.limit === "function") {
|
|
1131
|
-
chain = chain.limit(
|
|
1132
|
-
1
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
const result = await chain;
|
|
1136
|
-
if (!result || result.error) return null;
|
|
1137
|
-
if (Array.isArray(result.data)) {
|
|
1138
|
-
const first = result.data[0];
|
|
1139
|
-
return isPlainObject4(first) ? first : null;
|
|
1140
|
-
}
|
|
1141
|
-
return isPlainObject4(result.data) ? result.data : null;
|
|
1142
|
-
} catch {
|
|
1143
|
-
return null;
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
|
-
obj.from = ((table) => {
|
|
1147
|
-
const builder = originalFrom(table);
|
|
1148
|
-
return wrapBuilder(builder, table, prereadRow);
|
|
1149
|
-
});
|
|
1150
|
-
Object.defineProperty(obj, "__ezlogsWrapped", {
|
|
1151
|
-
value: true,
|
|
1152
|
-
enumerable: false,
|
|
1153
|
-
configurable: false
|
|
1154
|
-
});
|
|
1155
|
-
registerActorSource(obj);
|
|
1156
|
-
return client;
|
|
1157
|
-
}
|
|
1158
|
-
function registerActorSource(client) {
|
|
1159
|
-
try {
|
|
1160
|
-
const g = globalThis;
|
|
1161
|
-
g[GLOBAL_CLIENT_KEY] = client;
|
|
1162
|
-
} catch {
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
async function tryExtractSupabaseActor() {
|
|
1166
|
-
const g = globalThis;
|
|
1167
|
-
const client = g[GLOBAL_CLIENT_KEY];
|
|
1168
|
-
if (!client || typeof client.auth?.getUser !== "function") return null;
|
|
1169
|
-
try {
|
|
1170
|
-
const { data } = await client.auth.getUser();
|
|
1171
|
-
const user = data?.user;
|
|
1172
|
-
if (!user || typeof user.id !== "string" || !user.id) return null;
|
|
1173
|
-
const label = user.user_metadata?.full_name ?? user.user_metadata?.name ?? user.email ?? void 0;
|
|
1174
|
-
return label ? { id: user.id, label } : { id: user.id };
|
|
1175
|
-
} catch {
|
|
1176
|
-
return null;
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
function wrapBuilder(builder, table, preread) {
|
|
1180
|
-
if (typeof builder.insert === "function") {
|
|
1181
|
-
builder.insert = wrapMutation(
|
|
1182
|
-
builder.insert.bind(builder),
|
|
1183
|
-
{ table, operation: "create" },
|
|
1184
|
-
preread
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
if (typeof builder.upsert === "function") {
|
|
1188
|
-
builder.upsert = wrapMutation(
|
|
1189
|
-
builder.upsert.bind(builder),
|
|
1190
|
-
{ table, operation: "update" },
|
|
1191
|
-
// supabase upsert is conceptually update-with-fallback
|
|
1192
|
-
preread
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
if (typeof builder.update === "function") {
|
|
1196
|
-
builder.update = wrapMutation(
|
|
1197
|
-
builder.update.bind(builder),
|
|
1198
|
-
{ table, operation: "update" },
|
|
1199
|
-
preread
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
if (typeof builder.delete === "function") {
|
|
1203
|
-
builder.delete = wrapDeleteMutation(
|
|
1204
|
-
builder.delete.bind(builder),
|
|
1205
|
-
table,
|
|
1206
|
-
preread
|
|
1207
|
-
);
|
|
1208
|
-
}
|
|
1209
|
-
return builder;
|
|
1210
|
-
}
|
|
1211
|
-
function wrapMutation(original, ctx, preread) {
|
|
1212
|
-
return (values, options) => {
|
|
1213
|
-
const filterBuilder = original(values, options);
|
|
1214
|
-
const filters = trackFilterChain(filterBuilder);
|
|
1215
|
-
const beforeRowRef = { row: null };
|
|
1216
|
-
return instrumentFilterBuilder(
|
|
1217
|
-
filterBuilder,
|
|
1218
|
-
(result) => emitFromMutation(ctx, values, result, filters, beforeRowRef.row),
|
|
1219
|
-
async () => {
|
|
1220
|
-
if (ctx.operation !== "update") return;
|
|
1221
|
-
if (triggerPathWillCapture(ctx.table)) return;
|
|
1222
|
-
const prereadFilters = prereadFiltersFromCaptured(filters);
|
|
1223
|
-
if (prereadFilters !== null) {
|
|
1224
|
-
beforeRowRef.row = await preread(ctx.table, prereadFilters);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
);
|
|
1228
|
-
};
|
|
1229
|
-
}
|
|
1230
|
-
function wrapDeleteMutation(original, table, preread) {
|
|
1231
|
-
return (options) => {
|
|
1232
|
-
const filterBuilder = original(options);
|
|
1233
|
-
const filters = trackFilterChain(filterBuilder);
|
|
1234
|
-
const beforeRowRef = { row: null };
|
|
1235
|
-
return instrumentFilterBuilder(
|
|
1236
|
-
filterBuilder,
|
|
1237
|
-
(result) => emitFromDelete(table, result, filters, beforeRowRef.row),
|
|
1238
|
-
async () => {
|
|
1239
|
-
if (triggerPathWillCapture(table)) return;
|
|
1240
|
-
const prereadFilters = prereadFiltersFromCaptured(filters);
|
|
1241
|
-
if (prereadFilters !== null) {
|
|
1242
|
-
beforeRowRef.row = await preread(table, prereadFilters);
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
);
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1248
|
-
function trackFilterChain(builder) {
|
|
1249
|
-
const captured = { equals: {}, inLists: {} };
|
|
1250
|
-
if (!builder || typeof builder !== "object") return captured;
|
|
1251
|
-
const builderObj = builder;
|
|
1252
|
-
const wrapEq = (orig) => {
|
|
1253
|
-
if (typeof orig !== "function") return orig;
|
|
1254
|
-
return function patchedEq(column, value) {
|
|
1255
|
-
try {
|
|
1256
|
-
if (typeof column === "string") captured.equals[column] = value;
|
|
1257
|
-
} catch {
|
|
1258
|
-
}
|
|
1259
|
-
return orig.call(this, column, value);
|
|
1260
|
-
};
|
|
1261
|
-
};
|
|
1262
|
-
const wrapIn = (orig) => {
|
|
1263
|
-
if (typeof orig !== "function") return orig;
|
|
1264
|
-
return function patchedIn(column, values) {
|
|
1265
|
-
try {
|
|
1266
|
-
if (typeof column === "string" && Array.isArray(values)) {
|
|
1267
|
-
captured.inLists[column] = values;
|
|
1268
|
-
}
|
|
1269
|
-
} catch {
|
|
1270
|
-
}
|
|
1271
|
-
return orig.call(this, column, values);
|
|
1272
|
-
};
|
|
1273
|
-
};
|
|
1274
|
-
const wrapMatch = (orig) => {
|
|
1275
|
-
if (typeof orig !== "function") return orig;
|
|
1276
|
-
return function patchedMatch(query) {
|
|
1277
|
-
try {
|
|
1278
|
-
if (isPlainObject4(query)) {
|
|
1279
|
-
for (const [k, v] of Object.entries(query)) {
|
|
1280
|
-
captured.equals[k] = v;
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
} catch {
|
|
1284
|
-
}
|
|
1285
|
-
return orig.call(this, query);
|
|
1286
|
-
};
|
|
1287
|
-
};
|
|
1288
|
-
if ("eq" in builderObj) builderObj.eq = wrapEq(builderObj.eq);
|
|
1289
|
-
if ("in" in builderObj) builderObj.in = wrapIn(builderObj.in);
|
|
1290
|
-
if ("match" in builderObj) builderObj.match = wrapMatch(builderObj.match);
|
|
1291
|
-
return captured;
|
|
1292
|
-
}
|
|
1293
|
-
function instrumentFilterBuilder(builder, onResolved, beforeFire) {
|
|
1294
|
-
if (!builder || typeof builder !== "object") return builder;
|
|
1295
|
-
const originalThen = builder.then?.bind(builder);
|
|
1296
|
-
if (typeof originalThen !== "function") return builder;
|
|
1297
|
-
const wrappedThen = function ezlogsThen(onfulfilled, onrejected) {
|
|
1298
|
-
return new Promise((resolve, reject) => {
|
|
1299
|
-
const proceed = () => {
|
|
1300
|
-
originalThen(
|
|
1301
|
-
(raw) => {
|
|
1302
|
-
const result = raw;
|
|
1303
|
-
try {
|
|
1304
|
-
if (!result?.error) onResolved(result);
|
|
1305
|
-
} catch (error) {
|
|
1306
|
-
logger.debug(`supabase capture failed: ${describeError6(error)}`);
|
|
1307
|
-
}
|
|
1308
|
-
try {
|
|
1309
|
-
const passthrough = onfulfilled ? onfulfilled(raw) : raw;
|
|
1310
|
-
resolve(passthrough);
|
|
1311
|
-
} catch (e) {
|
|
1312
|
-
reject(e);
|
|
1313
|
-
}
|
|
1314
|
-
},
|
|
1315
|
-
(reason) => {
|
|
1316
|
-
try {
|
|
1317
|
-
const passthrough = onrejected ? onrejected(reason) : Promise.reject(reason);
|
|
1318
|
-
resolve(passthrough);
|
|
1319
|
-
} catch (e) {
|
|
1320
|
-
reject(e);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
);
|
|
1324
|
-
};
|
|
1325
|
-
if (beforeFire) {
|
|
1326
|
-
beforeFire().then(proceed, () => proceed());
|
|
1327
|
-
} else {
|
|
1328
|
-
proceed();
|
|
1329
|
-
}
|
|
1330
|
-
});
|
|
1331
|
-
};
|
|
1332
|
-
builder.then = wrappedThen;
|
|
1333
|
-
return builder;
|
|
1334
|
-
}
|
|
1335
|
-
function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
1336
|
-
if (Array.isArray(values)) {
|
|
1337
|
-
const resultRows = pickResultRows(result);
|
|
1338
|
-
values.forEach((row, index) => {
|
|
1339
|
-
if (!isPlainObject4(row)) return;
|
|
1340
|
-
emitOneRow(ctx, row, resultRows[index] ?? null, filters, null);
|
|
1341
|
-
});
|
|
1342
|
-
return;
|
|
1343
|
-
}
|
|
1344
|
-
if (!isPlainObject4(values)) {
|
|
1345
|
-
emitDbEvent({
|
|
1346
|
-
modelClass: ctx.table,
|
|
1347
|
-
operation: ctx.operation,
|
|
1348
|
-
resourceId: idFromFilters(filters)
|
|
1349
|
-
});
|
|
1350
|
-
return;
|
|
1351
|
-
}
|
|
1352
|
-
const valueObj = values;
|
|
1353
|
-
const resultRow = pickFirstResultRow(result);
|
|
1354
|
-
emitOneRow(ctx, valueObj, resultRow, filters, beforeRow);
|
|
1355
|
-
}
|
|
1356
|
-
function emitOneRow(ctx, values, resultRow, filters, beforeRow) {
|
|
1357
|
-
const resourceId = resultRow?.id ?? values.id ?? idFromFilters(filters) ?? null;
|
|
1358
|
-
const merged = beforeRow ?? resultRow ?? values;
|
|
1359
|
-
const displayName = resolveDisplayName(ctx.table, merged);
|
|
1360
|
-
if (ctx.operation === "create") {
|
|
1361
|
-
emitDbEvent({
|
|
1362
|
-
modelClass: ctx.table,
|
|
1363
|
-
operation: "create",
|
|
1364
|
-
resourceId,
|
|
1365
|
-
initialAttributes: values,
|
|
1366
|
-
displayName,
|
|
1367
|
-
modelInstance: merged
|
|
1368
|
-
});
|
|
1369
|
-
return;
|
|
1370
|
-
}
|
|
1371
|
-
if (ctx.operation === "update") {
|
|
1372
|
-
const changes = buildUpdateChanges(values, beforeRow);
|
|
1373
|
-
emitDbEvent({
|
|
1374
|
-
modelClass: ctx.table,
|
|
1375
|
-
operation: "update",
|
|
1376
|
-
resourceId,
|
|
1377
|
-
changes,
|
|
1378
|
-
displayName,
|
|
1379
|
-
modelInstance: merged
|
|
1380
|
-
});
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
function emitFromDelete(table, result, filters, beforeRow) {
|
|
1384
|
-
const resultRow = pickFirstResultRow(result);
|
|
1385
|
-
const resourceId = resultRow?.id ?? beforeRow?.id ?? idFromFilters(filters) ?? null;
|
|
1386
|
-
const richestRow = resultRow ?? beforeRow;
|
|
1387
|
-
const displayName = richestRow ? resolveDisplayName(table, richestRow) : null;
|
|
1388
|
-
emitDbEvent({
|
|
1389
|
-
modelClass: table,
|
|
1390
|
-
operation: "destroy",
|
|
1391
|
-
resourceId,
|
|
1392
|
-
displayName,
|
|
1393
|
-
modelInstance: richestRow
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
function prereadFiltersFromCaptured(filters) {
|
|
1397
|
-
const idValue = filters.equals["id"];
|
|
1398
|
-
if (!isScalarFilterValue(idValue)) return null;
|
|
1399
|
-
const out = [];
|
|
1400
|
-
for (const column of Object.keys(filters.equals)) {
|
|
1401
|
-
const value = filters.equals[column];
|
|
1402
|
-
if (!isScalarFilterValue(value)) continue;
|
|
1403
|
-
out.push({ column, value });
|
|
1404
|
-
}
|
|
1405
|
-
return out;
|
|
1406
|
-
}
|
|
1407
|
-
function idFromFilters(filters) {
|
|
1408
|
-
const value = filters.equals["id"];
|
|
1409
|
-
return isScalarFilterValue(value) ? value : null;
|
|
1410
|
-
}
|
|
1411
|
-
function isScalarFilterValue(value) {
|
|
1412
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "bigint";
|
|
1413
|
-
}
|
|
1414
|
-
function buildUpdateChanges(values, beforeRow) {
|
|
1415
|
-
return Object.keys(values).map((attribute) => {
|
|
1416
|
-
const change = {
|
|
1417
|
-
attribute,
|
|
1418
|
-
to: values[attribute]
|
|
1419
|
-
};
|
|
1420
|
-
if (beforeRow && Object.prototype.hasOwnProperty.call(beforeRow, attribute)) {
|
|
1421
|
-
change.from = beforeRow[attribute];
|
|
1422
|
-
}
|
|
1423
|
-
return change;
|
|
1424
|
-
});
|
|
1425
|
-
}
|
|
1426
|
-
function pickFirstResultRow(result) {
|
|
1427
|
-
if (!result || result.error) return null;
|
|
1428
|
-
if (Array.isArray(result.data)) {
|
|
1429
|
-
const first = result.data[0];
|
|
1430
|
-
return isPlainObject4(first) ? first : null;
|
|
1431
|
-
}
|
|
1432
|
-
if (isPlainObject4(result.data)) return result.data;
|
|
1433
|
-
return null;
|
|
1434
|
-
}
|
|
1435
|
-
function pickResultRows(result) {
|
|
1436
|
-
if (!result || result.error || !Array.isArray(result.data)) return [];
|
|
1437
|
-
return result.data.map(
|
|
1438
|
-
(row) => isPlainObject4(row) ? row : void 0
|
|
1439
|
-
);
|
|
1440
|
-
}
|
|
1441
|
-
function isPlainObject4(value) {
|
|
1442
|
-
if (value === null || typeof value !== "object") return false;
|
|
1443
|
-
if (Array.isArray(value)) return false;
|
|
1444
|
-
if (value instanceof Date) return false;
|
|
1445
|
-
return true;
|
|
1446
|
-
}
|
|
1447
|
-
function describeError6(error) {
|
|
1448
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1449
|
-
return String(error);
|
|
1450
|
-
}
|
|
1451
|
-
var GLOBAL_CLIENT_KEY;
|
|
1452
|
-
var init_supabase = __esm({
|
|
1453
|
-
"src/db/supabase.ts"() {
|
|
1454
|
-
init_logger();
|
|
1455
|
-
init_configuration();
|
|
1456
|
-
init_shared();
|
|
1457
|
-
GLOBAL_CLIENT_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:supabase-current-client");
|
|
1458
|
-
}
|
|
1459
|
-
});
|
|
1460
|
-
|
|
1461
|
-
// src/index.ts
|
|
1462
|
-
init_configuration();
|
|
1463
|
-
init_logger();
|
|
1464
|
-
init_buffer();
|
|
1465
|
-
|
|
1466
|
-
// src/pipeline/flush-scheduler.ts
|
|
1467
|
-
init_configuration();
|
|
1468
|
-
init_logger();
|
|
1469
|
-
init_buffer();
|
|
1470
|
-
|
|
1471
|
-
// src/pipeline/retry-sender.ts
|
|
1472
|
-
init_configuration();
|
|
1473
|
-
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');
|
|
1474
8
|
|
|
1475
9
|
// src/pipeline/transport.ts
|
|
1476
|
-
init_configuration();
|
|
1477
|
-
init_logger();
|
|
1478
10
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
1479
11
|
var transport = {
|
|
1480
12
|
async send(events) {
|
|
1481
13
|
if (!events || events.length === 0) return "success";
|
|
1482
|
-
const config = configuration();
|
|
14
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
1483
15
|
const serverUrl = config.serverUrl;
|
|
1484
16
|
if (!serverUrl) {
|
|
1485
|
-
logger.error("Transport: serverUrl not configured");
|
|
17
|
+
chunkV5YNKKTG_cjs.logger.error("Transport: serverUrl not configured");
|
|
1486
18
|
return "failure";
|
|
1487
19
|
}
|
|
1488
20
|
const url = `${stripTrailingSlash(serverUrl)}/api/events`;
|
|
@@ -1502,14 +34,14 @@ var transport = {
|
|
|
1502
34
|
signal: controller.signal
|
|
1503
35
|
});
|
|
1504
36
|
if (response.status >= 200 && response.status < 300) {
|
|
1505
|
-
logger.debug(`Transport send succeeded (${response.status})`);
|
|
37
|
+
chunkV5YNKKTG_cjs.logger.debug(`Transport send succeeded (${response.status})`);
|
|
1506
38
|
return "success";
|
|
1507
39
|
}
|
|
1508
|
-
logger.error(`Transport send failed (${response.status})`);
|
|
40
|
+
chunkV5YNKKTG_cjs.logger.error(`Transport send failed (${response.status})`);
|
|
1509
41
|
return "failure";
|
|
1510
42
|
} catch (error) {
|
|
1511
43
|
const desc = describeError(error);
|
|
1512
|
-
logger.error(`Transport send failed: ${desc}`);
|
|
44
|
+
chunkV5YNKKTG_cjs.logger.error(`Transport send failed: ${desc}`);
|
|
1513
45
|
return "failure";
|
|
1514
46
|
} finally {
|
|
1515
47
|
clearTimeout(timer);
|
|
@@ -1544,7 +76,7 @@ var retrySender = {
|
|
|
1544
76
|
await sleepBeforeRetry(attempt);
|
|
1545
77
|
attempt += 1;
|
|
1546
78
|
}
|
|
1547
|
-
logger.error(
|
|
79
|
+
chunkV5YNKKTG_cjs.logger.error(
|
|
1548
80
|
`RetrySender: failed after ${maxAttempts} attempts, dropping ${events.length} events`
|
|
1549
81
|
);
|
|
1550
82
|
return "failure";
|
|
@@ -1554,7 +86,7 @@ async function attemptSend(events, attempt, maxAttempts) {
|
|
|
1554
86
|
try {
|
|
1555
87
|
return await transport.send(events);
|
|
1556
88
|
} catch (error) {
|
|
1557
|
-
logger.error(
|
|
89
|
+
chunkV5YNKKTG_cjs.logger.error(
|
|
1558
90
|
`RetrySender: transport raised (attempt ${attempt}/${maxAttempts}): ${describeError2(error)}`
|
|
1559
91
|
);
|
|
1560
92
|
return "failure";
|
|
@@ -1571,7 +103,7 @@ function applyJitter(base) {
|
|
|
1571
103
|
}
|
|
1572
104
|
function retryAttempts() {
|
|
1573
105
|
try {
|
|
1574
|
-
const value = configuration().retryAttempts;
|
|
106
|
+
const value = chunkWASXTDLW_cjs.configuration().retryAttempts;
|
|
1575
107
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
1576
108
|
return 3;
|
|
1577
109
|
}
|
|
@@ -1605,7 +137,7 @@ var flushScheduler = {
|
|
|
1605
137
|
if (typeof s.timer === "object" && s.timer !== null && "unref" in s.timer) {
|
|
1606
138
|
s.timer.unref();
|
|
1607
139
|
}
|
|
1608
|
-
logger.debug(`FlushScheduler started (interval ${interval}ms)`);
|
|
140
|
+
chunkV5YNKKTG_cjs.logger.debug(`FlushScheduler started (interval ${interval}ms)`);
|
|
1609
141
|
},
|
|
1610
142
|
async stop() {
|
|
1611
143
|
const s = state();
|
|
@@ -1613,7 +145,7 @@ var flushScheduler = {
|
|
|
1613
145
|
clearInterval(s.timer);
|
|
1614
146
|
s.timer = null;
|
|
1615
147
|
await tick();
|
|
1616
|
-
logger.debug("FlushScheduler stopped");
|
|
148
|
+
chunkV5YNKKTG_cjs.logger.debug("FlushScheduler stopped");
|
|
1617
149
|
},
|
|
1618
150
|
isRunning() {
|
|
1619
151
|
return state().timer !== null;
|
|
@@ -1628,18 +160,18 @@ async function tick() {
|
|
|
1628
160
|
if (s.inFlight) return;
|
|
1629
161
|
s.inFlight = true;
|
|
1630
162
|
try {
|
|
1631
|
-
const events = drainEvents();
|
|
163
|
+
const events = chunkWASXTDLW_cjs.drainEvents();
|
|
1632
164
|
if (events.length === 0) return;
|
|
1633
165
|
await retrySender.send(events);
|
|
1634
166
|
} catch (error) {
|
|
1635
|
-
logger.error(`FlushScheduler tick failed: ${describeError3(error)}`);
|
|
167
|
+
chunkV5YNKKTG_cjs.logger.error(`FlushScheduler tick failed: ${describeError3(error)}`);
|
|
1636
168
|
} finally {
|
|
1637
169
|
s.inFlight = false;
|
|
1638
170
|
}
|
|
1639
171
|
}
|
|
1640
172
|
function sendInterval() {
|
|
1641
173
|
try {
|
|
1642
|
-
const value = configuration().sendInterval;
|
|
174
|
+
const value = chunkWASXTDLW_cjs.configuration().sendInterval;
|
|
1643
175
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
1644
176
|
return 5e3;
|
|
1645
177
|
}
|
|
@@ -1654,8 +186,6 @@ function describeError3(error) {
|
|
|
1654
186
|
}
|
|
1655
187
|
|
|
1656
188
|
// src/http/outgoing-fetch.ts
|
|
1657
|
-
init_correlation();
|
|
1658
|
-
init_logger();
|
|
1659
189
|
var HEADER = "x-correlation-id";
|
|
1660
190
|
var originalFetch = null;
|
|
1661
191
|
var patched = false;
|
|
@@ -1664,13 +194,13 @@ function patchGlobalFetch() {
|
|
|
1664
194
|
if (typeof globalThis.fetch !== "function") return;
|
|
1665
195
|
originalFetch = globalThis.fetch;
|
|
1666
196
|
const wrapped = (input, init) => {
|
|
1667
|
-
const id = current();
|
|
197
|
+
const id = chunkWASXTDLW_cjs.current();
|
|
1668
198
|
if (!id) return originalFetch.call(globalThis, input, init);
|
|
1669
199
|
try {
|
|
1670
200
|
const enriched = injectHeader(input, init, id);
|
|
1671
201
|
return originalFetch.call(globalThis, enriched.input, enriched.init);
|
|
1672
202
|
} catch (error) {
|
|
1673
|
-
logger.debug(`outgoing-fetch injection failed: ${describeError4(error)}`);
|
|
203
|
+
chunkV5YNKKTG_cjs.logger.debug(`outgoing-fetch injection failed: ${describeError4(error)}`);
|
|
1674
204
|
return originalFetch.call(globalThis, input, init);
|
|
1675
205
|
}
|
|
1676
206
|
};
|
|
@@ -1706,561 +236,6 @@ function describeError4(error) {
|
|
|
1706
236
|
return String(error);
|
|
1707
237
|
}
|
|
1708
238
|
|
|
1709
|
-
// src/triggers/patch-pg.ts
|
|
1710
|
-
init_actor();
|
|
1711
|
-
init_correlation();
|
|
1712
|
-
init_logger();
|
|
1713
|
-
var txState = /* @__PURE__ */ new WeakMap();
|
|
1714
|
-
function patchPgClient(pgModule) {
|
|
1715
|
-
if (!pgModule || !pgModule.Client || !pgModule.Client.prototype) {
|
|
1716
|
-
logger.debug("patchPgClient: not a recognized pg module shape, skipping");
|
|
1717
|
-
return;
|
|
1718
|
-
}
|
|
1719
|
-
const proto = pgModule.Client.prototype;
|
|
1720
|
-
if (proto._ezlogsPatched) return;
|
|
1721
|
-
const originalQuery = proto.query;
|
|
1722
|
-
proto.query = function patchedQuery(config, values, callback) {
|
|
1723
|
-
return runPatchedQuery(
|
|
1724
|
-
this,
|
|
1725
|
-
originalQuery,
|
|
1726
|
-
config,
|
|
1727
|
-
values,
|
|
1728
|
-
callback
|
|
1729
|
-
);
|
|
1730
|
-
};
|
|
1731
|
-
proto._ezlogsPatched = true;
|
|
1732
|
-
}
|
|
1733
|
-
function runPatchedQuery(client, original, config, values, callback) {
|
|
1734
|
-
const state2 = ensureState(client);
|
|
1735
|
-
const text = extractQueryText(config);
|
|
1736
|
-
const verb = leadingVerb(text);
|
|
1737
|
-
if (verb === "BEGIN" || verb === "START") {
|
|
1738
|
-
state2.inTx = true;
|
|
1739
|
-
state2.injected = false;
|
|
1740
|
-
return original.call(client, config, values, callback);
|
|
1741
|
-
}
|
|
1742
|
-
if (verb === "COMMIT" || verb === "ROLLBACK" || verb === "END") {
|
|
1743
|
-
const result = original.call(client, config, values, callback);
|
|
1744
|
-
state2.inTx = false;
|
|
1745
|
-
state2.injected = false;
|
|
1746
|
-
return result;
|
|
1747
|
-
}
|
|
1748
|
-
if (state2.inTx) {
|
|
1749
|
-
if (state2.injected) {
|
|
1750
|
-
return original.call(client, config, values, callback);
|
|
1751
|
-
}
|
|
1752
|
-
const ctx2 = snapshotContext();
|
|
1753
|
-
if (!ctx2.actorId && !ctx2.correlationId) {
|
|
1754
|
-
state2.injected = true;
|
|
1755
|
-
return original.call(client, config, values, callback);
|
|
1756
|
-
}
|
|
1757
|
-
state2.injected = true;
|
|
1758
|
-
return injectAndRun(client, original, config, values, callback, ctx2);
|
|
1759
|
-
}
|
|
1760
|
-
const ctx = snapshotContext();
|
|
1761
|
-
if (!ctx.actorId && !ctx.correlationId) {
|
|
1762
|
-
return original.call(client, config, values, callback);
|
|
1763
|
-
}
|
|
1764
|
-
return wrapInTx(client, original, config, values, callback, ctx);
|
|
1765
|
-
}
|
|
1766
|
-
function snapshotContext() {
|
|
1767
|
-
const actor = getCurrentActor();
|
|
1768
|
-
return {
|
|
1769
|
-
actorId: actor && actor.id ? actor.id : null,
|
|
1770
|
-
correlationId: current()
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
async function injectAndRun(client, original, config, values, callback, ctx) {
|
|
1774
|
-
if (ctx.actorId) {
|
|
1775
|
-
await safeSet(client, original, {
|
|
1776
|
-
text: "SELECT set_config('ezlogs.actor_id', $1, true)",
|
|
1777
|
-
values: [ctx.actorId]
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
if (ctx.correlationId) {
|
|
1781
|
-
await safeSet(client, original, {
|
|
1782
|
-
text: "SELECT set_config('ezlogs.correlation_id', $1, true)",
|
|
1783
|
-
values: [ctx.correlationId]
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
return original.call(client, config, values, callback);
|
|
1787
|
-
}
|
|
1788
|
-
async function safeSet(client, original, cfg) {
|
|
1789
|
-
try {
|
|
1790
|
-
const result = original.call(client, cfg);
|
|
1791
|
-
if (result && typeof result.then === "function") {
|
|
1792
|
-
await result;
|
|
1793
|
-
}
|
|
1794
|
-
} catch (err) {
|
|
1795
|
-
logger.debug(
|
|
1796
|
-
`patchPgClient: SET LOCAL failed (continuing): ${err instanceof Error ? err.message : String(err)}`
|
|
1797
|
-
);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
function wrapInTx(client, original, config, values, callback, ctx) {
|
|
1801
|
-
const state2 = ensureState(client);
|
|
1802
|
-
let userCb = null;
|
|
1803
|
-
let realValues = values;
|
|
1804
|
-
if (typeof callback === "function") {
|
|
1805
|
-
userCb = callback;
|
|
1806
|
-
} else if (typeof values === "function") {
|
|
1807
|
-
userCb = values;
|
|
1808
|
-
realValues = void 0;
|
|
1809
|
-
}
|
|
1810
|
-
const begin = original.call(client, "BEGIN");
|
|
1811
|
-
if (!begin || typeof begin.then !== "function") {
|
|
1812
|
-
return original.call(client, config, values, callback);
|
|
1813
|
-
}
|
|
1814
|
-
const wrapped = begin.then(async () => {
|
|
1815
|
-
state2.inTx = true;
|
|
1816
|
-
state2.injected = true;
|
|
1817
|
-
if (ctx.actorId) {
|
|
1818
|
-
await original.call(client, {
|
|
1819
|
-
text: "SELECT set_config('ezlogs.actor_id', $1, true)",
|
|
1820
|
-
values: [ctx.actorId]
|
|
1821
|
-
});
|
|
1822
|
-
}
|
|
1823
|
-
if (ctx.correlationId) {
|
|
1824
|
-
await original.call(client, {
|
|
1825
|
-
text: "SELECT set_config('ezlogs.correlation_id', $1, true)",
|
|
1826
|
-
values: [ctx.correlationId]
|
|
1827
|
-
});
|
|
1828
|
-
}
|
|
1829
|
-
}).then(
|
|
1830
|
-
() => (
|
|
1831
|
-
// Run the user's actual query in promise mode — DO NOT forward
|
|
1832
|
-
// the caller's callback. See comment above.
|
|
1833
|
-
original.call(client, config, realValues)
|
|
1834
|
-
)
|
|
1835
|
-
).then(
|
|
1836
|
-
async (result) => {
|
|
1837
|
-
await original.call(client, "COMMIT");
|
|
1838
|
-
state2.inTx = false;
|
|
1839
|
-
state2.injected = false;
|
|
1840
|
-
return result;
|
|
1841
|
-
},
|
|
1842
|
-
async (err) => {
|
|
1843
|
-
try {
|
|
1844
|
-
await original.call(client, "ROLLBACK");
|
|
1845
|
-
} catch {
|
|
1846
|
-
}
|
|
1847
|
-
state2.inTx = false;
|
|
1848
|
-
state2.injected = false;
|
|
1849
|
-
throw err;
|
|
1850
|
-
}
|
|
1851
|
-
);
|
|
1852
|
-
if (userCb) {
|
|
1853
|
-
wrapped.then(
|
|
1854
|
-
(result) => userCb(null, result),
|
|
1855
|
-
(err) => userCb(err instanceof Error ? err : new Error(String(err)))
|
|
1856
|
-
);
|
|
1857
|
-
return void 0;
|
|
1858
|
-
}
|
|
1859
|
-
return wrapped;
|
|
1860
|
-
}
|
|
1861
|
-
function ensureState(client) {
|
|
1862
|
-
let s = txState.get(client);
|
|
1863
|
-
if (!s) {
|
|
1864
|
-
s = { inTx: false, injected: false };
|
|
1865
|
-
txState.set(client, s);
|
|
1866
|
-
}
|
|
1867
|
-
return s;
|
|
1868
|
-
}
|
|
1869
|
-
function extractQueryText(config) {
|
|
1870
|
-
if (typeof config === "string") return config;
|
|
1871
|
-
if (config && typeof config === "object" && typeof config.text === "string") {
|
|
1872
|
-
return config.text;
|
|
1873
|
-
}
|
|
1874
|
-
return "";
|
|
1875
|
-
}
|
|
1876
|
-
function leadingVerb(text) {
|
|
1877
|
-
let s = text;
|
|
1878
|
-
while (true) {
|
|
1879
|
-
const before = s.length;
|
|
1880
|
-
s = s.replace(/^\s+/, "");
|
|
1881
|
-
s = s.replace(/^--[^\n]*\n?/, "");
|
|
1882
|
-
if (s.length === before) break;
|
|
1883
|
-
}
|
|
1884
|
-
const m = /^[A-Za-z]+/.exec(s);
|
|
1885
|
-
return m ? m[0].toUpperCase() : "";
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
// src/triggers/reader.ts
|
|
1889
|
-
init_logger();
|
|
1890
|
-
init_shared();
|
|
1891
|
-
init_correlation();
|
|
1892
|
-
init_actor();
|
|
1893
|
-
|
|
1894
|
-
// src/triggers/emit-dedup.ts
|
|
1895
|
-
init_edge_fallback();
|
|
1896
|
-
var storage3 = createScopedStorage(
|
|
1897
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:audit-emitted-ids-storage")
|
|
1898
|
-
);
|
|
1899
|
-
function currentEmittedAuditIds() {
|
|
1900
|
-
return storage3.read();
|
|
1901
|
-
}
|
|
1902
|
-
function runWithEmittedAuditIdsScope(callback) {
|
|
1903
|
-
const existing = storage3.read();
|
|
1904
|
-
if (existing !== null) return callback();
|
|
1905
|
-
return storage3.run(/* @__PURE__ */ new Set(), callback);
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
// src/triggers/reader.ts
|
|
1909
|
-
var COLUMNS = "id, table_name, op, old_row, new_row, resource_id, correlation_id, txid, captured_at";
|
|
1910
|
-
var ORPHAN_AGE = "5 minutes";
|
|
1911
|
-
var PRUNE_AGE = "24 hours";
|
|
1912
|
-
var SWEEP_BATCH = 100;
|
|
1913
|
-
var PRUNE_BATCH = 2e3;
|
|
1914
|
-
var SWEEP_INTERVAL_MS = 1e4;
|
|
1915
|
-
var PRUNE_INTERVAL_MS = 10 * 6e4;
|
|
1916
|
-
var lastSweepAt = 0;
|
|
1917
|
-
var lastPruneAt = 0;
|
|
1918
|
-
var deleteDenied = false;
|
|
1919
|
-
var txCorrelation = /* @__PURE__ */ new Map();
|
|
1920
|
-
async function readAuditRows(exec, correlationId) {
|
|
1921
|
-
try {
|
|
1922
|
-
if (!deleteDenied) {
|
|
1923
|
-
try {
|
|
1924
|
-
return sortById(
|
|
1925
|
-
extractRows(
|
|
1926
|
-
await exec(
|
|
1927
|
-
`DELETE FROM ezlogs_audit_log WHERE correlation_id = $1 RETURNING ${COLUMNS}`,
|
|
1928
|
-
[correlationId]
|
|
1929
|
-
)
|
|
1930
|
-
).map(normalizeAuditRow)
|
|
1931
|
-
);
|
|
1932
|
-
} catch (err) {
|
|
1933
|
-
if (!isPermissionDenied(err)) throw err;
|
|
1934
|
-
deleteDenied = true;
|
|
1935
|
-
logger.warn(
|
|
1936
|
-
"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'`."
|
|
1937
|
-
);
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
const result = await exec(
|
|
1941
|
-
`SELECT ${COLUMNS} FROM ezlogs_audit_log WHERE correlation_id = $1 ORDER BY id ASC`,
|
|
1942
|
-
[correlationId]
|
|
1943
|
-
);
|
|
1944
|
-
return extractRows(result).map(normalizeAuditRow);
|
|
1945
|
-
} catch (err) {
|
|
1946
|
-
logger.debug(
|
|
1947
|
-
`readAuditRows failed: ${err instanceof Error ? err.message : String(err)}`
|
|
1948
|
-
);
|
|
1949
|
-
return [];
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
async function sweepAuditLog(exec) {
|
|
1953
|
-
if (deleteDenied) return 0;
|
|
1954
|
-
try {
|
|
1955
|
-
const rows = sortById(
|
|
1956
|
-
extractRows(
|
|
1957
|
-
await exec(
|
|
1958
|
-
`DELETE FROM ezlogs_audit_log
|
|
1959
|
-
WHERE id IN (
|
|
1960
|
-
SELECT id FROM ezlogs_audit_log
|
|
1961
|
-
WHERE (correlation_id IS NULL
|
|
1962
|
-
OR captured_at < now() - interval '${ORPHAN_AGE}')
|
|
1963
|
-
-- Never resurface history: past the retention cap a
|
|
1964
|
-
-- row is pruned, not sent as new activity.
|
|
1965
|
-
AND captured_at > now() - interval '${PRUNE_AGE}'
|
|
1966
|
-
ORDER BY id
|
|
1967
|
-
LIMIT ${SWEEP_BATCH}
|
|
1968
|
-
FOR UPDATE SKIP LOCKED)
|
|
1969
|
-
RETURNING ${COLUMNS}`,
|
|
1970
|
-
[]
|
|
1971
|
-
)
|
|
1972
|
-
).map(normalizeAuditRow)
|
|
1973
|
-
);
|
|
1974
|
-
for (const row of rows) {
|
|
1975
|
-
const correlationId = row.correlation_id ?? correlationForTx(row.txid);
|
|
1976
|
-
runWithCorrelation(
|
|
1977
|
-
correlationId,
|
|
1978
|
-
() => runWithActorScope(() => emitOne(row))
|
|
1979
|
-
);
|
|
1980
|
-
}
|
|
1981
|
-
return rows.length;
|
|
1982
|
-
} catch (err) {
|
|
1983
|
-
logger.debug(
|
|
1984
|
-
`sweepAuditLog failed: ${err instanceof Error ? err.message : String(err)}`
|
|
1985
|
-
);
|
|
1986
|
-
return 0;
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
async function pruneAuditLog(exec) {
|
|
1990
|
-
if (deleteDenied) return;
|
|
1991
|
-
try {
|
|
1992
|
-
await exec(
|
|
1993
|
-
`DELETE FROM ezlogs_audit_log
|
|
1994
|
-
WHERE id IN (
|
|
1995
|
-
SELECT id FROM ezlogs_audit_log
|
|
1996
|
-
WHERE captured_at < now() - interval '${PRUNE_AGE}'
|
|
1997
|
-
LIMIT ${PRUNE_BATCH})`,
|
|
1998
|
-
[]
|
|
1999
|
-
);
|
|
2000
|
-
} catch (err) {
|
|
2001
|
-
logger.debug(
|
|
2002
|
-
`pruneAuditLog failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2003
|
-
);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
async function auditLogInstalled(exec) {
|
|
2007
|
-
try {
|
|
2008
|
-
const rows = extractRows(
|
|
2009
|
-
await exec(
|
|
2010
|
-
`SELECT to_regclass('public.ezlogs_audit_log') IS NOT NULL AS installed`,
|
|
2011
|
-
[]
|
|
2012
|
-
)
|
|
2013
|
-
);
|
|
2014
|
-
const installed = rows[0]?.installed;
|
|
2015
|
-
return typeof installed === "boolean" ? installed : null;
|
|
2016
|
-
} catch {
|
|
2017
|
-
return null;
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
async function checkAuditLogAccess(exec) {
|
|
2021
|
-
try {
|
|
2022
|
-
const rows = extractRows(
|
|
2023
|
-
await exec(
|
|
2024
|
-
`SELECT current_user AS role
|
|
2025
|
-
FROM pg_class c
|
|
2026
|
-
JOIN pg_roles r ON r.rolname = current_user
|
|
2027
|
-
WHERE c.oid = 'public.ezlogs_audit_log'::regclass
|
|
2028
|
-
AND c.relrowsecurity
|
|
2029
|
-
AND NOT r.rolsuper
|
|
2030
|
-
AND NOT r.rolbypassrls
|
|
2031
|
-
AND NOT pg_has_role(current_user, c.relowner, 'MEMBER')
|
|
2032
|
-
AND NOT EXISTS (SELECT 1 FROM pg_policies p
|
|
2033
|
-
WHERE p.schemaname = 'public'
|
|
2034
|
-
AND p.tablename = 'ezlogs_audit_log')`,
|
|
2035
|
-
[]
|
|
2036
|
-
)
|
|
2037
|
-
);
|
|
2038
|
-
const role = rows[0]?.role;
|
|
2039
|
-
if (typeof role !== "string") return false;
|
|
2040
|
-
logger.warn(
|
|
2041
|
-
`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);`
|
|
2042
|
-
);
|
|
2043
|
-
return true;
|
|
2044
|
-
} catch {
|
|
2045
|
-
return false;
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
async function detectTriggerTrackedTables(exec) {
|
|
2049
|
-
try {
|
|
2050
|
-
const result = await exec(
|
|
2051
|
-
`SELECT event_object_table AS table_name
|
|
2052
|
-
FROM information_schema.triggers
|
|
2053
|
-
WHERE trigger_name = 'ezlogs_audit'
|
|
2054
|
-
AND trigger_schema = 'public'`,
|
|
2055
|
-
[]
|
|
2056
|
-
);
|
|
2057
|
-
const rows = extractRows(result);
|
|
2058
|
-
const tables = /* @__PURE__ */ new Set();
|
|
2059
|
-
for (const row of rows) {
|
|
2060
|
-
const r = row ?? {};
|
|
2061
|
-
if (typeof r.table_name === "string" && r.table_name.length > 0) {
|
|
2062
|
-
tables.add(r.table_name);
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
return tables;
|
|
2066
|
-
} catch (err) {
|
|
2067
|
-
logger.debug(
|
|
2068
|
-
`detectTriggerTrackedTables failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2069
|
-
);
|
|
2070
|
-
return null;
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
function emitAuditRows(rows) {
|
|
2074
|
-
for (const row of rows) {
|
|
2075
|
-
emitOne(row);
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
async function flushAuditLog(exec) {
|
|
2079
|
-
if (!exec) return;
|
|
2080
|
-
const correlationId = current();
|
|
2081
|
-
if (!correlationId) return;
|
|
2082
|
-
const rows = await readAuditRows(exec, correlationId);
|
|
2083
|
-
emitFresh(rows);
|
|
2084
|
-
const now = Date.now();
|
|
2085
|
-
if (now - lastPruneAt >= PRUNE_INTERVAL_MS) {
|
|
2086
|
-
lastPruneAt = now;
|
|
2087
|
-
await pruneAuditLog(exec);
|
|
2088
|
-
}
|
|
2089
|
-
if (now - lastSweepAt >= SWEEP_INTERVAL_MS) {
|
|
2090
|
-
lastSweepAt = now;
|
|
2091
|
-
await sweepAuditLog(exec);
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
function emitFresh(rows) {
|
|
2095
|
-
if (rows.length === 0) return;
|
|
2096
|
-
const emitted = currentEmittedAuditIds();
|
|
2097
|
-
if (emitted === null) {
|
|
2098
|
-
emitAuditRows(rows);
|
|
2099
|
-
return;
|
|
2100
|
-
}
|
|
2101
|
-
const fresh = [];
|
|
2102
|
-
for (const row of rows) {
|
|
2103
|
-
if (row.id === "" || emitted.has(row.id)) continue;
|
|
2104
|
-
emitted.add(row.id);
|
|
2105
|
-
fresh.push(row);
|
|
2106
|
-
}
|
|
2107
|
-
emitAuditRows(fresh);
|
|
2108
|
-
}
|
|
2109
|
-
function correlationForTx(txid) {
|
|
2110
|
-
if (!txid) return generate();
|
|
2111
|
-
let id = txCorrelation.get(txid);
|
|
2112
|
-
if (!id) {
|
|
2113
|
-
if (txCorrelation.size >= 1e3) txCorrelation.clear();
|
|
2114
|
-
id = generate();
|
|
2115
|
-
txCorrelation.set(txid, id);
|
|
2116
|
-
}
|
|
2117
|
-
return id;
|
|
2118
|
-
}
|
|
2119
|
-
function isPermissionDenied(err) {
|
|
2120
|
-
return err?.code === "42501";
|
|
2121
|
-
}
|
|
2122
|
-
function sortById(rows) {
|
|
2123
|
-
return rows.sort(
|
|
2124
|
-
(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
|
|
2125
|
-
);
|
|
2126
|
-
}
|
|
2127
|
-
function emitOne(row) {
|
|
2128
|
-
const op = mapOp(row.op);
|
|
2129
|
-
if (!op) return;
|
|
2130
|
-
const oldRow = coerceJsonb(row.old_row);
|
|
2131
|
-
const newRow = coerceJsonb(row.new_row);
|
|
2132
|
-
if (op === "create" && newRow) {
|
|
2133
|
-
emitDbEvent({
|
|
2134
|
-
modelClass: row.table_name,
|
|
2135
|
-
operation: "create",
|
|
2136
|
-
resourceId: row.resource_id,
|
|
2137
|
-
initialAttributes: newRow,
|
|
2138
|
-
modelInstance: newRow,
|
|
2139
|
-
displayName: null,
|
|
2140
|
-
timestamp: row.captured_at ?? null,
|
|
2141
|
-
_fromTrigger: true
|
|
2142
|
-
});
|
|
2143
|
-
return;
|
|
2144
|
-
}
|
|
2145
|
-
if (op === "update" && oldRow && newRow) {
|
|
2146
|
-
const changes = computeChanges(oldRow, newRow);
|
|
2147
|
-
if (changes.length === 0) {
|
|
2148
|
-
return;
|
|
2149
|
-
}
|
|
2150
|
-
emitDbEvent({
|
|
2151
|
-
modelClass: row.table_name,
|
|
2152
|
-
operation: "update",
|
|
2153
|
-
resourceId: row.resource_id,
|
|
2154
|
-
changes,
|
|
2155
|
-
// Prefer the post-state for the display name — that's what the
|
|
2156
|
-
// user just told the system to call this row.
|
|
2157
|
-
modelInstance: newRow,
|
|
2158
|
-
displayName: null,
|
|
2159
|
-
timestamp: row.captured_at ?? null,
|
|
2160
|
-
_fromTrigger: true
|
|
2161
|
-
});
|
|
2162
|
-
return;
|
|
2163
|
-
}
|
|
2164
|
-
if (op === "destroy" && oldRow) {
|
|
2165
|
-
emitDbEvent({
|
|
2166
|
-
modelClass: row.table_name,
|
|
2167
|
-
operation: "destroy",
|
|
2168
|
-
resourceId: row.resource_id,
|
|
2169
|
-
initialAttributes: oldRow,
|
|
2170
|
-
modelInstance: oldRow,
|
|
2171
|
-
displayName: null,
|
|
2172
|
-
timestamp: row.captured_at ?? null,
|
|
2173
|
-
_fromTrigger: true
|
|
2174
|
-
});
|
|
2175
|
-
return;
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
function mapOp(op) {
|
|
2179
|
-
if (op === "INSERT") return "create";
|
|
2180
|
-
if (op === "UPDATE") return "update";
|
|
2181
|
-
if (op === "DELETE") return "destroy";
|
|
2182
|
-
return null;
|
|
2183
|
-
}
|
|
2184
|
-
function computeChanges(oldRow, newRow) {
|
|
2185
|
-
const out = [];
|
|
2186
|
-
for (const key of Object.keys(newRow)) {
|
|
2187
|
-
const before = oldRow[key];
|
|
2188
|
-
const after = newRow[key];
|
|
2189
|
-
if (deepEqual(before, after)) continue;
|
|
2190
|
-
out.push({ attribute: key, from: before, to: after });
|
|
2191
|
-
}
|
|
2192
|
-
return out;
|
|
2193
|
-
}
|
|
2194
|
-
function deepEqual(a, b) {
|
|
2195
|
-
if (a === b) return true;
|
|
2196
|
-
if (a === null || b === null) return false;
|
|
2197
|
-
if (typeof a !== typeof b) return false;
|
|
2198
|
-
if (typeof a !== "object") return false;
|
|
2199
|
-
try {
|
|
2200
|
-
return stableStringify(a) === stableStringify(b);
|
|
2201
|
-
} catch {
|
|
2202
|
-
return false;
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
function stableStringify(value) {
|
|
2206
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
2207
|
-
if (Array.isArray(value)) {
|
|
2208
|
-
return "[" + value.map((v) => stableStringify(v)).join(",") + "]";
|
|
2209
|
-
}
|
|
2210
|
-
const entries = Object.keys(value).sort().map((k) => JSON.stringify(k) + ":" + stableStringify(value[k]));
|
|
2211
|
-
return "{" + entries.join(",") + "}";
|
|
2212
|
-
}
|
|
2213
|
-
function extractRows(result) {
|
|
2214
|
-
if (!result) return [];
|
|
2215
|
-
if (Array.isArray(result)) return result;
|
|
2216
|
-
if (typeof result === "object" && Array.isArray(result.rows)) {
|
|
2217
|
-
return result.rows;
|
|
2218
|
-
}
|
|
2219
|
-
return [];
|
|
2220
|
-
}
|
|
2221
|
-
function toDate(value) {
|
|
2222
|
-
if (value == null) return null;
|
|
2223
|
-
const d = value instanceof Date ? value : new Date(String(value));
|
|
2224
|
-
return Number.isNaN(d.getTime()) ? null : d;
|
|
2225
|
-
}
|
|
2226
|
-
function normalizeAuditRow(raw) {
|
|
2227
|
-
const r = raw ?? {};
|
|
2228
|
-
return {
|
|
2229
|
-
id: r.id == null ? "" : String(r.id),
|
|
2230
|
-
table_name: String(r.table_name ?? ""),
|
|
2231
|
-
op: r.op,
|
|
2232
|
-
old_row: r.old_row ?? null,
|
|
2233
|
-
new_row: r.new_row ?? null,
|
|
2234
|
-
resource_id: r.resource_id == null ? null : String(r.resource_id),
|
|
2235
|
-
correlation_id: r.correlation_id == null ? null : String(r.correlation_id),
|
|
2236
|
-
txid: r.txid == null ? null : String(r.txid),
|
|
2237
|
-
captured_at: toDate(r.captured_at)
|
|
2238
|
-
};
|
|
2239
|
-
}
|
|
2240
|
-
function coerceJsonb(value) {
|
|
2241
|
-
if (value === null || value === void 0) return null;
|
|
2242
|
-
if (typeof value === "string") {
|
|
2243
|
-
try {
|
|
2244
|
-
const parsed = JSON.parse(value);
|
|
2245
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
2246
|
-
} catch {
|
|
2247
|
-
return null;
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
if (typeof value === "object" && !Array.isArray(value)) return value;
|
|
2251
|
-
return null;
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
// src/index.ts
|
|
2255
|
-
init_logger();
|
|
2256
|
-
init_event_builder();
|
|
2257
|
-
|
|
2258
|
-
// src/http/capture.ts
|
|
2259
|
-
init_configuration();
|
|
2260
|
-
init_logger();
|
|
2261
|
-
init_event_builder();
|
|
2262
|
-
init_buffer();
|
|
2263
|
-
|
|
2264
239
|
// src/pipeline/serverless.ts
|
|
2265
240
|
var cachedFlag = null;
|
|
2266
241
|
function isServerless() {
|
|
@@ -2280,9 +255,6 @@ function detect() {
|
|
|
2280
255
|
return false;
|
|
2281
256
|
}
|
|
2282
257
|
|
|
2283
|
-
// src/http/capture.ts
|
|
2284
|
-
init_actor();
|
|
2285
|
-
|
|
2286
258
|
// src/user-agent-detector.ts
|
|
2287
259
|
var PATTERNS = [
|
|
2288
260
|
{ prefix: "claude-", vendor: "claude", label: "Claude" },
|
|
@@ -2306,9 +278,6 @@ function classifyUserAgent(userAgent) {
|
|
|
2306
278
|
};
|
|
2307
279
|
}
|
|
2308
280
|
|
|
2309
|
-
// src/http/capture.ts
|
|
2310
|
-
init_correlation();
|
|
2311
|
-
|
|
2312
281
|
// src/http/path-matcher.ts
|
|
2313
282
|
function pathMatches(path, pattern) {
|
|
2314
283
|
const startsWithStar = pattern.startsWith("*");
|
|
@@ -2332,11 +301,7 @@ function hasExcludedExtension(path, extensions) {
|
|
|
2332
301
|
return extensions.some((ext) => path.endsWith(ext));
|
|
2333
302
|
}
|
|
2334
303
|
|
|
2335
|
-
// src/http/capture.ts
|
|
2336
|
-
init_configuration();
|
|
2337
|
-
|
|
2338
304
|
// src/http/source-data.ts
|
|
2339
|
-
init_sanitize();
|
|
2340
305
|
function buildHttpSourceData(input) {
|
|
2341
306
|
const { controller, action } = resolveControllerAction(input);
|
|
2342
307
|
const source = {
|
|
@@ -2365,7 +330,7 @@ function buildHttpSourceData(input) {
|
|
|
2365
330
|
source.graphql_variables = input.graphql.graphql_variables;
|
|
2366
331
|
}
|
|
2367
332
|
} else {
|
|
2368
|
-
const params = sanitizeRequestParams(input.rawParams, input.excludedVariableKeys);
|
|
333
|
+
const params = chunkWASXTDLW_cjs.sanitizeRequestParams(input.rawParams, input.excludedVariableKeys);
|
|
2369
334
|
if (params !== null) source.request_params = params;
|
|
2370
335
|
}
|
|
2371
336
|
return compact(source);
|
|
@@ -2493,7 +458,7 @@ function compact(obj) {
|
|
|
2493
458
|
}
|
|
2494
459
|
return out;
|
|
2495
460
|
}
|
|
2496
|
-
function determineOutcome(statusCode, exception, graphqlResponseErrors) {
|
|
461
|
+
function determineOutcome(statusCode, exception, graphqlResponseErrors, responseError = null) {
|
|
2497
462
|
if (exception) {
|
|
2498
463
|
return {
|
|
2499
464
|
outcome: "failure",
|
|
@@ -2501,7 +466,7 @@ function determineOutcome(statusCode, exception, graphqlResponseErrors) {
|
|
|
2501
466
|
};
|
|
2502
467
|
}
|
|
2503
468
|
if (statusCode !== null && statusCode >= 400) {
|
|
2504
|
-
return { outcome: "failure", error_message: `HTTP ${statusCode}` };
|
|
469
|
+
return { outcome: "failure", error_message: responseError ?? `HTTP ${statusCode}` };
|
|
2505
470
|
}
|
|
2506
471
|
if (graphqlResponseErrors) {
|
|
2507
472
|
return { outcome: "failure", error_message: graphqlResponseErrors };
|
|
@@ -2510,14 +475,13 @@ function determineOutcome(statusCode, exception, graphqlResponseErrors) {
|
|
|
2510
475
|
}
|
|
2511
476
|
|
|
2512
477
|
// src/http/graphql.ts
|
|
2513
|
-
init_sanitize();
|
|
2514
478
|
var QUERY_PREFIXES = ["Get", "Fetch", "List", "Find", "Load", "Search", "Query"];
|
|
2515
479
|
var MUTATION_PREFIXES = ["Create", "Update", "Delete", "Remove", "Add", "Set", "Upsert"];
|
|
2516
480
|
function isGraphqlPath(path) {
|
|
2517
481
|
return path === "/graphql" || path.startsWith("/graphql/");
|
|
2518
482
|
}
|
|
2519
483
|
function parseGraphqlBody(body, excludedOperations, excludedVariableKeys) {
|
|
2520
|
-
if (!
|
|
484
|
+
if (!isPlainObject(body)) return { metadata: null };
|
|
2521
485
|
const obj = body;
|
|
2522
486
|
const queryString = typeof obj.query === "string" ? obj.query : null;
|
|
2523
487
|
let operationName = typeof obj.operationName === "string" ? obj.operationName : null;
|
|
@@ -2528,7 +492,7 @@ function parseGraphqlBody(body, excludedOperations, excludedVariableKeys) {
|
|
|
2528
492
|
return { metadata: "skip" };
|
|
2529
493
|
}
|
|
2530
494
|
const operationType = inferOperationTypeFromQuery(queryString) ?? inferOperationTypeFromName(operationName);
|
|
2531
|
-
const sanitizedVariables = sanitizeRequestParams(obj.variables, excludedVariableKeys);
|
|
495
|
+
const sanitizedVariables = chunkWASXTDLW_cjs.sanitizeRequestParams(obj.variables, excludedVariableKeys);
|
|
2532
496
|
return {
|
|
2533
497
|
metadata: {
|
|
2534
498
|
graphql_operation: operationName ?? "anonymous",
|
|
@@ -2564,14 +528,14 @@ function isExcludedOperation(name, patterns) {
|
|
|
2564
528
|
});
|
|
2565
529
|
}
|
|
2566
530
|
function extractGraphqlErrorsFromBody(parsed) {
|
|
2567
|
-
if (!
|
|
531
|
+
if (!isPlainObject(parsed)) return null;
|
|
2568
532
|
const errors = parsed.errors;
|
|
2569
533
|
if (!Array.isArray(errors) || errors.length === 0) return null;
|
|
2570
|
-
const messages = errors.map((err) =>
|
|
534
|
+
const messages = errors.map((err) => isPlainObject(err) ? err.message : null).filter((m) => typeof m === "string" && m.length > 0);
|
|
2571
535
|
if (messages.length === 0) return null;
|
|
2572
536
|
return messages.length === 1 ? messages[0] : messages.join("; ");
|
|
2573
537
|
}
|
|
2574
|
-
function
|
|
538
|
+
function isPlainObject(value) {
|
|
2575
539
|
if (value === null || typeof value !== "object") return false;
|
|
2576
540
|
const proto = Object.getPrototypeOf(value);
|
|
2577
541
|
return proto === Object.prototype || proto === null;
|
|
@@ -2586,7 +550,7 @@ function captureRoute(handler, context = {}) {
|
|
|
2586
550
|
return handler(...invokeArgs);
|
|
2587
551
|
};
|
|
2588
552
|
try {
|
|
2589
|
-
if (!configuration().captureHttp) {
|
|
553
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) {
|
|
2590
554
|
return Promise.resolve(runHandler(...args));
|
|
2591
555
|
}
|
|
2592
556
|
const request = args[0];
|
|
@@ -2595,8 +559,9 @@ function captureRoute(handler, context = {}) {
|
|
|
2595
559
|
}
|
|
2596
560
|
const snapshot = await snapshotRequest(request);
|
|
2597
561
|
if (snapshot === null) return Promise.resolve(runHandler(...args));
|
|
2598
|
-
|
|
2599
|
-
|
|
562
|
+
snapshot.rawParams = mergeRouteParams(snapshot.rawParams, await readRouteParams(args[1]));
|
|
563
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation(request.headers ?? null);
|
|
564
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2600
565
|
correlationId,
|
|
2601
566
|
() => runWithActorAndAuditScope(async () => {
|
|
2602
567
|
await maybeRunActorHook(request);
|
|
@@ -2605,15 +570,23 @@ function captureRoute(handler, context = {}) {
|
|
|
2605
570
|
let response = null;
|
|
2606
571
|
let exception = null;
|
|
2607
572
|
let graphqlErrorMessage = null;
|
|
573
|
+
let responseErrorMessage = null;
|
|
2608
574
|
try {
|
|
2609
575
|
response = await Promise.resolve(runHandler(...args));
|
|
2610
576
|
statusCode = response.status;
|
|
2611
577
|
if (snapshot.graphqlBody !== null && response.status === 200) {
|
|
2612
578
|
graphqlErrorMessage = await readGraphqlErrors(response);
|
|
2613
579
|
}
|
|
580
|
+
responseErrorMessage = await readResponseErrorMessage(response);
|
|
2614
581
|
return response;
|
|
2615
582
|
} catch (e) {
|
|
583
|
+
const controlStatus = nextControlFlowStatus(e);
|
|
584
|
+
if (controlStatus !== null) {
|
|
585
|
+
statusCode = controlStatus;
|
|
586
|
+
throw e;
|
|
587
|
+
}
|
|
2616
588
|
exception = e instanceof Error ? e : new Error(String(e));
|
|
589
|
+
statusCode = 500;
|
|
2617
590
|
throw e;
|
|
2618
591
|
} finally {
|
|
2619
592
|
await maybeExtractSupabaseActor();
|
|
@@ -2623,6 +596,7 @@ function captureRoute(handler, context = {}) {
|
|
|
2623
596
|
statusCode,
|
|
2624
597
|
exception,
|
|
2625
598
|
graphqlErrorMessage,
|
|
599
|
+
responseErrorMessage,
|
|
2626
600
|
durationMs: Date.now() - startMs,
|
|
2627
601
|
startedAt: new Date(startMs)
|
|
2628
602
|
});
|
|
@@ -2635,14 +609,14 @@ function captureRoute(handler, context = {}) {
|
|
|
2635
609
|
);
|
|
2636
610
|
} catch (preCaptureError) {
|
|
2637
611
|
if (handlerInvoked) throw preCaptureError;
|
|
2638
|
-
logger.warn(
|
|
2639
|
-
`captureRoute pre-handler setup failed (${
|
|
612
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
613
|
+
`captureRoute pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this request`
|
|
2640
614
|
);
|
|
2641
615
|
return Promise.resolve(handler(...args));
|
|
2642
616
|
}
|
|
2643
617
|
};
|
|
2644
618
|
}
|
|
2645
|
-
var
|
|
619
|
+
var CORRELATION_HEADER = "x-ezlogs-correlation-id";
|
|
2646
620
|
function withMiddlewareCapture(middleware) {
|
|
2647
621
|
return async (request, ...rest) => {
|
|
2648
622
|
let middlewareInvoked = false;
|
|
@@ -2651,12 +625,12 @@ function withMiddlewareCapture(middleware) {
|
|
|
2651
625
|
return middleware(req, ...mRest);
|
|
2652
626
|
};
|
|
2653
627
|
try {
|
|
2654
|
-
const correlationId = resolveCorrelation(request.headers);
|
|
628
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation(request.headers);
|
|
2655
629
|
try {
|
|
2656
|
-
request.headers.set(
|
|
630
|
+
request.headers.set(CORRELATION_HEADER, correlationId);
|
|
2657
631
|
} catch {
|
|
2658
632
|
}
|
|
2659
|
-
return await runWithCorrelation(
|
|
633
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2660
634
|
correlationId,
|
|
2661
635
|
() => runWithActorAndAuditScope(async () => {
|
|
2662
636
|
const startMs = Date.now();
|
|
@@ -2664,7 +638,7 @@ function withMiddlewareCapture(middleware) {
|
|
|
2664
638
|
const response = await Promise.resolve(runMiddleware(request, ...rest));
|
|
2665
639
|
try {
|
|
2666
640
|
if (response?.headers && typeof response.headers.set === "function") {
|
|
2667
|
-
response.headers.set(
|
|
641
|
+
response.headers.set(CORRELATION_HEADER, correlationId);
|
|
2668
642
|
}
|
|
2669
643
|
} catch {
|
|
2670
644
|
}
|
|
@@ -2680,15 +654,15 @@ function withMiddlewareCapture(middleware) {
|
|
|
2680
654
|
});
|
|
2681
655
|
}
|
|
2682
656
|
} catch (error) {
|
|
2683
|
-
logger.debug(`page navigation capture failed: ${
|
|
657
|
+
chunkV5YNKKTG_cjs.logger.debug(`page navigation capture failed: ${describeError5(error)}`);
|
|
2684
658
|
}
|
|
2685
659
|
return response;
|
|
2686
660
|
})
|
|
2687
661
|
);
|
|
2688
662
|
} catch (preCaptureError) {
|
|
2689
663
|
if (middlewareInvoked) throw preCaptureError;
|
|
2690
|
-
logger.warn(
|
|
2691
|
-
`withMiddlewareCapture pre-handler setup failed (${
|
|
664
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
665
|
+
`withMiddlewareCapture pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this request`
|
|
2692
666
|
);
|
|
2693
667
|
return await Promise.resolve(middleware(request, ...rest));
|
|
2694
668
|
}
|
|
@@ -2728,27 +702,27 @@ async function emitPageNavigationEvent(input) {
|
|
|
2728
702
|
userAgent,
|
|
2729
703
|
remoteIp,
|
|
2730
704
|
contentType: null,
|
|
2731
|
-
excludedVariableKeys: configuration().excludedGraphqlVariableKeys
|
|
705
|
+
excludedVariableKeys: chunkWASXTDLW_cjs.configuration().excludedGraphqlVariableKeys
|
|
2732
706
|
});
|
|
2733
707
|
const { outcome, error_message } = determineOutcome(
|
|
2734
708
|
input.statusCode,
|
|
2735
709
|
null,
|
|
2736
710
|
null
|
|
2737
711
|
);
|
|
2738
|
-
const event = build({
|
|
712
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
2739
713
|
source_type: "http_request",
|
|
2740
714
|
source_data: sourceData,
|
|
2741
715
|
outcome,
|
|
2742
|
-
correlation_id: current(),
|
|
716
|
+
correlation_id: chunkWASXTDLW_cjs.current(),
|
|
2743
717
|
resource_ids: [],
|
|
2744
|
-
context: getCurrentActor() ? { actor: getCurrentActor() } : null,
|
|
718
|
+
context: chunkWASXTDLW_cjs.getCurrentActor() ? { actor: chunkWASXTDLW_cjs.getCurrentActor() } : null,
|
|
2745
719
|
duration_ms: input.durationMs,
|
|
2746
720
|
error_message,
|
|
2747
721
|
timestamp: input.startedAt
|
|
2748
722
|
});
|
|
2749
|
-
pushEvent(event);
|
|
723
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
2750
724
|
} catch (error) {
|
|
2751
|
-
logger.error(`page navigation emit failed: ${
|
|
725
|
+
chunkV5YNKKTG_cjs.logger.error(`page navigation emit failed: ${describeError5(error)}`);
|
|
2752
726
|
}
|
|
2753
727
|
}
|
|
2754
728
|
function pageControllerFromPath(pathname) {
|
|
@@ -2771,7 +745,7 @@ function capturePagesApi(handler, context = {}) {
|
|
|
2771
745
|
return handler(...invokeArgs);
|
|
2772
746
|
};
|
|
2773
747
|
try {
|
|
2774
|
-
if (!configuration().captureHttp) {
|
|
748
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) {
|
|
2775
749
|
return Promise.resolve(runHandler(...args));
|
|
2776
750
|
}
|
|
2777
751
|
const req = args[0];
|
|
@@ -2779,10 +753,10 @@ function capturePagesApi(handler, context = {}) {
|
|
|
2779
753
|
if (!req || !res) return Promise.resolve(runHandler(...args));
|
|
2780
754
|
const snapshot = snapshotPagesRequest(req);
|
|
2781
755
|
if (snapshot === null) return Promise.resolve(runHandler(...args));
|
|
2782
|
-
const correlationId = resolveCorrelation({
|
|
756
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation({
|
|
2783
757
|
get: (name) => readPagesHeader(req, name)
|
|
2784
758
|
});
|
|
2785
|
-
return await runWithCorrelation(
|
|
759
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2786
760
|
correlationId,
|
|
2787
761
|
() => runWithActorAndAuditScope(async () => {
|
|
2788
762
|
await maybeRunActorHookFromPages(req);
|
|
@@ -2813,8 +787,8 @@ function capturePagesApi(handler, context = {}) {
|
|
|
2813
787
|
);
|
|
2814
788
|
} catch (preCaptureError) {
|
|
2815
789
|
if (handlerInvoked) throw preCaptureError;
|
|
2816
|
-
logger.warn(
|
|
2817
|
-
`capturePagesApi pre-handler setup failed (${
|
|
790
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
791
|
+
`capturePagesApi pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this request`
|
|
2818
792
|
);
|
|
2819
793
|
return Promise.resolve(handler(...args));
|
|
2820
794
|
}
|
|
@@ -2828,12 +802,12 @@ function captureServerAction(action, actionName) {
|
|
|
2828
802
|
return action(...invokeArgs);
|
|
2829
803
|
};
|
|
2830
804
|
try {
|
|
2831
|
-
if (!configuration().captureHttp) {
|
|
805
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) {
|
|
2832
806
|
return Promise.resolve(runAction(...args));
|
|
2833
807
|
}
|
|
2834
808
|
const headersAdapter = await readNextHeadersAsAdapter();
|
|
2835
|
-
const correlationId = resolveCorrelation(headersAdapter);
|
|
2836
|
-
return await runWithCorrelation(
|
|
809
|
+
const correlationId = chunkWASXTDLW_cjs.resolveCorrelation(headersAdapter);
|
|
810
|
+
return await chunkWASXTDLW_cjs.runWithCorrelation(
|
|
2837
811
|
correlationId,
|
|
2838
812
|
() => runWithActorAndAuditScope(async () => {
|
|
2839
813
|
const startMs = Date.now();
|
|
@@ -2846,7 +820,10 @@ function captureServerAction(action, actionName) {
|
|
|
2846
820
|
const failure = classifyServerActionResult(result);
|
|
2847
821
|
await emitServerActionEvent({
|
|
2848
822
|
actionName,
|
|
2849
|
-
|
|
823
|
+
// A returned failure (`{ success: false, error }`) is a
|
|
824
|
+
// handled refusal, not a crash: no HTTP status is
|
|
825
|
+
// invented; outcome + error_message carry it.
|
|
826
|
+
statusCode: failure ? null : 200,
|
|
2850
827
|
exception: failure ? new Error(failure.errorMessage) : null,
|
|
2851
828
|
durationMs: Date.now() - startMs,
|
|
2852
829
|
startedAt,
|
|
@@ -2856,9 +833,12 @@ function captureServerAction(action, actionName) {
|
|
|
2856
833
|
} catch (e) {
|
|
2857
834
|
if (isNextControlFlowError(e)) {
|
|
2858
835
|
await maybeExtractSupabaseActor();
|
|
836
|
+
const controlStatus = nextControlFlowStatus(e) ?? 200;
|
|
2859
837
|
await emitServerActionEvent({
|
|
2860
838
|
actionName,
|
|
2861
|
-
|
|
839
|
+
// redirect() is a success; notFound() / forbidden()
|
|
840
|
+
// keep their 4xx.
|
|
841
|
+
statusCode: controlStatus >= 400 ? controlStatus : 200,
|
|
2862
842
|
exception: null,
|
|
2863
843
|
durationMs: Date.now() - startMs,
|
|
2864
844
|
startedAt,
|
|
@@ -2886,8 +866,8 @@ function captureServerAction(action, actionName) {
|
|
|
2886
866
|
);
|
|
2887
867
|
} catch (preCaptureError) {
|
|
2888
868
|
if (actionInvoked) throw preCaptureError;
|
|
2889
|
-
logger.warn(
|
|
2890
|
-
`captureServerAction pre-handler setup failed (${
|
|
869
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
870
|
+
`captureServerAction pre-handler setup failed (${describeError5(preCaptureError)}); bypassing capture for this action`
|
|
2891
871
|
);
|
|
2892
872
|
return Promise.resolve(action(...args));
|
|
2893
873
|
}
|
|
@@ -2908,7 +888,7 @@ async function __ezlogs_run_inline_server_action(actionName, body) {
|
|
|
2908
888
|
return wrapped();
|
|
2909
889
|
}
|
|
2910
890
|
function classifyServerActionResult(result) {
|
|
2911
|
-
const classifier = configuration().isServerActionError;
|
|
891
|
+
const classifier = chunkWASXTDLW_cjs.configuration().isServerActionError;
|
|
2912
892
|
if (classifier) {
|
|
2913
893
|
try {
|
|
2914
894
|
const verdict = classifier(result);
|
|
@@ -2919,7 +899,7 @@ function classifyServerActionResult(result) {
|
|
|
2919
899
|
return verdict;
|
|
2920
900
|
}
|
|
2921
901
|
} catch (error) {
|
|
2922
|
-
logger.debug(`isServerActionError classifier threw: ${
|
|
902
|
+
chunkV5YNKKTG_cjs.logger.debug(`isServerActionError classifier threw: ${describeError5(error)}`);
|
|
2923
903
|
}
|
|
2924
904
|
}
|
|
2925
905
|
if (Array.isArray(result) && result.length === 2 && result[0] === null && isZsaError(result[1])) {
|
|
@@ -3040,10 +1020,23 @@ function conformErrorMessage(result) {
|
|
|
3040
1020
|
return "Form submission failed";
|
|
3041
1021
|
}
|
|
3042
1022
|
function isNextControlFlowError(error) {
|
|
3043
|
-
|
|
1023
|
+
return nextControlFlowStatus(error) !== null;
|
|
1024
|
+
}
|
|
1025
|
+
function nextControlFlowStatus(error) {
|
|
1026
|
+
if (!error || typeof error !== "object") return null;
|
|
3044
1027
|
const digest = error.digest;
|
|
3045
|
-
if (typeof digest !== "string") return
|
|
3046
|
-
|
|
1028
|
+
if (typeof digest !== "string") return null;
|
|
1029
|
+
const parts = digest.split(";");
|
|
1030
|
+
if (parts[0] === "NEXT_REDIRECT") {
|
|
1031
|
+
const status = Number(parts[3]);
|
|
1032
|
+
return status >= 300 && status < 400 ? status : 307;
|
|
1033
|
+
}
|
|
1034
|
+
if (parts[0] === "NEXT_NOT_FOUND") return 404;
|
|
1035
|
+
if (parts[0] === "NEXT_HTTP_ERROR_FALLBACK") {
|
|
1036
|
+
const status = Number(parts[1]);
|
|
1037
|
+
return status >= 400 && status < 500 ? status : 404;
|
|
1038
|
+
}
|
|
1039
|
+
return null;
|
|
3047
1040
|
}
|
|
3048
1041
|
async function emitServerActionEvent(input) {
|
|
3049
1042
|
try {
|
|
@@ -3065,29 +1058,29 @@ async function emitServerActionEvent(input) {
|
|
|
3065
1058
|
rawParams: requestParams,
|
|
3066
1059
|
serverActionName: input.actionName,
|
|
3067
1060
|
userAgent,
|
|
3068
|
-
remoteIp:
|
|
1061
|
+
remoteIp: extractRemoteIp(await readNextHeadersAsAdapter()),
|
|
3069
1062
|
contentType: null,
|
|
3070
|
-
excludedVariableKeys: configuration().excludedGraphqlVariableKeys
|
|
1063
|
+
excludedVariableKeys: chunkWASXTDLW_cjs.configuration().excludedGraphqlVariableKeys
|
|
3071
1064
|
});
|
|
3072
1065
|
const { outcome, error_message } = determineOutcome(
|
|
3073
1066
|
input.statusCode,
|
|
3074
1067
|
input.exception,
|
|
3075
1068
|
null
|
|
3076
1069
|
);
|
|
3077
|
-
const event = build({
|
|
1070
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
3078
1071
|
source_type: "http_request",
|
|
3079
1072
|
source_data: sourceData,
|
|
3080
1073
|
outcome,
|
|
3081
|
-
correlation_id: current(),
|
|
1074
|
+
correlation_id: chunkWASXTDLW_cjs.current(),
|
|
3082
1075
|
resource_ids: [],
|
|
3083
|
-
context: getCurrentActor() ? { actor: getCurrentActor() } : null,
|
|
1076
|
+
context: chunkWASXTDLW_cjs.getCurrentActor() ? { actor: chunkWASXTDLW_cjs.getCurrentActor() } : null,
|
|
3084
1077
|
duration_ms: input.durationMs,
|
|
3085
1078
|
error_message,
|
|
3086
1079
|
timestamp: input.startedAt
|
|
3087
1080
|
});
|
|
3088
|
-
pushEvent(event);
|
|
1081
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
3089
1082
|
} catch (error) {
|
|
3090
|
-
logger.error(`server-action capture emit failed: ${
|
|
1083
|
+
chunkV5YNKKTG_cjs.logger.error(`server-action capture emit failed: ${describeError5(error)}`);
|
|
3091
1084
|
}
|
|
3092
1085
|
}
|
|
3093
1086
|
function extractServerActionArgs(args, actionName) {
|
|
@@ -3167,20 +1160,8 @@ var PAYMENT_ACTION_WORDS = /* @__PURE__ */ new Set([
|
|
|
3167
1160
|
function actionWords(name) {
|
|
3168
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);
|
|
3169
1162
|
}
|
|
3170
|
-
function passesLuhn(digits) {
|
|
3171
|
-
let sum = 0;
|
|
3172
|
-
for (let i = 0; i < digits.length; i += 1) {
|
|
3173
|
-
let d = Number(digits[digits.length - 1 - i]);
|
|
3174
|
-
if (i % 2 === 1) {
|
|
3175
|
-
d *= 2;
|
|
3176
|
-
if (d > 9) d -= 9;
|
|
3177
|
-
}
|
|
3178
|
-
sum += d;
|
|
3179
|
-
}
|
|
3180
|
-
return sum % 10 === 0;
|
|
3181
|
-
}
|
|
3182
1163
|
function looksLikeCardNumber(digits, paymentAction) {
|
|
3183
|
-
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;
|
|
3184
1165
|
return paymentAction || digits.length === 15 || digits.length === 16;
|
|
3185
1166
|
}
|
|
3186
1167
|
function maskPositional(value, flags) {
|
|
@@ -3268,7 +1249,7 @@ function serializeArgValue(value) {
|
|
|
3268
1249
|
return void 0;
|
|
3269
1250
|
}
|
|
3270
1251
|
async function captureHttpEvent(input) {
|
|
3271
|
-
if (!configuration().captureHttp) return;
|
|
1252
|
+
if (!chunkWASXTDLW_cjs.configuration().captureHttp) return;
|
|
3272
1253
|
const snapshot = await snapshotRequest(input.request);
|
|
3273
1254
|
if (snapshot === null) return;
|
|
3274
1255
|
let graphqlErrorMessage = null;
|
|
@@ -3329,59 +1310,59 @@ async function snapshotRequest(request) {
|
|
|
3329
1310
|
}
|
|
3330
1311
|
}
|
|
3331
1312
|
} catch (error) {
|
|
3332
|
-
logger.debug(`http snapshot body-parse failed: ${
|
|
1313
|
+
chunkV5YNKKTG_cjs.logger.debug(`http snapshot body-parse failed: ${describeError5(error)}`);
|
|
3333
1314
|
}
|
|
3334
1315
|
return { method, url, userAgent, remoteIp, contentType, rawParams, graphqlBody, serverActionId };
|
|
3335
1316
|
}
|
|
3336
1317
|
async function maybeRunActorHook(request) {
|
|
3337
|
-
const hook = configuration().actorFromRequest;
|
|
1318
|
+
const hook = chunkWASXTDLW_cjs.configuration().actorFromRequest;
|
|
3338
1319
|
let hookResult = null;
|
|
3339
1320
|
if (hook) {
|
|
3340
1321
|
try {
|
|
3341
1322
|
hookResult = await Promise.resolve(hook(request));
|
|
3342
1323
|
} catch (error) {
|
|
3343
|
-
logger.debug(`actorFromRequest hook failed: ${
|
|
1324
|
+
chunkV5YNKKTG_cjs.logger.debug(`actorFromRequest hook failed: ${describeError5(error)}`);
|
|
3344
1325
|
}
|
|
3345
1326
|
}
|
|
3346
1327
|
const userAgent = safeGetHeader(request.headers, "user-agent");
|
|
3347
1328
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
3348
1329
|
}
|
|
3349
1330
|
async function maybeRunActorHookFromPages(req) {
|
|
3350
|
-
const hook = configuration().actorFromRequest;
|
|
1331
|
+
const hook = chunkWASXTDLW_cjs.configuration().actorFromRequest;
|
|
3351
1332
|
let hookResult = null;
|
|
3352
1333
|
if (hook) {
|
|
3353
1334
|
try {
|
|
3354
1335
|
hookResult = await Promise.resolve(hook(req));
|
|
3355
1336
|
} catch (error) {
|
|
3356
|
-
logger.debug(`actorFromRequest hook (pages) failed: ${
|
|
1337
|
+
chunkV5YNKKTG_cjs.logger.debug(`actorFromRequest hook (pages) failed: ${describeError5(error)}`);
|
|
3357
1338
|
}
|
|
3358
1339
|
}
|
|
3359
1340
|
const userAgent = readPagesHeader(req, "user-agent");
|
|
3360
1341
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
3361
1342
|
}
|
|
3362
1343
|
async function maybeRunActorHookFromServerAction() {
|
|
3363
|
-
const hook = configuration().actorFromRequest;
|
|
1344
|
+
const hook = chunkWASXTDLW_cjs.configuration().actorFromRequest;
|
|
3364
1345
|
const headers = await loadNextHeaders();
|
|
3365
1346
|
if (!hook && !headers) {
|
|
3366
|
-
logger.debug("actorFromRequest (server action): no hook + no next/headers");
|
|
1347
|
+
chunkV5YNKKTG_cjs.logger.debug("actorFromRequest (server action): no hook + no next/headers");
|
|
3367
1348
|
return;
|
|
3368
1349
|
}
|
|
3369
1350
|
let hookResult = null;
|
|
3370
1351
|
if (hook) {
|
|
3371
1352
|
if (!headers) {
|
|
3372
|
-
logger.debug(
|
|
1353
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
3373
1354
|
"actorFromRequest hook (server action): skipped, no next/headers available"
|
|
3374
1355
|
);
|
|
3375
1356
|
} else {
|
|
3376
1357
|
const facade = { headers, method: "POST", url: "" };
|
|
3377
1358
|
try {
|
|
3378
1359
|
hookResult = await Promise.resolve(hook(facade));
|
|
3379
|
-
logger.debug(
|
|
1360
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
3380
1361
|
hookResult ? `actorFromRequest hook (server action): set actor id=${hookResult.id ?? "?"}` : "actorFromRequest hook (server action): returned null/undefined"
|
|
3381
1362
|
);
|
|
3382
1363
|
} catch (error) {
|
|
3383
|
-
logger.debug(
|
|
3384
|
-
`actorFromRequest hook (server action) failed: ${
|
|
1364
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
1365
|
+
`actorFromRequest hook (server action) failed: ${describeError5(error)}`
|
|
3385
1366
|
);
|
|
3386
1367
|
}
|
|
3387
1368
|
}
|
|
@@ -3390,15 +1371,15 @@ async function maybeRunActorHookFromServerAction() {
|
|
|
3390
1371
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
3391
1372
|
}
|
|
3392
1373
|
async function maybeExtractSupabaseActor() {
|
|
3393
|
-
const config = configuration();
|
|
1374
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3394
1375
|
if (!config.actorFromSupabase) return;
|
|
3395
|
-
if (getCurrentActor()) return;
|
|
1376
|
+
if (chunkWASXTDLW_cjs.getCurrentActor()) return;
|
|
3396
1377
|
try {
|
|
3397
|
-
const mod = await
|
|
1378
|
+
const mod = await import('./db/supabase.cjs');
|
|
3398
1379
|
const actor = await mod.tryExtractSupabaseActor();
|
|
3399
|
-
if (actor) setActor(actor);
|
|
1380
|
+
if (actor) chunkWASXTDLW_cjs.setActor(actor);
|
|
3400
1381
|
} catch (error) {
|
|
3401
|
-
logger.debug(`actorFromSupabase failed: ${
|
|
1382
|
+
chunkV5YNKKTG_cjs.logger.debug(`actorFromSupabase failed: ${describeError5(error)}`);
|
|
3402
1383
|
}
|
|
3403
1384
|
}
|
|
3404
1385
|
function snapshotPagesRequest(req) {
|
|
@@ -3475,7 +1456,7 @@ async function loadNextHeaders() {
|
|
|
3475
1456
|
try {
|
|
3476
1457
|
return await Promise.resolve(mod.headers());
|
|
3477
1458
|
} catch (error) {
|
|
3478
|
-
logger.debug(`loadNextHeaders mod.headers() failed: ${
|
|
1459
|
+
chunkV5YNKKTG_cjs.logger.debug(`loadNextHeaders mod.headers() failed: ${describeError5(error)}`);
|
|
3479
1460
|
return null;
|
|
3480
1461
|
}
|
|
3481
1462
|
}
|
|
@@ -3486,8 +1467,8 @@ async function tryLoadNextHeadersModule() {
|
|
|
3486
1467
|
try {
|
|
3487
1468
|
return await import('next/headers.js');
|
|
3488
1469
|
} catch (secondError) {
|
|
3489
|
-
logger.debug(
|
|
3490
|
-
`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)})`
|
|
3491
1472
|
);
|
|
3492
1473
|
return null;
|
|
3493
1474
|
}
|
|
@@ -3505,7 +1486,7 @@ function readPagesHeader(req, name) {
|
|
|
3505
1486
|
async function emitEvent(input) {
|
|
3506
1487
|
try {
|
|
3507
1488
|
await flushTriggerAuditLog();
|
|
3508
|
-
const config = configuration();
|
|
1489
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3509
1490
|
let graphql = null;
|
|
3510
1491
|
if (input.snapshot.graphqlBody !== null) {
|
|
3511
1492
|
const parsed = parseGraphqlBody(
|
|
@@ -3534,45 +1515,46 @@ async function emitEvent(input) {
|
|
|
3534
1515
|
const { outcome, error_message } = determineOutcome(
|
|
3535
1516
|
input.statusCode,
|
|
3536
1517
|
input.exception,
|
|
3537
|
-
input.graphqlErrorMessage
|
|
1518
|
+
input.graphqlErrorMessage,
|
|
1519
|
+
input.responseErrorMessage ?? null
|
|
3538
1520
|
);
|
|
3539
|
-
const contextValue =
|
|
3540
|
-
const event = build({
|
|
1521
|
+
const contextValue = buildContext();
|
|
1522
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
3541
1523
|
source_type: "http_request",
|
|
3542
1524
|
source_data: sourceData,
|
|
3543
1525
|
outcome,
|
|
3544
|
-
correlation_id: current(),
|
|
1526
|
+
correlation_id: chunkWASXTDLW_cjs.current(),
|
|
3545
1527
|
resource_ids: [],
|
|
3546
1528
|
context: contextValue,
|
|
3547
1529
|
duration_ms: input.durationMs,
|
|
3548
1530
|
error_message,
|
|
3549
1531
|
timestamp: input.startedAt
|
|
3550
1532
|
});
|
|
3551
|
-
pushEvent(event);
|
|
1533
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
3552
1534
|
} catch (error) {
|
|
3553
|
-
const cid = current();
|
|
1535
|
+
const cid = chunkWASXTDLW_cjs.current();
|
|
3554
1536
|
const cidLabel = cid ? ` (correlation_id=${cid})` : "";
|
|
3555
|
-
logger.error(`http capture emit failed${cidLabel}: ${
|
|
1537
|
+
chunkV5YNKKTG_cjs.logger.error(`http capture emit failed${cidLabel}: ${describeError5(error)}`);
|
|
3556
1538
|
}
|
|
3557
1539
|
}
|
|
3558
|
-
function
|
|
3559
|
-
const currentActor = getCurrentActor();
|
|
1540
|
+
function buildContext() {
|
|
1541
|
+
const currentActor = chunkWASXTDLW_cjs.getCurrentActor();
|
|
3560
1542
|
if (!currentActor) return null;
|
|
3561
1543
|
return { actor: currentActor };
|
|
3562
1544
|
}
|
|
3563
1545
|
async function flushTriggerAuditLog() {
|
|
3564
|
-
const reader = configuration().databaseReader;
|
|
1546
|
+
const reader = chunkWASXTDLW_cjs.configuration().databaseReader;
|
|
3565
1547
|
if (!reader) return;
|
|
3566
|
-
await flushAuditLog(reader);
|
|
1548
|
+
await chunkYX2XPLOA_cjs.flushAuditLog(reader);
|
|
3567
1549
|
}
|
|
3568
1550
|
function runWithActorAndAuditScope(callback) {
|
|
3569
|
-
if (configuration().databaseReader == null) {
|
|
3570
|
-
return runWithActorScope(callback);
|
|
1551
|
+
if (chunkWASXTDLW_cjs.configuration().databaseReader == null) {
|
|
1552
|
+
return chunkWASXTDLW_cjs.runWithActorScope(callback);
|
|
3571
1553
|
}
|
|
3572
|
-
return runWithActorScope(() => runWithEmittedAuditIdsScope(callback));
|
|
1554
|
+
return chunkWASXTDLW_cjs.runWithActorScope(() => chunkYX2XPLOA_cjs.runWithEmittedAuditIdsScope(callback));
|
|
3573
1555
|
}
|
|
3574
1556
|
function isExcludedPath(path, method) {
|
|
3575
|
-
const config = configuration();
|
|
1557
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3576
1558
|
const normalizedMethod = (method ?? "").toUpperCase();
|
|
3577
1559
|
for (const pattern of config.allExcludedPaths()) {
|
|
3578
1560
|
if (typeof pattern === "string") {
|
|
@@ -3584,7 +1566,7 @@ function isExcludedPath(path, method) {
|
|
|
3584
1566
|
return true;
|
|
3585
1567
|
}
|
|
3586
1568
|
}
|
|
3587
|
-
if (hasExcludedExtension(path, DEFAULT_EXCLUDED_EXTENSIONS)) return true;
|
|
1569
|
+
if (hasExcludedExtension(path, chunkWASXTDLW_cjs.DEFAULT_EXCLUDED_EXTENSIONS)) return true;
|
|
3588
1570
|
return false;
|
|
3589
1571
|
}
|
|
3590
1572
|
function extractRemoteIp(headers) {
|
|
@@ -3606,6 +1588,40 @@ function safeJsonParse(text) {
|
|
|
3606
1588
|
return null;
|
|
3607
1589
|
}
|
|
3608
1590
|
}
|
|
1591
|
+
async function readRouteParams(routeContext) {
|
|
1592
|
+
try {
|
|
1593
|
+
const params = await routeContext?.params;
|
|
1594
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) return null;
|
|
1595
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
1596
|
+
} catch {
|
|
1597
|
+
return null;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
function mergeRouteParams(rawParams, routeParams) {
|
|
1601
|
+
if (!routeParams) return rawParams;
|
|
1602
|
+
if (rawParams === null || rawParams === void 0) return { ...routeParams };
|
|
1603
|
+
if (typeof rawParams !== "object" || Array.isArray(rawParams)) return rawParams;
|
|
1604
|
+
return { ...routeParams, ...rawParams };
|
|
1605
|
+
}
|
|
1606
|
+
var MAX_ERROR_BODY_LENGTH = 16384;
|
|
1607
|
+
async function readResponseErrorMessage(response) {
|
|
1608
|
+
try {
|
|
1609
|
+
if (response.status < 400) return null;
|
|
1610
|
+
if (!(response.headers.get("content-type") ?? "").includes("json")) return null;
|
|
1611
|
+
if (Number(response.headers.get("content-length") ?? 0) > MAX_ERROR_BODY_LENGTH) return null;
|
|
1612
|
+
const text = await response.clone().text();
|
|
1613
|
+
if (!text || text.length > MAX_ERROR_BODY_LENGTH) return null;
|
|
1614
|
+
const body = safeJsonParse(text);
|
|
1615
|
+
if (!body || typeof body !== "object") return null;
|
|
1616
|
+
const nested = body.error;
|
|
1617
|
+
const raw = [body.error, body.message, nested?.message].find(
|
|
1618
|
+
(v) => typeof v === "string" && v.trim().length > 0
|
|
1619
|
+
);
|
|
1620
|
+
return raw ? truncate(chunkWASXTDLW_cjs.scrubSecretsInText(raw.trim(), { emails: true })) : null;
|
|
1621
|
+
} catch {
|
|
1622
|
+
return null;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
3609
1625
|
async function readGraphqlErrors(response) {
|
|
3610
1626
|
try {
|
|
3611
1627
|
const cloned = response.clone();
|
|
@@ -3617,7 +1633,7 @@ async function readGraphqlErrors(response) {
|
|
|
3617
1633
|
return null;
|
|
3618
1634
|
}
|
|
3619
1635
|
}
|
|
3620
|
-
function
|
|
1636
|
+
function describeError5(error) {
|
|
3621
1637
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
3622
1638
|
return String(error);
|
|
3623
1639
|
}
|
|
@@ -3625,23 +1641,23 @@ function applyActorFromHookAndUa(hookResult, userAgent) {
|
|
|
3625
1641
|
const uaMatch = classifyUserAgent(userAgent);
|
|
3626
1642
|
if (hookResult != null && typeof hookResult === "object" && !Array.isArray(hookResult)) {
|
|
3627
1643
|
if (uaMatch === null) {
|
|
3628
|
-
setActor(hookResult);
|
|
1644
|
+
chunkWASXTDLW_cjs.setActor(hookResult);
|
|
3629
1645
|
return;
|
|
3630
1646
|
}
|
|
3631
1647
|
const hookObj = hookResult;
|
|
3632
1648
|
const existingKind = hookObj.kind;
|
|
3633
1649
|
if (typeof existingKind === "string" && existingKind.length > 0) {
|
|
3634
|
-
setActor(hookObj);
|
|
1650
|
+
chunkWASXTDLW_cjs.setActor(hookObj);
|
|
3635
1651
|
return;
|
|
3636
1652
|
}
|
|
3637
|
-
setActor({ ...hookObj, kind: uaMatch.kind });
|
|
1653
|
+
chunkWASXTDLW_cjs.setActor({ ...hookObj, kind: uaMatch.kind });
|
|
3638
1654
|
return;
|
|
3639
1655
|
}
|
|
3640
1656
|
if (uaMatch !== null) {
|
|
3641
|
-
setActor(synthesizeAgentActor(uaMatch));
|
|
1657
|
+
chunkWASXTDLW_cjs.setActor(synthesizeAgentActor(uaMatch));
|
|
3642
1658
|
return;
|
|
3643
1659
|
}
|
|
3644
|
-
setActor(null);
|
|
1660
|
+
chunkWASXTDLW_cjs.setActor(null);
|
|
3645
1661
|
}
|
|
3646
1662
|
function synthesizeAgentActor(detection) {
|
|
3647
1663
|
return {
|
|
@@ -3669,9 +1685,9 @@ function markBeforeExitInstalled() {
|
|
|
3669
1685
|
}
|
|
3670
1686
|
var ezlogs = {
|
|
3671
1687
|
init(options) {
|
|
3672
|
-
const config = configuration();
|
|
1688
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3673
1689
|
config.apply(options);
|
|
3674
|
-
if (options.logLevel) setLogLevel(options.logLevel);
|
|
1690
|
+
if (options.logLevel) chunkV5YNKKTG_cjs.setLogLevel(options.logLevel);
|
|
3675
1691
|
warnIfInsecureServerUrl(config.serverUrl, config.allowInsecureTransport);
|
|
3676
1692
|
flushScheduler.start();
|
|
3677
1693
|
if (config.patchGlobalFetch) patchGlobalFetch();
|
|
@@ -3687,7 +1703,7 @@ var ezlogs = {
|
|
|
3687
1703
|
}
|
|
3688
1704
|
});
|
|
3689
1705
|
} else if (options.patchDatabaseClient) {
|
|
3690
|
-
patchPgClient(
|
|
1706
|
+
chunkY5NSHKWQ_cjs.patchPgClient(
|
|
3691
1707
|
options.patchDatabaseClient
|
|
3692
1708
|
);
|
|
3693
1709
|
}
|
|
@@ -3734,7 +1750,7 @@ function detectDatabaseUrlFromEnv() {
|
|
|
3734
1750
|
return null;
|
|
3735
1751
|
}
|
|
3736
1752
|
async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
3737
|
-
const config = configuration();
|
|
1753
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3738
1754
|
let pg;
|
|
3739
1755
|
try {
|
|
3740
1756
|
const dynImport = new Function(
|
|
@@ -3743,7 +1759,7 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
|
3743
1759
|
);
|
|
3744
1760
|
pg = await dynImport("pg");
|
|
3745
1761
|
} catch {
|
|
3746
|
-
logger.warn(
|
|
1762
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
3747
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)."
|
|
3748
1764
|
);
|
|
3749
1765
|
return;
|
|
@@ -3753,7 +1769,7 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
|
3753
1769
|
max: 4
|
|
3754
1770
|
});
|
|
3755
1771
|
const reader = (sql, params) => pool.query(sql, params);
|
|
3756
|
-
if (await auditLogInstalled(reader) === false) {
|
|
1772
|
+
if (await chunkYX2XPLOA_cjs.auditLogInstalled(reader) === false) {
|
|
3757
1773
|
warnAuditLogMissing();
|
|
3758
1774
|
void pool.end?.().catch(() => {
|
|
3759
1775
|
});
|
|
@@ -3762,43 +1778,43 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
|
|
|
3762
1778
|
if (config.databaseReader === null) {
|
|
3763
1779
|
config.databaseReader = reader;
|
|
3764
1780
|
}
|
|
3765
|
-
patchPgClient(pg);
|
|
3766
|
-
void checkAuditLogAccess(reader);
|
|
1781
|
+
chunkY5NSHKWQ_cjs.patchPgClient(pg);
|
|
1782
|
+
void chunkYX2XPLOA_cjs.checkAuditLogAccess(reader);
|
|
3767
1783
|
runTriggerTrackedTablesDetection();
|
|
3768
1784
|
}
|
|
3769
1785
|
function applyDatabaseReaderDefaults() {
|
|
3770
|
-
const config = configuration();
|
|
1786
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3771
1787
|
const reader = config.databaseReader;
|
|
3772
1788
|
if (!reader) return;
|
|
3773
|
-
auditLogInstalled(reader).then((installed) => {
|
|
1789
|
+
chunkYX2XPLOA_cjs.auditLogInstalled(reader).then((installed) => {
|
|
3774
1790
|
if (installed === false && config.databaseReader === reader) {
|
|
3775
1791
|
config.databaseReader = null;
|
|
3776
1792
|
warnAuditLogMissing();
|
|
3777
1793
|
return;
|
|
3778
1794
|
}
|
|
3779
|
-
if (installed === true) void checkAuditLogAccess(reader);
|
|
1795
|
+
if (installed === true) void chunkYX2XPLOA_cjs.checkAuditLogAccess(reader);
|
|
3780
1796
|
runTriggerTrackedTablesDetection();
|
|
3781
1797
|
}).catch(() => {
|
|
3782
1798
|
});
|
|
3783
1799
|
}
|
|
3784
1800
|
function warnAuditLogMissing() {
|
|
3785
|
-
logger.warn(
|
|
1801
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
3786
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."
|
|
3787
1803
|
);
|
|
3788
1804
|
}
|
|
3789
1805
|
function runTriggerTrackedTablesDetection() {
|
|
3790
|
-
const config = configuration();
|
|
1806
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
3791
1807
|
if (!config.databaseReader) return;
|
|
3792
1808
|
if (config.triggerTrackedTables !== null) return;
|
|
3793
|
-
detectTriggerTrackedTables(config.databaseReader).then((tables) => {
|
|
1809
|
+
chunkYX2XPLOA_cjs.detectTriggerTrackedTables(config.databaseReader).then((tables) => {
|
|
3794
1810
|
if (tables === null) {
|
|
3795
|
-
logger.debug(
|
|
1811
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
3796
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')`."
|
|
3797
1813
|
);
|
|
3798
1814
|
return;
|
|
3799
1815
|
}
|
|
3800
1816
|
config.triggerTrackedTables = tables;
|
|
3801
|
-
logger.debug(
|
|
1817
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
3802
1818
|
`[ezlogs] trigger-tracked tables: ${tables.size === 0 ? "(none)" : Array.from(tables).sort().join(", ")}`
|
|
3803
1819
|
);
|
|
3804
1820
|
}).catch(() => {
|
|
@@ -3830,13 +1846,20 @@ function warnIfInsecureServerUrl(serverUrl, allowInsecure) {
|
|
|
3830
1846
|
);
|
|
3831
1847
|
}
|
|
3832
1848
|
function _internalsForTests() {
|
|
3833
|
-
return { buffer: buffer_exports, flushScheduler };
|
|
1849
|
+
return { buffer: chunkWASXTDLW_cjs.buffer_exports, flushScheduler };
|
|
3834
1850
|
}
|
|
3835
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
|
+
});
|
|
3836
1860
|
exports.__ezlogs_run_inline_server_action = __ezlogs_run_inline_server_action;
|
|
3837
1861
|
exports._detectDatabaseUrlFromEnvForTests = _detectDatabaseUrlFromEnvForTests;
|
|
3838
1862
|
exports._internalsForTests = _internalsForTests;
|
|
3839
|
-
exports.buildEvent = build;
|
|
3840
1863
|
exports.captureHttpEvent = captureHttpEvent;
|
|
3841
1864
|
exports.capturePagesApi = capturePagesApi;
|
|
3842
1865
|
exports.captureRoute = captureRoute;
|