@divine-lab/request 1.0.1 → 1.0.2

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.
@@ -10,9 +10,9 @@ type httpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
10
10
  * @property {any} data - any additional data to include in the response
11
11
  */
12
12
  type SuccessResponse = {
13
- title: string;
14
- detail: string;
15
- data: any;
13
+ title?: string;
14
+ detail?: string;
15
+ data?: any;
16
16
  };
17
17
  /** Sends a standardized error response.
18
18
  * Uses the RFC 9457 Format.
@@ -38,7 +38,7 @@ export declare function errorResponse(res: FastifyReply, error: ServerErrorKey,
38
38
  * return successResponse(res, 200, "User Created", "The user was created successfully, you should recieve an email in a short while.", { id: 1, name: "Example" });
39
39
  * ```
40
40
  */
41
- export declare function successResponse(res: FastifyReply, status: number | undefined, { title, detail, data }: SuccessResponse): void;
41
+ export declare function successResponse(res: FastifyReply, status?: number, { title, detail, data }?: SuccessResponse): void;
42
42
  /** Utility function to register a route with standardized request typing and optional schema validation.
43
43
  * @param fastify - The Fastify instance to register the route on
44
44
  * @param method - HTTP method (e.g., "get", "post")
@@ -49,7 +49,7 @@ function errorResponse(res, error, { title, detail, type, data, status } = {}) {
49
49
  * return successResponse(res, 200, "User Created", "The user was created successfully, you should recieve an email in a short while.", { id: 1, name: "Example" });
50
50
  * ```
51
51
  */
52
- function successResponse(res, status = 200, { title = "Success", detail = "Success", data = "Success" }) {
52
+ function successResponse(res, status = 200, { title = "Success", detail = "Success", data = null } = { title: "Success", detail: "Success", data: null }) {
53
53
  if (API_LOG)
54
54
  logger_1.default.raw(`${new Date().toISOString()} ${(0, colors_1.colorize)("green", "[API]")} - ${(0, colors_1.colorize)("green", status)} - ${res.request.url} : ${(0, colors_1.colorize)("gray", title)}`);
55
55
  res.code(status).send({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divine-lab/request",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Simple utility for standardizing request and response objects.",
5
5
  "author": {
6
6
  "name": "Ishpreet Singh",