ezlogs-nextjs 0.1.4 → 0.3.0
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 +106 -11
- package/bin/install-triggers.cjs +49 -11
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/{configuration-3Pei_XZ_.d.cts → configuration-OHLNivON.d.cts} +11 -20
- package/dist/{configuration-3Pei_XZ_.d.ts → configuration-OHLNivON.d.ts} +11 -20
- package/dist/db/drizzle.cjs +154 -18
- package/dist/db/drizzle.js +154 -18
- package/dist/db/prisma.cjs +242 -45
- package/dist/db/prisma.d.cts +39 -1
- package/dist/db/prisma.d.ts +39 -1
- package/dist/db/prisma.js +241 -46
- package/dist/db/supabase.cjs +154 -18
- package/dist/db/supabase.js +154 -18
- package/dist/index.cjs +761 -245
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +761 -245
- package/dist/jobs/bullmq.cjs +973 -16
- package/dist/jobs/bullmq.d.cts +8 -3
- package/dist/jobs/bullmq.d.ts +8 -3
- package/dist/jobs/bullmq.js +973 -16
- package/dist/jobs/inngest.cjs +880 -14
- package/dist/jobs/inngest.d.cts +7 -5
- package/dist/jobs/inngest.d.ts +7 -5
- package/dist/jobs/inngest.js +880 -14
- package/dist/jobs/supabase-queues.cjs +878 -16
- package/dist/jobs/supabase-queues.js +878 -16
- package/dist/jobs/trigger.cjs +914 -42
- package/dist/jobs/trigger.js +914 -42
- package/dist/jobs/upstash-workflow.cjs +914 -14
- package/dist/jobs/upstash-workflow.d.cts +16 -2
- package/dist/jobs/upstash-workflow.d.ts +16 -2
- package/dist/jobs/upstash-workflow.js +914 -15
- package/dist/triggers/index.cjs +405 -76
- package/dist/triggers/index.d.cts +36 -41
- package/dist/triggers/index.d.ts +36 -41
- package/dist/triggers/index.js +404 -74
- package/package.json +5 -1
- package/sql/postgres/00_install.sql +244 -21
package/dist/db/supabase.cjs
CHANGED
|
@@ -111,7 +111,6 @@ var Configuration = class {
|
|
|
111
111
|
displayNameFor = {};
|
|
112
112
|
isServerActionError = null;
|
|
113
113
|
databaseReader = null;
|
|
114
|
-
databaseSnapshotMode = false;
|
|
115
114
|
databaseUrl = null;
|
|
116
115
|
/**
|
|
117
116
|
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
@@ -163,9 +162,6 @@ var Configuration = class {
|
|
|
163
162
|
if (options.databaseReader !== void 0) {
|
|
164
163
|
this.databaseReader = options.databaseReader;
|
|
165
164
|
}
|
|
166
|
-
if (options.databaseSnapshotMode !== void 0) {
|
|
167
|
-
this.databaseSnapshotMode = options.databaseSnapshotMode;
|
|
168
|
-
}
|
|
169
165
|
if (options.databaseUrl !== void 0) {
|
|
170
166
|
this.databaseUrl = options.databaseUrl;
|
|
171
167
|
}
|
|
@@ -493,6 +489,57 @@ var storage2 = createScopedStorage(
|
|
|
493
489
|
function getCurrentActor() {
|
|
494
490
|
return storage2.read();
|
|
495
491
|
}
|
|
492
|
+
var SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
493
|
+
"pin",
|
|
494
|
+
"otp",
|
|
495
|
+
"totp",
|
|
496
|
+
"iban",
|
|
497
|
+
"mfa",
|
|
498
|
+
"passphrase"
|
|
499
|
+
]);
|
|
500
|
+
function snakeLower(key) {
|
|
501
|
+
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
502
|
+
}
|
|
503
|
+
function matchesSensitiveKey(key, substringPatterns) {
|
|
504
|
+
const lower = key.toLowerCase();
|
|
505
|
+
const snake = snakeLower(key);
|
|
506
|
+
if (substringPatterns.some((p) => lower.includes(p) || snake.includes(p))) {
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
const words = snake.split(/[^a-z0-9]+/);
|
|
510
|
+
return SENSITIVE_WORD_PATTERNS.some((w) => words.includes(w));
|
|
511
|
+
}
|
|
512
|
+
function passesLuhn(digits) {
|
|
513
|
+
let sum = 0;
|
|
514
|
+
for (let i = 0; i < digits.length; i += 1) {
|
|
515
|
+
let d = Number(digits[digits.length - 1 - i]);
|
|
516
|
+
if (i % 2 === 1) {
|
|
517
|
+
d *= 2;
|
|
518
|
+
if (d > 9) d -= 9;
|
|
519
|
+
}
|
|
520
|
+
sum += d;
|
|
521
|
+
}
|
|
522
|
+
return sum % 10 === 0;
|
|
523
|
+
}
|
|
524
|
+
var SECRET_TEXT_PATTERNS = [
|
|
525
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
|
|
526
|
+
/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g,
|
|
527
|
+
/\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]+/g,
|
|
528
|
+
/\bsk-[A-Za-z0-9_-]{16,}/g,
|
|
529
|
+
/\bgh[pousr]_[A-Za-z0-9]{20,}/g,
|
|
530
|
+
/\bxox[abposr]-[A-Za-z0-9-]+/g,
|
|
531
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g
|
|
532
|
+
];
|
|
533
|
+
var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
534
|
+
function scrubSecretsInText(text, options = {}) {
|
|
535
|
+
let out = text;
|
|
536
|
+
for (const pattern of SECRET_TEXT_PATTERNS) out = out.replace(pattern, "[FILTERED]");
|
|
537
|
+
out = out.replace(/\b(Bearer|Basic)\s+[\w.~+/=-]+/gi, "$1 [FILTERED]").replace(/\b\d(?:[ -]?\d){12,18}\b/g, (match) => {
|
|
538
|
+
const digits = match.replace(/[ -]/g, "");
|
|
539
|
+
return (digits.length === 15 || digits.length === 16) && passesLuhn(digits) ? "[FILTERED]" : match;
|
|
540
|
+
});
|
|
541
|
+
return options.emails ? out.replace(EMAIL, "[FILTERED]") : out;
|
|
542
|
+
}
|
|
496
543
|
|
|
497
544
|
// src/db/shared.ts
|
|
498
545
|
var IGNORED_ATTRIBUTES = Object.freeze([
|
|
@@ -501,8 +548,6 @@ var IGNORED_ATTRIBUTES = Object.freeze([
|
|
|
501
548
|
"created_at",
|
|
502
549
|
"updatedAt",
|
|
503
550
|
"updated_at",
|
|
504
|
-
"deletedAt",
|
|
505
|
-
"deleted_at",
|
|
506
551
|
// Auth.js / NextAuth standard columns
|
|
507
552
|
"emailVerified",
|
|
508
553
|
"expires"
|
|
@@ -525,7 +570,19 @@ var DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
|
525
570
|
"salt",
|
|
526
571
|
"digest",
|
|
527
572
|
"signature",
|
|
528
|
-
"hmac"
|
|
573
|
+
"hmac",
|
|
574
|
+
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
575
|
+
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
576
|
+
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
577
|
+
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
578
|
+
"credential",
|
|
579
|
+
"passwd",
|
|
580
|
+
"passcode",
|
|
581
|
+
"apikey",
|
|
582
|
+
"card_number",
|
|
583
|
+
"cardnumber",
|
|
584
|
+
"cvv",
|
|
585
|
+
"cvc"
|
|
529
586
|
]);
|
|
530
587
|
function emitDbEvent(input) {
|
|
531
588
|
try {
|
|
@@ -534,14 +591,17 @@ function emitDbEvent(input) {
|
|
|
534
591
|
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
535
592
|
if (config.databaseReader && !input._fromTrigger) {
|
|
536
593
|
const tracked = config.triggerTrackedTables;
|
|
537
|
-
if (tracked === null || tracked.has(input.modelClass)) return;
|
|
594
|
+
if (tracked === null || tracked.has(input.table ?? input.modelClass)) return;
|
|
538
595
|
}
|
|
539
596
|
if (input.operation === "update") {
|
|
540
597
|
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
541
598
|
if (meaningful.length === 0) return;
|
|
542
599
|
}
|
|
543
600
|
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
544
|
-
const
|
|
601
|
+
const related = resourceIdStr === null ? input.relatedResourceIds ?? [] : [];
|
|
602
|
+
const context = buildContext(
|
|
603
|
+
related.length > 0 ? { ...input, displayName: null, modelInstance: null } : input
|
|
604
|
+
);
|
|
545
605
|
const event = build({
|
|
546
606
|
source_type: "database_callback",
|
|
547
607
|
source_data: {
|
|
@@ -550,9 +610,10 @@ function emitDbEvent(input) {
|
|
|
550
610
|
},
|
|
551
611
|
outcome: "success",
|
|
552
612
|
correlation_id: current(),
|
|
553
|
-
resource_ids: resourceIdStr === null ? [] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
613
|
+
resource_ids: resourceIdStr === null ? [...related] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
554
614
|
context,
|
|
555
|
-
duration_ms: null
|
|
615
|
+
duration_ms: null,
|
|
616
|
+
timestamp: input.timestamp ?? null
|
|
556
617
|
});
|
|
557
618
|
pushEvent(event);
|
|
558
619
|
} catch (error) {
|
|
@@ -596,7 +657,7 @@ function filterMeaningfulAttributes(attrs) {
|
|
|
596
657
|
return Object.keys(out).length === 0 ? null : out;
|
|
597
658
|
}
|
|
598
659
|
function filterMeaningfulChanges(changes) {
|
|
599
|
-
return changes.filter((c) => {
|
|
660
|
+
return flattenNestedChanges(changes).filter((c) => {
|
|
600
661
|
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
601
662
|
if (!isScalar(c.to)) return false;
|
|
602
663
|
if (c.from === void 0) return true;
|
|
@@ -604,14 +665,67 @@ function filterMeaningfulChanges(changes) {
|
|
|
604
665
|
return valuesActuallyChanged(c.from, c.to);
|
|
605
666
|
});
|
|
606
667
|
}
|
|
668
|
+
var MAX_NESTED_DEPTH = 3;
|
|
669
|
+
var MAX_NESTED_LEAVES = 20;
|
|
670
|
+
var MAX_UNKNOWN_FROM_LEAVES = 5;
|
|
671
|
+
function flattenNestedChanges(changes) {
|
|
672
|
+
if (!changes.some((c) => isPlainRecord(c.to) || isPlainRecord(c.from))) return changes;
|
|
673
|
+
const out = [];
|
|
674
|
+
for (const c of changes) {
|
|
675
|
+
if (!isPlainRecord(c.to) && !isPlainRecord(c.from)) {
|
|
676
|
+
out.push(c);
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
if (!isMeaningfulAttribute(c.attribute)) continue;
|
|
680
|
+
const leaves = [];
|
|
681
|
+
collectLeafChanges(c.attribute, c.from, c.to, 1, leaves);
|
|
682
|
+
const cap = c.from === void 0 ? MAX_UNKNOWN_FROM_LEAVES : MAX_NESTED_LEAVES;
|
|
683
|
+
out.push(...leaves.slice(0, cap).map(scrubLeaf));
|
|
684
|
+
}
|
|
685
|
+
return out;
|
|
686
|
+
}
|
|
687
|
+
function collectLeafChanges(path, from, to, depth, out) {
|
|
688
|
+
if (out.length > MAX_NESTED_LEAVES) return;
|
|
689
|
+
const fromObj = isPlainRecord(from);
|
|
690
|
+
const toObj = isPlainRecord(to);
|
|
691
|
+
if ((fromObj || toObj) && depth <= MAX_NESTED_DEPTH && (fromObj || from == null) && (toObj || to == null)) {
|
|
692
|
+
const f = fromObj ? from : {};
|
|
693
|
+
const t = toObj ? to : {};
|
|
694
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(f), ...Object.keys(t)])) {
|
|
695
|
+
const before = from === void 0 ? void 0 : f[key] ?? null;
|
|
696
|
+
collectLeafChanges(`${path}.${key}`, before, t[key] ?? null, depth + 1, out);
|
|
697
|
+
}
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (from !== void 0 && sameJson(from, to)) return;
|
|
701
|
+
out.push(from === void 0 ? { attribute: path, to } : { attribute: path, from, to });
|
|
702
|
+
}
|
|
703
|
+
function scrubLeaf(change) {
|
|
704
|
+
const scrub = (v) => typeof v === "string" ? scrubSecretsInText(v) : v;
|
|
705
|
+
const out = { attribute: change.attribute, to: scrub(change.to) };
|
|
706
|
+
if (change.from !== void 0) out.from = scrub(change.from);
|
|
707
|
+
return out;
|
|
708
|
+
}
|
|
709
|
+
function isPlainRecord(value) {
|
|
710
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
711
|
+
const proto = Object.getPrototypeOf(value);
|
|
712
|
+
return proto === Object.prototype || proto === null;
|
|
713
|
+
}
|
|
714
|
+
function sameJson(a, b) {
|
|
715
|
+
if (a === b) return true;
|
|
716
|
+
try {
|
|
717
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
718
|
+
} catch {
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
607
722
|
function isMeaningfulAttribute(name) {
|
|
608
723
|
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
609
724
|
if (isDbSensitive(name)) return false;
|
|
610
725
|
return true;
|
|
611
726
|
}
|
|
612
727
|
function isDbSensitive(name) {
|
|
613
|
-
|
|
614
|
-
return DB_SENSITIVE_PATTERNS.some((p) => lower.includes(p));
|
|
728
|
+
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
615
729
|
}
|
|
616
730
|
function isScalar(value) {
|
|
617
731
|
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
@@ -642,22 +756,44 @@ function isPrismaDecimal(value) {
|
|
|
642
756
|
const obj = value;
|
|
643
757
|
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
644
758
|
}
|
|
759
|
+
var DISPLAY_NAME_COLUMNS = ["name", "title", "number", "label"];
|
|
760
|
+
var MAX_DISPLAY_NAME_LENGTH = 120;
|
|
645
761
|
function resolveDisplayName(modelClass, instance) {
|
|
646
762
|
try {
|
|
647
763
|
const config = configuration();
|
|
648
764
|
const resolver = config.displayNameFor[modelClass];
|
|
649
765
|
const resolved = applyResolver(resolver, instance);
|
|
650
766
|
if (resolved !== null) return resolved;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if (
|
|
654
|
-
|
|
767
|
+
const columns = /* @__PURE__ */ new Map();
|
|
768
|
+
for (const key of Object.keys(instance)) {
|
|
769
|
+
if (isDbSensitive(key)) continue;
|
|
770
|
+
const norm = key.toLowerCase().replace(/_/g, "");
|
|
771
|
+
if (!columns.has(norm)) columns.set(norm, instance[key]);
|
|
772
|
+
}
|
|
773
|
+
const text = (norm) => {
|
|
774
|
+
const value = columns.get(norm);
|
|
775
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
776
|
+
return null;
|
|
655
777
|
}
|
|
778
|
+
const str = String(value).trim();
|
|
779
|
+
return str.length > 0 ? str.slice(0, MAX_DISPLAY_NAME_LENGTH) : null;
|
|
780
|
+
};
|
|
781
|
+
for (const column of DISPLAY_NAME_COLUMNS) {
|
|
782
|
+
const value = text(column);
|
|
783
|
+
if (value !== null) return value;
|
|
656
784
|
}
|
|
785
|
+
return text(`${singularNorm(modelClass)}number`);
|
|
657
786
|
} catch {
|
|
658
787
|
}
|
|
659
788
|
return null;
|
|
660
789
|
}
|
|
790
|
+
function singularNorm(modelClass) {
|
|
791
|
+
const norm = modelClass.toLowerCase().replace(/_/g, "");
|
|
792
|
+
if (norm.endsWith("ies")) return norm.slice(0, -3) + "y";
|
|
793
|
+
if (/(ss|us|is)$/.test(norm)) return norm;
|
|
794
|
+
if (/(xes|ches|shes|sses)$/.test(norm)) return norm.slice(0, -2);
|
|
795
|
+
return norm.endsWith("s") ? norm.slice(0, -1) : norm;
|
|
796
|
+
}
|
|
661
797
|
function applyResolver(resolver, instance) {
|
|
662
798
|
if (typeof resolver === "string") {
|
|
663
799
|
const value = instance[resolver];
|
package/dist/db/supabase.js
CHANGED
|
@@ -109,7 +109,6 @@ var Configuration = class {
|
|
|
109
109
|
displayNameFor = {};
|
|
110
110
|
isServerActionError = null;
|
|
111
111
|
databaseReader = null;
|
|
112
|
-
databaseSnapshotMode = false;
|
|
113
112
|
databaseUrl = null;
|
|
114
113
|
/**
|
|
115
114
|
* Tables that have the `ezlogs_audit` trigger attached. Detected once
|
|
@@ -161,9 +160,6 @@ var Configuration = class {
|
|
|
161
160
|
if (options.databaseReader !== void 0) {
|
|
162
161
|
this.databaseReader = options.databaseReader;
|
|
163
162
|
}
|
|
164
|
-
if (options.databaseSnapshotMode !== void 0) {
|
|
165
|
-
this.databaseSnapshotMode = options.databaseSnapshotMode;
|
|
166
|
-
}
|
|
167
163
|
if (options.databaseUrl !== void 0) {
|
|
168
164
|
this.databaseUrl = options.databaseUrl;
|
|
169
165
|
}
|
|
@@ -491,6 +487,57 @@ var storage2 = createScopedStorage(
|
|
|
491
487
|
function getCurrentActor() {
|
|
492
488
|
return storage2.read();
|
|
493
489
|
}
|
|
490
|
+
var SENSITIVE_WORD_PATTERNS = Object.freeze([
|
|
491
|
+
"pin",
|
|
492
|
+
"otp",
|
|
493
|
+
"totp",
|
|
494
|
+
"iban",
|
|
495
|
+
"mfa",
|
|
496
|
+
"passphrase"
|
|
497
|
+
]);
|
|
498
|
+
function snakeLower(key) {
|
|
499
|
+
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
500
|
+
}
|
|
501
|
+
function matchesSensitiveKey(key, substringPatterns) {
|
|
502
|
+
const lower = key.toLowerCase();
|
|
503
|
+
const snake = snakeLower(key);
|
|
504
|
+
if (substringPatterns.some((p) => lower.includes(p) || snake.includes(p))) {
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
const words = snake.split(/[^a-z0-9]+/);
|
|
508
|
+
return SENSITIVE_WORD_PATTERNS.some((w) => words.includes(w));
|
|
509
|
+
}
|
|
510
|
+
function passesLuhn(digits) {
|
|
511
|
+
let sum = 0;
|
|
512
|
+
for (let i = 0; i < digits.length; i += 1) {
|
|
513
|
+
let d = Number(digits[digits.length - 1 - i]);
|
|
514
|
+
if (i % 2 === 1) {
|
|
515
|
+
d *= 2;
|
|
516
|
+
if (d > 9) d -= 9;
|
|
517
|
+
}
|
|
518
|
+
sum += d;
|
|
519
|
+
}
|
|
520
|
+
return sum % 10 === 0;
|
|
521
|
+
}
|
|
522
|
+
var SECRET_TEXT_PATTERNS = [
|
|
523
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
|
|
524
|
+
/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g,
|
|
525
|
+
/\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]+/g,
|
|
526
|
+
/\bsk-[A-Za-z0-9_-]{16,}/g,
|
|
527
|
+
/\bgh[pousr]_[A-Za-z0-9]{20,}/g,
|
|
528
|
+
/\bxox[abposr]-[A-Za-z0-9-]+/g,
|
|
529
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g
|
|
530
|
+
];
|
|
531
|
+
var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
532
|
+
function scrubSecretsInText(text, options = {}) {
|
|
533
|
+
let out = text;
|
|
534
|
+
for (const pattern of SECRET_TEXT_PATTERNS) out = out.replace(pattern, "[FILTERED]");
|
|
535
|
+
out = out.replace(/\b(Bearer|Basic)\s+[\w.~+/=-]+/gi, "$1 [FILTERED]").replace(/\b\d(?:[ -]?\d){12,18}\b/g, (match) => {
|
|
536
|
+
const digits = match.replace(/[ -]/g, "");
|
|
537
|
+
return (digits.length === 15 || digits.length === 16) && passesLuhn(digits) ? "[FILTERED]" : match;
|
|
538
|
+
});
|
|
539
|
+
return options.emails ? out.replace(EMAIL, "[FILTERED]") : out;
|
|
540
|
+
}
|
|
494
541
|
|
|
495
542
|
// src/db/shared.ts
|
|
496
543
|
var IGNORED_ATTRIBUTES = Object.freeze([
|
|
@@ -499,8 +546,6 @@ var IGNORED_ATTRIBUTES = Object.freeze([
|
|
|
499
546
|
"created_at",
|
|
500
547
|
"updatedAt",
|
|
501
548
|
"updated_at",
|
|
502
|
-
"deletedAt",
|
|
503
|
-
"deleted_at",
|
|
504
549
|
// Auth.js / NextAuth standard columns
|
|
505
550
|
"emailVerified",
|
|
506
551
|
"expires"
|
|
@@ -523,7 +568,19 @@ var DB_SENSITIVE_PATTERNS = Object.freeze([
|
|
|
523
568
|
"salt",
|
|
524
569
|
"digest",
|
|
525
570
|
"signature",
|
|
526
|
-
"hmac"
|
|
571
|
+
"hmac",
|
|
572
|
+
// 0.2.0 additions. `credential` / `passwd` / `apikey` were already in
|
|
573
|
+
// the HTTP list; `passcode` / `card_number` / `cardnumber` / `cvv` /
|
|
574
|
+
// `cvc` are new. Whole-word `pin` / `otp` / `totp` / `iban` come from
|
|
575
|
+
// SENSITIVE_WORD_PATTERNS. The SQL trigger mirrors this list.
|
|
576
|
+
"credential",
|
|
577
|
+
"passwd",
|
|
578
|
+
"passcode",
|
|
579
|
+
"apikey",
|
|
580
|
+
"card_number",
|
|
581
|
+
"cardnumber",
|
|
582
|
+
"cvv",
|
|
583
|
+
"cvc"
|
|
527
584
|
]);
|
|
528
585
|
function emitDbEvent(input) {
|
|
529
586
|
try {
|
|
@@ -532,14 +589,17 @@ function emitDbEvent(input) {
|
|
|
532
589
|
if (config.allExcludedTables().includes(input.modelClass)) return;
|
|
533
590
|
if (config.databaseReader && !input._fromTrigger) {
|
|
534
591
|
const tracked = config.triggerTrackedTables;
|
|
535
|
-
if (tracked === null || tracked.has(input.modelClass)) return;
|
|
592
|
+
if (tracked === null || tracked.has(input.table ?? input.modelClass)) return;
|
|
536
593
|
}
|
|
537
594
|
if (input.operation === "update") {
|
|
538
595
|
const meaningful = input.changes ? filterMeaningfulChanges(input.changes) : [];
|
|
539
596
|
if (meaningful.length === 0) return;
|
|
540
597
|
}
|
|
541
598
|
const resourceIdStr = input.resourceId === null || input.resourceId === void 0 ? null : String(input.resourceId);
|
|
542
|
-
const
|
|
599
|
+
const related = resourceIdStr === null ? input.relatedResourceIds ?? [] : [];
|
|
600
|
+
const context = buildContext(
|
|
601
|
+
related.length > 0 ? { ...input, displayName: null, modelInstance: null } : input
|
|
602
|
+
);
|
|
543
603
|
const event = build({
|
|
544
604
|
source_type: "database_callback",
|
|
545
605
|
source_data: {
|
|
@@ -548,9 +608,10 @@ function emitDbEvent(input) {
|
|
|
548
608
|
},
|
|
549
609
|
outcome: "success",
|
|
550
610
|
correlation_id: current(),
|
|
551
|
-
resource_ids: resourceIdStr === null ? [] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
611
|
+
resource_ids: resourceIdStr === null ? [...related] : [{ resource_type: input.modelClass, resource_id: resourceIdStr }],
|
|
552
612
|
context,
|
|
553
|
-
duration_ms: null
|
|
613
|
+
duration_ms: null,
|
|
614
|
+
timestamp: input.timestamp ?? null
|
|
554
615
|
});
|
|
555
616
|
pushEvent(event);
|
|
556
617
|
} catch (error) {
|
|
@@ -594,7 +655,7 @@ function filterMeaningfulAttributes(attrs) {
|
|
|
594
655
|
return Object.keys(out).length === 0 ? null : out;
|
|
595
656
|
}
|
|
596
657
|
function filterMeaningfulChanges(changes) {
|
|
597
|
-
return changes.filter((c) => {
|
|
658
|
+
return flattenNestedChanges(changes).filter((c) => {
|
|
598
659
|
if (!isMeaningfulAttribute(c.attribute)) return false;
|
|
599
660
|
if (!isScalar(c.to)) return false;
|
|
600
661
|
if (c.from === void 0) return true;
|
|
@@ -602,14 +663,67 @@ function filterMeaningfulChanges(changes) {
|
|
|
602
663
|
return valuesActuallyChanged(c.from, c.to);
|
|
603
664
|
});
|
|
604
665
|
}
|
|
666
|
+
var MAX_NESTED_DEPTH = 3;
|
|
667
|
+
var MAX_NESTED_LEAVES = 20;
|
|
668
|
+
var MAX_UNKNOWN_FROM_LEAVES = 5;
|
|
669
|
+
function flattenNestedChanges(changes) {
|
|
670
|
+
if (!changes.some((c) => isPlainRecord(c.to) || isPlainRecord(c.from))) return changes;
|
|
671
|
+
const out = [];
|
|
672
|
+
for (const c of changes) {
|
|
673
|
+
if (!isPlainRecord(c.to) && !isPlainRecord(c.from)) {
|
|
674
|
+
out.push(c);
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
if (!isMeaningfulAttribute(c.attribute)) continue;
|
|
678
|
+
const leaves = [];
|
|
679
|
+
collectLeafChanges(c.attribute, c.from, c.to, 1, leaves);
|
|
680
|
+
const cap = c.from === void 0 ? MAX_UNKNOWN_FROM_LEAVES : MAX_NESTED_LEAVES;
|
|
681
|
+
out.push(...leaves.slice(0, cap).map(scrubLeaf));
|
|
682
|
+
}
|
|
683
|
+
return out;
|
|
684
|
+
}
|
|
685
|
+
function collectLeafChanges(path, from, to, depth, out) {
|
|
686
|
+
if (out.length > MAX_NESTED_LEAVES) return;
|
|
687
|
+
const fromObj = isPlainRecord(from);
|
|
688
|
+
const toObj = isPlainRecord(to);
|
|
689
|
+
if ((fromObj || toObj) && depth <= MAX_NESTED_DEPTH && (fromObj || from == null) && (toObj || to == null)) {
|
|
690
|
+
const f = fromObj ? from : {};
|
|
691
|
+
const t = toObj ? to : {};
|
|
692
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(f), ...Object.keys(t)])) {
|
|
693
|
+
const before = from === void 0 ? void 0 : f[key] ?? null;
|
|
694
|
+
collectLeafChanges(`${path}.${key}`, before, t[key] ?? null, depth + 1, out);
|
|
695
|
+
}
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (from !== void 0 && sameJson(from, to)) return;
|
|
699
|
+
out.push(from === void 0 ? { attribute: path, to } : { attribute: path, from, to });
|
|
700
|
+
}
|
|
701
|
+
function scrubLeaf(change) {
|
|
702
|
+
const scrub = (v) => typeof v === "string" ? scrubSecretsInText(v) : v;
|
|
703
|
+
const out = { attribute: change.attribute, to: scrub(change.to) };
|
|
704
|
+
if (change.from !== void 0) out.from = scrub(change.from);
|
|
705
|
+
return out;
|
|
706
|
+
}
|
|
707
|
+
function isPlainRecord(value) {
|
|
708
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
709
|
+
const proto = Object.getPrototypeOf(value);
|
|
710
|
+
return proto === Object.prototype || proto === null;
|
|
711
|
+
}
|
|
712
|
+
function sameJson(a, b) {
|
|
713
|
+
if (a === b) return true;
|
|
714
|
+
try {
|
|
715
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
716
|
+
} catch {
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
605
720
|
function isMeaningfulAttribute(name) {
|
|
606
721
|
if (IGNORED_ATTRIBUTES.includes(name)) return false;
|
|
607
722
|
if (isDbSensitive(name)) return false;
|
|
608
723
|
return true;
|
|
609
724
|
}
|
|
610
725
|
function isDbSensitive(name) {
|
|
611
|
-
|
|
612
|
-
return DB_SENSITIVE_PATTERNS.some((p) => lower.includes(p));
|
|
726
|
+
return matchesSensitiveKey(name, DB_SENSITIVE_PATTERNS);
|
|
613
727
|
}
|
|
614
728
|
function isScalar(value) {
|
|
615
729
|
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || value instanceof Date) {
|
|
@@ -640,22 +754,44 @@ function isPrismaDecimal(value) {
|
|
|
640
754
|
const obj = value;
|
|
641
755
|
return typeof obj.toString === "function" && typeof obj.toFixed === "function" && "d" in obj && "e" in obj && "s" in obj;
|
|
642
756
|
}
|
|
757
|
+
var DISPLAY_NAME_COLUMNS = ["name", "title", "number", "label"];
|
|
758
|
+
var MAX_DISPLAY_NAME_LENGTH = 120;
|
|
643
759
|
function resolveDisplayName(modelClass, instance) {
|
|
644
760
|
try {
|
|
645
761
|
const config = configuration();
|
|
646
762
|
const resolver = config.displayNameFor[modelClass];
|
|
647
763
|
const resolved = applyResolver(resolver, instance);
|
|
648
764
|
if (resolved !== null) return resolved;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (
|
|
652
|
-
|
|
765
|
+
const columns = /* @__PURE__ */ new Map();
|
|
766
|
+
for (const key of Object.keys(instance)) {
|
|
767
|
+
if (isDbSensitive(key)) continue;
|
|
768
|
+
const norm = key.toLowerCase().replace(/_/g, "");
|
|
769
|
+
if (!columns.has(norm)) columns.set(norm, instance[key]);
|
|
770
|
+
}
|
|
771
|
+
const text = (norm) => {
|
|
772
|
+
const value = columns.get(norm);
|
|
773
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
774
|
+
return null;
|
|
653
775
|
}
|
|
776
|
+
const str = String(value).trim();
|
|
777
|
+
return str.length > 0 ? str.slice(0, MAX_DISPLAY_NAME_LENGTH) : null;
|
|
778
|
+
};
|
|
779
|
+
for (const column of DISPLAY_NAME_COLUMNS) {
|
|
780
|
+
const value = text(column);
|
|
781
|
+
if (value !== null) return value;
|
|
654
782
|
}
|
|
783
|
+
return text(`${singularNorm(modelClass)}number`);
|
|
655
784
|
} catch {
|
|
656
785
|
}
|
|
657
786
|
return null;
|
|
658
787
|
}
|
|
788
|
+
function singularNorm(modelClass) {
|
|
789
|
+
const norm = modelClass.toLowerCase().replace(/_/g, "");
|
|
790
|
+
if (norm.endsWith("ies")) return norm.slice(0, -3) + "y";
|
|
791
|
+
if (/(ss|us|is)$/.test(norm)) return norm;
|
|
792
|
+
if (/(xes|ches|shes|sses)$/.test(norm)) return norm.slice(0, -2);
|
|
793
|
+
return norm.endsWith("s") ? norm.slice(0, -1) : norm;
|
|
794
|
+
}
|
|
659
795
|
function applyResolver(resolver, instance) {
|
|
660
796
|
if (typeof resolver === "string") {
|
|
661
797
|
const value = instance[resolver];
|