dalux-build-api 1.1.3 → 1.1.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.
@@ -1,59 +1,59 @@
1
- 'use strict';
2
-
3
- /**
4
- * API methods for test plans.
5
- */
6
- class TestPlansApi {
7
- /**
8
- * @param {import('../apiClient')} apiClient
9
- */
10
- constructor(apiClient) {
11
- this._client = apiClient;
12
- }
13
-
14
- /**
15
- * Browse all test plans on the given project.
16
- * GET /1.2/projects/{projectId}/testPlans
17
- * @param {string} projectId
18
- * @param {object} [params]
19
- * @returns {Promise<object>}
20
- */
21
- listTestPlans(projectId, params = {}) {
22
- return this._client.get(`/1.2/projects/${projectId}/testPlans`, params);
23
- }
24
-
25
- /**
26
- * Browse all test plan items on the given project.
27
- * GET /1.1/projects/{projectId}/testPlanItems
28
- * @param {string} projectId
29
- * @param {object} [params]
30
- * @returns {Promise<object>}
31
- */
32
- listTestPlanItems(projectId, params = {}) {
33
- return this._client.get(`/1.1/projects/${projectId}/testPlanItems`, params);
34
- }
35
-
36
- /**
37
- * Browse all test plan item zones on the given project.
38
- * GET /1.1/projects/{projectId}/testPlanItemZones
39
- * @param {string} projectId
40
- * @param {object} [params]
41
- * @returns {Promise<object>}
42
- */
43
- listTestPlanItemZones(projectId, params = {}) {
44
- return this._client.get(`/1.1/projects/${projectId}/testPlanItemZones`, params);
45
- }
46
-
47
- /**
48
- * Browse all test plan registrations on the given project.
49
- * GET /1.1/projects/{projectId}/testPlanRegistrations
50
- * @param {string} projectId
51
- * @param {object} [params]
52
- * @returns {Promise<object>}
53
- */
54
- listTestPlanRegistrations(projectId, params = {}) {
55
- return this._client.get(`/1.1/projects/${projectId}/testPlanRegistrations`, params);
56
- }
57
- }
58
-
59
- module.exports = TestPlansApi;
1
+ 'use strict';
2
+
3
+ /**
4
+ * API methods for test plans.
5
+ */
6
+ class TestPlansApi {
7
+ /**
8
+ * @param {import('../apiClient')} apiClient
9
+ */
10
+ constructor(apiClient) {
11
+ this._client = apiClient;
12
+ }
13
+
14
+ /**
15
+ * Browse all test plans on the given project.
16
+ * GET /1.2/projects/{projectId}/testPlans
17
+ * @param {string} projectId
18
+ * @param {object} [params]
19
+ * @returns {Promise<object>}
20
+ */
21
+ listTestPlans(projectId, params = {}) {
22
+ return this._client.get(`/1.2/projects/${projectId}/testPlans`, params);
23
+ }
24
+
25
+ /**
26
+ * Browse all test plan items on the given project.
27
+ * GET /1.1/projects/{projectId}/testPlanItems
28
+ * @param {string} projectId
29
+ * @param {object} [params]
30
+ * @returns {Promise<object>}
31
+ */
32
+ listTestPlanItems(projectId, params = {}) {
33
+ return this._client.get(`/1.1/projects/${projectId}/testPlanItems`, params);
34
+ }
35
+
36
+ /**
37
+ * Browse all test plan item zones on the given project.
38
+ * GET /1.1/projects/{projectId}/testPlanItemZones
39
+ * @param {string} projectId
40
+ * @param {object} [params]
41
+ * @returns {Promise<object>}
42
+ */
43
+ listTestPlanItemZones(projectId, params = {}) {
44
+ return this._client.get(`/1.1/projects/${projectId}/testPlanItemZones`, params);
45
+ }
46
+
47
+ /**
48
+ * Browse all test plan registrations on the given project.
49
+ * GET /1.1/projects/{projectId}/testPlanRegistrations
50
+ * @param {string} projectId
51
+ * @param {object} [params]
52
+ * @returns {Promise<object>}
53
+ */
54
+ listTestPlanRegistrations(projectId, params = {}) {
55
+ return this._client.get(`/1.1/projects/${projectId}/testPlanRegistrations`, params);
56
+ }
57
+ }
58
+
59
+ module.exports = TestPlansApi;
@@ -1,47 +1,47 @@
1
- 'use strict';
2
-
3
- /**
4
- * API methods for users.
5
- */
6
- class UsersApi {
7
- /**
8
- * @param {import('../apiClient')} apiClient
9
- */
10
- constructor(apiClient) {
11
- this._client = apiClient;
12
- }
13
-
14
- /**
15
- * Get a specific user.
16
- * GET /1.1/users/{userId}
17
- * @param {string} userId
18
- * @returns {Promise<object>}
19
- */
20
- getUser(userId) {
21
- return this._client.get(`/1.1/users/${userId}`);
22
- }
23
-
24
- /**
25
- * Get users on a project.
26
- * GET /1.2/projects/{projectId}/users
27
- * @param {string} projectId
28
- * @param {object} [params]
29
- * @returns {Promise<object>}
30
- */
31
- listProjectUsers(projectId, params = {}) {
32
- return this._client.get(`/1.2/projects/${projectId}/users`, params);
33
- }
34
-
35
- /**
36
- * Get a specific user on a project.
37
- * GET /1.1/projects/{projectId}/users/{userId}
38
- * @param {string} projectId
39
- * @param {string} userId
40
- * @returns {Promise<object>}
41
- */
42
- getProjectUser(projectId, userId) {
43
- return this._client.get(`/1.1/projects/${projectId}/users/${userId}`);
44
- }
45
- }
46
-
47
- module.exports = UsersApi;
1
+ 'use strict';
2
+
3
+ /**
4
+ * API methods for users.
5
+ */
6
+ class UsersApi {
7
+ /**
8
+ * @param {import('../apiClient')} apiClient
9
+ */
10
+ constructor(apiClient) {
11
+ this._client = apiClient;
12
+ }
13
+
14
+ /**
15
+ * Get a specific user.
16
+ * GET /1.1/users/{userId}
17
+ * @param {string} userId
18
+ * @returns {Promise<object>}
19
+ */
20
+ getUser(userId) {
21
+ return this._client.get(`/1.1/users/${userId}`);
22
+ }
23
+
24
+ /**
25
+ * Get users on a project.
26
+ * GET /1.2/projects/{projectId}/users
27
+ * @param {string} projectId
28
+ * @param {object} [params]
29
+ * @returns {Promise<object>}
30
+ */
31
+ listProjectUsers(projectId, params = {}) {
32
+ return this._client.get(`/1.2/projects/${projectId}/users`, params);
33
+ }
34
+
35
+ /**
36
+ * Get a specific user on a project.
37
+ * GET /1.1/projects/{projectId}/users/{userId}
38
+ * @param {string} projectId
39
+ * @param {string} userId
40
+ * @returns {Promise<object>}
41
+ */
42
+ getProjectUser(projectId, userId) {
43
+ return this._client.get(`/1.1/projects/${projectId}/users/${userId}`);
44
+ }
45
+ }
46
+
47
+ module.exports = UsersApi;
@@ -1,67 +1,67 @@
1
- 'use strict';
2
-
3
- /**
4
- * API methods for version sets.
5
- */
6
- class VersionSetsApi {
7
- /**
8
- * @param {import('../apiClient')} apiClient
9
- */
10
- constructor(apiClient) {
11
- this._client = apiClient;
12
- }
13
-
14
- /**
15
- * Retrieve the version sets on the given project.
16
- * GET /2.1/projects/{projectId}/version_sets
17
- * @param {string} projectId
18
- * @param {object} [params]
19
- * @returns {Promise<object>}
20
- */
21
- getVersionSets(projectId, params = {}) {
22
- return this._client.get(`/2.1/projects/${projectId}/version_sets`, params);
23
- }
24
-
25
- /**
26
- * Retrieve a specific version set.
27
- * GET /2.0/projects/{projectId}/version_sets/{versionSetId}
28
- * @param {string} projectId
29
- * @param {string} versionSetId
30
- * @returns {Promise<object>}
31
- */
32
- getVersionSet(projectId, versionSetId) {
33
- return this._client.get(`/2.0/projects/${projectId}/version_sets/${versionSetId}`);
34
- }
35
-
36
- /**
37
- * Browse all version sets on the given file area and project.
38
- * GET /2.1/projects/{projectId}/file_areas/{fileAreaId}/version_sets
39
- * @param {string} projectId
40
- * @param {string} fileAreaId
41
- * @param {object} [params]
42
- * @returns {Promise<object>}
43
- */
44
- listFileAreaVersionSets(projectId, fileAreaId, params = {}) {
45
- return this._client.get(
46
- `/2.1/projects/${projectId}/file_areas/${fileAreaId}/version_sets`,
47
- params,
48
- );
49
- }
50
-
51
- /**
52
- * Browse all files on the given project and given version set.
53
- * GET /3.0/projects/{projectId}/version_sets/{versionSetId}/files
54
- * @param {string} projectId
55
- * @param {string} versionSetId
56
- * @param {object} [params]
57
- * @returns {Promise<object>}
58
- */
59
- listVersionSetFiles(projectId, versionSetId, params = {}) {
60
- return this._client.get(
61
- `/3.0/projects/${projectId}/version_sets/${versionSetId}/files`,
62
- params,
63
- );
64
- }
65
- }
66
-
67
- module.exports = VersionSetsApi;
1
+ 'use strict';
2
+
3
+ /**
4
+ * API methods for version sets.
5
+ */
6
+ class VersionSetsApi {
7
+ /**
8
+ * @param {import('../apiClient')} apiClient
9
+ */
10
+ constructor(apiClient) {
11
+ this._client = apiClient;
12
+ }
13
+
14
+ /**
15
+ * Retrieve the version sets on the given project.
16
+ * GET /2.1/projects/{projectId}/version_sets
17
+ * @param {string} projectId
18
+ * @param {object} [params]
19
+ * @returns {Promise<object>}
20
+ */
21
+ getVersionSets(projectId, params = {}) {
22
+ return this._client.get(`/2.1/projects/${projectId}/version_sets`, params);
23
+ }
24
+
25
+ /**
26
+ * Retrieve a specific version set.
27
+ * GET /2.0/projects/{projectId}/version_sets/{versionSetId}
28
+ * @param {string} projectId
29
+ * @param {string} versionSetId
30
+ * @returns {Promise<object>}
31
+ */
32
+ getVersionSet(projectId, versionSetId) {
33
+ return this._client.get(`/2.0/projects/${projectId}/version_sets/${versionSetId}`);
34
+ }
35
+
36
+ /**
37
+ * Browse all version sets on the given file area and project.
38
+ * GET /2.1/projects/{projectId}/file_areas/{fileAreaId}/version_sets
39
+ * @param {string} projectId
40
+ * @param {string} fileAreaId
41
+ * @param {object} [params]
42
+ * @returns {Promise<object>}
43
+ */
44
+ listFileAreaVersionSets(projectId, fileAreaId, params = {}) {
45
+ return this._client.get(
46
+ `/2.1/projects/${projectId}/file_areas/${fileAreaId}/version_sets`,
47
+ params,
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Browse all files on the given project and given version set.
53
+ * GET /3.0/projects/{projectId}/version_sets/{versionSetId}/files
54
+ * @param {string} projectId
55
+ * @param {string} versionSetId
56
+ * @param {object} [params]
57
+ * @returns {Promise<object>}
58
+ */
59
+ listVersionSetFiles(projectId, versionSetId, params = {}) {
60
+ return this._client.get(
61
+ `/3.0/projects/${projectId}/version_sets/${versionSetId}/files`,
62
+ params,
63
+ );
64
+ }
65
+ }
66
+
67
+ module.exports = VersionSetsApi;
@@ -1,26 +1,26 @@
1
- 'use strict';
2
-
3
- /**
4
- * API methods for work packages on a project.
5
- */
6
- class WorkPackagesApi {
7
- /**
8
- * @param {import('../apiClient')} apiClient
9
- */
10
- constructor(apiClient) {
11
- this._client = apiClient;
12
- }
13
-
14
- /**
15
- * Browse all work packages on the given project.
16
- * GET /1.0/projects/{projectId}/workpackages
17
- * @param {string} projectId
18
- * @param {object} [params]
19
- * @returns {Promise<object>}
20
- */
21
- listWorkPackages(projectId, params = {}) {
22
- return this._client.get(`/1.0/projects/${projectId}/workpackages`, params);
23
- }
24
- }
25
-
26
- module.exports = WorkPackagesApi;
1
+ 'use strict';
2
+
3
+ /**
4
+ * API methods for work packages on a project.
5
+ */
6
+ class WorkPackagesApi {
7
+ /**
8
+ * @param {import('../apiClient')} apiClient
9
+ */
10
+ constructor(apiClient) {
11
+ this._client = apiClient;
12
+ }
13
+
14
+ /**
15
+ * Browse all work packages on the given project.
16
+ * GET /1.0/projects/{projectId}/workpackages
17
+ * @param {string} projectId
18
+ * @param {object} [params]
19
+ * @returns {Promise<object>}
20
+ */
21
+ listWorkPackages(projectId, params = {}) {
22
+ return this._client.get(`/1.0/projects/${projectId}/workpackages`, params);
23
+ }
24
+ }
25
+
26
+ module.exports = WorkPackagesApi;
package/src/apiClient.js CHANGED
@@ -1,75 +1,139 @@
1
- 'use strict';
2
-
3
- const axios = require('axios');
4
-
5
- /**
6
- * Base HTTP client that attaches the X-API-KEY header to every request.
7
- */
8
- class ApiClient {
9
- /**
10
- * @param {import('./configuration')} configuration
11
- */
12
- constructor(configuration) {
13
- if (!configuration) {
14
- throw new Error('configuration is required');
15
- }
16
- this.configuration = configuration;
17
-
18
- this._axios = axios.create({
19
- baseURL: configuration.baseUrl,
20
- headers: {
21
- 'X-API-KEY': configuration.apiKey,
22
- 'Content-Type': 'application/json',
23
- },
24
- });
25
- }
26
-
27
- /**
28
- * Perform a GET request.
29
- * @param {string} path - URL path (e.g. '/5.1/projects')
30
- * @param {object} [params] - Query string parameters
31
- * @returns {Promise<any>} Parsed response body
32
- */
33
- async get(path, params = {}) {
34
- const response = await this._axios.get(path, { params });
35
- return response.data;
36
- }
37
-
38
- /**
39
- * Perform a POST request.
40
- * @param {string} path
41
- * @param {object} [body]
42
- * @param {object} [params]
43
- * @param {object} [config] - Extra axios config (e.g. custom headers or responseType)
44
- * @returns {Promise<any>}
45
- */
46
- async post(path, body = {}, params = {}, config = {}) {
47
- const response = await this._axios.post(path, body, { params, ...config });
48
- return response.data;
49
- }
50
-
51
- /**
52
- * Perform a PATCH request.
53
- * @param {string} path
54
- * @param {object} [body]
55
- * @param {object} [params]
56
- * @returns {Promise<any>}
57
- */
58
- async patch(path, body = {}, params = {}) {
59
- const response = await this._axios.patch(path, body, { params });
60
- return response.data;
61
- }
62
-
63
- /**
64
- * Perform a DELETE request.
65
- * @param {string} path
66
- * @param {object} [params]
67
- * @returns {Promise<any>}
68
- */
69
- async delete(path, params = {}) {
70
- const response = await this._axios.delete(path, { params });
71
- return response.data;
72
- }
73
- }
74
-
75
- module.exports = ApiClient;
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 (data && typeof data === 'object') {
48
+ if (data.message) return data.message;
49
+ if (data.error) return data.error;
50
+ return JSON.stringify(data);
51
+ }
52
+ return String(data).slice(0, 100);
53
+ } catch {
54
+ return `HTTP ${response.status}`;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Map an Axios error to the appropriate Dalux error class.
60
+ * @param {import('axios').AxiosError} err
61
+ * @param {string} path
62
+ */
63
+ _handleAxiosError(err, path) {
64
+ if (err.response) {
65
+ const { status } = err.response;
66
+ const detail = this._getErrorDetail(err.response);
67
+ if (status === 404) throw new NotFoundError(`Resource not found: ${path}`);
68
+ if (status === 401) throw new AuthenticationError('Authentication failed');
69
+ if (status === 429) throw new RateLimitError('Rate limit exceeded');
70
+ throw new ApiError(`API request failed: ${detail}`);
71
+ }
72
+ throw new ApiError(`Request failed: ${err.message}`);
73
+ }
74
+
75
+ /**
76
+ * Perform a GET request.
77
+ * @param {string} path - URL path (e.g. '/5.1/projects')
78
+ * @param {object} [params] - Query string parameters
79
+ * @returns {Promise<any>} Parsed response body
80
+ */
81
+ async get(path, params = {}) {
82
+ try {
83
+ const response = await this._axios.get(path, { params });
84
+ return response.data;
85
+ } catch (err) {
86
+ this._handleAxiosError(err, path);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Perform a POST request.
92
+ * @param {string} path
93
+ * @param {object} [body]
94
+ * @param {object} [params]
95
+ * @param {object} [config] - Extra axios config (e.g. custom headers or responseType)
96
+ * @returns {Promise<any>}
97
+ */
98
+ async post(path, body = {}, params = {}, config = {}) {
99
+ try {
100
+ const response = await this._axios.post(path, body, { params, ...config });
101
+ return response.data;
102
+ } catch (err) {
103
+ this._handleAxiosError(err, path);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Perform a PATCH request.
109
+ * @param {string} path
110
+ * @param {object} [body]
111
+ * @param {object} [params]
112
+ * @returns {Promise<any>}
113
+ */
114
+ async patch(path, body = {}, params = {}) {
115
+ try {
116
+ const response = await this._axios.patch(path, body, { params });
117
+ return response.data;
118
+ } catch (err) {
119
+ this._handleAxiosError(err, path);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Perform a DELETE request.
125
+ * @param {string} path
126
+ * @param {object} [params]
127
+ * @returns {Promise<any>}
128
+ */
129
+ async delete(path, params = {}) {
130
+ try {
131
+ const response = await this._axios.delete(path, { params });
132
+ return response.data;
133
+ } catch (err) {
134
+ this._handleAxiosError(err, path);
135
+ }
136
+ }
137
+ }
138
+
139
+ module.exports = ApiClient;