@noony-serverless/core 0.3.0 → 0.3.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/build/middlewares/authenticationMiddleware.d.ts +8 -6
- package/build/middlewares/authenticationMiddleware.js +4 -2
- package/build/middlewares/bodyParserMiddleware.d.ts +7 -5
- package/build/middlewares/bodyParserMiddleware.js +4 -2
- package/build/middlewares/errorHandlerMiddleware.d.ts +8 -3
- package/build/middlewares/errorHandlerMiddleware.js +7 -0
- package/build/middlewares/queryParametersMiddleware.d.ts +7 -3
- package/build/middlewares/queryParametersMiddleware.js +4 -0
- package/build/middlewares/responseWrapperMiddleware.d.ts +10 -4
- package/build/middlewares/responseWrapperMiddleware.js +6 -0
- package/package.json +1 -1
|
@@ -209,7 +209,8 @@ export interface AuthenticationOptions {
|
|
|
209
209
|
* Class-based authentication middleware with comprehensive security features.
|
|
210
210
|
* Provides JWT validation, rate limiting, token blacklisting, and security logging.
|
|
211
211
|
*
|
|
212
|
-
* @template
|
|
212
|
+
* @template TUser - The type of user data returned by the token verification port
|
|
213
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
213
214
|
*
|
|
214
215
|
* @example
|
|
215
216
|
* Basic JWT authentication:
|
|
@@ -292,17 +293,18 @@ export interface AuthenticationOptions {
|
|
|
292
293
|
* });
|
|
293
294
|
* ```
|
|
294
295
|
*/
|
|
295
|
-
export declare class AuthenticationMiddleware<
|
|
296
|
+
export declare class AuthenticationMiddleware<TUser = unknown, TBody = unknown> implements BaseMiddleware<TBody, TUser> {
|
|
296
297
|
private tokenVerificationPort;
|
|
297
298
|
private options;
|
|
298
|
-
constructor(tokenVerificationPort: CustomTokenVerificationPort<
|
|
299
|
-
before(context: Context): Promise<void>;
|
|
299
|
+
constructor(tokenVerificationPort: CustomTokenVerificationPort<TUser>, options?: AuthenticationOptions);
|
|
300
|
+
before(context: Context<TBody, TUser>): Promise<void>;
|
|
300
301
|
}
|
|
301
302
|
/**
|
|
302
303
|
* Factory function that creates an authentication middleware with token verification.
|
|
303
304
|
* Provides a functional approach for authentication setup.
|
|
304
305
|
*
|
|
305
|
-
* @template
|
|
306
|
+
* @template TUser - The type of user data returned by the token verification port
|
|
307
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
306
308
|
* @param tokenVerificationPort - The token verification implementation
|
|
307
309
|
* @param options - Authentication configuration options
|
|
308
310
|
* @returns A BaseMiddleware object with authentication logic
|
|
@@ -427,5 +429,5 @@ export declare class AuthenticationMiddleware<T> implements BaseMiddleware {
|
|
|
427
429
|
* };
|
|
428
430
|
* ```
|
|
429
431
|
*/
|
|
430
|
-
export declare const verifyAuthTokenMiddleware: <
|
|
432
|
+
export declare const verifyAuthTokenMiddleware: <TUser = unknown, TBody = unknown>(tokenVerificationPort: CustomTokenVerificationPort<TUser>, options?: AuthenticationOptions) => BaseMiddleware<TBody, TUser>;
|
|
431
433
|
//# sourceMappingURL=authenticationMiddleware.d.ts.map
|
|
@@ -173,7 +173,8 @@ async function verifyToken(tokenVerificationPort, context, options = {}) {
|
|
|
173
173
|
* Class-based authentication middleware with comprehensive security features.
|
|
174
174
|
* Provides JWT validation, rate limiting, token blacklisting, and security logging.
|
|
175
175
|
*
|
|
176
|
-
* @template
|
|
176
|
+
* @template TUser - The type of user data returned by the token verification port
|
|
177
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
177
178
|
*
|
|
178
179
|
* @example
|
|
179
180
|
* Basic JWT authentication:
|
|
@@ -272,7 +273,8 @@ exports.AuthenticationMiddleware = AuthenticationMiddleware;
|
|
|
272
273
|
* Factory function that creates an authentication middleware with token verification.
|
|
273
274
|
* Provides a functional approach for authentication setup.
|
|
274
275
|
*
|
|
275
|
-
* @template
|
|
276
|
+
* @template TUser - The type of user data returned by the token verification port
|
|
277
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
276
278
|
* @param tokenVerificationPort - The token verification implementation
|
|
277
279
|
* @param options - Authentication configuration options
|
|
278
280
|
* @returns A BaseMiddleware object with authentication logic
|
|
@@ -8,7 +8,8 @@ import { BaseMiddleware, Context } from '../core';
|
|
|
8
8
|
* - Base64 decoding for Pub/Sub messages
|
|
9
9
|
* - Non-blocking parsing using setImmediate
|
|
10
10
|
*
|
|
11
|
-
* @template
|
|
11
|
+
* @template TBody - The expected type of the parsed body. Defaults to unknown if not specified.
|
|
12
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
12
13
|
* @implements {BaseMiddleware}
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
@@ -63,10 +64,10 @@ import { BaseMiddleware, Context } from '../core';
|
|
|
63
64
|
* });
|
|
64
65
|
* ```
|
|
65
66
|
*/
|
|
66
|
-
export declare class BodyParserMiddleware<
|
|
67
|
+
export declare class BodyParserMiddleware<TBody = unknown, TUser = unknown> implements BaseMiddleware<TBody, TUser> {
|
|
67
68
|
private maxSize;
|
|
68
69
|
constructor(maxSize?: number);
|
|
69
|
-
before(context: Context): Promise<void>;
|
|
70
|
+
before(context: Context<TBody, TUser>): Promise<void>;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* Enhanced middleware function for parsing the request body in specific HTTP methods.
|
|
@@ -76,7 +77,8 @@ export declare class BodyParserMiddleware<T = unknown> implements BaseMiddleware
|
|
|
76
77
|
* - Async parsing for large payloads
|
|
77
78
|
* - Size validation
|
|
78
79
|
*
|
|
79
|
-
* @template
|
|
80
|
+
* @template TBody - The expected type of the parsed request body.
|
|
81
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
80
82
|
* @param maxSize - Maximum allowed body size in bytes (default: 1MB)
|
|
81
83
|
* @returns {BaseMiddleware} A middleware object containing a `before` hook.
|
|
82
84
|
*
|
|
@@ -126,5 +128,5 @@ export declare class BodyParserMiddleware<T = unknown> implements BaseMiddleware
|
|
|
126
128
|
* });
|
|
127
129
|
* ```
|
|
128
130
|
*/
|
|
129
|
-
export declare const bodyParser: <
|
|
131
|
+
export declare const bodyParser: <TBody = unknown, TUser = unknown>(maxSize?: number) => BaseMiddleware<TBody, TUser>;
|
|
130
132
|
//# sourceMappingURL=bodyParserMiddleware.d.ts.map
|
|
@@ -157,7 +157,8 @@ const parseBody = async (body) => {
|
|
|
157
157
|
* - Base64 decoding for Pub/Sub messages
|
|
158
158
|
* - Non-blocking parsing using setImmediate
|
|
159
159
|
*
|
|
160
|
-
* @template
|
|
160
|
+
* @template TBody - The expected type of the parsed body. Defaults to unknown if not specified.
|
|
161
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
161
162
|
* @implements {BaseMiddleware}
|
|
162
163
|
*
|
|
163
164
|
* @example
|
|
@@ -241,7 +242,8 @@ exports.BodyParserMiddleware = BodyParserMiddleware;
|
|
|
241
242
|
* - Async parsing for large payloads
|
|
242
243
|
* - Size validation
|
|
243
244
|
*
|
|
244
|
-
* @template
|
|
245
|
+
* @template TBody - The expected type of the parsed request body.
|
|
246
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
245
247
|
* @param maxSize - Maximum allowed body size in bytes (default: 1MB)
|
|
246
248
|
* @returns {BaseMiddleware} A middleware object containing a `before` hook.
|
|
247
249
|
*
|
|
@@ -4,6 +4,9 @@ import { BaseMiddleware, Context } from '../core';
|
|
|
4
4
|
* Implements the `BaseMiddleware` interface and provides an asynchronous
|
|
5
5
|
* `onError` method that delegates error handling to the `handleError` function.
|
|
6
6
|
*
|
|
7
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
8
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
9
|
+
*
|
|
7
10
|
* @remarks
|
|
8
11
|
* This middleware should be registered to catch and process errors that occur
|
|
9
12
|
* during request handling.
|
|
@@ -50,12 +53,14 @@ import { BaseMiddleware, Context } from '../core';
|
|
|
50
53
|
* });
|
|
51
54
|
* ```
|
|
52
55
|
*/
|
|
53
|
-
export declare class ErrorHandlerMiddleware implements BaseMiddleware {
|
|
54
|
-
onError(error: Error, context: Context): Promise<void>;
|
|
56
|
+
export declare class ErrorHandlerMiddleware<TBody = unknown, TUser = unknown> implements BaseMiddleware<TBody, TUser> {
|
|
57
|
+
onError(error: Error, context: Context<TBody, TUser>): Promise<void>;
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
60
|
* Creates an error handling middleware for processing errors in the application.
|
|
58
61
|
*
|
|
62
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
63
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
59
64
|
* @returns {BaseMiddleware} An object implementing the `onError` method to handle errors.
|
|
60
65
|
*
|
|
61
66
|
* @remarks
|
|
@@ -96,5 +101,5 @@ export declare class ErrorHandlerMiddleware implements BaseMiddleware {
|
|
|
96
101
|
* });
|
|
97
102
|
* ```
|
|
98
103
|
*/
|
|
99
|
-
export declare const errorHandler: () => BaseMiddleware
|
|
104
|
+
export declare const errorHandler: <TBody = unknown, TUser = unknown>() => BaseMiddleware<TBody, TUser>;
|
|
100
105
|
//# sourceMappingURL=errorHandlerMiddleware.d.ts.map
|
|
@@ -9,6 +9,8 @@ const core_1 = require("../core");
|
|
|
9
9
|
* - For `HttpError` instances, responds with the error message, and optionally details and code based on environment and error type.
|
|
10
10
|
* - For other errors, responds with a generic message in production, and includes stack trace in development.
|
|
11
11
|
*
|
|
12
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
13
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
12
14
|
* @param error - The error object thrown during request processing.
|
|
13
15
|
* @param context - The request context containing request and response objects.
|
|
14
16
|
* @returns A promise that resolves when the error response has been sent.
|
|
@@ -65,6 +67,9 @@ const handleError = async (error, context) => {
|
|
|
65
67
|
* Implements the `BaseMiddleware` interface and provides an asynchronous
|
|
66
68
|
* `onError` method that delegates error handling to the `handleError` function.
|
|
67
69
|
*
|
|
70
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
71
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
72
|
+
*
|
|
68
73
|
* @remarks
|
|
69
74
|
* This middleware should be registered to catch and process errors that occur
|
|
70
75
|
* during request handling.
|
|
@@ -120,6 +125,8 @@ exports.ErrorHandlerMiddleware = ErrorHandlerMiddleware;
|
|
|
120
125
|
/**
|
|
121
126
|
* Creates an error handling middleware for processing errors in the application.
|
|
122
127
|
*
|
|
128
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
129
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
123
130
|
* @returns {BaseMiddleware} An object implementing the `onError` method to handle errors.
|
|
124
131
|
*
|
|
125
132
|
* @remarks
|
|
@@ -3,6 +3,8 @@ import { BaseMiddleware, Context } from '../core';
|
|
|
3
3
|
* Middleware class that validates and processes query parameters from the request URL.
|
|
4
4
|
* Extracts query parameters and validates that required parameters are present.
|
|
5
5
|
*
|
|
6
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
7
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
6
8
|
* @implements {BaseMiddleware}
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
@@ -43,15 +45,17 @@ import { BaseMiddleware, Context } from '../core';
|
|
|
43
45
|
* });
|
|
44
46
|
* ```
|
|
45
47
|
*/
|
|
46
|
-
export declare class QueryParametersMiddleware implements BaseMiddleware {
|
|
48
|
+
export declare class QueryParametersMiddleware<TBody = unknown, TUser = unknown> implements BaseMiddleware<TBody, TUser> {
|
|
47
49
|
private readonly requiredParams;
|
|
48
50
|
constructor(requiredParams?: string[]);
|
|
49
|
-
before(context: Context): Promise<void>;
|
|
51
|
+
before(context: Context<TBody, TUser>): Promise<void>;
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* Factory function that creates a query parameter processing middleware.
|
|
53
55
|
* Extracts and validates query parameters from the request URL.
|
|
54
56
|
*
|
|
57
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
58
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
55
59
|
* @param requiredParams - Array of parameter names that must be present (default: empty array)
|
|
56
60
|
* @returns BaseMiddleware object with query parameter processing logic
|
|
57
61
|
*
|
|
@@ -109,5 +113,5 @@ export declare class QueryParametersMiddleware implements BaseMiddleware {
|
|
|
109
113
|
* });
|
|
110
114
|
* ```
|
|
111
115
|
*/
|
|
112
|
-
export declare const queryParametersMiddleware: (requiredParams?: string[]) => BaseMiddleware
|
|
116
|
+
export declare const queryParametersMiddleware: <TBody = unknown, TUser = unknown>(requiredParams?: string[]) => BaseMiddleware<TBody, TUser>;
|
|
113
117
|
//# sourceMappingURL=queryParametersMiddleware.d.ts.map
|
|
@@ -24,6 +24,8 @@ const convertQueryToRecord = (query) => {
|
|
|
24
24
|
* Middleware class that validates and processes query parameters from the request URL.
|
|
25
25
|
* Extracts query parameters and validates that required parameters are present.
|
|
26
26
|
*
|
|
27
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
28
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
27
29
|
* @implements {BaseMiddleware}
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
@@ -84,6 +86,8 @@ exports.QueryParametersMiddleware = QueryParametersMiddleware;
|
|
|
84
86
|
* Factory function that creates a query parameter processing middleware.
|
|
85
87
|
* Extracts and validates query parameters from the request URL.
|
|
86
88
|
*
|
|
89
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
90
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
87
91
|
* @param requiredParams - Array of parameter names that must be present (default: empty array)
|
|
88
92
|
* @returns BaseMiddleware object with query parameter processing logic
|
|
89
93
|
*
|
|
@@ -5,6 +5,8 @@ import { Context } from '../core/core';
|
|
|
5
5
|
* Automatically wraps the response with success flag, payload, and timestamp.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of response data being wrapped
|
|
8
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
9
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
8
10
|
* @implements {BaseMiddleware}
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
@@ -60,14 +62,16 @@ import { Context } from '../core/core';
|
|
|
60
62
|
* });
|
|
61
63
|
* ```
|
|
62
64
|
*/
|
|
63
|
-
export declare class ResponseWrapperMiddleware<T> implements BaseMiddleware {
|
|
64
|
-
after(context: Context): Promise<void>;
|
|
65
|
+
export declare class ResponseWrapperMiddleware<T = unknown, TBody = unknown, TUser = unknown> implements BaseMiddleware<TBody, TUser> {
|
|
66
|
+
after(context: Context<TBody, TUser>): Promise<void>;
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* Factory function that creates a response wrapper middleware.
|
|
68
70
|
* Automatically wraps response data in a standardized format with success flag and timestamp.
|
|
69
71
|
*
|
|
70
72
|
* @template T - The type of response data being wrapped
|
|
73
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
74
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
71
75
|
* @returns BaseMiddleware object with response wrapping logic
|
|
72
76
|
*
|
|
73
77
|
* @example
|
|
@@ -118,12 +122,14 @@ export declare class ResponseWrapperMiddleware<T> implements BaseMiddleware {
|
|
|
118
122
|
* });
|
|
119
123
|
* ```
|
|
120
124
|
*/
|
|
121
|
-
export declare const responseWrapperMiddleware: <T>() => BaseMiddleware
|
|
125
|
+
export declare const responseWrapperMiddleware: <T = unknown, TBody = unknown, TUser = unknown>() => BaseMiddleware<TBody, TUser>;
|
|
122
126
|
/**
|
|
123
127
|
* Helper function to set response data in context for later wrapping.
|
|
124
128
|
* This function should be used in handlers when using ResponseWrapperMiddleware.
|
|
125
129
|
*
|
|
126
130
|
* @template T - The type of data being set
|
|
131
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
132
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
127
133
|
* @param context - The request context
|
|
128
134
|
* @param data - The data to be included in the response payload
|
|
129
135
|
*
|
|
@@ -176,5 +182,5 @@ export declare const responseWrapperMiddleware: <T>() => BaseMiddleware;
|
|
|
176
182
|
* });
|
|
177
183
|
* ```
|
|
178
184
|
*/
|
|
179
|
-
export declare function setResponseData<T>(context: Context, data: T): void;
|
|
185
|
+
export declare function setResponseData<T, TBody = unknown, TUser = unknown>(context: Context<TBody, TUser>, data: T): void;
|
|
180
186
|
//# sourceMappingURL=responseWrapperMiddleware.d.ts.map
|
|
@@ -18,6 +18,8 @@ const wrapResponse = (context) => {
|
|
|
18
18
|
* Automatically wraps the response with success flag, payload, and timestamp.
|
|
19
19
|
*
|
|
20
20
|
* @template T - The type of response data being wrapped
|
|
21
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
22
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
21
23
|
* @implements {BaseMiddleware}
|
|
22
24
|
*
|
|
23
25
|
* @example
|
|
@@ -84,6 +86,8 @@ exports.ResponseWrapperMiddleware = ResponseWrapperMiddleware;
|
|
|
84
86
|
* Automatically wraps response data in a standardized format with success flag and timestamp.
|
|
85
87
|
*
|
|
86
88
|
* @template T - The type of response data being wrapped
|
|
89
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
90
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
87
91
|
* @returns BaseMiddleware object with response wrapping logic
|
|
88
92
|
*
|
|
89
93
|
* @example
|
|
@@ -145,6 +149,8 @@ exports.responseWrapperMiddleware = responseWrapperMiddleware;
|
|
|
145
149
|
* This function should be used in handlers when using ResponseWrapperMiddleware.
|
|
146
150
|
*
|
|
147
151
|
* @template T - The type of data being set
|
|
152
|
+
* @template TBody - The type of the request body payload (preserves type chain)
|
|
153
|
+
* @template TUser - The type of the authenticated user (preserves type chain)
|
|
148
154
|
* @param context - The request context
|
|
149
155
|
* @param data - The data to be included in the response payload
|
|
150
156
|
*
|
package/package.json
CHANGED