@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,343 +0,0 @@
1
- import isPlainObject from 'lodash.isplainobject';
2
- import FacilityGroupings from './groupings';
3
- import CostCenters from './costCenters';
4
- import { formatFacilityWithInfoFromServer } from '../utils/facilities';
5
- import { toCamelCase, toSnakeCase } from '../utils/objects';
6
-
7
- /**
8
- * @typedef {Object} Facility
9
- * @property {string} [address1]
10
- * @property {string} [address2]
11
- * @property {string} [assetId] UUID corresponding with an asset
12
- * @property {string} [city]
13
- * @property {string} createdAt ISO 8601 Extended Format date/time string
14
- * @property {string} [geometryId] UUID corresponding with a geometry
15
- * @property {number} id
16
- * @property {Object} [Info] User declared information
17
- * @property {string} name
18
- * @property {Object} [Organization]
19
- * @property {string} [Organization.createdAt] ISO 8601 Extended Format date/time string
20
- * @property {string} [Organization.id] UUID formatted ID
21
- * @property {string} [Organization.name]
22
- * @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string
23
- * @property {string} [state]
24
- * @property {Object[]} [tags]
25
- * @property {string} [tags[].createdAt] ISO 8601 Extended Format date/time string
26
- * @property {number} [tags[].id]
27
- * @property {number} [tags[].facilityId]
28
- * @property {string} [tags[].name]
29
- * @property {string} [tags[].updatedAt] ISO 8601 Extended Format date/time string
30
- * @property {string} timezone An IANA Time Zone Database string, i.e. America/Los_Angeles
31
- * @property {number} [weatherLocationId]
32
- * @property {string} [zip] US Zip Code
33
- */
34
-
35
- /**
36
- * Module that provides access to, and the manipulation
37
- * of, information about different facilities
38
- *
39
- * @typicalname contxtSdk.facilities
40
- */
41
- class Facilities {
42
- /**
43
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules
44
- * @param {Object} request An instance of the request module tied to this module's audience.
45
- */
46
- constructor(sdk, request) {
47
- const baseUrl = `${sdk.config.audiences.facilities.host}/v1`;
48
-
49
- this._baseUrl = baseUrl;
50
- this._request = request;
51
- this._sdk = sdk;
52
-
53
- this.groupings = new FacilityGroupings(sdk, request, baseUrl);
54
- this.costCenters = new CostCenters(sdk, request, baseUrl);
55
- }
56
-
57
- /**
58
- * Creates a new facility
59
- *
60
- * API Endpoint: '/facilities'
61
- * Method: POST
62
- *
63
- * @param {Object} facility
64
- * @param {string} [facility.address1]
65
- * @param {string} [facility.address2]
66
- * @param {string} [facility.assetId] UUID corresponding with an asset
67
- * @param {string} [facility.city]
68
- * @param {string} [facility.geometryId] UUID corresponding with a geometry
69
- * @param {string} facility.name
70
- * @param {string} facility.organizationId UUID corresponding with an organization
71
- * @param {string} [facility.state]
72
- * @param {string} facility.timezone
73
- * @param {number} [facility.weatherLocationId]
74
- * @param {string} [facility.zip]
75
- *
76
- * @returns {Promise}
77
- * @fulfill {Facility} Information about the new facility
78
- * @reject {Error}
79
- *
80
- * @example
81
- * contxtSdk.facilities
82
- * .create({
83
- * address: '221 B Baker St, London, England',
84
- * name: 'Sherlock Holmes Museum',
85
- * organizationId: 25
86
- * })
87
- * .then((facilities) => console.log(facilities))
88
- * .catch((err) => console.log(err));
89
- */
90
- create(facility = {}) {
91
- const requiredFields = ['organizationId', 'name', 'timezone'];
92
-
93
- for (let i = 0; i < requiredFields.length; i++) {
94
- const field = requiredFields[i];
95
-
96
- if (!facility[field]) {
97
- return Promise.reject(
98
- new Error(`A ${field} is required to create a new facility.`)
99
- );
100
- }
101
- }
102
-
103
- return this._request
104
- .post(`${this._baseUrl}/facilities`, toSnakeCase(facility))
105
- .then((facility) => toCamelCase(facility));
106
- }
107
-
108
- /**
109
- * Creates or updates a facility's info (NOTE: This refers to the facility_info model)
110
- *
111
- * API Endpoint: '/facilities/:facilityId/info?should_update=true'
112
- * Method: POST
113
- *
114
- * @param {number} facilityId The ID of the facility to update
115
- * @param {Object} update An object containing the facility info for the facility
116
- *
117
- * @returns {Promise}
118
- * @fulfill {undefined}
119
- * @reject {Error}
120
- *
121
- * @example
122
- * contxtSdk.facilities.createOrUpdateInfo(25, {
123
- * square_feet: '10000'
124
- * });
125
- */
126
- createOrUpdateInfo(facilityId, update) {
127
- if (!facilityId) {
128
- return Promise.reject(
129
- new Error("A facility ID is required to update a facility's info.")
130
- );
131
- }
132
-
133
- if (!update) {
134
- return Promise.reject(
135
- new Error("An update is required to update a facility's info.")
136
- );
137
- }
138
-
139
- if (!isPlainObject(update)) {
140
- return Promise.reject(
141
- new Error(
142
- 'The facility info update must be a well-formed object with the data you wish to update.'
143
- )
144
- );
145
- }
146
-
147
- const options = {
148
- params: {
149
- should_update: true
150
- }
151
- };
152
-
153
- return this._request.post(
154
- `${this._baseUrl}/facilities/${facilityId}/info`,
155
- update,
156
- options
157
- );
158
- }
159
-
160
- /**
161
- * Deletes a facility
162
- *
163
- * API Endpoint: '/facilities/:facilityId'
164
- * Method: DELETE
165
- *
166
- * @param {number} facilityId The ID of the facility
167
- *
168
- * @returns {Promise}
169
- * @fulfill {undefined}
170
- * @reject {Error}
171
- *
172
- * @example
173
- * contxtSdk.facilities.delete(25);
174
- */
175
- delete(facilityId) {
176
- if (!facilityId) {
177
- return Promise.reject(
178
- new Error('A facility ID is required for deleting a facility')
179
- );
180
- }
181
-
182
- return this._request.delete(`${this._baseUrl}/facilities/${facilityId}`);
183
- }
184
-
185
- /**
186
- * Gets information about a facility
187
- *
188
- * API Endpoint: '/facilities/:facilityId'
189
- * Method: GET
190
- *
191
- * @param {number} facilityId The ID of the facility
192
- *
193
- * @returns {Promise}
194
- * @fulfill {Facility} Information about a facility
195
- * @reject {Error}
196
- *
197
- * @example
198
- * contxtSdk.facilities
199
- * .get(25)
200
- * .then((facility) => console.log(facility))
201
- * .catch((err) => console.log(err));
202
- */
203
- get(facilityId) {
204
- if (!facilityId) {
205
- return Promise.reject(
206
- new Error(
207
- 'A facility ID is required for getting information about a facility'
208
- )
209
- );
210
- }
211
-
212
- return this._request
213
- .get(`${this._baseUrl}/facilities/${facilityId}`)
214
- .then((facility) => formatFacilityWithInfoFromServer(facility));
215
- }
216
-
217
- /**
218
- * Gets a list of all facilities
219
- *
220
- * API Endpoint: '/facilities'
221
- * Method: GET
222
- *
223
- * @returns {Promise}
224
- * @fulfill {Facility[]} Information about all facilities
225
- * @reject {Error}
226
- *
227
- * @example
228
- * contxtSdk.facilities
229
- * .getAll()
230
- * .then((facilities) => console.log(facilities))
231
- * .catch((err) => console.log(err));
232
- */
233
- getAll() {
234
- return this._request
235
- .get(`${this._baseUrl}/facilities`)
236
- .then((facilities) =>
237
- facilities.map((facility) => formatFacilityWithInfoFromServer(facility))
238
- );
239
- }
240
-
241
- /**
242
- * Gets a list of all facilities that belong to a particular organization
243
- *
244
- * API Endpoint: '/organizations/:organizationId/facilities'
245
- * Method: GET
246
- *
247
- * @param {string} organizationId UUID corresponding with an organization
248
- * @param {object} [options] Object containing parameters to be called with the request
249
- * @param {boolean} [options.includeGroupings] Boolean flag for including groupings data with each facility
250
- *
251
- * @returns {Promise}
252
- * @fulfill {Facility[]} Information about all facilities
253
- * @reject {Error}
254
- *
255
- * @example
256
- * contxtSdk.facilities
257
- * .getAllByOrganizationId(25, { includeGroupings: true })
258
- * .then((facilities) => console.log(facilities))
259
- * .catch((err) => console.log(err));
260
- */
261
- getAllByOrganizationId(organizationId, options) {
262
- if (!organizationId) {
263
- return Promise.reject(
264
- new Error(
265
- "An organization ID is required for getting a list of an organization's facilities"
266
- )
267
- );
268
- }
269
-
270
- return this._request
271
- .get(`${this._baseUrl}/organizations/${organizationId}/facilities`, {
272
- params: toSnakeCase(options)
273
- })
274
- .then((facilities) =>
275
- facilities.map((facility) => formatFacilityWithInfoFromServer(facility))
276
- );
277
- }
278
-
279
- /**
280
- * Updates a facility's specifics
281
- *
282
- * API Endpoint: '/facilities/:facilityId'
283
- * Method: PUT
284
- *
285
- * @param {number} facilityId The ID of the facility to update
286
- * @param {Object} update An object containing the updated data for the facility
287
- * @param {string} [update.address1]
288
- * @param {string} [update.address2]
289
- * @param {string} [update.assetId] UUID corresponding with an asset
290
- * @param {string} [update.city]
291
- * @param {string} [update.geometryId] UUID corresponding with a geometry
292
- * @param {Object} [update.info] User declared information
293
- * @param {string} [update.name]
294
- * @param {string} [update.organizationId] UUID corresponding with an organization
295
- * @param {string} [update.state]
296
- * @param {string} [update.timezone]
297
- * @param {number} [update.weatherLocationId]
298
- * @param {string} [update.zip]
299
- *
300
- * @returns {Promise}
301
- * @fulfill {undefined}
302
- * @reject {Error}
303
- *
304
- * @example
305
- * contxtSdk.facilities.update(25, {
306
- * address: '221 B Baker St, London, England',
307
- * name: 'Sherlock Homes Museum',
308
- * organizationId: 25
309
- * });
310
- */
311
- update(facilityId, update) {
312
- if (!facilityId) {
313
- return Promise.reject(
314
- new Error('A facility ID is required to update a facility.')
315
- );
316
- }
317
-
318
- if (!update) {
319
- return Promise.reject(
320
- new Error('An update is required to update a facility.')
321
- );
322
- }
323
-
324
- if (!isPlainObject(update)) {
325
- return Promise.reject(
326
- new Error(
327
- 'The facility update must be a well-formed object with the data you wish to update.'
328
- )
329
- );
330
- }
331
-
332
- const formattedUpdate = toSnakeCase(update, {
333
- excludeKeys: ['id', 'organizationId']
334
- });
335
-
336
- return this._request.put(
337
- `${this._baseUrl}/facilities/${facilityId}`,
338
- formattedUpdate
339
- );
340
- }
341
- }
342
-
343
- export default Facilities;