dalux-build-api 2.3.0 → 2.4.0

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.
Files changed (48) hide show
  1. package/package.json +31 -11
  2. package/src/api/CompaniesApi.js +0 -67
  3. package/src/api/CompanyCatalogApi.js +0 -129
  4. package/src/api/FileAreasApi.js +0 -57
  5. package/src/api/FileRevisionsApi.js +0 -33
  6. package/src/api/FileUploadApi.js +0 -64
  7. package/src/api/FilesApi.js +0 -721
  8. package/src/api/FoldersApi.js +0 -283
  9. package/src/api/FormsApi.js +0 -53
  10. package/src/api/InspectionPlansApi.js +0 -140
  11. package/src/api/ProjectTemplatesApi.js +0 -25
  12. package/src/api/ProjectsApi.js +0 -127
  13. package/src/api/TasksApi.js +0 -193
  14. package/src/api/TestPlansApi.js +0 -137
  15. package/src/api/UsersApi.js +0 -52
  16. package/src/api/VersionSetsApi.js +0 -75
  17. package/src/api/WorkPackagesApi.js +0 -30
  18. package/src/apiClient.js +0 -143
  19. package/src/browser.js +0 -84
  20. package/src/configuration.js +0 -39
  21. package/src/index.js +0 -133
  22. package/src/models/common.js +0 -22
  23. package/src/models/companies/index.js +0 -14
  24. package/src/models/companyCatalog/index.js +0 -19
  25. package/src/models/convert.js +0 -44
  26. package/src/models/fileAreas/index.js +0 -20
  27. package/src/models/fileRevisions/index.js +0 -12
  28. package/src/models/fileUpload/index.js +0 -12
  29. package/src/models/files/index.js +0 -97
  30. package/src/models/folders/index.js +0 -20
  31. package/src/models/forms/index.js +0 -19
  32. package/src/models/helpers.js +0 -62
  33. package/src/models/index.js +0 -178
  34. package/src/models/inspectionPlans/index.js +0 -61
  35. package/src/models/projectTemplates/index.js +0 -11
  36. package/src/models/projects/index.js +0 -57
  37. package/src/models/tasks/index.js +0 -105
  38. package/src/models/testPlans/index.js +0 -61
  39. package/src/models/users/index.js +0 -29
  40. package/src/models/versionSets/index.js +0 -22
  41. package/src/models/workPackages/index.js +0 -19
  42. package/src/next.js +0 -89
  43. package/src/utils/errors.js +0 -45
  44. package/src/utils/index.js +0 -26
  45. package/src/utils/pagination.js +0 -82
  46. package/src/utils/pathResolver.js +0 -124
  47. package/src/utils/search.js +0 -61
  48. package/src/utils/validation.js +0 -36
@@ -1,193 +0,0 @@
1
- 'use strict';
2
-
3
- const { convertToModel, convertToModelList } = require('../models/convert');
4
- const {
5
- TaskSchema,
6
- TaskChangeSchema,
7
- TasksListResponseSchema,
8
- TaskResponseSchema,
9
- TaskChangesSchema,
10
- TaskAttachmentsListResponseSchema,
11
- } = require('../models/tasks');
12
-
13
- /**
14
- * Build query params for GET /5.2/projects/.../tasks (OData).
15
- * If params contains typeId and no $filter, expands to
16
- * $filter=data/type/typeId eq '<typeId>'
17
- * Single quotes in typeId are escaped as '' per OData. If $filter is set,
18
- * typeId is still omitted from the outgoing query (not merged).
19
- * @param {object} [params]
20
- * @returns {object}
21
- */
22
- function normalizeTaskParams(params = {}) {
23
- const normalized = { ...params };
24
- const typeId = normalized.typeId;
25
- delete normalized.typeId;
26
- if (typeId != null && normalized.$filter === undefined) {
27
- const escaped = String(typeId).replace(/'/g, "''");
28
- normalized.$filter = `data/type/typeId eq '${escaped}'`;
29
- }
30
- return normalized;
31
- }
32
-
33
- /**
34
- * API methods for tasks, approvals, safety issues, observations and good practices.
35
- */
36
- class TasksApi {
37
- /**
38
- * @param {import('../apiClient')} apiClient
39
- */
40
- constructor(apiClient) {
41
- this._client = apiClient;
42
- }
43
-
44
- /**
45
- * Retrieve tasks, approvals, safety issues, safety observations and good practices on a project.
46
- * GET /5.2/projects/{projectId}/tasks
47
- * @param {string} projectId
48
- * @param {object} [params] - Optional filters (e.g. updatedAfter). Pass typeId as shorthand for
49
- * OData $filter on task type, or pass $filter (and other OData options) directly.
50
- * @returns {Promise<object>}
51
- */
52
- async getProjectTasks(projectId, params = {}) {
53
- const response = await this._client.get(`/5.2/projects/${projectId}/tasks`, normalizeTaskParams(params));
54
- return convertToModel(response, TasksListResponseSchema, 'TasksListResponse');
55
- }
56
-
57
- /**
58
- * Retrieve all tasks on a project by following bookmark pagination automatically.
59
- * Matches Python client behaviour: uses metadata.totalRemainingItems when present;
60
- * otherwise uses metadata.totalItems across pages as a ceiling so pagination cannot run forever.
61
- * @param {string} projectId
62
- * @param {object} [params] - Optional filters / OData (typeId shorthand supported).
63
- * @param {boolean} [verbose=false] - Log progress to console.
64
- * @returns {Promise<object[]>} All task items across all pages
65
- */
66
- async getAllProjectTasks(projectId, params = {}, verbose = false) {
67
- const allItems = [];
68
- const baseParams = normalizeTaskParams(params);
69
- let currentParams = { ...baseParams };
70
- let hasNextPage = true;
71
- /** @type {number|null} */
72
- let tasksItemsCeiling = null;
73
-
74
- while (hasNextPage) {
75
- const response = await this._client.get(`/5.2/projects/${projectId}/tasks`, currentParams);
76
- const items = Array.isArray(response.items) ? response.items : [];
77
- if (items.length) {
78
- allItems.push(...items);
79
- }
80
- const meta = (response && response.metadata) || {};
81
- let remaining;
82
- let useFilesRemainingStop;
83
-
84
- if (Object.prototype.hasOwnProperty.call(meta, 'totalRemainingItems')) {
85
- remaining = Number(meta.totalRemainingItems);
86
- useFilesRemainingStop = true;
87
- } else if (Object.prototype.hasOwnProperty.call(meta, 'totalItems')) {
88
- const ti = Number(meta.totalItems);
89
- tasksItemsCeiling = Math.max(tasksItemsCeiling || 0, ti);
90
- remaining = ti;
91
- useFilesRemainingStop = false;
92
- } else {
93
- remaining = 0;
94
- useFilesRemainingStop = true;
95
- }
96
-
97
- const nextLink = (response.links || []).find((l) => l.rel === 'nextPage');
98
- const nextHref = nextLink ? nextLink.href : null;
99
-
100
- if (verbose) {
101
- const nextPart = nextHref ? ` next: ${nextHref}` : ' next: (none)';
102
- if (useFilesRemainingStop) {
103
- console.log(`Retrieved ${allItems.length} tasks so far, ${remaining} remaining...${nextPart}`);
104
- } else if (tasksItemsCeiling != null) {
105
- const remV = Math.max(0, tasksItemsCeiling - allItems.length);
106
- console.log(`Retrieved ${allItems.length} tasks so far, ${remV} remaining...${nextPart}`);
107
- } else {
108
- console.log(`Retrieved ${allItems.length} tasks so far, ${remaining} remaining...${nextPart}`);
109
- }
110
- }
111
-
112
- if (!items.length) {
113
- hasNextPage = false;
114
- } else if (useFilesRemainingStop && remaining === 0) {
115
- hasNextPage = false;
116
- } else if (
117
- !useFilesRemainingStop &&
118
- tasksItemsCeiling != null &&
119
- allItems.length >= tasksItemsCeiling
120
- ) {
121
- hasNextPage = false;
122
- } else if (nextLink) {
123
- const bookmark = new URL(nextLink.href).searchParams.get('bookmark');
124
- currentParams = { ...baseParams, bookmark };
125
- } else {
126
- hasNextPage = false;
127
- }
128
- }
129
-
130
- if (verbose) {
131
- console.log(`Done. Total tasks retrieved: ${allItems.length}`);
132
- }
133
- return convertToModelList(allItems, TaskSchema, 'Task');
134
- }
135
-
136
- /**
137
- * Retrieve a specific task/approval/safety issue/safety observation/good practice.
138
- * GET /3.3/projects/{projectId}/tasks/{taskId}
139
- * @param {string} projectId
140
- * @param {string} taskId
141
- * @returns {Promise<object>}
142
- */
143
- async getTask(projectId, taskId) {
144
- const response = await this._client.get(`/3.3/projects/${projectId}/tasks/${taskId}`);
145
- return convertToModel(response, TaskResponseSchema, 'TaskResponse');
146
- }
147
-
148
- /**
149
- * Retrieve task changes on a project in incremental updates.
150
- * GET /2.2/projects/{projectId}/tasks/changes
151
- * @param {string} projectId
152
- * @param {object} [params] - Optional filters (e.g. updatedAfter)
153
- * @returns {Promise<object>}
154
- */
155
- async getProjectTaskChanges(projectId, params = {}) {
156
- const response = await this._client.get(`/2.2/projects/${projectId}/tasks/changes`, params);
157
- return convertToModel(response, TaskChangesSchema, 'TaskChanges');
158
- }
159
-
160
- /**
161
- * Retrieve attachments on tasks on a project.
162
- * GET /1.1/projects/{projectId}/tasks/attachments
163
- * @param {string} projectId
164
- * @param {object} [params] - Optional filters (e.g. updatedAfter)
165
- * @returns {Promise<object>}
166
- */
167
- async getProjectTaskAttachments(projectId, params = {}) {
168
- const response = await this._client.get(`/1.1/projects/${projectId}/tasks/attachments`, params);
169
- return convertToModel(response, TaskAttachmentsListResponseSchema, 'TaskAttachmentsListResponse');
170
- }
171
-
172
- /**
173
- * Retrieve all task changes by following bookmark pagination automatically.
174
- * @param {string} projectId
175
- * @param {object} [params] - Optional query parameters (e.g. updatedAfter).
176
- * @param {boolean} [verbose=false]
177
- * @returns {Promise<object[]>} All task change items across all pages.
178
- */
179
- async getAllProjectTaskChanges(projectId, params = {}, verbose = false) {
180
- const { paginate } = require('../utils/pagination');
181
- const raw = await paginate(
182
- `/2.2/projects/${projectId}/tasks/changes`,
183
- this._client,
184
- params,
185
- verbose,
186
- );
187
- return convertToModelList(raw, TaskChangeSchema, 'TaskChange');
188
- }
189
- }
190
-
191
- TasksApi.normalizeTaskParams = normalizeTaskParams;
192
-
193
- module.exports = TasksApi;
@@ -1,137 +0,0 @@
1
- 'use strict';
2
-
3
- const { convertToModel, convertToModelList } = require('../models/convert');
4
- const { paginate } = require('../utils/pagination');
5
- const {
6
- TestPlanSchema,
7
- TestPlanItemSchema,
8
- TestPlanItemZoneSchema,
9
- TestPlanRegistrationSchema,
10
- TestPlansListResponseSchema,
11
- TestPlanItemsListResponseSchema,
12
- TestPlanItemZonesListResponseSchema,
13
- TestPlanRegistrationsListResponseSchema,
14
- } = require('../models/testPlans');
15
-
16
- /**
17
- * API methods for test plans.
18
- */
19
- class TestPlansApi {
20
- /**
21
- * @param {import('../apiClient')} apiClient
22
- */
23
- constructor(apiClient) {
24
- this._client = apiClient;
25
- }
26
-
27
- /**
28
- * Browse all test plans on the given project.
29
- * GET /1.2/projects/{projectId}/testPlans
30
- * @param {string} projectId
31
- * @param {object} [params]
32
- * @param {boolean} [fullResponse=false]
33
- * @returns {Promise<object[]|object>}
34
- */
35
- async listTestPlans(projectId, params = {}, fullResponse = false) {
36
- const response = await this._client.get(`/1.2/projects/${projectId}/testPlans`, params);
37
- const result = convertToModel(
38
- response,
39
- TestPlansListResponseSchema,
40
- 'TestPlansListResponse',
41
- );
42
- return fullResponse ? result : (result?.items || []);
43
- }
44
-
45
- async getAllTestPlans(projectId, params = {}, verbose = false) {
46
- const items = await paginate(
47
- `/1.2/projects/${projectId}/testPlans`,
48
- this._client,
49
- params,
50
- verbose,
51
- );
52
- return convertToModelList(items, TestPlanSchema, 'TestPlan');
53
- }
54
-
55
- /**
56
- * Browse all test plan items on the given project.
57
- * GET /1.1/projects/{projectId}/testPlanItems
58
- * @param {string} projectId
59
- * @param {object} [params]
60
- * @returns {Promise<object>}
61
- */
62
- async listTestPlanItems(projectId, params = {}, fullResponse = false) {
63
- const response = await this._client.get(`/1.1/projects/${projectId}/testPlanItems`, params);
64
- const result = convertToModel(
65
- response,
66
- TestPlanItemsListResponseSchema,
67
- 'TestPlanItemsListResponse',
68
- );
69
- return fullResponse ? result : (result?.items || []);
70
- }
71
-
72
- async getAllTestPlanItems(projectId, params = {}, verbose = false) {
73
- const items = await paginate(
74
- `/1.1/projects/${projectId}/testPlanItems`,
75
- this._client,
76
- params,
77
- verbose,
78
- );
79
- return convertToModelList(items, TestPlanItemSchema, 'TestPlanItem');
80
- }
81
-
82
- /**
83
- * Browse all test plan item zones on the given project.
84
- * GET /1.1/projects/{projectId}/testPlanItemZones
85
- * @param {string} projectId
86
- * @param {object} [params]
87
- * @returns {Promise<object>}
88
- */
89
- async listTestPlanItemZones(projectId, params = {}, fullResponse = false) {
90
- const response = await this._client.get(`/1.1/projects/${projectId}/testPlanItemZones`, params);
91
- const result = convertToModel(
92
- response,
93
- TestPlanItemZonesListResponseSchema,
94
- 'TestPlanItemZonesListResponse',
95
- );
96
- return fullResponse ? result : (result?.items || []);
97
- }
98
-
99
- async getAllTestPlanItemZones(projectId, params = {}, verbose = false) {
100
- const items = await paginate(
101
- `/1.1/projects/${projectId}/testPlanItemZones`,
102
- this._client,
103
- params,
104
- verbose,
105
- );
106
- return convertToModelList(items, TestPlanItemZoneSchema, 'TestPlanItemZone');
107
- }
108
-
109
- /**
110
- * Browse all test plan registrations on the given project.
111
- * GET /1.1/projects/{projectId}/testPlanRegistrations
112
- * @param {string} projectId
113
- * @param {object} [params]
114
- * @returns {Promise<object>}
115
- */
116
- async listTestPlanRegistrations(projectId, params = {}, fullResponse = false) {
117
- const response = await this._client.get(`/1.1/projects/${projectId}/testPlanRegistrations`, params);
118
- const result = convertToModel(
119
- response,
120
- TestPlanRegistrationsListResponseSchema,
121
- 'TestPlanRegistrationsListResponse',
122
- );
123
- return fullResponse ? result : (result?.items || []);
124
- }
125
-
126
- async getAllTestPlanRegistrations(projectId, params = {}, verbose = false) {
127
- const items = await paginate(
128
- `/1.1/projects/${projectId}/testPlanRegistrations`,
129
- this._client,
130
- params,
131
- verbose,
132
- );
133
- return convertToModelList(items, TestPlanRegistrationSchema, 'TestPlanRegistration');
134
- }
135
- }
136
-
137
- module.exports = TestPlansApi;
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- const { convertToModel } = require('../models/convert');
4
- const { UserResponseSchema, UsersListResponseSchema } = require('../models/users');
5
-
6
- /**
7
- * API methods for users.
8
- */
9
- class UsersApi {
10
- /**
11
- * @param {import('../apiClient')} apiClient
12
- */
13
- constructor(apiClient) {
14
- this._client = apiClient;
15
- }
16
-
17
- /**
18
- * Get a specific user.
19
- * GET /1.1/users/{userId}
20
- * @param {string} userId
21
- * @returns {Promise<object>} UserResponse ({ data: User, links? })
22
- */
23
- async getUser(userId) {
24
- const response = await this._client.get(`/1.1/users/${userId}`);
25
- return convertToModel(response, UserResponseSchema, 'UserResponse');
26
- }
27
-
28
- /**
29
- * Get users on a project.
30
- * GET /1.2/projects/{projectId}/users
31
- * @param {string} projectId
32
- * @param {object} [params]
33
- * @returns {Promise<object>} UsersListResponse ({ items: ProjectUser[], metadata?, links? })
34
- */
35
- async listProjectUsers(projectId, params = {}) {
36
- const response = await this._client.get(`/1.2/projects/${projectId}/users`, params);
37
- return convertToModel(response, UsersListResponseSchema, 'UsersListResponse');
38
- }
39
-
40
- /**
41
- * Get a specific user on a project.
42
- * GET /1.1/projects/{projectId}/users/{userId}
43
- * @param {string} projectId
44
- * @param {string} userId
45
- * @returns {Promise<object>}
46
- */
47
- getProjectUser(projectId, userId) {
48
- return this._client.get(`/1.1/projects/${projectId}/users/${userId}`);
49
- }
50
- }
51
-
52
- module.exports = UsersApi;
@@ -1,75 +0,0 @@
1
- 'use strict';
2
-
3
- const { convertToModel } = require('../models/convert');
4
- const { VersionSetsListResponseSchema, VersionSetResponseSchema } = require('../models/versionSets');
5
- const { FilesListResponseSchema } = require('../models/files');
6
-
7
- /**
8
- * API methods for version sets.
9
- */
10
- class VersionSetsApi {
11
- /**
12
- * @param {import('../apiClient')} apiClient
13
- */
14
- constructor(apiClient) {
15
- this._client = apiClient;
16
- }
17
-
18
- /**
19
- * Retrieve the version sets on the given project.
20
- * GET /2.1/projects/{projectId}/version_sets
21
- * @param {string} projectId
22
- * @param {object} [params]
23
- * @returns {Promise<object>} VersionSetsListResponse ({ items: VersionSet[], metadata?, links? })
24
- */
25
- async getVersionSets(projectId, params = {}) {
26
- const response = await this._client.get(`/2.1/projects/${projectId}/version_sets`, params);
27
- return convertToModel(response, VersionSetsListResponseSchema, 'VersionSetsListResponse');
28
- }
29
-
30
- /**
31
- * Retrieve a specific version set.
32
- * GET /2.0/projects/{projectId}/version_sets/{versionSetId}
33
- * @param {string} projectId
34
- * @param {string} versionSetId
35
- * @returns {Promise<object>} VersionSetResponse ({ data: VersionSet, links? })
36
- */
37
- async getVersionSet(projectId, versionSetId) {
38
- const response = await this._client.get(`/2.0/projects/${projectId}/version_sets/${versionSetId}`);
39
- return convertToModel(response, VersionSetResponseSchema, 'VersionSetResponse');
40
- }
41
-
42
- /**
43
- * Browse all version sets on the given file area and project.
44
- * GET /2.1/projects/{projectId}/file_areas/{fileAreaId}/version_sets
45
- * @param {string} projectId
46
- * @param {string} fileAreaId
47
- * @param {object} [params]
48
- * @returns {Promise<object>} VersionSetsListResponse
49
- */
50
- async listFileAreaVersionSets(projectId, fileAreaId, params = {}) {
51
- const response = await this._client.get(
52
- `/2.1/projects/${projectId}/file_areas/${fileAreaId}/version_sets`,
53
- params,
54
- );
55
- return convertToModel(response, VersionSetsListResponseSchema, 'VersionSetsListResponse');
56
- }
57
-
58
- /**
59
- * Browse all files on the given project and given version set.
60
- * GET /3.0/projects/{projectId}/version_sets/{versionSetId}/files
61
- * @param {string} projectId
62
- * @param {string} versionSetId
63
- * @param {object} [params]
64
- * @returns {Promise<object>} FilesListResponse (cross-endpoint reuse of the Files model, matches Python)
65
- */
66
- async listVersionSetFiles(projectId, versionSetId, params = {}) {
67
- const response = await this._client.get(
68
- `/3.0/projects/${projectId}/version_sets/${versionSetId}/files`,
69
- params,
70
- );
71
- return convertToModel(response, FilesListResponseSchema, 'FilesListResponse');
72
- }
73
- }
74
-
75
- module.exports = VersionSetsApi;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- const { convertToModel } = require('../models/convert');
4
- const { WorkPackagesListResponseSchema } = require('../models/workPackages');
5
-
6
- /**
7
- * API methods for work packages on a project.
8
- */
9
- class WorkPackagesApi {
10
- /**
11
- * @param {import('../apiClient')} apiClient
12
- */
13
- constructor(apiClient) {
14
- this._client = apiClient;
15
- }
16
-
17
- /**
18
- * Browse all work packages on the given project.
19
- * GET /1.0/projects/{projectId}/workpackages
20
- * @param {string} projectId
21
- * @param {object} [params]
22
- * @returns {Promise<object>} WorkPackagesListResponse ({ items: WorkPackage[], metadata?, links? })
23
- */
24
- async listWorkPackages(projectId, params = {}) {
25
- const response = await this._client.get(`/1.0/projects/${projectId}/workpackages`, params);
26
- return convertToModel(response, WorkPackagesListResponseSchema, 'WorkPackagesListResponse');
27
- }
28
- }
29
-
30
- module.exports = WorkPackagesApi;
package/src/apiClient.js DELETED
@@ -1,143 +0,0 @@
1
- 'use strict';
2
-
3
- const axios = require('axios');
4
- const { NotFoundError, AuthenticationError, RateLimitError, ApiError } = require('./utils/errors');
5
-
6
- // Load .env file when dotenv is available (optional peer dep)
7
- try {
8
- require('dotenv').config();
9
- } catch (_) { /* dotenv not installed – skip */ }
10
-
11
- /**
12
- * Base HTTP client that attaches the X-API-KEY header to every request.
13
- *
14
- * When *configuration* is omitted the client reads ``DALUX_BASE_URL`` and
15
- * ``DALUX_API_KEY`` from the environment, matching the Python client behaviour.
16
- */
17
- class ApiClient {
18
- /**
19
- * @param {import('./configuration')} [configuration]
20
- */
21
- constructor(configuration) {
22
- if (!configuration) {
23
- const Configuration = require('./configuration');
24
- configuration = new Configuration();
25
- }
26
- this.configuration = configuration;
27
-
28
- this._axios = axios.create({
29
- baseURL: configuration.baseUrl,
30
- headers: {
31
- 'X-API-KEY': configuration.apiKey,
32
- 'Content-Type': 'application/json',
33
- 'Accept': 'application/json',
34
- 'User-Agent': 'dalux-build-js/1.0',
35
- },
36
- });
37
- }
38
-
39
- /**
40
- * Extract a human-readable error detail from an Axios error response.
41
- * @param {import('axios').AxiosResponse} response
42
- * @returns {string}
43
- */
44
- _getErrorDetail(response) {
45
- try {
46
- const data = response.data;
47
- if (Buffer.isBuffer(data) || data instanceof ArrayBuffer) {
48
- return Buffer.from(data).toString('utf8').slice(0, 200);
49
- }
50
- if (data && typeof data === 'object') {
51
- if (data.message) return data.message;
52
- if (data.error) return data.error;
53
- return JSON.stringify(data);
54
- }
55
- return String(data).slice(0, 100);
56
- } catch {
57
- return `HTTP ${response.status}`;
58
- }
59
- }
60
-
61
- /**
62
- * Map an Axios error to the appropriate Dalux error class.
63
- * @param {import('axios').AxiosError} err
64
- * @param {string} path
65
- */
66
- _handleAxiosError(err, path) {
67
- if (err.response) {
68
- const { status } = err.response;
69
- const detail = this._getErrorDetail(err.response);
70
- if (status === 404) throw new NotFoundError(`Resource not found: ${path}`);
71
- if (status === 401) throw new AuthenticationError('Authentication failed');
72
- if (status === 429) throw new RateLimitError('Rate limit exceeded');
73
- throw new ApiError(`API request failed: ${detail}`);
74
- }
75
- throw new ApiError(`Request failed: ${err.message}`);
76
- }
77
-
78
- /**
79
- * Perform a GET request.
80
- * @param {string} path - URL path (e.g. '/5.1/projects')
81
- * @param {object} [params] - Query string parameters
82
- * @param {object} [config] - Extra axios config (e.g. { responseType: 'arraybuffer' } for binary content)
83
- * @returns {Promise<any>} Parsed response body
84
- */
85
- async get(path, params = {}, config = {}) {
86
- try {
87
- const response = await this._axios.get(path, { params, ...config });
88
- return response.data;
89
- } catch (err) {
90
- this._handleAxiosError(err, path);
91
- }
92
- }
93
-
94
- /**
95
- * Perform a POST request.
96
- * @param {string} path
97
- * @param {object} [body]
98
- * @param {object} [params]
99
- * @param {object} [config] - Extra axios config (e.g. custom headers or responseType)
100
- * @returns {Promise<any>}
101
- */
102
- async post(path, body = {}, params = {}, config = {}) {
103
- try {
104
- const response = await this._axios.post(path, body, { params, ...config });
105
- return response.data;
106
- } catch (err) {
107
- this._handleAxiosError(err, path);
108
- }
109
- }
110
-
111
- /**
112
- * Perform a PATCH request.
113
- * @param {string} path
114
- * @param {object} [body]
115
- * @param {object} [params]
116
- * @returns {Promise<any>}
117
- */
118
- async patch(path, body = {}, params = {}) {
119
- try {
120
- const response = await this._axios.patch(path, body, { params });
121
- return response.data;
122
- } catch (err) {
123
- this._handleAxiosError(err, path);
124
- }
125
- }
126
-
127
- /**
128
- * Perform a DELETE request.
129
- * @param {string} path
130
- * @param {object} [params]
131
- * @returns {Promise<any>}
132
- */
133
- async delete(path, params = {}) {
134
- try {
135
- const response = await this._axios.delete(path, { params });
136
- return response.data;
137
- } catch (err) {
138
- this._handleAxiosError(err, path);
139
- }
140
- }
141
- }
142
-
143
- module.exports = ApiClient;