ezlogs-nextjs 0.4.6 → 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.
Files changed (42) hide show
  1. package/README.md +23 -3
  2. package/dist/{chunk-B5ZUQULZ.cjs → chunk-2YCQFLXW.cjs} +3 -0
  3. package/dist/{chunk-RD47JECJ.js → chunk-343ZGTMH.js} +1 -1
  4. package/dist/{chunk-2NFJOT6Q.js → chunk-5ZMOWEBY.js} +1 -1
  5. package/dist/{chunk-IBSNHBUC.js → chunk-7MFKEYDN.js} +3 -0
  6. package/dist/{chunk-U3IJV5EJ.js → chunk-AXIQTU52.js} +1 -1
  7. package/dist/{chunk-RMKGMIV2.js → chunk-BE3RCFNP.js} +1 -1
  8. package/dist/{chunk-H3FC5HMW.cjs → chunk-CHVJ4WPM.cjs} +2 -2
  9. package/dist/{chunk-M3VBQ5KT.js → chunk-CYAFYBKF.js} +2 -2
  10. package/dist/{chunk-O7SFYXJC.cjs → chunk-EXGEA4KE.cjs} +12 -12
  11. package/dist/{chunk-YO6E763S.cjs → chunk-JB4UYCZI.cjs} +5 -5
  12. package/dist/{chunk-65HRY3PW.cjs → chunk-KOFR5OC3.cjs} +21 -21
  13. package/dist/{chunk-PK2Z2ABL.js → chunk-Q3HRVWCS.js} +3 -3
  14. package/dist/{chunk-B3WST6ES.cjs → chunk-UC2KS5EG.cjs} +9 -9
  15. package/dist/{chunk-DM2EAOSF.cjs → chunk-XWEBKN65.cjs} +4 -4
  16. package/dist/db/drizzle.cjs +3 -3
  17. package/dist/db/drizzle.js +2 -2
  18. package/dist/db/postgres-js.cjs +4 -4
  19. package/dist/db/postgres-js.js +2 -2
  20. package/dist/db/prisma.cjs +12 -12
  21. package/dist/db/prisma.js +2 -2
  22. package/dist/db/supabase.cjs +11 -11
  23. package/dist/db/supabase.js +2 -2
  24. package/dist/index.cjs +121 -106
  25. package/dist/index.js +21 -6
  26. package/dist/jobs/bullmq.cjs +17 -17
  27. package/dist/jobs/bullmq.js +4 -4
  28. package/dist/jobs/inngest.cjs +154 -50
  29. package/dist/jobs/inngest.d.cts +6 -6
  30. package/dist/jobs/inngest.d.ts +6 -6
  31. package/dist/jobs/inngest.js +144 -40
  32. package/dist/jobs/supabase-queues.cjs +9 -9
  33. package/dist/jobs/supabase-queues.js +4 -4
  34. package/dist/jobs/trigger.cjs +7 -7
  35. package/dist/jobs/trigger.js +4 -4
  36. package/dist/jobs/upstash-workflow.cjs +19 -19
  37. package/dist/jobs/upstash-workflow.js +5 -5
  38. package/dist/nextjs-plugin/loader.cjs +34 -5
  39. package/dist/nextjs-plugin/loader.js +34 -5
  40. package/dist/triggers/index.cjs +16 -16
  41. package/dist/triggers/index.js +5 -5
  42. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { patchPgClient } from './chunk-2NFJOT6Q.js';
2
- import { runWithDeliverySlot } from './chunk-RMKGMIV2.js';
3
- import { flushAuditLog, runWithEmittedAuditIdsScope, auditLogInstalled, checkAuditLogAccess, detectTriggerTrackedTables, settleAuditFlushes, maintainAuditLogAfterRequests } from './chunk-M3VBQ5KT.js';
4
- import { build, pushEvent, maskAuthParams, isAuthActionName, isAuthPath, scrubSecretsInText, buffer_exports, sanitizeRequestParams, passesLuhn, isSensitiveKey, drainEvents } from './chunk-U3IJV5EJ.js';
5
- export { ArgError, build as buildEvent } from './chunk-U3IJV5EJ.js';
6
- import { configuration, resolveCorrelation, runWithCorrelation, maybeExtractSupabaseActor, endCorrelationScope, getCurrentActor, current, makeAsyncContextCapture, runWithActorScope, setActor, loadNodeBuiltin, DEFAULT_EXCLUDED_EXTENSIONS } from './chunk-IBSNHBUC.js';
1
+ import { patchPgClient } from './chunk-5ZMOWEBY.js';
2
+ import { runWithDeliverySlot } from './chunk-BE3RCFNP.js';
3
+ import { flushAuditLog, runWithEmittedAuditIdsScope, auditLogInstalled, checkAuditLogAccess, detectTriggerTrackedTables, settleAuditFlushes, maintainAuditLogAfterRequests } from './chunk-CYAFYBKF.js';
4
+ import { build, pushEvent, maskAuthParams, isAuthActionName, isAuthPath, scrubSecretsInText, buffer_exports, sanitizeRequestParams, passesLuhn, isSensitiveKey, drainEvents } from './chunk-AXIQTU52.js';
5
+ export { ArgError, build as buildEvent } from './chunk-AXIQTU52.js';
6
+ import { configuration, resolveCorrelation, runWithCorrelation, maybeExtractSupabaseActor, endCorrelationScope, getCurrentActor, current, makeAsyncContextCapture, runWithActorScope, setActor, loadNodeBuiltin, DEFAULT_EXCLUDED_EXTENSIONS } from './chunk-7MFKEYDN.js';
7
7
  import { logger, setLogLevel } from './chunk-FCFVIRQF.js';
8
8
  import './chunk-SIAA4J6H.js';
9
9
 
@@ -865,6 +865,7 @@ function captureRoute(handler, context = {}) {
865
865
  snapshot.rawParams = mergeRouteParams(snapshot.rawParams, await readRouteParams(args[1]));
866
866
  const correlationId = resolveCorrelation(request.headers ?? null);
867
867
  const delivery = { jobDelivery: false };
868
+ const inngestServerKind = request.headers?.get?.(INNGEST_SERVER_KIND) ?? null;
868
869
  return await runWithCorrelation(
869
870
  correlationId,
870
871
  () => runWithDeliverySlot(delivery, () => runWithActorAndAuditScope(async () => {
@@ -879,6 +880,9 @@ function captureRoute(handler, context = {}) {
879
880
  let handlerMs = null;
880
881
  const finish = async () => {
881
882
  await maybeExtractSupabaseActor();
883
+ if (isJobRunnerSync(snapshot.method, inngestServerKind, response?.headers?.get?.(INNGEST_SDK) ?? null)) {
884
+ delivery.jobDelivery = true;
885
+ }
882
886
  await emitEvent({
883
887
  snapshot,
884
888
  context,
@@ -1108,6 +1112,7 @@ function capturePagesApi(handler, context = {}) {
1108
1112
  get: (name) => readPagesHeader(req, name)
1109
1113
  });
1110
1114
  const delivery = { jobDelivery: false };
1115
+ const inngestServerKind = readPagesHeader(req, INNGEST_SERVER_KIND);
1111
1116
  return await runWithCorrelation(
1112
1117
  correlationId,
1113
1118
  () => runWithDeliverySlot(delivery, () => runWithActorAndAuditScope(async () => {
@@ -1124,6 +1129,10 @@ function capturePagesApi(handler, context = {}) {
1124
1129
  await maybeExtractSupabaseActor();
1125
1130
  const status = typeof res.statusCode === "number" ? res.statusCode : null;
1126
1131
  const getHeader = res.getHeader;
1132
+ const sdkHeader = typeof getHeader === "function" ? getHeader.call(res, INNGEST_SDK) : null;
1133
+ if (isJobRunnerSync(snapshot.method, inngestServerKind, sdkHeader ? String(sdkHeader) : null)) {
1134
+ delivery.jobDelivery = true;
1135
+ }
1127
1136
  await emitEvent({
1128
1137
  snapshot,
1129
1138
  context,
@@ -1927,6 +1936,12 @@ function readPagesHeader(req, name) {
1927
1936
  if (Array.isArray(value)) return value[0] ?? null;
1928
1937
  return null;
1929
1938
  }
1939
+ var INNGEST_SERVER_KIND = "x-inngest-server-kind";
1940
+ var INNGEST_SDK = "x-inngest-sdk";
1941
+ function isJobRunnerSync(method, inngestServerKind, sdkResponseHeader) {
1942
+ const m = (method ?? "").toUpperCase();
1943
+ return inngestServerKind !== null && sdkResponseHeader !== null && (m === "GET" || m === "PUT");
1944
+ }
1930
1945
  async function emitEvent(input) {
1931
1946
  try {
1932
1947
  await flushTriggerAuditLog();
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkVJR4VB4B_cjs = require('../chunk-VJR4VB4B.cjs');
4
- var chunk65HRY3PW_cjs = require('../chunk-65HRY3PW.cjs');
5
- require('../chunk-O7SFYXJC.cjs');
6
- require('../chunk-B3WST6ES.cjs');
7
- var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
4
+ var chunkKOFR5OC3_cjs = require('../chunk-KOFR5OC3.cjs');
5
+ require('../chunk-EXGEA4KE.cjs');
6
+ require('../chunk-UC2KS5EG.cjs');
7
+ var chunk2YCQFLXW_cjs = require('../chunk-2YCQFLXW.cjs');
8
8
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
9
9
  require('../chunk-ZDSQYCYV.cjs');
10
10
 
@@ -40,7 +40,7 @@ function wrapBullQueue(queue) {
40
40
  const wrappedAddBulk = (jobs) => {
41
41
  const stamped = jobs.map((j) => ({ ...j, data: stampPayload(j.data) }));
42
42
  const ours = stamped.map((j) => isOurs(j.data));
43
- const token = ours.includes(true) ? chunk65HRY3PW_cjs.signedActorToken(chunkB5ZUQULZ_cjs.current()) : null;
43
+ const token = ours.includes(true) ? chunkKOFR5OC3_cjs.signedActorToken(chunk2YCQFLXW_cjs.current()) : null;
44
44
  return inOrder(
45
45
  token,
46
46
  (t) => originalAddBulk(stamped.map((j, i) => ours[i] ? { ...j, data: withActor(j.data, t) } : j))
@@ -71,10 +71,10 @@ function wrapBullWorker(worker) {
71
71
  internals.processFn = function ezlogsProcess(...args) {
72
72
  const job = args[0] ?? {};
73
73
  if (typeof args[0] === "object" && args[0] !== null) reported.add(args[0]);
74
- const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(job.data);
75
- const token = job.data?.[chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY];
74
+ const correlationId = chunkKOFR5OC3_cjs.extractCorrelationFromPayload(job.data);
75
+ const token = job.data?.[chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY];
76
76
  if (typeof args[0] === "object" && args[0] !== null) hideAgentKeys(job);
77
- const run = (actor) => chunk65HRY3PW_cjs.runJobWithCapture(
77
+ const run = (actor) => chunkKOFR5OC3_cjs.runJobWithCapture(
78
78
  {
79
79
  jobClass: job.name ?? worker.name ?? "BullMQJob",
80
80
  jobId: job.id !== void 0 && job.id !== null ? String(job.id) : null,
@@ -90,7 +90,7 @@ function wrapBullWorker(worker) {
90
90
  () => Promise.resolve(original.apply(this, args))
91
91
  );
92
92
  if (!correlationId || token === void 0) return run(null);
93
- return chunk65HRY3PW_cjs.readActorToken(token, correlationId).then(run);
93
+ return chunkKOFR5OC3_cjs.readActorToken(token, correlationId).then(run);
94
94
  };
95
95
  worker.on("failed", (...args) => {
96
96
  const job = args[0];
@@ -131,10 +131,10 @@ function markWrapped(worker) {
131
131
  }
132
132
  function captureJob(job, worker, outcome, errorMessage) {
133
133
  try {
134
- const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(job.data);
134
+ const correlationId = chunkKOFR5OC3_cjs.extractCorrelationFromPayload(job.data);
135
135
  const startedAt = typeof job.timestamp === "number" ? new Date(job.timestamp) : /* @__PURE__ */ new Date();
136
136
  const durationMs = job.timestamp ? Date.now() - job.timestamp : null;
137
- chunk65HRY3PW_cjs.emitJobEvent({
137
+ chunkKOFR5OC3_cjs.emitJobEvent({
138
138
  jobClass: job.name ?? worker.name ?? "BullMQJob",
139
139
  jobId: job.id !== void 0 && job.id !== null ? String(job.id) : null,
140
140
  queue: job.queueName ?? worker.name ?? null,
@@ -151,15 +151,15 @@ function captureJob(job, worker, outcome, errorMessage) {
151
151
  }
152
152
  }
153
153
  function pendingActorTokenFor(data) {
154
- return isOurs(data) ? chunk65HRY3PW_cjs.signedActorToken(chunkB5ZUQULZ_cjs.current()) : null;
154
+ return isOurs(data) ? chunkKOFR5OC3_cjs.signedActorToken(chunk2YCQFLXW_cjs.current()) : null;
155
155
  }
156
156
  function isOurs(data) {
157
157
  if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
158
158
  const obj = data;
159
- const id = chunkB5ZUQULZ_cjs.current();
160
- return Boolean(id) && obj[chunk65HRY3PW_cjs.CORRELATION_PAYLOAD_KEY] === id && !(chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY in obj);
159
+ const id = chunk2YCQFLXW_cjs.current();
160
+ return Boolean(id) && obj[chunkKOFR5OC3_cjs.CORRELATION_PAYLOAD_KEY] === id && !(chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY in obj);
161
161
  }
162
- var AGENT_KEYS = [chunk65HRY3PW_cjs.CORRELATION_PAYLOAD_KEY, chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY];
162
+ var AGENT_KEYS = [chunkKOFR5OC3_cjs.CORRELATION_PAYLOAD_KEY, chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY];
163
163
  function hideAgentKeys(job) {
164
164
  try {
165
165
  const data = job.data;
@@ -181,13 +181,13 @@ function hideAgentKeys(job) {
181
181
  }
182
182
  }
183
183
  function withActor(data, token) {
184
- return token ? { ...data, [chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY]: token } : data;
184
+ return token ? { ...data, [chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY]: token } : data;
185
185
  }
186
186
  function stampPayload(data) {
187
187
  if (data === null || typeof data !== "object" || Array.isArray(data)) {
188
188
  return data;
189
189
  }
190
- return chunk65HRY3PW_cjs.stampCorrelationOnPayload(data, chunk65HRY3PW_cjs.CORRELATION_PAYLOAD_KEY);
190
+ return chunkKOFR5OC3_cjs.stampCorrelationOnPayload(data, chunkKOFR5OC3_cjs.CORRELATION_PAYLOAD_KEY);
191
191
  }
192
192
  function describeError(error) {
193
193
  if (error instanceof Error) return `${error.name}: ${error.message}`;
@@ -1,8 +1,8 @@
1
1
  import { instrumentFrom, instrumentClass } from '../chunk-JWJKFZBW.js';
2
- import { extractCorrelationFromPayload, ACTOR_PAYLOAD_KEY, readActorToken, CORRELATION_PAYLOAD_KEY, runJobWithCapture, emitJobEvent, stampCorrelationOnPayload, signedActorToken } from '../chunk-PK2Z2ABL.js';
3
- import '../chunk-M3VBQ5KT.js';
4
- import '../chunk-U3IJV5EJ.js';
5
- import { current } from '../chunk-IBSNHBUC.js';
2
+ import { extractCorrelationFromPayload, ACTOR_PAYLOAD_KEY, readActorToken, CORRELATION_PAYLOAD_KEY, runJobWithCapture, emitJobEvent, stampCorrelationOnPayload, signedActorToken } from '../chunk-Q3HRVWCS.js';
3
+ import '../chunk-CYAFYBKF.js';
4
+ import '../chunk-AXIQTU52.js';
5
+ import { current } from '../chunk-7MFKEYDN.js';
6
6
  import { logger } from '../chunk-FCFVIRQF.js';
7
7
  import '../chunk-SIAA4J6H.js';
8
8
 
@@ -1,25 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var chunkH3FC5HMW_cjs = require('../chunk-H3FC5HMW.cjs');
3
+ var chunkCHVJ4WPM_cjs = require('../chunk-CHVJ4WPM.cjs');
4
4
  var chunkVJR4VB4B_cjs = require('../chunk-VJR4VB4B.cjs');
5
- var chunk65HRY3PW_cjs = require('../chunk-65HRY3PW.cjs');
6
- require('../chunk-O7SFYXJC.cjs');
7
- require('../chunk-B3WST6ES.cjs');
8
- var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
5
+ var chunkKOFR5OC3_cjs = require('../chunk-KOFR5OC3.cjs');
6
+ require('../chunk-EXGEA4KE.cjs');
7
+ require('../chunk-UC2KS5EG.cjs');
8
+ var chunk2YCQFLXW_cjs = require('../chunk-2YCQFLXW.cjs');
9
9
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
10
10
  require('../chunk-ZDSQYCYV.cjs');
11
11
 
12
12
  // src/jobs/inngest.ts
13
- var warnedUnsupported = false;
13
+ var insideV4Run = chunk2YCQFLXW_cjs.createScopedStorage(/* @__PURE__ */ Symbol.for("ezlogs-nextjs:inngest-v4-run"));
14
14
  function ezlogsInngestMiddleware() {
15
15
  const middleware = function ezlogsInngestV4() {
16
- if (!warnedUnsupported) {
17
- warnedUnsupported = true;
18
- chunkTWTG5ILJ_cjs.logger.warn(
19
- "ezlogsInngestMiddleware supports Inngest v3 only; on this Inngest version it does nothing (jobs are not captured)"
20
- );
21
- }
22
- return {};
16
+ return inngestV4Hooks();
23
17
  };
24
18
  Object.defineProperty(middleware, "name", { value: "ezlogs-nextjs" });
25
19
  return Object.assign(middleware, {
@@ -29,13 +23,13 @@ function ezlogsInngestMiddleware() {
29
23
  // one function). Returns per-run hooks that fire as the run
30
24
  // proceeds. We track the run via closure-scoped state.
31
25
  onFunctionRun(args) {
32
- chunkH3FC5HMW_cjs.markJobDelivery();
26
+ chunkCHVJ4WPM_cjs.markJobDelivery();
33
27
  const fnId = functionId(args.fn) ?? "inngest-function";
34
28
  const runId = args.ctx?.runId ?? null;
35
29
  const attempt = typeof args.ctx?.attempt === "number" ? args.ctx.attempt : 0;
36
30
  const eventName = args.ctx?.event?.name ?? null;
37
31
  const eventData = args.ctx?.event?.data;
38
- const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(args.ctx?.event?.data) ?? chunkB5ZUQULZ_cjs.generate();
32
+ const correlationId = chunkKOFR5OC3_cjs.extractCorrelationFromPayload(args.ctx?.event?.data) ?? chunk2YCQFLXW_cjs.generate();
39
33
  const startedAt = /* @__PURE__ */ new Date();
40
34
  const startMs = startedAt.getTime();
41
35
  return {
@@ -49,7 +43,7 @@ function ezlogsInngestMiddleware() {
49
43
  const outcome = error ? "failure" : "success";
50
44
  const errorMessage = error ? formatError(error) : null;
51
45
  const ranStep = args2.step?.displayName ?? args2.step?.name;
52
- chunk65HRY3PW_cjs.emitJobEvent({
46
+ chunkKOFR5OC3_cjs.emitJobEvent({
53
47
  jobClass: fnId,
54
48
  jobId: runId,
55
49
  queue: eventName,
@@ -78,33 +72,7 @@ function ezlogsInngestMiddleware() {
78
72
  // objects are never written (one reused across requests
79
73
  // would carry the first request's id and actor).
80
74
  transformInput(args) {
81
- try {
82
- const id = chunkB5ZUQULZ_cjs.current();
83
- if (!id) return;
84
- if (!Array.isArray(args.payloads)) return;
85
- const stamped = [];
86
- const payloads = args.payloads.map((payload) => {
87
- if (!payload || typeof payload !== "object") return payload;
88
- const data = payload.data ?? {};
89
- if (typeof data !== "object" || data === null || Array.isArray(data)) {
90
- return payload;
91
- }
92
- if (typeof data.ezlogs_correlation_id === "string") {
93
- return payload;
94
- }
95
- const copy = { ...data, ezlogs_correlation_id: id };
96
- if (!(chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY in copy)) stamped.push(copy);
97
- return { ...payload, data: copy };
98
- });
99
- const pending = stamped.length > 0 ? chunk65HRY3PW_cjs.signedActorToken(id) : null;
100
- if (!pending) return { payloads };
101
- return pending.then((token) => {
102
- if (token) for (const data of stamped) data[chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY] = token;
103
- return { payloads };
104
- });
105
- } catch (error) {
106
- chunkTWTG5ILJ_cjs.logger.debug(`inngest send-stamp failed: ${describeError(error)}`);
107
- }
75
+ return stampSendEvents(args.payloads, (payloads) => ({ payloads }));
108
76
  }
109
77
  };
110
78
  }
@@ -112,21 +80,157 @@ function ezlogsInngestMiddleware() {
112
80
  }
113
81
  });
114
82
  }
83
+ function inngestV4Hooks() {
84
+ let runError = null;
85
+ let ranStep = null;
86
+ let executed = false;
87
+ return {
88
+ id: "ezlogs-nextjs",
89
+ // Before the function sees (and Inngest validates) its events: our keys
90
+ // are removed, so a trigger or `waitForEvent` with a strict schema
91
+ // still accepts them. The scope was opened from the request body.
92
+ transformFunctionInput(arg) {
93
+ executed = true;
94
+ try {
95
+ return withoutCarriedKeysInInput(arg);
96
+ } catch (error) {
97
+ chunkTWTG5ILJ_cjs.logger.debug(`inngest input strip failed: ${describeError(error)}`);
98
+ return arg;
99
+ }
100
+ },
101
+ // Called for `inngest.send` and `step.sendEvent`; returns the arg with stamped copies.
102
+ transformSendEvent(args) {
103
+ return stampSendEvents(args?.events, (events) => ({ ...args, events })) ?? args;
104
+ },
105
+ // Only for steps that run in this request (`step.run`, `step.sendEvent`), not memoized ones.
106
+ onStepStart(args) {
107
+ const options = args?.stepInfo?.options;
108
+ const name = options?.name ?? options?.id;
109
+ ranStep = typeof name === "string" && name ? name : null;
110
+ },
111
+ onStepError(args) {
112
+ runError = args?.error ?? runError;
113
+ },
114
+ onRunError(args) {
115
+ runError = args?.error ?? runError;
116
+ },
117
+ async wrapRequest(args) {
118
+ let nextCalled = false;
119
+ const next = () => {
120
+ nextCalled = true;
121
+ return args.next();
122
+ };
123
+ try {
124
+ const body = args.fn ? await args.requestInfo?.body?.() : null;
125
+ if (!body || typeof body !== "object") return await next();
126
+ const fnId = functionId(args.fn) ?? "inngest-function";
127
+ const event = body.event;
128
+ const attempt = typeof body.ctx?.attempt === "number" ? body.ctx.attempt : 0;
129
+ const runId = args.runId || body.ctx?.run_id || null;
130
+ return await runInsideInngestCorrelation(event, () => insideV4Run.run(true, async () => {
131
+ const startedAt = /* @__PURE__ */ new Date();
132
+ try {
133
+ return await next();
134
+ } catch (error) {
135
+ runError = error;
136
+ throw error;
137
+ } finally {
138
+ if (executed) {
139
+ chunkCHVJ4WPM_cjs.markJobDelivery();
140
+ chunkKOFR5OC3_cjs.emitJobEvent({
141
+ jobClass: fnId,
142
+ jobId: runId,
143
+ queue: event?.name ?? null,
144
+ step: ranStep,
145
+ retryCount: attempt,
146
+ outcome: runError ? "failure" : "success",
147
+ errorMessage: runError ? formatError(runError) : null,
148
+ durationMs: Date.now() - startedAt.getTime(),
149
+ startedAt,
150
+ payload: event?.data
151
+ });
152
+ }
153
+ }
154
+ }));
155
+ } catch (error) {
156
+ if (nextCalled) throw error;
157
+ chunkTWTG5ILJ_cjs.logger.debug(`inngest capture failed: ${describeError(error)}`);
158
+ return args.next();
159
+ }
160
+ }
161
+ };
162
+ }
163
+ function withoutCarriedKeysInInput(arg) {
164
+ const ctx = arg?.ctx;
165
+ if (!ctx) return arg;
166
+ let changed = false;
167
+ const strip = (value) => {
168
+ const out = withoutCarriedKeys(value);
169
+ if (out !== value) changed = true;
170
+ return out;
171
+ };
172
+ const event = strip(ctx.event);
173
+ const events = Array.isArray(ctx.events) ? ctx.events.map(strip) : ctx.events;
174
+ const steps = {};
175
+ for (const [id, step] of Object.entries(arg.steps ?? {})) {
176
+ steps[id] = step?.type === "data" ? { ...step, data: strip(step.data) } : step;
177
+ }
178
+ return changed ? { ...arg, ctx: { ...ctx, event, events }, steps } : arg;
179
+ }
180
+ function withoutCarriedKeys(event) {
181
+ const data = event?.data;
182
+ if (!data || typeof data !== "object" || Array.isArray(data)) return event;
183
+ if (!(chunkKOFR5OC3_cjs.CORRELATION_PAYLOAD_KEY in data) && !(chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY in data)) return event;
184
+ const rest = { ...data };
185
+ delete rest[chunkKOFR5OC3_cjs.CORRELATION_PAYLOAD_KEY];
186
+ delete rest[chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY];
187
+ return { ...event, data: rest };
188
+ }
189
+ function stampSendEvents(events, wrap) {
190
+ try {
191
+ const id = chunk2YCQFLXW_cjs.current();
192
+ if (!id) return;
193
+ if (!Array.isArray(events)) return;
194
+ const stamped = [];
195
+ const payloads = events.map((payload) => {
196
+ if (!payload || typeof payload !== "object") return payload;
197
+ const data = payload.data ?? {};
198
+ if (typeof data !== "object" || data === null || Array.isArray(data)) {
199
+ return payload;
200
+ }
201
+ if (typeof data.ezlogs_correlation_id === "string") {
202
+ return payload;
203
+ }
204
+ const copy = { ...data, ezlogs_correlation_id: id };
205
+ if (!(chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY in copy)) stamped.push(copy);
206
+ return { ...payload, data: copy };
207
+ });
208
+ const pending = stamped.length > 0 ? chunkKOFR5OC3_cjs.signedActorToken(id) : null;
209
+ if (!pending) return wrap(payloads);
210
+ return pending.then((token) => {
211
+ if (token) for (const data of stamped) data[chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY] = token;
212
+ return wrap(payloads);
213
+ });
214
+ } catch (error) {
215
+ chunkTWTG5ILJ_cjs.logger.debug(`inngest send-stamp failed: ${describeError(error)}`);
216
+ }
217
+ }
115
218
  async function runInsideInngestCorrelation(event, callback) {
116
- const carried = chunk65HRY3PW_cjs.extractCorrelationFromPayload(event?.data);
117
- const id = carried ?? chunkB5ZUQULZ_cjs.generate();
118
- const token = event?.data?.[chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY];
119
- const actor = carried && token !== void 0 ? await chunk65HRY3PW_cjs.readActorToken(token, carried) : null;
219
+ if (insideV4Run.read()) return callback();
220
+ const carried = chunkKOFR5OC3_cjs.extractCorrelationFromPayload(event?.data);
221
+ const id = carried ?? chunk2YCQFLXW_cjs.generate();
222
+ const token = event?.data?.[chunkKOFR5OC3_cjs.ACTOR_PAYLOAD_KEY];
223
+ const actor = carried && token !== void 0 ? await chunkKOFR5OC3_cjs.readActorToken(token, carried) : null;
120
224
  const startedAt = /* @__PURE__ */ new Date();
121
225
  const body = async () => {
122
226
  try {
123
227
  return await callback();
124
228
  } finally {
125
- await chunk65HRY3PW_cjs.flushJobAuditLog(startedAt);
229
+ await chunkKOFR5OC3_cjs.flushJobAuditLog(startedAt);
126
230
  }
127
231
  };
128
- const scoped = () => body().finally(chunkB5ZUQULZ_cjs.endCorrelationScope);
129
- return chunkB5ZUQULZ_cjs.runWithCorrelation(id, () => chunkB5ZUQULZ_cjs.runWithActorScope(scoped, actor));
232
+ const scoped = () => body().finally(chunk2YCQFLXW_cjs.endCorrelationScope);
233
+ return chunk2YCQFLXW_cjs.runWithCorrelation(id, () => chunk2YCQFLXW_cjs.runWithActorScope(scoped, actor));
130
234
  }
131
235
  function functionId(fn) {
132
236
  try {
@@ -1,21 +1,21 @@
1
1
  /**
2
- * Returns an Inngest v3 middleware. Pass it via:
2
+ * Returns an Inngest middleware for v3 and v4. Pass it via:
3
3
  * new Inngest({ middleware: [ezlogsInngestMiddleware()] })
4
4
  *
5
5
  * Returned `unknown` because Inngest's `Middleware` type is parameterized
6
6
  * over the client and we don't want to take a hard type dep.
7
7
  *
8
- * Inngest v4 has a different middleware API (a class it calls `new`
9
- * on) that this adapter doesn't support. There the middleware does
10
- * nothing and warns once, instead of crashing `inngest.send`.
8
+ * v3 reads `name` and calls `init()`. v4 calls `new` on it (one
9
+ * instance per request or send), which returns the v4 hooks.
11
10
  */
12
11
  declare function ezlogsInngestMiddleware(): unknown;
13
12
  /**
14
13
  * Run an Inngest function body (or a step) inside the run's
15
14
  * correlation scope, so its DB writes are tagged and emitted under the
16
- * action that sent the event. Inngest middleware can't wrap the body
15
+ * action that sent the event. Inngest v3 middleware can't wrap the body
17
16
  * itself, so without this the job event is captured but the body's DB
18
- * writes ship as their own actions:
17
+ * writes ship as their own actions. Not needed on v4 (the middleware
18
+ * wraps the run), where it is harmless:
19
19
  *
20
20
  * inngest.createFunction({ id: "send-invoice" }, { event: "invoice/created" },
21
21
  * ({ event, step }) => runInsideInngestCorrelation(event, async () => { ... }))
@@ -1,21 +1,21 @@
1
1
  /**
2
- * Returns an Inngest v3 middleware. Pass it via:
2
+ * Returns an Inngest middleware for v3 and v4. Pass it via:
3
3
  * new Inngest({ middleware: [ezlogsInngestMiddleware()] })
4
4
  *
5
5
  * Returned `unknown` because Inngest's `Middleware` type is parameterized
6
6
  * over the client and we don't want to take a hard type dep.
7
7
  *
8
- * Inngest v4 has a different middleware API (a class it calls `new`
9
- * on) that this adapter doesn't support. There the middleware does
10
- * nothing and warns once, instead of crashing `inngest.send`.
8
+ * v3 reads `name` and calls `init()`. v4 calls `new` on it (one
9
+ * instance per request or send), which returns the v4 hooks.
11
10
  */
12
11
  declare function ezlogsInngestMiddleware(): unknown;
13
12
  /**
14
13
  * Run an Inngest function body (or a step) inside the run's
15
14
  * correlation scope, so its DB writes are tagged and emitted under the
16
- * action that sent the event. Inngest middleware can't wrap the body
15
+ * action that sent the event. Inngest v3 middleware can't wrap the body
17
16
  * itself, so without this the job event is captured but the body's DB
18
- * writes ship as their own actions:
17
+ * writes ship as their own actions. Not needed on v4 (the middleware
18
+ * wraps the run), where it is harmless:
19
19
  *
20
20
  * inngest.createFunction({ id: "send-invoice" }, { event: "invoice/created" },
21
21
  * ({ event, step }) => runInsideInngestCorrelation(event, async () => { ... }))