@flexbe/sdk 0.2.34 → 0.2.35
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/README.md +6 -4
- package/dist/browser/client/api-client.js +19 -9
- package/dist/browser/client/client.js +1 -1
- package/dist/browser/client/meta-api.js +3 -3
- package/dist/browser/client/pages.js +3 -2
- package/dist/browser/client/token-manager.js +33 -24
- package/dist/cjs/client/api-client.js +8 -8
- package/dist/cjs/client/client.js +1 -1
- package/dist/cjs/client/meta-api.js +3 -3
- package/dist/cjs/client/pages.js +8 -6
- package/dist/cjs/client/token-manager.js +33 -24
- package/dist/esm/client/api-client.js +9 -9
- package/dist/esm/client/client.js +1 -1
- package/dist/esm/client/meta-api.js +3 -3
- package/dist/esm/client/pages.js +8 -6
- package/dist/esm/client/token-manager.js +33 -24
- package/dist/types/client/api-client.d.ts +1 -1
- package/dist/types/client/client.d.ts +2 -2
- package/dist/types/client/meta-api.d.ts +2 -2
- package/dist/types/client/pages.d.ts +2 -2
- package/dist/types/client/site-api.d.ts +1 -1
- package/dist/types/client/stat.d.ts +2 -2
- package/dist/types/client/token-manager.d.ts +1 -0
- package/dist/types/types/pages.d.ts +1 -1
- package/package.json +61 -64
- package/dist/browser/client/auth.js +0 -74
- package/dist/cjs/client/auth.js +0 -63
- package/dist/client/flexbe-client.d.ts +0 -13
- package/dist/client/flexbe-client.js +0 -62
- package/dist/esm/client/auth.js +0 -59
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -18
- package/dist/src/client/flexbe-client.d.ts +0 -20
- package/dist/src/client/flexbe-client.js +0 -86
- package/dist/src/client/pages-client.d.ts +0 -14
- package/dist/src/client/pages-client.js +0 -23
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -20
- package/dist/src/types/index.d.ts +0 -23
- package/dist/src/types/index.js +0 -2
- package/dist/src/types/pages.d.ts +0 -41
- package/dist/src/types/pages.js +0 -19
- package/dist/test/client/flexbe-client.test.d.ts +0 -1
- package/dist/test/client/flexbe-client.test.js +0 -38
- package/dist/test/client/pages-client.test.d.ts +0 -1
- package/dist/test/client/pages-client.test.js +0 -82
- package/dist/types/client/auth.d.ts +0 -11
- package/dist/types/index.js +0 -2
|
@@ -4,6 +4,7 @@ const TOKEN_REFRESH_THRESHOLD = 5 * 60 * 1000; // update token 5 minutes before
|
|
|
4
4
|
export class TokenManager {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.tokenPromise = null;
|
|
7
|
+
this.isRevoking = false;
|
|
7
8
|
}
|
|
8
9
|
static getInstance() {
|
|
9
10
|
if (!TokenManager.instance) {
|
|
@@ -18,6 +19,9 @@ export class TokenManager {
|
|
|
18
19
|
return TokenManager.instance;
|
|
19
20
|
}
|
|
20
21
|
async getToken() {
|
|
22
|
+
if (this.isRevoking) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
21
25
|
const token = this.getStoredToken();
|
|
22
26
|
if (token && token.expiresAt > Date.now()) {
|
|
23
27
|
// TODO check if token expire less that 1 minute
|
|
@@ -32,10 +36,14 @@ export class TokenManager {
|
|
|
32
36
|
return retrievedToken?.accessToken ?? null;
|
|
33
37
|
}
|
|
34
38
|
async revokeToken() {
|
|
39
|
+
this.isRevoking = true;
|
|
35
40
|
const token = this.getStoredToken();
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
if (!token) {
|
|
42
|
+
this.isRevoking = false;
|
|
38
43
|
return;
|
|
44
|
+
}
|
|
45
|
+
// Optimistic token cleanup
|
|
46
|
+
this.clearToken();
|
|
39
47
|
try {
|
|
40
48
|
const controller = new AbortController();
|
|
41
49
|
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
|
@@ -43,7 +51,7 @@ export class TokenManager {
|
|
|
43
51
|
method: 'POST',
|
|
44
52
|
headers: {
|
|
45
53
|
'Content-Type': 'application/json',
|
|
46
|
-
|
|
54
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
47
55
|
},
|
|
48
56
|
body: JSON.stringify({ token: token.accessToken }),
|
|
49
57
|
credentials: 'include',
|
|
@@ -54,10 +62,16 @@ export class TokenManager {
|
|
|
54
62
|
catch (error) {
|
|
55
63
|
console.error('Failed to revoke token:', error);
|
|
56
64
|
}
|
|
65
|
+
finally {
|
|
66
|
+
// Finally cleanup the token
|
|
67
|
+
this.clearToken();
|
|
68
|
+
this.isRevoking = false;
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
71
|
getStoredToken() {
|
|
59
|
-
if (typeof window === 'undefined')
|
|
72
|
+
if (typeof window === 'undefined') {
|
|
60
73
|
return null;
|
|
74
|
+
}
|
|
61
75
|
const storedToken = localStorage.getItem(TOKEN_STORAGE_KEY);
|
|
62
76
|
if (!storedToken) {
|
|
63
77
|
return null;
|
|
@@ -87,28 +101,23 @@ export class TokenManager {
|
|
|
87
101
|
async doRetrieveToken() {
|
|
88
102
|
const controller = new AbortController();
|
|
89
103
|
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
throw new UnauthorizedException(errorData.message || response.statusText);
|
|
103
|
-
}
|
|
104
|
-
throw new Error(errorData.message || response.statusText);
|
|
104
|
+
const response = await fetch('/oauth/token', {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: { 'Content-Type': 'application/json' },
|
|
107
|
+
body: JSON.stringify({ grant_type: 'client_credentials' }),
|
|
108
|
+
credentials: 'include',
|
|
109
|
+
signal: controller.signal,
|
|
110
|
+
});
|
|
111
|
+
clearTimeout(timeoutId);
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
const errorData = await response.json().catch(() => ({ message: response.statusText }));
|
|
114
|
+
if (response.status === 401) {
|
|
115
|
+
throw new UnauthorizedException(errorData.message || response.statusText);
|
|
105
116
|
}
|
|
106
|
-
|
|
107
|
-
this.setToken(data);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
throw error;
|
|
117
|
+
throw new Error(errorData.message || response.statusText);
|
|
111
118
|
}
|
|
119
|
+
const data = await response.json();
|
|
120
|
+
this.setToken(data);
|
|
112
121
|
}
|
|
113
122
|
setToken(tokenResponse) {
|
|
114
123
|
const expiresAt = this.getExpirationFromToken(tokenResponse.accessToken);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FlexbeConfig } from '../types';
|
|
2
|
-
import { SiteApi } from './site-api';
|
|
3
1
|
import { MetaApi } from './meta-api';
|
|
2
|
+
import { SiteApi } from './site-api';
|
|
3
|
+
import type { FlexbeConfig } from '../types';
|
|
4
4
|
export declare class FlexbeClient {
|
|
5
5
|
private readonly config;
|
|
6
6
|
private readonly api;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiClient } from './api-client';
|
|
2
|
-
import { SiteCurrency, SiteLanguage, UserLanguage } from '../types/meta';
|
|
1
|
+
import type { ApiClient } from './api-client';
|
|
2
|
+
import type { SiteCurrency, SiteLanguage, UserLanguage } from '../types/meta';
|
|
3
3
|
export declare class MetaApi {
|
|
4
4
|
private readonly api;
|
|
5
5
|
constructor(api: ApiClient);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ApiClient } from './api-client';
|
|
2
|
+
import type { BulkDeleteResponse, BulkUpdateFolderItem, BulkUpdateFolderResponse, BulkUpdatePageItem, BulkUpdateResponse, CreateFolderParams, GetPagesParams, Page, PageContent, PageFolder, PageFolderListResponse, PageHistoryItemData, PageHistoryListResponse, PageListResponse, PageVersionDataResponse, PageVersionListResponse, UpdateFolderParams, UpdatePageContentParams, UpdatePageParams } from '../types/pages';
|
|
3
3
|
export declare class Pages {
|
|
4
4
|
private readonly api;
|
|
5
5
|
private readonly siteId;
|
package/package.json
CHANGED
|
@@ -1,67 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "npm run build:esm && npm run build:cjs && npm run build:browser",
|
|
18
|
-
"build:esm": "tsc -p tsconfig.esm.json",
|
|
19
|
-
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
20
|
-
"build:browser": "tsc -p tsconfig.browser.json",
|
|
21
|
-
"dev": "tsc -p tsconfig.esm.json --watch",
|
|
22
|
-
"test": "dotenv -e test/.env.test jest",
|
|
23
|
-
"lint": "eslint src --ext .ts",
|
|
24
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
25
|
-
"prepare": "npm run build",
|
|
26
|
-
"prepublishOnly": "npm test && npm run lint"
|
|
27
|
-
},
|
|
28
|
-
"keywords": [
|
|
29
|
-
"flexbe",
|
|
30
|
-
"sdk",
|
|
31
|
-
"typescript",
|
|
32
|
-
"api-client"
|
|
33
|
-
],
|
|
34
|
-
"author": "Flexbe",
|
|
35
|
-
"license": "MIT",
|
|
36
|
-
"repository": {
|
|
37
|
-
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/flexbe/sdk-ts.git"
|
|
39
|
-
},
|
|
40
|
-
"bugs": {
|
|
41
|
-
"url": "https://github.com/flexbe/sdk-ts/issues"
|
|
42
|
-
},
|
|
43
|
-
"homepage": "https://github.com/flexbe/sdk-ts#readme",
|
|
44
|
-
"dependencies": {},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@types/jest": "^29.5.12",
|
|
47
|
-
"@types/node": "^20.11.19",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
49
|
-
"@typescript-eslint/parser": "^7.0.1",
|
|
50
|
-
"dotenv-cli": "^7.4.1",
|
|
51
|
-
"eslint": "^8.56.0",
|
|
52
|
-
"jest": "^29.7.0",
|
|
53
|
-
"prettier": "^3.2.5",
|
|
54
|
-
"ts-jest": "^29.1.2",
|
|
55
|
-
"typescript": "~5.5.0"
|
|
56
|
-
},
|
|
57
|
-
"files": [
|
|
58
|
-
"dist",
|
|
59
|
-
"README.md"
|
|
60
|
-
],
|
|
61
|
-
"engines": {
|
|
62
|
-
"node": ">=16.0.0"
|
|
63
|
-
},
|
|
64
|
-
"publishConfig": {
|
|
65
|
-
"access": "public"
|
|
2
|
+
"name": "@flexbe/sdk",
|
|
3
|
+
"version": "0.2.35",
|
|
4
|
+
"description": "TypeScript SDK for Flexbe API",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"browser": "dist/browser/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
66
14
|
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:browser",
|
|
18
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
19
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
20
|
+
"build:browser": "tsc -p tsconfig.browser.json",
|
|
21
|
+
"dev": "tsc -p tsconfig.esm.json --watch",
|
|
22
|
+
"test": "dotenv -e test/.env.test jest",
|
|
23
|
+
"lint": "eslint src --ext .ts",
|
|
24
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"prepublishOnly_": "npm test && npm run lint"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"flexbe",
|
|
30
|
+
"sdk",
|
|
31
|
+
"typescript",
|
|
32
|
+
"api-client"
|
|
33
|
+
],
|
|
34
|
+
"author": "Flexbe",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/flexbe/sdk-ts.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/flexbe/sdk-ts/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/flexbe/sdk-ts#readme",
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@flexbe/eslint-config": "^1.0.7",
|
|
46
|
+
"@types/jest": "^29.5.12",
|
|
47
|
+
"@types/node": "^20.11.19",
|
|
48
|
+
"dotenv-cli": "^7.4.1",
|
|
49
|
+
"eslint": "^9.26.0",
|
|
50
|
+
"jest": "^29.7.0",
|
|
51
|
+
"ts-jest": "^29.1.2",
|
|
52
|
+
"typescript": "~5.5.0"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"README.md"
|
|
57
|
+
],
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=16.0.0"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
}
|
|
67
64
|
}
|
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
};
|
|
10
|
-
import { FlexbeAuthType } from '../types';
|
|
11
|
-
import { TokenManager } from './token-manager';
|
|
12
|
-
export class FlexbeAuth {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.initialized = false;
|
|
15
|
-
this.initializationPromise = null;
|
|
16
|
-
this.config = config;
|
|
17
|
-
this.tokenManager = TokenManager.getInstance();
|
|
18
|
-
if (this.config.authType === FlexbeAuthType.BEARER) {
|
|
19
|
-
// Start initialization but don't wait for it
|
|
20
|
-
this.initializationPromise = this.initialize();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
this.initialized = true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
initialize() {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
try {
|
|
29
|
-
const token = yield this.tokenManager.getToken();
|
|
30
|
-
this.initialized = !!token;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
console.error('Failed to initialize auth:', error);
|
|
34
|
-
this.initialized = false;
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
this.initializationPromise = null;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
ensureInitialized() {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
if (this.config.authType !== FlexbeAuthType.BEARER || this.initialized) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
// If initialization is in progress, wait for it
|
|
47
|
-
if (this.initializationPromise) {
|
|
48
|
-
yield this.initializationPromise;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// If not initialized and no initialization in progress, start one
|
|
52
|
-
yield this.initialize();
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
getAuthHeaders() {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
yield this.ensureInitialized();
|
|
58
|
-
const headers = {
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
|
-
};
|
|
61
|
-
if (this.config.authType === FlexbeAuthType.API_KEY) {
|
|
62
|
-
headers['x-api-key'] = this.config.apiKey;
|
|
63
|
-
}
|
|
64
|
-
else if (this.config.authType === FlexbeAuthType.BEARER) {
|
|
65
|
-
const token = yield this.tokenManager.getToken();
|
|
66
|
-
if (!token) {
|
|
67
|
-
throw new Error('No valid bearer token available');
|
|
68
|
-
}
|
|
69
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
70
|
-
}
|
|
71
|
-
return headers;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
package/dist/cjs/client/auth.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlexbeAuth = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const token_manager_1 = require("./token-manager");
|
|
6
|
-
class FlexbeAuth {
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.initialized = false;
|
|
9
|
-
this.initializationPromise = null;
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.tokenManager = token_manager_1.TokenManager.getInstance();
|
|
12
|
-
if (this.config.authType === types_1.FlexbeAuthType.BEARER) {
|
|
13
|
-
// Start initialization but don't wait for it
|
|
14
|
-
this.initializationPromise = this.initialize();
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
this.initialized = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async initialize() {
|
|
21
|
-
try {
|
|
22
|
-
const token = await this.tokenManager.getToken();
|
|
23
|
-
this.initialized = !!token;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error('Failed to initialize auth:', error);
|
|
27
|
-
this.initialized = false;
|
|
28
|
-
}
|
|
29
|
-
finally {
|
|
30
|
-
this.initializationPromise = null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async ensureInitialized() {
|
|
34
|
-
if (this.config.authType !== types_1.FlexbeAuthType.BEARER || this.initialized) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// If initialization is in progress, wait for it
|
|
38
|
-
if (this.initializationPromise) {
|
|
39
|
-
await this.initializationPromise;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// If not initialized and no initialization in progress, start one
|
|
43
|
-
await this.initialize();
|
|
44
|
-
}
|
|
45
|
-
async getAuthHeaders() {
|
|
46
|
-
await this.ensureInitialized();
|
|
47
|
-
const headers = {
|
|
48
|
-
'Content-Type': 'application/json',
|
|
49
|
-
};
|
|
50
|
-
if (this.config.authType === types_1.FlexbeAuthType.API_KEY) {
|
|
51
|
-
headers['x-api-key'] = this.config.apiKey;
|
|
52
|
-
}
|
|
53
|
-
else if (this.config.authType === types_1.FlexbeAuthType.BEARER) {
|
|
54
|
-
const token = await this.tokenManager.getToken();
|
|
55
|
-
if (!token) {
|
|
56
|
-
throw new Error('No valid bearer token available');
|
|
57
|
-
}
|
|
58
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
59
|
-
}
|
|
60
|
-
return headers;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.FlexbeAuth = FlexbeAuth;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { FlexbeConfig, FlexbeResponse } from '../types';
|
|
3
|
-
export declare class FlexbeClient {
|
|
4
|
-
private readonly client;
|
|
5
|
-
private readonly config;
|
|
6
|
-
constructor(config: FlexbeConfig);
|
|
7
|
-
private setupInterceptors;
|
|
8
|
-
protected request<T>(config: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
9
|
-
protected get<T>(url: string, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
10
|
-
protected post<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
11
|
-
protected put<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
12
|
-
protected delete<T>(url: string, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
13
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FlexbeClient = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
class FlexbeClient {
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = {
|
|
11
|
-
baseUrl: config.baseUrl || 'https://api.flexbe.com',
|
|
12
|
-
timeout: config.timeout || 30000,
|
|
13
|
-
...config,
|
|
14
|
-
};
|
|
15
|
-
this.client = axios_1.default.create({
|
|
16
|
-
baseURL: this.config.baseUrl,
|
|
17
|
-
timeout: this.config.timeout,
|
|
18
|
-
headers: {
|
|
19
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
20
|
-
'Content-Type': 'application/json',
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
this.setupInterceptors();
|
|
24
|
-
}
|
|
25
|
-
setupInterceptors() {
|
|
26
|
-
this.client.interceptors.response.use((response) => response, (error) => {
|
|
27
|
-
const flexbeError = {
|
|
28
|
-
message: error.response?.data?.message || error.message,
|
|
29
|
-
code: error.response?.data?.code,
|
|
30
|
-
status: error.response?.status,
|
|
31
|
-
details: error.response?.data?.details,
|
|
32
|
-
};
|
|
33
|
-
return Promise.reject(flexbeError);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async request(config) {
|
|
37
|
-
try {
|
|
38
|
-
const response = await this.client.request(config);
|
|
39
|
-
return {
|
|
40
|
-
data: response.data,
|
|
41
|
-
status: response.status,
|
|
42
|
-
statusText: response.statusText,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
get(url, config) {
|
|
50
|
-
return this.request({ ...config, method: 'GET', url });
|
|
51
|
-
}
|
|
52
|
-
post(url, data, config) {
|
|
53
|
-
return this.request({ ...config, method: 'POST', url, data });
|
|
54
|
-
}
|
|
55
|
-
put(url, data, config) {
|
|
56
|
-
return this.request({ ...config, method: 'PUT', url, data });
|
|
57
|
-
}
|
|
58
|
-
delete(url, config) {
|
|
59
|
-
return this.request({ ...config, method: 'DELETE', url });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.FlexbeClient = FlexbeClient;
|
package/dist/esm/client/auth.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { FlexbeAuthType } from '../types';
|
|
2
|
-
import { TokenManager } from './token-manager';
|
|
3
|
-
export class FlexbeAuth {
|
|
4
|
-
constructor(config) {
|
|
5
|
-
this.initialized = false;
|
|
6
|
-
this.initializationPromise = null;
|
|
7
|
-
this.config = config;
|
|
8
|
-
this.tokenManager = TokenManager.getInstance();
|
|
9
|
-
if (this.config.authType === FlexbeAuthType.BEARER) {
|
|
10
|
-
// Start initialization but don't wait for it
|
|
11
|
-
this.initializationPromise = this.initialize();
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
this.initialized = true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
async initialize() {
|
|
18
|
-
try {
|
|
19
|
-
const token = await this.tokenManager.getToken();
|
|
20
|
-
this.initialized = !!token;
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
console.error('Failed to initialize auth:', error);
|
|
24
|
-
this.initialized = false;
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
this.initializationPromise = null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async ensureInitialized() {
|
|
31
|
-
if (this.config.authType !== FlexbeAuthType.BEARER || this.initialized) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// If initialization is in progress, wait for it
|
|
35
|
-
if (this.initializationPromise) {
|
|
36
|
-
await this.initializationPromise;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
// If not initialized and no initialization in progress, start one
|
|
40
|
-
await this.initialize();
|
|
41
|
-
}
|
|
42
|
-
async getAuthHeaders() {
|
|
43
|
-
await this.ensureInitialized();
|
|
44
|
-
const headers = {
|
|
45
|
-
'Content-Type': 'application/json',
|
|
46
|
-
};
|
|
47
|
-
if (this.config.authType === FlexbeAuthType.API_KEY) {
|
|
48
|
-
headers['x-api-key'] = this.config.apiKey;
|
|
49
|
-
}
|
|
50
|
-
else if (this.config.authType === FlexbeAuthType.BEARER) {
|
|
51
|
-
const token = await this.tokenManager.getToken();
|
|
52
|
-
if (!token) {
|
|
53
|
-
throw new Error('No valid bearer token available');
|
|
54
|
-
}
|
|
55
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
56
|
-
}
|
|
57
|
-
return headers;
|
|
58
|
-
}
|
|
59
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
|
-
__exportStar(require("./client/flexbe-client"), exports);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { FlexbeConfig, FlexbeResponse } from '../types';
|
|
3
|
-
import { PagesClient } from './pages-client';
|
|
4
|
-
export declare class FlexbeClient {
|
|
5
|
-
private readonly client;
|
|
6
|
-
private readonly config;
|
|
7
|
-
readonly pages: PagesClient;
|
|
8
|
-
constructor(config?: Partial<FlexbeConfig>);
|
|
9
|
-
private setupInterceptors;
|
|
10
|
-
private request;
|
|
11
|
-
private get;
|
|
12
|
-
private post;
|
|
13
|
-
private put;
|
|
14
|
-
private delete;
|
|
15
|
-
private getSiteUrl;
|
|
16
|
-
sitesGet<T>(path: string, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
17
|
-
sitesPost<T>(path: string, data?: unknown, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
18
|
-
sitesPut<T>(path: string, data?: unknown, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
19
|
-
sitesDelete<T>(path: string, config?: AxiosRequestConfig): Promise<FlexbeResponse<T>>;
|
|
20
|
-
}
|