ezlogs-nextjs 0.4.3 → 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 (66) hide show
  1. package/README.md +217 -86
  2. package/THIRD_PARTY_LICENSES.md +27 -0
  3. package/dist/actors/index.d.cts +1 -1
  4. package/dist/actors/index.d.ts +1 -1
  5. package/dist/{chunk-Z2TM3LGG.js → chunk-2NFJOT6Q.js} +1 -1
  6. package/dist/{chunk-R6IWVTX3.cjs → chunk-65HRY3PW.cjs} +31 -21
  7. package/dist/{chunk-YXZZNZG6.cjs → chunk-B3WST6ES.cjs} +9 -9
  8. package/dist/{chunk-MMLQXSSD.cjs → chunk-B5ZUQULZ.cjs} +18 -11
  9. package/dist/{chunk-NX4EL7BY.cjs → chunk-DM2EAOSF.cjs} +4 -4
  10. package/dist/chunk-DRE2VXFX.js +19 -0
  11. package/dist/chunk-H3FC5HMW.cjs +16 -0
  12. package/dist/{chunk-GI6BM4MR.js → chunk-IBSNHBUC.js} +18 -12
  13. package/dist/chunk-JWJKFZBW.js +52 -0
  14. package/dist/{chunk-MHBS5FEP.js → chunk-M3VBQ5KT.js} +27 -4
  15. package/dist/chunk-NFZ5OKF3.cjs +22 -0
  16. package/dist/{chunk-GMHOUAKD.cjs → chunk-O7SFYXJC.cjs} +37 -13
  17. package/dist/{chunk-U22T7QYY.js → chunk-PK2Z2ABL.js} +13 -3
  18. package/dist/{chunk-YMIGZYFH.js → chunk-RD47JECJ.js} +1 -1
  19. package/dist/chunk-RMKGMIV2.js +13 -0
  20. package/dist/{chunk-NINIAL7M.js → chunk-U3IJV5EJ.js} +1 -1
  21. package/dist/chunk-VJR4VB4B.cjs +56 -0
  22. package/dist/{chunk-PS4U2GFJ.cjs → chunk-YO6E763S.cjs} +5 -5
  23. package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
  24. package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
  25. package/dist/db/drizzle.cjs +3 -3
  26. package/dist/db/drizzle.js +2 -2
  27. package/dist/db/postgres-js.cjs +4 -4
  28. package/dist/db/postgres-js.js +2 -2
  29. package/dist/db/prisma.cjs +12 -12
  30. package/dist/db/prisma.js +2 -2
  31. package/dist/db/supabase.cjs +42 -17
  32. package/dist/db/supabase.d.cts +11 -5
  33. package/dist/db/supabase.d.ts +11 -5
  34. package/dist/db/supabase.js +33 -9
  35. package/dist/index.cjs +288 -142
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +198 -52
  39. package/dist/jobs/bullmq.cjs +44 -16
  40. package/dist/jobs/bullmq.d.cts +7 -1
  41. package/dist/jobs/bullmq.d.ts +7 -1
  42. package/dist/jobs/bullmq.js +33 -6
  43. package/dist/jobs/inngest.cjs +36 -17
  44. package/dist/jobs/inngest.d.cts +7 -1
  45. package/dist/jobs/inngest.d.ts +7 -1
  46. package/dist/jobs/inngest.js +23 -5
  47. package/dist/jobs/supabase-queues.cjs +9 -9
  48. package/dist/jobs/supabase-queues.js +4 -4
  49. package/dist/jobs/trigger.cjs +7 -7
  50. package/dist/jobs/trigger.js +4 -4
  51. package/dist/jobs/upstash-workflow.cjs +139 -23
  52. package/dist/jobs/upstash-workflow.d.cts +20 -2
  53. package/dist/jobs/upstash-workflow.d.ts +20 -2
  54. package/dist/jobs/upstash-workflow.js +129 -14
  55. package/dist/nextjs-plugin/index.cjs +46 -29
  56. package/dist/nextjs-plugin/index.js +46 -29
  57. package/dist/nextjs-plugin/loader.cjs +70 -60
  58. package/dist/nextjs-plugin/loader.d.cts +18 -1
  59. package/dist/nextjs-plugin/loader.d.ts +18 -1
  60. package/dist/nextjs-plugin/loader.js +70 -61
  61. package/dist/triggers/index.cjs +22 -16
  62. package/dist/triggers/index.d.cts +0 -10
  63. package/dist/triggers/index.d.ts +0 -10
  64. package/dist/triggers/index.js +11 -5
  65. package/package.json +6 -5
  66. package/sql/postgres/00_install.sql +20 -3
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InitOptions } from './configuration-CJ5yKVlP.cjs';
2
- export { A as ActorContext, a as ActorFromRequest, b as ActorPrincipal, D as DisplayNameMap } from './configuration-CJ5yKVlP.cjs';
1
+ import { I as InitOptions } from './configuration-b9pImwFB.cjs';
2
+ export { a as ActorContext, A as ActorFromRequest, b as ActorPrincipal, D as DisplayNameMap } from './configuration-b9pImwFB.cjs';
3
3
 
4
4
  /**
5
5
  * EventBuilder — port of ez_logs_agent/lib/ez_logs_agent/event_builder.rb.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InitOptions } from './configuration-CJ5yKVlP.js';
2
- export { A as ActorContext, a as ActorFromRequest, b as ActorPrincipal, D as DisplayNameMap } from './configuration-CJ5yKVlP.js';
1
+ import { I as InitOptions } from './configuration-b9pImwFB.js';
2
+ export { a as ActorContext, A as ActorFromRequest, b as ActorPrincipal, D as DisplayNameMap } from './configuration-b9pImwFB.js';
3
3
 
4
4
  /**
5
5
  * EventBuilder — port of ez_logs_agent/lib/ez_logs_agent/event_builder.rb.
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
- import { patchPgClient } from './chunk-Z2TM3LGG.js';
2
- import { flushAuditLog, runWithEmittedAuditIdsScope, auditLogInstalled, checkAuditLogAccess, detectTriggerTrackedTables, maintainAuditLogAfterRequests } from './chunk-MHBS5FEP.js';
3
- import { build, pushEvent, maskAuthParams, isAuthActionName, isAuthPath, scrubSecretsInText, buffer_exports, sanitizeRequestParams, passesLuhn, isSensitiveKey, drainEvents } from './chunk-NINIAL7M.js';
4
- export { ArgError, build as buildEvent } from './chunk-NINIAL7M.js';
5
- import { configuration, resolveCorrelation, runWithCorrelation, maybeExtractSupabaseActor, endCorrelationScope, getCurrentActor, current, makeAsyncContextCapture, runWithActorScope, setActor, DEFAULT_EXCLUDED_EXTENSIONS } from './chunk-GI6BM4MR.js';
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';
6
7
  import { logger, setLogLevel } from './chunk-FCFVIRQF.js';
7
8
  import './chunk-SIAA4J6H.js';
8
9
 
@@ -141,6 +142,7 @@ var flushScheduler = {
141
142
  },
142
143
  async stop() {
143
144
  const s = state();
145
+ await settleAuditFlushes();
144
146
  if (s.timer === null) return;
145
147
  clearInterval(s.timer);
146
148
  s.timer = null;
@@ -159,17 +161,20 @@ var flushScheduler = {
159
161
  * builds a queue.
160
162
  */
161
163
  flushNow() {
162
- const s = state();
163
- if (!s.inFlight || !s.current) return tick();
164
- if (!s.followUp) {
165
- s.followUp = s.current.then(() => {
166
- s.followUp = null;
167
- return tick();
168
- });
169
- }
170
- return s.followUp;
164
+ return settleAuditFlushes().then(() => sendNow());
171
165
  }
172
166
  };
167
+ function sendNow() {
168
+ const s = state();
169
+ if (!s.inFlight || !s.current) return tick();
170
+ if (!s.followUp) {
171
+ s.followUp = s.current.then(() => {
172
+ s.followUp = null;
173
+ return tick();
174
+ });
175
+ }
176
+ return s.followUp;
177
+ }
173
178
  function tick() {
174
179
  const s = state();
175
180
  if (s.inFlight && s.current) return s.current;
@@ -230,12 +235,50 @@ function patchGlobalFetch() {
230
235
  };
231
236
  globalThis.fetch = wrapped;
232
237
  patched = true;
238
+ subscribeUndiciRequests();
239
+ }
240
+ var subscribed = false;
241
+ function subscribeUndiciRequests() {
242
+ if (subscribed) return;
243
+ const channel = loadDiagnosticsChannel();
244
+ if (!channel) return;
245
+ channel.subscribe("undici:request:create", onUndiciRequest);
246
+ subscribed = true;
247
+ }
248
+ function onUndiciRequest(message) {
249
+ try {
250
+ const request = message?.request;
251
+ if (!request || typeof request.addHeader !== "function") return;
252
+ const id = current();
253
+ if (!id || hasCorrelationHeader(request.headers)) return;
254
+ request.addHeader(HEADER, id);
255
+ } catch (error) {
256
+ logger.debug(`outgoing request header injection failed: ${describeError4(error)}`);
257
+ }
258
+ }
259
+ function hasCorrelationHeader(headers) {
260
+ if (Array.isArray(headers)) {
261
+ for (let i = 0; i < headers.length; i += 2) {
262
+ if (String(headers[i]).toLowerCase() === HEADER) return true;
263
+ }
264
+ return false;
265
+ }
266
+ if (typeof headers === "string") return headers.toLowerCase().includes(`${HEADER}:`);
267
+ return false;
268
+ }
269
+ function loadDiagnosticsChannel() {
270
+ const mod = loadNodeBuiltin(["diagnostics", "channel"].join("_"));
271
+ return typeof mod?.subscribe === "function" ? mod : null;
233
272
  }
234
273
  function unpatchGlobalFetch() {
235
274
  if (!patched || originalFetch === null) return;
236
275
  globalThis.fetch = originalFetch;
237
276
  originalFetch = null;
238
277
  patched = false;
278
+ if (subscribed) {
279
+ loadDiagnosticsChannel()?.unsubscribe("undici:request:create", onUndiciRequest);
280
+ subscribed = false;
281
+ }
239
282
  }
240
283
  function injectHeader(input, init, correlationId) {
241
284
  if (input instanceof Request && !init) {
@@ -454,11 +497,38 @@ function parseServerActionName(name) {
454
497
  }
455
498
  const canonical = KNOWN_VERBS.get(leading);
456
499
  if (!canonical) return { verb: null, entity: null };
457
- const entityTokens = tokens.slice(entityStart);
500
+ let rest = tokens.slice(entityStart);
501
+ const isConnector = (t) => CONNECTORS.has(t.toLowerCase());
502
+ if (rest.length > 0 && COMPOUND.has(rest[0].toLowerCase())) {
503
+ rest = rest.slice(2);
504
+ if (rest.length > 0 && isConnector(rest[0])) {
505
+ rest = rest.slice(rest.map(isConnector).lastIndexOf(true) + 1);
506
+ }
507
+ }
508
+ const firstConnector = rest.findIndex(isConnector);
509
+ const entityTokens = firstConnector === -1 ? rest : rest.slice(0, firstConnector);
458
510
  if (entityTokens.length === 0) return { verb: canonical, entity: null };
459
511
  const entity = entityTokens.join("");
460
512
  return { verb: canonical, entity: stripTrailingS(entity) || entity };
461
513
  }
514
+ var COMPOUND = /* @__PURE__ */ new Set(["and", "or", "then"]);
515
+ var CONNECTORS = /* @__PURE__ */ new Set([
516
+ ...COMPOUND,
517
+ "to",
518
+ "with",
519
+ "without",
520
+ "for",
521
+ "from",
522
+ "by",
523
+ "in",
524
+ "into",
525
+ "on",
526
+ "of",
527
+ "via",
528
+ "using",
529
+ "as",
530
+ "at"
531
+ ]);
462
532
  function stripTrailingS(entity) {
463
533
  if (entity.length <= 1) return entity;
464
534
  if (entity.endsWith("ies")) return `${entity.slice(0, -3)}y`;
@@ -794,9 +864,10 @@ function captureRoute(handler, context = {}) {
794
864
  if (snapshot === null) return Promise.resolve(runHandler(...args));
795
865
  snapshot.rawParams = mergeRouteParams(snapshot.rawParams, await readRouteParams(args[1]));
796
866
  const correlationId = resolveCorrelation(request.headers ?? null);
867
+ const delivery = { jobDelivery: false };
797
868
  return await runWithCorrelation(
798
869
  correlationId,
799
- () => runWithActorAndAuditScope(async () => {
870
+ () => runWithDeliverySlot(delivery, () => runWithActorAndAuditScope(async () => {
800
871
  await maybeRunActorHook(request);
801
872
  const startMs = Date.now();
802
873
  let statusCode = null;
@@ -816,7 +887,8 @@ function captureRoute(handler, context = {}) {
816
887
  graphqlErrorMessage,
817
888
  responseErrorMessage,
818
889
  durationMs: handlerMs ?? Date.now() - startMs,
819
- startedAt: new Date(startMs)
890
+ startedAt: new Date(startMs),
891
+ jobDelivery: delivery.jobDelivery
820
892
  });
821
893
  await flushOnServerless();
822
894
  endCorrelationScope();
@@ -829,7 +901,7 @@ function captureRoute(handler, context = {}) {
829
901
  graphqlErrorMessage = await readGraphqlErrors(response);
830
902
  }
831
903
  const trpcRoute = isTrpcRoute(snapshot.rawParams, context.routeModulePath ?? null);
832
- responseErrorMessage = await readResponseErrorMessage(response, trpcRoute);
904
+ responseErrorMessage = await readResponseErrorMessage(response, trpcRoute) ?? authRedirectError(snapshot.url, response.status, response.headers.get("location"));
833
905
  const trpcStream = responseErrorMessage === null && trpcRoute ? trpcStreamErrorScanner(configuration().excludedGraphqlVariableKeys) : null;
834
906
  const followedResponse = followBody(
835
907
  response,
@@ -856,9 +928,12 @@ function captureRoute(handler, context = {}) {
856
928
  statusCode = 500;
857
929
  throw e;
858
930
  } finally {
859
- if (!followed) await finish();
931
+ if (!followed) {
932
+ await maybeExtractSupabaseActor();
933
+ await offTheResponse(finish);
934
+ }
860
935
  }
861
- })
936
+ }))
862
937
  );
863
938
  } catch (preCaptureError) {
864
939
  if (handlerInvoked) throw preCaptureError;
@@ -897,14 +972,21 @@ function withMiddlewareCapture(middleware) {
897
972
  }
898
973
  try {
899
974
  if (shouldEmitPageNavigation(request)) {
975
+ const durationMs = Date.now() - startMs;
900
976
  await maybeRunActorHook(request);
901
977
  await maybeExtractSupabaseActor();
902
- await emitPageNavigationEvent({
903
- request,
904
- statusCode: typeof response?.status === "number" ? response.status : null,
905
- durationMs: Date.now() - startMs,
906
- startedAt
907
- });
978
+ const event = rest[0];
979
+ await offTheResponse(
980
+ async () => {
981
+ await emitPageNavigationEvent({
982
+ request,
983
+ statusCode: typeof response?.status === "number" ? response.status : null,
984
+ durationMs,
985
+ startedAt
986
+ });
987
+ },
988
+ typeof event?.waitUntil === "function" ? event.waitUntil.bind(event) : null
989
+ );
908
990
  }
909
991
  } catch (error) {
910
992
  logger.debug(`page navigation capture failed: ${describeError5(error)}`);
@@ -1025,9 +1107,10 @@ function capturePagesApi(handler, context = {}) {
1025
1107
  const correlationId = resolveCorrelation({
1026
1108
  get: (name) => readPagesHeader(req, name)
1027
1109
  });
1110
+ const delivery = { jobDelivery: false };
1028
1111
  return await runWithCorrelation(
1029
1112
  correlationId,
1030
- () => runWithActorAndAuditScope(async () => {
1113
+ () => runWithDeliverySlot(delivery, () => runWithActorAndAuditScope(async () => {
1031
1114
  await maybeRunActorHookFromPages(req);
1032
1115
  const startMs = Date.now();
1033
1116
  let exception = null;
@@ -1039,19 +1122,28 @@ function capturePagesApi(handler, context = {}) {
1039
1122
  throw e;
1040
1123
  } finally {
1041
1124
  await maybeExtractSupabaseActor();
1125
+ const status = typeof res.statusCode === "number" ? res.statusCode : null;
1126
+ const getHeader = res.getHeader;
1042
1127
  await emitEvent({
1043
1128
  snapshot,
1044
1129
  context,
1045
- statusCode: typeof res.statusCode === "number" ? res.statusCode : null,
1130
+ statusCode: status,
1046
1131
  exception,
1047
1132
  graphqlErrorMessage: null,
1133
+ // NextAuth v4 under pages/api/auth: a failed sign-in redirects to ?error=.
1134
+ responseErrorMessage: authRedirectError(
1135
+ snapshot.url,
1136
+ status,
1137
+ typeof getHeader === "function" ? getHeader.call(res, "location") : null
1138
+ ),
1048
1139
  durationMs: Date.now() - startMs,
1049
- startedAt: new Date(startMs)
1140
+ startedAt: new Date(startMs),
1141
+ jobDelivery: delivery.jobDelivery
1050
1142
  });
1051
1143
  await flushOnServerless();
1052
1144
  endCorrelationScope();
1053
1145
  }
1054
- })
1146
+ }))
1055
1147
  );
1056
1148
  } catch (preCaptureError) {
1057
1149
  if (handlerInvoked) throw preCaptureError;
@@ -1082,27 +1174,21 @@ function captureServerAction(action, actionName) {
1082
1174
  const startedAt = new Date(startMs);
1083
1175
  let exception = null;
1084
1176
  await maybeRunActorHookFromServerAction();
1085
- try {
1086
- const result = await Promise.resolve(runAction(...args));
1177
+ const record = async (input) => {
1087
1178
  await maybeExtractSupabaseActor();
1088
- const failure = classifyServerActionResult(result);
1089
- await emitServerActionEvent({
1090
- actionName,
1091
- // A returned failure (`{ success: false, error }`) is a
1092
- // handled refusal, not a crash: no HTTP status is
1093
- // invented; outcome + error_message carry it.
1094
- statusCode: failure ? null : 200,
1095
- exception: failure ? new Error(failure.errorMessage) : null,
1096
- durationMs: Date.now() - startMs,
1097
- startedAt,
1098
- args
1179
+ await offTheResponse(async () => {
1180
+ await emitServerActionEvent(input);
1181
+ await flushOnServerless();
1182
+ endCorrelationScope();
1099
1183
  });
1100
- return result;
1184
+ };
1185
+ let result;
1186
+ try {
1187
+ result = await Promise.resolve(runAction(...args));
1101
1188
  } catch (e) {
1102
1189
  if (isNextControlFlowError(e)) {
1103
- await maybeExtractSupabaseActor();
1104
1190
  const controlStatus = nextControlFlowStatus(e) ?? 200;
1105
- await emitServerActionEvent({
1191
+ await record({
1106
1192
  actionName,
1107
1193
  // redirect() is a success; notFound() / forbidden()
1108
1194
  // keep their 4xx.
@@ -1116,8 +1202,7 @@ function captureServerAction(action, actionName) {
1116
1202
  throw e;
1117
1203
  }
1118
1204
  exception = e instanceof Error ? e : new Error(String(e));
1119
- await maybeExtractSupabaseActor();
1120
- await emitServerActionEvent({
1205
+ await record({
1121
1206
  actionName,
1122
1207
  statusCode: 500,
1123
1208
  exception,
@@ -1126,10 +1211,25 @@ function captureServerAction(action, actionName) {
1126
1211
  args
1127
1212
  });
1128
1213
  throw e;
1129
- } finally {
1130
- await flushOnServerless();
1131
- endCorrelationScope();
1132
1214
  }
1215
+ let failure = null;
1216
+ try {
1217
+ failure = classifyServerActionResult(result);
1218
+ } catch (e) {
1219
+ logger.debug(`server action result classification failed: ${describeError5(e)}`);
1220
+ }
1221
+ await record({
1222
+ actionName,
1223
+ // A returned failure (`{ success: false, error }`) is a
1224
+ // handled refusal, not a crash: no HTTP status is
1225
+ // invented; outcome + error_message carry it.
1226
+ statusCode: failure ? null : 200,
1227
+ exception: failure ? new Error(failure.errorMessage) : null,
1228
+ durationMs: Date.now() - startMs,
1229
+ startedAt,
1230
+ args
1231
+ });
1232
+ return result;
1133
1233
  })
1134
1234
  );
1135
1235
  } catch (preCaptureError) {
@@ -1830,6 +1930,7 @@ function readPagesHeader(req, name) {
1830
1930
  async function emitEvent(input) {
1831
1931
  try {
1832
1932
  await flushTriggerAuditLog();
1933
+ if (input.jobDelivery) return;
1833
1934
  const config = configuration();
1834
1935
  let graphql = null;
1835
1936
  if (input.snapshot.graphqlBody !== null) {
@@ -1941,6 +2042,26 @@ function followBody(response, method, onDone, onChunk) {
1941
2042
  return null;
1942
2043
  }
1943
2044
  }
2045
+ async function offTheResponse(work, waitUntil = null) {
2046
+ const done = work().catch((e) => logger.debug(`capture failed: ${describeError5(e)}`));
2047
+ if (!isServerless()) return;
2048
+ try {
2049
+ const keepAlive = waitUntil ?? platformWaitUntil();
2050
+ if (keepAlive) {
2051
+ keepAlive(done);
2052
+ return;
2053
+ }
2054
+ } catch (e) {
2055
+ logger.debug(`waitUntil unavailable, recording inline: ${describeError5(e)}`);
2056
+ }
2057
+ let timer;
2058
+ await Promise.race([
2059
+ done,
2060
+ new Promise((resolve) => {
2061
+ timer = setTimeout(resolve, SERVERLESS_INLINE_FLUSH_MS);
2062
+ })
2063
+ ]).finally(() => clearTimeout(timer));
2064
+ }
1944
2065
  var SERVERLESS_INLINE_FLUSH_MS = 2e3;
1945
2066
  async function flushOnServerless() {
1946
2067
  if (!isServerless()) return;
@@ -1985,7 +2106,22 @@ function buildContext() {
1985
2106
  async function flushTriggerAuditLog() {
1986
2107
  const reader = configuration().databaseReader;
1987
2108
  if (!reader) return;
1988
- await flushAuditLog(reader);
2109
+ const work = flushAuditLog(reader).catch(
2110
+ (e) => logger.debug(`trigger audit flush failed: ${describeError5(e)}`)
2111
+ );
2112
+ if (!isServerless()) return;
2113
+ const waitUntil = platformWaitUntil();
2114
+ if (waitUntil) {
2115
+ waitUntil(work.then(() => flushScheduler.flushNow()));
2116
+ return;
2117
+ }
2118
+ let timer;
2119
+ await Promise.race([
2120
+ work,
2121
+ new Promise((resolve) => {
2122
+ timer = setTimeout(resolve, SERVERLESS_INLINE_FLUSH_MS);
2123
+ })
2124
+ ]).finally(() => clearTimeout(timer));
1989
2125
  }
1990
2126
  function runWithActorAndAuditScope(callback) {
1991
2127
  if (configuration().databaseReader == null) {
@@ -2044,6 +2180,16 @@ function mergeRouteParams(rawParams, routeParams) {
2044
2180
  return { ...routeParams, ...rawParams };
2045
2181
  }
2046
2182
  var MAX_ERROR_BODY_LENGTH = 16384;
2183
+ function authRedirectError(url, status, location) {
2184
+ try {
2185
+ if (typeof status !== "number" || status < 300 || status >= 400 || !isAuthPath(url.pathname)) return null;
2186
+ if (typeof location !== "string" || !location) return null;
2187
+ const reason = new URL(location, url).searchParams.get("error");
2188
+ return reason ? capErrorText(reason) : null;
2189
+ } catch {
2190
+ return null;
2191
+ }
2192
+ }
2047
2193
  async function readResponseErrorMessage(response, trpcRoute = false) {
2048
2194
  try {
2049
2195
  if (response.status < 400 && response.status !== 207) return null;
@@ -1,9 +1,10 @@
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 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');
7
8
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
8
9
  require('../chunk-ZDSQYCYV.cjs');
9
10
 
@@ -39,7 +40,7 @@ function wrapBullQueue(queue) {
39
40
  const wrappedAddBulk = (jobs) => {
40
41
  const stamped = jobs.map((j) => ({ ...j, data: stampPayload(j.data) }));
41
42
  const ours = stamped.map((j) => isOurs(j.data));
42
- const token = ours.includes(true) ? chunkR6IWVTX3_cjs.signedActorToken(chunkMMLQXSSD_cjs.current()) : null;
43
+ const token = ours.includes(true) ? chunk65HRY3PW_cjs.signedActorToken(chunkB5ZUQULZ_cjs.current()) : null;
43
44
  return inOrder(
44
45
  token,
45
46
  (t) => originalAddBulk(stamped.map((j, i) => ours[i] ? { ...j, data: withActor(j.data, t) } : j))
@@ -70,8 +71,10 @@ function wrapBullWorker(worker) {
70
71
  internals.processFn = function ezlogsProcess(...args) {
71
72
  const job = args[0] ?? {};
72
73
  if (typeof args[0] === "object" && args[0] !== null) reported.add(args[0]);
73
- const correlationId = chunkR6IWVTX3_cjs.extractCorrelationFromPayload(job.data);
74
- const run = (actor) => chunkR6IWVTX3_cjs.runJobWithCapture(
74
+ const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(job.data);
75
+ const token = job.data?.[chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY];
76
+ if (typeof args[0] === "object" && args[0] !== null) hideAgentKeys(job);
77
+ const run = (actor) => chunk65HRY3PW_cjs.runJobWithCapture(
75
78
  {
76
79
  jobClass: job.name ?? worker.name ?? "BullMQJob",
77
80
  jobId: job.id !== void 0 && job.id !== null ? String(job.id) : null,
@@ -86,9 +89,8 @@ function wrapBullWorker(worker) {
86
89
  },
87
90
  () => Promise.resolve(original.apply(this, args))
88
91
  );
89
- const token = job.data?.[chunkR6IWVTX3_cjs.ACTOR_PAYLOAD_KEY];
90
92
  if (!correlationId || token === void 0) return run(null);
91
- return chunkR6IWVTX3_cjs.readActorToken(token, correlationId).then(run);
93
+ return chunk65HRY3PW_cjs.readActorToken(token, correlationId).then(run);
92
94
  };
93
95
  worker.on("failed", (...args) => {
94
96
  const job = args[0];
@@ -129,10 +131,10 @@ function markWrapped(worker) {
129
131
  }
130
132
  function captureJob(job, worker, outcome, errorMessage) {
131
133
  try {
132
- const correlationId = chunkR6IWVTX3_cjs.extractCorrelationFromPayload(job.data);
134
+ const correlationId = chunk65HRY3PW_cjs.extractCorrelationFromPayload(job.data);
133
135
  const startedAt = typeof job.timestamp === "number" ? new Date(job.timestamp) : /* @__PURE__ */ new Date();
134
136
  const durationMs = job.timestamp ? Date.now() - job.timestamp : null;
135
- chunkR6IWVTX3_cjs.emitJobEvent({
137
+ chunk65HRY3PW_cjs.emitJobEvent({
136
138
  jobClass: job.name ?? worker.name ?? "BullMQJob",
137
139
  jobId: job.id !== void 0 && job.id !== null ? String(job.id) : null,
138
140
  queue: job.queueName ?? worker.name ?? null,
@@ -149,27 +151,53 @@ function captureJob(job, worker, outcome, errorMessage) {
149
151
  }
150
152
  }
151
153
  function pendingActorTokenFor(data) {
152
- return isOurs(data) ? chunkR6IWVTX3_cjs.signedActorToken(chunkMMLQXSSD_cjs.current()) : null;
154
+ return isOurs(data) ? chunk65HRY3PW_cjs.signedActorToken(chunkB5ZUQULZ_cjs.current()) : null;
153
155
  }
154
156
  function isOurs(data) {
155
157
  if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
156
158
  const obj = data;
157
- const id = chunkMMLQXSSD_cjs.current();
158
- return Boolean(id) && obj[chunkR6IWVTX3_cjs.CORRELATION_PAYLOAD_KEY] === id && !(chunkR6IWVTX3_cjs.ACTOR_PAYLOAD_KEY in obj);
159
+ const id = chunkB5ZUQULZ_cjs.current();
160
+ return Boolean(id) && obj[chunk65HRY3PW_cjs.CORRELATION_PAYLOAD_KEY] === id && !(chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY in obj);
161
+ }
162
+ var AGENT_KEYS = [chunk65HRY3PW_cjs.CORRELATION_PAYLOAD_KEY, chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY];
163
+ function hideAgentKeys(job) {
164
+ try {
165
+ const data = job.data;
166
+ if (data === null || typeof data !== "object" || Array.isArray(data)) return;
167
+ const carried = Object.fromEntries(AGENT_KEYS.filter((k) => k in data).map((k) => [k, data[k]]));
168
+ if (Object.keys(carried).length === 0) return;
169
+ const rest = { ...data };
170
+ for (const k of AGENT_KEYS) delete rest[k];
171
+ job.data = rest;
172
+ const save = job.updateData;
173
+ if (typeof save !== "function") return;
174
+ job.updateData = async function ezlogsUpdateData(next, ...more) {
175
+ const stamped = next !== null && typeof next === "object" && !Array.isArray(next) ? { ...carried, ...next } : next;
176
+ const result = await save.call(job, stamped, ...more);
177
+ job.data = next;
178
+ return result;
179
+ };
180
+ } catch {
181
+ }
159
182
  }
160
183
  function withActor(data, token) {
161
- return token ? { ...data, [chunkR6IWVTX3_cjs.ACTOR_PAYLOAD_KEY]: token } : data;
184
+ return token ? { ...data, [chunk65HRY3PW_cjs.ACTOR_PAYLOAD_KEY]: token } : data;
162
185
  }
163
186
  function stampPayload(data) {
164
187
  if (data === null || typeof data !== "object" || Array.isArray(data)) {
165
188
  return data;
166
189
  }
167
- return chunkR6IWVTX3_cjs.stampCorrelationOnPayload(data, chunkR6IWVTX3_cjs.CORRELATION_PAYLOAD_KEY);
190
+ return chunk65HRY3PW_cjs.stampCorrelationOnPayload(data, chunk65HRY3PW_cjs.CORRELATION_PAYLOAD_KEY);
168
191
  }
169
192
  function describeError(error) {
170
193
  if (error instanceof Error) return `${error.name}: ${error.message}`;
171
194
  return String(error);
172
195
  }
196
+ var __ezlogsInstrument = chunkVJR4VB4B_cjs.instrumentFrom({
197
+ "bullmq#Queue": (original) => chunkVJR4VB4B_cjs.instrumentClass(original, (queue) => wrapBullQueue(queue)),
198
+ "bullmq#Worker": (original) => chunkVJR4VB4B_cjs.instrumentClass(original, (worker) => wrapBullWorker(worker))
199
+ });
173
200
 
201
+ exports.__ezlogsInstrument = __ezlogsInstrument;
174
202
  exports.wrapBullQueue = wrapBullQueue;
175
203
  exports.wrapBullWorker = wrapBullWorker;
@@ -38,5 +38,11 @@ declare function wrapBullQueue<T extends BullQueueLike>(queue: T): T;
38
38
  * Idempotent — calling on the same worker twice is a no-op.
39
39
  */
40
40
  declare function wrapBullWorker<T extends BullWorkerLike>(worker: T): T;
41
+ /**
42
+ * Replacements for the plugin's instrumented imports (instrument.ts):
43
+ * every Queue and Worker the app's server code constructs is wrapped.
44
+ * Internal: called by build-time generated code, not by apps.
45
+ */
46
+ declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
41
47
 
42
- export { wrapBullQueue, wrapBullWorker };
48
+ export { __ezlogsInstrument, wrapBullQueue, wrapBullWorker };
@@ -38,5 +38,11 @@ declare function wrapBullQueue<T extends BullQueueLike>(queue: T): T;
38
38
  * Idempotent — calling on the same worker twice is a no-op.
39
39
  */
40
40
  declare function wrapBullWorker<T extends BullWorkerLike>(worker: T): T;
41
+ /**
42
+ * Replacements for the plugin's instrumented imports (instrument.ts):
43
+ * every Queue and Worker the app's server code constructs is wrapped.
44
+ * Internal: called by build-time generated code, not by apps.
45
+ */
46
+ declare const __ezlogsInstrument: (key: string, original: unknown) => unknown;
41
47
 
42
- export { wrapBullQueue, wrapBullWorker };
48
+ export { __ezlogsInstrument, wrapBullQueue, wrapBullWorker };
@@ -1,7 +1,8 @@
1
- import { extractCorrelationFromPayload, ACTOR_PAYLOAD_KEY, readActorToken, emitJobEvent, signedActorToken, CORRELATION_PAYLOAD_KEY, stampCorrelationOnPayload, runJobWithCapture } from '../chunk-U22T7QYY.js';
2
- import '../chunk-MHBS5FEP.js';
3
- import '../chunk-NINIAL7M.js';
4
- import { current } from '../chunk-GI6BM4MR.js';
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';
5
6
  import { logger } from '../chunk-FCFVIRQF.js';
6
7
  import '../chunk-SIAA4J6H.js';
7
8
 
@@ -69,6 +70,8 @@ function wrapBullWorker(worker) {
69
70
  const job = args[0] ?? {};
70
71
  if (typeof args[0] === "object" && args[0] !== null) reported.add(args[0]);
71
72
  const correlationId = extractCorrelationFromPayload(job.data);
73
+ const token = job.data?.[ACTOR_PAYLOAD_KEY];
74
+ if (typeof args[0] === "object" && args[0] !== null) hideAgentKeys(job);
72
75
  const run = (actor) => runJobWithCapture(
73
76
  {
74
77
  jobClass: job.name ?? worker.name ?? "BullMQJob",
@@ -84,7 +87,6 @@ function wrapBullWorker(worker) {
84
87
  },
85
88
  () => Promise.resolve(original.apply(this, args))
86
89
  );
87
- const token = job.data?.[ACTOR_PAYLOAD_KEY];
88
90
  if (!correlationId || token === void 0) return run(null);
89
91
  return readActorToken(token, correlationId).then(run);
90
92
  };
@@ -155,6 +157,27 @@ function isOurs(data) {
155
157
  const id = current();
156
158
  return Boolean(id) && obj[CORRELATION_PAYLOAD_KEY] === id && !(ACTOR_PAYLOAD_KEY in obj);
157
159
  }
160
+ var AGENT_KEYS = [CORRELATION_PAYLOAD_KEY, ACTOR_PAYLOAD_KEY];
161
+ function hideAgentKeys(job) {
162
+ try {
163
+ const data = job.data;
164
+ if (data === null || typeof data !== "object" || Array.isArray(data)) return;
165
+ const carried = Object.fromEntries(AGENT_KEYS.filter((k) => k in data).map((k) => [k, data[k]]));
166
+ if (Object.keys(carried).length === 0) return;
167
+ const rest = { ...data };
168
+ for (const k of AGENT_KEYS) delete rest[k];
169
+ job.data = rest;
170
+ const save = job.updateData;
171
+ if (typeof save !== "function") return;
172
+ job.updateData = async function ezlogsUpdateData(next, ...more) {
173
+ const stamped = next !== null && typeof next === "object" && !Array.isArray(next) ? { ...carried, ...next } : next;
174
+ const result = await save.call(job, stamped, ...more);
175
+ job.data = next;
176
+ return result;
177
+ };
178
+ } catch {
179
+ }
180
+ }
158
181
  function withActor(data, token) {
159
182
  return token ? { ...data, [ACTOR_PAYLOAD_KEY]: token } : data;
160
183
  }
@@ -168,5 +191,9 @@ function describeError(error) {
168
191
  if (error instanceof Error) return `${error.name}: ${error.message}`;
169
192
  return String(error);
170
193
  }
194
+ var __ezlogsInstrument = instrumentFrom({
195
+ "bullmq#Queue": (original) => instrumentClass(original, (queue) => wrapBullQueue(queue)),
196
+ "bullmq#Worker": (original) => instrumentClass(original, (worker) => wrapBullWorker(worker))
197
+ });
171
198
 
172
- export { wrapBullQueue, wrapBullWorker };
199
+ export { __ezlogsInstrument, wrapBullQueue, wrapBullWorker };