@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,65 +0,0 @@
1
- import { toCamelCase } from '../objects';
2
-
3
- /**
4
- * Normalizes the facility object returned from the API server
5
- *
6
- * @param {Object} input
7
- * @param {string} input.address1
8
- * @param {string} input.address2
9
- * @param {string} [input.asset_id] UUID corresponding with an asset
10
- * @param {string} input.city
11
- * @param {Object[]} [input.cost_centers]
12
- * @param {string} [input.cost_centers[].created_at] ISO 8601 Extended Format date/time string
13
- * @param {string} [input.cost_centers[].description]
14
- * @param {string} [input.cost_centers[].id]
15
- * @param {string} [input.cost_centers[].name]
16
- * @param {string} [input.cost_centers[].organization_id] UUID corresponding with an organization
17
- * @param {string} [input.cost_centers[].updated_at] ISO 8601 Extended Format date/time string
18
- * @param {string} input.created_at ISO 8601 Extended Format date/time string
19
- * @param {Object[]}[input.facility_groupings]
20
- * @param {string} [input.facility_groupings[].created_at] ISO 8601 Extended Format date/time string
21
- * @param {number} [input.facility_groupings[].facility_id] ID corresponding with the parent facility
22
- * @param {number} [input.facility_groupings[].id]
23
- * @param {string} [input.facility_groupings[].name]
24
- * @param {string} [input.facility_groupings[].updated_at] ISO 8601 Extended Format date/time string
25
- * @param {string} [input.geometry_id] UUID corresponding with a geometry
26
- * @param {number} input.id
27
- * @param {Object} [input.Info] User declared information
28
- * @param {string} input.name
29
- * @param {Object} [input.Organization]
30
- * @param {string} [input.Organization.created_at] ISO 8601 Extended Format date/time string
31
- * @param {string} [input.Organization.id] UUID
32
- * @param {string} [input.Organization.name]
33
- * @param {string} [input.Organization.updated_at]
34
- * @param {string} input.organization_id UUID corresponding with an organization
35
- * @param {string} [input.state]
36
- * @param {Object[]} [input.tags]
37
- * @param {string} [input.tags[].created_at] ISO 8601 Extended Format date/time string
38
- * @param {number} [input.tags[].facility_id] ID corresponding with the parent facility
39
- * @param {number} [input.tags[].id]
40
- * @param {string} [input.tags[].name]
41
- * @param {string} [input.tags[].updated_at] ISO 8601 Extended Format date/time string
42
- * @param {string} input.timezone An IANA Time Zone Database string, i.e. America/Los_Angeles
43
- * @param {string} [input.weather_location_id]
44
- * @param {string} [input.zip]
45
- *
46
- * @returns {Facility}
47
- *
48
- * @private
49
- */
50
- function formatFacilityWithInfoFromServer() {
51
- var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
52
-
53
- var formattedFacility = toCamelCase(input, {
54
- excludeKeys: ['Info']
55
- });
56
-
57
- if (input.Info) {
58
- formattedFacility.info = input.Info;
59
- }
60
-
61
- return formattedFacility;
62
- }
63
-
64
- export default formatFacilityWithInfoFromServer;
65
- //# sourceMappingURL=formatFacilityWithInfoFromServer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["utils/facilities/formatFacilityWithInfoFromServer.js"],"names":["toCamelCase","formatFacilityWithInfoFromServer","input","formattedFacility","excludeKeys","Info","info"],"mappings":"AAAA,SAASA,WAAT,QAA4B,YAA5B;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAASC,gCAAT,GAAsD;AAAA,MAAZC,KAAY,uEAAJ,EAAI;;AACpD,MAAMC,oBAAoBH,YAAYE,KAAZ,EAAmB;AAC3CE,iBAAa,CAAC,MAAD;AAD8B,GAAnB,CAA1B;;AAIA,MAAIF,MAAMG,IAAV,EAAgB;AACdF,sBAAkBG,IAAlB,GAAyBJ,MAAMG,IAA/B;AACD;;AAED,SAAOF,iBAAP;AACD;;AAED,eAAeF,gCAAf","file":"formatFacilityWithInfoFromServer.js","sourcesContent":["import { toCamelCase } from '../objects';\n\n/**\n * Normalizes the facility object returned from the API server\n *\n * @param {Object} input\n * @param {string} input.address1\n * @param {string} input.address2\n * @param {string} [input.asset_id] UUID corresponding with an asset\n * @param {string} input.city\n * @param {Object[]} [input.cost_centers]\n * @param {string} [input.cost_centers[].created_at] ISO 8601 Extended Format date/time string\n * @param {string} [input.cost_centers[].description]\n * @param {string} [input.cost_centers[].id]\n * @param {string} [input.cost_centers[].name]\n * @param {string} [input.cost_centers[].organization_id] UUID corresponding with an organization\n * @param {string} [input.cost_centers[].updated_at] ISO 8601 Extended Format date/time string\n * @param {string} input.created_at ISO 8601 Extended Format date/time string\n * @param {Object[]}[input.facility_groupings]\n * @param {string} [input.facility_groupings[].created_at] ISO 8601 Extended Format date/time string\n * @param {number} [input.facility_groupings[].facility_id] ID corresponding with the parent facility\n * @param {number} [input.facility_groupings[].id]\n * @param {string} [input.facility_groupings[].name]\n * @param {string} [input.facility_groupings[].updated_at] ISO 8601 Extended Format date/time string\n * @param {string} [input.geometry_id] UUID corresponding with a geometry\n * @param {number} input.id\n * @param {Object} [input.Info] User declared information\n * @param {string} input.name\n * @param {Object} [input.Organization]\n * @param {string} [input.Organization.created_at] ISO 8601 Extended Format date/time string\n * @param {string} [input.Organization.id] UUID\n * @param {string} [input.Organization.name]\n * @param {string} [input.Organization.updated_at]\n * @param {string} input.organization_id UUID corresponding with an organization\n * @param {string} [input.state]\n * @param {Object[]} [input.tags]\n * @param {string} [input.tags[].created_at] ISO 8601 Extended Format date/time string\n * @param {number} [input.tags[].facility_id] ID corresponding with the parent facility\n * @param {number} [input.tags[].id]\n * @param {string} [input.tags[].name]\n * @param {string} [input.tags[].updated_at] ISO 8601 Extended Format date/time string\n * @param {string} input.timezone An IANA Time Zone Database string, i.e. America/Los_Angeles\n * @param {string} [input.weather_location_id]\n * @param {string} [input.zip]\n *\n * @returns {Facility}\n *\n * @private\n */\nfunction formatFacilityWithInfoFromServer(input = {}) {\n const formattedFacility = toCamelCase(input, {\n excludeKeys: ['Info']\n });\n\n if (input.Info) {\n formattedFacility.info = input.Info;\n }\n\n return formattedFacility;\n}\n\nexport default formatFacilityWithInfoFromServer;\n"]}
@@ -1,4 +0,0 @@
1
- import formatFacilityWithInfoFromServer from './formatFacilityWithInfoFromServer';
2
-
3
- export { formatFacilityWithInfoFromServer };
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["utils/facilities/index.js"],"names":["formatFacilityWithInfoFromServer"],"mappings":"AAAA,OAAOA,gCAAP,MAA6C,oCAA7C;;AAEA,SAASA,gCAAT","file":"index.js","sourcesContent":["import formatFacilityWithInfoFromServer from './formatFacilityWithInfoFromServer';\n\nexport { formatFacilityWithInfoFromServer };\n"]}
@@ -1,588 +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.has');
10
-
11
- var _lodash2 = _interopRequireDefault(_lodash);
12
-
13
- var _lodash3 = require('lodash.isplainobject');
14
-
15
- var _lodash4 = _interopRequireDefault(_lodash3);
16
-
17
- var _objects = require('../utils/objects');
18
-
19
- var _pagination = require('../utils/pagination');
20
-
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
-
25
- /**
26
- * @typedef {Object} PaginationMetadata
27
- * @property {number} offset Offset of records in subsequent queries
28
- * @property {number} totalRecords Total number of asset attributes found
29
- */
30
-
31
- /**
32
- * @typedef {Object} PaginationOptions
33
- * @property {Number} limit Maximum number of records to return per query
34
- * @property {Number} offset How many records from the first record to start
35
- * the query
36
- */
37
-
38
- /**
39
- * @typedef {Object} AssetAttribute
40
- * @property {string} assetTypeId UUID corresponding with the asset type
41
- * @property {string} createdAt ISO 8601 Extended Format date/time string
42
- * @property {string} dataType Data Type of attribute with options "boolean", "date", "number", "string"
43
- * @property {string} description
44
- * @property {string} id UUID
45
- * @property {boolean} isRequired
46
- * @property {string} label
47
- * @property {string} organizationId UUID corresponding with the organization
48
- * @property {string} [units]
49
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
50
- */
51
-
52
- /**
53
- * @typedef {Object} AssetAttributeData
54
- * @property {PaginationMetadata} _metadata Metadata about the pagination settings
55
- * @property {AssetAttribute[]} records
56
- */
57
-
58
- /**
59
- * @typedef {Object} AssetAttributeValue
60
- * @property {Object} [asset] The associated parent asset. Will always be
61
- * present if retrieving more than one AssetAttributeValue.
62
- * @property {string} [asset.label] Label of the parent asset. Will always be
63
- * present if retrieving more than one AssetAttributeValue.
64
- * @property {Object} [assetAttribute] The associated parent assetAttribute.
65
- * Will always be present if retrieving more than one AssetAttributeValue.
66
- * @property {boolean} [assetAttribute.isRequired] Indication of required status
67
- * for the parent asset attribute. Will always be present if retrieving more
68
- * than one AssetAttributeValue.
69
- * @property {string} [assetAttribute.label] Label of the parent assetAttribute.
70
- * Will always be present if retrieving more than one AssetAttributeValue.
71
- * @property {string} [assetAttribute.units] Units of the parent assetAttribute.
72
- * Will always be present if retrieving more than one AssetAttributeValue.
73
- * @property {string} assetAttributeId UUID corresponding to the assetAttribute
74
- * @property {string} assetId UUID corresponding to the asset
75
- * @property {string} createdAt ISO 8601 Extended Format date/time string
76
- * @property {string} effectiveDate ISO 8601 Extended Format date/time string
77
- * @property {string} id UUID
78
- * @property {string} [notes]
79
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
80
- * @property {string} value
81
- */
82
-
83
- /**
84
- * @typedef {Object} AssetAttributeValueData
85
- * @property {PaginationMetadata} _metadata Metadata about the pagination settings
86
- * @property {AssetAttributeValue[]} records
87
- */
88
-
89
- /**
90
- * Module that provides access to, and the manipulation of, information about
91
- * different asset attributes and their values
92
- *
93
- * @typicalname contxtSdk.assets.attributes
94
- */
95
- var AssetAttributes = function () {
96
- /**
97
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
98
- * @param {Object} request An instance of the request module tied to this module's audience.
99
- * @param {string} baseUrl The base URL provided by the parent module
100
- */
101
- function AssetAttributes(sdk, request, baseUrl) {
102
- _classCallCheck(this, AssetAttributes);
103
-
104
- this._baseUrl = baseUrl;
105
- this._request = request;
106
- this._sdk = sdk;
107
- }
108
-
109
- /**
110
- * Creates a new asset attribute
111
- *
112
- * API Endpoint: '/assets/types/:assetTypeId/attributes'
113
- * Method: POST
114
- *
115
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
116
- * @param {Object} assetAttribute
117
- * @param {string} assetAttribute.dataType
118
- * @param {string} assetAttribute.description
119
- * @param {boolean} [assetAttribute.isRequired]
120
- * @param {string} assetAttribute.label
121
- * @param {string} assetAttribute.organizationId Can be explicitly set to `null` to create a global attribute
122
- * @param {string} [assetAttribute.units]
123
- *
124
- * @returns {Promise}
125
- * @fulfill {AssetAttribute}
126
- * @reject {Error}
127
- *
128
- * @example
129
- * contxtSdk.assets.attributes
130
- * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {
131
- * dataType: 'boolean',
132
- * description: 'Square footage of a facility',
133
- * isRequired: true,
134
- * label: 'Square Footage',
135
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',
136
- * units: 'sqft'
137
- * })
138
- * .then((assetAttribute) => console.log(assetAttribute))
139
- * .catch((err) => console.log(err));
140
- */
141
-
142
-
143
- _createClass(AssetAttributes, [{
144
- key: 'create',
145
- value: function create(assetTypeId) {
146
- var assetAttribute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
147
-
148
- var hasFieldFns = {
149
- default: function _default(object, key) {
150
- return !!object[key];
151
- },
152
- organizationId: function organizationId(object, key) {
153
- return (0, _lodash2.default)(object, key);
154
- }
155
- };
156
-
157
- var requiredFields = ['description', 'label', 'organizationId'];
158
-
159
- if (!assetTypeId) {
160
- return Promise.reject(new Error('An asset type ID is required to create a new asset attribute.'));
161
- }
162
-
163
- for (var i = 0; i < requiredFields.length; i++) {
164
- var field = requiredFields[i];
165
- var hasField = hasFieldFns[field] || hasFieldFns.default;
166
-
167
- if (!hasField(assetAttribute, field)) {
168
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset attribute.'));
169
- }
170
- }
171
-
172
- return this._request.post(this._baseUrl + '/assets/types/' + assetTypeId + '/attributes', (0, _objects.toSnakeCase)(assetAttribute)).then(function (assetAttribute) {
173
- return (0, _objects.toCamelCase)(assetAttribute);
174
- });
175
- }
176
-
177
- /**
178
- * Deletes an asset attribute
179
- *
180
- * API Endpoint: '/assets/attributes/:assetAttributeId'
181
- * Method: DELETE
182
- *
183
- * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)
184
- *
185
- * @returns {Promise}
186
- * @fulfill {undefined}
187
- * @reject {Error}
188
- *
189
- * @example
190
- * contxtSdk.assets.attributes.delete('c7f927c3-11a7-4024-9269-e1231baeb765');
191
- */
192
-
193
- }, {
194
- key: 'delete',
195
- value: function _delete(assetAttributeId) {
196
- if (!assetAttributeId) {
197
- return Promise.reject(new Error('An asset attribute ID is required for deleting an asset attribute.'));
198
- }
199
-
200
- return this._request.delete(this._baseUrl + '/assets/attributes/' + assetAttributeId);
201
- }
202
-
203
- /**
204
- * Gets information about an asset attribute
205
- *
206
- * API Endpoint: '/assets/attributes/:assetAttributeId'
207
- * Method: GET
208
- *
209
- * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)
210
- *
211
- * @returns {Promise}
212
- * @fulfill {AssetAttribute}
213
- * @reject {Error}
214
- *
215
- * @example
216
- * contxtSdk.assets.attributes
217
- * .get('c7f927c3-11a7-4024-9269-e1231baeb765')
218
- * .then((assetAttribute) => console.log(assetAttribute))
219
- * .catch((err) => console.log(err));
220
- */
221
-
222
- }, {
223
- key: 'get',
224
- value: function get(assetAttributeId) {
225
- if (!assetAttributeId) {
226
- return Promise.reject(new Error('An asset attribute ID is required for getting information about an asset attribute.'));
227
- }
228
-
229
- return this._request.get(this._baseUrl + '/assets/attributes/' + assetAttributeId).then(function (assetAttribute) {
230
- return (0, _objects.toCamelCase)(assetAttribute);
231
- });
232
- }
233
-
234
- /**
235
- * Gets a list of asset attributes for a specific asset type
236
- *
237
- * API Endpoint: '/assets/types/:assetTypeId/attributes'
238
- * Method: GET
239
- *
240
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
241
- * @param {PaginationOptions} [paginationOptions]
242
- *
243
- * @returns {Promise}
244
- * @fulfill {AssetAttributeData}
245
- * @reject {Error}
246
- *
247
- * @example
248
- * contxtSdk.assets.attributes
249
- * .getAll('4f0e51c6-728b-4892-9863-6d002e61204d')
250
- * .then((assetAttributesData) => console.log(assetAttributesData))
251
- * .catch((err) => console.log(err));
252
- */
253
-
254
- }, {
255
- key: 'getAll',
256
- value: function getAll(assetTypeId, paginationOptions) {
257
- if (!assetTypeId) {
258
- return Promise.reject(new Error('An asset type ID is required to get a list of all asset attributes.'));
259
- }
260
-
261
- return this._request.get(this._baseUrl + '/assets/types/' + assetTypeId + '/attributes', {
262
- params: (0, _objects.toSnakeCase)(paginationOptions)
263
- }).then(function (assetAttributeData) {
264
- return (0, _pagination.formatPaginatedDataFromServer)(assetAttributeData);
265
- });
266
- }
267
-
268
- /**
269
- * Updates an asset attribute
270
- *
271
- * API Endpoint: '/assets/attributes/:assetAttributeId'
272
- * Method: PUT
273
- *
274
- * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)
275
- * @param {Object} update An object containing the updated data for the asset attribute
276
- * @param {string} [update.dataType]
277
- * @param {string} [update.description]
278
- * @param {boolean} [update.isRequired]
279
- * @param {string} [update.label]
280
- * @param {string} [update.units]
281
- *
282
- * @returns {Promise}
283
- * @fulfill {undefined}
284
- * @reject {Error}
285
- *
286
- * @example
287
- * contxtSdk.assets.attributes
288
- * .update('c7f927c3-11a7-4024-9269-e1231baeb765', {
289
- * dataType: 'boolean',
290
- * description: 'Temperature of a facility',
291
- * isRequired: false,
292
- * label: 'Temperature',
293
- * units: 'Celsius'
294
- * });
295
- */
296
-
297
- }, {
298
- key: 'update',
299
- value: function update(assetAttributeId, _update) {
300
- if (!assetAttributeId) {
301
- return Promise.reject(new Error('An asset attribute ID is required to update an asset attribute.'));
302
- }
303
-
304
- if (!_update) {
305
- return Promise.reject(new Error('An update is required to update an asset attribute.'));
306
- }
307
-
308
- if (!(0, _lodash4.default)(_update)) {
309
- return Promise.reject(new Error('The asset attribute update must be a well-formed object with the data you wish to update.'));
310
- }
311
-
312
- var formattedUpdate = (0, _objects.toSnakeCase)(_update, {
313
- excludeKeys: ['assetTypeId', 'id', 'organizationId']
314
- });
315
-
316
- return this._request.put(this._baseUrl + '/assets/attributes/' + assetAttributeId, formattedUpdate);
317
- }
318
-
319
- /**
320
- * Creates a new asset attribute value
321
- *
322
- * API Endpoint: '/assets/:assetId/attributes/:assetAttributeId/values'
323
- * Method: POST
324
- *
325
- * @param {string} assetId The ID of the asset type (formatted as a UUID)
326
- * @param {Object} assetAttributeValue
327
- * @param {string} assetAttributeValue.assetAttributeId UUID corresponding to the asset attribute
328
- * @param {string} assetAttributeValue.effectiveDate ISO 8601 Extended Format date/time string
329
- * @param {string} [assetAttributeValue.notes]
330
- * @param {string} assetAttributeValue.value
331
- *
332
- * @returns {Promise}
333
- * @fulfill {AssetAttributeValue}
334
- * @reject {Error}
335
- *
336
- * @example
337
- * contxtSdk.assets.attributes
338
- * .createValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
339
- * assetAttributeId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',
340
- * effectiveDate: '2018-07-09T14:36:36.004Z',
341
- * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',
342
- * value: '2206'
343
- * })
344
- * .then((assetAttributeValue) => console.log(assetAttributeValue))
345
- * .catch((err) => console.log(err));
346
- */
347
-
348
- }, {
349
- key: 'createValue',
350
- value: function createValue(assetId) {
351
- var assetAttributeValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
352
-
353
- var requiredFields = ['assetAttributeId', 'effectiveDate', 'value'];
354
-
355
- if (!assetId) {
356
- return Promise.reject(new Error('An asset ID is required to create a new asset attribute value.'));
357
- }
358
-
359
- for (var i = 0; i < requiredFields.length; i++) {
360
- var field = requiredFields[i];
361
-
362
- if (!assetAttributeValue[field]) {
363
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset attribute value.'));
364
- }
365
- }
366
-
367
- return this._request.post(this._baseUrl + '/assets/' + assetId + '/attributes/' + assetAttributeValue.assetAttributeId + '/values', (0, _objects.toSnakeCase)(assetAttributeValue)).then(function (assetAttributeValue) {
368
- return (0, _objects.toCamelCase)(assetAttributeValue);
369
- });
370
- }
371
-
372
- /**
373
- * Deletes an asset attribute value
374
- *
375
- * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'
376
- * Method: DELETE
377
- *
378
- * @param {string} assetAttributeValueId The ID of the asset attribute value (formatted as a UUID)
379
- *
380
- * @returns {Promise}
381
- * @fulfill {undefined}
382
- * @reject {Error}
383
- *
384
- * @example
385
- * contxtSdk.assets.attributes.deleteValue(
386
- * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'
387
- * );
388
- */
389
-
390
- }, {
391
- key: 'deleteValue',
392
- value: function deleteValue(assetAttributeValueId) {
393
- if (!assetAttributeValueId) {
394
- return Promise.reject(new Error('An asset attribute value ID is required for deleting an asset attribute value.'));
395
- }
396
-
397
- return this._request.delete(this._baseUrl + '/assets/attributes/values/' + assetAttributeValueId);
398
- }
399
-
400
- /**
401
- * Gets the effective attribute values for a particular asset
402
- *
403
- * API Endpoint: '/assets/:assetId/attributes/values'
404
- * Method: GET
405
- *
406
- * @param {String} assetId The ID of the asset for which you are looking up
407
- * attribute values (formatted as a UUID)
408
- * @param {Object} [assetAttributeFilters] Specific information that is used to
409
- * filter the list of asset attribute values
410
- * @param {String} [assetAttributeFilters.attributeLabel] Label of the parent
411
- * asset attribute
412
- * @param {String} [assetAttributeFilters.effectiveDate = (new Date()).toISOString()] Effective
413
- * date of the asset attribute values
414
- *
415
- * @returns {Promise}
416
- * @fulfill {AssetAttributeValue[]}
417
- * @rejects {Error}
418
- *
419
- * @example
420
- * contxtSdk.assets.attributes
421
- * .getEffectiveValuesByAssetId('d7329ef3-ca63-4ad5-bb3e-632b702584f8', {
422
- * attributeLabel: 'Square Footage',
423
- * effectiveDate: '2018-07-11T19:14:49.715Z'
424
- * })
425
- * .then((assetAttributeValues) => {
426
- * console.log(assetAttributeValues);
427
- * })
428
- * .catch((err) => console.log(err));
429
- */
430
-
431
- }, {
432
- key: 'getEffectiveValuesByAssetId',
433
- value: function getEffectiveValuesByAssetId(assetId, assetAttributeFilters) {
434
- if (!assetId) {
435
- return Promise.reject(new Error('An asset ID is required to get a list of asset attribute values.'));
436
- }
437
-
438
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/attributes/values', {
439
- params: (0, _objects.toSnakeCase)(assetAttributeFilters)
440
- }).then(function (assetAttributeValues) {
441
- return (0, _objects.toCamelCase)(assetAttributeValues);
442
- });
443
- }
444
-
445
- /**
446
- * Gets a paginated list of effective asset attribute values for an
447
- * organization.
448
- *
449
- * API Endpoint: '/organizations/:organizationId/attributes/values'
450
- * Method: GET
451
- *
452
- * @param {String} organizationId UUID corresponding with an organization
453
- * @param {PaginationOptions} [paginationOptions]
454
- *
455
- * @returns {Promise}
456
- * @fulfill {AssetAttributeValueData}
457
- * @rejects {Error}
458
- *
459
- * @example
460
- * contxtSdk.assets.attributes
461
- * .getValuesByAttributeId(
462
- * '53fba880-70b7-47a2-b4e3-ad9ecfb67d5c',
463
- * {
464
- * limit: 100,
465
- * offset: 0
466
- * }
467
- * )
468
- * .then((assetAttributeValuesData) => {
469
- * console.log(assetAttributeValuesData);
470
- * })
471
- * .catch((err) => console.log(err));
472
- */
473
-
474
- }, {
475
- key: 'getEffectiveValuesByOrganizationId',
476
- value: function getEffectiveValuesByOrganizationId(organizationId, paginationOptions) {
477
- if (!organizationId) {
478
- return Promise.reject(new Error('An organization ID is required to get a list of asset attribute values.'));
479
- }
480
-
481
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/attributes/values', { params: (0, _objects.toSnakeCase)(paginationOptions) }).then(function (assetAttributeValueData) {
482
- return (0, _pagination.formatPaginatedDataFromServer)(assetAttributeValueData);
483
- });
484
- }
485
-
486
- /**
487
- * Gets a paginated list of asset attribute values for a particular attribute
488
- * of a particular asset
489
- *
490
- * API Endpoint: '/assets/:assetId/attributes/:attributeId/values'
491
- * Method: GET
492
- *
493
- * @param {String} assetId The ID of the asset for which you are looking up
494
- * attribute values (formatted as a UUID)
495
- * @param {String} assetAttributeId The ID of the asset attribute for which you are
496
- * looking up attribute values (formatted as a UUID)
497
- * @param {PaginationOptions} [paginationOptions]
498
- *
499
- * @returns {Promise}
500
- * @fulfill {AssetAttributeValueData}
501
- * @rejects {Error}
502
- *
503
- * @example
504
- * contxtSdk.assets.attributes
505
- * .getValuesByAttributeId(
506
- * 'a4d80a97-cbf6-453b-bab5-0477e1ede04f',
507
- * 'c2779610-44d7-4313-aea2-96cce58d6efd',
508
- * {
509
- * limit: 100,
510
- * offset: 0
511
- * }
512
- * )
513
- * .then((assetAttributeValuesData) => {
514
- * console.log(assetAttributeValuesData);
515
- * })
516
- * .catch((err) => console.log(err));
517
- */
518
-
519
- }, {
520
- key: 'getValuesByAttributeId',
521
- value: function getValuesByAttributeId(assetId, assetAttributeId, paginationOptions) {
522
- if (!assetId) {
523
- return Promise.reject(new Error('An asset ID is required to get a list of asset attribute values.'));
524
- }
525
-
526
- if (!assetAttributeId) {
527
- return Promise.reject(new Error('An asset attribute ID is required to get a list of asset attribute values.'));
528
- }
529
-
530
- return this._request.get(this._baseUrl + '/assets/' + assetId + '/attributes/' + assetAttributeId + '/values', { params: (0, _objects.toSnakeCase)(paginationOptions) }).then(function (assetAttributeValueData) {
531
- return (0, _pagination.formatPaginatedDataFromServer)(assetAttributeValueData);
532
- });
533
- }
534
-
535
- /**
536
- * Updates an asset attribute value
537
- *
538
- * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'
539
- * Method: PUT
540
- *
541
- * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)
542
- * @param {Object} update An object containing the updated data for the asset attribute value
543
- * @param {string} [update.effectiveDate] ISO 8601 Extended Format date/time string
544
- * @param {string} [update.notes]
545
- * @param {string} [update.value]
546
- *
547
- * @returns {Promise}
548
- * @fulfill {undefined}
549
- * @reject {Error}
550
- *
551
- * @example
552
- * contxtSdk.assets.attributes
553
- * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {
554
- * effectiveDate: '2018-07-10T11:04:24.631Z',
555
- * notes: 'Dolores et sapiente sunt doloribus aut in.',
556
- * value: '61456'
557
- * })
558
- * .catch((err) => console.log(err));
559
- */
560
-
561
- }, {
562
- key: 'updateValue',
563
- value: function updateValue(assetAttributeValueId, update) {
564
- if (!assetAttributeValueId) {
565
- return Promise.reject(new Error('An asset attribute value ID is required to update an asset attribute value.'));
566
- }
567
-
568
- if (!update) {
569
- return Promise.reject(new Error('An update is required to update an asset attribute value.'));
570
- }
571
-
572
- if (!(0, _lodash4.default)(update)) {
573
- return Promise.reject(new Error('The asset attribute value update must be a well-formed object with the data you wish to update.'));
574
- }
575
-
576
- var formattedUpdate = (0, _objects.toSnakeCase)(update, {
577
- excludeKeys: ['assetAttributeId', 'assetId', 'id']
578
- });
579
-
580
- return this._request.put(this._baseUrl + '/assets/attributes/values/' + assetAttributeValueId, formattedUpdate);
581
- }
582
- }]);
583
-
584
- return AssetAttributes;
585
- }();
586
-
587
- exports.default = AssetAttributes;
588
- //# sourceMappingURL=assetAttributes.js.map