unnbound-logger-sdk 3.0.19 → 3.0.20

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 CHANGED
@@ -395,6 +395,7 @@ app.use(traceMiddleware(options?: HttpOptions));
395
395
  **HttpOptions:**
396
396
 
397
397
  - `traceHeaderKey?: string` - Custom trace header name (default: 'x-unnbound-trace-id')
398
+ - `messageHeaderKey?: string` - Custom message header name (default: 'x-message-id')
398
399
  - `ignoreTraceRoutes?: string[]` - Routes to ignore in middleware (default: ['/health', '/healthcheck'])
399
400
 
400
401
  ### traceAxios
@@ -6,5 +6,5 @@ interface Response {
6
6
  body?: unknown;
7
7
  }
8
8
  type GetPayload = (config: Request, res?: Response) => object;
9
- export declare const traceMiddleware: ({ ignoreTraceRoutes, traceHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => RequestHandler;
9
+ export declare const traceMiddleware: ({ ignoreTraceRoutes, traceHeaderKey, messageHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => RequestHandler;
10
10
  export {};
@@ -47,14 +47,16 @@ const buildIncomingHttpPayload = (req, res) => ({
47
47
  },
48
48
  });
49
49
  const getNoopPayload = () => ({});
50
- const traceMiddleware = ({ ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes, traceHeaderKey = types_1.defaultTraceHeaderKey, getPayload = getNoopPayload, } = {
50
+ const traceMiddleware = ({ ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes, traceHeaderKey = types_1.defaultTraceHeaderKey, messageHeaderKey = types_1.defaultMessageHeaderKey, getPayload = getNoopPayload, } = {
51
51
  ignoreTraceRoutes: types_1.defaultIgnoreTraceRoutes,
52
52
  traceHeaderKey: types_1.defaultTraceHeaderKey,
53
+ messageHeaderKey: types_1.defaultMessageHeaderKey,
53
54
  getPayload: getNoopPayload,
54
55
  }) => async (req, res, next) => {
55
56
  if ((0, utils_1.shouldIgnorePath)(req.path, ignoreTraceRoutes))
56
57
  return next();
57
58
  const traceId = req.header(traceHeaderKey) || (0, trace_1.getTraceId)();
59
+ const messageId = req.header(messageHeaderKey) || undefined;
58
60
  res.setHeader(traceHeaderKey, traceId);
59
61
  return await (0, trace_1.withTrace)(async () => {
60
62
  return await (0, span_1.startSpan)('Incoming HTTP request', async () => {
@@ -78,6 +80,6 @@ const traceMiddleware = ({ ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes,
78
80
  : undefined;
79
81
  return { ...buildIncomingHttpPayload(req, response), ...getPayload(req, response) };
80
82
  });
81
- }, { traceId });
83
+ }, messageId ? { traceId, messageId } : { traceId });
82
84
  };
83
85
  exports.traceMiddleware = traceMiddleware;
package/dist/trace.d.ts CHANGED
@@ -3,6 +3,11 @@
3
3
  * @returns A trace ID
4
4
  */
5
5
  export declare const getTraceId: () => string;
6
+ /**
7
+ * Generates a message ID
8
+ * @returns A message ID
9
+ */
10
+ export declare const getMessageId: () => string;
6
11
  /**
7
12
  * Runs a callback with a trace ID
8
13
  * @param callback - The callback to run
package/dist/trace.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withTrace = exports.getTraceId = void 0;
3
+ exports.withTrace = exports.getMessageId = exports.getTraceId = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const storage_1 = require("./storage");
6
6
  /**
@@ -9,6 +9,12 @@ const storage_1 = require("./storage");
9
9
  */
10
10
  const getTraceId = () => (0, uuid_1.v4)();
11
11
  exports.getTraceId = getTraceId;
12
+ /**
13
+ * Generates a message ID
14
+ * @returns A message ID
15
+ */
16
+ const getMessageId = () => (0, uuid_1.v4)();
17
+ exports.getMessageId = getMessageId;
12
18
  /**
13
19
  * Runs a callback with a trace ID
14
20
  * @param callback - The callback to run
@@ -18,6 +24,7 @@ exports.getTraceId = getTraceId;
18
24
  const withTrace = (callback, extra) => {
19
25
  const previous = storage_1.storage.getStore();
20
26
  const traceId = extra?.traceId ?? previous?.traceId ?? (0, exports.getTraceId)();
21
- return storage_1.storage.run({ ...previous, ...extra, traceId }, callback);
27
+ const messageId = extra?.messageId ?? previous?.messageId ?? (0, exports.getMessageId)();
28
+ return storage_1.storage.run({ ...previous, ...extra, traceId, messageId }, callback);
22
29
  };
23
30
  exports.withTrace = withTrace;
package/dist/types.d.ts CHANGED
@@ -69,7 +69,9 @@ export interface EdiPayload {
69
69
  export interface HttpOptions<G extends Function> {
70
70
  ignoreTraceRoutes?: string[];
71
71
  traceHeaderKey?: string;
72
+ messageHeaderKey?: string;
72
73
  getPayload?: G;
73
74
  }
74
75
  export declare const defaultIgnoreTraceRoutes: string[];
75
76
  export declare const defaultTraceHeaderKey = "x-unnbound-trace-id";
77
+ export declare const defaultMessageHeaderKey = "x-message-id";
package/dist/types.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * Type definitions for structured logging library
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defaultTraceHeaderKey = exports.defaultIgnoreTraceRoutes = void 0;
6
+ exports.defaultMessageHeaderKey = exports.defaultTraceHeaderKey = exports.defaultIgnoreTraceRoutes = void 0;
7
7
  exports.defaultIgnoreTraceRoutes = ['/health', '/healthcheck'];
8
8
  exports.defaultTraceHeaderKey = 'x-unnbound-trace-id';
9
+ exports.defaultMessageHeaderKey = 'x-message-id';
package/package.json CHANGED
@@ -1,9 +1,23 @@
1
1
  {
2
2
  "name": "unnbound-logger-sdk",
3
3
  "description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.",
4
- "version": "3.0.19",
4
+ "version": "3.0.20",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "jest",
10
+ "test:coverage": "jest --coverage",
11
+ "test:watch": "jest --watch",
12
+ "typecheck": "tsc -noEmit",
13
+ "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
14
+ "lint:fix": "pnpm lint --fix",
15
+ "format": "prettier --write .",
16
+ "format:check": "prettier --check .",
17
+ "prepublishOnly": "pnpm build",
18
+ "start:example": "npx --yes tsx --watch examples/node-express.ts",
19
+ "version:bump": "npm version patch"
20
+ },
7
21
  "keywords": [
8
22
  "logging",
9
23
  "typescript",
@@ -57,18 +71,5 @@
57
71
  "engines": {
58
72
  "node": ">=22"
59
73
  },
60
- "sideEffects": false,
61
- "scripts": {
62
- "build": "tsc",
63
- "test": "jest",
64
- "test:coverage": "jest --coverage",
65
- "test:watch": "jest --watch",
66
- "typecheck": "tsc -noEmit",
67
- "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
68
- "lint:fix": "pnpm lint --fix",
69
- "format": "prettier --write .",
70
- "format:check": "prettier --check .",
71
- "start:example": "npx --yes tsx --watch examples/node-express.ts",
72
- "version:bump": "npm version patch"
73
- }
74
- }
74
+ "sideEffects": false
75
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Unnbound Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.