nextemos 3.0.0 → 3.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.
|
@@ -4,9 +4,9 @@ import { IApiResponse, IRequestOptions } from '../';
|
|
|
4
4
|
* @returns {object} İstek yapmak için yöntemlere sahip HTTP istemcisi.
|
|
5
5
|
*/
|
|
6
6
|
declare const fetchRequest: () => {
|
|
7
|
-
get: <T>(url: string, options: Omit<IRequestOptions,
|
|
8
|
-
post: <
|
|
9
|
-
put: <
|
|
10
|
-
delete: <
|
|
7
|
+
get: <T>(url: string, options: Omit<IRequestOptions, "url" | "method">) => Promise<IApiResponse<T>>;
|
|
8
|
+
post: <T>(url: string, options: Omit<IRequestOptions, "url" | "method">) => Promise<IApiResponse<T>>;
|
|
9
|
+
put: <T>(url: string, options: Omit<IRequestOptions, "url" | "method">) => Promise<IApiResponse<T>>;
|
|
10
|
+
delete: <T>(url: string, options: Omit<IRequestOptions, "url" | "method">) => Promise<IApiResponse<T>>;
|
|
11
11
|
};
|
|
12
12
|
export default fetchRequest;
|
|
@@ -19,7 +19,11 @@ 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 });
|
|
26
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
23
27
|
const __1 = require("../");
|
|
24
28
|
/**
|
|
25
29
|
* İstek yapmak için bir HTTP istemcisi oluşturur.
|
|
@@ -34,31 +38,34 @@ const fetchRequest = () => {
|
|
|
34
38
|
*/
|
|
35
39
|
const request = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
40
|
var { url, method, params } = _a, options = __rest(_a, ["url", "method", "params"]);
|
|
37
|
-
const apiURL = new URL(url);
|
|
41
|
+
const apiURL = new URL(url);
|
|
38
42
|
if (params)
|
|
39
43
|
Object.keys(params).forEach(key => apiURL.searchParams.append(key, params[key]));
|
|
40
44
|
if (method === __1.HTTPMethod.POST)
|
|
41
45
|
options.headers = Object.assign(Object.assign({}, options.headers), { ['Content-Type']: 'application/json' });
|
|
46
|
+
logger_1.default.info(`Fetch Request: ${method} - ${apiURL} - ${JSON.stringify(Object.assign({ cache: 'no-cache' }, options))}`);
|
|
42
47
|
try {
|
|
43
48
|
const response = yield fetch(apiURL.toString(), Object.assign(Object.assign({ cache: 'no-cache' }, options), { method }));
|
|
44
49
|
// Headers nesnesini Object'e dönüştürme
|
|
45
50
|
const headers = {};
|
|
46
|
-
if (response.headers) {
|
|
51
|
+
if (response === null || response === void 0 ? void 0 : response.headers) {
|
|
47
52
|
response.headers.forEach((value, name) => {
|
|
48
53
|
headers[name] = value;
|
|
49
54
|
});
|
|
50
55
|
}
|
|
51
56
|
// response data nesnesini JSON'a dönüştürme.
|
|
52
57
|
const responseData = yield response.json().catch(() => ({}));
|
|
58
|
+
// logger.debug(`Fetch Response: ${JSON.stringify(responseData)}`);
|
|
53
59
|
if (!response.ok) {
|
|
54
|
-
const errorMessage = (responseData === null || responseData === void 0 ? void 0 : responseData.message) || 'Bir şeyler
|
|
55
|
-
|
|
60
|
+
const errorMessage = (responseData === null || responseData === void 0 ? void 0 : responseData.message) || 'Bir şeyler ters gitti!';
|
|
61
|
+
logger_1.default.error(`Fetch Request Error: ${response.status} - ${errorMessage}`);
|
|
56
62
|
return { status: response.status, error: errorMessage, headers };
|
|
57
63
|
}
|
|
58
64
|
return { status: response.status, data: responseData, headers };
|
|
59
65
|
}
|
|
60
66
|
catch (error) {
|
|
61
|
-
|
|
67
|
+
logger_1.default.error(`Fetch Request Exception Error! -> ${error}`);
|
|
68
|
+
return { status: 500, error: `Fetch Request Exception Error! -> ${error}` };
|
|
62
69
|
}
|
|
63
70
|
});
|
|
64
71
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const pino_1 = __importDefault(require("pino"));
|
|
7
|
+
const logger = (0, pino_1.default)({
|
|
8
|
+
level: process.env.NODE_ENV === 'development' ? 'debug' : 'silent'
|
|
9
|
+
});
|
|
10
|
+
exports.default = logger;
|
package/dist/test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = test;
|
|
3
4
|
const hooks_1 = require("./hooks");
|
|
4
5
|
const services_1 = require("./services");
|
|
5
6
|
function test() {
|
|
@@ -15,4 +16,3 @@ function test() {
|
|
|
15
16
|
});
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
exports.default = test;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextemos",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -44,5 +44,8 @@
|
|
|
44
44
|
"nextjs",
|
|
45
45
|
"typescript",
|
|
46
46
|
"nextemos"
|
|
47
|
-
]
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"pino": "^9.3.2"
|
|
50
|
+
}
|
|
48
51
|
}
|