@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.
- package/.gitattributes +1 -0
- package/CHANGELOG.md +8 -0
- package/CODEOWNERS +1 -0
- package/docs/Facilities.md +0 -144
- package/docs/FacilityGroupings.md +0 -160
- package/docs/Nionic.md +63 -0
- package/docs/README.md +3 -29
- package/docs/Typedefs.md +0 -101
- package/esm/config/audiences.js +13 -13
- package/esm/config/audiences.js.map +1 -1
- package/esm/index.js +4 -6
- package/esm/index.js.map +1 -1
- package/esm/nionic/index.js +126 -0
- package/esm/nionic/index.js.map +1 -0
- package/lib/config/audiences.js +13 -13
- package/lib/config/audiences.js.map +1 -1
- package/lib/index.js +10 -15
- package/lib/index.js.map +1 -1
- package/lib/nionic/index.js +130 -0
- package/lib/nionic/index.js.map +1 -0
- package/meta.yaml +11 -0
- package/package.json +9 -10
- package/src/bus/index.spec.js +3 -2
- package/src/bus/webSocketConnection.spec.js +31 -31
- package/src/config/audiences.js +13 -13
- package/src/config/index.spec.js +6 -6
- package/src/coordinator/applications.spec.js +8 -8
- package/src/coordinator/consent.spec.js +1 -1
- package/src/coordinator/edgeNodes.spec.js +3 -3
- package/src/coordinator/organizations.spec.js +4 -4
- package/src/coordinator/permissions.spec.js +4 -4
- package/src/coordinator/roles.spec.js +3 -3
- package/src/coordinator/users.spec.js +14 -15
- package/src/events/index.spec.js +16 -16
- package/src/files/index.spec.js +7 -7
- package/src/index.js +4 -6
- package/src/index.spec.js +8 -22
- package/src/iot/feeds.spec.js +4 -4
- package/src/iot/fieldCategories.spec.js +4 -4
- package/src/iot/fieldGroupings.spec.js +5 -5
- package/src/iot/outputs.spec.js +6 -6
- package/src/nionic/index.js +151 -0
- package/src/request.spec.js +3 -3
- package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
- package/src/sessionTypes/index.spec.js +3 -3
- package/src/sessionTypes/machineAuth.spec.js +3 -3
- package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
- package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
- package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
- package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
- package/src/utils/url/stringifyParams.spec.js +2 -3
- package/support/fixtures/factories/IOSDevice.js +3 -3
- package/support/fixtures/factories/applicationGrouping.js +4 -4
- package/support/fixtures/factories/applicationModule.js +2 -2
- package/support/fixtures/factories/asset.js +1 -1
- package/support/fixtures/factories/assetAttribute.js +2 -2
- package/support/fixtures/factories/assetAttributeValue.js +2 -2
- package/support/fixtures/factories/assetMetric.js +1 -1
- package/support/fixtures/factories/assetMetricValue.js +3 -3
- package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
- package/support/fixtures/factories/assetType.js +1 -1
- package/support/fixtures/factories/authResults.js +3 -3
- package/support/fixtures/factories/channel.js +1 -1
- package/support/fixtures/factories/contxtApplication.js +5 -5
- package/support/fixtures/factories/contxtOrganization.js +2 -2
- package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
- package/support/fixtures/factories/contxtProject.js +2 -2
- package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
- package/support/fixtures/factories/contxtRole.js +3 -3
- package/support/fixtures/factories/contxtRoleApplication.js +1 -1
- package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUser.js +2 -2
- package/support/fixtures/factories/contxtUserApplication.js +1 -1
- package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
- package/support/fixtures/factories/contxtUserPermissions.js +5 -5
- package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUserRole.js +2 -2
- package/support/fixtures/factories/costCenter.js +2 -2
- package/support/fixtures/factories/costCenterFacility.js +3 -3
- package/support/fixtures/factories/edgeNode.js +1 -1
- package/support/fixtures/factories/event.js +5 -5
- package/support/fixtures/factories/eventType.js +4 -4
- package/support/fixtures/factories/eventUser.js +5 -5
- package/support/fixtures/factories/facility.js +4 -4
- package/support/fixtures/factories/facilityGrouping.js +3 -3
- package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
- package/support/fixtures/factories/facilityInfo.js +2 -2
- package/support/fixtures/factories/facilityTag.js +1 -1
- package/support/fixtures/factories/feedStatus.js +1 -1
- package/support/fixtures/factories/feedType.js +1 -1
- package/support/fixtures/factories/feeds.js +5 -5
- package/support/fixtures/factories/fieldCategory.js +3 -3
- package/support/fixtures/factories/fieldGrouping.js +4 -4
- package/support/fixtures/factories/fieldGroupingField.js +3 -3
- package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
- package/support/fixtures/factories/file.js +1 -1
- package/support/fixtures/factories/fileUploadInfo.js +1 -1
- package/support/fixtures/factories/organization.js +1 -1
- package/support/fixtures/factories/outputField.js +10 -10
- package/support/fixtures/factories/outputFieldData.js +1 -1
- package/support/fixtures/factories/owner.js +2 -2
- package/support/fixtures/factories/paginationMetadata.js +2 -2
- package/support/fixtures/factories/triggeredEvent.js +4 -4
- package/support/fixtures/factories/userEventSubscription.js +1 -1
- package/support/fixtures/factories/userMobileNumber.js +1 -1
- package/support/fixtures/factories/userPermissionsMap.js +2 -2
- package/.huskyrc.js +0 -11
- package/.nycrc +0 -12
- package/esm/assets/assetAttributes.js +0 -574
- package/esm/assets/assetAttributes.js.map +0 -1
- package/esm/assets/assetMetrics.js +0 -690
- package/esm/assets/assetMetrics.js.map +0 -1
- package/esm/assets/assetTypes.js +0 -273
- package/esm/assets/assetTypes.js.map +0 -1
- package/esm/assets/index.js +0 -283
- package/esm/assets/index.js.map +0 -1
- package/esm/facilities/costCenters.js +0 -306
- package/esm/facilities/costCenters.js.map +0 -1
- package/esm/facilities/groupings.js +0 -323
- package/esm/facilities/groupings.js.map +0 -1
- package/esm/facilities/index.js +0 -343
- package/esm/facilities/index.js.map +0 -1
- package/esm/health/index.js +0 -229
- package/esm/health/index.js.map +0 -1
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/esm/utils/facilities/index.js +0 -4
- package/esm/utils/facilities/index.js.map +0 -1
- package/lib/assets/assetAttributes.js +0 -588
- package/lib/assets/assetAttributes.js.map +0 -1
- package/lib/assets/assetMetrics.js +0 -705
- package/lib/assets/assetMetrics.js.map +0 -1
- package/lib/assets/assetTypes.js +0 -287
- package/lib/assets/assetTypes.js.map +0 -1
- package/lib/assets/index.js +0 -302
- package/lib/assets/index.js.map +0 -1
- package/lib/facilities/costCenters.js +0 -316
- package/lib/facilities/costCenters.js.map +0 -1
- package/lib/facilities/groupings.js +0 -333
- package/lib/facilities/groupings.js.map +0 -1
- package/lib/facilities/index.js +0 -360
- package/lib/facilities/index.js.map +0 -1
- package/lib/health/index.js +0 -232
- package/lib/health/index.js.map +0 -1
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/lib/utils/facilities/index.js +0 -15
- package/lib/utils/facilities/index.js.map +0 -1
- package/src/assets/assetAttributes.js +0 -619
- package/src/assets/assetAttributes.spec.js +0 -1143
- package/src/assets/assetMetrics.js +0 -736
- package/src/assets/assetMetrics.spec.js +0 -1180
- package/src/assets/assetTypes.js +0 -260
- package/src/assets/assetTypes.spec.js +0 -556
- package/src/assets/index.js +0 -271
- package/src/assets/index.spec.js +0 -515
- package/src/facilities/costCenters.js +0 -295
- package/src/facilities/costCenters.spec.js +0 -529
- package/src/facilities/groupings.js +0 -320
- package/src/facilities/groupings.spec.js +0 -567
- package/src/facilities/index.js +0 -343
- package/src/facilities/index.spec.js +0 -551
- package/src/health/index.js +0 -200
- package/src/health/index.spec.js +0 -501
- package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
- package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
- package/src/utils/facilities/index.js +0 -3
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["assets/assetMetrics.js"],"names":["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","stringifyParamsWithCommaSeparatedArrays","assetMetricValues","result","excludeTransform","labels","assetIds"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;AACA;;AACA;;AACA;;;;;;;;AAEA;;;;;;;;;;;;;AAaA;;;;;;;;AAQA;;;;;;;;;;;;;;AAcA;;;;;;;;AAQA;;;;;;;;;AASA;;;;AAIA;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;IAKMA,Y;AACJ;;;;;AAKA,wBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA8BOM,W,EAA+B;AAAA,UAAlBC,WAAkB,uEAAJ,EAAI;;AACpC,UAAI,CAACD,WAAL,EAAkB;AAChB,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,yDAAV,CADK,CAAP;AAGD;;AAED,UAAMC,cAAc;AAClBC,iBAAS,kBAACC,MAAD,EAASC,GAAT;AAAA,iBAAiB,CAAC,CAACD,OAAOC,GAAP,CAAnB;AAAA,SADS;AAElBC,wBAAgB,wBAACF,MAAD,EAASC,GAAT;AAAA,iBAAiB,sBAAID,MAAJ,EAAYC,GAAZ,CAAjB;AAAA;AAFE,OAApB;AAIA,UAAME,iBAAiB,CACrB,aADqB,EAErB,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D;AACF;;AAED,aAAO,KAAKf,QAAL,CACJqB,GADI,CACG,KAAKtB,QADR,6BAC0C;AAC7CyB,gBAAQ,0BAAYU,kBAAZ,CADqC;AAE7CC,0BAAkBC;AAF2B,OAD1C,EAKJlB,IALI,CAKC,UAACmB,iBAAD,EAAuB;AAC3B,YAAMC,SAAS,0BAAYD,iBAAZ,EAA+B;AAC5CE,yDACKL,mBAAmBM,MADxB,sBAEKN,mBAAmBO,QAFxB;AAD4C,SAA/B,CAAf;;AAOA,eAAOH,MAAP;AACD,OAdI,CAAP;AAeD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCA4BYP,kB,EAAoBL,M,EAAQ;AACtC,UAAI,CAACK,kBAAL,EAAyB;AACvB,eAAO3B,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,uEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACoB,MAAL,EAAa;AACX,eAAOtB,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,wDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAAC,sBAAcoB,MAAd,CAAL,EAA4B;AAC1B,eAAOtB,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,8FADF,CADK,CAAP;AAKD;;AAED,UAAMqB,kBAAkB,0BAAYD,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;;;;;;kBAGYhC,Y","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"]}
|
package/lib/assets/assetTypes.js
DELETED
|
@@ -1,287 +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} AssetType
|
|
27
|
-
* @property {string} createdAt ISO 8601 Extended Format date/time string
|
|
28
|
-
* @property {string} description
|
|
29
|
-
* @property {string} id UUID
|
|
30
|
-
* @property {string} label
|
|
31
|
-
* @property {string} organizationId UUID corresponding with the organization
|
|
32
|
-
* @property {string} updatedAt ISO 8601 Extended Format date/time string
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {Object} AssetTypesFromServer
|
|
37
|
-
* @property {Object} _metadata Metadata about the pagination settings
|
|
38
|
-
* @property {number} _metadata.offset Offset of records in subsequent queries
|
|
39
|
-
* @property {number} _metadata.totalRecords Total number of asset types found
|
|
40
|
-
* @property {AssetType[]} records
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Module that provides access to, and the manipulation of, information about different asset types
|
|
45
|
-
*
|
|
46
|
-
* @typicalname contxtSdk.assets.types
|
|
47
|
-
*/
|
|
48
|
-
var AssetTypes = function () {
|
|
49
|
-
/**
|
|
50
|
-
* @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
|
|
51
|
-
* @param {Object} request An instance of the request module tied to this module's audience.
|
|
52
|
-
* @param {string} baseUrl The base URL provided by the parent module
|
|
53
|
-
*/
|
|
54
|
-
function AssetTypes(sdk, request, baseUrl) {
|
|
55
|
-
_classCallCheck(this, AssetTypes);
|
|
56
|
-
|
|
57
|
-
this._baseUrl = baseUrl;
|
|
58
|
-
this._request = request;
|
|
59
|
-
this._sdk = sdk;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new asset type
|
|
64
|
-
*
|
|
65
|
-
* API Endpoint: '/assets/types'
|
|
66
|
-
* Method: POST
|
|
67
|
-
*
|
|
68
|
-
* @param {Object} assetType
|
|
69
|
-
* @param {string} assetType.description
|
|
70
|
-
* @param {string} assetType.label
|
|
71
|
-
* @param {string} assetType.organizationId The ID of the asset type's parent organization. Can be
|
|
72
|
-
* explicitly set to `null` to create a global asset type
|
|
73
|
-
*
|
|
74
|
-
* @returns {Promise}
|
|
75
|
-
* @fulfill {AssetType} Information about the new asset type
|
|
76
|
-
* @reject {Error}
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* contxtSdk.assets.types
|
|
80
|
-
* .create({
|
|
81
|
-
* description: 'A physicial facility building',
|
|
82
|
-
* label: 'Facility',
|
|
83
|
-
* organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'
|
|
84
|
-
* })
|
|
85
|
-
* .then((assetType) => console.log(assetType))
|
|
86
|
-
* .catch((err) => console.log(err));
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_createClass(AssetTypes, [{
|
|
91
|
-
key: 'create',
|
|
92
|
-
value: function create() {
|
|
93
|
-
var assetType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
94
|
-
|
|
95
|
-
var hasFieldFns = {
|
|
96
|
-
default: function _default(object, key) {
|
|
97
|
-
return !!object[key];
|
|
98
|
-
},
|
|
99
|
-
organizationId: function organizationId(object, key) {
|
|
100
|
-
return (0, _lodash2.default)(object, key);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
var requiredFields = ['description', 'label', 'organizationId'];
|
|
104
|
-
|
|
105
|
-
for (var i = 0; i < requiredFields.length; i++) {
|
|
106
|
-
var field = requiredFields[i];
|
|
107
|
-
var hasField = hasFieldFns[field] || hasFieldFns.default;
|
|
108
|
-
|
|
109
|
-
if (!hasField(assetType, field)) {
|
|
110
|
-
return Promise.reject(new Error('A ' + field + ' is required to create a new asset type.'));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return this._request.post(this._baseUrl + '/assets/types', (0, _objects.toSnakeCase)(assetType)).then(function (assetType) {
|
|
115
|
-
return (0, _objects.toCamelCase)(assetType);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Deletes an asset type
|
|
121
|
-
*
|
|
122
|
-
* API Endpoint: '/assets/types/:assetTypeId'
|
|
123
|
-
* Method: DELETE
|
|
124
|
-
*
|
|
125
|
-
* @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
|
|
126
|
-
*
|
|
127
|
-
* @returns {Promise}
|
|
128
|
-
* @fulfill {undefined}
|
|
129
|
-
* @reject {Error}
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* contxtSdk.assets.types.delete('4f0e51c6-728b-4892-9863-6d002e61204d')
|
|
133
|
-
*/
|
|
134
|
-
|
|
135
|
-
}, {
|
|
136
|
-
key: 'delete',
|
|
137
|
-
value: function _delete(assetTypeId) {
|
|
138
|
-
if (!assetTypeId) {
|
|
139
|
-
return Promise.reject(new Error('An asset type ID is required for deleting an asset type.'));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return this._request.delete(this._baseUrl + '/assets/types/' + assetTypeId);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Gets information about an asset type
|
|
147
|
-
*
|
|
148
|
-
* API Endpoint: '/assets/types/:assetTypeId'
|
|
149
|
-
* Method: GET
|
|
150
|
-
*
|
|
151
|
-
* @param {string} assetTypeId The ID of the asset type (formatted as a UUID)
|
|
152
|
-
*
|
|
153
|
-
* @returns {Promise}
|
|
154
|
-
* @fulfill {AssetType} Information about the asset type
|
|
155
|
-
* @reject {Error}
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* contxtSdk.assets.types
|
|
159
|
-
* .get('4f0e51c6-728b-4892-9863-6d002e61204d')
|
|
160
|
-
* .then((assetType) => console.log(assetType))
|
|
161
|
-
* .catch((err) => console.log(err));
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
}, {
|
|
165
|
-
key: 'get',
|
|
166
|
-
value: function get(assetTypeId) {
|
|
167
|
-
if (!assetTypeId) {
|
|
168
|
-
return Promise.reject(new Error('An asset type ID is required for getting information about an asset type.'));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return this._request.get(this._baseUrl + '/assets/types/' + assetTypeId).then(function (assetType) {
|
|
172
|
-
return (0, _objects.toCamelCase)(assetType);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Gets a list of all asset types
|
|
178
|
-
*
|
|
179
|
-
* API Endpoint: '/assets/types/
|
|
180
|
-
* Method: GET
|
|
181
|
-
*
|
|
182
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
183
|
-
*
|
|
184
|
-
* @returns {Promise}
|
|
185
|
-
* @fulfill {AssetTypesFromServer}
|
|
186
|
-
* @reject {Error}
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* contxtSdk.assets.types
|
|
190
|
-
* .getAll()
|
|
191
|
-
* .then((assetTypes) => console.log(assetTypes))
|
|
192
|
-
* .catch((err) => console.log(err));
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
}, {
|
|
196
|
-
key: 'getAll',
|
|
197
|
-
value: function getAll(paginationOptions) {
|
|
198
|
-
return this._request.get(this._baseUrl + '/assets/types', {
|
|
199
|
-
params: (0, _objects.toSnakeCase)(paginationOptions)
|
|
200
|
-
}).then(function (assetTypesData) {
|
|
201
|
-
return (0, _pagination.formatPaginatedDataFromServer)(assetTypesData);
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Gets a list of all asset types that belong to a particular organization
|
|
207
|
-
*
|
|
208
|
-
* API Endpoint: '/organizations/:organizationId/assets/types'
|
|
209
|
-
* Method: GET
|
|
210
|
-
*
|
|
211
|
-
* @param {string} organizationId UUID corresponding with an organization
|
|
212
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
213
|
-
*
|
|
214
|
-
* @returns {Promise}
|
|
215
|
-
* @fulfill {AssetTypesFromServer}
|
|
216
|
-
* @reject {Error}
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* contxtSdk.assets.types
|
|
220
|
-
* .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c')
|
|
221
|
-
* .then((assetTypes) => console.log(assetTypes))
|
|
222
|
-
* .catch((err) => console.log(assetTypes));
|
|
223
|
-
*/
|
|
224
|
-
|
|
225
|
-
}, {
|
|
226
|
-
key: 'getAllByOrganizationId',
|
|
227
|
-
value: function getAllByOrganizationId(organizationId, paginationOptions) {
|
|
228
|
-
if (!organizationId) {
|
|
229
|
-
return Promise.reject(new Error("An organization ID is required for getting a list of an organization's asset types."));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/assets/types', {
|
|
233
|
-
params: (0, _objects.toSnakeCase)(paginationOptions)
|
|
234
|
-
}).then(function (assetTypesData) {
|
|
235
|
-
return (0, _pagination.formatPaginatedDataFromServer)(assetTypesData);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Updates an asset type's data
|
|
241
|
-
*
|
|
242
|
-
* API Endpoint: '/assets/types/:assetTypeId'
|
|
243
|
-
* Method: PUT
|
|
244
|
-
*
|
|
245
|
-
* @param {string} assetTypeId The ID of the asset type to update (formatted as a UUID)
|
|
246
|
-
* @param {Object} update An object containing the updated data for the asset type
|
|
247
|
-
* @param {string} update.description
|
|
248
|
-
*
|
|
249
|
-
* @returns {Promise}
|
|
250
|
-
* @fulfill {undefined}
|
|
251
|
-
* @reject {Error}
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* contxtSdk.assets.types
|
|
255
|
-
* .update('5f310899-d8f9-4dac-ae82-cedb2048a8ef', {
|
|
256
|
-
* description: 'A physical facility building'
|
|
257
|
-
* });
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
}, {
|
|
261
|
-
key: 'update',
|
|
262
|
-
value: function update(assetTypeId, _update) {
|
|
263
|
-
if (!assetTypeId) {
|
|
264
|
-
return Promise.reject(new Error('An asset type ID is required to update an asset type.'));
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (!_update) {
|
|
268
|
-
return Promise.reject(new Error('An update is required to update an asset type.'));
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (!(0, _lodash4.default)(_update)) {
|
|
272
|
-
return Promise.reject(new Error('The asset type update must be a well-formed object with the data you wish to update.'));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
var formattedUpdate = (0, _objects.toSnakeCase)(_update, {
|
|
276
|
-
excludeKeys: ['id', 'label', 'organizationId']
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
return this._request.put(this._baseUrl + '/assets/types/' + assetTypeId, formattedUpdate);
|
|
280
|
-
}
|
|
281
|
-
}]);
|
|
282
|
-
|
|
283
|
-
return AssetTypes;
|
|
284
|
-
}();
|
|
285
|
-
|
|
286
|
-
exports.default = AssetTypes;
|
|
287
|
-
//# sourceMappingURL=assetTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["assets/assetTypes.js"],"names":["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":";;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,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,CAAC,sBAAcS,OAAd,CAAL,EAA4B;AAC1B,eAAOX,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sFADF,CADK,CAAP;AAKD;;AAED,UAAMU,kBAAkB,0BAAYD,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;;;;;;kBAGY9B,U","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"]}
|