mongodb-redact 1.1.7 → 1.2.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/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -22
- package/dist/index.js.map +1 -1
- package/dist/secrets.d.ts +8 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +30 -0
- package/dist/secrets.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +22 -0
- package/dist/utils.js.map +1 -0
- package/package.json +15 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Secret } from './secrets';
|
|
2
|
+
export declare function redact<T>(message: T, secrets?: Secret[] | undefined): T;
|
|
2
3
|
export default redact;
|
|
4
|
+
export type { Secret } from './secrets';
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,wBAAgB,MAAM,CAAC,CAAC,EACtB,OAAO,EAAE,CAAC,EACV,OAAO,GAAE,MAAM,EAAE,GAAG,SAAqB,GACxC,CAAC,CAsCH;AAED,eAAe,MAAM,CAAC;AACtB,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,34 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.redact = redact;
|
|
4
4
|
const regexes_1 = require("./regexes");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Object.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return true;
|
|
15
|
-
if (!Object.prototype.hasOwnProperty.call(proto, 'constructor'))
|
|
16
|
-
return false;
|
|
17
|
-
const ctor = proto.constructor;
|
|
18
|
-
if (typeof ctor !== 'function')
|
|
19
|
-
return ctor;
|
|
20
|
-
const ctorPrototype = Object.getPrototypeOf(ctor);
|
|
21
|
-
return Object.getPrototypeOf(ctorPrototype) === ctor.prototype;
|
|
22
|
-
}
|
|
23
|
-
function redact(message) {
|
|
24
|
-
if (isPlainObject(message)) {
|
|
25
|
-
return Object.fromEntries(Object.entries(message).map(([key, value]) => [key, redact(value)]));
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const secrets_1 = require("./secrets");
|
|
7
|
+
function redact(message, secrets = undefined) {
|
|
8
|
+
if ((0, utils_1.isPlainObject)(message)) {
|
|
9
|
+
const newMessage = Object.fromEntries(Object.entries(message).map(([key, value]) => [
|
|
10
|
+
key,
|
|
11
|
+
redact(value, secrets),
|
|
12
|
+
]));
|
|
13
|
+
return Object.setPrototypeOf(newMessage, Object.getPrototypeOf(message));
|
|
26
14
|
}
|
|
27
15
|
if (Array.isArray(message)) {
|
|
28
|
-
return message.map(redact);
|
|
16
|
+
return message.map((msg) => redact(msg, secrets));
|
|
29
17
|
}
|
|
30
18
|
if (typeof message !== 'string') {
|
|
31
19
|
return message;
|
|
32
20
|
}
|
|
21
|
+
if (secrets) {
|
|
22
|
+
message = (0, secrets_1.redactSecretsOnString)(message, secrets);
|
|
23
|
+
}
|
|
33
24
|
for (const [regex, replacement] of regexes_1.regexes) {
|
|
34
25
|
message = message.replace(regex, replacement);
|
|
35
26
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAKA,wBAyCC;AA9CD,uCAAoC;AACpC,mCAAwC;AACxC,uCAAkD;AAGlD,SAAgB,MAAM,CACpB,OAAU,EACV,UAAgC,SAAS;IAEzC,IAAI,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE,CAAC;QAE3B,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;YAC5C,GAAG;YACH,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;SACvB,CAAC,CACE,CAAC;QAIP,OAAO,MAAM,CAAC,cAAc,CAC1B,UAAU,EACV,MAAM,CAAC,cAAc,CAAC,OAAO,CAAkB,CAChD,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAE3B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAM,CAAC;IACzD,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAEhC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,GAAG,IAAA,+BAAqB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAGD,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,iBAAO,EAAE,CAAC;QAG3C,OAAO,GAAI,OAAsB,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAe,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kBAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const SECRET_KIND: readonly ["base64", "private key", "user", "password", "email", "ip", "url", "mongodb uri"];
|
|
2
|
+
export type SecretKind = (typeof SECRET_KIND)[number];
|
|
3
|
+
export type Secret = {
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly kind: SecretKind;
|
|
6
|
+
};
|
|
7
|
+
export declare function redactSecretsOnString<T extends string>(content: T, secrets: Secret[]): T;
|
|
8
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,6FASd,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,MAAM,EAAE,GAChB,CAAC,CAcH"}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SECRET_KIND = void 0;
|
|
7
|
+
exports.redactSecretsOnString = redactSecretsOnString;
|
|
8
|
+
const regexp_escape_1 = __importDefault(require("regexp.escape"));
|
|
9
|
+
exports.SECRET_KIND = [
|
|
10
|
+
'base64',
|
|
11
|
+
'private key',
|
|
12
|
+
'user',
|
|
13
|
+
'password',
|
|
14
|
+
'email',
|
|
15
|
+
'ip',
|
|
16
|
+
'url',
|
|
17
|
+
'mongodb uri',
|
|
18
|
+
];
|
|
19
|
+
function redactSecretsOnString(content, secrets) {
|
|
20
|
+
let result = content;
|
|
21
|
+
for (const { value, kind } of secrets) {
|
|
22
|
+
if (!exports.SECRET_KIND.includes(kind)) {
|
|
23
|
+
throw new Error(`Unknown secret kind ${kind}. Valid types: ${exports.SECRET_KIND.join(', ')}`);
|
|
24
|
+
}
|
|
25
|
+
const regex = new RegExp(`\\b${(0, regexp_escape_1.default)(value)}\\b`, 'g');
|
|
26
|
+
result = result.replace(regex, `<${kind}>`);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":";;;;;;AAsBA,sDAiBC;AArCD,kEAAmC;AAEtB,QAAA,WAAW,GAAG;IACzB,QAAQ;IACR,aAAa;IACb,MAAM;IACN,UAAU;IACV,OAAO;IACP,IAAI;IACJ,KAAK;IACL,aAAa;CACL,CAAC;AASX,SAAgB,qBAAqB,CACnC,OAAU,EACV,OAAiB;IAEjB,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC;QACtC,IAAI,CAAC,mBAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,uBAAuB,IAAI,kBAAkB,mBAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACtE,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,IAAA,uBAAM,EAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACxD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,GAAG,CAAM,CAAC;IACnD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAiBzD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPlainObject = isPlainObject;
|
|
4
|
+
const plainObjectTag = Object.prototype.toString.call({});
|
|
5
|
+
function isPlainObject(val) {
|
|
6
|
+
if (typeof val !== 'object' ||
|
|
7
|
+
!val ||
|
|
8
|
+
Object.prototype.toString.call(val) !== plainObjectTag) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const proto = Object.getPrototypeOf(val);
|
|
12
|
+
if (proto === null)
|
|
13
|
+
return true;
|
|
14
|
+
if (!Object.prototype.hasOwnProperty.call(proto, 'constructor'))
|
|
15
|
+
return false;
|
|
16
|
+
const ctor = proto.constructor;
|
|
17
|
+
if (typeof ctor !== 'function')
|
|
18
|
+
return false;
|
|
19
|
+
const ctorPrototype = Object.getPrototypeOf(ctor);
|
|
20
|
+
return Object.getPrototypeOf(ctorPrototype) === ctor.prototype;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAEA,sCAiBC;AAnBD,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAE1D,SAAgB,aAAa,CAAC,GAAY;IACxC,IACE,OAAO,GAAG,KAAK,QAAQ;QACvB,CAAC,GAAG;QACJ,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,cAAc,EACtD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC;IAC/B,IAAI,OAAO,IAAI,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAG7C,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"email": "compass@mongodb.com"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/mongodb-js/devtools-shared",
|
|
16
|
-
"version": "1.
|
|
16
|
+
"version": "1.2.0",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "https://github.com/mongodb-js/devtools-shared.git"
|
|
@@ -23,12 +23,17 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"main": "dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
26
27
|
"exports": {
|
|
27
|
-
"require":
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
"require": {
|
|
29
|
+
"default": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"default": "./dist/.esm-wrapper.mjs",
|
|
34
|
+
"types": "./dist/index.d.ts"
|
|
35
|
+
}
|
|
30
36
|
},
|
|
31
|
-
"types": "./dist/index.d.ts",
|
|
32
37
|
"scripts": {
|
|
33
38
|
"bootstrap": "npm run compile",
|
|
34
39
|
"prepublishOnly": "npm run compile",
|
|
@@ -53,6 +58,7 @@
|
|
|
53
58
|
"@mongodb-js/tsconfig-devtools": "^1.0.3",
|
|
54
59
|
"@types/chai": "^4.2.21",
|
|
55
60
|
"@types/mocha": "^9.1.1",
|
|
61
|
+
"@types/regexp.escape": "^2.0.0",
|
|
56
62
|
"@types/sinon-chai": "^3.2.5",
|
|
57
63
|
"chai": "^4.5.0",
|
|
58
64
|
"depcheck": "^1.4.7",
|
|
@@ -64,5 +70,8 @@
|
|
|
64
70
|
"sinon": "^9.2.3",
|
|
65
71
|
"typescript": "^5.0.4"
|
|
66
72
|
},
|
|
67
|
-
"
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"regexp.escape": "^2.0.1"
|
|
75
|
+
},
|
|
76
|
+
"gitHead": "2bbe0a7e81791ef069c7e136ff6a8873852ea247"
|
|
68
77
|
}
|