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
package/dist/jobs/trigger.cjs
CHANGED
|
@@ -1,564 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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/event-builder.ts
|
|
46
|
-
var SENSITIVE_KEYS = Object.freeze([
|
|
47
|
-
"password",
|
|
48
|
-
"token",
|
|
49
|
-
"secret",
|
|
50
|
-
"api_key",
|
|
51
|
-
"credit_card"
|
|
52
|
-
]);
|
|
53
|
-
var VALID_SOURCE_TYPES = [
|
|
54
|
-
"http_request",
|
|
55
|
-
"background_job",
|
|
56
|
-
"database_callback"
|
|
57
|
-
];
|
|
58
|
-
var VALID_OUTCOMES = ["success", "failure"];
|
|
59
|
-
function build(input) {
|
|
60
|
-
const source_type = validateSourceType(input.source_type);
|
|
61
|
-
const source_data_raw = validateSourceData(input.source_data);
|
|
62
|
-
const outcome = validateOutcome(input.outcome);
|
|
63
|
-
const timestamp = validateTimestamp(input.timestamp ?? null);
|
|
64
|
-
const resource_ids = validateResourceIds(input.resource_ids ?? []);
|
|
65
|
-
const context_raw = validateContext();
|
|
66
|
-
const duration_ms = validateDurationMs(input.duration_ms ?? null);
|
|
67
|
-
const error_message = input.error_message ?? null;
|
|
68
|
-
validateOutcomeErrorConsistency(outcome, error_message);
|
|
69
|
-
const source_data = sanitizeRecord(source_data_raw);
|
|
70
|
-
const context = context_raw === null ? null : sanitizeRecord(context_raw);
|
|
71
|
-
const correlation_id = input.correlation_id ?? null;
|
|
72
|
-
const event = {
|
|
73
|
-
timestamp,
|
|
74
|
-
source_type,
|
|
75
|
-
source_data,
|
|
76
|
-
outcome,
|
|
77
|
-
correlation_id,
|
|
78
|
-
resource_ids,
|
|
79
|
-
context,
|
|
80
|
-
duration_ms,
|
|
81
|
-
error_message
|
|
82
|
-
};
|
|
83
|
-
return event;
|
|
84
|
-
}
|
|
85
|
-
function validateSourceType(value) {
|
|
86
|
-
const normalized = String(value);
|
|
87
|
-
if (!VALID_SOURCE_TYPES.includes(normalized)) {
|
|
88
|
-
throw new ArgError(
|
|
89
|
-
`source_type must be one of ${VALID_SOURCE_TYPES.join(", ")}, got: ${normalized}`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return normalized;
|
|
93
|
-
}
|
|
94
|
-
function validateSourceData(value) {
|
|
95
|
-
if (value === null || value === void 0) {
|
|
96
|
-
throw new ArgError("source_data is required");
|
|
97
|
-
}
|
|
98
|
-
if (!isPlainObject(value)) {
|
|
99
|
-
throw new ArgError(
|
|
100
|
-
`source_data must be an object, got: ${describe(value)}`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
return value;
|
|
104
|
-
}
|
|
105
|
-
function validateOutcome(value) {
|
|
106
|
-
if (value === null || value === void 0) {
|
|
107
|
-
throw new ArgError("outcome is required");
|
|
108
|
-
}
|
|
109
|
-
const normalized = String(value);
|
|
110
|
-
if (!VALID_OUTCOMES.includes(normalized)) {
|
|
111
|
-
throw new ArgError(
|
|
112
|
-
`outcome must be one of ${VALID_OUTCOMES.join(", ")}, got: ${normalized}`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return normalized;
|
|
116
|
-
}
|
|
117
|
-
function validateTimestamp(value) {
|
|
118
|
-
if (value === null) {
|
|
119
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
120
|
-
}
|
|
121
|
-
if (typeof value === "string") {
|
|
122
|
-
const parsed = new Date(value);
|
|
123
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
124
|
-
throw new ArgError(
|
|
125
|
-
`timestamp must be valid ISO 8601 format, got: ${value}`
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
return value;
|
|
129
|
-
}
|
|
130
|
-
if (value instanceof Date) {
|
|
131
|
-
if (Number.isNaN(value.getTime())) {
|
|
132
|
-
throw new ArgError("timestamp must be a valid Date");
|
|
133
|
-
}
|
|
134
|
-
return value.toISOString();
|
|
135
|
-
}
|
|
136
|
-
throw new ArgError(
|
|
137
|
-
`timestamp must be a string or Date, got: ${describe(value)}`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
function validateResourceIds(value) {
|
|
141
|
-
if (!Array.isArray(value)) {
|
|
142
|
-
throw new ArgError(`resource_ids must be an array, got: ${describe(value)}`);
|
|
143
|
-
}
|
|
144
|
-
value.forEach((entry, index) => {
|
|
145
|
-
if (!isPlainObject(entry)) {
|
|
146
|
-
throw new ArgError(
|
|
147
|
-
`resource_ids[${index}] must be an object, got: ${describe(entry)}`
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
const e = entry;
|
|
151
|
-
if (!("resource_type" in e) || !("resource_id" in e)) {
|
|
152
|
-
throw new ArgError(
|
|
153
|
-
`resource_ids[${index}] must have resource_type and resource_id keys, got: ${Object.keys(e).join(", ")}`
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
if (typeof e.resource_type !== "string") {
|
|
157
|
-
throw new ArgError(
|
|
158
|
-
`resource_ids[${index}].resource_type must be a string, got: ${describe(e.resource_type)}`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
if (typeof e.resource_id !== "string") {
|
|
162
|
-
throw new ArgError(
|
|
163
|
-
`resource_ids[${index}].resource_id must be a string, got: ${describe(e.resource_id)}`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
function validateContext(value) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
function validateDurationMs(value) {
|
|
173
|
-
if (value === null || value === void 0) return null;
|
|
174
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
175
|
-
throw new ArgError(`duration_ms must be a number, got: ${describe(value)}`);
|
|
176
|
-
}
|
|
177
|
-
if (!Number.isInteger(value)) {
|
|
178
|
-
throw new ArgError(`duration_ms must be an integer, got: ${value}`);
|
|
179
|
-
}
|
|
180
|
-
if (value < 0) {
|
|
181
|
-
throw new ArgError(`duration_ms must be >= 0, got: ${value}`);
|
|
182
|
-
}
|
|
183
|
-
return value;
|
|
184
|
-
}
|
|
185
|
-
function validateOutcomeErrorConsistency(outcome, error_message) {
|
|
186
|
-
if (outcome === "failure") {
|
|
187
|
-
if (error_message === null || error_message === "") {
|
|
188
|
-
throw new ArgError("error_message is required when outcome is 'failure'");
|
|
189
|
-
}
|
|
190
|
-
} else if (outcome === "success") {
|
|
191
|
-
if (error_message !== null) {
|
|
192
|
-
throw new ArgError("error_message must be null when outcome is 'success'");
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function sanitizeRecord(input) {
|
|
197
|
-
const result = {};
|
|
198
|
-
for (const key of Object.keys(input)) {
|
|
199
|
-
const value = input[key];
|
|
200
|
-
if (isSensitiveKey(key)) {
|
|
201
|
-
result[key] = "[FILTERED]";
|
|
202
|
-
} else if (isPlainObject(value)) {
|
|
203
|
-
result[key] = sanitizeRecord(value);
|
|
204
|
-
} else if (Array.isArray(value)) {
|
|
205
|
-
result[key] = value.map(
|
|
206
|
-
(item) => isPlainObject(item) ? sanitizeRecord(item) : item
|
|
207
|
-
);
|
|
208
|
-
} else {
|
|
209
|
-
result[key] = value;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
function isSensitiveKey(key) {
|
|
215
|
-
const lower = key.toLowerCase();
|
|
216
|
-
return SENSITIVE_KEYS.some((p) => lower.includes(p));
|
|
217
|
-
}
|
|
218
|
-
function isPlainObject(value) {
|
|
219
|
-
if (value === null || typeof value !== "object") return false;
|
|
220
|
-
const proto = Object.getPrototypeOf(value);
|
|
221
|
-
return proto === Object.prototype || proto === null;
|
|
222
|
-
}
|
|
223
|
-
function describe(value) {
|
|
224
|
-
if (value === null) return "null";
|
|
225
|
-
if (Array.isArray(value)) return "Array";
|
|
226
|
-
return typeof value;
|
|
227
|
-
}
|
|
228
|
-
var ArgError = class extends Error {
|
|
229
|
-
constructor(message) {
|
|
230
|
-
super(message);
|
|
231
|
-
this.name = "ArgError";
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// src/configuration.ts
|
|
236
|
-
var DEFAULT_EXCLUDED_PATHS = Object.freeze([
|
|
237
|
-
// Next.js / Vercel infrastructure noise
|
|
238
|
-
"/_next/*",
|
|
239
|
-
"/_vercel/*",
|
|
240
|
-
"/__nextjs_*",
|
|
241
|
-
// NextAuth.js / Auth.js — skip session-refresh polls and CSRF/provider
|
|
242
|
-
// metadata GETs (high-frequency, no business meaning), but CAPTURE
|
|
243
|
-
// POSTs (callbacks, signin, signout, register). The POSTs are the
|
|
244
|
-
// actual auth events users care about; the GETs are pure plumbing.
|
|
245
|
-
Object.freeze({ path: "/api/auth/*", methods: ["GET", "HEAD"] }),
|
|
246
|
-
// Generic infrastructure
|
|
247
|
-
"/health*",
|
|
248
|
-
"/api/health",
|
|
249
|
-
"/up",
|
|
250
|
-
"/alive",
|
|
251
|
-
"/ready",
|
|
252
|
-
"/metrics",
|
|
253
|
-
"/favicon.ico",
|
|
254
|
-
"/.well-known*",
|
|
255
|
-
"/robots.txt",
|
|
256
|
-
"/sitemap.xml",
|
|
257
|
-
"/*.hot-update.*",
|
|
258
|
-
// Auth routes (common patterns across Clerk, NextAuth, custom auth)
|
|
259
|
-
"*/login*",
|
|
260
|
-
"*/logout*",
|
|
261
|
-
"*/sign-in*",
|
|
262
|
-
"*/sign-out*",
|
|
263
|
-
"*/signin*",
|
|
264
|
-
"*/signout*",
|
|
265
|
-
"/session*"
|
|
266
|
-
]);
|
|
267
|
-
var DEFAULT_EXCLUDED_TABLES = Object.freeze([
|
|
268
|
-
// Prisma migration ledger
|
|
269
|
-
"_prisma_migrations",
|
|
270
|
-
// Auth.js / NextAuth Prisma adapter — session/verification-token churn
|
|
271
|
-
// is auth machinery, not business activity. Account/User stay captured.
|
|
272
|
-
"Session",
|
|
273
|
-
"VerificationToken",
|
|
274
|
-
// Common cross-stack convention names for the same things
|
|
275
|
-
"sessions",
|
|
276
|
-
"session",
|
|
277
|
-
"verification_tokens"
|
|
278
|
-
]);
|
|
279
|
-
var DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
|
|
280
|
-
var DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
|
|
281
|
-
var Configuration = class {
|
|
282
|
-
serverUrl = null;
|
|
283
|
-
projectToken = null;
|
|
284
|
-
captureHttp = true;
|
|
285
|
-
captureDb = true;
|
|
286
|
-
captureJobs = true;
|
|
287
|
-
bufferSize = 1e4;
|
|
288
|
-
/** Default 3000 ms — equivalent to Ruby's 3 seconds. */
|
|
289
|
-
sendInterval = 3e3;
|
|
290
|
-
retryAttempts = 3;
|
|
291
|
-
logLevel = "warn";
|
|
292
|
-
patchGlobalFetch = true;
|
|
293
|
-
actorFromSupabase = true;
|
|
294
|
-
allowInsecureTransport = false;
|
|
295
|
-
excludedPaths = [];
|
|
296
|
-
excludedTables = [];
|
|
297
|
-
excludedJobClasses = [];
|
|
298
|
-
excludedGraphqlOperations = [];
|
|
299
|
-
excludedGraphqlVariableKeys = [];
|
|
300
|
-
actorFromRequest = null;
|
|
301
|
-
displayNameFor = {};
|
|
302
|
-
isServerActionError = null;
|
|
303
|
-
databaseReader = null;
|
|
304
|
-
databaseUrl = null;
|
|
305
|
-
/**
|
|
306
|
-
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
307
|
-
* at agent startup by reading `information_schema.triggers`. The
|
|
308
|
-
* supabase / drizzle / prisma adapters use this to decide whether
|
|
309
|
-
* their per-mutation emit is redundant: if the table is trigger-
|
|
310
|
-
* tracked the audit-log reader will surface the same write with full
|
|
311
|
-
* old/new state, so the adapter's emit is suppressed. Tables NOT in
|
|
312
|
-
* this set fall through to the adapter so they're still captured.
|
|
313
|
-
*
|
|
314
|
-
* `null` means "detection hasn't run yet or failed" — in that state
|
|
315
|
-
* `databaseReader`-wired apps suppress every adapter emit (the
|
|
316
|
-
* original Phase 5 behavior). After detection completes the agent
|
|
317
|
-
* gives the more accurate per-table answer.
|
|
318
|
-
*/
|
|
319
|
-
triggerTrackedTables = null;
|
|
320
|
-
apply(options) {
|
|
321
|
-
this.serverUrl = options.serverUrl;
|
|
322
|
-
this.projectToken = options.projectToken;
|
|
323
|
-
if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
|
|
324
|
-
if (options.captureDb !== void 0) this.captureDb = options.captureDb;
|
|
325
|
-
if (options.captureJobs !== void 0) this.captureJobs = options.captureJobs;
|
|
326
|
-
if (options.bufferSize !== void 0) this.bufferSize = options.bufferSize;
|
|
327
|
-
if (options.sendInterval !== void 0) this.sendInterval = options.sendInterval;
|
|
328
|
-
if (options.retryAttempts !== void 0) this.retryAttempts = options.retryAttempts;
|
|
329
|
-
if (options.excludedPaths) this.excludedPaths = [...options.excludedPaths];
|
|
330
|
-
if (options.excludedTables) this.excludedTables = [...options.excludedTables];
|
|
331
|
-
if (options.excludedJobClasses) {
|
|
332
|
-
this.excludedJobClasses = [...options.excludedJobClasses];
|
|
333
|
-
}
|
|
334
|
-
if (options.excludedGraphqlOperations) {
|
|
335
|
-
this.excludedGraphqlOperations = [...options.excludedGraphqlOperations];
|
|
336
|
-
}
|
|
337
|
-
if (options.excludedGraphqlVariableKeys) {
|
|
338
|
-
this.excludedGraphqlVariableKeys = [...options.excludedGraphqlVariableKeys];
|
|
339
|
-
}
|
|
340
|
-
if (options.actorFromRequest) this.actorFromRequest = options.actorFromRequest;
|
|
341
|
-
if (options.displayNameFor) this.displayNameFor = { ...options.displayNameFor };
|
|
342
|
-
if (options.isServerActionError) this.isServerActionError = options.isServerActionError;
|
|
343
|
-
if (options.patchGlobalFetch !== void 0) {
|
|
344
|
-
this.patchGlobalFetch = options.patchGlobalFetch;
|
|
345
|
-
}
|
|
346
|
-
if (options.allowInsecureTransport !== void 0) {
|
|
347
|
-
this.allowInsecureTransport = options.allowInsecureTransport;
|
|
348
|
-
}
|
|
349
|
-
if (options.actorFromSupabase !== void 0) {
|
|
350
|
-
this.actorFromSupabase = options.actorFromSupabase;
|
|
351
|
-
}
|
|
352
|
-
if (options.databaseReader !== void 0) {
|
|
353
|
-
this.databaseReader = options.databaseReader;
|
|
354
|
-
}
|
|
355
|
-
if (options.databaseUrl !== void 0) {
|
|
356
|
-
this.databaseUrl = options.databaseUrl;
|
|
357
|
-
}
|
|
358
|
-
if (options.logLevel) this.logLevel = options.logLevel;
|
|
359
|
-
}
|
|
360
|
-
allExcludedPaths() {
|
|
361
|
-
return [...DEFAULT_EXCLUDED_PATHS, ...this.excludedPaths];
|
|
362
|
-
}
|
|
363
|
-
allExcludedTables() {
|
|
364
|
-
return [...DEFAULT_EXCLUDED_TABLES, ...this.excludedTables];
|
|
365
|
-
}
|
|
366
|
-
allExcludedJobClasses() {
|
|
367
|
-
return [...DEFAULT_EXCLUDED_JOB_CLASSES, ...this.excludedJobClasses];
|
|
368
|
-
}
|
|
369
|
-
allExcludedGraphqlOperations() {
|
|
370
|
-
return [...DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS, ...this.excludedGraphqlOperations];
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
var GLOBAL_CONFIG_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:configuration");
|
|
374
|
-
function configuration() {
|
|
375
|
-
const g = globalThis;
|
|
376
|
-
if (!g[GLOBAL_CONFIG_KEY]) {
|
|
377
|
-
g[GLOBAL_CONFIG_KEY] = new Configuration();
|
|
378
|
-
}
|
|
379
|
-
return g[GLOBAL_CONFIG_KEY];
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// src/pipeline/buffer.ts
|
|
383
|
-
var GLOBAL_QUEUE_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:buffer-queue");
|
|
384
|
-
function getQueue() {
|
|
385
|
-
const g = globalThis;
|
|
386
|
-
if (!g[GLOBAL_QUEUE_KEY]) g[GLOBAL_QUEUE_KEY] = [];
|
|
387
|
-
return g[GLOBAL_QUEUE_KEY];
|
|
388
|
-
}
|
|
389
|
-
function pushEvent(event) {
|
|
390
|
-
try {
|
|
391
|
-
const queue = getQueue();
|
|
392
|
-
const max = maxSize();
|
|
393
|
-
if (queue.length >= max) {
|
|
394
|
-
queue.shift();
|
|
395
|
-
logger.warn(`Buffer full (${max}), dropped oldest event`);
|
|
396
|
-
}
|
|
397
|
-
queue.push(event);
|
|
398
|
-
} catch (error) {
|
|
399
|
-
logger.error(`pushEvent failed: ${describe2(error)}`);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
function maxSize() {
|
|
403
|
-
try {
|
|
404
|
-
return configuration().bufferSize;
|
|
405
|
-
} catch {
|
|
406
|
-
return 1e4;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
function describe2(error) {
|
|
410
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
411
|
-
return String(error);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// src/edge-fallback.ts
|
|
415
|
-
var ALS_CTOR = loadAsyncLocalStorage();
|
|
416
|
-
function loadAsyncLocalStorage() {
|
|
417
|
-
const fromGlobal = globalThis.AsyncLocalStorage;
|
|
418
|
-
if (typeof fromGlobal === "function") return fromGlobal;
|
|
419
|
-
try {
|
|
420
|
-
const req = typeof __require !== "undefined" ? __require : (
|
|
421
|
-
// In ESM, `createRequire` is the official escape hatch.
|
|
422
|
-
// We pull it via globalThis to avoid a static `import`
|
|
423
|
-
// that would itself be browser-bundled.
|
|
424
|
-
void 0
|
|
425
|
-
);
|
|
426
|
-
if (typeof req === "function") {
|
|
427
|
-
const moduleName = ["async", "hooks"].join("_");
|
|
428
|
-
const mod = req("node:" + moduleName);
|
|
429
|
-
if (typeof mod.AsyncLocalStorage === "function") return mod.AsyncLocalStorage;
|
|
430
|
-
}
|
|
431
|
-
} catch {
|
|
432
|
-
}
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
function createScopedStorage(key = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:default-scoped-storage")) {
|
|
436
|
-
const globalStore = globalThis;
|
|
437
|
-
let entry = globalStore[key];
|
|
438
|
-
if (!entry) {
|
|
439
|
-
const als2 = (() => {
|
|
440
|
-
if (!ALS_CTOR) return null;
|
|
441
|
-
try {
|
|
442
|
-
return new ALS_CTOR();
|
|
443
|
-
} catch {
|
|
444
|
-
return null;
|
|
445
|
-
}
|
|
446
|
-
})();
|
|
447
|
-
entry = { als: als2, edgeFallback: null };
|
|
448
|
-
globalStore[key] = entry;
|
|
449
|
-
}
|
|
450
|
-
const als = entry.als;
|
|
451
|
-
const stateRef = entry;
|
|
452
|
-
return {
|
|
453
|
-
read() {
|
|
454
|
-
if (als) return als.getStore()?.value ?? null;
|
|
455
|
-
return stateRef.edgeFallback?.value ?? null;
|
|
456
|
-
},
|
|
457
|
-
run(value, callback) {
|
|
458
|
-
if (als) return als.run({ value }, callback);
|
|
459
|
-
const previous = stateRef.edgeFallback;
|
|
460
|
-
stateRef.edgeFallback = { value };
|
|
461
|
-
try {
|
|
462
|
-
return callback();
|
|
463
|
-
} finally {
|
|
464
|
-
stateRef.edgeFallback = previous;
|
|
465
|
-
}
|
|
466
|
-
},
|
|
467
|
-
update(value) {
|
|
468
|
-
if (als) {
|
|
469
|
-
const store = als.getStore();
|
|
470
|
-
if (store) store.value = value;
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
stateRef.edgeFallback = { value };
|
|
474
|
-
},
|
|
475
|
-
_resetForTests() {
|
|
476
|
-
stateRef.edgeFallback = null;
|
|
477
|
-
},
|
|
478
|
-
_isAsyncLocalStorage() {
|
|
479
|
-
return als !== null;
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// src/correlation.ts
|
|
485
|
-
var storage = createScopedStorage(
|
|
486
|
-
/* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
|
|
487
|
-
);
|
|
488
|
-
function generate() {
|
|
489
|
-
const ts = Date.now();
|
|
490
|
-
const hex = randomHexBytes(4);
|
|
491
|
-
return `ezl_${ts}_${hex}`;
|
|
492
|
-
}
|
|
493
|
-
function randomHexBytes(byteCount) {
|
|
494
|
-
const buf = new Uint8Array(byteCount);
|
|
495
|
-
globalThis.crypto.getRandomValues(buf);
|
|
496
|
-
let out = "";
|
|
497
|
-
for (let i = 0; i < buf.length; i++) {
|
|
498
|
-
out += buf[i].toString(16).padStart(2, "0");
|
|
499
|
-
}
|
|
500
|
-
return out;
|
|
501
|
-
}
|
|
502
|
-
function current() {
|
|
503
|
-
return storage.read();
|
|
504
|
-
}
|
|
505
|
-
function runWithCorrelation(correlationId, callback) {
|
|
506
|
-
return storage.run(correlationId, callback);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// src/jobs/shared.ts
|
|
510
|
-
var CORRELATION_PAYLOAD_KEY = "ezlogs_correlation_id";
|
|
511
|
-
function emitJobEvent(input) {
|
|
512
|
-
try {
|
|
513
|
-
const config = configuration();
|
|
514
|
-
if (!config.captureJobs) return;
|
|
515
|
-
if (config.allExcludedJobClasses().includes(input.jobClass)) return;
|
|
516
|
-
const sourceData = compactJobSourceData({
|
|
517
|
-
job_class: input.jobClass,
|
|
518
|
-
job_id: input.jobId ?? null,
|
|
519
|
-
queue: input.queue ?? null,
|
|
520
|
-
retry_count: input.retryCount ?? null
|
|
521
|
-
});
|
|
522
|
-
const event = build({
|
|
523
|
-
source_type: "background_job",
|
|
524
|
-
source_data: sourceData,
|
|
525
|
-
outcome: input.outcome,
|
|
526
|
-
correlation_id: input.correlationId ?? current(),
|
|
527
|
-
resource_ids: [],
|
|
528
|
-
context: null,
|
|
529
|
-
duration_ms: input.durationMs ?? null,
|
|
530
|
-
error_message: input.errorMessage ?? null,
|
|
531
|
-
timestamp: input.startedAt
|
|
532
|
-
});
|
|
533
|
-
pushEvent(event);
|
|
534
|
-
} catch (error) {
|
|
535
|
-
logger.debug(`job emit failed: ${describeError(error)}`);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
function extractCorrelationFromPayload(payload, key = CORRELATION_PAYLOAD_KEY) {
|
|
539
|
-
if (payload === null || typeof payload !== "object") return null;
|
|
540
|
-
const value = payload[key];
|
|
541
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
542
|
-
}
|
|
543
|
-
function compactJobSourceData(data) {
|
|
544
|
-
const out = {};
|
|
545
|
-
for (const key of Object.keys(data)) {
|
|
546
|
-
const value = data[key];
|
|
547
|
-
if (value !== null && value !== void 0) out[key] = value;
|
|
548
|
-
}
|
|
549
|
-
return out;
|
|
550
|
-
}
|
|
551
|
-
function describeError(error) {
|
|
552
|
-
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
553
|
-
return String(error);
|
|
554
|
-
}
|
|
3
|
+
var chunkUWHYJH4M_cjs = require('../chunk-UWHYJH4M.cjs');
|
|
4
|
+
require('../chunk-YX2XPLOA.cjs');
|
|
5
|
+
var chunkWASXTDLW_cjs = require('../chunk-WASXTDLW.cjs');
|
|
6
|
+
var chunkV5YNKKTG_cjs = require('../chunk-V5YNKKTG.cjs');
|
|
7
|
+
require('../chunk-ZDSQYCYV.cjs');
|
|
555
8
|
|
|
556
9
|
// src/jobs/trigger.ts
|
|
557
10
|
var REGISTERED_FLAG = "__ezlogsTriggerRegistered";
|
|
558
11
|
function registerTriggerHooks(tasks) {
|
|
559
12
|
if (tasks[REGISTERED_FLAG]) return;
|
|
560
13
|
if (typeof tasks.middleware !== "function") {
|
|
561
|
-
logger.debug("trigger.dev tasks.middleware not available \u2014 adapter not registered");
|
|
14
|
+
chunkV5YNKKTG_cjs.logger.debug("trigger.dev tasks.middleware not available \u2014 adapter not registered");
|
|
562
15
|
return;
|
|
563
16
|
}
|
|
564
17
|
tasks.middleware("ezlogs", async (params) => {
|
|
@@ -577,42 +30,20 @@ async function runWithEzlogsCapture(params) {
|
|
|
577
30
|
const queueName = ctx.run?.queue?.name ?? null;
|
|
578
31
|
const attemptNumber = ctx.attempt?.number ?? 1;
|
|
579
32
|
const retryCount = Math.max(0, attemptNumber - 1);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
correlationId,
|
|
592
|
-
outcome: "success",
|
|
593
|
-
durationMs: Date.now() - startMs,
|
|
594
|
-
startedAt
|
|
595
|
-
});
|
|
596
|
-
return result;
|
|
597
|
-
} catch (error) {
|
|
598
|
-
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
599
|
-
emitJobEvent({
|
|
600
|
-
jobClass: taskId,
|
|
601
|
-
jobId: runId,
|
|
602
|
-
queue: queueName,
|
|
603
|
-
retryCount,
|
|
604
|
-
correlationId,
|
|
605
|
-
outcome: "failure",
|
|
606
|
-
errorMessage: message,
|
|
607
|
-
durationMs: Date.now() - startMs,
|
|
608
|
-
startedAt
|
|
609
|
-
});
|
|
610
|
-
throw error;
|
|
611
|
-
}
|
|
612
|
-
});
|
|
33
|
+
return chunkUWHYJH4M_cjs.runJobWithCapture(
|
|
34
|
+
{
|
|
35
|
+
jobClass: taskId,
|
|
36
|
+
jobId: runId,
|
|
37
|
+
queue: queueName,
|
|
38
|
+
retryCount,
|
|
39
|
+
correlationId: chunkUWHYJH4M_cjs.extractCorrelationFromPayload(params.payload),
|
|
40
|
+
payload: params.payload
|
|
41
|
+
},
|
|
42
|
+
() => params.next()
|
|
43
|
+
);
|
|
613
44
|
}
|
|
614
45
|
function stampPayloadForTrigger(payload) {
|
|
615
|
-
const id = current();
|
|
46
|
+
const id = chunkWASXTDLW_cjs.current();
|
|
616
47
|
if (!id) return payload;
|
|
617
48
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
618
49
|
return payload;
|