@ndustrial/contxt-sdk 4.3.6 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +8 -0
  3. package/CODEOWNERS +1 -0
  4. package/docs/Facilities.md +0 -144
  5. package/docs/FacilityGroupings.md +0 -160
  6. package/docs/Nionic.md +63 -0
  7. package/docs/README.md +3 -29
  8. package/docs/Typedefs.md +0 -101
  9. package/esm/config/audiences.js +13 -13
  10. package/esm/config/audiences.js.map +1 -1
  11. package/esm/index.js +4 -6
  12. package/esm/index.js.map +1 -1
  13. package/esm/nionic/index.js +126 -0
  14. package/esm/nionic/index.js.map +1 -0
  15. package/lib/config/audiences.js +13 -13
  16. package/lib/config/audiences.js.map +1 -1
  17. package/lib/index.js +10 -15
  18. package/lib/index.js.map +1 -1
  19. package/lib/nionic/index.js +130 -0
  20. package/lib/nionic/index.js.map +1 -0
  21. package/meta.yaml +11 -0
  22. package/package.json +9 -10
  23. package/src/bus/index.spec.js +3 -2
  24. package/src/bus/webSocketConnection.spec.js +31 -31
  25. package/src/config/audiences.js +13 -13
  26. package/src/config/index.spec.js +6 -6
  27. package/src/coordinator/applications.spec.js +8 -8
  28. package/src/coordinator/consent.spec.js +1 -1
  29. package/src/coordinator/edgeNodes.spec.js +3 -3
  30. package/src/coordinator/organizations.spec.js +4 -4
  31. package/src/coordinator/permissions.spec.js +4 -4
  32. package/src/coordinator/roles.spec.js +3 -3
  33. package/src/coordinator/users.spec.js +14 -15
  34. package/src/events/index.spec.js +16 -16
  35. package/src/files/index.spec.js +7 -7
  36. package/src/index.js +4 -6
  37. package/src/index.spec.js +8 -22
  38. package/src/iot/feeds.spec.js +4 -4
  39. package/src/iot/fieldCategories.spec.js +4 -4
  40. package/src/iot/fieldGroupings.spec.js +5 -5
  41. package/src/iot/outputs.spec.js +6 -6
  42. package/src/nionic/index.js +151 -0
  43. package/src/request.spec.js +3 -3
  44. package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
  45. package/src/sessionTypes/index.spec.js +3 -3
  46. package/src/sessionTypes/machineAuth.spec.js +3 -3
  47. package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
  48. package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
  49. package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
  50. package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
  51. package/src/utils/url/stringifyParams.spec.js +2 -3
  52. package/support/fixtures/factories/IOSDevice.js +3 -3
  53. package/support/fixtures/factories/applicationGrouping.js +4 -4
  54. package/support/fixtures/factories/applicationModule.js +2 -2
  55. package/support/fixtures/factories/asset.js +1 -1
  56. package/support/fixtures/factories/assetAttribute.js +2 -2
  57. package/support/fixtures/factories/assetAttributeValue.js +2 -2
  58. package/support/fixtures/factories/assetMetric.js +1 -1
  59. package/support/fixtures/factories/assetMetricValue.js +3 -3
  60. package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
  61. package/support/fixtures/factories/assetType.js +1 -1
  62. package/support/fixtures/factories/authResults.js +3 -3
  63. package/support/fixtures/factories/channel.js +1 -1
  64. package/support/fixtures/factories/contxtApplication.js +5 -5
  65. package/support/fixtures/factories/contxtOrganization.js +2 -2
  66. package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
  67. package/support/fixtures/factories/contxtProject.js +2 -2
  68. package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
  69. package/support/fixtures/factories/contxtRole.js +3 -3
  70. package/support/fixtures/factories/contxtRoleApplication.js +1 -1
  71. package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
  72. package/support/fixtures/factories/contxtUser.js +2 -2
  73. package/support/fixtures/factories/contxtUserApplication.js +1 -1
  74. package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
  75. package/support/fixtures/factories/contxtUserPermissions.js +5 -5
  76. package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
  77. package/support/fixtures/factories/contxtUserRole.js +2 -2
  78. package/support/fixtures/factories/costCenter.js +2 -2
  79. package/support/fixtures/factories/costCenterFacility.js +3 -3
  80. package/support/fixtures/factories/edgeNode.js +1 -1
  81. package/support/fixtures/factories/event.js +5 -5
  82. package/support/fixtures/factories/eventType.js +4 -4
  83. package/support/fixtures/factories/eventUser.js +5 -5
  84. package/support/fixtures/factories/facility.js +4 -4
  85. package/support/fixtures/factories/facilityGrouping.js +3 -3
  86. package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
  87. package/support/fixtures/factories/facilityInfo.js +2 -2
  88. package/support/fixtures/factories/facilityTag.js +1 -1
  89. package/support/fixtures/factories/feedStatus.js +1 -1
  90. package/support/fixtures/factories/feedType.js +1 -1
  91. package/support/fixtures/factories/feeds.js +5 -5
  92. package/support/fixtures/factories/fieldCategory.js +3 -3
  93. package/support/fixtures/factories/fieldGrouping.js +4 -4
  94. package/support/fixtures/factories/fieldGroupingField.js +3 -3
  95. package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
  96. package/support/fixtures/factories/file.js +1 -1
  97. package/support/fixtures/factories/fileUploadInfo.js +1 -1
  98. package/support/fixtures/factories/organization.js +1 -1
  99. package/support/fixtures/factories/outputField.js +10 -10
  100. package/support/fixtures/factories/outputFieldData.js +1 -1
  101. package/support/fixtures/factories/owner.js +2 -2
  102. package/support/fixtures/factories/paginationMetadata.js +2 -2
  103. package/support/fixtures/factories/triggeredEvent.js +4 -4
  104. package/support/fixtures/factories/userEventSubscription.js +1 -1
  105. package/support/fixtures/factories/userMobileNumber.js +1 -1
  106. package/support/fixtures/factories/userPermissionsMap.js +2 -2
  107. package/.huskyrc.js +0 -11
  108. package/.nycrc +0 -12
  109. package/esm/assets/assetAttributes.js +0 -574
  110. package/esm/assets/assetAttributes.js.map +0 -1
  111. package/esm/assets/assetMetrics.js +0 -690
  112. package/esm/assets/assetMetrics.js.map +0 -1
  113. package/esm/assets/assetTypes.js +0 -273
  114. package/esm/assets/assetTypes.js.map +0 -1
  115. package/esm/assets/index.js +0 -283
  116. package/esm/assets/index.js.map +0 -1
  117. package/esm/facilities/costCenters.js +0 -306
  118. package/esm/facilities/costCenters.js.map +0 -1
  119. package/esm/facilities/groupings.js +0 -323
  120. package/esm/facilities/groupings.js.map +0 -1
  121. package/esm/facilities/index.js +0 -343
  122. package/esm/facilities/index.js.map +0 -1
  123. package/esm/health/index.js +0 -229
  124. package/esm/health/index.js.map +0 -1
  125. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  126. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  127. package/esm/utils/facilities/index.js +0 -4
  128. package/esm/utils/facilities/index.js.map +0 -1
  129. package/lib/assets/assetAttributes.js +0 -588
  130. package/lib/assets/assetAttributes.js.map +0 -1
  131. package/lib/assets/assetMetrics.js +0 -705
  132. package/lib/assets/assetMetrics.js.map +0 -1
  133. package/lib/assets/assetTypes.js +0 -287
  134. package/lib/assets/assetTypes.js.map +0 -1
  135. package/lib/assets/index.js +0 -302
  136. package/lib/assets/index.js.map +0 -1
  137. package/lib/facilities/costCenters.js +0 -316
  138. package/lib/facilities/costCenters.js.map +0 -1
  139. package/lib/facilities/groupings.js +0 -333
  140. package/lib/facilities/groupings.js.map +0 -1
  141. package/lib/facilities/index.js +0 -360
  142. package/lib/facilities/index.js.map +0 -1
  143. package/lib/health/index.js +0 -232
  144. package/lib/health/index.js.map +0 -1
  145. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  146. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  147. package/lib/utils/facilities/index.js +0 -15
  148. package/lib/utils/facilities/index.js.map +0 -1
  149. package/src/assets/assetAttributes.js +0 -619
  150. package/src/assets/assetAttributes.spec.js +0 -1143
  151. package/src/assets/assetMetrics.js +0 -736
  152. package/src/assets/assetMetrics.spec.js +0 -1180
  153. package/src/assets/assetTypes.js +0 -260
  154. package/src/assets/assetTypes.spec.js +0 -556
  155. package/src/assets/index.js +0 -271
  156. package/src/assets/index.spec.js +0 -515
  157. package/src/facilities/costCenters.js +0 -295
  158. package/src/facilities/costCenters.spec.js +0 -529
  159. package/src/facilities/groupings.js +0 -320
  160. package/src/facilities/groupings.spec.js +0 -567
  161. package/src/facilities/index.js +0 -343
  162. package/src/facilities/index.spec.js +0 -551
  163. package/src/health/index.js +0 -200
  164. package/src/health/index.spec.js +0 -501
  165. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  166. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  167. package/src/utils/facilities/index.js +0 -3
@@ -1,302 +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 _assetAttributes = require('./assetAttributes');
14
-
15
- var _assetAttributes2 = _interopRequireDefault(_assetAttributes);
16
-
17
- var _assetMetrics = require('./assetMetrics');
18
-
19
- var _assetMetrics2 = _interopRequireDefault(_assetMetrics);
20
-
21
- var _assetTypes = require('./assetTypes');
22
-
23
- var _assetTypes2 = _interopRequireDefault(_assetTypes);
24
-
25
- var _objects = require('../utils/objects');
26
-
27
- var _pagination = require('../utils/pagination');
28
-
29
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
32
-
33
- /**
34
- * @typedef {Object} Asset
35
- * @property {string} assetTypeId UUID corresponding with the asset type
36
- * @property {string} createdAt ISO 8601 Extended Format date/time string
37
- * @property {string} [description]
38
- * @property {string} id UUID
39
- * @property {string} label
40
- * @property {string} organizationId UUID corresponding with the organization
41
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
42
- */
43
-
44
- /**
45
- * @typedef {Object} AssetsFromServer
46
- * @property {Object} _metadata Metadata about the pagination settings
47
- * @property {number} _metadata.offset Offset of records in subsequent queries
48
- * @property {number} _metadata.totalRecords Total number of asset types found
49
- * @property {Asset[]} records
50
- */
51
-
52
- /**
53
- * Module that provides access to, and the manipulation of, information about different assets
54
- *
55
- * @typicalname contxtSdk.assets
56
- */
57
- var Assets = function () {
58
- /**
59
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
60
- * @param {Object} request An instance of the request module tied to this module's audience.
61
- */
62
- function Assets(sdk, request) {
63
- _classCallCheck(this, Assets);
64
-
65
- var baseUrl = sdk.config.audiences.facilities.host + '/v1';
66
-
67
- this._baseUrl = baseUrl;
68
- this._request = request;
69
- this._sdk = sdk;
70
-
71
- this.attributes = new _assetAttributes2.default(sdk, request, baseUrl);
72
- this.types = new _assetTypes2.default(sdk, request, baseUrl);
73
- this.metrics = new _assetMetrics2.default(sdk, request, baseUrl);
74
- }
75
-
76
- /**
77
- * Creates a new asset
78
- *
79
- * API Endpoint: '/assets'
80
- * Method: POST
81
- *
82
- * @param {Object} asset
83
- * @param {string} asset.assetTypeId UUID
84
- * @param {string} [asset.description]
85
- * @param {string} asset.label
86
- * @param {string} asset.organizationId UUID
87
- *
88
- * @returns {Promise}
89
- * @fulfill {Asset} information about the new asset
90
- * @reject {Error}
91
- *
92
- * @example
93
- * contxtSdk.assets
94
- * .create({
95
- * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d',
96
- * description: '221B Baker Street, London',
97
- * label: 'Sherlock Homes Museum',
98
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'
99
- * })
100
- * .then((asset) => console.log(asset))
101
- * .catch((err) => console.log(err));
102
- */
103
-
104
-
105
- _createClass(Assets, [{
106
- key: 'create',
107
- value: function create() {
108
- var asset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
109
-
110
- var requiredFields = ['assetTypeId', 'label', 'organizationId'];
111
-
112
- for (var i = 0; i < requiredFields.length; i++) {
113
- var field = requiredFields[i];
114
-
115
- if (!asset[field]) {
116
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset.'));
117
- }
118
- }
119
-
120
- return this._request.post(this._baseUrl + '/assets', (0, _objects.toSnakeCase)(asset)).then(function (asset) {
121
- return (0, _objects.toCamelCase)(asset);
122
- });
123
- }
124
-
125
- /**
126
- * Deletes an asset
127
- *
128
- * API Endpoint: '/assets/:assetId'
129
- * Method: DELETE
130
- *
131
- * @param {string} assetId The ID of the asset (formatted as a UUID)
132
- *
133
- * @returns {Promise}
134
- * @fulfill {undefined}
135
- * @reject {Error}
136
- *
137
- * @example
138
- * contxtSdk.assets.delete('0b51429f-91a0-48ba-b144-fd2db697000e');
139
- */
140
-
141
- }, {
142
- key: 'delete',
143
- value: function _delete(assetId) {
144
- if (!assetId) {
145
- return Promise.reject(new Error('An asset ID is required for deleting an asset.'));
146
- }
147
-
148
- return this._request.delete(this._baseUrl + '/assets/' + assetId);
149
- }
150
-
151
- /**
152
- * Gets information about an asset
153
- *
154
- * API Endpoint: '/assets/:assetId'
155
- * Method: GET
156
- *
157
- * @param {string} assetId The ID of the asset (formatted as a UUID)
158
- *
159
- * @returns {Promise}
160
- * @fulfill {Asset} Information about the asset
161
- * @reject {Error}
162
- *
163
- * @example
164
- * contxtSdk.assets
165
- * .get('0b51429f-91a0-48ba-b144-fd2db697000e')
166
- * .then((asset) => console.log(asset))
167
- * .catch((err) => console.log(err));
168
- */
169
-
170
- }, {
171
- key: 'get',
172
- value: function get(assetId) {
173
- if (!assetId) {
174
- return Promise.reject(new Error('An asset ID is required for getting information about an asset.'));
175
- }
176
-
177
- return this._request.get(this._baseUrl + '/assets/' + assetId).then(function (asset) {
178
- return (0, _objects.toCamelCase)(asset);
179
- });
180
- }
181
-
182
- /**
183
- * Get a list of all assets
184
- *
185
- * API Endpoint: '/assets'
186
- * Method: GET
187
- *
188
- * @param {PaginationOptions} [paginationOptions]
189
- *
190
- * @returns {Promise}
191
- * @fulfill {AssetsFromServer}
192
- * @reject {Error}
193
- *
194
- * @example
195
- * contxtSdk.assets
196
- * .getAll()
197
- * .then((assets) => console.log(assets))
198
- * .catch((err) => console.log(err));
199
- */
200
-
201
- }, {
202
- key: 'getAll',
203
- value: function getAll(paginationOptions) {
204
- return this._request.get(this._baseUrl + '/assets', {
205
- params: (0, _objects.toSnakeCase)(paginationOptions)
206
- }).then(function (assetsData) {
207
- return (0, _pagination.formatPaginatedDataFromServer)(assetsData);
208
- });
209
- }
210
-
211
- /**
212
- * Get a list of all assets that belong to a particular organization
213
- *
214
- * API Endpoint: '/organizations/:organizationId/assets'
215
- * Method: GET
216
- *
217
- * @param {string} organizationId UUID corresponding with an organization
218
- * @param {Object} [options] Object containing parameters to be called with the request
219
- * @param {string} [options.assetTypeId] UUID of the asset type to use for filtering
220
- * @param {Number} [options.limit] Maximum number of records to return per query
221
- * @param {Number} [options.offset] How many records from the first record to start
222
- * @param {boolean} [options.includeTypeDescendents] When true will look for all asset types that are descendendents from options.assetTypeId
223
- * @param {string} [options.includeMetricId] If asset has an associated metric value the latest metric will be returned.
224
- *
225
- * @returns {Promise}
226
- * @fulfill {AssetsFromServer}
227
- * @reject {Error}
228
- *
229
- * @example
230
- * contxtSdk.assets
231
- * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c', {
232
- * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d'
233
- * })
234
- * .then((assets) => console.log(assets))
235
- * .catch((err) => console.log(err));
236
- */
237
-
238
- }, {
239
- key: 'getAllByOrganizationId',
240
- value: function getAllByOrganizationId(organizationId, options) {
241
- if (!organizationId) {
242
- return Promise.reject(new Error("An organization ID is required for getting a list of an organization's assets."));
243
- }
244
-
245
- var params = (0, _objects.toSnakeCase)(options);
246
-
247
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/assets', {
248
- params: params
249
- }).then(function (assetsData) {
250
- return (0, _pagination.formatPaginatedDataFromServer)(assetsData);
251
- });
252
- }
253
-
254
- /**
255
- * Updates an asset's data
256
- *
257
- * API Endpoint: '/assets/:assetId'
258
- * Method: PUT
259
- *
260
- * @param {string} assetId The ID of the asset to update (formatted as a UUID)
261
- * @param {Object} update An object containing the updated data for the asset
262
- * @param {string} update.description
263
- *
264
- * @example
265
- * contxtSdk.assets
266
- * .update({
267
- * description: 'A new description'
268
- * })
269
- * .then((asset) => console.log(asset))
270
- * .catch((err) => console.log(err));
271
- */
272
-
273
- }, {
274
- key: 'update',
275
- value: function update(assetId, _update) {
276
- if (!assetId) {
277
- return Promise.reject(new Error('An asset ID is required to update an asset.'));
278
- }
279
-
280
- if (!_update) {
281
- return Promise.reject(new Error('An update is required to update an asset.'));
282
- }
283
-
284
- if (!(0, _lodash2.default)(_update)) {
285
- return Promise.reject(new Error('The asset update must be a well-formed object with the data you wish to update.'));
286
- }
287
-
288
- var formattedUpdate = (0, _objects.toSnakeCase)(_update, {
289
- excludeKeys: ['assetTypeId', 'id', 'label', 'organizationId']
290
- });
291
-
292
- return this._request.put(this._baseUrl + '/assets/' + assetId, formattedUpdate).then(function (asset) {
293
- return (0, _objects.toCamelCase)(asset);
294
- });
295
- }
296
- }]);
297
-
298
- return Assets;
299
- }();
300
-
301
- exports.default = Assets;
302
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["assets/index.js"],"names":["Assets","sdk","request","baseUrl","config","audiences","facilities","host","_baseUrl","_request","_sdk","attributes","AssetAttributes","types","AssetTypes","metrics","AssetMetrics","asset","requiredFields","i","length","field","Promise","reject","Error","post","then","assetId","delete","get","paginationOptions","params","assetsData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AAhB;AAAA,OAJD,CAAP;AAKD;;AAED;;;;;;;;;;;;;;;;;;;;;2BAkBOL,O,EAASQ,O,EAAQ;AACtB,UAAI,CAACR,OAAL,EAAc;AACZ,eAAOL,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,6CAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACW,OAAL,EAAa;AACX,eAAOb,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,2CAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAAC,sBAAcW,OAAd,CAAL,EAA4B;AAC1B,eAAOb,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,iFADF,CADK,CAAP;AAKD;;AAED,UAAMY,kBAAkB,0BAAYD,OAAZ,EAAoB;AAC1CE,qBAAa,CAAC,aAAD,EAAgB,IAAhB,EAAsB,OAAtB,EAA+B,gBAA/B;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAK5B,QAAL,CACJ6B,GADI,CACG,KAAK9B,QADR,gBAC2BmB,OAD3B,EACsCS,eADtC,EAEJV,IAFI,CAEC,UAACT,KAAD;AAAA,eAAW,0BAAYA,KAAZ,CAAX;AAAA,OAFD,CAAP;AAGD;;;;;;kBAGYjB,M","file":"index.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport AssetAttributes from './assetAttributes';\nimport AssetMetrics from './assetMetrics';\nimport AssetTypes from './assetTypes';\n\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\nimport { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} Asset\n * @property {string} assetTypeId UUID corresponding with the asset type\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} [description]\n * @property {string} id UUID\n * @property {string} label\n * @property {string} organizationId UUID corresponding with the organization\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} AssetsFromServer\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 {Asset[]} records\n */\n\n/**\n * Module that provides access to, and the manipulation of, information about different assets\n *\n * @typicalname contxtSdk.assets\n */\nclass Assets {\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.attributes = new AssetAttributes(sdk, request, baseUrl);\n this.types = new AssetTypes(sdk, request, baseUrl);\n this.metrics = new AssetMetrics(sdk, request, baseUrl);\n }\n\n /**\n * Creates a new asset\n *\n * API Endpoint: '/assets'\n * Method: POST\n *\n * @param {Object} asset\n * @param {string} asset.assetTypeId UUID\n * @param {string} [asset.description]\n * @param {string} asset.label\n * @param {string} asset.organizationId UUID\n *\n * @returns {Promise}\n * @fulfill {Asset} information about the new asset\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .create({\n * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d',\n * description: '221B Baker Street, London',\n * label: 'Sherlock Homes Museum',\n * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'\n * })\n * .then((asset) => console.log(asset))\n * .catch((err) => console.log(err));\n */\n create(asset = {}) {\n const requiredFields = ['assetTypeId', 'label', 'organizationId'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!asset[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new asset.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/assets`, toSnakeCase(asset))\n .then((asset) => toCamelCase(asset));\n }\n\n /**\n * Deletes an asset\n *\n * API Endpoint: '/assets/:assetId'\n * Method: DELETE\n *\n * @param {string} assetId The ID of the asset (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.delete('0b51429f-91a0-48ba-b144-fd2db697000e');\n */\n delete(assetId) {\n if (!assetId) {\n return Promise.reject(\n new Error('An asset ID is required for deleting an asset.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/assets/${assetId}`);\n }\n\n /**\n * Gets information about an asset\n *\n * API Endpoint: '/assets/:assetId'\n * Method: GET\n *\n * @param {string} assetId The ID of the asset (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {Asset} Information about the asset\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .get('0b51429f-91a0-48ba-b144-fd2db697000e')\n * .then((asset) => console.log(asset))\n * .catch((err) => console.log(err));\n */\n get(assetId) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required for getting information about an asset.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/${assetId}`)\n .then((asset) => toCamelCase(asset));\n }\n\n /**\n * Get a list of all assets\n *\n * API Endpoint: '/assets'\n * Method: GET\n *\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetsFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .getAll()\n * .then((assets) => console.log(assets))\n * .catch((err) => console.log(err));\n */\n getAll(paginationOptions) {\n return this._request\n .get(`${this._baseUrl}/assets`, {\n params: toSnakeCase(paginationOptions)\n })\n .then((assetsData) => formatPaginatedDataFromServer(assetsData));\n }\n\n /**\n * Get a list of all assets that belong to a particular organization\n *\n * API Endpoint: '/organizations/:organizationId/assets'\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 {string} [options.assetTypeId] UUID of the asset type to use for filtering\n * @param {Number} [options.limit] Maximum number of records to return per query\n * @param {Number} [options.offset] How many records from the first record to start\n * @param {boolean} [options.includeTypeDescendents] When true will look for all asset types that are descendendents from options.assetTypeId\n * @param {string} [options.includeMetricId] If asset has an associated metric value the latest metric will be returned.\n *\n * @returns {Promise}\n * @fulfill {AssetsFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c', {\n * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d'\n * })\n * .then((assets) => console.log(assets))\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 assets.\"\n )\n );\n }\n\n const params = toSnakeCase(options);\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/assets`, {\n params\n })\n .then((assetsData) => formatPaginatedDataFromServer(assetsData));\n }\n\n /**\n * Updates an asset's data\n *\n * API Endpoint: '/assets/:assetId'\n * Method: PUT\n *\n * @param {string} assetId The ID of the asset to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset\n * @param {string} update.description\n *\n * @example\n * contxtSdk.assets\n * .update({\n * description: 'A new description'\n * })\n * .then((asset) => console.log(asset))\n * .catch((err) => console.log(err));\n */\n update(assetId, update) {\n if (!assetId) {\n return Promise.reject(\n new Error('An asset ID is required to update an asset.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset 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', 'label', 'organizationId']\n });\n\n return this._request\n .put(`${this._baseUrl}/assets/${assetId}`, formattedUpdate)\n .then((asset) => toCamelCase(asset));\n }\n}\n\nexport default Assets;\n"]}
@@ -1,316 +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 _objects = require('../utils/objects');
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- /**
20
- * @typedef {Object} CostCenter
21
- * @param {string} createdAt ISO 8601 Extended Format date/time string
22
- * @param {string} [description]
23
- * @param {string} id UUID
24
- * @param {string} name
25
- * @param {string} organizationId UUID
26
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
27
- */
28
-
29
- /**
30
- * @typedef {Object} CostCenterFacility
31
- * @param {string} costCenterId UUID
32
- * @param {string} createdAt ISO 8601 Extended Format date/time string
33
- * @param {number} facilityId
34
- * @param {string} id UUID
35
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
36
- */
37
-
38
- /**
39
- * Module that provides access to cost centers, and helps manage
40
- * the relationship between those cost centers and facilities
41
- *
42
- * @typicalname contxtSdk.facilities.costCenters
43
- */
44
- var CostCenters = function () {
45
- /**
46
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules
47
- * @param {Object} request An instance of the request module tied to this module's audience.
48
- * @param {string} baseUrl The base URL provided by the parent module
49
- */
50
- function CostCenters(sdk, request, baseUrl) {
51
- _classCallCheck(this, CostCenters);
52
-
53
- this._baseUrl = baseUrl;
54
- this._request = request;
55
- this._sdk = sdk;
56
- }
57
-
58
- /**
59
- * Adds a facility to a cost center
60
- *
61
- * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'
62
- * Method: POST
63
- *
64
- * @param {string} costCenterId UUID corresponding with a cost center
65
- * @param {number} facilityId The ID of a facility
66
- *
67
- * @returns {Promise}
68
- * @fulfill {CostCenterFacility} Information about the new cost center facility relationship
69
- * @reject {Error}
70
- *
71
- * @example
72
- * contxtSdk.facilities.costCenters
73
- * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
74
- * .then((costCenter) => console.log(costCenter))
75
- * .catch((err) => console.log(err));
76
- */
77
-
78
-
79
- _createClass(CostCenters, [{
80
- key: 'addFacility',
81
- value: function addFacility(costCenterId, facilityId) {
82
- var errorMsg = void 0;
83
-
84
- if (!costCenterId) {
85
- errorMsg = 'A costCenterId is required to create a relationship between a cost center and a facility.';
86
- } else if (!facilityId) {
87
- errorMsg = 'A facilityId is required to create a relationship between a cost center and a facility.';
88
- }
89
-
90
- if (errorMsg) {
91
- return Promise.reject(new Error(errorMsg));
92
- }
93
-
94
- return this._request.post(this._baseUrl + '/costcenters/' + costCenterId + '/facility/' + facilityId).then(function (costCenterFacility) {
95
- return (0, _objects.toCamelCase)(costCenterFacility);
96
- });
97
- }
98
-
99
- /**
100
- * Creates a new cost center
101
- *
102
- * API Endpoint: '/costcenters'
103
- * Method: POST
104
- *
105
- * @param {Object} costCenter
106
- * @param {string} [costCenter.description]
107
- * @param {string} costCenter.name
108
- * @param {string} costCenter.organizationId UUID
109
- *
110
- * @returns {Promise}
111
- * @fulfill {CostCenter} Information about the new cost center
112
- * @reject {Error}
113
- *
114
- * @example
115
- * contxtSdk.facilities.costCenters
116
- * .create({
117
- * decsription: 'Cost center number 1',
118
- * name: 'North Carolina, USA',
119
- * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5'
120
- * })
121
- * .then((costCenter) => console.log(costCenter))
122
- * .catch((err) => console.log(err));
123
- */
124
-
125
- }, {
126
- key: 'create',
127
- value: function create() {
128
- var costCenter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
129
-
130
- var requiredFields = ['name', 'organizationId'];
131
-
132
- for (var i = 0; i < requiredFields.length; i++) {
133
- var field = requiredFields[i];
134
-
135
- if (!costCenter[field]) {
136
- return Promise.reject(new Error('A ' + field + ' is required to create a new cost center.'));
137
- }
138
- }
139
-
140
- return this._request.post(this._baseUrl + '/costcenters', (0, _objects.toSnakeCase)(costCenter)).then(function (costCenter) {
141
- return (0, _objects.toCamelCase)(costCenter);
142
- });
143
- }
144
-
145
- /**
146
- * Delete a cost center
147
- *
148
- * API Endpoint: '/costcenters/:costCenterId'
149
- * Method: DELETE
150
- *
151
- * @param {string} costCenterId The ID of the cost center (formatted as a UUID)
152
- *
153
- * @returns {Promise}
154
- * @fulfill {undefined}
155
- * @reject {Error}
156
- *
157
- * @example
158
- * contxtSdk.facilities.costCenters.delete(
159
- * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'
160
- * );
161
- */
162
-
163
- }, {
164
- key: 'delete',
165
- value: function _delete(costCenterId) {
166
- if (!costCenterId) {
167
- return Promise.reject(new Error('A cost center id is required for deleting a cost center.'));
168
- }
169
-
170
- return this._request.delete(this._baseUrl + '/costcenters/' + costCenterId);
171
- }
172
-
173
- /**
174
- * Get a listing of all cost centers
175
- *
176
- * API Endpoint: '/costcenters'
177
- * METHOD: GET
178
- *
179
- * @returns {Promise}
180
- * @fulfill {CostCenter[]}
181
- * @reject {Error}
182
- *
183
- * @example
184
- * contxtSdk.facilities.costCenters
185
- * .getAll()
186
- * .then((costCenters) => console.log(costCenters))
187
- * .catch((err) => console.log(err));
188
- */
189
-
190
- }, {
191
- key: 'getAll',
192
- value: function getAll() {
193
- return this._request.get(this._baseUrl + '/costcenters').then(function (costCenters) {
194
- return (0, _objects.toCamelCase)(costCenters);
195
- });
196
- }
197
-
198
- /**
199
- * Get a listing of all cost centers for an organization
200
- *
201
- * API Endpoint: '/organizations/:organizationId/costcenters'
202
- * METHOD: GET
203
- *
204
- * @param {string} organizationId The ID of the organization (formatted as a UUID)
205
- *
206
- * @returns {Promise}
207
- * @fulfill {CostCenter[]}
208
- * @reject {Error}
209
- *
210
- * @example
211
- * contxtSdk.facilities.costCenters
212
- * .getAllByOrganizationId('59270c25-4de9-4b22-8e0b-ab287ac344ce')
213
- * .then((costCenters) => console.log(costCenters))
214
- * .catch((err) => console.log(err));
215
- */
216
-
217
- }, {
218
- key: 'getAllByOrganizationId',
219
- value: function getAllByOrganizationId(organizationId) {
220
- if (!organizationId) {
221
- return Promise.reject(new Error("An organization id is required for getting a list of an organization's cost centers."));
222
- }
223
-
224
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/costcenters').then(function (costCenters) {
225
- return (0, _objects.toCamelCase)(costCenters);
226
- });
227
- }
228
-
229
- /**
230
- * Removes a facility from a cost center
231
- *
232
- * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'
233
- * Method: DELETE
234
- *
235
- * @param {string} costCenterId UUID corresponding with a cost center
236
- * @param {number} facilityId ID corresponding with the facility
237
- *
238
- * @returns {Promise}
239
- * @fulfill {undefined}
240
- * @reject {Error}
241
- *
242
- * @example
243
- * contxtSdk.facilities.costCenters
244
- * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
245
- * .catch((err) => console.log(err));
246
- */
247
-
248
- }, {
249
- key: 'removeFacility',
250
- value: function removeFacility(costCenterId, facilityId) {
251
- var errorMsg = void 0;
252
-
253
- if (!costCenterId) {
254
- errorMsg = 'A costCenterId is required to remove a relationship between a cost center and a facility.';
255
- } else if (!facilityId) {
256
- errorMsg = 'A facilityId is required to remove a relationship between a cost center and a facility.';
257
- }
258
-
259
- if (errorMsg) {
260
- return Promise.reject(new Error(errorMsg));
261
- }
262
-
263
- return this._request.delete(this._baseUrl + '/costcenters/' + costCenterId + '/facility/' + facilityId);
264
- }
265
-
266
- /**
267
- * Updates an existing cost center
268
- *
269
- * API Endpoint: '/costcenters/:costCenterId'
270
- * Method: PUT
271
- *
272
- * @param {String} costCenterId
273
- * @param {Object} update
274
- * @param {string} [update.description]
275
- * @param {string} [update.name]
276
- *
277
- * @returns {Promise}
278
- * @fulfill {FacilityGrouping} Information about the updated cost center
279
- * @reject {Error}
280
- *
281
- * @example
282
- * contxtSdk.facilities.costCenters
283
- * .update({
284
- * description: 'Refrigeration compressors throughout the facility',
285
- * name: 'Compressors',
286
- * })
287
- * .then((costCenter) => console.log(costCenter))
288
- * .catch((err) => console.log(err));
289
- */
290
-
291
- }, {
292
- key: 'update',
293
- value: function update(costCenterId, _update) {
294
- if (!costCenterId) {
295
- return Promise.reject(new Error('A cost center id is required to update a cost center.'));
296
- }
297
-
298
- if (!_update) {
299
- return Promise.reject(new Error('An update is required to update a cost center.'));
300
- }
301
-
302
- if (!(0, _lodash2.default)(_update)) {
303
- return Promise.reject(new Error('The cost center update must be a well-formed object with the data you wish to update.'));
304
- }
305
-
306
- return this._request.put(this._baseUrl + '/costcenters/' + costCenterId, (0, _objects.toSnakeCase)(_update)).then(function (costCenter) {
307
- return (0, _objects.toCamelCase)(costCenter);
308
- });
309
- }
310
- }]);
311
-
312
- return CostCenters;
313
- }();
314
-
315
- exports.default = CostCenters;
316
- //# sourceMappingURL=costCenters.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["facilities/costCenters.js"],"names":["CostCenters","sdk","request","baseUrl","_baseUrl","_request","_sdk","costCenterId","facilityId","errorMsg","Promise","reject","Error","post","then","costCenterFacility","costCenter","requiredFields","i","length","field","delete","get","costCenters","organizationId","update","put"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;;;AAEA;;;;;;;;;;AAUA;;;;;;;;;AASA;;;;;;IAMMA,W;AACJ;;;;;AAKA,uBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;gCAmBYM,Y,EAAcC,U,EAAY;AACpC,UAAIC,iBAAJ;;AAEA,UAAI,CAACF,YAAL,EAAmB;AACjBE,mBACE,2FADF;AAED,OAHD,MAGO,IAAI,CAACD,UAAL,EAAiB;AACtBC,mB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KAAKtB,QADR,qBACgCG,YADhC,EACgD,0BAAYkB,OAAZ,CADhD,EAEJX,IAFI,CAEC,UAACE,UAAD;AAAA,eAAgB,0BAAYA,UAAZ,CAAhB;AAAA,OAFD,CAAP;AAGD;;;;;;kBAGYhB,W","file":"costCenters.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} CostCenter\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {string} [description]\n * @param {string} id UUID\n * @param {string} name\n * @param {string} organizationId UUID\n * @param {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} CostCenterFacility\n * @param {string} costCenterId UUID\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {number} facilityId\n * @param {string} id UUID\n * @param {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * Module that provides access to cost centers, and helps manage\n * the relationship between those cost centers and facilities\n *\n * @typicalname contxtSdk.facilities.costCenters\n */\nclass CostCenters {\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 * Adds a facility to a cost center\n *\n * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'\n * Method: POST\n *\n * @param {string} costCenterId UUID corresponding with a cost center\n * @param {number} facilityId The ID of a facility\n *\n * @returns {Promise}\n * @fulfill {CostCenterFacility} Information about the new cost center facility relationship\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .then((costCenter) => console.log(costCenter))\n * .catch((err) => console.log(err));\n */\n addFacility(costCenterId, facilityId) {\n let errorMsg;\n\n if (!costCenterId) {\n errorMsg =\n 'A costCenterId is required to create a relationship between a cost center and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to create a relationship between a cost center and a facility.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .post(\n `${this._baseUrl}/costcenters/${costCenterId}/facility/${facilityId}`\n )\n .then((costCenterFacility) => toCamelCase(costCenterFacility));\n }\n\n /**\n * Creates a new cost center\n *\n * API Endpoint: '/costcenters'\n * Method: POST\n *\n * @param {Object} costCenter\n * @param {string} [costCenter.description]\n * @param {string} costCenter.name\n * @param {string} costCenter.organizationId UUID\n *\n * @returns {Promise}\n * @fulfill {CostCenter} Information about the new cost center\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .create({\n * decsription: 'Cost center number 1',\n * name: 'North Carolina, USA',\n * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5'\n * })\n * .then((costCenter) => console.log(costCenter))\n * .catch((err) => console.log(err));\n */\n create(costCenter = {}) {\n const requiredFields = ['name', 'organizationId'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!costCenter[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new cost center.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/costcenters`, toSnakeCase(costCenter))\n .then((costCenter) => toCamelCase(costCenter));\n }\n\n /**\n * Delete a cost center\n *\n * API Endpoint: '/costcenters/:costCenterId'\n * Method: DELETE\n *\n * @param {string} costCenterId The ID of the cost center (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters.delete(\n * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'\n * );\n */\n delete(costCenterId) {\n if (!costCenterId) {\n return Promise.reject(\n new Error('A cost center id is required for deleting a cost center.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/costcenters/${costCenterId}`);\n }\n\n /**\n * Get a listing of all cost centers\n *\n * API Endpoint: '/costcenters'\n * METHOD: GET\n *\n * @returns {Promise}\n * @fulfill {CostCenter[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .getAll()\n * .then((costCenters) => console.log(costCenters))\n * .catch((err) => console.log(err));\n */\n getAll() {\n return this._request\n .get(`${this._baseUrl}/costcenters`)\n .then((costCenters) => toCamelCase(costCenters));\n }\n\n /**\n * Get a listing of all cost centers for an organization\n *\n * API Endpoint: '/organizations/:organizationId/costcenters'\n * METHOD: GET\n *\n * @param {string} organizationId The ID of the organization (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {CostCenter[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .getAllByOrganizationId('59270c25-4de9-4b22-8e0b-ab287ac344ce')\n * .then((costCenters) => console.log(costCenters))\n * .catch((err) => console.log(err));\n */\n getAllByOrganizationId(organizationId) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n \"An organization id is required for getting a list of an organization's cost centers.\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/costcenters`)\n .then((costCenters) => toCamelCase(costCenters));\n }\n\n /**\n * Removes a facility from a cost center\n *\n * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'\n * Method: DELETE\n *\n * @param {string} costCenterId UUID corresponding with a cost center\n * @param {number} facilityId ID corresponding with the facility\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .catch((err) => console.log(err));\n */\n removeFacility(costCenterId, facilityId) {\n let errorMsg;\n\n if (!costCenterId) {\n errorMsg =\n 'A costCenterId is required to remove a relationship between a cost center and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to remove a relationship between a cost center and a facility.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request.delete(\n `${this._baseUrl}/costcenters/${costCenterId}/facility/${facilityId}`\n );\n }\n\n /**\n * Updates an existing cost center\n *\n * API Endpoint: '/costcenters/:costCenterId'\n * Method: PUT\n *\n * @param {String} costCenterId\n * @param {Object} update\n * @param {string} [update.description]\n * @param {string} [update.name]\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping} Information about the updated cost center\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .update({\n * description: 'Refrigeration compressors throughout the facility',\n * name: 'Compressors',\n * })\n * .then((costCenter) => console.log(costCenter))\n * .catch((err) => console.log(err));\n */\n update(costCenterId, update) {\n if (!costCenterId) {\n return Promise.reject(\n new Error('A cost center id is required to update a cost center.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a cost center.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The cost center update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n return this._request\n .put(`${this._baseUrl}/costcenters/${costCenterId}`, toSnakeCase(update))\n .then((costCenter) => toCamelCase(costCenter));\n }\n}\n\nexport default CostCenters;\n"]}