@ndustrial/contxt-sdk 4.3.6 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +8 -0
  3. package/docs/Facilities.md +0 -144
  4. package/docs/FacilityGroupings.md +0 -160
  5. package/docs/Nionic.md +63 -0
  6. package/docs/README.md +3 -29
  7. package/docs/Typedefs.md +0 -101
  8. package/esm/config/audiences.js +13 -13
  9. package/esm/config/audiences.js.map +1 -1
  10. package/esm/index.js +3 -6
  11. package/esm/index.js.map +1 -1
  12. package/esm/nionic/index.js +126 -0
  13. package/esm/nionic/index.js.map +1 -0
  14. package/lib/config/audiences.js +13 -13
  15. package/lib/config/audiences.js.map +1 -1
  16. package/lib/index.js +19 -13
  17. package/lib/index.js.map +1 -1
  18. package/lib/nionic/index.js +130 -0
  19. package/lib/nionic/index.js.map +1 -0
  20. package/meta.yaml +11 -0
  21. package/package.json +9 -10
  22. package/src/bus/index.spec.js +3 -2
  23. package/src/bus/webSocketConnection.spec.js +31 -31
  24. package/src/config/audiences.js +13 -13
  25. package/src/config/index.spec.js +6 -6
  26. package/src/coordinator/applications.spec.js +8 -8
  27. package/src/coordinator/consent.spec.js +1 -1
  28. package/src/coordinator/edgeNodes.spec.js +3 -3
  29. package/src/coordinator/organizations.spec.js +4 -4
  30. package/src/coordinator/permissions.spec.js +4 -4
  31. package/src/coordinator/roles.spec.js +3 -3
  32. package/src/coordinator/users.spec.js +14 -15
  33. package/src/events/index.spec.js +16 -16
  34. package/src/files/index.spec.js +7 -7
  35. package/src/index.js +3 -6
  36. package/src/index.spec.js +8 -22
  37. package/src/iot/feeds.spec.js +4 -4
  38. package/src/iot/fieldCategories.spec.js +4 -4
  39. package/src/iot/fieldGroupings.spec.js +5 -5
  40. package/src/iot/outputs.spec.js +6 -6
  41. package/src/nionic/index.js +151 -0
  42. package/src/request.spec.js +3 -3
  43. package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
  44. package/src/sessionTypes/index.spec.js +3 -3
  45. package/src/sessionTypes/machineAuth.spec.js +3 -3
  46. package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
  47. package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
  48. package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
  49. package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
  50. package/src/utils/url/stringifyParams.spec.js +2 -3
  51. package/support/fixtures/factories/IOSDevice.js +3 -3
  52. package/support/fixtures/factories/applicationGrouping.js +4 -4
  53. package/support/fixtures/factories/applicationModule.js +2 -2
  54. package/support/fixtures/factories/asset.js +1 -1
  55. package/support/fixtures/factories/assetAttribute.js +2 -2
  56. package/support/fixtures/factories/assetAttributeValue.js +2 -2
  57. package/support/fixtures/factories/assetMetric.js +1 -1
  58. package/support/fixtures/factories/assetMetricValue.js +3 -3
  59. package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
  60. package/support/fixtures/factories/assetType.js +1 -1
  61. package/support/fixtures/factories/authResults.js +3 -3
  62. package/support/fixtures/factories/channel.js +1 -1
  63. package/support/fixtures/factories/contxtApplication.js +5 -5
  64. package/support/fixtures/factories/contxtOrganization.js +2 -2
  65. package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
  66. package/support/fixtures/factories/contxtProject.js +2 -2
  67. package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
  68. package/support/fixtures/factories/contxtRole.js +3 -3
  69. package/support/fixtures/factories/contxtRoleApplication.js +1 -1
  70. package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
  71. package/support/fixtures/factories/contxtUser.js +2 -2
  72. package/support/fixtures/factories/contxtUserApplication.js +1 -1
  73. package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
  74. package/support/fixtures/factories/contxtUserPermissions.js +5 -5
  75. package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
  76. package/support/fixtures/factories/contxtUserRole.js +2 -2
  77. package/support/fixtures/factories/costCenter.js +2 -2
  78. package/support/fixtures/factories/costCenterFacility.js +3 -3
  79. package/support/fixtures/factories/edgeNode.js +1 -1
  80. package/support/fixtures/factories/event.js +5 -5
  81. package/support/fixtures/factories/eventType.js +4 -4
  82. package/support/fixtures/factories/eventUser.js +5 -5
  83. package/support/fixtures/factories/facility.js +4 -4
  84. package/support/fixtures/factories/facilityGrouping.js +3 -3
  85. package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
  86. package/support/fixtures/factories/facilityInfo.js +2 -2
  87. package/support/fixtures/factories/facilityTag.js +1 -1
  88. package/support/fixtures/factories/feedStatus.js +1 -1
  89. package/support/fixtures/factories/feedType.js +1 -1
  90. package/support/fixtures/factories/feeds.js +5 -5
  91. package/support/fixtures/factories/fieldCategory.js +3 -3
  92. package/support/fixtures/factories/fieldGrouping.js +4 -4
  93. package/support/fixtures/factories/fieldGroupingField.js +3 -3
  94. package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
  95. package/support/fixtures/factories/file.js +1 -1
  96. package/support/fixtures/factories/fileUploadInfo.js +1 -1
  97. package/support/fixtures/factories/organization.js +1 -1
  98. package/support/fixtures/factories/outputField.js +10 -10
  99. package/support/fixtures/factories/outputFieldData.js +1 -1
  100. package/support/fixtures/factories/owner.js +2 -2
  101. package/support/fixtures/factories/paginationMetadata.js +2 -2
  102. package/support/fixtures/factories/triggeredEvent.js +4 -4
  103. package/support/fixtures/factories/userEventSubscription.js +1 -1
  104. package/support/fixtures/factories/userMobileNumber.js +1 -1
  105. package/support/fixtures/factories/userPermissionsMap.js +2 -2
  106. package/.huskyrc.js +0 -11
  107. package/.nycrc +0 -12
  108. package/esm/assets/assetAttributes.js +0 -574
  109. package/esm/assets/assetAttributes.js.map +0 -1
  110. package/esm/assets/assetMetrics.js +0 -690
  111. package/esm/assets/assetMetrics.js.map +0 -1
  112. package/esm/assets/assetTypes.js +0 -273
  113. package/esm/assets/assetTypes.js.map +0 -1
  114. package/esm/assets/index.js +0 -283
  115. package/esm/assets/index.js.map +0 -1
  116. package/esm/facilities/costCenters.js +0 -306
  117. package/esm/facilities/costCenters.js.map +0 -1
  118. package/esm/facilities/groupings.js +0 -323
  119. package/esm/facilities/groupings.js.map +0 -1
  120. package/esm/facilities/index.js +0 -343
  121. package/esm/facilities/index.js.map +0 -1
  122. package/esm/health/index.js +0 -229
  123. package/esm/health/index.js.map +0 -1
  124. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  125. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  126. package/esm/utils/facilities/index.js +0 -4
  127. package/esm/utils/facilities/index.js.map +0 -1
  128. package/lib/assets/assetAttributes.js +0 -588
  129. package/lib/assets/assetAttributes.js.map +0 -1
  130. package/lib/assets/assetMetrics.js +0 -705
  131. package/lib/assets/assetMetrics.js.map +0 -1
  132. package/lib/assets/assetTypes.js +0 -287
  133. package/lib/assets/assetTypes.js.map +0 -1
  134. package/lib/assets/index.js +0 -302
  135. package/lib/assets/index.js.map +0 -1
  136. package/lib/facilities/costCenters.js +0 -316
  137. package/lib/facilities/costCenters.js.map +0 -1
  138. package/lib/facilities/groupings.js +0 -333
  139. package/lib/facilities/groupings.js.map +0 -1
  140. package/lib/facilities/index.js +0 -360
  141. package/lib/facilities/index.js.map +0 -1
  142. package/lib/health/index.js +0 -232
  143. package/lib/health/index.js.map +0 -1
  144. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  145. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  146. package/lib/utils/facilities/index.js +0 -15
  147. package/lib/utils/facilities/index.js.map +0 -1
  148. package/src/assets/assetAttributes.js +0 -619
  149. package/src/assets/assetAttributes.spec.js +0 -1143
  150. package/src/assets/assetMetrics.js +0 -736
  151. package/src/assets/assetMetrics.spec.js +0 -1180
  152. package/src/assets/assetTypes.js +0 -260
  153. package/src/assets/assetTypes.spec.js +0 -556
  154. package/src/assets/index.js +0 -271
  155. package/src/assets/index.spec.js +0 -515
  156. package/src/facilities/costCenters.js +0 -295
  157. package/src/facilities/costCenters.spec.js +0 -529
  158. package/src/facilities/groupings.js +0 -320
  159. package/src/facilities/groupings.spec.js +0 -567
  160. package/src/facilities/index.js +0 -343
  161. package/src/facilities/index.spec.js +0 -551
  162. package/src/health/index.js +0 -200
  163. package/src/health/index.spec.js +0 -501
  164. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  165. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  166. package/src/utils/facilities/index.js +0 -3
@@ -1,271 +0,0 @@
1
- import isPlainObject from 'lodash.isplainobject';
2
- import AssetAttributes from './assetAttributes';
3
- import AssetMetrics from './assetMetrics';
4
- import AssetTypes from './assetTypes';
5
-
6
- import { toCamelCase, toSnakeCase } from '../utils/objects';
7
- import { formatPaginatedDataFromServer } from '../utils/pagination';
8
-
9
- /**
10
- * @typedef {Object} Asset
11
- * @property {string} assetTypeId UUID corresponding with the asset type
12
- * @property {string} createdAt ISO 8601 Extended Format date/time string
13
- * @property {string} [description]
14
- * @property {string} id UUID
15
- * @property {string} label
16
- * @property {string} organizationId UUID corresponding with the organization
17
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
18
- */
19
-
20
- /**
21
- * @typedef {Object} AssetsFromServer
22
- * @property {Object} _metadata Metadata about the pagination settings
23
- * @property {number} _metadata.offset Offset of records in subsequent queries
24
- * @property {number} _metadata.totalRecords Total number of asset types found
25
- * @property {Asset[]} records
26
- */
27
-
28
- /**
29
- * Module that provides access to, and the manipulation of, information about different assets
30
- *
31
- * @typicalname contxtSdk.assets
32
- */
33
- class Assets {
34
- /**
35
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
36
- * @param {Object} request An instance of the request module tied to this module's audience.
37
- */
38
- constructor(sdk, request) {
39
- const baseUrl = `${sdk.config.audiences.facilities.host}/v1`;
40
-
41
- this._baseUrl = baseUrl;
42
- this._request = request;
43
- this._sdk = sdk;
44
-
45
- this.attributes = new AssetAttributes(sdk, request, baseUrl);
46
- this.types = new AssetTypes(sdk, request, baseUrl);
47
- this.metrics = new AssetMetrics(sdk, request, baseUrl);
48
- }
49
-
50
- /**
51
- * Creates a new asset
52
- *
53
- * API Endpoint: '/assets'
54
- * Method: POST
55
- *
56
- * @param {Object} asset
57
- * @param {string} asset.assetTypeId UUID
58
- * @param {string} [asset.description]
59
- * @param {string} asset.label
60
- * @param {string} asset.organizationId UUID
61
- *
62
- * @returns {Promise}
63
- * @fulfill {Asset} information about the new asset
64
- * @reject {Error}
65
- *
66
- * @example
67
- * contxtSdk.assets
68
- * .create({
69
- * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d',
70
- * description: '221B Baker Street, London',
71
- * label: 'Sherlock Homes Museum',
72
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'
73
- * })
74
- * .then((asset) => console.log(asset))
75
- * .catch((err) => console.log(err));
76
- */
77
- create(asset = {}) {
78
- const requiredFields = ['assetTypeId', 'label', 'organizationId'];
79
-
80
- for (let i = 0; i < requiredFields.length; i++) {
81
- const field = requiredFields[i];
82
-
83
- if (!asset[field]) {
84
- return Promise.reject(
85
- new Error(`A ${field} is required to create a new asset.`)
86
- );
87
- }
88
- }
89
-
90
- return this._request
91
- .post(`${this._baseUrl}/assets`, toSnakeCase(asset))
92
- .then((asset) => toCamelCase(asset));
93
- }
94
-
95
- /**
96
- * Deletes an asset
97
- *
98
- * API Endpoint: '/assets/:assetId'
99
- * Method: DELETE
100
- *
101
- * @param {string} assetId The ID of the asset (formatted as a UUID)
102
- *
103
- * @returns {Promise}
104
- * @fulfill {undefined}
105
- * @reject {Error}
106
- *
107
- * @example
108
- * contxtSdk.assets.delete('0b51429f-91a0-48ba-b144-fd2db697000e');
109
- */
110
- delete(assetId) {
111
- if (!assetId) {
112
- return Promise.reject(
113
- new Error('An asset ID is required for deleting an asset.')
114
- );
115
- }
116
-
117
- return this._request.delete(`${this._baseUrl}/assets/${assetId}`);
118
- }
119
-
120
- /**
121
- * Gets information about an asset
122
- *
123
- * API Endpoint: '/assets/:assetId'
124
- * Method: GET
125
- *
126
- * @param {string} assetId The ID of the asset (formatted as a UUID)
127
- *
128
- * @returns {Promise}
129
- * @fulfill {Asset} Information about the asset
130
- * @reject {Error}
131
- *
132
- * @example
133
- * contxtSdk.assets
134
- * .get('0b51429f-91a0-48ba-b144-fd2db697000e')
135
- * .then((asset) => console.log(asset))
136
- * .catch((err) => console.log(err));
137
- */
138
- get(assetId) {
139
- if (!assetId) {
140
- return Promise.reject(
141
- new Error(
142
- 'An asset ID is required for getting information about an asset.'
143
- )
144
- );
145
- }
146
-
147
- return this._request
148
- .get(`${this._baseUrl}/assets/${assetId}`)
149
- .then((asset) => toCamelCase(asset));
150
- }
151
-
152
- /**
153
- * Get a list of all assets
154
- *
155
- * API Endpoint: '/assets'
156
- * Method: GET
157
- *
158
- * @param {PaginationOptions} [paginationOptions]
159
- *
160
- * @returns {Promise}
161
- * @fulfill {AssetsFromServer}
162
- * @reject {Error}
163
- *
164
- * @example
165
- * contxtSdk.assets
166
- * .getAll()
167
- * .then((assets) => console.log(assets))
168
- * .catch((err) => console.log(err));
169
- */
170
- getAll(paginationOptions) {
171
- return this._request
172
- .get(`${this._baseUrl}/assets`, {
173
- params: toSnakeCase(paginationOptions)
174
- })
175
- .then((assetsData) => formatPaginatedDataFromServer(assetsData));
176
- }
177
-
178
- /**
179
- * Get a list of all assets that belong to a particular organization
180
- *
181
- * API Endpoint: '/organizations/:organizationId/assets'
182
- * Method: GET
183
- *
184
- * @param {string} organizationId UUID corresponding with an organization
185
- * @param {Object} [options] Object containing parameters to be called with the request
186
- * @param {string} [options.assetTypeId] UUID of the asset type to use for filtering
187
- * @param {Number} [options.limit] Maximum number of records to return per query
188
- * @param {Number} [options.offset] How many records from the first record to start
189
- * @param {boolean} [options.includeTypeDescendents] When true will look for all asset types that are descendendents from options.assetTypeId
190
- * @param {string} [options.includeMetricId] If asset has an associated metric value the latest metric will be returned.
191
- *
192
- * @returns {Promise}
193
- * @fulfill {AssetsFromServer}
194
- * @reject {Error}
195
- *
196
- * @example
197
- * contxtSdk.assets
198
- * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c', {
199
- * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d'
200
- * })
201
- * .then((assets) => console.log(assets))
202
- * .catch((err) => console.log(err));
203
- */
204
- getAllByOrganizationId(organizationId, options) {
205
- if (!organizationId) {
206
- return Promise.reject(
207
- new Error(
208
- "An organization ID is required for getting a list of an organization's assets."
209
- )
210
- );
211
- }
212
-
213
- const params = toSnakeCase(options);
214
-
215
- return this._request
216
- .get(`${this._baseUrl}/organizations/${organizationId}/assets`, {
217
- params
218
- })
219
- .then((assetsData) => formatPaginatedDataFromServer(assetsData));
220
- }
221
-
222
- /**
223
- * Updates an asset's data
224
- *
225
- * API Endpoint: '/assets/:assetId'
226
- * Method: PUT
227
- *
228
- * @param {string} assetId The ID of the asset to update (formatted as a UUID)
229
- * @param {Object} update An object containing the updated data for the asset
230
- * @param {string} update.description
231
- *
232
- * @example
233
- * contxtSdk.assets
234
- * .update({
235
- * description: 'A new description'
236
- * })
237
- * .then((asset) => console.log(asset))
238
- * .catch((err) => console.log(err));
239
- */
240
- update(assetId, update) {
241
- if (!assetId) {
242
- return Promise.reject(
243
- new Error('An asset ID is required to update an asset.')
244
- );
245
- }
246
-
247
- if (!update) {
248
- return Promise.reject(
249
- new Error('An update is required to update an asset.')
250
- );
251
- }
252
-
253
- if (!isPlainObject(update)) {
254
- return Promise.reject(
255
- new Error(
256
- 'The asset update must be a well-formed object with the data you wish to update.'
257
- )
258
- );
259
- }
260
-
261
- const formattedUpdate = toSnakeCase(update, {
262
- excludeKeys: ['assetTypeId', 'id', 'label', 'organizationId']
263
- });
264
-
265
- return this._request
266
- .put(`${this._baseUrl}/assets/${assetId}`, formattedUpdate)
267
- .then((asset) => toCamelCase(asset));
268
- }
269
- }
270
-
271
- export default Assets;