@flexbe/sdk 0.2.2 → 0.2.4
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 +7 -16
- package/dist/browser/client/api-client.js +1 -8
- package/dist/browser/client/client.js +15 -3
- package/dist/browser/client/pages.js +13 -12
- package/dist/browser/client/site-api.js +6 -0
- package/dist/cjs/client/api-client.js +1 -8
- package/dist/cjs/client/client.js +15 -3
- package/dist/cjs/client/pages.js +17 -12
- package/dist/cjs/client/site-api.js +10 -0
- package/dist/esm/client/api-client.js +1 -8
- package/dist/esm/client/client.js +15 -3
- package/dist/esm/client/pages.js +17 -12
- package/dist/esm/client/site-api.js +6 -0
- package/dist/types/client/api-client.d.ts +0 -1
- package/dist/types/client/client.d.ts +9 -4
- package/dist/types/client/pages.d.ts +4 -4
- package/dist/types/client/site-api.d.ts +6 -0
- package/dist/types/types/pages.d.ts +2 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,23 +16,15 @@ import { FlexbeClient } from '@flexbe/sdk';
|
|
|
16
16
|
// Initialize the client with API Key authentication
|
|
17
17
|
const client = new FlexbeClient({
|
|
18
18
|
apiKey: 'your-api-key',
|
|
19
|
-
siteId: 'your-site-id', // optional, required for site-specific endpoints
|
|
20
19
|
baseUrl: 'https://api.flexbe.com', // optional
|
|
21
20
|
timeout: 30000, // optional, defaults to 30 seconds
|
|
22
21
|
});
|
|
22
|
+
const siteApi = client.getSiteApi(SITE_ID)
|
|
23
23
|
|
|
24
|
-
//
|
|
25
|
-
const client = new FlexbeClient({
|
|
26
|
-
authType: 'bearer',
|
|
27
|
-
siteId: 'your-site-id', // optional, required for site-specific endpoints
|
|
28
|
-
baseUrl: 'https://api.flexbe.com', // optional
|
|
29
|
-
timeout: 30000, // optional, defaults to 30 seconds
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Using the Pages API
|
|
24
|
+
// Using the Pages API for a specific site
|
|
33
25
|
try {
|
|
34
|
-
// Get list of pages
|
|
35
|
-
const pages = await
|
|
26
|
+
// Get list of pages for site
|
|
27
|
+
const pages = await siteApi.pages.getPages({
|
|
36
28
|
limit: 10,
|
|
37
29
|
offset: 0,
|
|
38
30
|
type: 'page',
|
|
@@ -40,8 +32,8 @@ try {
|
|
|
40
32
|
});
|
|
41
33
|
console.log(pages.pages);
|
|
42
34
|
|
|
43
|
-
// Get a single page
|
|
44
|
-
const page = await
|
|
35
|
+
// Get a single page from site
|
|
36
|
+
const page = await siteApi.pages.getPage(123);
|
|
45
37
|
console.log(page);
|
|
46
38
|
} catch (error) {
|
|
47
39
|
console.error(error.message);
|
|
@@ -58,7 +50,7 @@ try {
|
|
|
58
50
|
- Automatic error handling
|
|
59
51
|
- Configurable timeout and base URL
|
|
60
52
|
- Native fetch API support (works in both Node.js and browser)
|
|
61
|
-
-
|
|
53
|
+
- Multi-site support with site-specific API instances
|
|
62
54
|
- Query parameter handling
|
|
63
55
|
- Request timeout handling
|
|
64
56
|
- Token sharing between browser tabs (for JWT authentication)
|
|
@@ -68,7 +60,6 @@ try {
|
|
|
68
60
|
The SDK supports the following environment variables:
|
|
69
61
|
- `FLEXBE_API_KEY`: Your API key (required for API Key authentication)
|
|
70
62
|
- `FLEXBE_API_URL`: Base URL (defaults to 'https://api.flexbe.com')
|
|
71
|
-
- `FLEXBE_SITE_ID`: Your site ID
|
|
72
63
|
|
|
73
64
|
## Development
|
|
74
65
|
|
|
@@ -13,14 +13,7 @@ export class ApiClient {
|
|
|
13
13
|
this.config = config;
|
|
14
14
|
this.auth = new FlexbeAuth(config);
|
|
15
15
|
}
|
|
16
|
-
replaceSiteId(url) {
|
|
17
|
-
if (!this.config.siteId) {
|
|
18
|
-
return url;
|
|
19
|
-
}
|
|
20
|
-
return url.replace(/:siteId:/g, this.config.siteId);
|
|
21
|
-
}
|
|
22
16
|
buildUrl(path, params) {
|
|
23
|
-
const processedPath = this.replaceSiteId(path);
|
|
24
17
|
const searchParams = new URLSearchParams();
|
|
25
18
|
if (params) {
|
|
26
19
|
Object.entries(params).forEach(([key, value]) => {
|
|
@@ -29,7 +22,7 @@ export class ApiClient {
|
|
|
29
22
|
}
|
|
30
23
|
});
|
|
31
24
|
}
|
|
32
|
-
return `${
|
|
25
|
+
return `${path}${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
|
33
26
|
}
|
|
34
27
|
request(config) {
|
|
35
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FlexbeAuthType } from '../types';
|
|
2
|
-
import { Pages } from './pages';
|
|
3
2
|
import { ApiClient } from './api-client';
|
|
3
|
+
import { SiteApi } from './site-api';
|
|
4
4
|
export class FlexbeClient {
|
|
5
5
|
constructor(config) {
|
|
6
|
+
this.siteApis = new Map();
|
|
6
7
|
const getEnvVar = (key) => {
|
|
7
8
|
if (typeof process !== 'undefined' && process.env) {
|
|
8
9
|
return process.env[key];
|
|
@@ -13,13 +14,24 @@ export class FlexbeClient {
|
|
|
13
14
|
baseUrl: (config === null || config === void 0 ? void 0 : config.baseUrl) || getEnvVar('FLEXBE_API_URL') || 'https://api.flexbe.com',
|
|
14
15
|
timeout: (config === null || config === void 0 ? void 0 : config.timeout) || 30000,
|
|
15
16
|
apiKey: (config === null || config === void 0 ? void 0 : config.apiKey) || getEnvVar('FLEXBE_API_KEY') || '',
|
|
16
|
-
siteId: (config === null || config === void 0 ? void 0 : config.siteId) || getEnvVar('FLEXBE_SITE_ID'),
|
|
17
17
|
authType: (config === null || config === void 0 ? void 0 : config.authType) || FlexbeAuthType.API_KEY,
|
|
18
18
|
};
|
|
19
19
|
if (this.config.authType === 'apiKey' && !this.config.apiKey) {
|
|
20
20
|
throw new Error('API key is required when using apiKey authentication. Please provide it either through config or FLEXBE_API_KEY environment variable.');
|
|
21
21
|
}
|
|
22
22
|
this.api = new ApiClient(this.config);
|
|
23
|
-
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get a SiteApi instance for a specific site
|
|
26
|
+
* @param siteId - The ID of the site to get an API instance for
|
|
27
|
+
* @returns A SiteApi instance for the specified site
|
|
28
|
+
*/
|
|
29
|
+
getSiteApi(siteId) {
|
|
30
|
+
let siteApi = this.siteApis.get(siteId);
|
|
31
|
+
if (!siteApi) {
|
|
32
|
+
siteApi = new SiteApi(this.api, siteId);
|
|
33
|
+
this.siteApis.set(siteId, siteApi);
|
|
34
|
+
}
|
|
35
|
+
return siteApi;
|
|
24
36
|
}
|
|
25
37
|
}
|
|
@@ -8,23 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
export class Pages {
|
|
11
|
-
constructor(api) {
|
|
11
|
+
constructor(api, siteId) {
|
|
12
12
|
this.api = api;
|
|
13
|
+
this.siteId = siteId;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Get list of pages for a site
|
|
16
17
|
* @param params - Query parameters including:
|
|
17
18
|
* - offset: Number of items to skip (default: 0)
|
|
18
19
|
* - limit: Maximum number of items to return (default: 100)
|
|
19
|
-
* - type: Filter by page type
|
|
20
|
-
* - status: Filter by page status
|
|
20
|
+
* - type: Filter by page type (could be an array of types)
|
|
21
|
+
* - status: Filter by page status (could be an array of statuses)
|
|
21
22
|
* - uri: Search by URI (exact match with '/' or partial match with '%word%')
|
|
22
|
-
* - title: Search by title
|
|
23
23
|
* - folderId: Filter by folder ID
|
|
24
24
|
*/
|
|
25
25
|
getPages(params) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const
|
|
27
|
+
const processedParams = params ? Object.assign(Object.assign({}, params), { type: Array.isArray(params.type) ? params.type.join(',') : params.type, status: Array.isArray(params.status) ? params.status.join(',') : params.status }) : undefined;
|
|
28
|
+
const response = yield this.api.get(`/sites/${this.siteId}/pages`, { params: processedParams });
|
|
28
29
|
return response.data;
|
|
29
30
|
});
|
|
30
31
|
}
|
|
@@ -33,7 +34,7 @@ export class Pages {
|
|
|
33
34
|
*/
|
|
34
35
|
getPage(pageId) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const response = yield this.api.get(`/sites
|
|
37
|
+
const response = yield this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
|
|
37
38
|
return response.data;
|
|
38
39
|
});
|
|
39
40
|
}
|
|
@@ -42,7 +43,7 @@ export class Pages {
|
|
|
42
43
|
*/
|
|
43
44
|
getFolders() {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const response = yield this.api.get(
|
|
46
|
+
const response = yield this.api.get(`/sites/${this.siteId}/pages-folders`);
|
|
46
47
|
return response.data;
|
|
47
48
|
});
|
|
48
49
|
}
|
|
@@ -51,7 +52,7 @@ export class Pages {
|
|
|
51
52
|
*/
|
|
52
53
|
getFolder(folderId) {
|
|
53
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const response = yield this.api.get(`/sites
|
|
55
|
+
const response = yield this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
|
|
55
56
|
return response.data;
|
|
56
57
|
});
|
|
57
58
|
}
|
|
@@ -64,7 +65,7 @@ export class Pages {
|
|
|
64
65
|
*/
|
|
65
66
|
updateFolder(folderId, data) {
|
|
66
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const response = yield this.api.patch(`/sites
|
|
68
|
+
const response = yield this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
|
|
68
69
|
return response.data;
|
|
69
70
|
});
|
|
70
71
|
}
|
|
@@ -76,7 +77,7 @@ export class Pages {
|
|
|
76
77
|
*/
|
|
77
78
|
createFolder(data) {
|
|
78
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const response = yield this.api.post(
|
|
80
|
+
const response = yield this.api.post(`/sites/${this.siteId}/pages-folders`, data);
|
|
80
81
|
return response.data;
|
|
81
82
|
});
|
|
82
83
|
}
|
|
@@ -87,7 +88,7 @@ export class Pages {
|
|
|
87
88
|
*/
|
|
88
89
|
deleteFolder(folderId) {
|
|
89
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
yield this.api.delete(`/sites
|
|
91
|
+
yield this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
@@ -112,7 +113,7 @@ export class Pages {
|
|
|
112
113
|
*/
|
|
113
114
|
updatePage(pageId, data) {
|
|
114
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
const response = yield this.api.put(`/sites
|
|
116
|
+
const response = yield this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
|
|
116
117
|
return response.data;
|
|
117
118
|
});
|
|
118
119
|
}
|
|
@@ -7,14 +7,7 @@ class ApiClient {
|
|
|
7
7
|
this.config = config;
|
|
8
8
|
this.auth = new auth_1.FlexbeAuth(config);
|
|
9
9
|
}
|
|
10
|
-
replaceSiteId(url) {
|
|
11
|
-
if (!this.config.siteId) {
|
|
12
|
-
return url;
|
|
13
|
-
}
|
|
14
|
-
return url.replace(/:siteId:/g, this.config.siteId);
|
|
15
|
-
}
|
|
16
10
|
buildUrl(path, params) {
|
|
17
|
-
const processedPath = this.replaceSiteId(path);
|
|
18
11
|
const searchParams = new URLSearchParams();
|
|
19
12
|
if (params) {
|
|
20
13
|
Object.entries(params).forEach(([key, value]) => {
|
|
@@ -23,7 +16,7 @@ class ApiClient {
|
|
|
23
16
|
}
|
|
24
17
|
});
|
|
25
18
|
}
|
|
26
|
-
return `${
|
|
19
|
+
return `${path}${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
|
27
20
|
}
|
|
28
21
|
async request(config) {
|
|
29
22
|
try {
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlexbeClient = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
const pages_1 = require("./pages");
|
|
6
5
|
const api_client_1 = require("./api-client");
|
|
6
|
+
const site_api_1 = require("./site-api");
|
|
7
7
|
class FlexbeClient {
|
|
8
8
|
constructor(config) {
|
|
9
|
+
this.siteApis = new Map();
|
|
9
10
|
const getEnvVar = (key) => {
|
|
10
11
|
if (typeof process !== 'undefined' && process.env) {
|
|
11
12
|
return process.env[key];
|
|
@@ -16,14 +17,25 @@ class FlexbeClient {
|
|
|
16
17
|
baseUrl: config?.baseUrl || getEnvVar('FLEXBE_API_URL') || 'https://api.flexbe.com',
|
|
17
18
|
timeout: config?.timeout || 30000,
|
|
18
19
|
apiKey: config?.apiKey || getEnvVar('FLEXBE_API_KEY') || '',
|
|
19
|
-
siteId: config?.siteId || getEnvVar('FLEXBE_SITE_ID'),
|
|
20
20
|
authType: config?.authType || types_1.FlexbeAuthType.API_KEY,
|
|
21
21
|
};
|
|
22
22
|
if (this.config.authType === 'apiKey' && !this.config.apiKey) {
|
|
23
23
|
throw new Error('API key is required when using apiKey authentication. Please provide it either through config or FLEXBE_API_KEY environment variable.');
|
|
24
24
|
}
|
|
25
25
|
this.api = new api_client_1.ApiClient(this.config);
|
|
26
|
-
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get a SiteApi instance for a specific site
|
|
29
|
+
* @param siteId - The ID of the site to get an API instance for
|
|
30
|
+
* @returns A SiteApi instance for the specified site
|
|
31
|
+
*/
|
|
32
|
+
getSiteApi(siteId) {
|
|
33
|
+
let siteApi = this.siteApis.get(siteId);
|
|
34
|
+
if (!siteApi) {
|
|
35
|
+
siteApi = new site_api_1.SiteApi(this.api, siteId);
|
|
36
|
+
this.siteApis.set(siteId, siteApi);
|
|
37
|
+
}
|
|
38
|
+
return siteApi;
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
exports.FlexbeClient = FlexbeClient;
|
package/dist/cjs/client/pages.js
CHANGED
|
@@ -2,43 +2,48 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Pages = void 0;
|
|
4
4
|
class Pages {
|
|
5
|
-
constructor(api) {
|
|
5
|
+
constructor(api, siteId) {
|
|
6
6
|
this.api = api;
|
|
7
|
+
this.siteId = siteId;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Get list of pages for a site
|
|
10
11
|
* @param params - Query parameters including:
|
|
11
12
|
* - offset: Number of items to skip (default: 0)
|
|
12
13
|
* - limit: Maximum number of items to return (default: 100)
|
|
13
|
-
* - type: Filter by page type
|
|
14
|
-
* - status: Filter by page status
|
|
14
|
+
* - type: Filter by page type (could be an array of types)
|
|
15
|
+
* - status: Filter by page status (could be an array of statuses)
|
|
15
16
|
* - uri: Search by URI (exact match with '/' or partial match with '%word%')
|
|
16
|
-
* - title: Search by title
|
|
17
17
|
* - folderId: Filter by folder ID
|
|
18
18
|
*/
|
|
19
19
|
async getPages(params) {
|
|
20
|
-
const
|
|
20
|
+
const processedParams = params ? {
|
|
21
|
+
...params,
|
|
22
|
+
type: Array.isArray(params.type) ? params.type.join(',') : params.type,
|
|
23
|
+
status: Array.isArray(params.status) ? params.status.join(',') : params.status
|
|
24
|
+
} : undefined;
|
|
25
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages`, { params: processedParams });
|
|
21
26
|
return response.data;
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Get a single page by ID
|
|
25
30
|
*/
|
|
26
31
|
async getPage(pageId) {
|
|
27
|
-
const response = await this.api.get(`/sites
|
|
32
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
|
|
28
33
|
return response.data;
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* Get list of folders for a site
|
|
32
37
|
*/
|
|
33
38
|
async getFolders() {
|
|
34
|
-
const response = await this.api.get(
|
|
39
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages-folders`);
|
|
35
40
|
return response.data;
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Get a single folder by ID
|
|
39
44
|
*/
|
|
40
45
|
async getFolder(folderId) {
|
|
41
|
-
const response = await this.api.get(`/sites
|
|
46
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
|
|
42
47
|
return response.data;
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
@@ -49,7 +54,7 @@ class Pages {
|
|
|
49
54
|
* - sortIndex: New position in the folder list
|
|
50
55
|
*/
|
|
51
56
|
async updateFolder(folderId, data) {
|
|
52
|
-
const response = await this.api.patch(`/sites
|
|
57
|
+
const response = await this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
|
|
53
58
|
return response.data;
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
@@ -59,7 +64,7 @@ class Pages {
|
|
|
59
64
|
* - sortIndex: Position in the folder list (optional)
|
|
60
65
|
*/
|
|
61
66
|
async createFolder(data) {
|
|
62
|
-
const response = await this.api.post(
|
|
67
|
+
const response = await this.api.post(`/sites/${this.siteId}/pages-folders`, data);
|
|
63
68
|
return response.data;
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
@@ -68,7 +73,7 @@ class Pages {
|
|
|
68
73
|
* @throws {ForbiddenException} When the folder does not belong to the site
|
|
69
74
|
*/
|
|
70
75
|
async deleteFolder(folderId) {
|
|
71
|
-
await this.api.delete(`/sites
|
|
76
|
+
await this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
|
|
72
77
|
}
|
|
73
78
|
/**
|
|
74
79
|
* Update a page's properties
|
|
@@ -91,7 +96,7 @@ class Pages {
|
|
|
91
96
|
* - grid: Grid configuration for the page
|
|
92
97
|
*/
|
|
93
98
|
async updatePage(pageId, data) {
|
|
94
|
-
const response = await this.api.put(`/sites
|
|
99
|
+
const response = await this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
|
|
95
100
|
return response.data;
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SiteApi = void 0;
|
|
4
|
+
const pages_1 = require("./pages");
|
|
5
|
+
class SiteApi {
|
|
6
|
+
constructor(api, siteId) {
|
|
7
|
+
this.pages = new pages_1.Pages(api, siteId);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SiteApi = SiteApi;
|
|
@@ -4,14 +4,7 @@ export class ApiClient {
|
|
|
4
4
|
this.config = config;
|
|
5
5
|
this.auth = new FlexbeAuth(config);
|
|
6
6
|
}
|
|
7
|
-
replaceSiteId(url) {
|
|
8
|
-
if (!this.config.siteId) {
|
|
9
|
-
return url;
|
|
10
|
-
}
|
|
11
|
-
return url.replace(/:siteId:/g, this.config.siteId);
|
|
12
|
-
}
|
|
13
7
|
buildUrl(path, params) {
|
|
14
|
-
const processedPath = this.replaceSiteId(path);
|
|
15
8
|
const searchParams = new URLSearchParams();
|
|
16
9
|
if (params) {
|
|
17
10
|
Object.entries(params).forEach(([key, value]) => {
|
|
@@ -20,7 +13,7 @@ export class ApiClient {
|
|
|
20
13
|
}
|
|
21
14
|
});
|
|
22
15
|
}
|
|
23
|
-
return `${
|
|
16
|
+
return `${path}${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
|
24
17
|
}
|
|
25
18
|
async request(config) {
|
|
26
19
|
try {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FlexbeAuthType } from '../types';
|
|
2
|
-
import { Pages } from './pages';
|
|
3
2
|
import { ApiClient } from './api-client';
|
|
3
|
+
import { SiteApi } from './site-api';
|
|
4
4
|
export class FlexbeClient {
|
|
5
5
|
constructor(config) {
|
|
6
|
+
this.siteApis = new Map();
|
|
6
7
|
const getEnvVar = (key) => {
|
|
7
8
|
if (typeof process !== 'undefined' && process.env) {
|
|
8
9
|
return process.env[key];
|
|
@@ -13,13 +14,24 @@ export class FlexbeClient {
|
|
|
13
14
|
baseUrl: config?.baseUrl || getEnvVar('FLEXBE_API_URL') || 'https://api.flexbe.com',
|
|
14
15
|
timeout: config?.timeout || 30000,
|
|
15
16
|
apiKey: config?.apiKey || getEnvVar('FLEXBE_API_KEY') || '',
|
|
16
|
-
siteId: config?.siteId || getEnvVar('FLEXBE_SITE_ID'),
|
|
17
17
|
authType: config?.authType || FlexbeAuthType.API_KEY,
|
|
18
18
|
};
|
|
19
19
|
if (this.config.authType === 'apiKey' && !this.config.apiKey) {
|
|
20
20
|
throw new Error('API key is required when using apiKey authentication. Please provide it either through config or FLEXBE_API_KEY environment variable.');
|
|
21
21
|
}
|
|
22
22
|
this.api = new ApiClient(this.config);
|
|
23
|
-
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get a SiteApi instance for a specific site
|
|
26
|
+
* @param siteId - The ID of the site to get an API instance for
|
|
27
|
+
* @returns A SiteApi instance for the specified site
|
|
28
|
+
*/
|
|
29
|
+
getSiteApi(siteId) {
|
|
30
|
+
let siteApi = this.siteApis.get(siteId);
|
|
31
|
+
if (!siteApi) {
|
|
32
|
+
siteApi = new SiteApi(this.api, siteId);
|
|
33
|
+
this.siteApis.set(siteId, siteApi);
|
|
34
|
+
}
|
|
35
|
+
return siteApi;
|
|
24
36
|
}
|
|
25
37
|
}
|
package/dist/esm/client/pages.js
CHANGED
|
@@ -1,41 +1,46 @@
|
|
|
1
1
|
export class Pages {
|
|
2
|
-
constructor(api) {
|
|
2
|
+
constructor(api, siteId) {
|
|
3
3
|
this.api = api;
|
|
4
|
+
this.siteId = siteId;
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* Get list of pages for a site
|
|
7
8
|
* @param params - Query parameters including:
|
|
8
9
|
* - offset: Number of items to skip (default: 0)
|
|
9
10
|
* - limit: Maximum number of items to return (default: 100)
|
|
10
|
-
* - type: Filter by page type
|
|
11
|
-
* - status: Filter by page status
|
|
11
|
+
* - type: Filter by page type (could be an array of types)
|
|
12
|
+
* - status: Filter by page status (could be an array of statuses)
|
|
12
13
|
* - uri: Search by URI (exact match with '/' or partial match with '%word%')
|
|
13
|
-
* - title: Search by title
|
|
14
14
|
* - folderId: Filter by folder ID
|
|
15
15
|
*/
|
|
16
16
|
async getPages(params) {
|
|
17
|
-
const
|
|
17
|
+
const processedParams = params ? {
|
|
18
|
+
...params,
|
|
19
|
+
type: Array.isArray(params.type) ? params.type.join(',') : params.type,
|
|
20
|
+
status: Array.isArray(params.status) ? params.status.join(',') : params.status
|
|
21
|
+
} : undefined;
|
|
22
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages`, { params: processedParams });
|
|
18
23
|
return response.data;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Get a single page by ID
|
|
22
27
|
*/
|
|
23
28
|
async getPage(pageId) {
|
|
24
|
-
const response = await this.api.get(`/sites
|
|
29
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
|
|
25
30
|
return response.data;
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* Get list of folders for a site
|
|
29
34
|
*/
|
|
30
35
|
async getFolders() {
|
|
31
|
-
const response = await this.api.get(
|
|
36
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages-folders`);
|
|
32
37
|
return response.data;
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* Get a single folder by ID
|
|
36
41
|
*/
|
|
37
42
|
async getFolder(folderId) {
|
|
38
|
-
const response = await this.api.get(`/sites
|
|
43
|
+
const response = await this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
|
|
39
44
|
return response.data;
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
@@ -46,7 +51,7 @@ export class Pages {
|
|
|
46
51
|
* - sortIndex: New position in the folder list
|
|
47
52
|
*/
|
|
48
53
|
async updateFolder(folderId, data) {
|
|
49
|
-
const response = await this.api.patch(`/sites
|
|
54
|
+
const response = await this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
|
|
50
55
|
return response.data;
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
@@ -56,7 +61,7 @@ export class Pages {
|
|
|
56
61
|
* - sortIndex: Position in the folder list (optional)
|
|
57
62
|
*/
|
|
58
63
|
async createFolder(data) {
|
|
59
|
-
const response = await this.api.post(
|
|
64
|
+
const response = await this.api.post(`/sites/${this.siteId}/pages-folders`, data);
|
|
60
65
|
return response.data;
|
|
61
66
|
}
|
|
62
67
|
/**
|
|
@@ -65,7 +70,7 @@ export class Pages {
|
|
|
65
70
|
* @throws {ForbiddenException} When the folder does not belong to the site
|
|
66
71
|
*/
|
|
67
72
|
async deleteFolder(folderId) {
|
|
68
|
-
await this.api.delete(`/sites
|
|
73
|
+
await this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
|
|
69
74
|
}
|
|
70
75
|
/**
|
|
71
76
|
* Update a page's properties
|
|
@@ -88,7 +93,7 @@ export class Pages {
|
|
|
88
93
|
* - grid: Grid configuration for the page
|
|
89
94
|
*/
|
|
90
95
|
async updatePage(pageId, data) {
|
|
91
|
-
const response = await this.api.put(`/sites
|
|
96
|
+
const response = await this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
|
|
92
97
|
return response.data;
|
|
93
98
|
}
|
|
94
99
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { FlexbeConfig } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
import { ApiClient } from './api-client';
|
|
2
|
+
import { SiteApi } from './site-api';
|
|
4
3
|
export declare class FlexbeClient {
|
|
5
4
|
private readonly config;
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
5
|
+
private readonly api;
|
|
6
|
+
private readonly siteApis;
|
|
8
7
|
constructor(config?: Partial<FlexbeConfig>);
|
|
8
|
+
/**
|
|
9
|
+
* Get a SiteApi instance for a specific site
|
|
10
|
+
* @param siteId - The ID of the site to get an API instance for
|
|
11
|
+
* @returns A SiteApi instance for the specified site
|
|
12
|
+
*/
|
|
13
|
+
getSiteApi(siteId: number): SiteApi;
|
|
9
14
|
}
|
|
@@ -2,16 +2,16 @@ import { Page, GetPagesParams, PageListResponse, PageFolder, PageFolderListRespo
|
|
|
2
2
|
import { ApiClient } from './api-client';
|
|
3
3
|
export declare class Pages {
|
|
4
4
|
private readonly api;
|
|
5
|
-
|
|
5
|
+
private readonly siteId;
|
|
6
|
+
constructor(api: ApiClient, siteId: number);
|
|
6
7
|
/**
|
|
7
8
|
* Get list of pages for a site
|
|
8
9
|
* @param params - Query parameters including:
|
|
9
10
|
* - offset: Number of items to skip (default: 0)
|
|
10
11
|
* - limit: Maximum number of items to return (default: 100)
|
|
11
|
-
* - type: Filter by page type
|
|
12
|
-
* - status: Filter by page status
|
|
12
|
+
* - type: Filter by page type (could be an array of types)
|
|
13
|
+
* - status: Filter by page status (could be an array of statuses)
|
|
13
14
|
* - uri: Search by URI (exact match with '/' or partial match with '%word%')
|
|
14
|
-
* - title: Search by title
|
|
15
15
|
* - folderId: Filter by folder ID
|
|
16
16
|
*/
|
|
17
17
|
getPages(params?: GetPagesParams): Promise<PageListResponse>;
|
|
@@ -55,15 +55,13 @@ export interface Page {
|
|
|
55
55
|
deletedAt: Date | null;
|
|
56
56
|
screenshot: Screenshot | null;
|
|
57
57
|
meta: PageMeta | null;
|
|
58
|
-
grid?: GridConfig;
|
|
59
58
|
}
|
|
60
59
|
export interface GetPagesParams {
|
|
61
60
|
offset?: number;
|
|
62
61
|
limit?: number;
|
|
63
|
-
type?: PageType;
|
|
64
|
-
status?: PageStatus;
|
|
62
|
+
type?: PageType | PageType[];
|
|
63
|
+
status?: PageStatus | PageStatus[];
|
|
65
64
|
uri?: string;
|
|
66
|
-
title?: string;
|
|
67
65
|
folderId?: number;
|
|
68
66
|
}
|
|
69
67
|
export interface PageListResponse {
|
|
@@ -102,19 +100,4 @@ export interface UpdatePageParams {
|
|
|
102
100
|
ogDescription?: string;
|
|
103
101
|
noindex?: boolean;
|
|
104
102
|
};
|
|
105
|
-
grid?: {
|
|
106
|
-
color?: string;
|
|
107
|
-
desktop?: {
|
|
108
|
-
columns: number;
|
|
109
|
-
containerWidth: number;
|
|
110
|
-
columnWidth: number;
|
|
111
|
-
gap: number;
|
|
112
|
-
};
|
|
113
|
-
mobile?: {
|
|
114
|
-
columns: number;
|
|
115
|
-
containerWidth: number;
|
|
116
|
-
columnWidth: number;
|
|
117
|
-
gap: number;
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
103
|
}
|