@divine-lab/request 1.0.3 → 1.0.5

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.
@@ -27,7 +27,7 @@ logger_1.default.raw(`${(0, colors_1.colorize)("blue", "[API]")} - API logging i
27
27
  function errorResponse(res, error, { title, detail, type, data, status } = {}) {
28
28
  const errorDef = BackendErrors_1.SERVER_ERRORS[error];
29
29
  if (API_LOG)
30
- logger_1.default.raw(`${new Date().toISOString()} ${(0, colors_1.colorize)("red", "[API]")} - ${(0, colors_1.colorize)("red", (status || errorDef.status))} - ${res.request.url} : ${(0, colors_1.colorize)("gray", `${title || errorDef.title} - ${detail || errorDef.detail}`)}`);
30
+ logger_1.default.raw(`${new Date().toISOString()} ${(0, colors_1.colorize)("red", "[API]")} - ${(0, colors_1.colorize)("gray", res.request.ip)} - ${(0, colors_1.colorize)("red", (status || errorDef.status))} - ${res.request.url} : ${(0, colors_1.colorize)("gray", `${title || errorDef.title} - ${detail || errorDef.detail}`)}`);
31
31
  res.code(status || errorDef.status).send({
32
32
  status: status || errorDef.status,
33
33
  instance: res.request.url,
@@ -51,7 +51,7 @@ function errorResponse(res, error, { title, detail, type, data, status } = {}) {
51
51
  */
52
52
  function successResponse(res, status = 200, { title = "Success", detail = "Success", data = null } = { title: "Success", detail: "Success", data: null }) {
53
53
  if (API_LOG)
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)}`);
54
+ logger_1.default.raw(`${new Date().toISOString()} ${(0, colors_1.colorize)("green", "[API]")} - ${(0, colors_1.colorize)("gray", res.request.ip)} - ${(0, colors_1.colorize)("green", status)} - ${res.request.url} : ${(0, colors_1.colorize)("gray", title)}`);
55
55
  res.code(status).send({
56
56
  success: true,
57
57
  title,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divine-lab/request",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Simple utility for standardizing request and response objects.",
5
5
  "author": {
6
6
  "name": "Ishpreet Singh",
package/readme.md CHANGED
@@ -14,7 +14,7 @@ success response and error response both follow a defined standard.
14
14
  These functions are defined to be used with fastify for now.
15
15
 
16
16
  ```ts
17
- import { successResponse } from "@divine-lab/request/fastify-helpers"
17
+ import { successResponse } from "@divine-lab/request/fastify-helpers";
18
18
 
19
19
  // Mock type
20
20
  type SuccessResponse = {
@@ -22,22 +22,22 @@ type SuccessResponse = {
22
22
  title: string;
23
23
  detail: string;
24
24
  data: any;
25
- }
25
+ };
26
26
 
27
27
  // Example of a success response:
28
28
  const userCreatedResponse: SuccessResponse = {
29
29
  success: true,
30
30
  title: "Account created successfully",
31
- detail: "You will recieve a email confirming the account creation in a 5-10 minutes."
32
- data: { id: 1, name: "user", age: 21 }
33
- }
31
+ detail: "You will recieve a email confirming the account creation in a 5-10 minutes.",
32
+ data: { id: 1, name: "user", age: 21 },
33
+ };
34
34
 
35
35
  // Example success response
36
- successResponse(res, 200, userCreatedResponse)
36
+ successResponse(res, 200, userCreatedResponse);
37
37
  ```
38
38
 
39
39
  ```ts
40
- import { errorResponse } from "@divine-lab/request/fastify-helpers"
40
+ import { errorResponse } from "@divine-lab/request/fastify-helpers";
41
41
 
42
42
  // Mock type
43
43
  type ErrorResponse = {
@@ -47,7 +47,7 @@ type ErrorResponse = {
47
47
  type: string;
48
48
  instance: string;
49
49
  data: any;
50
- }
50
+ };
51
51
 
52
52
  // Example of Error Response
53
53
  const userNotFoundError: ErrorResponse = {
@@ -55,12 +55,12 @@ const userNotFoundError: ErrorResponse = {
55
55
  title: "User Not Found",
56
56
  detail: "The User with the user id '1' not found in our database, please contact customer support if this is a mistake.",
57
57
  type: "http://example-errors.com/404/user-not-found",
58
- instance: "/users/1"
59
- data: null
60
- }
58
+ instance: "/users/1",
59
+ data: null,
60
+ };
61
61
 
62
62
  // example error response
63
- errorResponse(res, "UNKNOWN", userNotFoundError)
63
+ errorResponse(res, "UNKNOWN", userNotFoundError);
64
64
  ```
65
65
 
66
66
  Note: RFC9457 requires error responses to contain `instance` in the response. Right now all error responses automatically attach the request url as the instance.
@@ -115,4 +115,4 @@ Enable by setting ENV Variable `DIVINE_LAB_REQUEST_API_LOG` to `true`.
115
115
 
116
116
  #### Contact:
117
117
 
118
- - mail: <a href="mailto:ishpreet7521@gmail.com">ishpreet7521@gmail.com<a>
118
+ - mail: <a href="mailto:ishpreet@appshala.com">ishpreet@appshala.com<a>