ezlogs-nextjs 0.3.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -30
- package/bin/install-triggers.cjs +7 -2
- package/dist/actors/index.cjs +4 -4
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/actors/index.js +1 -1
- package/dist/{chunk-C5OSM557.js → chunk-FCFVIRQF.js} +7 -0
- package/dist/chunk-GI6BM4MR.js +443 -0
- package/dist/{chunk-YX2XPLOA.cjs → chunk-GMHOUAKD.cjs} +63 -34
- package/dist/{chunk-CU45I2WR.js → chunk-MHBS5FEP.js} +48 -20
- package/dist/chunk-MMLQXSSD.cjs +461 -0
- package/dist/{chunk-CE3R7DVB.js → chunk-NINIAL7M.js} +60 -384
- package/dist/{chunk-Y5NSHKWQ.cjs → chunk-NX4EL7BY.cjs} +57 -7
- package/dist/chunk-PS4U2GFJ.cjs +52 -0
- package/dist/chunk-R6IWVTX3.cjs +212 -0
- package/dist/{chunk-V5YNKKTG.cjs → chunk-TWTG5ILJ.cjs} +7 -0
- package/dist/chunk-U22T7QYY.js +200 -0
- package/dist/chunk-YMIGZYFH.js +48 -0
- package/dist/{chunk-WASXTDLW.cjs → chunk-YXZZNZG6.cjs} +71 -403
- package/dist/{chunk-DKRNNI4I.js → chunk-Z2TM3LGG.js} +53 -3
- package/dist/{configuration-OHLNivON.d.ts → configuration-CJ5yKVlP.d.cts} +14 -8
- package/dist/{configuration-OHLNivON.d.cts → configuration-CJ5yKVlP.d.ts} +14 -8
- package/dist/db/drizzle.cjs +5 -4
- package/dist/db/drizzle.js +3 -2
- package/dist/db/postgres-js.cjs +98 -0
- package/dist/db/postgres-js.d.cts +11 -0
- package/dist/db/postgres-js.d.ts +11 -0
- package/dist/db/postgres-js.js +95 -0
- package/dist/db/prisma.cjs +21 -20
- package/dist/db/prisma.d.cts +19 -2
- package/dist/db/prisma.d.ts +19 -2
- package/dist/db/prisma.js +6 -5
- package/dist/db/supabase.cjs +19 -12
- package/dist/db/supabase.d.cts +3 -2
- package/dist/db/supabase.d.ts +3 -2
- package/dist/db/supabase.js +11 -4
- package/dist/index.cjs +596 -165
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +492 -62
- package/dist/jobs/bullmq.cjs +63 -18
- package/dist/jobs/bullmq.d.cts +0 -4
- package/dist/jobs/bullmq.d.ts +0 -4
- package/dist/jobs/bullmq.js +59 -14
- package/dist/jobs/inngest.cjs +61 -24
- package/dist/jobs/inngest.d.cts +5 -1
- package/dist/jobs/inngest.d.ts +5 -1
- package/dist/jobs/inngest.js +55 -18
- package/dist/jobs/supabase-queues.cjs +17 -15
- package/dist/jobs/supabase-queues.d.cts +1 -1
- package/dist/jobs/supabase-queues.d.ts +1 -1
- package/dist/jobs/supabase-queues.js +15 -13
- package/dist/jobs/trigger.cjs +11 -12
- package/dist/jobs/trigger.d.cts +4 -3
- package/dist/jobs/trigger.d.ts +4 -3
- package/dist/jobs/trigger.js +7 -8
- package/dist/jobs/upstash-workflow.cjs +43 -35
- package/dist/jobs/upstash-workflow.d.cts +2 -8
- package/dist/jobs/upstash-workflow.d.ts +2 -8
- package/dist/jobs/upstash-workflow.js +38 -30
- package/dist/nextjs-plugin/index.cjs +39 -3
- package/dist/nextjs-plugin/index.d.cts +8 -1
- package/dist/nextjs-plugin/index.d.ts +8 -1
- package/dist/nextjs-plugin/index.js +39 -3
- package/dist/nextjs-plugin/loader.cjs +41 -3
- package/dist/nextjs-plugin/loader.d.cts +1 -0
- package/dist/nextjs-plugin/loader.d.ts +1 -0
- package/dist/nextjs-plugin/loader.js +42 -4
- package/dist/triggers/index.cjs +145 -92
- package/dist/triggers/index.d.cts +20 -5
- package/dist/triggers/index.d.ts +20 -5
- package/dist/triggers/index.js +125 -82
- package/package.json +11 -1
- package/sql/postgres/00_install.sql +1 -1
- package/dist/chunk-UQHEW6ER.js +0 -119
- package/dist/chunk-UWHYJH4M.cjs +0 -126
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { patchPgClient } from './chunk-
|
|
2
|
-
import { flushAuditLog, runWithEmittedAuditIdsScope, auditLogInstalled, checkAuditLogAccess, detectTriggerTrackedTables } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
export { ArgError, build as buildEvent } from './chunk-
|
|
5
|
-
import {
|
|
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, drainEvents, isSensitiveKey } 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';
|
|
6
|
+
import { logger, setLogLevel } from './chunk-FCFVIRQF.js';
|
|
6
7
|
import './chunk-SIAA4J6H.js';
|
|
7
8
|
|
|
8
9
|
// src/pipeline/transport.ts
|
|
@@ -160,8 +161,12 @@ async function tick() {
|
|
|
160
161
|
s.inFlight = true;
|
|
161
162
|
try {
|
|
162
163
|
const events = drainEvents();
|
|
163
|
-
if (events.length
|
|
164
|
-
|
|
164
|
+
if (events.length > 0) await retrySender.send(events);
|
|
165
|
+
const reader = configuration().databaseReader;
|
|
166
|
+
if (!reader) return;
|
|
167
|
+
await maintainAuditLogAfterRequests(reader);
|
|
168
|
+
const swept = drainEvents();
|
|
169
|
+
if (swept.length > 0) await retrySender.send(swept);
|
|
165
170
|
} catch (error) {
|
|
166
171
|
logger.error(`FlushScheduler tick failed: ${describeError3(error)}`);
|
|
167
172
|
} finally {
|
|
@@ -437,7 +442,7 @@ function parseServerActionName(name) {
|
|
|
437
442
|
function stripTrailingS(entity) {
|
|
438
443
|
if (entity.length <= 1) return entity;
|
|
439
444
|
if (entity.endsWith("ies")) return `${entity.slice(0, -3)}y`;
|
|
440
|
-
if (entity.endsWith("s") &&
|
|
445
|
+
if (entity.endsWith("s") && !/(ss|us|sis)$/i.test(entity)) return entity.slice(0, -1);
|
|
441
446
|
return entity;
|
|
442
447
|
}
|
|
443
448
|
function deriveFormat(contentType) {
|
|
@@ -459,9 +464,11 @@ function compact(obj) {
|
|
|
459
464
|
}
|
|
460
465
|
function determineOutcome(statusCode, exception, graphqlResponseErrors, responseError = null) {
|
|
461
466
|
if (exception) {
|
|
467
|
+
const issues = exception.issues;
|
|
468
|
+
const message = Array.isArray(issues) ? capErrorText(specificErrorMessage({ issues }) ?? "Validation failed") : exception.message;
|
|
462
469
|
return {
|
|
463
470
|
outcome: "failure",
|
|
464
|
-
error_message: `${exception.name}: ${
|
|
471
|
+
error_message: `${exception.name}: ${message}`
|
|
465
472
|
};
|
|
466
473
|
}
|
|
467
474
|
if (statusCode !== null && statusCode >= 400) {
|
|
@@ -470,8 +477,215 @@ function determineOutcome(statusCode, exception, graphqlResponseErrors, response
|
|
|
470
477
|
if (graphqlResponseErrors) {
|
|
471
478
|
return { outcome: "failure", error_message: graphqlResponseErrors };
|
|
472
479
|
}
|
|
480
|
+
if (responseError) {
|
|
481
|
+
return { outcome: "failure", error_message: responseError };
|
|
482
|
+
}
|
|
473
483
|
return { outcome: "success", error_message: null };
|
|
474
484
|
}
|
|
485
|
+
var MAX_SPECIFIC_ERROR_LENGTH = 200;
|
|
486
|
+
function capErrorText(text) {
|
|
487
|
+
const out = scrubSecretsInText(text, { emails: true });
|
|
488
|
+
return out.length <= MAX_SPECIFIC_ERROR_LENGTH ? out : `${out.slice(0, MAX_SPECIFIC_ERROR_LENGTH - 1)}\u2026`;
|
|
489
|
+
}
|
|
490
|
+
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;
|
|
491
|
+
function isGenericErrorText(text) {
|
|
492
|
+
return GENERIC_ERROR_TEXT.test(text.trim());
|
|
493
|
+
}
|
|
494
|
+
function specificErrorMessage(body, userPatterns = []) {
|
|
495
|
+
if (!isRecord(body)) return null;
|
|
496
|
+
const error = isRecord(body.error) ? body.error : {};
|
|
497
|
+
const details = isRecord(body.details) ? body.details : {};
|
|
498
|
+
for (const list of [body.details, body.issues, body.errors, error.issues, error.details]) {
|
|
499
|
+
if (!Array.isArray(list)) continue;
|
|
500
|
+
for (const issue of list) {
|
|
501
|
+
const found = issueMessage(issue, userPatterns);
|
|
502
|
+
if (found) return found;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
for (const flat of [body, details, error]) {
|
|
506
|
+
const fields = isRecord(flat.fieldErrors) ? flat.fieldErrors : null;
|
|
507
|
+
for (const [field, value] of Object.entries(fields ?? {})) {
|
|
508
|
+
const found = fieldMessage([field], firstString(value), userPatterns);
|
|
509
|
+
if (found) return found;
|
|
510
|
+
}
|
|
511
|
+
const form = fieldMessage([], firstString(flat.formErrors), userPatterns);
|
|
512
|
+
if (form) return form;
|
|
513
|
+
}
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
function issueMessage(issue, userPatterns = []) {
|
|
517
|
+
if (!isRecord(issue) || typeof issue.message !== "string") return null;
|
|
518
|
+
const path = Array.isArray(issue.path) ? issue.path.map(pathKey) : [];
|
|
519
|
+
return fieldMessage(path, issue.message, userPatterns);
|
|
520
|
+
}
|
|
521
|
+
function fieldMessage(path, message, userPatterns) {
|
|
522
|
+
const text = message?.replace(/\s+/g, " ").trim().replace(/received\s+("[^"]*"|'[^']*'|`[^`]*`)/gi, "received [FILTERED]");
|
|
523
|
+
if (!text) return null;
|
|
524
|
+
const keys = path.filter((k) => k !== null && k !== "");
|
|
525
|
+
if (keys.some((k) => isSensitiveKey(k, userPatterns))) return null;
|
|
526
|
+
if (keys.length > 0) return `${keys.join(".")}: ${text}`;
|
|
527
|
+
return text.split(/[^A-Za-z0-9_]+/).some((w) => w !== "" && isSensitiveKey(w, userPatterns)) ? null : text;
|
|
528
|
+
}
|
|
529
|
+
function pathKey(segment) {
|
|
530
|
+
if (typeof segment === "string") return segment;
|
|
531
|
+
if (isRecord(segment) && typeof segment.key === "string") return segment.key;
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
function firstString(value) {
|
|
535
|
+
if (typeof value === "string") return value;
|
|
536
|
+
if (Array.isArray(value) && typeof value[0] === "string") return value[0];
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
function isRecord(value) {
|
|
540
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/http/trpc.ts
|
|
544
|
+
function isRecord2(value) {
|
|
545
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
546
|
+
}
|
|
547
|
+
function isSuperjsonEnvelope(value) {
|
|
548
|
+
if (!isRecord2(value) || !("json" in value)) return false;
|
|
549
|
+
return Object.keys(value).every((k) => k === "json" || k === "meta");
|
|
550
|
+
}
|
|
551
|
+
function unwrap(value) {
|
|
552
|
+
return isSuperjsonEnvelope(value) ? value.json : value;
|
|
553
|
+
}
|
|
554
|
+
function isIndexed(value) {
|
|
555
|
+
const keys = Object.keys(value);
|
|
556
|
+
return keys.length > 0 && keys.every((k, i) => k === String(i));
|
|
557
|
+
}
|
|
558
|
+
function safeJsonParse(text) {
|
|
559
|
+
try {
|
|
560
|
+
return JSON.parse(text);
|
|
561
|
+
} catch {
|
|
562
|
+
return void 0;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function isTrpcRoute(raw, routeModulePath = null) {
|
|
566
|
+
return isRecord2(raw) && "trpc" in raw || routeModulePath?.includes("[trpc]") === true;
|
|
567
|
+
}
|
|
568
|
+
function unwrapTrpcParams(raw, url, routeModulePath = null) {
|
|
569
|
+
if (!isRecord2(raw) || !isTrpcRoute(raw, routeModulePath)) return raw;
|
|
570
|
+
const batch = url.searchParams.get("batch") === "1";
|
|
571
|
+
const rest = {};
|
|
572
|
+
let payload = void 0;
|
|
573
|
+
if (typeof raw.input === "string") {
|
|
574
|
+
const parsed = safeJsonParse(raw.input);
|
|
575
|
+
if (parsed !== void 0) {
|
|
576
|
+
for (const [k, v] of Object.entries(raw)) if (k !== "input" && k !== "batch") rest[k] = v;
|
|
577
|
+
if (isSuperjsonEnvelope(parsed) || batch && isRecord2(parsed) && isIndexed(parsed)) payload = parsed;
|
|
578
|
+
else return liftInput(parsed, rest);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (payload === void 0) {
|
|
582
|
+
const indexed = {};
|
|
583
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
584
|
+
if (/^\d+$/.test(k)) indexed[k] = v;
|
|
585
|
+
else rest[k] = v;
|
|
586
|
+
}
|
|
587
|
+
const envelopes = Object.values(indexed);
|
|
588
|
+
if (isIndexed(indexed) && (batch || envelopes.every(isSuperjsonEnvelope))) {
|
|
589
|
+
payload = indexed;
|
|
590
|
+
} else if (isSuperjsonEnvelope(raw)) {
|
|
591
|
+
return liftInput(raw.json, {});
|
|
592
|
+
} else {
|
|
593
|
+
return raw;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (isSuperjsonEnvelope(payload)) return liftInput(payload.json, rest);
|
|
597
|
+
const calls = Object.values(payload).map(unwrap);
|
|
598
|
+
if (calls.length === 1) return liftInput(calls[0], rest);
|
|
599
|
+
const out = {};
|
|
600
|
+
calls.forEach((input, i) => {
|
|
601
|
+
if (input !== null && input !== void 0) out[String(i)] = input;
|
|
602
|
+
});
|
|
603
|
+
return { ...out, ...rest };
|
|
604
|
+
}
|
|
605
|
+
function liftInput(input, rest) {
|
|
606
|
+
let out;
|
|
607
|
+
if (input === null || input === void 0) out = { ...rest };
|
|
608
|
+
else if (isRecord2(input)) out = { ...input, ...rest };
|
|
609
|
+
else out = { input, ...rest };
|
|
610
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
611
|
+
}
|
|
612
|
+
function trpcErrorMessage(body, userPatterns = []) {
|
|
613
|
+
const items = Array.isArray(body) ? body : [body];
|
|
614
|
+
for (const item of items) {
|
|
615
|
+
if (!isRecord2(item)) continue;
|
|
616
|
+
const error = unwrap(item.error);
|
|
617
|
+
if (!isRecord2(error) || typeof error.message !== "string") continue;
|
|
618
|
+
const data = error.data;
|
|
619
|
+
if (!isRecord2(data) || typeof data.code !== "string") continue;
|
|
620
|
+
const reason = callReason(error.message.trim(), data.zodError, userPatterns);
|
|
621
|
+
if (!reason) continue;
|
|
622
|
+
const path = typeof data.path === "string" && data.path.length > 0 ? `${data.path}: ` : "";
|
|
623
|
+
return capErrorText(`${path}${reason}`);
|
|
624
|
+
}
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
function callReason(message, zodError, userPatterns) {
|
|
628
|
+
const specific = isRecord2(zodError) ? specificErrorMessage(zodError, userPatterns) : null;
|
|
629
|
+
if (specific) return specific;
|
|
630
|
+
if (message.startsWith("[") || message.startsWith("{")) {
|
|
631
|
+
const parsed = safeJsonParse(message);
|
|
632
|
+
const issues = Array.isArray(parsed) ? parsed : isRecord2(parsed) ? parsed.issues : null;
|
|
633
|
+
const fromIssues = Array.isArray(issues) ? specificErrorMessage({ issues }, userPatterns) : null;
|
|
634
|
+
if (fromIssues) return fromIssues;
|
|
635
|
+
if (parsed !== void 0) return "Validation failed";
|
|
636
|
+
}
|
|
637
|
+
return message.length > 0 ? message : null;
|
|
638
|
+
}
|
|
639
|
+
var MAX_STREAM_LINE = 16384;
|
|
640
|
+
function trpcStreamErrorScanner(userPatterns = []) {
|
|
641
|
+
const decoder = new TextDecoder();
|
|
642
|
+
let line = "";
|
|
643
|
+
let skipping = false;
|
|
644
|
+
let error = null;
|
|
645
|
+
let callChunks = null;
|
|
646
|
+
return {
|
|
647
|
+
get error() {
|
|
648
|
+
return error;
|
|
649
|
+
},
|
|
650
|
+
push(chunk) {
|
|
651
|
+
if (error) return;
|
|
652
|
+
const parts = decoder.decode(chunk, { stream: true }).split("\n");
|
|
653
|
+
for (let i = 0; i < parts.length; i++) {
|
|
654
|
+
if (!skipping) line += parts[i];
|
|
655
|
+
if (line.length > MAX_STREAM_LINE) {
|
|
656
|
+
line = "";
|
|
657
|
+
skipping = true;
|
|
658
|
+
}
|
|
659
|
+
if (i === parts.length - 1) return;
|
|
660
|
+
if (!skipping) {
|
|
661
|
+
if (callChunks) error = streamLineError(line, callChunks, userPatterns);
|
|
662
|
+
else callChunks = headCallChunks(line);
|
|
663
|
+
}
|
|
664
|
+
if (error) return;
|
|
665
|
+
line = "";
|
|
666
|
+
skipping = false;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
function headCallChunks(text) {
|
|
672
|
+
const ids = /* @__PURE__ */ new Set();
|
|
673
|
+
const head = unwrap(safeJsonParse(text));
|
|
674
|
+
if (!isRecord2(head)) return ids;
|
|
675
|
+
for (const call of Object.values(head)) {
|
|
676
|
+
const ref = Array.isArray(call) ? call[1] : null;
|
|
677
|
+
if (Array.isArray(ref) && typeof ref[2] === "number") ids.add(ref[2]);
|
|
678
|
+
}
|
|
679
|
+
return ids;
|
|
680
|
+
}
|
|
681
|
+
function streamLineError(text, callChunks, userPatterns) {
|
|
682
|
+
const chunk = unwrap(safeJsonParse(text));
|
|
683
|
+
if (!Array.isArray(chunk) || chunk.length !== 3 || typeof chunk[0] !== "number") return null;
|
|
684
|
+
const value = chunk[2];
|
|
685
|
+
if (!Array.isArray(value)) return trpcErrorMessage({ error: value }, userPatterns);
|
|
686
|
+
if (!callChunks.has(chunk[0]) || !Array.isArray(value[0])) return null;
|
|
687
|
+
return trpcErrorMessage(value[0][0], userPatterns);
|
|
688
|
+
}
|
|
475
689
|
|
|
476
690
|
// src/http/graphql.ts
|
|
477
691
|
var QUERY_PREFIXES = ["Get", "Fetch", "List", "Find", "Load", "Search", "Query"];
|
|
@@ -570,13 +784,50 @@ function captureRoute(handler, context = {}) {
|
|
|
570
784
|
let exception = null;
|
|
571
785
|
let graphqlErrorMessage = null;
|
|
572
786
|
let responseErrorMessage = null;
|
|
787
|
+
let followed = false;
|
|
788
|
+
let handlerMs = null;
|
|
789
|
+
const finish = async () => {
|
|
790
|
+
await maybeExtractSupabaseActor();
|
|
791
|
+
await emitEvent({
|
|
792
|
+
snapshot,
|
|
793
|
+
context,
|
|
794
|
+
statusCode,
|
|
795
|
+
exception,
|
|
796
|
+
graphqlErrorMessage,
|
|
797
|
+
responseErrorMessage,
|
|
798
|
+
durationMs: handlerMs ?? Date.now() - startMs,
|
|
799
|
+
startedAt: new Date(startMs)
|
|
800
|
+
});
|
|
801
|
+
if (isServerless()) {
|
|
802
|
+
await flushScheduler.flushNow().catch(() => {
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
endCorrelationScope();
|
|
806
|
+
};
|
|
573
807
|
try {
|
|
574
808
|
response = await Promise.resolve(runHandler(...args));
|
|
809
|
+
handlerMs = Date.now() - startMs;
|
|
575
810
|
statusCode = response.status;
|
|
576
811
|
if (snapshot.graphqlBody !== null && response.status === 200) {
|
|
577
812
|
graphqlErrorMessage = await readGraphqlErrors(response);
|
|
578
813
|
}
|
|
579
|
-
|
|
814
|
+
const trpcRoute = isTrpcRoute(snapshot.rawParams, context.routeModulePath ?? null);
|
|
815
|
+
responseErrorMessage = await readResponseErrorMessage(response, trpcRoute);
|
|
816
|
+
const trpcStream = responseErrorMessage === null && trpcRoute ? trpcStreamErrorScanner(configuration().excludedGraphqlVariableKeys) : null;
|
|
817
|
+
const followedResponse = followBody(
|
|
818
|
+
response,
|
|
819
|
+
snapshot.method,
|
|
820
|
+
(streamError) => {
|
|
821
|
+
if (streamError) exception = streamError;
|
|
822
|
+
responseErrorMessage ??= trpcStream?.error ?? null;
|
|
823
|
+
return finish();
|
|
824
|
+
},
|
|
825
|
+
trpcStream ? (chunk) => trpcStream.push(chunk) : void 0
|
|
826
|
+
);
|
|
827
|
+
if (followedResponse) {
|
|
828
|
+
followed = true;
|
|
829
|
+
return followedResponse;
|
|
830
|
+
}
|
|
580
831
|
return response;
|
|
581
832
|
} catch (e) {
|
|
582
833
|
const controlStatus = nextControlFlowStatus(e);
|
|
@@ -588,21 +839,7 @@ function captureRoute(handler, context = {}) {
|
|
|
588
839
|
statusCode = 500;
|
|
589
840
|
throw e;
|
|
590
841
|
} finally {
|
|
591
|
-
await
|
|
592
|
-
await emitEvent({
|
|
593
|
-
snapshot,
|
|
594
|
-
context,
|
|
595
|
-
statusCode,
|
|
596
|
-
exception,
|
|
597
|
-
graphqlErrorMessage,
|
|
598
|
-
responseErrorMessage,
|
|
599
|
-
durationMs: Date.now() - startMs,
|
|
600
|
-
startedAt: new Date(startMs)
|
|
601
|
-
});
|
|
602
|
-
if (isServerless()) {
|
|
603
|
-
await flushScheduler.flushNow().catch(() => {
|
|
604
|
-
});
|
|
605
|
-
}
|
|
842
|
+
if (!followed) await finish();
|
|
606
843
|
}
|
|
607
844
|
})
|
|
608
845
|
);
|
|
@@ -656,7 +893,7 @@ function withMiddlewareCapture(middleware) {
|
|
|
656
893
|
logger.debug(`page navigation capture failed: ${describeError5(error)}`);
|
|
657
894
|
}
|
|
658
895
|
return response;
|
|
659
|
-
})
|
|
896
|
+
}).finally(endCorrelationScope)
|
|
660
897
|
);
|
|
661
898
|
} catch (preCaptureError) {
|
|
662
899
|
if (middlewareInvoked) throw preCaptureError;
|
|
@@ -669,9 +906,16 @@ function withMiddlewareCapture(middleware) {
|
|
|
669
906
|
}
|
|
670
907
|
function shouldEmitPageNavigation(request) {
|
|
671
908
|
if (request.method !== "GET") return false;
|
|
672
|
-
|
|
673
|
-
if (
|
|
674
|
-
|
|
909
|
+
const headers = request.headers;
|
|
910
|
+
if (headers.get("next-action")) return false;
|
|
911
|
+
for (const marker of ROUTER_FETCH_HEADERS) {
|
|
912
|
+
if (headers.get(marker) !== null) return false;
|
|
913
|
+
}
|
|
914
|
+
if (/prefetch|prerender/i.test(headers.get("sec-purpose") ?? headers.get("purpose") ?? "")) {
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
const fetchMode = headers.get("sec-fetch-mode");
|
|
918
|
+
if (fetchMode !== null && fetchMode !== "navigate") return false;
|
|
675
919
|
let url;
|
|
676
920
|
try {
|
|
677
921
|
url = new URL(request.url);
|
|
@@ -683,6 +927,15 @@ function shouldEmitPageNavigation(request) {
|
|
|
683
927
|
if (url.pathname.startsWith("/api/")) return false;
|
|
684
928
|
return true;
|
|
685
929
|
}
|
|
930
|
+
var ROUTER_FETCH_HEADERS = [
|
|
931
|
+
"rsc",
|
|
932
|
+
"next-router-prefetch",
|
|
933
|
+
"next-router-segment-prefetch",
|
|
934
|
+
"next-router-state-tree",
|
|
935
|
+
"next-url",
|
|
936
|
+
"x-middleware-prefetch",
|
|
937
|
+
"x-nextjs-data"
|
|
938
|
+
];
|
|
686
939
|
async function emitPageNavigationEvent(input) {
|
|
687
940
|
try {
|
|
688
941
|
await flushTriggerAuditLog();
|
|
@@ -781,6 +1034,7 @@ function capturePagesApi(handler, context = {}) {
|
|
|
781
1034
|
if (isServerless()) {
|
|
782
1035
|
await flushScheduler.flushNow().catch(() => void 0);
|
|
783
1036
|
}
|
|
1037
|
+
endCorrelationScope();
|
|
784
1038
|
}
|
|
785
1039
|
})
|
|
786
1040
|
);
|
|
@@ -841,7 +1095,8 @@ function captureServerAction(action, actionName) {
|
|
|
841
1095
|
exception: null,
|
|
842
1096
|
durationMs: Date.now() - startMs,
|
|
843
1097
|
startedAt,
|
|
844
|
-
args
|
|
1098
|
+
args,
|
|
1099
|
+
redirectTo: redirectTarget(e)
|
|
845
1100
|
});
|
|
846
1101
|
throw e;
|
|
847
1102
|
}
|
|
@@ -860,6 +1115,7 @@ function captureServerAction(action, actionName) {
|
|
|
860
1115
|
if (isServerless()) {
|
|
861
1116
|
await flushScheduler.flushNow().catch(() => void 0);
|
|
862
1117
|
}
|
|
1118
|
+
endCorrelationScope();
|
|
863
1119
|
}
|
|
864
1120
|
})
|
|
865
1121
|
);
|
|
@@ -932,11 +1188,45 @@ function classifyServerActionResult(result) {
|
|
|
932
1188
|
};
|
|
933
1189
|
}
|
|
934
1190
|
if (r.success === false && typeof r.error === "string" && r.error.length > 0) {
|
|
935
|
-
return { errorMessage:
|
|
1191
|
+
return { errorMessage: specificOrOwn(r, r.error) };
|
|
1192
|
+
}
|
|
1193
|
+
const rowShaped = isRowShaped(r);
|
|
1194
|
+
if (!rowShaped && typeof r.error === "string" && r.error.trim().length > 0 && !r.success && !r.ok && r.data == null) {
|
|
1195
|
+
return { errorMessage: specificOrOwn(r, r.error.trim()) };
|
|
1196
|
+
}
|
|
1197
|
+
if (!rowShaped && !r.success && !r.ok && Object.keys(r).every((k) => FORM_STATE_KEYS.has(k)) && hasErrorEntries(r.errors)) {
|
|
1198
|
+
return { errorMessage: formStateErrorMessage(r) };
|
|
936
1199
|
}
|
|
937
1200
|
}
|
|
938
1201
|
return null;
|
|
939
1202
|
}
|
|
1203
|
+
var FORM_STATE_KEYS = /* @__PURE__ */ new Set([
|
|
1204
|
+
"errors",
|
|
1205
|
+
"message",
|
|
1206
|
+
"success",
|
|
1207
|
+
"ok",
|
|
1208
|
+
"status",
|
|
1209
|
+
"fields",
|
|
1210
|
+
"fieldErrors",
|
|
1211
|
+
"formErrors"
|
|
1212
|
+
]);
|
|
1213
|
+
function isRowShaped(r) {
|
|
1214
|
+
return Object.keys(r).some((k) => k === "id" || /(^|_)(created|updated)_?at$/i.test(k));
|
|
1215
|
+
}
|
|
1216
|
+
function hasErrorEntries(errors, depth = 0) {
|
|
1217
|
+
if (typeof errors === "string") return errors.trim().length > 0;
|
|
1218
|
+
if (depth > 3 || errors === null || typeof errors !== "object") return false;
|
|
1219
|
+
return Object.values(errors).some((v) => hasErrorEntries(v, depth + 1));
|
|
1220
|
+
}
|
|
1221
|
+
function formStateErrorMessage(r) {
|
|
1222
|
+
const patterns = configuration().excludedGraphqlVariableKeys;
|
|
1223
|
+
const specific = Array.isArray(r.errors) ? specificErrorMessage({ errors: r.errors }, patterns) ?? specificErrorMessage({ formErrors: r.errors }, patterns) : specificErrorMessage({ fieldErrors: r.errors }, patterns);
|
|
1224
|
+
if (specific) return capErrorText(specific);
|
|
1225
|
+
if (typeof r.message === "string" && r.message.trim().length > 0) {
|
|
1226
|
+
return capErrorText(r.message.trim());
|
|
1227
|
+
}
|
|
1228
|
+
return "Validation failed";
|
|
1229
|
+
}
|
|
940
1230
|
function defaultErrorMessage(result) {
|
|
941
1231
|
if (result && typeof result === "object" && !Array.isArray(result)) {
|
|
942
1232
|
const r = result;
|
|
@@ -944,7 +1234,7 @@ function defaultErrorMessage(result) {
|
|
|
944
1234
|
return truncate(r.serverError);
|
|
945
1235
|
}
|
|
946
1236
|
const err = r.error;
|
|
947
|
-
if (typeof err === "string" && err.length > 0) return
|
|
1237
|
+
if (typeof err === "string" && err.length > 0) return specificOrOwn(r, err);
|
|
948
1238
|
if (isZsaError(err)) return truncate(err.message);
|
|
949
1239
|
if (isZodErrorLike(err)) {
|
|
950
1240
|
return formatZodIssues(err.issues);
|
|
@@ -956,6 +1246,10 @@ function defaultErrorMessage(result) {
|
|
|
956
1246
|
return "Server Action returned a failure result";
|
|
957
1247
|
}
|
|
958
1248
|
var MAX_ERROR_MESSAGE_LENGTH = 200;
|
|
1249
|
+
function specificOrOwn(result, error) {
|
|
1250
|
+
const specific = isGenericErrorText(error) ? specificErrorMessage(result, configuration().excludedGraphqlVariableKeys) : null;
|
|
1251
|
+
return capErrorText(specific ?? error);
|
|
1252
|
+
}
|
|
959
1253
|
function truncate(value) {
|
|
960
1254
|
if (value.length <= MAX_ERROR_MESSAGE_LENGTH) return value;
|
|
961
1255
|
return value.slice(0, MAX_ERROR_MESSAGE_LENGTH - 1) + "\u2026";
|
|
@@ -971,16 +1265,15 @@ function isZodErrorLike(value) {
|
|
|
971
1265
|
return Array.isArray(issues) && issues.length > 0;
|
|
972
1266
|
}
|
|
973
1267
|
function formatZodIssues(issues) {
|
|
1268
|
+
const patterns = configuration().excludedGraphqlVariableKeys;
|
|
974
1269
|
const messages = [];
|
|
975
1270
|
for (const issue of issues) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
if (typeof m === "string" && m.length > 0) messages.push(m);
|
|
979
|
-
}
|
|
1271
|
+
const m = issueMessage(issue, patterns);
|
|
1272
|
+
if (m) messages.push(m);
|
|
980
1273
|
if (messages.length >= 3) break;
|
|
981
1274
|
}
|
|
982
1275
|
if (messages.length === 0) return "Validation failed";
|
|
983
|
-
return
|
|
1276
|
+
return capErrorText(messages.join("; "));
|
|
984
1277
|
}
|
|
985
1278
|
function hasNonEmptyValidationError(errors) {
|
|
986
1279
|
for (const value of Object.values(errors)) {
|
|
@@ -1037,6 +1330,35 @@ function nextControlFlowStatus(error) {
|
|
|
1037
1330
|
}
|
|
1038
1331
|
return null;
|
|
1039
1332
|
}
|
|
1333
|
+
function pathOf(url) {
|
|
1334
|
+
if (!url) return "";
|
|
1335
|
+
try {
|
|
1336
|
+
return new URL(url, "http://localhost").pathname;
|
|
1337
|
+
} catch {
|
|
1338
|
+
return "";
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function redirectTarget(error) {
|
|
1342
|
+
const digest = error?.digest;
|
|
1343
|
+
if (typeof digest !== "string" || !digest.startsWith("NEXT_REDIRECT;")) return null;
|
|
1344
|
+
const parts = digest.split(";").slice(2);
|
|
1345
|
+
while (parts.length > 0 && (parts[parts.length - 1] === "" || /^\d{3}$/.test(parts[parts.length - 1]))) {
|
|
1346
|
+
parts.pop();
|
|
1347
|
+
}
|
|
1348
|
+
return parts.length > 0 ? parts.join(";") : null;
|
|
1349
|
+
}
|
|
1350
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1351
|
+
function redirectPath(target, requestHost) {
|
|
1352
|
+
try {
|
|
1353
|
+
const absolute = /^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith("//");
|
|
1354
|
+
const url = new URL(target, "http://ezlogs.internal");
|
|
1355
|
+
if (absolute && (!requestHost || url.host.toLowerCase() !== requestHost.toLowerCase())) return null;
|
|
1356
|
+
const path = url.pathname.split("/").map((seg) => /^[A-Za-z0-9_-]{20,}$/.test(seg) && !UUID.test(seg) ? "[FILTERED]" : seg).join("/");
|
|
1357
|
+
return path ? scrubSecretsInText(path, { emails: true }) : null;
|
|
1358
|
+
} catch {
|
|
1359
|
+
return null;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1040
1362
|
async function emitServerActionEvent(input) {
|
|
1041
1363
|
try {
|
|
1042
1364
|
await flushTriggerAuditLog();
|
|
@@ -1045,7 +1367,11 @@ async function emitServerActionEvent(input) {
|
|
|
1045
1367
|
const userAgent = await readNextHeader("user-agent");
|
|
1046
1368
|
const fromPage = referer ?? nextUrl ?? null;
|
|
1047
1369
|
const argParams = extractServerActionArgs(input.args, input.actionName);
|
|
1048
|
-
const
|
|
1370
|
+
const combined = argParams !== null || fromPage !== null ? { ...argParams ?? {}, ...fromPage !== null ? { from_page: fromPage } : {} } : null;
|
|
1371
|
+
const requestParams = maskAuthParams(
|
|
1372
|
+
combined,
|
|
1373
|
+
isAuthActionName(input.actionName) || isAuthPath(pathOf(fromPage))
|
|
1374
|
+
);
|
|
1049
1375
|
const syntheticUrl = new URL(
|
|
1050
1376
|
`http://localhost/__server-action/${encodeURIComponent(input.actionName)}`
|
|
1051
1377
|
);
|
|
@@ -1061,6 +1387,11 @@ async function emitServerActionEvent(input) {
|
|
|
1061
1387
|
contentType: null,
|
|
1062
1388
|
excludedVariableKeys: configuration().excludedGraphqlVariableKeys
|
|
1063
1389
|
});
|
|
1390
|
+
if (input.redirectTo) {
|
|
1391
|
+
const host = await readNextHeader("x-forwarded-host") ?? await readNextHeader("host");
|
|
1392
|
+
const redirectTo = redirectPath(input.redirectTo, host?.split(",")[0]?.trim() ?? null);
|
|
1393
|
+
if (redirectTo) sourceData.redirect_to = redirectTo;
|
|
1394
|
+
}
|
|
1064
1395
|
const { outcome, error_message } = determineOutcome(
|
|
1065
1396
|
input.statusCode,
|
|
1066
1397
|
input.exception,
|
|
@@ -1294,7 +1625,7 @@ async function snapshotRequest(request) {
|
|
|
1294
1625
|
try {
|
|
1295
1626
|
if (contentType?.includes("application/json")) {
|
|
1296
1627
|
const text = await cloned.text();
|
|
1297
|
-
const parsed = text ?
|
|
1628
|
+
const parsed = text ? safeJsonParse2(text) : null;
|
|
1298
1629
|
if (isGraphql) graphqlBody = parsed;
|
|
1299
1630
|
else rawParams = parsed;
|
|
1300
1631
|
} else if (contentType?.includes("application/x-www-form-urlencoded")) {
|
|
@@ -1331,7 +1662,8 @@ async function maybeRunActorHookFromPages(req) {
|
|
|
1331
1662
|
let hookResult = null;
|
|
1332
1663
|
if (hook) {
|
|
1333
1664
|
try {
|
|
1334
|
-
|
|
1665
|
+
const headers = req.headers instanceof Headers ? req.headers : toWebHeaders(req.headers);
|
|
1666
|
+
hookResult = await Promise.resolve(hook({ headers }));
|
|
1335
1667
|
} catch (error) {
|
|
1336
1668
|
logger.debug(`actorFromRequest hook (pages) failed: ${describeError5(error)}`);
|
|
1337
1669
|
}
|
|
@@ -1369,18 +1701,6 @@ async function maybeRunActorHookFromServerAction() {
|
|
|
1369
1701
|
const userAgent = headers ? safeGetHeader(headers, "user-agent") : null;
|
|
1370
1702
|
applyActorFromHookAndUa(hookResult, userAgent);
|
|
1371
1703
|
}
|
|
1372
|
-
async function maybeExtractSupabaseActor() {
|
|
1373
|
-
const config = configuration();
|
|
1374
|
-
if (!config.actorFromSupabase) return;
|
|
1375
|
-
if (getCurrentActor()) return;
|
|
1376
|
-
try {
|
|
1377
|
-
const mod = await import('./db/supabase.js');
|
|
1378
|
-
const actor = await mod.tryExtractSupabaseActor();
|
|
1379
|
-
if (actor) setActor(actor);
|
|
1380
|
-
} catch (error) {
|
|
1381
|
-
logger.debug(`actorFromSupabase failed: ${describeError5(error)}`);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
1704
|
function snapshotPagesRequest(req) {
|
|
1385
1705
|
let url;
|
|
1386
1706
|
try {
|
|
@@ -1473,6 +1793,18 @@ async function tryLoadNextHeadersModule() {
|
|
|
1473
1793
|
}
|
|
1474
1794
|
}
|
|
1475
1795
|
}
|
|
1796
|
+
function toWebHeaders(raw) {
|
|
1797
|
+
const headers = new Headers();
|
|
1798
|
+
for (const [name, value] of Object.entries(raw ?? {})) {
|
|
1799
|
+
for (const v of Array.isArray(value) ? value : value === void 0 ? [] : [value]) {
|
|
1800
|
+
try {
|
|
1801
|
+
headers.append(name, v);
|
|
1802
|
+
} catch {
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
return headers;
|
|
1807
|
+
}
|
|
1476
1808
|
function readPagesHeader(req, name) {
|
|
1477
1809
|
const raw = req.headers;
|
|
1478
1810
|
if (raw instanceof Headers) return raw.get(name);
|
|
@@ -1501,7 +1833,10 @@ async function emitEvent(input) {
|
|
|
1501
1833
|
method: input.snapshot.method,
|
|
1502
1834
|
url: input.snapshot.url,
|
|
1503
1835
|
statusCode: input.statusCode,
|
|
1504
|
-
rawParams:
|
|
1836
|
+
rawParams: maskAuthParams(
|
|
1837
|
+
unwrapTrpcParams(input.snapshot.rawParams, input.snapshot.url, input.context.routeModulePath ?? null),
|
|
1838
|
+
isAuthPath(input.snapshot.url.pathname)
|
|
1839
|
+
),
|
|
1505
1840
|
routeModulePath: input.context.routeModulePath ?? null,
|
|
1506
1841
|
serverActionName,
|
|
1507
1842
|
userAgent: input.snapshot.userAgent,
|
|
@@ -1536,6 +1871,74 @@ async function emitEvent(input) {
|
|
|
1536
1871
|
logger.error(`http capture emit failed${cidLabel}: ${describeError5(error)}`);
|
|
1537
1872
|
}
|
|
1538
1873
|
}
|
|
1874
|
+
function followBody(response, method, onDone, onChunk) {
|
|
1875
|
+
try {
|
|
1876
|
+
if (!response.body || method === "HEAD" || response.bodyUsed) return null;
|
|
1877
|
+
const capture = makeAsyncContextCapture();
|
|
1878
|
+
if (!capture) return null;
|
|
1879
|
+
const keepAlive = isServerless() ? platformWaitUntil() : null;
|
|
1880
|
+
if (isServerless() && !keepAlive) return null;
|
|
1881
|
+
const run = capture();
|
|
1882
|
+
let settled;
|
|
1883
|
+
keepAlive?.(new Promise((resolve) => settled = resolve));
|
|
1884
|
+
const source = response.body;
|
|
1885
|
+
let reader = null;
|
|
1886
|
+
let finished = false;
|
|
1887
|
+
const finish = (error) => {
|
|
1888
|
+
if (finished) return;
|
|
1889
|
+
finished = true;
|
|
1890
|
+
run(() => onDone(error)).catch((e) => logger.debug(`streamed response capture failed: ${describeError5(e)}`)).finally(() => settled?.());
|
|
1891
|
+
};
|
|
1892
|
+
const body = new ReadableStream(
|
|
1893
|
+
{
|
|
1894
|
+
async pull(controller) {
|
|
1895
|
+
try {
|
|
1896
|
+
const chunk = await run(() => (reader ??= source.getReader()).read());
|
|
1897
|
+
if (chunk.done) {
|
|
1898
|
+
controller.close();
|
|
1899
|
+
finish(null);
|
|
1900
|
+
} else {
|
|
1901
|
+
try {
|
|
1902
|
+
onChunk?.(chunk.value);
|
|
1903
|
+
} catch (e) {
|
|
1904
|
+
logger.debug(`streamed chunk scan failed: ${describeError5(e)}`);
|
|
1905
|
+
}
|
|
1906
|
+
controller.enqueue(chunk.value);
|
|
1907
|
+
}
|
|
1908
|
+
} catch (e) {
|
|
1909
|
+
controller.error(e);
|
|
1910
|
+
finish(e instanceof Error ? e : new Error(String(e)));
|
|
1911
|
+
}
|
|
1912
|
+
},
|
|
1913
|
+
cancel(reason) {
|
|
1914
|
+
finish(null);
|
|
1915
|
+
return reader ? reader.cancel(reason) : source.cancel(reason);
|
|
1916
|
+
}
|
|
1917
|
+
},
|
|
1918
|
+
// Read the source only when the consumer asks: nothing is buffered.
|
|
1919
|
+
{ highWaterMark: 0 }
|
|
1920
|
+
);
|
|
1921
|
+
return new Response(body, {
|
|
1922
|
+
status: response.status,
|
|
1923
|
+
statusText: response.statusText,
|
|
1924
|
+
headers: response.headers
|
|
1925
|
+
});
|
|
1926
|
+
} catch (e) {
|
|
1927
|
+
logger.debug(`could not follow the response body: ${describeError5(e)}`);
|
|
1928
|
+
return null;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
function platformWaitUntil() {
|
|
1932
|
+
for (const key of ["@next/request-context", "@vercel/request-context"]) {
|
|
1933
|
+
try {
|
|
1934
|
+
const holder = globalThis[Symbol.for(key)];
|
|
1935
|
+
const ctx = holder?.get?.();
|
|
1936
|
+
if (typeof ctx?.waitUntil === "function") return ctx.waitUntil.bind(ctx);
|
|
1937
|
+
} catch {
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
return null;
|
|
1941
|
+
}
|
|
1539
1942
|
function buildContext() {
|
|
1540
1943
|
const currentActor = getCurrentActor();
|
|
1541
1944
|
if (!currentActor) return null;
|
|
@@ -1580,7 +1983,7 @@ function safeClone(request) {
|
|
|
1580
1983
|
return null;
|
|
1581
1984
|
}
|
|
1582
1985
|
}
|
|
1583
|
-
function
|
|
1986
|
+
function safeJsonParse2(text) {
|
|
1584
1987
|
try {
|
|
1585
1988
|
return JSON.parse(text);
|
|
1586
1989
|
} catch {
|
|
@@ -1603,19 +2006,25 @@ function mergeRouteParams(rawParams, routeParams) {
|
|
|
1603
2006
|
return { ...routeParams, ...rawParams };
|
|
1604
2007
|
}
|
|
1605
2008
|
var MAX_ERROR_BODY_LENGTH = 16384;
|
|
1606
|
-
async function readResponseErrorMessage(response) {
|
|
2009
|
+
async function readResponseErrorMessage(response, trpcRoute = false) {
|
|
1607
2010
|
try {
|
|
1608
|
-
if (response.status < 400) return null;
|
|
1609
|
-
if (!(response.headers.get("content-type") ?? "").includes("json")) return null;
|
|
2011
|
+
if (response.status < 400 && response.status !== 207) return null;
|
|
2012
|
+
if (!trpcRoute && !(response.headers.get("content-type") ?? "").includes("json")) return null;
|
|
1610
2013
|
if (Number(response.headers.get("content-length") ?? 0) > MAX_ERROR_BODY_LENGTH) return null;
|
|
1611
2014
|
const text = await response.clone().text();
|
|
1612
2015
|
if (!text || text.length > MAX_ERROR_BODY_LENGTH) return null;
|
|
1613
|
-
const
|
|
2016
|
+
const parsed = safeJsonParse2(text);
|
|
2017
|
+
const trpc = trpcErrorMessage(parsed, configuration().excludedGraphqlVariableKeys);
|
|
2018
|
+
if (trpc) return trpc;
|
|
2019
|
+
if (response.status === 207) return null;
|
|
2020
|
+
const body = parsed;
|
|
1614
2021
|
if (!body || typeof body !== "object") return null;
|
|
1615
2022
|
const nested = body.error;
|
|
1616
2023
|
const raw = [body.error, body.message, nested?.message].find(
|
|
1617
2024
|
(v) => typeof v === "string" && v.trim().length > 0
|
|
1618
2025
|
);
|
|
2026
|
+
const specific = !raw || isGenericErrorText(raw) ? specificErrorMessage(body, configuration().excludedGraphqlVariableKeys) : null;
|
|
2027
|
+
if (specific) return capErrorText(specific);
|
|
1619
2028
|
return raw ? truncate(scrubSecretsInText(raw.trim(), { emails: true })) : null;
|
|
1620
2029
|
} catch {
|
|
1621
2030
|
return null;
|
|
@@ -1626,7 +2035,7 @@ async function readGraphqlErrors(response) {
|
|
|
1626
2035
|
const cloned = response.clone();
|
|
1627
2036
|
const text = await cloned.text();
|
|
1628
2037
|
if (!text) return null;
|
|
1629
|
-
const parsed =
|
|
2038
|
+
const parsed = safeJsonParse2(text);
|
|
1630
2039
|
return extractGraphqlErrorsFromBody(parsed);
|
|
1631
2040
|
} catch {
|
|
1632
2041
|
return null;
|
|
@@ -1682,12 +2091,33 @@ function isBeforeExitInstalled() {
|
|
|
1682
2091
|
function markBeforeExitInstalled() {
|
|
1683
2092
|
globalThis[BEFORE_EXIT_INSTALLED_KEY] = true;
|
|
1684
2093
|
}
|
|
2094
|
+
var STARTUP_ANNOUNCED_KEY = /* @__PURE__ */ Symbol.for("ezlogs-nextjs:startupAnnounced");
|
|
2095
|
+
function announceStartup(serverUrl, projectToken) {
|
|
2096
|
+
const g = globalThis;
|
|
2097
|
+
if (g[STARTUP_ANNOUNCED_KEY]) return;
|
|
2098
|
+
g[STARTUP_ANNOUNCED_KEY] = true;
|
|
2099
|
+
if (!serverUrl || !projectToken) {
|
|
2100
|
+
logger.warn("not capturing: projectToken missing in ezlogs.init() (check EZLOGS_PROJECT_TOKEN)");
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
let host = serverUrl;
|
|
2104
|
+
try {
|
|
2105
|
+
host = new URL(serverUrl).host;
|
|
2106
|
+
} catch {
|
|
2107
|
+
}
|
|
2108
|
+
const project = projectToken.startsWith("ezl_") && projectToken.length >= 24 ? ` (key ${projectToken.slice(0, 12)}\u2026)` : "";
|
|
2109
|
+
logger.notice(`capturing \u2192 ${host}${project}`);
|
|
2110
|
+
}
|
|
2111
|
+
function _resetStartupAnnouncementForTests() {
|
|
2112
|
+
delete globalThis[STARTUP_ANNOUNCED_KEY];
|
|
2113
|
+
}
|
|
1685
2114
|
var ezlogs = {
|
|
1686
2115
|
init(options) {
|
|
1687
2116
|
const config = configuration();
|
|
1688
2117
|
config.apply(options);
|
|
1689
2118
|
if (options.logLevel) setLogLevel(options.logLevel);
|
|
1690
2119
|
warnIfInsecureServerUrl(config.serverUrl, config.allowInsecureTransport);
|
|
2120
|
+
announceStartup(config.serverUrl, config.projectToken);
|
|
1691
2121
|
flushScheduler.start();
|
|
1692
2122
|
if (config.patchGlobalFetch) patchGlobalFetch();
|
|
1693
2123
|
const resolvedDbUrl = options.databaseUrl ?? detectDatabaseUrlFromEnv();
|
|
@@ -1808,13 +2238,13 @@ function runTriggerTrackedTablesDetection() {
|
|
|
1808
2238
|
detectTriggerTrackedTables(config.databaseReader).then((tables) => {
|
|
1809
2239
|
if (tables === null) {
|
|
1810
2240
|
logger.debug(
|
|
1811
|
-
"
|
|
2241
|
+
"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')`."
|
|
1812
2242
|
);
|
|
1813
2243
|
return;
|
|
1814
2244
|
}
|
|
1815
2245
|
config.triggerTrackedTables = tables;
|
|
1816
2246
|
logger.debug(
|
|
1817
|
-
`
|
|
2247
|
+
`trigger-tracked tables: ${tables.size === 0 ? "(none)" : Array.from(tables).sort().join(", ")}`
|
|
1818
2248
|
);
|
|
1819
2249
|
}).catch(() => {
|
|
1820
2250
|
});
|
|
@@ -1848,4 +2278,4 @@ function _internalsForTests() {
|
|
|
1848
2278
|
return { buffer: buffer_exports, flushScheduler };
|
|
1849
2279
|
}
|
|
1850
2280
|
|
|
1851
|
-
export { __ezlogs_run_inline_server_action, _detectDatabaseUrlFromEnvForTests, _internalsForTests, captureHttpEvent, capturePagesApi, captureRoute, captureServerAction, captureServerActionExport, ezlogs, withMiddlewareCapture };
|
|
2281
|
+
export { __ezlogs_run_inline_server_action, _detectDatabaseUrlFromEnvForTests, _internalsForTests, _resetStartupAnnouncementForTests, captureHttpEvent, capturePagesApi, captureRoute, captureServerAction, captureServerActionExport, ezlogs, withMiddlewareCapture };
|