@zintrust/core 0.4.20 → 0.4.21
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/package.json +1 -1
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/functions/cloudflare.js +37 -10
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +1 -1
- package/src/index.js +3 -3
- package/src/middleware/AuthMiddleware.d.ts.map +1 -1
- package/src/middleware/AuthMiddleware.js +7 -1
- package/src/middleware/JwtAuthMiddleware.d.ts.map +1 -1
- package/src/middleware/JwtAuthMiddleware.js +63 -69
- package/src/middleware/MiddlewareFailureBody.d.ts +12 -0
- package/src/middleware/MiddlewareFailureBody.d.ts.map +1 -0
- package/src/middleware/MiddlewareFailureBody.js +8 -0
- package/src/middleware/MiddlewareFailureResponder.d.ts +1 -0
- package/src/middleware/MiddlewareFailureResponder.d.ts.map +1 -1
- package/src/middleware/MiddlewareFailureResponder.js +1 -0
- package/src/middleware/SecurityMiddleware.d.ts.map +1 -1
- package/src/middleware/SecurityMiddleware.js +9 -5
- package/src/middleware/index.d.ts +1 -0
- package/src/middleware/index.d.ts.map +1 -1
- package/src/middleware/index.js +1 -0
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -1
- package/src/runtime/RuntimeAdapter.js +38 -28
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/functions/cloudflare.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/functions/cloudflare.ts"],"names":[],"mappings":";mBAwNuB,OAAO,QAAQ,OAAO,QAAQ,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;;AADhF,wBAoCE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { clearMiddlewareConfigCache } from '../config/middleware.js';
|
|
2
1
|
import { Logger } from '../config/logger.js';
|
|
2
|
+
import { clearMiddlewareConfigCache } from '../config/middleware.js';
|
|
3
3
|
import { CloudflareAdapter } from '../runtime/adapters/CloudflareAdapter.js';
|
|
4
4
|
import mergeOverrideValues from '../runtime/OverrideValueMerge.js';
|
|
5
5
|
import { ProjectRuntime } from '../runtime/ProjectRuntime.js';
|
|
@@ -40,16 +40,43 @@ const startupConfigModules = Object.freeze([
|
|
|
40
40
|
serviceModuleId: '@service-runtime-config/' + 'storage.ts',
|
|
41
41
|
},
|
|
42
42
|
]);
|
|
43
|
+
const importRootBroadcastModule = async () => {
|
|
44
|
+
return (await import('@runtime-config/' + 'broadcast.ts'));
|
|
45
|
+
};
|
|
46
|
+
const importRootCacheModule = async () => {
|
|
47
|
+
return (await import('@runtime-config/' + 'cache.ts'));
|
|
48
|
+
};
|
|
49
|
+
const importRootDatabaseModule = async () => {
|
|
50
|
+
return (await import('@runtime-config/' + 'database.ts'));
|
|
51
|
+
};
|
|
52
|
+
const importRootMailModule = async () => {
|
|
53
|
+
return (await import('@runtime-config/' + 'mail.ts'));
|
|
54
|
+
};
|
|
55
|
+
const importRootMiddlewareModule = async () => {
|
|
56
|
+
return (await import('@runtime-config/' + 'middleware.ts'));
|
|
57
|
+
};
|
|
58
|
+
const importRootNotificationModule = async () => {
|
|
59
|
+
return (await import('@runtime-config/' + 'notification.ts'));
|
|
60
|
+
};
|
|
61
|
+
const importRootQueueModule = async () => {
|
|
62
|
+
return (await import('@runtime-config/' + 'queue.ts'));
|
|
63
|
+
};
|
|
64
|
+
const importRootStorageModule = async () => {
|
|
65
|
+
return (await import('@runtime-config/' + 'storage.ts'));
|
|
66
|
+
};
|
|
67
|
+
const importRootWorkersModule = async () => {
|
|
68
|
+
return (await import('@runtime-config/' + 'workers.ts'));
|
|
69
|
+
};
|
|
43
70
|
const rootStartupImporters = Object.freeze({
|
|
44
|
-
[StartupConfigFile.Broadcast]:
|
|
45
|
-
[StartupConfigFile.Cache]:
|
|
46
|
-
[StartupConfigFile.Database]:
|
|
47
|
-
[StartupConfigFile.Mail]:
|
|
48
|
-
[StartupConfigFile.Middleware]:
|
|
49
|
-
[StartupConfigFile.Notification]:
|
|
50
|
-
[StartupConfigFile.Queue]:
|
|
51
|
-
[StartupConfigFile.Storage]:
|
|
52
|
-
[StartupConfigFile.Workers]:
|
|
71
|
+
[StartupConfigFile.Broadcast]: importRootBroadcastModule,
|
|
72
|
+
[StartupConfigFile.Cache]: importRootCacheModule,
|
|
73
|
+
[StartupConfigFile.Database]: importRootDatabaseModule,
|
|
74
|
+
[StartupConfigFile.Mail]: importRootMailModule,
|
|
75
|
+
[StartupConfigFile.Middleware]: importRootMiddlewareModule,
|
|
76
|
+
[StartupConfigFile.Notification]: importRootNotificationModule,
|
|
77
|
+
[StartupConfigFile.Queue]: importRootQueueModule,
|
|
78
|
+
[StartupConfigFile.Storage]: importRootStorageModule,
|
|
79
|
+
[StartupConfigFile.Workers]: importRootWorkersModule,
|
|
53
80
|
});
|
|
54
81
|
const importOptionalDefault = async (importer) => {
|
|
55
82
|
try {
|
package/src/http/Kernel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Kernel.d.ts","sourceRoot":"","sources":["../../../src/http/Kernel.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"Kernel.d.ts","sourceRoot":"","sources":["../../../src/http/Kernel.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,qBAAqB,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAK7E,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,mBAAmB,CAAC;AAGpE,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/C,wBAAwB,CAAC,GAAG,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAC5D,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IACpE,SAAS,IAAI,OAAO,CAAC;IACrB,YAAY,IAAI,iBAAiB,CAAC;IAClC,kBAAkB,IAAI,gBAAgB,CAAC;IAGvC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5C,cAAc,IAAI,IAAI,CAAC;IACvB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AA6VD,eAAO,MAAM,MAAM;qBA1DK,OAAO,aAAa,iBAAiB,KAAG,OAAO;EA4DrE,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/src/http/Kernel.js
CHANGED
|
@@ -112,7 +112,7 @@ const maybeSetKernelTraceRoute = (traceSpan, method, routeLabel) => {
|
|
|
112
112
|
const runKernelPipeline = async (router, globalMiddleware, routeMiddleware, req, res, context, traceSpan) => {
|
|
113
113
|
Logger.info(`[${req.getMethod()}] ${req.getPath()}`);
|
|
114
114
|
const route = resolveRouteWithPreflightFallback(router, req.getMethod(), req.getPath());
|
|
115
|
-
if (
|
|
115
|
+
if (route === null) {
|
|
116
116
|
const routeLabel = 'not_found';
|
|
117
117
|
maybeSetKernelTraceRoute(traceSpan, context.method, routeLabel);
|
|
118
118
|
const handleNotFound = ErrorRouting.handleNotFound;
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zintrust/core v0.4.
|
|
2
|
+
* @zintrust/core v0.4.21
|
|
3
3
|
*
|
|
4
4
|
* ZinTrust Framework - Production-Grade TypeScript Backend
|
|
5
5
|
* Built for performance, type safety, and exceptional developer experience
|
|
6
6
|
*
|
|
7
7
|
* Build Information:
|
|
8
|
-
* Built: 2026-03-
|
|
8
|
+
* Built: 2026-03-26T13:55:52.794Z
|
|
9
9
|
* Node: >=20.0.0
|
|
10
10
|
* License: MIT
|
|
11
11
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Available at runtime for debugging and health checks
|
|
22
22
|
*/
|
|
23
23
|
export const ZINTRUST_VERSION = '0.1.41';
|
|
24
|
-
export const ZINTRUST_BUILD_DATE = '2026-03-
|
|
24
|
+
export const ZINTRUST_BUILD_DATE = '2026-03-26T13:55:52.759Z'; // Replaced during build
|
|
25
25
|
export { Application } from './boot/Application.js';
|
|
26
26
|
export { AwsSigV4 } from './common/index.js';
|
|
27
27
|
export { SignedRequest } from './security/SignedRequest.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/AuthMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AuthMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/AuthMiddleware.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAS9D,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,0BAA0B,CAAC;CAC7C;AAED,eAAO,MAAM,cAAc;qBACT,WAAW,GAAQ,UAAU;EAsB7C,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { respondWithMiddlewareFailure, } from './MiddlewareFailureResponder.js';
|
|
2
|
+
const createAuthFailureBody = (reason, message) => ({
|
|
3
|
+
error: {
|
|
4
|
+
code: reason,
|
|
5
|
+
message,
|
|
6
|
+
},
|
|
7
|
+
});
|
|
2
8
|
export const AuthMiddleware = Object.freeze({
|
|
3
9
|
create(options = {}) {
|
|
4
10
|
const headerName = (options.headerName ?? 'authorization').toLowerCase();
|
|
@@ -12,7 +18,7 @@ export const AuthMiddleware = Object.freeze({
|
|
|
12
18
|
reason: 'missing_authorization_header',
|
|
13
19
|
statusCode: 401,
|
|
14
20
|
message,
|
|
15
|
-
body:
|
|
21
|
+
body: createAuthFailureBody('missing_authorization_header', message),
|
|
16
22
|
});
|
|
17
23
|
return;
|
|
18
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JwtAuthMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/JwtAuthMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JwtAuthMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/JwtAuthMiddleware.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAItE,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,0BAA0B,CAAC;CAC7C;AAqJD,eAAO,MAAM,iBAAiB;qBACZ,cAAc,GAAQ,UAAU;EAWhD,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -38,6 +38,68 @@ const getOptionalStringOrNumberClaim = (payload, key) => {
|
|
|
38
38
|
return String(value);
|
|
39
39
|
return undefined;
|
|
40
40
|
};
|
|
41
|
+
const createJwtFailureBody = (reason, message) => ({
|
|
42
|
+
error: {
|
|
43
|
+
code: reason,
|
|
44
|
+
message,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const respondJwtUnauthorized = async (req, res, onUnauthorized, reason, message, error) => {
|
|
48
|
+
await respondWithMiddlewareFailure(req, res, onUnauthorized, {
|
|
49
|
+
middleware: 'jwt',
|
|
50
|
+
reason,
|
|
51
|
+
statusCode: 401,
|
|
52
|
+
message,
|
|
53
|
+
body: createJwtFailureBody(reason, message),
|
|
54
|
+
error,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const hydrateJwtRequestContext = (req, payload) => {
|
|
58
|
+
req.user = payload;
|
|
59
|
+
const subject = payload['sub'];
|
|
60
|
+
if (typeof subject === 'string' && subject.trim() !== '') {
|
|
61
|
+
RequestContext.setUserId(req, subject);
|
|
62
|
+
}
|
|
63
|
+
const tenantId = getOptionalStringOrNumberClaim(payload, 'tenantId') ??
|
|
64
|
+
getOptionalStringOrNumberClaim(payload, 'tenant_id');
|
|
65
|
+
if (tenantId !== undefined && tenantId.trim() !== '') {
|
|
66
|
+
RequestContext.setTenantId(req, tenantId);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const createJwtMiddlewareHandler = (jwt, algorithm, onUnauthorized) => {
|
|
70
|
+
return async (req, res, next) => {
|
|
71
|
+
if (req.context?.['authStrategy'] === 'bulletproof' && req.user !== undefined) {
|
|
72
|
+
await next();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const authorizationHeader = getHeaderValue(req.getHeader('authorization'));
|
|
76
|
+
if (authorizationHeader === '') {
|
|
77
|
+
await respondJwtUnauthorized(req, res, onUnauthorized, 'missing_authorization_header', 'Missing authorization header');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const token = getBearerToken(authorizationHeader);
|
|
81
|
+
if (token === null) {
|
|
82
|
+
await respondJwtUnauthorized(req, res, onUnauthorized, 'invalid_authorization_header_format', 'Invalid authorization header format');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const payload = jwt.verify(token, algorithm);
|
|
87
|
+
if (!(await JwtSessions.isActive(token))) {
|
|
88
|
+
await respondJwtUnauthorized(req, res, onUnauthorized, 'inactive_session', 'Invalid or expired token');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
hydrateJwtRequestContext(req, payload);
|
|
92
|
+
await next();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
Logger.debug('JWT verification failed', {
|
|
96
|
+
algorithm,
|
|
97
|
+
error: error instanceof Error ? error.message : String(error),
|
|
98
|
+
});
|
|
99
|
+
await respondJwtUnauthorized(req, res, onUnauthorized, getJwtFailureReason(error), 'Invalid or expired token', error);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
};
|
|
41
103
|
export const JwtAuthMiddleware = Object.freeze({
|
|
42
104
|
create(options = {}) {
|
|
43
105
|
const algorithm = options.algorithm ?? securityConfig.jwt.algorithm;
|
|
@@ -46,75 +108,7 @@ export const JwtAuthMiddleware = Object.freeze({
|
|
|
46
108
|
if (algorithm === 'HS256' || algorithm === 'HS512') {
|
|
47
109
|
jwt.setHmacSecret(secret);
|
|
48
110
|
}
|
|
49
|
-
return
|
|
50
|
-
// If a stronger auth strategy already authenticated this request, do not re-verify.
|
|
51
|
-
if (req.context?.['authStrategy'] === 'bulletproof' && req.user !== undefined) {
|
|
52
|
-
await next();
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const authorizationHeader = getHeaderValue(req.getHeader('authorization'));
|
|
56
|
-
if (authorizationHeader === '') {
|
|
57
|
-
await respondWithMiddlewareFailure(req, res, options.onUnauthorized, {
|
|
58
|
-
middleware: 'jwt',
|
|
59
|
-
reason: 'missing_authorization_header',
|
|
60
|
-
statusCode: 401,
|
|
61
|
-
message: 'Missing authorization header',
|
|
62
|
-
body: { error: 'Missing authorization header' },
|
|
63
|
-
});
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const token = getBearerToken(authorizationHeader);
|
|
67
|
-
if (token === null) {
|
|
68
|
-
await respondWithMiddlewareFailure(req, res, options.onUnauthorized, {
|
|
69
|
-
middleware: 'jwt',
|
|
70
|
-
reason: 'invalid_authorization_header_format',
|
|
71
|
-
statusCode: 401,
|
|
72
|
-
message: 'Invalid authorization header format',
|
|
73
|
-
body: { error: 'Invalid authorization header format' },
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
const payload = jwt.verify(token, algorithm);
|
|
79
|
-
// Session allowlist: token must exist in the session store to be accepted.
|
|
80
|
-
if (!(await JwtSessions.isActive(token))) {
|
|
81
|
-
await respondWithMiddlewareFailure(req, res, options.onUnauthorized, {
|
|
82
|
-
middleware: 'jwt',
|
|
83
|
-
reason: 'inactive_session',
|
|
84
|
-
statusCode: 401,
|
|
85
|
-
message: 'Invalid or expired token',
|
|
86
|
-
body: { error: 'Invalid or expired token' },
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
req.user = payload;
|
|
91
|
-
// Standardize request-scoped context fields.
|
|
92
|
-
if (typeof payload.sub === 'string' && payload.sub.trim() !== '') {
|
|
93
|
-
RequestContext.setUserId(req, payload.sub);
|
|
94
|
-
}
|
|
95
|
-
// Optional: if a tenant claim exists, attach it. (Apps may use a different claim name.)
|
|
96
|
-
const tenantId = getOptionalStringOrNumberClaim(payload, 'tenantId') ??
|
|
97
|
-
getOptionalStringOrNumberClaim(payload, 'tenant_id');
|
|
98
|
-
if (tenantId !== undefined && tenantId.trim() !== '') {
|
|
99
|
-
RequestContext.setTenantId(req, tenantId);
|
|
100
|
-
}
|
|
101
|
-
await next();
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
Logger.debug('JWT verification failed', {
|
|
105
|
-
algorithm,
|
|
106
|
-
error: error instanceof Error ? error.message : String(error),
|
|
107
|
-
});
|
|
108
|
-
await respondWithMiddlewareFailure(req, res, options.onUnauthorized, {
|
|
109
|
-
middleware: 'jwt',
|
|
110
|
-
reason: getJwtFailureReason(error),
|
|
111
|
-
statusCode: 401,
|
|
112
|
-
message: 'Invalid or expired token',
|
|
113
|
-
body: { error: 'Invalid or expired token' },
|
|
114
|
-
error,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
111
|
+
return createJwtMiddlewareHandler(jwt, algorithm, options.onUnauthorized);
|
|
118
112
|
},
|
|
119
113
|
});
|
|
120
114
|
export default JwtAuthMiddleware;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type MiddlewareFailureBodyInput = Readonly<{
|
|
2
|
+
reason: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}>;
|
|
5
|
+
export type DefaultMiddlewareFailureBody = Readonly<{
|
|
6
|
+
error: Readonly<{
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function createDefaultMiddlewareFailureBody(context: MiddlewareFailureBodyInput): DefaultMiddlewareFailureBody;
|
|
12
|
+
//# sourceMappingURL=MiddlewareFailureBody.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareFailureBody.d.ts","sourceRoot":"","sources":["../../../src/middleware/MiddlewareFailureBody.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,QAAQ,CAAC;IAClD,KAAK,EAAE,QAAQ,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ,CAAC,CAAC;AAEH,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,0BAA0B,GAClC,4BAA4B,CAO9B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IRequest } from '../http/Request';
|
|
2
2
|
import type { IResponse } from '../http/Response';
|
|
3
|
+
export { createDefaultMiddlewareFailureBody, type DefaultMiddlewareFailureBody, type MiddlewareFailureBodyInput, } from './MiddlewareFailureBody';
|
|
3
4
|
export type MiddlewareFailureContext = Readonly<{
|
|
4
5
|
middleware: string;
|
|
5
6
|
reason: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MiddlewareFailureResponder.d.ts","sourceRoot":"","sources":["../../../src/middleware/MiddlewareFailureResponder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,CACvC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,wBAAwB,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,eAAO,MAAM,iCAAiC,EAAE,0BAgB/C,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,WAAW,0BAA0B,GAAG,SAAS,EACjD,SAAS,wBAAwB,KAChC,OAAO,CAAC,IAAI,CAEd,CAAC"}
|
|
1
|
+
{"version":3,"file":"MiddlewareFailureResponder.d.ts","sourceRoot":"","sources":["../../../src/middleware/MiddlewareFailureResponder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EACL,kCAAkC,EAClC,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,GAChC,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,CACvC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,wBAAwB,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,eAAO,MAAM,iCAAiC,EAAE,0BAgB/C,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,WAAW,0BAA0B,GAAG,SAAS,EACjD,SAAS,wBAAwB,KAChC,OAAO,CAAC,IAAI,CAEd,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isObject } from '../helper/index.js';
|
|
2
|
+
export { createDefaultMiddlewareFailureBody, } from './MiddlewareFailureBody.js';
|
|
2
3
|
export const defaultMiddlewareFailureResponder = (_req, res, context) => {
|
|
3
4
|
const statusTarget = res.setStatus(context.statusCode);
|
|
4
5
|
const responseTarget = isObject(statusTarget) ? statusTarget : res;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/SecurityMiddleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,UAAU,CAAC,EAAE;QACX,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;KAChC,CAAC;IACF,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KACvC,CAAC;CACH;
|
|
1
|
+
{"version":3,"file":"SecurityMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/SecurityMiddleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,UAAU,CAAC,EAAE;QACX,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;KAChC,CAAC;IACF,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KACvC,CAAC;CACH;AAwID,eAAO,MAAM,kBAAkB;IAC7B;;OAEG;qBACa,eAAe,GAAQ,UAAU;EAgBjD,CAAC"}
|
|
@@ -10,8 +10,12 @@ const normalizeCorsList = (values, fallback) => {
|
|
|
10
10
|
.filter((value) => value !== '');
|
|
11
11
|
return normalized.length > 0 ? normalized : fallback;
|
|
12
12
|
};
|
|
13
|
+
const getSecurityCorsConfig = () => {
|
|
14
|
+
const config = securityConfig;
|
|
15
|
+
return config?.cors ?? {};
|
|
16
|
+
};
|
|
13
17
|
const resolveCorsOrigin = () => {
|
|
14
|
-
const origins = normalizeCorsList(
|
|
18
|
+
const origins = normalizeCorsList(getSecurityCorsConfig().origins, ['*']);
|
|
15
19
|
return origins.includes('*') ? '*' : origins;
|
|
16
20
|
};
|
|
17
21
|
const DEFAULT_OPTIONS = {
|
|
@@ -25,7 +29,7 @@ const DEFAULT_OPTIONS = {
|
|
|
25
29
|
},
|
|
26
30
|
cors: {
|
|
27
31
|
origin: resolveCorsOrigin(),
|
|
28
|
-
methods: normalizeCorsList(
|
|
32
|
+
methods: normalizeCorsList(getSecurityCorsConfig().methods, [
|
|
29
33
|
'GET',
|
|
30
34
|
'HEAD',
|
|
31
35
|
'PUT',
|
|
@@ -33,14 +37,14 @@ const DEFAULT_OPTIONS = {
|
|
|
33
37
|
'POST',
|
|
34
38
|
'DELETE',
|
|
35
39
|
]),
|
|
36
|
-
allowedHeaders: normalizeCorsList(
|
|
40
|
+
allowedHeaders: normalizeCorsList(getSecurityCorsConfig().allowedHeaders, [
|
|
37
41
|
'Content-Type',
|
|
38
42
|
'Authorization',
|
|
39
43
|
'X-Requested-With',
|
|
40
44
|
'X-CSRF-Token',
|
|
41
45
|
]),
|
|
42
|
-
credentials:
|
|
43
|
-
maxAge:
|
|
46
|
+
credentials: getSecurityCorsConfig().credentials,
|
|
47
|
+
maxAge: getSecurityCorsConfig().maxAge,
|
|
44
48
|
},
|
|
45
49
|
};
|
|
46
50
|
const mergeSecurityOptions = (options) => {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export * from './CsrfMiddleware';
|
|
6
6
|
export * from './ErrorHandlerMiddleware';
|
|
7
7
|
export * from './LoggingMiddleware';
|
|
8
|
+
export * from './MiddlewareFailureBody';
|
|
8
9
|
export * from './MiddlewareFailureResponder';
|
|
9
10
|
export * from './MiddlewareStack';
|
|
10
11
|
export * from './RateLimiter';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wCAAwC,CAAC;AACvD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,wCAAwC,CAAC;AACvD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
|
package/src/middleware/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export * from './CsrfMiddleware.js';
|
|
6
6
|
export * from './ErrorHandlerMiddleware.js';
|
|
7
7
|
export * from './LoggingMiddleware.js';
|
|
8
|
+
export * from './MiddlewareFailureBody.js';
|
|
8
9
|
export * from './MiddlewareFailureResponder.js';
|
|
9
10
|
export * from './MiddlewareStack.js';
|
|
10
11
|
export * from './RateLimiter.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeAdapter.d.ts","sourceRoot":"","sources":["../../../src/runtime/RuntimeAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAO7E,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,E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;IACtC,UAAU,IAAI,gBAAgB,CAAC;CAChC;AAED,eAAO,MAAM,YAAY;cACb,aAAa;EA0EvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa;uBACL,MAAM,WAAW,MAAM,YAAY,OAAO,GAAG,aAAa;EAW7E,CAAC;AAgGH,KAAK,OAAO,GAAG;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,EAAE,KAAK,CAAC;CACb,CAAC;AAoIF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,GAAG;IAC/D,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC;CACvB,CAMA"}
|
|
@@ -157,6 +157,40 @@ const applyWriteHead = (responseData, statusCode, headers) => {
|
|
|
157
157
|
}
|
|
158
158
|
return null;
|
|
159
159
|
};
|
|
160
|
+
const closeWriterOnAbort = (request, response) => {
|
|
161
|
+
if (!request.signal || !response._writer)
|
|
162
|
+
return;
|
|
163
|
+
request.signal.addEventListener('abort', () => {
|
|
164
|
+
if (response._writer) {
|
|
165
|
+
try {
|
|
166
|
+
response._writer.close();
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Ignore close errors
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
response.emit('close');
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const writeToResponseWriter = (response, chunk) => {
|
|
176
|
+
if (!response._writer)
|
|
177
|
+
return false;
|
|
178
|
+
try {
|
|
179
|
+
response._writer.write(new TextEncoder().encode(String(chunk)));
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const emitResponseListeners = (listeners, event, args) => {
|
|
187
|
+
if (listeners[event] === undefined)
|
|
188
|
+
return;
|
|
189
|
+
[...listeners[event]].forEach((fn) => {
|
|
190
|
+
fn(...args);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const isRequestAborted = (request) => request.signal?.aborted === true;
|
|
160
194
|
const resData = (responseData, request) => {
|
|
161
195
|
return {
|
|
162
196
|
get statusCode() {
|
|
@@ -173,20 +207,7 @@ const resData = (responseData, request) => {
|
|
|
173
207
|
},
|
|
174
208
|
writeHead: function (statusCode, headers) {
|
|
175
209
|
this._writer = applyWriteHead(responseData, statusCode, headers);
|
|
176
|
-
|
|
177
|
-
if (request.signal && this._writer) {
|
|
178
|
-
request.signal.addEventListener('abort', () => {
|
|
179
|
-
if (this._writer) {
|
|
180
|
-
try {
|
|
181
|
-
this._writer.close();
|
|
182
|
-
}
|
|
183
|
-
catch {
|
|
184
|
-
// Ignore close errors
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
this.emit('close');
|
|
188
|
-
});
|
|
189
|
-
}
|
|
210
|
+
closeWriterOnAbort(request, this);
|
|
190
211
|
return this;
|
|
191
212
|
},
|
|
192
213
|
setHeader: function (name, value) {
|
|
@@ -209,16 +230,10 @@ const resData = (responseData, request) => {
|
|
|
209
230
|
},
|
|
210
231
|
write: function (chunk) {
|
|
211
232
|
if (this._writer) {
|
|
212
|
-
|
|
213
|
-
this._writer.write(new TextEncoder().encode(String(chunk)));
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
233
|
+
return writeToResponseWriter(this, chunk);
|
|
219
234
|
}
|
|
220
235
|
responseData.body = chunk;
|
|
221
|
-
return
|
|
236
|
+
return isRequestAborted(request) === false;
|
|
222
237
|
},
|
|
223
238
|
on: function (event, listener) {
|
|
224
239
|
this._listeners ??= {};
|
|
@@ -240,12 +255,7 @@ const resData = (responseData, request) => {
|
|
|
240
255
|
return this;
|
|
241
256
|
},
|
|
242
257
|
emit: function (event, ...args) {
|
|
243
|
-
|
|
244
|
-
// Create a copy to avoid issues if listeners remove themselves
|
|
245
|
-
[...this._listeners[event]].forEach((fn) => {
|
|
246
|
-
fn(...args);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
258
|
+
emitResponseListeners(this._listeners, event, args);
|
|
249
259
|
},
|
|
250
260
|
_writer: null,
|
|
251
261
|
_listeners: {},
|