@darksheep/express 2.0.1 → 2.1.1
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/CHANGELOG.md +28 -0
- package/express.d.ts +2 -2
- package/package.json +6 -6
- package/src/content-type/middleware.js +3 -2
- package/src/error-handler/http.handler.js +3 -1
- package/src/error-handler/json-schema.handler.js +5 -3
- package/src/error-handler/zod.handler.js +3 -1
- package/src/logger/filter.js +3 -1
- package/src/logger/middleware.js +7 -4
- package/src/not-found/middleware.js +9 -3
- package/src/request-id/middleware.js +1 -1
- package/types/content-type/middleware.d.ts +1 -1
- package/types/error-handler/http.handler.d.ts +3 -1
- package/types/error-handler/json-schema.handler.d.ts +2 -3
- package/types/error-handler/middleware.d.ts +1 -1
- package/types/error-handler/zod.handler.d.ts +3 -1
- package/types/logger/filter.d.ts +3 -1
- package/types/not-found/middleware.d.ts +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.1](https://github.com/DarkSheepSoftware/node-packages/compare/express-v2.1.0...express-v2.1.1) (2025-12-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### 📚 Documentation
|
|
7
|
+
|
|
8
|
+
* fix issue in example ([#797](https://github.com/DarkSheepSoftware/node-packages/issues/797)) ([c889a98](https://github.com/DarkSheepSoftware/node-packages/commit/c889a980ea4b6cbe970eac7627d8229becddbe83))
|
|
9
|
+
|
|
10
|
+
## [2.1.0](https://github.com/DarkSheepSoftware/node-packages/compare/express-v2.0.1...express-v2.1.0) (2025-10-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### 🌟 Features
|
|
14
|
+
|
|
15
|
+
* Support node 24 ([#761](https://github.com/DarkSheepSoftware/node-packages/issues/761)) ([f13caae](https://github.com/DarkSheepSoftware/node-packages/commit/f13caaef978c7a657e4599f775e0a62d1738f475))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Dependencies
|
|
19
|
+
|
|
20
|
+
* The following workspace dependencies were updated
|
|
21
|
+
* dependencies
|
|
22
|
+
* @darksheep/errors bumped from 1.1.1 to 1.2.0
|
|
23
|
+
* @darksheep/prune bumped from 1.0.4 to 1.1.0
|
|
24
|
+
* devDependencies
|
|
25
|
+
* @darksheep/json-schema bumped to 0.1.1
|
|
26
|
+
* @darksheep/logger bumped from 1.2.0 to 1.3.0
|
|
27
|
+
* peerDependencies
|
|
28
|
+
* @darksheep/json-schema bumped to 0.1.1
|
|
29
|
+
* @darksheep/logger bumped from >=1.0.10 to >=1.3.0
|
|
30
|
+
|
|
3
31
|
## [2.0.1](https://github.com/DarkSheepSoftware/node-packages/compare/express-v2.0.0...express-v2.0.1) (2025-09-17)
|
|
4
32
|
|
|
5
33
|
|
package/express.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/consistent-type-definitions: 0 */
|
|
2
2
|
import { type Logger } from '@darksheep/logger';
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export interface ApiError {
|
|
5
5
|
message?: string;
|
|
6
6
|
name: string;
|
|
7
7
|
path?: (number | string)[] | string;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
|
|
10
10
|
export type ErrorHandler<E extends Error = Error> = {
|
|
11
11
|
format(error: E): ApiError[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darksheep/express",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "express utilites and other bits",
|
|
5
5
|
"license": "UNLICENCED",
|
|
6
6
|
"type": "module",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"test:watch": "node --watch --test src/**/*.test.js"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@darksheep/errors": "1.
|
|
26
|
-
"@darksheep/prune": "1.0
|
|
25
|
+
"@darksheep/errors": "1.2.0",
|
|
26
|
+
"@darksheep/prune": "1.1.0",
|
|
27
27
|
"on-finished": "2.4.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@darksheep/json-schema": "",
|
|
31
|
-
"@darksheep/logger": "1.
|
|
31
|
+
"@darksheep/logger": "1.3.0",
|
|
32
32
|
"@types/express": "~5.0.0",
|
|
33
33
|
"@types/on-finished": "^2",
|
|
34
|
-
"express": "~5.
|
|
34
|
+
"express": "~5.2.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@darksheep/json-schema": "",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": "^20.13.1 ||
|
|
50
|
+
"node": "^20.13.1 || >=22.2.0"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -22,14 +22,15 @@ export function createContentTypeMiddleware(targetContentTypes, shouldThrow = tr
|
|
|
22
22
|
provided != null &&
|
|
23
23
|
contentTypes.has(provided)
|
|
24
24
|
) {
|
|
25
|
-
|
|
25
|
+
next();
|
|
26
|
+
return;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
if (shouldThrow === true) {
|
|
29
30
|
return unsupportedMediaType(request, response, next);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
next('route');
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* @property {Record<string, string> | undefined} headers - Additional headers to send.
|
|
9
9
|
* @property {number} statusCode - The response status code.
|
|
10
10
|
*/
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Error & HttpErrorExtra} HttpError
|
|
13
|
+
*/
|
|
12
14
|
|
|
13
15
|
/** @type {ErrorHandler<HttpError>} */
|
|
14
16
|
export const HttpErrorHandler = {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @import * as JsonSchema from '@darksheep/json-schema';
|
|
2
3
|
* @import { ErrorHandler } from '../../express.js';
|
|
3
4
|
* @import { RequestSchemaError, ResponseSchemaError } from '@darksheep/json-schema';
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* @type {
|
|
8
|
+
* @type {JsonSchema}
|
|
8
9
|
*/
|
|
9
10
|
let schema;
|
|
10
11
|
try {
|
|
@@ -33,8 +34,9 @@ export const SchemaErrorHandler = {
|
|
|
33
34
|
format(error) {
|
|
34
35
|
const base = HttpErrorHandler.format(error);
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
for (const child of error.errors) {
|
|
38
|
+
base.push(Object.assign(child, { name: child.keyword }));
|
|
39
|
+
}
|
|
38
40
|
|
|
39
41
|
return base;
|
|
40
42
|
},
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* @property {string} code - The zod error code text.
|
|
9
9
|
* @property {string} path - The path to the error in zod.
|
|
10
10
|
*/
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Error & { errors: ZodIssue[] }} ZodError
|
|
13
|
+
*/
|
|
12
14
|
|
|
13
15
|
/** @type {ErrorHandler<ZodError>} */
|
|
14
16
|
export const ZodErrorHandler = {
|
package/src/logger/filter.js
CHANGED
package/src/logger/middleware.js
CHANGED
|
@@ -34,7 +34,8 @@ export function createRequestLoggerMiddleware(
|
|
|
34
34
|
requestPath == null ||
|
|
35
35
|
shouldFilterOutRequest(requestPath, filters)
|
|
36
36
|
) {
|
|
37
|
-
|
|
37
|
+
next();
|
|
38
|
+
return;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const startBytesRead = sockets.get(request.socket) ?? 0;
|
|
@@ -61,14 +62,16 @@ export function createRequestLoggerMiddleware(
|
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
if (response.statusCode < 400) {
|
|
64
|
-
|
|
65
|
+
request.logger.info(message, context);
|
|
66
|
+
return;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
if (response.statusCode < 500) {
|
|
68
|
-
|
|
70
|
+
request.logger.warning(message, context);
|
|
71
|
+
return;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
request.logger.error(message, context);
|
|
72
75
|
});
|
|
73
76
|
|
|
74
77
|
next();
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import {
|
|
2
|
+
* @import { NextFunction } from 'express'
|
|
3
|
+
* @import { Request, Response } from '../../express.js'
|
|
3
4
|
*/
|
|
4
5
|
import { NotFound } from '@darksheep/errors';
|
|
5
6
|
|
|
6
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* @param {Request} request - The express request.
|
|
9
|
+
* @param {Response} _response - The express response.
|
|
10
|
+
* @param {NextFunction} next - The next handler.
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
7
13
|
export function notFoundMiddleware(request, _response, next) {
|
|
8
|
-
|
|
14
|
+
next(
|
|
9
15
|
new NotFound(`${request.method} ${request.originalUrl}`),
|
|
10
16
|
);
|
|
11
17
|
}
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* @returns {Handler}
|
|
5
5
|
*/
|
|
6
6
|
export function createContentTypeMiddleware(targetContentTypes: string | string[], shouldThrow?: boolean): Handler;
|
|
7
|
-
export function unsupportedMediaType(req: import(".store/@types-express-serve-static-core-npm-5.0
|
|
7
|
+
export function unsupportedMediaType(req: import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").Request<import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").ParamsDictionary, any, any, import(".store/@types-qs-npm-6.14.0-e27d9ca044/package").ParsedQs, Record<string, any>>, res: import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").Response<any, Record<string, any>, number>, next: import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").NextFunction): unknown;
|
|
8
8
|
import type { Handler } from '../../express.js';
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* @property {Record<string, string> | undefined} headers - Additional headers to send.
|
|
8
8
|
* @property {number} statusCode - The response status code.
|
|
9
9
|
*/
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Error & HttpErrorExtra} HttpError
|
|
12
|
+
*/
|
|
11
13
|
/** @type {ErrorHandler<HttpError>} */
|
|
12
14
|
export const HttpErrorHandler: ErrorHandler<HttpError>;
|
|
13
15
|
export type HttpErrorExtra = {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @type {ErrorHandler<RequestSchemaError | ResponseSchemaError>} */
|
|
2
|
-
export const SchemaErrorHandler: ErrorHandler<RequestSchemaError | ResponseSchemaError>;
|
|
3
|
-
import type
|
|
4
|
-
import type { ResponseSchemaError } from '@darksheep/json-schema';
|
|
2
|
+
export const SchemaErrorHandler: ErrorHandler<JsonSchema.RequestSchemaError | JsonSchema.ResponseSchemaError>;
|
|
3
|
+
import type * as JsonSchema from '@darksheep/json-schema';
|
|
5
4
|
import type { ErrorHandler } from '../../express.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function errorHandlerMiddleware(err: any, req: import(".store/@types-express-serve-static-core-npm-5.0
|
|
1
|
+
export function errorHandlerMiddleware(err: any, req: import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").Request<import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").ParamsDictionary, any, any, import(".store/@types-qs-npm-6.14.0-e27d9ca044/package").ParsedQs, Record<string, any>>, res: import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").Response<any, Record<string, any>, number>, next: import(".store/@types-express-serve-static-core-npm-5.1.0-227fccbb7d/package").NextFunction): unknown;
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* @property {string} code - The zod error code text.
|
|
8
8
|
* @property {string} path - The path to the error in zod.
|
|
9
9
|
*/
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Error & { errors: ZodIssue[] }} ZodError
|
|
12
|
+
*/
|
|
11
13
|
/** @type {ErrorHandler<ZodError>} */
|
|
12
14
|
export const ZodErrorHandler: ErrorHandler<ZodError>;
|
|
13
15
|
export type ZodIssue = {
|
package/types/logger/filter.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Request} request - The express request.
|
|
3
|
+
* @param {Response} _response - The express response.
|
|
4
|
+
* @param {NextFunction} next - The next handler.
|
|
5
|
+
* @returns {void}
|
|
6
|
+
*/
|
|
7
|
+
export function notFoundMiddleware(request: Request, _response: Response, next: NextFunction): void;
|
|
8
|
+
import type { Request } from '../../express.js';
|
|
9
|
+
import type { Response } from '../../express.js';
|
|
10
|
+
import type { NextFunction } from 'express';
|