@rawnodes/logger 2.9.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -13
- package/dist/index.d.mts +27 -252
- package/dist/index.d.ts +27 -252
- package/dist/index.js +168 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -94
- package/dist/index.mjs.map +1 -1
- package/dist/transports/relay.d.mts +14 -0
- package/dist/transports/relay.d.ts +14 -0
- package/dist/transports/relay.js +368 -0
- package/dist/transports/relay.js.map +1 -0
- package/dist/transports/relay.mjs +363 -0
- package/dist/transports/relay.mjs.map +1 -0
- package/dist/types-lfJLhC8J.d.mts +280 -0
- package/dist/types-lfJLhC8J.d.ts +280 -0
- package/package.json +21 -5
package/dist/index.mjs
CHANGED
|
@@ -161,8 +161,10 @@ var DEFAULT_OPTIONS = {
|
|
|
161
161
|
var BaseHttpTransport = class {
|
|
162
162
|
buffer;
|
|
163
163
|
onErrorCallback;
|
|
164
|
+
masker;
|
|
164
165
|
constructor(opts = {}) {
|
|
165
166
|
this.onErrorCallback = opts.onError;
|
|
167
|
+
this.masker = opts.masker;
|
|
166
168
|
this.buffer = new MessageBuffer({
|
|
167
169
|
batchSize: opts.batchSize ?? DEFAULT_OPTIONS.batchSize,
|
|
168
170
|
flushInterval: opts.flushInterval ?? DEFAULT_OPTIONS.flushInterval,
|
|
@@ -197,12 +199,16 @@ var BaseHttpTransport = class {
|
|
|
197
199
|
}
|
|
198
200
|
transformMessage(info) {
|
|
199
201
|
const { level, message, timestamp, context, ...meta } = info;
|
|
202
|
+
let resolvedMeta;
|
|
203
|
+
if (Object.keys(meta).length > 0) {
|
|
204
|
+
resolvedMeta = this.masker ? this.masker(meta) : meta;
|
|
205
|
+
}
|
|
200
206
|
return {
|
|
201
207
|
level,
|
|
202
208
|
message: String(message),
|
|
203
209
|
timestamp: timestamp instanceof Date ? timestamp : timestamp ? new Date(String(timestamp)) : /* @__PURE__ */ new Date(),
|
|
204
210
|
context,
|
|
205
|
-
meta:
|
|
211
|
+
meta: resolvedMeta
|
|
206
212
|
};
|
|
207
213
|
}
|
|
208
214
|
handleError(error, messages) {
|
|
@@ -249,7 +255,7 @@ var DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
|
|
|
249
255
|
var DiscordTransport = class extends BaseHttpTransport {
|
|
250
256
|
config;
|
|
251
257
|
requestTimeout;
|
|
252
|
-
constructor(config) {
|
|
258
|
+
constructor(config, masker) {
|
|
253
259
|
super({
|
|
254
260
|
batchSize: config.batchSize ?? 10,
|
|
255
261
|
flushInterval: config.flushInterval ?? 2e3,
|
|
@@ -258,7 +264,8 @@ var DiscordTransport = class extends BaseHttpTransport {
|
|
|
258
264
|
maxQueueSize: config.maxQueueSize,
|
|
259
265
|
dropPolicy: config.dropPolicy,
|
|
260
266
|
onDrop: config.onDrop,
|
|
261
|
-
onError: config.onError
|
|
267
|
+
onError: config.onError,
|
|
268
|
+
masker
|
|
262
269
|
});
|
|
263
270
|
this.config = config;
|
|
264
271
|
this.requestTimeout = config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
@@ -398,7 +405,7 @@ var TelegramTransport = class extends BaseHttpTransport {
|
|
|
398
405
|
config;
|
|
399
406
|
apiUrl;
|
|
400
407
|
requestTimeout;
|
|
401
|
-
constructor(config) {
|
|
408
|
+
constructor(config, masker) {
|
|
402
409
|
super({
|
|
403
410
|
batchSize: config.batchSize ?? 20,
|
|
404
411
|
flushInterval: config.flushInterval ?? 1e3,
|
|
@@ -407,7 +414,8 @@ var TelegramTransport = class extends BaseHttpTransport {
|
|
|
407
414
|
maxQueueSize: config.maxQueueSize,
|
|
408
415
|
dropPolicy: config.dropPolicy,
|
|
409
416
|
onDrop: config.onDrop,
|
|
410
|
-
onError: config.onError
|
|
417
|
+
onError: config.onError,
|
|
418
|
+
masker
|
|
411
419
|
});
|
|
412
420
|
this.config = config;
|
|
413
421
|
this.apiUrl = `https://api.telegram.org/bot${config.botToken}`;
|
|
@@ -512,7 +520,7 @@ var ZohoCliqTransport = class extends BaseHttpTransport {
|
|
|
512
520
|
config;
|
|
513
521
|
endpoint;
|
|
514
522
|
requestTimeout;
|
|
515
|
-
constructor(config) {
|
|
523
|
+
constructor(config, masker) {
|
|
516
524
|
super({
|
|
517
525
|
batchSize: config.batchSize ?? 20,
|
|
518
526
|
flushInterval: config.flushInterval ?? 2e3,
|
|
@@ -521,7 +529,8 @@ var ZohoCliqTransport = class extends BaseHttpTransport {
|
|
|
521
529
|
maxQueueSize: config.maxQueueSize,
|
|
522
530
|
dropPolicy: config.dropPolicy,
|
|
523
531
|
onDrop: config.onDrop,
|
|
524
|
-
onError: config.onError
|
|
532
|
+
onError: config.onError,
|
|
533
|
+
masker
|
|
525
534
|
});
|
|
526
535
|
this.config = config;
|
|
527
536
|
this.requestTimeout = config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
|
|
@@ -643,7 +652,8 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
643
652
|
initialized = false;
|
|
644
653
|
initPromise = null;
|
|
645
654
|
resolvedLogStreamName;
|
|
646
|
-
|
|
655
|
+
maskReplacer;
|
|
656
|
+
constructor(config, configHostname, maskReplacerFn) {
|
|
647
657
|
super({
|
|
648
658
|
batchSize: config.batchSize ?? 100,
|
|
649
659
|
flushInterval: config.flushInterval ?? 1e3,
|
|
@@ -654,6 +664,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
654
664
|
onDrop: config.onDrop,
|
|
655
665
|
onError: config.onError
|
|
656
666
|
});
|
|
667
|
+
this.maskReplacer = maskReplacerFn;
|
|
657
668
|
this.config = config;
|
|
658
669
|
this.resolvedLogStreamName = resolveLogStreamName(config.logStreamName, configHostname);
|
|
659
670
|
this.client = new CloudWatchLogsClient({
|
|
@@ -666,6 +677,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
666
677
|
}
|
|
667
678
|
async sendBatch(messages) {
|
|
668
679
|
await this.ensureInitialized();
|
|
680
|
+
const replacer = this.maskReplacer;
|
|
669
681
|
const logEvents = messages.map((msg) => ({
|
|
670
682
|
timestamp: msg.timestamp.getTime(),
|
|
671
683
|
message: JSON.stringify({
|
|
@@ -673,7 +685,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
673
685
|
message: msg.message,
|
|
674
686
|
context: msg.context,
|
|
675
687
|
...msg.meta
|
|
676
|
-
})
|
|
688
|
+
}, replacer)
|
|
677
689
|
}));
|
|
678
690
|
logEvents.sort((a, b) => (a.timestamp ?? 0) - (b.timestamp ?? 0));
|
|
679
691
|
const command = new PutLogEventsCommand({
|
|
@@ -825,12 +837,12 @@ function shouldPassTransport(log, level, rules, state, respectOverrides) {
|
|
|
825
837
|
return LOG_LEVELS[logLevel] <= LOG_LEVELS[effectiveLevel];
|
|
826
838
|
}
|
|
827
839
|
var RESERVED_LOG_FIELDS = /* @__PURE__ */ new Set(["level", "time", "msg", "context", "__or"]);
|
|
828
|
-
function formatLog(log, format,
|
|
840
|
+
function formatLog(log, format, state) {
|
|
829
841
|
const levelName = getLevelName(log.level);
|
|
830
842
|
const timestamp = new Date(log.time).toISOString();
|
|
831
843
|
const context = log.context || "APP";
|
|
832
844
|
const message = log.msg || "";
|
|
833
|
-
const storeContext = store.getStore();
|
|
845
|
+
const storeContext = state.store.getStore();
|
|
834
846
|
const meta = {};
|
|
835
847
|
for (const [key, value] of Object.entries(log)) {
|
|
836
848
|
if (!RESERVED_LOG_FIELDS.has(key)) {
|
|
@@ -840,6 +852,7 @@ function formatLog(log, format, store) {
|
|
|
840
852
|
if (storeContext) {
|
|
841
853
|
Object.assign(meta, storeContext);
|
|
842
854
|
}
|
|
855
|
+
const replacer = state.maskReplacer;
|
|
843
856
|
if (format === "json") {
|
|
844
857
|
return JSON.stringify({
|
|
845
858
|
level: levelName,
|
|
@@ -847,7 +860,7 @@ function formatLog(log, format, store) {
|
|
|
847
860
|
context,
|
|
848
861
|
message,
|
|
849
862
|
...meta
|
|
850
|
-
}) + "\n";
|
|
863
|
+
}, replacer) + "\n";
|
|
851
864
|
}
|
|
852
865
|
if (format === "plain") {
|
|
853
866
|
const LEVEL_COLORS = {
|
|
@@ -863,10 +876,11 @@ function formatLog(log, format, store) {
|
|
|
863
876
|
const color = LEVEL_COLORS[levelName] || "";
|
|
864
877
|
const coloredLevel = color ? `${color}${levelName}${RESET}` : levelName;
|
|
865
878
|
const formatValue = (key, value) => {
|
|
866
|
-
|
|
867
|
-
|
|
879
|
+
const masked = replacer ? replacer.call(void 0, key, value) : value;
|
|
880
|
+
if (typeof masked === "string" && masked.includes("\n")) {
|
|
881
|
+
return "\n " + masked.split("\n").join("\n ");
|
|
868
882
|
}
|
|
869
|
-
return JSON.stringify(
|
|
883
|
+
return JSON.stringify(masked, replacer);
|
|
870
884
|
};
|
|
871
885
|
const metaStr = Object.keys(meta).length > 0 ? "\n " + Object.entries(meta).map(([k, v]) => `${k}: ${formatValue(k, v)}`).join("\n ") : "";
|
|
872
886
|
return `[${timestamp}] ${coloredLevel} [${context}] ${message}${metaStr}
|
|
@@ -875,7 +889,8 @@ function formatLog(log, format, store) {
|
|
|
875
889
|
if (format === "logfmt") {
|
|
876
890
|
const parts = [`level=${levelName}`, `msg="${message}"`, `context=${context}`, `ts=${timestamp}`];
|
|
877
891
|
for (const [k, v] of Object.entries(meta)) {
|
|
878
|
-
|
|
892
|
+
const masked = replacer ? replacer.call(void 0, k, v) : v;
|
|
893
|
+
parts.push(`${k}=${JSON.stringify(masked, replacer)}`);
|
|
879
894
|
}
|
|
880
895
|
return parts.join(" ") + "\n";
|
|
881
896
|
}
|
|
@@ -899,7 +914,7 @@ function createFormattedFilterStream(format, level, rules, state, destination, r
|
|
|
899
914
|
callback();
|
|
900
915
|
return;
|
|
901
916
|
}
|
|
902
|
-
const formatted = formatLog(log, format, state
|
|
917
|
+
const formatted = formatLog(log, format, state);
|
|
903
918
|
destination.write(formatted);
|
|
904
919
|
callback();
|
|
905
920
|
}
|
|
@@ -956,7 +971,7 @@ function createStreams(config, state) {
|
|
|
956
971
|
});
|
|
957
972
|
}
|
|
958
973
|
for (const discordConfig of toArray(config.discord)) {
|
|
959
|
-
const transport = new DiscordTransport(discordConfig);
|
|
974
|
+
const transport = new DiscordTransport(discordConfig, state.maskerFn);
|
|
960
975
|
transports.push(transport);
|
|
961
976
|
const discordStream = createHttpTransportStream(
|
|
962
977
|
transport,
|
|
@@ -971,7 +986,7 @@ function createStreams(config, state) {
|
|
|
971
986
|
});
|
|
972
987
|
}
|
|
973
988
|
for (const telegramConfig of toArray(config.telegram)) {
|
|
974
|
-
const transport = new TelegramTransport(telegramConfig);
|
|
989
|
+
const transport = new TelegramTransport(telegramConfig, state.maskerFn);
|
|
975
990
|
transports.push(transport);
|
|
976
991
|
const telegramStream = createHttpTransportStream(
|
|
977
992
|
transport,
|
|
@@ -986,7 +1001,7 @@ function createStreams(config, state) {
|
|
|
986
1001
|
});
|
|
987
1002
|
}
|
|
988
1003
|
for (const zohoCliqConfig of toArray(config.zohoCliq)) {
|
|
989
|
-
const transport = new ZohoCliqTransport(zohoCliqConfig);
|
|
1004
|
+
const transport = new ZohoCliqTransport(zohoCliqConfig, state.maskerFn);
|
|
990
1005
|
transports.push(transport);
|
|
991
1006
|
const zohoStream = createHttpTransportStream(
|
|
992
1007
|
transport,
|
|
@@ -1001,7 +1016,7 @@ function createStreams(config, state) {
|
|
|
1001
1016
|
});
|
|
1002
1017
|
}
|
|
1003
1018
|
for (const cloudwatchConfig of toArray(config.cloudwatch)) {
|
|
1004
|
-
const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname);
|
|
1019
|
+
const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname, state.maskReplacer);
|
|
1005
1020
|
transports.push(transport);
|
|
1006
1021
|
const cwStream = createHttpTransportStream(
|
|
1007
1022
|
transport,
|
|
@@ -1073,6 +1088,116 @@ function createHttpTransportStream(transport, level, rules, state, respectOverri
|
|
|
1073
1088
|
});
|
|
1074
1089
|
}
|
|
1075
1090
|
|
|
1091
|
+
// src/utils/mask-secrets.ts
|
|
1092
|
+
var DEFAULT_SECRET_PATTERNS = [
|
|
1093
|
+
"password",
|
|
1094
|
+
"secret",
|
|
1095
|
+
"token",
|
|
1096
|
+
"apikey",
|
|
1097
|
+
"api_key",
|
|
1098
|
+
"api-key",
|
|
1099
|
+
"auth",
|
|
1100
|
+
"credential",
|
|
1101
|
+
"private"
|
|
1102
|
+
];
|
|
1103
|
+
var DEFAULT_MASK = "***";
|
|
1104
|
+
var REGEX_ESCAPE_RE = /[.*+?^${}()|[\]\\]/g;
|
|
1105
|
+
function buildSecretRe(patterns) {
|
|
1106
|
+
const escaped = patterns.map((p) => p.replace(REGEX_ESCAPE_RE, "\\$&"));
|
|
1107
|
+
return new RegExp(escaped.join("|"), "i");
|
|
1108
|
+
}
|
|
1109
|
+
var DEFAULT_SECRET_RE = buildSecretRe(DEFAULT_SECRET_PATTERNS);
|
|
1110
|
+
var DEFAULT_RESOLVED = {
|
|
1111
|
+
secretRe: DEFAULT_SECRET_RE,
|
|
1112
|
+
mask: DEFAULT_MASK,
|
|
1113
|
+
deep: true
|
|
1114
|
+
};
|
|
1115
|
+
function resolveOptions(options) {
|
|
1116
|
+
if (options.patterns === void 0 && options.mask === void 0 && options.deep === void 0) {
|
|
1117
|
+
return DEFAULT_RESOLVED;
|
|
1118
|
+
}
|
|
1119
|
+
const { patterns = DEFAULT_SECRET_PATTERNS, mask = DEFAULT_MASK, deep = true } = options;
|
|
1120
|
+
return {
|
|
1121
|
+
secretRe: patterns === DEFAULT_SECRET_PATTERNS ? DEFAULT_SECRET_RE : buildSecretRe(patterns),
|
|
1122
|
+
mask,
|
|
1123
|
+
deep
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function isSecretKey(key, secretRe) {
|
|
1127
|
+
return secretRe.test(key);
|
|
1128
|
+
}
|
|
1129
|
+
function maskUrlCredentials(url, mask) {
|
|
1130
|
+
try {
|
|
1131
|
+
const parsed = new URL(url);
|
|
1132
|
+
if (parsed.password) {
|
|
1133
|
+
parsed.password = mask;
|
|
1134
|
+
}
|
|
1135
|
+
if (parsed.username && parsed.password) {
|
|
1136
|
+
parsed.username = mask;
|
|
1137
|
+
}
|
|
1138
|
+
return parsed.toString();
|
|
1139
|
+
} catch {
|
|
1140
|
+
return url;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function maskString(str, mask) {
|
|
1144
|
+
if (str.length < 10) return str;
|
|
1145
|
+
if (str.charCodeAt(0) !== 104) return str;
|
|
1146
|
+
if (!str.startsWith("http://") && !str.startsWith("https://")) return str;
|
|
1147
|
+
if (str.indexOf("@") === -1) return str;
|
|
1148
|
+
return maskUrlCredentials(str, mask);
|
|
1149
|
+
}
|
|
1150
|
+
function maskInternal(obj, opts) {
|
|
1151
|
+
if (obj === null || obj === void 0) return obj;
|
|
1152
|
+
const t = typeof obj;
|
|
1153
|
+
if (t === "string") return maskString(obj, opts.mask);
|
|
1154
|
+
if (t !== "object") return obj;
|
|
1155
|
+
if (Array.isArray(obj)) {
|
|
1156
|
+
return opts.deep ? obj.map((item) => maskInternal(item, opts)) : obj;
|
|
1157
|
+
}
|
|
1158
|
+
const { secretRe, mask, deep } = opts;
|
|
1159
|
+
const result = {};
|
|
1160
|
+
const syms = Object.getOwnPropertySymbols(obj);
|
|
1161
|
+
for (let i = 0; i < syms.length; i++) {
|
|
1162
|
+
const sym = syms[i];
|
|
1163
|
+
result[sym] = obj[sym];
|
|
1164
|
+
}
|
|
1165
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1166
|
+
if (isSecretKey(key, secretRe)) {
|
|
1167
|
+
result[key] = mask;
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
const vt = typeof value;
|
|
1171
|
+
if (vt === "string") {
|
|
1172
|
+
result[key] = maskString(value, mask);
|
|
1173
|
+
} else if (deep && vt === "object" && value !== null) {
|
|
1174
|
+
result[key] = maskInternal(value, opts);
|
|
1175
|
+
} else {
|
|
1176
|
+
result[key] = value;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return result;
|
|
1180
|
+
}
|
|
1181
|
+
function maskSecrets(obj, options = {}) {
|
|
1182
|
+
return maskInternal(obj, resolveOptions(options));
|
|
1183
|
+
}
|
|
1184
|
+
function createMasker(options = {}) {
|
|
1185
|
+
const opts = resolveOptions(options);
|
|
1186
|
+
return (obj) => maskInternal(obj, opts);
|
|
1187
|
+
}
|
|
1188
|
+
function maskReplacer(options = {}) {
|
|
1189
|
+
const { secretRe, mask } = resolveOptions(options);
|
|
1190
|
+
return function(key, value) {
|
|
1191
|
+
if (key !== "" && secretRe.test(key)) return mask;
|
|
1192
|
+
if (typeof value !== "string") return value;
|
|
1193
|
+
if (value.length < 10) return value;
|
|
1194
|
+
if (value.charCodeAt(0) !== 104) return value;
|
|
1195
|
+
if (!value.startsWith("http://") && !value.startsWith("https://")) return value;
|
|
1196
|
+
if (value.indexOf("@") === -1) return value;
|
|
1197
|
+
return maskUrlCredentials(value, mask);
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1076
1201
|
// src/state.ts
|
|
1077
1202
|
var CUSTOM_LEVELS = {
|
|
1078
1203
|
http: 25,
|
|
@@ -1121,6 +1246,7 @@ function createState(config, store) {
|
|
|
1121
1246
|
levelOverrides.set(key, rule);
|
|
1122
1247
|
}
|
|
1123
1248
|
const { contextIndex, complexRules } = buildIndexes(levelOverrides);
|
|
1249
|
+
const maskOptions = config.maskSecrets === true ? {} : config.maskSecrets || void 0;
|
|
1124
1250
|
const state = {
|
|
1125
1251
|
pino: null,
|
|
1126
1252
|
store: loggerStore,
|
|
@@ -1129,7 +1255,9 @@ function createState(config, store) {
|
|
|
1129
1255
|
contextIndex,
|
|
1130
1256
|
complexRules,
|
|
1131
1257
|
callerConfig: void 0,
|
|
1132
|
-
transports: []
|
|
1258
|
+
transports: [],
|
|
1259
|
+
maskReplacer: maskOptions ? maskReplacer(maskOptions) : void 0,
|
|
1260
|
+
maskerFn: maskOptions ? createMasker(maskOptions) : void 0
|
|
1133
1261
|
};
|
|
1134
1262
|
const { destination, transports } = createStreams(config, state);
|
|
1135
1263
|
state.transports = transports;
|
|
@@ -1354,7 +1482,16 @@ var RelayConfigSchema = z.object({
|
|
|
1354
1482
|
bufferSize: z.number().int().positive().optional(),
|
|
1355
1483
|
reconnectDelay: z.number().int().positive().optional(),
|
|
1356
1484
|
maxReconnectDelay: z.number().int().positive().optional(),
|
|
1357
|
-
respectRuntimeOverrides: z.boolean().optional()
|
|
1485
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1486
|
+
allowedWsHosts: z.array(z.string()).optional(),
|
|
1487
|
+
maskSecrets: z.union([
|
|
1488
|
+
z.boolean(),
|
|
1489
|
+
z.object({
|
|
1490
|
+
patterns: z.array(z.string()).optional(),
|
|
1491
|
+
mask: z.string().optional(),
|
|
1492
|
+
deep: z.boolean().optional()
|
|
1493
|
+
})
|
|
1494
|
+
]).optional()
|
|
1358
1495
|
});
|
|
1359
1496
|
var LevelConfigObjectSchema = z.object({
|
|
1360
1497
|
default: LogLevelSchema,
|
|
@@ -1372,6 +1509,11 @@ var AutoShutdownConfigSchema = z.object({
|
|
|
1372
1509
|
timeout: z.number().int().positive().optional(),
|
|
1373
1510
|
signals: z.array(z.string()).optional()
|
|
1374
1511
|
});
|
|
1512
|
+
var MaskSecretsOptionsSchema = z.object({
|
|
1513
|
+
patterns: z.array(z.string()).optional(),
|
|
1514
|
+
mask: z.string().optional(),
|
|
1515
|
+
deep: z.boolean().optional()
|
|
1516
|
+
});
|
|
1375
1517
|
var LoggerConfigSchema = z.object({
|
|
1376
1518
|
level: LevelConfigSchema,
|
|
1377
1519
|
console: ConsoleConfigSchema,
|
|
@@ -1383,7 +1525,8 @@ var LoggerConfigSchema = z.object({
|
|
|
1383
1525
|
relay: RelayConfigSchema.optional(),
|
|
1384
1526
|
caller: z.union([z.boolean(), CallerConfigSchema]).optional(),
|
|
1385
1527
|
hostname: z.string().optional(),
|
|
1386
|
-
autoShutdown: z.union([z.boolean(), AutoShutdownConfigSchema]).optional()
|
|
1528
|
+
autoShutdown: z.union([z.boolean(), AutoShutdownConfigSchema]).optional(),
|
|
1529
|
+
maskSecrets: z.union([z.boolean(), MaskSecretsOptionsSchema]).optional()
|
|
1387
1530
|
});
|
|
1388
1531
|
function validateConfig(config) {
|
|
1389
1532
|
return LoggerConfigSchema.parse(config);
|
|
@@ -1921,75 +2064,6 @@ function getOrGenerateRequestId(headers, options = {}) {
|
|
|
1921
2064
|
return extractRequestId(headers) ?? generateRequestId(options);
|
|
1922
2065
|
}
|
|
1923
2066
|
|
|
1924
|
-
// src/utils/mask-secrets.ts
|
|
1925
|
-
var DEFAULT_SECRET_PATTERNS = [
|
|
1926
|
-
"password",
|
|
1927
|
-
"secret",
|
|
1928
|
-
"token",
|
|
1929
|
-
"apikey",
|
|
1930
|
-
"api_key",
|
|
1931
|
-
"api-key",
|
|
1932
|
-
"auth",
|
|
1933
|
-
"credential",
|
|
1934
|
-
"private"
|
|
1935
|
-
];
|
|
1936
|
-
var DEFAULT_MASK = "***";
|
|
1937
|
-
function isSecretKey(key, patterns) {
|
|
1938
|
-
const lowerKey = key.toLowerCase();
|
|
1939
|
-
return patterns.some((pattern) => lowerKey.includes(pattern.toLowerCase()));
|
|
1940
|
-
}
|
|
1941
|
-
function maskUrlCredentials(url, mask) {
|
|
1942
|
-
try {
|
|
1943
|
-
const parsed = new URL(url);
|
|
1944
|
-
if (parsed.password) {
|
|
1945
|
-
parsed.password = mask;
|
|
1946
|
-
}
|
|
1947
|
-
if (parsed.username && parsed.password) {
|
|
1948
|
-
parsed.username = mask;
|
|
1949
|
-
}
|
|
1950
|
-
return parsed.toString();
|
|
1951
|
-
} catch {
|
|
1952
|
-
return url;
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
function maskSecrets(obj, options = {}) {
|
|
1956
|
-
const { patterns = DEFAULT_SECRET_PATTERNS, mask = DEFAULT_MASK, deep = true } = options;
|
|
1957
|
-
if (obj === null || obj === void 0) {
|
|
1958
|
-
return obj;
|
|
1959
|
-
}
|
|
1960
|
-
if (typeof obj === "string") {
|
|
1961
|
-
if (obj.startsWith("http://") || obj.startsWith("https://")) {
|
|
1962
|
-
return maskUrlCredentials(obj, mask);
|
|
1963
|
-
}
|
|
1964
|
-
return obj;
|
|
1965
|
-
}
|
|
1966
|
-
if (Array.isArray(obj)) {
|
|
1967
|
-
return deep ? obj.map((item) => maskSecrets(item, options)) : obj;
|
|
1968
|
-
}
|
|
1969
|
-
if (typeof obj === "object") {
|
|
1970
|
-
const result = {};
|
|
1971
|
-
for (const sym of Object.getOwnPropertySymbols(obj)) {
|
|
1972
|
-
result[sym] = obj[sym];
|
|
1973
|
-
}
|
|
1974
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
1975
|
-
if (isSecretKey(key, patterns)) {
|
|
1976
|
-
result[key] = mask;
|
|
1977
|
-
} else if (deep && typeof value === "object" && value !== null) {
|
|
1978
|
-
result[key] = maskSecrets(value, options);
|
|
1979
|
-
} else if (typeof value === "string") {
|
|
1980
|
-
result[key] = maskSecrets(value, options);
|
|
1981
|
-
} else {
|
|
1982
|
-
result[key] = value;
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
return result;
|
|
1986
|
-
}
|
|
1987
|
-
return obj;
|
|
1988
|
-
}
|
|
1989
|
-
function createMasker(options = {}) {
|
|
1990
|
-
return (obj) => maskSecrets(obj, options);
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
2067
|
// src/formatters.ts
|
|
1994
2068
|
var MAX_FLATTEN_DEPTH = 10;
|
|
1995
2069
|
var CIRCULAR_REF = "[Circular]";
|
|
@@ -2041,6 +2115,6 @@ function formatLogfmt(data) {
|
|
|
2041
2115
|
return Object.entries(flattened).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${formatLogfmtValue(value)}`).join(" ");
|
|
2042
2116
|
}
|
|
2043
2117
|
|
|
2044
|
-
export { AutoShutdownConfigSchema, BaseHttpTransport, CallerConfigSchema, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfigSchema, DiscordConfigSchema, DiscordTransport, FileConfigSchema, HttpTransportBaseConfigSchema, LOG_LEVELS, LevelConfigObjectSchema, LevelConfigSchema, LevelRuleSchema, LogFormatSchema, LogLevelSchema, LogStreamNameSchema, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfigSchema, Logger, LoggerConfigSchema, LoggerStore, MessageBuffer, RelayConfigSchema, TelegramConfigSchema, TelegramTransport, ZohoCliqConfigSchema, ZohoCliqTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
|
2118
|
+
export { AutoShutdownConfigSchema, BaseHttpTransport, CallerConfigSchema, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfigSchema, DiscordConfigSchema, DiscordTransport, FileConfigSchema, HttpTransportBaseConfigSchema, LOG_LEVELS, LevelConfigObjectSchema, LevelConfigSchema, LevelRuleSchema, LogFormatSchema, LogLevelSchema, LogStreamNameSchema, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfigSchema, Logger, LoggerConfigSchema, LoggerStore, MessageBuffer, RelayConfigSchema, TelegramConfigSchema, TelegramTransport, ZohoCliqConfigSchema, ZohoCliqTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskReplacer, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
|
2045
2119
|
//# sourceMappingURL=index.mjs.map
|
|
2046
2120
|
//# sourceMappingURL=index.mjs.map
|