dalux-build-api 1.0.4 → 1.1.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.
@@ -1,87 +1,161 @@
1
- 'use strict';
2
-
3
- /**
4
- * API methods for tasks, approvals, safety issues, observations and good practices.
5
- */
6
- class TasksApi {
7
- /**
8
- * @param {import('../apiClient')} apiClient
9
- */
10
- constructor(apiClient) {
11
- this._client = apiClient;
12
- }
13
-
14
- /**
15
- * Retrieve tasks, approvals, safety issues, safety observations and good practices on a project.
16
- * GET /5.2/projects/{projectId}/tasks
17
- * @param {string} projectId
18
- * @param {object} [params] - Optional filters (e.g. updatedAfter, status, typeFilter)
19
- * @returns {Promise<object>}
20
- */
21
- getProjectTasks(projectId, params = {}) {
22
- return this._client.get(`/5.2/projects/${projectId}/tasks`, params);
23
- }
24
-
25
- /**
26
- * Retrieve all tasks on a project by following bookmark pagination automatically.
27
- * Combines all pages into a single array of items.
28
- * @param {string} projectId
29
- * @param {object} [params] - Optional filters (e.g. updatedAfter, status, typeFilter)
30
- * @returns {Promise<object[]>} All task items across all pages
31
- */
32
- async getAllProjectTasks(projectId, params = {}) {
33
- const allItems = [];
34
- let currentParams = { ...params };
35
- let hasNextPage = true;
36
-
37
- while (hasNextPage) {
38
- const response = await this._client.get(`/5.2/projects/${projectId}/tasks`, currentParams);
39
- if (Array.isArray(response.items)) {
40
- allItems.push(...response.items);
41
- }
42
- const nextLink = (response.links || []).find(l => l.rel === 'nextPage');
43
- if (nextLink) {
44
- const bookmark = new URL(nextLink.href).searchParams.get('bookmark');
45
- currentParams = { ...params, bookmark };
46
- } else {
47
- hasNextPage = false;
48
- }
49
- }
50
- return allItems;
51
- }
52
-
53
- /**
54
- * Retrieve a specific task/approval/safety issue/safety observation/good practice.
55
- * GET /3.3/projects/{projectId}/tasks/{taskId}
56
- * @param {string} projectId
57
- * @param {string} taskId
58
- * @returns {Promise<object>}
59
- */
60
- getTask(projectId, taskId) {
61
- return this._client.get(`/3.3/projects/${projectId}/tasks/${taskId}`);
62
- }
63
-
64
- /**
65
- * Retrieve task changes on a project in incremental updates.
66
- * GET /2.2/projects/{projectId}/tasks/changes
67
- * @param {string} projectId
68
- * @param {object} [params] - Optional filters (e.g. updatedAfter)
69
- * @returns {Promise<object>}
70
- */
71
- getProjectTaskChanges(projectId, params = {}) {
72
- return this._client.get(`/2.2/projects/${projectId}/tasks/changes`, params);
73
- }
74
-
75
- /**
76
- * Retrieve attachments on tasks on a project.
77
- * GET /1.1/projects/{projectId}/tasks/attachments
78
- * @param {string} projectId
79
- * @param {object} [params] - Optional filters (e.g. updatedAfter)
80
- * @returns {Promise<object>}
81
- */
82
- getProjectTaskAttachments(projectId, params = {}) {
83
- return this._client.get(`/1.1/projects/${projectId}/tasks/attachments`, params);
84
- }
85
- }
86
-
87
- module.exports = TasksApi;
1
+ 'use strict';
2
+
3
+ /**
4
+ * Build query params for GET /5.2/projects/.../tasks (OData).
5
+ * If params contains typeId and no $filter, expands to
6
+ * $filter=data/type/typeId eq '<typeId>'
7
+ * Single quotes in typeId are escaped as '' per OData. If $filter is set,
8
+ * typeId is still omitted from the outgoing query (not merged).
9
+ * @param {object} [params]
10
+ * @returns {object}
11
+ */
12
+ function normalizeTaskParams(params = {}) {
13
+ const normalized = { ...params };
14
+ const typeId = normalized.typeId;
15
+ delete normalized.typeId;
16
+ if (typeId != null && normalized.$filter === undefined) {
17
+ const escaped = String(typeId).replace(/'/g, "''");
18
+ normalized.$filter = `data/type/typeId eq '${escaped}'`;
19
+ }
20
+ return normalized;
21
+ }
22
+
23
+ /**
24
+ * API methods for tasks, approvals, safety issues, observations and good practices.
25
+ */
26
+ class TasksApi {
27
+ /**
28
+ * @param {import('../apiClient')} apiClient
29
+ */
30
+ constructor(apiClient) {
31
+ this._client = apiClient;
32
+ }
33
+
34
+ /**
35
+ * Retrieve tasks, approvals, safety issues, safety observations and good practices on a project.
36
+ * GET /5.2/projects/{projectId}/tasks
37
+ * @param {string} projectId
38
+ * @param {object} [params] - Optional filters (e.g. updatedAfter). Pass typeId as shorthand for
39
+ * OData $filter on task type, or pass $filter (and other OData options) directly.
40
+ * @returns {Promise<object>}
41
+ */
42
+ getProjectTasks(projectId, params = {}) {
43
+ return this._client.get(`/5.2/projects/${projectId}/tasks`, normalizeTaskParams(params));
44
+ }
45
+
46
+ /**
47
+ * Retrieve all tasks on a project by following bookmark pagination automatically.
48
+ * Matches Python client behaviour: uses metadata.totalRemainingItems when present;
49
+ * otherwise uses metadata.totalItems across pages as a ceiling so pagination cannot run forever.
50
+ * @param {string} projectId
51
+ * @param {object} [params] - Optional filters / OData (typeId shorthand supported).
52
+ * @param {boolean} [verbose=false] - Log progress to console.
53
+ * @returns {Promise<object[]>} All task items across all pages
54
+ */
55
+ async getAllProjectTasks(projectId, params = {}, verbose = false) {
56
+ const allItems = [];
57
+ const baseParams = normalizeTaskParams(params);
58
+ let currentParams = { ...baseParams };
59
+ let hasNextPage = true;
60
+ /** @type {number|null} */
61
+ let tasksItemsCeiling = null;
62
+
63
+ while (hasNextPage) {
64
+ const response = await this._client.get(`/5.2/projects/${projectId}/tasks`, currentParams);
65
+ const items = Array.isArray(response.items) ? response.items : [];
66
+ if (items.length) {
67
+ allItems.push(...items);
68
+ }
69
+ const meta = (response && response.metadata) || {};
70
+ let remaining;
71
+ let useFilesRemainingStop;
72
+
73
+ if (Object.prototype.hasOwnProperty.call(meta, 'totalRemainingItems')) {
74
+ remaining = Number(meta.totalRemainingItems);
75
+ useFilesRemainingStop = true;
76
+ } else if (Object.prototype.hasOwnProperty.call(meta, 'totalItems')) {
77
+ const ti = Number(meta.totalItems);
78
+ tasksItemsCeiling = Math.max(tasksItemsCeiling || 0, ti);
79
+ remaining = ti;
80
+ useFilesRemainingStop = false;
81
+ } else {
82
+ remaining = 0;
83
+ useFilesRemainingStop = true;
84
+ }
85
+
86
+ const nextLink = (response.links || []).find((l) => l.rel === 'nextPage');
87
+ const nextHref = nextLink ? nextLink.href : null;
88
+
89
+ if (verbose) {
90
+ const nextPart = nextHref ? ` next: ${nextHref}` : ' next: (none)';
91
+ if (useFilesRemainingStop) {
92
+ console.log(`Retrieved ${allItems.length} tasks so far, ${remaining} remaining...${nextPart}`);
93
+ } else if (tasksItemsCeiling != null) {
94
+ const remV = Math.max(0, tasksItemsCeiling - allItems.length);
95
+ console.log(`Retrieved ${allItems.length} tasks so far, ${remV} remaining...${nextPart}`);
96
+ } else {
97
+ console.log(`Retrieved ${allItems.length} tasks so far, ${remaining} remaining...${nextPart}`);
98
+ }
99
+ }
100
+
101
+ if (!items.length) {
102
+ hasNextPage = false;
103
+ } else if (useFilesRemainingStop && remaining === 0) {
104
+ hasNextPage = false;
105
+ } else if (
106
+ !useFilesRemainingStop &&
107
+ tasksItemsCeiling != null &&
108
+ allItems.length >= tasksItemsCeiling
109
+ ) {
110
+ hasNextPage = false;
111
+ } else if (nextLink) {
112
+ const bookmark = new URL(nextLink.href).searchParams.get('bookmark');
113
+ currentParams = { ...baseParams, bookmark };
114
+ } else {
115
+ hasNextPage = false;
116
+ }
117
+ }
118
+
119
+ if (verbose) {
120
+ console.log(`Done. Total tasks retrieved: ${allItems.length}`);
121
+ }
122
+ return allItems;
123
+ }
124
+
125
+ /**
126
+ * Retrieve a specific task/approval/safety issue/safety observation/good practice.
127
+ * GET /3.3/projects/{projectId}/tasks/{taskId}
128
+ * @param {string} projectId
129
+ * @param {string} taskId
130
+ * @returns {Promise<object>}
131
+ */
132
+ getTask(projectId, taskId) {
133
+ return this._client.get(`/3.3/projects/${projectId}/tasks/${taskId}`);
134
+ }
135
+
136
+ /**
137
+ * Retrieve task changes on a project in incremental updates.
138
+ * GET /2.2/projects/{projectId}/tasks/changes
139
+ * @param {string} projectId
140
+ * @param {object} [params] - Optional filters (e.g. updatedAfter)
141
+ * @returns {Promise<object>}
142
+ */
143
+ getProjectTaskChanges(projectId, params = {}) {
144
+ return this._client.get(`/2.2/projects/${projectId}/tasks/changes`, params);
145
+ }
146
+
147
+ /**
148
+ * Retrieve attachments on tasks on a project.
149
+ * GET /1.1/projects/{projectId}/tasks/attachments
150
+ * @param {string} projectId
151
+ * @param {object} [params] - Optional filters (e.g. updatedAfter)
152
+ * @returns {Promise<object>}
153
+ */
154
+ getProjectTaskAttachments(projectId, params = {}) {
155
+ return this._client.get(`/1.1/projects/${projectId}/tasks/attachments`, params);
156
+ }
157
+ }
158
+
159
+ TasksApi.normalizeTaskParams = normalizeTaskParams;
160
+
161
+ module.exports = TasksApi;
@@ -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;