ezlogs-nextjs 0.4.4 → 0.4.7
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 +73 -13
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/{chunk-MMLQXSSD.cjs → chunk-2YCQFLXW.cjs} +21 -11
- package/dist/{chunk-YMIGZYFH.js → chunk-343ZGTMH.js} +1 -1
- package/dist/{chunk-Z2TM3LGG.js → chunk-5ZMOWEBY.js} +1 -1
- package/dist/{chunk-GI6BM4MR.js → chunk-7MFKEYDN.js} +21 -12
- package/dist/{chunk-NINIAL7M.js → chunk-AXIQTU52.js} +1 -1
- package/dist/chunk-BE3RCFNP.js +13 -0
- package/dist/chunk-CHVJ4WPM.cjs +16 -0
- package/dist/{chunk-MHBS5FEP.js → chunk-CYAFYBKF.js} +27 -4
- package/dist/chunk-DRE2VXFX.js +19 -0
- package/dist/{chunk-GMHOUAKD.cjs → chunk-EXGEA4KE.cjs} +37 -13
- package/dist/{chunk-PS4U2GFJ.cjs → chunk-JB4UYCZI.cjs} +5 -5
- package/dist/chunk-JWJKFZBW.js +52 -0
- package/dist/{chunk-R6IWVTX3.cjs → chunk-KOFR5OC3.cjs} +31 -21
- package/dist/chunk-NFZ5OKF3.cjs +22 -0
- package/dist/{chunk-U22T7QYY.js → chunk-Q3HRVWCS.js} +13 -3
- package/dist/{chunk-YXZZNZG6.cjs → chunk-UC2KS5EG.cjs} +9 -9
- package/dist/chunk-VJR4VB4B.cjs +56 -0
- package/dist/{chunk-NX4EL7BY.cjs → chunk-XWEBKN65.cjs} +4 -4
- 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 +303 -142
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +213 -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 +171 -48
- package/dist/jobs/inngest.d.cts +13 -7
- package/dist/jobs/inngest.d.ts +13 -7
- package/dist/jobs/inngest.js +162 -40
- 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 +104 -65
- package/dist/nextjs-plugin/loader.d.cts +18 -1
- package/dist/nextjs-plugin/loader.d.ts +18 -1
- package/dist/nextjs-plugin/loader.js +104 -66
- 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
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 chunkUC2KS5EG_cjs = require('../chunk-UC2KS5EG.cjs');
|
|
5
|
+
var chunk2YCQFLXW_cjs = require('../chunk-2YCQFLXW.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 = chunk2YCQFLXW_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 = chunk2YCQFLXW_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 = chunk2YCQFLXW_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
|
+
chunkUC2KS5EG_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 = chunkUC2KS5EG_cjs.resolveDisplayName(ctx.table, merged);
|
|
273
293
|
if (ctx.operation === "create") {
|
|
274
|
-
|
|
294
|
+
chunkUC2KS5EG_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
|
+
chunkUC2KS5EG_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 ? chunkUC2KS5EG_cjs.resolveDisplayName(table, richestRow) : null;
|
|
321
|
+
chunkUC2KS5EG_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 };
|
package/dist/db/supabase.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { instrumentFrom, instrumentFactory } from '../chunk-JWJKFZBW.js';
|
|
2
|
+
import { emitDbEvent, resolveDisplayName } from '../chunk-AXIQTU52.js';
|
|
3
|
+
import { currentActorSource, configuration } from '../chunk-7MFKEYDN.js';
|
|
3
4
|
import { logger } from '../chunk-FCFVIRQF.js';
|
|
4
5
|
import '../chunk-SIAA4J6H.js';
|
|
5
6
|
|
|
@@ -64,7 +65,8 @@ function registerActorSource(client) {
|
|
|
64
65
|
try {
|
|
65
66
|
const slot = currentActorSource();
|
|
66
67
|
if (slot) {
|
|
67
|
-
slot.
|
|
68
|
+
slot.clients ??= [];
|
|
69
|
+
if (!slot.clients.includes(client)) slot.clients.push(client);
|
|
68
70
|
slot.tried = false;
|
|
69
71
|
return;
|
|
70
72
|
}
|
|
@@ -75,18 +77,36 @@ function registerActorSource(client) {
|
|
|
75
77
|
}
|
|
76
78
|
async function tryExtractSupabaseActor() {
|
|
77
79
|
const slot = currentActorSource();
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
+
const clients = slot ? slot.clients ?? [] : [globalThis[GLOBAL_CLIENT_KEY]];
|
|
81
|
+
for (const client of clients) {
|
|
82
|
+
const actor = await userOf(client);
|
|
83
|
+
if (actor) return actor;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
async function userOf(client) {
|
|
88
|
+
const auth = client?.auth;
|
|
89
|
+
if (!auth) return null;
|
|
80
90
|
try {
|
|
81
|
-
|
|
91
|
+
if (typeof auth.getClaims === "function") {
|
|
92
|
+
const claims = await auth.getClaims().then((r) => r?.data?.claims, () => null);
|
|
93
|
+
if (claims && typeof claims.sub === "string" && claims.sub) {
|
|
94
|
+
return withLabel(claims.sub, claims.user_metadata?.full_name, claims.user_metadata?.name, claims.email);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (typeof auth.getUser !== "function") return null;
|
|
98
|
+
const { data } = await auth.getUser();
|
|
82
99
|
const user = data?.user;
|
|
83
100
|
if (!user || typeof user.id !== "string" || !user.id) return null;
|
|
84
|
-
|
|
85
|
-
return label ? { id: user.id, label } : { id: user.id };
|
|
101
|
+
return withLabel(user.id, user.user_metadata?.full_name, user.user_metadata?.name, user.email);
|
|
86
102
|
} catch {
|
|
87
103
|
return null;
|
|
88
104
|
}
|
|
89
105
|
}
|
|
106
|
+
function withLabel(id, ...candidates) {
|
|
107
|
+
const label = candidates.find((c) => typeof c === "string" && c.length > 0);
|
|
108
|
+
return label ? { id, label } : { id };
|
|
109
|
+
}
|
|
90
110
|
function wrapBuilder(builder, table, preread) {
|
|
91
111
|
if (typeof builder.insert === "function") {
|
|
92
112
|
builder.insert = wrapMutation(
|
|
@@ -359,5 +379,9 @@ function describeError(error) {
|
|
|
359
379
|
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
360
380
|
return String(error);
|
|
361
381
|
}
|
|
382
|
+
var __ezlogsInstrument = instrumentFrom({
|
|
383
|
+
"@supabase/supabase-js#createClient": (original) => instrumentFactory(original, wrapSupabase),
|
|
384
|
+
"@supabase/ssr#createServerClient": (original) => instrumentFactory(original, wrapSupabase)
|
|
385
|
+
});
|
|
362
386
|
|
|
363
|
-
export { tryExtractSupabaseActor, wrapSupabase };
|
|
387
|
+
export { __ezlogsInstrument, tryExtractSupabaseActor, wrapSupabase };
|