@expressots/core 4.0.0-preview.1 → 4.0.0-preview.3
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/LICENSE.md +21 -21
- package/README.md +66 -66
- package/lib/CHANGELOG.md +774 -774
- package/lib/README.md +66 -66
- package/lib/cjs/application/application-factory.js +6 -0
- package/lib/cjs/application/bootstrap.js +117 -213
- package/lib/cjs/config/define-config.js +1 -1
- package/lib/cjs/config/env-field-builders.js +47 -0
- package/lib/cjs/config/index.js +7 -1
- package/lib/cjs/framework-version.js +10 -0
- package/lib/cjs/lazy-loading/index.js +5 -1
- package/lib/cjs/lazy-loading/lazy-module-helpers.js +49 -0
- package/lib/cjs/middleware/index.js +8 -9
- package/lib/cjs/middleware/middleware-service.js +68 -12
- package/lib/cjs/middleware/presets-standalone.js +93 -0
- package/lib/cjs/provider/db-in-memory/adapter/in-memory.adapter.js +23 -0
- package/lib/cjs/provider/db-in-memory/index.js +11 -1
- package/lib/cjs/provider/db-in-memory/query/query-engine.js +28 -0
- package/lib/cjs/provider/db-in-memory/schema/decorators.js +18 -0
- package/lib/cjs/provider/db-in-memory/storage/index.js +3 -1
- package/lib/cjs/provider/db-in-memory/storage/memory-store.js +72 -1
- package/lib/cjs/provider/logger/logger.banner.js +40 -31
- package/lib/cjs/provider/logger/logger.config.js +11 -1
- package/lib/cjs/provider/logger/logger.formatter.js +22 -1
- package/lib/cjs/provider/logger/logger.provider.js +59 -9
- package/lib/cjs/provider/logger/transports/console.transport.js +69 -6
- package/lib/cjs/provider/logger/transports/file.transport.js +27 -18
- package/lib/cjs/provider/logger/utils/log-levels.js +6 -5
- package/lib/cjs/provider/validation/adapters/index.js +12 -5
- package/lib/cjs/provider/validation/adapters/yup.adapter.js +118 -0
- package/lib/cjs/provider/validation/adapters/zod.adapter.js +137 -0
- package/lib/cjs/provider/validation/index.js +5 -1
- package/lib/cjs/render/adapters/react-adapter.js +14 -14
- package/lib/cjs/render/features/type-generator.js +30 -30
- package/lib/cjs/render/features/view-debugger.js +75 -55
- package/lib/cjs/testing/fluent-request.js +7 -0
- package/lib/cjs/testing/snapshot-request.js +2 -0
- package/lib/cjs/types/application/application-factory.d.ts +6 -0
- package/lib/cjs/types/application/bootstrap.d.ts +196 -24
- package/lib/cjs/types/config/config.interfaces.d.ts +7 -1
- package/lib/cjs/types/config/env-field-builders.d.ts +39 -0
- package/lib/cjs/types/config/index.d.ts +1 -1
- package/lib/cjs/types/framework-version.d.ts +7 -0
- package/lib/cjs/types/lazy-loading/index.d.ts +1 -0
- package/lib/cjs/types/lazy-loading/lazy-module-helpers.d.ts +42 -0
- package/lib/cjs/types/middleware/index.d.ts +1 -1
- package/lib/cjs/types/middleware/middleware-service.d.ts +21 -0
- package/lib/cjs/types/middleware/presets-standalone.d.ts +75 -0
- package/lib/cjs/types/provider/db-in-memory/adapter/in-memory.adapter.d.ts +2 -0
- package/lib/cjs/types/provider/db-in-memory/index.d.ts +9 -1
- package/lib/cjs/types/provider/db-in-memory/query/query-engine.d.ts +14 -1
- package/lib/cjs/types/provider/db-in-memory/schema/decorators.d.ts +14 -0
- package/lib/cjs/types/provider/db-in-memory/storage/index.d.ts +1 -1
- package/lib/cjs/types/provider/db-in-memory/storage/memory-store.d.ts +34 -0
- package/lib/cjs/types/provider/logger/logger.banner.d.ts +1 -1
- package/lib/cjs/types/provider/logger/logger.config.d.ts +7 -0
- package/lib/cjs/types/provider/logger/logger.formatter.d.ts +10 -0
- package/lib/cjs/types/provider/logger/logger.provider.d.ts +32 -1
- package/lib/cjs/types/provider/logger/transports/console.transport.d.ts +7 -0
- package/lib/cjs/types/provider/logger/utils/log-levels.d.ts +3 -3
- package/lib/cjs/types/provider/validation/adapters/index.d.ts +7 -4
- package/lib/cjs/types/provider/validation/adapters/yup.adapter.d.ts +65 -0
- package/lib/cjs/types/provider/validation/adapters/zod.adapter.d.ts +84 -0
- package/lib/cjs/types/provider/validation/index.d.ts +1 -1
- package/lib/cjs/types/render/features/view-debugger.d.ts +10 -0
- package/lib/cjs/types/testing/testing.interfaces.d.ts +31 -6
- package/lib/esm/application/application-factory.js +6 -0
- package/lib/esm/application/bootstrap.js +117 -213
- package/lib/esm/config/define-config.js +1 -1
- package/lib/esm/config/env-field-builders.js +48 -0
- package/lib/esm/config/index.js +6 -1
- package/lib/esm/framework-version.js +7 -0
- package/lib/esm/lazy-loading/index.js +2 -0
- package/lib/esm/lazy-loading/lazy-module-helpers.js +45 -0
- package/lib/esm/middleware/index.js +3 -2
- package/lib/esm/middleware/middleware-service.js +68 -12
- package/lib/esm/middleware/presets-standalone.js +87 -0
- package/lib/esm/provider/db-in-memory/adapter/in-memory.adapter.js +23 -0
- package/lib/esm/provider/db-in-memory/index.js +9 -1
- package/lib/esm/provider/db-in-memory/query/query-engine.js +28 -0
- package/lib/esm/provider/db-in-memory/schema/decorators.js +18 -0
- package/lib/esm/provider/db-in-memory/storage/index.js +1 -1
- package/lib/esm/provider/db-in-memory/storage/memory-store.js +75 -0
- package/lib/esm/provider/logger/logger.banner.js +40 -31
- package/lib/esm/provider/logger/logger.config.js +12 -2
- package/lib/esm/provider/logger/logger.formatter.js +22 -1
- package/lib/esm/provider/logger/logger.provider.js +61 -10
- package/lib/esm/provider/logger/transports/console.transport.js +69 -6
- package/lib/esm/provider/logger/transports/file.transport.js +27 -18
- package/lib/esm/provider/logger/utils/log-levels.js +6 -5
- package/lib/esm/provider/validation/adapters/index.js +7 -4
- package/lib/esm/provider/validation/adapters/yup.adapter.js +111 -0
- package/lib/esm/provider/validation/adapters/zod.adapter.js +130 -0
- package/lib/esm/provider/validation/index.js +1 -1
- package/lib/esm/render/adapters/react-adapter.js +14 -14
- package/lib/esm/render/features/type-generator.js +30 -30
- package/lib/esm/render/features/view-debugger.js +75 -55
- package/lib/esm/testing/fluent-request.js +7 -0
- package/lib/esm/testing/snapshot-request.js +2 -0
- package/lib/esm/types/application/application-factory.d.ts +6 -0
- package/lib/esm/types/application/bootstrap.d.ts +196 -24
- package/lib/esm/types/config/config.interfaces.d.ts +7 -1
- package/lib/esm/types/config/env-field-builders.d.ts +39 -0
- package/lib/esm/types/config/index.d.ts +1 -1
- package/lib/esm/types/framework-version.d.ts +7 -0
- package/lib/esm/types/lazy-loading/index.d.ts +1 -0
- package/lib/esm/types/lazy-loading/lazy-module-helpers.d.ts +42 -0
- package/lib/esm/types/middleware/index.d.ts +1 -1
- package/lib/esm/types/middleware/middleware-service.d.ts +21 -0
- package/lib/esm/types/middleware/presets-standalone.d.ts +75 -0
- package/lib/esm/types/provider/db-in-memory/adapter/in-memory.adapter.d.ts +2 -0
- package/lib/esm/types/provider/db-in-memory/index.d.ts +9 -1
- package/lib/esm/types/provider/db-in-memory/query/query-engine.d.ts +14 -1
- package/lib/esm/types/provider/db-in-memory/schema/decorators.d.ts +14 -0
- package/lib/esm/types/provider/db-in-memory/storage/index.d.ts +1 -1
- package/lib/esm/types/provider/db-in-memory/storage/memory-store.d.ts +34 -0
- package/lib/esm/types/provider/logger/logger.banner.d.ts +1 -1
- package/lib/esm/types/provider/logger/logger.config.d.ts +7 -0
- package/lib/esm/types/provider/logger/logger.formatter.d.ts +10 -0
- package/lib/esm/types/provider/logger/logger.provider.d.ts +32 -1
- package/lib/esm/types/provider/logger/transports/console.transport.d.ts +7 -0
- package/lib/esm/types/provider/logger/utils/log-levels.d.ts +3 -3
- package/lib/esm/types/provider/validation/adapters/index.d.ts +7 -4
- package/lib/esm/types/provider/validation/adapters/yup.adapter.d.ts +65 -0
- package/lib/esm/types/provider/validation/adapters/zod.adapter.d.ts +84 -0
- package/lib/esm/types/provider/validation/index.d.ts +1 -1
- package/lib/esm/types/render/features/view-debugger.d.ts +10 -0
- package/lib/esm/types/testing/testing.interfaces.d.ts +31 -6
- package/lib/package.json +23 -8
- package/package.json +23 -8
- package/lib/cjs/middleware/middleware-presets.js +0 -294
- package/lib/cjs/types/middleware/middleware-presets.d.ts +0 -90
- package/lib/esm/middleware/middleware-presets.js +0 -286
- package/lib/esm/types/middleware/middleware-presets.d.ts +0 -90
|
@@ -345,13 +345,15 @@ export interface FluentRequest {
|
|
|
345
345
|
*/
|
|
346
346
|
expect<T>(assertion: (response: FluentResponse<T>) => void): FluentRequest;
|
|
347
347
|
/**
|
|
348
|
-
* Execute the request and return the response.
|
|
348
|
+
* Execute the request and return the response. Body type defaults to
|
|
349
|
+
* `any` for ergonomic test code — see {@link FluentResponse} for the
|
|
350
|
+
* rationale and how to opt into strict typing via `<T>`.
|
|
349
351
|
*/
|
|
350
|
-
execute<T =
|
|
352
|
+
execute<T = any>(): Promise<FluentResponse<T>>;
|
|
351
353
|
/**
|
|
352
354
|
* Alias for execute().
|
|
353
355
|
*/
|
|
354
|
-
end<T =
|
|
356
|
+
end<T = any>(): Promise<FluentResponse<T>>;
|
|
355
357
|
}
|
|
356
358
|
/**
|
|
357
359
|
* Time assertion options for performance testing.
|
|
@@ -372,8 +374,30 @@ export interface TimeAssertion {
|
|
|
372
374
|
}
|
|
373
375
|
/**
|
|
374
376
|
* Fluent response object.
|
|
377
|
+
*
|
|
378
|
+
* The body type defaults to `any` rather than `unknown` — this is a
|
|
379
|
+
* deliberate ergonomics call for a *test-time* HTTP client API.
|
|
380
|
+
*
|
|
381
|
+
* Tests written against ExpressoTS controllers usually look like:
|
|
382
|
+
*
|
|
383
|
+
* const r = await testApp.request.get("/users/1").execute();
|
|
384
|
+
* expect(r.body.id).toBe(1);
|
|
385
|
+
*
|
|
386
|
+
* With `body: unknown` (the type-safe default), every property access
|
|
387
|
+
* trips TS18046 and forces every test to either pass an inline generic
|
|
388
|
+
* (`.execute<{ id: number }>()`) or cast (`(r.body as { id: number })`).
|
|
389
|
+
* That's the right default for *production* code where you don't
|
|
390
|
+
* actually know the response shape — but in a test, the fixture _is_
|
|
391
|
+
* the type contract: the test file already encodes the expected shape
|
|
392
|
+
* in its assertions, so the type check is redundant noise.
|
|
393
|
+
*
|
|
394
|
+
* Users who want strict typing can still parameterise: the generic
|
|
395
|
+
* is preserved on `request.execute<T>()` and on `FluentResponse<T>`
|
|
396
|
+
* itself, so opting into a typed body remains a single keystroke
|
|
397
|
+
* (`.execute<UserDto>()`). This mirrors how `supertest` and `axios`
|
|
398
|
+
* default — both publish `body: any` for the same reason.
|
|
375
399
|
*/
|
|
376
|
-
export interface FluentResponse<T =
|
|
400
|
+
export interface FluentResponse<T = any> {
|
|
377
401
|
/**
|
|
378
402
|
* Response status code.
|
|
379
403
|
*/
|
|
@@ -387,7 +411,8 @@ export interface FluentResponse<T = unknown> {
|
|
|
387
411
|
*/
|
|
388
412
|
headers: Record<string, string>;
|
|
389
413
|
/**
|
|
390
|
-
* Parsed response body.
|
|
414
|
+
* Parsed response body. Defaults to `any` — see the interface
|
|
415
|
+
* docstring for the rationale and how to opt into strict typing.
|
|
391
416
|
*/
|
|
392
417
|
body: T;
|
|
393
418
|
/**
|
|
@@ -487,7 +512,7 @@ export interface SnapshotRequest {
|
|
|
487
512
|
expectContentType(type: string | RegExp): SnapshotRequest;
|
|
488
513
|
expectBodyPath(path: string, expected: unknown): SnapshotRequest;
|
|
489
514
|
expect<T>(assertion: (response: FluentResponse<T>) => void): SnapshotRequest;
|
|
490
|
-
execute<T =
|
|
515
|
+
execute<T = any>(): Promise<FluentResponse<T>>;
|
|
491
516
|
/**
|
|
492
517
|
* Assert response matches snapshot.
|
|
493
518
|
*/
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "4.0.0-preview.
|
|
3
|
+
"version": "4.0.0-preview.3",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.18.0"
|
|
41
|
+
},
|
|
39
42
|
"keywords": [
|
|
40
43
|
"expressots",
|
|
41
44
|
"nodejs",
|
|
@@ -50,29 +53,33 @@
|
|
|
50
53
|
"prepare": "husky",
|
|
51
54
|
"clean": "node scripts/rm.js lib",
|
|
52
55
|
"copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
|
|
53
|
-
"
|
|
56
|
+
"sync-version": "node scripts/sync-version.js",
|
|
57
|
+
"build": "npm run clean && npm run sync-version && npm run build:cjs && npm run build:esm && npm run copy",
|
|
54
58
|
"build:esm": "node scripts/build-esm.js",
|
|
55
59
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
56
60
|
"prepublish": "npm run build && npm pack",
|
|
57
61
|
"release": "release-it",
|
|
62
|
+
"release:prepare": "node scripts/release/prepare-publish.mjs",
|
|
63
|
+
"release:restore": "node scripts/release/restore-package-json.mjs",
|
|
64
|
+
"release:publish": "npm run build && npm run release:prepare && npm publish --tag next --access public && npm run release:restore",
|
|
58
65
|
"test": "jest",
|
|
59
66
|
"test:watch": "jest --watch",
|
|
60
67
|
"coverage": "jest --coverage",
|
|
61
68
|
"format": "prettier --write \"packages/**/*.ts\" --cache",
|
|
62
|
-
"lint": "eslint \"packages/**/*.ts\"",
|
|
63
|
-
"lint:fix": "eslint \"packages/**/*.ts\" --fix",
|
|
69
|
+
"lint": "eslint \"packages/**/*.ts\" --cache --cache-location node_modules/.cache/eslint/",
|
|
70
|
+
"lint:fix": "eslint \"packages/**/*.ts\" --fix --cache --cache-location node_modules/.cache/eslint/",
|
|
64
71
|
"docs:generate": "node scripts/generate-docs.js",
|
|
65
72
|
"docs:clean": "node scripts/rm.js docs"
|
|
66
73
|
},
|
|
67
74
|
"dependencies": {
|
|
75
|
+
"@expressots/shared": "file:../shared/expressots-shared-4.0.0-preview.3.tgz",
|
|
68
76
|
"reflect-metadata": "0.2.2"
|
|
69
77
|
},
|
|
70
78
|
"devDependencies": {
|
|
71
|
-
"@codecov/vite-plugin": "
|
|
79
|
+
"@codecov/vite-plugin": "^2.0.1",
|
|
72
80
|
"@commitlint/cli": "19.2.1",
|
|
73
81
|
"@commitlint/config-conventional": "19.1.0",
|
|
74
|
-
"@
|
|
75
|
-
"@release-it/conventional-changelog": "8.0.1",
|
|
82
|
+
"@release-it/conventional-changelog": "^11.0.0",
|
|
76
83
|
"@types/express": "4.17.21",
|
|
77
84
|
"@types/jest": "^29.5.14",
|
|
78
85
|
"@types/node": "20.14.10",
|
|
@@ -82,12 +89,20 @@
|
|
|
82
89
|
"eslint-config-prettier": "9.1.0",
|
|
83
90
|
"husky": "9.0.11",
|
|
84
91
|
"jest": "29.7.0",
|
|
92
|
+
"lint-staged": "^15.2.10",
|
|
85
93
|
"prettier": "3.3.3",
|
|
86
|
-
"release-it": "
|
|
94
|
+
"release-it": "^20.0.1",
|
|
87
95
|
"ts-jest": "29.2.5",
|
|
96
|
+
"ts-node": "10.9.2",
|
|
88
97
|
"typedoc": "^0.28.15",
|
|
89
98
|
"typescript": "5.5.3"
|
|
90
99
|
},
|
|
100
|
+
"lint-staged": {
|
|
101
|
+
"packages/**/*.ts": [
|
|
102
|
+
"eslint --cache --cache-location node_modules/.cache/eslint/ --fix",
|
|
103
|
+
"prettier --write --cache"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
91
106
|
"release-it": {
|
|
92
107
|
"git": {
|
|
93
108
|
"commitMessage": "chore(release): ${version}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "4.0.0-preview.
|
|
3
|
+
"version": "4.0.0-preview.3",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.18.0"
|
|
41
|
+
},
|
|
39
42
|
"keywords": [
|
|
40
43
|
"expressots",
|
|
41
44
|
"nodejs",
|
|
@@ -50,29 +53,33 @@
|
|
|
50
53
|
"prepare": "husky",
|
|
51
54
|
"clean": "node scripts/rm.js lib",
|
|
52
55
|
"copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
|
|
53
|
-
"
|
|
56
|
+
"sync-version": "node scripts/sync-version.js",
|
|
57
|
+
"build": "npm run clean && npm run sync-version && npm run build:cjs && npm run build:esm && npm run copy",
|
|
54
58
|
"build:esm": "node scripts/build-esm.js",
|
|
55
59
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
56
60
|
"prepublish": "npm run build && npm pack",
|
|
57
61
|
"release": "release-it",
|
|
62
|
+
"release:prepare": "node scripts/release/prepare-publish.mjs",
|
|
63
|
+
"release:restore": "node scripts/release/restore-package-json.mjs",
|
|
64
|
+
"release:publish": "npm run build && npm run release:prepare && npm publish --tag next --access public && npm run release:restore",
|
|
58
65
|
"test": "jest",
|
|
59
66
|
"test:watch": "jest --watch",
|
|
60
67
|
"coverage": "jest --coverage",
|
|
61
68
|
"format": "prettier --write \"packages/**/*.ts\" --cache",
|
|
62
|
-
"lint": "eslint \"packages/**/*.ts\"",
|
|
63
|
-
"lint:fix": "eslint \"packages/**/*.ts\" --fix",
|
|
69
|
+
"lint": "eslint \"packages/**/*.ts\" --cache --cache-location node_modules/.cache/eslint/",
|
|
70
|
+
"lint:fix": "eslint \"packages/**/*.ts\" --fix --cache --cache-location node_modules/.cache/eslint/",
|
|
64
71
|
"docs:generate": "node scripts/generate-docs.js",
|
|
65
72
|
"docs:clean": "node scripts/rm.js docs"
|
|
66
73
|
},
|
|
67
74
|
"dependencies": {
|
|
75
|
+
"@expressots/shared": "^4.0.0-preview.3",
|
|
68
76
|
"reflect-metadata": "0.2.2"
|
|
69
77
|
},
|
|
70
78
|
"devDependencies": {
|
|
71
|
-
"@codecov/vite-plugin": "
|
|
79
|
+
"@codecov/vite-plugin": "^2.0.1",
|
|
72
80
|
"@commitlint/cli": "19.2.1",
|
|
73
81
|
"@commitlint/config-conventional": "19.1.0",
|
|
74
|
-
"@
|
|
75
|
-
"@release-it/conventional-changelog": "8.0.1",
|
|
82
|
+
"@release-it/conventional-changelog": "^11.0.0",
|
|
76
83
|
"@types/express": "4.17.21",
|
|
77
84
|
"@types/jest": "^29.5.14",
|
|
78
85
|
"@types/node": "20.14.10",
|
|
@@ -82,12 +89,20 @@
|
|
|
82
89
|
"eslint-config-prettier": "9.1.0",
|
|
83
90
|
"husky": "9.0.11",
|
|
84
91
|
"jest": "29.7.0",
|
|
92
|
+
"lint-staged": "^15.2.10",
|
|
85
93
|
"prettier": "3.3.3",
|
|
86
|
-
"release-it": "
|
|
94
|
+
"release-it": "^20.0.1",
|
|
87
95
|
"ts-jest": "29.2.5",
|
|
96
|
+
"ts-node": "10.9.2",
|
|
88
97
|
"typedoc": "^0.28.15",
|
|
89
98
|
"typescript": "5.5.3"
|
|
90
99
|
},
|
|
100
|
+
"lint-staged": {
|
|
101
|
+
"packages/**/*.ts": [
|
|
102
|
+
"eslint --cache --cache-location node_modules/.cache/eslint/ --fix",
|
|
103
|
+
"prettier --write --cache"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
91
106
|
"release-it": {
|
|
92
107
|
"git": {
|
|
93
108
|
"commitMessage": "chore(release): ${version}"
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MIDDLEWARE_PRESETS = void 0;
|
|
4
|
-
exports.getPreset = getPreset;
|
|
5
|
-
exports.getPresetNames = getPresetNames;
|
|
6
|
-
exports.getPresetsByTag = getPresetsByTag;
|
|
7
|
-
exports.createPreset = createPreset;
|
|
8
|
-
exports.mergePresets = mergePresets;
|
|
9
|
-
/**
|
|
10
|
-
* Default CORS options for API preset.
|
|
11
|
-
*/
|
|
12
|
-
const API_CORS_OPTIONS = {
|
|
13
|
-
origin: true,
|
|
14
|
-
credentials: true,
|
|
15
|
-
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
|
16
|
-
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Default Helmet options for secure preset.
|
|
20
|
-
*/
|
|
21
|
-
const SECURE_HELMET_OPTIONS = {
|
|
22
|
-
contentSecurityPolicy: {
|
|
23
|
-
directives: {
|
|
24
|
-
"default-src": ["'self'"],
|
|
25
|
-
"style-src": ["'self'", "'unsafe-inline'"],
|
|
26
|
-
"script-src": ["'self'"],
|
|
27
|
-
"img-src": ["'self'", "data:", "https:"],
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
crossOriginEmbedderPolicy: { policy: "require-corp" },
|
|
31
|
-
crossOriginOpenerPolicy: { policy: "same-origin" },
|
|
32
|
-
crossOriginResourcePolicy: { policy: "same-origin" },
|
|
33
|
-
xDnsPrefetchControl: { allow: false },
|
|
34
|
-
xFrameOptions: { action: "deny" },
|
|
35
|
-
strictTransportSecurity: {
|
|
36
|
-
maxAge: 31536000,
|
|
37
|
-
includeSubDomains: true,
|
|
38
|
-
preload: true,
|
|
39
|
-
},
|
|
40
|
-
xDownloadOptions: "noopen",
|
|
41
|
-
xContentTypeOptions: "nosniff",
|
|
42
|
-
xPermittedCrossDomainPolicies: { permittedPolicies: "none" },
|
|
43
|
-
referrerPolicy: { policy: "strict-origin-when-cross-origin" },
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Default rate limit options.
|
|
47
|
-
*/
|
|
48
|
-
const DEFAULT_RATE_LIMIT_OPTIONS = {
|
|
49
|
-
windowMs: 60 * 1000, // 1 minute
|
|
50
|
-
limit: 100, // 100 requests per minute
|
|
51
|
-
standardHeaders: "draft-7",
|
|
52
|
-
legacyHeaders: false,
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Strict rate limit for production.
|
|
56
|
-
*/
|
|
57
|
-
const PRODUCTION_RATE_LIMIT_OPTIONS = {
|
|
58
|
-
windowMs: 60 * 1000,
|
|
59
|
-
limit: 60,
|
|
60
|
-
standardHeaders: "draft-7",
|
|
61
|
-
legacyHeaders: false,
|
|
62
|
-
skipSuccessfulRequests: false,
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Built-in middleware presets.
|
|
66
|
-
* @public API
|
|
67
|
-
*/
|
|
68
|
-
exports.MIDDLEWARE_PRESETS = {
|
|
69
|
-
/**
|
|
70
|
-
* API Preset - Optimized for REST APIs
|
|
71
|
-
* Includes: CORS, Helmet, JSON parser, URL-encoded parser, Compression, Rate limiting
|
|
72
|
-
*/
|
|
73
|
-
api: {
|
|
74
|
-
name: "api",
|
|
75
|
-
description: "Optimized configuration for REST APIs with security and performance",
|
|
76
|
-
tags: ["rest", "backend", "security"],
|
|
77
|
-
middleware: [
|
|
78
|
-
{ name: "Cors", options: API_CORS_OPTIONS },
|
|
79
|
-
{ name: "Helmet", options: {} },
|
|
80
|
-
{ name: "BodyParser", options: { limit: "10mb" } },
|
|
81
|
-
{
|
|
82
|
-
name: "UrlEncodedParser",
|
|
83
|
-
options: { extended: true },
|
|
84
|
-
},
|
|
85
|
-
{ name: "Compression", options: { level: 6 } },
|
|
86
|
-
{ name: "RateLimiter", options: DEFAULT_RATE_LIMIT_OPTIONS },
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
/**
|
|
90
|
-
* Web Preset - For traditional web applications
|
|
91
|
-
* Includes: Session, Cookie parser, Static files, CORS, Helmet
|
|
92
|
-
*/
|
|
93
|
-
web: {
|
|
94
|
-
name: "web",
|
|
95
|
-
description: "Configuration for traditional web applications with sessions",
|
|
96
|
-
tags: ["web", "frontend", "session"],
|
|
97
|
-
middleware: [
|
|
98
|
-
{ name: "Cors", options: { origin: true } },
|
|
99
|
-
{ name: "Helmet", options: {} },
|
|
100
|
-
{ name: "BodyParser", options: { limit: "5mb" } },
|
|
101
|
-
{
|
|
102
|
-
name: "UrlEncodedParser",
|
|
103
|
-
options: { extended: true },
|
|
104
|
-
},
|
|
105
|
-
{ name: "CookieParser", options: undefined, optional: true },
|
|
106
|
-
{ name: "Compression", options: {} },
|
|
107
|
-
],
|
|
108
|
-
},
|
|
109
|
-
/**
|
|
110
|
-
* Microservice Preset - Lightweight for service-to-service communication
|
|
111
|
-
* Minimal middleware for maximum performance
|
|
112
|
-
*/
|
|
113
|
-
microservice: {
|
|
114
|
-
name: "microservice",
|
|
115
|
-
description: "Lightweight configuration for microservices",
|
|
116
|
-
tags: ["microservice", "performance", "minimal"],
|
|
117
|
-
middleware: [
|
|
118
|
-
{ name: "BodyParser", options: { limit: "1mb" } },
|
|
119
|
-
{ name: "Compression", options: { level: 6 } },
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
/**
|
|
123
|
-
* GraphQL Preset - Optimized for GraphQL APIs
|
|
124
|
-
*/
|
|
125
|
-
graphql: {
|
|
126
|
-
name: "graphql",
|
|
127
|
-
description: "Optimized for GraphQL API servers",
|
|
128
|
-
tags: ["graphql", "api"],
|
|
129
|
-
middleware: [
|
|
130
|
-
{
|
|
131
|
-
name: "Cors",
|
|
132
|
-
options: {
|
|
133
|
-
origin: true,
|
|
134
|
-
methods: ["GET", "POST", "OPTIONS"],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
{ name: "BodyParser", options: { limit: "50mb" } },
|
|
138
|
-
{ name: "Compression", options: {} },
|
|
139
|
-
],
|
|
140
|
-
},
|
|
141
|
-
/**
|
|
142
|
-
* Minimal Preset - Absolute minimum for simple apps
|
|
143
|
-
*/
|
|
144
|
-
minimal: {
|
|
145
|
-
name: "minimal",
|
|
146
|
-
description: "Minimal configuration with just body parsing",
|
|
147
|
-
tags: ["minimal", "simple"],
|
|
148
|
-
middleware: [
|
|
149
|
-
{ name: "BodyParser", options: {} },
|
|
150
|
-
{
|
|
151
|
-
name: "UrlEncodedParser",
|
|
152
|
-
options: { extended: false },
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
|
-
/**
|
|
157
|
-
* Secure Preset - Maximum security configuration
|
|
158
|
-
*/
|
|
159
|
-
secure: {
|
|
160
|
-
name: "secure",
|
|
161
|
-
description: "Maximum security configuration for sensitive applications",
|
|
162
|
-
tags: ["security", "production", "hardened"],
|
|
163
|
-
middleware: [
|
|
164
|
-
{ name: "Helmet", options: SECURE_HELMET_OPTIONS },
|
|
165
|
-
{
|
|
166
|
-
name: "Cors",
|
|
167
|
-
options: {
|
|
168
|
-
origin: false, // Must be explicitly configured
|
|
169
|
-
credentials: true,
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
{ name: "RateLimiter", options: PRODUCTION_RATE_LIMIT_OPTIONS },
|
|
173
|
-
{ name: "BodyParser", options: { limit: "1mb" } },
|
|
174
|
-
{
|
|
175
|
-
name: "UrlEncodedParser",
|
|
176
|
-
options: { extended: false, limit: "1mb" },
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
/**
|
|
181
|
-
* Development Preset - Verbose logging and relaxed security
|
|
182
|
-
*/
|
|
183
|
-
development: {
|
|
184
|
-
name: "development",
|
|
185
|
-
description: "Development-friendly with logging and relaxed security",
|
|
186
|
-
tags: ["development", "debug", "logging"],
|
|
187
|
-
middleware: [
|
|
188
|
-
{ name: "Cors", options: { origin: true } },
|
|
189
|
-
{ name: "BodyParser", options: { limit: "50mb" } },
|
|
190
|
-
{
|
|
191
|
-
name: "UrlEncodedParser",
|
|
192
|
-
options: { extended: true },
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: "Morgan",
|
|
196
|
-
options: "dev",
|
|
197
|
-
optional: true,
|
|
198
|
-
},
|
|
199
|
-
{ name: "Compression", options: {}, optional: true },
|
|
200
|
-
],
|
|
201
|
-
},
|
|
202
|
-
/**
|
|
203
|
-
* Production Preset - Optimized for production deployment
|
|
204
|
-
*/
|
|
205
|
-
production: {
|
|
206
|
-
name: "production",
|
|
207
|
-
description: "Production-optimized with security and performance",
|
|
208
|
-
tags: ["production", "performance", "security"],
|
|
209
|
-
middleware: [
|
|
210
|
-
{ name: "Helmet", options: {} },
|
|
211
|
-
{ name: "Cors", options: API_CORS_OPTIONS },
|
|
212
|
-
{ name: "RateLimiter", options: PRODUCTION_RATE_LIMIT_OPTIONS },
|
|
213
|
-
{
|
|
214
|
-
name: "Compression",
|
|
215
|
-
options: { level: 6, threshold: 1024 },
|
|
216
|
-
},
|
|
217
|
-
{ name: "BodyParser", options: { limit: "10mb" } },
|
|
218
|
-
{
|
|
219
|
-
name: "UrlEncodedParser",
|
|
220
|
-
options: { extended: true },
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
/**
|
|
226
|
-
* Get a preset by name.
|
|
227
|
-
*
|
|
228
|
-
* @param name - The preset name
|
|
229
|
-
* @returns The preset configuration or undefined
|
|
230
|
-
* @public API
|
|
231
|
-
*/
|
|
232
|
-
function getPreset(name) {
|
|
233
|
-
return exports.MIDDLEWARE_PRESETS[name];
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Get all available preset names.
|
|
237
|
-
*
|
|
238
|
-
* @returns Array of preset names
|
|
239
|
-
* @public API
|
|
240
|
-
*/
|
|
241
|
-
function getPresetNames() {
|
|
242
|
-
return Object.keys(exports.MIDDLEWARE_PRESETS);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Get presets by tag.
|
|
246
|
-
*
|
|
247
|
-
* @param tag - The tag to filter by
|
|
248
|
-
* @returns Array of matching presets
|
|
249
|
-
* @public API
|
|
250
|
-
*/
|
|
251
|
-
function getPresetsByTag(tag) {
|
|
252
|
-
return Object.values(exports.MIDDLEWARE_PRESETS).filter((preset) => preset.tags?.includes(tag));
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Create a custom preset.
|
|
256
|
-
*
|
|
257
|
-
* @param config - The preset configuration
|
|
258
|
-
* @returns The created preset
|
|
259
|
-
* @public API
|
|
260
|
-
*/
|
|
261
|
-
function createPreset(config) {
|
|
262
|
-
return config;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Merge two presets, with the second overriding the first.
|
|
266
|
-
*
|
|
267
|
-
* @param base - The base preset
|
|
268
|
-
* @param override - The overriding preset
|
|
269
|
-
* @returns Merged preset
|
|
270
|
-
* @public API
|
|
271
|
-
*/
|
|
272
|
-
function mergePresets(base, override) {
|
|
273
|
-
const mergedMiddleware = [...base.middleware];
|
|
274
|
-
if (override.middleware) {
|
|
275
|
-
for (const overrideMiddleware of override.middleware) {
|
|
276
|
-
const existingIndex = mergedMiddleware.findIndex((m) => m.name === overrideMiddleware.name);
|
|
277
|
-
if (existingIndex >= 0) {
|
|
278
|
-
mergedMiddleware[existingIndex] = {
|
|
279
|
-
...mergedMiddleware[existingIndex],
|
|
280
|
-
...overrideMiddleware,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
mergedMiddleware.push(overrideMiddleware);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
...base,
|
|
290
|
-
...override,
|
|
291
|
-
middleware: mergedMiddleware,
|
|
292
|
-
tags: [...(base.tags ?? []), ...(override.tags ?? [])],
|
|
293
|
-
};
|
|
294
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Individual middleware configuration within a preset.
|
|
3
|
-
* @public API
|
|
4
|
-
*/
|
|
5
|
-
export interface PresetMiddlewareConfig {
|
|
6
|
-
/** Middleware name (matches the add* method name without 'add' prefix) */
|
|
7
|
-
name: string;
|
|
8
|
-
/** Configuration options for the middleware */
|
|
9
|
-
options?: unknown;
|
|
10
|
-
/** Whether this middleware is optional (won't fail if not installed) */
|
|
11
|
-
optional?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Available preset names.
|
|
15
|
-
* @public API
|
|
16
|
-
*/
|
|
17
|
-
export type MiddlewarePresetName = "api" | "web" | "microservice" | "graphql" | "minimal" | "secure" | "development" | "production";
|
|
18
|
-
/**
|
|
19
|
-
* Preset configuration with metadata.
|
|
20
|
-
* @public API
|
|
21
|
-
*/
|
|
22
|
-
export interface MiddlewarePreset {
|
|
23
|
-
/** Preset name */
|
|
24
|
-
name: MiddlewarePresetName;
|
|
25
|
-
/** Human-readable description */
|
|
26
|
-
description: string;
|
|
27
|
-
/** List of middleware to apply */
|
|
28
|
-
middleware: Array<PresetMiddlewareConfig>;
|
|
29
|
-
/** Tags for categorization */
|
|
30
|
-
tags?: Array<string>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Options for applying a preset.
|
|
34
|
-
* @public API
|
|
35
|
-
*/
|
|
36
|
-
export interface ApplyPresetOptions {
|
|
37
|
-
/** Override specific middleware options */
|
|
38
|
-
overrides?: Record<string, unknown>;
|
|
39
|
-
/** Skip specific middleware by name */
|
|
40
|
-
skip?: Array<string>;
|
|
41
|
-
/** Only apply middleware that are already installed */
|
|
42
|
-
onlyInstalled?: boolean;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Built-in middleware presets.
|
|
46
|
-
* @public API
|
|
47
|
-
*/
|
|
48
|
-
export declare const MIDDLEWARE_PRESETS: Record<MiddlewarePresetName, MiddlewarePreset>;
|
|
49
|
-
/**
|
|
50
|
-
* Get a preset by name.
|
|
51
|
-
*
|
|
52
|
-
* @param name - The preset name
|
|
53
|
-
* @returns The preset configuration or undefined
|
|
54
|
-
* @public API
|
|
55
|
-
*/
|
|
56
|
-
export declare function getPreset(name: MiddlewarePresetName): MiddlewarePreset | undefined;
|
|
57
|
-
/**
|
|
58
|
-
* Get all available preset names.
|
|
59
|
-
*
|
|
60
|
-
* @returns Array of preset names
|
|
61
|
-
* @public API
|
|
62
|
-
*/
|
|
63
|
-
export declare function getPresetNames(): Array<MiddlewarePresetName>;
|
|
64
|
-
/**
|
|
65
|
-
* Get presets by tag.
|
|
66
|
-
*
|
|
67
|
-
* @param tag - The tag to filter by
|
|
68
|
-
* @returns Array of matching presets
|
|
69
|
-
* @public API
|
|
70
|
-
*/
|
|
71
|
-
export declare function getPresetsByTag(tag: string): Array<MiddlewarePreset>;
|
|
72
|
-
/**
|
|
73
|
-
* Create a custom preset.
|
|
74
|
-
*
|
|
75
|
-
* @param config - The preset configuration
|
|
76
|
-
* @returns The created preset
|
|
77
|
-
* @public API
|
|
78
|
-
*/
|
|
79
|
-
export declare function createPreset(config: Omit<MiddlewarePreset, "name"> & {
|
|
80
|
-
name: string;
|
|
81
|
-
}): MiddlewarePreset;
|
|
82
|
-
/**
|
|
83
|
-
* Merge two presets, with the second overriding the first.
|
|
84
|
-
*
|
|
85
|
-
* @param base - The base preset
|
|
86
|
-
* @param override - The overriding preset
|
|
87
|
-
* @returns Merged preset
|
|
88
|
-
* @public API
|
|
89
|
-
*/
|
|
90
|
-
export declare function mergePresets(base: MiddlewarePreset, override: Partial<MiddlewarePreset>): MiddlewarePreset;
|