@ndustrial/contxt-sdk 4.3.4 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +8 -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 +3 -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 +19 -13
- 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 +3 -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/.envrc +0 -0
- 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
- package/tmp/package.json +0 -11
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["assets/assetAttributes.js"],"names":["AssetAttributes","sdk","request","baseUrl","_baseUrl","_request","_sdk","assetTypeId","assetAttribute","hasFieldFns","default","object","key","organizationId","requiredFields","Promise","reject","Error","i","length","field","hasField","post","then","assetAttributeId","delete","get","paginationOptions","params","assetAttributeData","update","formattedUpdate","excludeKeys","put","assetId","assetAttributeValue","assetAttributeValueId","assetAttributeFilters","assetAttributeValues","assetAttributeValueData"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;AACA;;AACA;;;;;;AAEA;;;;;;AAMA;;;;;;;AAOA;;;;;;;;;;;;;;AAcA;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;;;;;AAMA;;;;;;IAMMA,e;AACJ;;;;;AAKA,2BAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAgCOM,W,EAAkC;AAAA,UAArBC,cAAqB,uEAAJ,EAAI;;AACvC,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;;AAKA,UAAME,iBAAiB,CAAC,aAAD,EAAgB,OAAhB,EAAyB,gBAAzB,CAAvB;;AAEA,UAAI,CAACP,WAAL,EAAkB;AAChB,eAAOQ,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,+DADF,CADK,CAAP;AAKD;;AAED,WAAK,IAAIC,IAAI,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,CAAxB;;AAIA,aAAO,KAAK3B,QAAL,CAAc4B,GAAd,CACF,KAAK7B,QADH,kCACwCgC,qBADxC,EAELL,eAFK,CAAP;AAID;;;;;;kBAGY/B,e","file":"assetAttributes.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} PaginationMetadata\n * @property {number} offset Offset of records in subsequent queries\n * @property {number} totalRecords Total number of asset attributes found\n */\n\n/**\n * @typedef {Object} PaginationOptions\n * @property {Number} limit Maximum number of records to return per query\n * @property {Number} offset How many records from the first record to start\n * the query\n */\n\n/**\n * @typedef {Object} AssetAttribute\n * @property {string} assetTypeId UUID corresponding with the asset type\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} dataType Data Type of attribute with options \"boolean\", \"date\", \"number\", \"string\"\n * @property {string} description\n * @property {string} id UUID\n * @property {boolean} isRequired\n * @property {string} label\n * @property {string} organizationId UUID corresponding with the organization\n * @property {string} [units]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} AssetAttributeData\n * @property {PaginationMetadata} _metadata Metadata about the pagination settings\n * @property {AssetAttribute[]} records\n */\n\n/**\n * @typedef {Object} AssetAttributeValue\n * @property {Object} [asset] The associated parent asset. Will always be\n * present if retrieving more than one AssetAttributeValue.\n * @property {string} [asset.label] Label of the parent asset. Will always be\n * present if retrieving more than one AssetAttributeValue.\n * @property {Object} [assetAttribute] The associated parent assetAttribute.\n * Will always be present if retrieving more than one AssetAttributeValue.\n * @property {boolean} [assetAttribute.isRequired] Indication of required status\n * for the parent asset attribute. Will always be present if retrieving more\n * than one AssetAttributeValue.\n * @property {string} [assetAttribute.label] Label of the parent assetAttribute.\n * Will always be present if retrieving more than one AssetAttributeValue.\n * @property {string} [assetAttribute.units] Units of the parent assetAttribute.\n * Will always be present if retrieving more than one AssetAttributeValue.\n * @property {string} assetAttributeId UUID corresponding to the assetAttribute\n * @property {string} assetId UUID corresponding to the asset\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} effectiveDate 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 */\n\n/**\n * @typedef {Object} AssetAttributeValueData\n * @property {PaginationMetadata} _metadata Metadata about the pagination settings\n * @property {AssetAttributeValue[]} records\n */\n\n/**\n * Module that provides access to, and the manipulation of, information about\n * different asset attributes and their values\n *\n * @typicalname contxtSdk.assets.attributes\n */\nclass AssetAttributes {\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 attribute\n *\n * API Endpoint: '/assets/types/:assetTypeId/attributes'\n * Method: POST\n *\n * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)\n * @param {Object} assetAttribute\n * @param {string} assetAttribute.dataType\n * @param {string} assetAttribute.description\n * @param {boolean} [assetAttribute.isRequired]\n * @param {string} assetAttribute.label\n * @param {string} assetAttribute.organizationId Can be explicitly set to `null` to create a global attribute\n * @param {string} [assetAttribute.units]\n *\n * @returns {Promise}\n * @fulfill {AssetAttribute}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .create('4f0e51c6-728b-4892-9863-6d002e61204d', {\n * dataType: 'boolean',\n * description: 'Square footage of a facility',\n * isRequired: true,\n * label: 'Square Footage',\n * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42',\n * units: 'sqft'\n * })\n * .then((assetAttribute) => console.log(assetAttribute))\n * .catch((err) => console.log(err));\n */\n create(assetTypeId, assetAttribute = {}) {\n const hasFieldFns = {\n default: (object, key) => !!object[key],\n organizationId: (object, key) => has(object, key)\n };\n\n const requiredFields = ['description', 'label', 'organizationId'];\n\n if (!assetTypeId) {\n return Promise.reject(\n new Error(\n 'An asset type ID is required to create a new asset attribute.'\n )\n );\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(assetAttribute, field)) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new asset attribute.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/assets/types/${assetTypeId}/attributes`,\n toSnakeCase(assetAttribute)\n )\n .then((assetAttribute) => toCamelCase(assetAttribute));\n }\n\n /**\n * Deletes an asset attribute\n *\n * API Endpoint: '/assets/attributes/:assetAttributeId'\n * Method: DELETE\n *\n * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes.delete('c7f927c3-11a7-4024-9269-e1231baeb765');\n */\n delete(assetAttributeId) {\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required for deleting an asset attribute.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/assets/attributes/${assetAttributeId}`\n );\n }\n\n /**\n * Gets information about an asset attribute\n *\n * API Endpoint: '/assets/attributes/:assetAttributeId'\n * Method: GET\n *\n * @param {string} assetAttributeId The ID of the asset attribute (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {AssetAttribute}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .get('c7f927c3-11a7-4024-9269-e1231baeb765')\n * .then((assetAttribute) => console.log(assetAttribute))\n * .catch((err) => console.log(err));\n */\n get(assetAttributeId) {\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required for getting information about an asset attribute.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/attributes/${assetAttributeId}`)\n .then((assetAttribute) => toCamelCase(assetAttribute));\n }\n\n /**\n * Gets a list of asset attributes for a specific asset type\n *\n * API Endpoint: '/assets/types/:assetTypeId/attributes'\n * Method: GET\n *\n * @param {string} assetTypeId The ID of the asset type (formatted as a UUID)\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeData}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getAll('4f0e51c6-728b-4892-9863-6d002e61204d')\n * .then((assetAttributesData) => console.log(assetAttributesData))\n * .catch((err) => console.log(err));\n */\n getAll(assetTypeId, paginationOptions) {\n if (!assetTypeId) {\n return Promise.reject(\n new Error(\n 'An asset type ID is required to get a list of all asset attributes.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/types/${assetTypeId}/attributes`, {\n params: toSnakeCase(paginationOptions)\n })\n .then((assetAttributeData) =>\n formatPaginatedDataFromServer(assetAttributeData)\n );\n }\n\n /**\n * Updates an asset attribute\n *\n * API Endpoint: '/assets/attributes/:assetAttributeId'\n * Method: PUT\n *\n * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset attribute\n * @param {string} [update.dataType]\n * @param {string} [update.description]\n * @param {boolean} [update.isRequired]\n * @param {string} [update.label]\n * @param {string} [update.units]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .update('c7f927c3-11a7-4024-9269-e1231baeb765', {\n * dataType: 'boolean',\n * description: 'Temperature of a facility',\n * isRequired: false,\n * label: 'Temperature',\n * units: 'Celsius'\n * });\n */\n update(assetAttributeId, update) {\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required to update an asset attribute.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset attribute.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset attribute 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: ['assetTypeId', 'id', 'organizationId']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/attributes/${assetAttributeId}`,\n formattedUpdate\n );\n }\n\n /**\n * Creates a new asset attribute value\n *\n * API Endpoint: '/assets/:assetId/attributes/:assetAttributeId/values'\n * Method: POST\n *\n * @param {string} assetId The ID of the asset type (formatted as a UUID)\n * @param {Object} assetAttributeValue\n * @param {string} assetAttributeValue.assetAttributeId UUID corresponding to the asset attribute\n * @param {string} assetAttributeValue.effectiveDate ISO 8601 Extended Format date/time string\n * @param {string} [assetAttributeValue.notes]\n * @param {string} assetAttributeValue.value\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValue}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .createValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {\n * assetAttributeId: 'cca11baa-cf7d-44c0-9d0a-6ad73d5f30cb',\n * effectiveDate: '2018-07-09T14:36:36.004Z',\n * notes: 'Iure delectus non sunt a voluptates pariatur fuga.',\n * value: '2206'\n * })\n * .then((assetAttributeValue) => console.log(assetAttributeValue))\n * .catch((err) => console.log(err));\n */\n createValue(assetId, assetAttributeValue = {}) {\n const requiredFields = ['assetAttributeId', 'effectiveDate', 'value'];\n\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to create a new asset attribute value.'\n )\n );\n }\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!assetAttributeValue[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new asset attribute value.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/assets/${assetId}/attributes/${\n assetAttributeValue.assetAttributeId\n }/values`,\n toSnakeCase(assetAttributeValue)\n )\n .then((assetAttributeValue) => toCamelCase(assetAttributeValue));\n }\n\n /**\n * Deletes an asset attribute value\n *\n * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'\n * Method: DELETE\n *\n * @param {string} assetAttributeValueId The ID of the asset attribute value (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes.deleteValue(\n * 'f4cd0d84-6c61-4d19-9322-7c1ab226dc83'\n * );\n */\n deleteValue(assetAttributeValueId) {\n if (!assetAttributeValueId) {\n return Promise.reject(\n new Error(\n 'An asset attribute value ID is required for deleting an asset attribute value.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/assets/attributes/values/${assetAttributeValueId}`\n );\n }\n\n /**\n * Gets the effective attribute values for a particular asset\n *\n * API Endpoint: '/assets/:assetId/attributes/values'\n * Method: GET\n *\n * @param {String} assetId The ID of the asset for which you are looking up\n * attribute values (formatted as a UUID)\n * @param {Object} [assetAttributeFilters] Specific information that is used to\n * filter the list of asset attribute values\n * @param {String} [assetAttributeFilters.attributeLabel] Label of the parent\n * asset attribute\n * @param {String} [assetAttributeFilters.effectiveDate = (new Date()).toISOString()] Effective\n * date of the asset attribute values\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValue[]}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getEffectiveValuesByAssetId('d7329ef3-ca63-4ad5-bb3e-632b702584f8', {\n * attributeLabel: 'Square Footage',\n * effectiveDate: '2018-07-11T19:14:49.715Z'\n * })\n * .then((assetAttributeValues) => {\n * console.log(assetAttributeValues);\n * })\n * .catch((err) => console.log(err));\n */\n getEffectiveValuesByAssetId(assetId, assetAttributeFilters) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/${assetId}/attributes/values`, {\n params: toSnakeCase(assetAttributeFilters)\n })\n .then((assetAttributeValues) => toCamelCase(assetAttributeValues));\n }\n\n /**\n * Gets a paginated list of effective asset attribute values for an\n * organization.\n *\n * API Endpoint: '/organizations/:organizationId/attributes/values'\n * Method: GET\n *\n * @param {String} organizationId UUID corresponding with an organization\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValueData}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getValuesByAttributeId(\n * '53fba880-70b7-47a2-b4e3-ad9ecfb67d5c',\n * {\n * limit: 100,\n * offset: 0\n * }\n * )\n * .then((assetAttributeValuesData) => {\n * console.log(assetAttributeValuesData);\n * })\n * .catch((err) => console.log(err));\n */\n getEffectiveValuesByOrganizationId(organizationId, paginationOptions) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n return this._request\n .get(\n `${this._baseUrl}/organizations/${organizationId}/attributes/values`,\n { params: toSnakeCase(paginationOptions) }\n )\n .then((assetAttributeValueData) =>\n formatPaginatedDataFromServer(assetAttributeValueData)\n );\n }\n\n /**\n * Gets a paginated list of asset attribute values for a particular attribute\n * of a particular asset\n *\n * API Endpoint: '/assets/:assetId/attributes/:attributeId/values'\n * Method: GET\n *\n * @param {String} assetId The ID of the asset for which you are looking up\n * attribute values (formatted as a UUID)\n * @param {String} assetAttributeId The ID of the asset attribute for which you are\n * looking up attribute values (formatted as a UUID)\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetAttributeValueData}\n * @rejects {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .getValuesByAttributeId(\n * 'a4d80a97-cbf6-453b-bab5-0477e1ede04f',\n * 'c2779610-44d7-4313-aea2-96cce58d6efd',\n * {\n * limit: 100,\n * offset: 0\n * }\n * )\n * .then((assetAttributeValuesData) => {\n * console.log(assetAttributeValuesData);\n * })\n * .catch((err) => console.log(err));\n */\n getValuesByAttributeId(assetId, assetAttributeId, paginationOptions) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n if (!assetAttributeId) {\n return Promise.reject(\n new Error(\n 'An asset attribute ID is required to get a list of asset attribute values.'\n )\n );\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/assets/${assetId}/attributes/${assetAttributeId}/values`,\n { params: toSnakeCase(paginationOptions) }\n )\n .then((assetAttributeValueData) =>\n formatPaginatedDataFromServer(assetAttributeValueData)\n );\n }\n\n /**\n * Updates an asset attribute value\n *\n * API Endpoint: '/assets/attributes/values/:assetAttributeValueId'\n * Method: PUT\n *\n * @param {string} assetAttributeId The ID of the asset attribute to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset attribute value\n * @param {string} [update.effectiveDate] ISO 8601 Extended Format date/time string\n * @param {string} [update.notes]\n * @param {string} [update.value]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.attributes\n * .updateValue('2140cc2e-6d13-42ee-9941-487fe98f8e2d', {\n * effectiveDate: '2018-07-10T11:04:24.631Z',\n * notes: 'Dolores et sapiente sunt doloribus aut in.',\n * value: '61456'\n * })\n * .catch((err) => console.log(err));\n */\n updateValue(assetAttributeValueId, update) {\n if (!assetAttributeValueId) {\n return Promise.reject(\n new Error(\n 'An asset attribute value ID is required to update an asset attribute value.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset attribute value.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset attribute 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: ['assetAttributeId', 'assetId', 'id']\n });\n\n return this._request.put(\n `${this._baseUrl}/assets/attributes/values/${assetAttributeValueId}`,\n formattedUpdate\n );\n }\n}\n\nexport default AssetAttributes;\n"]}
|