@divine-lab/request 1.0.2 → 1.0.4

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.
@@ -12,7 +12,7 @@ const colors_1 = require("@divine-lab/logger/colors");
12
12
  const APIError_1 = require("../errors/APIError");
13
13
  const logger_1 = __importDefault(require("@divine-lab/logger"));
14
14
  const API_LOG = process.env.DIVINE_LAB_REQUEST_API_LOG === "true";
15
- logger_1.default.raw(`${(0, colors_1.colorize)("blue", "[API]")} - API logging is ${API_LOG ? (0, colors_1.colorize)("green", "enabled") : (0, colors_1.colorize)("red", "disabled")} - ${API_LOG ? "API requests and responses will be logged." : "to enable, set API_LOG=true in environment variables"}`);
15
+ logger_1.default.raw(`${(0, colors_1.colorize)("blue", "[API]")} - API logging is ${API_LOG ? (0, colors_1.colorize)("green", "enabled") : (0, colors_1.colorize)("red", "disabled")} - ${API_LOG ? "API requests and responses will be logged." : `to enable, set ${(0, colors_1.colorize)("yellow", "DIVINE_LAB_REQUEST_API_LOG")}=true in environment variables`}`);
16
16
  /** Sends a standardized error response.
17
17
  * Uses the RFC 9457 Format.
18
18
  * @param res - Fastify reply object
@@ -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.2",
3
+ "version": "1.0.4",
4
4
  "description": "Simple utility for standardizing request and response objects.",
5
5
  "author": {
6
6
  "name": "Ishpreet Singh",