@divine-lab/request 1.2.0 → 1.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/dist/fastify-helpers/index.d.ts +14 -2
- package/package.json +1 -1
- package/readme.md +1 -0
|
@@ -4,6 +4,11 @@ import { type FastifyRequest } from "fastify/types/request";
|
|
|
4
4
|
import { type FastifyReply } from "fastify/types/reply";
|
|
5
5
|
import { type FastifyInstance } from "fastify";
|
|
6
6
|
type httpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
7
|
+
type RateLimitConfig = {
|
|
8
|
+
max: number;
|
|
9
|
+
TimeWindow: string;
|
|
10
|
+
keyGenerator?: (req: FastifyRequest) => string;
|
|
11
|
+
};
|
|
7
12
|
/** Type definition for the success response payload.
|
|
8
13
|
* @property {string} title - short, human-readable summary of the response
|
|
9
14
|
* @property {string} detail - detailed description of the response
|
|
@@ -64,10 +69,11 @@ export declare function successResponse(res: FastifyReply, status?: number, { ti
|
|
|
64
69
|
* });
|
|
65
70
|
* ```
|
|
66
71
|
*/
|
|
67
|
-
export declare function REGISTER_ROUTE<BodyType extends TObject, QueryType extends TObject, ParamsType extends TObject>(fastify: FastifyInstance, method: httpMethod, path: string, handler: (req: FastifyRequest<{
|
|
72
|
+
export declare function REGISTER_ROUTE<BodyType extends TObject, QueryType extends TObject, ParamsType extends TObject, RateLimitType extends RateLimitConfig | undefined = undefined>(fastify: FastifyInstance, method: httpMethod, path: string, handler: (req: FastifyRequest<{
|
|
68
73
|
Body: Static<BodyType>;
|
|
69
74
|
Querystring: Static<QueryType>;
|
|
70
75
|
Params: Static<ParamsType>;
|
|
76
|
+
RateLimit: RateLimitType;
|
|
71
77
|
}>, reply: any) => void, options?: {
|
|
72
78
|
schema?: {
|
|
73
79
|
body?: BodyType;
|
|
@@ -75,7 +81,13 @@ export declare function REGISTER_ROUTE<BodyType extends TObject, QueryType exten
|
|
|
75
81
|
params?: ParamsType;
|
|
76
82
|
};
|
|
77
83
|
preHandler?: Array<(req: FastifyRequest, reply: any) => void> | ((req: FastifyRequest, reply: any) => void);
|
|
78
|
-
}
|
|
84
|
+
} & (RateLimitType extends undefined ? {
|
|
85
|
+
config?: any;
|
|
86
|
+
} : {
|
|
87
|
+
config: {
|
|
88
|
+
rateLimit: RateLimitType;
|
|
89
|
+
};
|
|
90
|
+
})): void;
|
|
79
91
|
/** Centralized error handler for Fastify.
|
|
80
92
|
* @param error - The error object caught by Fastify
|
|
81
93
|
* @param request - The incoming request object
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -120,6 +120,7 @@ Additionally if a `400 Bad request` is made, then this handler should handle it
|
|
|
120
120
|
- 1.1.0: added rate limit error response in backend errors and handling it in global error handler (when using `@fastify/rate-limit`)
|
|
121
121
|
- 1.1.1: fixed data response for the rate-limit in global error handler for fastify.
|
|
122
122
|
- 1.2.0: added support for instance base path in error responses via environment variable.
|
|
123
|
+
- 1.3.0: added support for rate-limiting when registering routes in the REGISTER_ROUTE function.
|
|
123
124
|
|
|
124
125
|
#### Contact:
|
|
125
126
|
|