dalux-build-api 1.1.5 → 2.0.1
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.
- package/README.md +257 -187
- package/package.json +11 -4
- package/src/api/CompaniesApi.js +19 -12
- package/src/api/CompanyCatalogApi.js +22 -18
- package/src/api/FileAreasApi.js +14 -12
- package/src/api/FilesApi.js +11 -7
- package/src/api/FoldersApi.js +14 -12
- package/src/api/FormsApi.js +11 -6
- package/src/api/InspectionPlansApi.js +87 -9
- package/src/api/ProjectsApi.js +22 -18
- package/src/api/TasksApi.js +25 -10
- package/src/api/TestPlansApi.js +87 -9
- package/src/api/UsersApi.js +11 -6
- package/src/api/VersionSetsApi.js +20 -12
- package/src/api/WorkPackagesApi.js +7 -3
- package/src/browser.js +84 -0
- package/src/index.js +5 -0
- package/src/models/common.js +22 -0
- package/src/models/companies/index.js +14 -0
- package/src/models/companyCatalog/index.js +19 -0
- package/src/models/convert.js +44 -0
- package/src/models/fileAreas/index.js +20 -0
- package/src/models/fileRevisions/index.js +12 -0
- package/src/models/fileUpload/index.js +12 -0
- package/src/models/files/index.js +97 -0
- package/src/models/folders/index.js +20 -0
- package/src/models/forms/index.js +19 -0
- package/src/models/helpers.js +62 -0
- package/src/models/index.js +178 -0
- package/src/models/inspectionPlans/index.js +61 -0
- package/src/models/projectTemplates/index.js +11 -0
- package/src/models/projects/index.js +57 -0
- package/src/models/tasks/index.js +105 -0
- package/src/models/testPlans/index.js +61 -0
- package/src/models/users/index.js +29 -0
- package/src/models/versionSets/index.js +22 -0
- package/src/models/workPackages/index.js +19 -0
- package/src/next.js +89 -0
- package/LICENSE +0 -21
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dalux-build-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Node.js client for the Dalux Build API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.js",
|
|
8
|
+
"./browser": "./src/browser.js",
|
|
9
|
+
"./next": "./src/next.js"
|
|
10
|
+
},
|
|
6
11
|
"files": [
|
|
7
12
|
"src",
|
|
8
13
|
"README.md"
|
|
@@ -24,17 +29,19 @@
|
|
|
24
29
|
"license": "MIT",
|
|
25
30
|
"repository": {
|
|
26
31
|
"type": "git",
|
|
27
|
-
"url": "git+https://github.com/bruadam/dalux-build.git"
|
|
32
|
+
"url": "git+https://github.com/bruadam/dalux-build.git",
|
|
33
|
+
"directory": "javascript"
|
|
28
34
|
},
|
|
29
35
|
"bugs": {
|
|
30
36
|
"url": "https://github.com/bruadam/dalux-build/issues"
|
|
31
37
|
},
|
|
32
|
-
"homepage": "https://github.com/bruadam/dalux-build#readme",
|
|
38
|
+
"homepage": "https://github.com/bruadam/dalux-build/tree/main/javascript#readme",
|
|
33
39
|
"publishConfig": {
|
|
34
40
|
"access": "public"
|
|
35
41
|
},
|
|
36
42
|
"dependencies": {
|
|
37
|
-
"axios": "^1.7.7"
|
|
43
|
+
"axios": "^1.7.7",
|
|
44
|
+
"zod": "^3.23.8"
|
|
38
45
|
},
|
|
39
46
|
"devDependencies": {
|
|
40
47
|
"axios-mock-adapter": "^2.1.0",
|
package/src/api/CompaniesApi.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { convertToModel } = require('../models/convert');
|
|
4
|
+
const { CompaniesListResponseSchema, CompanyResponseSchema } = require('../models/companies');
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* API methods for managing companies on a project.
|
|
5
8
|
*/
|
|
@@ -16,10 +19,11 @@ class CompaniesApi {
|
|
|
16
19
|
* GET /3.1/projects/{projectId}/companies
|
|
17
20
|
* @param {string} projectId
|
|
18
21
|
* @param {object} [params]
|
|
19
|
-
* @returns {Promise<object>}
|
|
22
|
+
* @returns {Promise<object>} CompaniesListResponse ({ items: ProjectCompany[], metadata?, links? })
|
|
20
23
|
*/
|
|
21
|
-
listProjectCompanies(projectId, params = {}) {
|
|
22
|
-
|
|
24
|
+
async listProjectCompanies(projectId, params = {}) {
|
|
25
|
+
const response = await this._client.get(`/3.1/projects/${projectId}/companies`, params);
|
|
26
|
+
return convertToModel(response, CompaniesListResponseSchema, 'CompaniesListResponse');
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -27,10 +31,11 @@ class CompaniesApi {
|
|
|
27
31
|
* GET /3.0/projects/{projectId}/companies/{companyId}
|
|
28
32
|
* @param {string} projectId
|
|
29
33
|
* @param {string} companyId
|
|
30
|
-
* @returns {Promise<object>}
|
|
34
|
+
* @returns {Promise<object>} CompanyResponse ({ data: ProjectCompany, links? })
|
|
31
35
|
*/
|
|
32
|
-
getProjectCompany(projectId, companyId) {
|
|
33
|
-
|
|
36
|
+
async getProjectCompany(projectId, companyId) {
|
|
37
|
+
const response = await this._client.get(`/3.0/projects/${projectId}/companies/${companyId}`);
|
|
38
|
+
return convertToModel(response, CompanyResponseSchema, 'CompanyResponse');
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
/**
|
|
@@ -38,10 +43,11 @@ class CompaniesApi {
|
|
|
38
43
|
* POST /3.1/projects/{projectId}/companies
|
|
39
44
|
* @param {string} projectId
|
|
40
45
|
* @param {object} body
|
|
41
|
-
* @returns {Promise<object>}
|
|
46
|
+
* @returns {Promise<object>} CompanyResponse
|
|
42
47
|
*/
|
|
43
|
-
createProjectCompany(projectId, body) {
|
|
44
|
-
|
|
48
|
+
async createProjectCompany(projectId, body) {
|
|
49
|
+
const response = await this._client.post(`/3.1/projects/${projectId}/companies`, body);
|
|
50
|
+
return convertToModel(response, CompanyResponseSchema, 'CompanyResponse');
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -50,10 +56,11 @@ class CompaniesApi {
|
|
|
50
56
|
* @param {string} projectId
|
|
51
57
|
* @param {string} companyId
|
|
52
58
|
* @param {object} body
|
|
53
|
-
* @returns {Promise<object>}
|
|
59
|
+
* @returns {Promise<object>} CompanyResponse
|
|
54
60
|
*/
|
|
55
|
-
updateProjectCompany(projectId, companyId, body) {
|
|
56
|
-
|
|
61
|
+
async updateProjectCompany(projectId, companyId, body) {
|
|
62
|
+
const response = await this._client.patch(`/3.0/projects/${projectId}/companies/${companyId}`, body);
|
|
63
|
+
return convertToModel(response, CompanyResponseSchema, 'CompanyResponse');
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { findByField } = require('../utils/search');
|
|
4
|
+
const { convertToModel } = require('../models/convert');
|
|
5
|
+
const { CompaniesListResponseSchema, CompanyResponseSchema } = require('../models/companies');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* API methods for the company catalog.
|
|
5
9
|
*/
|
|
@@ -15,30 +19,33 @@ class CompanyCatalogApi {
|
|
|
15
19
|
* Get companies registered in the company catalog.
|
|
16
20
|
* GET /2.2/companyCatalog
|
|
17
21
|
* @param {object} [params]
|
|
18
|
-
* @returns {Promise<object>}
|
|
22
|
+
* @returns {Promise<object>} CompaniesListResponse ({ items: ProjectCompany[], metadata?, links? })
|
|
19
23
|
*/
|
|
20
|
-
getCompanies(params = {}) {
|
|
21
|
-
|
|
24
|
+
async getCompanies(params = {}) {
|
|
25
|
+
const response = await this._client.get('/2.2/companyCatalog', params);
|
|
26
|
+
return convertToModel(response, CompaniesListResponseSchema, 'CompaniesListResponse');
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
30
|
* Get a specific company from the catalog.
|
|
26
31
|
* GET /1.2/companyCatalog/{catalogCompanyId}
|
|
27
32
|
* @param {string} catalogCompanyId
|
|
28
|
-
* @returns {Promise<object>}
|
|
33
|
+
* @returns {Promise<object>} CompanyResponse ({ data: ProjectCompany, links? })
|
|
29
34
|
*/
|
|
30
|
-
getCompany(catalogCompanyId) {
|
|
31
|
-
|
|
35
|
+
async getCompany(catalogCompanyId) {
|
|
36
|
+
const response = await this._client.get(`/1.2/companyCatalog/${catalogCompanyId}`);
|
|
37
|
+
return convertToModel(response, CompanyResponseSchema, 'CompanyResponse');
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
41
|
* Add a company to the catalog.
|
|
36
42
|
* POST /2.2/companyCatalog
|
|
37
43
|
* @param {object} body
|
|
38
|
-
* @returns {Promise<object>}
|
|
44
|
+
* @returns {Promise<object>} CompanyResponse
|
|
39
45
|
*/
|
|
40
|
-
createCompany(body) {
|
|
41
|
-
|
|
46
|
+
async createCompany(body) {
|
|
47
|
+
const response = await this._client.post('/2.2/companyCatalog', body);
|
|
48
|
+
return convertToModel(response, CompanyResponseSchema, 'CompanyResponse');
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
/**
|
|
@@ -46,10 +53,11 @@ class CompanyCatalogApi {
|
|
|
46
53
|
* PATCH /2.1/companyCatalog/{catalogCompanyId}
|
|
47
54
|
* @param {string} catalogCompanyId
|
|
48
55
|
* @param {object} body
|
|
49
|
-
* @returns {Promise<object>}
|
|
56
|
+
* @returns {Promise<object>} CompanyResponse
|
|
50
57
|
*/
|
|
51
|
-
updateCompany(catalogCompanyId, body) {
|
|
52
|
-
|
|
58
|
+
async updateCompany(catalogCompanyId, body) {
|
|
59
|
+
const response = await this._client.patch(`/2.1/companyCatalog/${catalogCompanyId}`, body);
|
|
60
|
+
return convertToModel(response, CompanyResponseSchema, 'CompanyResponse');
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
/**
|
|
@@ -110,15 +118,11 @@ class CompanyCatalogApi {
|
|
|
110
118
|
* @returns {Promise<string|null>} The catalogCompanyId, or null if not found.
|
|
111
119
|
*/
|
|
112
120
|
async getCompanyByName(companyName) {
|
|
113
|
-
const { findByField } = require('../utils/search');
|
|
114
121
|
const response = await this.getCompanies();
|
|
115
122
|
const items = (response && response.items) || [];
|
|
116
|
-
const company =
|
|
117
|
-
findByField(items, 'companyName', companyName, (x) => x.data || x) ||
|
|
118
|
-
findByField(items, 'name', companyName, (x) => x.data || x);
|
|
123
|
+
const company = findByField(items, 'name', companyName);
|
|
119
124
|
if (!company) return null;
|
|
120
|
-
|
|
121
|
-
return data.catalogCompanyId || data.id || null;
|
|
125
|
+
return company.catalogCompanyId || null;
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
128
|
|
package/src/api/FileAreasApi.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { findByField } = require('../utils/search');
|
|
4
|
+
const { convertToModel } = require('../models/convert');
|
|
5
|
+
const { FileAreaSchema, FileAreasListResponseSchema } = require('../models/fileAreas');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* API methods for file areas on a project.
|
|
5
9
|
*/
|
|
@@ -16,10 +20,11 @@ class FileAreasApi {
|
|
|
16
20
|
* GET /5.1/projects/{projectId}/file_areas
|
|
17
21
|
* @param {string} projectId
|
|
18
22
|
* @param {object} [params]
|
|
19
|
-
* @returns {Promise<object>}
|
|
23
|
+
* @returns {Promise<object>} FileAreasListResponse ({ items: FileArea[], metadata?, links? })
|
|
20
24
|
*/
|
|
21
|
-
getFileAreas(projectId, params = {}) {
|
|
22
|
-
|
|
25
|
+
async getFileAreas(projectId, params = {}) {
|
|
26
|
+
const response = await this._client.get(`/5.1/projects/${projectId}/file_areas`, params);
|
|
27
|
+
return convertToModel(response, FileAreasListResponseSchema, 'FileAreasListResponse');
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
/**
|
|
@@ -27,10 +32,11 @@ class FileAreasApi {
|
|
|
27
32
|
* GET /1.0/projects/{projectId}/file_areas/{fileAreaId}
|
|
28
33
|
* @param {string} projectId
|
|
29
34
|
* @param {string} fileAreaId
|
|
30
|
-
* @returns {Promise<object>}
|
|
35
|
+
* @returns {Promise<object>} FileArea (not wrapped in a data envelope, matches Python)
|
|
31
36
|
*/
|
|
32
|
-
getFileArea(projectId, fileAreaId) {
|
|
33
|
-
|
|
37
|
+
async getFileArea(projectId, fileAreaId) {
|
|
38
|
+
const response = await this._client.get(`/1.0/projects/${projectId}/file_areas/${fileAreaId}`);
|
|
39
|
+
return convertToModel(response, FileAreaSchema, 'FileArea');
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
@@ -40,15 +46,11 @@ class FileAreasApi {
|
|
|
40
46
|
* @returns {Promise<string|null>} The fileAreaId, or null if not found.
|
|
41
47
|
*/
|
|
42
48
|
async getFileAreaByName(projectId, fileAreaName) {
|
|
43
|
-
const { findByField } = require('../utils/search');
|
|
44
49
|
const response = await this.getFileAreas(projectId);
|
|
45
50
|
const items = (response && response.items) || [];
|
|
46
|
-
const area =
|
|
47
|
-
findByField(items, 'fileAreaName', fileAreaName, (x) => x.data || x) ||
|
|
48
|
-
findByField(items, 'name', fileAreaName, (x) => x.data || x);
|
|
51
|
+
const area = findByField(items, 'fileAreaName', fileAreaName);
|
|
49
52
|
if (!area) return null;
|
|
50
|
-
|
|
51
|
-
return data.fileAreaId || data.id || null;
|
|
53
|
+
return area.fileAreaId || null;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
|
package/src/api/FilesApi.js
CHANGED
|
@@ -7,6 +7,8 @@ const axios = require('axios');
|
|
|
7
7
|
const { findByField, findAllByField } = require('../utils/search');
|
|
8
8
|
const { resolveFolderIdFromNamedPath } = require('../utils/pathResolver');
|
|
9
9
|
const { validateProjectId, validateFileAreaId, validateFolderId } = require('../utils/validation');
|
|
10
|
+
const { convertToModel, convertToModelList } = require('../models/convert');
|
|
11
|
+
const { FileSchema, FileResponseSchema, FilesListResponseSchema } = require('../models/files');
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* API methods for files within a file area.
|
|
@@ -24,14 +26,15 @@ class FilesApi {
|
|
|
24
26
|
* GET /6.1/projects/{projectId}/file_areas/{fileAreaId}/files
|
|
25
27
|
* @param {string} projectId
|
|
26
28
|
* @param {string} fileAreaId
|
|
27
|
-
* @param {object} [params] - Optional params
|
|
29
|
+
* @param {object} [params] - Optional documented params such as includeProperties. The files endpoint does not support OData $filter.
|
|
28
30
|
* @returns {Promise<object>}
|
|
29
31
|
*/
|
|
30
|
-
listFiles(projectId, fileAreaId, params = {}) {
|
|
31
|
-
|
|
32
|
+
async listFiles(projectId, fileAreaId, params = {}) {
|
|
33
|
+
const response = await this._client.get(
|
|
32
34
|
`/6.1/projects/${projectId}/file_areas/${fileAreaId}/files`,
|
|
33
35
|
params,
|
|
34
36
|
);
|
|
37
|
+
return convertToModel(response, FilesListResponseSchema, 'FilesListResponse');
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -75,7 +78,7 @@ class FilesApi {
|
|
|
75
78
|
if (verbose) {
|
|
76
79
|
console.log(`Done. Total files retrieved: ${allItems.length}`);
|
|
77
80
|
}
|
|
78
|
-
return allItems;
|
|
81
|
+
return convertToModelList(allItems, FileSchema, 'File');
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
/**
|
|
@@ -208,9 +211,10 @@ class FilesApi {
|
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
// ID-based lookup (original behaviour)
|
|
211
|
-
const
|
|
214
|
+
const rawResponse = await this._client.get(
|
|
212
215
|
`/5.0/projects/${projectId}/file_areas/${fileAreaIdOrPath}/files/${fileId}`,
|
|
213
216
|
);
|
|
217
|
+
const fileInfo = convertToModel(rawResponse, FileResponseSchema, 'FileResponse');
|
|
214
218
|
if (options.download && fileInfo && fileInfo.data && fileInfo.data.downloadLink) {
|
|
215
219
|
const name = fileInfo.data.fileName || fileId;
|
|
216
220
|
const downloadedPath = await this.downloadFileFromLink(
|
|
@@ -538,11 +542,11 @@ class FilesApi {
|
|
|
538
542
|
const question = (prompt) => new Promise((resolve) => rl.question(prompt, resolve));
|
|
539
543
|
|
|
540
544
|
function getFid(f) {
|
|
541
|
-
const d = f.data || {};
|
|
545
|
+
const d = f.data || f || {};
|
|
542
546
|
return d.id || d.fileId || null;
|
|
543
547
|
}
|
|
544
548
|
function getFname(f) {
|
|
545
|
-
return (f.data || {}).fileName || '<unknown>';
|
|
549
|
+
return (f.data || f || {}).fileName || '<unknown>';
|
|
546
550
|
}
|
|
547
551
|
function hasContent(node) {
|
|
548
552
|
if (node.files.length) return true;
|
package/src/api/FoldersApi.js
CHANGED
|
@@ -4,6 +4,8 @@ const { paginate } = require('../utils/pagination');
|
|
|
4
4
|
const { findByField } = require('../utils/search');
|
|
5
5
|
const { validateProjectId, validateFileAreaId } = require('../utils/validation');
|
|
6
6
|
const { resolveFolderIdFromNamedPath } = require('../utils/pathResolver');
|
|
7
|
+
const { convertToModel, convertToModelList } = require('../models/convert');
|
|
8
|
+
const { FolderSchema, FolderResponseSchema, FoldersListResponseSchema } = require('../models/folders');
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* API methods for folders within a file area.
|
|
@@ -24,11 +26,12 @@ class FoldersApi {
|
|
|
24
26
|
* @param {object} [params]
|
|
25
27
|
* @returns {Promise<object>}
|
|
26
28
|
*/
|
|
27
|
-
listFolders(projectId, fileAreaId, params = {}) {
|
|
28
|
-
|
|
29
|
+
async listFolders(projectId, fileAreaId, params = {}) {
|
|
30
|
+
const response = await this._client.get(
|
|
29
31
|
`/5.1/projects/${projectId}/file_areas/${fileAreaId}/folders`,
|
|
30
32
|
params,
|
|
31
33
|
);
|
|
34
|
+
return convertToModel(response, FoldersListResponseSchema, 'FoldersListResponse');
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
@@ -43,7 +46,8 @@ class FoldersApi {
|
|
|
43
46
|
validateProjectId(projectId);
|
|
44
47
|
validateFileAreaId(fileAreaId);
|
|
45
48
|
const endpoint = `/5.1/projects/${projectId}/file_areas/${fileAreaId}/folders`;
|
|
46
|
-
|
|
49
|
+
const raw = await paginate(endpoint, this._client, params, verbose);
|
|
50
|
+
return convertToModelList(raw, FolderSchema, 'Folder');
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
/**
|
|
@@ -54,10 +58,11 @@ class FoldersApi {
|
|
|
54
58
|
* @param {string} folderId
|
|
55
59
|
* @returns {Promise<object>}
|
|
56
60
|
*/
|
|
57
|
-
getFolder(projectId, fileAreaId, folderId) {
|
|
58
|
-
|
|
61
|
+
async getFolder(projectId, fileAreaId, folderId) {
|
|
62
|
+
const response = await this._client.get(
|
|
59
63
|
`/5.0/projects/${projectId}/file_areas/${fileAreaId}/folders/${folderId}`,
|
|
60
64
|
);
|
|
65
|
+
return convertToModel(response, FolderResponseSchema, 'FolderResponse');
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
/**
|
|
@@ -103,15 +108,12 @@ class FoldersApi {
|
|
|
103
108
|
validateProjectId(projectId);
|
|
104
109
|
validateFileAreaId(fileAreaId);
|
|
105
110
|
const allFolders = await this.getAllFolders(projectId, fileAreaId);
|
|
106
|
-
const folder = findByField(allFolders, 'folderName', folderName
|
|
107
|
-
|| findByField(allFolders, 'name', folderName, (x) => x.data || x);
|
|
111
|
+
const folder = findByField(allFolders, 'folderName', folderName);
|
|
108
112
|
if (!folder) return null;
|
|
109
|
-
if (parentFolderId != null) {
|
|
110
|
-
|
|
111
|
-
const pid = data.parentFolderId || data.parentId;
|
|
112
|
-
if (pid !== parentFolderId) return null;
|
|
113
|
+
if (parentFolderId != null && folder.parentFolderId !== parentFolderId) {
|
|
114
|
+
return null;
|
|
113
115
|
}
|
|
114
|
-
return folder;
|
|
116
|
+
return convertToModel({ data: folder }, FolderResponseSchema, 'FolderResponse');
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/**
|
package/src/api/FormsApi.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { convertToModel } = require('../models/convert');
|
|
4
|
+
const { FormsListResponseSchema, FormResponseSchema } = require('../models/forms');
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* API methods for forms on a project.
|
|
5
8
|
*/
|
|
@@ -16,10 +19,11 @@ class FormsApi {
|
|
|
16
19
|
* GET /2.1/projects/{projectId}/forms
|
|
17
20
|
* @param {string} projectId
|
|
18
21
|
* @param {object} [params] - Optional filters (e.g. updatedAfter)
|
|
19
|
-
* @returns {Promise<object>}
|
|
22
|
+
* @returns {Promise<object>} FormsListResponse ({ items, metadata?, links? })
|
|
20
23
|
*/
|
|
21
|
-
getProjectForms(projectId, params = {}) {
|
|
22
|
-
|
|
24
|
+
async getProjectForms(projectId, params = {}) {
|
|
25
|
+
const response = await this._client.get(`/2.1/projects/${projectId}/forms`, params);
|
|
26
|
+
return convertToModel(response, FormsListResponseSchema, 'FormsListResponse');
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -27,10 +31,11 @@ class FormsApi {
|
|
|
27
31
|
* GET /1.2/projects/{projectId}/forms/{formId}
|
|
28
32
|
* @param {string} projectId
|
|
29
33
|
* @param {string} formId
|
|
30
|
-
* @returns {Promise<object>}
|
|
34
|
+
* @returns {Promise<object>} FormResponse ({ data, links? })
|
|
31
35
|
*/
|
|
32
|
-
getForm(projectId, formId) {
|
|
33
|
-
|
|
36
|
+
async getForm(projectId, formId) {
|
|
37
|
+
const response = await this._client.get(`/1.2/projects/${projectId}/forms/${formId}`);
|
|
38
|
+
return convertToModel(response, FormResponseSchema, 'FormResponse');
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
/**
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { convertToModel, convertToModelList } = require('../models/convert');
|
|
4
|
+
const { paginate } = require('../utils/pagination');
|
|
5
|
+
const {
|
|
6
|
+
InspectionPlanSchema,
|
|
7
|
+
InspectionPlanItemSchema,
|
|
8
|
+
InspectionPlanItemZoneSchema,
|
|
9
|
+
InspectionPlanRegistrationSchema,
|
|
10
|
+
InspectionPlansListResponseSchema,
|
|
11
|
+
InspectionPlanItemsListResponseSchema,
|
|
12
|
+
InspectionPlanItemZonesListResponseSchema,
|
|
13
|
+
InspectionPlanRegistrationsListResponseSchema,
|
|
14
|
+
} = require('../models/inspectionPlans');
|
|
15
|
+
|
|
3
16
|
/**
|
|
4
17
|
* API methods for inspection plans.
|
|
5
18
|
*/
|
|
@@ -16,10 +29,27 @@ class InspectionPlansApi {
|
|
|
16
29
|
* GET /1.2/projects/{projectId}/inspectionPlans
|
|
17
30
|
* @param {string} projectId
|
|
18
31
|
* @param {object} [params]
|
|
19
|
-
* @
|
|
32
|
+
* @param {boolean} [fullResponse=false]
|
|
33
|
+
* @returns {Promise<object[]|object>}
|
|
20
34
|
*/
|
|
21
|
-
listInspectionPlans(projectId, params = {}) {
|
|
22
|
-
|
|
35
|
+
async listInspectionPlans(projectId, params = {}, fullResponse = false) {
|
|
36
|
+
const response = await this._client.get(`/1.2/projects/${projectId}/inspectionPlans`, params);
|
|
37
|
+
const result = convertToModel(
|
|
38
|
+
response,
|
|
39
|
+
InspectionPlansListResponseSchema,
|
|
40
|
+
'InspectionPlansListResponse',
|
|
41
|
+
);
|
|
42
|
+
return fullResponse ? result : (result?.items || []);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getAllInspectionPlans(projectId, params = {}, verbose = false) {
|
|
46
|
+
const items = await paginate(
|
|
47
|
+
`/1.2/projects/${projectId}/inspectionPlans`,
|
|
48
|
+
this._client,
|
|
49
|
+
params,
|
|
50
|
+
verbose,
|
|
51
|
+
);
|
|
52
|
+
return convertToModelList(items, InspectionPlanSchema, 'InspectionPlan');
|
|
23
53
|
}
|
|
24
54
|
|
|
25
55
|
/**
|
|
@@ -29,8 +59,24 @@ class InspectionPlansApi {
|
|
|
29
59
|
* @param {object} [params]
|
|
30
60
|
* @returns {Promise<object>}
|
|
31
61
|
*/
|
|
32
|
-
listInspectionPlanItems(projectId, params = {}) {
|
|
33
|
-
|
|
62
|
+
async listInspectionPlanItems(projectId, params = {}, fullResponse = false) {
|
|
63
|
+
const response = await this._client.get(`/1.1/projects/${projectId}/inspectionPlanItems`, params);
|
|
64
|
+
const result = convertToModel(
|
|
65
|
+
response,
|
|
66
|
+
InspectionPlanItemsListResponseSchema,
|
|
67
|
+
'InspectionPlanItemsListResponse',
|
|
68
|
+
);
|
|
69
|
+
return fullResponse ? result : (result?.items || []);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async getAllInspectionPlanItems(projectId, params = {}, verbose = false) {
|
|
73
|
+
const items = await paginate(
|
|
74
|
+
`/1.1/projects/${projectId}/inspectionPlanItems`,
|
|
75
|
+
this._client,
|
|
76
|
+
params,
|
|
77
|
+
verbose,
|
|
78
|
+
);
|
|
79
|
+
return convertToModelList(items, InspectionPlanItemSchema, 'InspectionPlanItem');
|
|
34
80
|
}
|
|
35
81
|
|
|
36
82
|
/**
|
|
@@ -40,8 +86,24 @@ class InspectionPlansApi {
|
|
|
40
86
|
* @param {object} [params]
|
|
41
87
|
* @returns {Promise<object>}
|
|
42
88
|
*/
|
|
43
|
-
listInspectionPlanItemZones(projectId, params = {}) {
|
|
44
|
-
|
|
89
|
+
async listInspectionPlanItemZones(projectId, params = {}, fullResponse = false) {
|
|
90
|
+
const response = await this._client.get(`/1.1/projects/${projectId}/inspectionPlanItemZones`, params);
|
|
91
|
+
const result = convertToModel(
|
|
92
|
+
response,
|
|
93
|
+
InspectionPlanItemZonesListResponseSchema,
|
|
94
|
+
'InspectionPlanItemZonesListResponse',
|
|
95
|
+
);
|
|
96
|
+
return fullResponse ? result : (result?.items || []);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getAllInspectionPlanItemZones(projectId, params = {}, verbose = false) {
|
|
100
|
+
const items = await paginate(
|
|
101
|
+
`/1.1/projects/${projectId}/inspectionPlanItemZones`,
|
|
102
|
+
this._client,
|
|
103
|
+
params,
|
|
104
|
+
verbose,
|
|
105
|
+
);
|
|
106
|
+
return convertToModelList(items, InspectionPlanItemZoneSchema, 'InspectionPlanItemZone');
|
|
45
107
|
}
|
|
46
108
|
|
|
47
109
|
/**
|
|
@@ -51,11 +113,27 @@ class InspectionPlansApi {
|
|
|
51
113
|
* @param {object} [params]
|
|
52
114
|
* @returns {Promise<object>}
|
|
53
115
|
*/
|
|
54
|
-
listInspectionPlanRegistrations(projectId, params = {}) {
|
|
55
|
-
|
|
116
|
+
async listInspectionPlanRegistrations(projectId, params = {}, fullResponse = false) {
|
|
117
|
+
const response = await this._client.get(
|
|
118
|
+
`/2.1/projects/${projectId}/inspectionPlanRegistrations`,
|
|
119
|
+
params,
|
|
120
|
+
);
|
|
121
|
+
const result = convertToModel(
|
|
122
|
+
response,
|
|
123
|
+
InspectionPlanRegistrationsListResponseSchema,
|
|
124
|
+
'InspectionPlanRegistrationsListResponse',
|
|
125
|
+
);
|
|
126
|
+
return fullResponse ? result : (result?.items || []);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async getAllInspectionPlanRegistrations(projectId, params = {}, verbose = false) {
|
|
130
|
+
const items = await paginate(
|
|
56
131
|
`/2.1/projects/${projectId}/inspectionPlanRegistrations`,
|
|
132
|
+
this._client,
|
|
57
133
|
params,
|
|
134
|
+
verbose,
|
|
58
135
|
);
|
|
136
|
+
return convertToModelList(items, InspectionPlanRegistrationSchema, 'InspectionPlanRegistration');
|
|
59
137
|
}
|
|
60
138
|
}
|
|
61
139
|
|
package/src/api/ProjectsApi.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { findByField } = require('../utils/search');
|
|
4
|
+
const { convertToModel } = require('../models/convert');
|
|
5
|
+
const { ProjectsListResponseSchema, ProjectResponseSchema } = require('../models/projects');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* API methods for project management.
|
|
5
9
|
*/
|
|
@@ -15,30 +19,33 @@ class ProjectsApi {
|
|
|
15
19
|
* Get all available projects.
|
|
16
20
|
* GET /5.1/projects
|
|
17
21
|
* @param {object} [params] - Optional query parameters (e.g. updatedAfter)
|
|
18
|
-
* @returns {Promise<object>}
|
|
22
|
+
* @returns {Promise<object>} ProjectsListResponse ({ items: Project[], metadata?, links? })
|
|
19
23
|
*/
|
|
20
|
-
listProjects(params = {}) {
|
|
21
|
-
|
|
24
|
+
async listProjects(params = {}) {
|
|
25
|
+
const response = await this._client.get('/5.1/projects', params);
|
|
26
|
+
return convertToModel(response, ProjectsListResponseSchema, 'ProjectsListResponse');
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
30
|
* Get a specific project.
|
|
26
31
|
* GET /5.0/projects/{projectId}
|
|
27
32
|
* @param {string} projectId
|
|
28
|
-
* @returns {Promise<object>}
|
|
33
|
+
* @returns {Promise<object>} ProjectResponse ({ data: Project, links? })
|
|
29
34
|
*/
|
|
30
|
-
getProject(projectId) {
|
|
31
|
-
|
|
35
|
+
async getProject(projectId) {
|
|
36
|
+
const response = await this._client.get(`/5.0/projects/${projectId}`);
|
|
37
|
+
return convertToModel(response, ProjectResponseSchema, 'ProjectResponse');
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
41
|
* Create a new project.
|
|
36
42
|
* POST /5.0/projects
|
|
37
43
|
* @param {object} body
|
|
38
|
-
* @returns {Promise<object>}
|
|
44
|
+
* @returns {Promise<object>} ProjectResponse
|
|
39
45
|
*/
|
|
40
|
-
createProject(body) {
|
|
41
|
-
|
|
46
|
+
async createProject(body) {
|
|
47
|
+
const response = await this._client.post('/5.0/projects', body);
|
|
48
|
+
return convertToModel(response, ProjectResponseSchema, 'ProjectResponse');
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
/**
|
|
@@ -46,10 +53,11 @@ class ProjectsApi {
|
|
|
46
53
|
* PATCH /5.0/projects/{projectId}
|
|
47
54
|
* @param {string} projectId
|
|
48
55
|
* @param {object} body
|
|
49
|
-
* @returns {Promise<object>}
|
|
56
|
+
* @returns {Promise<object>} ProjectResponse
|
|
50
57
|
*/
|
|
51
|
-
updateProject(projectId, body) {
|
|
52
|
-
|
|
58
|
+
async updateProject(projectId, body) {
|
|
59
|
+
const response = await this._client.patch(`/5.0/projects/${projectId}`, body);
|
|
60
|
+
return convertToModel(response, ProjectResponseSchema, 'ProjectResponse');
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
/**
|
|
@@ -108,15 +116,11 @@ class ProjectsApi {
|
|
|
108
116
|
* @returns {Promise<string|null>} The projectId, or null if not found.
|
|
109
117
|
*/
|
|
110
118
|
async getProjectByName(projectName) {
|
|
111
|
-
const { findByField } = require('../utils/search');
|
|
112
119
|
const response = await this.listProjects();
|
|
113
120
|
const items = (response && response.items) || [];
|
|
114
|
-
const project =
|
|
115
|
-
findByField(items, 'projectName', projectName, (x) => x.data || x) ||
|
|
116
|
-
findByField(items, 'name', projectName, (x) => x.data || x);
|
|
121
|
+
const project = findByField(items, 'projectName', projectName);
|
|
117
122
|
if (!project) return null;
|
|
118
|
-
|
|
119
|
-
return data.projectId || data.id || null;
|
|
123
|
+
return project.projectId || null;
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
|