@noony-serverless/core 0.2.2 → 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/README.md +7 -7
- package/build/core/containerPool.d.ts +44 -0
- package/build/core/containerPool.js +100 -0
- package/build/core/core.d.ts +68 -17
- package/build/core/core.js +63 -2
- package/build/core/errors.d.ts +43 -0
- package/build/core/errors.js +74 -1
- package/build/core/handler.d.ts +16 -37
- package/build/core/handler.js +42 -131
- package/build/core/index.d.ts +1 -0
- package/build/core/index.js +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +4 -0
- package/build/middlewares/bodyValidationMiddleware.d.ts +10 -12
- package/build/middlewares/bodyValidationMiddleware.js +7 -9
- package/build/middlewares/guards/RouteGuards.d.ts +2 -2
- package/build/middlewares/guards/RouteGuards.js +2 -2
- package/build/middlewares/guards/adapters/CustomTokenVerificationPortAdapter.d.ts +1 -1
- package/build/middlewares/guards/guards/FastAuthGuard.d.ts +5 -5
- package/build/middlewares/guards/guards/PermissionGuardFactory.d.ts +10 -2
- package/build/middlewares/guards/guards/PermissionGuardFactory.js +1 -1
- package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.js +1 -1
- package/build/middlewares/guards/resolvers/PermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/resolvers/PlainPermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/resolvers/WildcardPermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/services/FastUserContextService.d.ts +34 -10
- package/build/middlewares/index.d.ts +1 -3
- package/build/middlewares/index.js +1 -6
- package/build/middlewares/validationMiddleware.d.ts +154 -0
- package/build/middlewares/validationMiddleware.js +185 -0
- package/package.json +1 -3
package/build/core/handler.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Handler = void 0;
|
|
7
|
-
// Container import
|
|
8
|
-
const typedi_1 = __importDefault(require("typedi"));
|
|
4
|
+
// Container import removed - now using containerPool for performance
|
|
9
5
|
const core_1 = require("./core");
|
|
6
|
+
const containerPool_1 = require("./containerPool");
|
|
10
7
|
/**
|
|
11
8
|
* The Handler class is responsible for managing and executing middleware functions
|
|
12
9
|
* and a main handler function in a sequential and controlled manner.
|
|
@@ -15,8 +12,6 @@ const core_1 = require("./core");
|
|
|
15
12
|
* process a request/response flow either before the main handler (via `before`),
|
|
16
13
|
* after the main handler (via `after`), or handle errors (via `onError`).
|
|
17
14
|
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
15
|
* interface MessagePayload {
|
|
21
16
|
* action: string;
|
|
22
17
|
* data: Record<string, unknown>;
|
|
@@ -27,10 +22,10 @@ const core_1 = require("./core");
|
|
|
27
22
|
* .use(bodyParser())
|
|
28
23
|
* .handle(async (context) => {
|
|
29
24
|
* const { req } = context;
|
|
30
|
-
* // Handle the request
|
|
25
|
+
* // Handle the request
|
|
31
26
|
* });
|
|
32
|
-
* ```
|
|
33
27
|
* @template T Type for the input request data.
|
|
28
|
+
* @template U Type for the additional context or response data.
|
|
34
29
|
*/
|
|
35
30
|
class Handler {
|
|
36
31
|
baseMiddlewares = [];
|
|
@@ -45,9 +40,12 @@ class Handler {
|
|
|
45
40
|
return handler;
|
|
46
41
|
}
|
|
47
42
|
use(middleware) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const handler = new Handler();
|
|
44
|
+
handler.baseMiddlewares = [
|
|
45
|
+
...this.baseMiddlewares,
|
|
46
|
+
middleware,
|
|
47
|
+
];
|
|
48
|
+
return handler;
|
|
51
49
|
}
|
|
52
50
|
handle(handler) {
|
|
53
51
|
this.handler = handler;
|
|
@@ -65,17 +63,12 @@ class Handler {
|
|
|
65
63
|
this.errorMiddlewares = this.reversedMiddlewares.filter((m) => m.onError);
|
|
66
64
|
this.middlewaresPrecomputed = true;
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const req = this.adaptToNoonyRequest(nativeReq);
|
|
75
|
-
const res = this.adaptToNoonyResponse(nativeRes, nativeReq);
|
|
76
|
-
// Direct container creation - simpler and appropriate for serverless
|
|
77
|
-
const container = typedi_1.default.of();
|
|
78
|
-
const context = (0, core_1.createContext)(req, res, {
|
|
66
|
+
async execute(req, res) {
|
|
67
|
+
const genericReq = (0, core_1.adaptGCPRequest)(req);
|
|
68
|
+
const genericRes = (0, core_1.adaptGCPResponse)(res);
|
|
69
|
+
// Performance optimization: Use container pool instead of creating new containers
|
|
70
|
+
const container = containerPool_1.containerPool.acquire();
|
|
71
|
+
const context = (0, core_1.createContext)(genericReq, genericRes, {
|
|
79
72
|
container,
|
|
80
73
|
});
|
|
81
74
|
try {
|
|
@@ -90,7 +83,10 @@ class Handler {
|
|
|
90
83
|
// Execute error handlers using pre-computed array
|
|
91
84
|
await this.executeErrorMiddlewares(error, context);
|
|
92
85
|
}
|
|
93
|
-
|
|
86
|
+
finally {
|
|
87
|
+
// Always return container to pool for reuse
|
|
88
|
+
containerPool_1.containerPool.release(container);
|
|
89
|
+
}
|
|
94
90
|
}
|
|
95
91
|
/**
|
|
96
92
|
* Execute before middlewares with optimized batching for independent middlewares
|
|
@@ -125,115 +121,30 @@ class Handler {
|
|
|
125
121
|
}
|
|
126
122
|
}
|
|
127
123
|
/**
|
|
128
|
-
*
|
|
129
|
-
*/
|
|
130
|
-
adaptToNoonyRequest(nativeReq) {
|
|
131
|
-
const req = nativeReq;
|
|
132
|
-
// Universal property mapping that works with any HTTP framework
|
|
133
|
-
return {
|
|
134
|
-
method: req.method || req.httpMethod || core_1.HttpMethod.GET,
|
|
135
|
-
url: req.url || req.originalUrl || req.path || '/',
|
|
136
|
-
path: req.path || req.resource,
|
|
137
|
-
headers: req.headers || {},
|
|
138
|
-
query: req.query || req.queryStringParameters || {},
|
|
139
|
-
params: req.params || req.pathParameters || {},
|
|
140
|
-
body: req.body,
|
|
141
|
-
rawBody: req.rawBody || req.body,
|
|
142
|
-
parsedBody: req.parsedBody,
|
|
143
|
-
validatedBody: req.validatedBody,
|
|
144
|
-
ip: req.ip || req.requestContext?.identity?.sourceIp,
|
|
145
|
-
userAgent: (typeof req.headers?.['user-agent'] === 'string'
|
|
146
|
-
? req.headers['user-agent']
|
|
147
|
-
: Array.isArray(req.headers?.['user-agent'])
|
|
148
|
-
? req.headers['user-agent'][0]
|
|
149
|
-
: undefined) || req.get?.('user-agent'),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Universal response adapter - converts any framework's response to NoonyResponse
|
|
154
|
-
*/
|
|
155
|
-
adaptToNoonyResponse(nativeRes, nativeReq) {
|
|
156
|
-
const req = nativeReq;
|
|
157
|
-
// Detect AWS Lambda pattern (different from standard HTTP)
|
|
158
|
-
if (req?.requestContext && typeof nativeRes === 'function') {
|
|
159
|
-
return this.createAWSLambdaResponse(nativeRes);
|
|
160
|
-
}
|
|
161
|
-
// Standard HTTP response (GCP, Express, Fastify, etc.)
|
|
162
|
-
return this.createStandardHTTPResponse(nativeRes);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Create response adapter for AWS Lambda
|
|
166
|
-
*/
|
|
167
|
-
createAWSLambdaResponse(lambdaCallback) {
|
|
168
|
-
let statusCode = 200;
|
|
169
|
-
const headers = {};
|
|
170
|
-
let body;
|
|
171
|
-
return {
|
|
172
|
-
status: (code) => {
|
|
173
|
-
statusCode = code;
|
|
174
|
-
return this.createAWSLambdaResponse(lambdaCallback);
|
|
175
|
-
},
|
|
176
|
-
json: (data) => {
|
|
177
|
-
body = JSON.stringify(data);
|
|
178
|
-
headers['Content-Type'] = 'application/json';
|
|
179
|
-
lambdaCallback(null, { statusCode, headers, body });
|
|
180
|
-
},
|
|
181
|
-
send: (data) => {
|
|
182
|
-
body = data;
|
|
183
|
-
lambdaCallback(null, { statusCode, headers, body });
|
|
184
|
-
},
|
|
185
|
-
header: (name, value) => {
|
|
186
|
-
headers[name] = value;
|
|
187
|
-
return this.createAWSLambdaResponse(lambdaCallback);
|
|
188
|
-
},
|
|
189
|
-
headers: (newHeaders) => {
|
|
190
|
-
Object.assign(headers, newHeaders);
|
|
191
|
-
return this.createAWSLambdaResponse(lambdaCallback);
|
|
192
|
-
},
|
|
193
|
-
end: () => lambdaCallback(null, { statusCode, headers, body }),
|
|
194
|
-
statusCode,
|
|
195
|
-
headersSent: false,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Create response adapter for standard HTTP frameworks (GCP, Express, Fastify)
|
|
200
|
-
*/
|
|
201
|
-
createStandardHTTPResponse(nativeRes) {
|
|
202
|
-
const res = nativeRes;
|
|
203
|
-
return {
|
|
204
|
-
status: (code) => {
|
|
205
|
-
res.status(code);
|
|
206
|
-
return this.createStandardHTTPResponse(nativeRes);
|
|
207
|
-
},
|
|
208
|
-
json: (data) => res.json(data),
|
|
209
|
-
send: (data) => res.send(data),
|
|
210
|
-
header: (name, value) => {
|
|
211
|
-
res.header(name, value);
|
|
212
|
-
return this.createStandardHTTPResponse(nativeRes);
|
|
213
|
-
},
|
|
214
|
-
headers: (headers) => {
|
|
215
|
-
if (res.set) {
|
|
216
|
-
res.set(headers); // Express style
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
Object.entries(headers).forEach(([k, v]) => res.header(k, v)); // GCP style
|
|
220
|
-
}
|
|
221
|
-
return this.createStandardHTTPResponse(nativeRes);
|
|
222
|
-
},
|
|
223
|
-
end: () => res.end(),
|
|
224
|
-
get statusCode() {
|
|
225
|
-
return res.statusCode;
|
|
226
|
-
},
|
|
227
|
-
get headersSent() {
|
|
228
|
-
return res.headersSent;
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* @deprecated Use execute() instead - automatically detects framework
|
|
124
|
+
* Framework-agnostic execute method that works with GenericRequest/GenericResponse
|
|
234
125
|
*/
|
|
235
126
|
async executeGeneric(req, res) {
|
|
236
|
-
|
|
127
|
+
// Performance optimization: Use container pool instead of creating new containers
|
|
128
|
+
const container = containerPool_1.containerPool.acquire();
|
|
129
|
+
const context = (0, core_1.createContext)(req, res, {
|
|
130
|
+
container,
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
// Execute before middlewares with performance optimizations
|
|
134
|
+
await this.executeBeforeMiddlewares(context);
|
|
135
|
+
await this.handler(context);
|
|
136
|
+
// Execute after middlewares in reverse order using pre-computed array
|
|
137
|
+
await this.executeAfterMiddlewares(context);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
context.error = error;
|
|
141
|
+
// Execute error handlers using pre-computed array
|
|
142
|
+
await this.executeErrorMiddlewares(error, context);
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
// Always return container to pool for reuse
|
|
146
|
+
containerPool_1.containerPool.release(container);
|
|
147
|
+
}
|
|
237
148
|
}
|
|
238
149
|
}
|
|
239
150
|
exports.Handler = Handler;
|
package/build/core/index.d.ts
CHANGED
package/build/core/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./core"), exports);
|
|
|
18
18
|
__exportStar(require("./errors"), exports);
|
|
19
19
|
__exportStar(require("./handler"), exports);
|
|
20
20
|
__exportStar(require("./logger"), exports);
|
|
21
|
+
__exportStar(require("./containerPool"), exports);
|
|
21
22
|
__exportStar(require("./performanceMonitor"), exports);
|
|
22
23
|
__exportStar(require("../middlewares"), exports);
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -14,6 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Core exports
|
|
17
18
|
__exportStar(require("./core"), exports);
|
|
19
|
+
// Middleware exports
|
|
18
20
|
__exportStar(require("./middlewares"), exports);
|
|
21
|
+
// Utility exports
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
19
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -23,21 +23,20 @@ import { z } from 'zod';
|
|
|
23
23
|
*
|
|
24
24
|
* type UserRequest = z.infer<typeof userSchema>;
|
|
25
25
|
*
|
|
26
|
-
* async function handleCreateUser(context: Context<UserRequest>) {
|
|
26
|
+
* async function handleCreateUser(context: Context<UserRequest, AuthenticatedUser>) {
|
|
27
27
|
* const user = context.req.validatedBody!; // Fully typed
|
|
28
|
-
* const authenticatedUser = context.user; // User type inferred from auth middleware
|
|
29
28
|
* return { success: true, user: { id: '123', ...user } };
|
|
30
29
|
* }
|
|
31
30
|
*
|
|
32
|
-
* const createUserHandler = new Handler<UserRequest>()
|
|
33
|
-
* .use(new BodyValidationMiddleware<UserRequest>(userSchema))
|
|
31
|
+
* const createUserHandler = new Handler<UserRequest, AuthenticatedUser>()
|
|
32
|
+
* .use(new BodyValidationMiddleware<UserRequest, AuthenticatedUser>(userSchema))
|
|
34
33
|
* .handle(handleCreateUser);
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
|
-
export declare class BodyValidationMiddleware<T = unknown> implements BaseMiddleware<T> {
|
|
36
|
+
export declare class BodyValidationMiddleware<T = unknown, U = unknown> implements BaseMiddleware<T, U> {
|
|
38
37
|
private readonly schema;
|
|
39
38
|
constructor(schema: z.ZodSchema<T>);
|
|
40
|
-
before(context: Context<T>): Promise<void>;
|
|
39
|
+
before(context: Context<T, U>): Promise<void>;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Factory function that creates a body validation middleware with Zod schema validation.
|
|
@@ -60,19 +59,18 @@ export declare class BodyValidationMiddleware<T = unknown> implements BaseMiddle
|
|
|
60
59
|
*
|
|
61
60
|
* type LoginRequest = z.infer<typeof loginSchema>;
|
|
62
61
|
*
|
|
63
|
-
* async function handleLogin(context: Context<LoginRequest>) {
|
|
62
|
+
* async function handleLogin(context: Context<LoginRequest, AuthenticatedUser>) {
|
|
64
63
|
* const credentials = context.req.parsedBody as LoginRequest;
|
|
65
64
|
* const token = await authenticate(credentials.username, credentials.password);
|
|
66
|
-
* const authenticatedUser = context.user; // User type from auth middleware
|
|
67
65
|
* return { success: true, token };
|
|
68
66
|
* }
|
|
69
67
|
*
|
|
70
|
-
* const loginHandler = new Handler<LoginRequest>()
|
|
71
|
-
* .use(bodyValidatorMiddleware<LoginRequest>(loginSchema))
|
|
68
|
+
* const loginHandler = new Handler<LoginRequest, AuthenticatedUser>()
|
|
69
|
+
* .use(bodyValidatorMiddleware<LoginRequest, AuthenticatedUser>(loginSchema))
|
|
72
70
|
* .handle(handleLogin);
|
|
73
71
|
* ```
|
|
74
72
|
*/
|
|
75
|
-
export declare const bodyValidatorMiddleware: <T>(schema: z.ZodType<T>) => {
|
|
76
|
-
before: (context: Context<T>) => Promise<void>;
|
|
73
|
+
export declare const bodyValidatorMiddleware: <T, U = unknown>(schema: z.ZodType<T>) => {
|
|
74
|
+
before: (context: Context<T, U>) => Promise<void>;
|
|
77
75
|
};
|
|
78
76
|
//# sourceMappingURL=bodyValidationMiddleware.d.ts.map
|
|
@@ -36,14 +36,13 @@ const validateBody = async (schema, data) => {
|
|
|
36
36
|
*
|
|
37
37
|
* type UserRequest = z.infer<typeof userSchema>;
|
|
38
38
|
*
|
|
39
|
-
* async function handleCreateUser(context: Context<UserRequest>) {
|
|
39
|
+
* async function handleCreateUser(context: Context<UserRequest, AuthenticatedUser>) {
|
|
40
40
|
* const user = context.req.validatedBody!; // Fully typed
|
|
41
|
-
* const authenticatedUser = context.user; // User type inferred from auth middleware
|
|
42
41
|
* return { success: true, user: { id: '123', ...user } };
|
|
43
42
|
* }
|
|
44
43
|
*
|
|
45
|
-
* const createUserHandler = new Handler<UserRequest>()
|
|
46
|
-
* .use(new BodyValidationMiddleware<UserRequest>(userSchema))
|
|
44
|
+
* const createUserHandler = new Handler<UserRequest, AuthenticatedUser>()
|
|
45
|
+
* .use(new BodyValidationMiddleware<UserRequest, AuthenticatedUser>(userSchema))
|
|
47
46
|
* .handle(handleCreateUser);
|
|
48
47
|
* ```
|
|
49
48
|
*/
|
|
@@ -78,19 +77,18 @@ exports.BodyValidationMiddleware = BodyValidationMiddleware;
|
|
|
78
77
|
*
|
|
79
78
|
* type LoginRequest = z.infer<typeof loginSchema>;
|
|
80
79
|
*
|
|
81
|
-
* async function handleLogin(context: Context<LoginRequest>) {
|
|
80
|
+
* async function handleLogin(context: Context<LoginRequest, AuthenticatedUser>) {
|
|
82
81
|
* const credentials = context.req.parsedBody as LoginRequest;
|
|
83
82
|
* const token = await authenticate(credentials.username, credentials.password);
|
|
84
|
-
* const authenticatedUser = context.user; // User type from auth middleware
|
|
85
83
|
* return { success: true, token };
|
|
86
84
|
* }
|
|
87
85
|
*
|
|
88
|
-
* const loginHandler = new Handler<LoginRequest>()
|
|
89
|
-
* .use(bodyValidatorMiddleware<LoginRequest>(loginSchema))
|
|
86
|
+
* const loginHandler = new Handler<LoginRequest, AuthenticatedUser>()
|
|
87
|
+
* .use(bodyValidatorMiddleware<LoginRequest, AuthenticatedUser>(loginSchema))
|
|
90
88
|
* .handle(handleLogin);
|
|
91
89
|
* ```
|
|
92
90
|
*/
|
|
93
|
-
//
|
|
91
|
+
// Modified to fix type instantiation error
|
|
94
92
|
const bodyValidatorMiddleware = (schema) => ({
|
|
95
93
|
before: async (context) => {
|
|
96
94
|
context.req.parsedBody = await validateBody(schema, context.req.body);
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
* return { valid: false, error: error.message };
|
|
43
43
|
* }
|
|
44
44
|
* },
|
|
45
|
-
* extractUserId: (decoded:
|
|
46
|
-
* isTokenExpired: (decoded:
|
|
45
|
+
* extractUserId: (decoded: any) => decoded.sub,
|
|
46
|
+
* isTokenExpired: (decoded: any) => decoded.exp < Date.now() / 1000
|
|
47
47
|
* };
|
|
48
48
|
*
|
|
49
49
|
* // Configure guard system
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
* return { valid: false, error: error.message };
|
|
44
44
|
* }
|
|
45
45
|
* },
|
|
46
|
-
* extractUserId: (decoded:
|
|
47
|
-
* isTokenExpired: (decoded:
|
|
46
|
+
* extractUserId: (decoded: any) => decoded.sub,
|
|
47
|
+
* isTokenExpired: (decoded: any) => decoded.exp < Date.now() / 1000
|
|
48
48
|
* };
|
|
49
49
|
*
|
|
50
50
|
* // Configure guard system
|
|
@@ -245,7 +245,7 @@ export declare class TokenVerificationAdapterFactory {
|
|
|
245
245
|
* @param expirationField - Optional field name for expiration (e.g., 'expiresAt', 'exp')
|
|
246
246
|
* @returns Configured adapter for API key tokens
|
|
247
247
|
*/
|
|
248
|
-
static forAPIKey<T extends Record<string,
|
|
248
|
+
static forAPIKey<T extends Record<string, any>>(verificationPort: CustomTokenVerificationPort<T>, userIdField: keyof T, expirationField?: keyof T): CustomTokenVerificationPortAdapter<T>;
|
|
249
249
|
/**
|
|
250
250
|
* Create adapter for OAuth tokens with standard OAuth claims.
|
|
251
251
|
*
|
|
@@ -43,7 +43,7 @@ export interface AuthenticationResult {
|
|
|
43
43
|
success: boolean;
|
|
44
44
|
user?: UserContext;
|
|
45
45
|
token?: {
|
|
46
|
-
decoded:
|
|
46
|
+
decoded: any;
|
|
47
47
|
raw: string;
|
|
48
48
|
expiresAt: string;
|
|
49
49
|
issuer?: string;
|
|
@@ -63,7 +63,7 @@ export interface AuthGuardConfig {
|
|
|
63
63
|
allowedIssuers?: string[];
|
|
64
64
|
requireEmailVerification: boolean;
|
|
65
65
|
allowInactiveUsers: boolean;
|
|
66
|
-
customValidation?: (token:
|
|
66
|
+
customValidation?: (token: any, user: UserContext) => Promise<boolean>;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Token validation service interface
|
|
@@ -74,17 +74,17 @@ export interface TokenValidator {
|
|
|
74
74
|
*/
|
|
75
75
|
validateToken(token: string): Promise<{
|
|
76
76
|
valid: boolean;
|
|
77
|
-
decoded?:
|
|
77
|
+
decoded?: any;
|
|
78
78
|
error?: string;
|
|
79
79
|
}>;
|
|
80
80
|
/**
|
|
81
81
|
* Extract user ID from decoded token
|
|
82
82
|
*/
|
|
83
|
-
extractUserId(decoded:
|
|
83
|
+
extractUserId(decoded: any): string;
|
|
84
84
|
/**
|
|
85
85
|
* Check if token is expired
|
|
86
86
|
*/
|
|
87
|
-
isTokenExpired(decoded:
|
|
87
|
+
isTokenExpired(decoded: any): boolean;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Fast Authentication Guard Implementation
|
|
@@ -162,8 +162,16 @@ export declare class PermissionGuardFactory {
|
|
|
162
162
|
getStats(): {
|
|
163
163
|
totalGuards: number;
|
|
164
164
|
guardsByType: Record<string, number>;
|
|
165
|
-
individualGuardStats:
|
|
166
|
-
|
|
165
|
+
individualGuardStats: {
|
|
166
|
+
guardType: string;
|
|
167
|
+
checkCount: number;
|
|
168
|
+
successCount: number;
|
|
169
|
+
failureCount: number;
|
|
170
|
+
successRate: number;
|
|
171
|
+
averageProcessingTimeUs: number;
|
|
172
|
+
totalProcessingTimeUs: number;
|
|
173
|
+
}[];
|
|
174
|
+
aggregatedStats: any;
|
|
167
175
|
};
|
|
168
176
|
/**
|
|
169
177
|
* Clear guard cache
|
|
@@ -388,7 +388,7 @@ let PermissionGuardFactory = class PermissionGuardFactory {
|
|
|
388
388
|
createCompositeGuard(requirements, config = {}) {
|
|
389
389
|
const fullConfig = {
|
|
390
390
|
requireAuth: true,
|
|
391
|
-
permissions: requirements, // Store requirements as permissions for cache key
|
|
391
|
+
permissions: requirements, // Store requirements as permissions for cache key (complex composite type)
|
|
392
392
|
cacheResults: true,
|
|
393
393
|
auditTrail: false,
|
|
394
394
|
...config,
|
|
@@ -118,7 +118,7 @@ export declare class ExpressionPermissionResolver extends PermissionResolver<Per
|
|
|
118
118
|
/**
|
|
119
119
|
* Check if this resolver can handle the given requirement type
|
|
120
120
|
*/
|
|
121
|
-
canHandle(requirement:
|
|
121
|
+
canHandle(requirement: any): requirement is PermissionExpression;
|
|
122
122
|
/**
|
|
123
123
|
* Normalize expression for consistent cache keys
|
|
124
124
|
*
|
|
@@ -412,7 +412,7 @@ class ExpressionPermissionResolver extends PermissionResolver_1.PermissionResolv
|
|
|
412
412
|
* Check if this resolver can handle the given requirement type
|
|
413
413
|
*/
|
|
414
414
|
canHandle(requirement) {
|
|
415
|
-
return
|
|
415
|
+
return (requirement &&
|
|
416
416
|
typeof requirement === 'object' &&
|
|
417
417
|
PermissionResolver_1.PermissionUtils.isValidExpression(requirement));
|
|
418
418
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* different types of permission requirements. The generic type T represents
|
|
20
20
|
* the specific requirement format for each resolver.
|
|
21
21
|
*/
|
|
22
|
-
export declare abstract class PermissionResolver<T =
|
|
22
|
+
export declare abstract class PermissionResolver<T = any> {
|
|
23
23
|
/**
|
|
24
24
|
* Check if user permissions satisfy the requirement
|
|
25
25
|
*
|
|
@@ -96,6 +96,6 @@ export declare class PlainPermissionResolver extends PermissionResolver<string[]
|
|
|
96
96
|
* @param requirement - The requirement to check
|
|
97
97
|
* @returns true if this resolver can handle the requirement
|
|
98
98
|
*/
|
|
99
|
-
canHandle(requirement:
|
|
99
|
+
canHandle(requirement: any): requirement is string[];
|
|
100
100
|
}
|
|
101
101
|
//# sourceMappingURL=PlainPermissionResolver.d.ts.map
|
|
@@ -141,6 +141,6 @@ export declare class WildcardPermissionResolver extends PermissionResolver<strin
|
|
|
141
141
|
/**
|
|
142
142
|
* Check if this resolver can handle the given requirement type
|
|
143
143
|
*/
|
|
144
|
-
canHandle(requirement:
|
|
144
|
+
canHandle(requirement: any): requirement is string[];
|
|
145
145
|
}
|
|
146
146
|
//# sourceMappingURL=WildcardPermissionResolver.d.ts.map
|
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
* @version 1.0.0
|
|
24
24
|
*/
|
|
25
25
|
import { CacheAdapter } from '../cache/CacheAdapter';
|
|
26
|
-
import { GuardConfiguration } from '../config/GuardConfiguration';
|
|
26
|
+
import { GuardConfiguration, PermissionResolutionStrategy } from '../config/GuardConfiguration';
|
|
27
27
|
import { PermissionRegistry } from '../registry/PermissionRegistry';
|
|
28
28
|
import { PermissionResolverType, PermissionCheckResult, PermissionExpression } from '../resolvers/PermissionResolver';
|
|
29
29
|
/**
|
|
30
30
|
* Type alias for permission requirements that can be strings, string arrays, or complex expressions
|
|
31
|
+
* Note: Currently defined but reserved for future use
|
|
31
32
|
*/
|
|
32
|
-
type PermissionRequirement = string | string[] | PermissionExpression | Record<string, unknown>;
|
|
33
|
+
export type PermissionRequirement = string | string[] | PermissionExpression | Record<string, unknown>;
|
|
33
34
|
/**
|
|
34
35
|
* User context with cached permissions and metadata
|
|
35
36
|
*/
|
|
@@ -37,7 +38,7 @@ export interface UserContext {
|
|
|
37
38
|
userId: string;
|
|
38
39
|
permissions: Set<string>;
|
|
39
40
|
roles: string[];
|
|
40
|
-
metadata: Record<string,
|
|
41
|
+
metadata: Record<string, any>;
|
|
41
42
|
expandedPermissions?: Set<string>;
|
|
42
43
|
lastUpdated: string;
|
|
43
44
|
expiresAt?: string;
|
|
@@ -52,7 +53,7 @@ export interface UserPermissionSource {
|
|
|
52
53
|
getUserPermissions(userId: string): Promise<{
|
|
53
54
|
permissions: string[];
|
|
54
55
|
roles: string[];
|
|
55
|
-
metadata?: Record<string,
|
|
56
|
+
metadata?: Record<string, any>;
|
|
56
57
|
} | null>;
|
|
57
58
|
/**
|
|
58
59
|
* Get role-based permissions for expansion
|
|
@@ -117,7 +118,7 @@ export declare class FastUserContextService {
|
|
|
117
118
|
* @param options - Check options
|
|
118
119
|
* @returns Detailed permission check result
|
|
119
120
|
*/
|
|
120
|
-
checkPermission(userId: string, requirement:
|
|
121
|
+
checkPermission(userId: string, requirement: any, options?: PermissionCheckOptions): Promise<PermissionCheckResult>;
|
|
121
122
|
/**
|
|
122
123
|
* Batch check multiple permissions for a user
|
|
123
124
|
*
|
|
@@ -130,7 +131,7 @@ export declare class FastUserContextService {
|
|
|
130
131
|
* @returns Array of permission check results
|
|
131
132
|
*/
|
|
132
133
|
checkPermissions(userId: string, requirements: Array<{
|
|
133
|
-
requirement:
|
|
134
|
+
requirement: any;
|
|
134
135
|
resolverType?: PermissionResolverType;
|
|
135
136
|
}>, options?: PermissionCheckOptions): Promise<PermissionCheckResult[]>;
|
|
136
137
|
/**
|
|
@@ -165,9 +166,33 @@ export declare class FastUserContextService {
|
|
|
165
166
|
averageResolutionTimeUs: number;
|
|
166
167
|
totalResolutionTimeUs: number;
|
|
167
168
|
resolverStats: {
|
|
168
|
-
plain:
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
plain: {
|
|
170
|
+
checkCount: number;
|
|
171
|
+
averageResolutionTimeUs: number;
|
|
172
|
+
totalResolutionTimeUs: number;
|
|
173
|
+
};
|
|
174
|
+
wildcard: {
|
|
175
|
+
strategy: PermissionResolutionStrategy;
|
|
176
|
+
checkCount: number;
|
|
177
|
+
averageResolutionTimeUs: number;
|
|
178
|
+
totalResolutionTimeUs: number;
|
|
179
|
+
cacheHitRate: number;
|
|
180
|
+
cacheHits: number;
|
|
181
|
+
cacheMisses: number;
|
|
182
|
+
};
|
|
183
|
+
expression: {
|
|
184
|
+
checkCount: number;
|
|
185
|
+
averageResolutionTimeUs: number;
|
|
186
|
+
totalResolutionTimeUs: number;
|
|
187
|
+
cacheHitRate: number;
|
|
188
|
+
cacheHits: number;
|
|
189
|
+
cacheMisses: number;
|
|
190
|
+
complexityDistribution: {
|
|
191
|
+
simple: number;
|
|
192
|
+
moderate: number;
|
|
193
|
+
complex: number;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
171
196
|
};
|
|
172
197
|
};
|
|
173
198
|
/**
|
|
@@ -199,5 +224,4 @@ export declare class FastUserContextService {
|
|
|
199
224
|
*/
|
|
200
225
|
private recordAuditTrail;
|
|
201
226
|
}
|
|
202
|
-
export {};
|
|
203
227
|
//# sourceMappingURL=FastUserContextService.d.ts.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export * from './SecurityMiddleware';
|
|
2
|
-
export * from './ConsolidatedValidationMiddleware';
|
|
3
|
-
export * from './ProcessingMiddleware';
|
|
4
1
|
export * from './authenticationMiddleware';
|
|
5
2
|
export * from './bodyParserMiddleware';
|
|
6
3
|
export * from './bodyValidationMiddleware';
|
|
@@ -13,5 +10,6 @@ export * from './rateLimitingMiddleware';
|
|
|
13
10
|
export * from './responseWrapperMiddleware';
|
|
14
11
|
export * from './securityAuditMiddleware';
|
|
15
12
|
export * from './securityHeadersMiddleware';
|
|
13
|
+
export * from './validationMiddleware';
|
|
16
14
|
export * from './guards';
|
|
17
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -14,11 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// === NEW CONSOLIDATED MIDDLEWARES ===
|
|
18
|
-
__exportStar(require("./SecurityMiddleware"), exports);
|
|
19
|
-
__exportStar(require("./ConsolidatedValidationMiddleware"), exports);
|
|
20
|
-
__exportStar(require("./ProcessingMiddleware"), exports);
|
|
21
|
-
// === EXISTING INDIVIDUAL MIDDLEWARES (for backward compatibility) ===
|
|
22
17
|
__exportStar(require("./authenticationMiddleware"), exports);
|
|
23
18
|
__exportStar(require("./bodyParserMiddleware"), exports);
|
|
24
19
|
__exportStar(require("./bodyValidationMiddleware"), exports);
|
|
@@ -31,6 +26,6 @@ __exportStar(require("./rateLimitingMiddleware"), exports);
|
|
|
31
26
|
__exportStar(require("./responseWrapperMiddleware"), exports);
|
|
32
27
|
__exportStar(require("./securityAuditMiddleware"), exports);
|
|
33
28
|
__exportStar(require("./securityHeadersMiddleware"), exports);
|
|
34
|
-
|
|
29
|
+
__exportStar(require("./validationMiddleware"), exports);
|
|
35
30
|
__exportStar(require("./guards"), exports);
|
|
36
31
|
//# sourceMappingURL=index.js.map
|