@bymax-one/nest-logger 1.4.29 → 1.4.31

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.
@@ -90,10 +90,36 @@ var GROUP_KEYS = {
90
90
  };
91
91
  var GROUP_NAMES = Object.keys(GROUP_KEYS);
92
92
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
93
+ var MAX_PROTOTYPE_HOPS = 256;
94
+ function rootHolding(source, key) {
95
+ let hops = 0;
96
+ for (let at = source; at !== null; at = Object.getPrototypeOf(at)) {
97
+ if (hops++ > MAX_PROTOTYPE_HOPS) {
98
+ refuse(
99
+ `[BymaxLoggerModule] options.${key} holds more than ${String(MAX_PROTOTYPE_HOPS)} prototypes`
100
+ );
101
+ }
102
+ if (Object.hasOwn(at, key)) {
103
+ return at !== source && Object.getPrototypeOf(at) === null ? at : void 0;
104
+ }
105
+ }
106
+ return void 0;
107
+ }
93
108
  function readSet(source, keys) {
94
- const set = {};
109
+ const set = /* @__PURE__ */ Object.create(null);
95
110
  for (const key of keys) {
111
+ const root = rootHolding(source, key);
112
+ const planted = root && Object.getOwnPropertyDescriptor(root, key);
113
+ const accessor = planted !== void 0 && Object.hasOwn(planted, "get") && planted.get !== void 0;
114
+ if (accessor) {
115
+ if (util.types.isProxy(source))
116
+ refuse(
117
+ `[BymaxLoggerModule] options.${key} is read through a Proxy while an accessor of that name is planted on Object.prototype`
118
+ );
119
+ continue;
120
+ }
96
121
  const value = Reflect.get(source, key);
122
+ if (planted && Object.hasOwn(planted, "value") && Object.is(value, planted.value)) continue;
97
123
  if (value !== void 0 && value !== null) Reflect.set(set, key, value);
98
124
  }
99
125
  return set;
@@ -130,7 +156,8 @@ function dropUnsetOptions(options) {
130
156
  Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
131
157
  }
132
158
  const service = Reflect.get(set, "service");
133
- if (isRecord(service)) Reflect.set(set, "service", { ...service });
159
+ if (isRecord(service))
160
+ Reflect.set(set, "service", Object.assign(/* @__PURE__ */ Object.create(null), service));
134
161
  const serializers = Reflect.get(set, "serializers");
135
162
  if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
136
163
  copyLists(set, LIST_OPTIONS, "");
@@ -195,7 +222,9 @@ function applyDefaults(given) {
195
222
  options.otel
196
223
  );
197
224
  const merged = {
198
- service: Object.freeze({ ...options.service }),
225
+ service: Object.freeze(
226
+ Object.assign(/* @__PURE__ */ Object.create(null), options.service)
227
+ ),
199
228
  level: options.level ?? (isProduction ? "info" : "debug"),
200
229
  isGlobal: options.isGlobal ?? true,
201
230
  shouldUseAsNestLogger: options.shouldUseAsNestLogger ?? true,
@@ -301,6 +330,7 @@ function checkGroup(path, value) {
301
330
  if (!isRecord2(value)) reject(path, "must be an object", value);
302
331
  return value;
303
332
  }
333
+ var MAX_REDACT_PATH_LENGTH = 256;
304
334
  var MAX_TIMER_MS = 2147483647;
305
335
  function checkTimerMs(path, value) {
306
336
  if (value === void 0) return;
@@ -415,6 +445,13 @@ function validateCustomization(options) {
415
445
  if (!isNonEmptyString(entry)) {
416
446
  reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry, true);
417
447
  }
448
+ if (entry.length > MAX_REDACT_PATH_LENGTH) {
449
+ reject(
450
+ `redactPaths[${String(index)}]`,
451
+ `must be at most ${String(MAX_REDACT_PATH_LENGTH)} characters`,
452
+ entry
453
+ );
454
+ }
418
455
  });
419
456
  }
420
457
  const serializers = options.serializers;
@@ -531,8 +568,131 @@ function validateOptions(given) {
531
568
  validateOtel(options);
532
569
  }
533
570
 
571
+ // src/server/utils/bare-descriptor.util.ts
572
+ var assign = Object.assign;
573
+ function bareDescriptor(descriptor) {
574
+ return assign(/* @__PURE__ */ Object.create(null), descriptor);
575
+ }
576
+
577
+ // src/server/utils/captured-builtins.util.ts
578
+ var call = Function.prototype.call;
579
+ var defineProperty = Object.defineProperty;
580
+ var setHas = call.bind(Set.prototype.has);
581
+ var setAdd = call.bind(Set.prototype.add);
582
+ var lowerCase = call.bind(String.prototype.toLowerCase);
583
+ var indexOfText = call.bind(String.prototype.indexOf);
584
+ var sliceText = call.bind(String.prototype.slice);
585
+ function replaceAllText(text, search, replacement) {
586
+ if (search === "") return text;
587
+ let result = "";
588
+ let from = 0;
589
+ for (let at = indexOfText(text, search, 0); at !== -1; at = indexOfText(text, search, from)) {
590
+ result += sliceText(text, from, at) + replacement;
591
+ from = at + search.length;
592
+ }
593
+ return result + sliceText(text, from);
594
+ }
595
+ var normalizeText = call.bind(String.prototype.normalize);
596
+ var regExpExec = call.bind(RegExp.prototype.exec);
597
+ var regExpReplace = call.bind(RegExp.prototype[Symbol.replace]);
598
+ function matchesPattern(pattern, text) {
599
+ return regExpExec(pattern, text) !== null;
600
+ }
601
+ function allMatches(pattern, text) {
602
+ const found = [];
603
+ pattern.lastIndex = 0;
604
+ for (let match = regExpExec(pattern, text); match !== null; match = regExpExec(pattern, text)) {
605
+ if (match[0] === "") break;
606
+ found[found.length] = match;
607
+ }
608
+ pattern.lastIndex = 0;
609
+ return found;
610
+ }
611
+ function replacer(pattern) {
612
+ defineProperty(
613
+ pattern,
614
+ "exec",
615
+ bareDescriptor({ value: (text) => regExpExec(pattern, text) })
616
+ );
617
+ return (text, replacement) => regExpReplace(pattern, text, replacement);
618
+ }
619
+ function capturedSet(values = []) {
620
+ const set = /* @__PURE__ */ new Set();
621
+ const has = (value) => setHas(set, value);
622
+ const add = (value) => {
623
+ setAdd(set, value);
624
+ return set;
625
+ };
626
+ defineProperty(set, "has", bareDescriptor({ value: has }));
627
+ defineProperty(set, "add", bareDescriptor({ value: add }));
628
+ if (Array.isArray(values)) for (let at = 0; at < values.length; at++) add(values[at]);
629
+ else for (const value of values) add(value);
630
+ return set;
631
+ }
632
+ function nextOf(iterator) {
633
+ return Object.getPrototypeOf(iterator);
634
+ }
635
+ var GUARDED_BUILTINS = [
636
+ [Array, ["from", "isArray"]],
637
+ [ArrayBuffer, ["isView"]],
638
+ [Buffer, ["byteLength", "from"]],
639
+ [Buffer.prototype, ["readUInt8", "subarray"]],
640
+ [
641
+ Array.prototype,
642
+ ["at", "filter", "flatMap", "forEach", "join", "map", "push", "reduce", "shift", "some", "sort"]
643
+ ],
644
+ [Array.prototype, [Symbol.iterator]],
645
+ [String, ["fromCodePoint"]],
646
+ [
647
+ String.prototype,
648
+ ["includes", "indexOf", "lastIndexOf", "normalize", "replace", "search", "slice", "split"]
649
+ ],
650
+ [String.prototype, ["charCodeAt", "startsWith", "toLowerCase", Symbol.iterator, Symbol.replace]],
651
+ [Map.prototype, ["clear", "get", "has", "set", Symbol.iterator]],
652
+ [Set.prototype, ["add", "delete", "has", "values", Symbol.iterator]],
653
+ [RegExp.prototype, ["exec", "test", Symbol.replace]],
654
+ [
655
+ Object,
656
+ ["assign", "create", "defineProperty", "entries", "fromEntries", "getOwnPropertyDescriptor"]
657
+ ],
658
+ [Function.prototype, ["call"]],
659
+ [Object, ["getOwnPropertyDescriptors", "getPrototypeOf", "hasOwn", "keys"]],
660
+ [
661
+ Reflect,
662
+ ["defineProperty", "deleteProperty", "get", "getOwnPropertyDescriptor", "ownKeys", "set"]
663
+ ],
664
+ [Math, ["max", "min"]],
665
+ [Number, ["isInteger"]],
666
+ [nextOf([][Symbol.iterator]()), ["next"]],
667
+ [nextOf(""[Symbol.iterator]()), ["next"]],
668
+ [nextOf((/* @__PURE__ */ new Map())[Symbol.iterator]()), ["next"]],
669
+ [nextOf((/* @__PURE__ */ new Set())[Symbol.iterator]()), ["next"]],
670
+ [nextOf(/(?:)/[Symbol.matchAll]("")), ["next"]]
671
+ ];
672
+ var guardedHolders = [];
673
+ var guardedMembers = [];
674
+ var guardedValues = [];
675
+ for (let at = 0; at < GUARDED_BUILTINS.length; at++) {
676
+ const entry = GUARDED_BUILTINS[at];
677
+ for (let member = 0; member < entry[1].length; member++) {
678
+ const name = entry[1][member];
679
+ guardedHolders[guardedHolders.length] = entry[0];
680
+ guardedMembers[guardedMembers.length] = name;
681
+ guardedValues[guardedValues.length] = entry[0][name];
682
+ }
683
+ }
684
+ function pinoBuiltinsIntact() {
685
+ for (let at = 0; at < guardedHolders.length; at++) {
686
+ if (guardedHolders[at][guardedMembers[at]] !== guardedValues[at]) {
687
+ return false;
688
+ }
689
+ }
690
+ return true;
691
+ }
692
+
534
693
  // src/server/config/resolve-options.ts
535
694
  function resolveOptions(given) {
695
+ if (!pinoBuiltinsIntact()) throw new Error("LOGGER_BUILTINS_REPLACED");
536
696
  return guardOptions(() => {
537
697
  const snapshot = dropUnsetOptions(given);
538
698
  validateOptions(snapshot);
@@ -586,7 +746,7 @@ var RESERVED_LOG_KEYS_NOT_EMITTED = Object.freeze({
586
746
  });
587
747
 
588
748
  // src/server/constants/prototype-polluting-keys.constants.ts
589
- var PROTOTYPE_POLLUTING_KEYS = /* @__PURE__ */ new Set([
749
+ var PROTOTYPE_POLLUTING_KEYS = capturedSet([
590
750
  "__proto__",
591
751
  "constructor",
592
752
  "prototype"
@@ -638,33 +798,35 @@ function createEntryTextFinisher(redact, limit, onCut) {
638
798
  };
639
799
  }
640
800
 
641
- // src/server/utils/escape-log-text.util.ts
642
- var LINE_TERMINATORS = /* @__PURE__ */ new Set(["\r", "\n", "\x85", "\u2028", "\u2029"]);
643
- var UNSAFE_IN_SINGLE_LINE = /[\u0000-\u0008\u000A-\u001F\u007F-\u009F\u2028\u2029\p{Cs}]/gu;
644
- var UNSAFE_IN_MULTILINE = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u2028\u2029\p{Cs}]/gu;
645
- function toEscapeSequence(char) {
646
- return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
647
- }
648
- function toSingleLineMessage(text) {
649
- return text.replace(
650
- UNSAFE_IN_SINGLE_LINE,
651
- (char) => LINE_TERMINATORS.has(char) ? "\\n" : toEscapeSequence(char)
652
- );
653
- }
654
- function toBoundedMessage(text) {
655
- return cutText(toSingleLineMessage(text));
656
- }
657
- function escapeControlCharacters(text) {
658
- return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
659
- }
801
+ // src/server/utils/glyph-letters.generated.ts
802
+ var GLYPH_LETTER_RUNS = [
803
+ [127312, "abcdefghijklmnopqrstuvwxyz"],
804
+ [127344, "abcdefghijklmnopqrstuvwxyzp"],
805
+ [127397, "d"],
806
+ [127462, "abcdefghijklmnopqrstuvwxyz"]
807
+ ];
660
808
 
661
809
  // src/server/utils/fold-key.util.ts
662
- var NOT_NAME = /[^\p{L}\p{N}]|[\u115f\u1160\u3164\uffa0]/gu;
663
- var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}\u115f\u1160\u2800\u3164\uffa0]/gu;
664
- var DOTS = /[\u3002\u0701\u06d4\u22c5\u00b7\ufe12]/gu;
810
+ var dropNotName = replacer(/[^\p{L}\p{N}]|[\u115f\u1160\u3164\uffa0]/gu);
811
+ var SYMBOL_STAND_IN = "\uFFFC";
812
+ var standInSymbols = replacer(/(?=[^\0-\x7f])[\p{So}\p{Sm}\p{Sk}]/gu);
813
+ var dropNotNameStrict = replacer(/[^\p{L}\p{N}\ufffc]|[\u115f\u1160\u3164\uffa0]/gu);
814
+ var GLYPH_LETTERS = new Map(
815
+ GLYPH_LETTER_RUNS.flatMap(
816
+ ([first, letters]) => [...letters].map((letter, index) => [
817
+ String.fromCodePoint(first + index),
818
+ letter
819
+ ])
820
+ )
821
+ );
822
+ function readGlyphs(text) {
823
+ return Array.from(text, (glyph) => GLYPH_LETTERS.get(glyph) ?? glyph).join("");
824
+ }
825
+ var dropInvisible = replacer(/[\s\p{Cc}\p{Cf}\p{M}\u115f\u1160\u2800\u3164\uffa0]/gu);
826
+ var readDots = replacer(/[\u3002\u0701\u06d4\u22c5\u00b7\ufe12]/gu);
665
827
  var PLAIN = /^[\x21-\x7e]*$/;
666
828
  var NON_ASCII = /[^\x20-\x7e]/;
667
- var NOT_ASCII_NAME = /[^A-Za-z0-9]/g;
829
+ var dropNotAscii = replacer(/[^A-Za-z0-9]/g);
668
830
  var LOOKALIKES = new Map(
669
831
  Object.entries({
670
832
  a: "\u0430\u03B1\u1D00",
@@ -694,40 +856,57 @@ var LOOKALIKES = new Map(
694
856
  z: "\u1D22"
695
857
  }).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
696
858
  );
859
+ var LOOKALIKE_PAIRS = Array.from(LOOKALIKES);
697
860
  var I_LIKE = new Map(
698
861
  [..."\u0456\u03B9\u0131\u026A\u0269"].map((letter) => [letter, "i"])
699
862
  );
863
+ var I_LIKE_PAIRS = Array.from(I_LIKE);
700
864
  function foldKey(key, keepSeparators = false) {
701
865
  if (keepSeparators) {
702
- if (PLAIN.test(key)) return key.toLowerCase();
703
- return withLookalikes(
704
- key.normalize("NFKD").toLowerCase().replace(DOTS, ".").replace(INVISIBLE, ""),
866
+ return matchesPattern(PLAIN, key) ? lowerCase(key) : withLookalikes(
867
+ dropInvisible(readDots(readGlyphs(lowerCase(normalizeText(key, "NFKD"))), "."), ""),
705
868
  true
706
869
  );
707
870
  }
708
- if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
709
- return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), true);
871
+ return matchesPattern(PLAIN, key) ? lowerCase(dropNotAscii(key, "")) : withLookalikes(dropNotName(readGlyphs(lowerCase(normalizeText(key, "NFKD"))), ""), true);
710
872
  }
711
873
  function foldStrict(key) {
712
- if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
713
- return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), false);
874
+ return matchesPattern(PLAIN, key) ? lowerCase(dropNotAscii(key, "")) : withLookalikes(
875
+ dropNotNameStrict(
876
+ standInSymbols(readGlyphs(lowerCase(normalizeText(key, "NFKD"))), SYMBOL_STAND_IN),
877
+ ""
878
+ ),
879
+ false
880
+ );
714
881
  }
715
882
  function withLookalikes(folded, all) {
716
883
  let read = folded;
717
- for (const [letter, latin] of LOOKALIKES) read = read.replaceAll(letter, latin);
718
- if (all) for (const [letter, latin] of I_LIKE) read = read.replaceAll(letter, latin);
884
+ for (let at = 0; at < LOOKALIKE_PAIRS.length; at++) {
885
+ const [letter, latin] = LOOKALIKE_PAIRS[at];
886
+ read = replaceAllText(read, letter, latin);
887
+ }
888
+ if (all) {
889
+ for (let at = 0; at < I_LIKE_PAIRS.length; at++) {
890
+ const [letter, latin] = I_LIKE_PAIRS[at];
891
+ read = replaceAllText(read, letter, latin);
892
+ }
893
+ }
719
894
  return read;
720
895
  }
721
896
  var ALNUM = /^[A-Za-z0-9]*$/;
722
897
  function formOf(key) {
723
- return ALNUM.test(key) ? key.toLowerCase() : foldStrict(key);
898
+ return matchesPattern(ALNUM, key) ? lowerCase(key) : foldStrict(key);
724
899
  }
725
900
  var answers = /* @__PURE__ */ new WeakMap();
726
901
  function foldName(key) {
727
902
  return formOf(key);
728
903
  }
729
904
  function foldedNames(names) {
730
- return new Set(Array.from(names, foldName).filter((name) => name !== ""));
905
+ return capturedSet(
906
+ Array.from(names, (name) => replaceAllText(foldName(name), SYMBOL_STAND_IN, "")).filter(
907
+ (name) => name !== ""
908
+ )
909
+ );
731
910
  }
732
911
  var MAX_CANDIDATES = 64;
733
912
  var grouped = /* @__PURE__ */ new WeakMap();
@@ -750,34 +929,46 @@ function groupsOf(names) {
750
929
  }
751
930
  function matchesFolded(names, folded) {
752
931
  if (names.has(folded)) return true;
753
- if (!NON_ASCII.test(folded)) return false;
932
+ if (!matchesPattern(NON_ASCII, folded)) return false;
754
933
  const letters = [...folded];
755
934
  const wide = letters.filter((letter) => !isAscii(letter)).length;
935
+ const stands = letters.filter((letter) => letter === SYMBOL_STAND_IN).length;
756
936
  const { byLength, longest } = groupsOf(names);
757
- if (letters.length > longest) return false;
937
+ if (longest === 0) return false;
938
+ if (stands > longest) return true;
939
+ const shortest = letters.length - stands;
940
+ const reach = longest - shortest;
758
941
  const lengths = Array.from(
759
- { length: wide + 1 },
760
- (_, extra) => byLength.get(letters.length + extra) ?? []
942
+ { length: Math.min(wide + stands + 1, reach + 1) },
943
+ (_, extra) => byLength.get(shortest + extra) ?? []
761
944
  );
762
945
  if (lengths.reduce((count, same) => count + same.length, 0) > MAX_CANDIDATES) return true;
763
946
  return lengths.some((same) => same.some((name) => matchesName(letters, [...name])));
764
947
  }
765
948
  var isAscii = (letter) => letter < "\x80";
766
949
  function matchesName(letters, name) {
767
- let at = /* @__PURE__ */ new Set([0]);
950
+ const initial = /* @__PURE__ */ new Set();
951
+ setAdd(initial, 0);
952
+ let at = initial;
768
953
  for (const letter of letters) {
769
954
  const next = /* @__PURE__ */ new Set();
770
955
  for (const position of at) {
956
+ if (letter === SYMBOL_STAND_IN) {
957
+ setAdd(next, position);
958
+ setAdd(next, position + 1);
959
+ setAdd(next, position + 2);
960
+ continue;
961
+ }
771
962
  if (isAscii(letter)) {
772
- if (name[position] === letter) next.add(position + 1);
963
+ if (name[position] === letter) setAdd(next, position + 1);
773
964
  continue;
774
965
  }
775
- next.add(position + 1);
776
- next.add(position + 2);
966
+ setAdd(next, position + 1);
967
+ setAdd(next, position + 2);
777
968
  }
778
969
  at = next;
779
970
  }
780
- return at.has(name.length);
971
+ return setHas(at, name.length);
781
972
  }
782
973
  function matchesKey(names, key) {
783
974
  const seen = answers.get(names) ?? /* @__PURE__ */ new Map();
@@ -796,7 +987,8 @@ function matchesKey(names, key) {
796
987
  // src/server/utils/hide-message-in-stack.util.ts
797
988
  function failureTable(message) {
798
989
  const table = new Int32Array(message.length);
799
- for (let i = 1, matched = 0; i < message.length; i += 1) {
990
+ const end = Math.max(1, message.length);
991
+ for (let i = 1, matched = 0; i !== end; i += 1) {
800
992
  while (matched > 0 && message[i] !== message[matched]) matched = table[matched - 1];
801
993
  if (message[i] === message[matched]) matched += 1;
802
994
  table[i] = matched;
@@ -804,14 +996,17 @@ function failureTable(message) {
804
996
  return table;
805
997
  }
806
998
  function occurrences(stack, message) {
807
- if (message.length > stack.length) return [];
808
- const table = failureTable(message);
999
+ const searched = message.slice(0, stack.length + 1);
1000
+ const table = failureTable(searched);
809
1001
  const spans = [];
810
- for (let i = 0, matched = 0; i < stack.length; i += 1) {
811
- while (matched > 0 && stack[i] !== message[matched]) matched = table[matched - 1];
812
- if (stack[i] === message[matched]) matched += 1;
813
- if (matched === message.length) {
814
- spans.push([i + 1 - message.length, i + 1]);
1002
+ for (let i = 0, matched = 0; i !== stack.length; i += 1) {
1003
+ while (matched > 0 && stack[i] !== searched[matched]) matched = table[matched - 1];
1004
+ if (stack[i] === searched[matched]) matched += 1;
1005
+ if (matched === searched.length) {
1006
+ const start = i + 1 - searched.length;
1007
+ const last = spans[spans.length - 1];
1008
+ if (last !== void 0 && start < last[1]) last[1] = i + 1;
1009
+ else spans.push([start, i + 1]);
815
1010
  }
816
1011
  }
817
1012
  return spans;
@@ -834,19 +1029,6 @@ function hideMessagesInStack(stack, messages, replacement, limit) {
834
1029
  }
835
1030
  return result + stack.slice(from, Math.max(end, from));
836
1031
  }
837
- function hideMessageInStack(stack, message, replacement) {
838
- return hideMessagesInStack(stack, [message], replacement, stack.length);
839
- }
840
-
841
- // src/server/utils/is-plain-record.util.ts
842
- function isPlainRecord(node) {
843
- try {
844
- const prototype = Object.getPrototypeOf(node);
845
- return prototype === Object.prototype || prototype === null;
846
- } catch {
847
- return false;
848
- }
849
- }
850
1032
 
851
1033
  // src/server/utils/censor-stack-header.util.ts
852
1034
  var NAME_SEPARATOR = ": ";
@@ -866,6 +1048,26 @@ function splitCensoredHeader(stack, name, message, censored) {
866
1048
  if (endsHeader(stack, message, 0)) return [censored, stack.slice(message.length)];
867
1049
  return [name === "" ? censored : name + NAME_SEPARATOR + censored, ""];
868
1050
  }
1051
+
1052
+ // src/server/utils/escape-log-text.util.ts
1053
+ var LINE_TERMINATORS = capturedSet(["\r", "\n", "\x85", "\u2028", "\u2029"]);
1054
+ var UNSAFE_IN_SINGLE_LINE = /[\u0000-\u0008\u000A-\u001F\u007F-\u009F\u2028\u2029\p{Cs}]/gu;
1055
+ var UNSAFE_IN_MULTILINE = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u2028\u2029\p{Cs}]/gu;
1056
+ function toEscapeSequence(char) {
1057
+ return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
1058
+ }
1059
+ function toSingleLineMessage(text) {
1060
+ return text.replace(
1061
+ UNSAFE_IN_SINGLE_LINE,
1062
+ (char) => LINE_TERMINATORS.has(char) ? "\\n" : toEscapeSequence(char)
1063
+ );
1064
+ }
1065
+ function toBoundedMessage(text) {
1066
+ return cutText(toSingleLineMessage(text));
1067
+ }
1068
+ function escapeControlCharacters(text) {
1069
+ return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
1070
+ }
869
1071
  function isError(value) {
870
1072
  try {
871
1073
  return util.types.isNativeError(value) || value instanceof Error;
@@ -889,17 +1091,17 @@ var DEFAULT_SAFE_ERROR_FIELDS = [
889
1091
  "schema",
890
1092
  "routine"
891
1093
  ];
892
- var DERIVED_ERROR_FIELDS = /* @__PURE__ */ new Set([
1094
+ var DERIVED_ERROR_FIELDS = capturedSet([
893
1095
  "name",
894
1096
  "message",
895
1097
  "stack",
896
1098
  "cause",
897
1099
  "errors"
898
1100
  ]);
899
- var ALL_OWN_FIELDS = { safe: false, names: /* @__PURE__ */ new Set() };
1101
+ var ALL_OWN_FIELDS = { safe: false, names: capturedSet() };
900
1102
  function createOwnFieldPolicy(mode, extraNames) {
901
1103
  if (mode === "all") return ALL_OWN_FIELDS;
902
- return { safe: true, names: /* @__PURE__ */ new Set([...DEFAULT_SAFE_ERROR_FIELDS, ...extraNames]) };
1104
+ return { safe: true, names: capturedSet([...DEFAULT_SAFE_ERROR_FIELDS, ...extraNames]) };
903
1105
  }
904
1106
  function allowsOwnField(policy, key) {
905
1107
  return !policy.safe || DERIVED_ERROR_FIELDS.has(key) || key === "_errorFieldsIncomplete" || policy.names.has(key);
@@ -996,26 +1198,30 @@ function toSanitizedError(value, seen, depth2, walk2) {
996
1198
  return { name: "SanitizeFailed", message: "Failed to sanitize the thrown value" };
997
1199
  }
998
1200
  }
999
- var ARGUMENT_FIELDS = /* @__PURE__ */ new Set(["args", "parameters"]);
1000
- var DATABASE_VALUE_FIELDS = /* @__PURE__ */ new Set(["detail", "where", "internalQuery"]);
1201
+ var ARGUMENT_FIELDS = capturedSet(["args", "parameters"]);
1202
+ var DATABASE_VALUE_FIELDS = capturedSet(["detail", "where", "internalQuery"]);
1001
1203
  var SQLSTATE = /^[0-9A-DF-Z][0-9A-Z]{4}$/;
1002
1204
  var OMIT_OWN_FIELD = /* @__PURE__ */ Symbol("omit-own-field");
1205
+ function ownDataValue(source, key) {
1206
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
1207
+ return descriptor !== void 0 && Object.hasOwn(descriptor, "value") ? descriptor.value : void 0;
1208
+ }
1003
1209
  function isDatabaseError(source) {
1004
- const code = Object.getOwnPropertyDescriptor(source, "code")?.value;
1005
- return typeof code === "string" && SQLSTATE.test(code);
1210
+ const code = ownDataValue(source, "code");
1211
+ return typeof code === "string" && matchesPattern(SQLSTATE, code);
1006
1212
  }
1007
1213
  function ownFieldForLog(source, key, value, policy = ALL_OWN_FIELDS) {
1008
1214
  if (!allowsOwnField(policy, key)) return OMIT_OWN_FIELD;
1009
- if (ARGUMENT_FIELDS.has(key.toLowerCase())) return OMIT_OWN_FIELD;
1215
+ if (ARGUMENT_FIELDS.has(lowerCase(key))) return OMIT_OWN_FIELD;
1010
1216
  if (DATABASE_VALUE_FIELDS.has(key) && isDatabaseError(source)) return OMIT_OWN_FIELD;
1011
1217
  if (key !== "command" || typeof value !== "object" || value === null) {
1012
1218
  return withBinaryAsSize(value);
1013
1219
  }
1014
- const name = Object.getOwnPropertyDescriptor(value, "name")?.value;
1220
+ const name = ownDataValue(value, "name");
1015
1221
  return typeof name === "string" ? { name } : OMIT_OWN_FIELD;
1016
1222
  }
1017
1223
  function defineErrorField(target, key, value) {
1018
- Object.defineProperty(target, key, { value, enumerable: true });
1224
+ Object.defineProperty(target, key, bareDescriptor({ value, enumerable: true }));
1019
1225
  }
1020
1226
  function assignOwnErrorFields(target, source, policy = ALL_OWN_FIELDS) {
1021
1227
  try {
@@ -1032,7 +1238,11 @@ function assignOwnErrorFields(target, source, policy = ALL_OWN_FIELDS) {
1032
1238
  }
1033
1239
  }
1034
1240
  function markIncomplete(target) {
1035
- Reflect.defineProperty(target, "_errorFieldsIncomplete", { value: true, enumerable: true });
1241
+ Reflect.defineProperty(
1242
+ target,
1243
+ "_errorFieldsIncomplete",
1244
+ bareDescriptor({ value: true, enumerable: true })
1245
+ );
1036
1246
  }
1037
1247
  function readOptional(read, node) {
1038
1248
  try {
@@ -1043,7 +1253,7 @@ function readOptional(read, node) {
1043
1253
  }
1044
1254
  }
1045
1255
  function toSanitizedChild(value, seen, depth2, walk2) {
1046
- if (isObject(value) && seen.has(value)) {
1256
+ if (seen.has(value)) {
1047
1257
  return CIRCULAR_SENTINEL;
1048
1258
  }
1049
1259
  return toSanitizedError(value, seen, depth2, walk2);
@@ -1067,7 +1277,7 @@ var MAX_PLAIN_NAME = 64;
1067
1277
  var PLAIN_NAME = /^[A-Za-z_$][\w$.-]*$/;
1068
1278
  function censorName(name, censorMessage) {
1069
1279
  if (censorMessage === void 0 || name === "") return name;
1070
- if (name.length <= MAX_PLAIN_NAME && PLAIN_NAME.test(name)) return name;
1280
+ if (name.length <= MAX_PLAIN_NAME && matchesPattern(PLAIN_NAME, name)) return name;
1071
1281
  try {
1072
1282
  return censorMessage(name);
1073
1283
  } catch {
@@ -1108,9 +1318,6 @@ function scrubStack(stack, header, wasLonger = false) {
1108
1318
  );
1109
1319
  return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
1110
1320
  }
1111
- function isObject(value) {
1112
- return typeof value === "object" && value !== null;
1113
- }
1114
1321
  function createDepthMarker() {
1115
1322
  return { _truncated: true, _reason: "cause-depth-exceeded" };
1116
1323
  }
@@ -1118,6 +1325,178 @@ function createWidthMarker(omitted) {
1118
1325
  return { _truncated: true, _reason: "aggregate-width-exceeded", _omitted: omitted };
1119
1326
  }
1120
1327
 
1328
+ // src/server/utils/redact-error-parts.util.ts
1329
+ function defineOwn(target, key, value) {
1330
+ Reflect.defineProperty(target, key, bareDescriptor({ value, enumerable: true, writable: true }));
1331
+ }
1332
+ var linkDepths = /* @__PURE__ */ new WeakMap();
1333
+ var ERROR_TEXT_FIELDS = capturedSet(["name", "message", "stack"]);
1334
+ var INCOMPLETE_KEY = "_errorFieldsIncomplete";
1335
+ var widthMarkers = /* @__PURE__ */ new WeakSet();
1336
+ function capErrors(errors, host) {
1337
+ if (!Array.isArray(errors) || errors.length <= MAX_AGGREGATE_ERRORS) return errors;
1338
+ if (host.hasToJson(errors)) return errors;
1339
+ const kept = [];
1340
+ for (let index = 0; index < MAX_AGGREGATE_ERRORS; index++) kept.push(Reflect.get(errors, index));
1341
+ const marker = createWidthMarker(errors.length - MAX_AGGREGATE_ERRORS);
1342
+ widthMarkers.add(marker);
1343
+ kept.push(marker);
1344
+ return kept;
1345
+ }
1346
+ function linkTargets(value) {
1347
+ const targets = [];
1348
+ const take = (link) => {
1349
+ if (typeof link === "object" && link !== null) targets.push(link);
1350
+ };
1351
+ if (!Array.isArray(value)) take(value);
1352
+ else for (let index = 0; index < value.length; index++) take(Reflect.get(value, index));
1353
+ return targets;
1354
+ }
1355
+ function walkChainPart(value, level, host, depth2) {
1356
+ const targets = linkTargets(value);
1357
+ if (targets.length > 0 && level + 1 > DEFAULT_MAX_CAUSE_DEPTH) {
1358
+ if (Array.isArray(value) && host.nameKey === "name") {
1359
+ return Array.from({ length: value.length }, (_member, index) => {
1360
+ const member = Reflect.get(value, index);
1361
+ return typeof member === "object" && member !== null && widthMarkers.has(member) ? member : createDepthMarker();
1362
+ });
1363
+ }
1364
+ return createDepthMarker();
1365
+ }
1366
+ const before = new Map(targets.map((target) => [target, linkDepths.get(target)]));
1367
+ for (const target of targets) linkDepths.set(target, level + 1);
1368
+ try {
1369
+ return host.walk(value, depth2 + 1);
1370
+ } finally {
1371
+ before.forEach((earlier, target) => {
1372
+ if (earlier === void 0) linkDepths.delete(target);
1373
+ else linkDepths.set(target, earlier);
1374
+ });
1375
+ }
1376
+ }
1377
+ function cutOrWalk(value, level, host, depth2) {
1378
+ return typeof value === "string" ? cutText(value) : walkChainPart(value, level, host, depth2);
1379
+ }
1380
+ function writeName(value, level, host, depth2) {
1381
+ const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
1382
+ return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
1383
+ }
1384
+ function addErrorParts(copy, error, ownKeys, host, depth2) {
1385
+ const taken = capturedSet(ownKeys);
1386
+ const level = linkDepths.get(error) ?? 0;
1387
+ let incomplete = false;
1388
+ const add = (key, covers, read, write = (value) => walkChainPart(value, level, host, depth2)) => {
1389
+ if (taken.has(key)) return;
1390
+ try {
1391
+ const written = write(read());
1392
+ if (written === void 0) return;
1393
+ const covered = covers.some((name) => host.sensitive.has(name));
1394
+ defineOwn(copy, key, covered ? host.censor : written);
1395
+ } catch {
1396
+ incomplete = true;
1397
+ }
1398
+ };
1399
+ add(
1400
+ host.nameKey,
1401
+ [host.nameKey, "name"],
1402
+ () => error.name,
1403
+ (name) => writeName(name, level, host, depth2)
1404
+ );
1405
+ add(
1406
+ "message",
1407
+ ["message"],
1408
+ () => error.message,
1409
+ (message) => cutOrWalk(message, level, host, depth2)
1410
+ );
1411
+ add(
1412
+ "stack",
1413
+ ["stack", "name", "message"],
1414
+ () => error.stack,
1415
+ (stack) => typeof stack === "string" ? scrubStack(stack) : void 0
1416
+ );
1417
+ add("cause", ["cause"], () => error.cause);
1418
+ add("errors", ["errors"], () => capErrors(error.errors, host));
1419
+ if (incomplete && !taken.has(INCOMPLETE_KEY)) defineOwn(copy, INCOMPLETE_KEY, true);
1420
+ }
1421
+
1422
+ // src/server/utils/error-text-exemption.util.ts
1423
+ var ERROR_TEXT_KEYS = capturedSet(["message"]);
1424
+ function leavesErrorText(rules, key, value, honorToJson) {
1425
+ return rules.errorTextToSerializer && !honorToJson && key === "err" && !Array.isArray(value);
1426
+ }
1427
+ function rulesBelow(rules, key, value, honorToJson) {
1428
+ if (leavesErrorText(rules, key, value, honorToJson)) {
1429
+ return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
1430
+ }
1431
+ return { ...rules, exemptKeys: void 0, headerKept: void 0 };
1432
+ }
1433
+ function isCensored(rules, key, value) {
1434
+ return matchesKey(rules.sensitive, key) && !(typeof value === "string" && rules.exemptKeys?.has(key));
1435
+ }
1436
+ function messageCensor(rules) {
1437
+ return (text) => rules.sensitive.has("message") ? rules.censor : text;
1438
+ }
1439
+ var isStackKey = (key) => matchesKey(STACK_NAMES, key);
1440
+ var STACK_NAMES = capturedSet(["stack"]);
1441
+ var MESSAGE_NAMES = capturedSet(["message"]);
1442
+ var MAX_STACK_ALIASES = 8;
1443
+ var NO_STACK = { texts: /* @__PURE__ */ new Map(), stackKeys: capturedSet(), overflow: false };
1444
+ function headerMessage(rules, source, keys, isError2) {
1445
+ const keysOf = (names) => keys.filter((candidate) => matchesKey(names, candidate));
1446
+ const stacks = keysOf(STACK_NAMES);
1447
+ if (stacks.length === 0) return isError2 ? void 0 : NO_STACK;
1448
+ const hides = rules.sensitive.has("message") && (isError2 || rules.exemptKeys?.has("message") !== true && rules.headerKept !== true);
1449
+ const texts = /* @__PURE__ */ new Map();
1450
+ if (hides) {
1451
+ for (const key of keysOf(MESSAGE_NAMES)) {
1452
+ const text = Reflect.get(source, key);
1453
+ if (typeof text === "string") texts.set(key, text);
1454
+ }
1455
+ const named = keys.includes("message") ? void 0 : Reflect.get(source, "message");
1456
+ if (typeof named === "string") texts.set("message", named);
1457
+ }
1458
+ const overflow = stacks.length > MAX_STACK_ALIASES || capturedSet(texts.values()).size > MAX_STACK_ALIASES || [...texts.values()].some((text) => text.length > MAX_TEXT_LENGTH);
1459
+ return { texts, stackKeys: capturedSet(stacks), overflow };
1460
+ }
1461
+ function readField(source, key, header) {
1462
+ return header?.texts.get(key) ?? Reflect.get(source, key);
1463
+ }
1464
+ function censorAnyName(rules, name) {
1465
+ if (typeof name === "string") return censorName(name, messageCensor(rules));
1466
+ const holder = typeof name === "object" && name !== null || typeof name === "function";
1467
+ return holder && rules.sensitive.has("message") ? rules.censor : name;
1468
+ }
1469
+ function scrubPlainStack(rules, stack, header) {
1470
+ const texts = [...capturedSet(header?.texts.values())];
1471
+ const longest = texts.reduce((most, text) => Math.max(most, text.length), 0);
1472
+ const hidden = hideMessagesInStack(
1473
+ stack.slice(0, MAX_STACK_SCAN + longest),
1474
+ texts,
1475
+ rules.censor,
1476
+ MAX_STACK_SCAN
1477
+ );
1478
+ return scrubStack(hidden, void 0, stack.length > MAX_STACK_SCAN);
1479
+ }
1480
+ function errorTextField(rules, key, value, isError2, header) {
1481
+ const isStack = typeof value === "string" && (header === void 0 ? !isError2 && matchesKey(STACK_NAMES, key) : header.stackKeys.has(key));
1482
+ if (isStack) {
1483
+ return header?.overflow === true ? rules.censor : scrubPlainStack(rules, value, header);
1484
+ }
1485
+ if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
1486
+ const cut = cutIfText(value);
1487
+ return key === "name" ? censorAnyName(rules, cut) : cut;
1488
+ }
1489
+
1490
+ // src/server/utils/is-plain-record.util.ts
1491
+ function isPlainRecord(node) {
1492
+ try {
1493
+ const prototype = Object.getPrototypeOf(node);
1494
+ return prototype === Object.prototype || prototype === null;
1495
+ } catch {
1496
+ return false;
1497
+ }
1498
+ }
1499
+
1121
1500
  // src/server/services/pino-logger.service.ts
1122
1501
  var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
1123
1502
  var ENTRY_STRUCTURE_KEYS = ["level", "time", "msg", "service", "deployment"];
@@ -1128,17 +1507,17 @@ var RESOURCE_KEYS = [
1128
1507
  "service.instance.id",
1129
1508
  "deployment.environment.name"
1130
1509
  ];
1131
- var OWNED_KEY_SPELLINGS = new Set(
1510
+ var OWNED_KEY_SPELLINGS = capturedSet(
1132
1511
  [...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map((key) => foldKey(key))
1133
1512
  );
1134
- var DERIVED_KEYS = /* @__PURE__ */ new Set([
1513
+ var DERIVED_KEYS = capturedSet([
1135
1514
  "exception.type",
1136
1515
  "exception.message",
1137
1516
  "exception.stacktrace",
1138
1517
  "error.type"
1139
1518
  ]);
1140
1519
  var isOwnedKey = (key) => {
1141
- const lower = key.toLowerCase();
1520
+ const lower = lowerCase(key);
1142
1521
  return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(foldKey(key, true)) || lower.startsWith("service.") || lower.startsWith("deployment.");
1143
1522
  };
1144
1523
  function withoutOwnedKeys(metadata, omit) {
@@ -1177,12 +1556,27 @@ function objectMessageText(fields) {
1177
1556
  }
1178
1557
  return void 0;
1179
1558
  }
1180
- function hideStackMessage(payload, text, censor) {
1181
- const stack = Reflect.get(payload, "stack");
1182
- if (text?.key !== "message" || typeof stack !== "string") return;
1559
+ function hideStackMessage(payload, text, censor, positional) {
1560
+ const kept = positional === void 0 ? void 0 : cutText(positional);
1561
+ if (text?.key !== "message") return kept;
1183
1562
  const censored = censor(text.text);
1184
- if (censored === text.text) return;
1185
- Reflect.set(payload, "stack", hideMessageInStack(stack, text.text, censored));
1563
+ if (censored === text.text) return kept;
1564
+ const keys = Object.keys(payload).filter(isStackKey);
1565
+ const overflow = keys.length + (positional === void 0 ? 0 : 1) > MAX_STACK_ALIASES || text.text.length > MAX_TEXT_LENGTH;
1566
+ const hide = (stack) => overflow ? censored : cutText(
1567
+ hideMessagesInStack(
1568
+ stack.slice(0, MAX_TEXT_LENGTH + text.text.length),
1569
+ [text.text],
1570
+ censored,
1571
+ MAX_TEXT_LENGTH
1572
+ ),
1573
+ stack.length > MAX_TEXT_LENGTH
1574
+ );
1575
+ for (const key of keys) {
1576
+ const stack = Reflect.get(payload, key);
1577
+ if (typeof stack === "string") Reflect.set(payload, key, hide(stack));
1578
+ }
1579
+ return positional === void 0 ? void 0 : hide(positional);
1186
1580
  }
1187
1581
  function readObjectMessage(message) {
1188
1582
  const fields = isPlainRecord(message) && !isErrorLike(message) ? message : void 0;
@@ -1203,9 +1597,12 @@ function findErrorParam(optionalParams) {
1203
1597
  }
1204
1598
  function assignIfDefined(payload, key, value) {
1205
1599
  if (value !== void 0) {
1206
- Reflect.defineProperty(payload, key, { value, enumerable: true });
1600
+ Reflect.defineProperty(payload, key, bareDescriptor({ value, enumerable: true }));
1207
1601
  }
1208
1602
  }
1603
+ function emitRecord(pino2, level, payload, msg) {
1604
+ if (pinoBuiltinsIntact()) pino2[level](payload, msg);
1605
+ }
1209
1606
  exports.PinoLoggerService = class PinoLoggerService {
1210
1607
  /**
1211
1608
  * **A hand-built instance is NOT this library's behaviour.** Constructing
@@ -1260,17 +1657,27 @@ exports.PinoLoggerService = class PinoLoggerService {
1260
1657
  if (isErrorLike(message)) {
1261
1658
  const payload2 = { err: message };
1262
1659
  assignIfDefined(payload2, "context", this.resolveContext(optionalParams));
1263
- this.pino.error(payload2, this.errorText(message));
1660
+ emitRecord(this.pino, "error", payload2, this.errorText(message));
1264
1661
  return;
1265
1662
  }
1266
1663
  const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
1267
1664
  const context = typeof optionalParams[1] === "string" ? optionalParams[1] : this.context;
1268
1665
  const { fields, text, payload } = readObjectMessage(message);
1269
- hideStackMessage(payload, text, (message2) => this.censorText({ key: "message", text: message2 }));
1666
+ const positional = hideStackMessage(
1667
+ payload,
1668
+ text,
1669
+ (message2) => this.censorText({ key: "message", text: message2 }),
1670
+ stack
1671
+ );
1270
1672
  assignIfDefined(payload, "context", context);
1271
- assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
1673
+ assignIfDefined(payload, "stack", positional);
1272
1674
  assignIfDefined(payload, "err", findErrorParam(optionalParams));
1273
- this.pino.error(payload, this.nestStyleMessage("error", void 0, fields, text, message));
1675
+ emitRecord(
1676
+ this.pino,
1677
+ "error",
1678
+ payload,
1679
+ this.nestStyleMessage("error", void 0, fields, text, message)
1680
+ );
1274
1681
  }
1275
1682
  /**
1276
1683
  * NestJS `warn` (warn level).
@@ -1356,7 +1763,7 @@ exports.PinoLoggerService = class PinoLoggerService {
1356
1763
  };
1357
1764
  assignIfDefined(payload, "userId", userId);
1358
1765
  assignIfDefined(payload, "context", this.context);
1359
- this.pino.error(payload, this.errorText(error));
1766
+ emitRecord(this.pino, "error", payload, this.errorText(error));
1360
1767
  }
1361
1768
  // ─── Helpers / escape hatches ─────────────────────────────────────────────
1362
1769
  /**
@@ -1416,9 +1823,9 @@ exports.PinoLoggerService = class PinoLoggerService {
1416
1823
  assignIfDefined(payload, "context", this.context);
1417
1824
  const line = toBoundedMessage(message);
1418
1825
  if (level === "info") {
1419
- this.pino.info(payload, line);
1826
+ emitRecord(this.pino, "info", payload, line);
1420
1827
  } else {
1421
- this.pino.warn(payload, line);
1828
+ emitRecord(this.pino, "warn", payload, line);
1422
1829
  }
1423
1830
  }
1424
1831
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
@@ -1474,23 +1881,7 @@ exports.PinoLoggerService = class PinoLoggerService {
1474
1881
  const leading = isErrorLike(message) ? message : void 0;
1475
1882
  assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
1476
1883
  const msg = this.nestStyleMessage(level, leading, fields, text, message);
1477
- switch (level) {
1478
- case "info":
1479
- this.pino.info(payload, msg);
1480
- break;
1481
- case "warn":
1482
- this.pino.warn(payload, msg);
1483
- break;
1484
- case "debug":
1485
- this.pino.debug(payload, msg);
1486
- break;
1487
- case "trace":
1488
- this.pino.trace(payload, msg);
1489
- break;
1490
- case "fatal":
1491
- this.pino.fatal(payload, msg);
1492
- break;
1493
- }
1884
+ emitRecord(this.pino, level, payload, msg);
1494
1885
  }
1495
1886
  };
1496
1887
  exports.PinoLoggerService = __decorateClass([
@@ -1684,6 +2075,7 @@ var NANOID_REGEX = /\/[A-Za-z0-9_-]{21}(?![A-Za-z0-9_-])/g;
1684
2075
  var NUMERIC_ID_REGEX = /\/\d+/g;
1685
2076
  var ID_PLACEHOLDER = "/:id";
1686
2077
  var SECRET_PLACEHOLDER = ":redacted";
2078
+ var WHOLE_PATH_PLACEHOLDER = `/${SECRET_PLACEHOLDER}`;
1687
2079
  var HEX_SECRET_REGEX = /^[0-9a-f]{32,}$/i;
1688
2080
  var JWT_SECRET_REGEX = /^eyJ[\w-]*\.[\w-]+\.[\w-]*$/;
1689
2081
  var TOKEN_SECRET_REGEX = /^[A-Za-z0-9_+/-]{32,}={0,2}$/;
@@ -1708,13 +2100,13 @@ function hasTokenPart(segment) {
1708
2100
  }
1709
2101
  function withoutExtension(segment) {
1710
2102
  const dot = segment.lastIndexOf(".");
1711
- const dotAfterStart = dot > 0;
1712
- return dotAfterStart && segment.length - dot <= 9 ? segment.slice(0, dot) : segment;
2103
+ return segment.length - dot <= 9 ? segment.slice(0, dot) : segment;
1713
2104
  }
1714
2105
  function looksLikeToken(value) {
1715
2106
  return HEX_SECRET_REGEX.test(value) || HEX_RUN_REGEX.test(value) || JWT_SECRET_REGEX.test(value) || TOKEN_SECRET_REGEX.test(value) && !SLUG_REGEX.test(value) && !UUID_SEGMENT_REGEX.test(value);
1716
2107
  }
1717
2108
  function secretPathSegments(url, extra = []) {
2109
+ if (!pinoBuiltinsIntact()) return [url];
1718
2110
  const found = /* @__PURE__ */ new Set();
1719
2111
  for (const segment of stripQueryString(url).split("/")) {
1720
2112
  if (isSecretSegment(segment, extra)) found.add(segment);
@@ -1722,6 +2114,7 @@ function secretPathSegments(url, extra = []) {
1722
2114
  return [...found];
1723
2115
  }
1724
2116
  function scrubSecretSegments(path, extra = []) {
2117
+ if (!pinoBuiltinsIntact()) return WHOLE_PATH_PLACEHOLDER;
1725
2118
  return path.split("/").map((segment) => isSecretSegment(segment, extra) ? SECRET_PLACEHOLDER : segment).join("/");
1726
2119
  }
1727
2120
  function normalizeUrl(url, extra = []) {
@@ -1732,6 +2125,7 @@ function stripQueryString(url) {
1732
2125
  return queryStart === -1 ? url : url.slice(0, queryStart);
1733
2126
  }
1734
2127
  function withoutRequestSecrets(text, extra, ...urls) {
2128
+ if (!pinoBuiltinsIntact()) return SECRET_PLACEHOLDER;
1735
2129
  let result = text;
1736
2130
  const segments = /* @__PURE__ */ new Set();
1737
2131
  for (const url of urls) {
@@ -2231,13 +2625,128 @@ exports.LogContextService = class LogContextService {
2231
2625
  exports.LogContextService = __decorateClass([
2232
2626
  common.Injectable()
2233
2627
  ], exports.LogContextService);
2628
+ var IntrinsicPromise = Object.getPrototypeOf((async () => void 0)()).constructor;
2629
+ var hasOwn = Object.hasOwn;
2630
+ var isNativePromise = util.types.isPromise;
2631
+ var define = Object.defineProperty;
2632
+ var remove = Reflect.deleteProperty;
2633
+ var ownDescriptor = Reflect.getOwnPropertyDescriptor;
2634
+ var nativeThen = Function.prototype.call.bind(IntrinsicPromise.prototype.then);
2635
+ var promisePrototype = IntrinsicPromise.prototype;
2636
+ var speciesGetter = ownSpeciesGetter();
2637
+ var objectRoot = Object.prototype;
2638
+ var arrayRoot = Array.prototype;
2639
+ var functionRoot = Function.prototype;
2640
+ function ownSpeciesGetter() {
2641
+ const descriptor = ownDescriptor(IntrinsicPromise, Symbol.species);
2642
+ return descriptor !== void 0 && hasOwn(descriptor, "get") ? descriptor.get : void 0;
2643
+ }
2644
+ var PromiseTamperedError = class extends Error {
2645
+ constructor() {
2646
+ super(
2647
+ "the promise baseline does not hold: the constructor of the promise prototype was replaced, a then was planted on a prototype root, or the promise awaited carries its own constructor or then"
2648
+ );
2649
+ }
2650
+ };
2651
+ if (speciesGetter === void 0) throw new PromiseTamperedError();
2652
+ function promiseIntact() {
2653
+ const own = ownDescriptor(promisePrototype, "constructor");
2654
+ if (own === void 0 || !hasOwn(own, "value") || own.value !== IntrinsicPromise) return false;
2655
+ if (ownSpeciesGetter() !== speciesGetter) return false;
2656
+ return !hasOwn(objectRoot, "then") && !hasOwn(arrayRoot, "then") && !hasOwn(functionRoot, "then");
2657
+ }
2658
+ function intactOr(pending) {
2659
+ if (!promiseIntact()) throw new PromiseTamperedError();
2660
+ return pending;
2661
+ }
2662
+ function absorb(pending) {
2663
+ const drop = () => void 0;
2664
+ const pinned = pin(pending);
2665
+ try {
2666
+ try {
2667
+ nativeThen(pending, drop, drop);
2668
+ return;
2669
+ } catch {
2670
+ }
2671
+ void (async () => {
2672
+ try {
2673
+ await pending;
2674
+ } catch {
2675
+ }
2676
+ })();
2677
+ } finally {
2678
+ if (pinned) unpin(pending);
2679
+ }
2680
+ }
2681
+ function tag(promise) {
2682
+ setOwnConstructor(promise, false);
2683
+ return promise;
2684
+ }
2685
+ function setOwnConstructor(target, temporary) {
2686
+ try {
2687
+ define(target, "constructor", {
2688
+ __proto__: null,
2689
+ value: IntrinsicPromise,
2690
+ writable: temporary,
2691
+ configurable: temporary
2692
+ });
2693
+ return true;
2694
+ } catch {
2695
+ return false;
2696
+ }
2697
+ }
2698
+ function pin(target) {
2699
+ if (!isNativePromise(target) || hasOwn(target, "constructor")) return false;
2700
+ return setOwnConstructor(target, true);
2701
+ }
2702
+ function unpin(target) {
2703
+ try {
2704
+ remove(target, "constructor");
2705
+ } catch {
2706
+ }
2707
+ }
2708
+ function hold(value) {
2709
+ if (!isNativePromise(value)) return value;
2710
+ if (hasOwn(value, "constructor") || hasOwn(value, "then") || !setOwnConstructor(value, true)) {
2711
+ throw new PromiseTamperedError();
2712
+ }
2713
+ try {
2714
+ return (async () => {
2715
+ await value;
2716
+ })();
2717
+ } finally {
2718
+ unpin(value);
2719
+ }
2720
+ }
2721
+ function awaitOutcome(work, finish, held) {
2722
+ absorb(run(work, finish, held));
2723
+ }
2724
+ async function run(work, finish, held) {
2725
+ if (!promiseIntact()) {
2726
+ absorb(held);
2727
+ return finish({ __proto__: null, ok: false, cause: new PromiseTamperedError() });
2728
+ }
2729
+ let pending;
2730
+ try {
2731
+ pending = work();
2732
+ } catch (cause) {
2733
+ return finish({ __proto__: null, ok: false, cause });
2734
+ }
2735
+ try {
2736
+ await hold(intactOr(pending));
2737
+ } catch (cause) {
2738
+ if (cause instanceof PromiseTamperedError) absorb(pending);
2739
+ return finish({ __proto__: null, ok: false, cause });
2740
+ }
2741
+ finish({ __proto__: null, ok: true, cause: void 0 });
2742
+ }
2234
2743
 
2235
2744
  // src/server/middlewares/request-id.middleware.ts
2236
2745
  var REQUEST_ID_HEADER = "x-request-id";
2237
2746
  var MAX_CORRELATION_ID_LENGTH = 256;
2238
2747
  var CORRELATION_ID_CHARSET = /^[A-Za-z0-9._:/+=-]+$/;
2239
2748
  function settleLate(answer) {
2240
- Promise.resolve(answer).catch(() => void 0);
2749
+ absorb(answer);
2241
2750
  }
2242
2751
  var INHERITABLE_CONTEXT_KEYS = ["requestId", "tenantId"];
2243
2752
  function isAcceptableHeaderValue(value) {
@@ -2667,9 +3176,7 @@ function createTraceContextMixin(logContext, opts) {
2667
3176
  return function mixin(_mergeObject, _level, _logger) {
2668
3177
  const merged = {};
2669
3178
  const store = logContext.getStore();
2670
- if (store) {
2671
- Object.assign(merged, store);
2672
- }
3179
+ Object.assign(merged, store);
2673
3180
  if (traceApi) {
2674
3181
  try {
2675
3182
  const span = traceApi.getActiveSpan();
@@ -2695,7 +3202,7 @@ function createTraceContextMixin(logContext, opts) {
2695
3202
  // src/server/utils/compile-redact-paths.util.ts
2696
3203
  function compileRedactPaths(extraPaths, shouldSkipDefaults) {
2697
3204
  const sources = shouldSkipDefaults ? [extraPaths] : [DEFAULT_REDACT_PATHS, extraPaths];
2698
- return Array.from(new Set(sources.flat()));
3205
+ return Array.from(capturedSet(sources.flat()));
2699
3206
  }
2700
3207
 
2701
3208
  // src/server/utils/cut-strings.util.ts
@@ -2744,8 +3251,7 @@ function rescueToStdout(payload) {
2744
3251
  function ownQueuedBytes(destination) {
2745
3252
  try {
2746
3253
  const bytes = destination.queuedBytes?.() ?? 0;
2747
- const positive = Number.isFinite(bytes) && bytes > 0;
2748
- return positive ? bytes : 0;
3254
+ return Number.isFinite(bytes) ? Math.max(0, bytes) : 0;
2749
3255
  } catch {
2750
3256
  return 0;
2751
3257
  }
@@ -2817,7 +3323,6 @@ function destinationToStream(destination, health, maxQueueBytes = 0, censorMessa
2817
3323
  // Keep string chunks as strings (Node's default re-encodes them to Buffers
2818
3324
  // before `_write`): the common Pino path emits NDJSON strings, so this skips
2819
3325
  // a string→Buffer→string round-trip on the hot logging path.
2820
- // Stryker disable next-line BooleanLiteral: equivalent for every chunk this stream receives — with `true`, Node encodes the string to a Buffer and `write()` below decodes it back with `toString('utf-8')`. Pino writes UTF-8 NDJSON strings at the default encoding, so the round-trip returns the identical string. It is NOT equivalent in general: a `write(chunk, 'latin1')` would round-trip through UTF-8 and change non-ASCII bytes, which is unreachable here because nothing writes to this stream but Pino. The flag stays because it skips the round-trip on the hot logging path.
2821
3326
  decodeStrings: false,
2822
3327
  write(chunk, _encoding, settled) {
2823
3328
  const bytes = Buffer.byteLength(chunk);
@@ -2843,15 +3348,14 @@ function destinationToStream(destination, health, maxQueueBytes = 0, censorMessa
2843
3348
  callback();
2844
3349
  } else {
2845
3350
  health.markWritePending(destination);
2846
- Promise.resolve(result).then(
2847
- () => {
3351
+ awaitOutcome(
3352
+ () => result,
3353
+ (outcome) => {
2848
3354
  health.markWriteSettled(destination);
2849
- callback();
3355
+ if (outcome.ok) callback();
3356
+ else onFailure(outcome.cause);
2850
3357
  },
2851
- (cause) => {
2852
- health.markWriteSettled(destination);
2853
- onFailure(cause);
2854
- }
3358
+ result
2855
3359
  );
2856
3360
  }
2857
3361
  } catch (cause) {
@@ -2870,11 +3374,11 @@ function mergeMixinSafely(mergeObject, mixinObject) {
2870
3374
  const merged = {};
2871
3375
  const written = /* @__PURE__ */ new Set();
2872
3376
  for (const [key, value] of Object.entries(mixinObject)) {
2873
- if (value !== void 0) written.add(foldKey(key));
3377
+ if (value !== void 0) setAdd(written, foldKey(key));
2874
3378
  }
2875
3379
  for (const key of Object.keys(mergeObject)) {
2876
3380
  if (key === PROTOTYPE_KEY) continue;
2877
- if (key !== EXPLICIT_USER_KEY && written.has(foldKey(key))) continue;
3381
+ if (key !== EXPLICIT_USER_KEY && setHas(written, foldKey(key))) continue;
2878
3382
  Reflect.set(merged, key, Reflect.get(mergeObject, key));
2879
3383
  }
2880
3384
  for (const [key, value] of Object.entries(mixinObject)) {
@@ -2900,225 +3404,79 @@ function censorRawHeaders(raw, sensitive, censor) {
2900
3404
  });
2901
3405
  }
2902
3406
 
2903
- // src/server/utils/redact-error-parts.util.ts
2904
- function defineOwn(target, key, value) {
2905
- Reflect.defineProperty(target, key, { value, enumerable: true, writable: true });
2906
- }
2907
- var linkDepths = /* @__PURE__ */ new WeakMap();
2908
- var ERROR_TEXT_FIELDS = /* @__PURE__ */ new Set(["name", "message", "stack"]);
2909
- var INCOMPLETE_KEY = "_errorFieldsIncomplete";
2910
- var widthMarkers = /* @__PURE__ */ new WeakSet();
2911
- function capErrors(errors, host) {
2912
- if (!Array.isArray(errors) || errors.length <= MAX_AGGREGATE_ERRORS) return errors;
2913
- if (host.hasToJson(errors)) return errors;
2914
- const kept = [];
2915
- for (let index = 0; index < MAX_AGGREGATE_ERRORS; index++) kept.push(Reflect.get(errors, index));
2916
- const marker = createWidthMarker(errors.length - MAX_AGGREGATE_ERRORS);
2917
- widthMarkers.add(marker);
2918
- kept.push(marker);
2919
- return kept;
2920
- }
2921
- function linkTargets(value) {
2922
- const targets = [];
2923
- const take = (link) => {
2924
- if (typeof link === "object" && link !== null) targets.push(link);
2925
- };
2926
- if (!Array.isArray(value)) take(value);
2927
- else for (let index = 0; index < value.length; index++) take(Reflect.get(value, index));
2928
- return targets;
2929
- }
2930
- function walkChainPart(value, level, host, depth2) {
2931
- const targets = linkTargets(value);
2932
- if (targets.length > 0 && level + 1 > DEFAULT_MAX_CAUSE_DEPTH) {
2933
- if (Array.isArray(value) && host.nameKey === "name") {
2934
- return Array.from({ length: value.length }, (_member, index) => {
2935
- const member = Reflect.get(value, index);
2936
- return typeof member === "object" && member !== null && widthMarkers.has(member) ? member : createDepthMarker();
2937
- });
2938
- }
2939
- return createDepthMarker();
2940
- }
2941
- const before = new Map(targets.map((target) => [target, linkDepths.get(target)]));
2942
- for (const target of targets) linkDepths.set(target, level + 1);
2943
- try {
2944
- return host.walk(value, depth2 + 1);
2945
- } finally {
2946
- before.forEach((earlier, target) => {
2947
- if (earlier === void 0) linkDepths.delete(target);
2948
- else linkDepths.set(target, earlier);
2949
- });
2950
- }
2951
- }
2952
- function cutOrWalk(value, level, host, depth2) {
2953
- return typeof value === "string" ? cutText(value) : walkChainPart(value, level, host, depth2);
2954
- }
2955
- function writeName(value, level, host, depth2) {
2956
- const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
2957
- return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
2958
- }
2959
- function addErrorParts(copy, error, ownKeys, host, depth2) {
2960
- const taken = new Set(ownKeys);
2961
- const level = linkDepths.get(error) ?? 0;
2962
- let incomplete = false;
2963
- const add = (key, covers, read, write = (value) => walkChainPart(value, level, host, depth2)) => {
2964
- if (taken.has(key)) return;
2965
- try {
2966
- const written = write(read());
2967
- if (written === void 0) return;
2968
- const covered = covers.some((name) => host.sensitive.has(name));
2969
- defineOwn(copy, key, covered ? host.censor : written);
2970
- } catch {
2971
- incomplete = true;
2972
- }
2973
- };
2974
- add(
2975
- host.nameKey,
2976
- [host.nameKey, "name"],
2977
- () => error.name,
2978
- (name) => writeName(name, level, host, depth2)
2979
- );
2980
- add(
2981
- "message",
2982
- ["message"],
2983
- () => error.message,
2984
- (message) => cutOrWalk(message, level, host, depth2)
2985
- );
2986
- add(
2987
- "stack",
2988
- ["stack", "name", "message"],
2989
- () => error.stack,
2990
- (stack) => typeof stack === "string" ? scrubStack(stack) : void 0
2991
- );
2992
- add("cause", ["cause"], () => error.cause);
2993
- add("errors", ["errors"], () => capErrors(error.errors, host));
2994
- if (incomplete && !taken.has(INCOMPLETE_KEY)) defineOwn(copy, INCOMPLETE_KEY, true);
2995
- }
2996
-
2997
- // src/server/utils/error-text-exemption.util.ts
2998
- var ERROR_TEXT_KEYS = /* @__PURE__ */ new Set(["message"]);
2999
- function leavesErrorText(rules, key, value, honorToJson) {
3000
- return rules.errorTextToSerializer && !honorToJson && key === "err" && !Array.isArray(value);
3001
- }
3002
- function rulesBelow(rules, key, value, honorToJson) {
3003
- if (leavesErrorText(rules, key, value, honorToJson)) {
3004
- return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
3005
- }
3006
- return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
3007
- }
3008
- function isCensored(rules, key, value) {
3009
- return matchesKey(rules.sensitive, key) && !(typeof value === "string" && rules.exemptKeys?.has(key));
3010
- }
3011
- function messageCensor(rules) {
3012
- return (text) => rules.sensitive.has("message") ? rules.censor : text;
3013
- }
3014
- var STACK_NAMES = /* @__PURE__ */ new Set(["stack"]);
3015
- var MESSAGE_NAMES = /* @__PURE__ */ new Set(["message"]);
3016
- var MAX_STACK_ALIASES = 8;
3017
- var NO_STACK = { texts: /* @__PURE__ */ new Map(), stackKeys: /* @__PURE__ */ new Set(), overflow: false };
3018
- function headerMessage(rules, source, keys, isError2) {
3019
- if (isError2) return void 0;
3020
- const keysOf = (names) => keys.filter((candidate) => matchesKey(names, candidate));
3021
- const stacks = keysOf(STACK_NAMES);
3022
- if (stacks.length === 0) return NO_STACK;
3023
- const hides = rules.sensitive.has("message") && rules.exemptKeys?.has("message") !== true && rules.headerKept !== true;
3024
- const texts = /* @__PURE__ */ new Map();
3025
- if (hides) {
3026
- for (const key of keysOf(MESSAGE_NAMES)) {
3027
- const text = Reflect.get(source, key);
3028
- if (typeof text === "string") texts.set(key, text);
3029
- }
3030
- const named = keys.includes("message") ? void 0 : Reflect.get(source, "message");
3031
- if (typeof named === "string") texts.set("message", named);
3032
- }
3033
- const overflow = stacks.length > MAX_STACK_ALIASES || new Set(texts.values()).size > MAX_STACK_ALIASES;
3034
- return { texts, stackKeys: new Set(stacks), overflow };
3035
- }
3036
- function readField(source, key, header) {
3037
- return header?.texts.get(key) ?? Reflect.get(source, key);
3038
- }
3039
- function censorAnyName(rules, name) {
3040
- if (typeof name === "string") return censorName(name, messageCensor(rules));
3041
- const holder = typeof name === "object" && name !== null || typeof name === "function";
3042
- return holder && rules.sensitive.has("message") ? rules.censor : name;
3043
- }
3044
- function scrubPlainStack(rules, stack, header) {
3045
- const texts = [...new Set(header?.texts.values())];
3046
- const longest = texts.reduce((most, text) => Math.max(most, text.length), 0);
3047
- const hidden = hideMessagesInStack(
3048
- // Stryker disable next-line MethodExpression: equivalent in output: an occurrence that starts before the bound ends inside the window, and one that starts after it is not read, so a longer text gives the same result; the slice only bounds the search.
3049
- stack.slice(0, MAX_STACK_SCAN + longest),
3050
- texts,
3051
- rules.censor,
3052
- MAX_STACK_SCAN
3053
- );
3054
- return scrubStack(hidden, void 0, stack.length > MAX_STACK_SCAN);
3055
- }
3056
- function errorTextField(rules, key, value, isError2, header) {
3057
- const isStack = !isError2 && typeof value === "string" && (header === void 0 ? matchesKey(STACK_NAMES, key) : header.stackKeys.has(key));
3058
- if (isStack) {
3059
- return header?.overflow === true ? rules.censor : scrubPlainStack(rules, value, header);
3060
- }
3061
- if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
3062
- const cut = cutIfText(value);
3063
- return key === "name" ? censorAnyName(rules, cut) : cut;
3064
- }
3065
-
3066
3407
  // src/server/utils/redact-error-clone.util.ts
3067
3408
  function shadowHook(target) {
3068
- Reflect.defineProperty(target, "toJSON", { value: void 0, configurable: true });
3409
+ Reflect.defineProperty(target, "toJSON", bareDescriptor({ value: void 0, configurable: true }));
3069
3410
  }
3070
3411
  function withoutEnumerableKeys(clone) {
3071
3412
  for (const key of Object.keys(clone)) Reflect.deleteProperty(clone, key);
3072
3413
  }
3073
3414
  function discardWrite() {
3074
3415
  }
3075
- function cloneError(error) {
3076
- const descriptors = Object.getOwnPropertyDescriptors(error);
3077
- for (const descriptor of Object.values(descriptors)) {
3416
+ function relaxedDescriptors(descriptors) {
3417
+ const relaxed = /* @__PURE__ */ Object.create(null);
3418
+ for (const key of Reflect.ownKeys(descriptors)) {
3419
+ const descriptor = bareDescriptor(Reflect.get(descriptors, key));
3078
3420
  descriptor.configurable = true;
3079
- if ("value" in descriptor) descriptor.writable = true;
3421
+ if (Object.hasOwn(descriptor, "value")) descriptor.writable = true;
3080
3422
  else descriptor.set ??= discardWrite;
3423
+ Reflect.set(relaxed, key, descriptor);
3081
3424
  }
3082
- const clone = Object.create(Object.getPrototypeOf(error), descriptors);
3425
+ return relaxed;
3426
+ }
3427
+ function cloneError(error) {
3428
+ const clone = Object.create(
3429
+ Object.getPrototypeOf(error),
3430
+ relaxedDescriptors(Object.getOwnPropertyDescriptors(error))
3431
+ );
3083
3432
  const { stack } = error;
3084
3433
  if (typeof stack === "string") {
3085
- Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false, writable: true });
3434
+ Reflect.defineProperty(
3435
+ clone,
3436
+ "stack",
3437
+ bareDescriptor({ value: stack, enumerable: false, writable: true })
3438
+ );
3086
3439
  }
3087
3440
  withoutEnumerableKeys(clone);
3088
3441
  shadowHook(clone);
3089
3442
  return clone;
3090
3443
  }
3091
-
3092
- // src/server/utils/redact-by-name.util.ts
3093
- var RAW_HEADER_KEYS = /* @__PURE__ */ new Set(["rawheaders", "rawtrailers"]);
3094
- function censorHeaderArray(key, walked, rules) {
3095
- return matchesKey(RAW_HEADER_KEYS, key) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
3096
- }
3097
- var REDACT_MAX_TRAVERSAL_DEPTH = 100;
3098
- var REDACT_DEPTH_EXCEEDED = "[REDACTION_DEPTH_EXCEEDED]";
3099
- var REDACT_MAX_VISITS = 2e5;
3100
- var REDACT_BUDGET_EXCEEDED = "[REDACTION_BUDGET_EXCEEDED]";
3101
- var REDACT_CIRCULAR = "[Circular]";
3444
+ var MAX_PROTOTYPE_HOPS2 = 256;
3102
3445
  function resolveToJson(value, viaGet = false) {
3103
3446
  let candidate = viaGet ? Reflect.get(value, "toJSON") : void 0;
3104
3447
  let accessor = false;
3105
3448
  let proxied = false;
3106
3449
  let current = viaGet ? null : value;
3107
- while (current !== null) {
3450
+ for (let hops = 0; current !== null; hops++) {
3451
+ if (hops > MAX_PROTOTYPE_HOPS2) return { method: void 0, volatile: true, hostile: true };
3108
3452
  proxied = proxied || util.types.isProxy(current);
3109
3453
  const descriptor = Object.getOwnPropertyDescriptor(current, "toJSON");
3110
3454
  if (descriptor !== void 0) {
3111
- accessor = descriptor.get !== void 0;
3112
- candidate = descriptor.get === void 0 ? descriptor.value : descriptor.get.call(value);
3455
+ const getter = Object.hasOwn(descriptor, "get") ? descriptor.get : void 0;
3456
+ accessor = getter !== void 0;
3457
+ if (getter !== void 0) candidate = getter.call(value);
3458
+ else if (Object.hasOwn(descriptor, "value")) candidate = descriptor.value;
3113
3459
  break;
3114
3460
  }
3115
- current = Object.getPrototypeOf(current);
3461
+ const next = Object.getPrototypeOf(current);
3462
+ current = typeof next === "object" ? next : null;
3116
3463
  }
3117
3464
  return {
3118
3465
  method: typeof candidate === "function" ? candidate : void 0,
3119
3466
  volatile: accessor || proxied
3120
3467
  };
3121
3468
  }
3469
+
3470
+ // src/server/utils/redact-by-name.util.ts
3471
+ var RAW_HEADER_KEYS = capturedSet(["rawheaders", "rawtrailers"]);
3472
+ function censorHeaderArray(key, walked, rules) {
3473
+ return matchesKey(RAW_HEADER_KEYS, key) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
3474
+ }
3475
+ var REDACT_MAX_TRAVERSAL_DEPTH = 100;
3476
+ var REDACT_DEPTH_EXCEEDED = "[REDACTION_DEPTH_EXCEEDED]";
3477
+ var REDACT_MAX_VISITS = 2e5;
3478
+ var REDACT_BUDGET_EXCEEDED = "[REDACTION_BUDGET_EXCEEDED]";
3479
+ var REDACT_CIRCULAR = "[Circular]";
3122
3480
  function rulesInside(rules, names, visits) {
3123
3481
  return names === void 0 ? void 0 : { ...rules, sensitive: names, visits, insideErrors: void 0 };
3124
3482
  }
@@ -3155,7 +3513,7 @@ function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false
3155
3513
  if (++rules.visits.count > rules.maxVisits) {
3156
3514
  return REDACT_BUDGET_EXCEEDED;
3157
3515
  }
3158
- if (ancestors.has(value)) {
3516
+ if (setHas(ancestors, value)) {
3159
3517
  return REDACT_CIRCULAR;
3160
3518
  }
3161
3519
  if (isError(value)) {
@@ -3183,7 +3541,8 @@ function walkObject(value, rules, depth2, ancestors, honorToJson, inSerialized)
3183
3541
  return withBinaryAsSize(value);
3184
3542
  }
3185
3543
  const resolved = resolveToJson(value, rules.ownFields.safe);
3186
- ancestors.add(value);
3544
+ if (resolved.hostile) return rules.censor;
3545
+ setAdd(ancestors, value);
3187
3546
  try {
3188
3547
  return walkForm(value, resolved, rules, depth2, ancestors, honorToJson, inSerialized);
3189
3548
  } finally {
@@ -3223,7 +3582,7 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
3223
3582
  const current = scrubbed ? ownFieldForLog(source, key, read, rules.ownFields) : read;
3224
3583
  const hook = honorToJson && key === "toJSON" && typeof current === "function";
3225
3584
  if (current === OMIT_OWN_FIELD || hook) {
3226
- omitted.add(key);
3585
+ setAdd(omitted, key);
3227
3586
  continue;
3228
3587
  }
3229
3588
  Reflect.deleteProperty(copy, key);
@@ -3251,7 +3610,7 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
3251
3610
  return copy;
3252
3611
  }
3253
3612
  function without(keys, omitted) {
3254
- return keys.filter((key) => !omitted.has(key));
3613
+ return keys.filter((key) => !setHas(omitted, key));
3255
3614
  }
3256
3615
  function startCopy(value, asData) {
3257
3616
  const clone = isError(value) ? cloneError(value) : void 0;
@@ -3276,7 +3635,7 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3276
3635
  sensitive: foldedNames(fieldNames),
3277
3636
  headerNames: foldedNames(headerNames ?? fieldNames),
3278
3637
  censor,
3279
- serializedKeys: new Set(serializedKeys),
3638
+ serializedKeys: capturedSet(serializedKeys),
3280
3639
  errorsAsData: serializedKeys !== void 0,
3281
3640
  errorTextToSerializer,
3282
3641
  maxVisits,
@@ -3286,13 +3645,13 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3286
3645
  return (value, isRecordRoot = false) => {
3287
3646
  try {
3288
3647
  const visits = { count: 0 };
3289
- const call = {
3648
+ const call2 = {
3290
3649
  ...rules,
3291
3650
  headerKept: typeof value === "object" && value !== null && errorOutputs.has(value),
3292
3651
  visits,
3293
3652
  insideErrors: rulesInside(rules, insideNames, visits)
3294
3653
  };
3295
- return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
3654
+ return walk(value, call2, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
3296
3655
  } catch {
3297
3656
  return {
3298
3657
  _redactionFailed: true,
@@ -3329,7 +3688,11 @@ function parseResourceAttributes(raw) {
3329
3688
  } catch {
3330
3689
  value = rawValue;
3331
3690
  }
3332
- Object.defineProperty(parsed, key, { value, enumerable: true, configurable: true });
3691
+ Object.defineProperty(
3692
+ parsed,
3693
+ key,
3694
+ bareDescriptor({ value, enumerable: true, configurable: true })
3695
+ );
3333
3696
  }
3334
3697
  return parsed;
3335
3698
  }
@@ -3406,7 +3769,7 @@ function buildResourceBindings(resolved, format, extras = {}) {
3406
3769
  }
3407
3770
  return bindings;
3408
3771
  }
3409
- var OWNED_SERVICE_KEYS = /* @__PURE__ */ new Set([
3772
+ var OWNED_SERVICE_KEYS = capturedSet([
3410
3773
  "name",
3411
3774
  "version",
3412
3775
  "namespace",
@@ -3467,16 +3830,16 @@ function withSemconvException(record, format, maxBytes = Number.POSITIVE_INFINIT
3467
3830
  }
3468
3831
 
3469
3832
  // src/server/utils/serialize-request.util.ts
3470
- function isObject2(value) {
3833
+ function isObject(value) {
3471
3834
  return typeof value === "object" && value !== null;
3472
3835
  }
3473
3836
  function isRequest(value) {
3474
- if (!isObject2(value)) return false;
3837
+ if (!isObject(value)) return false;
3475
3838
  const { rawHeaders, method, socket } = value;
3476
- return Array.isArray(rawHeaders) || typeof method === "string" && isObject2(socket);
3839
+ return Array.isArray(rawHeaders) || typeof method === "string" && isObject(socket);
3477
3840
  }
3478
3841
  function copyHeaders(headers) {
3479
- return isObject2(headers) ? { ...headers } : {};
3842
+ return isObject(headers) ? { ...headers } : {};
3480
3843
  }
3481
3844
  function serializeRequestValue(input, secretSegments = []) {
3482
3845
  try {
@@ -3553,9 +3916,9 @@ var PATH_SEGMENT = /\[\s*['"]([^'"]+)['"]\s*\]|([^.[\]]+)/g;
3553
3916
  var INDEX_SEGMENT = /^\d+$/;
3554
3917
  function leafNameOf(path) {
3555
3918
  let leaf;
3556
- for (const match of path.matchAll(PATH_SEGMENT)) {
3919
+ for (const match of allMatches(PATH_SEGMENT, path)) {
3557
3920
  const quoted = match[1];
3558
- const name = quoted ?? (match[2] !== void 0 && INDEX_SEGMENT.test(match[2]) ? void 0 : match[2]);
3921
+ const name = quoted ?? (match[2] !== void 0 && matchesPattern(INDEX_SEGMENT, match[2]) ? void 0 : match[2]);
3559
3922
  if (name !== void 0 && name !== "*") {
3560
3923
  leaf = name;
3561
3924
  }
@@ -3582,7 +3945,7 @@ function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS, censorMessage)
3582
3945
  return serialized;
3583
3946
  }
3584
3947
  function toEventName(logKey) {
3585
- return logKey.toLowerCase().replaceAll("_", ".");
3948
+ return replaceAllText(lowerCase(logKey), "_", ".");
3586
3949
  }
3587
3950
  function withEventName(record, field) {
3588
3951
  if (field === false) {
@@ -3607,7 +3970,7 @@ function resolveRecordRedactor(options) {
3607
3970
  );
3608
3971
  }
3609
3972
  function wholeRootKeys(options) {
3610
- return /* @__PURE__ */ new Set(["logKey", "err", ...Object.keys(options.serializers)]);
3973
+ return capturedSet(["logKey", "err", ...Object.keys(options.serializers)]);
3611
3974
  }
3612
3975
  function ownFieldPolicyOf(options) {
3613
3976
  return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
@@ -3646,7 +4009,7 @@ function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = tr
3646
4009
  );
3647
4010
  }
3648
4011
  function resolveRedactOption(options) {
3649
- const paths = options.redactStrategy === "paths" ? compileRedactPaths(options.redactPaths, options.shouldDisableDefaultRedact) : [...new Set(options.redactPaths)];
4012
+ const paths = options.redactStrategy === "paths" ? compileRedactPaths(options.redactPaths, options.shouldDisableDefaultRedact) : [...capturedSet(options.redactPaths)];
3650
4013
  if (paths.length === 0) {
3651
4014
  return void 0;
3652
4015
  }
@@ -3689,6 +4052,10 @@ function buildTraceMixin(logContext, options) {
3689
4052
  censorMessage: buildMessageCensor(options)
3690
4053
  });
3691
4054
  }
4055
+ var UNSET_ENTRY_NAMES = {
4056
+ levelVal: void 0,
4057
+ write: void 0
4058
+ };
3692
4059
  function buildStreams(options, destinations, health) {
3693
4060
  const censorMessage = buildMessageCensor(options);
3694
4061
  return destinations.map((destination) => {
@@ -3700,6 +4067,7 @@ function buildStreams(options, destinations, health) {
3700
4067
  );
3701
4068
  health.registerStream(destination, stream);
3702
4069
  return {
4070
+ ...UNSET_ENTRY_NAMES,
3703
4071
  // Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
3704
4072
  // consumer implementing `minLevel` as a throwing getter would fail the factory
3705
4073
  // and the application would never start — earlier than any fail-soft path can
@@ -3756,10 +4124,24 @@ function buildFormatters(options, redactRecord, redactBindings, onTruncate) {
3756
4124
  log: buildRecordFormatter(options, redactRecord, onTruncate)
3757
4125
  };
3758
4126
  }
3759
- function buildPinoInstance(options, logContext, destinations, health) {
4127
+ var UNSET_PINO_NAMES = {
4128
+ transport: void 0,
4129
+ crlf: false,
4130
+ msgPrefix: void 0,
4131
+ name: void 0,
4132
+ writable: false,
4133
+ _writableState: void 0,
4134
+ prettyPrint: void 0,
4135
+ onChild: void 0
4136
+ };
4137
+ function refuseUnsafeOptions(options) {
4138
+ if (!pinoBuiltinsIntact()) throw new Error("LOGGER_BUILTINS_REPLACED");
3760
4139
  if (options.maxStringLength !== void 0) {
3761
4140
  refuseCensorBeyondLimit(options.redactCensor, options.maxStringLength);
3762
4141
  }
4142
+ }
4143
+ function buildPinoInstance(options, logContext, destinations, health) {
4144
+ refuseUnsafeOptions(options);
3763
4145
  const redactRecord = resolveRecordRedactor(options);
3764
4146
  const redactSerialized = buildNameRedactor(options);
3765
4147
  const ownFields = ownFieldPolicyOf(options);
@@ -3767,10 +4149,10 @@ function buildPinoInstance(options, logContext, destinations, health) {
3767
4149
  const onTruncate = (reason) => health.recordTruncation(reason);
3768
4150
  const pinoOptions = {
3769
4151
  level: options.level,
3770
- ...redactOption === void 0 ? {} : { redact: redactOption },
3771
- // Resource identity, resolved ONCE here rather than per entry: Pino
3772
- // pre-serializes `base` into the instance's chindings, so the cost of the
3773
- // extra attributes is one string built at construction, not work per log.
4152
+ ...redactOption === void 0 ? {} : { redact: { ...redactOption, remove: false } },
4153
+ ...UNSET_PINO_NAMES,
4154
+ // Resource identity, resolved ONCE here rather than per entry: Pino pre-serializes `base` into
4155
+ // the instance's chindings, so the extra attributes cost one string at construction.
3774
4156
  base: buildResourceBindings(
3775
4157
  resolveServiceMetadata(options.service),
3776
4158
  options.resourceFormat,
@@ -3809,7 +4191,7 @@ var DestinationHealth = class {
3809
4191
  this.entrySizeTruncations = 0;
3810
4192
  this.stringLengthTruncations = 0;
3811
4193
  /** Destinations whose `onInit()` rejected. Identity-keyed, not name-keyed. */
3812
- this.failed = /* @__PURE__ */ new Set();
4194
+ this.failed = capturedSet();
3813
4195
  /**
3814
4196
  * Destinations that initialized, each with its effective level as an index into
3815
4197
  * {@link LOG_LEVEL_PRIORITY}.
@@ -3835,7 +4217,7 @@ var DestinationHealth = class {
3835
4217
  * for the whole window — coarser than per-entry tracking, and wrong only in the
3836
4218
  * direction that duplicates rather than loses.
3837
4219
  */
3838
- this.writeFailed = /* @__PURE__ */ new Set();
4220
+ this.writeFailed = capturedSet();
3839
4221
  /**
3840
4222
  * In-flight asynchronous writes per destination.
3841
4223
  *
@@ -4091,20 +4473,21 @@ var HookTimeoutError = class extends Error {
4091
4473
  }
4092
4474
  };
4093
4475
  function withTimeout(work, ms) {
4094
- return new Promise((resolve, reject2) => {
4476
+ const wait = new IntrinsicPromise((resolve, reject2) => {
4095
4477
  const timer = setTimeout(() => {
4096
4478
  reject2(new HookTimeoutError(ms));
4097
4479
  }, ms);
4098
- const settle = (done) => (...args) => {
4099
- clearTimeout(timer);
4100
- done(...args);
4101
- };
4102
- try {
4103
- Promise.resolve(work()).then(settle(resolve), settle(reject2));
4104
- } catch (cause) {
4105
- settle(reject2)(cause);
4106
- }
4480
+ awaitOutcome(work, (outcome) => {
4481
+ if (outcome.ok) resolve();
4482
+ else reject2(outcome.cause);
4483
+ try {
4484
+ clearTimeout(timer);
4485
+ } catch {
4486
+ }
4487
+ });
4107
4488
  });
4489
+ absorb(wait);
4490
+ return tag(wait);
4108
4491
  }
4109
4492
 
4110
4493
  // src/server/services/destination-registry.service.ts
@@ -4154,7 +4537,9 @@ var DestinationRegistry = class {
4154
4537
  async onModuleInit() {
4155
4538
  for (const destination of this.registered) {
4156
4539
  try {
4157
- await withTimeout(() => destination.onInit?.(), this.options.destinationHookTimeoutMs);
4540
+ await intactOr(
4541
+ withTimeout(() => destination.onInit?.(), this.options.destinationHookTimeoutMs)
4542
+ );
4158
4543
  this.active.push(destination);
4159
4544
  this.health.markHealthy(destination, this.effectiveLevelOf(destination));
4160
4545
  } catch (cause) {
@@ -4186,14 +4571,16 @@ var DestinationRegistry = class {
4186
4571
  async notifyRegistryReady() {
4187
4572
  for (const destination of this.registered) {
4188
4573
  try {
4189
- await withTimeout(
4190
- () => destination.onRegistryReady?.({
4191
- heldEntriesDeliveredElsewhere: this.health.deliveredByHealthySink(
4192
- destination,
4193
- this.effectiveLevelOf(destination)
4194
- )
4195
- }),
4196
- this.options.destinationHookTimeoutMs
4574
+ await intactOr(
4575
+ withTimeout(
4576
+ () => destination.onRegistryReady?.({
4577
+ heldEntriesDeliveredElsewhere: this.health.deliveredByHealthySink(
4578
+ destination,
4579
+ this.effectiveLevelOf(destination)
4580
+ )
4581
+ }),
4582
+ this.options.destinationHookTimeoutMs
4583
+ )
4197
4584
  );
4198
4585
  } catch (cause) {
4199
4586
  this.reportHookFailure(destination, cause);
@@ -4221,7 +4608,9 @@ var DestinationRegistry = class {
4221
4608
  if (configured === void 0) {
4222
4609
  return this.options.level;
4223
4610
  }
4224
- return LOG_LEVEL_PRIORITY.indexOf(configured) > LOG_LEVEL_PRIORITY.indexOf(this.options.level) ? configured : this.options.level;
4611
+ return LOG_LEVEL_PRIORITY.slice(LOG_LEVEL_PRIORITY.indexOf(this.options.level)).includes(
4612
+ configured
4613
+ ) ? configured : this.options.level;
4225
4614
  }
4226
4615
  /**
4227
4616
  * Report one destination init failure as a structured
@@ -4335,7 +4724,7 @@ var DestinationRegistry = class {
4335
4724
  continue;
4336
4725
  }
4337
4726
  try {
4338
- await withTimeout(() => destination.onShutdown?.(), remaining);
4727
+ await intactOr(withTimeout(() => destination.onShutdown?.(), remaining));
4339
4728
  } catch (cause) {
4340
4729
  this.reportShutdownFailure(destination, cause);
4341
4730
  }
@@ -4714,7 +5103,7 @@ function productionRefusal() {
4714
5103
  );
4715
5104
  }
4716
5105
  async function buildTransform(view) {
4717
- const { build } = await import('pino-pretty');
5106
+ const { build } = await tag(import('pino-pretty'));
4718
5107
  return build({
4719
5108
  ...DEFAULT_VIEW,
4720
5109
  ...view,
@@ -4791,7 +5180,7 @@ var PrettyDevDestination = class {
4791
5180
  throw productionRefusal();
4792
5181
  }
4793
5182
  try {
4794
- this.stream = await buildTransform(this.view);
5183
+ this.stream = await tag(buildTransform(this.view));
4795
5184
  } catch (cause) {
4796
5185
  this.initFailed = true;
4797
5186
  throw initFailure(cause);
@@ -5151,8 +5540,8 @@ function isRecord3(value) {
5151
5540
  }
5152
5541
  function exceptionFields(error) {
5153
5542
  try {
5154
- if (!isRecord3(error) || typeof error["getResponse"] !== "function") return {};
5155
- const response = error["getResponse"]();
5543
+ if (!isRecord3(error)) return {};
5544
+ const response = error["getResponse"]?.();
5156
5545
  if (!isRecord3(response)) return {};
5157
5546
  const nested = response["error"];
5158
5547
  const carrier = isRecord3(nested) && typeof nested["code"] === "string" ? nested : response;