@ndustrial/contxt-sdk 4.3.6 → 5.2.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 (167) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +8 -0
  3. package/CODEOWNERS +1 -0
  4. package/docs/Facilities.md +0 -144
  5. package/docs/FacilityGroupings.md +0 -160
  6. package/docs/Nionic.md +63 -0
  7. package/docs/README.md +3 -29
  8. package/docs/Typedefs.md +0 -101
  9. package/esm/config/audiences.js +13 -13
  10. package/esm/config/audiences.js.map +1 -1
  11. package/esm/index.js +4 -6
  12. package/esm/index.js.map +1 -1
  13. package/esm/nionic/index.js +126 -0
  14. package/esm/nionic/index.js.map +1 -0
  15. package/lib/config/audiences.js +13 -13
  16. package/lib/config/audiences.js.map +1 -1
  17. package/lib/index.js +10 -15
  18. package/lib/index.js.map +1 -1
  19. package/lib/nionic/index.js +130 -0
  20. package/lib/nionic/index.js.map +1 -0
  21. package/meta.yaml +11 -0
  22. package/package.json +9 -10
  23. package/src/bus/index.spec.js +3 -2
  24. package/src/bus/webSocketConnection.spec.js +31 -31
  25. package/src/config/audiences.js +13 -13
  26. package/src/config/index.spec.js +6 -6
  27. package/src/coordinator/applications.spec.js +8 -8
  28. package/src/coordinator/consent.spec.js +1 -1
  29. package/src/coordinator/edgeNodes.spec.js +3 -3
  30. package/src/coordinator/organizations.spec.js +4 -4
  31. package/src/coordinator/permissions.spec.js +4 -4
  32. package/src/coordinator/roles.spec.js +3 -3
  33. package/src/coordinator/users.spec.js +14 -15
  34. package/src/events/index.spec.js +16 -16
  35. package/src/files/index.spec.js +7 -7
  36. package/src/index.js +4 -6
  37. package/src/index.spec.js +8 -22
  38. package/src/iot/feeds.spec.js +4 -4
  39. package/src/iot/fieldCategories.spec.js +4 -4
  40. package/src/iot/fieldGroupings.spec.js +5 -5
  41. package/src/iot/outputs.spec.js +6 -6
  42. package/src/nionic/index.js +151 -0
  43. package/src/request.spec.js +3 -3
  44. package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
  45. package/src/sessionTypes/index.spec.js +3 -3
  46. package/src/sessionTypes/machineAuth.spec.js +3 -3
  47. package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
  48. package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
  49. package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
  50. package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
  51. package/src/utils/url/stringifyParams.spec.js +2 -3
  52. package/support/fixtures/factories/IOSDevice.js +3 -3
  53. package/support/fixtures/factories/applicationGrouping.js +4 -4
  54. package/support/fixtures/factories/applicationModule.js +2 -2
  55. package/support/fixtures/factories/asset.js +1 -1
  56. package/support/fixtures/factories/assetAttribute.js +2 -2
  57. package/support/fixtures/factories/assetAttributeValue.js +2 -2
  58. package/support/fixtures/factories/assetMetric.js +1 -1
  59. package/support/fixtures/factories/assetMetricValue.js +3 -3
  60. package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
  61. package/support/fixtures/factories/assetType.js +1 -1
  62. package/support/fixtures/factories/authResults.js +3 -3
  63. package/support/fixtures/factories/channel.js +1 -1
  64. package/support/fixtures/factories/contxtApplication.js +5 -5
  65. package/support/fixtures/factories/contxtOrganization.js +2 -2
  66. package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
  67. package/support/fixtures/factories/contxtProject.js +2 -2
  68. package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
  69. package/support/fixtures/factories/contxtRole.js +3 -3
  70. package/support/fixtures/factories/contxtRoleApplication.js +1 -1
  71. package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
  72. package/support/fixtures/factories/contxtUser.js +2 -2
  73. package/support/fixtures/factories/contxtUserApplication.js +1 -1
  74. package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
  75. package/support/fixtures/factories/contxtUserPermissions.js +5 -5
  76. package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
  77. package/support/fixtures/factories/contxtUserRole.js +2 -2
  78. package/support/fixtures/factories/costCenter.js +2 -2
  79. package/support/fixtures/factories/costCenterFacility.js +3 -3
  80. package/support/fixtures/factories/edgeNode.js +1 -1
  81. package/support/fixtures/factories/event.js +5 -5
  82. package/support/fixtures/factories/eventType.js +4 -4
  83. package/support/fixtures/factories/eventUser.js +5 -5
  84. package/support/fixtures/factories/facility.js +4 -4
  85. package/support/fixtures/factories/facilityGrouping.js +3 -3
  86. package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
  87. package/support/fixtures/factories/facilityInfo.js +2 -2
  88. package/support/fixtures/factories/facilityTag.js +1 -1
  89. package/support/fixtures/factories/feedStatus.js +1 -1
  90. package/support/fixtures/factories/feedType.js +1 -1
  91. package/support/fixtures/factories/feeds.js +5 -5
  92. package/support/fixtures/factories/fieldCategory.js +3 -3
  93. package/support/fixtures/factories/fieldGrouping.js +4 -4
  94. package/support/fixtures/factories/fieldGroupingField.js +3 -3
  95. package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
  96. package/support/fixtures/factories/file.js +1 -1
  97. package/support/fixtures/factories/fileUploadInfo.js +1 -1
  98. package/support/fixtures/factories/organization.js +1 -1
  99. package/support/fixtures/factories/outputField.js +10 -10
  100. package/support/fixtures/factories/outputFieldData.js +1 -1
  101. package/support/fixtures/factories/owner.js +2 -2
  102. package/support/fixtures/factories/paginationMetadata.js +2 -2
  103. package/support/fixtures/factories/triggeredEvent.js +4 -4
  104. package/support/fixtures/factories/userEventSubscription.js +1 -1
  105. package/support/fixtures/factories/userMobileNumber.js +1 -1
  106. package/support/fixtures/factories/userPermissionsMap.js +2 -2
  107. package/.huskyrc.js +0 -11
  108. package/.nycrc +0 -12
  109. package/esm/assets/assetAttributes.js +0 -574
  110. package/esm/assets/assetAttributes.js.map +0 -1
  111. package/esm/assets/assetMetrics.js +0 -690
  112. package/esm/assets/assetMetrics.js.map +0 -1
  113. package/esm/assets/assetTypes.js +0 -273
  114. package/esm/assets/assetTypes.js.map +0 -1
  115. package/esm/assets/index.js +0 -283
  116. package/esm/assets/index.js.map +0 -1
  117. package/esm/facilities/costCenters.js +0 -306
  118. package/esm/facilities/costCenters.js.map +0 -1
  119. package/esm/facilities/groupings.js +0 -323
  120. package/esm/facilities/groupings.js.map +0 -1
  121. package/esm/facilities/index.js +0 -343
  122. package/esm/facilities/index.js.map +0 -1
  123. package/esm/health/index.js +0 -229
  124. package/esm/health/index.js.map +0 -1
  125. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  126. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  127. package/esm/utils/facilities/index.js +0 -4
  128. package/esm/utils/facilities/index.js.map +0 -1
  129. package/lib/assets/assetAttributes.js +0 -588
  130. package/lib/assets/assetAttributes.js.map +0 -1
  131. package/lib/assets/assetMetrics.js +0 -705
  132. package/lib/assets/assetMetrics.js.map +0 -1
  133. package/lib/assets/assetTypes.js +0 -287
  134. package/lib/assets/assetTypes.js.map +0 -1
  135. package/lib/assets/index.js +0 -302
  136. package/lib/assets/index.js.map +0 -1
  137. package/lib/facilities/costCenters.js +0 -316
  138. package/lib/facilities/costCenters.js.map +0 -1
  139. package/lib/facilities/groupings.js +0 -333
  140. package/lib/facilities/groupings.js.map +0 -1
  141. package/lib/facilities/index.js +0 -360
  142. package/lib/facilities/index.js.map +0 -1
  143. package/lib/health/index.js +0 -232
  144. package/lib/health/index.js.map +0 -1
  145. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  146. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  147. package/lib/utils/facilities/index.js +0 -15
  148. package/lib/utils/facilities/index.js.map +0 -1
  149. package/src/assets/assetAttributes.js +0 -619
  150. package/src/assets/assetAttributes.spec.js +0 -1143
  151. package/src/assets/assetMetrics.js +0 -736
  152. package/src/assets/assetMetrics.spec.js +0 -1180
  153. package/src/assets/assetTypes.js +0 -260
  154. package/src/assets/assetTypes.spec.js +0 -556
  155. package/src/assets/index.js +0 -271
  156. package/src/assets/index.spec.js +0 -515
  157. package/src/facilities/costCenters.js +0 -295
  158. package/src/facilities/costCenters.spec.js +0 -529
  159. package/src/facilities/groupings.js +0 -320
  160. package/src/facilities/groupings.spec.js +0 -567
  161. package/src/facilities/index.js +0 -343
  162. package/src/facilities/index.spec.js +0 -551
  163. package/src/health/index.js +0 -200
  164. package/src/health/index.spec.js +0 -501
  165. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  166. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  167. package/src/utils/facilities/index.js +0 -3
@@ -1,619 +0,0 @@
1
- import has from 'lodash.has';
2
- import isPlainObject from 'lodash.isplainobject';
3
- import { toCamelCase, toSnakeCase } from '../utils/objects';
4
- import { formatPaginatedDataFromServer } from '../utils/pagination';
5
-
6
- /**
7
- * @typedef {Object} PaginationMetadata
8
- * @property {number} offset Offset of records in subsequent queries
9
- * @property {number} totalRecords Total number of asset attributes found
10
- */
11
-
12
- /**
13
- * @typedef {Object} PaginationOptions
14
- * @property {Number} limit Maximum number of records to return per query
15
- * @property {Number} offset How many records from the first record to start
16
- * the query
17
- */
18
-
19
- /**
20
- * @typedef {Object} AssetAttribute
21
- * @property {string} assetTypeId UUID corresponding with the asset type
22
- * @property {string} createdAt ISO 8601 Extended Format date/time string
23
- * @property {string} dataType Data Type of attribute with options "boolean", "date", "number", "string"
24
- * @property {string} description
25
- * @property {string} id UUID
26
- * @property {boolean} isRequired
27
- * @property {string} label
28
- * @property {string} organizationId UUID corresponding with the organization
29
- * @property {string} [units]
30
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
31
- */
32
-
33
- /**
34
- * @typedef {Object} AssetAttributeData
35
- * @property {PaginationMetadata} _metadata Metadata about the pagination settings
36
- * @property {AssetAttribute[]} records
37
- */
38
-
39
- /**
40
- * @typedef {Object} AssetAttributeValue
41
- * @property {Object} [asset] The associated parent asset. Will always be
42
- * present if retrieving more than one AssetAttributeValue.
43
- * @property {string} [asset.label] Label of the parent asset. Will always be
44
- * present if retrieving more than one AssetAttributeValue.
45
- * @property {Object} [assetAttribute] The associated parent assetAttribute.
46
- * Will always be present if retrieving more than one AssetAttributeValue.
47
- * @property {boolean} [assetAttribute.isRequired] Indication of required status
48
- * for the parent asset attribute. Will always be present if retrieving more
49
- * than one AssetAttributeValue.
50
- * @property {string} [assetAttribute.label] Label of the parent assetAttribute.
51
- * Will always be present if retrieving more than one AssetAttributeValue.
52
- * @property {string} [assetAttribute.units] Units of the parent assetAttribute.
53
- * Will always be present if retrieving more than one AssetAttributeValue.
54
- * @property {string} assetAttributeId UUID corresponding to the assetAttribute
55
- * @property {string} assetId UUID corresponding to the asset
56
- * @property {string} createdAt ISO 8601 Extended Format date/time string
57
- * @property {string} effectiveDate ISO 8601 Extended Format date/time string
58
- * @property {string} id UUID
59
- * @property {string} [notes]
60
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
61
- * @property {string} value
62
- */
63
-
64
- /**
65
- * @typedef {Object} AssetAttributeValueData
66
- * @property {PaginationMetadata} _metadata Metadata about the pagination settings
67
- * @property {AssetAttributeValue[]} records
68
- */
69
-
70
- /**
71
- * Module that provides access to, and the manipulation of, information about
72
- * different asset attributes and their values
73
- *
74
- * @typicalname contxtSdk.assets.attributes
75
- */
76
- class AssetAttributes {
77
- /**
78
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
79
- * @param {Object} request An instance of the request module tied to this module's audience.
80
- * @param {string} baseUrl The base URL provided by the parent module
81
- */
82
- constructor(sdk, request, baseUrl) {
83
- this._baseUrl = baseUrl;
84
- this._request = request;
85
- this._sdk = sdk;
86
- }
87
-
88
- /**
89
- * Creates a new asset attribute
90
- *
91
- * API Endpoint: '/assets/types/:assetTypeId/attributes'
92
- * Method: POST
93
- *
94
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
95
- * @param {Object} assetAttribute
96
- * @param {string} assetAttribute.dataType
97
- * @param {string} assetAttribute.description
98
- * @param {boolean} [assetAttribute.isRequired]
99
- * @param {string} assetAttribute.label
100
- * @param {string} assetAttribute.organizationId Can be explicitly set to `null` to create a global attribute
101
- * @param {string} [assetAttribute.units]
102
- *
103
- * @returns {Promise}
104
- * @fulfill {AssetAttribute}
105
- * @reject {Error}
106
- *
107
- * @example
108
- * contxtSdk.assets.attributes
109
- * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {
110
- * dataType: 'boolean',
111
- * description: 'Square footage of a facility',
112
- * isRequired: true,
113
- * label: 'Square Footage',
114
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',
115
- * units: 'sqft'
116
- * })
117
- * .then((assetAttribute) => console.log(assetAttribute))
118
- * .catch((err) => console.log(err));
119
- */
120
- create(assetTypeId, assetAttribute = {}) {
121
- const hasFieldFns = {
122
- default: (object, key) => !!object[key],
123
- organizationId: (object, key) => has(object, key)
124
- };
125
-
126
- const requiredFields = ['description', 'label', 'organizationId'];
127
-
128
- if (!assetTypeId) {
129
- return Promise.reject(
130
- new Error(
131
- 'An asset type ID is required to create a new asset attribute.'
132
- )
133
- );
134
- }
135
-
136
- for (let i = 0; i < requiredFields.length; i++) {
137
- const field = requiredFields[i];
138
- const hasField = hasFieldFns[field] || hasFieldFns.default;
139
-
140
- if (!hasField(assetAttribute, field)) {
141
- return Promise.reject(
142
- new Error(`A ${field} is required to create a new asset attribute.`)
143
- );
144
- }
145
- }
146
-
147
- return this._request
148
- .post(
149
- `${this._baseUrl}/assets/types/${assetTypeId}/attributes`,
150
- toSnakeCase(assetAttribute)
151
- )
152
- .then((assetAttribute) => toCamelCase(assetAttribute));
153
- }
154
-
155
- /**
156
- * Deletes an asset attribute
157
- *
158
- * API Endpoint: '/assets/attributes/:assetAttributeId'
159
- * Method: DELETE
160
- *
161
- * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)
162
- *
163
- * @returns {Promise}
164
- * @fulfill {undefined}
165
- * @reject {Error}
166
- *
167
- * @example
168
- * contxtSdk.assets.attributes.delete('c7f927c3-11a7-4024-9269-e1231baeb765');
169
- */
170
- delete(assetAttributeId) {
171
- if (!assetAttributeId) {
172
- return Promise.reject(
173
- new Error(
174
- 'An asset attribute ID is required for deleting an asset attribute.'
175
- )
176
- );
177
- }
178
-
179
- return this._request.delete(
180
- `${this._baseUrl}/assets/attributes/${assetAttributeId}`
181
- );
182
- }
183
-
184
- /**
185
- * Gets information about an asset attribute
186
- *
187
- * API Endpoint: '/assets/attributes/:assetAttributeId'
188
- * Method: GET
189
- *
190
- * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)
191
- *
192
- * @returns {Promise}
193
- * @fulfill {AssetAttribute}
194
- * @reject {Error}
195
- *
196
- * @example
197
- * contxtSdk.assets.attributes
198
- * .get('c7f927c3-11a7-4024-9269-e1231baeb765')
199
- * .then((assetAttribute) => console.log(assetAttribute))
200
- * .catch((err) => console.log(err));
201
- */
202
- get(assetAttributeId) {
203
- if (!assetAttributeId) {
204
- return Promise.reject(
205
- new Error(
206
- 'An asset attribute ID is required for getting information about an asset attribute.'
207
- )
208
- );
209
- }
210
-
211
- return this._request
212
- .get(`${this._baseUrl}/assets/attributes/${assetAttributeId}`)
213
- .then((assetAttribute) => toCamelCase(assetAttribute));
214
- }
215
-
216
- /**
217
- * Gets a list of asset attributes for a specific asset type
218
- *
219
- * API Endpoint: '/assets/types/:assetTypeId/attributes'
220
- * Method: GET
221
- *
222
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
223
- * @param {PaginationOptions} [paginationOptions]
224
- *
225
- * @returns {Promise}
226
- * @fulfill {AssetAttributeData}
227
- * @reject {Error}
228
- *
229
- * @example
230
- * contxtSdk.assets.attributes
231
- * .getAll('4f0e51c6-728b-4892-9863-6d002e61204d')
232
- * .then((assetAttributesData) => console.log(assetAttributesData))
233
- * .catch((err) => console.log(err));
234
- */
235
- getAll(assetTypeId, paginationOptions) {
236
- if (!assetTypeId) {
237
- return Promise.reject(
238
- new Error(
239
- 'An asset type ID is required to get a list of all asset attributes.'
240
- )
241
- );
242
- }
243
-
244
- return this._request
245
- .get(`${this._baseUrl}/assets/types/${assetTypeId}/attributes`, {
246
- params: toSnakeCase(paginationOptions)
247
- })
248
- .then((assetAttributeData) =>
249
- formatPaginatedDataFromServer(assetAttributeData)
250
- );
251
- }
252
-
253
- /**
254
- * Updates an asset attribute
255
- *
256
- * API Endpoint: '/assets/attributes/:assetAttributeId'
257
- * Method: PUT
258
- *
259
- * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)
260
- * @param {Object} update An object containing the updated data for the asset attribute
261
- * @param {string} [update.dataType]
262
- * @param {string} [update.description]
263
- * @param {boolean} [update.isRequired]
264
- * @param {string} [update.label]
265
- * @param {string} [update.units]
266
- *
267
- * @returns {Promise}
268
- * @fulfill {undefined}
269
- * @reject {Error}
270
- *
271
- * @example
272
- * contxtSdk.assets.attributes
273
- * .update('c7f927c3-11a7-4024-9269-e1231baeb765', {
274
- * dataType: 'boolean',
275
- * description: 'Temperature of a facility',
276
- * isRequired: false,
277
- * label: 'Temperature',
278
- * units: 'Celsius'
279
- * });
280
- */
281
- update(assetAttributeId, update) {
282
- if (!assetAttributeId) {
283
- return Promise.reject(
284
- new Error(
285
- 'An asset attribute ID is required to update an asset attribute.'
286
- )
287
- );
288
- }
289
-
290
- if (!update) {
291
- return Promise.reject(
292
- new Error('An update is required to update an asset attribute.')
293
- );
294
- }
295
-
296
- if (!isPlainObject(update)) {
297
- return Promise.reject(
298
- new Error(
299
- 'The asset attribute update must be a well-formed object with the data you wish to update.'
300
- )
301
- );
302
- }
303
-
304
- const formattedUpdate = toSnakeCase(update, {
305
- excludeKeys: ['assetTypeId', 'id', 'organizationId']
306
- });
307
-
308
- return this._request.put(
309
- `${this._baseUrl}/assets/attributes/${assetAttributeId}`,
310
- formattedUpdate
311
- );
312
- }
313
-
314
- /**
315
- * Creates a new asset attribute value
316
- *
317
- * API Endpoint: '/assets/:assetId/attributes/:assetAttributeId/values'
318
- * Method: POST
319
- *
320
- * @param {string} assetId The ID of the asset type (formatted as a UUID)
321
- * @param {Object} assetAttributeValue
322
- * @param {string} assetAttributeValue.assetAttributeId UUID corresponding to the asset attribute
323
- * @param {string} assetAttributeValue.effectiveDate ISO 8601 Extended Format date/time string
324
- * @param {string} [assetAttributeValue.notes]
325
- * @param {string} assetAttributeValue.value
326
- *
327
- * @returns {Promise}
328
- * @fulfill {AssetAttributeValue}
329
- * @reject {Error}
330
- *
331
- * @example
332
- * contxtSdk.assets.attributes
333
- * .createValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
334
- * assetAttributeId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',
335
- * effectiveDate: '2018-07-09T14:36:36.004Z',
336
- * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',
337
- * value: '2206'
338
- * })
339
- * .then((assetAttributeValue) => console.log(assetAttributeValue))
340
- * .catch((err) => console.log(err));
341
- */
342
- createValue(assetId, assetAttributeValue = {}) {
343
- const requiredFields = ['assetAttributeId', 'effectiveDate', 'value'];
344
-
345
- if (!assetId) {
346
- return Promise.reject(
347
- new Error(
348
- 'An asset ID is required to create a new asset attribute value.'
349
- )
350
- );
351
- }
352
-
353
- for (let i = 0; i < requiredFields.length; i++) {
354
- const field = requiredFields[i];
355
-
356
- if (!assetAttributeValue[field]) {
357
- return Promise.reject(
358
- new Error(
359
- `A ${field} is required to create a new asset attribute value.`
360
- )
361
- );
362
- }
363
- }
364
-
365
- return this._request
366
- .post(
367
- `${this._baseUrl}/assets/${assetId}/attributes/${
368
- assetAttributeValue.assetAttributeId
369
- }/values`,
370
- toSnakeCase(assetAttributeValue)
371
- )
372
- .then((assetAttributeValue) => toCamelCase(assetAttributeValue));
373
- }
374
-
375
- /**
376
- * Deletes an asset attribute value
377
- *
378
- * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'
379
- * Method: DELETE
380
- *
381
- * @param {string} assetAttributeValueId The ID of the asset attribute value (formatted as a UUID)
382
- *
383
- * @returns {Promise}
384
- * @fulfill {undefined}
385
- * @reject {Error}
386
- *
387
- * @example
388
- * contxtSdk.assets.attributes.deleteValue(
389
- * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'
390
- * );
391
- */
392
- deleteValue(assetAttributeValueId) {
393
- if (!assetAttributeValueId) {
394
- return Promise.reject(
395
- new Error(
396
- 'An asset attribute value ID is required for deleting an asset attribute value.'
397
- )
398
- );
399
- }
400
-
401
- return this._request.delete(
402
- `${this._baseUrl}/assets/attributes/values/${assetAttributeValueId}`
403
- );
404
- }
405
-
406
- /**
407
- * Gets the effective attribute values for a particular asset
408
- *
409
- * API Endpoint: '/assets/:assetId/attributes/values'
410
- * Method: GET
411
- *
412
- * @param {String} assetId The ID of the asset for which you are looking up
413
- * attribute values (formatted as a UUID)
414
- * @param {Object} [assetAttributeFilters] Specific information that is used to
415
- * filter the list of asset attribute values
416
- * @param {String} [assetAttributeFilters.attributeLabel] Label of the parent
417
- * asset attribute
418
- * @param {String} [assetAttributeFilters.effectiveDate = (new Date()).toISOString()] Effective
419
- * date of the asset attribute values
420
- *
421
- * @returns {Promise}
422
- * @fulfill {AssetAttributeValue[]}
423
- * @rejects {Error}
424
- *
425
- * @example
426
- * contxtSdk.assets.attributes
427
- * .getEffectiveValuesByAssetId('d7329ef3-ca63-4ad5-bb3e-632b702584f8', {
428
- * attributeLabel: 'Square Footage',
429
- * effectiveDate: '2018-07-11T19:14:49.715Z'
430
- * })
431
- * .then((assetAttributeValues) => {
432
- * console.log(assetAttributeValues);
433
- * })
434
- * .catch((err) => console.log(err));
435
- */
436
- getEffectiveValuesByAssetId(assetId, assetAttributeFilters) {
437
- if (!assetId) {
438
- return Promise.reject(
439
- new Error(
440
- 'An asset ID is required to get a list of asset attribute values.'
441
- )
442
- );
443
- }
444
-
445
- return this._request
446
- .get(`${this._baseUrl}/assets/${assetId}/attributes/values`, {
447
- params: toSnakeCase(assetAttributeFilters)
448
- })
449
- .then((assetAttributeValues) => toCamelCase(assetAttributeValues));
450
- }
451
-
452
- /**
453
- * Gets a paginated list of effective asset attribute values for an
454
- * organization.
455
- *
456
- * API Endpoint: '/organizations/:organizationId/attributes/values'
457
- * Method: GET
458
- *
459
- * @param {String} organizationId UUID corresponding with an organization
460
- * @param {PaginationOptions} [paginationOptions]
461
- *
462
- * @returns {Promise}
463
- * @fulfill {AssetAttributeValueData}
464
- * @rejects {Error}
465
- *
466
- * @example
467
- * contxtSdk.assets.attributes
468
- * .getValuesByAttributeId(
469
- * '53fba880-70b7-47a2-b4e3-ad9ecfb67d5c',
470
- * {
471
- * limit: 100,
472
- * offset: 0
473
- * }
474
- * )
475
- * .then((assetAttributeValuesData) => {
476
- * console.log(assetAttributeValuesData);
477
- * })
478
- * .catch((err) => console.log(err));
479
- */
480
- getEffectiveValuesByOrganizationId(organizationId, paginationOptions) {
481
- if (!organizationId) {
482
- return Promise.reject(
483
- new Error(
484
- 'An organization ID is required to get a list of asset attribute values.'
485
- )
486
- );
487
- }
488
-
489
- return this._request
490
- .get(
491
- `${this._baseUrl}/organizations/${organizationId}/attributes/values`,
492
- { params: toSnakeCase(paginationOptions) }
493
- )
494
- .then((assetAttributeValueData) =>
495
- formatPaginatedDataFromServer(assetAttributeValueData)
496
- );
497
- }
498
-
499
- /**
500
- * Gets a paginated list of asset attribute values for a particular attribute
501
- * of a particular asset
502
- *
503
- * API Endpoint: '/assets/:assetId/attributes/:attributeId/values'
504
- * Method: GET
505
- *
506
- * @param {String} assetId The ID of the asset for which you are looking up
507
- * attribute values (formatted as a UUID)
508
- * @param {String} assetAttributeId The ID of the asset attribute for which you are
509
- * looking up attribute values (formatted as a UUID)
510
- * @param {PaginationOptions} [paginationOptions]
511
- *
512
- * @returns {Promise}
513
- * @fulfill {AssetAttributeValueData}
514
- * @rejects {Error}
515
- *
516
- * @example
517
- * contxtSdk.assets.attributes
518
- * .getValuesByAttributeId(
519
- * 'a4d80a97-cbf6-453b-bab5-0477e1ede04f',
520
- * 'c2779610-44d7-4313-aea2-96cce58d6efd',
521
- * {
522
- * limit: 100,
523
- * offset: 0
524
- * }
525
- * )
526
- * .then((assetAttributeValuesData) => {
527
- * console.log(assetAttributeValuesData);
528
- * })
529
- * .catch((err) => console.log(err));
530
- */
531
- getValuesByAttributeId(assetId, assetAttributeId, paginationOptions) {
532
- if (!assetId) {
533
- return Promise.reject(
534
- new Error(
535
- 'An asset ID is required to get a list of asset attribute values.'
536
- )
537
- );
538
- }
539
-
540
- if (!assetAttributeId) {
541
- return Promise.reject(
542
- new Error(
543
- 'An asset attribute ID is required to get a list of asset attribute values.'
544
- )
545
- );
546
- }
547
-
548
- return this._request
549
- .get(
550
- `${
551
- this._baseUrl
552
- }/assets/${assetId}/attributes/${assetAttributeId}/values`,
553
- { params: toSnakeCase(paginationOptions) }
554
- )
555
- .then((assetAttributeValueData) =>
556
- formatPaginatedDataFromServer(assetAttributeValueData)
557
- );
558
- }
559
-
560
- /**
561
- * Updates an asset attribute value
562
- *
563
- * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'
564
- * Method: PUT
565
- *
566
- * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)
567
- * @param {Object} update An object containing the updated data for the asset attribute value
568
- * @param {string} [update.effectiveDate] ISO 8601 Extended Format date/time string
569
- * @param {string} [update.notes]
570
- * @param {string} [update.value]
571
- *
572
- * @returns {Promise}
573
- * @fulfill {undefined}
574
- * @reject {Error}
575
- *
576
- * @example
577
- * contxtSdk.assets.attributes
578
- * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
579
- * effectiveDate: '2018-07-10T11:04:24.631Z',
580
- * notes: 'Dolores et sapiente sunt doloribus aut in.',
581
- * value: '61456'
582
- * })
583
- * .catch((err) => console.log(err));
584
- */
585
- updateValue(assetAttributeValueId, update) {
586
- if (!assetAttributeValueId) {
587
- return Promise.reject(
588
- new Error(
589
- 'An asset attribute value ID is required to update an asset attribute value.'
590
- )
591
- );
592
- }
593
-
594
- if (!update) {
595
- return Promise.reject(
596
- new Error('An update is required to update an asset attribute value.')
597
- );
598
- }
599
-
600
- if (!isPlainObject(update)) {
601
- return Promise.reject(
602
- new Error(
603
- 'The asset attribute value update must be a well-formed object with the data you wish to update.'
604
- )
605
- );
606
- }
607
-
608
- const formattedUpdate = toSnakeCase(update, {
609
- excludeKeys: ['assetAttributeId', 'assetId', 'id']
610
- });
611
-
612
- return this._request.put(
613
- `${this._baseUrl}/assets/attributes/values/${assetAttributeValueId}`,
614
- formattedUpdate
615
- );
616
- }
617
- }
618
-
619
- export default AssetAttributes;