@forklaunch/express 0.2.8 → 0.3.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/lib/index.d.mts CHANGED
@@ -83,7 +83,7 @@ declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}
83
83
  * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
84
84
  * @template LocalsObj - A type for local variables, defaulting to an empty object.
85
85
  */
86
- interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, Omit<Request$1<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers'> {
86
+ interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, Omit<Request$1<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers' | 'path'> {
87
87
  }
88
88
  /**
89
89
  * Extends the Forklaunch response interface with properties from Express's response interface.
package/lib/index.d.ts CHANGED
@@ -83,7 +83,7 @@ declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}
83
83
  * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
84
84
  * @template LocalsObj - A type for local variables, defaulting to an empty object.
85
85
  */
86
- interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, Omit<Request$1<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers'> {
86
+ interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, Omit<Request$1<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers' | 'path'> {
87
87
  }
88
88
  /**
89
89
  * Extends the Forklaunch response interface with properties from Express's response interface.
package/lib/index.js CHANGED
@@ -51,18 +51,42 @@ var Application = class extends import_http.ForklaunchExpressLikeApplication {
51
51
  listen(...args) {
52
52
  const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
53
53
  this.internal.use(
54
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
54
+ `/api/${process.env.VERSION ?? "v1"}/swagger`,
55
55
  import_swagger_ui_express.default.serve,
56
56
  import_swagger_ui_express.default.setup(
57
57
  (0, import_http.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
58
58
  )
59
59
  );
60
- const errorHandler = (err, _req, res, _next) => {
61
- console.error(err);
60
+ import("@scalar/express-api-reference").then(({ apiReference }) => {
61
+ this.internal.use(
62
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
63
+ apiReference({
64
+ spec: {
65
+ content: (0, import_http.generateSwaggerDocument)(
66
+ this.schemaValidator,
67
+ port,
68
+ this.routers
69
+ )
70
+ }
71
+ })
72
+ );
73
+ }).catch((error) => {
74
+ console.warn("Failed to load Scalar API reference:", error);
75
+ });
76
+ const errorHandler = (err, req, res, _next) => {
62
77
  res.locals.errorMessage = err.message;
63
78
  res.status(res.statusCode && res.statusCode >= 400 ? res.statusCode : 500).send(`Internal server error:
64
79
 
65
80
  ${err.message}`);
81
+ (0, import_http.emitLoggerError)(
82
+ {
83
+ contractDetails: { name: "unknown" },
84
+ originalPath: req.route?.path,
85
+ ...req
86
+ },
87
+ res,
88
+ err.stack ?? err.message
89
+ );
66
90
  };
67
91
  this.internal.use(errorHandler);
68
92
  return this.internal.listen(...args);
@@ -81,12 +105,15 @@ function enrichResponseTransmission(req, res, next) {
81
105
  const originalSetHeader = res.setHeader;
82
106
  res.json = function(data) {
83
107
  res.bodyData = data;
84
- return originalJson.call(this, data);
108
+ (0, import_http2.enrichExpressLikeSend)(this, req, res, originalJson, data, !res.cors);
109
+ (0, import_http2.recordMetric)(req, res);
110
+ return data;
85
111
  };
86
112
  res.send = function(data) {
87
113
  if (!res.bodyData) {
88
114
  res.bodyData = data;
89
115
  }
116
+ (0, import_http2.recordMetric)(req, res);
90
117
  return (0, import_http2.enrichExpressLikeSend)(this, req, res, originalSend, data, !res.cors);
91
118
  };
92
119
  res.setHeader = function(name, value) {
package/lib/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/expressApplication.ts
2
2
  import {
3
+ emitLoggerError,
3
4
  ForklaunchExpressLikeApplication,
4
5
  generateSwaggerDocument
5
6
  } from "@forklaunch/core/http";
@@ -17,18 +18,42 @@ var Application = class extends ForklaunchExpressLikeApplication {
17
18
  listen(...args) {
18
19
  const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
19
20
  this.internal.use(
20
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
21
+ `/api/${process.env.VERSION ?? "v1"}/swagger`,
21
22
  swaggerUi.serve,
22
23
  swaggerUi.setup(
23
24
  generateSwaggerDocument(this.schemaValidator, port, this.routers)
24
25
  )
25
26
  );
26
- const errorHandler = (err, _req, res, _next) => {
27
- console.error(err);
27
+ import("@scalar/express-api-reference").then(({ apiReference }) => {
28
+ this.internal.use(
29
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
30
+ apiReference({
31
+ spec: {
32
+ content: generateSwaggerDocument(
33
+ this.schemaValidator,
34
+ port,
35
+ this.routers
36
+ )
37
+ }
38
+ })
39
+ );
40
+ }).catch((error) => {
41
+ console.warn("Failed to load Scalar API reference:", error);
42
+ });
43
+ const errorHandler = (err, req, res, _next) => {
28
44
  res.locals.errorMessage = err.message;
29
45
  res.status(res.statusCode && res.statusCode >= 400 ? res.statusCode : 500).send(`Internal server error:
30
46
 
31
47
  ${err.message}`);
48
+ emitLoggerError(
49
+ {
50
+ contractDetails: { name: "unknown" },
51
+ originalPath: req.route?.path,
52
+ ...req
53
+ },
54
+ res,
55
+ err.stack ?? err.message
56
+ );
32
57
  };
33
58
  this.internal.use(errorHandler);
34
59
  return this.internal.listen(...args);
@@ -42,19 +67,25 @@ import {
42
67
  import express2 from "express";
43
68
 
44
69
  // src/middleware/response.middleware.ts
45
- import { enrichExpressLikeSend } from "@forklaunch/core/http";
70
+ import {
71
+ enrichExpressLikeSend,
72
+ recordMetric
73
+ } from "@forklaunch/core/http";
46
74
  function enrichResponseTransmission(req, res, next) {
47
75
  const originalSend = res.send;
48
76
  const originalJson = res.json;
49
77
  const originalSetHeader = res.setHeader;
50
78
  res.json = function(data) {
51
79
  res.bodyData = data;
52
- return originalJson.call(this, data);
80
+ enrichExpressLikeSend(this, req, res, originalJson, data, !res.cors);
81
+ recordMetric(req, res);
82
+ return data;
53
83
  };
54
84
  res.send = function(data) {
55
85
  if (!res.bodyData) {
56
86
  res.bodyData = data;
57
87
  }
88
+ recordMetric(req, res);
58
89
  return enrichExpressLikeSend(this, req, res, originalSend, data, !res.cors);
59
90
  };
60
91
  res.setHeader = function(name, value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/express",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Forklaunch framework for express.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -25,6 +25,7 @@
25
25
  "lib/**"
26
26
  ],
27
27
  "dependencies": {
28
+ "@scalar/express-api-reference": "^0.4.186",
28
29
  "@types/express": "^5.0.0",
29
30
  "cors": "^2.8.5",
30
31
  "express": "^4.21.2",
@@ -32,22 +33,22 @@
32
33
  "swagger-ui-express": "^5.0.1",
33
34
  "@forklaunch/common": "0.2.1",
34
35
  "@forklaunch/validator": "0.4.4",
35
- "@forklaunch/core": "0.3.6"
36
+ "@forklaunch/core": "0.4.0"
36
37
  },
37
38
  "devDependencies": {
38
- "@eslint/js": "^9.20.0",
39
+ "@eslint/js": "^9.21.0",
39
40
  "@types/cors": "^2.8.17",
40
41
  "@types/jest": "^29.5.14",
41
42
  "@types/qs": "^6.9.18",
42
- "@types/swagger-ui-express": "^4.1.7",
43
+ "@types/swagger-ui-express": "^4.1.8",
43
44
  "jest": "^29.7.0",
44
45
  "kill-port-process": "^3.2.1",
45
- "prettier": "^3.5.1",
46
- "ts-jest": "^29.2.5",
46
+ "prettier": "^3.5.2",
47
+ "ts-jest": "^29.2.6",
47
48
  "ts-node": "^10.9.2",
48
- "tsup": "^8.3.6",
49
- "typescript": "^5.7.3",
50
- "typescript-eslint": "^8.24.0"
49
+ "tsup": "^8.4.0",
50
+ "typescript": "^5.8.2",
51
+ "typescript-eslint": "^8.25.0"
51
52
  },
52
53
  "scripts": {
53
54
  "build": "tsc --noEmit && tsup index.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",