nextemos 4.1.2 → 4.1.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.
@@ -19,8 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  const __1 = require("../");
27
+ const chalk_1 = __importDefault(require("chalk"));
24
28
  /**
25
29
  * İstek yapmak için bir HTTP istemcisi oluşturur.
26
30
  * @returns {object} İstek yapmak için yöntemlere sahip HTTP istemcisi.
@@ -40,7 +44,26 @@ const fetchRequest = () => {
40
44
  if (method === __1.HTTPMethod.POST)
41
45
  options.headers = Object.assign({ ['Content-Type']: 'application/json' }, options.headers);
42
46
  const requestOptions = Object.assign(Object.assign({ cache: process.env.CACHE_STRATEGY || "no-store" }, options), { method });
43
- console.log(`Fetch Request: ${method} - ${apiURL} - ${JSON.stringify(requestOptions)}`);
47
+ if (window !== undefined) {
48
+ const metholInfo = () => {
49
+ switch (method) {
50
+ case __1.HTTPMethod.GET:
51
+ return chalk_1.default.bgBlue.blueBright.bold(` ${method} => `);
52
+ case __1.HTTPMethod.POST:
53
+ return chalk_1.default.bgGreen.greenBright.bold(` ${method} => `);
54
+ case __1.HTTPMethod.PUT:
55
+ return chalk_1.default.bgYellowBright.yellow.bold(` ${method} => `);
56
+ case __1.HTTPMethod.DELETE:
57
+ return chalk_1.default.bgRedBright.red.bold(` ${method} => `);
58
+ default:
59
+ break;
60
+ }
61
+ };
62
+ console.log(metholInfo() + chalk_1.default.bgWhite.black(apiURL) + " - " + JSON.stringify(requestOptions));
63
+ }
64
+ else {
65
+ console.log(method + " => - " + apiURL + " - " + JSON.stringify(requestOptions));
66
+ }
44
67
  try {
45
68
  const response = yield fetch(apiURL.toString(), requestOptions);
46
69
  // Headers nesnesini Object'e dönüştürme
@@ -60,6 +83,10 @@ const fetchRequest = () => {
60
83
  }
61
84
  // response data nesnesini JSON'a dönüştürme.
62
85
  const responseData = yield response.json().catch(() => ({}));
86
+ if (window !== undefined)
87
+ console.log(chalk_1.default.bgGreen.white.bold("Response is successfully..."));
88
+ else
89
+ console.log("Response is successfully...");
63
90
  return {
64
91
  status: response.status,
65
92
  data: responseData,
@@ -68,14 +95,14 @@ const fetchRequest = () => {
68
95
  }
69
96
  catch (error) {
70
97
  if (error instanceof Error) {
71
- console.log(`Fetch Request Exception Error! -> ${apiURL} -> ${error.name} : ${error.message}`);
98
+ console.log(chalk_1.default.red(`Fetch Request Exception Error! -> ${apiURL} -> ${error.name} : ${error.message}`));
72
99
  return {
73
100
  status: 500,
74
101
  error: error.name,
75
102
  errorMessage: error.message
76
103
  };
77
104
  }
78
- console.log(`Fetch Request Exception Unknown Error! ->`, error);
105
+ console.log(chalk_1.default.red(`Fetch Request Exception Unknown Error! ->`, error));
79
106
  return {
80
107
  status: 500,
81
108
  error: `${error}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextemos",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
4
4
  "description": "For helpers and hooks used in NextJS projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -38,6 +38,7 @@
38
38
  "nextemos"
39
39
  ],
40
40
  "dependencies": {
41
+ "chalk": "^5.3.0",
41
42
  "html-entities": "^2.5.2"
42
43
  }
43
44
  }