ezlogs-nextjs 0.4.4 → 0.4.6

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 (65) hide show
  1. package/README.md +51 -11
  2. package/dist/actors/index.d.cts +1 -1
  3. package/dist/actors/index.d.ts +1 -1
  4. package/dist/{chunk-Z2TM3LGG.js → chunk-2NFJOT6Q.js} +1 -1
  5. package/dist/{chunk-R6IWVTX3.cjs → chunk-65HRY3PW.cjs} +31 -21
  6. package/dist/{chunk-YXZZNZG6.cjs → chunk-B3WST6ES.cjs} +9 -9
  7. package/dist/{chunk-MMLQXSSD.cjs → chunk-B5ZUQULZ.cjs} +18 -11
  8. package/dist/{chunk-NX4EL7BY.cjs → chunk-DM2EAOSF.cjs} +4 -4
  9. package/dist/chunk-DRE2VXFX.js +19 -0
  10. package/dist/chunk-H3FC5HMW.cjs +16 -0
  11. package/dist/{chunk-GI6BM4MR.js → chunk-IBSNHBUC.js} +18 -12
  12. package/dist/chunk-JWJKFZBW.js +52 -0
  13. package/dist/{chunk-MHBS5FEP.js → chunk-M3VBQ5KT.js} +27 -4
  14. package/dist/chunk-NFZ5OKF3.cjs +22 -0
  15. package/dist/{chunk-GMHOUAKD.cjs → chunk-O7SFYXJC.cjs} +37 -13
  16. package/dist/{chunk-U22T7QYY.js → chunk-PK2Z2ABL.js} +13 -3
  17. package/dist/{chunk-YMIGZYFH.js → chunk-RD47JECJ.js} +1 -1
  18. package/dist/chunk-RMKGMIV2.js +13 -0
  19. package/dist/{chunk-NINIAL7M.js → chunk-U3IJV5EJ.js} +1 -1
  20. package/dist/chunk-VJR4VB4B.cjs +56 -0
  21. package/dist/{chunk-PS4U2GFJ.cjs → chunk-YO6E763S.cjs} +5 -5
  22. package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
  23. package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
  24. package/dist/db/drizzle.cjs +3 -3
  25. package/dist/db/drizzle.js +2 -2
  26. package/dist/db/postgres-js.cjs +4 -4
  27. package/dist/db/postgres-js.js +2 -2
  28. package/dist/db/prisma.cjs +12 -12
  29. package/dist/db/prisma.js +2 -2
  30. package/dist/db/supabase.cjs +42 -17
  31. package/dist/db/supabase.d.cts +11 -5
  32. package/dist/db/supabase.d.ts +11 -5
  33. package/dist/db/supabase.js +33 -9
  34. package/dist/index.cjs +288 -142
  35. package/dist/index.d.cts +2 -2
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +198 -52
  38. package/dist/jobs/bullmq.cjs +44 -16
  39. package/dist/jobs/bullmq.d.cts +7 -1
  40. package/dist/jobs/bullmq.d.ts +7 -1
  41. package/dist/jobs/bullmq.js +33 -6
  42. package/dist/jobs/inngest.cjs +36 -17
  43. package/dist/jobs/inngest.d.cts +7 -1
  44. package/dist/jobs/inngest.d.ts +7 -1
  45. package/dist/jobs/inngest.js +23 -5
  46. package/dist/jobs/supabase-queues.cjs +9 -9
  47. package/dist/jobs/supabase-queues.js +4 -4
  48. package/dist/jobs/trigger.cjs +7 -7
  49. package/dist/jobs/trigger.js +4 -4
  50. package/dist/jobs/upstash-workflow.cjs +139 -23
  51. package/dist/jobs/upstash-workflow.d.cts +20 -2
  52. package/dist/jobs/upstash-workflow.d.ts +20 -2
  53. package/dist/jobs/upstash-workflow.js +129 -14
  54. package/dist/nextjs-plugin/index.cjs +46 -29
  55. package/dist/nextjs-plugin/index.js +46 -29
  56. package/dist/nextjs-plugin/loader.cjs +70 -60
  57. package/dist/nextjs-plugin/loader.d.cts +18 -1
  58. package/dist/nextjs-plugin/loader.d.ts +18 -1
  59. package/dist/nextjs-plugin/loader.js +70 -61
  60. package/dist/triggers/index.cjs +22 -16
  61. package/dist/triggers/index.d.cts +0 -10
  62. package/dist/triggers/index.d.ts +0 -10
  63. package/dist/triggers/index.js +11 -5
  64. package/package.json +1 -1
  65. package/sql/postgres/00_install.sql +20 -3
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkR6IWVTX3_cjs = require('../chunk-R6IWVTX3.cjs');
4
- require('../chunk-GMHOUAKD.cjs');
5
- require('../chunk-YXZZNZG6.cjs');
6
- var chunkMMLQXSSD_cjs = require('../chunk-MMLQXSSD.cjs');
3
+ var chunkH3FC5HMW_cjs = require('../chunk-H3FC5HMW.cjs');
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');
7
9
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
8
10
  require('../chunk-ZDSQYCYV.cjs');
9
11
 
@@ -27,27 +29,31 @@ function ezlogsInngestMiddleware() {
27
29
  // one function). Returns per-run hooks that fire as the run
28
30
  // proceeds. We track the run via closure-scoped state.
29
31
  onFunctionRun(args) {
32
+ chunkH3FC5HMW_cjs.markJobDelivery();
30
33
  const fnId = functionId(args.fn) ?? "inngest-function";
31
34
  const runId = args.ctx?.runId ?? null;
32
35
  const attempt = typeof args.ctx?.attempt === "number" ? args.ctx.attempt : 0;
33
36
  const eventName = args.ctx?.event?.name ?? null;
34
37
  const eventData = args.ctx?.event?.data;
35
- const correlationId = chunkR6IWVTX3_cjs.extractCorrelationFromPayload(args.ctx?.event?.data) ?? chunkMMLQXSSD_cjs.generate();
38
+ const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(args.ctx?.event?.data) ?? chunkB5ZUQULZ_cjs.generate();
36
39
  const startedAt = /* @__PURE__ */ new Date();
37
40
  const startMs = startedAt.getTime();
38
41
  return {
39
42
  // Inngest calls this once after the function body returns
40
43
  // (success) or throws (failure surfaces via result.error).
44
+ // `step`: the step this execution ran (none on the one where the function returns).
41
45
  transformOutput(args2) {
42
46
  try {
43
47
  const result = args2.result;
44
48
  const error = result?.error;
45
49
  const outcome = error ? "failure" : "success";
46
50
  const errorMessage = error ? formatError(error) : null;
47
- chunkR6IWVTX3_cjs.emitJobEvent({
51
+ const ranStep = args2.step?.displayName ?? args2.step?.name;
52
+ chunk65HRY3PW_cjs.emitJobEvent({
48
53
  jobClass: fnId,
49
54
  jobId: runId,
50
55
  queue: eventName,
56
+ step: typeof ranStep === "string" && ranStep ? ranStep : null,
51
57
  retryCount: attempt,
52
58
  correlationId,
53
59
  outcome,
@@ -73,7 +79,7 @@ function ezlogsInngestMiddleware() {
73
79
  // would carry the first request's id and actor).
74
80
  transformInput(args) {
75
81
  try {
76
- const id = chunkMMLQXSSD_cjs.current();
82
+ const id = chunkB5ZUQULZ_cjs.current();
77
83
  if (!id) return;
78
84
  if (!Array.isArray(args.payloads)) return;
79
85
  const stamped = [];
@@ -87,13 +93,13 @@ function ezlogsInngestMiddleware() {
87
93
  return payload;
88
94
  }
89
95
  const copy = { ...data, ezlogs_correlation_id: id };
90
- if (!(chunkR6IWVTX3_cjs.ACTOR_PAYLOAD_KEY in copy)) stamped.push(copy);
96
+ if (!(chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY in copy)) stamped.push(copy);
91
97
  return { ...payload, data: copy };
92
98
  });
93
- const pending = stamped.length > 0 ? chunkR6IWVTX3_cjs.signedActorToken(id) : null;
99
+ const pending = stamped.length > 0 ? chunk65HRY3PW_cjs.signedActorToken(id) : null;
94
100
  if (!pending) return { payloads };
95
101
  return pending.then((token) => {
96
- if (token) for (const data of stamped) data[chunkR6IWVTX3_cjs.ACTOR_PAYLOAD_KEY] = token;
102
+ if (token) for (const data of stamped) data[chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY] = token;
97
103
  return { payloads };
98
104
  });
99
105
  } catch (error) {
@@ -107,20 +113,20 @@ function ezlogsInngestMiddleware() {
107
113
  });
108
114
  }
109
115
  async function runInsideInngestCorrelation(event, callback) {
110
- const carried = chunkR6IWVTX3_cjs.extractCorrelationFromPayload(event?.data);
111
- const id = carried ?? chunkMMLQXSSD_cjs.generate();
112
- const token = event?.data?.[chunkR6IWVTX3_cjs.ACTOR_PAYLOAD_KEY];
113
- const actor = carried && token !== void 0 ? await chunkR6IWVTX3_cjs.readActorToken(token, carried) : null;
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;
114
120
  const startedAt = /* @__PURE__ */ new Date();
115
121
  const body = async () => {
116
122
  try {
117
123
  return await callback();
118
124
  } finally {
119
- await chunkR6IWVTX3_cjs.flushJobAuditLog(startedAt);
125
+ await chunk65HRY3PW_cjs.flushJobAuditLog(startedAt);
120
126
  }
121
127
  };
122
- const scoped = () => body().finally(chunkMMLQXSSD_cjs.endCorrelationScope);
123
- return chunkMMLQXSSD_cjs.runWithCorrelation(id, () => chunkMMLQXSSD_cjs.runWithActorScope(scoped, actor));
128
+ const scoped = () => body().finally(chunkB5ZUQULZ_cjs.endCorrelationScope);
129
+ return chunkB5ZUQULZ_cjs.runWithCorrelation(id, () => chunkB5ZUQULZ_cjs.runWithActorScope(scoped, actor));
124
130
  }
125
131
  function functionId(fn) {
126
132
  try {
@@ -145,6 +151,19 @@ function describeError(error) {
145
151
  if (error instanceof Error) return `${error.name}: ${error.message}`;
146
152
  return String(error);
147
153
  }
154
+ function withEzlogsMiddleware(args) {
155
+ const [options, ...rest] = args;
156
+ if (!options || typeof options !== "object" || Array.isArray(options)) return args;
157
+ const opts = options;
158
+ const existing = Array.isArray(opts.middleware) ? opts.middleware : opts.middleware == null ? [] : null;
159
+ if (existing === null) return args;
160
+ if (existing.some((m) => m?.name === "ezlogs-nextjs")) return args;
161
+ return [{ ...opts, middleware: [...existing, ezlogsInngestMiddleware()] }, ...rest];
162
+ }
163
+ var __ezlogsInstrument = chunkVJR4VB4B_cjs.instrumentFrom({
164
+ "inngest#Inngest": (original) => chunkVJR4VB4B_cjs.instrumentClass(original, (client) => client, withEzlogsMiddleware)
165
+ });
148
166
 
167
+ exports.__ezlogsInstrument = __ezlogsInstrument;
149
168
  exports.ezlogsInngestMiddleware = ezlogsInngestMiddleware;
150
169
  exports.runInsideInngestCorrelation = runInsideInngestCorrelation;
@@ -23,5 +23,11 @@ declare function ezlogsInngestMiddleware(): unknown;
23
23
  declare function runInsideInngestCorrelation<T>(event: {
24
24
  data?: unknown;
25
25
  } | undefined, callback: () => Promise<T>): Promise<T>;
26
+ /**
27
+ * Replacements for the plugin's instrumented imports (instrument.ts):
28
+ * every Inngest client the app's server code constructs gets
29
+ * ezlogsInngestMiddleware. Internal: called by build-time generated code.
30
+ */
31
+ declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
26
32
 
27
- export { ezlogsInngestMiddleware, runInsideInngestCorrelation };
33
+ export { __ezlogsInstrument, ezlogsInngestMiddleware, runInsideInngestCorrelation };
@@ -23,5 +23,11 @@ declare function ezlogsInngestMiddleware(): unknown;
23
23
  declare function runInsideInngestCorrelation<T>(event: {
24
24
  data?: unknown;
25
25
  } | undefined, callback: () => Promise<T>): Promise<T>;
26
+ /**
27
+ * Replacements for the plugin's instrumented imports (instrument.ts):
28
+ * every Inngest client the app's server code constructs gets
29
+ * ezlogsInngestMiddleware. Internal: called by build-time generated code.
30
+ */
31
+ declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
26
32
 
27
- export { ezlogsInngestMiddleware, runInsideInngestCorrelation };
33
+ export { __ezlogsInstrument, ezlogsInngestMiddleware, runInsideInngestCorrelation };
@@ -1,7 +1,9 @@
1
- import { ACTOR_PAYLOAD_KEY, signedActorToken, extractCorrelationFromPayload, emitJobEvent, readActorToken, flushJobAuditLog } from '../chunk-U22T7QYY.js';
2
- import '../chunk-MHBS5FEP.js';
3
- import '../chunk-NINIAL7M.js';
4
- import { current, generate, runWithCorrelation, runWithActorScope, endCorrelationScope } from '../chunk-GI6BM4MR.js';
1
+ import { markJobDelivery } from '../chunk-RMKGMIV2.js';
2
+ import { instrumentFrom, instrumentClass } from '../chunk-JWJKFZBW.js';
3
+ import { ACTOR_PAYLOAD_KEY, signedActorToken, extractCorrelationFromPayload, emitJobEvent, readActorToken, flushJobAuditLog } from '../chunk-PK2Z2ABL.js';
4
+ import '../chunk-M3VBQ5KT.js';
5
+ import '../chunk-U3IJV5EJ.js';
6
+ import { current, generate, runWithCorrelation, runWithActorScope, endCorrelationScope } from '../chunk-IBSNHBUC.js';
5
7
  import { logger } from '../chunk-FCFVIRQF.js';
6
8
  import '../chunk-SIAA4J6H.js';
7
9
 
@@ -25,6 +27,7 @@ function ezlogsInngestMiddleware() {
25
27
  // one function). Returns per-run hooks that fire as the run
26
28
  // proceeds. We track the run via closure-scoped state.
27
29
  onFunctionRun(args) {
30
+ markJobDelivery();
28
31
  const fnId = functionId(args.fn) ?? "inngest-function";
29
32
  const runId = args.ctx?.runId ?? null;
30
33
  const attempt = typeof args.ctx?.attempt === "number" ? args.ctx.attempt : 0;
@@ -36,16 +39,19 @@ function ezlogsInngestMiddleware() {
36
39
  return {
37
40
  // Inngest calls this once after the function body returns
38
41
  // (success) or throws (failure surfaces via result.error).
42
+ // `step`: the step this execution ran (none on the one where the function returns).
39
43
  transformOutput(args2) {
40
44
  try {
41
45
  const result = args2.result;
42
46
  const error = result?.error;
43
47
  const outcome = error ? "failure" : "success";
44
48
  const errorMessage = error ? formatError(error) : null;
49
+ const ranStep = args2.step?.displayName ?? args2.step?.name;
45
50
  emitJobEvent({
46
51
  jobClass: fnId,
47
52
  jobId: runId,
48
53
  queue: eventName,
54
+ step: typeof ranStep === "string" && ranStep ? ranStep : null,
49
55
  retryCount: attempt,
50
56
  correlationId,
51
57
  outcome,
@@ -143,5 +149,17 @@ function describeError(error) {
143
149
  if (error instanceof Error) return `${error.name}: ${error.message}`;
144
150
  return String(error);
145
151
  }
152
+ function withEzlogsMiddleware(args) {
153
+ const [options, ...rest] = args;
154
+ if (!options || typeof options !== "object" || Array.isArray(options)) return args;
155
+ const opts = options;
156
+ const existing = Array.isArray(opts.middleware) ? opts.middleware : opts.middleware == null ? [] : null;
157
+ if (existing === null) return args;
158
+ if (existing.some((m) => m?.name === "ezlogs-nextjs")) return args;
159
+ return [{ ...opts, middleware: [...existing, ezlogsInngestMiddleware()] }, ...rest];
160
+ }
161
+ var __ezlogsInstrument = instrumentFrom({
162
+ "inngest#Inngest": (original) => instrumentClass(original, (client) => client, withEzlogsMiddleware)
163
+ });
146
164
 
147
- export { ezlogsInngestMiddleware, runInsideInngestCorrelation };
165
+ export { __ezlogsInstrument, ezlogsInngestMiddleware, runInsideInngestCorrelation };
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkR6IWVTX3_cjs = require('../chunk-R6IWVTX3.cjs');
4
- require('../chunk-GMHOUAKD.cjs');
5
- require('../chunk-YXZZNZG6.cjs');
6
- require('../chunk-MMLQXSSD.cjs');
3
+ var chunk65HRY3PW_cjs = require('../chunk-65HRY3PW.cjs');
4
+ require('../chunk-O7SFYXJC.cjs');
5
+ require('../chunk-B3WST6ES.cjs');
6
+ require('../chunk-B5ZUQULZ.cjs');
7
7
  require('../chunk-TWTG5ILJ.cjs');
8
8
  require('../chunk-ZDSQYCYV.cjs');
9
9
 
@@ -41,21 +41,21 @@ function wrapPgmqSchema(schema) {
41
41
  }
42
42
  function stampPgmqMessage(args) {
43
43
  if ("message" in args && isPlainObject(args.message)) {
44
- return { ...args, message: chunkR6IWVTX3_cjs.stampCorrelationOnPayload(args.message) };
44
+ return { ...args, message: chunk65HRY3PW_cjs.stampCorrelationOnPayload(args.message) };
45
45
  }
46
46
  if (Array.isArray(args.messages)) {
47
47
  return {
48
48
  ...args,
49
49
  messages: args.messages.map(
50
- (msg) => isPlainObject(msg) ? chunkR6IWVTX3_cjs.stampCorrelationOnPayload(msg) : msg
50
+ (msg) => isPlainObject(msg) ? chunk65HRY3PW_cjs.stampCorrelationOnPayload(msg) : msg
51
51
  )
52
52
  };
53
53
  }
54
54
  return args;
55
55
  }
56
56
  async function captureQueueMessage(meta, work) {
57
- const correlationId = chunkR6IWVTX3_cjs.extractCorrelationFromPayload(meta.message);
58
- return chunkR6IWVTX3_cjs.runJobWithCapture(
57
+ const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(meta.message);
58
+ return chunk65HRY3PW_cjs.runJobWithCapture(
59
59
  {
60
60
  jobClass: meta.queueName,
61
61
  jobId: meta.messageId !== void 0 && meta.messageId !== null ? String(meta.messageId) : null,
@@ -69,7 +69,7 @@ async function captureQueueMessage(meta, work) {
69
69
  }
70
70
  function stampPgmqPayload(message) {
71
71
  if (!isPlainObject(message)) return message;
72
- return chunkR6IWVTX3_cjs.stampCorrelationOnPayload(message);
72
+ return chunk65HRY3PW_cjs.stampCorrelationOnPayload(message);
73
73
  }
74
74
  function isPlainObject(value) {
75
75
  if (value === null || typeof value !== "object") return false;
@@ -1,7 +1,7 @@
1
- import { extractCorrelationFromPayload, runJobWithCapture, stampCorrelationOnPayload } from '../chunk-U22T7QYY.js';
2
- import '../chunk-MHBS5FEP.js';
3
- import '../chunk-NINIAL7M.js';
4
- import '../chunk-GI6BM4MR.js';
1
+ import { extractCorrelationFromPayload, runJobWithCapture, stampCorrelationOnPayload } from '../chunk-PK2Z2ABL.js';
2
+ import '../chunk-M3VBQ5KT.js';
3
+ import '../chunk-U3IJV5EJ.js';
4
+ import '../chunk-IBSNHBUC.js';
5
5
  import '../chunk-FCFVIRQF.js';
6
6
  import '../chunk-SIAA4J6H.js';
7
7
 
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkR6IWVTX3_cjs = require('../chunk-R6IWVTX3.cjs');
4
- require('../chunk-GMHOUAKD.cjs');
5
- require('../chunk-YXZZNZG6.cjs');
6
- var chunkMMLQXSSD_cjs = require('../chunk-MMLQXSSD.cjs');
3
+ var chunk65HRY3PW_cjs = require('../chunk-65HRY3PW.cjs');
4
+ require('../chunk-O7SFYXJC.cjs');
5
+ require('../chunk-B3WST6ES.cjs');
6
+ var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
7
7
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
8
8
  require('../chunk-ZDSQYCYV.cjs');
9
9
 
@@ -31,20 +31,20 @@ async function runWithEzlogsCapture(params) {
31
31
  const queueName = ctx.run?.queue?.name ?? null;
32
32
  const attemptNumber = ctx.attempt?.number ?? 1;
33
33
  const retryCount = Math.max(0, attemptNumber - 1);
34
- return chunkR6IWVTX3_cjs.runJobWithCapture(
34
+ return chunk65HRY3PW_cjs.runJobWithCapture(
35
35
  {
36
36
  jobClass: taskId,
37
37
  jobId: runId,
38
38
  queue: queueName,
39
39
  retryCount,
40
- correlationId: chunkR6IWVTX3_cjs.extractCorrelationFromPayload(params.payload),
40
+ correlationId: chunk65HRY3PW_cjs.extractCorrelationFromPayload(params.payload),
41
41
  payload: params.payload
42
42
  },
43
43
  () => params.next()
44
44
  );
45
45
  }
46
46
  function stampPayloadForTrigger(payload) {
47
- const id = chunkMMLQXSSD_cjs.current();
47
+ const id = chunkB5ZUQULZ_cjs.current();
48
48
  if (!id) return payload;
49
49
  if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
50
50
  return payload;
@@ -1,7 +1,7 @@
1
- import { runJobWithCapture, extractCorrelationFromPayload } from '../chunk-U22T7QYY.js';
2
- import '../chunk-MHBS5FEP.js';
3
- import '../chunk-NINIAL7M.js';
4
- import { current } from '../chunk-GI6BM4MR.js';
1
+ import { runJobWithCapture, extractCorrelationFromPayload } from '../chunk-PK2Z2ABL.js';
2
+ import '../chunk-M3VBQ5KT.js';
3
+ import '../chunk-U3IJV5EJ.js';
4
+ import { current } from '../chunk-IBSNHBUC.js';
5
5
  import { logger } from '../chunk-FCFVIRQF.js';
6
6
  import '../chunk-SIAA4J6H.js';
7
7
 
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkR6IWVTX3_cjs = require('../chunk-R6IWVTX3.cjs');
4
- require('../chunk-GMHOUAKD.cjs');
5
- require('../chunk-YXZZNZG6.cjs');
6
- var chunkMMLQXSSD_cjs = require('../chunk-MMLQXSSD.cjs');
3
+ var chunkH3FC5HMW_cjs = require('../chunk-H3FC5HMW.cjs');
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');
7
9
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
8
10
  require('../chunk-ZDSQYCYV.cjs');
9
11
 
@@ -29,7 +31,7 @@ function wrapWorkflowClient(client) {
29
31
  if (typeof client.trigger === "function") {
30
32
  const original = client.trigger.bind(client);
31
33
  client.trigger = async (params) => {
32
- if (chunkMMLQXSSD_cjs.current()) await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
34
+ if (chunkB5ZUQULZ_cjs.current()) await chunkB5ZUQULZ_cjs.maybeExtractSupabaseActor();
33
35
  return original(
34
36
  Array.isArray(params) ? await Promise.all(params.map(stampTriggerOptions)) : await stampTriggerOptions(params)
35
37
  );
@@ -43,14 +45,14 @@ function wrapWorkflowClient(client) {
43
45
  return client;
44
46
  }
45
47
  async function stampTriggerOptions(options) {
46
- const current2 = chunkMMLQXSSD_cjs.current();
48
+ const current2 = chunkB5ZUQULZ_cjs.current();
47
49
  if (!current2 || !options || typeof options !== "object") return options;
48
50
  const opts = options;
49
51
  const headers = { ...opts.headers ?? {} };
50
52
  const supplied = Object.keys(headers).find((k) => k.toLowerCase() === CORRELATION_HEADER);
51
53
  const id = supplied ? headers[supplied] : current2;
52
54
  if (!supplied) headers[CORRELATION_HEADER] = id;
53
- const token = AGENT_CORRELATION_ID.test(id) ? await chunkR6IWVTX3_cjs.actorToken(id) : null;
55
+ const token = AGENT_CORRELATION_ID.test(id) ? await chunk65HRY3PW_cjs.actorToken(id) : null;
54
56
  if (token && !Object.keys(headers).some((k) => k.toLowerCase() === ACTOR_HEADER)) {
55
57
  headers[ACTOR_HEADER] = token;
56
58
  }
@@ -75,43 +77,150 @@ function wrapQStashClient(client) {
75
77
  return client;
76
78
  }
77
79
  async function stampPublishRequest(request) {
78
- const id = chunkMMLQXSSD_cjs.current();
80
+ const id = chunkB5ZUQULZ_cjs.current();
79
81
  if (!id || !request || typeof request !== "object") return request;
80
82
  const headerKey = `${FORWARD_PREFIX}${CORRELATION_HEADER}`;
81
83
  const raw = request.headers;
82
84
  const headers = raw instanceof Headers || Array.isArray(raw) ? Object.fromEntries(new Headers(raw)) : { ...raw ?? {} };
83
85
  if (Object.keys(headers).some((key) => key.toLowerCase() === headerKey)) return request;
84
86
  headers[headerKey] = id;
85
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
86
- const token = await chunkR6IWVTX3_cjs.actorToken(id);
87
+ await chunkB5ZUQULZ_cjs.maybeExtractSupabaseActor();
88
+ const token = await chunk65HRY3PW_cjs.actorToken(id);
87
89
  if (token) headers[`${FORWARD_PREFIX}${ACTOR_HEADER}`] = token;
88
90
  return { ...request, headers };
89
91
  }
92
+ var warnedNoHeaders = false;
90
93
  async function captureWorkflowRequest(meta, work) {
91
- const headers = meta.request.headers;
92
- const correlationId = readCorrelationFromHeaders(headers);
93
- const runId = readHeader(headers, "upstash-workflow-runid");
94
+ if (meta.context?.disabled === true) return work();
95
+ chunkH3FC5HMW_cjs.markJobDelivery();
96
+ if (insideStepCapture.read()) return work();
97
+ const headers = meta.request?.headers ?? meta.context?.headers;
98
+ if (!headers) {
99
+ if (!warnedNoHeaders) {
100
+ warnedNoHeaders = true;
101
+ chunkTWTG5ILJ_cjs.logger.warn(
102
+ "captureWorkflowRequest got no headers (pass { context, workflowName }); this step runs without capture"
103
+ );
104
+ }
105
+ return work();
106
+ }
107
+ const runId = readHeader(headers, "upstash-workflow-runid") ?? meta.context?.workflowRunId ?? null;
108
+ const correlationId = readCorrelationFromHeaders(headers) ?? correlationFromRunId(runId);
94
109
  const retried = parseRetried(readHeader(headers, "upstash-retried"));
95
- const actor = correlationId ? await chunkR6IWVTX3_cjs.readActorToken(
110
+ const actor = correlationId ? await chunk65HRY3PW_cjs.readActorToken(
96
111
  readHeader(headers, ACTOR_HEADER) ?? readHeader(headers, `${FORWARD_PREFIX}${ACTOR_HEADER}`),
97
112
  correlationId
98
- ) ?? await chunkR6IWVTX3_cjs.readActorToken(runId ? AGENT_RUN_ID.exec(runId)?.[2] : null, correlationId) : null;
99
- return chunkR6IWVTX3_cjs.runJobWithCapture(
113
+ ) ?? await chunk65HRY3PW_cjs.readActorToken(runId ? AGENT_RUN_ID.exec(runId)?.[2] : null, correlationId) : null;
114
+ return insideStepCapture.run(true, () => chunk65HRY3PW_cjs.runJobWithCapture(
100
115
  {
101
116
  jobClass: meta.workflowName,
102
117
  jobId: runId,
103
118
  queue: meta.stepName ?? meta.workflowName,
119
+ step: () => meta.ranStep?.() ?? meta.stepName ?? null,
104
120
  retryCount: retried,
105
121
  correlationId,
106
- actor
122
+ actor,
123
+ // The SDK ends each delivery by throwing: WorkflowAbort after a
124
+ // step ran (and WorkflowCancelAbort on context.cancel()) is a
125
+ // finished step, WorkflowAuthError is its signature probe that
126
+ // runs no step. Only other errors are failures.
127
+ isControlFlow: (error) => errorName(error) === "WorkflowAuthError",
128
+ isSuccessfulExit: (error) => SUCCESSFUL_EXITS.has(errorName(error))
107
129
  },
108
130
  work
109
- );
131
+ ));
132
+ }
133
+ var insideStepCapture = chunkB5ZUQULZ_cjs.createScopedStorage(/* @__PURE__ */ Symbol.for("ezlogs-nextjs:upstash-step-capture"));
134
+ function workflowNameOf(context) {
135
+ try {
136
+ if (typeof context.url === "string") return new URL(context.url).pathname;
137
+ } catch {
138
+ }
139
+ return "upstash-workflow";
110
140
  }
141
+ function captureRouteFunction(routeFunction) {
142
+ if (typeof routeFunction !== "function") return routeFunction;
143
+ const run = routeFunction;
144
+ return function ezlogsWorkflowStep(context, ...rest) {
145
+ if (!context || typeof context !== "object" || !context.headers) return run.call(this, context, ...rest);
146
+ const ran = {};
147
+ const watched = watchRunSteps(context, ran);
148
+ return captureWorkflowRequest(
149
+ { context, workflowName: workflowNameOf(context), ranStep: () => ran.step },
150
+ () => run.call(this, watched, ...rest)
151
+ );
152
+ };
153
+ }
154
+ function watchRunSteps(context, ran) {
155
+ if (typeof context.run !== "function") return context;
156
+ try {
157
+ return new Proxy(context, {
158
+ get(target, key) {
159
+ const value = Reflect.get(target, key, target);
160
+ if (typeof value !== "function") return value;
161
+ if (key !== "run") return value.bind(target);
162
+ const run = value;
163
+ return (name, fn, ...rest) => {
164
+ if (typeof fn !== "function") return run.call(target, name, fn, ...rest);
165
+ const step = fn;
166
+ return run.call(target, name, (...args) => {
167
+ if (typeof name === "string" && ran.step === void 0) ran.step = name;
168
+ return step(...args);
169
+ }, ...rest);
170
+ };
171
+ }
172
+ });
173
+ } catch {
174
+ return context;
175
+ }
176
+ }
177
+ function instrumentServe(original) {
178
+ if (typeof original !== "function") return original;
179
+ const serve = original;
180
+ return function ezlogsServe(routeFunction, ...rest) {
181
+ const served = serve.call(this, captureRouteFunction(routeFunction), ...rest);
182
+ if (!served || typeof served !== "object") return served;
183
+ const handlers = { ...served };
184
+ for (const [name, handler] of Object.entries(handlers)) {
185
+ if (typeof handler !== "function") continue;
186
+ const deliver = handler;
187
+ handlers[name] = function ezlogsDelivery(...args) {
188
+ if (signedByQStash(args[0])) chunkH3FC5HMW_cjs.markJobDelivery();
189
+ return deliver.apply(this, args);
190
+ };
191
+ }
192
+ return handlers;
193
+ };
194
+ }
195
+ function signedByQStash(request) {
196
+ const headers = request?.headers;
197
+ if (!headers || typeof headers !== "object") return false;
198
+ if (typeof headers.get === "function") return Boolean(headers.get("upstash-signature"));
199
+ return Boolean(headers["upstash-signature"]);
200
+ }
201
+ function instrumentCreateWorkflow(original) {
202
+ if (typeof original !== "function") return original;
203
+ const create = original;
204
+ return function ezlogsCreateWorkflow(routeFunction, ...rest) {
205
+ return create.call(this, captureRouteFunction(routeFunction), ...rest);
206
+ };
207
+ }
208
+ var __ezlogsInstrument = chunkVJR4VB4B_cjs.instrumentFrom({
209
+ "@upstash/workflow/nextjs#serve": instrumentServe,
210
+ "@upstash/workflow/nextjs#servePagesRouter": instrumentServe,
211
+ "@upstash/workflow/nextjs#createWorkflow": instrumentCreateWorkflow,
212
+ "@upstash/workflow/nextjs#createWorkflowPagesRouter": instrumentCreateWorkflow,
213
+ // Its workflows come from createWorkflow (captured there); only the handlers are marked.
214
+ "@upstash/workflow/nextjs#serveMany": instrumentServe,
215
+ "@upstash/workflow/nextjs#serveManyPagesRouter": instrumentServe,
216
+ "@upstash/workflow#serve": instrumentServe,
217
+ "@upstash/workflow#Client": (original) => chunkVJR4VB4B_cjs.instrumentClass(original, (client) => wrapWorkflowClient(client)),
218
+ "@upstash/qstash#Client": (original) => chunkVJR4VB4B_cjs.instrumentClass(original, (client) => wrapQStashClient(client))
219
+ });
111
220
  function emitUpstashWorkflowEvent(input) {
112
221
  try {
113
222
  const headers = input.request.headers;
114
- chunkR6IWVTX3_cjs.emitJobEvent({
223
+ chunk65HRY3PW_cjs.emitJobEvent({
115
224
  jobClass: input.workflowName,
116
225
  jobId: readHeader(headers, "upstash-workflow-runid"),
117
226
  queue: input.workflowName,
@@ -129,7 +238,7 @@ function emitUpstashWorkflowEvent(input) {
129
238
  function randomHex(bytes) {
130
239
  const buf = new Uint8Array(bytes);
131
240
  globalThis.crypto.getRandomValues(buf);
132
- return chunkR6IWVTX3_cjs.toHex(buf);
241
+ return chunk65HRY3PW_cjs.toHex(buf);
133
242
  }
134
243
  function readHeader(headers, name) {
135
244
  try {
@@ -139,14 +248,20 @@ function readHeader(headers, name) {
139
248
  return null;
140
249
  }
141
250
  }
251
+ var SUCCESSFUL_EXITS = /* @__PURE__ */ new Set(["WorkflowAbort", "WorkflowCancelAbort"]);
252
+ function errorName(error) {
253
+ return error !== null && typeof error === "object" ? String(error.name ?? "") : "";
254
+ }
255
+ function correlationFromRunId(runId) {
256
+ const fromRunId = runId ? AGENT_RUN_ID.exec(runId)?.[1] : void 0;
257
+ return fromRunId && isAcceptableStepId(fromRunId) ? fromRunId : null;
258
+ }
142
259
  function readCorrelationFromHeaders(headers) {
143
260
  for (const name of [CORRELATION_HEADER, LEGACY_CORRELATION_HEADER]) {
144
261
  const value = readHeader(headers, name) ?? readHeader(headers, `${FORWARD_PREFIX}${name}`);
145
262
  if (value && isAcceptableStepId(value)) return value;
146
263
  }
147
- const runId = readHeader(headers, "upstash-workflow-runid");
148
- const fromRunId = runId ? AGENT_RUN_ID.exec(runId)?.[1] : void 0;
149
- return fromRunId && isAcceptableStepId(fromRunId) ? fromRunId : null;
264
+ return correlationFromRunId(readHeader(headers, "upstash-workflow-runid"));
150
265
  }
151
266
  function parseRetried(value) {
152
267
  if (value === null) return null;
@@ -159,6 +274,7 @@ function describeError(error) {
159
274
  return String(error);
160
275
  }
161
276
 
277
+ exports.__ezlogsInstrument = __ezlogsInstrument;
162
278
  exports.captureWorkflowRequest = captureWorkflowRequest;
163
279
  exports.emitUpstashWorkflowEvent = emitUpstashWorkflowEvent;
164
280
  exports.wrapQStashClient = wrapQStashClient;
@@ -40,13 +40,31 @@ declare function wrapQStashClient<T extends QStashClientLike>(client: T): T;
40
40
  * Workflow retry / failure-routing semantics still work.
41
41
  */
42
42
  declare function captureWorkflowRequest<T>(meta: {
43
- request: Request | {
43
+ /**
44
+ * The workflow's context (`serve(async (context) => …)`), or the
45
+ * delivery Request. With the context, the run id comes from
46
+ * `context.workflowRunId`: Upstash keeps only the triggering
47
+ * request's headers on `context.headers`, without the per-delivery
48
+ * `Upstash-Workflow-RunId`.
49
+ */
50
+ context?: {
51
+ headers: Headers;
52
+ workflowRunId?: string;
53
+ };
54
+ request?: Request | {
44
55
  headers: Headers;
45
56
  };
46
57
  workflowName: string;
47
58
  /** Optional explicit step name; defaults to workflowName. */
48
59
  stepName?: string;
60
+ /** @internal The step this delivery ran, read when it ends (the plugin's serve()). */
61
+ ranStep?: () => string | undefined;
49
62
  }, work: () => Promise<T>): Promise<T>;
63
+ /**
64
+ * Replacements for the plugin's instrumented imports (instrument.ts).
65
+ * Internal: called by build-time generated code, not by apps.
66
+ */
67
+ declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
50
68
  /**
51
69
  * Standalone capture entry — for users who already have a finished
52
70
  * request/response pair and just want an event recorded (e.g.
@@ -63,4 +81,4 @@ declare function emitUpstashWorkflowEvent(input: {
63
81
  startedAt?: Date;
64
82
  }): void;
65
83
 
66
- export { captureWorkflowRequest, emitUpstashWorkflowEvent, wrapQStashClient, wrapWorkflowClient };
84
+ export { __ezlogsInstrument, captureWorkflowRequest, emitUpstashWorkflowEvent, wrapQStashClient, wrapWorkflowClient };
@@ -40,13 +40,31 @@ declare function wrapQStashClient<T extends QStashClientLike>(client: T): T;
40
40
  * Workflow retry / failure-routing semantics still work.
41
41
  */
42
42
  declare function captureWorkflowRequest<T>(meta: {
43
- request: Request | {
43
+ /**
44
+ * The workflow's context (`serve(async (context) => …)`), or the
45
+ * delivery Request. With the context, the run id comes from
46
+ * `context.workflowRunId`: Upstash keeps only the triggering
47
+ * request's headers on `context.headers`, without the per-delivery
48
+ * `Upstash-Workflow-RunId`.
49
+ */
50
+ context?: {
51
+ headers: Headers;
52
+ workflowRunId?: string;
53
+ };
54
+ request?: Request | {
44
55
  headers: Headers;
45
56
  };
46
57
  workflowName: string;
47
58
  /** Optional explicit step name; defaults to workflowName. */
48
59
  stepName?: string;
60
+ /** @internal The step this delivery ran, read when it ends (the plugin's serve()). */
61
+ ranStep?: () => string | undefined;
49
62
  }, work: () => Promise<T>): Promise<T>;
63
+ /**
64
+ * Replacements for the plugin's instrumented imports (instrument.ts).
65
+ * Internal: called by build-time generated code, not by apps.
66
+ */
67
+ declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
50
68
  /**
51
69
  * Standalone capture entry — for users who already have a finished
52
70
  * request/response pair and just want an event recorded (e.g.
@@ -63,4 +81,4 @@ declare function emitUpstashWorkflowEvent(input: {
63
81
  startedAt?: Date;
64
82
  }): void;
65
83
 
66
- export { captureWorkflowRequest, emitUpstashWorkflowEvent, wrapQStashClient, wrapWorkflowClient };
84
+ export { __ezlogsInstrument, captureWorkflowRequest, emitUpstashWorkflowEvent, wrapQStashClient, wrapWorkflowClient };