@camstack/server 1.2.810 → 1.2.812
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/CHANGELOG.md +17 -0
- package/dist/api/trpc/cap-router-runtime.js +3 -0
- package/dist/api/trpc/generated-cap-mounts.js +3 -1
- package/dist/api/trpc/generated-cap-routers.js +1869 -1789
- package/dist/core/addon/hub-addon-api.js +8 -1
- package/dist/core/moleculer/moleculer.service.js +3 -0
- package/package.json +9 -42
- package/system/dist/addon-runner.js +4 -1
- package/system/dist/addon-runner.mjs +5 -2
- package/system/dist/{agent-https-B5cYxyQW.mjs → agent-https-CyEBY3RB.mjs} +1 -1
- package/system/dist/{agent-https-C0QE8tXs.js → agent-https-a3mE4PW4.js} +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +3 -101
- package/system/dist/builtins/alerts/alerts.addon.mjs +40 -134
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +6 -5
- package/system/dist/builtins/composer/composer.addon.mjs +6 -5
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +358 -32
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +361 -35
- package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +42 -0
- package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +1 -1
- package/system/dist/builtins/core-blocks/remote-service.d.ts +38 -0
- package/system/dist/builtins/device-history/device-history.addon.d.ts +5 -0
- package/system/dist/builtins/device-history/device-history.addon.js +357 -18
- package/system/dist/builtins/device-history/device-history.addon.mjs +357 -18
- package/system/dist/builtins/device-history/retention/retention.d.ts +14 -1
- package/system/dist/builtins/device-history/transitions/device-transitions-record-kinds.d.ts +14 -0
- package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +80 -0
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +712 -18
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +780 -95
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
- package/system/dist/builtins/device-manager/transitions/command-args.d.ts +4 -0
- package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +68 -0
- package/system/dist/builtins/device-manager/transitions/transitions-sender.d.ts +37 -0
- package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +25 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-DHvJXvuV.js → capture-engine-BO9mSlY-.js} +1 -1
- package/system/dist/{capture-engine-Ci4GwgjQ.mjs → capture-engine-ByF-6AFH.mjs} +1 -1
- package/system/dist/{composition-sources-CXJ0SzYJ.mjs → composition-sources-AziMFo7T.mjs} +1 -1
- package/system/dist/{composition-sources-B-WY9L7z.js → composition-sources-BMJUPUh2.js} +1 -1
- package/system/dist/{constants-DAuOjW5K.mjs → constants-CTikgsC_.mjs} +1 -1
- package/system/dist/{constants-DnJ2vuC7.js → constants-CjRlgRlu.js} +1 -1
- package/system/dist/{device-ca-D0HejZGK.mjs → device-ca-CNRlFqFC.mjs} +1 -1
- package/system/dist/{device-ca-BRpXm-B0.js → device-ca-Dxl6kVcJ.js} +1 -1
- package/system/dist/{dist-BLxWQm_m.mjs → dist-BPq13Y8j.mjs} +17392 -15506
- package/system/dist/{dist-DZQowBDF.js → dist-CkJnelZr.js} +17463 -15511
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-BJx5WmFx.mjs → hub-mdns-ciao-CrjItezp.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-ClSuN_QT.js → hub-mdns-ciao-Cx6yJBl9.js} +2 -2
- package/system/dist/index.js +67 -75
- package/system/dist/index.mjs +53 -68
- package/system/dist/kernel/cap-router-builder.d.ts +9 -0
- package/system/dist/kernel/command-observation.d.ts +76 -0
- package/system/dist/kernel/index.d.ts +2 -0
- package/system/dist/kernel/transport/child-cap-protocol.d.ts +10 -1
- package/system/dist/kernel/transport/local-child-registry.d.ts +15 -0
- package/system/dist/{legacy-integration-rows-door-BiNKE2zW.js → legacy-integration-rows-door-CKM-LxvL.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-CN84_M7B.mjs → legacy-integration-rows-door-Dxcqwc-w.mjs} +1 -1
- package/system/dist/log-redactor-BhIEMaG9.js +149 -0
- package/system/dist/log-redactor-XLDrPzOi.mjs +120 -0
- package/system/dist/logging/log-redactor.d.ts +2 -0
- package/system/dist/{restore-archive-Co1yYMV3.js → restore-archive-BQWOdGAB.js} +1 -1
- package/system/dist/{restore-archive-gLW5oc1w.mjs → restore-archive-r3zTdLKr.mjs} +82 -82
- package/system/dist/{retention-BNONb5X_.js → retention-BcOSL6b9.js} +33 -2
- package/system/dist/{retention-B9l9TnGE.mjs → retention-CUOVI1p7.mjs} +33 -2
- package/system/dist/{wal-maintenance-BQaIM_cY.js → wal-maintenance-CiCgL4Hp.js} +0 -0
- package/system/dist/{wal-maintenance-Zji_8sLK.mjs → wal-maintenance-zJ4-ORo6.mjs} +0 -0
- package/system/package.json +7 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
let _camstack_types_addon = require("@camstack/types/addon");
|
|
2
|
+
//#region src/logging/log-redactor.ts
|
|
3
|
+
var REDACTED = "***";
|
|
4
|
+
/** Credential-named keys. Substring, case-insensitive; only STRING values are replaced. */
|
|
5
|
+
var SECRET_KEY_SUBSTRINGS = [
|
|
6
|
+
"password",
|
|
7
|
+
"passwd",
|
|
8
|
+
"secret",
|
|
9
|
+
"token",
|
|
10
|
+
"apikey",
|
|
11
|
+
"api_key",
|
|
12
|
+
"authkey",
|
|
13
|
+
"auth_key",
|
|
14
|
+
"privatekey",
|
|
15
|
+
"private_key",
|
|
16
|
+
"passphrase",
|
|
17
|
+
"credential",
|
|
18
|
+
"cookie"
|
|
19
|
+
];
|
|
20
|
+
/** True when a meta key names a credential. */
|
|
21
|
+
function isCredentialKeyName(key) {
|
|
22
|
+
const lower = key.toLowerCase();
|
|
23
|
+
return SECRET_KEY_SUBSTRINGS.some((needle) => lower.includes(needle));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Words that name a credential only as the LAST word of a key (`pin`, `adminPin`,
|
|
27
|
+
* `otp`, `apiKey`, `code`). Not part of the log net above: an error `code`
|
|
28
|
+
* is a string in most log meta, and `keyFrame` is not a key. Used where an
|
|
29
|
+
* argument bag is stored (D1022), where a wrongly hidden value costs less than
|
|
30
|
+
* a leaked code.
|
|
31
|
+
*/
|
|
32
|
+
var SECRET_LAST_WORDS = new Set([
|
|
33
|
+
"pin",
|
|
34
|
+
"pincode",
|
|
35
|
+
"passcode",
|
|
36
|
+
"otp",
|
|
37
|
+
"code",
|
|
38
|
+
"key"
|
|
39
|
+
]);
|
|
40
|
+
/** The last camelCase / snake_case / kebab-case word of a key, lowercased. */
|
|
41
|
+
function lastWord(key) {
|
|
42
|
+
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_-]+/);
|
|
43
|
+
return (words[words.length - 1] ?? "").toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
/** True for a credential-named key, or one whose last word is a code, pin, otp or key. */
|
|
46
|
+
function isSecretArgumentKey(key) {
|
|
47
|
+
return isCredentialKeyName(key) || SECRET_LAST_WORDS.has(lastWord(key));
|
|
48
|
+
}
|
|
49
|
+
var URL_IN_TEXT = /\b[a-z][a-z0-9+.-]*:\/\/[^\s"'<>`]+/gi;
|
|
50
|
+
/** A root-relative path WITH a query, as request logs print it. */
|
|
51
|
+
var RELATIVE_URL_IN_TEXT = /(^|[\s"'(=])(\/[^\s"'<>`?]*\?[^\s"'<>`]+)/g;
|
|
52
|
+
var CREDENTIAL_FLAG = /(--(?:token|auth-?key|password|passwd|pass|secret|api-?key|access-?token|refresh-?token)(?:=|\s+))(\S+)/gi;
|
|
53
|
+
/** Redact one free-form string. */
|
|
54
|
+
function redactLogText(text) {
|
|
55
|
+
let out = (0, _camstack_types_addon.scrubKnownSecrets)(text);
|
|
56
|
+
if (out.includes("://")) out = out.replace(URL_IN_TEXT, (url) => (0, _camstack_types_addon.maskUrlCredentials)(url));
|
|
57
|
+
if (out.includes("/") && out.includes("?") && out.includes("=")) out = out.replace(RELATIVE_URL_IN_TEXT, (_m, lead, path) => `${lead}${(0, _camstack_types_addon.maskUrlCredentials)(path)}`);
|
|
58
|
+
if (out.includes("--")) out = out.replace(CREDENTIAL_FLAG, (_m, flag, value) => value.startsWith("‹secret:") ? `${flag}${value}` : `${flag}${REDACTED}`);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/** Bounds on the meta walk — a log line is not a place to traverse a graph. */
|
|
62
|
+
var MAX_DEPTH = 8;
|
|
63
|
+
var MAX_NODES = 2e3;
|
|
64
|
+
/**
|
|
65
|
+
* Redact a value, returning the SAME reference when nothing in it changed —
|
|
66
|
+
* most lines carry clean meta, and copying every one would put an allocation
|
|
67
|
+
* per log line on hub-main's event loop.
|
|
68
|
+
*/
|
|
69
|
+
function redactValue(value, depth, budget, seen) {
|
|
70
|
+
if (budget.nodes++ > MAX_NODES) return value;
|
|
71
|
+
if (typeof value === "string") return redactLogText(value);
|
|
72
|
+
if (value === null || typeof value !== "object") return value;
|
|
73
|
+
if (depth >= MAX_DEPTH || seen.has(value)) return value;
|
|
74
|
+
if (value instanceof Error) {
|
|
75
|
+
const message = redactLogText(value.message);
|
|
76
|
+
return message === value.message ? value : message;
|
|
77
|
+
}
|
|
78
|
+
if (value instanceof Date || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return value;
|
|
79
|
+
seen.add(value);
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
let copy = null;
|
|
82
|
+
for (let i = 0; i < value.length; i++) {
|
|
83
|
+
const item = value[i];
|
|
84
|
+
const next = redactValue(item, depth + 1, budget, seen);
|
|
85
|
+
if (next !== item) {
|
|
86
|
+
copy ??= [...value];
|
|
87
|
+
copy[i] = next;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return copy ?? value;
|
|
91
|
+
}
|
|
92
|
+
let copy = null;
|
|
93
|
+
for (const [key, child] of Object.entries(value)) {
|
|
94
|
+
const next = typeof child === "string" && child.length > 0 && isCredentialKeyName(key) ? REDACTED : redactValue(child, depth + 1, budget, seen);
|
|
95
|
+
if (next !== child) {
|
|
96
|
+
copy ??= { ...value };
|
|
97
|
+
copy[key] = next;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return copy ?? value;
|
|
101
|
+
}
|
|
102
|
+
/** Redact a `meta` record; the same object back when it was already clean. */
|
|
103
|
+
function redactLogMeta(meta) {
|
|
104
|
+
const out = redactValue(meta, 0, { nodes: 0 }, /* @__PURE__ */ new WeakSet());
|
|
105
|
+
if (out === meta) return meta;
|
|
106
|
+
return out !== null && typeof out === "object" && !Array.isArray(out) ? Object.fromEntries(Object.entries(out)) : meta;
|
|
107
|
+
}
|
|
108
|
+
/** Redact a whole entry: message and meta. Tags are identifiers, left alone. */
|
|
109
|
+
function redactLogEntry(entry) {
|
|
110
|
+
const message = redactLogText(entry.message);
|
|
111
|
+
const meta = entry.meta !== void 0 ? redactLogMeta(entry.meta) : void 0;
|
|
112
|
+
if (message === entry.message && meta === entry.meta) return entry;
|
|
113
|
+
return {
|
|
114
|
+
...entry,
|
|
115
|
+
message,
|
|
116
|
+
...meta !== void 0 ? { meta } : {}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
Object.defineProperty(exports, "isCredentialKeyName", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function() {
|
|
123
|
+
return isCredentialKeyName;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(exports, "isSecretArgumentKey", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function() {
|
|
129
|
+
return isSecretArgumentKey;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
Object.defineProperty(exports, "redactLogEntry", {
|
|
133
|
+
enumerable: true,
|
|
134
|
+
get: function() {
|
|
135
|
+
return redactLogEntry;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(exports, "redactLogMeta", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function() {
|
|
141
|
+
return redactLogMeta;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
Object.defineProperty(exports, "redactLogText", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
get: function() {
|
|
147
|
+
return redactLogText;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { maskUrlCredentials, scrubKnownSecrets } from "@camstack/types/addon";
|
|
2
|
+
//#region src/logging/log-redactor.ts
|
|
3
|
+
var REDACTED = "***";
|
|
4
|
+
/** Credential-named keys. Substring, case-insensitive; only STRING values are replaced. */
|
|
5
|
+
var SECRET_KEY_SUBSTRINGS = [
|
|
6
|
+
"password",
|
|
7
|
+
"passwd",
|
|
8
|
+
"secret",
|
|
9
|
+
"token",
|
|
10
|
+
"apikey",
|
|
11
|
+
"api_key",
|
|
12
|
+
"authkey",
|
|
13
|
+
"auth_key",
|
|
14
|
+
"privatekey",
|
|
15
|
+
"private_key",
|
|
16
|
+
"passphrase",
|
|
17
|
+
"credential",
|
|
18
|
+
"cookie"
|
|
19
|
+
];
|
|
20
|
+
/** True when a meta key names a credential. */
|
|
21
|
+
function isCredentialKeyName(key) {
|
|
22
|
+
const lower = key.toLowerCase();
|
|
23
|
+
return SECRET_KEY_SUBSTRINGS.some((needle) => lower.includes(needle));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Words that name a credential only as the LAST word of a key (`pin`, `adminPin`,
|
|
27
|
+
* `otp`, `apiKey`, `code`). Not part of the log net above: an error `code`
|
|
28
|
+
* is a string in most log meta, and `keyFrame` is not a key. Used where an
|
|
29
|
+
* argument bag is stored (D1022), where a wrongly hidden value costs less than
|
|
30
|
+
* a leaked code.
|
|
31
|
+
*/
|
|
32
|
+
var SECRET_LAST_WORDS = new Set([
|
|
33
|
+
"pin",
|
|
34
|
+
"pincode",
|
|
35
|
+
"passcode",
|
|
36
|
+
"otp",
|
|
37
|
+
"code",
|
|
38
|
+
"key"
|
|
39
|
+
]);
|
|
40
|
+
/** The last camelCase / snake_case / kebab-case word of a key, lowercased. */
|
|
41
|
+
function lastWord(key) {
|
|
42
|
+
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_-]+/);
|
|
43
|
+
return (words[words.length - 1] ?? "").toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
/** True for a credential-named key, or one whose last word is a code, pin, otp or key. */
|
|
46
|
+
function isSecretArgumentKey(key) {
|
|
47
|
+
return isCredentialKeyName(key) || SECRET_LAST_WORDS.has(lastWord(key));
|
|
48
|
+
}
|
|
49
|
+
var URL_IN_TEXT = /\b[a-z][a-z0-9+.-]*:\/\/[^\s"'<>`]+/gi;
|
|
50
|
+
/** A root-relative path WITH a query, as request logs print it. */
|
|
51
|
+
var RELATIVE_URL_IN_TEXT = /(^|[\s"'(=])(\/[^\s"'<>`?]*\?[^\s"'<>`]+)/g;
|
|
52
|
+
var CREDENTIAL_FLAG = /(--(?:token|auth-?key|password|passwd|pass|secret|api-?key|access-?token|refresh-?token)(?:=|\s+))(\S+)/gi;
|
|
53
|
+
/** Redact one free-form string. */
|
|
54
|
+
function redactLogText(text) {
|
|
55
|
+
let out = scrubKnownSecrets(text);
|
|
56
|
+
if (out.includes("://")) out = out.replace(URL_IN_TEXT, (url) => maskUrlCredentials(url));
|
|
57
|
+
if (out.includes("/") && out.includes("?") && out.includes("=")) out = out.replace(RELATIVE_URL_IN_TEXT, (_m, lead, path) => `${lead}${maskUrlCredentials(path)}`);
|
|
58
|
+
if (out.includes("--")) out = out.replace(CREDENTIAL_FLAG, (_m, flag, value) => value.startsWith("‹secret:") ? `${flag}${value}` : `${flag}${REDACTED}`);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/** Bounds on the meta walk — a log line is not a place to traverse a graph. */
|
|
62
|
+
var MAX_DEPTH = 8;
|
|
63
|
+
var MAX_NODES = 2e3;
|
|
64
|
+
/**
|
|
65
|
+
* Redact a value, returning the SAME reference when nothing in it changed —
|
|
66
|
+
* most lines carry clean meta, and copying every one would put an allocation
|
|
67
|
+
* per log line on hub-main's event loop.
|
|
68
|
+
*/
|
|
69
|
+
function redactValue(value, depth, budget, seen) {
|
|
70
|
+
if (budget.nodes++ > MAX_NODES) return value;
|
|
71
|
+
if (typeof value === "string") return redactLogText(value);
|
|
72
|
+
if (value === null || typeof value !== "object") return value;
|
|
73
|
+
if (depth >= MAX_DEPTH || seen.has(value)) return value;
|
|
74
|
+
if (value instanceof Error) {
|
|
75
|
+
const message = redactLogText(value.message);
|
|
76
|
+
return message === value.message ? value : message;
|
|
77
|
+
}
|
|
78
|
+
if (value instanceof Date || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return value;
|
|
79
|
+
seen.add(value);
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
let copy = null;
|
|
82
|
+
for (let i = 0; i < value.length; i++) {
|
|
83
|
+
const item = value[i];
|
|
84
|
+
const next = redactValue(item, depth + 1, budget, seen);
|
|
85
|
+
if (next !== item) {
|
|
86
|
+
copy ??= [...value];
|
|
87
|
+
copy[i] = next;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return copy ?? value;
|
|
91
|
+
}
|
|
92
|
+
let copy = null;
|
|
93
|
+
for (const [key, child] of Object.entries(value)) {
|
|
94
|
+
const next = typeof child === "string" && child.length > 0 && isCredentialKeyName(key) ? REDACTED : redactValue(child, depth + 1, budget, seen);
|
|
95
|
+
if (next !== child) {
|
|
96
|
+
copy ??= { ...value };
|
|
97
|
+
copy[key] = next;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return copy ?? value;
|
|
101
|
+
}
|
|
102
|
+
/** Redact a `meta` record; the same object back when it was already clean. */
|
|
103
|
+
function redactLogMeta(meta) {
|
|
104
|
+
const out = redactValue(meta, 0, { nodes: 0 }, /* @__PURE__ */ new WeakSet());
|
|
105
|
+
if (out === meta) return meta;
|
|
106
|
+
return out !== null && typeof out === "object" && !Array.isArray(out) ? Object.fromEntries(Object.entries(out)) : meta;
|
|
107
|
+
}
|
|
108
|
+
/** Redact a whole entry: message and meta. Tags are identifiers, left alone. */
|
|
109
|
+
function redactLogEntry(entry) {
|
|
110
|
+
const message = redactLogText(entry.message);
|
|
111
|
+
const meta = entry.meta !== void 0 ? redactLogMeta(entry.meta) : void 0;
|
|
112
|
+
if (message === entry.message && meta === entry.meta) return entry;
|
|
113
|
+
return {
|
|
114
|
+
...entry,
|
|
115
|
+
message,
|
|
116
|
+
...meta !== void 0 ? { meta } : {}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { redactLogText as a, redactLogMeta as i, isSecretArgumentKey as n, redactLogEntry as r, isCredentialKeyName as t };
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
import type { LogEntry } from "@camstack/types";
|
|
23
23
|
/** True when a meta key names a credential. */
|
|
24
24
|
export declare function isCredentialKeyName(key: string): boolean;
|
|
25
|
+
/** True for a credential-named key, or one whose last word is a code, pin, otp or key. */
|
|
26
|
+
export declare function isSecretArgumentKey(key: string): boolean;
|
|
25
27
|
/** Redact one free-form string. */
|
|
26
28
|
export declare function redactLogText(text: string): string;
|
|
27
29
|
/** Redact a `meta` record; the same object back when it was already clean. */
|