@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 +0,0 @@
1
- {"version":3,"sources":["assets/assetMetrics.js"],"names":["has","isPlainObject","toCamelCase","toSnakeCase","stringifyParamsWithCommaSeparatedArrays","formatPaginatedDataFromServer","AssetMetrics","sdk","request","baseUrl","_baseUrl","_request","_sdk","assetTypeId","assetMetric","Promise","reject","Error","hasFieldFns","default","object","key","organizationId","requiredFields","i","length","field","hasField","post","then","assetMetricId","delete","get","assetId","assetMetricsFilters","params","assetMetricsData","update","formattedUpdate","excludeKeys","put","assetMetricValue","assetMetricValueId","assetMetricValuesFilters","assetMetricValueData","assetMetricFilters","paramsSerializer","assetMetricValues","result","excludeTransform","labels","assetIds"],"mappings":";;;;;;AAAA,OAAOA,GAAP,MAAgB,YAAhB;AACA,OAAOC,aAAP,MAA0B,sBAA1B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;AACA,SAASC,uCAAT,QAAwD,cAAxD;AACA,SAASC,6BAAT,QAA8C,qBAA9C;;AAEA;;;;;;;;;;;;;AAaA;;;;;;;;AAQA;;;;;;;;;;;;;;AAcA;;;;;;;;AAQA;;;;;;;;;AASA;;;;AAIA;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;IAKMC,Y;AACJ;;;;;AAKA,wBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;A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,wDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAAChB,cAAcoC,MAAd,CAAL,EAA4B;AAC1B,eAAOtB,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,8FADF,CADK,CAAP;AAKD;;AAED,UAAMqB,kBAAkBnC,YAAYkC,MAAZ,EAAoB;AAC1CE,qBAAa,CAAC,SAAD,EAAY,eAAZ,EAA6B,IAA7B;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAK5B,QAAL,CAAc6B,GAAd,CACF,KAAK9B,QADH,+BACqCgC,kBADrC,EAELJ,eAFK,CAAP;AAID;;;;;;AAGH,eAAehC,YAAf","file":"assetMetrics.js","sourcesContent":["import has from 'lodash.has';\nimport isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\nimport { stringifyParamsWithCommaSeparatedArrays } from '../utils/url';\nimport { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} AssetMetric\n * @property {string} assetTypeId UUID corresponding with the asset type\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} description\n * @property {string} id UUID\n * @property {string} label\n * @property {string} organizationId UUID corresponding with the organization\n * @property {string} timeInterval Options are \"hourly\", \"daily\", \"weekly\", \"monthly\", \"yearly\"\n * @property {string} [units]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} AssetMetricsFromServer\n * @property {Object} _metadata Metadata about the pagination settings\n * @property {number} _metadata.offset Offset of records in subsequent queries\n * @property {number} _metadata.totalRecords Total number of asset types found\n * @property {AssetMetric[]} records\n */\n\n/**\n * @typedef {Object} AssetMetricValue\n * @property {string} assetId UUID corresponding to the asset\n * @property {string} assetMetricId UUID corresponding to the asset metric\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} effectiveEndDate ISO 8601 Extended Format date/time string\n * @property {string} effectiveStartDate ISO 8601 Extended Format date/time string\n * @property {string} id UUID\n * @property {string} notes\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n * @property {string} value\n * @property {boolean} isEstimated Whether the value is an estimation or a true reading\n */\n\n/**\n * @typedef {Object} AssetMetricValuesFromServer\n * @property {Object} _metadata Metadata about the pagination settings\n * @property {number} _metadata.offset Offset of records in subsequent queries\n * @property {number} _metadata.totalRecords Total number of asset types found\n * @property {AssetMetricValue[]} records\n */\n\n/**\n * @typedef {Object} AssetMetricValueCompact\n * @property {string} id the UUID corresponding to the asset metric value id\n * @property {string} value\n * @property {boolean} is_estimated\n * @property {string} effectiveEndDate ISO 8601 Extended Format date/time string\n * @property {string} effectiveStartDate ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object.<AssetMetric.label, AssetMetricValueCompact[]>} AssetMetricsKeyedByMetricId\n */\n\n/**\n * An object with asset ids as keys to another object with asset metric labels as keys.\n * At this final level the object contains arrays of {@link AssetMetricValueCompact}\n * @typedef {Object.<Asset.id, AssetMetricsKeyedByMetricId>} AssetMetricValuesByAssetIdMetricId\n * @example\n * {\n * \"b47e45af-3e18-408a-8070-008f9e6d7b42\" : {\n * \"facility_daily_cuft\": [\n * {\n * \"id\": \"cf7e45af-3e18-408a-8070-008f9e6d7b3j\",\n * \"value\": 10,\n * \"isEstimated\": false,\n * \"effectiveEndDate\": \"2018-07-10T11:04:24.631Z\",\n * \"effectiveStartDate\" \"2018-07-10T11:04:24.631Z\"\n * }\n * ]\n * }\n * }\n */\n\n/**\n * Module that provides access to, and the manipulation of, information about different asset metrics\n *\n * @typicalname contxtSdk.assets.metrics\n */\nclass AssetMetrics {\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 * Creates a new asset metric\n *\n * API Endpoint: '/assets/types/:assetTypeId/metrics'\n * Method: POST\n *\n * @param {string} assetTypeId The UUID formatted ID of the asset type\n * @param {Object} assetMetric\n * @param {string} assetMetric.description\n * @param {string} assetMetric.label\n * @param {string} assetMetric.organizationId Organization ID (UUID) to which the metric belongs\n * @param {string} assetMetric.timeInterval Options are \"hourly\", \"daily\", \"weekly\", \"monthly\", \"yearly\"\n * @param {string} [assetMetric.units] Units of the metric\n *\n * @returns {Promise}\n * @fulfill {AssetMetric} Information about the new asset metric\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {\n * description: 'Number of injuries which occur in the facility each month',\n * label: 'Facility Injuries',\n * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',\n * timeInterval: 'monthly',\n * units: 'injuries'\n * })\n * .then((assetMetric) => console.log(assetMetric))\n * .catch((err) => console.log(err));\n */\n create(assetTypeId, assetMetric = {}) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error('An asset type ID is required to create an asset metric.')\n );\n }\n\n const hasFieldFns = {\n default: (object, key) => !!object[key],\n organizationId: (object, key) => has(object, key)\n };\n const requiredFields = [\n 'description',\n 'label',\n 'organizationId',\n 'timeInterval'\n ];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n const hasField = hasFieldFns[field] || hasFieldFns.default;\n\n if (!hasField(assetMetric, field)) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new asset metric.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/assets/types/${assetTypeId}/metrics`,\n toSnakeCase(assetMetric)\n )\n .then((assetMetric) => toCamelCase(assetMetric));\n }\n\n /**\n * Deletes an asset metric\n *\n * API Endpoint: '/assets/metrics/:assetMetricId'\n * Method: DELETE\n *\n * @param {string} assetMetricId The UUID formatted ID of the asset metric\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics.delete('4f0e51c6-728b-4892-9863-6d002e61204d');\n */\n delete(assetMetricId) {\n if (!assetMetricId) {\n return Promise.reject(\n new Error(\n 'An asset metric ID is required for deleting an asset metric.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/assets/metrics/${assetMetricId}`\n );\n }\n\n /**\n * Gets information about an asset metric\n *\n * API Endpoint: '/assets/metrics/:assetMetricId'\n * Method: GET\n *\n * @param {string} assetMetricId The UUID formatted ID of the asset metric\n *\n * @returns {Promise}\n * @fulfill {AssetMetric} Information about the asset metric\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .get('4f0e51c6-728b-4892-9863-6d002e61204d')\n * .then((assetMetric) => console.log(assetMetric))\n * .catch((err) => console.log(err));\n */\n get(assetMetricId) {\n if (!assetMetricId) {\n return Promise.reject(\n new Error(\n 'An asset metric ID is required for getting information about an asset metric.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/metrics/${assetMetricId}`)\n .then((assetMetric) => toCamelCase(assetMetric));\n }\n\n /**\n * Gets a list of all asset metrics that belong to a given asset\n *\n * API Endpoint: '/assets/:assetId/metrics\n * Method: GET\n *\n * @param {string} assetId The UUID formatted ID of the asset type\n * @param {Object} [assetMetricsFilters] Specific information that is used to\n * filter the list of asset metrics\n * @param {String} [assetMetricsFilters.assetMetricLabel] The label of the\n * associated asset metrics\n * @param {Number} [assetMetricsFilters.limit] Maximum number of records to\n * return per query\n * @param {Number} [assetMetricsFilters.offset] How many records from the first\n * record to start the query\n *\n * @returns {Promise}\n * @fulfill {AssetMetricsFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .getByAssetId(\n * 'f3be81fd-4494-443b-87a3-320b1c9aa495',\n * {\n * assetMetricLabel: 'Square Footage',\n * limit: 50,\n * offset: 150\n * }\n * )\n * .then((assetMetricData) => console.log(assetMetricData))\n * .catch((err) => console.log(err));\n */\n getByAssetId(assetId, assetMetricsFilters) {\n if (!assetId) {\n return Promise.reject(\n new Error('An asset ID is required to get a list of all asset metrics.')\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/${assetId}/metrics`, {\n params: toSnakeCase(assetMetricsFilters)\n })\n .then((assetMetricsData) =>\n formatPaginatedDataFromServer(assetMetricsData)\n );\n }\n\n /**\n * Gets a list of all asset metrics that belong to a given type\n *\n * API Endpoint: '/assets/types/:assetTypeId/metrics\n * Method: GET\n *\n * @param {string} assetTypeId The UUID formatted ID of the asset type\n * @param {Object} [assetMetricsFilters] Specific information that is used to\n * filter the list of asset metrics\n * @param {Number} [assetMetricsFilters.limit] Maximum number of records to\n * return per query\n * @param {Number} [assetMetricsFilters.offset] How many records from the first\n * record to start the query\n * @param {String} [assetMetricsFilters.organizationId] The UUID formatted ID\n * of the organization to filter asset metrics by\n *\n * @returns {Promise}\n * @fulfill {AssetMetricsFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .getByAssetTypeId(\n * '4f0e51c6-728b-4892-9863-6d002e61204d'\n * {\n * limit: 50,\n * offset: 150\n * }\n * )\n * .then((assetMetrics) => console.log(assetMetrics))\n * .catch((err) => console.log(err));\n */\n getByAssetTypeId(assetTypeId, assetMetricsFilters) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error(\n 'An asset type ID is required to get a list of all asset metrics.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/types/${assetTypeId}/metrics`, {\n params: toSnakeCase(assetMetricsFilters)\n })\n .then((assetMetricsData) =>\n formatPaginatedDataFromServer(assetMetricsData)\n );\n }\n\n /**\n * Updates an asset metric's data\n *\n * API Endpoint: '/assets/metrics/:assetMetricId'\n * Method: PUT\n *\n * @param {string} assetMetricId The ID of the asset metric to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset metric\n * @param {string} [update.description]\n * @param {string} [update.label]\n * @param {string} [update.timeInterval]\n * @param {string} [update.units]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .update('5f310899-d8f9-4dac-ae82-cedb2048a8ef', {\n * description: 'An updated description of this metric'\n * });\n */\n update(assetMetricId, update) {\n if (!assetMetricId) {\n return Promise.reject(\n new Error('An asset metric ID is required to update an asset metric.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset metric.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset metric 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: ['createdAt', 'id', 'label', 'organizationId', 'updatedAt']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/metrics/${assetMetricId}`,\n formattedUpdate\n );\n }\n\n /**\n * Creates a new asset metric value\n *\n * API Endpoint: '/assets/:assetId/metrics/:assetMetricId/values'\n * Method: POST\n *\n * @param {string} assetId The ID of the asset (formatted as a UUID)\n * @param {Object} assetMetricValue\n * @param {string} assetMetricValue.assetMetricId UUID corresponding to the asset metric\n * @param {string} assetMetricValue.effectiveEndDate ISO 8601 Extended Format date/time string\n * @param {string} assetMetricValue.effectiveStartDate ISO 8601 Extended Format date/time string\n * @param {string} [assetMetricValue.notes]\n * @param {string} assetMetricValue.value\n * @param {boolean} [assetMetricValue.isEstimated] Whether the value is an estimation or a true reading\n *\n * @returns {Promise}\n * @fulfill {AssetMetricValue}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .createValue('1140cc2e-6d13-42ee-9941-487fe98f8e2d', {\n * assetMetricId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',\n * effectiveEndDate: '2018-08-28T18:18:18.264Z',\n * effectiveStartDate: '2018-08-27T18:18:03.175Z',\n * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',\n * value: '2000',\n * isEstimated: true\n * })\n * .then((newAssetMetricValue) => {\n * console.log(newAssetMetricValue);\n * })\n * .catch((error) => {\n * console.error(error);\n * });\n */\n createValue(assetId, assetMetricValue = {}) {\n const requiredFields = [\n 'assetMetricId',\n 'effectiveEndDate',\n 'effectiveStartDate',\n 'value'\n ];\n\n if (!assetId) {\n return Promise.reject(\n new Error('An asset ID is required to create a new asset metric value.')\n );\n }\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!assetMetricValue[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new asset metric value.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/assets/${assetId}/metrics/${\n assetMetricValue.assetMetricId\n }/values`,\n toSnakeCase(assetMetricValue)\n )\n .then((assetMetricValue) => toCamelCase(assetMetricValue));\n }\n\n /**\n * Deletes an asset metric value\n *\n * API Endpoint: '/assets/metrics/values/:assetMetricValueId'\n * Method: DELETE\n *\n * @param {string} assetMetricValueId The ID of the asset metric value (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics.deleteValue(\n * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'\n * );\n */\n deleteValue(assetMetricValueId) {\n if (!assetMetricValueId) {\n return Promise.reject(\n new Error(\n 'An asset metric value ID is required for deleting an asset metric value.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/assets/metrics/values/${assetMetricValueId}`\n );\n }\n\n /**\n * Gets asset metric values for a particular asset\n *\n * API Endpoint: '/assets/:assetId/metrics/values'\n * Method: GET\n *\n * @param {String} assetId The ID of the asset (formatted as a UUID)\n * @param {Object} [assetMetricValuesFilters] Specific information that is\n * used to filter the list of asset metric values\n * @param {String} [assetMetricValuesFilters.assetMetricLabel] The label of\n * the associated asset metrics\n * @param {String} [assetMetricValuesFilters.effectiveEndDate] Effective end\n * date (ISO 8601 Extended formatted) of the asset metric values\n * @param {String} [assetMetricValuesFilters.effectiveStartDate] Effective\n * start date (ISO 8601 Extended formatted) of the asset metric values\n * @param {Number} [assetMetricValuesFilters.limit] Maximum number of records\n * to return per query\n * @param {Number} [assetMetricValuesFilters.offset] How many records from the\n * first record to start the query\n *\n * @returns {Promise}\n * @fulfill {AssetMetricValuesFromServer}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .getValuesByAssetId(\n * 'f9c606f3-d270-4623-bf3b-b085424d9a8b',\n * {\n * assetMetricLabel: 'Square Footage',\n * effectiveEndDate: '2018-04-13T15:44:51.943Z'\n * effectiveStartDate: '2017-12-13T15:42:01.376Z'\n * limit: 10,\n * offset: 200\n * }\n * )\n * .then((assetMetricValuesData) => console.log(assetMetricValuesData))\n * .catch((err) => console.log(err));\n */\n getValuesByAssetId(assetId, assetMetricValuesFilters) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to get a list of asset metric values.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/${assetId}/metrics/values`, {\n params: toSnakeCase(assetMetricValuesFilters)\n })\n .then((assetMetricValueData) =>\n formatPaginatedDataFromServer(assetMetricValueData)\n );\n }\n\n /**\n * Gets asset metric values for a particular asset and metric\n *\n * API Endpoint: '/assets/:assetId/metrics/:assetMetricId/values'\n * Method: GET\n *\n * @param {String} assetId The ID of the asset (formatted as a UUID)\n * @param {String} assetMetricId The ID of the asset metric (formatted as a\n * UUID)\n * @param {Object} [assetMetricValuesFilters] Specific information that is\n * used to filter the list of asset metric values\n * @param {String} [assetMetricValuesFilters.effectiveEndDate] Effective end\n * date (ISO 8601 Extended formatted) of the asset metric values\n * @param {String} [assetMetricValuesFilters.effectiveStartDate] Effective\n * start date (ISO 8601 Extended formatted) of the asset metric values\n * @param {Number} [assetMetricValuesFilters.limit] Maximum number of records\n * to return per query\n * @param {Number} [assetMetricValuesFilters.offset] How many records from the\n * first record to start the query\n *\n * @returns {Promise}\n * @fulfill {AssetMetricValuesFromServer}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .getValuesByMetricId(\n * 'd7329ef3-ca63-4ad5-bb3e-632b702584f8',\n * 'a1329ef3-ca63-4ad5-bb3e-632b702584f8',\n * {\n * limit: 10,\n * effectiveStartDate: '2018-07-11T19:14:49.715Z'\n * }\n * )\n * .then((assetMetricValuesData) => {\n * console.log(assetMetricValuesData);\n * })\n * .catch((err) => console.log(err));\n */\n getValuesByMetricId(assetId, assetMetricId, assetMetricValuesFilters) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to get a list of asset metric values.'\n )\n );\n }\n\n if (!assetMetricId) {\n return Promise.reject(\n new Error(\n 'An asset metric ID is required to get a list of asset metric values.'\n )\n );\n }\n\n return this._request\n .get(\n `${this._baseUrl}/assets/${assetId}/metrics/${assetMetricId}/values`,\n {\n params: toSnakeCase(assetMetricValuesFilters)\n }\n )\n .then((assetMetricValueData) =>\n formatPaginatedDataFromServer(assetMetricValueData)\n );\n }\n\n /**\n * Gets asset metric values for a particular asset and metric\n *\n * API Endpoint: '/assets/metrics/values'\n * Method: GET\n *\n * @param {Object} [assetMetricFilters] Specific information that is\n * used to filter the list of asset metric values\n * @param {String[]} assetMetricFilters.assetIds an array of asset ids\n * to request the metrics for\n * @param {String[]} assetMetricFilters.labels an array of metric labels\n * to request the metrics for\n * @param {String} [assetMetricFilters.effectiveEndDate] Effective end\n * date (ISO 8601 Extended formatted) of the asset metric values\n * @param {String} [assetMetricFilters.effectiveStartDate] Effective\n * start date (ISO 8601 Extended formatted) of the asset metric values\n * @returns {Promise}\n * @fulfill {AssetMetricValuesByAssetIdMetricId}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .getValuesByMetricIdsAssetIds(\n * {\n * effectiveStartDate: '2018-07-11T19:14:49.715Z',\n * effectiveEndDate: '2018-07-11T19:14:49.715Z',\n * assetIds: ['2140cc2e-6d13-42ee-9941-487fe98f8e2d', '5540cc2e-6d13-42ee-9941-487fe98f8efc'],\n * labels: ['facility_kwh', 'facility_cuft'],\n * }\n * )\n * .then((assetMetricValuesByAssetIdMetricId) => {\n * console.log(assetMetricValuesByAssetIdMetricId);\n * })\n * .catch((err) => console.log(err));\n */\n getValuesByMetricIdsAssetIds(assetMetricFilters) {\n const requiredFields = ['assetIds', 'labels'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!assetMetricFilters[field]) {\n return Promise.reject(\n new Error(`The ${field} param is required to fetch data.`)\n );\n }\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/metrics/values`, {\n params: toSnakeCase(assetMetricFilters),\n paramsSerializer: stringifyParamsWithCommaSeparatedArrays\n })\n .then((assetMetricValues) => {\n const result = toCamelCase(assetMetricValues, {\n excludeTransform: [\n ...assetMetricFilters.labels,\n ...assetMetricFilters.assetIds\n ]\n });\n\n return result;\n });\n }\n\n /**\n * Updates an asset metric value\n *\n * API Endpoint: '/assets/metrics/values/:assetMetricValueId'\n * Method: PUT\n *\n * @param {string} assetMetricValueId The ID of the asset metric value to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset metric value\n * @param {string} [update.effectiveEndDate] ISO 8601 Extended Format date/time string\n * @param {string} [update.effectiveStartDate] ISO 8601 Extended Format date/time string\n * @param {string} [update.notes]\n * @param {string} [update.value]\n * @param {boolean} [update.isEstimated] Whether the value is an estimation or a true reading\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.metrics\n * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {\n * effectiveEndDate: '2018-07-10T11:04:24.631Z',\n * notes: 'Dolores et sapiente sunt doloribus aut in.',\n * value: '61456',\n * isEstimated: true\n * })\n * .catch((err) => console.log(err));\n */\n updateValue(assetMetricValueId, update) {\n if (!assetMetricValueId) {\n return Promise.reject(\n new Error(\n 'An asset metric value ID is required to update an asset metric value.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset metric value.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset metric value 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: ['assetId', 'assetMetricId', 'id']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/metrics/values/${assetMetricValueId}`,\n formattedUpdate\n );\n }\n}\n\nexport default AssetMetrics;\n"]}
@@ -1,273 +0,0 @@
1
- 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; }; }();
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- import has from 'lodash.has';
6
- import isPlainObject from 'lodash.isplainobject';
7
- import { toCamelCase, toSnakeCase } from '../utils/objects';
8
- import { formatPaginatedDataFromServer } from '../utils/pagination';
9
-
10
- /**
11
- * @typedef {Object} AssetType
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} AssetTypesFromServer
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 {AssetType[]} records
26
- */
27
-
28
- /**
29
- * Module that provides access to, and the manipulation of, information about different asset types
30
- *
31
- * @typicalname contxtSdk.assets.types
32
- */
33
-
34
- var AssetTypes = function () {
35
- /**
36
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
37
- * @param {Object} request An instance of the request module tied to this module's audience.
38
- * @param {string} baseUrl The base URL provided by the parent module
39
- */
40
- function AssetTypes(sdk, request, baseUrl) {
41
- _classCallCheck(this, AssetTypes);
42
-
43
- this._baseUrl = baseUrl;
44
- this._request = request;
45
- this._sdk = sdk;
46
- }
47
-
48
- /**
49
- * Creates a new asset type
50
- *
51
- * API Endpoint: '/assets/types'
52
- * Method: POST
53
- *
54
- * @param {Object} assetType
55
- * @param {string} assetType.description
56
- * @param {string} assetType.label
57
- * @param {string} assetType.organizationId The ID of the asset type's parent organization. Can be
58
- * explicitly set to `null` to create a global asset type
59
- *
60
- * @returns {Promise}
61
- * @fulfill {AssetType} Information about the new asset type
62
- * @reject {Error}
63
- *
64
- * @example
65
- * contxtSdk.assets.types
66
- * .create({
67
- * description: 'A physicial facility building',
68
- * label: 'Facility',
69
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'
70
- * })
71
- * .then((assetType) => console.log(assetType))
72
- * .catch((err) => console.log(err));
73
- */
74
-
75
-
76
- _createClass(AssetTypes, [{
77
- key: 'create',
78
- value: function create() {
79
- var assetType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
80
-
81
- var hasFieldFns = {
82
- default: function _default(object, key) {
83
- return !!object[key];
84
- },
85
- organizationId: function organizationId(object, key) {
86
- return has(object, key);
87
- }
88
- };
89
- var requiredFields = ['description', 'label', 'organizationId'];
90
-
91
- for (var i = 0; i < requiredFields.length; i++) {
92
- var field = requiredFields[i];
93
- var hasField = hasFieldFns[field] || hasFieldFns.default;
94
-
95
- if (!hasField(assetType, field)) {
96
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset type.'));
97
- }
98
- }
99
-
100
- return this._request.post(this._baseUrl + '/assets/types', toSnakeCase(assetType)).then(function (assetType) {
101
- return toCamelCase(assetType);
102
- });
103
- }
104
-
105
- /**
106
- * Deletes an asset type
107
- *
108
- * API Endpoint: '/assets/types/:assetTypeId'
109
- * Method: DELETE
110
- *
111
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
112
- *
113
- * @returns {Promise}
114
- * @fulfill {undefined}
115
- * @reject {Error}
116
- *
117
- * @example
118
- * contxtSdk.assets.types.delete('4f0e51c6-728b-4892-9863-6d002e61204d')
119
- */
120
-
121
- }, {
122
- key: 'delete',
123
- value: function _delete(assetTypeId) {
124
- if (!assetTypeId) {
125
- return Promise.reject(new Error('An asset type ID is required for deleting an asset type.'));
126
- }
127
-
128
- return this._request.delete(this._baseUrl + '/assets/types/' + assetTypeId);
129
- }
130
-
131
- /**
132
- * Gets information about an asset type
133
- *
134
- * API Endpoint: '/assets/types/:assetTypeId'
135
- * Method: GET
136
- *
137
- * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
138
- *
139
- * @returns {Promise}
140
- * @fulfill {AssetType} Information about the asset type
141
- * @reject {Error}
142
- *
143
- * @example
144
- * contxtSdk.assets.types
145
- * .get('4f0e51c6-728b-4892-9863-6d002e61204d')
146
- * .then((assetType) => console.log(assetType))
147
- * .catch((err) => console.log(err));
148
- */
149
-
150
- }, {
151
- key: 'get',
152
- value: function get(assetTypeId) {
153
- if (!assetTypeId) {
154
- return Promise.reject(new Error('An asset type ID is required for getting information about an asset type.'));
155
- }
156
-
157
- return this._request.get(this._baseUrl + '/assets/types/' + assetTypeId).then(function (assetType) {
158
- return toCamelCase(assetType);
159
- });
160
- }
161
-
162
- /**
163
- * Gets a list of all asset types
164
- *
165
- * API Endpoint: '/assets/types/
166
- * Method: GET
167
- *
168
- * @param {PaginationOptions} [paginationOptions]
169
- *
170
- * @returns {Promise}
171
- * @fulfill {AssetTypesFromServer}
172
- * @reject {Error}
173
- *
174
- * @example
175
- * contxtSdk.assets.types
176
- * .getAll()
177
- * .then((assetTypes) => console.log(assetTypes))
178
- * .catch((err) => console.log(err));
179
- */
180
-
181
- }, {
182
- key: 'getAll',
183
- value: function getAll(paginationOptions) {
184
- return this._request.get(this._baseUrl + '/assets/types', {
185
- params: toSnakeCase(paginationOptions)
186
- }).then(function (assetTypesData) {
187
- return formatPaginatedDataFromServer(assetTypesData);
188
- });
189
- }
190
-
191
- /**
192
- * Gets a list of all asset types that belong to a particular organization
193
- *
194
- * API Endpoint: '/organizations/:organizationId/assets/types'
195
- * Method: GET
196
- *
197
- * @param {string} organizationId UUID corresponding with an organization
198
- * @param {PaginationOptions} [paginationOptions]
199
- *
200
- * @returns {Promise}
201
- * @fulfill {AssetTypesFromServer}
202
- * @reject {Error}
203
- *
204
- * @example
205
- * contxtSdk.assets.types
206
- * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c')
207
- * .then((assetTypes) => console.log(assetTypes))
208
- * .catch((err) => console.log(assetTypes));
209
- */
210
-
211
- }, {
212
- key: 'getAllByOrganizationId',
213
- value: function getAllByOrganizationId(organizationId, paginationOptions) {
214
- if (!organizationId) {
215
- return Promise.reject(new Error("An organization ID is required for getting a list of an organization's asset types."));
216
- }
217
-
218
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/assets/types', {
219
- params: toSnakeCase(paginationOptions)
220
- }).then(function (assetTypesData) {
221
- return formatPaginatedDataFromServer(assetTypesData);
222
- });
223
- }
224
-
225
- /**
226
- * Updates an asset type's data
227
- *
228
- * API Endpoint: '/assets/types/:assetTypeId'
229
- * Method: PUT
230
- *
231
- * @param {string} assetTypeId The ID of the asset type to update (formatted as a UUID)
232
- * @param {Object} update An object containing the updated data for the asset type
233
- * @param {string} update.description
234
- *
235
- * @returns {Promise}
236
- * @fulfill {undefined}
237
- * @reject {Error}
238
- *
239
- * @example
240
- * contxtSdk.assets.types
241
- * .update('5f310899-d8f9-4dac-ae82-cedb2048a8ef', {
242
- * description: 'A physical facility building'
243
- * });
244
- */
245
-
246
- }, {
247
- key: 'update',
248
- value: function update(assetTypeId, _update) {
249
- if (!assetTypeId) {
250
- return Promise.reject(new Error('An asset type ID is required to update an asset type.'));
251
- }
252
-
253
- if (!_update) {
254
- return Promise.reject(new Error('An update is required to update an asset type.'));
255
- }
256
-
257
- if (!isPlainObject(_update)) {
258
- return Promise.reject(new Error('The asset type update must be a well-formed object with the data you wish to update.'));
259
- }
260
-
261
- var formattedUpdate = toSnakeCase(_update, {
262
- excludeKeys: ['id', 'label', 'organizationId']
263
- });
264
-
265
- return this._request.put(this._baseUrl + '/assets/types/' + assetTypeId, formattedUpdate);
266
- }
267
- }]);
268
-
269
- return AssetTypes;
270
- }();
271
-
272
- export default AssetTypes;
273
- //# sourceMappingURL=assetTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["assets/assetTypes.js"],"names":["has","isPlainObject","toCamelCase","toSnakeCase","formatPaginatedDataFromServer","AssetTypes","sdk","request","baseUrl","_baseUrl","_request","_sdk","assetType","hasFieldFns","default","object","key","organizationId","requiredFields","i","length","field","hasField","Promise","reject","Error","post","then","assetTypeId","delete","get","paginationOptions","params","assetTypesData","update","formattedUpdate","excludeKeys","put"],"mappings":";;;;AAAA,OAAOA,GAAP,MAAgB,YAAhB;AACA,OAAOC,aAAP,MAA0B,sBAA1B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;AACA,SAASC,6BAAT,QAA8C,qBAA9C;;AAEA;;;;;;;;;;AAUA;;;;;;;;AAQA;;;;;;IAKMC,U;AACJ;;;;;AAKA,sBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BuB;AAAA,UAAhBM,SAAgB,uEAAJ,EAAI;;AACrB,UAAMC,cAAc;AAClBC,iBAAS,kBAACC,MAAD,EAASC,GAAT;AAAA,iBAAiB,CAAC,CAACD,OAAOC,GAAP,CAAnB;AAAA,SADS;AAElBC,wBAAgB,wBAACF,MAAD,EAASC,GAAT;AAAA,iBAAiBhB,IAAIe,MAAJ,EAAYC,GAAZ,CAAjB;AAAA;AAFE,OAApB;AAIA,UAAME,iBAAiB,CAAC,aAAD,EAAgB,OAAhB,EAAyB,gBAAzB,CAAvB;;AAEA,WAAK,IAAIC,IAAI,CAA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oB7B,8BAA8B6B,cAA9B,CAApB;AAAA,OAJD,CAAP;AAKD;;AAED;;;;;;;;;;;;;;;;;;;;;;2CAmBuBhB,c,EAAgBc,iB,EAAmB;AACxD,UAAI,CAACd,cAAL,EAAqB;AACnB,eAAOM,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,qFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKf,QAAL,CACJoB,GADI,CACG,KAAKrB,QADR,uBACkCQ,cADlC,oBACiE;AACpEe,gBAAQ7B,YAAY4B,iBAAZ;AAD4D,OADjE,EAIJJ,IAJI,CAIC,UAACM,cAAD;AAAA,eAAoB7B,8BAA8B6B,cAA9B,CAApB;AAAA,OAJD,CAAP;AAKD;;AAED;;;;;;;;;;;;;;;;;;;;;;;2BAoBOL,W,EAAaM,O,EAAQ;AAC1B,UAAI,CAACN,WAAL,EAAkB;AAChB,eAAOL,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACS,OAAL,EAAa;AACX,eAAOX,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,gDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACxB,cAAciC,OAAd,CAAL,EAA4B;AAC1B,eAAOX,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sFADF,CADK,CAAP;AAKD;;AAED,UAAMU,kBAAkBhC,YAAY+B,OAAZ,EAAoB;AAC1CE,qBAAa,CAAC,IAAD,EAAO,OAAP,EAAgB,gBAAhB;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAK1B,QAAL,CAAc2B,GAAd,CACF,KAAK5B,QADH,sBAC4BmB,WAD5B,EAELO,eAFK,CAAP;AAID;;;;;;AAGH,eAAe9B,UAAf","file":"assetTypes.js","sourcesContent":["import has from 'lodash.has';\nimport isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\nimport { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} AssetType\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} description\n * @property {string} id UUID\n * @property {string} label\n * @property {string} organizationId UUID corresponding with the organization\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} AssetTypesFromServer\n * @property {Object} _metadata Metadata about the pagination settings\n * @property {number} _metadata.offset Offset of records in subsequent queries\n * @property {number} _metadata.totalRecords Total number of asset types found\n * @property {AssetType[]} records\n */\n\n/**\n * Module that provides access to, and the manipulation of, information about different asset types\n *\n * @typicalname contxtSdk.assets.types\n */\nclass AssetTypes {\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 * Creates a new asset type\n *\n * API Endpoint: '/assets/types'\n * Method: POST\n *\n * @param {Object} assetType\n * @param {string} assetType.description\n * @param {string} assetType.label\n * @param {string} assetType.organizationId The ID of the asset type's parent organization. Can be\n * explicitly set to `null` to create a global asset type\n *\n * @returns {Promise}\n * @fulfill {AssetType} Information about the new asset type\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.types\n * .create({\n * description: 'A physicial facility building',\n * label: 'Facility',\n * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'\n * })\n * .then((assetType) => console.log(assetType))\n * .catch((err) => console.log(err));\n */\n create(assetType = {}) {\n const hasFieldFns = {\n default: (object, key) => !!object[key],\n organizationId: (object, key) => has(object, key)\n };\n const requiredFields = ['description', 'label', 'organizationId'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n const hasField = hasFieldFns[field] || hasFieldFns.default;\n\n if (!hasField(assetType, field)) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new asset type.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/assets/types`, toSnakeCase(assetType))\n .then((assetType) => toCamelCase(assetType));\n }\n\n /**\n * Deletes an asset type\n *\n * API Endpoint: '/assets/types/:assetTypeId'\n * Method: DELETE\n *\n * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.types.delete('4f0e51c6-728b-4892-9863-6d002e61204d')\n */\n delete(assetTypeId) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error('An asset type ID is required for deleting an asset type.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/assets/types/${assetTypeId}`);\n }\n\n /**\n * Gets information about an asset type\n *\n * API Endpoint: '/assets/types/:assetTypeId'\n * Method: GET\n *\n * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {AssetType} Information about the asset type\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.types\n * .get('4f0e51c6-728b-4892-9863-6d002e61204d')\n * .then((assetType) => console.log(assetType))\n * .catch((err) => console.log(err));\n */\n get(assetTypeId) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error(\n 'An asset type ID is required for getting information about an asset type.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/types/${assetTypeId}`)\n .then((assetType) => toCamelCase(assetType));\n }\n\n /**\n * Gets a list of all asset types\n *\n * API Endpoint: '/assets/types/\n * Method: GET\n *\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetTypesFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.types\n * .getAll()\n * .then((assetTypes) => console.log(assetTypes))\n * .catch((err) => console.log(err));\n */\n getAll(paginationOptions) {\n return this._request\n .get(`${this._baseUrl}/assets/types`, {\n params: toSnakeCase(paginationOptions)\n })\n .then((assetTypesData) => formatPaginatedDataFromServer(assetTypesData));\n }\n\n /**\n * Gets a list of all asset types that belong to a particular organization\n *\n * API Endpoint: '/organizations/:organizationId/assets/types'\n * Method: GET\n *\n * @param {string} organizationId UUID corresponding with an organization\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetTypesFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.types\n * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c')\n * .then((assetTypes) => console.log(assetTypes))\n * .catch((err) => console.log(assetTypes));\n */\n getAllByOrganizationId(organizationId, paginationOptions) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n \"An organization ID is required for getting a list of an organization's asset types.\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/assets/types`, {\n params: toSnakeCase(paginationOptions)\n })\n .then((assetTypesData) => formatPaginatedDataFromServer(assetTypesData));\n }\n\n /**\n * Updates an asset type's data\n *\n * API Endpoint: '/assets/types/:assetTypeId'\n * Method: PUT\n *\n * @param {string} assetTypeId The ID of the asset type to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset type\n * @param {string} update.description\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.types\n * .update('5f310899-d8f9-4dac-ae82-cedb2048a8ef', {\n * description: 'A physical facility building'\n * });\n */\n update(assetTypeId, update) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error('An asset type ID is required to update an asset type.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset type.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset type 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', 'label', 'organizationId']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/types/${assetTypeId}`,\n formattedUpdate\n );\n }\n}\n\nexport default AssetTypes;\n"]}
@@ -1,283 +0,0 @@
1
- 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; }; }();
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- import isPlainObject from 'lodash.isplainobject';
6
- import AssetAttributes from './assetAttributes';
7
- import AssetMetrics from './assetMetrics';
8
- import AssetTypes from './assetTypes';
9
-
10
- import { toCamelCase, toSnakeCase } from '../utils/objects';
11
- import { formatPaginatedDataFromServer } from '../utils/pagination';
12
-
13
- /**
14
- * @typedef {Object} Asset
15
- * @property {string} assetTypeId UUID corresponding with the asset type
16
- * @property {string} createdAt ISO 8601 Extended Format date/time string
17
- * @property {string} [description]
18
- * @property {string} id UUID
19
- * @property {string} label
20
- * @property {string} organizationId UUID corresponding with the organization
21
- * @property {string} updatedAt ISO 8601 Extended Format date/time string
22
- */
23
-
24
- /**
25
- * @typedef {Object} AssetsFromServer
26
- * @property {Object} _metadata Metadata about the pagination settings
27
- * @property {number} _metadata.offset Offset of records in subsequent queries
28
- * @property {number} _metadata.totalRecords Total number of asset types found
29
- * @property {Asset[]} records
30
- */
31
-
32
- /**
33
- * Module that provides access to, and the manipulation of, information about different assets
34
- *
35
- * @typicalname contxtSdk.assets
36
- */
37
-
38
- var Assets = function () {
39
- /**
40
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
41
- * @param {Object} request An instance of the request module tied to this module's audience.
42
- */
43
- function Assets(sdk, request) {
44
- _classCallCheck(this, Assets);
45
-
46
- var baseUrl = sdk.config.audiences.facilities.host + '/v1';
47
-
48
- this._baseUrl = baseUrl;
49
- this._request = request;
50
- this._sdk = sdk;
51
-
52
- this.attributes = new AssetAttributes(sdk, request, baseUrl);
53
- this.types = new AssetTypes(sdk, request, baseUrl);
54
- this.metrics = new AssetMetrics(sdk, request, baseUrl);
55
- }
56
-
57
- /**
58
- * Creates a new asset
59
- *
60
- * API Endpoint: '/assets'
61
- * Method: POST
62
- *
63
- * @param {Object} asset
64
- * @param {string} asset.assetTypeId UUID
65
- * @param {string} [asset.description]
66
- * @param {string} asset.label
67
- * @param {string} asset.organizationId UUID
68
- *
69
- * @returns {Promise}
70
- * @fulfill {Asset} information about the new asset
71
- * @reject {Error}
72
- *
73
- * @example
74
- * contxtSdk.assets
75
- * .create({
76
- * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d',
77
- * description: '221B Baker Street, London',
78
- * label: 'Sherlock Homes Museum',
79
- * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'
80
- * })
81
- * .then((asset) => console.log(asset))
82
- * .catch((err) => console.log(err));
83
- */
84
-
85
-
86
- _createClass(Assets, [{
87
- key: 'create',
88
- value: function create() {
89
- var asset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
90
-
91
- var requiredFields = ['assetTypeId', 'label', 'organizationId'];
92
-
93
- for (var i = 0; i < requiredFields.length; i++) {
94
- var field = requiredFields[i];
95
-
96
- if (!asset[field]) {
97
- return Promise.reject(new Error('A ' + field + ' is required to create a new asset.'));
98
- }
99
- }
100
-
101
- return this._request.post(this._baseUrl + '/assets', toSnakeCase(asset)).then(function (asset) {
102
- return toCamelCase(asset);
103
- });
104
- }
105
-
106
- /**
107
- * Deletes an asset
108
- *
109
- * API Endpoint: '/assets/:assetId'
110
- * Method: DELETE
111
- *
112
- * @param {string} assetId The ID of the asset (formatted as a UUID)
113
- *
114
- * @returns {Promise}
115
- * @fulfill {undefined}
116
- * @reject {Error}
117
- *
118
- * @example
119
- * contxtSdk.assets.delete('0b51429f-91a0-48ba-b144-fd2db697000e');
120
- */
121
-
122
- }, {
123
- key: 'delete',
124
- value: function _delete(assetId) {
125
- if (!assetId) {
126
- return Promise.reject(new Error('An asset ID is required for deleting an asset.'));
127
- }
128
-
129
- return this._request.delete(this._baseUrl + '/assets/' + assetId);
130
- }
131
-
132
- /**
133
- * Gets information about an asset
134
- *
135
- * API Endpoint: '/assets/:assetId'
136
- * Method: GET
137
- *
138
- * @param {string} assetId The ID of the asset (formatted as a UUID)
139
- *
140
- * @returns {Promise}
141
- * @fulfill {Asset} Information about the asset
142
- * @reject {Error}
143
- *
144
- * @example
145
- * contxtSdk.assets
146
- * .get('0b51429f-91a0-48ba-b144-fd2db697000e')
147
- * .then((asset) => console.log(asset))
148
- * .catch((err) => console.log(err));
149
- */
150
-
151
- }, {
152
- key: 'get',
153
- value: function get(assetId) {
154
- if (!assetId) {
155
- return Promise.reject(new Error('An asset ID is required for getting information about an asset.'));
156
- }
157
-
158
- return this._request.get(this._baseUrl + '/assets/' + assetId).then(function (asset) {
159
- return toCamelCase(asset);
160
- });
161
- }
162
-
163
- /**
164
- * Get a list of all assets
165
- *
166
- * API Endpoint: '/assets'
167
- * Method: GET
168
- *
169
- * @param {PaginationOptions} [paginationOptions]
170
- *
171
- * @returns {Promise}
172
- * @fulfill {AssetsFromServer}
173
- * @reject {Error}
174
- *
175
- * @example
176
- * contxtSdk.assets
177
- * .getAll()
178
- * .then((assets) => console.log(assets))
179
- * .catch((err) => console.log(err));
180
- */
181
-
182
- }, {
183
- key: 'getAll',
184
- value: function getAll(paginationOptions) {
185
- return this._request.get(this._baseUrl + '/assets', {
186
- params: toSnakeCase(paginationOptions)
187
- }).then(function (assetsData) {
188
- return formatPaginatedDataFromServer(assetsData);
189
- });
190
- }
191
-
192
- /**
193
- * Get a list of all assets that belong to a particular organization
194
- *
195
- * API Endpoint: '/organizations/:organizationId/assets'
196
- * Method: GET
197
- *
198
- * @param {string} organizationId UUID corresponding with an organization
199
- * @param {Object} [options] Object containing parameters to be called with the request
200
- * @param {string} [options.assetTypeId] UUID of the asset type to use for filtering
201
- * @param {Number} [options.limit] Maximum number of records to return per query
202
- * @param {Number} [options.offset] How many records from the first record to start
203
- * @param {boolean} [options.includeTypeDescendents] When true will look for all asset types that are descendendents from options.assetTypeId
204
- * @param {string} [options.includeMetricId] If asset has an associated metric value the latest metric will be returned.
205
- *
206
- * @returns {Promise}
207
- * @fulfill {AssetsFromServer}
208
- * @reject {Error}
209
- *
210
- * @example
211
- * contxtSdk.assets
212
- * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c', {
213
- * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d'
214
- * })
215
- * .then((assets) => console.log(assets))
216
- * .catch((err) => console.log(err));
217
- */
218
-
219
- }, {
220
- key: 'getAllByOrganizationId',
221
- value: function getAllByOrganizationId(organizationId, options) {
222
- if (!organizationId) {
223
- return Promise.reject(new Error("An organization ID is required for getting a list of an organization's assets."));
224
- }
225
-
226
- var params = toSnakeCase(options);
227
-
228
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/assets', {
229
- params: params
230
- }).then(function (assetsData) {
231
- return formatPaginatedDataFromServer(assetsData);
232
- });
233
- }
234
-
235
- /**
236
- * Updates an asset's data
237
- *
238
- * API Endpoint: '/assets/:assetId'
239
- * Method: PUT
240
- *
241
- * @param {string} assetId The ID of the asset to update (formatted as a UUID)
242
- * @param {Object} update An object containing the updated data for the asset
243
- * @param {string} update.description
244
- *
245
- * @example
246
- * contxtSdk.assets
247
- * .update({
248
- * description: 'A new description'
249
- * })
250
- * .then((asset) => console.log(asset))
251
- * .catch((err) => console.log(err));
252
- */
253
-
254
- }, {
255
- key: 'update',
256
- value: function update(assetId, _update) {
257
- if (!assetId) {
258
- return Promise.reject(new Error('An asset ID is required to update an asset.'));
259
- }
260
-
261
- if (!_update) {
262
- return Promise.reject(new Error('An update is required to update an asset.'));
263
- }
264
-
265
- if (!isPlainObject(_update)) {
266
- return Promise.reject(new Error('The asset update must be a well-formed object with the data you wish to update.'));
267
- }
268
-
269
- var formattedUpdate = toSnakeCase(_update, {
270
- excludeKeys: ['assetTypeId', 'id', 'label', 'organizationId']
271
- });
272
-
273
- return this._request.put(this._baseUrl + '/assets/' + assetId, formattedUpdate).then(function (asset) {
274
- return toCamelCase(asset);
275
- });
276
- }
277
- }]);
278
-
279
- return Assets;
280
- }();
281
-
282
- export default Assets;
283
- //# sourceMappingURL=index.js.map