ezlogs-nextjs 0.4.4 → 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 (65) hide show
  1. package/README.md +73 -13
  2. package/dist/actors/index.d.cts +1 -1
  3. package/dist/actors/index.d.ts +1 -1
  4. package/dist/{chunk-MMLQXSSD.cjs → chunk-2YCQFLXW.cjs} +21 -11
  5. package/dist/{chunk-YMIGZYFH.js → chunk-343ZGTMH.js} +1 -1
  6. package/dist/{chunk-Z2TM3LGG.js → chunk-5ZMOWEBY.js} +1 -1
  7. package/dist/{chunk-GI6BM4MR.js → chunk-7MFKEYDN.js} +21 -12
  8. package/dist/{chunk-NINIAL7M.js → chunk-AXIQTU52.js} +1 -1
  9. package/dist/chunk-BE3RCFNP.js +13 -0
  10. package/dist/chunk-CHVJ4WPM.cjs +16 -0
  11. package/dist/{chunk-MHBS5FEP.js → chunk-CYAFYBKF.js} +27 -4
  12. package/dist/chunk-DRE2VXFX.js +19 -0
  13. package/dist/{chunk-GMHOUAKD.cjs → chunk-EXGEA4KE.cjs} +37 -13
  14. package/dist/{chunk-PS4U2GFJ.cjs → chunk-JB4UYCZI.cjs} +5 -5
  15. package/dist/chunk-JWJKFZBW.js +52 -0
  16. package/dist/{chunk-R6IWVTX3.cjs → chunk-KOFR5OC3.cjs} +31 -21
  17. package/dist/chunk-NFZ5OKF3.cjs +22 -0
  18. package/dist/{chunk-U22T7QYY.js → chunk-Q3HRVWCS.js} +13 -3
  19. package/dist/{chunk-YXZZNZG6.cjs → chunk-UC2KS5EG.cjs} +9 -9
  20. package/dist/chunk-VJR4VB4B.cjs +56 -0
  21. package/dist/{chunk-NX4EL7BY.cjs → chunk-XWEBKN65.cjs} +4 -4
  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 +303 -142
  35. package/dist/index.d.cts +2 -2
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +213 -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 +171 -48
  43. package/dist/jobs/inngest.d.cts +13 -7
  44. package/dist/jobs/inngest.d.ts +13 -7
  45. package/dist/jobs/inngest.js +162 -40
  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 +104 -65
  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 +104 -66
  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
package/dist/index.cjs CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkNX4EL7BY_cjs = require('./chunk-NX4EL7BY.cjs');
4
- var chunkGMHOUAKD_cjs = require('./chunk-GMHOUAKD.cjs');
5
- var chunkYXZZNZG6_cjs = require('./chunk-YXZZNZG6.cjs');
6
- var chunkMMLQXSSD_cjs = require('./chunk-MMLQXSSD.cjs');
3
+ var chunkXWEBKN65_cjs = require('./chunk-XWEBKN65.cjs');
4
+ var chunkCHVJ4WPM_cjs = require('./chunk-CHVJ4WPM.cjs');
5
+ var chunkEXGEA4KE_cjs = require('./chunk-EXGEA4KE.cjs');
6
+ var chunkUC2KS5EG_cjs = require('./chunk-UC2KS5EG.cjs');
7
+ var chunk2YCQFLXW_cjs = require('./chunk-2YCQFLXW.cjs');
7
8
  var chunkTWTG5ILJ_cjs = require('./chunk-TWTG5ILJ.cjs');
8
9
  require('./chunk-ZDSQYCYV.cjs');
9
10
 
@@ -12,7 +13,7 @@ var REQUEST_TIMEOUT_MS = 1e4;
12
13
  var transport = {
13
14
  async send(events) {
14
15
  if (!events || events.length === 0) return "success";
15
- const config = chunkMMLQXSSD_cjs.configuration();
16
+ const config = chunk2YCQFLXW_cjs.configuration();
16
17
  const serverUrl = config.serverUrl;
17
18
  if (!serverUrl) {
18
19
  chunkTWTG5ILJ_cjs.logger.error("Transport: serverUrl not configured");
@@ -104,7 +105,7 @@ function applyJitter(base) {
104
105
  }
105
106
  function retryAttempts() {
106
107
  try {
107
- const value = chunkMMLQXSSD_cjs.configuration().retryAttempts;
108
+ const value = chunk2YCQFLXW_cjs.configuration().retryAttempts;
108
109
  if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
109
110
  return 3;
110
111
  }
@@ -142,6 +143,7 @@ var flushScheduler = {
142
143
  },
143
144
  async stop() {
144
145
  const s = state();
146
+ await chunkEXGEA4KE_cjs.settleAuditFlushes();
145
147
  if (s.timer === null) return;
146
148
  clearInterval(s.timer);
147
149
  s.timer = null;
@@ -160,17 +162,20 @@ var flushScheduler = {
160
162
  * builds a queue.
161
163
  */
162
164
  flushNow() {
163
- const s = state();
164
- if (!s.inFlight || !s.current) return tick();
165
- if (!s.followUp) {
166
- s.followUp = s.current.then(() => {
167
- s.followUp = null;
168
- return tick();
169
- });
170
- }
171
- return s.followUp;
165
+ return chunkEXGEA4KE_cjs.settleAuditFlushes().then(() => sendNow());
172
166
  }
173
167
  };
168
+ function sendNow() {
169
+ const s = state();
170
+ if (!s.inFlight || !s.current) return tick();
171
+ if (!s.followUp) {
172
+ s.followUp = s.current.then(() => {
173
+ s.followUp = null;
174
+ return tick();
175
+ });
176
+ }
177
+ return s.followUp;
178
+ }
174
179
  function tick() {
175
180
  const s = state();
176
181
  if (s.inFlight && s.current) return s.current;
@@ -183,12 +188,12 @@ function tick() {
183
188
  }
184
189
  async function runTick() {
185
190
  try {
186
- const events = chunkYXZZNZG6_cjs.drainEvents();
191
+ const events = chunkUC2KS5EG_cjs.drainEvents();
187
192
  if (events.length > 0) await retrySender.send(events);
188
- const reader = chunkMMLQXSSD_cjs.configuration().databaseReader;
193
+ const reader = chunk2YCQFLXW_cjs.configuration().databaseReader;
189
194
  if (!reader) return;
190
- await chunkGMHOUAKD_cjs.maintainAuditLogAfterRequests(reader);
191
- const swept = chunkYXZZNZG6_cjs.drainEvents();
195
+ await chunkEXGEA4KE_cjs.maintainAuditLogAfterRequests(reader);
196
+ const swept = chunkUC2KS5EG_cjs.drainEvents();
192
197
  if (swept.length > 0) await retrySender.send(swept);
193
198
  } catch (error) {
194
199
  chunkTWTG5ILJ_cjs.logger.error(`FlushScheduler tick failed: ${describeError3(error)}`);
@@ -196,7 +201,7 @@ async function runTick() {
196
201
  }
197
202
  function sendInterval() {
198
203
  try {
199
- const value = chunkMMLQXSSD_cjs.configuration().sendInterval;
204
+ const value = chunk2YCQFLXW_cjs.configuration().sendInterval;
200
205
  if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
201
206
  return 5e3;
202
207
  }
@@ -219,7 +224,7 @@ function patchGlobalFetch() {
219
224
  if (typeof globalThis.fetch !== "function") return;
220
225
  originalFetch = globalThis.fetch;
221
226
  const wrapped = (input, init) => {
222
- const id = chunkMMLQXSSD_cjs.current();
227
+ const id = chunk2YCQFLXW_cjs.current();
223
228
  if (!id) return originalFetch.call(globalThis, input, init);
224
229
  try {
225
230
  const enriched = injectHeader(input, init, id);
@@ -231,12 +236,50 @@ function patchGlobalFetch() {
231
236
  };
232
237
  globalThis.fetch = wrapped;
233
238
  patched = true;
239
+ subscribeUndiciRequests();
240
+ }
241
+ var subscribed = false;
242
+ function subscribeUndiciRequests() {
243
+ if (subscribed) return;
244
+ const channel = loadDiagnosticsChannel();
245
+ if (!channel) return;
246
+ channel.subscribe("undici:request:create", onUndiciRequest);
247
+ subscribed = true;
248
+ }
249
+ function onUndiciRequest(message) {
250
+ try {
251
+ const request = message?.request;
252
+ if (!request || typeof request.addHeader !== "function") return;
253
+ const id = chunk2YCQFLXW_cjs.current();
254
+ if (!id || hasCorrelationHeader(request.headers)) return;
255
+ request.addHeader(HEADER, id);
256
+ } catch (error) {
257
+ chunkTWTG5ILJ_cjs.logger.debug(`outgoing request header injection failed: ${describeError4(error)}`);
258
+ }
259
+ }
260
+ function hasCorrelationHeader(headers) {
261
+ if (Array.isArray(headers)) {
262
+ for (let i = 0; i < headers.length; i += 2) {
263
+ if (String(headers[i]).toLowerCase() === HEADER) return true;
264
+ }
265
+ return false;
266
+ }
267
+ if (typeof headers === "string") return headers.toLowerCase().includes(`${HEADER}:`);
268
+ return false;
269
+ }
270
+ function loadDiagnosticsChannel() {
271
+ const mod = chunk2YCQFLXW_cjs.loadNodeBuiltin(["diagnostics", "channel"].join("_"));
272
+ return typeof mod?.subscribe === "function" ? mod : null;
234
273
  }
235
274
  function unpatchGlobalFetch() {
236
275
  if (!patched || originalFetch === null) return;
237
276
  globalThis.fetch = originalFetch;
238
277
  originalFetch = null;
239
278
  patched = false;
279
+ if (subscribed) {
280
+ loadDiagnosticsChannel()?.unsubscribe("undici:request:create", onUndiciRequest);
281
+ subscribed = false;
282
+ }
240
283
  }
241
284
  function injectHeader(input, init, correlationId) {
242
285
  if (input instanceof Request && !init) {
@@ -355,7 +398,7 @@ function buildHttpSourceData(input) {
355
398
  source.graphql_variables = input.graphql.graphql_variables;
356
399
  }
357
400
  } else {
358
- const params = chunkYXZZNZG6_cjs.sanitizeRequestParams(input.rawParams, input.excludedVariableKeys);
401
+ const params = chunkUC2KS5EG_cjs.sanitizeRequestParams(input.rawParams, input.excludedVariableKeys);
359
402
  if (params !== null) source.request_params = params;
360
403
  }
361
404
  return compact(source);
@@ -455,11 +498,38 @@ function parseServerActionName(name) {
455
498
  }
456
499
  const canonical = KNOWN_VERBS.get(leading);
457
500
  if (!canonical) return { verb: null, entity: null };
458
- const entityTokens = tokens.slice(entityStart);
501
+ let rest = tokens.slice(entityStart);
502
+ const isConnector = (t) => CONNECTORS.has(t.toLowerCase());
503
+ if (rest.length > 0 && COMPOUND.has(rest[0].toLowerCase())) {
504
+ rest = rest.slice(2);
505
+ if (rest.length > 0 && isConnector(rest[0])) {
506
+ rest = rest.slice(rest.map(isConnector).lastIndexOf(true) + 1);
507
+ }
508
+ }
509
+ const firstConnector = rest.findIndex(isConnector);
510
+ const entityTokens = firstConnector === -1 ? rest : rest.slice(0, firstConnector);
459
511
  if (entityTokens.length === 0) return { verb: canonical, entity: null };
460
512
  const entity = entityTokens.join("");
461
513
  return { verb: canonical, entity: stripTrailingS(entity) || entity };
462
514
  }
515
+ var COMPOUND = /* @__PURE__ */ new Set(["and", "or", "then"]);
516
+ var CONNECTORS = /* @__PURE__ */ new Set([
517
+ ...COMPOUND,
518
+ "to",
519
+ "with",
520
+ "without",
521
+ "for",
522
+ "from",
523
+ "by",
524
+ "in",
525
+ "into",
526
+ "on",
527
+ "of",
528
+ "via",
529
+ "using",
530
+ "as",
531
+ "at"
532
+ ]);
463
533
  function stripTrailingS(entity) {
464
534
  if (entity.length <= 1) return entity;
465
535
  if (entity.endsWith("ies")) return `${entity.slice(0, -3)}y`;
@@ -505,7 +575,7 @@ function determineOutcome(statusCode, exception, graphqlResponseErrors, response
505
575
  }
506
576
  var MAX_SPECIFIC_ERROR_LENGTH = 200;
507
577
  function capErrorText(text) {
508
- const out = chunkYXZZNZG6_cjs.scrubSecretsInText(text, { emails: true });
578
+ const out = chunkUC2KS5EG_cjs.scrubSecretsInText(text, { emails: true });
509
579
  return out.length <= MAX_SPECIFIC_ERROR_LENGTH ? out : `${out.slice(0, MAX_SPECIFIC_ERROR_LENGTH - 1)}\u2026`;
510
580
  }
511
581
  var GENERIC_ERROR_TEXT = /^(?:validation(?: error| failed)?|invalid (?:input|request|data|body|payload|params|parameters|arguments)|bad request|unprocessable(?: entity| content)?|error|failed|request failed)[.!]?$/i;
@@ -543,9 +613,9 @@ function fieldMessage(path, message, userPatterns) {
543
613
  const text = message?.replace(/\s+/g, " ").trim().replace(/received\s+("[^"]*"|'[^']*'|`[^`]*`)/gi, "received [FILTERED]");
544
614
  if (!text) return null;
545
615
  const keys = path.filter((k) => k !== null && k !== "");
546
- if (keys.some((k) => chunkYXZZNZG6_cjs.isSensitiveKey(k, userPatterns))) return null;
616
+ if (keys.some((k) => chunkUC2KS5EG_cjs.isSensitiveKey(k, userPatterns))) return null;
547
617
  if (keys.length > 0) return `${keys.join(".")}: ${text}`;
548
- return text.split(/[^A-Za-z0-9_]+/).some((w) => w !== "" && chunkYXZZNZG6_cjs.isSensitiveKey(w, userPatterns)) ? null : text;
618
+ return text.split(/[^A-Za-z0-9_]+/).some((w) => w !== "" && chunkUC2KS5EG_cjs.isSensitiveKey(w, userPatterns)) ? null : text;
549
619
  }
550
620
  function pathKey(segment) {
551
621
  if (typeof segment === "string") return segment;
@@ -726,7 +796,7 @@ function parseGraphqlBody(body, excludedOperations, excludedVariableKeys) {
726
796
  return { metadata: "skip" };
727
797
  }
728
798
  const operationType = inferOperationTypeFromQuery(queryString) ?? inferOperationTypeFromName(operationName);
729
- const sanitizedVariables = chunkYXZZNZG6_cjs.sanitizeRequestParams(obj.variables, excludedVariableKeys);
799
+ const sanitizedVariables = chunkUC2KS5EG_cjs.sanitizeRequestParams(obj.variables, excludedVariableKeys);
730
800
  return {
731
801
  metadata: {
732
802
  graphql_operation: operationName ?? "anonymous",
@@ -784,7 +854,7 @@ function captureRoute(handler, context = {}) {
784
854
  return handler(...invokeArgs);
785
855
  };
786
856
  try {
787
- if (!chunkMMLQXSSD_cjs.configuration().captureHttp) {
857
+ if (!chunk2YCQFLXW_cjs.configuration().captureHttp) {
788
858
  return Promise.resolve(runHandler(...args));
789
859
  }
790
860
  const request = args[0];
@@ -794,10 +864,12 @@ function captureRoute(handler, context = {}) {
794
864
  const snapshot = await snapshotRequest(request);
795
865
  if (snapshot === null) return Promise.resolve(runHandler(...args));
796
866
  snapshot.rawParams = mergeRouteParams(snapshot.rawParams, await readRouteParams(args[1]));
797
- const correlationId = chunkMMLQXSSD_cjs.resolveCorrelation(request.headers ?? null);
798
- return await chunkMMLQXSSD_cjs.runWithCorrelation(
867
+ const correlationId = chunk2YCQFLXW_cjs.resolveCorrelation(request.headers ?? null);
868
+ const delivery = { jobDelivery: false };
869
+ const inngestServerKind = request.headers?.get?.(INNGEST_SERVER_KIND) ?? null;
870
+ return await chunk2YCQFLXW_cjs.runWithCorrelation(
799
871
  correlationId,
800
- () => runWithActorAndAuditScope(async () => {
872
+ () => chunkCHVJ4WPM_cjs.runWithDeliverySlot(delivery, () => runWithActorAndAuditScope(async () => {
801
873
  await maybeRunActorHook(request);
802
874
  const startMs = Date.now();
803
875
  let statusCode = null;
@@ -808,7 +880,10 @@ function captureRoute(handler, context = {}) {
808
880
  let followed = false;
809
881
  let handlerMs = null;
810
882
  const finish = async () => {
811
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
883
+ await chunk2YCQFLXW_cjs.maybeExtractSupabaseActor();
884
+ if (isJobRunnerSync(snapshot.method, inngestServerKind, response?.headers?.get?.(INNGEST_SDK) ?? null)) {
885
+ delivery.jobDelivery = true;
886
+ }
812
887
  await emitEvent({
813
888
  snapshot,
814
889
  context,
@@ -817,10 +892,11 @@ function captureRoute(handler, context = {}) {
817
892
  graphqlErrorMessage,
818
893
  responseErrorMessage,
819
894
  durationMs: handlerMs ?? Date.now() - startMs,
820
- startedAt: new Date(startMs)
895
+ startedAt: new Date(startMs),
896
+ jobDelivery: delivery.jobDelivery
821
897
  });
822
898
  await flushOnServerless();
823
- chunkMMLQXSSD_cjs.endCorrelationScope();
899
+ chunk2YCQFLXW_cjs.endCorrelationScope();
824
900
  };
825
901
  try {
826
902
  response = await Promise.resolve(runHandler(...args));
@@ -830,8 +906,8 @@ function captureRoute(handler, context = {}) {
830
906
  graphqlErrorMessage = await readGraphqlErrors(response);
831
907
  }
832
908
  const trpcRoute = isTrpcRoute(snapshot.rawParams, context.routeModulePath ?? null);
833
- responseErrorMessage = await readResponseErrorMessage(response, trpcRoute);
834
- const trpcStream = responseErrorMessage === null && trpcRoute ? trpcStreamErrorScanner(chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys) : null;
909
+ responseErrorMessage = await readResponseErrorMessage(response, trpcRoute) ?? authRedirectError(snapshot.url, response.status, response.headers.get("location"));
910
+ const trpcStream = responseErrorMessage === null && trpcRoute ? trpcStreamErrorScanner(chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys) : null;
835
911
  const followedResponse = followBody(
836
912
  response,
837
913
  snapshot.method,
@@ -857,9 +933,12 @@ function captureRoute(handler, context = {}) {
857
933
  statusCode = 500;
858
934
  throw e;
859
935
  } finally {
860
- if (!followed) await finish();
936
+ if (!followed) {
937
+ await chunk2YCQFLXW_cjs.maybeExtractSupabaseActor();
938
+ await offTheResponse(finish);
939
+ }
861
940
  }
862
- })
941
+ }))
863
942
  );
864
943
  } catch (preCaptureError) {
865
944
  if (handlerInvoked) throw preCaptureError;
@@ -879,12 +958,12 @@ function withMiddlewareCapture(middleware) {
879
958
  return middleware(req, ...mRest);
880
959
  };
881
960
  try {
882
- const correlationId = chunkMMLQXSSD_cjs.resolveCorrelation(request.headers);
961
+ const correlationId = chunk2YCQFLXW_cjs.resolveCorrelation(request.headers);
883
962
  try {
884
963
  request.headers.set(CORRELATION_HEADER, correlationId);
885
964
  } catch {
886
965
  }
887
- return await chunkMMLQXSSD_cjs.runWithCorrelation(
966
+ return await chunk2YCQFLXW_cjs.runWithCorrelation(
888
967
  correlationId,
889
968
  () => runWithActorAndAuditScope(async () => {
890
969
  const startMs = Date.now();
@@ -898,20 +977,27 @@ function withMiddlewareCapture(middleware) {
898
977
  }
899
978
  try {
900
979
  if (shouldEmitPageNavigation(request)) {
980
+ const durationMs = Date.now() - startMs;
901
981
  await maybeRunActorHook(request);
902
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
903
- await emitPageNavigationEvent({
904
- request,
905
- statusCode: typeof response?.status === "number" ? response.status : null,
906
- durationMs: Date.now() - startMs,
907
- startedAt
908
- });
982
+ await chunk2YCQFLXW_cjs.maybeExtractSupabaseActor();
983
+ const event = rest[0];
984
+ await offTheResponse(
985
+ async () => {
986
+ await emitPageNavigationEvent({
987
+ request,
988
+ statusCode: typeof response?.status === "number" ? response.status : null,
989
+ durationMs,
990
+ startedAt
991
+ });
992
+ },
993
+ typeof event?.waitUntil === "function" ? event.waitUntil.bind(event) : null
994
+ );
909
995
  }
910
996
  } catch (error) {
911
997
  chunkTWTG5ILJ_cjs.logger.debug(`page navigation capture failed: ${describeError5(error)}`);
912
998
  }
913
999
  return response;
914
- }).finally(chunkMMLQXSSD_cjs.endCorrelationScope)
1000
+ }).finally(chunk2YCQFLXW_cjs.endCorrelationScope)
915
1001
  );
916
1002
  } catch (preCaptureError) {
917
1003
  if (middlewareInvoked) throw preCaptureError;
@@ -972,25 +1058,25 @@ async function emitPageNavigationEvent(input) {
972
1058
  userAgent,
973
1059
  remoteIp,
974
1060
  contentType: null,
975
- excludedVariableKeys: chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys
1061
+ excludedVariableKeys: chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys
976
1062
  });
977
1063
  const { outcome, error_message } = determineOutcome(
978
1064
  input.statusCode,
979
1065
  null,
980
1066
  null
981
1067
  );
982
- const event = chunkYXZZNZG6_cjs.build({
1068
+ const event = chunkUC2KS5EG_cjs.build({
983
1069
  source_type: "http_request",
984
1070
  source_data: sourceData,
985
1071
  outcome,
986
- correlation_id: chunkMMLQXSSD_cjs.current(),
1072
+ correlation_id: chunk2YCQFLXW_cjs.current(),
987
1073
  resource_ids: [],
988
- context: chunkMMLQXSSD_cjs.getCurrentActor() ? { actor: chunkMMLQXSSD_cjs.getCurrentActor() } : null,
1074
+ context: chunk2YCQFLXW_cjs.getCurrentActor() ? { actor: chunk2YCQFLXW_cjs.getCurrentActor() } : null,
989
1075
  duration_ms: input.durationMs,
990
1076
  error_message,
991
1077
  timestamp: input.startedAt
992
1078
  });
993
- chunkYXZZNZG6_cjs.pushEvent(event);
1079
+ chunkUC2KS5EG_cjs.pushEvent(event);
994
1080
  } catch (error) {
995
1081
  chunkTWTG5ILJ_cjs.logger.error(`page navigation emit failed: ${describeError5(error)}`);
996
1082
  }
@@ -1015,7 +1101,7 @@ function capturePagesApi(handler, context = {}) {
1015
1101
  return handler(...invokeArgs);
1016
1102
  };
1017
1103
  try {
1018
- if (!chunkMMLQXSSD_cjs.configuration().captureHttp) {
1104
+ if (!chunk2YCQFLXW_cjs.configuration().captureHttp) {
1019
1105
  return Promise.resolve(runHandler(...args));
1020
1106
  }
1021
1107
  const req = args[0];
@@ -1023,12 +1109,14 @@ function capturePagesApi(handler, context = {}) {
1023
1109
  if (!req || !res) return Promise.resolve(runHandler(...args));
1024
1110
  const snapshot = snapshotPagesRequest(req);
1025
1111
  if (snapshot === null) return Promise.resolve(runHandler(...args));
1026
- const correlationId = chunkMMLQXSSD_cjs.resolveCorrelation({
1112
+ const correlationId = chunk2YCQFLXW_cjs.resolveCorrelation({
1027
1113
  get: (name) => readPagesHeader(req, name)
1028
1114
  });
1029
- return await chunkMMLQXSSD_cjs.runWithCorrelation(
1115
+ const delivery = { jobDelivery: false };
1116
+ const inngestServerKind = readPagesHeader(req, INNGEST_SERVER_KIND);
1117
+ return await chunk2YCQFLXW_cjs.runWithCorrelation(
1030
1118
  correlationId,
1031
- () => runWithActorAndAuditScope(async () => {
1119
+ () => chunkCHVJ4WPM_cjs.runWithDeliverySlot(delivery, () => runWithActorAndAuditScope(async () => {
1032
1120
  await maybeRunActorHookFromPages(req);
1033
1121
  const startMs = Date.now();
1034
1122
  let exception = null;
@@ -1039,20 +1127,33 @@ function capturePagesApi(handler, context = {}) {
1039
1127
  exception = e instanceof Error ? e : new Error(String(e));
1040
1128
  throw e;
1041
1129
  } finally {
1042
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
1130
+ await chunk2YCQFLXW_cjs.maybeExtractSupabaseActor();
1131
+ const status = typeof res.statusCode === "number" ? res.statusCode : null;
1132
+ const getHeader = res.getHeader;
1133
+ const sdkHeader = typeof getHeader === "function" ? getHeader.call(res, INNGEST_SDK) : null;
1134
+ if (isJobRunnerSync(snapshot.method, inngestServerKind, sdkHeader ? String(sdkHeader) : null)) {
1135
+ delivery.jobDelivery = true;
1136
+ }
1043
1137
  await emitEvent({
1044
1138
  snapshot,
1045
1139
  context,
1046
- statusCode: typeof res.statusCode === "number" ? res.statusCode : null,
1140
+ statusCode: status,
1047
1141
  exception,
1048
1142
  graphqlErrorMessage: null,
1143
+ // NextAuth v4 under pages/api/auth: a failed sign-in redirects to ?error=.
1144
+ responseErrorMessage: authRedirectError(
1145
+ snapshot.url,
1146
+ status,
1147
+ typeof getHeader === "function" ? getHeader.call(res, "location") : null
1148
+ ),
1049
1149
  durationMs: Date.now() - startMs,
1050
- startedAt: new Date(startMs)
1150
+ startedAt: new Date(startMs),
1151
+ jobDelivery: delivery.jobDelivery
1051
1152
  });
1052
1153
  await flushOnServerless();
1053
- chunkMMLQXSSD_cjs.endCorrelationScope();
1154
+ chunk2YCQFLXW_cjs.endCorrelationScope();
1054
1155
  }
1055
- })
1156
+ }))
1056
1157
  );
1057
1158
  } catch (preCaptureError) {
1058
1159
  if (handlerInvoked) throw preCaptureError;
@@ -1071,39 +1172,33 @@ function captureServerAction(action, actionName) {
1071
1172
  return action(...invokeArgs);
1072
1173
  };
1073
1174
  try {
1074
- if (!chunkMMLQXSSD_cjs.configuration().captureHttp) {
1175
+ if (!chunk2YCQFLXW_cjs.configuration().captureHttp) {
1075
1176
  return Promise.resolve(runAction(...args));
1076
1177
  }
1077
1178
  const headersAdapter = await readNextHeadersAsAdapter();
1078
- const correlationId = chunkMMLQXSSD_cjs.resolveCorrelation(headersAdapter);
1079
- return await chunkMMLQXSSD_cjs.runWithCorrelation(
1179
+ const correlationId = chunk2YCQFLXW_cjs.resolveCorrelation(headersAdapter);
1180
+ return await chunk2YCQFLXW_cjs.runWithCorrelation(
1080
1181
  correlationId,
1081
1182
  () => runWithActorAndAuditScope(async () => {
1082
1183
  const startMs = Date.now();
1083
1184
  const startedAt = new Date(startMs);
1084
1185
  let exception = null;
1085
1186
  await maybeRunActorHookFromServerAction();
1086
- try {
1087
- const result = await Promise.resolve(runAction(...args));
1088
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
1089
- const failure = classifyServerActionResult(result);
1090
- await emitServerActionEvent({
1091
- actionName,
1092
- // A returned failure (`{ success: false, error }`) is a
1093
- // handled refusal, not a crash: no HTTP status is
1094
- // invented; outcome + error_message carry it.
1095
- statusCode: failure ? null : 200,
1096
- exception: failure ? new Error(failure.errorMessage) : null,
1097
- durationMs: Date.now() - startMs,
1098
- startedAt,
1099
- args
1187
+ const record = async (input) => {
1188
+ await chunk2YCQFLXW_cjs.maybeExtractSupabaseActor();
1189
+ await offTheResponse(async () => {
1190
+ await emitServerActionEvent(input);
1191
+ await flushOnServerless();
1192
+ chunk2YCQFLXW_cjs.endCorrelationScope();
1100
1193
  });
1101
- return result;
1194
+ };
1195
+ let result;
1196
+ try {
1197
+ result = await Promise.resolve(runAction(...args));
1102
1198
  } catch (e) {
1103
1199
  if (isNextControlFlowError(e)) {
1104
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
1105
1200
  const controlStatus = nextControlFlowStatus(e) ?? 200;
1106
- await emitServerActionEvent({
1201
+ await record({
1107
1202
  actionName,
1108
1203
  // redirect() is a success; notFound() / forbidden()
1109
1204
  // keep their 4xx.
@@ -1117,8 +1212,7 @@ function captureServerAction(action, actionName) {
1117
1212
  throw e;
1118
1213
  }
1119
1214
  exception = e instanceof Error ? e : new Error(String(e));
1120
- await chunkMMLQXSSD_cjs.maybeExtractSupabaseActor();
1121
- await emitServerActionEvent({
1215
+ await record({
1122
1216
  actionName,
1123
1217
  statusCode: 500,
1124
1218
  exception,
@@ -1127,10 +1221,25 @@ function captureServerAction(action, actionName) {
1127
1221
  args
1128
1222
  });
1129
1223
  throw e;
1130
- } finally {
1131
- await flushOnServerless();
1132
- chunkMMLQXSSD_cjs.endCorrelationScope();
1133
1224
  }
1225
+ let failure = null;
1226
+ try {
1227
+ failure = classifyServerActionResult(result);
1228
+ } catch (e) {
1229
+ chunkTWTG5ILJ_cjs.logger.debug(`server action result classification failed: ${describeError5(e)}`);
1230
+ }
1231
+ await record({
1232
+ actionName,
1233
+ // A returned failure (`{ success: false, error }`) is a
1234
+ // handled refusal, not a crash: no HTTP status is
1235
+ // invented; outcome + error_message carry it.
1236
+ statusCode: failure ? null : 200,
1237
+ exception: failure ? new Error(failure.errorMessage) : null,
1238
+ durationMs: Date.now() - startMs,
1239
+ startedAt,
1240
+ args
1241
+ });
1242
+ return result;
1134
1243
  })
1135
1244
  );
1136
1245
  } catch (preCaptureError) {
@@ -1157,7 +1266,7 @@ async function __ezlogs_run_inline_server_action(actionName, body) {
1157
1266
  return wrapped();
1158
1267
  }
1159
1268
  function classifyServerActionResult(result) {
1160
- const classifier = chunkMMLQXSSD_cjs.configuration().isServerActionError;
1269
+ const classifier = chunk2YCQFLXW_cjs.configuration().isServerActionError;
1161
1270
  if (classifier) {
1162
1271
  try {
1163
1272
  const verdict = classifier(result);
@@ -1233,7 +1342,7 @@ function hasErrorEntries(errors, depth = 0) {
1233
1342
  return Object.values(errors).some((v) => hasErrorEntries(v, depth + 1));
1234
1343
  }
1235
1344
  function formStateErrorMessage(r) {
1236
- const patterns = chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys;
1345
+ const patterns = chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys;
1237
1346
  const specific = Array.isArray(r.errors) ? specificErrorMessage({ errors: r.errors }, patterns) ?? specificErrorMessage({ formErrors: r.errors }, patterns) : specificErrorMessage({ fieldErrors: r.errors }, patterns);
1238
1347
  if (specific) return capErrorText(specific);
1239
1348
  if (typeof r.message === "string" && r.message.trim().length > 0) {
@@ -1261,7 +1370,7 @@ function defaultErrorMessage(result) {
1261
1370
  }
1262
1371
  var MAX_ERROR_MESSAGE_LENGTH = 200;
1263
1372
  function specificOrOwn(result, error) {
1264
- const specific = isGenericErrorText(error) ? specificErrorMessage(result, chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys) : null;
1373
+ const specific = isGenericErrorText(error) ? specificErrorMessage(result, chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys) : null;
1265
1374
  return capErrorText(specific ?? error);
1266
1375
  }
1267
1376
  function truncate(value) {
@@ -1279,7 +1388,7 @@ function isZodErrorLike(value) {
1279
1388
  return Array.isArray(issues) && issues.length > 0;
1280
1389
  }
1281
1390
  function formatZodIssues(issues) {
1282
- const patterns = chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys;
1391
+ const patterns = chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys;
1283
1392
  const messages = [];
1284
1393
  for (const issue of issues) {
1285
1394
  const m = issueMessage(issue, patterns);
@@ -1368,7 +1477,7 @@ function redirectPath(target, requestHost) {
1368
1477
  const url = new URL(target, "http://ezlogs.internal");
1369
1478
  if (absolute && (!requestHost || url.host.toLowerCase() !== requestHost.toLowerCase())) return null;
1370
1479
  const path = url.pathname.split("/").map((seg) => /^[A-Za-z0-9_-]{20,}$/.test(seg) && !UUID.test(seg) ? "[FILTERED]" : seg).join("/");
1371
- return path ? chunkYXZZNZG6_cjs.scrubSecretsInText(path, { emails: true }) : null;
1480
+ return path ? chunkUC2KS5EG_cjs.scrubSecretsInText(path, { emails: true }) : null;
1372
1481
  } catch {
1373
1482
  return null;
1374
1483
  }
@@ -1382,9 +1491,9 @@ async function emitServerActionEvent(input) {
1382
1491
  const fromPage = referer ?? nextUrl ?? null;
1383
1492
  const argParams = extractServerActionArgs(input.args, input.actionName);
1384
1493
  const combined = argParams !== null || fromPage !== null ? { ...argParams ?? {}, ...fromPage !== null ? { from_page: fromPage } : {} } : null;
1385
- const requestParams = chunkYXZZNZG6_cjs.maskAuthParams(
1494
+ const requestParams = chunkUC2KS5EG_cjs.maskAuthParams(
1386
1495
  combined,
1387
- chunkYXZZNZG6_cjs.isAuthActionName(input.actionName) || chunkYXZZNZG6_cjs.isAuthPath(pathOf(fromPage))
1496
+ chunkUC2KS5EG_cjs.isAuthActionName(input.actionName) || chunkUC2KS5EG_cjs.isAuthPath(pathOf(fromPage))
1388
1497
  );
1389
1498
  const syntheticUrl = new URL(
1390
1499
  `http://localhost/__server-action/${encodeURIComponent(input.actionName)}`
@@ -1399,7 +1508,7 @@ async function emitServerActionEvent(input) {
1399
1508
  userAgent,
1400
1509
  remoteIp: extractRemoteIp(await readNextHeadersAsAdapter()),
1401
1510
  contentType: null,
1402
- excludedVariableKeys: chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys
1511
+ excludedVariableKeys: chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys
1403
1512
  });
1404
1513
  if (input.redirectTo) {
1405
1514
  const host = await readNextHeader("x-forwarded-host") ?? await readNextHeader("host");
@@ -1411,18 +1520,18 @@ async function emitServerActionEvent(input) {
1411
1520
  input.exception,
1412
1521
  null
1413
1522
  );
1414
- const event = chunkYXZZNZG6_cjs.build({
1523
+ const event = chunkUC2KS5EG_cjs.build({
1415
1524
  source_type: "http_request",
1416
1525
  source_data: sourceData,
1417
1526
  outcome,
1418
- correlation_id: chunkMMLQXSSD_cjs.current(),
1527
+ correlation_id: chunk2YCQFLXW_cjs.current(),
1419
1528
  resource_ids: [],
1420
- context: chunkMMLQXSSD_cjs.getCurrentActor() ? { actor: chunkMMLQXSSD_cjs.getCurrentActor() } : null,
1529
+ context: chunk2YCQFLXW_cjs.getCurrentActor() ? { actor: chunk2YCQFLXW_cjs.getCurrentActor() } : null,
1421
1530
  duration_ms: input.durationMs,
1422
1531
  error_message,
1423
1532
  timestamp: input.startedAt
1424
1533
  });
1425
- chunkYXZZNZG6_cjs.pushEvent(event);
1534
+ chunkUC2KS5EG_cjs.pushEvent(event);
1426
1535
  } catch (error) {
1427
1536
  chunkTWTG5ILJ_cjs.logger.error(`server-action capture emit failed: ${describeError5(error)}`);
1428
1537
  }
@@ -1505,7 +1614,7 @@ function actionWords(name) {
1505
1614
  return name.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([a-zA-Z])(\d)/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
1506
1615
  }
1507
1616
  function looksLikeCardNumber(digits, paymentAction) {
1508
- if (digits.length < 13 || digits.length > 19 || !chunkYXZZNZG6_cjs.passesLuhn(digits)) return false;
1617
+ if (digits.length < 13 || digits.length > 19 || !chunkUC2KS5EG_cjs.passesLuhn(digits)) return false;
1509
1618
  return paymentAction || digits.length === 15 || digits.length === 16;
1510
1619
  }
1511
1620
  function maskPositional(value, flags) {
@@ -1593,7 +1702,7 @@ function serializeArgValue(value) {
1593
1702
  return void 0;
1594
1703
  }
1595
1704
  async function captureHttpEvent(input) {
1596
- if (!chunkMMLQXSSD_cjs.configuration().captureHttp) return;
1705
+ if (!chunk2YCQFLXW_cjs.configuration().captureHttp) return;
1597
1706
  const snapshot = await snapshotRequest(input.request);
1598
1707
  if (snapshot === null) return;
1599
1708
  let graphqlErrorMessage = null;
@@ -1659,7 +1768,7 @@ async function snapshotRequest(request) {
1659
1768
  return { method, url, userAgent, remoteIp, contentType, rawParams, graphqlBody, serverActionId };
1660
1769
  }
1661
1770
  async function maybeRunActorHook(request) {
1662
- const hook = chunkMMLQXSSD_cjs.configuration().actorFromRequest;
1771
+ const hook = chunk2YCQFLXW_cjs.configuration().actorFromRequest;
1663
1772
  let hookResult = null;
1664
1773
  if (hook) {
1665
1774
  try {
@@ -1672,7 +1781,7 @@ async function maybeRunActorHook(request) {
1672
1781
  applyActorFromHookAndUa(hookResult, userAgent);
1673
1782
  }
1674
1783
  async function maybeRunActorHookFromPages(req) {
1675
- const hook = chunkMMLQXSSD_cjs.configuration().actorFromRequest;
1784
+ const hook = chunk2YCQFLXW_cjs.configuration().actorFromRequest;
1676
1785
  let hookResult = null;
1677
1786
  if (hook) {
1678
1787
  try {
@@ -1686,7 +1795,7 @@ async function maybeRunActorHookFromPages(req) {
1686
1795
  applyActorFromHookAndUa(hookResult, userAgent);
1687
1796
  }
1688
1797
  async function maybeRunActorHookFromServerAction() {
1689
- const hook = chunkMMLQXSSD_cjs.configuration().actorFromRequest;
1798
+ const hook = chunk2YCQFLXW_cjs.configuration().actorFromRequest;
1690
1799
  const headers = await loadNextHeaders();
1691
1800
  if (!hook && !headers) {
1692
1801
  chunkTWTG5ILJ_cjs.logger.debug("actorFromRequest (server action): no hook + no next/headers");
@@ -1828,10 +1937,17 @@ function readPagesHeader(req, name) {
1828
1937
  if (Array.isArray(value)) return value[0] ?? null;
1829
1938
  return null;
1830
1939
  }
1940
+ var INNGEST_SERVER_KIND = "x-inngest-server-kind";
1941
+ var INNGEST_SDK = "x-inngest-sdk";
1942
+ function isJobRunnerSync(method, inngestServerKind, sdkResponseHeader) {
1943
+ const m = (method ?? "").toUpperCase();
1944
+ return inngestServerKind !== null && sdkResponseHeader !== null && (m === "GET" || m === "PUT");
1945
+ }
1831
1946
  async function emitEvent(input) {
1832
1947
  try {
1833
1948
  await flushTriggerAuditLog();
1834
- const config = chunkMMLQXSSD_cjs.configuration();
1949
+ if (input.jobDelivery) return;
1950
+ const config = chunk2YCQFLXW_cjs.configuration();
1835
1951
  let graphql = null;
1836
1952
  if (input.snapshot.graphqlBody !== null) {
1837
1953
  const parsed = parseGraphqlBody(
@@ -1847,9 +1963,9 @@ async function emitEvent(input) {
1847
1963
  method: input.snapshot.method,
1848
1964
  url: input.snapshot.url,
1849
1965
  statusCode: input.statusCode,
1850
- rawParams: chunkYXZZNZG6_cjs.maskAuthParams(
1966
+ rawParams: chunkUC2KS5EG_cjs.maskAuthParams(
1851
1967
  unwrapTrpcParams(input.snapshot.rawParams, input.snapshot.url, input.context.routeModulePath ?? null),
1852
- chunkYXZZNZG6_cjs.isAuthPath(input.snapshot.url.pathname)
1968
+ chunkUC2KS5EG_cjs.isAuthPath(input.snapshot.url.pathname)
1853
1969
  ),
1854
1970
  routeModulePath: input.context.routeModulePath ?? null,
1855
1971
  serverActionName,
@@ -1867,20 +1983,20 @@ async function emitEvent(input) {
1867
1983
  input.responseErrorMessage ?? null
1868
1984
  );
1869
1985
  const contextValue = buildContext();
1870
- const event = chunkYXZZNZG6_cjs.build({
1986
+ const event = chunkUC2KS5EG_cjs.build({
1871
1987
  source_type: "http_request",
1872
1988
  source_data: sourceData,
1873
1989
  outcome,
1874
- correlation_id: chunkMMLQXSSD_cjs.current(),
1990
+ correlation_id: chunk2YCQFLXW_cjs.current(),
1875
1991
  resource_ids: [],
1876
1992
  context: contextValue,
1877
1993
  duration_ms: input.durationMs,
1878
1994
  error_message,
1879
1995
  timestamp: input.startedAt
1880
1996
  });
1881
- chunkYXZZNZG6_cjs.pushEvent(event);
1997
+ chunkUC2KS5EG_cjs.pushEvent(event);
1882
1998
  } catch (error) {
1883
- const cid = chunkMMLQXSSD_cjs.current();
1999
+ const cid = chunk2YCQFLXW_cjs.current();
1884
2000
  const cidLabel = cid ? ` (correlation_id=${cid})` : "";
1885
2001
  chunkTWTG5ILJ_cjs.logger.error(`http capture emit failed${cidLabel}: ${describeError5(error)}`);
1886
2002
  }
@@ -1888,7 +2004,7 @@ async function emitEvent(input) {
1888
2004
  function followBody(response, method, onDone, onChunk) {
1889
2005
  try {
1890
2006
  if (!response.body || method === "HEAD" || response.bodyUsed) return null;
1891
- const capture = chunkMMLQXSSD_cjs.makeAsyncContextCapture();
2007
+ const capture = chunk2YCQFLXW_cjs.makeAsyncContextCapture();
1892
2008
  if (!capture) return null;
1893
2009
  const keepAlive = isServerless() ? platformWaitUntil() : null;
1894
2010
  if (isServerless() && !keepAlive) return null;
@@ -1942,6 +2058,26 @@ function followBody(response, method, onDone, onChunk) {
1942
2058
  return null;
1943
2059
  }
1944
2060
  }
2061
+ async function offTheResponse(work, waitUntil = null) {
2062
+ const done = work().catch((e) => chunkTWTG5ILJ_cjs.logger.debug(`capture failed: ${describeError5(e)}`));
2063
+ if (!isServerless()) return;
2064
+ try {
2065
+ const keepAlive = waitUntil ?? platformWaitUntil();
2066
+ if (keepAlive) {
2067
+ keepAlive(done);
2068
+ return;
2069
+ }
2070
+ } catch (e) {
2071
+ chunkTWTG5ILJ_cjs.logger.debug(`waitUntil unavailable, recording inline: ${describeError5(e)}`);
2072
+ }
2073
+ let timer;
2074
+ await Promise.race([
2075
+ done,
2076
+ new Promise((resolve) => {
2077
+ timer = setTimeout(resolve, SERVERLESS_INLINE_FLUSH_MS);
2078
+ })
2079
+ ]).finally(() => clearTimeout(timer));
2080
+ }
1945
2081
  var SERVERLESS_INLINE_FLUSH_MS = 2e3;
1946
2082
  async function flushOnServerless() {
1947
2083
  if (!isServerless()) return;
@@ -1979,23 +2115,38 @@ function platformWaitUntil() {
1979
2115
  return null;
1980
2116
  }
1981
2117
  function buildContext() {
1982
- const currentActor = chunkMMLQXSSD_cjs.getCurrentActor();
2118
+ const currentActor = chunk2YCQFLXW_cjs.getCurrentActor();
1983
2119
  if (!currentActor) return null;
1984
2120
  return { actor: currentActor };
1985
2121
  }
1986
2122
  async function flushTriggerAuditLog() {
1987
- const reader = chunkMMLQXSSD_cjs.configuration().databaseReader;
2123
+ const reader = chunk2YCQFLXW_cjs.configuration().databaseReader;
1988
2124
  if (!reader) return;
1989
- await chunkGMHOUAKD_cjs.flushAuditLog(reader);
2125
+ const work = chunkEXGEA4KE_cjs.flushAuditLog(reader).catch(
2126
+ (e) => chunkTWTG5ILJ_cjs.logger.debug(`trigger audit flush failed: ${describeError5(e)}`)
2127
+ );
2128
+ if (!isServerless()) return;
2129
+ const waitUntil = platformWaitUntil();
2130
+ if (waitUntil) {
2131
+ waitUntil(work.then(() => flushScheduler.flushNow()));
2132
+ return;
2133
+ }
2134
+ let timer;
2135
+ await Promise.race([
2136
+ work,
2137
+ new Promise((resolve) => {
2138
+ timer = setTimeout(resolve, SERVERLESS_INLINE_FLUSH_MS);
2139
+ })
2140
+ ]).finally(() => clearTimeout(timer));
1990
2141
  }
1991
2142
  function runWithActorAndAuditScope(callback) {
1992
- if (chunkMMLQXSSD_cjs.configuration().databaseReader == null) {
1993
- return chunkMMLQXSSD_cjs.runWithActorScope(callback);
2143
+ if (chunk2YCQFLXW_cjs.configuration().databaseReader == null) {
2144
+ return chunk2YCQFLXW_cjs.runWithActorScope(callback);
1994
2145
  }
1995
- return chunkMMLQXSSD_cjs.runWithActorScope(() => chunkGMHOUAKD_cjs.runWithEmittedAuditIdsScope(callback));
2146
+ return chunk2YCQFLXW_cjs.runWithActorScope(() => chunkEXGEA4KE_cjs.runWithEmittedAuditIdsScope(callback));
1996
2147
  }
1997
2148
  function isExcludedPath(path, method) {
1998
- const config = chunkMMLQXSSD_cjs.configuration();
2149
+ const config = chunk2YCQFLXW_cjs.configuration();
1999
2150
  const normalizedMethod = (method ?? "").toUpperCase();
2000
2151
  for (const pattern of config.allExcludedPaths()) {
2001
2152
  if (typeof pattern === "string") {
@@ -2007,7 +2158,7 @@ function isExcludedPath(path, method) {
2007
2158
  return true;
2008
2159
  }
2009
2160
  }
2010
- if (hasExcludedExtension(path, chunkMMLQXSSD_cjs.DEFAULT_EXCLUDED_EXTENSIONS)) return true;
2161
+ if (hasExcludedExtension(path, chunk2YCQFLXW_cjs.DEFAULT_EXCLUDED_EXTENSIONS)) return true;
2011
2162
  return false;
2012
2163
  }
2013
2164
  function extractRemoteIp(headers) {
@@ -2045,6 +2196,16 @@ function mergeRouteParams(rawParams, routeParams) {
2045
2196
  return { ...routeParams, ...rawParams };
2046
2197
  }
2047
2198
  var MAX_ERROR_BODY_LENGTH = 16384;
2199
+ function authRedirectError(url, status, location) {
2200
+ try {
2201
+ if (typeof status !== "number" || status < 300 || status >= 400 || !chunkUC2KS5EG_cjs.isAuthPath(url.pathname)) return null;
2202
+ if (typeof location !== "string" || !location) return null;
2203
+ const reason = new URL(location, url).searchParams.get("error");
2204
+ return reason ? capErrorText(reason) : null;
2205
+ } catch {
2206
+ return null;
2207
+ }
2208
+ }
2048
2209
  async function readResponseErrorMessage(response, trpcRoute = false) {
2049
2210
  try {
2050
2211
  if (response.status < 400 && response.status !== 207) return null;
@@ -2053,7 +2214,7 @@ async function readResponseErrorMessage(response, trpcRoute = false) {
2053
2214
  const text = await response.clone().text();
2054
2215
  if (!text || text.length > MAX_ERROR_BODY_LENGTH) return null;
2055
2216
  const parsed = safeJsonParse2(text);
2056
- const trpc = trpcErrorMessage(parsed, chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys);
2217
+ const trpc = trpcErrorMessage(parsed, chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys);
2057
2218
  if (trpc) return trpc;
2058
2219
  if (response.status === 207) return null;
2059
2220
  const body = parsed;
@@ -2062,9 +2223,9 @@ async function readResponseErrorMessage(response, trpcRoute = false) {
2062
2223
  const raw = [body.error, body.message, nested?.message].find(
2063
2224
  (v) => typeof v === "string" && v.trim().length > 0
2064
2225
  );
2065
- const specific = !raw || isGenericErrorText(raw) ? specificErrorMessage(body, chunkMMLQXSSD_cjs.configuration().excludedGraphqlVariableKeys) : null;
2226
+ const specific = !raw || isGenericErrorText(raw) ? specificErrorMessage(body, chunk2YCQFLXW_cjs.configuration().excludedGraphqlVariableKeys) : null;
2066
2227
  if (specific) return capErrorText(specific);
2067
- return raw ? truncate(chunkYXZZNZG6_cjs.scrubSecretsInText(raw.trim(), { emails: true })) : null;
2228
+ return raw ? truncate(chunkUC2KS5EG_cjs.scrubSecretsInText(raw.trim(), { emails: true })) : null;
2068
2229
  } catch {
2069
2230
  return null;
2070
2231
  }
@@ -2088,23 +2249,23 @@ function applyActorFromHookAndUa(hookResult, userAgent) {
2088
2249
  const uaMatch = classifyUserAgent(userAgent);
2089
2250
  if (hookResult != null && typeof hookResult === "object" && !Array.isArray(hookResult)) {
2090
2251
  if (uaMatch === null) {
2091
- chunkMMLQXSSD_cjs.setActor(hookResult);
2252
+ chunk2YCQFLXW_cjs.setActor(hookResult);
2092
2253
  return;
2093
2254
  }
2094
2255
  const hookObj = hookResult;
2095
2256
  const existingKind = hookObj.kind;
2096
2257
  if (typeof existingKind === "string" && existingKind.length > 0) {
2097
- chunkMMLQXSSD_cjs.setActor(hookObj);
2258
+ chunk2YCQFLXW_cjs.setActor(hookObj);
2098
2259
  return;
2099
2260
  }
2100
- chunkMMLQXSSD_cjs.setActor({ ...hookObj, kind: uaMatch.kind });
2261
+ chunk2YCQFLXW_cjs.setActor({ ...hookObj, kind: uaMatch.kind });
2101
2262
  return;
2102
2263
  }
2103
2264
  if (uaMatch !== null) {
2104
- chunkMMLQXSSD_cjs.setActor(synthesizeAgentActor(uaMatch));
2265
+ chunk2YCQFLXW_cjs.setActor(synthesizeAgentActor(uaMatch));
2105
2266
  return;
2106
2267
  }
2107
- chunkMMLQXSSD_cjs.setActor(null);
2268
+ chunk2YCQFLXW_cjs.setActor(null);
2108
2269
  }
2109
2270
  function synthesizeAgentActor(detection) {
2110
2271
  return {
@@ -2152,7 +2313,7 @@ function _resetStartupAnnouncementForTests() {
2152
2313
  }
2153
2314
  var ezlogs = {
2154
2315
  init(options) {
2155
- const config = chunkMMLQXSSD_cjs.configuration();
2316
+ const config = chunk2YCQFLXW_cjs.configuration();
2156
2317
  config.apply(options);
2157
2318
  if (options.logLevel) chunkTWTG5ILJ_cjs.setLogLevel(options.logLevel);
2158
2319
  warnIfInsecureServerUrl(config.serverUrl, config.allowInsecureTransport);
@@ -2171,7 +2332,7 @@ var ezlogs = {
2171
2332
  }
2172
2333
  });
2173
2334
  } else if (options.patchDatabaseClient) {
2174
- chunkNX4EL7BY_cjs.patchPgClient(
2335
+ chunkXWEBKN65_cjs.patchPgClient(
2175
2336
  options.patchDatabaseClient
2176
2337
  );
2177
2338
  }
@@ -2218,7 +2379,7 @@ function detectDatabaseUrlFromEnv() {
2218
2379
  return null;
2219
2380
  }
2220
2381
  async function autoWireTriggerPathFromDatabaseUrl(options) {
2221
- const config = chunkMMLQXSSD_cjs.configuration();
2382
+ const config = chunk2YCQFLXW_cjs.configuration();
2222
2383
  let pg;
2223
2384
  try {
2224
2385
  const dynImport = new Function(
@@ -2237,7 +2398,7 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
2237
2398
  max: 4
2238
2399
  });
2239
2400
  const reader = (sql, params) => pool.query(sql, params);
2240
- if (await chunkGMHOUAKD_cjs.auditLogInstalled(reader) === false) {
2401
+ if (await chunkEXGEA4KE_cjs.auditLogInstalled(reader) === false) {
2241
2402
  warnAuditLogMissing();
2242
2403
  void pool.end?.().catch(() => {
2243
2404
  });
@@ -2246,21 +2407,21 @@ async function autoWireTriggerPathFromDatabaseUrl(options) {
2246
2407
  if (config.databaseReader === null) {
2247
2408
  config.databaseReader = reader;
2248
2409
  }
2249
- chunkNX4EL7BY_cjs.patchPgClient(pg);
2250
- void chunkGMHOUAKD_cjs.checkAuditLogAccess(reader);
2410
+ chunkXWEBKN65_cjs.patchPgClient(pg);
2411
+ void chunkEXGEA4KE_cjs.checkAuditLogAccess(reader);
2251
2412
  runTriggerTrackedTablesDetection();
2252
2413
  }
2253
2414
  function applyDatabaseReaderDefaults() {
2254
- const config = chunkMMLQXSSD_cjs.configuration();
2415
+ const config = chunk2YCQFLXW_cjs.configuration();
2255
2416
  const reader = config.databaseReader;
2256
2417
  if (!reader) return;
2257
- chunkGMHOUAKD_cjs.auditLogInstalled(reader).then((installed) => {
2418
+ chunkEXGEA4KE_cjs.auditLogInstalled(reader).then((installed) => {
2258
2419
  if (installed === false && config.databaseReader === reader) {
2259
2420
  config.databaseReader = null;
2260
2421
  warnAuditLogMissing();
2261
2422
  return;
2262
2423
  }
2263
- if (installed === true) void chunkGMHOUAKD_cjs.checkAuditLogAccess(reader);
2424
+ if (installed === true) void chunkEXGEA4KE_cjs.checkAuditLogAccess(reader);
2264
2425
  runTriggerTrackedTablesDetection();
2265
2426
  }).catch(() => {
2266
2427
  });
@@ -2271,10 +2432,10 @@ function warnAuditLogMissing() {
2271
2432
  );
2272
2433
  }
2273
2434
  function runTriggerTrackedTablesDetection() {
2274
- const config = chunkMMLQXSSD_cjs.configuration();
2435
+ const config = chunk2YCQFLXW_cjs.configuration();
2275
2436
  if (!config.databaseReader) return;
2276
2437
  if (config.triggerTrackedTables !== null) return;
2277
- chunkGMHOUAKD_cjs.detectTriggerTrackedTables(config.databaseReader).then((tables) => {
2438
+ chunkEXGEA4KE_cjs.detectTriggerTrackedTables(config.databaseReader).then((tables) => {
2278
2439
  if (tables === null) {
2279
2440
  chunkTWTG5ILJ_cjs.logger.debug(
2280
2441
  "trigger-tracked-table detection failed; falling back to suppress-all on `databaseReader` paths. Untracked tables will not appear in the dashboard until detection succeeds or the table is added with `SELECT ezlogs_track('table_name')`."
@@ -2314,16 +2475,16 @@ function warnIfInsecureServerUrl(serverUrl, allowInsecure) {
2314
2475
  );
2315
2476
  }
2316
2477
  function _internalsForTests() {
2317
- return { buffer: chunkYXZZNZG6_cjs.buffer_exports, flushScheduler };
2478
+ return { buffer: chunkUC2KS5EG_cjs.buffer_exports, flushScheduler };
2318
2479
  }
2319
2480
 
2320
2481
  Object.defineProperty(exports, "ArgError", {
2321
2482
  enumerable: true,
2322
- get: function () { return chunkYXZZNZG6_cjs.ArgError; }
2483
+ get: function () { return chunkUC2KS5EG_cjs.ArgError; }
2323
2484
  });
2324
2485
  Object.defineProperty(exports, "buildEvent", {
2325
2486
  enumerable: true,
2326
- get: function () { return chunkYXZZNZG6_cjs.build; }
2487
+ get: function () { return chunkUC2KS5EG_cjs.build; }
2327
2488
  });
2328
2489
  exports.__ezlogs_run_inline_server_action = __ezlogs_run_inline_server_action;
2329
2490
  exports._detectDatabaseUrlFromEnvForTests = _detectDatabaseUrlFromEnvForTests;