@devmoods/express-extras 0.20.1 → 0.21.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/listen.d.ts CHANGED
@@ -9,5 +9,5 @@ import type * as http from 'node:http';
9
9
  export declare function listen(server: http.Server, options: {
10
10
  port: number;
11
11
  onShutdown?: () => void | Promise<void>;
12
- healthCheck?: () => Promise<void>;
12
+ healthCheck?: () => Promise<unknown>;
13
13
  }): void;
package/dist/listen.js CHANGED
@@ -34,13 +34,18 @@ export function listen(server, options) {
34
34
  return false;
35
35
  }
36
36
  try {
37
- await options?.healthCheck?.();
37
+ const meta = await options?.healthCheck?.();
38
+ return {
39
+ meta,
40
+ timestamp: new Date().toISOString(),
41
+ };
38
42
  }
39
43
  catch (error) {
40
44
  logger.error(error, 'health check failed');
41
45
  throw error;
42
46
  }
43
47
  },
48
+ verbatim: true,
44
49
  },
45
50
  });
46
51
  const port = options.port;
package/dist/logger.d.ts CHANGED
@@ -21,14 +21,14 @@ export declare function createLogger({ name, getContext, silent, }: LoggerOption
21
21
  debug(message: string, context?: LoggerContext): void;
22
22
  info(message: string, context?: LoggerContext): void;
23
23
  warn(message: string, context?: LoggerContext): void;
24
- error(error: Error | null, message?: string): void;
25
- fatal(error: Error | null, message?: string): void;
24
+ error(error: Error | null, message?: string, context?: LoggerContext): void;
25
+ fatal(error: Error | null, message?: string, context?: LoggerContext): void;
26
26
  };
27
27
  export declare function getLogger(name?: string): Logger;
28
28
  export declare function getLoggers(): Map<string, {
29
29
  debug(message: string, context?: LoggerContext): void;
30
30
  info(message: string, context?: LoggerContext): void;
31
31
  warn(message: string, context?: LoggerContext): void;
32
- error(error: Error | null, message?: string | undefined): void;
33
- fatal(error: Error | null, message?: string | undefined): void;
32
+ error(error: Error | null, message?: string | undefined, context?: LoggerContext): void;
33
+ fatal(error: Error | null, message?: string | undefined, context?: LoggerContext): void;
34
34
  }>;
package/dist/logger.js CHANGED
@@ -62,23 +62,29 @@ export function createLogger({ name, getContext, silent = () => process.env.NODE
62
62
  warn(message, context = {}) {
63
63
  return log(LEVELS.WARN, message, getFinalContext(context));
64
64
  },
65
- error(error, message) {
66
- const context = getFinalContext({ err: error?.stack });
65
+ error(error, message, context = {}) {
66
+ const finalContext = getFinalContext(context);
67
67
  if (_sentryClient != null) {
68
68
  _sentryClient.captureException(error, {
69
- tags: context,
69
+ tags: finalContext,
70
70
  });
71
71
  }
72
- return log(LEVELS.ERROR, message || error?.message || '', context);
72
+ return log(LEVELS.ERROR, message || error?.message || '', {
73
+ ...finalContext,
74
+ err: error?.stack,
75
+ });
73
76
  },
74
- fatal(error, message) {
75
- const context = getFinalContext({ err: error });
77
+ fatal(error, message, context = {}) {
78
+ const finalContext = getFinalContext(context);
76
79
  if (_sentryClient != null) {
77
80
  _sentryClient.captureException(error, {
78
- tags: context,
81
+ tags: finalContext,
79
82
  });
80
83
  }
81
- return log(LEVELS.FATAL, message || error?.message || '', context);
84
+ return log(LEVELS.FATAL, message || error?.message || '', {
85
+ ...finalContext,
86
+ err: error?.stack,
87
+ });
82
88
  },
83
89
  };
84
90
  _loggers.set(name, api);
package/dist/routes.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Application } from 'express';
2
- export declare function listRoutes(app: Application): string[];
1
+ import type { RequestHandler, Express } from 'express';
2
+ export declare function createDocsRouter(app: Express, extras?: Record<string, any>): RequestHandler;
package/dist/routes.js CHANGED
@@ -1,41 +1,10 @@
1
- function split(value) {
2
- if (typeof value === 'string') {
3
- return value;
4
- }
5
- else if (value.fast_slash) {
6
- return '';
7
- }
8
- else {
9
- const match = value
10
- .toString()
11
- .replace('/?', '')
12
- .replace('(?=/|$)', '$')
13
- .match(/^\/\^((?:\\[.*+?^${}()|[\]\\/]|[^.*+?^${}()|[\]\\/])*)\$\//);
14
- return match
15
- ? match[1].replace(/\\(.)/g, '$1')
16
- : '<complex:' + value.toString() + '>';
17
- }
18
- }
19
- function getRoutesOfLayer(path, layer) {
20
- if (layer.method) {
21
- return [{ method: layer.method.toUpperCase(), path }];
22
- }
23
- else if (layer.route) {
24
- return getRoutesOfLayer(path + split(layer.route.path), layer.route.stack[0]);
25
- }
26
- else if (layer.name === 'router' && layer.handle.stack) {
27
- let routes = [];
28
- layer.handle.stack.forEach(function (stackItem) {
29
- routes = routes.concat(getRoutesOfLayer(path + split(layer.regexp), stackItem));
30
- });
31
- return routes;
32
- }
33
- return [];
34
- }
35
- export function listRoutes(app) {
36
- const routes = [];
37
- for (const layer of app._router.stack) {
38
- routes.push(...getRoutesOfLayer('', layer));
39
- }
40
- return routes;
1
+ import { parseExpressApp } from 'express-route-parser';
2
+ import { route } from './middleware.js';
3
+ export function createDocsRouter(app, extras = {}) {
4
+ return route(() => {
5
+ return {
6
+ ...extras,
7
+ routes: parseExpressApp(app),
8
+ };
9
+ });
41
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devmoods/express-extras",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "description": "Kubernetes-ready utilities for rapid Node.js application development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -75,6 +75,7 @@
75
75
  "cookie-parser": "^1.4.6",
76
76
  "dotenv": "^16.3.1",
77
77
  "express": "^4.18.2",
78
+ "express-route-parser": "^1.0.5",
78
79
  "helmet": "^7.0.0",
79
80
  "jsonwebtoken": "^9.0.1",
80
81
  "meow": "^12.0.1",