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/prisma.cjs
CHANGED
|
@@ -1,725 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
// src/logger.ts
|
|
11
|
-
var LEVEL_RANK = {
|
|
12
|
-
debug: 10,
|
|
13
|
-
info: 20,
|
|
14
|
-
warn: 30,
|
|
15
|
-
error: 40,
|
|
16
|
-
silent: 100
|
|
17
|
-
};
|
|
18
|
-
var LEVEL_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:log-level");
|
|
19
|
-
function readLevel() {
|
|
20
|
-
const g = globalThis;
|
|
21
|
-
return g[LEVEL_KEY] ?? "warn";
|
|
22
|
-
}
|
|
23
|
-
function shouldLog(level) {
|
|
24
|
-
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
25
|
-
}
|
|
26
|
-
function safeWrite(level, message) {
|
|
27
|
-
try {
|
|
28
|
-
if (!shouldLog(level)) return;
|
|
29
|
-
const line = `[ezlogs] ${message}`;
|
|
30
|
-
if (level === "error" || level === "warn") {
|
|
31
|
-
console.error(line);
|
|
32
|
-
} else {
|
|
33
|
-
console.log(line);
|
|
34
|
-
}
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
var logger = {
|
|
39
|
-
debug: (message) => safeWrite("debug", message),
|
|
40
|
-
info: (message) => safeWrite("info", message),
|
|
41
|
-
warn: (message) => safeWrite("warn", message),
|
|
42
|
-
error: (message) => safeWrite("error", message)
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/edge-fallback.ts
|
|
46
|
-
var ALS_CTOR = loadAsyncLocalStorage();
|
|
47
|
-
function loadAsyncLocalStorage() {
|
|
48
|
-
const fromGlobal = globalThis.AsyncLocalStorage;
|
|
49
|
-
if (typeof fromGlobal === "function") return fromGlobal;
|
|
50
|
-
try {
|
|
51
|
-
const req = typeof __require !== "undefined" ? __require : (
|
|
52
|
-
// In ESM, `createRequire` is the official escape hatch.
|
|
53
|
-
// We pull it via globalThis to avoid a static `import`
|
|
54
|
-
// that would itself be browser-bundled.
|
|
55
|
-
void 0
|
|
56
|
-
);
|
|
57
|
-
if (typeof req === "function") {
|
|
58
|
-
const moduleName = ["async", "hooks"].join("_");
|
|
59
|
-
const mod = req("node:" + moduleName);
|
|
60
|
-
if (typeof mod.AsyncLocalStorage === "function") return mod.AsyncLocalStorage;
|
|
61
|
-
}
|
|
62
|
-
} catch {
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
function makeAsyncContextCapture() {
|
|
67
|
-
if (!ALS_CTOR) return null;
|
|
68
|
-
const ctor = ALS_CTOR;
|
|
69
|
-
if (typeof ctor.snapshot !== "function") return null;
|
|
70
|
-
const snapshot = ctor.snapshot.bind(ctor);
|
|
71
|
-
return () => {
|
|
72
|
-
const runSnapshot = snapshot();
|
|
73
|
-
return (fn) => runSnapshot(fn);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function createScopedStorage(key = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:default-scoped-storage")) {
|
|
77
|
-
const globalStore = globalThis;
|
|
78
|
-
let entry = globalStore[key];
|
|
79
|
-
if (!entry) {
|
|
80
|
-
const als2 = (() => {
|
|
81
|
-
if (!ALS_CTOR) return null;
|
|
82
|
-
try {
|
|
83
|
-
return new ALS_CTOR();
|
|
84
|
-
} catch {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
})();
|
|
88
|
-
entry = { als: als2, edgeFallback: null };
|
|
89
|
-
globalStore[key] = entry;
|
|
90
|
-
}
|
|
91
|
-
const als = entry.als;
|
|
92
|
-
const stateRef = entry;
|
|
93
|
-
return {
|
|
94
|
-
read() {
|
|
95
|
-
if (als) return als.getStore()?.value ?? null;
|
|
96
|
-
return stateRef.edgeFallback?.value ?? null;
|
|
97
|
-
},
|
|
98
|
-
run(value, callback) {
|
|
99
|
-
if (als) return als.run({ value }, callback);
|
|
100
|
-
const previous = stateRef.edgeFallback;
|
|
101
|
-
stateRef.edgeFallback = { value };
|
|
102
|
-
try {
|
|
103
|
-
return callback();
|
|
104
|
-
} finally {
|
|
105
|
-
stateRef.edgeFallback = previous;
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
update(value) {
|
|
109
|
-
if (als) {
|
|
110
|
-
const store = als.getStore();
|
|
111
|
-
if (store) store.value = value;
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
stateRef.edgeFallback = { value };
|
|
115
|
-
},
|
|
116
|
-
_resetForTests() {
|
|
117
|
-
stateRef.edgeFallback = null;
|
|
118
|
-
},
|
|
119
|
-
_isAsyncLocalStorage() {
|
|
120
|
-
return als !== null;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/correlation.ts
|
|
126
|
-
var storage = createScopedStorage(
|
|
127
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
|
|
128
|
-
);
|
|
129
|
-
function current() {
|
|
130
|
-
return storage.read();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/configuration.ts
|
|
134
|
-
var DEFAULT_EXCLUDED_PATHS = Object.freeze([
|
|
135
|
-
// Next.js / Vercel infrastructure noise
|
|
136
|
-
"/_next/*",
|
|
137
|
-
"/_vercel/*",
|
|
138
|
-
"/__nextjs_*",
|
|
139
|
-
// NextAuth.js / Auth.js — skip session-refresh polls and CSRF/provider
|
|
140
|
-
// metadata GETs (high-frequency, no business meaning), but CAPTURE
|
|
141
|
-
// POSTs (callbacks, signin, signout, register). The POSTs are the
|
|
142
|
-
// actual auth events users care about; the GETs are pure plumbing.
|
|
143
|
-
Object.freeze({ path: "/api/auth/*", methods: ["GET", "HEAD"] }),
|
|
144
|
-
// Generic infrastructure
|
|
145
|
-
"/health*",
|
|
146
|
-
"/api/health",
|
|
147
|
-
"/up",
|
|
148
|
-
"/alive",
|
|
149
|
-
"/ready",
|
|
150
|
-
"/metrics",
|
|
151
|
-
"/favicon.ico",
|
|
152
|
-
"/.well-known*",
|
|
153
|
-
"/robots.txt",
|
|
154
|
-
"/sitemap.xml",
|
|
155
|
-
"/*.hot-update.*",
|
|
156
|
-
// Auth routes (common patterns across Clerk, NextAuth, custom auth)
|
|
157
|
-
"*/login*",
|
|
158
|
-
"*/logout*",
|
|
159
|
-
"*/sign-in*",
|
|
160
|
-
"*/sign-out*",
|
|
161
|
-
"*/signin*",
|
|
162
|
-
"*/signout*",
|
|
163
|
-
"/session*"
|
|
164
|
-
]);
|
|
165
|
-
var DEFAULT_EXCLUDED_TABLES = Object.freeze([
|
|
166
|
-
// Prisma migration ledger
|
|
167
|
-
"_prisma_migrations",
|
|
168
|
-
// Auth.js / NextAuth Prisma adapter — session/verification-token churn
|
|
169
|
-
// is auth machinery, not business activity. Account/User stay captured.
|
|
170
|
-
"Session",
|
|
171
|
-
"VerificationToken",
|
|
172
|
-
// Common cross-stack convention names for the same things
|
|
173
|
-
"sessions",
|
|
174
|
-
"session",
|
|
175
|
-
"verification_tokens"
|
|
176
|
-
]);
|
|
177
|
-
var DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
|
|
178
|
-
var DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
|
|
179
|
-
var Configuration = class {
|
|
180
|
-
serverUrl = null;
|
|
181
|
-
projectToken = null;
|
|
182
|
-
captureHttp = true;
|
|
183
|
-
captureDb = true;
|
|
184
|
-
captureJobs = true;
|
|
185
|
-
bufferSize = 1e4;
|
|
186
|
-
/** Default 3000 ms — equivalent to Ruby's 3 seconds. */
|
|
187
|
-
sendInterval = 3e3;
|
|
188
|
-
retryAttempts = 3;
|
|
189
|
-
logLevel = "warn";
|
|
190
|
-
patchGlobalFetch = true;
|
|
191
|
-
actorFromSupabase = true;
|
|
192
|
-
allowInsecureTransport = false;
|
|
193
|
-
excludedPaths = [];
|
|
194
|
-
excludedTables = [];
|
|
195
|
-
excludedJobClasses = [];
|
|
196
|
-
excludedGraphqlOperations = [];
|
|
197
|
-
excludedGraphqlVariableKeys = [];
|
|
198
|
-
actorFromRequest = null;
|
|
199
|
-
displayNameFor = {};
|
|
200
|
-
isServerActionError = null;
|
|
201
|
-
databaseReader = null;
|
|
202
|
-
databaseUrl = null;
|
|
203
|
-
/**
|
|
204
|
-
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
205
|
-
* at agent startup by reading `information_schema.triggers`. The
|
|
206
|
-
* supabase / drizzle / prisma adapters use this to decide whether
|
|
207
|
-
* their per-mutation emit is redundant: if the table is trigger-
|
|
208
|
-
* tracked the audit-log reader will surface the same write with full
|
|
209
|
-
* old/new state, so the adapter's emit is suppressed. Tables NOT in
|
|
210
|
-
* this set fall through to the adapter so they're still captured.
|
|
211
|
-
*
|
|
212
|
-
* `null` means "detection hasn't run yet or failed" — in that state
|
|
213
|
-
* `databaseReader`-wired apps suppress every adapter emit (the
|
|
214
|
-
* original Phase 5 behavior). After detection completes the agent
|
|
215
|
-
* gives the more accurate per-table answer.
|
|
216
|
-
*/
|
|
217
|
-
triggerTrackedTables = null;
|
|
218
|
-
apply(options) {
|
|
219
|
-
this.serverUrl = options.serverUrl;
|
|
220
|
-
this.projectToken = options.projectToken;
|
|
221
|
-
if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
|
|
222
|
-
if (options.captureDb !== void 0) this.captureDb = options.captureDb;
|
|
223
|
-
if (options.captureJobs !== void 0) this.captureJobs = options.captureJobs;
|
|
224
|
-
if (options.bufferSize !== void 0) this.bufferSize = options.bufferSize;
|
|
225
|
-
if (options.sendInterval !== void 0) this.sendInterval = options.sendInterval;
|
|
226
|
-
if (options.retryAttempts !== void 0) this.retryAttempts = options.retryAttempts;
|
|
227
|
-
if (options.excludedPaths) this.excludedPaths = [...options.excludedPaths];
|
|
228
|
-
if (options.excludedTables) this.excludedTables = [...options.excludedTables];
|
|
229
|
-
if (options.excludedJobClasses) {
|
|
230
|
-
this.excludedJobClasses = [...options.excludedJobClasses];
|
|
231
|
-
}
|
|
232
|
-
if (options.excludedGraphqlOperations) {
|
|
233
|
-
this.excludedGraphqlOperations = [...options.excludedGraphqlOperations];
|
|
234
|
-
}
|
|
235
|
-
if (options.excludedGraphqlVariableKeys) {
|
|
236
|
-
this.excludedGraphqlVariableKeys = [...options.excludedGraphqlVariableKeys];
|
|
237
|
-
}
|
|
238
|
-
if (options.actorFromRequest) this.actorFromRequest = options.actorFromRequest;
|
|
239
|
-
if (options.displayNameFor) this.displayNameFor = { ...options.displayNameFor };
|
|
240
|
-
if (options.isServerActionError) this.isServerActionError = options.isServerActionError;
|
|
241
|
-
if (options.patchGlobalFetch !== void 0) {
|
|
242
|
-
this.patchGlobalFetch = options.patchGlobalFetch;
|
|
243
|
-
}
|
|
244
|
-
if (options.allowInsecureTransport !== void 0) {
|
|
245
|
-
this.allowInsecureTransport = options.allowInsecureTransport;
|
|
246
|
-
}
|
|
247
|
-
if (options.actorFromSupabase !== void 0) {
|
|
248
|
-
this.actorFromSupabase = options.actorFromSupabase;
|
|
249
|
-
}
|
|
250
|
-
if (options.databaseReader !== void 0) {
|
|
251
|
-
this.databaseReader = options.databaseReader;
|
|
252
|
-
}
|
|
253
|
-
if (options.databaseUrl !== void 0) {
|
|
254
|
-
this.databaseUrl = options.databaseUrl;
|
|
255
|
-
}
|
|
256
|
-
if (options.logLevel) this.logLevel = options.logLevel;
|
|
257
|
-
}
|
|
258
|
-
allExcludedPaths() {
|
|
259
|
-
return [...DEFAULT_EXCLUDED_PATHS, ...this.excludedPaths];
|
|
260
|
-
}
|
|
261
|
-
allExcludedTables() {
|
|
262
|
-
return [...DEFAULT_EXCLUDED_TABLES, ...this.excludedTables];
|
|
263
|
-
}
|
|
264
|
-
allExcludedJobClasses() {
|
|
265
|
-
return [...DEFAULT_EXCLUDED_JOB_CLASSES, ...this.excludedJobClasses];
|
|
266
|
-
}
|
|
267
|
-
allExcludedGraphqlOperations() {
|
|
268
|
-
return [...DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, ...this.excludedGraphqlOperations];
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
var GLOBAL_CONFIG_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:configuration");
|
|
272
|
-
function configuration() {
|
|
273
|
-
const g = globalThis;
|
|
274
|
-
if (!g[GLOBAL_CONFIG_KEY]) {
|
|
275
|
-
g[GLOBAL_CONFIG_KEY] = new Configuration();
|
|
276
|
-
}
|
|
277
|
-
return g[GLOBAL_CONFIG_KEY];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// src/event-builder.ts
|
|
281
|
-
var SENSITIVE_KEYS = Object.freeze([
|
|
282
|
-
"password",
|
|
283
|
-
"token",
|
|
284
|
-
"secret",
|
|
285
|
-
"api_key",
|
|
286
|
-
"credit_card"
|
|
287
|
-
]);
|
|
288
|
-
var VALID_SOURCE_TYPES = [
|
|
289
|
-
"http_request",
|
|
290
|
-
"background_job",
|
|
291
|
-
"database_callback"
|
|
292
|
-
];
|
|
293
|
-
var VALID_OUTCOMES = ["success", "failure"];
|
|
294
|
-
function build(input) {
|
|
295
|
-
const source_type = validateSourceType(input.source_type);
|
|
296
|
-
const source_data_raw = validateSourceData(input.source_data);
|
|
297
|
-
const outcome = validateOutcome(input.outcome);
|
|
298
|
-
const timestamp = validateTimestamp(input.timestamp ?? null);
|
|
299
|
-
const resource_ids = validateResourceIds(input.resource_ids ?? []);
|
|
300
|
-
const context_raw = validateContext(input.context ?? null);
|
|
301
|
-
const duration_ms = validateDurationMs();
|
|
302
|
-
const error_message = input.error_message ?? null;
|
|
303
|
-
validateOutcomeErrorConsistency(outcome, error_message);
|
|
304
|
-
const source_data = sanitizeRecord(source_data_raw);
|
|
305
|
-
const context = context_raw === null ? null : sanitizeRecord(context_raw);
|
|
306
|
-
const correlation_id = input.correlation_id ?? null;
|
|
307
|
-
const event = {
|
|
308
|
-
timestamp,
|
|
309
|
-
source_type,
|
|
310
|
-
source_data,
|
|
311
|
-
outcome,
|
|
312
|
-
correlation_id,
|
|
313
|
-
resource_ids,
|
|
314
|
-
context,
|
|
315
|
-
duration_ms,
|
|
316
|
-
error_message
|
|
317
|
-
};
|
|
318
|
-
return event;
|
|
319
|
-
}
|
|
320
|
-
function validateSourceType(value) {
|
|
321
|
-
const normalized = String(value);
|
|
322
|
-
if (!VALID_SOURCE_TYPES.includes(normalized)) {
|
|
323
|
-
throw new ArgError(
|
|
324
|
-
`source_type must be one of ${VALID_SOURCE_TYPES.join(", ")}, got: ${normalized}`
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
return normalized;
|
|
328
|
-
}
|
|
329
|
-
function validateSourceData(value) {
|
|
330
|
-
if (value === null || value === void 0) {
|
|
331
|
-
throw new ArgError("source_data is required");
|
|
332
|
-
}
|
|
333
|
-
if (!isPlainObject(value)) {
|
|
334
|
-
throw new ArgError(
|
|
335
|
-
`source_data must be an object, got: ${describe(value)}`
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
return value;
|
|
339
|
-
}
|
|
340
|
-
function validateOutcome(value) {
|
|
341
|
-
const normalized = String(value);
|
|
342
|
-
if (!VALID_OUTCOMES.includes(normalized)) {
|
|
343
|
-
throw new ArgError(
|
|
344
|
-
`outcome must be one of ${VALID_OUTCOMES.join(", ")}, got: ${normalized}`
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
return normalized;
|
|
348
|
-
}
|
|
349
|
-
function validateTimestamp(value) {
|
|
350
|
-
if (value === null) {
|
|
351
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
352
|
-
}
|
|
353
|
-
if (typeof value === "string") {
|
|
354
|
-
const parsed = new Date(value);
|
|
355
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
356
|
-
throw new ArgError(
|
|
357
|
-
`timestamp must be valid ISO 8601 format, got: ${value}`
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
return value;
|
|
361
|
-
}
|
|
362
|
-
if (value instanceof Date) {
|
|
363
|
-
if (Number.isNaN(value.getTime())) {
|
|
364
|
-
throw new ArgError("timestamp must be a valid Date");
|
|
365
|
-
}
|
|
366
|
-
return value.toISOString();
|
|
367
|
-
}
|
|
368
|
-
throw new ArgError(
|
|
369
|
-
`timestamp must be a string or Date, got: ${describe(value)}`
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
function validateResourceIds(value) {
|
|
373
|
-
if (!Array.isArray(value)) {
|
|
374
|
-
throw new ArgError(`resource_ids must be an array, got: ${describe(value)}`);
|
|
375
|
-
}
|
|
376
|
-
value.forEach((entry, index) => {
|
|
377
|
-
if (!isPlainObject(entry)) {
|
|
378
|
-
throw new ArgError(
|
|
379
|
-
`resource_ids[${index}] must be an object, got: ${describe(entry)}`
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
const e = entry;
|
|
383
|
-
if (!("resource_type" in e) || !("resource_id" in e)) {
|
|
384
|
-
throw new ArgError(
|
|
385
|
-
`resource_ids[${index}] must have resource_type and resource_id keys, got: ${Object.keys(e).join(", ")}`
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
if (typeof e.resource_type !== "string") {
|
|
389
|
-
throw new ArgError(
|
|
390
|
-
`resource_ids[${index}].resource_type must be a string, got: ${describe(e.resource_type)}`
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
if (typeof e.resource_id !== "string") {
|
|
394
|
-
throw new ArgError(
|
|
395
|
-
`resource_ids[${index}].resource_id must be a string, got: ${describe(e.resource_id)}`
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
return value;
|
|
400
|
-
}
|
|
401
|
-
function validateContext(value) {
|
|
402
|
-
if (value === null) return null;
|
|
403
|
-
if (!isPlainObject(value)) {
|
|
404
|
-
throw new ArgError(
|
|
405
|
-
`context must be an object or null, got: ${describe(value)}`
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
return value;
|
|
409
|
-
}
|
|
410
|
-
function validateDurationMs(value) {
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
function validateOutcomeErrorConsistency(outcome, error_message) {
|
|
414
|
-
if (outcome === "failure") {
|
|
415
|
-
if (error_message === null || error_message === "") {
|
|
416
|
-
throw new ArgError("error_message is required when outcome is 'failure'");
|
|
417
|
-
}
|
|
418
|
-
} else if (outcome === "success") {
|
|
419
|
-
if (error_message !== null) {
|
|
420
|
-
throw new ArgError("error_message must be null when outcome is 'success'");
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
function sanitizeRecord(input) {
|
|
425
|
-
const result = {};
|
|
426
|
-
for (const key of Object.keys(input)) {
|
|
427
|
-
const value = input[key];
|
|
428
|
-
if (isSensitiveKey(key)) {
|
|
429
|
-
result[key] = "[FILTERED]";
|
|
430
|
-
} else if (isPlainObject(value)) {
|
|
431
|
-
result[key] = sanitizeRecord(value);
|
|
432
|
-
} else if (Array.isArray(value)) {
|
|
433
|
-
result[key] = value.map(
|
|
434
|
-
(item) => isPlainObject(item) ? sanitizeRecord(item) : item
|
|
435
|
-
);
|
|
436
|
-
} else {
|
|
437
|
-
result[key] = value;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return result;
|
|
441
|
-
}
|
|
442
|
-
function isSensitiveKey(key) {
|
|
443
|
-
const lower = key.toLowerCase();
|
|
444
|
-
return SENSITIVE_KEYS.some((p) => lower.includes(p));
|
|
445
|
-
}
|
|
446
|
-
function isPlainObject(value) {
|
|
447
|
-
if (value === null || typeof value !== "object") return false;
|
|
448
|
-
const proto = Object.getPrototypeOf(value);
|
|
449
|
-
return proto === Object.prototype || proto === null;
|
|
450
|
-
}
|
|
451
|
-
function describe(value) {
|
|
452
|
-
if (value === null) return "null";
|
|
453
|
-
if (Array.isArray(value)) return "Array";
|
|
454
|
-
return typeof value;
|
|
455
|
-
}
|
|
456
|
-
var ArgError = class extends Error {
|
|
457
|
-
constructor(message) {
|
|
458
|
-
super(message);
|
|
459
|
-
this.name = "ArgError";
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
// src/pipeline/buffer.ts
|
|
464
|
-
var GLOBAL_QUEUE_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:buffer-queue");
|
|
465
|
-
function getQueue() {
|
|
466
|
-
const g = globalThis;
|
|
467
|
-
if (!g[GLOBAL_QUEUE_KEY]) g[GLOBAL_QUEUE_KEY] = [];
|
|
468
|
-
return g[GLOBAL_QUEUE_KEY];
|
|
469
|
-
}
|
|
470
|
-
function pushEvent(event) {
|
|
471
|
-
try {
|
|
472
|
-
const queue = getQueue();
|
|
473
|
-
const max = maxSize();
|
|
474
|
-
if (queue.length >= max) {
|
|
475
|
-
queue.shift();
|
|
476
|
-
logger.warn(`Buffer full (${max}), dropped oldest event`);
|
|
477
|
-
}
|
|
478
|
-
queue.push(event);
|
|
479
|
-
} catch (error) {
|
|
480
|
-
logger.error(`pushEvent failed: ${describe2(error)}`);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
function maxSize() {
|
|
484
|
-
try {
|
|
485
|
-
return configuration().bufferSize;
|
|
486
|
-
} catch {
|
|
487
|
-
return 1e4;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function describe2(error) {
|
|
491
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
492
|
-
return String(error);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// src/actor.ts
|
|
496
|
-
var storage2 = createScopedStorage(
|
|
497
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:actor-storage")
|
|
498
|
-
);
|
|
499
|
-
function getCurrentActor() {
|
|
500
|
-
return storage2.read();
|
|
501
|
-
}
|
|
502
|
-
var SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
503
|
-
"pin",
|
|
504
|
-
"otp",
|
|
505
|
-
"totp",
|
|
506
|
-
"iban",
|
|
507
|
-
"mfa",
|
|
508
|
-
"passphrase"
|
|
509
|
-
]);
|
|
510
|
-
function snakeLower(key) {
|
|
511
|
-
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
512
|
-
}
|
|
513
|
-
function matchesSensitiveKey(key, substringPatterns) {
|
|
514
|
-
const lower = key.toLowerCase();
|
|
515
|
-
const snake = snakeLower(key);
|
|
516
|
-
if (substringPatterns.some((p) => lower.includes(p) || snake.includes(p))) {
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
const words = snake.split(/[^a-z0-9]+/);
|
|
520
|
-
return SENSITIVE_WORD_PATTERNS.some((w) => words.includes(w));
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/db/shared.ts
|
|
524
|
-
var IGNORED_ATTRIBUTES = Object.freeze([
|
|
525
|
-
"id",
|
|
526
|
-
"createdAt",
|
|
527
|
-
"created_at",
|
|
528
|
-
"updatedAt",
|
|
529
|
-
"updated_at",
|
|
530
|
-
"deletedAt",
|
|
531
|
-
"deleted_at",
|
|
532
|
-
// Auth.js / NextAuth standard columns
|
|
533
|
-
"emailVerified",
|
|
534
|
-
"expires"
|
|
535
|
-
]);
|
|
536
|
-
var DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
537
|
-
"password",
|
|
538
|
-
"token",
|
|
539
|
-
"secret",
|
|
540
|
-
"api_key",
|
|
541
|
-
"credit_card",
|
|
542
|
-
"ssn",
|
|
543
|
-
"social_security",
|
|
544
|
-
"encrypted",
|
|
545
|
-
"private_key",
|
|
546
|
-
"public_key",
|
|
547
|
-
"signing_key",
|
|
548
|
-
"pem",
|
|
549
|
-
"cipher",
|
|
550
|
-
"nonce",
|
|
551
|
-
"salt",
|
|
552
|
-
"digest",
|
|
553
|
-
"signature",
|
|
554
|
-
"hmac",
|
|
555
|
-
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
556
|
-
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
557
|
-
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
558
|
-
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
559
|
-
"credential",
|
|
560
|
-
"passwd",
|
|
561
|
-
"passcode",
|
|
562
|
-
"apikey",
|
|
563
|
-
"card_number",
|
|
564
|
-
"cardnumber",
|
|
565
|
-
"cvv",
|
|
566
|
-
"cvc"
|
|
567
|
-
]);
|
|
568
|
-
function emitDbEvent(input) {
|
|
569
|
-
try {
|
|
570
|
-
const config = configuration();
|
|
571
|
-
if (!config.captureDb) return;
|
|
572
|
-
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
573
|
-
if (config.databaseReader && !input._fromTrigger) {
|
|
574
|
-
const tracked = config.triggerTrackedTables;
|
|
575
|
-
if (tracked === null || tracked.has(input.modelClass)) return;
|
|
576
|
-
}
|
|
577
|
-
if (input.operation === "update") {
|
|
578
|
-
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
579
|
-
if (meaningful.length === 0) return;
|
|
580
|
-
}
|
|
581
|
-
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
582
|
-
const context = buildContext(input);
|
|
583
|
-
const event = build({
|
|
584
|
-
source_type: "database_callback",
|
|
585
|
-
source_data: {
|
|
586
|
-
model_class: input.modelClass,
|
|
587
|
-
operation: input.operation
|
|
588
|
-
},
|
|
589
|
-
outcome: "success",
|
|
590
|
-
correlation_id: current(),
|
|
591
|
-
resource_ids: resourceIdStr === null ? [] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
592
|
-
context,
|
|
593
|
-
duration_ms: null,
|
|
594
|
-
timestamp: input.timestamp ?? null
|
|
595
|
-
});
|
|
596
|
-
pushEvent(event);
|
|
597
|
-
} catch (error) {
|
|
598
|
-
logger.debug(`db emit failed: ${describeError(error)}`);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
function buildContext(input) {
|
|
602
|
-
const context = {};
|
|
603
|
-
const actor = getCurrentActor();
|
|
604
|
-
if (actor) context.actor = actor;
|
|
605
|
-
if ((input.operation === "create" || input.operation === "destroy") && input.initialAttributes) {
|
|
606
|
-
const filtered = filterMeaningfulAttributes(input.initialAttributes);
|
|
607
|
-
if (filtered !== null) context.initial_attributes = filtered;
|
|
608
|
-
}
|
|
609
|
-
if (input.operation === "update" && input.changes) {
|
|
610
|
-
const filtered = filterMeaningfulChanges(input.changes);
|
|
611
|
-
if (filtered.length > 0) {
|
|
612
|
-
context.changes = filtered.map((c) => {
|
|
613
|
-
const out = {
|
|
614
|
-
attribute: c.attribute,
|
|
615
|
-
to: formatForJson(c.to)
|
|
616
|
-
};
|
|
617
|
-
if (c.from !== void 0) out.from = formatForJson(c.from);
|
|
618
|
-
return out;
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
const displayName = input.displayName ?? (input.modelInstance ? resolveDisplayName(input.modelClass, input.modelInstance) : null);
|
|
623
|
-
if (displayName !== null) context.display_name = displayName;
|
|
624
|
-
return Object.keys(context).length === 0 ? null : context;
|
|
625
|
-
}
|
|
626
|
-
function filterMeaningfulAttributes(attrs) {
|
|
627
|
-
const out = {};
|
|
628
|
-
for (const key of Object.keys(attrs)) {
|
|
629
|
-
if (!isMeaningfulAttribute(key)) continue;
|
|
630
|
-
const value = attrs[key];
|
|
631
|
-
if (value === null || value === void 0) continue;
|
|
632
|
-
if (!isScalar(value)) continue;
|
|
633
|
-
out[key] = formatForJson(value);
|
|
634
|
-
}
|
|
635
|
-
return Object.keys(out).length === 0 ? null : out;
|
|
636
|
-
}
|
|
637
|
-
function filterMeaningfulChanges(changes) {
|
|
638
|
-
return changes.filter((c) => {
|
|
639
|
-
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
640
|
-
if (!isScalar(c.to)) return false;
|
|
641
|
-
if (c.from === void 0) return true;
|
|
642
|
-
if (!isScalar(c.from)) return false;
|
|
643
|
-
return valuesActuallyChanged(c.from, c.to);
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
function isMeaningfulAttribute(name) {
|
|
647
|
-
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
648
|
-
if (isDbSensitive(name)) return false;
|
|
649
|
-
return true;
|
|
650
|
-
}
|
|
651
|
-
function isDbSensitive(name) {
|
|
652
|
-
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
653
|
-
}
|
|
654
|
-
function isScalar(value) {
|
|
655
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
656
|
-
return true;
|
|
657
|
-
}
|
|
658
|
-
if (isPrismaDecimal(value)) return true;
|
|
659
|
-
if (Buffer.isBuffer?.(value)) return false;
|
|
660
|
-
if (Array.isArray(value)) return value.every((v) => isScalar(v));
|
|
661
|
-
return false;
|
|
662
|
-
}
|
|
663
|
-
function valuesActuallyChanged(from, to) {
|
|
664
|
-
if (from === null && to === null) return false;
|
|
665
|
-
if (from instanceof Date && to instanceof Date) {
|
|
666
|
-
return from.getTime() !== to.getTime();
|
|
667
|
-
}
|
|
668
|
-
return from !== to;
|
|
669
|
-
}
|
|
670
|
-
function formatForJson(value) {
|
|
671
|
-
if (value === null || value === void 0) return value;
|
|
672
|
-
if (value instanceof Date) return value.toISOString();
|
|
673
|
-
if (typeof value === "bigint") return value.toString();
|
|
674
|
-
if (isPrismaDecimal(value)) return Number(value.toString());
|
|
675
|
-
if (Array.isArray(value)) return value.map(formatForJson);
|
|
676
|
-
return value;
|
|
677
|
-
}
|
|
678
|
-
function isPrismaDecimal(value) {
|
|
679
|
-
if (value === null || typeof value !== "object") return false;
|
|
680
|
-
const obj = value;
|
|
681
|
-
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
682
|
-
}
|
|
683
|
-
function resolveDisplayName(modelClass, instance) {
|
|
684
|
-
try {
|
|
685
|
-
const config = configuration();
|
|
686
|
-
const resolver = config.displayNameFor[modelClass];
|
|
687
|
-
const resolved = applyResolver(resolver, instance);
|
|
688
|
-
if (resolved !== null) return resolved;
|
|
689
|
-
for (const field of ["name", "title", "number"]) {
|
|
690
|
-
const value = instance[field];
|
|
691
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
692
|
-
return String(value);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
} catch {
|
|
696
|
-
}
|
|
697
|
-
return null;
|
|
698
|
-
}
|
|
699
|
-
function applyResolver(resolver, instance) {
|
|
700
|
-
if (typeof resolver === "string") {
|
|
701
|
-
const value = instance[resolver];
|
|
702
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
703
|
-
return String(value);
|
|
704
|
-
}
|
|
705
|
-
return null;
|
|
706
|
-
}
|
|
707
|
-
if (typeof resolver === "function") {
|
|
708
|
-
try {
|
|
709
|
-
const value = resolver(instance);
|
|
710
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
711
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
712
|
-
return String(value);
|
|
713
|
-
}
|
|
714
|
-
} catch {
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return null;
|
|
718
|
-
}
|
|
719
|
-
function describeError(error) {
|
|
720
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
721
|
-
return String(error);
|
|
722
|
-
}
|
|
3
|
+
var chunkWASXTDLW_cjs = require('../chunk-WASXTDLW.cjs');
|
|
4
|
+
var chunkV5YNKKTG_cjs = require('../chunk-V5YNKKTG.cjs');
|
|
5
|
+
require('../chunk-ZDSQYCYV.cjs');
|
|
723
6
|
|
|
724
7
|
// src/db/prisma.ts
|
|
725
8
|
var CAPTURED_OPERATIONS = /* @__PURE__ */ new Set([
|
|
@@ -745,7 +28,7 @@ var OPERATION_TO_DB_OPERATION = {
|
|
|
745
28
|
function ezlogsPrisma() {
|
|
746
29
|
return (client) => client.$extends(buildPrismaExtension(client));
|
|
747
30
|
}
|
|
748
|
-
function buildPrismaExtension(client) {
|
|
31
|
+
function buildPrismaExtension(client, schemaClient = client) {
|
|
749
32
|
return {
|
|
750
33
|
name: "ezlogs",
|
|
751
34
|
query: {
|
|
@@ -756,9 +39,9 @@ function buildPrismaExtension(client) {
|
|
|
756
39
|
}
|
|
757
40
|
const result = await runTagged(client, ctx);
|
|
758
41
|
try {
|
|
759
|
-
recordPrismaOperation(ctx, result);
|
|
42
|
+
recordPrismaOperation(ctx, result, tableNameFor(schemaClient, ctx.model));
|
|
760
43
|
} catch (error) {
|
|
761
|
-
logger.debug(`prisma capture failed: ${
|
|
44
|
+
chunkV5YNKKTG_cjs.logger.debug(`prisma capture failed: ${describeError(error)}`);
|
|
762
45
|
}
|
|
763
46
|
return result;
|
|
764
47
|
}
|
|
@@ -778,15 +61,15 @@ async function runTagged(client, ctx) {
|
|
|
778
61
|
if (!shouldTag(client, ctx)) return ctx.query(ctx.args);
|
|
779
62
|
try {
|
|
780
63
|
const results = await client.$transaction([
|
|
781
|
-
client.$executeRawUnsafe(SET_CORRELATION_SQL, current()),
|
|
64
|
+
client.$executeRawUnsafe(SET_CORRELATION_SQL, chunkWASXTDLW_cjs.current()),
|
|
782
65
|
ctx.query(ctx.args)
|
|
783
66
|
]);
|
|
784
67
|
return results[1];
|
|
785
68
|
} catch (error) {
|
|
786
69
|
if (!isTransactionUnsupported(error)) throw error;
|
|
787
70
|
taggingDisabled.add(client);
|
|
788
|
-
logger.warn(
|
|
789
|
-
`this Prisma client can't run transactions, so DB writes won't be linked to their request (they still show up as their own actions): ${
|
|
71
|
+
chunkV5YNKKTG_cjs.logger.warn(
|
|
72
|
+
`this Prisma client can't run transactions, so DB writes won't be linked to their request (they still show up as their own actions): ${describeError(error)}`
|
|
790
73
|
);
|
|
791
74
|
return ctx.query(ctx.args);
|
|
792
75
|
}
|
|
@@ -797,12 +80,12 @@ function _resetPrismaTaggingForTests() {
|
|
|
797
80
|
}
|
|
798
81
|
function shouldTag(client, ctx) {
|
|
799
82
|
if (!client || taggingDisabled.has(client)) return false;
|
|
800
|
-
if (configuration().databaseReader == null) return false;
|
|
83
|
+
if (chunkWASXTDLW_cjs.configuration().databaseReader == null) return false;
|
|
801
84
|
if (!isPostgresClient(client)) return false;
|
|
802
85
|
if (typeof client.$transaction !== "function" || typeof client.$executeRawUnsafe !== "function") {
|
|
803
86
|
return false;
|
|
804
87
|
}
|
|
805
|
-
if (!current()) return false;
|
|
88
|
+
if (!chunkWASXTDLW_cjs.current()) return false;
|
|
806
89
|
const params = ctx.__internalParams;
|
|
807
90
|
return params != null && !params.transaction;
|
|
808
91
|
}
|
|
@@ -816,21 +99,30 @@ function isTransactionUnsupported(error) {
|
|
|
816
99
|
const message = error instanceof Error ? error.message : String(error);
|
|
817
100
|
return /transaction/i.test(message) && /not (?:be )?supported|unsupported|not available/i.test(message);
|
|
818
101
|
}
|
|
819
|
-
function
|
|
102
|
+
function tableNameFor(schemaClient, model) {
|
|
103
|
+
try {
|
|
104
|
+
const dbName = schemaClient?._runtimeDataModel?.models?.[model]?.dbName;
|
|
105
|
+
return typeof dbName === "string" && dbName.length > 0 ? dbName : model;
|
|
106
|
+
} catch {
|
|
107
|
+
return model;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function recordPrismaOperation(ctx, result, table) {
|
|
820
111
|
const dbOperation = OPERATION_TO_DB_OPERATION[ctx.operation];
|
|
821
112
|
if (!dbOperation) return;
|
|
822
113
|
if (isBatchResult(result)) {
|
|
823
|
-
emitDbEvent({
|
|
114
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
824
115
|
modelClass: ctx.model,
|
|
116
|
+
table,
|
|
825
117
|
operation: dbOperation,
|
|
826
118
|
resourceId: null,
|
|
827
119
|
// For batch updates we still capture the `args.data` shape so
|
|
828
120
|
// downstream sees what columns were touched even if we can't
|
|
829
121
|
// identify a specific row.
|
|
830
|
-
...dbOperation === "update" &&
|
|
122
|
+
...dbOperation === "update" && isPlainObject(ctx.args.data) ? {
|
|
831
123
|
changes: extractChangesFromUpdateData(ctx.args.data)
|
|
832
124
|
} : {},
|
|
833
|
-
...dbOperation === "create" &&
|
|
125
|
+
...dbOperation === "create" && isPlainObject(ctx.args.data) ? {
|
|
834
126
|
initialAttributes: ctx.args.data
|
|
835
127
|
} : {}
|
|
836
128
|
});
|
|
@@ -838,16 +130,17 @@ function recordPrismaOperation(ctx, result) {
|
|
|
838
130
|
}
|
|
839
131
|
if (Array.isArray(result)) {
|
|
840
132
|
for (const row of result) {
|
|
841
|
-
emitSingleRowEvent(ctx, dbOperation, row);
|
|
133
|
+
emitSingleRowEvent(ctx, dbOperation, row, table);
|
|
842
134
|
}
|
|
843
135
|
return;
|
|
844
136
|
}
|
|
845
|
-
emitSingleRowEvent(ctx, dbOperation, result);
|
|
137
|
+
emitSingleRowEvent(ctx, dbOperation, result, table);
|
|
846
138
|
}
|
|
847
|
-
function emitSingleRowEvent(ctx, dbOperation, row) {
|
|
848
|
-
if (!
|
|
849
|
-
emitDbEvent({
|
|
139
|
+
function emitSingleRowEvent(ctx, dbOperation, row, table) {
|
|
140
|
+
if (!isPlainObject(row)) {
|
|
141
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
850
142
|
modelClass: ctx.model,
|
|
143
|
+
table,
|
|
851
144
|
operation: dbOperation,
|
|
852
145
|
resourceId: null
|
|
853
146
|
});
|
|
@@ -855,21 +148,26 @@ function emitSingleRowEvent(ctx, dbOperation, row) {
|
|
|
855
148
|
}
|
|
856
149
|
const rowObj = row;
|
|
857
150
|
const resourceId = rowObj.id ?? null;
|
|
858
|
-
const displayName = resolveDisplayName(ctx.model, rowObj);
|
|
151
|
+
const displayName = chunkWASXTDLW_cjs.resolveDisplayName(ctx.model, rowObj);
|
|
859
152
|
if (dbOperation === "create") {
|
|
860
|
-
emitDbEvent({
|
|
153
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
861
154
|
modelClass: ctx.model,
|
|
155
|
+
table,
|
|
862
156
|
operation: "create",
|
|
863
157
|
resourceId,
|
|
864
|
-
initialAttributes:
|
|
158
|
+
initialAttributes: {
|
|
159
|
+
...isPlainObject(ctx.args.data) ? ctx.args.data : {},
|
|
160
|
+
...rowObj
|
|
161
|
+
},
|
|
865
162
|
displayName,
|
|
866
163
|
modelInstance: rowObj
|
|
867
164
|
});
|
|
868
165
|
return;
|
|
869
166
|
}
|
|
870
167
|
if (dbOperation === "update") {
|
|
871
|
-
emitDbEvent({
|
|
168
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
872
169
|
modelClass: ctx.model,
|
|
170
|
+
table,
|
|
873
171
|
operation: "update",
|
|
874
172
|
resourceId,
|
|
875
173
|
changes: extractUpdateChangesFromArgs(ctx, rowObj),
|
|
@@ -878,49 +176,40 @@ function emitSingleRowEvent(ctx, dbOperation, row) {
|
|
|
878
176
|
});
|
|
879
177
|
return;
|
|
880
178
|
}
|
|
881
|
-
emitDbEvent({
|
|
179
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
882
180
|
modelClass: ctx.model,
|
|
181
|
+
table,
|
|
883
182
|
operation: "destroy",
|
|
884
183
|
resourceId,
|
|
184
|
+
initialAttributes: rowObj,
|
|
885
185
|
displayName,
|
|
886
186
|
modelInstance: rowObj
|
|
887
187
|
});
|
|
888
188
|
}
|
|
889
|
-
function extractCreateAttributes(ctx, resultRow) {
|
|
890
|
-
if (isPlainObject2(ctx.args.data)) {
|
|
891
|
-
return ctx.args.data;
|
|
892
|
-
}
|
|
893
|
-
if (ctx.operation === "upsert" && isPlainObject2(ctx.args.create)) {
|
|
894
|
-
return ctx.args.create;
|
|
895
|
-
}
|
|
896
|
-
return resultRow;
|
|
897
|
-
}
|
|
898
189
|
function extractUpdateChangesFromArgs(ctx, resultRow) {
|
|
899
|
-
const data =
|
|
190
|
+
const data = isPlainObject(ctx.args.data) ? ctx.args.data : ctx.operation === "upsert" && isPlainObject(ctx.args.update) ? ctx.args.update : null;
|
|
900
191
|
if (!data) return [];
|
|
901
192
|
return Object.keys(data).map((attribute) => ({
|
|
902
193
|
attribute,
|
|
903
|
-
from: null,
|
|
904
194
|
to: resultRow[attribute] ?? data[attribute]
|
|
905
195
|
}));
|
|
906
196
|
}
|
|
907
197
|
function extractChangesFromUpdateData(data) {
|
|
908
198
|
return Object.keys(data).map((attribute) => ({
|
|
909
199
|
attribute,
|
|
910
|
-
from: null,
|
|
911
200
|
to: data[attribute]
|
|
912
201
|
}));
|
|
913
202
|
}
|
|
914
203
|
function isBatchResult(value) {
|
|
915
|
-
return
|
|
204
|
+
return isPlainObject(value) && typeof value.count === "number" && Object.keys(value).length === 1;
|
|
916
205
|
}
|
|
917
|
-
function
|
|
206
|
+
function isPlainObject(value) {
|
|
918
207
|
if (value === null || typeof value !== "object") return false;
|
|
919
208
|
if (Array.isArray(value)) return false;
|
|
920
209
|
if (value instanceof Date) return false;
|
|
921
210
|
return true;
|
|
922
211
|
}
|
|
923
|
-
function
|
|
212
|
+
function describeError(error) {
|
|
924
213
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
925
214
|
return String(error);
|
|
926
215
|
}
|
|
@@ -978,16 +267,16 @@ function patchPrismaClient(prisma, adapter) {
|
|
|
978
267
|
if (prisma[EZLOGS_PRISMA_BRAND] === true) {
|
|
979
268
|
return prisma;
|
|
980
269
|
}
|
|
981
|
-
const captureAndRun = makeAsyncContextCapture();
|
|
270
|
+
const captureAndRun = chunkWASXTDLW_cjs.makeAsyncContextCapture();
|
|
982
271
|
if (!captureAndRun) {
|
|
983
|
-
logger.debug(
|
|
272
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
984
273
|
"patchPrismaClient: AsyncLocalStorage.snapshot() unavailable; skipping ALS bind, applying ezlogsPrisma() only."
|
|
985
274
|
);
|
|
986
275
|
return applyEzlogsExtension(prisma);
|
|
987
276
|
}
|
|
988
277
|
const patchedAdapter = adapter && typeof adapter === "object" && adapter[EZLOGS_ADAPTER_BRAND] === true ? adapter : null;
|
|
989
278
|
if (adapter && !patchedAdapter) {
|
|
990
|
-
logger.debug(
|
|
279
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
991
280
|
"patchPrismaClient: adapter is not the output of patchPrismaPgAdapter(). Correlation_id will be NULL on concurrent requests. Wrap the adapter first."
|
|
992
281
|
);
|
|
993
282
|
}
|
|
@@ -998,15 +287,15 @@ function patchPrismaClient(prisma, adapter) {
|
|
|
998
287
|
function applyEzlogsExtension(prisma) {
|
|
999
288
|
const client = prisma;
|
|
1000
289
|
if (typeof client.$extends !== "function") {
|
|
1001
|
-
logger.debug(
|
|
290
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
1002
291
|
"patchPrismaClient: client has no $extends; skipping ezlogsPrisma extension."
|
|
1003
292
|
);
|
|
1004
293
|
return prisma;
|
|
1005
294
|
}
|
|
1006
295
|
try {
|
|
1007
|
-
return client.$extends(buildPrismaExtension(null));
|
|
296
|
+
return client.$extends(buildPrismaExtension(null, prisma));
|
|
1008
297
|
} catch (error) {
|
|
1009
|
-
logger.debug(`patchPrismaClient: $extends failed: ${
|
|
298
|
+
chunkV5YNKKTG_cjs.logger.debug(`patchPrismaClient: $extends failed: ${describeError(error)}`);
|
|
1010
299
|
return prisma;
|
|
1011
300
|
}
|
|
1012
301
|
}
|