@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,690 +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 _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- import has from 'lodash.has';
8
- import isPlainObject from 'lodash.isplainobject';
9
- import { toCamelCase, toSnakeCase } from '../utils/objects';
10
- import { stringifyParamsWithCommaSeparatedArrays } from '../utils/url';
11
- import { formatPaginatedDataFromServer } from '../utils/pagination';
12
-
13
- /**
14
- * @typedef {Object} AssetMetric
15
- * @property {string} assetTypeId UUID corresponding with the asset type
16
- * @property {string} createdAt ISO 8601 Extended Format date/time string
17
- * @property {string} description
18
- * @property {string} id UUID
19
- * @property {string} label
20
- * @property {string} organizationId UUID corresponding with the organization
21
- * @property {string} timeInterval Options are "hourly", "daily", "weekly", "monthly", "yearly"
22
- * @property {string} [units]
23
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
24
- */
25
-
26
- /**
27
- * @typedef {Object} AssetMetricsFromServer
28
- * @property {Object} _metadata Metadata about the pagination settings
29
- * @property {number} _metadata.offset Offset of records in subsequent queries
30
- * @property {number} _metadata.totalRecords Total number of asset types found
31
- * @property {AssetMetric[]} records
32
- */
33
-
34
- /**
35
- * @typedef {Object} AssetMetricValue
36
- * @property {string} assetId UUID corresponding to the asset
37
- * @property {string} assetMetricId UUID corresponding to the asset metric
38
- * @property {string} createdAt ISO 8601 Extended Format date/time string
39
- * @property {string} effectiveEndDate ISO 8601 Extended Format date/time string
40
- * @property {string} effectiveStartDate ISO 8601 Extended Format date/time string
41
- * @property {string} id UUID
42
- * @property {string} notes
43
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
44
- * @property {string} value
45
- * @property {boolean} isEstimated Whether the value is an estimation or a true reading
46
- */
47
-
48
- /**
49
- * @typedef {Object} AssetMetricValuesFromServer
50
- * @property {Object} _metadata Metadata about the pagination settings
51
- * @property {number} _metadata.offset Offset of records in subsequent queries
52
- * @property {number} _metadata.totalRecords Total number of asset types found
53
- * @property {AssetMetricValue[]} records
54
- */
55
-
56
- /**
57
- * @typedef {Object} AssetMetricValueCompact
58
- * @property {string} id the UUID corresponding to the asset metric value id
59
- * @property {string} value
60
- * @property {boolean} is_estimated
61
- * @property {string} effectiveEndDate ISO 8601 Extended Format date/time string
62
- * @property {string} effectiveStartDate ISO 8601 Extended Format date/time string
63
- */
64
-
65
- /**
66
- * @typedef {Object.<AssetMetric.label, AssetMetricValueCompact[]>} AssetMetricsKeyedByMetricId
67
- */
68
-
69
- /**
70
- * An object with asset ids as keys to another object with asset metric labels as keys.
71
- * At this final level the object contains arrays of {@link AssetMetricValueCompact}
72
- * @typedef {Object.<Asset.id, AssetMetricsKeyedByMetricId>} AssetMetricValuesByAssetIdMetricId
73
- * @example
74
- * {
75
- * "b47e45af-3e18-408a-8070-008f9e6d7b42" : {
76
- * "facility_daily_cuft": [
77
- * {
78
- * "id": "cf7e45af-3e18-408a-8070-008f9e6d7b3j",
79
- * "value": 10,
80
- * "isEstimated": false,
81
- * "effectiveEndDate": "2018-07-10T11:04:24.631Z",
82
- * "effectiveStartDate" "2018-07-10T11:04:24.631Z"
83
- * }
84
- * ]
85
- * }
86
- * }
87
- */
88
-
89
- /**
90
- * Module that provides access to, and the manipulation of, information about different asset metrics
91
- *
92
- * @typicalname contxtSdk.assets.metrics
93
- */
94
-
95
- var AssetMetrics = function () {
96
- /**
97
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
98
- * @param {Object} request An instance of the request module tied to this module's audience.
99
- * @param {string} baseUrl The base URL provided by the parent module
100
- */
101
- function AssetMetrics(sdk, request, baseUrl) {
102
- _classCallCheck(this, AssetMetrics);
103
-
104
- this._baseUrl = baseUrl;
105
- this._request = request;
106
- this._sdk = sdk;
107
- }
108
-
109
- /**
110
- * Creates a new asset metric
111
- *
112
- * API Endpoint: '/assets/types/:assetTypeId/metrics'
113
- * Method: POST
114
- *
115
- * @param {string} assetTypeId The UUID formatted ID of the asset type
116
- * @param {Object} assetMetric
117
- * @param {string} assetMetric.description
118
- * @param {string} assetMetric.label
119
- * @param {string} assetMetric.organizationId Organization ID (UUID) to which the metric belongs
120
- * @param {string} assetMetric.timeInterval Options are "hourly", "daily", "weekly", "monthly", "yearly"
121
- * @param {string} [assetMetric.units] Units of the metric
122
- *
123
- * @returns {Promise}
124
- * @fulfill {AssetMetric} Information about the new asset metric
125
- * @reject {Error}
126
- *
127
- * @example
128
- * contxtSdk.assets.metrics
129
- * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {
130
- * description: 'Number of injuries which occur in the facility each month',
131
- * label: 'Facility Injuries',
132
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',
133
- * timeInterval: 'monthly',
134
- * units: 'injuries'
135
- * })
136
- * .then((assetMetric) => console.log(assetMetric))
137
- * .catch((err) => console.log(err));
138
- */
139
-
140
-
141
- _createClass(AssetMetrics, [{
142
- key: 'create',
143
- value: function create(assetTypeId) {
144
- var assetMetric = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
145
-
146
- if (!assetTypeId) {
147
- return Promise.reject(new Error('An asset type ID is required to create an asset metric.'));
148
- }
149
-
150
- var hasFieldFns = {
151
- default: function _default(object, key) {
152
- return !!object[key];
153
- },
154
- organizationId: function organizationId(object, key) {
155
- return has(object, key);
156
- }
157
- };
158
- var requiredFields = ['description', 'label', 'organizationId', 'timeInterval'];
159
-
160
- for (var i = 0; i < requiredFields.length; i++) {
161
- var field = requiredFields[i];
162
- var hasField = hasFieldFns[field] || hasFieldFns.default;
163
-
164
- if (!hasField(assetMetric, field)) {
165
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset metric.'));
166
- }
167
- }
168
-
169
- return this._request.post(this._baseUrl + '/assets/types/' + assetTypeId + '/metrics', toSnakeCase(assetMetric)).then(function (assetMetric) {
170
- return toCamelCase(assetMetric);
171
- });
172
- }
173
-
174
- /**
175
- * Deletes an asset metric
176
- *
177
- * API Endpoint: '/assets/metrics/:assetMetricId'
178
- * Method: DELETE
179
- *
180
- * @param {string} assetMetricId The UUID formatted ID of the asset metric
181
- *
182
- * @returns {Promise}
183
- * @fulfill {undefined}
184
- * @reject {Error}
185
- *
186
- * @example
187
- * contxtSdk.assets.metrics.delete('4f0e51c6-728b-4892-9863-6d002e61204d');
188
- */
189
-
190
- }, {
191
- key: 'delete',
192
- value: function _delete(assetMetricId) {
193
- if (!assetMetricId) {
194
- return Promise.reject(new Error('An asset metric ID is required for deleting an asset metric.'));
195
- }
196
-
197
- return this._request.delete(this._baseUrl + '/assets/metrics/' + assetMetricId);
198
- }
199
-
200
- /**
201
- * Gets information about an asset metric
202
- *
203
- * API Endpoint: '/assets/metrics/:assetMetricId'
204
- * Method: GET
205
- *
206
- * @param {string} assetMetricId The UUID formatted ID of the asset metric
207
- *
208
- * @returns {Promise}
209
- * @fulfill {AssetMetric} Information about the asset metric
210
- * @reject {Error}
211
- *
212
- * @example
213
- * contxtSdk.assets.metrics
214
- * .get('4f0e51c6-728b-4892-9863-6d002e61204d')
215
- * .then((assetMetric) => console.log(assetMetric))
216
- * .catch((err) => console.log(err));
217
- */
218
-
219
- }, {
220
- key: 'get',
221
- value: function get(assetMetricId) {
222
- if (!assetMetricId) {
223
- return Promise.reject(new Error('An asset metric ID is required for getting information about an asset metric.'));
224
- }
225
-
226
- return this._request.get(this._baseUrl + '/assets/metrics/' + assetMetricId).then(function (assetMetric) {
227
- return toCamelCase(assetMetric);
228
- });
229
- }
230
-
231
- /**
232
- * Gets a list of all asset metrics that belong to a given asset
233
- *
234
- * API Endpoint: '/assets/:assetId/metrics
235
- * Method: GET
236
- *
237
- * @param {string} assetId The UUID formatted ID of the asset type
238
- * @param {Object} [assetMetricsFilters] Specific information that is used to
239
- * filter the list of asset metrics
240
- * @param {String} [assetMetricsFilters.assetMetricLabel] The label of the
241
- * associated asset metrics
242
- * @param {Number} [assetMetricsFilters.limit] Maximum number of records to
243
- * return per query
244
- * @param {Number} [assetMetricsFilters.offset] How many records from the first
245
- * record to start the query
246
- *
247
- * @returns {Promise}
248
- * @fulfill {AssetMetricsFromServer}
249
- * @reject {Error}
250
- *
251
- * @example
252
- * contxtSdk.assets.metrics
253
- * .getByAssetId(
254
- * 'f3be81fd-4494-443b-87a3-320b1c9aa495',
255
- * {
256
- * assetMetricLabel: 'Square Footage',
257
- * limit: 50,
258
- * offset: 150
259
- * }
260
- * )
261
- * .then((assetMetricData) => console.log(assetMetricData))
262
- * .catch((err) => console.log(err));
263
- */
264
-
265
- }, {
266
- key: 'getByAssetId',
267
- value: function getByAssetId(assetId, assetMetricsFilters) {
268
- if (!assetId) {
269
- return Promise.reject(new Error('An asset ID is required to get a list of all asset metrics.'));
270
- }
271
-
272
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/metrics', {
273
- params: toSnakeCase(assetMetricsFilters)
274
- }).then(function (assetMetricsData) {
275
- return formatPaginatedDataFromServer(assetMetricsData);
276
- });
277
- }
278
-
279
- /**
280
- * Gets a list of all asset metrics that belong to a given type
281
- *
282
- * API Endpoint: '/assets/types/:assetTypeId/metrics
283
- * Method: GET
284
- *
285
- * @param {string} assetTypeId The UUID formatted ID of the asset type
286
- * @param {Object} [assetMetricsFilters] Specific information that is used to
287
- * filter the list of asset metrics
288
- * @param {Number} [assetMetricsFilters.limit] Maximum number of records to
289
- * return per query
290
- * @param {Number} [assetMetricsFilters.offset] How many records from the first
291
- * record to start the query
292
- * @param {String} [assetMetricsFilters.organizationId] The UUID formatted ID
293
- * of the organization to filter asset metrics by
294
- *
295
- * @returns {Promise}
296
- * @fulfill {AssetMetricsFromServer}
297
- * @reject {Error}
298
- *
299
- * @example
300
- * contxtSdk.assets.metrics
301
- * .getByAssetTypeId(
302
- * '4f0e51c6-728b-4892-9863-6d002e61204d'
303
- * {
304
- * limit: 50,
305
- * offset: 150
306
- * }
307
- * )
308
- * .then((assetMetrics) => console.log(assetMetrics))
309
- * .catch((err) => console.log(err));
310
- */
311
-
312
- }, {
313
- key: 'getByAssetTypeId',
314
- value: function getByAssetTypeId(assetTypeId, assetMetricsFilters) {
315
- if (!assetTypeId) {
316
- return Promise.reject(new Error('An asset type ID is required to get a list of all asset metrics.'));
317
- }
318
-
319
- return this._request.get(this._baseUrl + '/assets/types/' + assetTypeId + '/metrics', {
320
- params: toSnakeCase(assetMetricsFilters)
321
- }).then(function (assetMetricsData) {
322
- return formatPaginatedDataFromServer(assetMetricsData);
323
- });
324
- }
325
-
326
- /**
327
- * Updates an asset metric's data
328
- *
329
- * API Endpoint: '/assets/metrics/:assetMetricId'
330
- * Method: PUT
331
- *
332
- * @param {string} assetMetricId The ID of the asset metric to update (formatted as a UUID)
333
- * @param {Object} update An object containing the updated data for the asset metric
334
- * @param {string} [update.description]
335
- * @param {string} [update.label]
336
- * @param {string} [update.timeInterval]
337
- * @param {string} [update.units]
338
- *
339
- * @returns {Promise}
340
- * @fulfill {undefined}
341
- * @reject {Error}
342
- *
343
- * @example
344
- * contxtSdk.assets.metrics
345
- * .update('5f310899-d8f9-4dac-ae82-cedb2048a8ef', {
346
- * description: 'An updated description of this metric'
347
- * });
348
- */
349
-
350
- }, {
351
- key: 'update',
352
- value: function update(assetMetricId, _update) {
353
- if (!assetMetricId) {
354
- return Promise.reject(new Error('An asset metric ID is required to update an asset metric.'));
355
- }
356
-
357
- if (!_update) {
358
- return Promise.reject(new Error('An update is required to update an asset metric.'));
359
- }
360
-
361
- if (!isPlainObject(_update)) {
362
- return Promise.reject(new Error('The asset metric update must be a well-formed object with the data you wish to update.'));
363
- }
364
-
365
- var formattedUpdate = toSnakeCase(_update, {
366
- excludeKeys: ['createdAt', 'id', 'label', 'organizationId', 'updatedAt']
367
- });
368
-
369
- return this._request.put(this._baseUrl + '/assets/metrics/' + assetMetricId, formattedUpdate);
370
- }
371
-
372
- /**
373
- * Creates a new asset metric value
374
- *
375
- * API Endpoint: '/assets/:assetId/metrics/:assetMetricId/values'
376
- * Method: POST
377
- *
378
- * @param {string} assetId The ID of the asset (formatted as a UUID)
379
- * @param {Object} assetMetricValue
380
- * @param {string} assetMetricValue.assetMetricId UUID corresponding to the asset metric
381
- * @param {string} assetMetricValue.effectiveEndDate ISO 8601 Extended Format date/time string
382
- * @param {string} assetMetricValue.effectiveStartDate ISO 8601 Extended Format date/time string
383
- * @param {string} [assetMetricValue.notes]
384
- * @param {string} assetMetricValue.value
385
- * @param {boolean} [assetMetricValue.isEstimated] Whether the value is an estimation or a true reading
386
- *
387
- * @returns {Promise}
388
- * @fulfill {AssetMetricValue}
389
- * @reject {Error}
390
- *
391
- * @example
392
- * contxtSdk.assets.metrics
393
- * .createValue('1140cc2e-6d13-42ee-9941-487fe98f8e2d', {
394
- * assetMetricId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',
395
- * effectiveEndDate: '2018-08-28T18:18:18.264Z',
396
- * effectiveStartDate: '2018-08-27T18:18:03.175Z',
397
- * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',
398
- * value: '2000',
399
- * isEstimated: true
400
- * })
401
- * .then((newAssetMetricValue) => {
402
- * console.log(newAssetMetricValue);
403
- * })
404
- * .catch((error) => {
405
- * console.error(error);
406
- * });
407
- */
408
-
409
- }, {
410
- key: 'createValue',
411
- value: function createValue(assetId) {
412
- var assetMetricValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
413
-
414
- var requiredFields = ['assetMetricId', 'effectiveEndDate', 'effectiveStartDate', 'value'];
415
-
416
- if (!assetId) {
417
- return Promise.reject(new Error('An asset ID is required to create a new asset metric value.'));
418
- }
419
-
420
- for (var i = 0; i < requiredFields.length; i++) {
421
- var field = requiredFields[i];
422
-
423
- if (!assetMetricValue[field]) {
424
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset metric value.'));
425
- }
426
- }
427
-
428
- return this._request.post(this._baseUrl + '/assets/' + assetId + '/metrics/' + assetMetricValue.assetMetricId + '/values', toSnakeCase(assetMetricValue)).then(function (assetMetricValue) {
429
- return toCamelCase(assetMetricValue);
430
- });
431
- }
432
-
433
- /**
434
- * Deletes an asset metric value
435
- *
436
- * API Endpoint: '/assets/metrics/values/:assetMetricValueId'
437
- * Method: DELETE
438
- *
439
- * @param {string} assetMetricValueId The ID of the asset metric value (formatted as a UUID)
440
- *
441
- * @returns {Promise}
442
- * @fulfill {undefined}
443
- * @reject {Error}
444
- *
445
- * @example
446
- * contxtSdk.assets.metrics.deleteValue(
447
- * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'
448
- * );
449
- */
450
-
451
- }, {
452
- key: 'deleteValue',
453
- value: function deleteValue(assetMetricValueId) {
454
- if (!assetMetricValueId) {
455
- return Promise.reject(new Error('An asset metric value ID is required for deleting an asset metric value.'));
456
- }
457
-
458
- return this._request.delete(this._baseUrl + '/assets/metrics/values/' + assetMetricValueId);
459
- }
460
-
461
- /**
462
- * Gets asset metric values for a particular asset
463
- *
464
- * API Endpoint: '/assets/:assetId/metrics/values'
465
- * Method: GET
466
- *
467
- * @param {String} assetId The ID of the asset (formatted as a UUID)
468
- * @param {Object} [assetMetricValuesFilters] Specific information that is
469
- * used to filter the list of asset metric values
470
- * @param {String} [assetMetricValuesFilters.assetMetricLabel] The label of
471
- * the associated asset metrics
472
- * @param {String} [assetMetricValuesFilters.effectiveEndDate] Effective end
473
- * date (ISO 8601 Extended formatted) of the asset metric values
474
- * @param {String} [assetMetricValuesFilters.effectiveStartDate] Effective
475
- * start date (ISO 8601 Extended formatted) of the asset metric values
476
- * @param {Number} [assetMetricValuesFilters.limit] Maximum number of records
477
- * to return per query
478
- * @param {Number} [assetMetricValuesFilters.offset] How many records from the
479
- * first record to start the query
480
- *
481
- * @returns {Promise}
482
- * @fulfill {AssetMetricValuesFromServer}
483
- * @rejects {Error}
484
- *
485
- * @example
486
- * contxtSdk.assets.metrics
487
- * .getValuesByAssetId(
488
- * 'f9c606f3-d270-4623-bf3b-b085424d9a8b',
489
- * {
490
- * assetMetricLabel: 'Square Footage',
491
- * effectiveEndDate: '2018-04-13T15:44:51.943Z'
492
- * effectiveStartDate: '2017-12-13T15:42:01.376Z'
493
- * limit: 10,
494
- * offset: 200
495
- * }
496
- * )
497
- * .then((assetMetricValuesData) => console.log(assetMetricValuesData))
498
- * .catch((err) => console.log(err));
499
- */
500
-
501
- }, {
502
- key: 'getValuesByAssetId',
503
- value: function getValuesByAssetId(assetId, assetMetricValuesFilters) {
504
- if (!assetId) {
505
- return Promise.reject(new Error('An asset ID is required to get a list of asset metric values.'));
506
- }
507
-
508
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/metrics/values', {
509
- params: toSnakeCase(assetMetricValuesFilters)
510
- }).then(function (assetMetricValueData) {
511
- return formatPaginatedDataFromServer(assetMetricValueData);
512
- });
513
- }
514
-
515
- /**
516
- * Gets asset metric values for a particular asset and metric
517
- *
518
- * API Endpoint: '/assets/:assetId/metrics/:assetMetricId/values'
519
- * Method: GET
520
- *
521
- * @param {String} assetId The ID of the asset (formatted as a UUID)
522
- * @param {String} assetMetricId The ID of the asset metric (formatted as a
523
- * UUID)
524
- * @param {Object} [assetMetricValuesFilters] Specific information that is
525
- * used to filter the list of asset metric values
526
- * @param {String} [assetMetricValuesFilters.effectiveEndDate] Effective end
527
- * date (ISO 8601 Extended formatted) of the asset metric values
528
- * @param {String} [assetMetricValuesFilters.effectiveStartDate] Effective
529
- * start date (ISO 8601 Extended formatted) of the asset metric values
530
- * @param {Number} [assetMetricValuesFilters.limit] Maximum number of records
531
- * to return per query
532
- * @param {Number} [assetMetricValuesFilters.offset] How many records from the
533
- * first record to start the query
534
- *
535
- * @returns {Promise}
536
- * @fulfill {AssetMetricValuesFromServer}
537
- * @rejects {Error}
538
- *
539
- * @example
540
- * contxtSdk.assets.metrics
541
- * .getValuesByMetricId(
542
- * 'd7329ef3-ca63-4ad5-bb3e-632b702584f8',
543
- * 'a1329ef3-ca63-4ad5-bb3e-632b702584f8',
544
- * {
545
- * limit: 10,
546
- * effectiveStartDate: '2018-07-11T19:14:49.715Z'
547
- * }
548
- * )
549
- * .then((assetMetricValuesData) => {
550
- * console.log(assetMetricValuesData);
551
- * })
552
- * .catch((err) => console.log(err));
553
- */
554
-
555
- }, {
556
- key: 'getValuesByMetricId',
557
- value: function getValuesByMetricId(assetId, assetMetricId, assetMetricValuesFilters) {
558
- if (!assetId) {
559
- return Promise.reject(new Error('An asset ID is required to get a list of asset metric values.'));
560
- }
561
-
562
- if (!assetMetricId) {
563
- return Promise.reject(new Error('An asset metric ID is required to get a list of asset metric values.'));
564
- }
565
-
566
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/metrics/' + assetMetricId + '/values', {
567
- params: toSnakeCase(assetMetricValuesFilters)
568
- }).then(function (assetMetricValueData) {
569
- return formatPaginatedDataFromServer(assetMetricValueData);
570
- });
571
- }
572
-
573
- /**
574
- * Gets asset metric values for a particular asset and metric
575
- *
576
- * API Endpoint: '/assets/metrics/values'
577
- * Method: GET
578
- *
579
- * @param {Object} [assetMetricFilters] Specific information that is
580
- * used to filter the list of asset metric values
581
- * @param {String[]} assetMetricFilters.assetIds an array of asset ids
582
- * to request the metrics for
583
- * @param {String[]} assetMetricFilters.labels an array of metric labels
584
- * to request the metrics for
585
- * @param {String} [assetMetricFilters.effectiveEndDate] Effective end
586
- * date (ISO 8601 Extended formatted) of the asset metric values
587
- * @param {String} [assetMetricFilters.effectiveStartDate] Effective
588
- * start date (ISO 8601 Extended formatted) of the asset metric values
589
- * @returns {Promise}
590
- * @fulfill {AssetMetricValuesByAssetIdMetricId}
591
- * @rejects {Error}
592
- *
593
- * @example
594
- * contxtSdk.assets.metrics
595
- * .getValuesByMetricIdsAssetIds(
596
- * {
597
- * effectiveStartDate: '2018-07-11T19:14:49.715Z',
598
- * effectiveEndDate: '2018-07-11T19:14:49.715Z',
599
- * assetIds: ['2140cc2e-6d13-42ee-9941-487fe98f8e2d', '5540cc2e-6d13-42ee-9941-487fe98f8efc'],
600
- * labels: ['facility_kwh', 'facility_cuft'],
601
- * }
602
- * )
603
- * .then((assetMetricValuesByAssetIdMetricId) => {
604
- * console.log(assetMetricValuesByAssetIdMetricId);
605
- * })
606
- * .catch((err) => console.log(err));
607
- */
608
-
609
- }, {
610
- key: 'getValuesByMetricIdsAssetIds',
611
- value: function getValuesByMetricIdsAssetIds(assetMetricFilters) {
612
- var requiredFields = ['assetIds', 'labels'];
613
-
614
- for (var i = 0; i < requiredFields.length; i++) {
615
- var field = requiredFields[i];
616
-
617
- if (!assetMetricFilters[field]) {
618
- return Promise.reject(new Error('The ' + field + ' param is required to fetch data.'));
619
- }
620
- }
621
-
622
- return this._request.get(this._baseUrl + '/assets/metrics/values', {
623
- params: toSnakeCase(assetMetricFilters),
624
- paramsSerializer: stringifyParamsWithCommaSeparatedArrays
625
- }).then(function (assetMetricValues) {
626
- var result = toCamelCase(assetMetricValues, {
627
- excludeTransform: [].concat(_toConsumableArray(assetMetricFilters.labels), _toConsumableArray(assetMetricFilters.assetIds))
628
- });
629
-
630
- return result;
631
- });
632
- }
633
-
634
- /**
635
- * Updates an asset metric value
636
- *
637
- * API Endpoint: '/assets/metrics/values/:assetMetricValueId'
638
- * Method: PUT
639
- *
640
- * @param {string} assetMetricValueId The ID of the asset metric value to update (formatted as a UUID)
641
- * @param {Object} update An object containing the updated data for the asset metric value
642
- * @param {string} [update.effectiveEndDate] ISO 8601 Extended Format date/time string
643
- * @param {string} [update.effectiveStartDate] ISO 8601 Extended Format date/time string
644
- * @param {string} [update.notes]
645
- * @param {string} [update.value]
646
- * @param {boolean} [update.isEstimated] Whether the value is an estimation or a true reading
647
- *
648
- * @returns {Promise}
649
- * @fulfill {undefined}
650
- * @reject {Error}
651
- *
652
- * @example
653
- * contxtSdk.assets.metrics
654
- * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
655
- * effectiveEndDate: '2018-07-10T11:04:24.631Z',
656
- * notes: 'Dolores et sapiente sunt doloribus aut in.',
657
- * value: '61456',
658
- * isEstimated: true
659
- * })
660
- * .catch((err) => console.log(err));
661
- */
662
-
663
- }, {
664
- key: 'updateValue',
665
- value: function updateValue(assetMetricValueId, update) {
666
- if (!assetMetricValueId) {
667
- return Promise.reject(new Error('An asset metric value ID is required to update an asset metric value.'));
668
- }
669
-
670
- if (!update) {
671
- return Promise.reject(new Error('An update is required to update an asset metric value.'));
672
- }
673
-
674
- if (!isPlainObject(update)) {
675
- return Promise.reject(new Error('The asset metric value update must be a well-formed object with the data you wish to update.'));
676
- }
677
-
678
- var formattedUpdate = toSnakeCase(update, {
679
- excludeKeys: ['assetId', 'assetMetricId', 'id']
680
- });
681
-
682
- return this._request.put(this._baseUrl + '/assets/metrics/values/' + assetMetricValueId, formattedUpdate);
683
- }
684
- }]);
685
-
686
- return AssetMetrics;
687
- }();
688
-
689
- export default AssetMetrics;
690
- //# sourceMappingURL=assetMetrics.js.map