@lidofinance/api-logger 0.0.2
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 +36 -0
- package/dist/index.cjs +72 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +53 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @lidofinance/api-logger
|
|
2
|
+
|
|
3
|
+
Logger, which hides secrets from logs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
1. Authenticate to use GitHub registry as described in parent [README.md](../../../README.md).
|
|
8
|
+
2. `yarn add @lidofinance/api-logger`.
|
|
9
|
+
|
|
10
|
+
## Getting started
|
|
11
|
+
|
|
12
|
+
You just need to initialize it with secrets you want to hide, usually it's all secrets from `serverRuntimeConfig` ,
|
|
13
|
+
after that, you are free to use it as regular `console.log`.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import getConfig from 'next/config';
|
|
17
|
+
import { serverLoggerFactory } from '@lidofinance/api-logger';
|
|
18
|
+
|
|
19
|
+
const { serverRuntimeConfig } = getConfig();
|
|
20
|
+
const {
|
|
21
|
+
infuraApiKey,
|
|
22
|
+
alchemyApiKey,
|
|
23
|
+
subgraphMainnet,
|
|
24
|
+
subgraphGoerli,
|
|
25
|
+
} = serverRuntimeConfig;
|
|
26
|
+
|
|
27
|
+
export const serverLogger = serverLoggerFactory([
|
|
28
|
+
infuraApiKey,
|
|
29
|
+
alchemyApiKey,
|
|
30
|
+
subgraphMainnet,
|
|
31
|
+
subgraphGoerli,
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
serverLogger.log('Something common')
|
|
35
|
+
serverLogger.error(new Error('Some error'))
|
|
36
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var $dDFU1$darkobitsmaskstring = require("@darkobits/mask-string");
|
|
2
|
+
|
|
3
|
+
function $parcel$exportWildcard(dest, source) {
|
|
4
|
+
Object.keys(source).forEach(function(key) {
|
|
5
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(dest, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return source[key];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return dest;
|
|
18
|
+
}
|
|
19
|
+
function $parcel$interopDefault(a) {
|
|
20
|
+
return a && a.__esModule ? a.default : a;
|
|
21
|
+
}
|
|
22
|
+
function $parcel$export(e, n, v, s) {
|
|
23
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
24
|
+
}
|
|
25
|
+
var $2b0676a8d7ac44c3$exports = {};
|
|
26
|
+
|
|
27
|
+
$parcel$export($2b0676a8d7ac44c3$exports, "serverLoggerFactory", () => $2b0676a8d7ac44c3$export$937ae38af6b48c0f);
|
|
28
|
+
|
|
29
|
+
const $2b0676a8d7ac44c3$var$anyHex = new RegExp("0x[a-fA-F0-9]+", "ig");
|
|
30
|
+
const $2b0676a8d7ac44c3$var$anyEnsAddress = new RegExp("[a-zA-Z.]+\\.eth", "ig");
|
|
31
|
+
let $2b0676a8d7ac44c3$var$LEVEL;
|
|
32
|
+
(function(LEVEL1) {
|
|
33
|
+
LEVEL1["error"] = "error";
|
|
34
|
+
LEVEL1["warn"] = "warn";
|
|
35
|
+
LEVEL1["info"] = "info";
|
|
36
|
+
LEVEL1["debug"] = "debug";
|
|
37
|
+
LEVEL1["log"] = "log";
|
|
38
|
+
})($2b0676a8d7ac44c3$var$LEVEL || ($2b0676a8d7ac44c3$var$LEVEL = {}));
|
|
39
|
+
const $2b0676a8d7ac44c3$var$stringify = (data)=>data instanceof Error ? JSON.stringify({
|
|
40
|
+
message: data.message,
|
|
41
|
+
stack: data.stack
|
|
42
|
+
}) : JSON.stringify(data);
|
|
43
|
+
const $2b0676a8d7ac44c3$export$937ae38af6b48c0f = (secrets)=>{
|
|
44
|
+
const patterns = [
|
|
45
|
+
...secrets,
|
|
46
|
+
$2b0676a8d7ac44c3$var$anyHex,
|
|
47
|
+
$2b0676a8d7ac44c3$var$anyEnsAddress
|
|
48
|
+
].filter(Boolean);
|
|
49
|
+
// TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}
|
|
50
|
+
const mask = (message)=>(0, ($parcel$interopDefault($dDFU1$darkobitsmaskstring)))(patterns, message);
|
|
51
|
+
const log = (level)=>(...output)=>{
|
|
52
|
+
try {
|
|
53
|
+
console[level](...output.map($2b0676a8d7ac44c3$var$stringify).map(mask));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(error);
|
|
56
|
+
console.warn("Failed to sanitize output");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return process.env.NODE_ENV === "production" ? {
|
|
60
|
+
error: log($2b0676a8d7ac44c3$var$LEVEL.error),
|
|
61
|
+
warn: log($2b0676a8d7ac44c3$var$LEVEL.warn),
|
|
62
|
+
info: log($2b0676a8d7ac44c3$var$LEVEL.info),
|
|
63
|
+
debug: log($2b0676a8d7ac44c3$var$LEVEL.debug),
|
|
64
|
+
log: log($2b0676a8d7ac44c3$var$LEVEL.log)
|
|
65
|
+
} : console;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
$parcel$exportWildcard(module.exports, $2b0676a8d7ac44c3$exports);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA;AAEA,MAAM,4BAAM,GAAG,IAAI,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAA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AAE,GAAG,CAAC,2BAAK,CAAC,IAAI,CAAC;QACrB,IAAI,EAAE,GAAG,CAAC,2BAAK,CAAC,IAAI,CAAC;QACrB,KAAK,EAAE,GAAG,CAAC,2BAAK,CAAC,KAAK,CAAC;QACvB,GAAG,EAAE,GAAG,CAAC,2BAAK,CAAC,GAAG,CAAC;KACpB,GACD,OAAO,CAAA;CACZ;;ADvDD","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts"],"sourcesContent":["export * from './serverLoggerFactory'\n","import maskString from '@darkobits/mask-string'\n\nconst anyHex = new RegExp('0x[a-fA-F0-9]+', 'ig')\nconst anyEnsAddress = new RegExp('[a-zA-Z.]+\\\\.eth', 'ig')\n\nenum LEVEL {\n error = 'error',\n warn = 'warn',\n info = 'info',\n debug = 'debug',\n log = 'log',\n}\n\nconst stringify = (data: unknown) =>\n data instanceof Error\n ? // extract Error's non-enumerable props before stringifying\n JSON.stringify({\n message: data.message,\n stack: data.stack,\n })\n : JSON.stringify(data)\n\nexport type Logger = (...messages: unknown[]) => void\nexport type ServerLogger = {\n error: Logger\n warn: Logger\n info: Logger\n debug: Logger\n log: Logger\n}\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...secrets, anyHex, anyEnsAddress].filter(Boolean)\n // TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}\n const mask = (message: string): string => maskString(patterns, message)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](...output.map(stringify).map(mask))\n } catch (error) {\n console.error(error)\n console.warn('Failed to sanitize output')\n }\n }\n return process.env.NODE_ENV === 'production'\n ? {\n error: log(LEVEL.error),\n warn: log(LEVEL.warn),\n info: log(LEVEL.info),\n debug: log(LEVEL.debug),\n log: log(LEVEL.log),\n }\n : console\n}\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Logger = (...messages: unknown[]) => void;
|
|
2
|
+
export type ServerLogger = {
|
|
3
|
+
error: Logger;
|
|
4
|
+
warn: Logger;
|
|
5
|
+
info: Logger;
|
|
6
|
+
debug: Logger;
|
|
7
|
+
log: Logger;
|
|
8
|
+
};
|
|
9
|
+
export const serverLoggerFactory: (secrets: Array<RegExp | string>) => ServerLogger;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAqBA,qBAAqB,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AACrD,2BAA2B;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,OAAO,MAAM,+BAAgC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAG,YAwBrE,CAAA","sources":["packages/api/logger/src/src/serverLoggerFactory.ts","packages/api/logger/src/src/index.ts","packages/api/logger/src/index.ts"],"sourcesContent":[null,null,"export * from './serverLoggerFactory'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import $2Az7d$darkobitsmaskstring from "@darkobits/mask-string";
|
|
2
|
+
|
|
3
|
+
function $parcel$export(e, n, v, s) {
|
|
4
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
5
|
+
}
|
|
6
|
+
var $3e685537995feb8a$exports = {};
|
|
7
|
+
|
|
8
|
+
$parcel$export($3e685537995feb8a$exports, "serverLoggerFactory", () => $3e685537995feb8a$export$937ae38af6b48c0f);
|
|
9
|
+
|
|
10
|
+
const $3e685537995feb8a$var$anyHex = new RegExp("0x[a-fA-F0-9]+", "ig");
|
|
11
|
+
const $3e685537995feb8a$var$anyEnsAddress = new RegExp("[a-zA-Z.]+\\.eth", "ig");
|
|
12
|
+
let $3e685537995feb8a$var$LEVEL;
|
|
13
|
+
(function(LEVEL1) {
|
|
14
|
+
LEVEL1["error"] = "error";
|
|
15
|
+
LEVEL1["warn"] = "warn";
|
|
16
|
+
LEVEL1["info"] = "info";
|
|
17
|
+
LEVEL1["debug"] = "debug";
|
|
18
|
+
LEVEL1["log"] = "log";
|
|
19
|
+
})($3e685537995feb8a$var$LEVEL || ($3e685537995feb8a$var$LEVEL = {}));
|
|
20
|
+
const $3e685537995feb8a$var$stringify = (data)=>data instanceof Error ? JSON.stringify({
|
|
21
|
+
message: data.message,
|
|
22
|
+
stack: data.stack
|
|
23
|
+
}) : JSON.stringify(data);
|
|
24
|
+
const $3e685537995feb8a$export$937ae38af6b48c0f = (secrets)=>{
|
|
25
|
+
const patterns = [
|
|
26
|
+
...secrets,
|
|
27
|
+
$3e685537995feb8a$var$anyHex,
|
|
28
|
+
$3e685537995feb8a$var$anyEnsAddress
|
|
29
|
+
].filter(Boolean);
|
|
30
|
+
// TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}
|
|
31
|
+
const mask = (message)=>(0, $2Az7d$darkobitsmaskstring)(patterns, message);
|
|
32
|
+
const log = (level)=>(...output)=>{
|
|
33
|
+
try {
|
|
34
|
+
console[level](...output.map($3e685537995feb8a$var$stringify).map(mask));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
console.warn("Failed to sanitize output");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return process.env.NODE_ENV === "production" ? {
|
|
41
|
+
error: log($3e685537995feb8a$var$LEVEL.error),
|
|
42
|
+
warn: log($3e685537995feb8a$var$LEVEL.warn),
|
|
43
|
+
info: log($3e685537995feb8a$var$LEVEL.info),
|
|
44
|
+
debug: log($3e685537995feb8a$var$LEVEL.debug),
|
|
45
|
+
log: log($3e685537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,GAAG,CAAC,+BAAS,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACnD,CAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC;aAC1C;SACF;IACH,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GACxC;QACE,KAAK,EAAE,GAAG,CAAC,2BAAK,CAAC,KAAK,CAAC;QACvB,IAAI,EAAE,GAAG,CAAC,2BAAK,CAAC,IAAI,CAAC;QACrB,IAAI,EAAE,GAAG,CAAC,2BAAK,CAAC,IAAI,CAAC;QACrB,KAAK,EAAE,GAAG,CAAC,2BAAK,CAAC,KAAK,CAAC;QACvB,GAAG,EAAE,GAAG,CAAC,2BAAK,CAAC,GAAG,CAAC;KACpB,GACD,OAAO,CAAA;CACZ;;ADvDD","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts"],"sourcesContent":["export * from './serverLoggerFactory'\n","import maskString from '@darkobits/mask-string'\n\nconst anyHex = new RegExp('0x[a-fA-F0-9]+', 'ig')\nconst anyEnsAddress = new RegExp('[a-zA-Z.]+\\\\.eth', 'ig')\n\nenum LEVEL {\n error = 'error',\n warn = 'warn',\n info = 'info',\n debug = 'debug',\n log = 'log',\n}\n\nconst stringify = (data: unknown) =>\n data instanceof Error\n ? // extract Error's non-enumerable props before stringifying\n JSON.stringify({\n message: data.message,\n stack: data.stack,\n })\n : JSON.stringify(data)\n\nexport type Logger = (...messages: unknown[]) => void\nexport type ServerLogger = {\n error: Logger\n warn: Logger\n info: Logger\n debug: Logger\n log: Logger\n}\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...secrets, anyHex, anyEnsAddress].filter(Boolean)\n // TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}\n const mask = (message: string): string => maskString(patterns, message)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](...output.map(stringify).map(mask))\n } catch (error) {\n console.error(error)\n console.warn('Failed to sanitize output')\n }\n }\n return process.env.NODE_ENV === 'production'\n ? {\n error: log(LEVEL.error),\n warn: log(LEVEL.warn),\n info: log(LEVEL.info),\n debug: log(LEVEL.debug),\n log: log(LEVEL.log),\n }\n : console\n}\n"],"names":[],"version":3,"file":"index.mjs.map","sourceRoot":"../../../../"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lidofinance/api-logger",
|
|
3
|
+
"description": "API logger, which hides secrets",
|
|
4
|
+
"repository": "git@github.com:lidofinance/lido-ui-blocks.git",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "0.0.2",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">= 16"
|
|
12
|
+
},
|
|
13
|
+
"source": "./src/index.ts",
|
|
14
|
+
"main": "dist/index.cjs",
|
|
15
|
+
"module": "dist/index.mjs",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "parcel build",
|
|
19
|
+
"format": "prettier --check src",
|
|
20
|
+
"format:fix": "yarn format --write",
|
|
21
|
+
"types": "tsc --noEmit",
|
|
22
|
+
"test": "jest"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@darkobits/mask-string": "^2.0.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@lidofinance/config-prettier": "0.0.1",
|
|
29
|
+
"@types/jest": "^28.1.6",
|
|
30
|
+
"@types/node": "^18.0.6",
|
|
31
|
+
"jest": "^28.1.3",
|
|
32
|
+
"ts-jest": "^28.0.7"
|
|
33
|
+
}
|
|
34
|
+
}
|