@ndustrial/contxt-sdk 4.3.5 → 5.1.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.
Files changed (167) hide show
  1. package/.gitattributes +1 -0
  2. package/.nvmrc +1 -1
  3. package/CHANGELOG.md +8 -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,574 +0,0 @@
1
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- import has from 'lodash.has';
6
- import isPlainObject from 'lodash.isplainobject';
7
- import { toCamelCase, toSnakeCase } from '../utils/objects';
8
- import { formatPaginatedDataFromServer } from '../utils/pagination';
9
-
10
- /**
11
- * @typedef {Object} PaginationMetadata
12
- * @property {number} offset Offset of records in subsequent queries
13
- * @property {number} totalRecords Total number of asset attributes found
14
- */
15
-
16
- /**
17
- * @typedef {Object} PaginationOptions
18
- * @property {Number} limit Maximum number of records to return per query
19
- * @property {Number} offset How many records from the first record to start
20
- * the query
21
- */
22
-
23
- /**
24
- * @typedef {Object} AssetAttribute
25
- * @property {string} assetTypeId UUID corresponding with the asset type
26
- * @property {string} createdAt ISO 8601 Extended Format date/time string
27
- * @property {string} dataType Data Type of attribute with options "boolean", "date", "number", "string"
28
- * @property {string} description
29
- * @property {string} id UUID
30
- * @property {boolean} isRequired
31
- * @property {string} label
32
- * @property {string} organizationId UUID corresponding with the organization
33
- * @property {string} [units]
34
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
35
- */
36
-
37
- /**
38
- * @typedef {Object} AssetAttributeData
39
- * @property {PaginationMetadata} _metadata Metadata about the pagination settings
40
- * @property {AssetAttribute[]} records
41
- */
42
-
43
- /**
44
- * @typedef {Object} AssetAttributeValue
45
- * @property {Object} [asset] The associated parent asset. Will always be
46
- * present if retrieving more than one AssetAttributeValue.
47
- * @property {string} [asset.label] Label of the parent asset. Will always be
48
- * present if retrieving more than one AssetAttributeValue.
49
- * @property {Object} [assetAttribute] The associated parent assetAttribute.
50
- * Will always be present if retrieving more than one AssetAttributeValue.
51
- * @property {boolean} [assetAttribute.isRequired] Indication of required status
52
- * for the parent asset attribute. Will always be present if retrieving more
53
- * than one AssetAttributeValue.
54
- * @property {string} [assetAttribute.label] Label of the parent assetAttribute.
55
- * Will always be present if retrieving more than one AssetAttributeValue.
56
- * @property {string} [assetAttribute.units] Units of the parent assetAttribute.
57
- * Will always be present if retrieving more than one AssetAttributeValue.
58
- * @property {string} assetAttributeId UUID corresponding to the assetAttribute
59
- * @property {string} assetId UUID corresponding to the asset
60
- * @property {string} createdAt ISO 8601 Extended Format date/time string
61
- * @property {string} effectiveDate ISO 8601 Extended Format date/time string
62
- * @property {string} id UUID
63
- * @property {string} [notes]
64
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
65
- * @property {string} value
66
- */
67
-
68
- /**
69
- * @typedef {Object} AssetAttributeValueData
70
- * @property {PaginationMetadata} _metadata Metadata about the pagination settings
71
- * @property {AssetAttributeValue[]} records
72
- */
73
-
74
- /**
75
- * Module that provides access to, and the manipulation of, information about
76
- * different asset attributes and their values
77
- *
78
- * @typicalname contxtSdk.assets.attributes
79
- */
80
-
81
- var AssetAttributes = function () {
82
- /**
83
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
84
- * @param {Object} request An instance of the request module tied to this module's audience.
85
- * @param {string} baseUrl The base URL provided by the parent module
86
- */
87
- function AssetAttributes(sdk, request, baseUrl) {
88
- _classCallCheck(this, AssetAttributes);
89
-
90
- this._baseUrl = baseUrl;
91
- this._request = request;
92
- this._sdk = sdk;
93
- }
94
-
95
- /**
96
- * Creates a new asset attribute
97
- *
98
- * API Endpoint: '/assets/types/:assetTypeId/attributes'
99
- * Method: POST
100
- *
101
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
102
- * @param {Object} assetAttribute
103
- * @param {string} assetAttribute.dataType
104
- * @param {string} assetAttribute.description
105
- * @param {boolean} [assetAttribute.isRequired]
106
- * @param {string} assetAttribute.label
107
- * @param {string} assetAttribute.organizationId Can be explicitly set to `null` to create a global attribute
108
- * @param {string} [assetAttribute.units]
109
- *
110
- * @returns {Promise}
111
- * @fulfill {AssetAttribute}
112
- * @reject {Error}
113
- *
114
- * @example
115
- * contxtSdk.assets.attributes
116
- * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {
117
- * dataType: 'boolean',
118
- * description: 'Square footage of a facility',
119
- * isRequired: true,
120
- * label: 'Square Footage',
121
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',
122
- * units: 'sqft'
123
- * })
124
- * .then((assetAttribute) => console.log(assetAttribute))
125
- * .catch((err) => console.log(err));
126
- */
127
-
128
-
129
- _createClass(AssetAttributes, [{
130
- key: 'create',
131
- value: function create(assetTypeId) {
132
- var assetAttribute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
133
-
134
- var hasFieldFns = {
135
- default: function _default(object, key) {
136
- return !!object[key];
137
- },
138
- organizationId: function organizationId(object, key) {
139
- return has(object, key);
140
- }
141
- };
142
-
143
- var requiredFields = ['description', 'label', 'organizationId'];
144
-
145
- if (!assetTypeId) {
146
- return Promise.reject(new Error('An asset type ID is required to create a new asset attribute.'));
147
- }
148
-
149
- for (var i = 0; i < requiredFields.length; i++) {
150
- var field = requiredFields[i];
151
- var hasField = hasFieldFns[field] || hasFieldFns.default;
152
-
153
- if (!hasField(assetAttribute, field)) {
154
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset attribute.'));
155
- }
156
- }
157
-
158
- return this._request.post(this._baseUrl + '/assets/types/' + assetTypeId + '/attributes', toSnakeCase(assetAttribute)).then(function (assetAttribute) {
159
- return toCamelCase(assetAttribute);
160
- });
161
- }
162
-
163
- /**
164
- * Deletes an asset attribute
165
- *
166
- * API Endpoint: '/assets/attributes/:assetAttributeId'
167
- * Method: DELETE
168
- *
169
- * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)
170
- *
171
- * @returns {Promise}
172
- * @fulfill {undefined}
173
- * @reject {Error}
174
- *
175
- * @example
176
- * contxtSdk.assets.attributes.delete('c7f927c3-11a7-4024-9269-e1231baeb765');
177
- */
178
-
179
- }, {
180
- key: 'delete',
181
- value: function _delete(assetAttributeId) {
182
- if (!assetAttributeId) {
183
- return Promise.reject(new Error('An asset attribute ID is required for deleting an asset attribute.'));
184
- }
185
-
186
- return this._request.delete(this._baseUrl + '/assets/attributes/' + assetAttributeId);
187
- }
188
-
189
- /**
190
- * Gets information about an asset attribute
191
- *
192
- * API Endpoint: '/assets/attributes/:assetAttributeId'
193
- * Method: GET
194
- *
195
- * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)
196
- *
197
- * @returns {Promise}
198
- * @fulfill {AssetAttribute}
199
- * @reject {Error}
200
- *
201
- * @example
202
- * contxtSdk.assets.attributes
203
- * .get('c7f927c3-11a7-4024-9269-e1231baeb765')
204
- * .then((assetAttribute) => console.log(assetAttribute))
205
- * .catch((err) => console.log(err));
206
- */
207
-
208
- }, {
209
- key: 'get',
210
- value: function get(assetAttributeId) {
211
- if (!assetAttributeId) {
212
- return Promise.reject(new Error('An asset attribute ID is required for getting information about an asset attribute.'));
213
- }
214
-
215
- return this._request.get(this._baseUrl + '/assets/attributes/' + assetAttributeId).then(function (assetAttribute) {
216
- return toCamelCase(assetAttribute);
217
- });
218
- }
219
-
220
- /**
221
- * Gets a list of asset attributes for a specific asset type
222
- *
223
- * API Endpoint: '/assets/types/:assetTypeId/attributes'
224
- * Method: GET
225
- *
226
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
227
- * @param {PaginationOptions} [paginationOptions]
228
- *
229
- * @returns {Promise}
230
- * @fulfill {AssetAttributeData}
231
- * @reject {Error}
232
- *
233
- * @example
234
- * contxtSdk.assets.attributes
235
- * .getAll('4f0e51c6-728b-4892-9863-6d002e61204d')
236
- * .then((assetAttributesData) => console.log(assetAttributesData))
237
- * .catch((err) => console.log(err));
238
- */
239
-
240
- }, {
241
- key: 'getAll',
242
- value: function getAll(assetTypeId, paginationOptions) {
243
- if (!assetTypeId) {
244
- return Promise.reject(new Error('An asset type ID is required to get a list of all asset attributes.'));
245
- }
246
-
247
- return this._request.get(this._baseUrl + '/assets/types/' + assetTypeId + '/attributes', {
248
- params: toSnakeCase(paginationOptions)
249
- }).then(function (assetAttributeData) {
250
- return formatPaginatedDataFromServer(assetAttributeData);
251
- });
252
- }
253
-
254
- /**
255
- * Updates an asset attribute
256
- *
257
- * API Endpoint: '/assets/attributes/:assetAttributeId'
258
- * Method: PUT
259
- *
260
- * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)
261
- * @param {Object} update An object containing the updated data for the asset attribute
262
- * @param {string} [update.dataType]
263
- * @param {string} [update.description]
264
- * @param {boolean} [update.isRequired]
265
- * @param {string} [update.label]
266
- * @param {string} [update.units]
267
- *
268
- * @returns {Promise}
269
- * @fulfill {undefined}
270
- * @reject {Error}
271
- *
272
- * @example
273
- * contxtSdk.assets.attributes
274
- * .update('c7f927c3-11a7-4024-9269-e1231baeb765', {
275
- * dataType: 'boolean',
276
- * description: 'Temperature of a facility',
277
- * isRequired: false,
278
- * label: 'Temperature',
279
- * units: 'Celsius'
280
- * });
281
- */
282
-
283
- }, {
284
- key: 'update',
285
- value: function update(assetAttributeId, _update) {
286
- if (!assetAttributeId) {
287
- return Promise.reject(new Error('An asset attribute ID is required to update an asset attribute.'));
288
- }
289
-
290
- if (!_update) {
291
- return Promise.reject(new Error('An update is required to update an asset attribute.'));
292
- }
293
-
294
- if (!isPlainObject(_update)) {
295
- return Promise.reject(new Error('The asset attribute update must be a well-formed object with the data you wish to update.'));
296
- }
297
-
298
- var formattedUpdate = toSnakeCase(_update, {
299
- excludeKeys: ['assetTypeId', 'id', 'organizationId']
300
- });
301
-
302
- return this._request.put(this._baseUrl + '/assets/attributes/' + assetAttributeId, formattedUpdate);
303
- }
304
-
305
- /**
306
- * Creates a new asset attribute value
307
- *
308
- * API Endpoint: '/assets/:assetId/attributes/:assetAttributeId/values'
309
- * Method: POST
310
- *
311
- * @param {string} assetId The ID of the asset type (formatted as a UUID)
312
- * @param {Object} assetAttributeValue
313
- * @param {string} assetAttributeValue.assetAttributeId UUID corresponding to the asset attribute
314
- * @param {string} assetAttributeValue.effectiveDate ISO 8601 Extended Format date/time string
315
- * @param {string} [assetAttributeValue.notes]
316
- * @param {string} assetAttributeValue.value
317
- *
318
- * @returns {Promise}
319
- * @fulfill {AssetAttributeValue}
320
- * @reject {Error}
321
- *
322
- * @example
323
- * contxtSdk.assets.attributes
324
- * .createValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
325
- * assetAttributeId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',
326
- * effectiveDate: '2018-07-09T14:36:36.004Z',
327
- * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',
328
- * value: '2206'
329
- * })
330
- * .then((assetAttributeValue) => console.log(assetAttributeValue))
331
- * .catch((err) => console.log(err));
332
- */
333
-
334
- }, {
335
- key: 'createValue',
336
- value: function createValue(assetId) {
337
- var assetAttributeValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
338
-
339
- var requiredFields = ['assetAttributeId', 'effectiveDate', 'value'];
340
-
341
- if (!assetId) {
342
- return Promise.reject(new Error('An asset ID is required to create a new asset attribute value.'));
343
- }
344
-
345
- for (var i = 0; i < requiredFields.length; i++) {
346
- var field = requiredFields[i];
347
-
348
- if (!assetAttributeValue[field]) {
349
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset attribute value.'));
350
- }
351
- }
352
-
353
- return this._request.post(this._baseUrl + '/assets/' + assetId + '/attributes/' + assetAttributeValue.assetAttributeId + '/values', toSnakeCase(assetAttributeValue)).then(function (assetAttributeValue) {
354
- return toCamelCase(assetAttributeValue);
355
- });
356
- }
357
-
358
- /**
359
- * Deletes an asset attribute value
360
- *
361
- * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'
362
- * Method: DELETE
363
- *
364
- * @param {string} assetAttributeValueId The ID of the asset attribute value (formatted as a UUID)
365
- *
366
- * @returns {Promise}
367
- * @fulfill {undefined}
368
- * @reject {Error}
369
- *
370
- * @example
371
- * contxtSdk.assets.attributes.deleteValue(
372
- * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'
373
- * );
374
- */
375
-
376
- }, {
377
- key: 'deleteValue',
378
- value: function deleteValue(assetAttributeValueId) {
379
- if (!assetAttributeValueId) {
380
- return Promise.reject(new Error('An asset attribute value ID is required for deleting an asset attribute value.'));
381
- }
382
-
383
- return this._request.delete(this._baseUrl + '/assets/attributes/values/' + assetAttributeValueId);
384
- }
385
-
386
- /**
387
- * Gets the effective attribute values for a particular asset
388
- *
389
- * API Endpoint: '/assets/:assetId/attributes/values'
390
- * Method: GET
391
- *
392
- * @param {String} assetId The ID of the asset for which you are looking up
393
- * attribute values (formatted as a UUID)
394
- * @param {Object} [assetAttributeFilters] Specific information that is used to
395
- * filter the list of asset attribute values
396
- * @param {String} [assetAttributeFilters.attributeLabel] Label of the parent
397
- * asset attribute
398
- * @param {String} [assetAttributeFilters.effectiveDate = (new Date()).toISOString()] Effective
399
- * date of the asset attribute values
400
- *
401
- * @returns {Promise}
402
- * @fulfill {AssetAttributeValue[]}
403
- * @rejects {Error}
404
- *
405
- * @example
406
- * contxtSdk.assets.attributes
407
- * .getEffectiveValuesByAssetId('d7329ef3-ca63-4ad5-bb3e-632b702584f8', {
408
- * attributeLabel: 'Square Footage',
409
- * effectiveDate: '2018-07-11T19:14:49.715Z'
410
- * })
411
- * .then((assetAttributeValues) => {
412
- * console.log(assetAttributeValues);
413
- * })
414
- * .catch((err) => console.log(err));
415
- */
416
-
417
- }, {
418
- key: 'getEffectiveValuesByAssetId',
419
- value: function getEffectiveValuesByAssetId(assetId, assetAttributeFilters) {
420
- if (!assetId) {
421
- return Promise.reject(new Error('An asset ID is required to get a list of asset attribute values.'));
422
- }
423
-
424
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/attributes/values', {
425
- params: toSnakeCase(assetAttributeFilters)
426
- }).then(function (assetAttributeValues) {
427
- return toCamelCase(assetAttributeValues);
428
- });
429
- }
430
-
431
- /**
432
- * Gets a paginated list of effective asset attribute values for an
433
- * organization.
434
- *
435
- * API Endpoint: '/organizations/:organizationId/attributes/values'
436
- * Method: GET
437
- *
438
- * @param {String} organizationId UUID corresponding with an organization
439
- * @param {PaginationOptions} [paginationOptions]
440
- *
441
- * @returns {Promise}
442
- * @fulfill {AssetAttributeValueData}
443
- * @rejects {Error}
444
- *
445
- * @example
446
- * contxtSdk.assets.attributes
447
- * .getValuesByAttributeId(
448
- * '53fba880-70b7-47a2-b4e3-ad9ecfb67d5c',
449
- * {
450
- * limit: 100,
451
- * offset: 0
452
- * }
453
- * )
454
- * .then((assetAttributeValuesData) => {
455
- * console.log(assetAttributeValuesData);
456
- * })
457
- * .catch((err) => console.log(err));
458
- */
459
-
460
- }, {
461
- key: 'getEffectiveValuesByOrganizationId',
462
- value: function getEffectiveValuesByOrganizationId(organizationId, paginationOptions) {
463
- if (!organizationId) {
464
- return Promise.reject(new Error('An organization ID is required to get a list of asset attribute values.'));
465
- }
466
-
467
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/attributes/values', { params: toSnakeCase(paginationOptions) }).then(function (assetAttributeValueData) {
468
- return formatPaginatedDataFromServer(assetAttributeValueData);
469
- });
470
- }
471
-
472
- /**
473
- * Gets a paginated list of asset attribute values for a particular attribute
474
- * of a particular asset
475
- *
476
- * API Endpoint: '/assets/:assetId/attributes/:attributeId/values'
477
- * Method: GET
478
- *
479
- * @param {String} assetId The ID of the asset for which you are looking up
480
- * attribute values (formatted as a UUID)
481
- * @param {String} assetAttributeId The ID of the asset attribute for which you are
482
- * looking up attribute values (formatted as a UUID)
483
- * @param {PaginationOptions} [paginationOptions]
484
- *
485
- * @returns {Promise}
486
- * @fulfill {AssetAttributeValueData}
487
- * @rejects {Error}
488
- *
489
- * @example
490
- * contxtSdk.assets.attributes
491
- * .getValuesByAttributeId(
492
- * 'a4d80a97-cbf6-453b-bab5-0477e1ede04f',
493
- * 'c2779610-44d7-4313-aea2-96cce58d6efd',
494
- * {
495
- * limit: 100,
496
- * offset: 0
497
- * }
498
- * )
499
- * .then((assetAttributeValuesData) => {
500
- * console.log(assetAttributeValuesData);
501
- * })
502
- * .catch((err) => console.log(err));
503
- */
504
-
505
- }, {
506
- key: 'getValuesByAttributeId',
507
- value: function getValuesByAttributeId(assetId, assetAttributeId, paginationOptions) {
508
- if (!assetId) {
509
- return Promise.reject(new Error('An asset ID is required to get a list of asset attribute values.'));
510
- }
511
-
512
- if (!assetAttributeId) {
513
- return Promise.reject(new Error('An asset attribute ID is required to get a list of asset attribute values.'));
514
- }
515
-
516
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/attributes/' + assetAttributeId + '/values', { params: toSnakeCase(paginationOptions) }).then(function (assetAttributeValueData) {
517
- return formatPaginatedDataFromServer(assetAttributeValueData);
518
- });
519
- }
520
-
521
- /**
522
- * Updates an asset attribute value
523
- *
524
- * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'
525
- * Method: PUT
526
- *
527
- * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)
528
- * @param {Object} update An object containing the updated data for the asset attribute value
529
- * @param {string} [update.effectiveDate] ISO 8601 Extended Format date/time string
530
- * @param {string} [update.notes]
531
- * @param {string} [update.value]
532
- *
533
- * @returns {Promise}
534
- * @fulfill {undefined}
535
- * @reject {Error}
536
- *
537
- * @example
538
- * contxtSdk.assets.attributes
539
- * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
540
- * effectiveDate: '2018-07-10T11:04:24.631Z',
541
- * notes: 'Dolores et sapiente sunt doloribus aut in.',
542
- * value: '61456'
543
- * })
544
- * .catch((err) => console.log(err));
545
- */
546
-
547
- }, {
548
- key: 'updateValue',
549
- value: function updateValue(assetAttributeValueId, update) {
550
- if (!assetAttributeValueId) {
551
- return Promise.reject(new Error('An asset attribute value ID is required to update an asset attribute value.'));
552
- }
553
-
554
- if (!update) {
555
- return Promise.reject(new Error('An update is required to update an asset attribute value.'));
556
- }
557
-
558
- if (!isPlainObject(update)) {
559
- return Promise.reject(new Error('The asset attribute value update must be a well-formed object with the data you wish to update.'));
560
- }
561
-
562
- var formattedUpdate = toSnakeCase(update, {
563
- excludeKeys: ['assetAttributeId', 'assetId', 'id']
564
- });
565
-
566
- return this._request.put(this._baseUrl + '/assets/attributes/values/' + assetAttributeValueId, formattedUpdate);
567
- }
568
- }]);
569
-
570
- return AssetAttributes;
571
- }();
572
-
573
- export default AssetAttributes;
574
- //# sourceMappingURL=assetAttributes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["assets/assetAttributes.js"],"names":["has","isPlainObject","toCamelCase","toSnakeCase","formatPaginatedDataFromServer","AssetAttributes","sdk","request","baseUrl","_baseUrl","_request","_sdk","assetTypeId","assetAttribute","hasFieldFns","default","object","key","organizationId","requiredFields","Promise","reject","Error","i","length","field","hasField","post","then","assetAttributeId","delete","get","paginationOptions","params","assetAttributeData","update","formattedUpdate","excludeKeys","put","assetId","assetAttributeValue","assetAttributeValueId","assetAttributeFilters","assetAttributeValues","assetAttributeValueData"],"mappings":";;;;AAAA,OAAOA,GAAP,MAAgB,YAAhB;AACA,OAAOC,aAAP,MAA0B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mB;AACnE,UAAI,CAACO,OAAL,EAAc;AACZ,eAAOnB,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,kEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACO,gBAAL,EAAuB;AACrB,eAAOT,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,4EADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKZ,QAAL,CACJqB,GADI,CAGD,KAAKtB,QAHJ,gBAIQ8B,OAJR,oBAI8BV,gBAJ9B,cAKH,EAAEI,QAAQ9B,YAAY6B,iBAAZ,CAAV,EALG,EAOJJ,IAPI,CAOC,UAACgB,uBAAD;AAAA,eACJxC,8BAA8BwC,uBAA9B,CADI;AAAA,OAPD,CAAP;AAUD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAyBYH,qB,EAAuBN,M,EAAQ;AACzC,UAAI,CAACM,qBAAL,EAA4B;AAC1B,eAAOrB,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,6EADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACa,MAAL,EAAa;AACX,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,2DAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACrB,cAAckC,MAAd,CAAL,EAA4B;AAC1B,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,iGADF,CADK,CAAP;AAKD;;AAED,UAAMc,kBAAkBjC,YAAYgC,MAAZ,EAAoB;AAC1CE,qBAAa,CAAC,kBAAD,EAAqB,SAArB,EAAgC,IAAhC;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAK3B,QAAL,CAAc4B,GAAd,CACF,KAAK7B,QADH,kCACwCgC,qBADxC,EAELL,eAFK,CAAP;AAID;;;;;;AAGH,eAAe/B,eAAf","file":"assetAttributes.js","sourcesContent":["import has from 'lodash.has';\nimport isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\nimport { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} PaginationMetadata\n * @property {number} offset Offset of records in subsequent queries\n * @property {number} totalRecords Total number of asset attributes found\n */\n\n/**\n * @typedef {Object} PaginationOptions\n * @property {Number} limit Maximum number of records to return per query\n * @property {Number} offset How many records from the first record to start\n * the query\n */\n\n/**\n * @typedef {Object} AssetAttribute\n * @property {string} assetTypeId UUID corresponding with the asset type\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} dataType Data Type of attribute with options \"boolean\", \"date\", \"number\", \"string\"\n * @property {string} description\n * @property {string} id UUID\n * @property {boolean} isRequired\n * @property {string} label\n * @property {string} organizationId UUID corresponding with the organization\n * @property {string} [units]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} AssetAttributeData\n * @property {PaginationMetadata} _metadata Metadata about the pagination settings\n * @property {AssetAttribute[]} records\n */\n\n/**\n * @typedef {Object} AssetAttributeValue\n * @property {Object} [asset] The associated parent asset. Will always be\n * present if retrieving more than one AssetAttributeValue.\n * @property {string} [asset.label] Label of the parent asset. Will always be\n * present if retrieving more than one AssetAttributeValue.\n * @property {Object} [assetAttribute] The associated parent assetAttribute.\n * Will always be present if retrieving more than one AssetAttributeValue.\n * @property {boolean} [assetAttribute.isRequired] Indication of required status\n * for the parent asset attribute. Will always be present if retrieving more\n * than one AssetAttributeValue.\n * @property {string} [assetAttribute.label] Label of the parent assetAttribute.\n * Will always be present if retrieving more than one AssetAttributeValue.\n * @property {string} [assetAttribute.units] Units of the parent assetAttribute.\n * Will always be present if retrieving more than one AssetAttributeValue.\n * @property {string} assetAttributeId UUID corresponding to the assetAttribute\n * @property {string} assetId UUID corresponding to the asset\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} effectiveDate ISO 8601 Extended Format date/time string\n * @property {string} id UUID\n * @property {string} [notes]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n * @property {string} value\n */\n\n/**\n * @typedef {Object} AssetAttributeValueData\n * @property {PaginationMetadata} _metadata Metadata about the pagination settings\n * @property {AssetAttributeValue[]} records\n */\n\n/**\n * Module that provides access to, and the manipulation of, information about\n * different asset attributes and their values\n *\n * @typicalname contxtSdk.assets.attributes\n */\nclass AssetAttributes {\n /**\n * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.\n * @param {Object} request An instance of the request module tied to this module's audience.\n * @param {string} baseUrl The base URL provided by the parent module\n */\n constructor(sdk, request, baseUrl) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n }\n\n /**\n * Creates a new asset attribute\n *\n * API Endpoint: '/assets/types/:assetTypeId/attributes'\n * Method: POST\n *\n * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)\n * @param {Object} assetAttribute\n * @param {string} assetAttribute.dataType\n * @param {string} assetAttribute.description\n * @param {boolean} [assetAttribute.isRequired]\n * @param {string} assetAttribute.label\n * @param {string} assetAttribute.organizationId Can be explicitly set to `null` to create a global attribute\n * @param {string} [assetAttribute.units]\n *\n * @returns {Promise}\n * @fulfill {AssetAttribute}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {\n * dataType: 'boolean',\n * description: 'Square footage of a facility',\n * isRequired: true,\n * label: 'Square Footage',\n * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',\n * units: 'sqft'\n * })\n * .then((assetAttribute) => console.log(assetAttribute))\n * .catch((err) => console.log(err));\n */\n create(assetTypeId, assetAttribute = {}) {\n const hasFieldFns = {\n default: (object, key) => !!object[key],\n organizationId: (object, key) => has(object, key)\n };\n\n const requiredFields = ['description', 'label', 'organizationId'];\n\n if (!assetTypeId) {\n return Promise.reject(\n new Error(\n 'An asset type ID is required to create a new asset attribute.'\n )\n );\n }\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n const hasField = hasFieldFns[field] || hasFieldFns.default;\n\n if (!hasField(assetAttribute, field)) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new asset attribute.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/assets/types/${assetTypeId}/attributes`,\n toSnakeCase(assetAttribute)\n )\n .then((assetAttribute) => toCamelCase(assetAttribute));\n }\n\n /**\n * Deletes an asset attribute\n *\n * API Endpoint: '/assets/attributes/:assetAttributeId'\n * Method: DELETE\n *\n * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes.delete('c7f927c3-11a7-4024-9269-e1231baeb765');\n */\n delete(assetAttributeId) {\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required for deleting an asset attribute.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/assets/attributes/${assetAttributeId}`\n );\n }\n\n /**\n * Gets information about an asset attribute\n *\n * API Endpoint: '/assets/attributes/:assetAttributeId'\n * Method: GET\n *\n * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {AssetAttribute}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .get('c7f927c3-11a7-4024-9269-e1231baeb765')\n * .then((assetAttribute) => console.log(assetAttribute))\n * .catch((err) => console.log(err));\n */\n get(assetAttributeId) {\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required for getting information about an asset attribute.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/attributes/${assetAttributeId}`)\n .then((assetAttribute) => toCamelCase(assetAttribute));\n }\n\n /**\n * Gets a list of asset attributes for a specific asset type\n *\n * API Endpoint: '/assets/types/:assetTypeId/attributes'\n * Method: GET\n *\n * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeData}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getAll('4f0e51c6-728b-4892-9863-6d002e61204d')\n * .then((assetAttributesData) => console.log(assetAttributesData))\n * .catch((err) => console.log(err));\n */\n getAll(assetTypeId, paginationOptions) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error(\n 'An asset type ID is required to get a list of all asset attributes.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/types/${assetTypeId}/attributes`, {\n params: toSnakeCase(paginationOptions)\n })\n .then((assetAttributeData) =>\n formatPaginatedDataFromServer(assetAttributeData)\n );\n }\n\n /**\n * Updates an asset attribute\n *\n * API Endpoint: '/assets/attributes/:assetAttributeId'\n * Method: PUT\n *\n * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset attribute\n * @param {string} [update.dataType]\n * @param {string} [update.description]\n * @param {boolean} [update.isRequired]\n * @param {string} [update.label]\n * @param {string} [update.units]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .update('c7f927c3-11a7-4024-9269-e1231baeb765', {\n * dataType: 'boolean',\n * description: 'Temperature of a facility',\n * isRequired: false,\n * label: 'Temperature',\n * units: 'Celsius'\n * });\n */\n update(assetAttributeId, update) {\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required to update an asset attribute.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset attribute.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset attribute update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n const formattedUpdate = toSnakeCase(update, {\n excludeKeys: ['assetTypeId', 'id', 'organizationId']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/attributes/${assetAttributeId}`,\n formattedUpdate\n );\n }\n\n /**\n * Creates a new asset attribute value\n *\n * API Endpoint: '/assets/:assetId/attributes/:assetAttributeId/values'\n * Method: POST\n *\n * @param {string} assetId The ID of the asset type (formatted as a UUID)\n * @param {Object} assetAttributeValue\n * @param {string} assetAttributeValue.assetAttributeId UUID corresponding to the asset attribute\n * @param {string} assetAttributeValue.effectiveDate ISO 8601 Extended Format date/time string\n * @param {string} [assetAttributeValue.notes]\n * @param {string} assetAttributeValue.value\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValue}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .createValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {\n * assetAttributeId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',\n * effectiveDate: '2018-07-09T14:36:36.004Z',\n * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',\n * value: '2206'\n * })\n * .then((assetAttributeValue) => console.log(assetAttributeValue))\n * .catch((err) => console.log(err));\n */\n createValue(assetId, assetAttributeValue = {}) {\n const requiredFields = ['assetAttributeId', 'effectiveDate', 'value'];\n\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to create a new asset attribute value.'\n )\n );\n }\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!assetAttributeValue[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new asset attribute value.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/assets/${assetId}/attributes/${\n assetAttributeValue.assetAttributeId\n }/values`,\n toSnakeCase(assetAttributeValue)\n )\n .then((assetAttributeValue) => toCamelCase(assetAttributeValue));\n }\n\n /**\n * Deletes an asset attribute value\n *\n * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'\n * Method: DELETE\n *\n * @param {string} assetAttributeValueId The ID of the asset attribute value (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes.deleteValue(\n * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'\n * );\n */\n deleteValue(assetAttributeValueId) {\n if (!assetAttributeValueId) {\n return Promise.reject(\n new Error(\n 'An asset attribute value ID is required for deleting an asset attribute value.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/assets/attributes/values/${assetAttributeValueId}`\n );\n }\n\n /**\n * Gets the effective attribute values for a particular asset\n *\n * API Endpoint: '/assets/:assetId/attributes/values'\n * Method: GET\n *\n * @param {String} assetId The ID of the asset for which you are looking up\n * attribute values (formatted as a UUID)\n * @param {Object} [assetAttributeFilters] Specific information that is used to\n * filter the list of asset attribute values\n * @param {String} [assetAttributeFilters.attributeLabel] Label of the parent\n * asset attribute\n * @param {String} [assetAttributeFilters.effectiveDate = (new Date()).toISOString()] Effective\n * date of the asset attribute values\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValue[]}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getEffectiveValuesByAssetId('d7329ef3-ca63-4ad5-bb3e-632b702584f8', {\n * attributeLabel: 'Square Footage',\n * effectiveDate: '2018-07-11T19:14:49.715Z'\n * })\n * .then((assetAttributeValues) => {\n * console.log(assetAttributeValues);\n * })\n * .catch((err) => console.log(err));\n */\n getEffectiveValuesByAssetId(assetId, assetAttributeFilters) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/${assetId}/attributes/values`, {\n params: toSnakeCase(assetAttributeFilters)\n })\n .then((assetAttributeValues) => toCamelCase(assetAttributeValues));\n }\n\n /**\n * Gets a paginated list of effective asset attribute values for an\n * organization.\n *\n * API Endpoint: '/organizations/:organizationId/attributes/values'\n * Method: GET\n *\n * @param {String} organizationId UUID corresponding with an organization\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValueData}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getValuesByAttributeId(\n * '53fba880-70b7-47a2-b4e3-ad9ecfb67d5c',\n * {\n * limit: 100,\n * offset: 0\n * }\n * )\n * .then((assetAttributeValuesData) => {\n * console.log(assetAttributeValuesData);\n * })\n * .catch((err) => console.log(err));\n */\n getEffectiveValuesByOrganizationId(organizationId, paginationOptions) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n return this._request\n .get(\n `${this._baseUrl}/organizations/${organizationId}/attributes/values`,\n { params: toSnakeCase(paginationOptions) }\n )\n .then((assetAttributeValueData) =>\n formatPaginatedDataFromServer(assetAttributeValueData)\n );\n }\n\n /**\n * Gets a paginated list of asset attribute values for a particular attribute\n * of a particular asset\n *\n * API Endpoint: '/assets/:assetId/attributes/:attributeId/values'\n * Method: GET\n *\n * @param {String} assetId The ID of the asset for which you are looking up\n * attribute values (formatted as a UUID)\n * @param {String} assetAttributeId The ID of the asset attribute for which you are\n * looking up attribute values (formatted as a UUID)\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValueData}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getValuesByAttributeId(\n * 'a4d80a97-cbf6-453b-bab5-0477e1ede04f',\n * 'c2779610-44d7-4313-aea2-96cce58d6efd',\n * {\n * limit: 100,\n * offset: 0\n * }\n * )\n * .then((assetAttributeValuesData) => {\n * console.log(assetAttributeValuesData);\n * })\n * .catch((err) => console.log(err));\n */\n getValuesByAttributeId(assetId, assetAttributeId, paginationOptions) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/assets/${assetId}/attributes/${assetAttributeId}/values`,\n { params: toSnakeCase(paginationOptions) }\n )\n .then((assetAttributeValueData) =>\n formatPaginatedDataFromServer(assetAttributeValueData)\n );\n }\n\n /**\n * Updates an asset attribute value\n *\n * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'\n * Method: PUT\n *\n * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset attribute value\n * @param {string} [update.effectiveDate] ISO 8601 Extended Format date/time string\n * @param {string} [update.notes]\n * @param {string} [update.value]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {\n * effectiveDate: '2018-07-10T11:04:24.631Z',\n * notes: 'Dolores et sapiente sunt doloribus aut in.',\n * value: '61456'\n * })\n * .catch((err) => console.log(err));\n */\n updateValue(assetAttributeValueId, update) {\n if (!assetAttributeValueId) {\n return Promise.reject(\n new Error(\n 'An asset attribute value ID is required to update an asset attribute value.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset attribute value.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset attribute value update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n const formattedUpdate = toSnakeCase(update, {\n excludeKeys: ['assetAttributeId', 'assetId', 'id']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/attributes/values/${assetAttributeValueId}`,\n formattedUpdate\n );\n }\n}\n\nexport default AssetAttributes;\n"]}