@flexbe/sdk 0.2.22 → 0.2.23
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/browser/client/client.js +23 -0
- package/dist/browser/client/token-manager.js +27 -0
- package/dist/cjs/client/client.js +12 -0
- package/dist/cjs/client/token-manager.js +25 -0
- package/dist/esm/client/client.js +12 -0
- package/dist/esm/client/token-manager.js +25 -0
- package/dist/types/client/client.d.ts +6 -0
- package/dist/types/client/token-manager.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { FlexbeAuthType } from '../types';
|
|
2
11
|
import { ApiClient } from './api-client';
|
|
3
12
|
import { SiteApi } from './site-api';
|
|
4
13
|
import { MetaApi } from './meta-api';
|
|
14
|
+
import { TokenManager } from './token-manager';
|
|
5
15
|
export class FlexbeClient {
|
|
6
16
|
constructor(config) {
|
|
7
17
|
this.siteApis = new Map();
|
|
@@ -36,4 +46,17 @@ export class FlexbeClient {
|
|
|
36
46
|
}
|
|
37
47
|
return siteApi;
|
|
38
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Revokes the current authentication token and clears it from storage.
|
|
51
|
+
* This should be called during logout to ensure proper cleanup.
|
|
52
|
+
* @returns Promise that resolves when the token is revoked
|
|
53
|
+
*/
|
|
54
|
+
revokeToken() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (this.config.authType !== FlexbeAuthType.BEARER) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
yield TokenManager.getInstance().revokeToken();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
39
62
|
}
|
|
@@ -235,4 +235,31 @@ export class TokenManager {
|
|
|
235
235
|
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
+
revokeToken() {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
const token = this.token;
|
|
241
|
+
this.clearToken();
|
|
242
|
+
if (!token)
|
|
243
|
+
return;
|
|
244
|
+
try {
|
|
245
|
+
const controller = new AbortController();
|
|
246
|
+
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
|
247
|
+
yield fetch('/oauth/revoke', {
|
|
248
|
+
method: 'POST',
|
|
249
|
+
headers: {
|
|
250
|
+
'Content-Type': 'application/json',
|
|
251
|
+
'Authorization': `Bearer ${token.accessToken}`
|
|
252
|
+
},
|
|
253
|
+
body: JSON.stringify({ token: token.accessToken }),
|
|
254
|
+
credentials: 'include',
|
|
255
|
+
signal: controller.signal,
|
|
256
|
+
});
|
|
257
|
+
clearTimeout(timeoutId);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
console.error('Failed to revoke token:', error);
|
|
261
|
+
// Even if revocation fails, we still want to clear the local token
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
238
265
|
}
|
|
@@ -5,6 +5,7 @@ const types_1 = require("../types");
|
|
|
5
5
|
const api_client_1 = require("./api-client");
|
|
6
6
|
const site_api_1 = require("./site-api");
|
|
7
7
|
const meta_api_1 = require("./meta-api");
|
|
8
|
+
const token_manager_1 = require("./token-manager");
|
|
8
9
|
class FlexbeClient {
|
|
9
10
|
constructor(config) {
|
|
10
11
|
this.siteApis = new Map();
|
|
@@ -39,5 +40,16 @@ class FlexbeClient {
|
|
|
39
40
|
}
|
|
40
41
|
return siteApi;
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Revokes the current authentication token and clears it from storage.
|
|
45
|
+
* This should be called during logout to ensure proper cleanup.
|
|
46
|
+
* @returns Promise that resolves when the token is revoked
|
|
47
|
+
*/
|
|
48
|
+
async revokeToken() {
|
|
49
|
+
if (this.config.authType !== types_1.FlexbeAuthType.BEARER) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
await token_manager_1.TokenManager.getInstance().revokeToken();
|
|
53
|
+
}
|
|
42
54
|
}
|
|
43
55
|
exports.FlexbeClient = FlexbeClient;
|
|
@@ -226,5 +226,30 @@ class TokenManager {
|
|
|
226
226
|
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
+
async revokeToken() {
|
|
230
|
+
const token = this.token;
|
|
231
|
+
this.clearToken();
|
|
232
|
+
if (!token)
|
|
233
|
+
return;
|
|
234
|
+
try {
|
|
235
|
+
const controller = new AbortController();
|
|
236
|
+
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
|
237
|
+
await fetch('/oauth/revoke', {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
headers: {
|
|
240
|
+
'Content-Type': 'application/json',
|
|
241
|
+
'Authorization': `Bearer ${token.accessToken}`
|
|
242
|
+
},
|
|
243
|
+
body: JSON.stringify({ token: token.accessToken }),
|
|
244
|
+
credentials: 'include',
|
|
245
|
+
signal: controller.signal,
|
|
246
|
+
});
|
|
247
|
+
clearTimeout(timeoutId);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
console.error('Failed to revoke token:', error);
|
|
251
|
+
// Even if revocation fails, we still want to clear the local token
|
|
252
|
+
}
|
|
253
|
+
}
|
|
229
254
|
}
|
|
230
255
|
exports.TokenManager = TokenManager;
|
|
@@ -2,6 +2,7 @@ import { FlexbeAuthType } from '../types';
|
|
|
2
2
|
import { ApiClient } from './api-client';
|
|
3
3
|
import { SiteApi } from './site-api';
|
|
4
4
|
import { MetaApi } from './meta-api';
|
|
5
|
+
import { TokenManager } from './token-manager';
|
|
5
6
|
export class FlexbeClient {
|
|
6
7
|
constructor(config) {
|
|
7
8
|
this.siteApis = new Map();
|
|
@@ -36,4 +37,15 @@ export class FlexbeClient {
|
|
|
36
37
|
}
|
|
37
38
|
return siteApi;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Revokes the current authentication token and clears it from storage.
|
|
42
|
+
* This should be called during logout to ensure proper cleanup.
|
|
43
|
+
* @returns Promise that resolves when the token is revoked
|
|
44
|
+
*/
|
|
45
|
+
async revokeToken() {
|
|
46
|
+
if (this.config.authType !== FlexbeAuthType.BEARER) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await TokenManager.getInstance().revokeToken();
|
|
50
|
+
}
|
|
39
51
|
}
|
|
@@ -223,4 +223,29 @@ export class TokenManager {
|
|
|
223
223
|
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
+
async revokeToken() {
|
|
227
|
+
const token = this.token;
|
|
228
|
+
this.clearToken();
|
|
229
|
+
if (!token)
|
|
230
|
+
return;
|
|
231
|
+
try {
|
|
232
|
+
const controller = new AbortController();
|
|
233
|
+
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
|
234
|
+
await fetch('/oauth/revoke', {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
headers: {
|
|
237
|
+
'Content-Type': 'application/json',
|
|
238
|
+
'Authorization': `Bearer ${token.accessToken}`
|
|
239
|
+
},
|
|
240
|
+
body: JSON.stringify({ token: token.accessToken }),
|
|
241
|
+
credentials: 'include',
|
|
242
|
+
signal: controller.signal,
|
|
243
|
+
});
|
|
244
|
+
clearTimeout(timeoutId);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
console.error('Failed to revoke token:', error);
|
|
248
|
+
// Even if revocation fails, we still want to clear the local token
|
|
249
|
+
}
|
|
250
|
+
}
|
|
226
251
|
}
|
|
@@ -13,4 +13,10 @@ export declare class FlexbeClient {
|
|
|
13
13
|
* @returns A SiteApi instance for the specified site
|
|
14
14
|
*/
|
|
15
15
|
getSiteApi(siteId: number): SiteApi;
|
|
16
|
+
/**
|
|
17
|
+
* Revokes the current authentication token and clears it from storage.
|
|
18
|
+
* This should be called during logout to ensure proper cleanup.
|
|
19
|
+
* @returns Promise that resolves when the token is revoked
|
|
20
|
+
*/
|
|
21
|
+
revokeToken(): Promise<void>;
|
|
16
22
|
}
|