ezlogs-nextjs 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/bin/install-triggers.cjs +33 -5
- package/dist/actors/index.cjs +5 -37
- package/dist/actors/index.js +2 -34
- package/dist/chunk-C5OSM557.js +39 -0
- package/dist/chunk-CE3R7DVB.js +1127 -0
- package/dist/chunk-CU45I2WR.js +498 -0
- package/dist/chunk-DKRNNI4I.js +180 -0
- package/dist/chunk-SIAA4J6H.js +17 -0
- package/dist/chunk-UQHEW6ER.js +119 -0
- package/dist/chunk-UWHYJH4M.cjs +126 -0
- package/dist/chunk-V5YNKKTG.cjs +42 -0
- package/dist/chunk-WASXTDLW.cjs +1151 -0
- package/dist/chunk-Y5NSHKWQ.cjs +182 -0
- package/dist/chunk-YX2XPLOA.cjs +508 -0
- package/dist/chunk-ZDSQYCYV.cjs +21 -0
- package/dist/db/drizzle.cjs +6 -821
- package/dist/db/drizzle.js +5 -820
- package/dist/db/prisma.cjs +28 -853
- package/dist/db/prisma.js +14 -839
- package/dist/db/supabase.cjs +21 -836
- package/dist/db/supabase.js +14 -829
- package/dist/index.cjs +132 -2362
- package/dist/index.js +34 -2270
- package/dist/jobs/bullmq.cjs +13 -1465
- package/dist/jobs/bullmq.js +7 -1459
- package/dist/jobs/inngest.cjs +14 -1422
- package/dist/jobs/inngest.js +8 -1416
- package/dist/jobs/supabase-queues.cjs +15 -1467
- package/dist/jobs/supabase-queues.js +10 -1462
- package/dist/jobs/trigger.cjs +9 -1454
- package/dist/jobs/trigger.js +5 -1450
- package/dist/jobs/upstash-workflow.cjs +30 -1456
- package/dist/jobs/upstash-workflow.d.cts +2 -1
- package/dist/jobs/upstash-workflow.d.ts +2 -1
- package/dist/jobs/upstash-workflow.js +27 -1453
- package/dist/nextjs-plugin/index.cjs +1 -1
- package/dist/nextjs-plugin/index.js +1 -1
- package/dist/nextjs-plugin/loader.cjs +21 -25
- package/dist/nextjs-plugin/loader.js +1 -5
- package/dist/triggers/index.cjs +40 -1434
- package/dist/triggers/index.js +6 -1421
- package/package.json +2 -1
package/dist/db/supabase.cjs
CHANGED
|
@@ -1,827 +1,12 @@
|
|
|
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/configuration.ts
|
|
46
|
-
var DEFAULT_EXCLUDED_PATHS = Object.freeze([
|
|
47
|
-
// Next.js / Vercel infrastructure noise
|
|
48
|
-
"/_next/*",
|
|
49
|
-
"/_vercel/*",
|
|
50
|
-
"/__nextjs_*",
|
|
51
|
-
// NextAuth.js / Auth.js — skip session-refresh polls and CSRF/provider
|
|
52
|
-
// metadata GETs (high-frequency, no business meaning), but CAPTURE
|
|
53
|
-
// POSTs (callbacks, signin, signout, register). The POSTs are the
|
|
54
|
-
// actual auth events users care about; the GETs are pure plumbing.
|
|
55
|
-
Object.freeze({ path: "/api/auth/*", methods: ["GET", "HEAD"] }),
|
|
56
|
-
// Generic infrastructure
|
|
57
|
-
"/health*",
|
|
58
|
-
"/api/health",
|
|
59
|
-
"/up",
|
|
60
|
-
"/alive",
|
|
61
|
-
"/ready",
|
|
62
|
-
"/metrics",
|
|
63
|
-
"/favicon.ico",
|
|
64
|
-
"/.well-known*",
|
|
65
|
-
"/robots.txt",
|
|
66
|
-
"/sitemap.xml",
|
|
67
|
-
"/*.hot-update.*",
|
|
68
|
-
// Auth routes (common patterns across Clerk, NextAuth, custom auth)
|
|
69
|
-
"*/login*",
|
|
70
|
-
"*/logout*",
|
|
71
|
-
"*/sign-in*",
|
|
72
|
-
"*/sign-out*",
|
|
73
|
-
"*/signin*",
|
|
74
|
-
"*/signout*",
|
|
75
|
-
"/session*"
|
|
76
|
-
]);
|
|
77
|
-
var DEFAULT_EXCLUDED_TABLES = Object.freeze([
|
|
78
|
-
// Prisma migration ledger
|
|
79
|
-
"_prisma_migrations",
|
|
80
|
-
// Auth.js / NextAuth Prisma adapter — session/verification-token churn
|
|
81
|
-
// is auth machinery, not business activity. Account/User stay captured.
|
|
82
|
-
"Session",
|
|
83
|
-
"VerificationToken",
|
|
84
|
-
// Common cross-stack convention names for the same things
|
|
85
|
-
"sessions",
|
|
86
|
-
"session",
|
|
87
|
-
"verification_tokens"
|
|
88
|
-
]);
|
|
89
|
-
var DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
|
|
90
|
-
var DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
|
|
91
|
-
var Configuration = class {
|
|
92
|
-
serverUrl = null;
|
|
93
|
-
projectToken = null;
|
|
94
|
-
captureHttp = true;
|
|
95
|
-
captureDb = true;
|
|
96
|
-
captureJobs = true;
|
|
97
|
-
bufferSize = 1e4;
|
|
98
|
-
/** Default 3000 ms — equivalent to Ruby's 3 seconds. */
|
|
99
|
-
sendInterval = 3e3;
|
|
100
|
-
retryAttempts = 3;
|
|
101
|
-
logLevel = "warn";
|
|
102
|
-
patchGlobalFetch = true;
|
|
103
|
-
actorFromSupabase = true;
|
|
104
|
-
allowInsecureTransport = false;
|
|
105
|
-
excludedPaths = [];
|
|
106
|
-
excludedTables = [];
|
|
107
|
-
excludedJobClasses = [];
|
|
108
|
-
excludedGraphqlOperations = [];
|
|
109
|
-
excludedGraphqlVariableKeys = [];
|
|
110
|
-
actorFromRequest = null;
|
|
111
|
-
displayNameFor = {};
|
|
112
|
-
isServerActionError = null;
|
|
113
|
-
databaseReader = null;
|
|
114
|
-
databaseUrl = null;
|
|
115
|
-
/**
|
|
116
|
-
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
117
|
-
* at agent startup by reading `information_schema.triggers`. The
|
|
118
|
-
* supabase / drizzle / prisma adapters use this to decide whether
|
|
119
|
-
* their per-mutation emit is redundant: if the table is trigger-
|
|
120
|
-
* tracked the audit-log reader will surface the same write with full
|
|
121
|
-
* old/new state, so the adapter's emit is suppressed. Tables NOT in
|
|
122
|
-
* this set fall through to the adapter so they're still captured.
|
|
123
|
-
*
|
|
124
|
-
* `null` means "detection hasn't run yet or failed" — in that state
|
|
125
|
-
* `databaseReader`-wired apps suppress every adapter emit (the
|
|
126
|
-
* original Phase 5 behavior). After detection completes the agent
|
|
127
|
-
* gives the more accurate per-table answer.
|
|
128
|
-
*/
|
|
129
|
-
triggerTrackedTables = null;
|
|
130
|
-
apply(options) {
|
|
131
|
-
this.serverUrl = options.serverUrl;
|
|
132
|
-
this.projectToken = options.projectToken;
|
|
133
|
-
if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
|
|
134
|
-
if (options.captureDb !== void 0) this.captureDb = options.captureDb;
|
|
135
|
-
if (options.captureJobs !== void 0) this.captureJobs = options.captureJobs;
|
|
136
|
-
if (options.bufferSize !== void 0) this.bufferSize = options.bufferSize;
|
|
137
|
-
if (options.sendInterval !== void 0) this.sendInterval = options.sendInterval;
|
|
138
|
-
if (options.retryAttempts !== void 0) this.retryAttempts = options.retryAttempts;
|
|
139
|
-
if (options.excludedPaths) this.excludedPaths = [...options.excludedPaths];
|
|
140
|
-
if (options.excludedTables) this.excludedTables = [...options.excludedTables];
|
|
141
|
-
if (options.excludedJobClasses) {
|
|
142
|
-
this.excludedJobClasses = [...options.excludedJobClasses];
|
|
143
|
-
}
|
|
144
|
-
if (options.excludedGraphqlOperations) {
|
|
145
|
-
this.excludedGraphqlOperations = [...options.excludedGraphqlOperations];
|
|
146
|
-
}
|
|
147
|
-
if (options.excludedGraphqlVariableKeys) {
|
|
148
|
-
this.excludedGraphqlVariableKeys = [...options.excludedGraphqlVariableKeys];
|
|
149
|
-
}
|
|
150
|
-
if (options.actorFromRequest) this.actorFromRequest = options.actorFromRequest;
|
|
151
|
-
if (options.displayNameFor) this.displayNameFor = { ...options.displayNameFor };
|
|
152
|
-
if (options.isServerActionError) this.isServerActionError = options.isServerActionError;
|
|
153
|
-
if (options.patchGlobalFetch !== void 0) {
|
|
154
|
-
this.patchGlobalFetch = options.patchGlobalFetch;
|
|
155
|
-
}
|
|
156
|
-
if (options.allowInsecureTransport !== void 0) {
|
|
157
|
-
this.allowInsecureTransport = options.allowInsecureTransport;
|
|
158
|
-
}
|
|
159
|
-
if (options.actorFromSupabase !== void 0) {
|
|
160
|
-
this.actorFromSupabase = options.actorFromSupabase;
|
|
161
|
-
}
|
|
162
|
-
if (options.databaseReader !== void 0) {
|
|
163
|
-
this.databaseReader = options.databaseReader;
|
|
164
|
-
}
|
|
165
|
-
if (options.databaseUrl !== void 0) {
|
|
166
|
-
this.databaseUrl = options.databaseUrl;
|
|
167
|
-
}
|
|
168
|
-
if (options.logLevel) this.logLevel = options.logLevel;
|
|
169
|
-
}
|
|
170
|
-
allExcludedPaths() {
|
|
171
|
-
return [...DEFAULT_EXCLUDED_PATHS, ...this.excludedPaths];
|
|
172
|
-
}
|
|
173
|
-
allExcludedTables() {
|
|
174
|
-
return [...DEFAULT_EXCLUDED_TABLES, ...this.excludedTables];
|
|
175
|
-
}
|
|
176
|
-
allExcludedJobClasses() {
|
|
177
|
-
return [...DEFAULT_EXCLUDED_JOB_CLASSES, ...this.excludedJobClasses];
|
|
178
|
-
}
|
|
179
|
-
allExcludedGraphqlOperations() {
|
|
180
|
-
return [...DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, ...this.excludedGraphqlOperations];
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
var GLOBAL_CONFIG_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:configuration");
|
|
184
|
-
function configuration() {
|
|
185
|
-
const g = globalThis;
|
|
186
|
-
if (!g[GLOBAL_CONFIG_KEY]) {
|
|
187
|
-
g[GLOBAL_CONFIG_KEY] = new Configuration();
|
|
188
|
-
}
|
|
189
|
-
return g[GLOBAL_CONFIG_KEY];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// src/event-builder.ts
|
|
193
|
-
var SENSITIVE_KEYS = Object.freeze([
|
|
194
|
-
"password",
|
|
195
|
-
"token",
|
|
196
|
-
"secret",
|
|
197
|
-
"api_key",
|
|
198
|
-
"credit_card"
|
|
199
|
-
]);
|
|
200
|
-
var VALID_SOURCE_TYPES = [
|
|
201
|
-
"http_request",
|
|
202
|
-
"background_job",
|
|
203
|
-
"database_callback"
|
|
204
|
-
];
|
|
205
|
-
var VALID_OUTCOMES = ["success", "failure"];
|
|
206
|
-
function build(input) {
|
|
207
|
-
const source_type = validateSourceType(input.source_type);
|
|
208
|
-
const source_data_raw = validateSourceData(input.source_data);
|
|
209
|
-
const outcome = validateOutcome(input.outcome);
|
|
210
|
-
const timestamp = validateTimestamp(input.timestamp ?? null);
|
|
211
|
-
const resource_ids = validateResourceIds(input.resource_ids ?? []);
|
|
212
|
-
const context_raw = validateContext(input.context ?? null);
|
|
213
|
-
const duration_ms = validateDurationMs();
|
|
214
|
-
const error_message = input.error_message ?? null;
|
|
215
|
-
validateOutcomeErrorConsistency(outcome, error_message);
|
|
216
|
-
const source_data = sanitizeRecord(source_data_raw);
|
|
217
|
-
const context = context_raw === null ? null : sanitizeRecord(context_raw);
|
|
218
|
-
const correlation_id = input.correlation_id ?? null;
|
|
219
|
-
const event = {
|
|
220
|
-
timestamp,
|
|
221
|
-
source_type,
|
|
222
|
-
source_data,
|
|
223
|
-
outcome,
|
|
224
|
-
correlation_id,
|
|
225
|
-
resource_ids,
|
|
226
|
-
context,
|
|
227
|
-
duration_ms,
|
|
228
|
-
error_message
|
|
229
|
-
};
|
|
230
|
-
return event;
|
|
231
|
-
}
|
|
232
|
-
function validateSourceType(value) {
|
|
233
|
-
const normalized = String(value);
|
|
234
|
-
if (!VALID_SOURCE_TYPES.includes(normalized)) {
|
|
235
|
-
throw new ArgError(
|
|
236
|
-
`source_type must be one of ${VALID_SOURCE_TYPES.join(", ")}, got: ${normalized}`
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
return normalized;
|
|
240
|
-
}
|
|
241
|
-
function validateSourceData(value) {
|
|
242
|
-
if (value === null || value === void 0) {
|
|
243
|
-
throw new ArgError("source_data is required");
|
|
244
|
-
}
|
|
245
|
-
if (!isPlainObject(value)) {
|
|
246
|
-
throw new ArgError(
|
|
247
|
-
`source_data must be an object, got: ${describe(value)}`
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
return value;
|
|
251
|
-
}
|
|
252
|
-
function validateOutcome(value) {
|
|
253
|
-
const normalized = String(value);
|
|
254
|
-
if (!VALID_OUTCOMES.includes(normalized)) {
|
|
255
|
-
throw new ArgError(
|
|
256
|
-
`outcome must be one of ${VALID_OUTCOMES.join(", ")}, got: ${normalized}`
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
return normalized;
|
|
260
|
-
}
|
|
261
|
-
function validateTimestamp(value) {
|
|
262
|
-
if (value === null) {
|
|
263
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
264
|
-
}
|
|
265
|
-
if (typeof value === "string") {
|
|
266
|
-
const parsed = new Date(value);
|
|
267
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
268
|
-
throw new ArgError(
|
|
269
|
-
`timestamp must be valid ISO 8601 format, got: ${value}`
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
|
-
if (value instanceof Date) {
|
|
275
|
-
if (Number.isNaN(value.getTime())) {
|
|
276
|
-
throw new ArgError("timestamp must be a valid Date");
|
|
277
|
-
}
|
|
278
|
-
return value.toISOString();
|
|
279
|
-
}
|
|
280
|
-
throw new ArgError(
|
|
281
|
-
`timestamp must be a string or Date, got: ${describe(value)}`
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
function validateResourceIds(value) {
|
|
285
|
-
if (!Array.isArray(value)) {
|
|
286
|
-
throw new ArgError(`resource_ids must be an array, got: ${describe(value)}`);
|
|
287
|
-
}
|
|
288
|
-
value.forEach((entry, index) => {
|
|
289
|
-
if (!isPlainObject(entry)) {
|
|
290
|
-
throw new ArgError(
|
|
291
|
-
`resource_ids[${index}] must be an object, got: ${describe(entry)}`
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
const e = entry;
|
|
295
|
-
if (!("resource_type" in e) || !("resource_id" in e)) {
|
|
296
|
-
throw new ArgError(
|
|
297
|
-
`resource_ids[${index}] must have resource_type and resource_id keys, got: ${Object.keys(e).join(", ")}`
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
if (typeof e.resource_type !== "string") {
|
|
301
|
-
throw new ArgError(
|
|
302
|
-
`resource_ids[${index}].resource_type must be a string, got: ${describe(e.resource_type)}`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
if (typeof e.resource_id !== "string") {
|
|
306
|
-
throw new ArgError(
|
|
307
|
-
`resource_ids[${index}].resource_id must be a string, got: ${describe(e.resource_id)}`
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
return value;
|
|
312
|
-
}
|
|
313
|
-
function validateContext(value) {
|
|
314
|
-
if (value === null) return null;
|
|
315
|
-
if (!isPlainObject(value)) {
|
|
316
|
-
throw new ArgError(
|
|
317
|
-
`context must be an object or null, got: ${describe(value)}`
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
return value;
|
|
321
|
-
}
|
|
322
|
-
function validateDurationMs(value) {
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
function validateOutcomeErrorConsistency(outcome, error_message) {
|
|
326
|
-
if (outcome === "failure") {
|
|
327
|
-
if (error_message === null || error_message === "") {
|
|
328
|
-
throw new ArgError("error_message is required when outcome is 'failure'");
|
|
329
|
-
}
|
|
330
|
-
} else if (outcome === "success") {
|
|
331
|
-
if (error_message !== null) {
|
|
332
|
-
throw new ArgError("error_message must be null when outcome is 'success'");
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
function sanitizeRecord(input) {
|
|
337
|
-
const result = {};
|
|
338
|
-
for (const key of Object.keys(input)) {
|
|
339
|
-
const value = input[key];
|
|
340
|
-
if (isSensitiveKey(key)) {
|
|
341
|
-
result[key] = "[FILTERED]";
|
|
342
|
-
} else if (isPlainObject(value)) {
|
|
343
|
-
result[key] = sanitizeRecord(value);
|
|
344
|
-
} else if (Array.isArray(value)) {
|
|
345
|
-
result[key] = value.map(
|
|
346
|
-
(item) => isPlainObject(item) ? sanitizeRecord(item) : item
|
|
347
|
-
);
|
|
348
|
-
} else {
|
|
349
|
-
result[key] = value;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return result;
|
|
353
|
-
}
|
|
354
|
-
function isSensitiveKey(key) {
|
|
355
|
-
const lower = key.toLowerCase();
|
|
356
|
-
return SENSITIVE_KEYS.some((p) => lower.includes(p));
|
|
357
|
-
}
|
|
358
|
-
function isPlainObject(value) {
|
|
359
|
-
if (value === null || typeof value !== "object") return false;
|
|
360
|
-
const proto = Object.getPrototypeOf(value);
|
|
361
|
-
return proto === Object.prototype || proto === null;
|
|
362
|
-
}
|
|
363
|
-
function describe(value) {
|
|
364
|
-
if (value === null) return "null";
|
|
365
|
-
if (Array.isArray(value)) return "Array";
|
|
366
|
-
return typeof value;
|
|
367
|
-
}
|
|
368
|
-
var ArgError = class extends Error {
|
|
369
|
-
constructor(message) {
|
|
370
|
-
super(message);
|
|
371
|
-
this.name = "ArgError";
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// src/pipeline/buffer.ts
|
|
376
|
-
var GLOBAL_QUEUE_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:buffer-queue");
|
|
377
|
-
function getQueue() {
|
|
378
|
-
const g = globalThis;
|
|
379
|
-
if (!g[GLOBAL_QUEUE_KEY]) g[GLOBAL_QUEUE_KEY] = [];
|
|
380
|
-
return g[GLOBAL_QUEUE_KEY];
|
|
381
|
-
}
|
|
382
|
-
function pushEvent(event) {
|
|
383
|
-
try {
|
|
384
|
-
const queue = getQueue();
|
|
385
|
-
const max = maxSize();
|
|
386
|
-
if (queue.length >= max) {
|
|
387
|
-
queue.shift();
|
|
388
|
-
logger.warn(`Buffer full (${max}), dropped oldest event`);
|
|
389
|
-
}
|
|
390
|
-
queue.push(event);
|
|
391
|
-
} catch (error) {
|
|
392
|
-
logger.error(`pushEvent failed: ${describe2(error)}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function maxSize() {
|
|
396
|
-
try {
|
|
397
|
-
return configuration().bufferSize;
|
|
398
|
-
} catch {
|
|
399
|
-
return 1e4;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
function describe2(error) {
|
|
403
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
404
|
-
return String(error);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// src/edge-fallback.ts
|
|
408
|
-
var ALS_CTOR = loadAsyncLocalStorage();
|
|
409
|
-
function loadAsyncLocalStorage() {
|
|
410
|
-
const fromGlobal = globalThis.AsyncLocalStorage;
|
|
411
|
-
if (typeof fromGlobal === "function") return fromGlobal;
|
|
412
|
-
try {
|
|
413
|
-
const req = typeof __require !== "undefined" ? __require : (
|
|
414
|
-
// In ESM, `createRequire` is the official escape hatch.
|
|
415
|
-
// We pull it via globalThis to avoid a static `import`
|
|
416
|
-
// that would itself be browser-bundled.
|
|
417
|
-
void 0
|
|
418
|
-
);
|
|
419
|
-
if (typeof req === "function") {
|
|
420
|
-
const moduleName = ["async", "hooks"].join("_");
|
|
421
|
-
const mod = req("node:" + moduleName);
|
|
422
|
-
if (typeof mod.AsyncLocalStorage === "function") return mod.AsyncLocalStorage;
|
|
423
|
-
}
|
|
424
|
-
} catch {
|
|
425
|
-
}
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
function createScopedStorage(key = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:default-scoped-storage")) {
|
|
429
|
-
const globalStore = globalThis;
|
|
430
|
-
let entry = globalStore[key];
|
|
431
|
-
if (!entry) {
|
|
432
|
-
const als2 = (() => {
|
|
433
|
-
if (!ALS_CTOR) return null;
|
|
434
|
-
try {
|
|
435
|
-
return new ALS_CTOR();
|
|
436
|
-
} catch {
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
})();
|
|
440
|
-
entry = { als: als2, edgeFallback: null };
|
|
441
|
-
globalStore[key] = entry;
|
|
442
|
-
}
|
|
443
|
-
const als = entry.als;
|
|
444
|
-
const stateRef = entry;
|
|
445
|
-
return {
|
|
446
|
-
read() {
|
|
447
|
-
if (als) return als.getStore()?.value ?? null;
|
|
448
|
-
return stateRef.edgeFallback?.value ?? null;
|
|
449
|
-
},
|
|
450
|
-
run(value, callback) {
|
|
451
|
-
if (als) return als.run({ value }, callback);
|
|
452
|
-
const previous = stateRef.edgeFallback;
|
|
453
|
-
stateRef.edgeFallback = { value };
|
|
454
|
-
try {
|
|
455
|
-
return callback();
|
|
456
|
-
} finally {
|
|
457
|
-
stateRef.edgeFallback = previous;
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
update(value) {
|
|
461
|
-
if (als) {
|
|
462
|
-
const store = als.getStore();
|
|
463
|
-
if (store) store.value = value;
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
stateRef.edgeFallback = { value };
|
|
467
|
-
},
|
|
468
|
-
_resetForTests() {
|
|
469
|
-
stateRef.edgeFallback = null;
|
|
470
|
-
},
|
|
471
|
-
_isAsyncLocalStorage() {
|
|
472
|
-
return als !== null;
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// src/correlation.ts
|
|
478
|
-
var storage = createScopedStorage(
|
|
479
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
|
|
480
|
-
);
|
|
481
|
-
function current() {
|
|
482
|
-
return storage.read();
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// src/actor.ts
|
|
486
|
-
var storage2 = createScopedStorage(
|
|
487
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:actor-storage")
|
|
488
|
-
);
|
|
489
|
-
function getCurrentActor() {
|
|
490
|
-
return storage2.read();
|
|
491
|
-
}
|
|
492
|
-
var SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
493
|
-
"pin",
|
|
494
|
-
"otp",
|
|
495
|
-
"totp",
|
|
496
|
-
"iban",
|
|
497
|
-
"mfa",
|
|
498
|
-
"passphrase"
|
|
499
|
-
]);
|
|
500
|
-
function snakeLower(key) {
|
|
501
|
-
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
502
|
-
}
|
|
503
|
-
function matchesSensitiveKey(key, substringPatterns) {
|
|
504
|
-
const lower = key.toLowerCase();
|
|
505
|
-
const snake = snakeLower(key);
|
|
506
|
-
if (substringPatterns.some((p) => lower.includes(p) || snake.includes(p))) {
|
|
507
|
-
return true;
|
|
508
|
-
}
|
|
509
|
-
const words = snake.split(/[^a-z0-9]+/);
|
|
510
|
-
return SENSITIVE_WORD_PATTERNS.some((w) => words.includes(w));
|
|
511
|
-
}
|
|
512
|
-
function passesLuhn(digits) {
|
|
513
|
-
let sum = 0;
|
|
514
|
-
for (let i = 0; i < digits.length; i += 1) {
|
|
515
|
-
let d = Number(digits[digits.length - 1 - i]);
|
|
516
|
-
if (i % 2 === 1) {
|
|
517
|
-
d *= 2;
|
|
518
|
-
if (d > 9) d -= 9;
|
|
519
|
-
}
|
|
520
|
-
sum += d;
|
|
521
|
-
}
|
|
522
|
-
return sum % 10 === 0;
|
|
523
|
-
}
|
|
524
|
-
var SECRET_TEXT_PATTERNS = [
|
|
525
|
-
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
|
|
526
|
-
/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g,
|
|
527
|
-
/\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]+/g,
|
|
528
|
-
/\bsk-[A-Za-z0-9_-]{16,}/g,
|
|
529
|
-
/\bgh[pousr]_[A-Za-z0-9]{20,}/g,
|
|
530
|
-
/\bxox[abposr]-[A-Za-z0-9-]+/g,
|
|
531
|
-
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g
|
|
532
|
-
];
|
|
533
|
-
var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
534
|
-
function scrubSecretsInText(text, options = {}) {
|
|
535
|
-
let out = text;
|
|
536
|
-
for (const pattern of SECRET_TEXT_PATTERNS) out = out.replace(pattern, "[FILTERED]");
|
|
537
|
-
out = out.replace(/\b(Bearer|Basic)\s+[\w.~+/=-]+/gi, "$1 [FILTERED]").replace(/\b\d(?:[ -]?\d){12,18}\b/g, (match) => {
|
|
538
|
-
const digits = match.replace(/[ -]/g, "");
|
|
539
|
-
return (digits.length === 15 || digits.length === 16) && passesLuhn(digits) ? "[FILTERED]" : match;
|
|
540
|
-
});
|
|
541
|
-
return options.emails ? out.replace(EMAIL, "[FILTERED]") : out;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// src/db/shared.ts
|
|
545
|
-
var IGNORED_ATTRIBUTES = Object.freeze([
|
|
546
|
-
"id",
|
|
547
|
-
"createdAt",
|
|
548
|
-
"created_at",
|
|
549
|
-
"updatedAt",
|
|
550
|
-
"updated_at",
|
|
551
|
-
// Auth.js / NextAuth standard columns
|
|
552
|
-
"emailVerified",
|
|
553
|
-
"expires"
|
|
554
|
-
]);
|
|
555
|
-
var DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
556
|
-
"password",
|
|
557
|
-
"token",
|
|
558
|
-
"secret",
|
|
559
|
-
"api_key",
|
|
560
|
-
"credit_card",
|
|
561
|
-
"ssn",
|
|
562
|
-
"social_security",
|
|
563
|
-
"encrypted",
|
|
564
|
-
"private_key",
|
|
565
|
-
"public_key",
|
|
566
|
-
"signing_key",
|
|
567
|
-
"pem",
|
|
568
|
-
"cipher",
|
|
569
|
-
"nonce",
|
|
570
|
-
"salt",
|
|
571
|
-
"digest",
|
|
572
|
-
"signature",
|
|
573
|
-
"hmac",
|
|
574
|
-
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
575
|
-
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
576
|
-
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
577
|
-
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
578
|
-
"credential",
|
|
579
|
-
"passwd",
|
|
580
|
-
"passcode",
|
|
581
|
-
"apikey",
|
|
582
|
-
"card_number",
|
|
583
|
-
"cardnumber",
|
|
584
|
-
"cvv",
|
|
585
|
-
"cvc"
|
|
586
|
-
]);
|
|
587
|
-
function emitDbEvent(input) {
|
|
588
|
-
try {
|
|
589
|
-
const config = configuration();
|
|
590
|
-
if (!config.captureDb) return;
|
|
591
|
-
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
592
|
-
if (config.databaseReader && !input._fromTrigger) {
|
|
593
|
-
const tracked = config.triggerTrackedTables;
|
|
594
|
-
if (tracked === null || tracked.has(input.table ?? input.modelClass)) return;
|
|
595
|
-
}
|
|
596
|
-
if (input.operation === "update") {
|
|
597
|
-
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
598
|
-
if (meaningful.length === 0) return;
|
|
599
|
-
}
|
|
600
|
-
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
601
|
-
const related = resourceIdStr === null ? input.relatedResourceIds ?? [] : [];
|
|
602
|
-
const context = buildContext(
|
|
603
|
-
related.length > 0 ? { ...input, displayName: null, modelInstance: null } : input
|
|
604
|
-
);
|
|
605
|
-
const event = build({
|
|
606
|
-
source_type: "database_callback",
|
|
607
|
-
source_data: {
|
|
608
|
-
model_class: input.modelClass,
|
|
609
|
-
operation: input.operation
|
|
610
|
-
},
|
|
611
|
-
outcome: "success",
|
|
612
|
-
correlation_id: current(),
|
|
613
|
-
resource_ids: resourceIdStr === null ? [...related] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
614
|
-
context,
|
|
615
|
-
duration_ms: null,
|
|
616
|
-
timestamp: input.timestamp ?? null
|
|
617
|
-
});
|
|
618
|
-
pushEvent(event);
|
|
619
|
-
} catch (error) {
|
|
620
|
-
logger.debug(`db emit failed: ${describeError(error)}`);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
function buildContext(input) {
|
|
624
|
-
const context = {};
|
|
625
|
-
const actor = getCurrentActor();
|
|
626
|
-
if (actor) context.actor = actor;
|
|
627
|
-
if ((input.operation === "create" || input.operation === "destroy") && input.initialAttributes) {
|
|
628
|
-
const filtered = filterMeaningfulAttributes(input.initialAttributes);
|
|
629
|
-
if (filtered !== null) context.initial_attributes = filtered;
|
|
630
|
-
}
|
|
631
|
-
if (input.operation === "update" && input.changes) {
|
|
632
|
-
const filtered = filterMeaningfulChanges(input.changes);
|
|
633
|
-
if (filtered.length > 0) {
|
|
634
|
-
context.changes = filtered.map((c) => {
|
|
635
|
-
const out = {
|
|
636
|
-
attribute: c.attribute,
|
|
637
|
-
to: formatForJson(c.to)
|
|
638
|
-
};
|
|
639
|
-
if (c.from !== void 0) out.from = formatForJson(c.from);
|
|
640
|
-
return out;
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
const displayName = input.displayName ?? (input.modelInstance ? resolveDisplayName(input.modelClass, input.modelInstance) : null);
|
|
645
|
-
if (displayName !== null) context.display_name = displayName;
|
|
646
|
-
return Object.keys(context).length === 0 ? null : context;
|
|
647
|
-
}
|
|
648
|
-
function filterMeaningfulAttributes(attrs) {
|
|
649
|
-
const out = {};
|
|
650
|
-
for (const key of Object.keys(attrs)) {
|
|
651
|
-
if (!isMeaningfulAttribute(key)) continue;
|
|
652
|
-
const value = attrs[key];
|
|
653
|
-
if (value === null || value === void 0) continue;
|
|
654
|
-
if (!isScalar(value)) continue;
|
|
655
|
-
out[key] = formatForJson(value);
|
|
656
|
-
}
|
|
657
|
-
return Object.keys(out).length === 0 ? null : out;
|
|
658
|
-
}
|
|
659
|
-
function filterMeaningfulChanges(changes) {
|
|
660
|
-
return flattenNestedChanges(changes).filter((c) => {
|
|
661
|
-
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
662
|
-
if (!isScalar(c.to)) return false;
|
|
663
|
-
if (c.from === void 0) return true;
|
|
664
|
-
if (!isScalar(c.from)) return false;
|
|
665
|
-
return valuesActuallyChanged(c.from, c.to);
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
var MAX_NESTED_DEPTH = 3;
|
|
669
|
-
var MAX_NESTED_LEAVES = 20;
|
|
670
|
-
var MAX_UNKNOWN_FROM_LEAVES = 5;
|
|
671
|
-
function flattenNestedChanges(changes) {
|
|
672
|
-
if (!changes.some((c) => isPlainRecord(c.to) || isPlainRecord(c.from))) return changes;
|
|
673
|
-
const out = [];
|
|
674
|
-
for (const c of changes) {
|
|
675
|
-
if (!isPlainRecord(c.to) && !isPlainRecord(c.from)) {
|
|
676
|
-
out.push(c);
|
|
677
|
-
continue;
|
|
678
|
-
}
|
|
679
|
-
if (!isMeaningfulAttribute(c.attribute)) continue;
|
|
680
|
-
const leaves = [];
|
|
681
|
-
collectLeafChanges(c.attribute, c.from, c.to, 1, leaves);
|
|
682
|
-
const cap = c.from === void 0 ? MAX_UNKNOWN_FROM_LEAVES : MAX_NESTED_LEAVES;
|
|
683
|
-
out.push(...leaves.slice(0, cap).map(scrubLeaf));
|
|
684
|
-
}
|
|
685
|
-
return out;
|
|
686
|
-
}
|
|
687
|
-
function collectLeafChanges(path, from, to, depth, out) {
|
|
688
|
-
if (out.length > MAX_NESTED_LEAVES) return;
|
|
689
|
-
const fromObj = isPlainRecord(from);
|
|
690
|
-
const toObj = isPlainRecord(to);
|
|
691
|
-
if ((fromObj || toObj) && depth <= MAX_NESTED_DEPTH && (fromObj || from == null) && (toObj || to == null)) {
|
|
692
|
-
const f = fromObj ? from : {};
|
|
693
|
-
const t = toObj ? to : {};
|
|
694
|
-
for (const key of /* @__PURE__ */ new Set([...Object.keys(f), ...Object.keys(t)])) {
|
|
695
|
-
const before = from === void 0 ? void 0 : f[key] ?? null;
|
|
696
|
-
collectLeafChanges(`${path}.${key}`, before, t[key] ?? null, depth + 1, out);
|
|
697
|
-
}
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
if (from !== void 0 && sameJson(from, to)) return;
|
|
701
|
-
out.push(from === void 0 ? { attribute: path, to } : { attribute: path, from, to });
|
|
702
|
-
}
|
|
703
|
-
function scrubLeaf(change) {
|
|
704
|
-
const scrub = (v) => typeof v === "string" ? scrubSecretsInText(v) : v;
|
|
705
|
-
const out = { attribute: change.attribute, to: scrub(change.to) };
|
|
706
|
-
if (change.from !== void 0) out.from = scrub(change.from);
|
|
707
|
-
return out;
|
|
708
|
-
}
|
|
709
|
-
function isPlainRecord(value) {
|
|
710
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
711
|
-
const proto = Object.getPrototypeOf(value);
|
|
712
|
-
return proto === Object.prototype || proto === null;
|
|
713
|
-
}
|
|
714
|
-
function sameJson(a, b) {
|
|
715
|
-
if (a === b) return true;
|
|
716
|
-
try {
|
|
717
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
718
|
-
} catch {
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
function isMeaningfulAttribute(name) {
|
|
723
|
-
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
724
|
-
if (isDbSensitive(name)) return false;
|
|
725
|
-
return true;
|
|
726
|
-
}
|
|
727
|
-
function isDbSensitive(name) {
|
|
728
|
-
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
729
|
-
}
|
|
730
|
-
function isScalar(value) {
|
|
731
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
732
|
-
return true;
|
|
733
|
-
}
|
|
734
|
-
if (isPrismaDecimal(value)) return true;
|
|
735
|
-
if (Buffer.isBuffer?.(value)) return false;
|
|
736
|
-
if (Array.isArray(value)) return value.every((v) => isScalar(v));
|
|
737
|
-
return false;
|
|
738
|
-
}
|
|
739
|
-
function valuesActuallyChanged(from, to) {
|
|
740
|
-
if (from === null && to === null) return false;
|
|
741
|
-
if (from instanceof Date && to instanceof Date) {
|
|
742
|
-
return from.getTime() !== to.getTime();
|
|
743
|
-
}
|
|
744
|
-
return from !== to;
|
|
745
|
-
}
|
|
746
|
-
function formatForJson(value) {
|
|
747
|
-
if (value === null || value === void 0) return value;
|
|
748
|
-
if (value instanceof Date) return value.toISOString();
|
|
749
|
-
if (typeof value === "bigint") return value.toString();
|
|
750
|
-
if (isPrismaDecimal(value)) return Number(value.toString());
|
|
751
|
-
if (Array.isArray(value)) return value.map(formatForJson);
|
|
752
|
-
return value;
|
|
753
|
-
}
|
|
754
|
-
function isPrismaDecimal(value) {
|
|
755
|
-
if (value === null || typeof value !== "object") return false;
|
|
756
|
-
const obj = value;
|
|
757
|
-
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
758
|
-
}
|
|
759
|
-
var DISPLAY_NAME_COLUMNS = ["name", "title", "number", "label"];
|
|
760
|
-
var MAX_DISPLAY_NAME_LENGTH = 120;
|
|
761
|
-
function resolveDisplayName(modelClass, instance) {
|
|
762
|
-
try {
|
|
763
|
-
const config = configuration();
|
|
764
|
-
const resolver = config.displayNameFor[modelClass];
|
|
765
|
-
const resolved = applyResolver(resolver, instance);
|
|
766
|
-
if (resolved !== null) return resolved;
|
|
767
|
-
const columns = /* @__PURE__ */ new Map();
|
|
768
|
-
for (const key of Object.keys(instance)) {
|
|
769
|
-
if (isDbSensitive(key)) continue;
|
|
770
|
-
const norm = key.toLowerCase().replace(/_/g, "");
|
|
771
|
-
if (!columns.has(norm)) columns.set(norm, instance[key]);
|
|
772
|
-
}
|
|
773
|
-
const text = (norm) => {
|
|
774
|
-
const value = columns.get(norm);
|
|
775
|
-
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
776
|
-
return null;
|
|
777
|
-
}
|
|
778
|
-
const str = String(value).trim();
|
|
779
|
-
return str.length > 0 ? str.slice(0, MAX_DISPLAY_NAME_LENGTH) : null;
|
|
780
|
-
};
|
|
781
|
-
for (const column of DISPLAY_NAME_COLUMNS) {
|
|
782
|
-
const value = text(column);
|
|
783
|
-
if (value !== null) return value;
|
|
784
|
-
}
|
|
785
|
-
return text(`${singularNorm(modelClass)}number`);
|
|
786
|
-
} catch {
|
|
787
|
-
}
|
|
788
|
-
return null;
|
|
789
|
-
}
|
|
790
|
-
function singularNorm(modelClass) {
|
|
791
|
-
const norm = modelClass.toLowerCase().replace(/_/g, "");
|
|
792
|
-
if (norm.endsWith("ies")) return norm.slice(0, -3) + "y";
|
|
793
|
-
if (/(ss|us|is)$/.test(norm)) return norm;
|
|
794
|
-
if (/(xes|ches|shes|sses)$/.test(norm)) return norm.slice(0, -2);
|
|
795
|
-
return norm.endsWith("s") ? norm.slice(0, -1) : norm;
|
|
796
|
-
}
|
|
797
|
-
function applyResolver(resolver, instance) {
|
|
798
|
-
if (typeof resolver === "string") {
|
|
799
|
-
const value = instance[resolver];
|
|
800
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
801
|
-
return String(value);
|
|
802
|
-
}
|
|
803
|
-
return null;
|
|
804
|
-
}
|
|
805
|
-
if (typeof resolver === "function") {
|
|
806
|
-
try {
|
|
807
|
-
const value = resolver(instance);
|
|
808
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
809
|
-
if (value !== null && value !== void 0 && String(value).length > 0) {
|
|
810
|
-
return String(value);
|
|
811
|
-
}
|
|
812
|
-
} catch {
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
return null;
|
|
816
|
-
}
|
|
817
|
-
function describeError(error) {
|
|
818
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
819
|
-
return String(error);
|
|
820
|
-
}
|
|
3
|
+
var chunkWASXTDLW_cjs = require('../chunk-WASXTDLW.cjs');
|
|
4
|
+
var chunkV5YNKKTG_cjs = require('../chunk-V5YNKKTG.cjs');
|
|
5
|
+
require('../chunk-ZDSQYCYV.cjs');
|
|
821
6
|
|
|
822
7
|
// src/db/supabase.ts
|
|
823
8
|
function triggerPathWillCapture(table) {
|
|
824
|
-
const config = configuration();
|
|
9
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
825
10
|
if (!config.databaseReader) return false;
|
|
826
11
|
const tracked = config.triggerTrackedTables;
|
|
827
12
|
if (tracked === null) return false;
|
|
@@ -856,9 +41,9 @@ function wrapSupabase(client) {
|
|
|
856
41
|
if (!result || result.error) return null;
|
|
857
42
|
if (Array.isArray(result.data)) {
|
|
858
43
|
const first = result.data[0];
|
|
859
|
-
return
|
|
44
|
+
return isPlainObject(first) ? first : null;
|
|
860
45
|
}
|
|
861
|
-
return
|
|
46
|
+
return isPlainObject(result.data) ? result.data : null;
|
|
862
47
|
} catch {
|
|
863
48
|
return null;
|
|
864
49
|
}
|
|
@@ -996,7 +181,7 @@ function trackFilterChain(builder) {
|
|
|
996
181
|
if (typeof orig !== "function") return orig;
|
|
997
182
|
return function patchedMatch(query) {
|
|
998
183
|
try {
|
|
999
|
-
if (
|
|
184
|
+
if (isPlainObject(query)) {
|
|
1000
185
|
for (const [k, v] of Object.entries(query)) {
|
|
1001
186
|
captured.equals[k] = v;
|
|
1002
187
|
}
|
|
@@ -1024,7 +209,7 @@ function instrumentFilterBuilder(builder, onResolved, beforeFire) {
|
|
|
1024
209
|
try {
|
|
1025
210
|
if (!result?.error) onResolved(result);
|
|
1026
211
|
} catch (error) {
|
|
1027
|
-
logger.debug(`supabase capture failed: ${
|
|
212
|
+
chunkV5YNKKTG_cjs.logger.debug(`supabase capture failed: ${describeError(error)}`);
|
|
1028
213
|
}
|
|
1029
214
|
try {
|
|
1030
215
|
const passthrough = onfulfilled ? onfulfilled(raw) : raw;
|
|
@@ -1057,13 +242,13 @@ function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
|
1057
242
|
if (Array.isArray(values)) {
|
|
1058
243
|
const resultRows = pickResultRows(result);
|
|
1059
244
|
values.forEach((row, index) => {
|
|
1060
|
-
if (!
|
|
245
|
+
if (!isPlainObject(row)) return;
|
|
1061
246
|
emitOneRow(ctx, row, resultRows[index] ?? null, filters, null);
|
|
1062
247
|
});
|
|
1063
248
|
return;
|
|
1064
249
|
}
|
|
1065
|
-
if (!
|
|
1066
|
-
emitDbEvent({
|
|
250
|
+
if (!isPlainObject(values)) {
|
|
251
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
1067
252
|
modelClass: ctx.table,
|
|
1068
253
|
operation: ctx.operation,
|
|
1069
254
|
resourceId: idFromFilters(filters)
|
|
@@ -1077,9 +262,9 @@ function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
|
1077
262
|
function emitOneRow(ctx, values, resultRow, filters, beforeRow) {
|
|
1078
263
|
const resourceId = resultRow?.id ?? values.id ?? idFromFilters(filters) ?? null;
|
|
1079
264
|
const merged = beforeRow ?? resultRow ?? values;
|
|
1080
|
-
const displayName = resolveDisplayName(ctx.table, merged);
|
|
265
|
+
const displayName = chunkWASXTDLW_cjs.resolveDisplayName(ctx.table, merged);
|
|
1081
266
|
if (ctx.operation === "create") {
|
|
1082
|
-
emitDbEvent({
|
|
267
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
1083
268
|
modelClass: ctx.table,
|
|
1084
269
|
operation: "create",
|
|
1085
270
|
resourceId,
|
|
@@ -1091,7 +276,7 @@ function emitOneRow(ctx, values, resultRow, filters, beforeRow) {
|
|
|
1091
276
|
}
|
|
1092
277
|
if (ctx.operation === "update") {
|
|
1093
278
|
const changes = buildUpdateChanges(values, beforeRow);
|
|
1094
|
-
emitDbEvent({
|
|
279
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
1095
280
|
modelClass: ctx.table,
|
|
1096
281
|
operation: "update",
|
|
1097
282
|
resourceId,
|
|
@@ -1105,8 +290,8 @@ function emitFromDelete(table, result, filters, beforeRow) {
|
|
|
1105
290
|
const resultRow = pickFirstResultRow(result);
|
|
1106
291
|
const resourceId = resultRow?.id ?? beforeRow?.id ?? idFromFilters(filters) ?? null;
|
|
1107
292
|
const richestRow = resultRow ?? beforeRow;
|
|
1108
|
-
const displayName = richestRow ? resolveDisplayName(table, richestRow) : null;
|
|
1109
|
-
emitDbEvent({
|
|
293
|
+
const displayName = richestRow ? chunkWASXTDLW_cjs.resolveDisplayName(table, richestRow) : null;
|
|
294
|
+
chunkWASXTDLW_cjs.emitDbEvent({
|
|
1110
295
|
modelClass: table,
|
|
1111
296
|
operation: "destroy",
|
|
1112
297
|
resourceId,
|
|
@@ -1148,24 +333,24 @@ function pickFirstResultRow(result) {
|
|
|
1148
333
|
if (!result || result.error) return null;
|
|
1149
334
|
if (Array.isArray(result.data)) {
|
|
1150
335
|
const first = result.data[0];
|
|
1151
|
-
return
|
|
336
|
+
return isPlainObject(first) ? first : null;
|
|
1152
337
|
}
|
|
1153
|
-
if (
|
|
338
|
+
if (isPlainObject(result.data)) return result.data;
|
|
1154
339
|
return null;
|
|
1155
340
|
}
|
|
1156
341
|
function pickResultRows(result) {
|
|
1157
342
|
if (!result || result.error || !Array.isArray(result.data)) return [];
|
|
1158
343
|
return result.data.map(
|
|
1159
|
-
(row) =>
|
|
344
|
+
(row) => isPlainObject(row) ? row : void 0
|
|
1160
345
|
);
|
|
1161
346
|
}
|
|
1162
|
-
function
|
|
347
|
+
function isPlainObject(value) {
|
|
1163
348
|
if (value === null || typeof value !== "object") return false;
|
|
1164
349
|
if (Array.isArray(value)) return false;
|
|
1165
350
|
if (value instanceof Date) return false;
|
|
1166
351
|
return true;
|
|
1167
352
|
}
|
|
1168
|
-
function
|
|
353
|
+
function describeError(error) {
|
|
1169
354
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1170
355
|
return String(error);
|
|
1171
356
|
}
|