ezlogs-nextjs 0.4.4 → 0.4.6
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 +51 -11
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/{chunk-Z2TM3LGG.js → chunk-2NFJOT6Q.js} +1 -1
- package/dist/{chunk-R6IWVTX3.cjs → chunk-65HRY3PW.cjs} +31 -21
- package/dist/{chunk-YXZZNZG6.cjs → chunk-B3WST6ES.cjs} +9 -9
- package/dist/{chunk-MMLQXSSD.cjs → chunk-B5ZUQULZ.cjs} +18 -11
- package/dist/{chunk-NX4EL7BY.cjs → chunk-DM2EAOSF.cjs} +4 -4
- package/dist/chunk-DRE2VXFX.js +19 -0
- package/dist/chunk-H3FC5HMW.cjs +16 -0
- package/dist/{chunk-GI6BM4MR.js → chunk-IBSNHBUC.js} +18 -12
- package/dist/chunk-JWJKFZBW.js +52 -0
- package/dist/{chunk-MHBS5FEP.js → chunk-M3VBQ5KT.js} +27 -4
- package/dist/chunk-NFZ5OKF3.cjs +22 -0
- package/dist/{chunk-GMHOUAKD.cjs → chunk-O7SFYXJC.cjs} +37 -13
- package/dist/{chunk-U22T7QYY.js → chunk-PK2Z2ABL.js} +13 -3
- package/dist/{chunk-YMIGZYFH.js → chunk-RD47JECJ.js} +1 -1
- package/dist/chunk-RMKGMIV2.js +13 -0
- package/dist/{chunk-NINIAL7M.js → chunk-U3IJV5EJ.js} +1 -1
- package/dist/chunk-VJR4VB4B.cjs +56 -0
- package/dist/{chunk-PS4U2GFJ.cjs → chunk-YO6E763S.cjs} +5 -5
- package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
- package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
- package/dist/db/drizzle.cjs +3 -3
- package/dist/db/drizzle.js +2 -2
- package/dist/db/postgres-js.cjs +4 -4
- package/dist/db/postgres-js.js +2 -2
- package/dist/db/prisma.cjs +12 -12
- package/dist/db/prisma.js +2 -2
- package/dist/db/supabase.cjs +42 -17
- package/dist/db/supabase.d.cts +11 -5
- package/dist/db/supabase.d.ts +11 -5
- package/dist/db/supabase.js +33 -9
- package/dist/index.cjs +288 -142
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +198 -52
- package/dist/jobs/bullmq.cjs +44 -16
- package/dist/jobs/bullmq.d.cts +7 -1
- package/dist/jobs/bullmq.d.ts +7 -1
- package/dist/jobs/bullmq.js +33 -6
- package/dist/jobs/inngest.cjs +36 -17
- package/dist/jobs/inngest.d.cts +7 -1
- package/dist/jobs/inngest.d.ts +7 -1
- package/dist/jobs/inngest.js +23 -5
- package/dist/jobs/supabase-queues.cjs +9 -9
- package/dist/jobs/supabase-queues.js +4 -4
- package/dist/jobs/trigger.cjs +7 -7
- package/dist/jobs/trigger.js +4 -4
- package/dist/jobs/upstash-workflow.cjs +139 -23
- package/dist/jobs/upstash-workflow.d.cts +20 -2
- package/dist/jobs/upstash-workflow.d.ts +20 -2
- package/dist/jobs/upstash-workflow.js +129 -14
- package/dist/nextjs-plugin/index.cjs +46 -29
- package/dist/nextjs-plugin/index.js +46 -29
- package/dist/nextjs-plugin/loader.cjs +70 -60
- package/dist/nextjs-plugin/loader.d.cts +18 -1
- package/dist/nextjs-plugin/loader.d.ts +18 -1
- package/dist/nextjs-plugin/loader.js +70 -61
- package/dist/triggers/index.cjs +22 -16
- package/dist/triggers/index.d.cts +0 -10
- package/dist/triggers/index.d.ts +0 -10
- package/dist/triggers/index.js +11 -5
- package/package.json +1 -1
- package/sql/postgres/00_install.sql +20 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkB3WST6ES_cjs = require('./chunk-B3WST6ES.cjs');
|
|
4
|
+
var chunkB5ZUQULZ_cjs = require('./chunk-B5ZUQULZ.cjs');
|
|
5
5
|
var chunkTWTG5ILJ_cjs = require('./chunk-TWTG5ILJ.cjs');
|
|
6
6
|
|
|
7
7
|
// src/triggers/emit-dedup.ts
|
|
8
|
-
var storage =
|
|
8
|
+
var storage = chunkB5ZUQULZ_cjs.createScopedStorage(
|
|
9
9
|
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:audit-emitted-ids-storage")
|
|
10
10
|
);
|
|
11
11
|
function currentEmittedAuditIds() {
|
|
@@ -103,7 +103,7 @@ async function sweepAuditLog(exec) {
|
|
|
103
103
|
await loadTableMeta(exec, rows);
|
|
104
104
|
for (const row of rows) {
|
|
105
105
|
const correlationId = row.correlation_id ?? correlationForTx(row.txid);
|
|
106
|
-
|
|
106
|
+
chunkB5ZUQULZ_cjs.runWithCorrelation(correlationId, () => emitWithRowActor(row));
|
|
107
107
|
}
|
|
108
108
|
return rows.length;
|
|
109
109
|
} catch (err) {
|
|
@@ -216,13 +216,36 @@ function emitAuditRows(rows) {
|
|
|
216
216
|
}
|
|
217
217
|
function emitWithRowActor(row) {
|
|
218
218
|
const stored = row.actor_id || null;
|
|
219
|
-
const claimer =
|
|
219
|
+
const claimer = chunkB5ZUQULZ_cjs.getCurrentActor();
|
|
220
220
|
const actor = stored ? claimer?.id === stored ? claimer : { id: stored } : null;
|
|
221
|
-
|
|
221
|
+
chunkB5ZUQULZ_cjs.runWithActorScope(() => emitOne(row), actor);
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
var inFlightFlushes = /* @__PURE__ */ new Set();
|
|
224
|
+
var IN_FLIGHT_MAX_MS = 5e3;
|
|
225
|
+
function settleAuditFlushes(maxMs = IN_FLIGHT_MAX_MS) {
|
|
226
|
+
if (inFlightFlushes.size === 0) return Promise.resolve();
|
|
227
|
+
let timer;
|
|
228
|
+
return Promise.race([
|
|
229
|
+
Promise.allSettled([...inFlightFlushes]).then(() => void 0),
|
|
230
|
+
new Promise((resolve) => {
|
|
231
|
+
timer = setTimeout(resolve, maxMs);
|
|
232
|
+
timer.unref?.();
|
|
233
|
+
})
|
|
234
|
+
]).finally(() => clearTimeout(timer));
|
|
235
|
+
}
|
|
236
|
+
function flushAuditLog(exec, options = {}) {
|
|
237
|
+
const work = readAndEmit(exec, options);
|
|
238
|
+
inFlightFlushes.add(work);
|
|
239
|
+
const done = () => inFlightFlushes.delete(work);
|
|
240
|
+
work.then(done, done);
|
|
241
|
+
const forget = setTimeout(done, IN_FLIGHT_MAX_MS);
|
|
242
|
+
forget.unref?.();
|
|
243
|
+
work.then(() => clearTimeout(forget), () => clearTimeout(forget));
|
|
244
|
+
return work;
|
|
245
|
+
}
|
|
246
|
+
async function readAndEmit(exec, options) {
|
|
224
247
|
if (!exec) return;
|
|
225
|
-
const correlationId =
|
|
248
|
+
const correlationId = chunkB5ZUQULZ_cjs.current();
|
|
226
249
|
if (!correlationId) return;
|
|
227
250
|
lastRequestFlushAt = Date.now();
|
|
228
251
|
const rows = await readAuditRows(exec, correlationId, options.since ?? null);
|
|
@@ -365,11 +388,11 @@ function emitFresh(rows) {
|
|
|
365
388
|
emitAuditRows(fresh);
|
|
366
389
|
}
|
|
367
390
|
function correlationForTx(txid) {
|
|
368
|
-
if (!txid) return
|
|
391
|
+
if (!txid) return chunkB5ZUQULZ_cjs.generate();
|
|
369
392
|
let id = txCorrelation.get(txid);
|
|
370
393
|
if (!id) {
|
|
371
394
|
if (txCorrelation.size >= 1e3) txCorrelation.clear();
|
|
372
|
-
id =
|
|
395
|
+
id = chunkB5ZUQULZ_cjs.generate();
|
|
373
396
|
txCorrelation.set(txid, id);
|
|
374
397
|
}
|
|
375
398
|
return id;
|
|
@@ -390,7 +413,7 @@ function emitOne(row) {
|
|
|
390
413
|
const newRow = withUtcTimestamps(coerceJsonb(row.new_row), naive);
|
|
391
414
|
const related = row.resource_id === null ? relatedResourceIds(row.table_name, newRow ?? oldRow ?? {}) : null;
|
|
392
415
|
if (op === "create" && newRow) {
|
|
393
|
-
|
|
416
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
394
417
|
modelClass: row.table_name,
|
|
395
418
|
operation: "create",
|
|
396
419
|
resourceId: row.resource_id,
|
|
@@ -408,7 +431,7 @@ function emitOne(row) {
|
|
|
408
431
|
if (changes.length === 0) {
|
|
409
432
|
return;
|
|
410
433
|
}
|
|
411
|
-
|
|
434
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
412
435
|
modelClass: row.table_name,
|
|
413
436
|
operation: "update",
|
|
414
437
|
resourceId: row.resource_id,
|
|
@@ -424,7 +447,7 @@ function emitOne(row) {
|
|
|
424
447
|
return;
|
|
425
448
|
}
|
|
426
449
|
if (op === "destroy" && oldRow) {
|
|
427
|
-
|
|
450
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
428
451
|
modelClass: row.table_name,
|
|
429
452
|
operation: "destroy",
|
|
430
453
|
resourceId: row.resource_id,
|
|
@@ -534,4 +557,5 @@ exports.maintainAuditLogAfterRequests = maintainAuditLogAfterRequests;
|
|
|
534
557
|
exports.pruneAuditLog = pruneAuditLog;
|
|
535
558
|
exports.readAuditRows = readAuditRows;
|
|
536
559
|
exports.runWithEmittedAuditIdsScope = runWithEmittedAuditIdsScope;
|
|
560
|
+
exports.settleAuditFlushes = settleAuditFlushes;
|
|
537
561
|
exports.sweepAuditLog = sweepAuditLog;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { flushAuditLog } from './chunk-
|
|
2
|
-
import { build, pushEvent, sanitizeArgs } from './chunk-
|
|
3
|
-
import { configuration, current, generate, runWithCorrelation, runWithActorScope, getCurrentActor, maybeExtractSupabaseActor, endCorrelationScope } from './chunk-
|
|
1
|
+
import { flushAuditLog } from './chunk-M3VBQ5KT.js';
|
|
2
|
+
import { build, pushEvent, sanitizeArgs } from './chunk-U3IJV5EJ.js';
|
|
3
|
+
import { configuration, current, generate, runWithCorrelation, runWithActorScope, getCurrentActor, maybeExtractSupabaseActor, endCorrelationScope } from './chunk-IBSNHBUC.js';
|
|
4
4
|
import { logger } from './chunk-FCFVIRQF.js';
|
|
5
5
|
|
|
6
6
|
// src/jobs/shared.ts
|
|
@@ -18,6 +18,7 @@ function emitJobEvent(input) {
|
|
|
18
18
|
job_id: input.jobId ?? null,
|
|
19
19
|
queue: input.queue ?? null,
|
|
20
20
|
retry_count: input.retryCount ?? null,
|
|
21
|
+
step: input.step ?? null,
|
|
21
22
|
arguments: jobArguments(input.payload)
|
|
22
23
|
});
|
|
23
24
|
const event = build({
|
|
@@ -41,10 +42,15 @@ async function runJobWithCapture(meta, work) {
|
|
|
41
42
|
const body = async () => {
|
|
42
43
|
const startedAt = /* @__PURE__ */ new Date();
|
|
43
44
|
const startMs = startedAt.getTime();
|
|
45
|
+
const step = meta.step;
|
|
44
46
|
const baseMeta = {
|
|
45
47
|
jobClass: meta.jobClass,
|
|
46
48
|
jobId: meta.jobId ?? null,
|
|
47
49
|
queue: meta.queue ?? null,
|
|
50
|
+
// Read when the event is built (after the run): the step it executed.
|
|
51
|
+
get step() {
|
|
52
|
+
return (typeof step === "function" ? step() : step) ?? null;
|
|
53
|
+
},
|
|
48
54
|
retryCount: meta.retryCount ?? null,
|
|
49
55
|
correlationId,
|
|
50
56
|
startedAt,
|
|
@@ -63,6 +69,10 @@ async function runJobWithCapture(meta, work) {
|
|
|
63
69
|
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
64
70
|
await flushJobAuditLog(startedAt);
|
|
65
71
|
if (meta.isControlFlow?.(error)) throw error;
|
|
72
|
+
if (meta.isSuccessfulExit?.(error)) {
|
|
73
|
+
emitJobEvent({ ...baseMeta, outcome: "success", durationMs: Date.now() - startMs });
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
66
76
|
emitJobEvent({
|
|
67
77
|
...baseMeta,
|
|
68
78
|
outcome: "failure",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createScopedStorage } from './chunk-IBSNHBUC.js';
|
|
2
|
+
|
|
3
|
+
// src/job-delivery.ts
|
|
4
|
+
var storage = createScopedStorage(/* @__PURE__ */ Symbol.for("ezlogs-nextjs:job-delivery"));
|
|
5
|
+
function runWithDeliverySlot(slot, callback) {
|
|
6
|
+
return storage.run(slot, callback);
|
|
7
|
+
}
|
|
8
|
+
function markJobDelivery() {
|
|
9
|
+
const slot = storage.read();
|
|
10
|
+
if (slot) slot.jobDelivery = true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { markJobDelivery, runWithDeliverySlot };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { configuration, DEFAULT_EXCLUDED_TABLES, current, getCurrentActor, AUTH_SESSION_TABLE_NAMES, isSessionStoreColumn } from './chunk-
|
|
1
|
+
import { configuration, DEFAULT_EXCLUDED_TABLES, current, getCurrentActor, AUTH_SESSION_TABLE_NAMES, isSessionStoreColumn } from './chunk-IBSNHBUC.js';
|
|
2
2
|
import { logger } from './chunk-FCFVIRQF.js';
|
|
3
3
|
import { __export } from './chunk-SIAA4J6H.js';
|
|
4
4
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkTWTG5ILJ_cjs = require('./chunk-TWTG5ILJ.cjs');
|
|
4
|
+
|
|
5
|
+
// src/instrument.ts
|
|
6
|
+
function instrumentFrom(replacements) {
|
|
7
|
+
return (key, original) => {
|
|
8
|
+
const replace = Object.prototype.hasOwnProperty.call(replacements, key) ? replacements[key] : void 0;
|
|
9
|
+
if (!replace) return original;
|
|
10
|
+
try {
|
|
11
|
+
return replace(original) ?? original;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
chunkTWTG5ILJ_cjs.logger.debug(`instrument ${key} failed (${error instanceof Error ? error.message : String(error)}); using the original`);
|
|
14
|
+
return original;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function instrumentClass(original, wrapInstance, mapArgs) {
|
|
19
|
+
if (typeof original !== "function") return original;
|
|
20
|
+
return new Proxy(original, {
|
|
21
|
+
construct(target, args, newTarget) {
|
|
22
|
+
let callArgs = args;
|
|
23
|
+
if (mapArgs) {
|
|
24
|
+
try {
|
|
25
|
+
callArgs = mapArgs(args);
|
|
26
|
+
} catch {
|
|
27
|
+
callArgs = args;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const instance = Reflect.construct(target, callArgs, newTarget);
|
|
31
|
+
try {
|
|
32
|
+
return wrapInstance(instance) ?? instance;
|
|
33
|
+
} catch {
|
|
34
|
+
return instance;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function instrumentFactory(original, wrapResult) {
|
|
40
|
+
if (typeof original !== "function") return original;
|
|
41
|
+
const factory = original;
|
|
42
|
+
return new Proxy(factory, {
|
|
43
|
+
apply(target, thisArg, args) {
|
|
44
|
+
const value = Reflect.apply(target, thisArg, args);
|
|
45
|
+
try {
|
|
46
|
+
return wrapResult(value) ?? value;
|
|
47
|
+
} catch {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.instrumentClass = instrumentClass;
|
|
55
|
+
exports.instrumentFactory = instrumentFactory;
|
|
56
|
+
exports.instrumentFrom = instrumentFrom;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkB5ZUQULZ_cjs = require('./chunk-B5ZUQULZ.cjs');
|
|
4
4
|
var chunkTWTG5ILJ_cjs = require('./chunk-TWTG5ILJ.cjs');
|
|
5
5
|
|
|
6
6
|
// src/triggers/context.ts
|
|
7
7
|
function getDatabaseContext() {
|
|
8
|
-
const actor =
|
|
8
|
+
const actor = chunkB5ZUQULZ_cjs.getCurrentActor();
|
|
9
9
|
return {
|
|
10
10
|
actorId: actor && actor.id ? actor.id : null,
|
|
11
|
-
correlationId:
|
|
11
|
+
correlationId: chunkB5ZUQULZ_cjs.current()
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
async function applyDatabaseContext(exec) {
|
|
15
|
-
const actor =
|
|
16
|
-
const correlationId =
|
|
15
|
+
const actor = chunkB5ZUQULZ_cjs.getCurrentActor();
|
|
16
|
+
const correlationId = chunkB5ZUQULZ_cjs.current();
|
|
17
17
|
if (!actor && !correlationId) return;
|
|
18
18
|
try {
|
|
19
19
|
if (actor && actor.id) {
|
|
@@ -83,7 +83,7 @@ type DisplayNameMap = Record<string, DisplayNameResolver>;
|
|
|
83
83
|
/**
|
|
84
84
|
* Classifier for Server Action failure return values.
|
|
85
85
|
*
|
|
86
|
-
* Many Next.js codebases (
|
|
86
|
+
* Many Next.js codebases (in-house action wrappers, next-safe-action templates, the
|
|
87
87
|
* Vercel App Router examples, tRPC) catch errors inside the action and
|
|
88
88
|
* return `{ success: false, error: "..." }` instead of throwing. The
|
|
89
89
|
* HTTP response is 200, so the agent can't tell the action failed
|
|
@@ -218,4 +218,4 @@ interface InitOptions {
|
|
|
218
218
|
*/
|
|
219
219
|
type DatabaseReader = (sql: string, params: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
220
220
|
|
|
221
|
-
export type {
|
|
221
|
+
export type { ActorFromRequest as A, DisplayNameMap as D, InitOptions as I, ActorContext as a, ActorPrincipal as b };
|
|
@@ -83,7 +83,7 @@ type DisplayNameMap = Record<string, DisplayNameResolver>;
|
|
|
83
83
|
/**
|
|
84
84
|
* Classifier for Server Action failure return values.
|
|
85
85
|
*
|
|
86
|
-
* Many Next.js codebases (
|
|
86
|
+
* Many Next.js codebases (in-house action wrappers, next-safe-action templates, the
|
|
87
87
|
* Vercel App Router examples, tRPC) catch errors inside the action and
|
|
88
88
|
* return `{ success: false, error: "..." }` instead of throwing. The
|
|
89
89
|
* HTTP response is 200, so the agent can't tell the action failed
|
|
@@ -218,4 +218,4 @@ interface InitOptions {
|
|
|
218
218
|
*/
|
|
219
219
|
type DatabaseReader = (sql: string, params: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
220
220
|
|
|
221
|
-
export type {
|
|
221
|
+
export type { ActorFromRequest as A, DisplayNameMap as D, InitOptions as I, ActorContext as a, ActorPrincipal as b };
|
package/dist/db/drizzle.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var chunkB3WST6ES_cjs = require('../chunk-B3WST6ES.cjs');
|
|
4
|
+
require('../chunk-B5ZUQULZ.cjs');
|
|
5
5
|
var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
|
|
6
6
|
require('../chunk-ZDSQYCYV.cjs');
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ function ezlogsDrizzleLogger(options = {}) {
|
|
|
14
14
|
if (parsed) {
|
|
15
15
|
const resourceId = parsed.operation === "create" ? null : extractResourceIdFromSimpleWhere(query, params);
|
|
16
16
|
const changes = parsed.operation === "update" ? extractSetChangesFromUpdate(query, params) : null;
|
|
17
|
-
|
|
17
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
18
18
|
modelClass: parsed.table,
|
|
19
19
|
operation: parsed.operation,
|
|
20
20
|
resourceId,
|
package/dist/db/drizzle.js
CHANGED
package/dist/db/postgres-js.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkYO6E763S_cjs = require('../chunk-YO6E763S.cjs');
|
|
4
|
+
var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
|
|
5
5
|
require('../chunk-TWTG5ILJ.cjs');
|
|
6
6
|
require('../chunk-ZDSQYCYV.cjs');
|
|
7
7
|
|
|
@@ -22,8 +22,8 @@ function wrapPostgresJs(sql) {
|
|
|
22
22
|
return proxy;
|
|
23
23
|
}
|
|
24
24
|
function tagContext() {
|
|
25
|
-
if (
|
|
26
|
-
const ctx =
|
|
25
|
+
if (chunkB5ZUQULZ_cjs.configuration().databaseReader == null) return null;
|
|
26
|
+
const ctx = chunkYO6E763S_cjs.getDatabaseContext();
|
|
27
27
|
return ctx.correlationId ? ctx : null;
|
|
28
28
|
}
|
|
29
29
|
function setContext(tx, ctx) {
|
package/dist/db/postgres-js.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getDatabaseContext } from '../chunk-
|
|
2
|
-
import { configuration } from '../chunk-
|
|
1
|
+
import { getDatabaseContext } from '../chunk-RD47JECJ.js';
|
|
2
|
+
import { configuration } from '../chunk-IBSNHBUC.js';
|
|
3
3
|
import '../chunk-FCFVIRQF.js';
|
|
4
4
|
import '../chunk-SIAA4J6H.js';
|
|
5
5
|
|
package/dist/db/prisma.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkB3WST6ES_cjs = require('../chunk-B3WST6ES.cjs');
|
|
4
|
+
var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
|
|
5
5
|
var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
|
|
6
6
|
require('../chunk-ZDSQYCYV.cjs');
|
|
7
7
|
|
|
@@ -62,7 +62,7 @@ async function runTagged(client, ctx) {
|
|
|
62
62
|
if (!shouldTag(client, ctx)) return ctx.query(ctx.args);
|
|
63
63
|
try {
|
|
64
64
|
const results = await client.$transaction([
|
|
65
|
-
client.$executeRawUnsafe(SET_CONTEXT_SQL,
|
|
65
|
+
client.$executeRawUnsafe(SET_CONTEXT_SQL, chunkB5ZUQULZ_cjs.current(), chunkB5ZUQULZ_cjs.getCurrentActor()?.id ?? ""),
|
|
66
66
|
ctx.query(ctx.args)
|
|
67
67
|
]);
|
|
68
68
|
return results[1];
|
|
@@ -81,12 +81,12 @@ function _resetPrismaTaggingForTests() {
|
|
|
81
81
|
}
|
|
82
82
|
function shouldTag(client, ctx) {
|
|
83
83
|
if (!client || taggingDisabled.has(client)) return false;
|
|
84
|
-
if (
|
|
84
|
+
if (chunkB5ZUQULZ_cjs.configuration().databaseReader == null) return false;
|
|
85
85
|
if (!isPostgresClient(client)) return false;
|
|
86
86
|
if (typeof client.$transaction !== "function" || typeof client.$executeRawUnsafe !== "function") {
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
89
|
-
if (!
|
|
89
|
+
if (!chunkB5ZUQULZ_cjs.current()) return false;
|
|
90
90
|
const params = ctx.__internalParams;
|
|
91
91
|
return params != null && !params.transaction;
|
|
92
92
|
}
|
|
@@ -112,7 +112,7 @@ function recordPrismaOperation(ctx, result, table) {
|
|
|
112
112
|
const dbOperation = OPERATION_TO_DB_OPERATION[ctx.operation];
|
|
113
113
|
if (!dbOperation) return;
|
|
114
114
|
if (isBatchResult(result)) {
|
|
115
|
-
|
|
115
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
116
116
|
modelClass: ctx.model,
|
|
117
117
|
table,
|
|
118
118
|
operation: dbOperation,
|
|
@@ -139,7 +139,7 @@ function recordPrismaOperation(ctx, result, table) {
|
|
|
139
139
|
}
|
|
140
140
|
function emitSingleRowEvent(ctx, dbOperation, row, table) {
|
|
141
141
|
if (!isPlainObject(row)) {
|
|
142
|
-
|
|
142
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
143
143
|
modelClass: ctx.model,
|
|
144
144
|
table,
|
|
145
145
|
operation: dbOperation,
|
|
@@ -149,9 +149,9 @@ function emitSingleRowEvent(ctx, dbOperation, row, table) {
|
|
|
149
149
|
}
|
|
150
150
|
const rowObj = row;
|
|
151
151
|
const resourceId = rowObj.id ?? null;
|
|
152
|
-
const displayName =
|
|
152
|
+
const displayName = chunkB3WST6ES_cjs.resolveDisplayName(ctx.model, rowObj);
|
|
153
153
|
if (dbOperation === "create") {
|
|
154
|
-
|
|
154
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
155
155
|
modelClass: ctx.model,
|
|
156
156
|
table,
|
|
157
157
|
operation: "create",
|
|
@@ -166,7 +166,7 @@ function emitSingleRowEvent(ctx, dbOperation, row, table) {
|
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
if (dbOperation === "update") {
|
|
169
|
-
|
|
169
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
170
170
|
modelClass: ctx.model,
|
|
171
171
|
table,
|
|
172
172
|
operation: "update",
|
|
@@ -177,7 +177,7 @@ function emitSingleRowEvent(ctx, dbOperation, row, table) {
|
|
|
177
177
|
});
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
|
-
|
|
180
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
181
181
|
modelClass: ctx.model,
|
|
182
182
|
table,
|
|
183
183
|
operation: "destroy",
|
|
@@ -268,7 +268,7 @@ function patchPrismaClient(prisma, adapter) {
|
|
|
268
268
|
if (prisma[EZLOGS_PRISMA_BRAND] === true) {
|
|
269
269
|
return prisma;
|
|
270
270
|
}
|
|
271
|
-
const captureAndRun =
|
|
271
|
+
const captureAndRun = chunkB5ZUQULZ_cjs.makeAsyncContextCapture();
|
|
272
272
|
if (!captureAndRun) {
|
|
273
273
|
chunkTWTG5ILJ_cjs.logger.debug(
|
|
274
274
|
"patchPrismaClient: AsyncLocalStorage.snapshot() unavailable; skipping ALS bind, applying ezlogsPrisma() only."
|
package/dist/db/prisma.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { emitDbEvent, resolveDisplayName } from '../chunk-
|
|
2
|
-
import { current, getCurrentActor, configuration, makeAsyncContextCapture } from '../chunk-
|
|
1
|
+
import { emitDbEvent, resolveDisplayName } from '../chunk-U3IJV5EJ.js';
|
|
2
|
+
import { current, getCurrentActor, configuration, makeAsyncContextCapture } from '../chunk-IBSNHBUC.js';
|
|
3
3
|
import { logger } from '../chunk-FCFVIRQF.js';
|
|
4
4
|
import '../chunk-SIAA4J6H.js';
|
|
5
5
|
|
package/dist/db/supabase.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkVJR4VB4B_cjs = require('../chunk-VJR4VB4B.cjs');
|
|
4
|
+
var chunkB3WST6ES_cjs = require('../chunk-B3WST6ES.cjs');
|
|
5
|
+
var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
|
|
5
6
|
var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
|
|
6
7
|
require('../chunk-ZDSQYCYV.cjs');
|
|
7
8
|
|
|
8
9
|
// src/db/supabase.ts
|
|
9
10
|
function triggerPathWillCapture(table) {
|
|
10
|
-
const config =
|
|
11
|
+
const config = chunkB5ZUQULZ_cjs.configuration();
|
|
11
12
|
if (!config.databaseReader) return false;
|
|
12
13
|
const tracked = config.triggerTrackedTables;
|
|
13
14
|
if (tracked === null) return false;
|
|
@@ -64,9 +65,10 @@ function wrapSupabase(client) {
|
|
|
64
65
|
var GLOBAL_CLIENT_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:supabase-current-client");
|
|
65
66
|
function registerActorSource(client) {
|
|
66
67
|
try {
|
|
67
|
-
const slot =
|
|
68
|
+
const slot = chunkB5ZUQULZ_cjs.currentActorSource();
|
|
68
69
|
if (slot) {
|
|
69
|
-
slot.
|
|
70
|
+
slot.clients ??= [];
|
|
71
|
+
if (!slot.clients.includes(client)) slot.clients.push(client);
|
|
70
72
|
slot.tried = false;
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
@@ -76,19 +78,37 @@ function registerActorSource(client) {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
async function tryExtractSupabaseActor() {
|
|
79
|
-
const slot =
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const slot = chunkB5ZUQULZ_cjs.currentActorSource();
|
|
82
|
+
const clients = slot ? slot.clients ?? [] : [globalThis[GLOBAL_CLIENT_KEY]];
|
|
83
|
+
for (const client of clients) {
|
|
84
|
+
const actor = await userOf(client);
|
|
85
|
+
if (actor) return actor;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
async function userOf(client) {
|
|
90
|
+
const auth = client?.auth;
|
|
91
|
+
if (!auth) return null;
|
|
82
92
|
try {
|
|
83
|
-
|
|
93
|
+
if (typeof auth.getClaims === "function") {
|
|
94
|
+
const claims = await auth.getClaims().then((r) => r?.data?.claims, () => null);
|
|
95
|
+
if (claims && typeof claims.sub === "string" && claims.sub) {
|
|
96
|
+
return withLabel(claims.sub, claims.user_metadata?.full_name, claims.user_metadata?.name, claims.email);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (typeof auth.getUser !== "function") return null;
|
|
100
|
+
const { data } = await auth.getUser();
|
|
84
101
|
const user = data?.user;
|
|
85
102
|
if (!user || typeof user.id !== "string" || !user.id) return null;
|
|
86
|
-
|
|
87
|
-
return label ? { id: user.id, label } : { id: user.id };
|
|
103
|
+
return withLabel(user.id, user.user_metadata?.full_name, user.user_metadata?.name, user.email);
|
|
88
104
|
} catch {
|
|
89
105
|
return null;
|
|
90
106
|
}
|
|
91
107
|
}
|
|
108
|
+
function withLabel(id, ...candidates) {
|
|
109
|
+
const label = candidates.find((c) => typeof c === "string" && c.length > 0);
|
|
110
|
+
return label ? { id, label } : { id };
|
|
111
|
+
}
|
|
92
112
|
function wrapBuilder(builder, table, preread) {
|
|
93
113
|
if (typeof builder.insert === "function") {
|
|
94
114
|
builder.insert = wrapMutation(
|
|
@@ -255,7 +275,7 @@ function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
|
255
275
|
return;
|
|
256
276
|
}
|
|
257
277
|
if (!isPlainObject(values)) {
|
|
258
|
-
|
|
278
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
259
279
|
modelClass: ctx.table,
|
|
260
280
|
operation: ctx.operation,
|
|
261
281
|
resourceId: idFromFilters(filters)
|
|
@@ -269,9 +289,9 @@ function emitFromMutation(ctx, values, result, filters, beforeRow) {
|
|
|
269
289
|
function emitOneRow(ctx, values, resultRow, filters, beforeRow) {
|
|
270
290
|
const resourceId = resultRow?.id ?? values.id ?? idFromFilters(filters) ?? null;
|
|
271
291
|
const merged = beforeRow ?? resultRow ?? values;
|
|
272
|
-
const displayName =
|
|
292
|
+
const displayName = chunkB3WST6ES_cjs.resolveDisplayName(ctx.table, merged);
|
|
273
293
|
if (ctx.operation === "create") {
|
|
274
|
-
|
|
294
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
275
295
|
modelClass: ctx.table,
|
|
276
296
|
operation: "create",
|
|
277
297
|
resourceId,
|
|
@@ -283,7 +303,7 @@ function emitOneRow(ctx, values, resultRow, filters, beforeRow) {
|
|
|
283
303
|
}
|
|
284
304
|
if (ctx.operation === "update") {
|
|
285
305
|
const changes = buildUpdateChanges(values, beforeRow);
|
|
286
|
-
|
|
306
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
287
307
|
modelClass: ctx.table,
|
|
288
308
|
operation: "update",
|
|
289
309
|
resourceId,
|
|
@@ -297,8 +317,8 @@ function emitFromDelete(table, result, filters, beforeRow) {
|
|
|
297
317
|
const resultRow = pickFirstResultRow(result);
|
|
298
318
|
const resourceId = resultRow?.id ?? beforeRow?.id ?? idFromFilters(filters) ?? null;
|
|
299
319
|
const richestRow = resultRow ?? beforeRow;
|
|
300
|
-
const displayName = richestRow ?
|
|
301
|
-
|
|
320
|
+
const displayName = richestRow ? chunkB3WST6ES_cjs.resolveDisplayName(table, richestRow) : null;
|
|
321
|
+
chunkB3WST6ES_cjs.emitDbEvent({
|
|
302
322
|
modelClass: table,
|
|
303
323
|
operation: "destroy",
|
|
304
324
|
resourceId,
|
|
@@ -361,6 +381,11 @@ function describeError(error) {
|
|
|
361
381
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
362
382
|
return String(error);
|
|
363
383
|
}
|
|
384
|
+
var __ezlogsInstrument = chunkVJR4VB4B_cjs.instrumentFrom({
|
|
385
|
+
"@supabase/supabase-js#createClient": (original) => chunkVJR4VB4B_cjs.instrumentFactory(original, wrapSupabase),
|
|
386
|
+
"@supabase/ssr#createServerClient": (original) => chunkVJR4VB4B_cjs.instrumentFactory(original, wrapSupabase)
|
|
387
|
+
});
|
|
364
388
|
|
|
389
|
+
exports.__ezlogsInstrument = __ezlogsInstrument;
|
|
365
390
|
exports.tryExtractSupabaseActor = tryExtractSupabaseActor;
|
|
366
391
|
exports.wrapSupabase = wrapSupabase;
|
package/dist/db/supabase.d.cts
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
declare function wrapSupabase<T>(client: T): T;
|
|
18
18
|
/**
|
|
19
|
-
* Returns the current actor (if any) by asking the Supabase
|
|
20
|
-
*
|
|
21
|
-
* for
|
|
22
|
-
*
|
|
19
|
+
* Returns the current actor (if any) by asking the Supabase clients
|
|
20
|
+
* constructed in this scope, oldest first (outside any scope: the most
|
|
21
|
+
* recent client), for their authenticated user. Returns null when no
|
|
22
|
+
* client knows one. Used by the HTTP
|
|
23
23
|
* capturer's default `actorFromSupabase` path.
|
|
24
24
|
*
|
|
25
25
|
* Cheap-but-not-free: each call is a Supabase auth roundtrip. Callers
|
|
@@ -29,5 +29,11 @@ declare function tryExtractSupabaseActor(): Promise<{
|
|
|
29
29
|
id: string;
|
|
30
30
|
label?: string;
|
|
31
31
|
} | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Replacements for the plugin's instrumented imports (instrument.ts):
|
|
34
|
+
* every server-side client the app creates is wrapped.
|
|
35
|
+
* Internal: called by build-time generated code, not by apps.
|
|
36
|
+
*/
|
|
37
|
+
declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
|
|
32
38
|
|
|
33
|
-
export { tryExtractSupabaseActor, wrapSupabase };
|
|
39
|
+
export { __ezlogsInstrument, tryExtractSupabaseActor, wrapSupabase };
|
package/dist/db/supabase.d.ts
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
declare function wrapSupabase<T>(client: T): T;
|
|
18
18
|
/**
|
|
19
|
-
* Returns the current actor (if any) by asking the Supabase
|
|
20
|
-
*
|
|
21
|
-
* for
|
|
22
|
-
*
|
|
19
|
+
* Returns the current actor (if any) by asking the Supabase clients
|
|
20
|
+
* constructed in this scope, oldest first (outside any scope: the most
|
|
21
|
+
* recent client), for their authenticated user. Returns null when no
|
|
22
|
+
* client knows one. Used by the HTTP
|
|
23
23
|
* capturer's default `actorFromSupabase` path.
|
|
24
24
|
*
|
|
25
25
|
* Cheap-but-not-free: each call is a Supabase auth roundtrip. Callers
|
|
@@ -29,5 +29,11 @@ declare function tryExtractSupabaseActor(): Promise<{
|
|
|
29
29
|
id: string;
|
|
30
30
|
label?: string;
|
|
31
31
|
} | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Replacements for the plugin's instrumented imports (instrument.ts):
|
|
34
|
+
* every server-side client the app creates is wrapped.
|
|
35
|
+
* Internal: called by build-time generated code, not by apps.
|
|
36
|
+
*/
|
|
37
|
+
declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
|
|
32
38
|
|
|
33
|
-
export { tryExtractSupabaseActor, wrapSupabase };
|
|
39
|
+
export { __ezlogsInstrument, tryExtractSupabaseActor, wrapSupabase };
|