@alba-cars/common-modules 1.4.6 → 1.4.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.
@@ -78,25 +78,22 @@ const buildUrl = (endpoint, query) => {
78
78
  };
79
79
  async function apiRequest(endpoint, options = {}) {
80
80
  var _a, _b, _c, _d;
81
- const tokens = (0, exports.getTokens)();
82
81
  const headers = {
83
82
  Accept: "application/json",
84
83
  "Content-Type": "application/json",
85
84
  ...options.headers,
86
85
  };
87
- if (!options.skipAuth && (tokens === null || tokens === void 0 ? void 0 : tokens.accessToken)) {
88
- headers.Authorization = `Bearer ${tokens.accessToken}`;
86
+ if (!isServer && !options.skipAuth) {
87
+ const tokens = (0, exports.getTokens)();
88
+ if (tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) {
89
+ headers.Authorization = `Bearer ${tokens.accessToken}`;
90
+ }
89
91
  }
90
92
  const config = {
91
93
  method: (_a = options.method) !== null && _a !== void 0 ? _a : enums_1.HttpMethods.GET,
92
94
  headers,
93
95
  ...options,
94
96
  };
95
- const logNonGetRequest = options.method && options.method !== enums_1.HttpMethods.GET;
96
- if (logNonGetRequest) {
97
- console.log("Request Config:", config);
98
- console.log("Request URL:", buildUrl(endpoint, options.query));
99
- }
100
97
  try {
101
98
  const url = buildUrl(endpoint, options.query);
102
99
  const response = await fetch(url, config);
@@ -104,9 +101,6 @@ async function apiRequest(endpoint, options = {}) {
104
101
  const responseData = (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))
105
102
  ? await response.json()
106
103
  : await response.text();
107
- if (logNonGetRequest) {
108
- console.log("Response Data:", responseData);
109
- }
110
104
  if (!response.ok) {
111
105
  const error = new Error(typeof responseData === "object"
112
106
  ? responseData.message || "API Error"
@@ -114,7 +108,8 @@ async function apiRequest(endpoint, options = {}) {
114
108
  error.status = response.status;
115
109
  error.data = responseData;
116
110
  // Handle token expired error
117
- if (response.status === enums_1.HttpStatusCodes.UNAUTHORIZED &&
111
+ if (!isServer &&
112
+ response.status === enums_1.HttpStatusCodes.UNAUTHORIZED &&
118
113
  ((_b = responseData === null || responseData === void 0 ? void 0 : responseData.error) === null || _b === void 0 ? void 0 : _b.type) === "AUTHENTICATION_ERROR" &&
119
114
  ((_c = responseData === null || responseData === void 0 ? void 0 : responseData.error) === null || _c === void 0 ? void 0 : _c.message) === "Token expired" &&
120
115
  !options.skipAuth) {
@@ -160,7 +155,7 @@ async function apiRequest(endpoint, options = {}) {
160
155
  }
161
156
  throw error;
162
157
  }
163
- if ((_d = responseData === null || responseData === void 0 ? void 0 : responseData.data) === null || _d === void 0 ? void 0 : _d.token) {
158
+ if (!isServer && !options.skipAuth && ((_d = responseData === null || responseData === void 0 ? void 0 : responseData.data) === null || _d === void 0 ? void 0 : _d.token)) {
164
159
  (0, exports.setTokens)({
165
160
  accessToken: responseData.data.token,
166
161
  refreshToken: responseData.data.refreshToken,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.4.6",
6
+ "version": "1.4.7",
7
7
  "description": "A package containing DTOs, validation classes and common modules and interfaces for Alba Cars",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",