@flexbe/sdk 0.2.35 → 0.2.38
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/auth.js +74 -0
- package/dist/browser/client/pages.js +54 -2
- package/dist/cjs/client/auth.js +63 -0
- package/dist/cjs/client/pages.js +48 -2
- package/dist/client/flexbe-client.d.ts +13 -0
- package/dist/client/flexbe-client.js +62 -0
- package/dist/esm/client/auth.js +59 -0
- package/dist/esm/client/pages.js +48 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/src/client/flexbe-client.d.ts +20 -0
- package/dist/src/client/flexbe-client.js +86 -0
- package/dist/src/client/pages-client.d.ts +14 -0
- package/dist/src/client/pages-client.js +23 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +20 -0
- package/dist/src/types/index.d.ts +23 -0
- package/dist/src/types/index.js +2 -0
- package/dist/src/types/pages.d.ts +41 -0
- package/dist/src/types/pages.js +19 -0
- package/dist/test/client/flexbe-client.test.d.ts +1 -0
- package/dist/test/client/flexbe-client.test.js +38 -0
- package/dist/test/client/pages-client.test.d.ts +1 -0
- package/dist/test/client/pages-client.test.js +82 -0
- package/dist/types/client/auth.d.ts +11 -0
- package/dist/types/client/pages.d.ts +42 -4
- package/dist/types/index.js +2 -0
- package/dist/types/types/pages.d.ts +23 -2
- package/package.json +2 -2
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
@@ -316,6 +316,22 @@ export class Pages {
|
|
|
316
316
|
* @throws {ServerException} When the server encounters an error
|
|
317
317
|
* @throws {TimeoutException} When the request times out
|
|
318
318
|
*/
|
|
319
|
+
getVersions(pageId) {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
const response = yield this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions`);
|
|
322
|
+
return response.data;
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* @deprecated Use getVersions instead, remove it after frontend will be updated
|
|
327
|
+
* @param pageId - ID of the page to get versions for
|
|
328
|
+
* @returns List of page versions
|
|
329
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
330
|
+
* @throws {NotFoundException} When the page is not found
|
|
331
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
332
|
+
* @throws {ServerException} When the server encounters an error
|
|
333
|
+
* @throws {TimeoutException} When the request times out
|
|
334
|
+
*/
|
|
319
335
|
getPageVersions(pageId) {
|
|
320
336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
321
337
|
const response = yield this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions`);
|
|
@@ -325,7 +341,7 @@ export class Pages {
|
|
|
325
341
|
/**
|
|
326
342
|
* Get a specific page version
|
|
327
343
|
* @param pageId - ID of the page
|
|
328
|
-
* @param versionId - ID of the version to get
|
|
344
|
+
* @param versionId - ID of the version to get or 'published' to get the published version
|
|
329
345
|
* @returns The requested page version with data
|
|
330
346
|
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
331
347
|
* @throws {NotFoundException} When the page or version is not found
|
|
@@ -333,10 +349,46 @@ export class Pages {
|
|
|
333
349
|
* @throws {ServerException} When the server encounters an error
|
|
334
350
|
* @throws {TimeoutException} When the request times out
|
|
335
351
|
*/
|
|
336
|
-
|
|
352
|
+
getVersion(pageId, versionId) {
|
|
337
353
|
return __awaiter(this, void 0, void 0, function* () {
|
|
338
354
|
const response = yield this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions/${versionId}`);
|
|
339
355
|
return response.data;
|
|
340
356
|
});
|
|
341
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Get the published version of a page
|
|
360
|
+
* @param pageId - ID of the page
|
|
361
|
+
* @returns The published page version with data
|
|
362
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
363
|
+
* @throws {NotFoundException} When the page is not found or has no published version
|
|
364
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
365
|
+
* @throws {ServerException} When the server encounters an error
|
|
366
|
+
* @throws {TimeoutException} When the request times out
|
|
367
|
+
*/
|
|
368
|
+
getPublishedVersion(pageId) {
|
|
369
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
return this.getVersion(pageId, 'published');
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Create a new page version
|
|
375
|
+
* @param pageId - ID of the page to create version for
|
|
376
|
+
* @param data - Version data including:
|
|
377
|
+
* - data: Page data structure containing blocks, modals, widgets, etc.
|
|
378
|
+
* - assets: Optional page assets (images, files, screenshot)
|
|
379
|
+
* - publish: Whether to publish this version immediately (default: true)
|
|
380
|
+
* @returns The created page version with data
|
|
381
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
382
|
+
* @throws {NotFoundException} When the page is not found
|
|
383
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
384
|
+
* @throws {BadRequestException} When the version data is invalid
|
|
385
|
+
* @throws {ServerException} When the server encounters an error
|
|
386
|
+
* @throws {TimeoutException} When the request times out
|
|
387
|
+
*/
|
|
388
|
+
createVersion(pageId, data) {
|
|
389
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
390
|
+
const response = yield this.api.post(`/sites/${this.siteId}/pages/${pageId}/versions`, data);
|
|
391
|
+
return response.data;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
342
394
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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;
|
package/dist/cjs/client/pages.js
CHANGED
|
@@ -283,6 +283,20 @@ class Pages {
|
|
|
283
283
|
* @throws {ServerException} When the server encounters an error
|
|
284
284
|
* @throws {TimeoutException} When the request times out
|
|
285
285
|
*/
|
|
286
|
+
async getVersions(pageId) {
|
|
287
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions`);
|
|
288
|
+
return response.data;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @deprecated Use getVersions instead, remove it after frontend will be updated
|
|
292
|
+
* @param pageId - ID of the page to get versions for
|
|
293
|
+
* @returns List of page versions
|
|
294
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
295
|
+
* @throws {NotFoundException} When the page is not found
|
|
296
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
297
|
+
* @throws {ServerException} When the server encounters an error
|
|
298
|
+
* @throws {TimeoutException} When the request times out
|
|
299
|
+
*/
|
|
286
300
|
async getPageVersions(pageId) {
|
|
287
301
|
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions`);
|
|
288
302
|
return response.data;
|
|
@@ -290,7 +304,7 @@ class Pages {
|
|
|
290
304
|
/**
|
|
291
305
|
* Get a specific page version
|
|
292
306
|
* @param pageId - ID of the page
|
|
293
|
-
* @param versionId - ID of the version to get
|
|
307
|
+
* @param versionId - ID of the version to get or 'published' to get the published version
|
|
294
308
|
* @returns The requested page version with data
|
|
295
309
|
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
296
310
|
* @throws {NotFoundException} When the page or version is not found
|
|
@@ -298,9 +312,41 @@ class Pages {
|
|
|
298
312
|
* @throws {ServerException} When the server encounters an error
|
|
299
313
|
* @throws {TimeoutException} When the request times out
|
|
300
314
|
*/
|
|
301
|
-
async
|
|
315
|
+
async getVersion(pageId, versionId) {
|
|
302
316
|
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions/${versionId}`);
|
|
303
317
|
return response.data;
|
|
304
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Get the published version of a page
|
|
321
|
+
* @param pageId - ID of the page
|
|
322
|
+
* @returns The published page version with data
|
|
323
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
324
|
+
* @throws {NotFoundException} When the page is not found or has no published version
|
|
325
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
326
|
+
* @throws {ServerException} When the server encounters an error
|
|
327
|
+
* @throws {TimeoutException} When the request times out
|
|
328
|
+
*/
|
|
329
|
+
async getPublishedVersion(pageId) {
|
|
330
|
+
return this.getVersion(pageId, 'published');
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Create a new page version
|
|
334
|
+
* @param pageId - ID of the page to create version for
|
|
335
|
+
* @param data - Version data including:
|
|
336
|
+
* - data: Page data structure containing blocks, modals, widgets, etc.
|
|
337
|
+
* - assets: Optional page assets (images, files, screenshot)
|
|
338
|
+
* - publish: Whether to publish this version immediately (default: true)
|
|
339
|
+
* @returns The created page version with data
|
|
340
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
341
|
+
* @throws {NotFoundException} When the page is not found
|
|
342
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
343
|
+
* @throws {BadRequestException} When the version data is invalid
|
|
344
|
+
* @throws {ServerException} When the server encounters an error
|
|
345
|
+
* @throws {TimeoutException} When the request times out
|
|
346
|
+
*/
|
|
347
|
+
async createVersion(pageId, data) {
|
|
348
|
+
const response = await this.api.post(`/sites/${this.siteId}/pages/${pageId}/versions`, data);
|
|
349
|
+
return response.data;
|
|
350
|
+
}
|
|
305
351
|
}
|
|
306
352
|
exports.Pages = Pages;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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;
|
|
@@ -0,0 +1,59 @@
|
|
|
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/esm/client/pages.js
CHANGED
|
@@ -280,6 +280,20 @@ export class Pages {
|
|
|
280
280
|
* @throws {ServerException} When the server encounters an error
|
|
281
281
|
* @throws {TimeoutException} When the request times out
|
|
282
282
|
*/
|
|
283
|
+
async getVersions(pageId) {
|
|
284
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions`);
|
|
285
|
+
return response.data;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* @deprecated Use getVersions instead, remove it after frontend will be updated
|
|
289
|
+
* @param pageId - ID of the page to get versions for
|
|
290
|
+
* @returns List of page versions
|
|
291
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
292
|
+
* @throws {NotFoundException} When the page is not found
|
|
293
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
294
|
+
* @throws {ServerException} When the server encounters an error
|
|
295
|
+
* @throws {TimeoutException} When the request times out
|
|
296
|
+
*/
|
|
283
297
|
async getPageVersions(pageId) {
|
|
284
298
|
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions`);
|
|
285
299
|
return response.data;
|
|
@@ -287,7 +301,7 @@ export class Pages {
|
|
|
287
301
|
/**
|
|
288
302
|
* Get a specific page version
|
|
289
303
|
* @param pageId - ID of the page
|
|
290
|
-
* @param versionId - ID of the version to get
|
|
304
|
+
* @param versionId - ID of the version to get or 'published' to get the published version
|
|
291
305
|
* @returns The requested page version with data
|
|
292
306
|
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
293
307
|
* @throws {NotFoundException} When the page or version is not found
|
|
@@ -295,8 +309,40 @@ export class Pages {
|
|
|
295
309
|
* @throws {ServerException} When the server encounters an error
|
|
296
310
|
* @throws {TimeoutException} When the request times out
|
|
297
311
|
*/
|
|
298
|
-
async
|
|
312
|
+
async getVersion(pageId, versionId) {
|
|
299
313
|
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}/versions/${versionId}`);
|
|
300
314
|
return response.data;
|
|
301
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Get the published version of a page
|
|
318
|
+
* @param pageId - ID of the page
|
|
319
|
+
* @returns The published page version with data
|
|
320
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
321
|
+
* @throws {NotFoundException} When the page is not found or has no published version
|
|
322
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
323
|
+
* @throws {ServerException} When the server encounters an error
|
|
324
|
+
* @throws {TimeoutException} When the request times out
|
|
325
|
+
*/
|
|
326
|
+
async getPublishedVersion(pageId) {
|
|
327
|
+
return this.getVersion(pageId, 'published');
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Create a new page version
|
|
331
|
+
* @param pageId - ID of the page to create version for
|
|
332
|
+
* @param data - Version data including:
|
|
333
|
+
* - data: Page data structure containing blocks, modals, widgets, etc.
|
|
334
|
+
* - assets: Optional page assets (images, files, screenshot)
|
|
335
|
+
* - publish: Whether to publish this version immediately (default: true)
|
|
336
|
+
* @returns The created page version with data
|
|
337
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
338
|
+
* @throws {NotFoundException} When the page is not found
|
|
339
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
340
|
+
* @throws {BadRequestException} When the version data is invalid
|
|
341
|
+
* @throws {ServerException} When the server encounters an error
|
|
342
|
+
* @throws {TimeoutException} When the request times out
|
|
343
|
+
*/
|
|
344
|
+
async createVersion(pageId, data) {
|
|
345
|
+
const response = await this.api.post(`/sites/${this.siteId}/pages/${pageId}/versions`, data);
|
|
346
|
+
return response.data;
|
|
347
|
+
}
|
|
302
348
|
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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);
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
const pages_client_1 = require("./pages-client");
|
|
9
|
+
class FlexbeClient {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = {
|
|
12
|
+
baseUrl: config?.baseUrl || process.env.FLEXBE_API_URL || 'https://api.flexbe.com',
|
|
13
|
+
timeout: config?.timeout || 30000,
|
|
14
|
+
apiKey: config?.apiKey || process.env.FLEXBE_API_KEY || '',
|
|
15
|
+
siteId: config?.siteId || process.env.FLEXBE_SITE_ID,
|
|
16
|
+
};
|
|
17
|
+
if (!this.config.apiKey) {
|
|
18
|
+
throw new Error('API key is required. Please provide it either through config or FLEXBE_API_KEY environment variable.');
|
|
19
|
+
}
|
|
20
|
+
this.client = axios_1.default.create({
|
|
21
|
+
baseURL: this.config.baseUrl,
|
|
22
|
+
timeout: this.config.timeout,
|
|
23
|
+
headers: {
|
|
24
|
+
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
this.setupInterceptors();
|
|
29
|
+
this.pages = new pages_client_1.PagesClient(this);
|
|
30
|
+
}
|
|
31
|
+
setupInterceptors() {
|
|
32
|
+
this.client.interceptors.response.use((response) => response, (error) => {
|
|
33
|
+
const flexbeError = {
|
|
34
|
+
message: error.response?.data?.message || error.message,
|
|
35
|
+
code: error.response?.data?.code,
|
|
36
|
+
status: error.response?.status,
|
|
37
|
+
details: error.response?.data?.details,
|
|
38
|
+
};
|
|
39
|
+
return Promise.reject(flexbeError);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async request(config) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await this.client.request(config);
|
|
45
|
+
return {
|
|
46
|
+
data: response.data,
|
|
47
|
+
status: response.status,
|
|
48
|
+
statusText: response.statusText,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
get(url, config) {
|
|
56
|
+
return this.request({ ...config, method: 'GET', url });
|
|
57
|
+
}
|
|
58
|
+
post(url, data, config) {
|
|
59
|
+
return this.request({ ...config, method: 'POST', url, data });
|
|
60
|
+
}
|
|
61
|
+
put(url, data, config) {
|
|
62
|
+
return this.request({ ...config, method: 'PUT', url, data });
|
|
63
|
+
}
|
|
64
|
+
delete(url, config) {
|
|
65
|
+
return this.request({ ...config, method: 'DELETE', url });
|
|
66
|
+
}
|
|
67
|
+
getSiteUrl(path) {
|
|
68
|
+
if (!this.config.siteId) {
|
|
69
|
+
return path;
|
|
70
|
+
}
|
|
71
|
+
return `/sites/${this.config.siteId}${path}`;
|
|
72
|
+
}
|
|
73
|
+
sitesGet(path, config) {
|
|
74
|
+
return this.get(this.getSiteUrl(path), config);
|
|
75
|
+
}
|
|
76
|
+
sitesPost(path, data, config) {
|
|
77
|
+
return this.post(this.getSiteUrl(path), data, config);
|
|
78
|
+
}
|
|
79
|
+
sitesPut(path, data, config) {
|
|
80
|
+
return this.put(this.getSiteUrl(path), data, config);
|
|
81
|
+
}
|
|
82
|
+
sitesDelete(path, config) {
|
|
83
|
+
return this.delete(this.getSiteUrl(path), config);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.FlexbeClient = FlexbeClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Page, GetPagesParams, PageListResponse } from '../types/pages';
|
|
2
|
+
import { FlexbeClient } from './flexbe-client';
|
|
3
|
+
export declare class PagesClient {
|
|
4
|
+
private readonly client;
|
|
5
|
+
constructor(client: FlexbeClient);
|
|
6
|
+
/**
|
|
7
|
+
* Get list of pages for a site
|
|
8
|
+
*/
|
|
9
|
+
getPages(params?: GetPagesParams): Promise<PageListResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Get a single page by ID
|
|
12
|
+
*/
|
|
13
|
+
getPage(pageId: number): Promise<Page>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PagesClient = void 0;
|
|
4
|
+
class PagesClient {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Get list of pages for a site
|
|
10
|
+
*/
|
|
11
|
+
async getPages(params) {
|
|
12
|
+
const response = await this.client.sitesGet('/pages', { params });
|
|
13
|
+
return response.data;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a single page by ID
|
|
17
|
+
*/
|
|
18
|
+
async getPage(pageId) {
|
|
19
|
+
const response = await this.client.sitesGet(`/pages/${pageId}`);
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.PagesClient = PagesClient;
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./client/flexbe-client"), exports);
|
|
18
|
+
__exportStar(require("./client/pages-client"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./types/pages"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface FlexbeConfig {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
siteId?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FlexbeResponse<T> {
|
|
8
|
+
data: T;
|
|
9
|
+
status: number;
|
|
10
|
+
statusText: string;
|
|
11
|
+
}
|
|
12
|
+
export interface FlexbeErrorResponse {
|
|
13
|
+
message: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
details?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface FlexbeError {
|
|
18
|
+
message: string;
|
|
19
|
+
code?: string;
|
|
20
|
+
status?: number;
|
|
21
|
+
details?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export type FlexbeAuthType = 'apiKey' | 'bearer' | 'oauth2';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare enum PageType {
|
|
2
|
+
PAGE = "page",
|
|
3
|
+
FILE = "file",
|
|
4
|
+
GLOBAL = "global",
|
|
5
|
+
AI = "ai",
|
|
6
|
+
CMS = "cms",
|
|
7
|
+
ECOMMERCE_PRODUCT = "ecommerce_product",
|
|
8
|
+
ECOMMERCE_CATEGORY = "ecommerce_category"
|
|
9
|
+
}
|
|
10
|
+
export declare enum PageStatus {
|
|
11
|
+
PUBLISHED = "published",
|
|
12
|
+
DRAFTED = "drafted",
|
|
13
|
+
DELETED = "deleted"
|
|
14
|
+
}
|
|
15
|
+
export interface Page {
|
|
16
|
+
id: number;
|
|
17
|
+
siteId: number;
|
|
18
|
+
type: PageType;
|
|
19
|
+
uri: string;
|
|
20
|
+
title: string | null;
|
|
21
|
+
status: PageStatus;
|
|
22
|
+
updatedAt?: Date;
|
|
23
|
+
imgId: number | null;
|
|
24
|
+
sortIndex: number;
|
|
25
|
+
}
|
|
26
|
+
export interface GetPagesParams {
|
|
27
|
+
offset?: number;
|
|
28
|
+
limit?: number;
|
|
29
|
+
type?: PageType;
|
|
30
|
+
status?: PageStatus;
|
|
31
|
+
search?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Pagination {
|
|
34
|
+
limit: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
total: number;
|
|
37
|
+
}
|
|
38
|
+
export interface PageListResponse {
|
|
39
|
+
pages: Page[];
|
|
40
|
+
pagination: Pagination;
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PageStatus = exports.PageType = void 0;
|
|
4
|
+
var PageType;
|
|
5
|
+
(function (PageType) {
|
|
6
|
+
PageType["PAGE"] = "page";
|
|
7
|
+
PageType["FILE"] = "file";
|
|
8
|
+
PageType["GLOBAL"] = "global";
|
|
9
|
+
PageType["AI"] = "ai";
|
|
10
|
+
PageType["CMS"] = "cms";
|
|
11
|
+
PageType["ECOMMERCE_PRODUCT"] = "ecommerce_product";
|
|
12
|
+
PageType["ECOMMERCE_CATEGORY"] = "ecommerce_category";
|
|
13
|
+
})(PageType || (exports.PageType = PageType = {}));
|
|
14
|
+
var PageStatus;
|
|
15
|
+
(function (PageStatus) {
|
|
16
|
+
PageStatus["PUBLISHED"] = "published";
|
|
17
|
+
PageStatus["DRAFTED"] = "drafted";
|
|
18
|
+
PageStatus["DELETED"] = "deleted";
|
|
19
|
+
})(PageStatus || (exports.PageStatus = PageStatus = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flexbe_client_1 = require("../../src/client/flexbe-client");
|
|
4
|
+
describe('FlexbeClient', () => {
|
|
5
|
+
let client;
|
|
6
|
+
const testConfig = {
|
|
7
|
+
apiKey: process.env.FLEXBE_API_KEY || 'test-api-key',
|
|
8
|
+
baseUrl: process.env.FLEXBE_API_URL || 'https://api.flexbe.com',
|
|
9
|
+
};
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
client = new flexbe_client_1.FlexbeClient(testConfig);
|
|
12
|
+
});
|
|
13
|
+
it('should initialize with correct configuration', () => {
|
|
14
|
+
expect(client).toBeDefined();
|
|
15
|
+
const axiosInstance = client.client;
|
|
16
|
+
expect(axiosInstance.defaults.baseURL).toBe(testConfig.baseUrl);
|
|
17
|
+
expect(axiosInstance.defaults.headers.Authorization).toBe(`Bearer ${testConfig.apiKey}`);
|
|
18
|
+
});
|
|
19
|
+
it('should handle successful GET request', async () => {
|
|
20
|
+
// Access protected method for testing
|
|
21
|
+
const response = await client.get('/');
|
|
22
|
+
expect(response).toBeDefined();
|
|
23
|
+
expect(response.status).toBe(200);
|
|
24
|
+
expect(response.data).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
it('should handle error response', async () => {
|
|
27
|
+
try {
|
|
28
|
+
// Access protected method for testing
|
|
29
|
+
await client.get('/non-existent-endpoint');
|
|
30
|
+
fail('Should have thrown an error');
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const flexbeError = error;
|
|
34
|
+
expect(flexbeError.message).toBeDefined();
|
|
35
|
+
expect(flexbeError.status).toBeDefined();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flexbe_client_1 = require("../../src/client/flexbe-client");
|
|
4
|
+
const pages_1 = require("../../src/types/pages");
|
|
5
|
+
describe('PagesClient', () => {
|
|
6
|
+
let client;
|
|
7
|
+
const testConfig = {
|
|
8
|
+
apiKey: process.env.FLEXBE_API_KEY || 'test-api-key',
|
|
9
|
+
baseUrl: process.env.FLEXBE_API_URL || 'https://api.flexbe.com',
|
|
10
|
+
siteId: process.env.FLEXBE_SITE_ID || '0',
|
|
11
|
+
};
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
client = new flexbe_client_1.FlexbeClient(testConfig);
|
|
14
|
+
});
|
|
15
|
+
it('should initialize with correct configuration', () => {
|
|
16
|
+
expect(client.pages).toBeDefined();
|
|
17
|
+
const axiosInstance = client.client;
|
|
18
|
+
expect(axiosInstance.defaults.baseURL).toBe(testConfig.baseUrl);
|
|
19
|
+
expect(axiosInstance.defaults.headers.Authorization).toBe(`Bearer ${testConfig.apiKey}`);
|
|
20
|
+
});
|
|
21
|
+
it('should get list of pages with default parameters', async () => {
|
|
22
|
+
const response = await client.pages.getPages();
|
|
23
|
+
expect(response).toBeDefined();
|
|
24
|
+
expect(response.pages).toBeDefined();
|
|
25
|
+
expect(response.pagination).toBeDefined();
|
|
26
|
+
expect(response.pagination.limit).toBe(10);
|
|
27
|
+
expect(response.pagination.offset).toBe(0);
|
|
28
|
+
expect(response.pagination.total).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
it('should get list of pages with custom parameters', async () => {
|
|
31
|
+
const params = {
|
|
32
|
+
offset: 0,
|
|
33
|
+
limit: 20,
|
|
34
|
+
type: pages_1.PageType.PAGE,
|
|
35
|
+
status: pages_1.PageStatus.PUBLISHED,
|
|
36
|
+
search: ''
|
|
37
|
+
};
|
|
38
|
+
const response = await client.pages.getPages(params);
|
|
39
|
+
expect(response).toBeDefined();
|
|
40
|
+
expect(response.pages).toBeDefined();
|
|
41
|
+
expect(response.pagination).toBeDefined();
|
|
42
|
+
expect(response.pagination.limit).toBe(params.limit);
|
|
43
|
+
expect(response.pagination.offset).toBe(params.offset);
|
|
44
|
+
expect(response.pagination.total).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
it('should get a single page by ID', async () => {
|
|
47
|
+
const pageId = 2272741;
|
|
48
|
+
const response = await client.pages.getPage(pageId);
|
|
49
|
+
expect(response).toBeDefined();
|
|
50
|
+
expect(response.id).toBe(pageId);
|
|
51
|
+
expect(response.siteId).toBe(Number(testConfig.siteId));
|
|
52
|
+
expect(response.type).toBeDefined();
|
|
53
|
+
expect(response.uri).toBeDefined();
|
|
54
|
+
expect(response.status).toBeDefined();
|
|
55
|
+
expect(response.sortIndex).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
it('should handle error when getting non-existent page', async () => {
|
|
58
|
+
try {
|
|
59
|
+
await client.pages.getPage(999999);
|
|
60
|
+
fail('Should have thrown an error');
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const flexbeError = error;
|
|
64
|
+
expect(flexbeError.message).toBeDefined();
|
|
65
|
+
expect(flexbeError.status).toBeDefined();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
it('should handle error when getting pages with invalid parameters', async () => {
|
|
69
|
+
try {
|
|
70
|
+
await client.pages.getPages({
|
|
71
|
+
offset: -1,
|
|
72
|
+
limit: 0
|
|
73
|
+
});
|
|
74
|
+
fail('Should have thrown an error');
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const flexbeError = error;
|
|
78
|
+
expect(flexbeError.message).toBeDefined();
|
|
79
|
+
expect(flexbeError.status).toBeDefined();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FlexbeConfig } from '../types';
|
|
2
|
+
export declare class FlexbeAuth {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly tokenManager;
|
|
5
|
+
private initialized;
|
|
6
|
+
private initializationPromise;
|
|
7
|
+
constructor(config: FlexbeConfig);
|
|
8
|
+
private initialize;
|
|
9
|
+
ensureInitialized(): Promise<void>;
|
|
10
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
11
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ApiClient } from './api-client';
|
|
2
|
+
import { BulkDeleteResponse, BulkUpdateFolderItem, BulkUpdateFolderResponse, BulkUpdatePageItem, BulkUpdateResponse, CreateFolderParams, CreatePageVersionParams, 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;
|
|
@@ -226,11 +226,22 @@ export declare class Pages {
|
|
|
226
226
|
* @throws {ServerException} When the server encounters an error
|
|
227
227
|
* @throws {TimeoutException} When the request times out
|
|
228
228
|
*/
|
|
229
|
+
getVersions(pageId: number): Promise<PageVersionListResponse>;
|
|
230
|
+
/**
|
|
231
|
+
* @deprecated Use getVersions instead, remove it after frontend will be updated
|
|
232
|
+
* @param pageId - ID of the page to get versions for
|
|
233
|
+
* @returns List of page versions
|
|
234
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
235
|
+
* @throws {NotFoundException} When the page is not found
|
|
236
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
237
|
+
* @throws {ServerException} When the server encounters an error
|
|
238
|
+
* @throws {TimeoutException} When the request times out
|
|
239
|
+
*/
|
|
229
240
|
getPageVersions(pageId: number): Promise<PageVersionListResponse>;
|
|
230
241
|
/**
|
|
231
242
|
* Get a specific page version
|
|
232
243
|
* @param pageId - ID of the page
|
|
233
|
-
* @param versionId - ID of the version to get
|
|
244
|
+
* @param versionId - ID of the version to get or 'published' to get the published version
|
|
234
245
|
* @returns The requested page version with data
|
|
235
246
|
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
236
247
|
* @throws {NotFoundException} When the page or version is not found
|
|
@@ -238,5 +249,32 @@ export declare class Pages {
|
|
|
238
249
|
* @throws {ServerException} When the server encounters an error
|
|
239
250
|
* @throws {TimeoutException} When the request times out
|
|
240
251
|
*/
|
|
241
|
-
|
|
252
|
+
getVersion(pageId: number, versionId: number | 'published'): Promise<PageVersionDataResponse>;
|
|
253
|
+
/**
|
|
254
|
+
* Get the published version of a page
|
|
255
|
+
* @param pageId - ID of the page
|
|
256
|
+
* @returns The published page version with data
|
|
257
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
258
|
+
* @throws {NotFoundException} When the page is not found or has no published version
|
|
259
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
260
|
+
* @throws {ServerException} When the server encounters an error
|
|
261
|
+
* @throws {TimeoutException} When the request times out
|
|
262
|
+
*/
|
|
263
|
+
getPublishedVersion(pageId: number): Promise<PageVersionDataResponse>;
|
|
264
|
+
/**
|
|
265
|
+
* Create a new page version
|
|
266
|
+
* @param pageId - ID of the page to create version for
|
|
267
|
+
* @param data - Version data including:
|
|
268
|
+
* - data: Page data structure containing blocks, modals, widgets, etc.
|
|
269
|
+
* - assets: Optional page assets (images, files, screenshot)
|
|
270
|
+
* - publish: Whether to publish this version immediately (default: true)
|
|
271
|
+
* @returns The created page version with data
|
|
272
|
+
* @throws {UnauthorizedException} When the API key is invalid or expired
|
|
273
|
+
* @throws {NotFoundException} When the page is not found
|
|
274
|
+
* @throws {ForbiddenException} When the page does not belong to the site
|
|
275
|
+
* @throws {BadRequestException} When the version data is invalid
|
|
276
|
+
* @throws {ServerException} When the server encounters an error
|
|
277
|
+
* @throws {TimeoutException} When the request times out
|
|
278
|
+
*/
|
|
279
|
+
createVersion(pageId: number, data: CreatePageVersionParams): Promise<PageVersionDataResponse>;
|
|
242
280
|
}
|
|
@@ -98,6 +98,15 @@ export interface UpdatePageParams {
|
|
|
98
98
|
sortIndex?: number;
|
|
99
99
|
meta?: Partial<PageMeta>;
|
|
100
100
|
}
|
|
101
|
+
export interface CreatePageVersionParams {
|
|
102
|
+
data: PageDataStructure;
|
|
103
|
+
assets?: {
|
|
104
|
+
images: number[];
|
|
105
|
+
files: string[];
|
|
106
|
+
screenshot?: number | null;
|
|
107
|
+
};
|
|
108
|
+
publish?: boolean;
|
|
109
|
+
}
|
|
101
110
|
export interface BulkUpdatePageItem extends UpdatePageParams {
|
|
102
111
|
id: number;
|
|
103
112
|
}
|
|
@@ -307,7 +316,19 @@ export interface PageVersionItem {
|
|
|
307
316
|
export interface PageVersionListResponse {
|
|
308
317
|
list: PageVersionItem[];
|
|
309
318
|
}
|
|
310
|
-
export interface
|
|
311
|
-
|
|
319
|
+
export interface PageDataStructure {
|
|
320
|
+
is: string;
|
|
321
|
+
template_id: string;
|
|
322
|
+
blocks: PageBlock[];
|
|
323
|
+
modals: PageModal[];
|
|
324
|
+
widgets: PageWidget[];
|
|
325
|
+
codes: string[];
|
|
326
|
+
abtests: PageABTest[];
|
|
327
|
+
background: PageBackground;
|
|
328
|
+
textStyles: TextStyleItem[];
|
|
329
|
+
responsive: string | boolean;
|
|
330
|
+
}
|
|
331
|
+
export interface PageVersionDataResponse extends PageVersionItem {
|
|
332
|
+
data: PageDataStructure;
|
|
312
333
|
}
|
|
313
334
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexbe/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"description": "TypeScript SDK for Flexbe API",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lint": "eslint src --ext .ts",
|
|
24
24
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
25
25
|
"prepare": "npm run build",
|
|
26
|
-
"
|
|
26
|
+
"prepublishOnly": "npm test && npm run lint"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [
|
|
29
29
|
"flexbe",
|