@flexbe/sdk 0.2.3 → 0.2.5

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.
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { NotFoundException, ForbiddenException, BadRequestException, UnauthorizedException, ServerException, TimeoutException } from '../types';
10
11
  import { FlexbeAuth } from './auth';
11
12
  export class ApiClient {
12
13
  constructor(config) {
@@ -35,15 +36,33 @@ export class ApiClient {
35
36
  const response = yield fetch(this.config.baseUrl + url, Object.assign(Object.assign({}, config), { headers, signal: controller.signal }));
36
37
  clearTimeout(timeoutId);
37
38
  if (!response.ok) {
38
- const defaultError = { message: response.statusText };
39
- const errorData = yield response.json().catch(() => defaultError);
40
- const error = {
41
- message: errorData.message || response.statusText,
42
- code: errorData.code,
43
- status: response.status,
44
- details: errorData.details,
39
+ const defaultError = {
40
+ message: response.statusText,
41
+ error: response.statusText,
42
+ statusCode: response.status
45
43
  };
46
- throw error;
44
+ const errorData = yield response.json().catch(() => defaultError);
45
+ switch (errorData.statusCode) {
46
+ case 400:
47
+ throw new BadRequestException(errorData.message);
48
+ case 401:
49
+ throw new UnauthorizedException(errorData.message);
50
+ case 403:
51
+ throw new ForbiddenException(errorData.message);
52
+ case 404:
53
+ throw new NotFoundException(errorData.message);
54
+ case 500:
55
+ case 502:
56
+ case 503:
57
+ case 504:
58
+ throw new ServerException(errorData.message, errorData.statusCode);
59
+ default:
60
+ throw {
61
+ message: errorData.message,
62
+ error: errorData.error,
63
+ statusCode: errorData.statusCode
64
+ };
65
+ }
47
66
  }
48
67
  const data = yield response.json();
49
68
  return {
@@ -54,11 +73,7 @@ export class ApiClient {
54
73
  }
55
74
  catch (error) {
56
75
  if (error instanceof Error && error.name === 'AbortError') {
57
- const timeoutError = {
58
- message: 'Request timeout',
59
- status: 408,
60
- };
61
- throw timeoutError;
76
+ throw new TimeoutException('Request timeout');
62
77
  }
63
78
  throw error;
64
79
  }
@@ -17,20 +17,30 @@ export class Pages {
17
17
  * @param params - Query parameters including:
18
18
  * - offset: Number of items to skip (default: 0)
19
19
  * - limit: Maximum number of items to return (default: 100)
20
- * - type: Filter by page type
21
- * - 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)
22
22
  * - uri: Search by URI (exact match with '/' or partial match with '%word%')
23
- * - title: Search by title
24
23
  * - folderId: Filter by folder ID
24
+ * @throws {UnauthorizedException} When the API key is invalid or expired
25
+ * @throws {ForbiddenException} When the site is not accessible
26
+ * @throws {BadRequestException} When the query parameters are invalid
27
+ * @throws {ServerException} When the server encounters an error
28
+ * @throws {TimeoutException} When the request times out
25
29
  */
26
30
  getPages(params) {
27
31
  return __awaiter(this, void 0, void 0, function* () {
28
- const response = yield this.api.get(`/sites/${this.siteId}/pages`, { params });
32
+ 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;
33
+ const response = yield this.api.get(`/sites/${this.siteId}/pages`, { params: processedParams });
29
34
  return response.data;
30
35
  });
31
36
  }
32
37
  /**
33
38
  * Get a single page by ID
39
+ * @throws {UnauthorizedException} When the API key is invalid or expired
40
+ * @throws {NotFoundException} When the page is not found
41
+ * @throws {ForbiddenException} When the page does not belong to the site
42
+ * @throws {ServerException} When the server encounters an error
43
+ * @throws {TimeoutException} When the request times out
34
44
  */
35
45
  getPage(pageId) {
36
46
  return __awaiter(this, void 0, void 0, function* () {
@@ -40,6 +50,10 @@ export class Pages {
40
50
  }
41
51
  /**
42
52
  * Get list of folders for a site
53
+ * @throws {UnauthorizedException} When the API key is invalid or expired
54
+ * @throws {ForbiddenException} When the site is not accessible
55
+ * @throws {ServerException} When the server encounters an error
56
+ * @throws {TimeoutException} When the request times out
43
57
  */
44
58
  getFolders() {
45
59
  return __awaiter(this, void 0, void 0, function* () {
@@ -49,6 +63,11 @@ export class Pages {
49
63
  }
50
64
  /**
51
65
  * Get a single folder by ID
66
+ * @throws {UnauthorizedException} When the API key is invalid or expired
67
+ * @throws {NotFoundException} When the folder is not found
68
+ * @throws {ForbiddenException} When the folder does not belong to the site
69
+ * @throws {ServerException} When the server encounters an error
70
+ * @throws {TimeoutException} When the request times out
52
71
  */
53
72
  getFolder(folderId) {
54
73
  return __awaiter(this, void 0, void 0, function* () {
@@ -62,6 +81,12 @@ export class Pages {
62
81
  * @param data - Update parameters:
63
82
  * - title: New title for the folder
64
83
  * - sortIndex: New position in the folder list
84
+ * @throws {UnauthorizedException} When the API key is invalid or expired
85
+ * @throws {NotFoundException} When the folder is not found
86
+ * @throws {ForbiddenException} When the folder does not belong to the site
87
+ * @throws {BadRequestException} When the update parameters are invalid
88
+ * @throws {ServerException} When the server encounters an error
89
+ * @throws {TimeoutException} When the request times out
65
90
  */
66
91
  updateFolder(folderId, data) {
67
92
  return __awaiter(this, void 0, void 0, function* () {
@@ -74,6 +99,11 @@ export class Pages {
74
99
  * @param data - Create parameters:
75
100
  * - title: Title of the new folder (required)
76
101
  * - sortIndex: Position in the folder list (optional)
102
+ * @throws {UnauthorizedException} When the API key is invalid or expired
103
+ * @throws {ForbiddenException} When the site is not accessible
104
+ * @throws {BadRequestException} When the create parameters are invalid
105
+ * @throws {ServerException} When the server encounters an error
106
+ * @throws {TimeoutException} When the request times out
77
107
  */
78
108
  createFolder(data) {
79
109
  return __awaiter(this, void 0, void 0, function* () {
@@ -83,14 +113,31 @@ export class Pages {
83
113
  }
84
114
  /**
85
115
  * Delete a folder and its items
116
+ * @throws {UnauthorizedException} When the API key is invalid or expired
86
117
  * @throws {NotFoundException} When the folder is not found
87
118
  * @throws {ForbiddenException} When the folder does not belong to the site
119
+ * @throws {ServerException} When the server encounters an error
120
+ * @throws {TimeoutException} When the request times out
88
121
  */
89
122
  deleteFolder(folderId) {
90
123
  return __awaiter(this, void 0, void 0, function* () {
91
124
  yield this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
92
125
  });
93
126
  }
127
+ /**
128
+ * Delete a page
129
+ * @param pageId - ID of the page to delete
130
+ * @throws {UnauthorizedException} When the API key is invalid or expired
131
+ * @throws {NotFoundException} When the page is not found
132
+ * @throws {ForbiddenException} When the page does not belong to the site
133
+ * @throws {ServerException} When the server encounters an error
134
+ * @throws {TimeoutException} When the request times out
135
+ */
136
+ deletePage(pageId) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ yield this.api.delete(`/sites/${this.siteId}/pages/${pageId}`);
139
+ });
140
+ }
94
141
  /**
95
142
  * Update a page's properties
96
143
  * @param pageId - ID of the page to update
@@ -110,6 +157,12 @@ export class Pages {
110
157
  * - ogDescription: Open Graph description for social sharing
111
158
  * - noindex: Whether to prevent search engine indexing
112
159
  * - grid: Grid configuration for the page
160
+ * @throws {UnauthorizedException} When the API key is invalid or expired
161
+ * @throws {NotFoundException} When the page is not found
162
+ * @throws {ForbiddenException} When the page does not belong to the site
163
+ * @throws {BadRequestException} When the update parameters are invalid
164
+ * @throws {ServerException} When the server encounters an error
165
+ * @throws {TimeoutException} When the request times out
113
166
  */
114
167
  updatePage(pageId, data) {
115
168
  return __awaiter(this, void 0, void 0, function* () {
@@ -3,3 +3,45 @@ export var FlexbeAuthType;
3
3
  FlexbeAuthType["API_KEY"] = "apiKey";
4
4
  FlexbeAuthType["BEARER"] = "bearer";
5
5
  })(FlexbeAuthType || (FlexbeAuthType = {}));
6
+ export class NotFoundException extends Error {
7
+ constructor(message) {
8
+ super(Array.isArray(message) ? message.join(', ') : message);
9
+ this.statusCode = 404;
10
+ this.name = 'NotFoundException';
11
+ }
12
+ }
13
+ export class ForbiddenException extends Error {
14
+ constructor(message) {
15
+ super(Array.isArray(message) ? message.join(', ') : message);
16
+ this.statusCode = 403;
17
+ this.name = 'ForbiddenException';
18
+ }
19
+ }
20
+ export class BadRequestException extends Error {
21
+ constructor(message) {
22
+ super(Array.isArray(message) ? message.join(', ') : message);
23
+ this.statusCode = 400;
24
+ this.name = 'BadRequestException';
25
+ }
26
+ }
27
+ export class UnauthorizedException extends Error {
28
+ constructor(message) {
29
+ super(Array.isArray(message) ? message.join(', ') : message);
30
+ this.statusCode = 401;
31
+ this.name = 'UnauthorizedException';
32
+ }
33
+ }
34
+ export class ServerException extends Error {
35
+ constructor(message, statusCode = 500) {
36
+ super(Array.isArray(message) ? message.join(', ') : message);
37
+ this.name = 'ServerException';
38
+ this.statusCode = statusCode;
39
+ }
40
+ }
41
+ export class TimeoutException extends Error {
42
+ constructor(message) {
43
+ super(Array.isArray(message) ? message.join(', ') : message);
44
+ this.statusCode = 408;
45
+ this.name = 'TimeoutException';
46
+ }
47
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiClient = void 0;
4
+ const types_1 = require("../types");
4
5
  const auth_1 = require("./auth");
5
6
  class ApiClient {
6
7
  constructor(config) {
@@ -35,15 +36,33 @@ class ApiClient {
35
36
  });
36
37
  clearTimeout(timeoutId);
37
38
  if (!response.ok) {
38
- const defaultError = { message: response.statusText };
39
- const errorData = await response.json().catch(() => defaultError);
40
- const error = {
41
- message: errorData.message || response.statusText,
42
- code: errorData.code,
43
- status: response.status,
44
- details: errorData.details,
39
+ const defaultError = {
40
+ message: response.statusText,
41
+ error: response.statusText,
42
+ statusCode: response.status
45
43
  };
46
- throw error;
44
+ const errorData = await response.json().catch(() => defaultError);
45
+ switch (errorData.statusCode) {
46
+ case 400:
47
+ throw new types_1.BadRequestException(errorData.message);
48
+ case 401:
49
+ throw new types_1.UnauthorizedException(errorData.message);
50
+ case 403:
51
+ throw new types_1.ForbiddenException(errorData.message);
52
+ case 404:
53
+ throw new types_1.NotFoundException(errorData.message);
54
+ case 500:
55
+ case 502:
56
+ case 503:
57
+ case 504:
58
+ throw new types_1.ServerException(errorData.message, errorData.statusCode);
59
+ default:
60
+ throw {
61
+ message: errorData.message,
62
+ error: errorData.error,
63
+ statusCode: errorData.statusCode
64
+ };
65
+ }
47
66
  }
48
67
  const data = await response.json();
49
68
  return {
@@ -54,11 +73,7 @@ class ApiClient {
54
73
  }
55
74
  catch (error) {
56
75
  if (error instanceof Error && error.name === 'AbortError') {
57
- const timeoutError = {
58
- message: 'Request timeout',
59
- status: 408,
60
- };
61
- throw timeoutError;
76
+ throw new types_1.TimeoutException('Request timeout');
62
77
  }
63
78
  throw error;
64
79
  }
@@ -11,18 +11,32 @@ class Pages {
11
11
  * @param params - Query parameters including:
12
12
  * - offset: Number of items to skip (default: 0)
13
13
  * - limit: Maximum number of items to return (default: 100)
14
- * - type: Filter by page type
15
- * - 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)
16
16
  * - uri: Search by URI (exact match with '/' or partial match with '%word%')
17
- * - title: Search by title
18
17
  * - folderId: Filter by folder ID
18
+ * @throws {UnauthorizedException} When the API key is invalid or expired
19
+ * @throws {ForbiddenException} When the site is not accessible
20
+ * @throws {BadRequestException} When the query parameters are invalid
21
+ * @throws {ServerException} When the server encounters an error
22
+ * @throws {TimeoutException} When the request times out
19
23
  */
20
24
  async getPages(params) {
21
- const response = await this.api.get(`/sites/${this.siteId}/pages`, { params });
25
+ const processedParams = params ? {
26
+ ...params,
27
+ type: Array.isArray(params.type) ? params.type.join(',') : params.type,
28
+ status: Array.isArray(params.status) ? params.status.join(',') : params.status
29
+ } : undefined;
30
+ const response = await this.api.get(`/sites/${this.siteId}/pages`, { params: processedParams });
22
31
  return response.data;
23
32
  }
24
33
  /**
25
34
  * Get a single page by ID
35
+ * @throws {UnauthorizedException} When the API key is invalid or expired
36
+ * @throws {NotFoundException} When the page is not found
37
+ * @throws {ForbiddenException} When the page does not belong to the site
38
+ * @throws {ServerException} When the server encounters an error
39
+ * @throws {TimeoutException} When the request times out
26
40
  */
27
41
  async getPage(pageId) {
28
42
  const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
@@ -30,6 +44,10 @@ class Pages {
30
44
  }
31
45
  /**
32
46
  * Get list of folders for a site
47
+ * @throws {UnauthorizedException} When the API key is invalid or expired
48
+ * @throws {ForbiddenException} When the site is not accessible
49
+ * @throws {ServerException} When the server encounters an error
50
+ * @throws {TimeoutException} When the request times out
33
51
  */
34
52
  async getFolders() {
35
53
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders`);
@@ -37,6 +55,11 @@ class Pages {
37
55
  }
38
56
  /**
39
57
  * Get a single folder by ID
58
+ * @throws {UnauthorizedException} When the API key is invalid or expired
59
+ * @throws {NotFoundException} When the folder is not found
60
+ * @throws {ForbiddenException} When the folder does not belong to the site
61
+ * @throws {ServerException} When the server encounters an error
62
+ * @throws {TimeoutException} When the request times out
40
63
  */
41
64
  async getFolder(folderId) {
42
65
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
@@ -48,6 +71,12 @@ class Pages {
48
71
  * @param data - Update parameters:
49
72
  * - title: New title for the folder
50
73
  * - sortIndex: New position in the folder list
74
+ * @throws {UnauthorizedException} When the API key is invalid or expired
75
+ * @throws {NotFoundException} When the folder is not found
76
+ * @throws {ForbiddenException} When the folder does not belong to the site
77
+ * @throws {BadRequestException} When the update parameters are invalid
78
+ * @throws {ServerException} When the server encounters an error
79
+ * @throws {TimeoutException} When the request times out
51
80
  */
52
81
  async updateFolder(folderId, data) {
53
82
  const response = await this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
@@ -58,6 +87,11 @@ class Pages {
58
87
  * @param data - Create parameters:
59
88
  * - title: Title of the new folder (required)
60
89
  * - sortIndex: Position in the folder list (optional)
90
+ * @throws {UnauthorizedException} When the API key is invalid or expired
91
+ * @throws {ForbiddenException} When the site is not accessible
92
+ * @throws {BadRequestException} When the create parameters are invalid
93
+ * @throws {ServerException} When the server encounters an error
94
+ * @throws {TimeoutException} When the request times out
61
95
  */
62
96
  async createFolder(data) {
63
97
  const response = await this.api.post(`/sites/${this.siteId}/pages-folders`, data);
@@ -65,12 +99,27 @@ class Pages {
65
99
  }
66
100
  /**
67
101
  * Delete a folder and its items
102
+ * @throws {UnauthorizedException} When the API key is invalid or expired
68
103
  * @throws {NotFoundException} When the folder is not found
69
104
  * @throws {ForbiddenException} When the folder does not belong to the site
105
+ * @throws {ServerException} When the server encounters an error
106
+ * @throws {TimeoutException} When the request times out
70
107
  */
71
108
  async deleteFolder(folderId) {
72
109
  await this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
73
110
  }
111
+ /**
112
+ * Delete a page
113
+ * @param pageId - ID of the page to delete
114
+ * @throws {UnauthorizedException} When the API key is invalid or expired
115
+ * @throws {NotFoundException} When the page is not found
116
+ * @throws {ForbiddenException} When the page does not belong to the site
117
+ * @throws {ServerException} When the server encounters an error
118
+ * @throws {TimeoutException} When the request times out
119
+ */
120
+ async deletePage(pageId) {
121
+ await this.api.delete(`/sites/${this.siteId}/pages/${pageId}`);
122
+ }
74
123
  /**
75
124
  * Update a page's properties
76
125
  * @param pageId - ID of the page to update
@@ -90,6 +139,12 @@ class Pages {
90
139
  * - ogDescription: Open Graph description for social sharing
91
140
  * - noindex: Whether to prevent search engine indexing
92
141
  * - grid: Grid configuration for the page
142
+ * @throws {UnauthorizedException} When the API key is invalid or expired
143
+ * @throws {NotFoundException} When the page is not found
144
+ * @throws {ForbiddenException} When the page does not belong to the site
145
+ * @throws {BadRequestException} When the update parameters are invalid
146
+ * @throws {ServerException} When the server encounters an error
147
+ * @throws {TimeoutException} When the request times out
93
148
  */
94
149
  async updatePage(pageId, data) {
95
150
  const response = await this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
@@ -1,8 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlexbeAuthType = void 0;
3
+ exports.TimeoutException = exports.ServerException = exports.UnauthorizedException = exports.BadRequestException = exports.ForbiddenException = exports.NotFoundException = exports.FlexbeAuthType = void 0;
4
4
  var FlexbeAuthType;
5
5
  (function (FlexbeAuthType) {
6
6
  FlexbeAuthType["API_KEY"] = "apiKey";
7
7
  FlexbeAuthType["BEARER"] = "bearer";
8
8
  })(FlexbeAuthType || (exports.FlexbeAuthType = FlexbeAuthType = {}));
9
+ class NotFoundException extends Error {
10
+ constructor(message) {
11
+ super(Array.isArray(message) ? message.join(', ') : message);
12
+ this.statusCode = 404;
13
+ this.name = 'NotFoundException';
14
+ }
15
+ }
16
+ exports.NotFoundException = NotFoundException;
17
+ class ForbiddenException extends Error {
18
+ constructor(message) {
19
+ super(Array.isArray(message) ? message.join(', ') : message);
20
+ this.statusCode = 403;
21
+ this.name = 'ForbiddenException';
22
+ }
23
+ }
24
+ exports.ForbiddenException = ForbiddenException;
25
+ class BadRequestException extends Error {
26
+ constructor(message) {
27
+ super(Array.isArray(message) ? message.join(', ') : message);
28
+ this.statusCode = 400;
29
+ this.name = 'BadRequestException';
30
+ }
31
+ }
32
+ exports.BadRequestException = BadRequestException;
33
+ class UnauthorizedException extends Error {
34
+ constructor(message) {
35
+ super(Array.isArray(message) ? message.join(', ') : message);
36
+ this.statusCode = 401;
37
+ this.name = 'UnauthorizedException';
38
+ }
39
+ }
40
+ exports.UnauthorizedException = UnauthorizedException;
41
+ class ServerException extends Error {
42
+ constructor(message, statusCode = 500) {
43
+ super(Array.isArray(message) ? message.join(', ') : message);
44
+ this.name = 'ServerException';
45
+ this.statusCode = statusCode;
46
+ }
47
+ }
48
+ exports.ServerException = ServerException;
49
+ class TimeoutException extends Error {
50
+ constructor(message) {
51
+ super(Array.isArray(message) ? message.join(', ') : message);
52
+ this.statusCode = 408;
53
+ this.name = 'TimeoutException';
54
+ }
55
+ }
56
+ exports.TimeoutException = TimeoutException;
@@ -1,3 +1,4 @@
1
+ import { NotFoundException, ForbiddenException, BadRequestException, UnauthorizedException, ServerException, TimeoutException } from '../types';
1
2
  import { FlexbeAuth } from './auth';
2
3
  export class ApiClient {
3
4
  constructor(config) {
@@ -32,15 +33,33 @@ export class ApiClient {
32
33
  });
33
34
  clearTimeout(timeoutId);
34
35
  if (!response.ok) {
35
- const defaultError = { message: response.statusText };
36
- const errorData = await response.json().catch(() => defaultError);
37
- const error = {
38
- message: errorData.message || response.statusText,
39
- code: errorData.code,
40
- status: response.status,
41
- details: errorData.details,
36
+ const defaultError = {
37
+ message: response.statusText,
38
+ error: response.statusText,
39
+ statusCode: response.status
42
40
  };
43
- throw error;
41
+ const errorData = await response.json().catch(() => defaultError);
42
+ switch (errorData.statusCode) {
43
+ case 400:
44
+ throw new BadRequestException(errorData.message);
45
+ case 401:
46
+ throw new UnauthorizedException(errorData.message);
47
+ case 403:
48
+ throw new ForbiddenException(errorData.message);
49
+ case 404:
50
+ throw new NotFoundException(errorData.message);
51
+ case 500:
52
+ case 502:
53
+ case 503:
54
+ case 504:
55
+ throw new ServerException(errorData.message, errorData.statusCode);
56
+ default:
57
+ throw {
58
+ message: errorData.message,
59
+ error: errorData.error,
60
+ statusCode: errorData.statusCode
61
+ };
62
+ }
44
63
  }
45
64
  const data = await response.json();
46
65
  return {
@@ -51,11 +70,7 @@ export class ApiClient {
51
70
  }
52
71
  catch (error) {
53
72
  if (error instanceof Error && error.name === 'AbortError') {
54
- const timeoutError = {
55
- message: 'Request timeout',
56
- status: 408,
57
- };
58
- throw timeoutError;
73
+ throw new TimeoutException('Request timeout');
59
74
  }
60
75
  throw error;
61
76
  }
@@ -8,18 +8,32 @@ export class Pages {
8
8
  * @param params - Query parameters including:
9
9
  * - offset: Number of items to skip (default: 0)
10
10
  * - limit: Maximum number of items to return (default: 100)
11
- * - type: Filter by page type
12
- * - 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)
13
13
  * - uri: Search by URI (exact match with '/' or partial match with '%word%')
14
- * - title: Search by title
15
14
  * - folderId: Filter by folder ID
15
+ * @throws {UnauthorizedException} When the API key is invalid or expired
16
+ * @throws {ForbiddenException} When the site is not accessible
17
+ * @throws {BadRequestException} When the query parameters are invalid
18
+ * @throws {ServerException} When the server encounters an error
19
+ * @throws {TimeoutException} When the request times out
16
20
  */
17
21
  async getPages(params) {
18
- const response = await this.api.get(`/sites/${this.siteId}/pages`, { params });
22
+ const processedParams = params ? {
23
+ ...params,
24
+ type: Array.isArray(params.type) ? params.type.join(',') : params.type,
25
+ status: Array.isArray(params.status) ? params.status.join(',') : params.status
26
+ } : undefined;
27
+ const response = await this.api.get(`/sites/${this.siteId}/pages`, { params: processedParams });
19
28
  return response.data;
20
29
  }
21
30
  /**
22
31
  * Get a single page by ID
32
+ * @throws {UnauthorizedException} When the API key is invalid or expired
33
+ * @throws {NotFoundException} When the page is not found
34
+ * @throws {ForbiddenException} When the page does not belong to the site
35
+ * @throws {ServerException} When the server encounters an error
36
+ * @throws {TimeoutException} When the request times out
23
37
  */
24
38
  async getPage(pageId) {
25
39
  const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
@@ -27,6 +41,10 @@ export class Pages {
27
41
  }
28
42
  /**
29
43
  * Get list of folders for a site
44
+ * @throws {UnauthorizedException} When the API key is invalid or expired
45
+ * @throws {ForbiddenException} When the site is not accessible
46
+ * @throws {ServerException} When the server encounters an error
47
+ * @throws {TimeoutException} When the request times out
30
48
  */
31
49
  async getFolders() {
32
50
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders`);
@@ -34,6 +52,11 @@ export class Pages {
34
52
  }
35
53
  /**
36
54
  * Get a single folder by ID
55
+ * @throws {UnauthorizedException} When the API key is invalid or expired
56
+ * @throws {NotFoundException} When the folder is not found
57
+ * @throws {ForbiddenException} When the folder does not belong to the site
58
+ * @throws {ServerException} When the server encounters an error
59
+ * @throws {TimeoutException} When the request times out
37
60
  */
38
61
  async getFolder(folderId) {
39
62
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
@@ -45,6 +68,12 @@ export class Pages {
45
68
  * @param data - Update parameters:
46
69
  * - title: New title for the folder
47
70
  * - sortIndex: New position in the folder list
71
+ * @throws {UnauthorizedException} When the API key is invalid or expired
72
+ * @throws {NotFoundException} When the folder is not found
73
+ * @throws {ForbiddenException} When the folder does not belong to the site
74
+ * @throws {BadRequestException} When the update parameters are invalid
75
+ * @throws {ServerException} When the server encounters an error
76
+ * @throws {TimeoutException} When the request times out
48
77
  */
49
78
  async updateFolder(folderId, data) {
50
79
  const response = await this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
@@ -55,6 +84,11 @@ export class Pages {
55
84
  * @param data - Create parameters:
56
85
  * - title: Title of the new folder (required)
57
86
  * - sortIndex: Position in the folder list (optional)
87
+ * @throws {UnauthorizedException} When the API key is invalid or expired
88
+ * @throws {ForbiddenException} When the site is not accessible
89
+ * @throws {BadRequestException} When the create parameters are invalid
90
+ * @throws {ServerException} When the server encounters an error
91
+ * @throws {TimeoutException} When the request times out
58
92
  */
59
93
  async createFolder(data) {
60
94
  const response = await this.api.post(`/sites/${this.siteId}/pages-folders`, data);
@@ -62,12 +96,27 @@ export class Pages {
62
96
  }
63
97
  /**
64
98
  * Delete a folder and its items
99
+ * @throws {UnauthorizedException} When the API key is invalid or expired
65
100
  * @throws {NotFoundException} When the folder is not found
66
101
  * @throws {ForbiddenException} When the folder does not belong to the site
102
+ * @throws {ServerException} When the server encounters an error
103
+ * @throws {TimeoutException} When the request times out
67
104
  */
68
105
  async deleteFolder(folderId) {
69
106
  await this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
70
107
  }
108
+ /**
109
+ * Delete a page
110
+ * @param pageId - ID of the page to delete
111
+ * @throws {UnauthorizedException} When the API key is invalid or expired
112
+ * @throws {NotFoundException} When the page is not found
113
+ * @throws {ForbiddenException} When the page does not belong to the site
114
+ * @throws {ServerException} When the server encounters an error
115
+ * @throws {TimeoutException} When the request times out
116
+ */
117
+ async deletePage(pageId) {
118
+ await this.api.delete(`/sites/${this.siteId}/pages/${pageId}`);
119
+ }
71
120
  /**
72
121
  * Update a page's properties
73
122
  * @param pageId - ID of the page to update
@@ -87,6 +136,12 @@ export class Pages {
87
136
  * - ogDescription: Open Graph description for social sharing
88
137
  * - noindex: Whether to prevent search engine indexing
89
138
  * - grid: Grid configuration for the page
139
+ * @throws {UnauthorizedException} When the API key is invalid or expired
140
+ * @throws {NotFoundException} When the page is not found
141
+ * @throws {ForbiddenException} When the page does not belong to the site
142
+ * @throws {BadRequestException} When the update parameters are invalid
143
+ * @throws {ServerException} When the server encounters an error
144
+ * @throws {TimeoutException} When the request times out
90
145
  */
91
146
  async updatePage(pageId, data) {
92
147
  const response = await this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
@@ -3,3 +3,45 @@ export var FlexbeAuthType;
3
3
  FlexbeAuthType["API_KEY"] = "apiKey";
4
4
  FlexbeAuthType["BEARER"] = "bearer";
5
5
  })(FlexbeAuthType || (FlexbeAuthType = {}));
6
+ export class NotFoundException extends Error {
7
+ constructor(message) {
8
+ super(Array.isArray(message) ? message.join(', ') : message);
9
+ this.statusCode = 404;
10
+ this.name = 'NotFoundException';
11
+ }
12
+ }
13
+ export class ForbiddenException extends Error {
14
+ constructor(message) {
15
+ super(Array.isArray(message) ? message.join(', ') : message);
16
+ this.statusCode = 403;
17
+ this.name = 'ForbiddenException';
18
+ }
19
+ }
20
+ export class BadRequestException extends Error {
21
+ constructor(message) {
22
+ super(Array.isArray(message) ? message.join(', ') : message);
23
+ this.statusCode = 400;
24
+ this.name = 'BadRequestException';
25
+ }
26
+ }
27
+ export class UnauthorizedException extends Error {
28
+ constructor(message) {
29
+ super(Array.isArray(message) ? message.join(', ') : message);
30
+ this.statusCode = 401;
31
+ this.name = 'UnauthorizedException';
32
+ }
33
+ }
34
+ export class ServerException extends Error {
35
+ constructor(message, statusCode = 500) {
36
+ super(Array.isArray(message) ? message.join(', ') : message);
37
+ this.name = 'ServerException';
38
+ this.statusCode = statusCode;
39
+ }
40
+ }
41
+ export class TimeoutException extends Error {
42
+ constructor(message) {
43
+ super(Array.isArray(message) ? message.join(', ') : message);
44
+ this.statusCode = 408;
45
+ this.name = 'TimeoutException';
46
+ }
47
+ }
@@ -9,23 +9,41 @@ export declare class Pages {
9
9
  * @param params - Query parameters including:
10
10
  * - offset: Number of items to skip (default: 0)
11
11
  * - limit: Maximum number of items to return (default: 100)
12
- * - type: Filter by page type
13
- * - 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)
14
14
  * - uri: Search by URI (exact match with '/' or partial match with '%word%')
15
- * - title: Search by title
16
15
  * - folderId: Filter by folder ID
16
+ * @throws {UnauthorizedException} When the API key is invalid or expired
17
+ * @throws {ForbiddenException} When the site is not accessible
18
+ * @throws {BadRequestException} When the query parameters are invalid
19
+ * @throws {ServerException} When the server encounters an error
20
+ * @throws {TimeoutException} When the request times out
17
21
  */
18
22
  getPages(params?: GetPagesParams): Promise<PageListResponse>;
19
23
  /**
20
24
  * Get a single page by ID
25
+ * @throws {UnauthorizedException} When the API key is invalid or expired
26
+ * @throws {NotFoundException} When the page is not found
27
+ * @throws {ForbiddenException} When the page does not belong to the site
28
+ * @throws {ServerException} When the server encounters an error
29
+ * @throws {TimeoutException} When the request times out
21
30
  */
22
31
  getPage(pageId: number): Promise<Page>;
23
32
  /**
24
33
  * Get list of folders for a site
34
+ * @throws {UnauthorizedException} When the API key is invalid or expired
35
+ * @throws {ForbiddenException} When the site is not accessible
36
+ * @throws {ServerException} When the server encounters an error
37
+ * @throws {TimeoutException} When the request times out
25
38
  */
26
39
  getFolders(): Promise<PageFolderListResponse>;
27
40
  /**
28
41
  * Get a single folder by ID
42
+ * @throws {UnauthorizedException} When the API key is invalid or expired
43
+ * @throws {NotFoundException} When the folder is not found
44
+ * @throws {ForbiddenException} When the folder does not belong to the site
45
+ * @throws {ServerException} When the server encounters an error
46
+ * @throws {TimeoutException} When the request times out
29
47
  */
30
48
  getFolder(folderId: number): Promise<PageFolder>;
31
49
  /**
@@ -34,6 +52,12 @@ export declare class Pages {
34
52
  * @param data - Update parameters:
35
53
  * - title: New title for the folder
36
54
  * - sortIndex: New position in the folder list
55
+ * @throws {UnauthorizedException} When the API key is invalid or expired
56
+ * @throws {NotFoundException} When the folder is not found
57
+ * @throws {ForbiddenException} When the folder does not belong to the site
58
+ * @throws {BadRequestException} When the update parameters are invalid
59
+ * @throws {ServerException} When the server encounters an error
60
+ * @throws {TimeoutException} When the request times out
37
61
  */
38
62
  updateFolder(folderId: number, data: UpdateFolderParams): Promise<PageFolder>;
39
63
  /**
@@ -41,14 +65,32 @@ export declare class Pages {
41
65
  * @param data - Create parameters:
42
66
  * - title: Title of the new folder (required)
43
67
  * - sortIndex: Position in the folder list (optional)
68
+ * @throws {UnauthorizedException} When the API key is invalid or expired
69
+ * @throws {ForbiddenException} When the site is not accessible
70
+ * @throws {BadRequestException} When the create parameters are invalid
71
+ * @throws {ServerException} When the server encounters an error
72
+ * @throws {TimeoutException} When the request times out
44
73
  */
45
74
  createFolder(data: CreateFolderParams): Promise<PageFolder>;
46
75
  /**
47
76
  * Delete a folder and its items
77
+ * @throws {UnauthorizedException} When the API key is invalid or expired
48
78
  * @throws {NotFoundException} When the folder is not found
49
79
  * @throws {ForbiddenException} When the folder does not belong to the site
80
+ * @throws {ServerException} When the server encounters an error
81
+ * @throws {TimeoutException} When the request times out
50
82
  */
51
83
  deleteFolder(folderId: number): Promise<void>;
84
+ /**
85
+ * Delete a page
86
+ * @param pageId - ID of the page to delete
87
+ * @throws {UnauthorizedException} When the API key is invalid or expired
88
+ * @throws {NotFoundException} When the page is not found
89
+ * @throws {ForbiddenException} When the page does not belong to the site
90
+ * @throws {ServerException} When the server encounters an error
91
+ * @throws {TimeoutException} When the request times out
92
+ */
93
+ deletePage(pageId: number): Promise<void>;
52
94
  /**
53
95
  * Update a page's properties
54
96
  * @param pageId - ID of the page to update
@@ -68,6 +110,12 @@ export declare class Pages {
68
110
  * - ogDescription: Open Graph description for social sharing
69
111
  * - noindex: Whether to prevent search engine indexing
70
112
  * - grid: Grid configuration for the page
113
+ * @throws {UnauthorizedException} When the API key is invalid or expired
114
+ * @throws {NotFoundException} When the page is not found
115
+ * @throws {ForbiddenException} When the page does not belong to the site
116
+ * @throws {BadRequestException} When the update parameters are invalid
117
+ * @throws {ServerException} When the server encounters an error
118
+ * @throws {TimeoutException} When the request times out
71
119
  */
72
120
  updatePage(pageId: number, data: UpdatePageParams): Promise<Page>;
73
121
  }
@@ -15,15 +15,14 @@ export interface FlexbeResponse<T> {
15
15
  statusText: string;
16
16
  }
17
17
  export interface FlexbeErrorResponse {
18
- message: string;
19
- code?: string;
20
- details?: unknown;
18
+ message: string | string[];
19
+ error: string;
20
+ statusCode: number;
21
21
  }
22
22
  export interface FlexbeError {
23
- message: string;
24
- code?: string;
25
- status?: number;
26
- details?: unknown;
23
+ message: string | string[];
24
+ error: string;
25
+ statusCode: number;
27
26
  }
28
27
  export interface JwtToken {
29
28
  accessToken: string;
@@ -37,3 +36,27 @@ export interface Pagination {
37
36
  offset: number;
38
37
  total: number;
39
38
  }
39
+ export declare class NotFoundException extends Error {
40
+ readonly statusCode = 404;
41
+ constructor(message: string | string[]);
42
+ }
43
+ export declare class ForbiddenException extends Error {
44
+ readonly statusCode = 403;
45
+ constructor(message: string | string[]);
46
+ }
47
+ export declare class BadRequestException extends Error {
48
+ readonly statusCode = 400;
49
+ constructor(message: string | string[]);
50
+ }
51
+ export declare class UnauthorizedException extends Error {
52
+ readonly statusCode = 401;
53
+ constructor(message: string | string[]);
54
+ }
55
+ export declare class ServerException extends Error {
56
+ readonly statusCode: number;
57
+ constructor(message: string | string[], statusCode?: number);
58
+ }
59
+ export declare class TimeoutException extends Error {
60
+ readonly statusCode = 408;
61
+ constructor(message: string | string[]);
62
+ }
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexbe/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "TypeScript SDK for Flexbe API",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",