nextemos 4.8.0 → 4.8.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.
@@ -1,4 +1,4 @@
1
- import { IApiResponse, IRequestOptions } from '../';
1
+ import { IApiResponse, IRequestOptions } from "../";
2
2
  /**
3
3
  * İstek yapmak için bir HTTP istemcisi oluşturur.
4
4
  * @returns {object} İstek yapmak için yöntemlere sahip HTTP istemcisi.
@@ -36,23 +36,27 @@ const fetchRequest = () => {
36
36
  var { url, method, params } = _a, options = __rest(_a, ["url", "method", "params"]);
37
37
  const apiURL = new URL(url);
38
38
  if (params)
39
- Object.keys(params).forEach(key => apiURL.searchParams.append(key, decodeURIComponent(params[key])));
40
- if ((method === __1.HTTPMethod.POST && (!options.body || typeof options.body === 'string')) ||
39
+ Object.keys(params).forEach((key) => apiURL.searchParams.append(key, decodeURIComponent(params[key])));
40
+ if ((method === __1.HTTPMethod.POST &&
41
+ (!options.body || typeof options.body === "string")) ||
41
42
  method === __1.HTTPMethod.PUT ||
42
43
  method === __1.HTTPMethod.DELETE) {
43
- options.headers = Object.assign({ ['Content-Type']: 'application/json' }, options.headers);
44
+ options.headers = Object.assign({ ["Content-Type"]: "application/json" }, options.headers);
44
45
  }
45
46
  const requestOptions = Object.assign(Object.assign({ cache: process.env.CACHE_STRATEGY || "no-store" }, options), { method });
46
- console.log(`Fetch Request: ${method} ${apiURL}`, requestOptions);
47
+ if (process.env.NODE_ENV === "development")
48
+ console.log(`Fetch Request: ${method}`, apiURL.toString(), apiURL, requestOptions);
47
49
  try {
48
50
  const response = yield fetch(apiURL.toString(), requestOptions);
49
51
  if (!response.ok) {
50
52
  const errorDetail = yield response.text();
51
- console.log("Fetch Error: ", {
52
- api: apiURL,
53
- status: response.status,
54
- errorMessage: errorDetail,
55
- });
53
+ if (process.env.NODE_ENV === "development")
54
+ console.log("Fetch Error: ", {
55
+ api: apiURL,
56
+ apiUrl: apiURL.toString(),
57
+ status: response.status,
58
+ errorMessage: errorDetail,
59
+ });
56
60
  return {
57
61
  status: response.status,
58
62
  errorMessage: errorDetail,
@@ -67,35 +71,38 @@ const fetchRequest = () => {
67
71
  }
68
72
  let responseModel;
69
73
  if (Object.keys(headers).length > 0 &&
70
- headers.hasOwnProperty('content-type') &&
71
- headers['content-type'].includes('text/plain'))
74
+ headers.hasOwnProperty("content-type") &&
75
+ headers["content-type"].includes("text/plain"))
72
76
  responseModel = yield response.text();
73
77
  else
74
78
  responseModel = yield response.json().catch(() => ({}));
75
- console.log("Fetch Success: ", {
76
- api: apiURL,
77
- status: response.status
78
- });
79
+ if (process.env.NODE_ENV === "development") {
80
+ console.log("Fetch Success: ", {
81
+ api: apiURL,
82
+ apiUrl: apiURL.toString(),
83
+ status: response.status,
84
+ });
85
+ }
79
86
  return {
80
87
  status: response.status,
81
88
  data: responseModel,
82
- headers
89
+ headers,
83
90
  };
84
91
  }
85
92
  catch (error) {
86
93
  if (error instanceof Error) {
87
- console.log(`Fetch Request Exception Error! -> ${apiURL} -> ${error.name} : ${error.message}`);
94
+ console.log(`Fetch Request Exception Error! -> ${apiURL.toString()} -> ${apiURL} -> ${error.name} : ${error.message}`);
88
95
  return {
89
96
  status: 500,
90
97
  error: error.name,
91
- errorMessage: error.message
98
+ errorMessage: error.message,
92
99
  };
93
100
  }
94
101
  console.log(`Fetch Request Exception Unknown Error! ->`, error);
95
102
  return {
96
103
  status: 500,
97
104
  error: `${error}`,
98
- errorMessage: `${error}`
105
+ errorMessage: `${error}`,
99
106
  };
100
107
  }
101
108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextemos",
3
- "version": "4.8.0",
3
+ "version": "4.8.2",
4
4
  "description": "For helpers and hooks used in NextJS projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",