@ndustrial/contxt-sdk 4.3.4 → 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 (169) hide show
  1. package/.gitattributes +1 -0
  2. package/.nvmrc +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/docs/Facilities.md +0 -144
  5. package/docs/FacilityGroupings.md +0 -160
  6. package/docs/Nionic.md +63 -0
  7. package/docs/README.md +3 -29
  8. package/docs/Typedefs.md +0 -101
  9. package/esm/config/audiences.js +13 -13
  10. package/esm/config/audiences.js.map +1 -1
  11. package/esm/index.js +3 -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 +19 -13
  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 +3 -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/.envrc +0 -0
  108. package/.huskyrc.js +0 -11
  109. package/.nycrc +0 -12
  110. package/esm/assets/assetAttributes.js +0 -574
  111. package/esm/assets/assetAttributes.js.map +0 -1
  112. package/esm/assets/assetMetrics.js +0 -690
  113. package/esm/assets/assetMetrics.js.map +0 -1
  114. package/esm/assets/assetTypes.js +0 -273
  115. package/esm/assets/assetTypes.js.map +0 -1
  116. package/esm/assets/index.js +0 -283
  117. package/esm/assets/index.js.map +0 -1
  118. package/esm/facilities/costCenters.js +0 -306
  119. package/esm/facilities/costCenters.js.map +0 -1
  120. package/esm/facilities/groupings.js +0 -323
  121. package/esm/facilities/groupings.js.map +0 -1
  122. package/esm/facilities/index.js +0 -343
  123. package/esm/facilities/index.js.map +0 -1
  124. package/esm/health/index.js +0 -229
  125. package/esm/health/index.js.map +0 -1
  126. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  127. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  128. package/esm/utils/facilities/index.js +0 -4
  129. package/esm/utils/facilities/index.js.map +0 -1
  130. package/lib/assets/assetAttributes.js +0 -588
  131. package/lib/assets/assetAttributes.js.map +0 -1
  132. package/lib/assets/assetMetrics.js +0 -705
  133. package/lib/assets/assetMetrics.js.map +0 -1
  134. package/lib/assets/assetTypes.js +0 -287
  135. package/lib/assets/assetTypes.js.map +0 -1
  136. package/lib/assets/index.js +0 -302
  137. package/lib/assets/index.js.map +0 -1
  138. package/lib/facilities/costCenters.js +0 -316
  139. package/lib/facilities/costCenters.js.map +0 -1
  140. package/lib/facilities/groupings.js +0 -333
  141. package/lib/facilities/groupings.js.map +0 -1
  142. package/lib/facilities/index.js +0 -360
  143. package/lib/facilities/index.js.map +0 -1
  144. package/lib/health/index.js +0 -232
  145. package/lib/health/index.js.map +0 -1
  146. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  147. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  148. package/lib/utils/facilities/index.js +0 -15
  149. package/lib/utils/facilities/index.js.map +0 -1
  150. package/src/assets/assetAttributes.js +0 -619
  151. package/src/assets/assetAttributes.spec.js +0 -1143
  152. package/src/assets/assetMetrics.js +0 -736
  153. package/src/assets/assetMetrics.spec.js +0 -1180
  154. package/src/assets/assetTypes.js +0 -260
  155. package/src/assets/assetTypes.spec.js +0 -556
  156. package/src/assets/index.js +0 -271
  157. package/src/assets/index.spec.js +0 -515
  158. package/src/facilities/costCenters.js +0 -295
  159. package/src/facilities/costCenters.spec.js +0 -529
  160. package/src/facilities/groupings.js +0 -320
  161. package/src/facilities/groupings.spec.js +0 -567
  162. package/src/facilities/index.js +0 -343
  163. package/src/facilities/index.spec.js +0 -551
  164. package/src/health/index.js +0 -200
  165. package/src/health/index.spec.js +0 -501
  166. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  167. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  168. package/src/utils/facilities/index.js +0 -3
  169. package/tmp/package.json +0 -11
@@ -1,333 +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} FacilityGrouping
21
- * @param {string} createdAt ISO 8601 Extended Format date/time string
22
- * @param {string} [description]
23
- * @param {Facility[]} [facilities]
24
- * @param {string} id UUID
25
- * @param {boolean} isPrivate
26
- * @param {string} name
27
- * @param {string} organizationId UUID
28
- * @param {string} ownerId Auth0 identifer of the user
29
- * @param {string} [parentGroupingId] UUID
30
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
31
- */
32
-
33
- /**
34
- * @typedef {Object} FacilityGroupingFacility
35
- * @param {string} createdAt ISO 8601 Extended Format date/time string
36
- * @param {string} facilityGroupingId UUID
37
- * @param {number} facilityId
38
- * @param {string} id UUID
39
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
40
- */
41
-
42
- /**
43
- * Module that provides access to facility groupings, and helps manage
44
- * the relationship between those groupings and facilities
45
- *
46
- * @typicalname contxtSdk.facilities.groupings
47
- */
48
- var FacilityGroupings = 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} baseUrl The base URL provided by the parent module
53
- */
54
- function FacilityGroupings(sdk, request, baseUrl) {
55
- _classCallCheck(this, FacilityGroupings);
56
-
57
- this._baseUrl = baseUrl;
58
- this._request = request;
59
- this._sdk = sdk;
60
- }
61
-
62
- /**
63
- * Adds a facility to a facility grouping
64
- *
65
- * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'
66
- * Method: POST
67
- *
68
- * @param {string} facilityGroupingId UUID corresponding with a facility grouping
69
- * @param {number} facilityId
70
- *
71
- * @returns {Promise}
72
- * @fulfill {FacilityGroupingFacility} Information about the new facility/grouping relationship
73
- * @reject {Error}
74
- *
75
- * @example
76
- * contxtSdk.facilities.groupings
77
- * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
78
- * .then((grouping) => console.log(grouping))
79
- * .catch((err) => console.log(err));
80
- */
81
-
82
-
83
- _createClass(FacilityGroupings, [{
84
- key: 'addFacility',
85
- value: function addFacility(facilityGroupingId, facilityId) {
86
- var errorMsg = void 0;
87
-
88
- if (!facilityGroupingId) {
89
- errorMsg = 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.';
90
- } else if (!facilityId) {
91
- errorMsg = 'A facilityId is required to create a relationship between a facility grouping and a facility.';
92
- }
93
-
94
- if (errorMsg) {
95
- return Promise.reject(new Error(errorMsg));
96
- }
97
-
98
- return this._request.post(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId).then(function (groupingFacility) {
99
- return (0, _objects.toCamelCase)(groupingFacility);
100
- });
101
- }
102
-
103
- /**
104
- * Creates a new facility grouping
105
- *
106
- * API Endpoint: '/groupings'
107
- * Method: POST
108
- *
109
- * @param {Object} facilityGrouping
110
- * @param {string} [facilityGrouping.description]
111
- * @param {boolean} [facilityGrouping.isPrivate = false]
112
- * @param {string} facilityGrouping.name
113
- * @param {string} facilityGrouping.organizationId UUID
114
- * @param {string} [facilityGrouping.parentGroupingId] UUID
115
- *
116
- * @returns {Promise}
117
- * @fulfill {FacilityGrouping} Information about the new facility grouping
118
- * @reject {Error}
119
- *
120
- * @example
121
- * contxtSdk.facilities.groupings
122
- * .create({
123
- * description: 'US States of CT, MA, ME, NH, RI, VT',
124
- * isPrivate: false,
125
- * name: 'New England, USA',
126
- * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5',
127
- * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'
128
- * })
129
- * .then((grouping) => console.log(grouping))
130
- * .catch((err) => console.log(err));
131
- */
132
-
133
- }, {
134
- key: 'create',
135
- value: function create() {
136
- var grouping = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
137
-
138
- var requiredFields = ['name', 'organizationId'];
139
-
140
- for (var i = 0; requiredFields.length > i; i++) {
141
- var field = requiredFields[i];
142
-
143
- if (!grouping[field]) {
144
- return Promise.reject(new Error('A ' + field + ' is required to create a new facility grouping.'));
145
- }
146
- }
147
-
148
- return this._request.post(this._baseUrl + '/groupings', (0, _objects.toSnakeCase)(grouping)).then(function (grouping) {
149
- return (0, _objects.toCamelCase)(grouping);
150
- });
151
- }
152
-
153
- /**
154
- * Delete a facility groupings
155
- *
156
- * API Endpoint: '/groupings/:facilityGroupingId'
157
- * Method: DELETE
158
- *
159
- * @param {string} facilityGroupingId The id of the facility grouping (formatted as a UUID)
160
- *
161
- * @returns {Promise}
162
- * @fulfill {undefined}
163
- * @reject {Error}
164
- *
165
- * @example
166
- * contxtSdk.facilities.groupings.delete(
167
- * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'
168
- * );
169
- */
170
-
171
- }, {
172
- key: 'delete',
173
- value: function _delete(facilityGroupingId) {
174
- if (!facilityGroupingId) {
175
- return Promise.reject(new Error('A facility grouping id is required for deleting a facility grouping.'));
176
- }
177
-
178
- return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId);
179
- }
180
-
181
- /**
182
- * Get a listing of all facility groupings available to a user. Includes public groupings across
183
- * any organization the user has access to and the user's private groupings.
184
- *
185
- * API Endpoint: '/groupings'
186
- * Method: GET
187
- *
188
- * @returns {Promise}
189
- * @fulfill {FacilityGrouping[]}
190
- * @reject {Error}
191
- *
192
- * @example
193
- * contxtSdk.facilites.groupings
194
- * .getAll()
195
- * .then((groupings) => console.log(groupings))
196
- * .catch((err) => console.log(err));
197
- */
198
-
199
- }, {
200
- key: 'getAll',
201
- value: function getAll() {
202
- return this._request.get(this._baseUrl + '/groupings').then(function (groupings) {
203
- return (0, _objects.toCamelCase)(groupings);
204
- });
205
- }
206
-
207
- /**
208
- * Get a listing of all facility groupings for an organization. Includes public groupings
209
- * across that specific organization and the user's private groupings for that organization.
210
- *
211
- * API Endpoint: '/organizations/:organizationId/groupings'
212
- * Method: GET
213
- *
214
- * @param {string} organizationId UUID corresponding with an organization
215
- *
216
- * @returns {Promise}
217
- * @fulfill {FacilityGrouping[]}
218
- * @reject {Error}
219
- *
220
- * @example
221
- * contxtSdk.facilites.groupings
222
- * .getAllByOrganizationId('349dbd36-5dca-4a10-b54d-d0f71c3c8709')
223
- * .then((groupings) => console.log(groupings))
224
- * .catch((err) => console.log(err));
225
- */
226
-
227
- }, {
228
- key: 'getAllByOrganizationId',
229
- value: function getAllByOrganizationId(organizationId) {
230
- if (!organizationId) {
231
- return Promise.reject(new Error("An organization id is required for getting a list of an organization's facility groupings"));
232
- }
233
-
234
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/groupings').then(function (groupings) {
235
- return (0, _objects.toCamelCase)(groupings);
236
- });
237
- }
238
-
239
- /**
240
- * Removes a facility from a facility grouping
241
- *
242
- * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'
243
- * Method: DELETE
244
- *
245
- * @param {string} facilityGroupingId UUID corresponding with a facility grouping
246
- * @param {number} facilityId
247
- *
248
- * @returns {Promise}
249
- * @reject {Error}
250
- *
251
- * @example
252
- * contxtSdk.facilities.groupings
253
- * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
254
- * .catch((err) => console.log(err));
255
- */
256
-
257
- }, {
258
- key: 'removeFacility',
259
- value: function removeFacility(facilityGroupingId, facilityId) {
260
- var errorMsg = void 0;
261
-
262
- if (!facilityGroupingId) {
263
- errorMsg = 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.';
264
- } else if (!facilityId) {
265
- errorMsg = 'A facilityId is required to remove a relationship between a facility grouping and a facility.';
266
- }
267
-
268
- if (errorMsg) {
269
- return Promise.reject(new Error(errorMsg));
270
- }
271
-
272
- return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId);
273
- }
274
-
275
- /**
276
- * Updates an existing facility grouping
277
- *
278
- * API Endpoint: '/groupings/:facilityGroupingId'
279
- * Method: PUT
280
- *
281
- * @param {String} facilityGroupingId
282
- * @param {Object} update
283
- * @param {string} [update.description]
284
- * @param {boolean} [update.isPrivate]
285
- * @param {string} [update.name]
286
- * @param {string} [update.parentGroupingId] UUID corresponding with another facility grouping
287
- *
288
- * @returns {Promise}
289
- * @fulfill {FacilityGrouping} Information about the updated facility grouping
290
- * @reject {Error}
291
- *
292
- * @example
293
- * contxtSdk.facilities.groupings
294
- * .update('b3dbaae3-25dd-475b-80dc-66296630a8d0', {
295
- * description: 'US States of CT, MA, ME, NH, RI, VT',
296
- * isPrivate: false,
297
- * name: 'New England, USA',
298
- * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'
299
- * })
300
- * .then((grouping) => console.log(grouping))
301
- * .catch((err) => console.log(err));
302
- */
303
-
304
- }, {
305
- key: 'update',
306
- value: function update(facilityGroupingId, _update) {
307
- if (!facilityGroupingId) {
308
- return Promise.reject(new Error('A facility grouping id is required to update a facility grouping.'));
309
- }
310
-
311
- if (!_update) {
312
- return Promise.reject(new Error('An update is required to update a facility grouping'));
313
- }
314
-
315
- if (!(0, _lodash2.default)(_update)) {
316
- return Promise.reject(new Error('The facility grouping update must be a well-formed object with the data you wish to update.'));
317
- }
318
-
319
- var formattedUpdate = (0, _objects.toSnakeCase)(_update, {
320
- excludeKeys: ['id', 'organizationId', 'ownerId']
321
- });
322
-
323
- return this._request.put(this._baseUrl + '/groupings/' + facilityGroupingId, formattedUpdate).then(function (grouping) {
324
- return (0, _objects.toCamelCase)(grouping);
325
- });
326
- }
327
- }]);
328
-
329
- return FacilityGroupings;
330
- }();
331
-
332
- exports.default = FacilityGroupings;
333
- //# sourceMappingURL=groupings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["facilities/groupings.js"],"names":["FacilityGroupings","sdk","request","baseUrl","_baseUrl","_request","_sdk","facilityGroupingId","facilityId","errorMsg","Promise","reject","Error","post","then","groupingFacility","grouping","requiredFields","i","length","field","delete","get","groupings","organizationId","update","formattedUpdate","excludeKeys","put"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;;;AAEA;;;;;;;;;;;;;;AAcA;;;;;;;;;AASA;;;;;;IAMMA,iB;AACJ;;;;;AAKA,6BAAYC,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,kB,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AI,CAAC,sBAAca,OAAd,CAAL,EAA4B;AAC1B,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,6FADF,CADK,CAAP;AAKD;;AAED,UAAMc,kBAAkB,0BAAYD,OAAZ,EAAoB;AAC1CE,qBAAa,CAAC,IAAD,EAAO,gBAAP,EAAyB,SAAzB;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAKtB,QAAL,CACJuB,GADI,CACG,KAAKxB,QADR,mBAC8BG,kBAD9B,EACoDmB,eADpD,EAEJZ,IAFI,CAEC,UAACE,QAAD;AAAA,eAAc,0BAAYA,QAAZ,CAAd;AAAA,OAFD,CAAP;AAGD;;;;;;kBAGYhB,iB","file":"groupings.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} FacilityGrouping\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {string} [description]\n * @param {Facility[]} [facilities]\n * @param {string} id UUID\n * @param {boolean} isPrivate\n * @param {string} name\n * @param {string} organizationId UUID\n * @param {string} ownerId Auth0 identifer of the user\n * @param {string} [parentGroupingId] UUID\n * @param {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} FacilityGroupingFacility\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {string} facilityGroupingId UUID\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 facility groupings, and helps manage\n * the relationship between those groupings and facilities\n *\n * @typicalname contxtSdk.facilities.groupings\n */\nclass FacilityGroupings {\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 facility grouping\n *\n * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'\n * Method: POST\n *\n * @param {string} facilityGroupingId UUID corresponding with a facility grouping\n * @param {number} facilityId\n *\n * @returns {Promise}\n * @fulfill {FacilityGroupingFacility} Information about the new facility/grouping relationship\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .then((grouping) => console.log(grouping))\n * .catch((err) => console.log(err));\n */\n addFacility(facilityGroupingId, facilityId) {\n let errorMsg;\n\n if (!facilityGroupingId) {\n errorMsg =\n 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to create a relationship between a facility grouping and a facility.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .post(\n `${\n this._baseUrl\n }/groupings/${facilityGroupingId}/facility/${facilityId}`\n )\n .then((groupingFacility) => toCamelCase(groupingFacility));\n }\n\n /**\n * Creates a new facility grouping\n *\n * API Endpoint: '/groupings'\n * Method: POST\n *\n * @param {Object} facilityGrouping\n * @param {string} [facilityGrouping.description]\n * @param {boolean} [facilityGrouping.isPrivate = false]\n * @param {string} facilityGrouping.name\n * @param {string} facilityGrouping.organizationId UUID\n * @param {string} [facilityGrouping.parentGroupingId] UUID\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping} Information about the new facility grouping\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .create({\n * description: 'US States of CT, MA, ME, NH, RI, VT',\n * isPrivate: false,\n * name: 'New England, USA',\n * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5',\n * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'\n * })\n * .then((grouping) => console.log(grouping))\n * .catch((err) => console.log(err));\n */\n create(grouping = {}) {\n const requiredFields = ['name', 'organizationId'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!grouping[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new facility grouping.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/groupings`, toSnakeCase(grouping))\n .then((grouping) => toCamelCase(grouping));\n }\n\n /**\n * Delete a facility groupings\n *\n * API Endpoint: '/groupings/:facilityGroupingId'\n * Method: DELETE\n *\n * @param {string} facilityGroupingId The id of the facility grouping (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings.delete(\n * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'\n * );\n */\n delete(facilityGroupingId) {\n if (!facilityGroupingId) {\n return Promise.reject(\n new Error(\n 'A facility grouping id is required for deleting a facility grouping.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/groupings/${facilityGroupingId}`\n );\n }\n\n /**\n * Get a listing of all facility groupings available to a user. Includes public groupings across\n * any organization the user has access to and the user's private groupings.\n *\n * API Endpoint: '/groupings'\n * Method: GET\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilites.groupings\n * .getAll()\n * .then((groupings) => console.log(groupings))\n * .catch((err) => console.log(err));\n */\n getAll() {\n return this._request\n .get(`${this._baseUrl}/groupings`)\n .then((groupings) => toCamelCase(groupings));\n }\n\n /**\n * Get a listing of all facility groupings for an organization. Includes public groupings\n * across that specific organization and the user's private groupings for that organization.\n *\n * API Endpoint: '/organizations/:organizationId/groupings'\n * Method: GET\n *\n * @param {string} organizationId UUID corresponding with an organization\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilites.groupings\n * .getAllByOrganizationId('349dbd36-5dca-4a10-b54d-d0f71c3c8709')\n * .then((groupings) => console.log(groupings))\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 facility groupings\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/groupings`)\n .then((groupings) => toCamelCase(groupings));\n }\n\n /**\n * Removes a facility from a facility grouping\n *\n * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'\n * Method: DELETE\n *\n * @param {string} facilityGroupingId UUID corresponding with a facility grouping\n * @param {number} facilityId\n *\n * @returns {Promise}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .catch((err) => console.log(err));\n */\n removeFacility(facilityGroupingId, facilityId) {\n let errorMsg;\n\n if (!facilityGroupingId) {\n errorMsg =\n 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to remove a relationship between a facility grouping 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}/groupings/${facilityGroupingId}/facility/${facilityId}`\n );\n }\n\n /**\n * Updates an existing facility grouping\n *\n * API Endpoint: '/groupings/:facilityGroupingId'\n * Method: PUT\n *\n * @param {String} facilityGroupingId\n * @param {Object} update\n * @param {string} [update.description]\n * @param {boolean} [update.isPrivate]\n * @param {string} [update.name]\n * @param {string} [update.parentGroupingId] UUID corresponding with another facility grouping\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping} Information about the updated facility grouping\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .update('b3dbaae3-25dd-475b-80dc-66296630a8d0', {\n * description: 'US States of CT, MA, ME, NH, RI, VT',\n * isPrivate: false,\n * name: 'New England, USA',\n * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'\n * })\n * .then((grouping) => console.log(grouping))\n * .catch((err) => console.log(err));\n */\n update(facilityGroupingId, update) {\n if (!facilityGroupingId) {\n return Promise.reject(\n new Error(\n 'A facility grouping id is required to update a facility grouping.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a facility grouping')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The facility grouping 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', 'ownerId']\n });\n\n return this._request\n .put(`${this._baseUrl}/groupings/${facilityGroupingId}`, formattedUpdate)\n .then((grouping) => toCamelCase(grouping));\n }\n}\n\nexport default FacilityGroupings;\n"]}