@flexbe/sdk 0.2.4 → 0.2.6

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
  }
@@ -21,6 +21,11 @@ export class Pages {
21
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
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
24
29
  */
25
30
  getPages(params) {
26
31
  return __awaiter(this, void 0, void 0, function* () {
@@ -31,6 +36,11 @@ export class Pages {
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* () {
@@ -117,4 +170,51 @@ export class Pages {
117
170
  return response.data;
118
171
  });
119
172
  }
173
+ /**
174
+ * Bulk update multiple pages
175
+ * @param updates - Array of page updates, each containing:
176
+ * - pageId: ID of the page to update
177
+ * - status: New status for the page
178
+ * - name: New name for the page
179
+ * - uri: New URI for the page
180
+ * - language: New language for the page
181
+ * - folderId: New folder ID for the page
182
+ * - sortIndex: New position in the page list
183
+ * - meta: Meta information for the page
184
+ * @returns Object containing:
185
+ * - updated: Array of successfully updated pages
186
+ * - errors: Array of errors for failed updates
187
+ * @throws {UnauthorizedException} When the API key is invalid or expired
188
+ * @throws {ForbiddenException} When the site is not accessible
189
+ * @throws {BadRequestException} When all pages fail to update
190
+ * @throws {ServerException} When the server encounters an error
191
+ * @throws {TimeoutException} When the request times out
192
+ */
193
+ bulkUpdatePages(updates) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const response = yield this.api.patch(`/sites/${this.siteId}/pages`, updates);
196
+ return response.data;
197
+ });
198
+ }
199
+ /**
200
+ * Bulk update multiple folders
201
+ * @param updates - Array of folder updates, each containing:
202
+ * - folderId: ID of the folder to update
203
+ * - title: New title for the folder
204
+ * - sortIndex: New position in the folder list
205
+ * @returns Object containing:
206
+ * - updated: Array of successfully updated folders
207
+ * - errors: Array of errors for failed updates
208
+ * @throws {UnauthorizedException} When the API key is invalid or expired
209
+ * @throws {ForbiddenException} When the site is not accessible
210
+ * @throws {BadRequestException} When all folders fail to update
211
+ * @throws {ServerException} When the server encounters an error
212
+ * @throws {TimeoutException} When the request times out
213
+ */
214
+ bulkUpdateFolders(updates) {
215
+ return __awaiter(this, void 0, void 0, function* () {
216
+ const response = yield this.api.patch(`/sites/${this.siteId}/pages-folders`, updates);
217
+ return response.data;
218
+ });
219
+ }
120
220
  }
@@ -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
  }
@@ -15,6 +15,11 @@ class Pages {
15
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
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
18
23
  */
19
24
  async getPages(params) {
20
25
  const processedParams = params ? {
@@ -27,6 +32,11 @@ class Pages {
27
32
  }
28
33
  /**
29
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
30
40
  */
31
41
  async getPage(pageId) {
32
42
  const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
@@ -34,6 +44,10 @@ class Pages {
34
44
  }
35
45
  /**
36
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
37
51
  */
38
52
  async getFolders() {
39
53
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders`);
@@ -41,6 +55,11 @@ class Pages {
41
55
  }
42
56
  /**
43
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
44
63
  */
45
64
  async getFolder(folderId) {
46
65
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
@@ -52,6 +71,12 @@ class Pages {
52
71
  * @param data - Update parameters:
53
72
  * - title: New title for the folder
54
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
55
80
  */
56
81
  async updateFolder(folderId, data) {
57
82
  const response = await this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
@@ -62,6 +87,11 @@ class Pages {
62
87
  * @param data - Create parameters:
63
88
  * - title: Title of the new folder (required)
64
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
65
95
  */
66
96
  async createFolder(data) {
67
97
  const response = await this.api.post(`/sites/${this.siteId}/pages-folders`, data);
@@ -69,12 +99,27 @@ class Pages {
69
99
  }
70
100
  /**
71
101
  * Delete a folder and its items
102
+ * @throws {UnauthorizedException} When the API key is invalid or expired
72
103
  * @throws {NotFoundException} When the folder is not found
73
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
74
107
  */
75
108
  async deleteFolder(folderId) {
76
109
  await this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
77
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
+ }
78
123
  /**
79
124
  * Update a page's properties
80
125
  * @param pageId - ID of the page to update
@@ -94,10 +139,59 @@ class Pages {
94
139
  * - ogDescription: Open Graph description for social sharing
95
140
  * - noindex: Whether to prevent search engine indexing
96
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
97
148
  */
98
149
  async updatePage(pageId, data) {
99
150
  const response = await this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
100
151
  return response.data;
101
152
  }
153
+ /**
154
+ * Bulk update multiple pages
155
+ * @param updates - Array of page updates, each containing:
156
+ * - pageId: ID of the page to update
157
+ * - status: New status for the page
158
+ * - name: New name for the page
159
+ * - uri: New URI for the page
160
+ * - language: New language for the page
161
+ * - folderId: New folder ID for the page
162
+ * - sortIndex: New position in the page list
163
+ * - meta: Meta information for the page
164
+ * @returns Object containing:
165
+ * - updated: Array of successfully updated pages
166
+ * - errors: Array of errors for failed updates
167
+ * @throws {UnauthorizedException} When the API key is invalid or expired
168
+ * @throws {ForbiddenException} When the site is not accessible
169
+ * @throws {BadRequestException} When all pages fail to update
170
+ * @throws {ServerException} When the server encounters an error
171
+ * @throws {TimeoutException} When the request times out
172
+ */
173
+ async bulkUpdatePages(updates) {
174
+ const response = await this.api.patch(`/sites/${this.siteId}/pages`, updates);
175
+ return response.data;
176
+ }
177
+ /**
178
+ * Bulk update multiple folders
179
+ * @param updates - Array of folder updates, each containing:
180
+ * - folderId: ID of the folder to update
181
+ * - title: New title for the folder
182
+ * - sortIndex: New position in the folder list
183
+ * @returns Object containing:
184
+ * - updated: Array of successfully updated folders
185
+ * - errors: Array of errors for failed updates
186
+ * @throws {UnauthorizedException} When the API key is invalid or expired
187
+ * @throws {ForbiddenException} When the site is not accessible
188
+ * @throws {BadRequestException} When all folders fail to update
189
+ * @throws {ServerException} When the server encounters an error
190
+ * @throws {TimeoutException} When the request times out
191
+ */
192
+ async bulkUpdateFolders(updates) {
193
+ const response = await this.api.patch(`/sites/${this.siteId}/pages-folders`, updates);
194
+ return response.data;
195
+ }
102
196
  }
103
197
  exports.Pages = Pages;
@@ -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
  }
@@ -12,6 +12,11 @@ export class Pages {
12
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
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
15
20
  */
16
21
  async getPages(params) {
17
22
  const processedParams = params ? {
@@ -24,6 +29,11 @@ export class Pages {
24
29
  }
25
30
  /**
26
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
27
37
  */
28
38
  async getPage(pageId) {
29
39
  const response = await this.api.get(`/sites/${this.siteId}/pages/${pageId}`);
@@ -31,6 +41,10 @@ export class Pages {
31
41
  }
32
42
  /**
33
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
34
48
  */
35
49
  async getFolders() {
36
50
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders`);
@@ -38,6 +52,11 @@ export class Pages {
38
52
  }
39
53
  /**
40
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
41
60
  */
42
61
  async getFolder(folderId) {
43
62
  const response = await this.api.get(`/sites/${this.siteId}/pages-folders/${folderId}`);
@@ -49,6 +68,12 @@ export class Pages {
49
68
  * @param data - Update parameters:
50
69
  * - title: New title for the folder
51
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
52
77
  */
53
78
  async updateFolder(folderId, data) {
54
79
  const response = await this.api.patch(`/sites/${this.siteId}/pages-folders/${folderId}`, data);
@@ -59,6 +84,11 @@ export class Pages {
59
84
  * @param data - Create parameters:
60
85
  * - title: Title of the new folder (required)
61
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
62
92
  */
63
93
  async createFolder(data) {
64
94
  const response = await this.api.post(`/sites/${this.siteId}/pages-folders`, data);
@@ -66,12 +96,27 @@ export class Pages {
66
96
  }
67
97
  /**
68
98
  * Delete a folder and its items
99
+ * @throws {UnauthorizedException} When the API key is invalid or expired
69
100
  * @throws {NotFoundException} When the folder is not found
70
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
71
104
  */
72
105
  async deleteFolder(folderId) {
73
106
  await this.api.delete(`/sites/${this.siteId}/pages-folders/${folderId}`);
74
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
+ }
75
120
  /**
76
121
  * Update a page's properties
77
122
  * @param pageId - ID of the page to update
@@ -91,9 +136,58 @@ export class Pages {
91
136
  * - ogDescription: Open Graph description for social sharing
92
137
  * - noindex: Whether to prevent search engine indexing
93
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
94
145
  */
95
146
  async updatePage(pageId, data) {
96
147
  const response = await this.api.put(`/sites/${this.siteId}/pages/${pageId}`, data);
97
148
  return response.data;
98
149
  }
150
+ /**
151
+ * Bulk update multiple pages
152
+ * @param updates - Array of page updates, each containing:
153
+ * - pageId: ID of the page to update
154
+ * - status: New status for the page
155
+ * - name: New name for the page
156
+ * - uri: New URI for the page
157
+ * - language: New language for the page
158
+ * - folderId: New folder ID for the page
159
+ * - sortIndex: New position in the page list
160
+ * - meta: Meta information for the page
161
+ * @returns Object containing:
162
+ * - updated: Array of successfully updated pages
163
+ * - errors: Array of errors for failed updates
164
+ * @throws {UnauthorizedException} When the API key is invalid or expired
165
+ * @throws {ForbiddenException} When the site is not accessible
166
+ * @throws {BadRequestException} When all pages fail to update
167
+ * @throws {ServerException} When the server encounters an error
168
+ * @throws {TimeoutException} When the request times out
169
+ */
170
+ async bulkUpdatePages(updates) {
171
+ const response = await this.api.patch(`/sites/${this.siteId}/pages`, updates);
172
+ return response.data;
173
+ }
174
+ /**
175
+ * Bulk update multiple folders
176
+ * @param updates - Array of folder updates, each containing:
177
+ * - folderId: ID of the folder to update
178
+ * - title: New title for the folder
179
+ * - sortIndex: New position in the folder list
180
+ * @returns Object containing:
181
+ * - updated: Array of successfully updated folders
182
+ * - errors: Array of errors for failed updates
183
+ * @throws {UnauthorizedException} When the API key is invalid or expired
184
+ * @throws {ForbiddenException} When the site is not accessible
185
+ * @throws {BadRequestException} When all folders fail to update
186
+ * @throws {ServerException} When the server encounters an error
187
+ * @throws {TimeoutException} When the request times out
188
+ */
189
+ async bulkUpdateFolders(updates) {
190
+ const response = await this.api.patch(`/sites/${this.siteId}/pages-folders`, updates);
191
+ return response.data;
192
+ }
99
193
  }
@@ -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,4 +1,4 @@
1
- import { Page, GetPagesParams, PageListResponse, PageFolder, PageFolderListResponse, UpdateFolderParams, CreateFolderParams, UpdatePageParams } from '../types/pages';
1
+ import { Page, GetPagesParams, PageListResponse, PageFolder, PageFolderListResponse, UpdateFolderParams, CreateFolderParams, UpdatePageParams, BulkUpdatePageItem, BulkUpdateResponse, BulkUpdateFolderItem, BulkUpdateFolderResponse } from '../types/pages';
2
2
  import { ApiClient } from './api-client';
3
3
  export declare class Pages {
4
4
  private readonly api;
@@ -13,18 +13,37 @@ export declare class Pages {
13
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
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
16
21
  */
17
22
  getPages(params?: GetPagesParams): Promise<PageListResponse>;
18
23
  /**
19
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
20
30
  */
21
31
  getPage(pageId: number): Promise<Page>;
22
32
  /**
23
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
24
38
  */
25
39
  getFolders(): Promise<PageFolderListResponse>;
26
40
  /**
27
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
28
47
  */
29
48
  getFolder(folderId: number): Promise<PageFolder>;
30
49
  /**
@@ -33,6 +52,12 @@ export declare class Pages {
33
52
  * @param data - Update parameters:
34
53
  * - title: New title for the folder
35
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
36
61
  */
37
62
  updateFolder(folderId: number, data: UpdateFolderParams): Promise<PageFolder>;
38
63
  /**
@@ -40,14 +65,32 @@ export declare class Pages {
40
65
  * @param data - Create parameters:
41
66
  * - title: Title of the new folder (required)
42
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
43
73
  */
44
74
  createFolder(data: CreateFolderParams): Promise<PageFolder>;
45
75
  /**
46
76
  * Delete a folder and its items
77
+ * @throws {UnauthorizedException} When the API key is invalid or expired
47
78
  * @throws {NotFoundException} When the folder is not found
48
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
49
82
  */
50
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>;
51
94
  /**
52
95
  * Update a page's properties
53
96
  * @param pageId - ID of the page to update
@@ -67,6 +110,49 @@ export declare class Pages {
67
110
  * - ogDescription: Open Graph description for social sharing
68
111
  * - noindex: Whether to prevent search engine indexing
69
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
70
119
  */
71
120
  updatePage(pageId: number, data: UpdatePageParams): Promise<Page>;
121
+ /**
122
+ * Bulk update multiple pages
123
+ * @param updates - Array of page updates, each containing:
124
+ * - pageId: ID of the page to update
125
+ * - status: New status for the page
126
+ * - name: New name for the page
127
+ * - uri: New URI for the page
128
+ * - language: New language for the page
129
+ * - folderId: New folder ID for the page
130
+ * - sortIndex: New position in the page list
131
+ * - meta: Meta information for the page
132
+ * @returns Object containing:
133
+ * - updated: Array of successfully updated pages
134
+ * - errors: Array of errors for failed updates
135
+ * @throws {UnauthorizedException} When the API key is invalid or expired
136
+ * @throws {ForbiddenException} When the site is not accessible
137
+ * @throws {BadRequestException} When all pages fail to update
138
+ * @throws {ServerException} When the server encounters an error
139
+ * @throws {TimeoutException} When the request times out
140
+ */
141
+ bulkUpdatePages(updates: BulkUpdatePageItem[]): Promise<BulkUpdateResponse>;
142
+ /**
143
+ * Bulk update multiple folders
144
+ * @param updates - Array of folder updates, each containing:
145
+ * - folderId: ID of the folder to update
146
+ * - title: New title for the folder
147
+ * - sortIndex: New position in the folder list
148
+ * @returns Object containing:
149
+ * - updated: Array of successfully updated folders
150
+ * - errors: Array of errors for failed updates
151
+ * @throws {UnauthorizedException} When the API key is invalid or expired
152
+ * @throws {ForbiddenException} When the site is not accessible
153
+ * @throws {BadRequestException} When all folders fail to update
154
+ * @throws {ServerException} When the server encounters an error
155
+ * @throws {TimeoutException} When the request times out
156
+ */
157
+ bulkUpdateFolders(updates: BulkUpdateFolderItem[]): Promise<BulkUpdateFolderResponse>;
72
158
  }
@@ -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
+ }
@@ -101,3 +101,27 @@ export interface UpdatePageParams {
101
101
  noindex?: boolean;
102
102
  };
103
103
  }
104
+ export interface BulkUpdatePageItem extends UpdatePageParams {
105
+ pageId: number;
106
+ }
107
+ export interface BulkUpdateError {
108
+ pageId: number;
109
+ code: number;
110
+ message: string;
111
+ }
112
+ export interface BulkUpdateResponse {
113
+ updated: Page[];
114
+ errors: BulkUpdateError[];
115
+ }
116
+ export interface BulkUpdateFolderItem extends UpdateFolderParams {
117
+ folderId: number;
118
+ }
119
+ export interface BulkUpdateFolderError {
120
+ folderId: number;
121
+ code: number;
122
+ message: string;
123
+ }
124
+ export interface BulkUpdateFolderResponse {
125
+ updated: PageFolder[];
126
+ errors: BulkUpdateFolderError[];
127
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexbe/sdk",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "TypeScript SDK for Flexbe API",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",