@ndustrial/contxt-sdk 4.3.6 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +8 -0
  3. package/docs/Facilities.md +0 -144
  4. package/docs/FacilityGroupings.md +0 -160
  5. package/docs/Nionic.md +63 -0
  6. package/docs/README.md +3 -29
  7. package/docs/Typedefs.md +0 -101
  8. package/esm/config/audiences.js +13 -13
  9. package/esm/config/audiences.js.map +1 -1
  10. package/esm/index.js +3 -6
  11. package/esm/index.js.map +1 -1
  12. package/esm/nionic/index.js +126 -0
  13. package/esm/nionic/index.js.map +1 -0
  14. package/lib/config/audiences.js +13 -13
  15. package/lib/config/audiences.js.map +1 -1
  16. package/lib/index.js +19 -13
  17. package/lib/index.js.map +1 -1
  18. package/lib/nionic/index.js +130 -0
  19. package/lib/nionic/index.js.map +1 -0
  20. package/meta.yaml +11 -0
  21. package/package.json +9 -10
  22. package/src/bus/index.spec.js +3 -2
  23. package/src/bus/webSocketConnection.spec.js +31 -31
  24. package/src/config/audiences.js +13 -13
  25. package/src/config/index.spec.js +6 -6
  26. package/src/coordinator/applications.spec.js +8 -8
  27. package/src/coordinator/consent.spec.js +1 -1
  28. package/src/coordinator/edgeNodes.spec.js +3 -3
  29. package/src/coordinator/organizations.spec.js +4 -4
  30. package/src/coordinator/permissions.spec.js +4 -4
  31. package/src/coordinator/roles.spec.js +3 -3
  32. package/src/coordinator/users.spec.js +14 -15
  33. package/src/events/index.spec.js +16 -16
  34. package/src/files/index.spec.js +7 -7
  35. package/src/index.js +3 -6
  36. package/src/index.spec.js +8 -22
  37. package/src/iot/feeds.spec.js +4 -4
  38. package/src/iot/fieldCategories.spec.js +4 -4
  39. package/src/iot/fieldGroupings.spec.js +5 -5
  40. package/src/iot/outputs.spec.js +6 -6
  41. package/src/nionic/index.js +151 -0
  42. package/src/request.spec.js +3 -3
  43. package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
  44. package/src/sessionTypes/index.spec.js +3 -3
  45. package/src/sessionTypes/machineAuth.spec.js +3 -3
  46. package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
  47. package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
  48. package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
  49. package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
  50. package/src/utils/url/stringifyParams.spec.js +2 -3
  51. package/support/fixtures/factories/IOSDevice.js +3 -3
  52. package/support/fixtures/factories/applicationGrouping.js +4 -4
  53. package/support/fixtures/factories/applicationModule.js +2 -2
  54. package/support/fixtures/factories/asset.js +1 -1
  55. package/support/fixtures/factories/assetAttribute.js +2 -2
  56. package/support/fixtures/factories/assetAttributeValue.js +2 -2
  57. package/support/fixtures/factories/assetMetric.js +1 -1
  58. package/support/fixtures/factories/assetMetricValue.js +3 -3
  59. package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
  60. package/support/fixtures/factories/assetType.js +1 -1
  61. package/support/fixtures/factories/authResults.js +3 -3
  62. package/support/fixtures/factories/channel.js +1 -1
  63. package/support/fixtures/factories/contxtApplication.js +5 -5
  64. package/support/fixtures/factories/contxtOrganization.js +2 -2
  65. package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
  66. package/support/fixtures/factories/contxtProject.js +2 -2
  67. package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
  68. package/support/fixtures/factories/contxtRole.js +3 -3
  69. package/support/fixtures/factories/contxtRoleApplication.js +1 -1
  70. package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
  71. package/support/fixtures/factories/contxtUser.js +2 -2
  72. package/support/fixtures/factories/contxtUserApplication.js +1 -1
  73. package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
  74. package/support/fixtures/factories/contxtUserPermissions.js +5 -5
  75. package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
  76. package/support/fixtures/factories/contxtUserRole.js +2 -2
  77. package/support/fixtures/factories/costCenter.js +2 -2
  78. package/support/fixtures/factories/costCenterFacility.js +3 -3
  79. package/support/fixtures/factories/edgeNode.js +1 -1
  80. package/support/fixtures/factories/event.js +5 -5
  81. package/support/fixtures/factories/eventType.js +4 -4
  82. package/support/fixtures/factories/eventUser.js +5 -5
  83. package/support/fixtures/factories/facility.js +4 -4
  84. package/support/fixtures/factories/facilityGrouping.js +3 -3
  85. package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
  86. package/support/fixtures/factories/facilityInfo.js +2 -2
  87. package/support/fixtures/factories/facilityTag.js +1 -1
  88. package/support/fixtures/factories/feedStatus.js +1 -1
  89. package/support/fixtures/factories/feedType.js +1 -1
  90. package/support/fixtures/factories/feeds.js +5 -5
  91. package/support/fixtures/factories/fieldCategory.js +3 -3
  92. package/support/fixtures/factories/fieldGrouping.js +4 -4
  93. package/support/fixtures/factories/fieldGroupingField.js +3 -3
  94. package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
  95. package/support/fixtures/factories/file.js +1 -1
  96. package/support/fixtures/factories/fileUploadInfo.js +1 -1
  97. package/support/fixtures/factories/organization.js +1 -1
  98. package/support/fixtures/factories/outputField.js +10 -10
  99. package/support/fixtures/factories/outputFieldData.js +1 -1
  100. package/support/fixtures/factories/owner.js +2 -2
  101. package/support/fixtures/factories/paginationMetadata.js +2 -2
  102. package/support/fixtures/factories/triggeredEvent.js +4 -4
  103. package/support/fixtures/factories/userEventSubscription.js +1 -1
  104. package/support/fixtures/factories/userMobileNumber.js +1 -1
  105. package/support/fixtures/factories/userPermissionsMap.js +2 -2
  106. package/.huskyrc.js +0 -11
  107. package/.nycrc +0 -12
  108. package/esm/assets/assetAttributes.js +0 -574
  109. package/esm/assets/assetAttributes.js.map +0 -1
  110. package/esm/assets/assetMetrics.js +0 -690
  111. package/esm/assets/assetMetrics.js.map +0 -1
  112. package/esm/assets/assetTypes.js +0 -273
  113. package/esm/assets/assetTypes.js.map +0 -1
  114. package/esm/assets/index.js +0 -283
  115. package/esm/assets/index.js.map +0 -1
  116. package/esm/facilities/costCenters.js +0 -306
  117. package/esm/facilities/costCenters.js.map +0 -1
  118. package/esm/facilities/groupings.js +0 -323
  119. package/esm/facilities/groupings.js.map +0 -1
  120. package/esm/facilities/index.js +0 -343
  121. package/esm/facilities/index.js.map +0 -1
  122. package/esm/health/index.js +0 -229
  123. package/esm/health/index.js.map +0 -1
  124. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  125. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  126. package/esm/utils/facilities/index.js +0 -4
  127. package/esm/utils/facilities/index.js.map +0 -1
  128. package/lib/assets/assetAttributes.js +0 -588
  129. package/lib/assets/assetAttributes.js.map +0 -1
  130. package/lib/assets/assetMetrics.js +0 -705
  131. package/lib/assets/assetMetrics.js.map +0 -1
  132. package/lib/assets/assetTypes.js +0 -287
  133. package/lib/assets/assetTypes.js.map +0 -1
  134. package/lib/assets/index.js +0 -302
  135. package/lib/assets/index.js.map +0 -1
  136. package/lib/facilities/costCenters.js +0 -316
  137. package/lib/facilities/costCenters.js.map +0 -1
  138. package/lib/facilities/groupings.js +0 -333
  139. package/lib/facilities/groupings.js.map +0 -1
  140. package/lib/facilities/index.js +0 -360
  141. package/lib/facilities/index.js.map +0 -1
  142. package/lib/health/index.js +0 -232
  143. package/lib/health/index.js.map +0 -1
  144. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  145. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  146. package/lib/utils/facilities/index.js +0 -15
  147. package/lib/utils/facilities/index.js.map +0 -1
  148. package/src/assets/assetAttributes.js +0 -619
  149. package/src/assets/assetAttributes.spec.js +0 -1143
  150. package/src/assets/assetMetrics.js +0 -736
  151. package/src/assets/assetMetrics.spec.js +0 -1180
  152. package/src/assets/assetTypes.js +0 -260
  153. package/src/assets/assetTypes.spec.js +0 -556
  154. package/src/assets/index.js +0 -271
  155. package/src/assets/index.spec.js +0 -515
  156. package/src/facilities/costCenters.js +0 -295
  157. package/src/facilities/costCenters.spec.js +0 -529
  158. package/src/facilities/groupings.js +0 -320
  159. package/src/facilities/groupings.spec.js +0 -567
  160. package/src/facilities/index.js +0 -343
  161. package/src/facilities/index.spec.js +0 -551
  162. package/src/health/index.js +0 -200
  163. package/src/health/index.spec.js +0 -501
  164. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  165. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  166. package/src/utils/facilities/index.js +0 -3
@@ -1,360 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- 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; }; }();
8
-
9
- var _lodash = require('lodash.isplainobject');
10
-
11
- var _lodash2 = _interopRequireDefault(_lodash);
12
-
13
- var _groupings = require('./groupings');
14
-
15
- var _groupings2 = _interopRequireDefault(_groupings);
16
-
17
- var _costCenters = require('./costCenters');
18
-
19
- var _costCenters2 = _interopRequireDefault(_costCenters);
20
-
21
- var _facilities = require('../utils/facilities');
22
-
23
- var _objects = require('../utils/objects');
24
-
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
-
27
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
28
-
29
- /**
30
- * @typedef {Object} Facility
31
- * @property {string} [address1]
32
- * @property {string} [address2]
33
- * @property {string} [assetId] UUID corresponding with an asset
34
- * @property {string} [city]
35
- * @property {string} createdAt ISO 8601 Extended Format date/time string
36
- * @property {string} [geometryId] UUID corresponding with a geometry
37
- * @property {number} id
38
- * @property {Object} [Info] User declared information
39
- * @property {string} name
40
- * @property {Object} [Organization]
41
- * @property {string} [Organization.createdAt] ISO 8601 Extended Format date/time string
42
- * @property {string} [Organization.id] UUID formatted ID
43
- * @property {string} [Organization.name]
44
- * @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string
45
- * @property {string} [state]
46
- * @property {Object[]} [tags]
47
- * @property {string} [tags[].createdAt] ISO 8601 Extended Format date/time string
48
- * @property {number} [tags[].id]
49
- * @property {number} [tags[].facilityId]
50
- * @property {string} [tags[].name]
51
- * @property {string} [tags[].updatedAt] ISO 8601 Extended Format date/time string
52
- * @property {string} timezone An IANA Time Zone Database string, i.e. America/Los_Angeles
53
- * @property {number} [weatherLocationId]
54
- * @property {string} [zip] US Zip Code
55
- */
56
-
57
- /**
58
- * Module that provides access to, and the manipulation
59
- * of, information about different facilities
60
- *
61
- * @typicalname contxtSdk.facilities
62
- */
63
- var Facilities = function () {
64
- /**
65
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules
66
- * @param {Object} request An instance of the request module tied to this module's audience.
67
- */
68
- function Facilities(sdk, request) {
69
- _classCallCheck(this, Facilities);
70
-
71
- var baseUrl = sdk.config.audiences.facilities.host + '/v1';
72
-
73
- this._baseUrl = baseUrl;
74
- this._request = request;
75
- this._sdk = sdk;
76
-
77
- this.groupings = new _groupings2.default(sdk, request, baseUrl);
78
- this.costCenters = new _costCenters2.default(sdk, request, baseUrl);
79
- }
80
-
81
- /**
82
- * Creates a new facility
83
- *
84
- * API Endpoint: '/facilities'
85
- * Method: POST
86
- *
87
- * @param {Object} facility
88
- * @param {string} [facility.address1]
89
- * @param {string} [facility.address2]
90
- * @param {string} [facility.assetId] UUID corresponding with an asset
91
- * @param {string} [facility.city]
92
- * @param {string} [facility.geometryId] UUID corresponding with a geometry
93
- * @param {string} facility.name
94
- * @param {string} facility.organizationId UUID corresponding with an organization
95
- * @param {string} [facility.state]
96
- * @param {string} facility.timezone
97
- * @param {number} [facility.weatherLocationId]
98
- * @param {string} [facility.zip]
99
- *
100
- * @returns {Promise}
101
- * @fulfill {Facility} Information about the new facility
102
- * @reject {Error}
103
- *
104
- * @example
105
- * contxtSdk.facilities
106
- * .create({
107
- * address: '221 B Baker St, London, England',
108
- * name: 'Sherlock Holmes Museum',
109
- * organizationId: 25
110
- * })
111
- * .then((facilities) => console.log(facilities))
112
- * .catch((err) => console.log(err));
113
- */
114
-
115
-
116
- _createClass(Facilities, [{
117
- key: 'create',
118
- value: function create() {
119
- var facility = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
120
-
121
- var requiredFields = ['organizationId', 'name', 'timezone'];
122
-
123
- for (var i = 0; i < requiredFields.length; i++) {
124
- var field = requiredFields[i];
125
-
126
- if (!facility[field]) {
127
- return Promise.reject(new Error('A ' + field + ' is required to create a new facility.'));
128
- }
129
- }
130
-
131
- return this._request.post(this._baseUrl + '/facilities', (0, _objects.toSnakeCase)(facility)).then(function (facility) {
132
- return (0, _objects.toCamelCase)(facility);
133
- });
134
- }
135
-
136
- /**
137
- * Creates or updates a facility's info (NOTE: This refers to the facility_info model)
138
- *
139
- * API Endpoint: '/facilities/:facilityId/info?should_update=true'
140
- * Method: POST
141
- *
142
- * @param {number} facilityId The ID of the facility to update
143
- * @param {Object} update An object containing the facility info for the facility
144
- *
145
- * @returns {Promise}
146
- * @fulfill {undefined}
147
- * @reject {Error}
148
- *
149
- * @example
150
- * contxtSdk.facilities.createOrUpdateInfo(25, {
151
- * square_feet: '10000'
152
- * });
153
- */
154
-
155
- }, {
156
- key: 'createOrUpdateInfo',
157
- value: function createOrUpdateInfo(facilityId, update) {
158
- if (!facilityId) {
159
- return Promise.reject(new Error("A facility ID is required to update a facility's info."));
160
- }
161
-
162
- if (!update) {
163
- return Promise.reject(new Error("An update is required to update a facility's info."));
164
- }
165
-
166
- if (!(0, _lodash2.default)(update)) {
167
- return Promise.reject(new Error('The facility info update must be a well-formed object with the data you wish to update.'));
168
- }
169
-
170
- var options = {
171
- params: {
172
- should_update: true
173
- }
174
- };
175
-
176
- return this._request.post(this._baseUrl + '/facilities/' + facilityId + '/info', update, options);
177
- }
178
-
179
- /**
180
- * Deletes a facility
181
- *
182
- * API Endpoint: '/facilities/:facilityId'
183
- * Method: DELETE
184
- *
185
- * @param {number} facilityId The ID of the facility
186
- *
187
- * @returns {Promise}
188
- * @fulfill {undefined}
189
- * @reject {Error}
190
- *
191
- * @example
192
- * contxtSdk.facilities.delete(25);
193
- */
194
-
195
- }, {
196
- key: 'delete',
197
- value: function _delete(facilityId) {
198
- if (!facilityId) {
199
- return Promise.reject(new Error('A facility ID is required for deleting a facility'));
200
- }
201
-
202
- return this._request.delete(this._baseUrl + '/facilities/' + facilityId);
203
- }
204
-
205
- /**
206
- * Gets information about a facility
207
- *
208
- * API Endpoint: '/facilities/:facilityId'
209
- * Method: GET
210
- *
211
- * @param {number} facilityId The ID of the facility
212
- *
213
- * @returns {Promise}
214
- * @fulfill {Facility} Information about a facility
215
- * @reject {Error}
216
- *
217
- * @example
218
- * contxtSdk.facilities
219
- * .get(25)
220
- * .then((facility) => console.log(facility))
221
- * .catch((err) => console.log(err));
222
- */
223
-
224
- }, {
225
- key: 'get',
226
- value: function get(facilityId) {
227
- if (!facilityId) {
228
- return Promise.reject(new Error('A facility ID is required for getting information about a facility'));
229
- }
230
-
231
- return this._request.get(this._baseUrl + '/facilities/' + facilityId).then(function (facility) {
232
- return (0, _facilities.formatFacilityWithInfoFromServer)(facility);
233
- });
234
- }
235
-
236
- /**
237
- * Gets a list of all facilities
238
- *
239
- * API Endpoint: '/facilities'
240
- * Method: GET
241
- *
242
- * @returns {Promise}
243
- * @fulfill {Facility[]} Information about all facilities
244
- * @reject {Error}
245
- *
246
- * @example
247
- * contxtSdk.facilities
248
- * .getAll()
249
- * .then((facilities) => console.log(facilities))
250
- * .catch((err) => console.log(err));
251
- */
252
-
253
- }, {
254
- key: 'getAll',
255
- value: function getAll() {
256
- return this._request.get(this._baseUrl + '/facilities').then(function (facilities) {
257
- return facilities.map(function (facility) {
258
- return (0, _facilities.formatFacilityWithInfoFromServer)(facility);
259
- });
260
- });
261
- }
262
-
263
- /**
264
- * Gets a list of all facilities that belong to a particular organization
265
- *
266
- * API Endpoint: '/organizations/:organizationId/facilities'
267
- * Method: GET
268
- *
269
- * @param {string} organizationId UUID corresponding with an organization
270
- * @param {object} [options] Object containing parameters to be called with the request
271
- * @param {boolean} [options.includeGroupings] Boolean flag for including groupings data with each facility
272
- *
273
- * @returns {Promise}
274
- * @fulfill {Facility[]} Information about all facilities
275
- * @reject {Error}
276
- *
277
- * @example
278
- * contxtSdk.facilities
279
- * .getAllByOrganizationId(25, { includeGroupings: true })
280
- * .then((facilities) => console.log(facilities))
281
- * .catch((err) => console.log(err));
282
- */
283
-
284
- }, {
285
- key: 'getAllByOrganizationId',
286
- value: function getAllByOrganizationId(organizationId, options) {
287
- if (!organizationId) {
288
- return Promise.reject(new Error("An organization ID is required for getting a list of an organization's facilities"));
289
- }
290
-
291
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/facilities', {
292
- params: (0, _objects.toSnakeCase)(options)
293
- }).then(function (facilities) {
294
- return facilities.map(function (facility) {
295
- return (0, _facilities.formatFacilityWithInfoFromServer)(facility);
296
- });
297
- });
298
- }
299
-
300
- /**
301
- * Updates a facility's specifics
302
- *
303
- * API Endpoint: '/facilities/:facilityId'
304
- * Method: PUT
305
- *
306
- * @param {number} facilityId The ID of the facility to update
307
- * @param {Object} update An object containing the updated data for the facility
308
- * @param {string} [update.address1]
309
- * @param {string} [update.address2]
310
- * @param {string} [update.assetId] UUID corresponding with an asset
311
- * @param {string} [update.city]
312
- * @param {string} [update.geometryId] UUID corresponding with a geometry
313
- * @param {Object} [update.info] User declared information
314
- * @param {string} [update.name]
315
- * @param {string} [update.organizationId] UUID corresponding with an organization
316
- * @param {string} [update.state]
317
- * @param {string} [update.timezone]
318
- * @param {number} [update.weatherLocationId]
319
- * @param {string} [update.zip]
320
- *
321
- * @returns {Promise}
322
- * @fulfill {undefined}
323
- * @reject {Error}
324
- *
325
- * @example
326
- * contxtSdk.facilities.update(25, {
327
- * address: '221 B Baker St, London, England',
328
- * name: 'Sherlock Homes Museum',
329
- * organizationId: 25
330
- * });
331
- */
332
-
333
- }, {
334
- key: 'update',
335
- value: function update(facilityId, _update) {
336
- if (!facilityId) {
337
- return Promise.reject(new Error('A facility ID is required to update a facility.'));
338
- }
339
-
340
- if (!_update) {
341
- return Promise.reject(new Error('An update is required to update a facility.'));
342
- }
343
-
344
- if (!(0, _lodash2.default)(_update)) {
345
- return Promise.reject(new Error('The facility update must be a well-formed object with the data you wish to update.'));
346
- }
347
-
348
- var formattedUpdate = (0, _objects.toSnakeCase)(_update, {
349
- excludeKeys: ['id', 'organizationId']
350
- });
351
-
352
- return this._request.put(this._baseUrl + '/facilities/' + facilityId, formattedUpdate);
353
- }
354
- }]);
355
-
356
- return Facilities;
357
- }();
358
-
359
- exports.default = Facilities;
360
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["facilities/index.js"],"names":["Facilities","sdk","request","baseUrl","config","audiences","facilities","host","_baseUrl","_request","_sdk","groupings","FacilityGroupings","costCenters","CostCenters","facility","requiredFields","i","length","field","Promise","reject","Error","post","then","facilityId","update","options","params","should_update","delete","get","map","organizationId","formattedUpdate","excludeKeys","put"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;AACA;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;;;;;IAMMA,U;AACJ;;;;AAIA,sBAAYC,GAAZ,EAAiBC,OAAjB,EAA0B;AAAA;;AACxB,QAAMC,UAAaF,IAAIG,MAAJ,CAAWC,SAAX,CAAqBC,UAArB,CAAgCC,IAA7C,QAAN;;AAEA,SAAKC,QAAL,GAAgBL,OAAhB;AACA,SAAKM,QAAL,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BAAYD,OAAZ;AAD0D,OAD/D,EAIJH,IAJI,CAIC,UAAClB,UAAD;AAAA,eACJA,WAAW0B,GAAX,CAAe,UAACjB,QAAD;AAAA,iBAAc,kDAAiCA,QAAjC,CAAd;AAAA,SAAf,CADI;AAAA,OAJD,CAAP;AAOD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAgCOU,U,EAAYC,O,EAAQ;AACzB,UAAI,CAACD,UAAL,EAAiB;AACf,eAAOL,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,iDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACI,OAAL,EAAa;AACX,eAAON,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,6CAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAAC,sBAAcI,OAAd,CAAL,EAA4B;AAC1B,eAAON,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,oFADF,CADK,CAAP;AAKD;;AAED,UAAMY,kBAAkB,0BAAYR,OAAZ,EAAoB;AAC1CS,qBAAa,CAAC,IAAD,EAAO,gBAAP;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAK1B,QAAL,CAAc2B,GAAd,CACF,KAAK5B,QADH,oBAC0BiB,UAD1B,EAELS,eAFK,CAAP;AAID;;;;;;kBAGYlC,U","file":"index.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport FacilityGroupings from './groupings';\nimport CostCenters from './costCenters';\nimport { formatFacilityWithInfoFromServer } from '../utils/facilities';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} Facility\n * @property {string} [address1]\n * @property {string} [address2]\n * @property {string} [assetId] UUID corresponding with an asset\n * @property {string} [city]\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} [geometryId] UUID corresponding with a geometry\n * @property {number} id\n * @property {Object} [Info] User declared information\n * @property {string} name\n * @property {Object} [Organization]\n * @property {string} [Organization.createdAt] ISO 8601 Extended Format date/time string\n * @property {string} [Organization.id] UUID formatted ID\n * @property {string} [Organization.name]\n * @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string\n * @property {string} [state]\n * @property {Object[]} [tags]\n * @property {string} [tags[].createdAt] ISO 8601 Extended Format date/time string\n * @property {number} [tags[].id]\n * @property {number} [tags[].facilityId]\n * @property {string} [tags[].name]\n * @property {string} [tags[].updatedAt] ISO 8601 Extended Format date/time string\n * @property {string} timezone An IANA Time Zone Database string, i.e. America/Los_Angeles\n * @property {number} [weatherLocationId]\n * @property {string} [zip] US Zip Code\n */\n\n/**\n * Module that provides access to, and the manipulation\n * of, information about different facilities\n *\n * @typicalname contxtSdk.facilities\n */\nclass Facilities {\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 */\n constructor(sdk, request) {\n const baseUrl = `${sdk.config.audiences.facilities.host}/v1`;\n\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n\n this.groupings = new FacilityGroupings(sdk, request, baseUrl);\n this.costCenters = new CostCenters(sdk, request, baseUrl);\n }\n\n /**\n * Creates a new facility\n *\n * API Endpoint: '/facilities'\n * Method: POST\n *\n * @param {Object} facility\n * @param {string} [facility.address1]\n * @param {string} [facility.address2]\n * @param {string} [facility.assetId] UUID corresponding with an asset\n * @param {string} [facility.city]\n * @param {string} [facility.geometryId] UUID corresponding with a geometry\n * @param {string} facility.name\n * @param {string} facility.organizationId UUID corresponding with an organization\n * @param {string} [facility.state]\n * @param {string} facility.timezone\n * @param {number} [facility.weatherLocationId]\n * @param {string} [facility.zip]\n *\n * @returns {Promise}\n * @fulfill {Facility} Information about the new facility\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .create({\n * address: '221 B Baker St, London, England',\n * name: 'Sherlock Holmes Museum',\n * organizationId: 25\n * })\n * .then((facilities) => console.log(facilities))\n * .catch((err) => console.log(err));\n */\n create(facility = {}) {\n const requiredFields = ['organizationId', 'name', 'timezone'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!facility[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new facility.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/facilities`, toSnakeCase(facility))\n .then((facility) => toCamelCase(facility));\n }\n\n /**\n * Creates or updates a facility's info (NOTE: This refers to the facility_info model)\n *\n * API Endpoint: '/facilities/:facilityId/info?should_update=true'\n * Method: POST\n *\n * @param {number} facilityId The ID of the facility to update\n * @param {Object} update An object containing the facility info for the facility\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.createOrUpdateInfo(25, {\n * square_feet: '10000'\n * });\n */\n createOrUpdateInfo(facilityId, update) {\n if (!facilityId) {\n return Promise.reject(\n new Error(\"A facility ID is required to update a facility's info.\")\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error(\"An update is required to update a facility's info.\")\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The facility info update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n const options = {\n params: {\n should_update: true\n }\n };\n\n return this._request.post(\n `${this._baseUrl}/facilities/${facilityId}/info`,\n update,\n options\n );\n }\n\n /**\n * Deletes a facility\n *\n * API Endpoint: '/facilities/:facilityId'\n * Method: DELETE\n *\n * @param {number} facilityId The ID of the facility\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.delete(25);\n */\n delete(facilityId) {\n if (!facilityId) {\n return Promise.reject(\n new Error('A facility ID is required for deleting a facility')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/facilities/${facilityId}`);\n }\n\n /**\n * Gets information about a facility\n *\n * API Endpoint: '/facilities/:facilityId'\n * Method: GET\n *\n * @param {number} facilityId The ID of the facility\n *\n * @returns {Promise}\n * @fulfill {Facility} Information about a facility\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .get(25)\n * .then((facility) => console.log(facility))\n * .catch((err) => console.log(err));\n */\n get(facilityId) {\n if (!facilityId) {\n return Promise.reject(\n new Error(\n 'A facility ID is required for getting information about a facility'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/facilities/${facilityId}`)\n .then((facility) => formatFacilityWithInfoFromServer(facility));\n }\n\n /**\n * Gets a list of all facilities\n *\n * API Endpoint: '/facilities'\n * Method: GET\n *\n * @returns {Promise}\n * @fulfill {Facility[]} Information about all facilities\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .getAll()\n * .then((facilities) => console.log(facilities))\n * .catch((err) => console.log(err));\n */\n getAll() {\n return this._request\n .get(`${this._baseUrl}/facilities`)\n .then((facilities) =>\n facilities.map((facility) => formatFacilityWithInfoFromServer(facility))\n );\n }\n\n /**\n * Gets a list of all facilities that belong to a particular organization\n *\n * API Endpoint: '/organizations/:organizationId/facilities'\n * Method: GET\n *\n * @param {string} organizationId UUID corresponding with an organization\n * @param {object} [options] Object containing parameters to be called with the request\n * @param {boolean} [options.includeGroupings] Boolean flag for including groupings data with each facility\n *\n * @returns {Promise}\n * @fulfill {Facility[]} Information about all facilities\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .getAllByOrganizationId(25, { includeGroupings: true })\n * .then((facilities) => console.log(facilities))\n * .catch((err) => console.log(err));\n */\n getAllByOrganizationId(organizationId, options) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n \"An organization ID is required for getting a list of an organization's facilities\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/facilities`, {\n params: toSnakeCase(options)\n })\n .then((facilities) =>\n facilities.map((facility) => formatFacilityWithInfoFromServer(facility))\n );\n }\n\n /**\n * Updates a facility's specifics\n *\n * API Endpoint: '/facilities/:facilityId'\n * Method: PUT\n *\n * @param {number} facilityId The ID of the facility to update\n * @param {Object} update An object containing the updated data for the facility\n * @param {string} [update.address1]\n * @param {string} [update.address2]\n * @param {string} [update.assetId] UUID corresponding with an asset\n * @param {string} [update.city]\n * @param {string} [update.geometryId] UUID corresponding with a geometry\n * @param {Object} [update.info] User declared information\n * @param {string} [update.name]\n * @param {string} [update.organizationId] UUID corresponding with an organization\n * @param {string} [update.state]\n * @param {string} [update.timezone]\n * @param {number} [update.weatherLocationId]\n * @param {string} [update.zip]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.update(25, {\n * address: '221 B Baker St, London, England',\n * name: 'Sherlock Homes Museum',\n * organizationId: 25\n * });\n */\n update(facilityId, update) {\n if (!facilityId) {\n return Promise.reject(\n new Error('A facility ID is required to update a facility.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a facility.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The facility 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: ['id', 'organizationId']\n });\n\n return this._request.put(\n `${this._baseUrl}/facilities/${facilityId}`,\n formattedUpdate\n );\n }\n}\n\nexport default Facilities;\n"]}
@@ -1,232 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- 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; }; }();
8
-
9
- var _pagination = require('../utils/pagination');
10
-
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
-
13
- /**
14
- * @typedef {Object} HealthStatus
15
- * @property {string} status A health status of value 'healthy' or 'unhealthy'
16
- * @property {string} timestamp ISO 8601 Extended Format date/time string
17
- */
18
-
19
- /**
20
- * @typedef {Object} HealthAsset
21
- * @augments Asset
22
- * @property {HealthStatus} health
23
- */
24
-
25
- /**
26
- * @interface PaginatedResponse
27
- * @template RecordType
28
- * @typedef {Object} PaginatedResponse
29
- * @property {Object} _metadata Metadata about the pagination settings
30
- * @property {number} _metadata.offset Offset of records in subsequent queries
31
- * @property {number} _metadata.totalRecords Total number of asset types found
32
- * @property {Array.<RecordType>} records
33
- */
34
-
35
- /**
36
- * @typedef {PaginatedResponse.<HealthAsset>} HealthAssetPaginatedResponse
37
- */
38
-
39
- /**
40
- * @typedef {PaginatedResponse.<HealthStatus>} HealthStatusPaginatedResponse
41
- */
42
-
43
- /**
44
- * Module that provides access to the Contxt Health Service
45
- *
46
- * @typicalname contxtSdk.health
47
- */
48
- var Health = function () {
49
- /**
50
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules
51
- * @param {Object} request An instance of the request module tied to this module's audience.
52
- * @param {string} [organizationId] The organization ID to be used in tenant url requests
53
- */
54
- function Health(sdk, request) {
55
- var organizationId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
56
-
57
- _classCallCheck(this, Health);
58
-
59
- var baseUrl = sdk.config.audiences.health.host + '/v1';
60
-
61
- this._baseUrl = baseUrl;
62
- this._request = request;
63
- this._sdk = sdk;
64
-
65
- this._organizationId = organizationId;
66
- }
67
-
68
- /**
69
- * The health status option constants
70
- * @enum {string}
71
- * @static
72
- * @example
73
- * console.log(Health.GOOD) //healthy
74
- * console.log(Health.BAD) //unhealthy
75
- */
76
-
77
-
78
- _createClass(Health, [{
79
- key: 'getAll',
80
-
81
-
82
- /**
83
- * Gets all of an organization's assets and their most recent health status
84
- *
85
- * API Endpoint: '/:organizationId/assets'
86
- * Method: GET
87
- *
88
- * @param {Object} options
89
- * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
90
- * @param {PaginationOptions} [paginationOptions]
91
- * @returns {Promise}
92
- * @fulfill {HealthAssetPaginatedResponse} Information about all contxt applications
93
- * @reject {Error}
94
- *
95
- * @example
96
- * contxtSdk.health
97
- * .getAll({
98
- * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'
99
- * }, {
100
- * limit: 50,
101
- * offset: 100
102
- * })
103
- * .then((healthAssetRecords) => console.log(healthAssetRecords))
104
- * .catch((err) => console.log(err));
105
- */
106
- value: function getAll(_ref, paginationOptions) {
107
- var _ref$organizationId = _ref.organizationId,
108
- organizationId = _ref$organizationId === undefined ? this._organizationId : _ref$organizationId;
109
-
110
- if (!organizationId) {
111
- return Promise.reject(new Error('An organization ID is required'));
112
- }
113
-
114
- return this._request.get(this._baseUrl + '/' + organizationId + '/assets', {
115
- params: paginationOptions
116
- }).then(function (response) {
117
- return (0, _pagination.formatPaginatedDataFromServer)(response);
118
- });
119
- }
120
-
121
- /**
122
- * Gets a list of health statuses for a single asset
123
- *
124
- * API Endpoint: '/:organizationId/assets/:assetId'
125
- * Method: GET
126
- *
127
- * @param {Object} options
128
- * @param {string} options.assetId The asset id to get the health for
129
- * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
130
- * @param {PaginationOptions} [paginationOptions]
131
- * @returns {Promise}
132
- * @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications
133
- * @reject {Error}
134
- *
135
- * @example
136
- * contxtSdk.health
137
- * .getByAssetId({
138
- * assetId: '9859f22d-cc45-4015-8674-1671f54d1888',
139
- * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'
140
- * }, {
141
- * limit: 50,
142
- * offset: 100
143
- * })
144
- * .then((healthStatusRecords) => console.log(healthStatusRecords))
145
- * .catch((err) => console.log(err));
146
- */
147
-
148
- }, {
149
- key: 'getByAssetId',
150
- value: function getByAssetId(_ref2, paginationOptions) {
151
- var assetId = _ref2.assetId,
152
- _ref2$organizationId = _ref2.organizationId,
153
- organizationId = _ref2$organizationId === undefined ? this._organizationId : _ref2$organizationId;
154
-
155
- if (!assetId) {
156
- return Promise.reject(new Error('An asset ID is required'));
157
- }
158
-
159
- if (!organizationId) {
160
- return Promise.reject(new Error('An organization ID is required'));
161
- }
162
-
163
- return this._request.get(this._baseUrl + '/' + organizationId + '/assets/' + assetId, {
164
- params: paginationOptions
165
- }).then(function (response) {
166
- return (0, _pagination.formatPaginatedDataFromServer)(response);
167
- });
168
- }
169
-
170
- /**
171
- * Creates a new health status entry for an asset
172
- *
173
- * API Endpoint: '/:organizationId/assets/:assetId'
174
- * Method: POST
175
- *
176
- * @param {Object} options
177
- * @param {string} options.assetId The asset id to get the health for
178
- * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
179
- * @param {string} options.status The health of the asset. One of type Health.status.GOOD or Health.status.BAD
180
- * @param {string} [options.timestamp] Defaults to now. ISO 8601 Extended Format date/time string
181
- * @returns {Promise}
182
- * @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications
183
- * @reject {Error}
184
- *
185
- * @example
186
- * contxtSdk.health
187
- * .post({
188
- * assetId: '9859f22d-cc45-4015-8674-1671f54d1888',
189
- * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83',
190
- * status: contxtSdk.health.status.GOOD
191
- * })
192
- * .then((healthStatus) => console.log(healthStatus))
193
- * .catch((err) => console.log(err));
194
- */
195
-
196
- }, {
197
- key: 'post',
198
- value: function post(_ref3) {
199
- var assetId = _ref3.assetId,
200
- _ref3$organizationId = _ref3.organizationId,
201
- organizationId = _ref3$organizationId === undefined ? this._organizationId : _ref3$organizationId,
202
- status = _ref3.status,
203
- timestamp = _ref3.timestamp;
204
-
205
- if (!assetId) {
206
- return Promise.reject(new Error('An asset ID is required'));
207
- }
208
-
209
- if (!organizationId) {
210
- return Promise.reject(new Error('An organization ID is required'));
211
- }
212
-
213
- if (!Object.values(Health.status).includes(status)) {
214
- return Promise.reject(new Error('Status must equal one of: ' + Object.values(Health.status).join(', ')));
215
- }
216
-
217
- return this._request.post(this._baseUrl + '/' + organizationId + '/assets/' + assetId, {
218
- status: status,
219
- timestamp: timestamp
220
- });
221
- }
222
- }]);
223
-
224
- return Health;
225
- }();
226
-
227
- Health.status = {
228
- GOOD: 'healthy',
229
- BAD: 'unhealthy'
230
- };
231
- exports.default = Health;
232
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["health/index.js"],"names":["Health","sdk","request","organizationId","baseUrl","config","audiences","health","host","_baseUrl","_request","_sdk","_organizationId","paginationOptions","Promise","reject","Error","get","params","then","response","assetId","status","timestamp","Object","values","includes","join","post","GOOD","BAD"],"mappings":";;;;;;;;AAAA;;;;AAEA;;;;;;AAMA;;;;;;AAMA;;;;;;;;;;AAUA;;;;AAIA;;;;AAIA;;;;;IAKMA,M;AACJ;;;;;AAKA,kBAAYC,GAAZ,EAAiBC,OAAjB,EAAiD;AAAA,QAAvBC,cAAuB,uEAAN,IAAM;;AAAA;;AAC/C,QAAMC,UAAaH,IAAII,MAAJ,CAAWC,SAAX,CAAqBC,MAArB,CAA4BC,IAAzC,QAAN;;AAEA,SAAKC,QAAL,GAAgBL,OAAhB;AACA,SAAKM,QAAL,GAAgBR,OAAhB;AACA,SAAKS,IAAL,GAAYV,GAAZ;;AAEA,SAAKW,eAAL,GAAuBT,cAAvB;AACD;;AAED;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;iCAwBkDU,iB,EAAmB;AAAA,qCAA5DV,cAA4D;AAAA,UAA5DA,cAA4D,uCAA3C,KAAKS,eAAsC;;AACnE,UAAI,CAACT,cAAL,EAAqB;AACnB,eAAOW,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAU,gCAAV,CAAf,CAAP;AACD;;AAED,aAAO,KAAKN,QAAL,CACJO,GADI,CACG,KAAKR,QADR,SACoBN,cADpB,cAC6C;AAChDe,gBAAQL;AADwC,OAD7C,EAIJM,IAJI,CAIC,UAACC,QAAD;AAAA,eAAc,+CAA8BA,QAA9B,CAAd;AAAA,OAJD,CAAP;AAK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,IAAlC,CAD/B,CADK,CAAP;AAKD;;AAED,aAAO,KAAKjB,QAAL,CAAckB,IAAd,CACF,KAAKnB,QADH,SACeN,cADf,gBACwCkB,OADxC,EAEL;AACEC,sBADF;AAEEC;AAFF,OAFK,CAAP;AAOD;;;;;;AA/JGvB,M,CAwBGsB,M,GAAS;AACdO,QAAM,SADQ;AAEdC,OAAK;AAFS,C;kBA0IH9B,M","file":"index.js","sourcesContent":["import { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} HealthStatus\n * @property {string} status A health status of value 'healthy' or 'unhealthy'\n * @property {string} timestamp ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} HealthAsset\n * @augments Asset\n * @property {HealthStatus} health\n */\n\n/**\n * @interface PaginatedResponse\n * @template RecordType\n * @typedef {Object} PaginatedResponse\n * @property {Object} _metadata Metadata about the pagination settings\n * @property {number} _metadata.offset Offset of records in subsequent queries\n * @property {number} _metadata.totalRecords Total number of asset types found\n * @property {Array.<RecordType>} records\n */\n\n/**\n * @typedef {PaginatedResponse.<HealthAsset>} HealthAssetPaginatedResponse\n */\n\n/**\n * @typedef {PaginatedResponse.<HealthStatus>} HealthStatusPaginatedResponse\n */\n\n/**\n * Module that provides access to the Contxt Health Service\n *\n * @typicalname contxtSdk.health\n */\nclass Health {\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} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(sdk, request, organizationId = null) {\n const baseUrl = `${sdk.config.audiences.health.host}/v1`;\n\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n\n this._organizationId = organizationId;\n }\n\n /**\n * The health status option constants\n * @enum {string}\n * @static\n * @example\n * console.log(Health.GOOD) //healthy\n * console.log(Health.BAD) //unhealthy\n */\n static status = {\n GOOD: 'healthy',\n BAD: 'unhealthy'\n };\n\n /**\n * Gets all of an organization's assets and their most recent health status\n *\n * API Endpoint: '/:organizationId/assets'\n * Method: GET\n *\n * @param {Object} options\n * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.\n * @param {PaginationOptions} [paginationOptions]\n * @returns {Promise}\n * @fulfill {HealthAssetPaginatedResponse} Information about all contxt applications\n * @reject {Error}\n *\n * @example\n * contxtSdk.health\n * .getAll({\n * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'\n * }, {\n * limit: 50,\n * offset: 100\n * })\n * .then((healthAssetRecords) => console.log(healthAssetRecords))\n * .catch((err) => console.log(err));\n */\n getAll({ organizationId = this._organizationId }, paginationOptions) {\n if (!organizationId) {\n return Promise.reject(new Error('An organization ID is required'));\n }\n\n return this._request\n .get(`${this._baseUrl}/${organizationId}/assets`, {\n params: paginationOptions\n })\n .then((response) => formatPaginatedDataFromServer(response));\n }\n\n /**\n * Gets a list of health statuses for a single asset\n *\n * API Endpoint: '/:organizationId/assets/:assetId'\n * Method: GET\n *\n * @param {Object} options\n * @param {string} options.assetId The asset id to get the health for\n * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.\n * @param {PaginationOptions} [paginationOptions]\n * @returns {Promise}\n * @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications\n * @reject {Error}\n *\n * @example\n * contxtSdk.health\n * .getByAssetId({\n * assetId: '9859f22d-cc45-4015-8674-1671f54d1888',\n * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'\n * }, {\n * limit: 50,\n * offset: 100\n * })\n * .then((healthStatusRecords) => console.log(healthStatusRecords))\n * .catch((err) => console.log(err));\n */\n getByAssetId(\n { assetId, organizationId = this._organizationId },\n paginationOptions\n ) {\n if (!assetId) {\n return Promise.reject(new Error('An asset ID is required'));\n }\n\n if (!organizationId) {\n return Promise.reject(new Error('An organization ID is required'));\n }\n\n return this._request\n .get(`${this._baseUrl}/${organizationId}/assets/${assetId}`, {\n params: paginationOptions\n })\n .then((response) => formatPaginatedDataFromServer(response));\n }\n\n /**\n * Creates a new health status entry for an asset\n *\n * API Endpoint: '/:organizationId/assets/:assetId'\n * Method: POST\n *\n * @param {Object} options\n * @param {string} options.assetId The asset id to get the health for\n * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.\n * @param {string} options.status The health of the asset. One of type Health.status.GOOD or Health.status.BAD\n * @param {string} [options.timestamp] Defaults to now. ISO 8601 Extended Format date/time string\n * @returns {Promise}\n * @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications\n * @reject {Error}\n *\n * @example\n * contxtSdk.health\n * .post({\n * assetId: '9859f22d-cc45-4015-8674-1671f54d1888',\n * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83',\n * status: contxtSdk.health.status.GOOD\n * })\n * .then((healthStatus) => console.log(healthStatus))\n * .catch((err) => console.log(err));\n */\n post({ assetId, organizationId = this._organizationId, status, timestamp }) {\n if (!assetId) {\n return Promise.reject(new Error('An asset ID is required'));\n }\n\n if (!organizationId) {\n return Promise.reject(new Error('An organization ID is required'));\n }\n\n if (!Object.values(Health.status).includes(status)) {\n return Promise.reject(\n new Error(\n `Status must equal one of: ${Object.values(Health.status).join(', ')}`\n )\n );\n }\n\n return this._request.post(\n `${this._baseUrl}/${organizationId}/assets/${assetId}`,\n {\n status,\n timestamp\n }\n );\n }\n}\n\nexport default Health;\n"]}