@ndustrial/contxt-sdk 4.3.4 → 5.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.
- package/.gitattributes +1 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +8 -0
- package/docs/Facilities.md +0 -144
- package/docs/FacilityGroupings.md +0 -160
- package/docs/Nionic.md +63 -0
- package/docs/README.md +3 -29
- package/docs/Typedefs.md +0 -101
- package/esm/config/audiences.js +13 -13
- package/esm/config/audiences.js.map +1 -1
- package/esm/index.js +3 -6
- package/esm/index.js.map +1 -1
- package/esm/nionic/index.js +126 -0
- package/esm/nionic/index.js.map +1 -0
- package/lib/config/audiences.js +13 -13
- package/lib/config/audiences.js.map +1 -1
- package/lib/index.js +19 -13
- package/lib/index.js.map +1 -1
- package/lib/nionic/index.js +130 -0
- package/lib/nionic/index.js.map +1 -0
- package/meta.yaml +11 -0
- package/package.json +9 -10
- package/src/bus/index.spec.js +3 -2
- package/src/bus/webSocketConnection.spec.js +31 -31
- package/src/config/audiences.js +13 -13
- package/src/config/index.spec.js +6 -6
- package/src/coordinator/applications.spec.js +8 -8
- package/src/coordinator/consent.spec.js +1 -1
- package/src/coordinator/edgeNodes.spec.js +3 -3
- package/src/coordinator/organizations.spec.js +4 -4
- package/src/coordinator/permissions.spec.js +4 -4
- package/src/coordinator/roles.spec.js +3 -3
- package/src/coordinator/users.spec.js +14 -15
- package/src/events/index.spec.js +16 -16
- package/src/files/index.spec.js +7 -7
- package/src/index.js +3 -6
- package/src/index.spec.js +8 -22
- package/src/iot/feeds.spec.js +4 -4
- package/src/iot/fieldCategories.spec.js +4 -4
- package/src/iot/fieldGroupings.spec.js +5 -5
- package/src/iot/outputs.spec.js +6 -6
- package/src/nionic/index.js +151 -0
- package/src/request.spec.js +3 -3
- package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
- package/src/sessionTypes/index.spec.js +3 -3
- package/src/sessionTypes/machineAuth.spec.js +3 -3
- package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
- package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
- package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
- package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
- package/src/utils/url/stringifyParams.spec.js +2 -3
- package/support/fixtures/factories/IOSDevice.js +3 -3
- package/support/fixtures/factories/applicationGrouping.js +4 -4
- package/support/fixtures/factories/applicationModule.js +2 -2
- package/support/fixtures/factories/asset.js +1 -1
- package/support/fixtures/factories/assetAttribute.js +2 -2
- package/support/fixtures/factories/assetAttributeValue.js +2 -2
- package/support/fixtures/factories/assetMetric.js +1 -1
- package/support/fixtures/factories/assetMetricValue.js +3 -3
- package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
- package/support/fixtures/factories/assetType.js +1 -1
- package/support/fixtures/factories/authResults.js +3 -3
- package/support/fixtures/factories/channel.js +1 -1
- package/support/fixtures/factories/contxtApplication.js +5 -5
- package/support/fixtures/factories/contxtOrganization.js +2 -2
- package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
- package/support/fixtures/factories/contxtProject.js +2 -2
- package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
- package/support/fixtures/factories/contxtRole.js +3 -3
- package/support/fixtures/factories/contxtRoleApplication.js +1 -1
- package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUser.js +2 -2
- package/support/fixtures/factories/contxtUserApplication.js +1 -1
- package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
- package/support/fixtures/factories/contxtUserPermissions.js +5 -5
- package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUserRole.js +2 -2
- package/support/fixtures/factories/costCenter.js +2 -2
- package/support/fixtures/factories/costCenterFacility.js +3 -3
- package/support/fixtures/factories/edgeNode.js +1 -1
- package/support/fixtures/factories/event.js +5 -5
- package/support/fixtures/factories/eventType.js +4 -4
- package/support/fixtures/factories/eventUser.js +5 -5
- package/support/fixtures/factories/facility.js +4 -4
- package/support/fixtures/factories/facilityGrouping.js +3 -3
- package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
- package/support/fixtures/factories/facilityInfo.js +2 -2
- package/support/fixtures/factories/facilityTag.js +1 -1
- package/support/fixtures/factories/feedStatus.js +1 -1
- package/support/fixtures/factories/feedType.js +1 -1
- package/support/fixtures/factories/feeds.js +5 -5
- package/support/fixtures/factories/fieldCategory.js +3 -3
- package/support/fixtures/factories/fieldGrouping.js +4 -4
- package/support/fixtures/factories/fieldGroupingField.js +3 -3
- package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
- package/support/fixtures/factories/file.js +1 -1
- package/support/fixtures/factories/fileUploadInfo.js +1 -1
- package/support/fixtures/factories/organization.js +1 -1
- package/support/fixtures/factories/outputField.js +10 -10
- package/support/fixtures/factories/outputFieldData.js +1 -1
- package/support/fixtures/factories/owner.js +2 -2
- package/support/fixtures/factories/paginationMetadata.js +2 -2
- package/support/fixtures/factories/triggeredEvent.js +4 -4
- package/support/fixtures/factories/userEventSubscription.js +1 -1
- package/support/fixtures/factories/userMobileNumber.js +1 -1
- package/support/fixtures/factories/userPermissionsMap.js +2 -2
- package/.envrc +0 -0
- package/.huskyrc.js +0 -11
- package/.nycrc +0 -12
- package/esm/assets/assetAttributes.js +0 -574
- package/esm/assets/assetAttributes.js.map +0 -1
- package/esm/assets/assetMetrics.js +0 -690
- package/esm/assets/assetMetrics.js.map +0 -1
- package/esm/assets/assetTypes.js +0 -273
- package/esm/assets/assetTypes.js.map +0 -1
- package/esm/assets/index.js +0 -283
- package/esm/assets/index.js.map +0 -1
- package/esm/facilities/costCenters.js +0 -306
- package/esm/facilities/costCenters.js.map +0 -1
- package/esm/facilities/groupings.js +0 -323
- package/esm/facilities/groupings.js.map +0 -1
- package/esm/facilities/index.js +0 -343
- package/esm/facilities/index.js.map +0 -1
- package/esm/health/index.js +0 -229
- package/esm/health/index.js.map +0 -1
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/esm/utils/facilities/index.js +0 -4
- package/esm/utils/facilities/index.js.map +0 -1
- package/lib/assets/assetAttributes.js +0 -588
- package/lib/assets/assetAttributes.js.map +0 -1
- package/lib/assets/assetMetrics.js +0 -705
- package/lib/assets/assetMetrics.js.map +0 -1
- package/lib/assets/assetTypes.js +0 -287
- package/lib/assets/assetTypes.js.map +0 -1
- package/lib/assets/index.js +0 -302
- package/lib/assets/index.js.map +0 -1
- package/lib/facilities/costCenters.js +0 -316
- package/lib/facilities/costCenters.js.map +0 -1
- package/lib/facilities/groupings.js +0 -333
- package/lib/facilities/groupings.js.map +0 -1
- package/lib/facilities/index.js +0 -360
- package/lib/facilities/index.js.map +0 -1
- package/lib/health/index.js +0 -232
- package/lib/health/index.js.map +0 -1
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/lib/utils/facilities/index.js +0 -15
- package/lib/utils/facilities/index.js.map +0 -1
- package/src/assets/assetAttributes.js +0 -619
- package/src/assets/assetAttributes.spec.js +0 -1143
- package/src/assets/assetMetrics.js +0 -736
- package/src/assets/assetMetrics.spec.js +0 -1180
- package/src/assets/assetTypes.js +0 -260
- package/src/assets/assetTypes.spec.js +0 -556
- package/src/assets/index.js +0 -271
- package/src/assets/index.spec.js +0 -515
- package/src/facilities/costCenters.js +0 -295
- package/src/facilities/costCenters.spec.js +0 -529
- package/src/facilities/groupings.js +0 -320
- package/src/facilities/groupings.spec.js +0 -567
- package/src/facilities/index.js +0 -343
- package/src/facilities/index.spec.js +0 -551
- package/src/health/index.js +0 -200
- package/src/health/index.spec.js +0 -501
- package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
- package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
- package/src/utils/facilities/index.js +0 -3
- package/tmp/package.json +0 -11
package/src/assets/index.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import isPlainObject from 'lodash.isplainobject';
|
|
2
|
-
import AssetAttributes from './assetAttributes';
|
|
3
|
-
import AssetMetrics from './assetMetrics';
|
|
4
|
-
import AssetTypes from './assetTypes';
|
|
5
|
-
|
|
6
|
-
import { toCamelCase, toSnakeCase } from '../utils/objects';
|
|
7
|
-
import { formatPaginatedDataFromServer } from '../utils/pagination';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {Object} Asset
|
|
11
|
-
* @property {string} assetTypeId UUID corresponding with the asset type
|
|
12
|
-
* @property {string} createdAt ISO 8601 Extended Format date/time string
|
|
13
|
-
* @property {string} [description]
|
|
14
|
-
* @property {string} id UUID
|
|
15
|
-
* @property {string} label
|
|
16
|
-
* @property {string} organizationId UUID corresponding with the organization
|
|
17
|
-
* @property {string} updatedAt ISO 8601 Extended Format date/time string
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {Object} AssetsFromServer
|
|
22
|
-
* @property {Object} _metadata Metadata about the pagination settings
|
|
23
|
-
* @property {number} _metadata.offset Offset of records in subsequent queries
|
|
24
|
-
* @property {number} _metadata.totalRecords Total number of asset types found
|
|
25
|
-
* @property {Asset[]} records
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Module that provides access to, and the manipulation of, information about different assets
|
|
30
|
-
*
|
|
31
|
-
* @typicalname contxtSdk.assets
|
|
32
|
-
*/
|
|
33
|
-
class Assets {
|
|
34
|
-
/**
|
|
35
|
-
* @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
|
|
36
|
-
* @param {Object} request An instance of the request module tied to this module's audience.
|
|
37
|
-
*/
|
|
38
|
-
constructor(sdk, request) {
|
|
39
|
-
const baseUrl = `${sdk.config.audiences.facilities.host}/v1`;
|
|
40
|
-
|
|
41
|
-
this._baseUrl = baseUrl;
|
|
42
|
-
this._request = request;
|
|
43
|
-
this._sdk = sdk;
|
|
44
|
-
|
|
45
|
-
this.attributes = new AssetAttributes(sdk, request, baseUrl);
|
|
46
|
-
this.types = new AssetTypes(sdk, request, baseUrl);
|
|
47
|
-
this.metrics = new AssetMetrics(sdk, request, baseUrl);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Creates a new asset
|
|
52
|
-
*
|
|
53
|
-
* API Endpoint: '/assets'
|
|
54
|
-
* Method: POST
|
|
55
|
-
*
|
|
56
|
-
* @param {Object} asset
|
|
57
|
-
* @param {string} asset.assetTypeId UUID
|
|
58
|
-
* @param {string} [asset.description]
|
|
59
|
-
* @param {string} asset.label
|
|
60
|
-
* @param {string} asset.organizationId UUID
|
|
61
|
-
*
|
|
62
|
-
* @returns {Promise}
|
|
63
|
-
* @fulfill {Asset} information about the new asset
|
|
64
|
-
* @reject {Error}
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* contxtSdk.assets
|
|
68
|
-
* .create({
|
|
69
|
-
* assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d',
|
|
70
|
-
* description: '221B Baker Street, London',
|
|
71
|
-
* label: 'Sherlock Homes Museum',
|
|
72
|
-
* organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'
|
|
73
|
-
* })
|
|
74
|
-
* .then((asset) => console.log(asset))
|
|
75
|
-
* .catch((err) => console.log(err));
|
|
76
|
-
*/
|
|
77
|
-
create(asset = {}) {
|
|
78
|
-
const requiredFields = ['assetTypeId', 'label', 'organizationId'];
|
|
79
|
-
|
|
80
|
-
for (let i = 0; i < requiredFields.length; i++) {
|
|
81
|
-
const field = requiredFields[i];
|
|
82
|
-
|
|
83
|
-
if (!asset[field]) {
|
|
84
|
-
return Promise.reject(
|
|
85
|
-
new Error(`A ${field} is required to create a new asset.`)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return this._request
|
|
91
|
-
.post(`${this._baseUrl}/assets`, toSnakeCase(asset))
|
|
92
|
-
.then((asset) => toCamelCase(asset));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Deletes an asset
|
|
97
|
-
*
|
|
98
|
-
* API Endpoint: '/assets/:assetId'
|
|
99
|
-
* Method: DELETE
|
|
100
|
-
*
|
|
101
|
-
* @param {string} assetId The ID of the asset (formatted as a UUID)
|
|
102
|
-
*
|
|
103
|
-
* @returns {Promise}
|
|
104
|
-
* @fulfill {undefined}
|
|
105
|
-
* @reject {Error}
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* contxtSdk.assets.delete('0b51429f-91a0-48ba-b144-fd2db697000e');
|
|
109
|
-
*/
|
|
110
|
-
delete(assetId) {
|
|
111
|
-
if (!assetId) {
|
|
112
|
-
return Promise.reject(
|
|
113
|
-
new Error('An asset ID is required for deleting an asset.')
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return this._request.delete(`${this._baseUrl}/assets/${assetId}`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Gets information about an asset
|
|
122
|
-
*
|
|
123
|
-
* API Endpoint: '/assets/:assetId'
|
|
124
|
-
* Method: GET
|
|
125
|
-
*
|
|
126
|
-
* @param {string} assetId The ID of the asset (formatted as a UUID)
|
|
127
|
-
*
|
|
128
|
-
* @returns {Promise}
|
|
129
|
-
* @fulfill {Asset} Information about the asset
|
|
130
|
-
* @reject {Error}
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* contxtSdk.assets
|
|
134
|
-
* .get('0b51429f-91a0-48ba-b144-fd2db697000e')
|
|
135
|
-
* .then((asset) => console.log(asset))
|
|
136
|
-
* .catch((err) => console.log(err));
|
|
137
|
-
*/
|
|
138
|
-
get(assetId) {
|
|
139
|
-
if (!assetId) {
|
|
140
|
-
return Promise.reject(
|
|
141
|
-
new Error(
|
|
142
|
-
'An asset ID is required for getting information about an asset.'
|
|
143
|
-
)
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return this._request
|
|
148
|
-
.get(`${this._baseUrl}/assets/${assetId}`)
|
|
149
|
-
.then((asset) => toCamelCase(asset));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Get a list of all assets
|
|
154
|
-
*
|
|
155
|
-
* API Endpoint: '/assets'
|
|
156
|
-
* Method: GET
|
|
157
|
-
*
|
|
158
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
159
|
-
*
|
|
160
|
-
* @returns {Promise}
|
|
161
|
-
* @fulfill {AssetsFromServer}
|
|
162
|
-
* @reject {Error}
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* contxtSdk.assets
|
|
166
|
-
* .getAll()
|
|
167
|
-
* .then((assets) => console.log(assets))
|
|
168
|
-
* .catch((err) => console.log(err));
|
|
169
|
-
*/
|
|
170
|
-
getAll(paginationOptions) {
|
|
171
|
-
return this._request
|
|
172
|
-
.get(`${this._baseUrl}/assets`, {
|
|
173
|
-
params: toSnakeCase(paginationOptions)
|
|
174
|
-
})
|
|
175
|
-
.then((assetsData) => formatPaginatedDataFromServer(assetsData));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get a list of all assets that belong to a particular organization
|
|
180
|
-
*
|
|
181
|
-
* API Endpoint: '/organizations/:organizationId/assets'
|
|
182
|
-
* Method: GET
|
|
183
|
-
*
|
|
184
|
-
* @param {string} organizationId UUID corresponding with an organization
|
|
185
|
-
* @param {Object} [options] Object containing parameters to be called with the request
|
|
186
|
-
* @param {string} [options.assetTypeId] UUID of the asset type to use for filtering
|
|
187
|
-
* @param {Number} [options.limit] Maximum number of records to return per query
|
|
188
|
-
* @param {Number} [options.offset] How many records from the first record to start
|
|
189
|
-
* @param {boolean} [options.includeTypeDescendents] When true will look for all asset types that are descendendents from options.assetTypeId
|
|
190
|
-
* @param {string} [options.includeMetricId] If asset has an associated metric value the latest metric will be returned.
|
|
191
|
-
*
|
|
192
|
-
* @returns {Promise}
|
|
193
|
-
* @fulfill {AssetsFromServer}
|
|
194
|
-
* @reject {Error}
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* contxtSdk.assets
|
|
198
|
-
* .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c', {
|
|
199
|
-
* assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d'
|
|
200
|
-
* })
|
|
201
|
-
* .then((assets) => console.log(assets))
|
|
202
|
-
* .catch((err) => console.log(err));
|
|
203
|
-
*/
|
|
204
|
-
getAllByOrganizationId(organizationId, options) {
|
|
205
|
-
if (!organizationId) {
|
|
206
|
-
return Promise.reject(
|
|
207
|
-
new Error(
|
|
208
|
-
"An organization ID is required for getting a list of an organization's assets."
|
|
209
|
-
)
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const params = toSnakeCase(options);
|
|
214
|
-
|
|
215
|
-
return this._request
|
|
216
|
-
.get(`${this._baseUrl}/organizations/${organizationId}/assets`, {
|
|
217
|
-
params
|
|
218
|
-
})
|
|
219
|
-
.then((assetsData) => formatPaginatedDataFromServer(assetsData));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Updates an asset's data
|
|
224
|
-
*
|
|
225
|
-
* API Endpoint: '/assets/:assetId'
|
|
226
|
-
* Method: PUT
|
|
227
|
-
*
|
|
228
|
-
* @param {string} assetId The ID of the asset to update (formatted as a UUID)
|
|
229
|
-
* @param {Object} update An object containing the updated data for the asset
|
|
230
|
-
* @param {string} update.description
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* contxtSdk.assets
|
|
234
|
-
* .update({
|
|
235
|
-
* description: 'A new description'
|
|
236
|
-
* })
|
|
237
|
-
* .then((asset) => console.log(asset))
|
|
238
|
-
* .catch((err) => console.log(err));
|
|
239
|
-
*/
|
|
240
|
-
update(assetId, update) {
|
|
241
|
-
if (!assetId) {
|
|
242
|
-
return Promise.reject(
|
|
243
|
-
new Error('An asset ID is required to update an asset.')
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!update) {
|
|
248
|
-
return Promise.reject(
|
|
249
|
-
new Error('An update is required to update an asset.')
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!isPlainObject(update)) {
|
|
254
|
-
return Promise.reject(
|
|
255
|
-
new Error(
|
|
256
|
-
'The asset update must be a well-formed object with the data you wish to update.'
|
|
257
|
-
)
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const formattedUpdate = toSnakeCase(update, {
|
|
262
|
-
excludeKeys: ['assetTypeId', 'id', 'label', 'organizationId']
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
return this._request
|
|
266
|
-
.put(`${this._baseUrl}/assets/${assetId}`, formattedUpdate)
|
|
267
|
-
.then((asset) => toCamelCase(asset));
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export default Assets;
|