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/db/supabase.js
CHANGED
|
@@ -1,713 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/logger.ts
|
|
9
|
-
var LEVEL_RANK = {
|
|
10
|
-
debug: 10,
|
|
11
|
-
info: 20,
|
|
12
|
-
warn: 30,
|
|
13
|
-
error: 40,
|
|
14
|
-
silent: 100
|
|
15
|
-
};
|
|
16
|
-
var LEVEL_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:log-level");
|
|
17
|
-
function readLevel() {
|
|
18
|
-
const g = globalThis;
|
|
19
|
-
return g[LEVEL_KEY] ?? "warn";
|
|
20
|
-
}
|
|
21
|
-
function shouldLog(level) {
|
|
22
|
-
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
23
|
-
}
|
|
24
|
-
function safeWrite(level, message) {
|
|
25
|
-
try {
|
|
26
|
-
if (!shouldLog(level)) return;
|
|
27
|
-
const line = `[ezlogs] ${message}`;
|
|
28
|
-
if (level === "error" || level === "warn") {
|
|
29
|
-
console.error(line);
|
|
30
|
-
} else {
|
|
31
|
-
console.log(line);
|
|
32
|
-
}
|
|
33
|
-
} catch {
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
var logger = {
|
|
37
|
-
debug: (message) => safeWrite("debug", message),
|
|
38
|
-
info: (message) => safeWrite("info", message),
|
|
39
|
-
warn: (message) => safeWrite("warn", message),
|
|
40
|
-
error: (message) => safeWrite("error", message)
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/configuration.ts
|
|
44
|
-
var DEFAULT_EXCLUDED_PATHS = Object.freeze([
|
|
45
|
-
// Next.js / Vercel infrastructure noise
|
|
46
|
-
"/_next/*",
|
|
47
|
-
"/_vercel/*",
|
|
48
|
-
"/__nextjs_*",
|
|
49
|
-
// NextAuth.js / Auth.js — skip session-refresh polls and CSRF/provider
|
|
50
|
-
// metadata GETs (high-frequency, no business meaning), but CAPTURE
|
|
51
|
-
// POSTs (callbacks, signin, signout, register). The POSTs are the
|
|
52
|
-
// actual auth events users care about; the GETs are pure plumbing.
|
|
53
|
-
Object.freeze({ path: "/api/auth/*", methods: ["GET", "HEAD"] }),
|
|
54
|
-
// Generic infrastructure
|
|
55
|
-
"/health*",
|
|
56
|
-
"/api/health",
|
|
57
|
-
"/up",
|
|
58
|
-
"/alive",
|
|
59
|
-
"/ready",
|
|
60
|
-
"/metrics",
|
|
61
|
-
"/favicon.ico",
|
|
62
|
-
"/.well-known*",
|
|
63
|
-
"/robots.txt",
|
|
64
|
-
"/sitemap.xml",
|
|
65
|
-
"/*.hot-update.*",
|
|
66
|
-
// Auth routes (common patterns across Clerk, NextAuth, custom auth)
|
|
67
|
-
"*/login*",
|
|
68
|
-
"*/logout*",
|
|
69
|
-
"*/sign-in*",
|
|
70
|
-
"*/sign-out*",
|
|
71
|
-
"*/signin*",
|
|
72
|
-
"*/signout*",
|
|
73
|
-
"/session*"
|
|
74
|
-
]);
|
|
75
|
-
var DEFAULT_EXCLUDED_TABLES = Object.freeze([
|
|
76
|
-
// Prisma migration ledger
|
|
77
|
-
"_prisma_migrations",
|
|
78
|
-
// Auth.js / NextAuth Prisma adapter — session/verification-token churn
|
|
79
|
-
// is auth machinery, not business activity. Account/User stay captured.
|
|
80
|
-
"Session",
|
|
81
|
-
"VerificationToken",
|
|
82
|
-
// Common cross-stack convention names for the same things
|
|
83
|
-
"sessions",
|
|
84
|
-
"session",
|
|
85
|
-
"verification_tokens"
|
|
86
|
-
]);
|
|
87
|
-
var DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
|
|
88
|
-
var DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
|
|
89
|
-
var Configuration = class {
|
|
90
|
-
serverUrl = null;
|
|
91
|
-
projectToken = null;
|
|
92
|
-
captureHttp = true;
|
|
93
|
-
captureDb = true;
|
|
94
|
-
captureJobs = true;
|
|
95
|
-
bufferSize = 1e4;
|
|
96
|
-
/** Default 3000 ms — equivalent to Ruby's 3 seconds. */
|
|
97
|
-
sendInterval = 3e3;
|
|
98
|
-
retryAttempts = 3;
|
|
99
|
-
logLevel = "warn";
|
|
100
|
-
patchGlobalFetch = true;
|
|
101
|
-
actorFromSupabase = true;
|
|
102
|
-
allowInsecureTransport = false;
|
|
103
|
-
excludedPaths = [];
|
|
104
|
-
excludedTables = [];
|
|
105
|
-
excludedJobClasses = [];
|
|
106
|
-
excludedGraphqlOperations = [];
|
|
107
|
-
excludedGraphqlVariableKeys = [];
|
|
108
|
-
actorFromRequest = null;
|
|
109
|
-
displayNameFor = {};
|
|
110
|
-
isServerActionError = null;
|
|
111
|
-
databaseReader = null;
|
|
112
|
-
databaseUrl = null;
|
|
113
|
-
/**
|
|
114
|
-
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
115
|
-
* at agent startup by reading `information_schema.triggers`. The
|
|
116
|
-
* supabase / drizzle / prisma adapters use this to decide whether
|
|
117
|
-
* their per-mutation emit is redundant: if the table is trigger-
|
|
118
|
-
* tracked the audit-log reader will surface the same write with full
|
|
119
|
-
* old/new state, so the adapter's emit is suppressed. Tables NOT in
|
|
120
|
-
* this set fall through to the adapter so they're still captured.
|
|
121
|
-
*
|
|
122
|
-
* `null` means "detection hasn't run yet or failed" — in that state
|
|
123
|
-
* `databaseReader`-wired apps suppress every adapter emit (the
|
|
124
|
-
* original Phase 5 behavior). After detection completes the agent
|
|
125
|
-
* gives the more accurate per-table answer.
|
|
126
|
-
*/
|
|
127
|
-
triggerTrackedTables = null;
|
|
128
|
-
apply(options) {
|
|
129
|
-
this.serverUrl = options.serverUrl;
|
|
130
|
-
this.projectToken = options.projectToken;
|
|
131
|
-
if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
|
|
132
|
-
if (options.captureDb !== void 0) this.captureDb = options.captureDb;
|
|
133
|
-
if (options.captureJobs !== void 0) this.captureJobs = options.captureJobs;
|
|
134
|
-
if (options.bufferSize !== void 0) this.bufferSize = options.bufferSize;
|
|
135
|
-
if (options.sendInterval !== void 0) this.sendInterval = options.sendInterval;
|
|
136
|
-
if (options.retryAttempts !== void 0) this.retryAttempts = options.retryAttempts;
|
|
137
|
-
if (options.excludedPaths) this.excludedPaths = [...options.excludedPaths];
|
|
138
|
-
if (options.excludedTables) this.excludedTables = [...options.excludedTables];
|
|
139
|
-
if (options.excludedJobClasses) {
|
|
140
|
-
this.excludedJobClasses = [...options.excludedJobClasses];
|
|
141
|
-
}
|
|
142
|
-
if (options.excludedGraphqlOperations) {
|
|
143
|
-
this.excludedGraphqlOperations = [...options.excludedGraphqlOperations];
|
|
144
|
-
}
|
|
145
|
-
if (options.excludedGraphqlVariableKeys) {
|
|
146
|
-
this.excludedGraphqlVariableKeys = [...options.excludedGraphqlVariableKeys];
|
|
147
|
-
}
|
|
148
|
-
if (options.actorFromRequest) this.actorFromRequest = options.actorFromRequest;
|
|
149
|
-
if (options.displayNameFor) this.displayNameFor = { ...options.displayNameFor };
|
|
150
|
-
if (options.isServerActionError) this.isServerActionError = options.isServerActionError;
|
|
151
|
-
if (options.patchGlobalFetch !== void 0) {
|
|
152
|
-
this.patchGlobalFetch = options.patchGlobalFetch;
|
|
153
|
-
}
|
|
154
|
-
if (options.allowInsecureTransport !== void 0) {
|
|
155
|
-
this.allowInsecureTransport = options.allowInsecureTransport;
|
|
156
|
-
}
|
|
157
|
-
if (options.actorFromSupabase !== void 0) {
|
|
158
|
-
this.actorFromSupabase = options.actorFromSupabase;
|
|
159
|
-
}
|
|
160
|
-
if (options.databaseReader !== void 0) {
|
|
161
|
-
this.databaseReader = options.databaseReader;
|
|
162
|
-
}
|
|
163
|
-
if (options.databaseUrl !== void 0) {
|
|
164
|
-
this.databaseUrl = options.databaseUrl;
|
|
165
|
-
}
|
|
166
|
-
if (options.logLevel) this.logLevel = options.logLevel;
|
|
167
|
-
}
|
|
168
|
-
allExcludedPaths() {
|
|
169
|
-
return [...DEFAULT_EXCLUDED_PATHS, ...this.excludedPaths];
|
|
170
|
-
}
|
|
171
|
-
allExcludedTables() {
|
|
172
|
-
return [...DEFAULT_EXCLUDED_TABLES, ...this.excludedTables];
|
|
173
|
-
}
|
|
174
|
-
allExcludedJobClasses() {
|
|
175
|
-
return [...DEFAULT_EXCLUDED_JOB_CLASSES, ...this.excludedJobClasses];
|
|
176
|
-
}
|
|
177
|
-
allExcludedGraphqlOperations() {
|
|
178
|
-
return [...DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, ...this.excludedGraphqlOperations];
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
var GLOBAL_CONFIG_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:configuration");
|
|
182
|
-
function configuration() {
|
|
183
|
-
const g = globalThis;
|
|
184
|
-
if (!g[GLOBAL_CONFIG_KEY]) {
|
|
185
|
-
g[GLOBAL_CONFIG_KEY] = new Configuration();
|
|
186
|
-
}
|
|
187
|
-
return g[GLOBAL_CONFIG_KEY];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// src/event-builder.ts
|
|
191
|
-
var SENSITIVE_KEYS = Object.freeze([
|
|
192
|
-
"password",
|
|
193
|
-
"token",
|
|
194
|
-
"secret",
|
|
195
|
-
"api_key",
|
|
196
|
-
"credit_card"
|
|
197
|
-
]);
|
|
198
|
-
var VALID_SOURCE_TYPES = [
|
|
199
|
-
"http_request",
|
|
200
|
-
"background_job",
|
|
201
|
-
"database_callback"
|
|
202
|
-
];
|
|
203
|
-
var VALID_OUTCOMES = ["success", "failure"];
|
|
204
|
-
function build(input) {
|
|
205
|
-
const source_type = validateSourceType(input.source_type);
|
|
206
|
-
const source_data_raw = validateSourceData(input.source_data);
|
|
207
|
-
const outcome = validateOutcome(input.outcome);
|
|
208
|
-
const timestamp = validateTimestamp(input.timestamp ?? null);
|
|
209
|
-
const resource_ids = validateResourceIds(input.resource_ids ?? []);
|
|
210
|
-
const context_raw = validateContext(input.context ?? null);
|
|
211
|
-
const duration_ms = validateDurationMs();
|
|
212
|
-
const error_message = input.error_message ?? null;
|
|
213
|
-
validateOutcomeErrorConsistency(outcome, error_message);
|
|
214
|
-
const source_data = sanitizeRecord(source_data_raw);
|
|
215
|
-
const context = context_raw === null ? null : sanitizeRecord(context_raw);
|
|
216
|
-
const correlation_id = input.correlation_id ?? null;
|
|
217
|
-
const event = {
|
|
218
|
-
timestamp,
|
|
219
|
-
source_type,
|
|
220
|
-
source_data,
|
|
221
|
-
outcome,
|
|
222
|
-
correlation_id,
|
|
223
|
-
resource_ids,
|
|
224
|
-
context,
|
|
225
|
-
duration_ms,
|
|
226
|
-
error_message
|
|
227
|
-
};
|
|
228
|
-
return event;
|
|
229
|
-
}
|
|
230
|
-
function validateSourceType(value) {
|
|
231
|
-
const normalized = String(value);
|
|
232
|
-
if (!VALID_SOURCE_TYPES.includes(normalized)) {
|
|
233
|
-
throw new ArgError(
|
|
234
|
-
`source_type must be one of ${VALID_SOURCE_TYPES.join(", ")}, got: ${normalized}`
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
return normalized;
|
|
238
|
-
}
|
|
239
|
-
function validateSourceData(value) {
|
|
240
|
-
if (value === null || value === void 0) {
|
|
241
|
-
throw new ArgError("source_data is required");
|
|
242
|
-
}
|
|
243
|
-
if (!isPlainObject(value)) {
|
|
244
|
-
throw new ArgError(
|
|
245
|
-
`source_data must be an object, got: ${describe(value)}`
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
return value;
|
|
249
|
-
}
|
|
250
|
-
function validateOutcome(value) {
|
|
251
|
-
const normalized = String(value);
|
|
252
|
-
if (!VALID_OUTCOMES.includes(normalized)) {
|
|
253
|
-
throw new ArgError(
|
|
254
|
-
`outcome must be one of ${VALID_OUTCOMES.join(", ")}, got: ${normalized}`
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
return normalized;
|
|
258
|
-
}
|
|
259
|
-
function validateTimestamp(value) {
|
|
260
|
-
if (value === null) {
|
|
261
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
262
|
-
}
|
|
263
|
-
if (typeof value === "string") {
|
|
264
|
-
const parsed = new Date(value);
|
|
265
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
266
|
-
throw new ArgError(
|
|
267
|
-
`timestamp must be valid ISO 8601 format, got: ${value}`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
return value;
|
|
271
|
-
}
|
|
272
|
-
if (value instanceof Date) {
|
|
273
|
-
if (Number.isNaN(value.getTime())) {
|
|
274
|
-
throw new ArgError("timestamp must be a valid Date");
|
|
275
|
-
}
|
|
276
|
-
return value.toISOString();
|
|
277
|
-
}
|
|
278
|
-
throw new ArgError(
|
|
279
|
-
`timestamp must be a string or Date, got: ${describe(value)}`
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
function validateResourceIds(value) {
|
|
283
|
-
if (!Array.isArray(value)) {
|
|
284
|
-
throw new ArgError(`resource_ids must be an array, got: ${describe(value)}`);
|
|
285
|
-
}
|
|
286
|
-
value.forEach((entry, index) => {
|
|
287
|
-
if (!isPlainObject(entry)) {
|
|
288
|
-
throw new ArgError(
|
|
289
|
-
`resource_ids[${index}] must be an object, got: ${describe(entry)}`
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
const e = entry;
|
|
293
|
-
if (!("resource_type" in e) || !("resource_id" in e)) {
|
|
294
|
-
throw new ArgError(
|
|
295
|
-
`resource_ids[${index}] must have resource_type and resource_id keys, got: ${Object.keys(e).join(", ")}`
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
if (typeof e.resource_type !== "string") {
|
|
299
|
-
throw new ArgError(
|
|
300
|
-
`resource_ids[${index}].resource_type must be a string, got: ${describe(e.resource_type)}`
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
if (typeof e.resource_id !== "string") {
|
|
304
|
-
throw new ArgError(
|
|
305
|
-
`resource_ids[${index}].resource_id must be a string, got: ${describe(e.resource_id)}`
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
return value;
|
|
310
|
-
}
|
|
311
|
-
function validateContext(value) {
|
|
312
|
-
if (value === null) return null;
|
|
313
|
-
if (!isPlainObject(value)) {
|
|
314
|
-
throw new ArgError(
|
|
315
|
-
`context must be an object or null, got: ${describe(value)}`
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
return value;
|
|
319
|
-
}
|
|
320
|
-
function validateDurationMs(value) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
function validateOutcomeErrorConsistency(outcome, error_message) {
|
|
324
|
-
if (outcome === "failure") {
|
|
325
|
-
if (error_message === null || error_message === "") {
|
|
326
|
-
throw new ArgError("error_message is required when outcome is 'failure'");
|
|
327
|
-
}
|
|
328
|
-
} else if (outcome === "success") {
|
|
329
|
-
if (error_message !== null) {
|
|
330
|
-
throw new ArgError("error_message must be null when outcome is 'success'");
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
function sanitizeRecord(input) {
|
|
335
|
-
const result = {};
|
|
336
|
-
for (const key of Object.keys(input)) {
|
|
337
|
-
const value = input[key];
|
|
338
|
-
if (isSensitiveKey(key)) {
|
|
339
|
-
result[key] = "[FILTERED]";
|
|
340
|
-
} else if (isPlainObject(value)) {
|
|
341
|
-
result[key] = sanitizeRecord(value);
|
|
342
|
-
} else if (Array.isArray(value)) {
|
|
343
|
-
result[key] = value.map(
|
|
344
|
-
(item) => isPlainObject(item) ? sanitizeRecord(item) : item
|
|
345
|
-
);
|
|
346
|
-
} else {
|
|
347
|
-
result[key] = value;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return result;
|
|
351
|
-
}
|
|
352
|
-
function isSensitiveKey(key) {
|
|
353
|
-
const lower = key.toLowerCase();
|
|
354
|
-
return SENSITIVE_KEYS.some((p) => lower.includes(p));
|
|
355
|
-
}
|
|
356
|
-
function isPlainObject(value) {
|
|
357
|
-
if (value === null || typeof value !== "object") return false;
|
|
358
|
-
const proto = Object.getPrototypeOf(value);
|
|
359
|
-
return proto === Object.prototype || proto === null;
|
|
360
|
-
}
|
|
361
|
-
function describe(value) {
|
|
362
|
-
if (value === null) return "null";
|
|
363
|
-
if (Array.isArray(value)) return "Array";
|
|
364
|
-
return typeof value;
|
|
365
|
-
}
|
|
366
|
-
var ArgError = class extends Error {
|
|
367
|
-
constructor(message) {
|
|
368
|
-
super(message);
|
|
369
|
-
this.name = "ArgError";
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
// src/pipeline/buffer.ts
|
|
374
|
-
var GLOBAL_QUEUE_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:buffer-queue");
|
|
375
|
-
function getQueue() {
|
|
376
|
-
const g = globalThis;
|
|
377
|
-
if (!g[GLOBAL_QUEUE_KEY]) g[GLOBAL_QUEUE_KEY] = [];
|
|
378
|
-
return g[GLOBAL_QUEUE_KEY];
|
|
379
|
-
}
|
|
380
|
-
function pushEvent(event) {
|
|
381
|
-
try {
|
|
382
|
-
const queue = getQueue();
|
|
383
|
-
const max = maxSize();
|
|
384
|
-
if (queue.length >= max) {
|
|
385
|
-
queue.shift();
|
|
386
|
-
logger.warn(`Buffer full (${max}), dropped oldest event`);
|
|
387
|
-
}
|
|
388
|
-
queue.push(event);
|
|
389
|
-
} catch (error) {
|
|
390
|
-
logger.error(`pushEvent failed: ${describe2(error)}`);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function maxSize() {
|
|
394
|
-
try {
|
|
395
|
-
return configuration().bufferSize;
|
|
396
|
-
} catch {
|
|
397
|
-
return 1e4;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function describe2(error) {
|
|
401
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
402
|
-
return String(error);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// src/edge-fallback.ts
|
|
406
|
-
var ALS_CTOR = loadAsyncLocalStorage();
|
|
407
|
-
function loadAsyncLocalStorage() {
|
|
408
|
-
const fromGlobal = globalThis.AsyncLocalStorage;
|
|
409
|
-
if (typeof fromGlobal === "function") return fromGlobal;
|
|
410
|
-
try {
|
|
411
|
-
const req = typeof __require !== "undefined" ? __require : (
|
|
412
|
-
// In ESM, `createRequire` is the official escape hatch.
|
|
413
|
-
// We pull it via globalThis to avoid a static `import`
|
|
414
|
-
// that would itself be browser-bundled.
|
|
415
|
-
void 0
|
|
416
|
-
);
|
|
417
|
-
if (typeof req === "function") {
|
|
418
|
-
const moduleName = ["async", "hooks"].join("_");
|
|
419
|
-
const mod = req("node:" + moduleName);
|
|
420
|
-
if (typeof mod.AsyncLocalStorage === "function") return mod.AsyncLocalStorage;
|
|
421
|
-
}
|
|
422
|
-
} catch {
|
|
423
|
-
}
|
|
424
|
-
return null;
|
|
425
|
-
}
|
|
426
|
-
function createScopedStorage(key = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:default-scoped-storage")) {
|
|
427
|
-
const globalStore = globalThis;
|
|
428
|
-
let entry = globalStore[key];
|
|
429
|
-
if (!entry) {
|
|
430
|
-
const als2 = (() => {
|
|
431
|
-
if (!ALS_CTOR) return null;
|
|
432
|
-
try {
|
|
433
|
-
return new ALS_CTOR();
|
|
434
|
-
} catch {
|
|
435
|
-
return null;
|
|
436
|
-
}
|
|
437
|
-
})();
|
|
438
|
-
entry = { als: als2, edgeFallback: null };
|
|
439
|
-
globalStore[key] = entry;
|
|
440
|
-
}
|
|
441
|
-
const als = entry.als;
|
|
442
|
-
const stateRef = entry;
|
|
443
|
-
return {
|
|
444
|
-
read() {
|
|
445
|
-
if (als) return als.getStore()?.value ?? null;
|
|
446
|
-
return stateRef.edgeFallback?.value ?? null;
|
|
447
|
-
},
|
|
448
|
-
run(value, callback) {
|
|
449
|
-
if (als) return als.run({ value }, callback);
|
|
450
|
-
const previous = stateRef.edgeFallback;
|
|
451
|
-
stateRef.edgeFallback = { value };
|
|
452
|
-
try {
|
|
453
|
-
return callback();
|
|
454
|
-
} finally {
|
|
455
|
-
stateRef.edgeFallback = previous;
|
|
456
|
-
}
|
|
457
|
-
},
|
|
458
|
-
update(value) {
|
|
459
|
-
if (als) {
|
|
460
|
-
const store = als.getStore();
|
|
461
|
-
if (store) store.value = value;
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
stateRef.edgeFallback = { value };
|
|
465
|
-
},
|
|
466
|
-
_resetForTests() {
|
|
467
|
-
stateRef.edgeFallback = null;
|
|
468
|
-
},
|
|
469
|
-
_isAsyncLocalStorage() {
|
|
470
|
-
return als !== null;
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// src/correlation.ts
|
|
476
|
-
var storage = createScopedStorage(
|
|
477
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
|
|
478
|
-
);
|
|
479
|
-
function current() {
|
|
480
|
-
return storage.read();
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// src/actor.ts
|
|
484
|
-
var storage2 = createScopedStorage(
|
|
485
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:actor-storage")
|
|
486
|
-
);
|
|
487
|
-
function getCurrentActor() {
|
|
488
|
-
return storage2.read();
|
|
489
|
-
}
|
|
490
|
-
var SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
491
|
-
"pin",
|
|
492
|
-
"otp",
|
|
493
|
-
"totp",
|
|
494
|
-
"iban",
|
|
495
|
-
"mfa",
|
|
496
|
-
"passphrase"
|
|
497
|
-
]);
|
|
498
|
-
function snakeLower(key) {
|
|
499
|
-
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
500
|
-
}
|
|
501
|
-
function matchesSensitiveKey(key, substringPatterns) {
|
|
502
|
-
const lower = key.toLowerCase();
|
|
503
|
-
const snake = snakeLower(key);
|
|
504
|
-
if (substringPatterns.some((p) => lower.includes(p) || snake.includes(p))) {
|
|
505
|
-
return true;
|
|
506
|
-
}
|
|
507
|
-
const words = snake.split(/[^a-z0-9]+/);
|
|
508
|
-
return SENSITIVE_WORD_PATTERNS.some((w) => words.includes(w));
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// src/db/shared.ts
|
|
512
|
-
var IGNORED_ATTRIBUTES = Object.freeze([
|
|
513
|
-
"id",
|
|
514
|
-
"createdAt",
|
|
515
|
-
"created_at",
|
|
516
|
-
"updatedAt",
|
|
517
|
-
"updated_at",
|
|
518
|
-
"deletedAt",
|
|
519
|
-
"deleted_at",
|
|
520
|
-
// Auth.js / NextAuth standard columns
|
|
521
|
-
"emailVerified",
|
|
522
|
-
"expires"
|
|
523
|
-
]);
|
|
524
|
-
var DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
525
|
-
"password",
|
|
526
|
-
"token",
|
|
527
|
-
"secret",
|
|
528
|
-
"api_key",
|
|
529
|
-
"credit_card",
|
|
530
|
-
"ssn",
|
|
531
|
-
"social_security",
|
|
532
|
-
"encrypted",
|
|
533
|
-
"private_key",
|
|
534
|
-
"public_key",
|
|
535
|
-
"signing_key",
|
|
536
|
-
"pem",
|
|
537
|
-
"cipher",
|
|
538
|
-
"nonce",
|
|
539
|
-
"salt",
|
|
540
|
-
"digest",
|
|
541
|
-
"signature",
|
|
542
|
-
"hmac",
|
|
543
|
-
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
544
|
-
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
545
|
-
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
546
|
-
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
547
|
-
"credential",
|
|
548
|
-
"passwd",
|
|
549
|
-
"passcode",
|
|
550
|
-
"apikey",
|
|
551
|
-
"card_number",
|
|
552
|
-
"cardnumber",
|
|
553
|
-
"cvv",
|
|
554
|
-
"cvc"
|
|
555
|
-
]);
|
|
556
|
-
function emitDbEvent(input) {
|
|
557
|
-
try {
|
|
558
|
-
const config = configuration();
|
|
559
|
-
if (!config.captureDb) return;
|
|
560
|
-
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
561
|
-
if (config.databaseReader && !input._fromTrigger) {
|
|
562
|
-
const tracked = config.triggerTrackedTables;
|
|
563
|
-
if (tracked === null || tracked.has(input.modelClass)) return;
|
|
564
|
-
}
|
|
565
|
-
if (input.operation === "update") {
|
|
566
|
-
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
567
|
-
if (meaningful.length === 0) return;
|
|
568
|
-
}
|
|
569
|
-
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
570
|
-
const context = buildContext(input);
|
|
571
|
-
const event = build({
|
|
572
|
-
source_type: "database_callback",
|
|
573
|
-
source_data: {
|
|
574
|
-
model_class: input.modelClass,
|
|
575
|
-
operation: input.operation
|
|
576
|
-
},
|
|
577
|
-
outcome: "success",
|
|
578
|
-
correlation_id: current(),
|
|
579
|
-
resource_ids: resourceIdStr === null ? [] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
580
|
-
context,
|
|
581
|
-
duration_ms: null,
|
|
582
|
-
timestamp: input.timestamp ?? null
|
|
583
|
-
});
|
|
584
|
-
pushEvent(event);
|
|
585
|
-
} catch (error) {
|
|
586
|
-
logger.debug(`db emit failed: ${describeError(error)}`);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
function buildContext(input) {
|
|
590
|
-
const context = {};
|
|
591
|
-
const actor = getCurrentActor();
|
|
592
|
-
if (actor) context.actor = actor;
|
|
593
|
-
if ((input.operation === "create" || input.operation === "destroy") && input.initialAttributes) {
|
|
594
|
-
const filtered = filterMeaningfulAttributes(input.initialAttributes);
|
|
595
|
-
if (filtered !== null) context.initial_attributes = filtered;
|
|
596
|
-
}
|
|
597
|
-
if (input.operation === "update" && input.changes) {
|
|
598
|
-
const filtered = filterMeaningfulChanges(input.changes);
|
|
599
|
-
if (filtered.length > 0) {
|
|
600
|
-
context.changes = filtered.map((c) => {
|
|
601
|
-
const out = {
|
|
602
|
-
attribute: c.attribute,
|
|
603
|
-
to: formatForJson(c.to)
|
|
604
|
-
};
|
|
605
|
-
if (c.from !== void 0) out.from = formatForJson(c.from);
|
|
606
|
-
return out;
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
const displayName = input.displayName ?? (input.modelInstance ? resolveDisplayName(input.modelClass, input.modelInstance) : null);
|
|
611
|
-
if (displayName !== null) context.display_name = displayName;
|
|
612
|
-
return Object.keys(context).length === 0 ? null : context;
|
|
613
|
-
}
|
|
614
|
-
function filterMeaningfulAttributes(attrs) {
|
|
615
|
-
const out = {};
|
|
616
|
-
for (const key of Object.keys(attrs)) {
|
|
617
|
-
if (!isMeaningfulAttribute(key)) continue;
|
|
618
|
-
const value = attrs[key];
|
|
619
|
-
if (value === null || value === void 0) continue;
|
|
620
|
-
if (!isScalar(value)) continue;
|
|
621
|
-
out[key] = formatForJson(value);
|
|
622
|
-
}
|
|
623
|
-
return Object.keys(out).length === 0 ? null : out;
|
|
624
|
-
}
|
|
625
|
-
function filterMeaningfulChanges(changes) {
|
|
626
|
-
return changes.filter((c) => {
|
|
627
|
-
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
628
|
-
if (!isScalar(c.to)) return false;
|
|
629
|
-
if (c.from === void 0) return true;
|
|
630
|
-
if (!isScalar(c.from)) return false;
|
|
631
|
-
return valuesActuallyChanged(c.from, c.to);
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
function isMeaningfulAttribute(name) {
|
|
635
|
-
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
636
|
-
if (isDbSensitive(name)) return false;
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
function isDbSensitive(name) {
|
|
640
|
-
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
641
|
-
}
|
|
642
|
-
function isScalar(value) {
|
|
643
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
if (isPrismaDecimal(value)) return true;
|
|
647
|
-
if (Buffer.isBuffer?.(value)) return false;
|
|
648
|
-
if (Array.isArray(value)) return value.every((v) => isScalar(v));
|
|
649
|
-
return false;
|
|
650
|
-
}
|
|
651
|
-
function valuesActuallyChanged(from, to) {
|
|
652
|
-
if (from === null && to === null) return false;
|
|
653
|
-
if (from instanceof Date && to instanceof Date) {
|
|
654
|
-
return from.getTime() !== to.getTime();
|
|
655
|
-
}
|
|
656
|
-
return from !== to;
|
|
657
|
-
}
|
|
658
|
-
function formatForJson(value) {
|
|
659
|
-
if (value === null || value === void 0) return value;
|
|
660
|
-
if (value instanceof Date) return value.toISOString();
|
|
661
|
-
if (typeof value === "bigint") return value.toString();
|
|
662
|
-
if (isPrismaDecimal(value)) return Number(value.toString());
|
|
663
|
-
if (Array.isArray(value)) return value.map(formatForJson);
|
|
664
|
-
return value;
|
|
665
|
-
}
|
|
666
|
-
function isPrismaDecimal(value) {
|
|
667
|
-
if (value === null || typeof value !== "object") return false;
|
|
668
|
-
const obj = value;
|
|
669
|
-
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
670
|
-
}
|
|
671
|
-
function resolveDisplayName(modelClass, instance) {
|
|
672
|
-
try {
|
|
673
|
-
const config = configuration();
|
|
674
|
-
const resolver = config.displayNameFor[modelClass];
|
|
675
|
-
const resolved = applyResolver(resolver, instance);
|
|
676
|
-
if (resolved !== null) return resolved;
|
|
677
|
-
for (const field of ["name", "title", "number"]) {
|
|
678
|
-
const value = instance[field];
|
|
679
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
680
|
-
return String(value);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
} catch {
|
|
684
|
-
}
|
|
685
|
-
return null;
|
|
686
|
-
}
|
|
687
|
-
function applyResolver(resolver, instance) {
|
|
688
|
-
if (typeof resolver === "string") {
|
|
689
|
-
const value = instance[resolver];
|
|
690
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
691
|
-
return String(value);
|
|
692
|
-
}
|
|
693
|
-
return null;
|
|
694
|
-
}
|
|
695
|
-
if (typeof resolver === "function") {
|
|
696
|
-
try {
|
|
697
|
-
const value = resolver(instance);
|
|
698
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
699
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
700
|
-
return String(value);
|
|
701
|
-
}
|
|
702
|
-
} catch {
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
return null;
|
|
706
|
-
}
|
|
707
|
-
function describeError(error) {
|
|
708
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
709
|
-
return String(error);
|
|
710
|
-
}
|
|
1
|
+
import { emitDbEvent, resolveDisplayName, configuration } from '../chunk-CE3R7DVB.js';
|
|
2
|
+
import { logger } from '../chunk-C5OSM557.js';
|
|
3
|
+
import '../chunk-SIAA4J6H.js';
|
|
711
4
|
|
|
712
5
|
// src/db/supabase.ts
|
|
713
6
|
function triggerPathWillCapture(table) {
|
|
@@ -746,9 +39,9 @@ function wrapSupabase(client) {
|
|
|
746
39
|
if (!result || result.error) return null;
|
|
747
40
|
if (Array.isArray(result.data)) {
|
|
748
41
|
const first = result.data[0];
|
|
749
|
-
return
|
|
42
|
+
return isPlainObject(first) ? first : null;
|
|
750
43
|
}
|
|
751
|
-
return
|
|
44
|
+
return isPlainObject(result.data) ? result.data : null;
|
|
752
45
|
} catch {
|
|
753
46
|
return null;
|
|
754
47
|
}
|
|
@@ -886,7 +179,7 @@ function trackFilterChain(builder) {
|
|
|
886
179
|
if (typeof orig !== "function") return orig;
|
|
887
180
|
return function patchedMatch(query) {
|
|
888
181
|
try {
|
|
889
|
-
if (
|
|
182
|
+
if (isPlainObject(query)) {
|
|
890
183
|
for (const [k, v] of Object.entries(query)) {
|
|
891
184
|
captured.equals[k] = v;
|
|
892
185
|
}
|
|
@@ -914,7 +207,7 @@ function instrumentFilterBuilder(builder, onResolved, beforeFire) {
|
|
|
914
207
|
try {
|
|
915
208
|
if (!result?.error) onResolved(result);
|
|
916
209
|
} catch (error) {
|
|
917
|
-
logger.debug(`supabase capture failed: ${
|
|
210
|
+
logger.debug(`supabase capture failed: ${describeError(error)}`);
|
|
918
211
|
}
|
|
919
212
|
try {
|
|
920
213
|
const passthrough = onfulfilled ? onfulfilled(raw) : raw;
|
|
@@ -947,12 +240,12 @@ function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
|
947
240
|
if (Array.isArray(values)) {
|
|
948
241
|
const resultRows = pickResultRows(result);
|
|
949
242
|
values.forEach((row, index) => {
|
|
950
|
-
if (!
|
|
243
|
+
if (!isPlainObject(row)) return;
|
|
951
244
|
emitOneRow(ctx, row, resultRows[index] ?? null, filters, null);
|
|
952
245
|
});
|
|
953
246
|
return;
|
|
954
247
|
}
|
|
955
|
-
if (!
|
|
248
|
+
if (!isPlainObject(values)) {
|
|
956
249
|
emitDbEvent({
|
|
957
250
|
modelClass: ctx.table,
|
|
958
251
|
operation: ctx.operation,
|
|
@@ -1038,24 +331,24 @@ function pickFirstResultRow(result) {
|
|
|
1038
331
|
if (!result || result.error) return null;
|
|
1039
332
|
if (Array.isArray(result.data)) {
|
|
1040
333
|
const first = result.data[0];
|
|
1041
|
-
return
|
|
334
|
+
return isPlainObject(first) ? first : null;
|
|
1042
335
|
}
|
|
1043
|
-
if (
|
|
336
|
+
if (isPlainObject(result.data)) return result.data;
|
|
1044
337
|
return null;
|
|
1045
338
|
}
|
|
1046
339
|
function pickResultRows(result) {
|
|
1047
340
|
if (!result || result.error || !Array.isArray(result.data)) return [];
|
|
1048
341
|
return result.data.map(
|
|
1049
|
-
(row) =>
|
|
342
|
+
(row) => isPlainObject(row) ? row : void 0
|
|
1050
343
|
);
|
|
1051
344
|
}
|
|
1052
|
-
function
|
|
345
|
+
function isPlainObject(value) {
|
|
1053
346
|
if (value === null || typeof value !== "object") return false;
|
|
1054
347
|
if (Array.isArray(value)) return false;
|
|
1055
348
|
if (value instanceof Date) return false;
|
|
1056
349
|
return true;
|
|
1057
350
|
}
|
|
1058
|
-
function
|
|
351
|
+
function describeError(error) {
|
|
1059
352
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1060
353
|
return String(error);
|
|
1061
354
|
}
|