@tatil/server-api 0.0.6 → 0.0.7
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.
- package/package.json +1 -1
- package/src/utils/tatilsepeti.js +11 -44
package/package.json
CHANGED
package/src/utils/tatilsepeti.js
CHANGED
|
@@ -8,59 +8,22 @@ const { API_URL } = process.env;
|
|
|
8
8
|
|
|
9
9
|
class TatilsepetiApi {
|
|
10
10
|
constructor() {
|
|
11
|
-
this.baseURL = API_URL;
|
|
12
11
|
this.instance = axios.create({
|
|
13
|
-
baseURL: API_URL
|
|
12
|
+
baseURL: `${API_URL}/api`,
|
|
14
13
|
});
|
|
15
14
|
|
|
16
15
|
this.logger = RequestLogger();
|
|
17
16
|
this.defaultHeaders = {
|
|
18
17
|
'Content-Type': 'application/json',
|
|
19
18
|
};
|
|
20
|
-
|
|
21
|
-
this.attachInterceptors();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
attachInterceptors() {
|
|
25
|
-
this.instance.interceptors.response.use(
|
|
26
|
-
(response) => {
|
|
27
|
-
console.log('[API RESPONSE]', {
|
|
28
|
-
url: response.config.url,
|
|
29
|
-
status: response.status,
|
|
30
|
-
data: response.data,
|
|
31
|
-
});
|
|
32
|
-
return response;
|
|
33
|
-
},
|
|
34
|
-
(error) => {
|
|
35
|
-
console.error('[API RESPONSE ERROR]', {
|
|
36
|
-
url: error.config?.url,
|
|
37
|
-
status: error.response?.status,
|
|
38
|
-
data: error.response?.data,
|
|
39
|
-
});
|
|
40
|
-
return Promise.reject(error);
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
joinEndpoint(endpoint) {
|
|
46
|
-
return endpoint.join('/');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
fullEndpoint(endpoint, version = 'v1') {
|
|
50
|
-
return `${this.baseURL}/api/${version}/${this.joinEndpoint(endpoint)}`;
|
|
51
19
|
}
|
|
52
20
|
|
|
53
21
|
buildUrl(endpoint, version = 'v1') {
|
|
54
|
-
|
|
55
22
|
if (Array.isArray(endpoint)) {
|
|
56
|
-
return
|
|
23
|
+
return `/${version}/${endpoint.join('/')}`;
|
|
57
24
|
}
|
|
58
25
|
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getEndpointPath(endpoint) {
|
|
63
|
-
return Array.isArray(endpoint) ? this.joinEndpoint(endpoint) : endpoint;
|
|
26
|
+
return `/${version}/${endpoint}`;
|
|
64
27
|
}
|
|
65
28
|
|
|
66
29
|
setAuthCookies(accessToken, expiresAt) {
|
|
@@ -116,9 +79,8 @@ class TatilsepetiApi {
|
|
|
116
79
|
}
|
|
117
80
|
|
|
118
81
|
async get(endpoint, params = {}, version = 'v1') {
|
|
119
|
-
const endpointPath = this.getEndpointPath(endpoint);
|
|
120
|
-
const logId = this.logger.start(endpointPath, 'GET');
|
|
121
82
|
const url = this.buildUrl(endpoint, version);
|
|
83
|
+
const logId = this.logger.start(url, 'GET');
|
|
122
84
|
|
|
123
85
|
const response = await this.instance.get(url, {
|
|
124
86
|
params,
|
|
@@ -155,10 +117,15 @@ class TatilsepetiApi {
|
|
|
155
117
|
}
|
|
156
118
|
|
|
157
119
|
async post(endpoint, body = {}, version = 'v1') {
|
|
158
|
-
const endpointPath = this.getEndpointPath(endpoint);
|
|
159
|
-
const logId = this.logger.start(endpointPath, 'POST');
|
|
160
120
|
const url = this.buildUrl(endpoint, version);
|
|
161
121
|
|
|
122
|
+
|
|
123
|
+
console.log(url, "urlurlurlurlurlurlurlurlurlurl");
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
const logId = this.logger.start(url, 'POST');
|
|
128
|
+
|
|
162
129
|
const response = await this.instance.post(url, body, {
|
|
163
130
|
headers: await this.getAuthHeaders(),
|
|
164
131
|
});
|