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/README.md
CHANGED
|
@@ -119,7 +119,7 @@ need one more step, depending on your stack:
|
|
|
119
119
|
|---|---|---|
|
|
120
120
|
| **Supabase** (supabase-js) | `npm i pg`, set `DATABASE_URL` to the Postgres connection string, run `npx ezlogs-nextjs install-triggers`. Nothing to wrap: the agent tags supabase-js requests and the trigger reads the tag. | Every write (`.from()`, `.rpc()`, bulk) with from→to diffs, linked to its request |
|
|
121
121
|
| **Prisma** on Postgres | triggers (as above) + `new PrismaClient().$extends(ezlogsPrisma())` (below) | Same |
|
|
122
|
-
| **Drizzle** (node-postgres) or raw **`pg`** | triggers (as above).
|
|
122
|
+
| **Drizzle** (node-postgres) or raw **`pg`** | triggers (as above). With `DATABASE_URL` set, the agent patches `pg` itself; if your app loads its own copy of `pg` (monorepos), pass it: `ezlogs.init({ ..., patchDatabaseClient: pg })`. | Same |
|
|
123
123
|
| postgres.js, Neon HTTP, scripts | triggers (as above) | Writes show up as their own actions, not linked to the request |
|
|
124
124
|
| MySQL, SQLite, PlanetScale, no trigger access | a per-ORM adapter: `ezlogsPrisma()`, `ezlogsDrizzleLogger`, `wrapSupabase` ([docs/database.md](./docs/database.md)) | New values only, no before-values |
|
|
125
125
|
|
|
@@ -132,7 +132,10 @@ Run it from your app's directory with the package installed there
|
|
|
132
132
|
(with bun: `bunx ezlogs-nextjs install-triggers` or
|
|
133
133
|
`./node_modules/.bin/ezlogs-nextjs install-triggers`); if the package
|
|
134
134
|
isn't installed locally, npx / bunx download whatever version is
|
|
135
|
-
published, and the CLI warns.
|
|
135
|
+
published, and the CLI warns. They also download it when your
|
|
136
|
+
lockfile's bin entries predate 0.3.0 (seen with bun and a `file:`
|
|
137
|
+
dependency); the CLI then prints the command that runs your project's
|
|
138
|
+
copy: `node node_modules/ezlogs-nextjs/bin/install-triggers.cjs install-triggers`. Migration tables, sessions, and the
|
|
136
139
|
agent's own audit table are skipped automatically. If `pg` or the
|
|
137
140
|
audit table is missing at runtime, the agent logs one warning at
|
|
138
141
|
startup and leaves the trigger path off.
|
|
@@ -156,6 +159,16 @@ your own `prisma.$transaction(...)` are not tagged: they still show up,
|
|
|
156
159
|
as separate actions without an actor. Without the extension, a plain
|
|
157
160
|
PrismaClient's writes are never tagged.
|
|
158
161
|
|
|
162
|
+
**Background workers** (BullMQ and other job processes) are separate
|
|
163
|
+
processes: call `ezlogs.init` there too and build the database client
|
|
164
|
+
the same way (extension for Prisma), or the job's writes show up as
|
|
165
|
+
separate actions without an actor.
|
|
166
|
+
|
|
167
|
+
**Self-check:** if writes made while requests or jobs run in a process
|
|
168
|
+
keep arriving untagged, and that process has never sent a tagged row,
|
|
169
|
+
the agent logs one warning naming the fix. It never guesses which
|
|
170
|
+
request an untagged row belongs to.
|
|
171
|
+
|
|
159
172
|
Without triggers, the extension still sends Prisma writes itself (new
|
|
160
173
|
values only — Prisma doesn't expose the old row). With triggers it
|
|
161
174
|
sends nothing for tracked tables; the trigger rows are the single
|
package/bin/install-triggers.cjs
CHANGED
|
@@ -40,12 +40,39 @@ function installedFromProject() {
|
|
|
40
40
|
|
|
41
41
|
// `npx` / `bunx` download the package to a temp dir when it isn't
|
|
42
42
|
// installed in this project — a version that may differ from the one
|
|
43
|
-
// your app runs, and a place `pg` can't be found from.
|
|
44
|
-
|
|
43
|
+
// your app runs, and a place `pg` can't be found from. They also do
|
|
44
|
+
// it when it IS installed but the lockfile's bin metadata predates
|
|
45
|
+
// the `ezlogs-nextjs` bin (seen with bun and a `file:` dependency):
|
|
46
|
+
// then point at the project's own copy.
|
|
47
|
+
const local = installedFromProject();
|
|
48
|
+
let runLocal = null;
|
|
49
|
+
if (local !== fs.realpathSync(path.join(__dirname, ".."))) {
|
|
50
|
+
let hint;
|
|
51
|
+
if (local) {
|
|
52
|
+
let localVersion = "?";
|
|
53
|
+
try {
|
|
54
|
+
localVersion = JSON.parse(fs.readFileSync(path.join(local, "package.json"), "utf8")).version;
|
|
55
|
+
} catch {
|
|
56
|
+
/* keep "?" */
|
|
57
|
+
}
|
|
58
|
+
const localBin = path.join(local, "bin", "install-triggers.cjs");
|
|
59
|
+
if (fs.existsSync(localBin)) {
|
|
60
|
+
runLocal = `node ${JSON.stringify(path.relative(process.cwd(), localBin))} install-triggers`;
|
|
61
|
+
}
|
|
62
|
+
hint =
|
|
63
|
+
`This project has ezlogs-nextjs ${localVersion} installed, but npx / bunx did not use it ` +
|
|
64
|
+
"(usually a lockfile whose bin entries predate 0.3.0, e.g. bun with a `file:` dependency). " +
|
|
65
|
+
"Run your project's copy instead:\n" +
|
|
66
|
+
(runLocal ? ` ${runLocal}\n or ` : " ") +
|
|
67
|
+
"./node_modules/.bin/ezlogs-nextjs install-triggers (./node_modules/.bin/install-triggers on older installs).";
|
|
68
|
+
} else {
|
|
69
|
+
hint =
|
|
70
|
+
"Run it from your app's directory after `npm install ezlogs-nextjs` " +
|
|
71
|
+
"(or `./node_modules/.bin/ezlogs-nextjs install-triggers`).";
|
|
72
|
+
}
|
|
45
73
|
console.warn(
|
|
46
74
|
`[ezlogs] Running ezlogs-nextjs ${version} from ${path.dirname(__dirname)}, not from ` +
|
|
47
|
-
|
|
48
|
-
"`npm install ezlogs-nextjs` (or `./node_modules/.bin/ezlogs-nextjs install-triggers`).",
|
|
75
|
+
`this project's node_modules. ${hint}`,
|
|
49
76
|
);
|
|
50
77
|
}
|
|
51
78
|
|
|
@@ -65,7 +92,8 @@ function installedFromProject() {
|
|
|
65
92
|
" Install it in your app (the agent also needs it at runtime to read the audit log):\n" +
|
|
66
93
|
" npm install pg (or: pnpm add pg / yarn add pg / bun add pg)\n" +
|
|
67
94
|
" then run this command again from your app's directory.\n" +
|
|
68
|
-
" Or print the SQL and run it with your own tool: npx ezlogs-nextjs install-triggers --print"
|
|
95
|
+
" Or print the SQL and run it with your own tool: npx ezlogs-nextjs install-triggers --print" +
|
|
96
|
+
(runLocal ? `\n This copy was not run from your project; try: ${runLocal}` : ""),
|
|
69
97
|
);
|
|
70
98
|
process.exit(1);
|
|
71
99
|
}
|
package/dist/actors/index.cjs
CHANGED
|
@@ -1,39 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
debug: 10,
|
|
6
|
-
info: 20,
|
|
7
|
-
warn: 30,
|
|
8
|
-
error: 40,
|
|
9
|
-
silent: 100
|
|
10
|
-
};
|
|
11
|
-
var LEVEL_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:log-level");
|
|
12
|
-
function readLevel() {
|
|
13
|
-
const g = globalThis;
|
|
14
|
-
return g[LEVEL_KEY] ?? "warn";
|
|
15
|
-
}
|
|
16
|
-
function shouldLog(level) {
|
|
17
|
-
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
18
|
-
}
|
|
19
|
-
function safeWrite(level, message) {
|
|
20
|
-
try {
|
|
21
|
-
if (!shouldLog(level)) return;
|
|
22
|
-
const line = `[ezlogs] ${message}`;
|
|
23
|
-
if (level === "error" || level === "warn") {
|
|
24
|
-
console.error(line);
|
|
25
|
-
} else {
|
|
26
|
-
console.log(line);
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
var logger = {
|
|
32
|
-
debug: (message) => safeWrite("debug", message),
|
|
33
|
-
info: (message) => safeWrite("info", message),
|
|
34
|
-
warn: (message) => safeWrite("warn", message),
|
|
35
|
-
error: (message) => safeWrite("error", message)
|
|
36
|
-
};
|
|
3
|
+
var chunkV5YNKKTG_cjs = require('../chunk-V5YNKKTG.cjs');
|
|
4
|
+
require('../chunk-ZDSQYCYV.cjs');
|
|
37
5
|
|
|
38
6
|
// src/actors/clerk.ts
|
|
39
7
|
function clerkActor() {
|
|
@@ -52,7 +20,7 @@ function clerkActor() {
|
|
|
52
20
|
const label = typeof claims.email === "string" && claims.email || typeof claims.name === "string" && claims.name || typeof claims.username === "string" && claims.username || void 0;
|
|
53
21
|
return label ? { id: userId, label } : { id: userId };
|
|
54
22
|
} catch (error) {
|
|
55
|
-
logger.debug(
|
|
23
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
56
24
|
`clerkActor: extraction failed (${error instanceof Error ? error.message : String(error)})`
|
|
57
25
|
);
|
|
58
26
|
return null;
|
|
@@ -78,7 +46,7 @@ function nextAuthActor(options) {
|
|
|
78
46
|
const label = typeof user.name === "string" && user.name || typeof user.email === "string" && user.email || void 0;
|
|
79
47
|
return label ? { id, label } : { id };
|
|
80
48
|
} catch (error) {
|
|
81
|
-
logger.debug(
|
|
49
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
82
50
|
`nextAuthActor: extraction failed (${error instanceof Error ? error.message : String(error)})`
|
|
83
51
|
);
|
|
84
52
|
return null;
|
|
@@ -98,7 +66,7 @@ function authJsActor(options) {
|
|
|
98
66
|
const label = typeof user.name === "string" && user.name || typeof user.email === "string" && user.email || void 0;
|
|
99
67
|
return label ? { id, label } : { id };
|
|
100
68
|
} catch (error) {
|
|
101
|
-
logger.debug(
|
|
69
|
+
chunkV5YNKKTG_cjs.logger.debug(
|
|
102
70
|
`authJsActor: extraction failed (${error instanceof Error ? error.message : String(error)})`
|
|
103
71
|
);
|
|
104
72
|
return null;
|
package/dist/actors/index.js
CHANGED
|
@@ -1,37 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
debug: 10,
|
|
4
|
-
info: 20,
|
|
5
|
-
warn: 30,
|
|
6
|
-
error: 40,
|
|
7
|
-
silent: 100
|
|
8
|
-
};
|
|
9
|
-
var LEVEL_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:log-level");
|
|
10
|
-
function readLevel() {
|
|
11
|
-
const g = globalThis;
|
|
12
|
-
return g[LEVEL_KEY] ?? "warn";
|
|
13
|
-
}
|
|
14
|
-
function shouldLog(level) {
|
|
15
|
-
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
16
|
-
}
|
|
17
|
-
function safeWrite(level, message) {
|
|
18
|
-
try {
|
|
19
|
-
if (!shouldLog(level)) return;
|
|
20
|
-
const line = `[ezlogs] ${message}`;
|
|
21
|
-
if (level === "error" || level === "warn") {
|
|
22
|
-
console.error(line);
|
|
23
|
-
} else {
|
|
24
|
-
console.log(line);
|
|
25
|
-
}
|
|
26
|
-
} catch {
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
var logger = {
|
|
30
|
-
debug: (message) => safeWrite("debug", message),
|
|
31
|
-
info: (message) => safeWrite("info", message),
|
|
32
|
-
warn: (message) => safeWrite("warn", message),
|
|
33
|
-
error: (message) => safeWrite("error", message)
|
|
34
|
-
};
|
|
1
|
+
import { logger } from '../chunk-C5OSM557.js';
|
|
2
|
+
import '../chunk-SIAA4J6H.js';
|
|
35
3
|
|
|
36
4
|
// src/actors/clerk.ts
|
|
37
5
|
function clerkActor() {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
var LEVEL_RANK = {
|
|
3
|
+
debug: 10,
|
|
4
|
+
info: 20,
|
|
5
|
+
warn: 30,
|
|
6
|
+
error: 40,
|
|
7
|
+
silent: 100
|
|
8
|
+
};
|
|
9
|
+
var LEVEL_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:log-level");
|
|
10
|
+
function readLevel() {
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
return g[LEVEL_KEY] ?? "warn";
|
|
13
|
+
}
|
|
14
|
+
function setLogLevel(level) {
|
|
15
|
+
globalThis[LEVEL_KEY] = level;
|
|
16
|
+
}
|
|
17
|
+
function shouldLog(level) {
|
|
18
|
+
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
19
|
+
}
|
|
20
|
+
function safeWrite(level, message) {
|
|
21
|
+
try {
|
|
22
|
+
if (!shouldLog(level)) return;
|
|
23
|
+
const line = `[ezlogs] ${message}`;
|
|
24
|
+
if (level === "error" || level === "warn") {
|
|
25
|
+
console.error(line);
|
|
26
|
+
} else {
|
|
27
|
+
console.log(line);
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
var logger = {
|
|
33
|
+
debug: (message) => safeWrite("debug", message),
|
|
34
|
+
info: (message) => safeWrite("info", message),
|
|
35
|
+
warn: (message) => safeWrite("warn", message),
|
|
36
|
+
error: (message) => safeWrite("error", message)
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { logger, setLogLevel };
|