@tatil/server-api 0.0.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tatil/server-api",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Tatilsepeti Server Api for Next.js server-side operations",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -8,57 +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
19
  }
48
20
 
49
- fullEndpoint(endpoint, version = 'v1') {
50
- return `${this.baseURL}/api/${version}/${this.joinEndpoint(endpoint)}`;
51
- }
52
-
53
- buildUrl(endpoint) {
21
+ buildUrl(endpoint, version = 'v1') {
54
22
  if (Array.isArray(endpoint)) {
55
- return this.fullEndpoint(endpoint);
23
+ return `/${version}/${endpoint.join('/')}`;
56
24
  }
57
- return `${this.baseURL}/api/v1${endpoint}`;
58
- }
59
25
 
60
- getEndpointPath(endpoint) {
61
- return Array.isArray(endpoint) ? this.joinEndpoint(endpoint) : endpoint;
26
+ return `/${version}/${endpoint}`;
62
27
  }
63
28
 
64
29
  setAuthCookies(accessToken, expiresAt) {
@@ -114,9 +79,8 @@ class TatilsepetiApi {
114
79
  }
115
80
 
116
81
  async get(endpoint, params = {}, version = 'v1') {
117
- const endpointPath = this.getEndpointPath(endpoint);
118
- const logId = this.logger.start(endpointPath, 'GET');
119
82
  const url = this.buildUrl(endpoint, version);
83
+ const logId = this.logger.start(url, 'GET');
120
84
 
121
85
  const response = await this.instance.get(url, {
122
86
  params,
@@ -153,10 +117,15 @@ class TatilsepetiApi {
153
117
  }
154
118
 
155
119
  async post(endpoint, body = {}, version = 'v1') {
156
- const endpointPath = this.getEndpointPath(endpoint);
157
- const logId = this.logger.start(endpointPath, 'POST');
158
120
  const url = this.buildUrl(endpoint, version);
159
121
 
122
+
123
+ console.log(url, "urlurlurlurlurlurlurlurlurlurl");
124
+
125
+
126
+
127
+ const logId = this.logger.start(url, 'POST');
128
+
160
129
  const response = await this.instance.post(url, body, {
161
130
  headers: await this.getAuthHeaders(),
162
131
  });