@rasadov/lumoar-sdk 2.0.4 → 2.0.8
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 -8
- package/dist/sdk.js +11 -8
- package/package.json +2 -2
- package/sdk.ts +8 -6
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
|
*
|
|
@@ -3136,12 +3136,6 @@ export interface ResetPasswordSchema {
|
|
|
3136
3136
|
* @memberof ResetPasswordSchema
|
|
3137
3137
|
*/
|
|
3138
3138
|
'new_password': string;
|
|
3139
|
-
/**
|
|
3140
|
-
*
|
|
3141
|
-
* @type {string}
|
|
3142
|
-
* @memberof ResetPasswordSchema
|
|
3143
|
-
*/
|
|
3144
|
-
'turnstile_token': string;
|
|
3145
3139
|
}
|
|
3146
3140
|
/**
|
|
3147
3141
|
*
|
package/dist/sdk.js
CHANGED
|
@@ -42,10 +42,7 @@ export class ApiSDK {
|
|
|
42
42
|
this.token = newToken;
|
|
43
43
|
}
|
|
44
44
|
getAuthHeader() {
|
|
45
|
-
|
|
46
|
-
throw new Error('No token set. Call setToken() first.');
|
|
47
|
-
}
|
|
48
|
-
return `Bearer ${this.token}`;
|
|
45
|
+
return this.token ? `Bearer ${this.token}` : '';
|
|
49
46
|
}
|
|
50
47
|
setupInterceptors() {
|
|
51
48
|
this.axiosInstance.interceptors.request.use((config) => {
|
|
@@ -55,15 +52,21 @@ export class ApiSDK {
|
|
|
55
52
|
return config;
|
|
56
53
|
});
|
|
57
54
|
this.axiosInstance.interceptors.response.use((response) => {
|
|
58
|
-
|
|
55
|
+
var _a;
|
|
56
|
+
const newToken = response.headers['authorization'] || response.headers['Authorization'] || ((_a = response.data) === null || _a === void 0 ? void 0 : _a.newToken);
|
|
59
57
|
if (newToken) {
|
|
60
|
-
this.setToken(newToken.replace(
|
|
58
|
+
this.setToken(newToken.replace(/^Bearer /i, ''));
|
|
61
59
|
console.log('Token automatically updated via backend refresh');
|
|
62
60
|
}
|
|
63
61
|
return response;
|
|
64
62
|
}, (error) => {
|
|
65
|
-
var _a;
|
|
66
|
-
|
|
63
|
+
var _a, _b, _c, _d, _e;
|
|
64
|
+
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']);
|
|
65
|
+
if (newToken) {
|
|
66
|
+
this.setToken(newToken.replace(/^Bearer /i, ''));
|
|
67
|
+
console.log('Token automatically updated via backend refresh (error response)');
|
|
68
|
+
}
|
|
69
|
+
if (((_e = error.response) === null || _e === void 0 ? void 0 : _e.status) === 401) {
|
|
67
70
|
console.error('Authentication failed - session expired');
|
|
68
71
|
}
|
|
69
72
|
return Promise.reject(error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rasadov/lumoar-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Lumoar API SDK for dashboard use (session-based authentication)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,4 +37,4 @@
|
|
|
37
37
|
"@types/node": "^24.5.2",
|
|
38
38
|
"typescript": "^5.9.2"
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|
package/sdk.ts
CHANGED
|
@@ -91,10 +91,7 @@ export class ApiSDK {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
private getAuthHeader(): string {
|
|
94
|
-
|
|
95
|
-
throw new Error('No token set. Call setToken() first.');
|
|
96
|
-
}
|
|
97
|
-
return `Bearer ${this.token}`;
|
|
94
|
+
return this.token ? `Bearer ${this.token}` : '';
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
private setupInterceptors() {
|
|
@@ -106,13 +103,18 @@ export class ApiSDK {
|
|
|
106
103
|
});
|
|
107
104
|
|
|
108
105
|
this.axiosInstance.interceptors.response.use((response: AxiosResponse) => {
|
|
109
|
-
const newToken = response.
|
|
106
|
+
const newToken = response.headers['authorization'] || response.headers['Authorization'] || response.data?.newToken;
|
|
110
107
|
if (newToken) {
|
|
111
|
-
this.setToken(newToken.replace(
|
|
108
|
+
this.setToken(newToken.replace(/^Bearer /i, ''));
|
|
112
109
|
console.log('Token automatically updated via backend refresh');
|
|
113
110
|
}
|
|
114
111
|
return response;
|
|
115
112
|
}, (error) => {
|
|
113
|
+
const newToken = error.response?.headers?.['authorization'] || error.response?.headers?.['Authorization'];
|
|
114
|
+
if (newToken) {
|
|
115
|
+
this.setToken(newToken.replace(/^Bearer /i, ''));
|
|
116
|
+
console.log('Token automatically updated via backend refresh (error response)');
|
|
117
|
+
}
|
|
116
118
|
if (error.response?.status === 401) {
|
|
117
119
|
console.error('Authentication failed - session expired');
|
|
118
120
|
}
|