@n8io/baseline-logger 0.0.0-stage → 2.0.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.
@@ -0,0 +1,2 @@
1
+ import { Logger } from "pino";
2
+ export declare const logger: Logger;
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import { loggerErrSerialize } from "./logger-err-serialize.js";
2
+ import { pino } from "pino";
3
+ // src/logger-options.ts
4
+ const fieldsSecret = [
5
+ "accessToken",
6
+ "access_token",
7
+ "apiKey",
8
+ "authorization",
9
+ "cookie",
10
+ "idToken",
11
+ "id_token",
12
+ "password",
13
+ "refreshToken",
14
+ "refresh_token",
15
+ "set-cookie",
16
+ "token"
17
+ ];
18
+ const keyPath = (prefix, key) => /^\w+$/.test(key) ? `${prefix}${prefix === "" ? "" : "."}${key}` : `${prefix}["${key}"]`;
19
+ const loggerRedactPaths = fieldsSecret.flatMap((field) => [
20
+ "",
21
+ "*",
22
+ "*.headers",
23
+ "*.*.headers"
24
+ ].map((prefix) => keyPath(prefix, field)));
25
+ const errFind = (first) => {
26
+ if (first instanceof Error) return first;
27
+ if (typeof first === "object" && first !== null && "err" in first && !("msg" in first)) return first.err;
28
+ };
29
+ const loggerOptions = (level) => ({
30
+ hooks: { logMethod(args, method) {
31
+ const [first, second] = args;
32
+ const err = errFind(first);
33
+ if (err !== void 0 && typeof second !== "string") {
34
+ const type = loggerErrSerialize(err).type;
35
+ return method.apply(this, [first, type]);
36
+ }
37
+ return method.apply(this, args);
38
+ } },
39
+ level,
40
+ redact: {
41
+ censor: "[Redacted]",
42
+ paths: [...loggerRedactPaths]
43
+ },
44
+ serializers: { err: loggerErrSerialize }
45
+ });
46
+ // src/index.ts
47
+ const logger = pino(loggerOptions(process.env.LOG_LEVEL || "info"));
48
+ export { logger };
@@ -0,0 +1,8 @@
1
+ export type LoggerErr = {
2
+ cause?: LoggerErr;
3
+ code?: number | string;
4
+ constraint?: string;
5
+ stack?: string;
6
+ type: string;
7
+ };
8
+ export declare const loggerErrSerialize: (value: unknown) => LoggerErr;
@@ -0,0 +1,26 @@
1
+ // src/logger-err-serialize.ts
2
+ const causeDepthMax = 10;
3
+ const stackFrame = /^\s+at /;
4
+ const errType = (value) => {
5
+ if (value instanceof Error) return value.constructor.name || "Error";
6
+ return value === null ? "null" : typeof value;
7
+ };
8
+ const stackFrames = (error) => {
9
+ if (typeof error.stack !== "string") return;
10
+ const at = error.message === "" ? -1 : error.stack.indexOf(error.message);
11
+ const frames = (at === -1 ? error.stack : error.stack.slice(at + error.message.length)).split("\n").filter((line) => stackFrame.test(line)).map((line) => line.trim());
12
+ return frames.length > 0 ? frames.join("\n") : void 0;
13
+ };
14
+ const errSerialize = (value, depth) => {
15
+ const shape = { type: errType(value) };
16
+ if (!(value instanceof Error)) return shape;
17
+ const { code, constraint } = value;
18
+ if (typeof code === "string" || typeof code === "number") shape.code = code;
19
+ if (typeof constraint === "string") shape.constraint = constraint;
20
+ const stack = stackFrames(value);
21
+ if (stack !== void 0) shape.stack = stack;
22
+ if (value.cause !== void 0 && depth < causeDepthMax) shape.cause = errSerialize(value.cause, depth + 1);
23
+ return shape;
24
+ };
25
+ const loggerErrSerialize = (value) => errSerialize(value, 0);
26
+ export { loggerErrSerialize };
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@n8io/baseline-logger",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0",
4
+ "description": "The one pino logger every baseline app and package logs through.",
5
+ "type": "module",
6
+ "license": "UNLICENSED",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/n8io/baseline.git",
10
+ "directory": "packages/logger"
11
+ },
12
+ "engines": {
13
+ "node": ">=26"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./err-serialize": {
24
+ "types": "./dist/logger-err-serialize.d.ts",
25
+ "default": "./dist/logger-err-serialize.js"
26
+ }
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org"
31
+ },
32
+ "dependencies": {
33
+ "pino": "^10.4.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsdown",
37
+ "check": "tsc --noEmit && pnpm pack --out dist/package.tgz && publint dist/package.tgz --strict && attw dist/package.tgz --profile esm-only",
38
+ "test": "vitest run"
39
+ }
6
40
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.