@bymax-one/nest-logger 1.4.27 → 1.4.29

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.
@@ -25,6 +25,23 @@ var __decorateClass = (decorators, target, key, kind) => {
25
25
  };
26
26
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
27
27
 
28
+ // src/server/config/options-refusal.util.ts
29
+ var refusals = /* @__PURE__ */ new WeakSet();
30
+ var UNREADABLE = "[BymaxLoggerModule] options could not be read";
31
+ function refuse(message) {
32
+ const error = new Error(message);
33
+ refusals.add(error);
34
+ throw error;
35
+ }
36
+ function guardOptions(read) {
37
+ try {
38
+ return read();
39
+ } catch (error) {
40
+ if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
41
+ throw new Error(UNREADABLE, { cause: error });
42
+ }
43
+ }
44
+
28
45
  // src/server/config/drop-unset-options.ts
29
46
  var OPTION_KEYS = {
30
47
  service: true,
@@ -81,6 +98,29 @@ function readSet(source, keys) {
81
98
  }
82
99
  return set;
83
100
  }
101
+ var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
102
+ var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
103
+ var MAX_LIST_ENTRIES = 1e4;
104
+ function copyLists(holder, names, prefix) {
105
+ for (const name of names) {
106
+ const value = Reflect.get(holder, name);
107
+ if (!Array.isArray(value)) continue;
108
+ const length = Reflect.get(value, "length");
109
+ if (!Number.isInteger(length) || length < 0) {
110
+ refuse(`[BymaxLoggerModule] options.${prefix}${name} has a length that is not a count`);
111
+ }
112
+ if (length > MAX_LIST_ENTRIES) {
113
+ refuse(
114
+ `[BymaxLoggerModule] options.${prefix}${name} holds more than ${String(MAX_LIST_ENTRIES)} entries`
115
+ );
116
+ }
117
+ Reflect.set(
118
+ holder,
119
+ name,
120
+ Array.from({ length }, (_, index) => Reflect.get(value, index))
121
+ );
122
+ }
123
+ }
84
124
  function dropUnsetOptions(options) {
85
125
  if (!isRecord(options)) return options;
86
126
  const set = readSet(options, Object.keys(OPTION_KEYS));
@@ -89,6 +129,13 @@ function dropUnsetOptions(options) {
89
129
  if (isRecord(value))
90
130
  Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
91
131
  }
132
+ const service = Reflect.get(set, "service");
133
+ if (isRecord(service)) Reflect.set(set, "service", { ...service });
134
+ const serializers = Reflect.get(set, "serializers");
135
+ if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
136
+ copyLists(set, LIST_OPTIONS, "");
137
+ const http = Reflect.get(set, "http");
138
+ if (isRecord(http)) copyLists(http, HTTP_LISTS, "http.");
92
139
  return set;
93
140
  }
94
141
 
@@ -186,23 +233,6 @@ function applyDefaults(given) {
186
233
  return Object.freeze(merged);
187
234
  }
188
235
 
189
- // src/server/config/options-refusal.util.ts
190
- var refusals = /* @__PURE__ */ new WeakSet();
191
- var UNREADABLE = "[BymaxLoggerModule] options could not be read";
192
- function refuse(message) {
193
- const error = new Error(message);
194
- refusals.add(error);
195
- throw error;
196
- }
197
- function guardOptions(read) {
198
- try {
199
- return read();
200
- } catch (error) {
201
- if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
202
- throw new Error(UNREADABLE, { cause: error });
203
- }
204
- }
205
-
206
236
  // src/server/constants/log-levels.constants.ts
207
237
  var PINO_LEVEL_NUMBERS = Object.freeze({
208
238
  fatal: 60,
@@ -501,6 +531,15 @@ function validateOptions(given) {
501
531
  validateOtel(options);
502
532
  }
503
533
 
534
+ // src/server/config/resolve-options.ts
535
+ function resolveOptions(given) {
536
+ return guardOptions(() => {
537
+ const snapshot = dropUnsetOptions(given);
538
+ validateOptions(snapshot);
539
+ return applyDefaults(snapshot);
540
+ });
541
+ }
542
+
504
543
  // src/server/constants/injection-tokens.constants.ts
505
544
  var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
506
545
  var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
@@ -620,47 +659,141 @@ function escapeControlCharacters(text) {
620
659
  }
621
660
 
622
661
  // src/server/utils/fold-key.util.ts
623
- var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
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;
624
665
  var PLAIN = /^[\x21-\x7e]*$/;
666
+ var NON_ASCII = /[^\x20-\x7e]/;
667
+ var NOT_ASCII_NAME = /[^A-Za-z0-9]/g;
625
668
  var LOOKALIKES = new Map(
626
669
  Object.entries({
627
670
  a: "\u0430\u03B1\u1D00",
628
671
  b: "\u0299",
629
- c: "\u0441\u03F2\u1D04",
672
+ c: "\u0441\u03F2\u1D04\u023C\u0188",
630
673
  d: "\u0501\u1D05",
631
- e: "\u0435\u03B5\u03F5\u1D07",
674
+ e: "\u0435\u03B5\u03F5\u1D07\u025B\u04BD",
632
675
  f: "\uA730",
633
676
  g: "\u0262",
634
677
  h: "\u029C",
635
- i: "\u0456\u03B9\u0131\u026A",
636
678
  j: "\u0458\u1D0A",
637
679
  k: "\u1D0B",
638
680
  l: "\u029F",
639
681
  m: "\u1D0D",
640
682
  n: "\u0274",
641
- o: "\u043E\u03BF\u1D0F",
642
- p: "\u0440\u03C1\u1D18",
683
+ o: "\u043E\u03BF\u1D0F\xF8",
684
+ p: "\u0440\u03C1\u1D18\u01BF",
643
685
  q: "\u051B",
644
686
  r: "\u0280",
645
687
  s: "\u0455\uA731",
646
- t: "\u1D1B",
688
+ t: "\u1D1B\u0167",
647
689
  u: "\u1D1C",
648
- v: "\u03BD\u1D20",
690
+ v: "\u1D20",
649
691
  w: "\u051D\u1D21",
650
692
  x: "\u0445",
651
- y: "\u0443\u028F",
693
+ y: "\u0443\u028F\u04AF",
652
694
  z: "\u1D22"
653
695
  }).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
654
696
  );
655
- function foldKey(key) {
656
- if (PLAIN.test(key)) return key.replace(IGNORED, "").toLowerCase();
657
- let folded = key.normalize("NFKD").toLowerCase().replace(IGNORED, "");
658
- for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
659
- return folded;
697
+ var I_LIKE = new Map(
698
+ [..."\u0456\u03B9\u0131\u026A\u0269"].map((letter) => [letter, "i"])
699
+ );
700
+ function foldKey(key, keepSeparators = false) {
701
+ if (keepSeparators) {
702
+ if (PLAIN.test(key)) return key.toLowerCase();
703
+ return withLookalikes(
704
+ key.normalize("NFKD").toLowerCase().replace(DOTS, ".").replace(INVISIBLE, ""),
705
+ true
706
+ );
707
+ }
708
+ if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
709
+ return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), true);
710
+ }
711
+ 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);
714
+ }
715
+ function withLookalikes(folded, all) {
716
+ 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);
719
+ return read;
720
+ }
721
+ var ALNUM = /^[A-Za-z0-9]*$/;
722
+ function formOf(key) {
723
+ return ALNUM.test(key) ? key.toLowerCase() : foldStrict(key);
724
+ }
725
+ var answers = /* @__PURE__ */ new WeakMap();
726
+ function foldName(key) {
727
+ return formOf(key);
728
+ }
729
+ function foldedNames(names) {
730
+ return new Set(Array.from(names, foldName).filter((name) => name !== ""));
731
+ }
732
+ var MAX_CANDIDATES = 64;
733
+ var grouped = /* @__PURE__ */ new WeakMap();
734
+ function groupsOf(names) {
735
+ let groups = grouped.get(names);
736
+ if (groups === void 0) {
737
+ const built = /* @__PURE__ */ new Map();
738
+ let longest = 0;
739
+ for (const name of names) {
740
+ const size = [...name].length;
741
+ const same = built.get(size);
742
+ if (same === void 0) built.set(size, [name]);
743
+ else same.push(name);
744
+ longest = Math.max(longest, size);
745
+ }
746
+ groups = { byLength: built, longest };
747
+ grouped.set(names, groups);
748
+ }
749
+ return groups;
750
+ }
751
+ function matchesFolded(names, folded) {
752
+ if (names.has(folded)) return true;
753
+ if (!NON_ASCII.test(folded)) return false;
754
+ const letters = [...folded];
755
+ const wide = letters.filter((letter) => !isAscii(letter)).length;
756
+ const { byLength, longest } = groupsOf(names);
757
+ if (letters.length > longest) return false;
758
+ const lengths = Array.from(
759
+ { length: wide + 1 },
760
+ (_, extra) => byLength.get(letters.length + extra) ?? []
761
+ );
762
+ if (lengths.reduce((count, same) => count + same.length, 0) > MAX_CANDIDATES) return true;
763
+ return lengths.some((same) => same.some((name) => matchesName(letters, [...name])));
764
+ }
765
+ var isAscii = (letter) => letter < "\x80";
766
+ function matchesName(letters, name) {
767
+ let at = /* @__PURE__ */ new Set([0]);
768
+ for (const letter of letters) {
769
+ const next = /* @__PURE__ */ new Set();
770
+ for (const position of at) {
771
+ if (isAscii(letter)) {
772
+ if (name[position] === letter) next.add(position + 1);
773
+ continue;
774
+ }
775
+ next.add(position + 1);
776
+ next.add(position + 2);
777
+ }
778
+ at = next;
779
+ }
780
+ return at.has(name.length);
781
+ }
782
+ function matchesKey(names, key) {
783
+ const seen = answers.get(names) ?? /* @__PURE__ */ new Map();
784
+ answers.set(names, seen);
785
+ const known = seen.get(key);
786
+ if (known !== void 0) return known;
787
+ const folded = formOf(key);
788
+ const answer = names.has(folded) || matchesFolded(names, folded);
789
+ if (key.length <= 64) {
790
+ if (seen.size > 1023) seen.clear();
791
+ seen.set(key, answer);
792
+ }
793
+ return answer;
660
794
  }
661
795
 
662
796
  // src/server/utils/hide-message-in-stack.util.ts
663
- var FRAME_LINE = /\n[ \t]+at /g;
664
797
  function failureTable(message) {
665
798
  const table = new Int32Array(message.length);
666
799
  for (let i = 1, matched = 0; i < message.length; i += 1) {
@@ -671,41 +804,38 @@ function failureTable(message) {
671
804
  return table;
672
805
  }
673
806
  function occurrences(stack, message) {
807
+ if (message.length > stack.length) return [];
674
808
  const table = failureTable(message);
675
809
  const spans = [];
676
810
  for (let i = 0, matched = 0; i < stack.length; i += 1) {
677
811
  while (matched > 0 && stack[i] !== message[matched]) matched = table[matched - 1];
678
812
  if (stack[i] === message[matched]) matched += 1;
679
813
  if (matched === message.length) {
680
- const start = i + 1 - message.length;
681
- const last = spans[spans.length - 1];
682
- if (last !== void 0 && start < last[1]) last[1] = i + 1;
683
- else spans.push([start, i + 1]);
814
+ spans.push([i + 1 - message.length, i + 1]);
684
815
  }
685
816
  }
686
817
  return spans;
687
818
  }
688
- function headerEnd(stack, spans) {
689
- let next = 0;
690
- for (const line of stack.matchAll(FRAME_LINE)) {
691
- while (next < spans.length && spans[next][1] <= line.index) next += 1;
692
- const span = spans[next];
693
- if (span === void 0 || line.index < span[0]) return line.index;
694
- }
695
- return stack.length;
696
- }
697
- function hideMessageInStack(stack, message, replacement) {
698
- if (message === "") return stack;
699
- if (message.length > stack.length) return stack;
700
- const spans = occurrences(stack, message);
701
- const end = headerEnd(stack, spans);
819
+ function hideMessagesInStack(stack, messages, replacement, limit) {
820
+ const spans = messages.filter((message) => message !== "").flatMap((message) => occurrences(stack, message)).sort((a, b) => a[0] - b[0]);
702
821
  let result = "";
703
822
  let from = 0;
704
- for (const [start, stop] of spans.filter(([, stop2]) => stop2 <= end)) {
823
+ let end = limit;
824
+ for (const [start, stop] of spans) {
825
+ if (start >= end) break;
826
+ if (start < from) {
827
+ from = Math.max(from, stop);
828
+ end = Math.max(end, from);
829
+ continue;
830
+ }
705
831
  result += stack.slice(from, start) + replacement;
706
832
  from = stop;
833
+ end = Math.max(end, stop);
707
834
  }
708
- return result + stack.slice(from);
835
+ return result + stack.slice(from, Math.max(end, from));
836
+ }
837
+ function hideMessageInStack(stack, message, replacement) {
838
+ return hideMessagesInStack(stack, [message], replacement, stack.length);
709
839
  }
710
840
 
711
841
  // src/server/utils/is-plain-record.util.ts
@@ -724,17 +854,17 @@ function endsHeader(stack, message, from) {
724
854
  const end = from + message.length;
725
855
  return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
726
856
  }
727
- function censorStackHeader(stack, name, message, censored) {
728
- if (message === "" || censored === message) return stack;
857
+ function splitCensoredHeader(stack, name, message, censored) {
858
+ if (message === "" || censored === message) return ["", stack];
729
859
  const separator = stack.indexOf(NAME_SEPARATOR);
730
860
  if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
731
861
  const from = separator + NAME_SEPARATOR.length;
732
862
  if (endsHeader(stack, message, from)) {
733
- return stack.slice(0, from) + censored + stack.slice(from + message.length);
863
+ return [stack.slice(0, from) + censored, stack.slice(from + message.length)];
734
864
  }
735
865
  }
736
- if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
737
- return name === "" ? censored : name + NAME_SEPARATOR + censored;
866
+ if (endsHeader(stack, message, 0)) return [censored, stack.slice(message.length)];
867
+ return [name === "" ? censored : name + NAME_SEPARATOR + censored, ""];
738
868
  }
739
869
  function isError(value) {
740
870
  try {
@@ -821,14 +951,15 @@ function readScrubbedStack(value, name, message, textName, result, walk2) {
821
951
  const stack = readOptional(() => value.stack, result);
822
952
  if (stack === void 0) return void 0;
823
953
  const header = headerCensor(name, message, walk2.censorMessage);
824
- return scrubStack(textName ? stack : withNamedHeader(stack, message), header);
954
+ return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
825
955
  }
826
- var FRAME_LINE2 = /\n[ \t]+at /;
956
+ var FRAME_LINE = /\n[ \t]+at /;
827
957
  function withNamedHeader(stack, message) {
828
- const found = message === "" ? -1 : stack.indexOf(message);
829
- if (found !== -1) return `Error: ${stack.slice(found)}`;
830
- const end = stack.search(FRAME_LINE2);
831
- const frames = end === -1 ? "" : stack.slice(end);
958
+ const head = stack.slice(0, MAX_STACK_SCAN);
959
+ const found = message === "" ? -1 : head.indexOf(message);
960
+ if (found !== -1) return `Error: ${head.slice(found)}`;
961
+ const end = head.search(FRAME_LINE);
962
+ const frames = end === -1 ? "" : head.slice(end);
832
963
  return `Error${message === "" ? "" : `: ${message}`}${frames}`;
833
964
  }
834
965
  function toSanitizedError(value, seen, depth2, walk2) {
@@ -956,17 +1087,26 @@ function headerCensor(name, message, censorMessage) {
956
1087
  function censorStackName(stack, header) {
957
1088
  return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
958
1089
  }
959
- function scrubStack(stack, header) {
960
- const head = stack.slice(0, MAX_STACK_SCAN);
1090
+ function censorMessageInStack(stack, header) {
1091
+ const [opened, rest] = splitCensoredHeader(
1092
+ censorStackName(stack, header),
1093
+ header.censoredName,
1094
+ header.message,
1095
+ header.censored
1096
+ );
1097
+ return header.censored === header.message ? opened + rest : opened + hideMessagesInStack(
1098
+ rest,
1099
+ [header.message],
1100
+ header.censored,
1101
+ Math.max(0, MAX_STACK_SCAN - (stack.length - rest.length))
1102
+ );
1103
+ }
1104
+ function scrubStack(stack, header, wasLonger = false) {
1105
+ const window = stack.slice(0, MAX_STACK_SCAN + (header?.message.length ?? 0));
961
1106
  const scrubbed = escapeControlCharacters(
962
- (header === void 0 ? head : censorStackHeader(
963
- censorStackName(head, header),
964
- header.censoredName,
965
- header.message,
966
- header.censored
967
- )).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
1107
+ (header === void 0 ? window : censorMessageInStack(window, header)).slice(0, MAX_STACK_SCAN).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
968
1108
  );
969
- return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
1109
+ return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
970
1110
  }
971
1111
  function isObject(value) {
972
1112
  return typeof value === "object" && value !== null;
@@ -989,7 +1129,7 @@ var RESOURCE_KEYS = [
989
1129
  "deployment.environment.name"
990
1130
  ];
991
1131
  var OWNED_KEY_SPELLINGS = new Set(
992
- [...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
1132
+ [...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map((key) => foldKey(key))
993
1133
  );
994
1134
  var DERIVED_KEYS = /* @__PURE__ */ new Set([
995
1135
  "exception.type",
@@ -997,10 +1137,9 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
997
1137
  "exception.stacktrace",
998
1138
  "error.type"
999
1139
  ]);
1000
- var lookAlike = (key) => key.normalize("NFKC").replace(/[\p{Cf}\p{Zs}]/gu, "").toLowerCase();
1001
1140
  var isOwnedKey = (key) => {
1002
1141
  const lower = key.toLowerCase();
1003
- return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(lookAlike(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
1142
+ return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(foldKey(key, true)) || lower.startsWith("service.") || lower.startsWith("deployment.");
1004
1143
  };
1005
1144
  function withoutOwnedKeys(metadata, omit) {
1006
1145
  if (metadata === void 0) {
@@ -2757,7 +2896,7 @@ function mergeMixinSafely(mergeObject, mixinObject) {
2757
2896
  function censorRawHeaders(raw, sensitive, censor) {
2758
2897
  return raw.map((entry, index) => {
2759
2898
  const name = index % 2 === 1 ? raw[index - 1] : void 0;
2760
- return typeof name === "string" && sensitive.has(name.toLowerCase()) ? censor : entry;
2899
+ return typeof name === "string" && matchesKey(sensitive, name) ? censor : entry;
2761
2900
  });
2762
2901
  }
2763
2902
 
@@ -2867,34 +3006,57 @@ function rulesBelow(rules, key, value, honorToJson) {
2867
3006
  return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
2868
3007
  }
2869
3008
  function isCensored(rules, key, value) {
2870
- const lower = key.toLowerCase();
2871
- return rules.sensitive.has(lower) && !(typeof value === "string" && rules.exemptKeys?.has(lower));
3009
+ return matchesKey(rules.sensitive, key) && !(typeof value === "string" && rules.exemptKeys?.has(key));
2872
3010
  }
2873
3011
  function messageCensor(rules) {
2874
3012
  return (text) => rules.sensitive.has("message") ? rules.censor : text;
2875
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 };
2876
3018
  function headerMessage(rules, source, keys, isError2) {
2877
- if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
2878
- return void 0;
2879
- if (rules.headerKept === true) return void 0;
2880
- const key = keys.find((candidate) => foldKey(candidate) === "message");
2881
- if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
2882
- return void 0;
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);
2883
3032
  }
2884
- const text = Reflect.get(source, key);
2885
- return typeof text === "string" ? { key, text } : void 0;
3033
+ const overflow = stacks.length > MAX_STACK_ALIASES || new Set(texts.values()).size > MAX_STACK_ALIASES;
3034
+ return { texts, stackKeys: new Set(stacks), overflow };
2886
3035
  }
2887
3036
  function readField(source, key, header) {
2888
- return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
3037
+ return header?.texts.get(key) ?? Reflect.get(source, key);
2889
3038
  }
2890
3039
  function censorAnyName(rules, name) {
2891
3040
  if (typeof name === "string") return censorName(name, messageCensor(rules));
2892
3041
  const holder = typeof name === "object" && name !== null || typeof name === "function";
2893
3042
  return holder && rules.sensitive.has("message") ? rules.censor : name;
2894
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
+ }
2895
3056
  function errorTextField(rules, key, value, isError2, header) {
2896
- if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
2897
- return hideMessageInStack(value, header.text, rules.censor);
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);
2898
3060
  }
2899
3061
  if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
2900
3062
  const cut = cutIfText(value);
@@ -2930,7 +3092,7 @@ function cloneError(error) {
2930
3092
  // src/server/utils/redact-by-name.util.ts
2931
3093
  var RAW_HEADER_KEYS = /* @__PURE__ */ new Set(["rawheaders", "rawtrailers"]);
2932
3094
  function censorHeaderArray(key, walked, rules) {
2933
- return RAW_HEADER_KEYS.has(key.toLowerCase()) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
3095
+ return matchesKey(RAW_HEADER_KEYS, key) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
2934
3096
  }
2935
3097
  var REDACT_MAX_TRAVERSAL_DEPTH = 100;
2936
3098
  var REDACT_DEPTH_EXCEEDED = "[REDACTION_DEPTH_EXCEEDED]";
@@ -3043,7 +3205,7 @@ function walkForm(value, resolved, rules, depth2, ancestors, honorToJson, inSeri
3043
3205
  return walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized);
3044
3206
  }
3045
3207
  function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized) {
3046
- if (Object.keys(value).some((key) => rules.sensitive.has(key.toLowerCase()))) {
3208
+ if (Object.keys(value).some((key) => matchesKey(rules.sensitive, key))) {
3047
3209
  return rules.censor;
3048
3210
  }
3049
3211
  return walk(toJson.call(value), rules, depth2 + 1, ancestors, true, inSerialized);
@@ -3111,8 +3273,8 @@ function errorPartsHost(rules, ancestors, inSerialized) {
3111
3273
  }
3112
3274
  function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames, errorTextToSerializer = false) {
3113
3275
  const rules = {
3114
- sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
3115
- headerNames: new Set(Array.from(headerNames ?? fieldNames, (name) => name.toLowerCase())),
3276
+ sensitive: foldedNames(fieldNames),
3277
+ headerNames: foldedNames(headerNames ?? fieldNames),
3116
3278
  censor,
3117
3279
  serializedKeys: new Set(serializedKeys),
3118
3280
  errorsAsData: serializedKeys !== void 0,
@@ -3120,7 +3282,7 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3120
3282
  maxVisits,
3121
3283
  ownFields
3122
3284
  };
3123
- const insideNames = errorOnlyNames === void 0 ? void 0 : new Set(Array.from(errorOnlyNames, (name) => name.toLowerCase()));
3285
+ const insideNames = errorOnlyNames === void 0 ? void 0 : foldedNames(errorOnlyNames);
3124
3286
  return (value, isRecordRoot = false) => {
3125
3287
  try {
3126
3288
  const visits = { count: 0 };
@@ -4404,10 +4566,8 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4404
4566
  * BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
4405
4567
  */
4406
4568
  static forRoot(options) {
4407
- const resolved = guardOptions(() => {
4408
- validateOptions(options);
4409
- return applyDefaults(options);
4410
- });
4569
+ const snapshot = guardOptions(() => dropUnsetOptions(options));
4570
+ const resolved = resolveOptions(snapshot);
4411
4571
  const providers = [
4412
4572
  { provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
4413
4573
  ...buildCommonProviders()
@@ -4419,7 +4579,7 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4419
4579
  }
4420
4580
  }
4421
4581
  return augmentLoggerModule(
4422
- guardOptions(() => super.forRoot(options)),
4582
+ guardOptions(() => super.forRoot(snapshot)),
4423
4583
  providers
4424
4584
  );
4425
4585
  }
@@ -4450,12 +4610,7 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4450
4610
  const providers = [
4451
4611
  {
4452
4612
  provide: LOGGER_OPTIONS_TOKEN,
4453
- useFactory: (raw) => {
4454
- return guardOptions(() => {
4455
- validateOptions(raw);
4456
- return applyDefaults(raw);
4457
- });
4458
- },
4613
+ useFactory: (raw) => resolveOptions(raw),
4459
4614
  inject: [BUILDER_OPTIONS_TOKEN]
4460
4615
  },
4461
4616
  ...buildCommonProviders(),