ezlogs-nextjs 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -16
- package/bin/install-triggers.cjs +73 -11
- package/dist/actors/index.cjs +5 -37
- package/dist/actors/index.js +2 -34
- package/dist/chunk-C5OSM557.js +39 -0
- package/dist/chunk-CE3R7DVB.js +1127 -0
- package/dist/chunk-CU45I2WR.js +498 -0
- package/dist/chunk-DKRNNI4I.js +180 -0
- package/dist/chunk-SIAA4J6H.js +17 -0
- package/dist/chunk-UQHEW6ER.js +119 -0
- package/dist/chunk-UWHYJH4M.cjs +126 -0
- package/dist/chunk-V5YNKKTG.cjs +42 -0
- package/dist/chunk-WASXTDLW.cjs +1151 -0
- package/dist/chunk-Y5NSHKWQ.cjs +182 -0
- package/dist/chunk-YX2XPLOA.cjs +508 -0
- package/dist/chunk-ZDSQYCYV.cjs +21 -0
- package/dist/db/drizzle.cjs +6 -713
- package/dist/db/drizzle.js +5 -712
- package/dist/db/prisma.cjs +52 -763
- package/dist/db/prisma.d.cts +3 -1
- package/dist/db/prisma.d.ts +3 -1
- package/dist/db/prisma.js +38 -749
- package/dist/db/supabase.cjs +21 -728
- package/dist/db/supabase.js +14 -721
- package/dist/index.cjs +204 -2181
- package/dist/index.js +107 -2090
- package/dist/jobs/bullmq.cjs +61 -552
- package/dist/jobs/bullmq.d.cts +8 -3
- package/dist/jobs/bullmq.d.ts +8 -3
- package/dist/jobs/bullmq.js +58 -549
- package/dist/jobs/inngest.cjs +23 -561
- package/dist/jobs/inngest.d.cts +7 -5
- package/dist/jobs/inngest.d.ts +7 -5
- package/dist/jobs/inngest.js +19 -557
- package/dist/jobs/supabase-queues.cjs +17 -603
- package/dist/jobs/supabase-queues.js +12 -598
- package/dist/jobs/trigger.cjs +18 -587
- package/dist/jobs/trigger.js +16 -585
- package/dist/jobs/upstash-workflow.cjs +62 -584
- package/dist/jobs/upstash-workflow.d.cts +17 -2
- package/dist/jobs/upstash-workflow.d.ts +17 -2
- package/dist/jobs/upstash-workflow.js +59 -582
- package/dist/nextjs-plugin/index.cjs +1 -1
- package/dist/nextjs-plugin/index.js +1 -1
- package/dist/nextjs-plugin/loader.cjs +21 -25
- package/dist/nextjs-plugin/loader.js +1 -5
- package/dist/triggers/index.cjs +40 -1234
- package/dist/triggers/index.d.cts +7 -2
- package/dist/triggers/index.d.ts +7 -2
- package/dist/triggers/index.js +6 -1221
- package/package.json +4 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { flushAuditLog } from './chunk-CU45I2WR.js';
|
|
2
|
+
import { configuration, build, current, pushEvent, generate, runWithCorrelation, sanitizeArgs } from './chunk-CE3R7DVB.js';
|
|
3
|
+
import { logger } from './chunk-C5OSM557.js';
|
|
4
|
+
|
|
5
|
+
// src/jobs/shared.ts
|
|
6
|
+
var CORRELATION_PAYLOAD_KEY = "ezlogs_correlation_id";
|
|
7
|
+
function emitJobEvent(input) {
|
|
8
|
+
try {
|
|
9
|
+
const config = configuration();
|
|
10
|
+
if (!config.captureJobs) return;
|
|
11
|
+
if (config.allExcludedJobClasses().includes(input.jobClass)) return;
|
|
12
|
+
const sourceData = compactJobSourceData({
|
|
13
|
+
job_class: input.jobClass,
|
|
14
|
+
job_id: input.jobId ?? null,
|
|
15
|
+
queue: input.queue ?? null,
|
|
16
|
+
retry_count: input.retryCount ?? null,
|
|
17
|
+
arguments: jobArguments(input.payload)
|
|
18
|
+
});
|
|
19
|
+
const event = build({
|
|
20
|
+
source_type: "background_job",
|
|
21
|
+
source_data: sourceData,
|
|
22
|
+
outcome: input.outcome,
|
|
23
|
+
correlation_id: input.correlationId ?? current(),
|
|
24
|
+
resource_ids: [],
|
|
25
|
+
context: null,
|
|
26
|
+
duration_ms: input.durationMs ?? null,
|
|
27
|
+
error_message: input.errorMessage ?? null,
|
|
28
|
+
timestamp: input.startedAt
|
|
29
|
+
});
|
|
30
|
+
pushEvent(event);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
logger.debug(`job emit failed: ${describeError(error)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function runJobWithCapture(meta, work) {
|
|
36
|
+
const correlationId = meta.correlationId ?? generate();
|
|
37
|
+
return runWithCorrelation(correlationId, async () => {
|
|
38
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
39
|
+
const startMs = startedAt.getTime();
|
|
40
|
+
const baseMeta = {
|
|
41
|
+
jobClass: meta.jobClass,
|
|
42
|
+
jobId: meta.jobId ?? null,
|
|
43
|
+
queue: meta.queue ?? null,
|
|
44
|
+
retryCount: meta.retryCount ?? null,
|
|
45
|
+
correlationId,
|
|
46
|
+
startedAt,
|
|
47
|
+
payload: meta.payload
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const result = await work();
|
|
51
|
+
await flushJobAuditLog(startedAt);
|
|
52
|
+
emitJobEvent({
|
|
53
|
+
...baseMeta,
|
|
54
|
+
outcome: "success",
|
|
55
|
+
durationMs: Date.now() - startMs
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
60
|
+
await flushJobAuditLog(startedAt);
|
|
61
|
+
if (meta.isControlFlow?.(error)) throw error;
|
|
62
|
+
emitJobEvent({
|
|
63
|
+
...baseMeta,
|
|
64
|
+
outcome: "failure",
|
|
65
|
+
errorMessage: message,
|
|
66
|
+
durationMs: Date.now() - startMs
|
|
67
|
+
});
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
var JOB_FLUSH_SKEW_MS = 500;
|
|
73
|
+
async function flushJobAuditLog(startedAt) {
|
|
74
|
+
try {
|
|
75
|
+
await flushAuditLog(configuration().databaseReader, {
|
|
76
|
+
since: new Date(startedAt.getTime() - JOB_FLUSH_SKEW_MS)
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.debug(`job audit flush failed: ${describeError(error)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function jobArguments(payload) {
|
|
83
|
+
if (payload === null || payload === void 0) return null;
|
|
84
|
+
const patterns = configuration().excludedGraphqlVariableKeys;
|
|
85
|
+
if (Array.isArray(payload)) return payload.length === 0 ? null : sanitizeArgs(payload, patterns);
|
|
86
|
+
if (typeof payload === "object" && Object.getPrototypeOf(payload) === Object.prototype) {
|
|
87
|
+
const rest = { ...payload };
|
|
88
|
+
delete rest[CORRELATION_PAYLOAD_KEY];
|
|
89
|
+
if (Object.keys(rest).length === 0) return null;
|
|
90
|
+
return sanitizeArgs([rest], patterns)[0];
|
|
91
|
+
}
|
|
92
|
+
return sanitizeArgs([payload], patterns);
|
|
93
|
+
}
|
|
94
|
+
function extractCorrelationFromPayload(payload, key = CORRELATION_PAYLOAD_KEY) {
|
|
95
|
+
if (payload === null || typeof payload !== "object") return null;
|
|
96
|
+
const value = payload[key];
|
|
97
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
98
|
+
}
|
|
99
|
+
function stampCorrelationOnPayload(payload, key = CORRELATION_PAYLOAD_KEY) {
|
|
100
|
+
if (!payload || typeof payload !== "object") return;
|
|
101
|
+
if (typeof payload[key] === "string" && payload[key]) return;
|
|
102
|
+
const id = current();
|
|
103
|
+
if (!id) return;
|
|
104
|
+
payload[key] = id;
|
|
105
|
+
}
|
|
106
|
+
function compactJobSourceData(data) {
|
|
107
|
+
const out = {};
|
|
108
|
+
for (const key of Object.keys(data)) {
|
|
109
|
+
const value = data[key];
|
|
110
|
+
if (value !== null && value !== void 0) out[key] = value;
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
function describeError(error) {
|
|
115
|
+
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
116
|
+
return String(error);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { CORRELATION_PAYLOAD_KEY, emitJobEvent, extractCorrelationFromPayload, flushJobAuditLog, runJobWithCapture, stampCorrelationOnPayload };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkYX2XPLOA_cjs = require('./chunk-YX2XPLOA.cjs');
|
|
4
|
+
var chunkWASXTDLW_cjs = require('./chunk-WASXTDLW.cjs');
|
|
5
|
+
var chunkV5YNKKTG_cjs = require('./chunk-V5YNKKTG.cjs');
|
|
6
|
+
|
|
7
|
+
// src/jobs/shared.ts
|
|
8
|
+
var CORRELATION_PAYLOAD_KEY = "ezlogs_correlation_id";
|
|
9
|
+
function emitJobEvent(input) {
|
|
10
|
+
try {
|
|
11
|
+
const config = chunkWASXTDLW_cjs.configuration();
|
|
12
|
+
if (!config.captureJobs) return;
|
|
13
|
+
if (config.allExcludedJobClasses().includes(input.jobClass)) return;
|
|
14
|
+
const sourceData = compactJobSourceData({
|
|
15
|
+
job_class: input.jobClass,
|
|
16
|
+
job_id: input.jobId ?? null,
|
|
17
|
+
queue: input.queue ?? null,
|
|
18
|
+
retry_count: input.retryCount ?? null,
|
|
19
|
+
arguments: jobArguments(input.payload)
|
|
20
|
+
});
|
|
21
|
+
const event = chunkWASXTDLW_cjs.build({
|
|
22
|
+
source_type: "background_job",
|
|
23
|
+
source_data: sourceData,
|
|
24
|
+
outcome: input.outcome,
|
|
25
|
+
correlation_id: input.correlationId ?? chunkWASXTDLW_cjs.current(),
|
|
26
|
+
resource_ids: [],
|
|
27
|
+
context: null,
|
|
28
|
+
duration_ms: input.durationMs ?? null,
|
|
29
|
+
error_message: input.errorMessage ?? null,
|
|
30
|
+
timestamp: input.startedAt
|
|
31
|
+
});
|
|
32
|
+
chunkWASXTDLW_cjs.pushEvent(event);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
chunkV5YNKKTG_cjs.logger.debug(`job emit failed: ${describeError(error)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function runJobWithCapture(meta, work) {
|
|
38
|
+
const correlationId = meta.correlationId ?? chunkWASXTDLW_cjs.generate();
|
|
39
|
+
return chunkWASXTDLW_cjs.runWithCorrelation(correlationId, async () => {
|
|
40
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
41
|
+
const startMs = startedAt.getTime();
|
|
42
|
+
const baseMeta = {
|
|
43
|
+
jobClass: meta.jobClass,
|
|
44
|
+
jobId: meta.jobId ?? null,
|
|
45
|
+
queue: meta.queue ?? null,
|
|
46
|
+
retryCount: meta.retryCount ?? null,
|
|
47
|
+
correlationId,
|
|
48
|
+
startedAt,
|
|
49
|
+
payload: meta.payload
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const result = await work();
|
|
53
|
+
await flushJobAuditLog(startedAt);
|
|
54
|
+
emitJobEvent({
|
|
55
|
+
...baseMeta,
|
|
56
|
+
outcome: "success",
|
|
57
|
+
durationMs: Date.now() - startMs
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
62
|
+
await flushJobAuditLog(startedAt);
|
|
63
|
+
if (meta.isControlFlow?.(error)) throw error;
|
|
64
|
+
emitJobEvent({
|
|
65
|
+
...baseMeta,
|
|
66
|
+
outcome: "failure",
|
|
67
|
+
errorMessage: message,
|
|
68
|
+
durationMs: Date.now() - startMs
|
|
69
|
+
});
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
var JOB_FLUSH_SKEW_MS = 500;
|
|
75
|
+
async function flushJobAuditLog(startedAt) {
|
|
76
|
+
try {
|
|
77
|
+
await chunkYX2XPLOA_cjs.flushAuditLog(chunkWASXTDLW_cjs.configuration().databaseReader, {
|
|
78
|
+
since: new Date(startedAt.getTime() - JOB_FLUSH_SKEW_MS)
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
chunkV5YNKKTG_cjs.logger.debug(`job audit flush failed: ${describeError(error)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function jobArguments(payload) {
|
|
85
|
+
if (payload === null || payload === void 0) return null;
|
|
86
|
+
const patterns = chunkWASXTDLW_cjs.configuration().excludedGraphqlVariableKeys;
|
|
87
|
+
if (Array.isArray(payload)) return payload.length === 0 ? null : chunkWASXTDLW_cjs.sanitizeArgs(payload, patterns);
|
|
88
|
+
if (typeof payload === "object" && Object.getPrototypeOf(payload) === Object.prototype) {
|
|
89
|
+
const rest = { ...payload };
|
|
90
|
+
delete rest[CORRELATION_PAYLOAD_KEY];
|
|
91
|
+
if (Object.keys(rest).length === 0) return null;
|
|
92
|
+
return chunkWASXTDLW_cjs.sanitizeArgs([rest], patterns)[0];
|
|
93
|
+
}
|
|
94
|
+
return chunkWASXTDLW_cjs.sanitizeArgs([payload], patterns);
|
|
95
|
+
}
|
|
96
|
+
function extractCorrelationFromPayload(payload, key = CORRELATION_PAYLOAD_KEY) {
|
|
97
|
+
if (payload === null || typeof payload !== "object") return null;
|
|
98
|
+
const value = payload[key];
|
|
99
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
100
|
+
}
|
|
101
|
+
function stampCorrelationOnPayload(payload, key = CORRELATION_PAYLOAD_KEY) {
|
|
102
|
+
if (!payload || typeof payload !== "object") return;
|
|
103
|
+
if (typeof payload[key] === "string" && payload[key]) return;
|
|
104
|
+
const id = chunkWASXTDLW_cjs.current();
|
|
105
|
+
if (!id) return;
|
|
106
|
+
payload[key] = id;
|
|
107
|
+
}
|
|
108
|
+
function compactJobSourceData(data) {
|
|
109
|
+
const out = {};
|
|
110
|
+
for (const key of Object.keys(data)) {
|
|
111
|
+
const value = data[key];
|
|
112
|
+
if (value !== null && value !== void 0) out[key] = value;
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
function describeError(error) {
|
|
117
|
+
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
118
|
+
return String(error);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
exports.CORRELATION_PAYLOAD_KEY = CORRELATION_PAYLOAD_KEY;
|
|
122
|
+
exports.emitJobEvent = emitJobEvent;
|
|
123
|
+
exports.extractCorrelationFromPayload = extractCorrelationFromPayload;
|
|
124
|
+
exports.flushJobAuditLog = flushJobAuditLog;
|
|
125
|
+
exports.runJobWithCapture = runJobWithCapture;
|
|
126
|
+
exports.stampCorrelationOnPayload = stampCorrelationOnPayload;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/logger.ts
|
|
4
|
+
var LEVEL_RANK = {
|
|
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 setLogLevel(level) {
|
|
17
|
+
globalThis[LEVEL_KEY] = level;
|
|
18
|
+
}
|
|
19
|
+
function shouldLog(level) {
|
|
20
|
+
return LEVEL_RANK[level] >= LEVEL_RANK[readLevel()];
|
|
21
|
+
}
|
|
22
|
+
function safeWrite(level, message) {
|
|
23
|
+
try {
|
|
24
|
+
if (!shouldLog(level)) return;
|
|
25
|
+
const line = `[ezlogs] ${message}`;
|
|
26
|
+
if (level === "error" || level === "warn") {
|
|
27
|
+
console.error(line);
|
|
28
|
+
} else {
|
|
29
|
+
console.log(line);
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var logger = {
|
|
35
|
+
debug: (message) => safeWrite("debug", message),
|
|
36
|
+
info: (message) => safeWrite("info", message),
|
|
37
|
+
warn: (message) => safeWrite("warn", message),
|
|
38
|
+
error: (message) => safeWrite("error", message)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.logger = logger;
|
|
42
|
+
exports.setLogLevel = setLogLevel;
|