@rasadov/lumoar-sdk 2.0.5 → 2.0.9
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/dist/api.d.ts +2 -2
- package/dist/sdk.d.ts +1 -1
- package/dist/sdk.js +24 -11
- package/package.json +1 -1
- package/sdk.ts +21 -9
package/dist/api.d.ts
CHANGED
|
@@ -619,13 +619,13 @@ export interface BaaDpaUploadConfirmRequest {
|
|
|
619
619
|
* @type {string}
|
|
620
620
|
* @memberof BaaDpaUploadConfirmRequest
|
|
621
621
|
*/
|
|
622
|
-
'valid_from'
|
|
622
|
+
'valid_from'?: string | null;
|
|
623
623
|
/**
|
|
624
624
|
*
|
|
625
625
|
* @type {string}
|
|
626
626
|
* @memberof BaaDpaUploadConfirmRequest
|
|
627
627
|
*/
|
|
628
|
-
'valid_until'
|
|
628
|
+
'valid_until'?: string | null;
|
|
629
629
|
}
|
|
630
630
|
/**
|
|
631
631
|
*
|
package/dist/sdk.d.ts
CHANGED
package/dist/sdk.js
CHANGED
|
@@ -11,7 +11,6 @@ export class ApiSDK {
|
|
|
11
11
|
this.setupInterceptors();
|
|
12
12
|
const config = new Configuration({
|
|
13
13
|
basePath,
|
|
14
|
-
apiKey: () => this.getAuthHeader(),
|
|
15
14
|
baseOptions: {
|
|
16
15
|
axios: this.axiosInstance
|
|
17
16
|
},
|
|
@@ -41,29 +40,43 @@ export class ApiSDK {
|
|
|
41
40
|
setToken(newToken) {
|
|
42
41
|
this.token = newToken;
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
throw new Error('No token set. Call setToken() first.');
|
|
47
|
-
}
|
|
48
|
-
return `Bearer ${this.token}`;
|
|
43
|
+
getToken() {
|
|
44
|
+
return this.token;
|
|
49
45
|
}
|
|
50
46
|
setupInterceptors() {
|
|
47
|
+
// Request interceptor: Always add Authorization header if token exists
|
|
51
48
|
this.axiosInstance.interceptors.request.use((config) => {
|
|
52
49
|
if (this.token) {
|
|
53
|
-
|
|
50
|
+
// Ensure headers object exists
|
|
51
|
+
if (!config.headers) {
|
|
52
|
+
config.headers = {};
|
|
53
|
+
}
|
|
54
|
+
config.headers['Authorization'] = `Bearer ${this.token}`;
|
|
54
55
|
}
|
|
55
56
|
return config;
|
|
57
|
+
}, (error) => {
|
|
58
|
+
return Promise.reject(error);
|
|
56
59
|
});
|
|
60
|
+
// Response interceptor: Extract and update token from backend responses
|
|
57
61
|
this.axiosInstance.interceptors.response.use((response) => {
|
|
58
|
-
|
|
62
|
+
var _a;
|
|
63
|
+
const newToken = response.headers['authorization'] || response.headers['Authorization'] || ((_a = response.data) === null || _a === void 0 ? void 0 : _a.newToken);
|
|
59
64
|
if (newToken) {
|
|
60
|
-
|
|
65
|
+
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
66
|
+
this.setToken(tokenValue);
|
|
61
67
|
console.log('Token automatically updated via backend refresh');
|
|
62
68
|
}
|
|
63
69
|
return response;
|
|
64
70
|
}, (error) => {
|
|
65
|
-
var _a;
|
|
66
|
-
|
|
71
|
+
var _a, _b, _c, _d, _e;
|
|
72
|
+
// Even on error, check if backend sent a refreshed token
|
|
73
|
+
const newToken = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['authorization']) || ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d['Authorization']);
|
|
74
|
+
if (newToken) {
|
|
75
|
+
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
76
|
+
this.setToken(tokenValue);
|
|
77
|
+
console.log('Token automatically updated via backend refresh (error response)');
|
|
78
|
+
}
|
|
79
|
+
if (((_e = error.response) === null || _e === void 0 ? void 0 : _e.status) === 401) {
|
|
67
80
|
console.error('Authentication failed - session expired');
|
|
68
81
|
}
|
|
69
82
|
return Promise.reject(error);
|
package/package.json
CHANGED
package/sdk.ts
CHANGED
|
@@ -57,7 +57,6 @@ export class ApiSDK {
|
|
|
57
57
|
this.setupInterceptors();
|
|
58
58
|
const config = new Configuration({
|
|
59
59
|
basePath,
|
|
60
|
-
apiKey: () => this.getAuthHeader(),
|
|
61
60
|
baseOptions: {
|
|
62
61
|
axios: this.axiosInstance
|
|
63
62
|
},
|
|
@@ -90,29 +89,42 @@ export class ApiSDK {
|
|
|
90
89
|
this.token = newToken;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
throw new Error('No token set. Call setToken() first.');
|
|
96
|
-
}
|
|
97
|
-
return `Bearer ${this.token}`;
|
|
92
|
+
public getToken(): string | null {
|
|
93
|
+
return this.token;
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
private setupInterceptors() {
|
|
97
|
+
// Request interceptor: Always add Authorization header if token exists
|
|
101
98
|
this.axiosInstance.interceptors.request.use((config) => {
|
|
102
99
|
if (this.token) {
|
|
103
|
-
|
|
100
|
+
// Ensure headers object exists
|
|
101
|
+
if (!config.headers) {
|
|
102
|
+
config.headers = {} as any;
|
|
103
|
+
}
|
|
104
|
+
config.headers['Authorization'] = `Bearer ${this.token}`;
|
|
104
105
|
}
|
|
105
106
|
return config;
|
|
107
|
+
}, (error) => {
|
|
108
|
+
return Promise.reject(error);
|
|
106
109
|
});
|
|
107
110
|
|
|
111
|
+
// Response interceptor: Extract and update token from backend responses
|
|
108
112
|
this.axiosInstance.interceptors.response.use((response: AxiosResponse) => {
|
|
109
|
-
const newToken = response.
|
|
113
|
+
const newToken = response.headers['authorization'] || response.headers['Authorization'] || response.data?.newToken;
|
|
110
114
|
if (newToken) {
|
|
111
|
-
|
|
115
|
+
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
116
|
+
this.setToken(tokenValue);
|
|
112
117
|
console.log('Token automatically updated via backend refresh');
|
|
113
118
|
}
|
|
114
119
|
return response;
|
|
115
120
|
}, (error) => {
|
|
121
|
+
// Even on error, check if backend sent a refreshed token
|
|
122
|
+
const newToken = error.response?.headers?.['authorization'] || error.response?.headers?.['Authorization'];
|
|
123
|
+
if (newToken) {
|
|
124
|
+
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
125
|
+
this.setToken(tokenValue);
|
|
126
|
+
console.log('Token automatically updated via backend refresh (error response)');
|
|
127
|
+
}
|
|
116
128
|
if (error.response?.status === 401) {
|
|
117
129
|
console.error('Authentication failed - session expired');
|
|
118
130
|
}
|