@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":["facilities/groupings.js"],"names":["isPlainObject","toCamelCase","toSnakeCase","FacilityGroupings","sdk","request","baseUrl","_baseUrl","_request","_sdk","facilityGroupingId","facilityId","errorMsg","Promise","reject","Error","post","then","groupingFacility","grouping","requiredFields","i","length","field","delete","get","groupings","organizationId","update","formattedUpdate","excludeKeys","put"],"mappings":";;;;AAAA,OAAOA,aAAP,MAA0B,sBAA1B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;;;;;AAcA;;;;;;;;;AASA;;;;;;;IAMMC,iB;AACJ;;;;;AAKA,6BAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;gCAmBYM,kB,EAAoBC,U,EAAY;AAC1C,UAAIC,iBAAJ;;AAEA,UAAI,CAACF,kBAAL,EAAyB;AACvBE,mBACE,uGADF;AAED,OAHD,MAGO,IAAI,CAACD,UAAL,EAAiB;AACtBC,mBACE,+FADF;AAED;;AAED,UAAIA,QAAJ,EAAc;AACZ,eAAOC,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAUH,QAAV,CAAf,CAAP;AACD;;AAED,aAAO,KAAKJ,QAAL,CACJQ,IADI,CAGD,KAAKT,QAHJ,mBAIWG,kBAJX,kBAI0CC,UAJ1C,EAMJM,IANI,CAMC,UAACC,gBAAD;AAAA,eAAsBjB,YAAYiB,gBAAZ,CAAtB;AAAA,OAND,CAAP;AAOD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA6BsB;AAAA,UAAfC,QAAe,uEAAJ,EAAI;;AACpB,UAAMC,iBAAiB,CAAC,MAAD,EAAS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B,kB,EAAoBC,U,EAAY;AAC7C,UAAIC,iBAAJ;;AAEA,UAAI,CAACF,kBAAL,EAAyB;AACvBE,mBACE,uGADF;AAED,OAHD,MAGO,IAAI,CAACD,UAAL,EAAiB;AACtBC,mBACE,+FADF;AAED;;AAED,UAAIA,QAAJ,EAAc;AACZ,eAAOC,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAUH,QAAV,CAAf,CAAP;AACD;;AAED,aAAO,KAAKJ,QAAL,CAAcgB,MAAd,CACF,KAAKjB,QADH,mBACyBG,kBADzB,kBACwDC,UADxD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA4BOD,kB,EAAoBkB,O,EAAQ;AACjC,UAAI,CAAClB,kBAAL,EAAyB;AACvB,eAAOG,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,mEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACa,OAAL,EAAa;AACX,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,qDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACf,cAAc4B,OAAd,CAAL,EAA4B;AAC1B,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,6FADF,CADK,CAAP;AAKD;;AAED,UAAMc,kBAAkB3B,YAAY0B,OAAZ,EAAoB;AAC1CE,qBAAa,CAAC,IAAD,EAAO,gBAAP,EAAyB,SAAzB;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAKtB,QAAL,CACJuB,GADI,CACG,KAAKxB,QADR,mBAC8BG,kBAD9B,EACoDmB,eADpD,EAEJZ,IAFI,CAEC,UAACE,QAAD;AAAA,eAAclB,YAAYkB,QAAZ,CAAd;AAAA,OAFD,CAAP;AAGD;;;;;;AAGH,eAAehB,iBAAf","file":"groupings.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} FacilityGrouping\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {string} [description]\n * @param {Facility[]} [facilities]\n * @param {string} id UUID\n * @param {boolean} isPrivate\n * @param {string} name\n * @param {string} organizationId UUID\n * @param {string} ownerId Auth0 identifer of the user\n * @param {string} [parentGroupingId] UUID\n * @param {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} FacilityGroupingFacility\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {string} facilityGroupingId UUID\n * @param {number} facilityId\n * @param {string} id UUID\n * @param {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * Module that provides access to facility groupings, and helps manage\n * the relationship between those groupings and facilities\n *\n * @typicalname contxtSdk.facilities.groupings\n */\nclass FacilityGroupings {\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 * Adds a facility to a facility grouping\n *\n * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'\n * Method: POST\n *\n * @param {string} facilityGroupingId UUID corresponding with a facility grouping\n * @param {number} facilityId\n *\n * @returns {Promise}\n * @fulfill {FacilityGroupingFacility} Information about the new facility/grouping relationship\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .then((grouping) => console.log(grouping))\n * .catch((err) => console.log(err));\n */\n addFacility(facilityGroupingId, facilityId) {\n let errorMsg;\n\n if (!facilityGroupingId) {\n errorMsg =\n 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to create a relationship between a facility grouping and a facility.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .post(\n `${\n this._baseUrl\n }/groupings/${facilityGroupingId}/facility/${facilityId}`\n )\n .then((groupingFacility) => toCamelCase(groupingFacility));\n }\n\n /**\n * Creates a new facility grouping\n *\n * API Endpoint: '/groupings'\n * Method: POST\n *\n * @param {Object} facilityGrouping\n * @param {string} [facilityGrouping.description]\n * @param {boolean} [facilityGrouping.isPrivate = false]\n * @param {string} facilityGrouping.name\n * @param {string} facilityGrouping.organizationId UUID\n * @param {string} [facilityGrouping.parentGroupingId] UUID\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping} Information about the new facility grouping\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .create({\n * description: 'US States of CT, MA, ME, NH, RI, VT',\n * isPrivate: false,\n * name: 'New England, USA',\n * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5',\n * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'\n * })\n * .then((grouping) => console.log(grouping))\n * .catch((err) => console.log(err));\n */\n create(grouping = {}) {\n const requiredFields = ['name', 'organizationId'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!grouping[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new facility grouping.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/groupings`, toSnakeCase(grouping))\n .then((grouping) => toCamelCase(grouping));\n }\n\n /**\n * Delete a facility groupings\n *\n * API Endpoint: '/groupings/:facilityGroupingId'\n * Method: DELETE\n *\n * @param {string} facilityGroupingId The id of the facility grouping (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings.delete(\n * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'\n * );\n */\n delete(facilityGroupingId) {\n if (!facilityGroupingId) {\n return Promise.reject(\n new Error(\n 'A facility grouping id is required for deleting a facility grouping.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/groupings/${facilityGroupingId}`\n );\n }\n\n /**\n * Get a listing of all facility groupings available to a user. Includes public groupings across\n * any organization the user has access to and the user's private groupings.\n *\n * API Endpoint: '/groupings'\n * Method: GET\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilites.groupings\n * .getAll()\n * .then((groupings) => console.log(groupings))\n * .catch((err) => console.log(err));\n */\n getAll() {\n return this._request\n .get(`${this._baseUrl}/groupings`)\n .then((groupings) => toCamelCase(groupings));\n }\n\n /**\n * Get a listing of all facility groupings for an organization. Includes public groupings\n * across that specific organization and the user's private groupings for that organization.\n *\n * API Endpoint: '/organizations/:organizationId/groupings'\n * Method: GET\n *\n * @param {string} organizationId UUID corresponding with an organization\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilites.groupings\n * .getAllByOrganizationId('349dbd36-5dca-4a10-b54d-d0f71c3c8709')\n * .then((groupings) => console.log(groupings))\n * .catch((err) => console.log(err));\n */\n getAllByOrganizationId(organizationId) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n \"An organization id is required for getting a list of an organization's facility groupings\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/groupings`)\n .then((groupings) => toCamelCase(groupings));\n }\n\n /**\n * Removes a facility from a facility grouping\n *\n * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'\n * Method: DELETE\n *\n * @param {string} facilityGroupingId UUID corresponding with a facility grouping\n * @param {number} facilityId\n *\n * @returns {Promise}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .catch((err) => console.log(err));\n */\n removeFacility(facilityGroupingId, facilityId) {\n let errorMsg;\n\n if (!facilityGroupingId) {\n errorMsg =\n 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to remove a relationship between a facility grouping and a facility.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request.delete(\n `${this._baseUrl}/groupings/${facilityGroupingId}/facility/${facilityId}`\n );\n }\n\n /**\n * Updates an existing facility grouping\n *\n * API Endpoint: '/groupings/:facilityGroupingId'\n * Method: PUT\n *\n * @param {String} facilityGroupingId\n * @param {Object} update\n * @param {string} [update.description]\n * @param {boolean} [update.isPrivate]\n * @param {string} [update.name]\n * @param {string} [update.parentGroupingId] UUID corresponding with another facility grouping\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping} Information about the updated facility grouping\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.groupings\n * .update('b3dbaae3-25dd-475b-80dc-66296630a8d0', {\n * description: 'US States of CT, MA, ME, NH, RI, VT',\n * isPrivate: false,\n * name: 'New England, USA',\n * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'\n * })\n * .then((grouping) => console.log(grouping))\n * .catch((err) => console.log(err));\n */\n update(facilityGroupingId, update) {\n if (!facilityGroupingId) {\n return Promise.reject(\n new Error(\n 'A facility grouping id is required to update a facility grouping.'\n )\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a facility grouping')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The facility grouping 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', 'organizationId', 'ownerId']\n });\n\n return this._request\n .put(`${this._baseUrl}/groupings/${facilityGroupingId}`, formattedUpdate)\n .then((grouping) => toCamelCase(grouping));\n }\n}\n\nexport default FacilityGroupings;\n"]}
|
package/esm/facilities/index.js
DELETED
|
@@ -1,343 +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 FacilityGroupings from './groupings';
|
|
7
|
-
import CostCenters from './costCenters';
|
|
8
|
-
import { formatFacilityWithInfoFromServer } from '../utils/facilities';
|
|
9
|
-
import { toCamelCase, toSnakeCase } from '../utils/objects';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {Object} Facility
|
|
13
|
-
* @property {string} [address1]
|
|
14
|
-
* @property {string} [address2]
|
|
15
|
-
* @property {string} [assetId] UUID corresponding with an asset
|
|
16
|
-
* @property {string} [city]
|
|
17
|
-
* @property {string} createdAt ISO 8601 Extended Format date/time string
|
|
18
|
-
* @property {string} [geometryId] UUID corresponding with a geometry
|
|
19
|
-
* @property {number} id
|
|
20
|
-
* @property {Object} [Info] User declared information
|
|
21
|
-
* @property {string} name
|
|
22
|
-
* @property {Object} [Organization]
|
|
23
|
-
* @property {string} [Organization.createdAt] ISO 8601 Extended Format date/time string
|
|
24
|
-
* @property {string} [Organization.id] UUID formatted ID
|
|
25
|
-
* @property {string} [Organization.name]
|
|
26
|
-
* @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string
|
|
27
|
-
* @property {string} [state]
|
|
28
|
-
* @property {Object[]} [tags]
|
|
29
|
-
* @property {string} [tags[].createdAt] ISO 8601 Extended Format date/time string
|
|
30
|
-
* @property {number} [tags[].id]
|
|
31
|
-
* @property {number} [tags[].facilityId]
|
|
32
|
-
* @property {string} [tags[].name]
|
|
33
|
-
* @property {string} [tags[].updatedAt] ISO 8601 Extended Format date/time string
|
|
34
|
-
* @property {string} timezone An IANA Time Zone Database string, i.e. America/Los_Angeles
|
|
35
|
-
* @property {number} [weatherLocationId]
|
|
36
|
-
* @property {string} [zip] US Zip Code
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Module that provides access to, and the manipulation
|
|
41
|
-
* of, information about different facilities
|
|
42
|
-
*
|
|
43
|
-
* @typicalname contxtSdk.facilities
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
var Facilities = function () {
|
|
47
|
-
/**
|
|
48
|
-
* @param {Object} sdk An instance of the SDK so the module can communicate with other modules
|
|
49
|
-
* @param {Object} request An instance of the request module tied to this module's audience.
|
|
50
|
-
*/
|
|
51
|
-
function Facilities(sdk, request) {
|
|
52
|
-
_classCallCheck(this, Facilities);
|
|
53
|
-
|
|
54
|
-
var baseUrl = sdk.config.audiences.facilities.host + '/v1';
|
|
55
|
-
|
|
56
|
-
this._baseUrl = baseUrl;
|
|
57
|
-
this._request = request;
|
|
58
|
-
this._sdk = sdk;
|
|
59
|
-
|
|
60
|
-
this.groupings = new FacilityGroupings(sdk, request, baseUrl);
|
|
61
|
-
this.costCenters = new CostCenters(sdk, request, baseUrl);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates a new facility
|
|
66
|
-
*
|
|
67
|
-
* API Endpoint: '/facilities'
|
|
68
|
-
* Method: POST
|
|
69
|
-
*
|
|
70
|
-
* @param {Object} facility
|
|
71
|
-
* @param {string} [facility.address1]
|
|
72
|
-
* @param {string} [facility.address2]
|
|
73
|
-
* @param {string} [facility.assetId] UUID corresponding with an asset
|
|
74
|
-
* @param {string} [facility.city]
|
|
75
|
-
* @param {string} [facility.geometryId] UUID corresponding with a geometry
|
|
76
|
-
* @param {string} facility.name
|
|
77
|
-
* @param {string} facility.organizationId UUID corresponding with an organization
|
|
78
|
-
* @param {string} [facility.state]
|
|
79
|
-
* @param {string} facility.timezone
|
|
80
|
-
* @param {number} [facility.weatherLocationId]
|
|
81
|
-
* @param {string} [facility.zip]
|
|
82
|
-
*
|
|
83
|
-
* @returns {Promise}
|
|
84
|
-
* @fulfill {Facility} Information about the new facility
|
|
85
|
-
* @reject {Error}
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* contxtSdk.facilities
|
|
89
|
-
* .create({
|
|
90
|
-
* address: '221 B Baker St, London, England',
|
|
91
|
-
* name: 'Sherlock Holmes Museum',
|
|
92
|
-
* organizationId: 25
|
|
93
|
-
* })
|
|
94
|
-
* .then((facilities) => console.log(facilities))
|
|
95
|
-
* .catch((err) => console.log(err));
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
_createClass(Facilities, [{
|
|
100
|
-
key: 'create',
|
|
101
|
-
value: function create() {
|
|
102
|
-
var facility = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
103
|
-
|
|
104
|
-
var requiredFields = ['organizationId', 'name', 'timezone'];
|
|
105
|
-
|
|
106
|
-
for (var i = 0; i < requiredFields.length; i++) {
|
|
107
|
-
var field = requiredFields[i];
|
|
108
|
-
|
|
109
|
-
if (!facility[field]) {
|
|
110
|
-
return Promise.reject(new Error('A ' + field + ' is required to create a new facility.'));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return this._request.post(this._baseUrl + '/facilities', toSnakeCase(facility)).then(function (facility) {
|
|
115
|
-
return toCamelCase(facility);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Creates or updates a facility's info (NOTE: This refers to the facility_info model)
|
|
121
|
-
*
|
|
122
|
-
* API Endpoint: '/facilities/:facilityId/info?should_update=true'
|
|
123
|
-
* Method: POST
|
|
124
|
-
*
|
|
125
|
-
* @param {number} facilityId The ID of the facility to update
|
|
126
|
-
* @param {Object} update An object containing the facility info for the facility
|
|
127
|
-
*
|
|
128
|
-
* @returns {Promise}
|
|
129
|
-
* @fulfill {undefined}
|
|
130
|
-
* @reject {Error}
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* contxtSdk.facilities.createOrUpdateInfo(25, {
|
|
134
|
-
* square_feet: '10000'
|
|
135
|
-
* });
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
}, {
|
|
139
|
-
key: 'createOrUpdateInfo',
|
|
140
|
-
value: function createOrUpdateInfo(facilityId, update) {
|
|
141
|
-
if (!facilityId) {
|
|
142
|
-
return Promise.reject(new Error("A facility ID is required to update a facility's info."));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (!update) {
|
|
146
|
-
return Promise.reject(new Error("An update is required to update a facility's info."));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (!isPlainObject(update)) {
|
|
150
|
-
return Promise.reject(new Error('The facility info update must be a well-formed object with the data you wish to update.'));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
var options = {
|
|
154
|
-
params: {
|
|
155
|
-
should_update: true
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
return this._request.post(this._baseUrl + '/facilities/' + facilityId + '/info', update, options);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Deletes a facility
|
|
164
|
-
*
|
|
165
|
-
* API Endpoint: '/facilities/:facilityId'
|
|
166
|
-
* Method: DELETE
|
|
167
|
-
*
|
|
168
|
-
* @param {number} facilityId The ID of the facility
|
|
169
|
-
*
|
|
170
|
-
* @returns {Promise}
|
|
171
|
-
* @fulfill {undefined}
|
|
172
|
-
* @reject {Error}
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* contxtSdk.facilities.delete(25);
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
}, {
|
|
179
|
-
key: 'delete',
|
|
180
|
-
value: function _delete(facilityId) {
|
|
181
|
-
if (!facilityId) {
|
|
182
|
-
return Promise.reject(new Error('A facility ID is required for deleting a facility'));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return this._request.delete(this._baseUrl + '/facilities/' + facilityId);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Gets information about a facility
|
|
190
|
-
*
|
|
191
|
-
* API Endpoint: '/facilities/:facilityId'
|
|
192
|
-
* Method: GET
|
|
193
|
-
*
|
|
194
|
-
* @param {number} facilityId The ID of the facility
|
|
195
|
-
*
|
|
196
|
-
* @returns {Promise}
|
|
197
|
-
* @fulfill {Facility} Information about a facility
|
|
198
|
-
* @reject {Error}
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* contxtSdk.facilities
|
|
202
|
-
* .get(25)
|
|
203
|
-
* .then((facility) => console.log(facility))
|
|
204
|
-
* .catch((err) => console.log(err));
|
|
205
|
-
*/
|
|
206
|
-
|
|
207
|
-
}, {
|
|
208
|
-
key: 'get',
|
|
209
|
-
value: function get(facilityId) {
|
|
210
|
-
if (!facilityId) {
|
|
211
|
-
return Promise.reject(new Error('A facility ID is required for getting information about a facility'));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return this._request.get(this._baseUrl + '/facilities/' + facilityId).then(function (facility) {
|
|
215
|
-
return formatFacilityWithInfoFromServer(facility);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Gets a list of all facilities
|
|
221
|
-
*
|
|
222
|
-
* API Endpoint: '/facilities'
|
|
223
|
-
* Method: GET
|
|
224
|
-
*
|
|
225
|
-
* @returns {Promise}
|
|
226
|
-
* @fulfill {Facility[]} Information about all facilities
|
|
227
|
-
* @reject {Error}
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* contxtSdk.facilities
|
|
231
|
-
* .getAll()
|
|
232
|
-
* .then((facilities) => console.log(facilities))
|
|
233
|
-
* .catch((err) => console.log(err));
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
}, {
|
|
237
|
-
key: 'getAll',
|
|
238
|
-
value: function getAll() {
|
|
239
|
-
return this._request.get(this._baseUrl + '/facilities').then(function (facilities) {
|
|
240
|
-
return facilities.map(function (facility) {
|
|
241
|
-
return formatFacilityWithInfoFromServer(facility);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Gets a list of all facilities that belong to a particular organization
|
|
248
|
-
*
|
|
249
|
-
* API Endpoint: '/organizations/:organizationId/facilities'
|
|
250
|
-
* Method: GET
|
|
251
|
-
*
|
|
252
|
-
* @param {string} organizationId UUID corresponding with an organization
|
|
253
|
-
* @param {object} [options] Object containing parameters to be called with the request
|
|
254
|
-
* @param {boolean} [options.includeGroupings] Boolean flag for including groupings data with each facility
|
|
255
|
-
*
|
|
256
|
-
* @returns {Promise}
|
|
257
|
-
* @fulfill {Facility[]} Information about all facilities
|
|
258
|
-
* @reject {Error}
|
|
259
|
-
*
|
|
260
|
-
* @example
|
|
261
|
-
* contxtSdk.facilities
|
|
262
|
-
* .getAllByOrganizationId(25, { includeGroupings: true })
|
|
263
|
-
* .then((facilities) => console.log(facilities))
|
|
264
|
-
* .catch((err) => console.log(err));
|
|
265
|
-
*/
|
|
266
|
-
|
|
267
|
-
}, {
|
|
268
|
-
key: 'getAllByOrganizationId',
|
|
269
|
-
value: function getAllByOrganizationId(organizationId, options) {
|
|
270
|
-
if (!organizationId) {
|
|
271
|
-
return Promise.reject(new Error("An organization ID is required for getting a list of an organization's facilities"));
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/facilities', {
|
|
275
|
-
params: toSnakeCase(options)
|
|
276
|
-
}).then(function (facilities) {
|
|
277
|
-
return facilities.map(function (facility) {
|
|
278
|
-
return formatFacilityWithInfoFromServer(facility);
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Updates a facility's specifics
|
|
285
|
-
*
|
|
286
|
-
* API Endpoint: '/facilities/:facilityId'
|
|
287
|
-
* Method: PUT
|
|
288
|
-
*
|
|
289
|
-
* @param {number} facilityId The ID of the facility to update
|
|
290
|
-
* @param {Object} update An object containing the updated data for the facility
|
|
291
|
-
* @param {string} [update.address1]
|
|
292
|
-
* @param {string} [update.address2]
|
|
293
|
-
* @param {string} [update.assetId] UUID corresponding with an asset
|
|
294
|
-
* @param {string} [update.city]
|
|
295
|
-
* @param {string} [update.geometryId] UUID corresponding with a geometry
|
|
296
|
-
* @param {Object} [update.info] User declared information
|
|
297
|
-
* @param {string} [update.name]
|
|
298
|
-
* @param {string} [update.organizationId] UUID corresponding with an organization
|
|
299
|
-
* @param {string} [update.state]
|
|
300
|
-
* @param {string} [update.timezone]
|
|
301
|
-
* @param {number} [update.weatherLocationId]
|
|
302
|
-
* @param {string} [update.zip]
|
|
303
|
-
*
|
|
304
|
-
* @returns {Promise}
|
|
305
|
-
* @fulfill {undefined}
|
|
306
|
-
* @reject {Error}
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* contxtSdk.facilities.update(25, {
|
|
310
|
-
* address: '221 B Baker St, London, England',
|
|
311
|
-
* name: 'Sherlock Homes Museum',
|
|
312
|
-
* organizationId: 25
|
|
313
|
-
* });
|
|
314
|
-
*/
|
|
315
|
-
|
|
316
|
-
}, {
|
|
317
|
-
key: 'update',
|
|
318
|
-
value: function update(facilityId, _update) {
|
|
319
|
-
if (!facilityId) {
|
|
320
|
-
return Promise.reject(new Error('A facility ID is required to update a facility.'));
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (!_update) {
|
|
324
|
-
return Promise.reject(new Error('An update is required to update a facility.'));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (!isPlainObject(_update)) {
|
|
328
|
-
return Promise.reject(new Error('The facility update must be a well-formed object with the data you wish to update.'));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
var formattedUpdate = toSnakeCase(_update, {
|
|
332
|
-
excludeKeys: ['id', 'organizationId']
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
return this._request.put(this._baseUrl + '/facilities/' + facilityId, formattedUpdate);
|
|
336
|
-
}
|
|
337
|
-
}]);
|
|
338
|
-
|
|
339
|
-
return Facilities;
|
|
340
|
-
}();
|
|
341
|
-
|
|
342
|
-
export default Facilities;
|
|
343
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["facilities/index.js"],"names":["isPlainObject","FacilityGroupings","CostCenters","formatFacilityWithInfoFromServer","toCamelCase","toSnakeCase","Facilities","sdk","request","baseUrl","config","audiences","facilities","host","_baseUrl","_request","_sdk","groupings","costCenters","facility","requiredFields","i","length","field","Promise","reject","Error","post","then","facilityId","update","options","params","should_update","delete","get","map","organizationId","formattedUpdate","excludeKeys","put"],"mappings":";;;;AAAA,OAAOA,aAAP,MAA0B,sBAA1B;AACA,OAAOC,iBAAP,MAA8B,aAA9B;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,SAASC,gCAAT,QAAiD,qBAAjD;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;;;;;;IAMMC,U;AACJ;;;;AAIA,sBAAYC,GAAZ,EAAiBC,OAAjB,EAA0B;AAAA;;AACxB,QAAMC,UAAaF,IAAIG,MAAJ,CAAWC,SAAX,CAAqBC,UAArB,CAAgCC,IAA7C,QAAN;;AAEA,SAAKC,QAAL,GAAgBL,OAAhB;AACA,SAAKM,QAAL,GAAgBP,OAAhB;AACA,SAAKQ,IAAL,GAAYT,GAAZ;;AAEA,SAAKU,SAAL,GAAiB,IAAIhB,iBAAJ,CAAsBM,GAAtB,EAA2BC,OAA3B,EAAoCC,OAApC,CAAjB;AACA,SAAKS,WAAL,GAAmB,IAAIhB,WAAJ,CAAgBK,GAAhB,EAAqBC,OAArB,EAA8BC,OAA9B,CAAnB;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,UAAL,EAAiB;AACf,eAAOL,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,iDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACI,OAAL,EAAa;AACX,eAAON,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,6CAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAAC1B,cAAc8B,OAAd,CAAL,EAA4B;AAC1B,eAAON,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,oFADF,CADK,CAAP;AAKD;;AAED,UAAMY,kBAAkBjC,YAAYyB,OAAZ,EAAoB;AAC1CS,qBAAa,CAAC,IAAD,EAAO,gBAAP;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAKxB,QAAL,CAAcyB,GAAd,CACF,KAAK1B,QADH,oBAC0Be,UAD1B,EAELS,eAFK,CAAP;AAID;;;;;;AAGH,eAAehC,UAAf","file":"index.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport FacilityGroupings from './groupings';\nimport CostCenters from './costCenters';\nimport { formatFacilityWithInfoFromServer } from '../utils/facilities';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} Facility\n * @property {string} [address1]\n * @property {string} [address2]\n * @property {string} [assetId] UUID corresponding with an asset\n * @property {string} [city]\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} [geometryId] UUID corresponding with a geometry\n * @property {number} id\n * @property {Object} [Info] User declared information\n * @property {string} name\n * @property {Object} [Organization]\n * @property {string} [Organization.createdAt] ISO 8601 Extended Format date/time string\n * @property {string} [Organization.id] UUID formatted ID\n * @property {string} [Organization.name]\n * @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string\n * @property {string} [state]\n * @property {Object[]} [tags]\n * @property {string} [tags[].createdAt] ISO 8601 Extended Format date/time string\n * @property {number} [tags[].id]\n * @property {number} [tags[].facilityId]\n * @property {string} [tags[].name]\n * @property {string} [tags[].updatedAt] ISO 8601 Extended Format date/time string\n * @property {string} timezone An IANA Time Zone Database string, i.e. America/Los_Angeles\n * @property {number} [weatherLocationId]\n * @property {string} [zip] US Zip Code\n */\n\n/**\n * Module that provides access to, and the manipulation\n * of, information about different facilities\n *\n * @typicalname contxtSdk.facilities\n */\nclass Facilities {\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 */\n constructor(sdk, request) {\n const baseUrl = `${sdk.config.audiences.facilities.host}/v1`;\n\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n\n this.groupings = new FacilityGroupings(sdk, request, baseUrl);\n this.costCenters = new CostCenters(sdk, request, baseUrl);\n }\n\n /**\n * Creates a new facility\n *\n * API Endpoint: '/facilities'\n * Method: POST\n *\n * @param {Object} facility\n * @param {string} [facility.address1]\n * @param {string} [facility.address2]\n * @param {string} [facility.assetId] UUID corresponding with an asset\n * @param {string} [facility.city]\n * @param {string} [facility.geometryId] UUID corresponding with a geometry\n * @param {string} facility.name\n * @param {string} facility.organizationId UUID corresponding with an organization\n * @param {string} [facility.state]\n * @param {string} facility.timezone\n * @param {number} [facility.weatherLocationId]\n * @param {string} [facility.zip]\n *\n * @returns {Promise}\n * @fulfill {Facility} Information about the new facility\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .create({\n * address: '221 B Baker St, London, England',\n * name: 'Sherlock Holmes Museum',\n * organizationId: 25\n * })\n * .then((facilities) => console.log(facilities))\n * .catch((err) => console.log(err));\n */\n create(facility = {}) {\n const requiredFields = ['organizationId', 'name', 'timezone'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!facility[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new facility.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/facilities`, toSnakeCase(facility))\n .then((facility) => toCamelCase(facility));\n }\n\n /**\n * Creates or updates a facility's info (NOTE: This refers to the facility_info model)\n *\n * API Endpoint: '/facilities/:facilityId/info?should_update=true'\n * Method: POST\n *\n * @param {number} facilityId The ID of the facility to update\n * @param {Object} update An object containing the facility info for the facility\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.createOrUpdateInfo(25, {\n * square_feet: '10000'\n * });\n */\n createOrUpdateInfo(facilityId, update) {\n if (!facilityId) {\n return Promise.reject(\n new Error(\"A facility ID is required to update a facility's info.\")\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error(\"An update is required to update a facility's info.\")\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The facility info update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n const options = {\n params: {\n should_update: true\n }\n };\n\n return this._request.post(\n `${this._baseUrl}/facilities/${facilityId}/info`,\n update,\n options\n );\n }\n\n /**\n * Deletes a facility\n *\n * API Endpoint: '/facilities/:facilityId'\n * Method: DELETE\n *\n * @param {number} facilityId The ID of the facility\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.delete(25);\n */\n delete(facilityId) {\n if (!facilityId) {\n return Promise.reject(\n new Error('A facility ID is required for deleting a facility')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/facilities/${facilityId}`);\n }\n\n /**\n * Gets information about a facility\n *\n * API Endpoint: '/facilities/:facilityId'\n * Method: GET\n *\n * @param {number} facilityId The ID of the facility\n *\n * @returns {Promise}\n * @fulfill {Facility} Information about a facility\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .get(25)\n * .then((facility) => console.log(facility))\n * .catch((err) => console.log(err));\n */\n get(facilityId) {\n if (!facilityId) {\n return Promise.reject(\n new Error(\n 'A facility ID is required for getting information about a facility'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/facilities/${facilityId}`)\n .then((facility) => formatFacilityWithInfoFromServer(facility));\n }\n\n /**\n * Gets a list of all facilities\n *\n * API Endpoint: '/facilities'\n * Method: GET\n *\n * @returns {Promise}\n * @fulfill {Facility[]} Information about all facilities\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .getAll()\n * .then((facilities) => console.log(facilities))\n * .catch((err) => console.log(err));\n */\n getAll() {\n return this._request\n .get(`${this._baseUrl}/facilities`)\n .then((facilities) =>\n facilities.map((facility) => formatFacilityWithInfoFromServer(facility))\n );\n }\n\n /**\n * Gets a list of all facilities that belong to a particular organization\n *\n * API Endpoint: '/organizations/:organizationId/facilities'\n * Method: GET\n *\n * @param {string} organizationId UUID corresponding with an organization\n * @param {object} [options] Object containing parameters to be called with the request\n * @param {boolean} [options.includeGroupings] Boolean flag for including groupings data with each facility\n *\n * @returns {Promise}\n * @fulfill {Facility[]} Information about all facilities\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities\n * .getAllByOrganizationId(25, { includeGroupings: true })\n * .then((facilities) => console.log(facilities))\n * .catch((err) => console.log(err));\n */\n getAllByOrganizationId(organizationId, options) {\n if (!organizationId) {\n return Promise.reject(\n new Error(\n \"An organization ID is required for getting a list of an organization's facilities\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/facilities`, {\n params: toSnakeCase(options)\n })\n .then((facilities) =>\n facilities.map((facility) => formatFacilityWithInfoFromServer(facility))\n );\n }\n\n /**\n * Updates a facility's specifics\n *\n * API Endpoint: '/facilities/:facilityId'\n * Method: PUT\n *\n * @param {number} facilityId The ID of the facility to update\n * @param {Object} update An object containing the updated data for the facility\n * @param {string} [update.address1]\n * @param {string} [update.address2]\n * @param {string} [update.assetId] UUID corresponding with an asset\n * @param {string} [update.city]\n * @param {string} [update.geometryId] UUID corresponding with a geometry\n * @param {Object} [update.info] User declared information\n * @param {string} [update.name]\n * @param {string} [update.organizationId] UUID corresponding with an organization\n * @param {string} [update.state]\n * @param {string} [update.timezone]\n * @param {number} [update.weatherLocationId]\n * @param {string} [update.zip]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.update(25, {\n * address: '221 B Baker St, London, England',\n * name: 'Sherlock Homes Museum',\n * organizationId: 25\n * });\n */\n update(facilityId, update) {\n if (!facilityId) {\n return Promise.reject(\n new Error('A facility ID is required to update a facility.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a facility.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The facility 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', 'organizationId']\n });\n\n return this._request.put(\n `${this._baseUrl}/facilities/${facilityId}`,\n formattedUpdate\n );\n }\n}\n\nexport default Facilities;\n"]}
|
package/esm/health/index.js
DELETED
|
@@ -1,229 +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 { formatPaginatedDataFromServer } from '../utils/pagination';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {Object} HealthStatus
|
|
9
|
-
* @property {string} status A health status of value 'healthy' or 'unhealthy'
|
|
10
|
-
* @property {string} timestamp ISO 8601 Extended Format date/time string
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {Object} HealthAsset
|
|
15
|
-
* @augments Asset
|
|
16
|
-
* @property {HealthStatus} health
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @interface PaginatedResponse
|
|
21
|
-
* @template RecordType
|
|
22
|
-
* @typedef {Object} PaginatedResponse
|
|
23
|
-
* @property {Object} _metadata Metadata about the pagination settings
|
|
24
|
-
* @property {number} _metadata.offset Offset of records in subsequent queries
|
|
25
|
-
* @property {number} _metadata.totalRecords Total number of asset types found
|
|
26
|
-
* @property {Array.<RecordType>} records
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @typedef {PaginatedResponse.<HealthAsset>} HealthAssetPaginatedResponse
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {PaginatedResponse.<HealthStatus>} HealthStatusPaginatedResponse
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Module that provides access to the Contxt Health Service
|
|
39
|
-
*
|
|
40
|
-
* @typicalname contxtSdk.health
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
var Health = function () {
|
|
44
|
-
/**
|
|
45
|
-
* @param {Object} sdk An instance of the SDK so the module can communicate with other modules
|
|
46
|
-
* @param {Object} request An instance of the request module tied to this module's audience.
|
|
47
|
-
* @param {string} [organizationId] The organization ID to be used in tenant url requests
|
|
48
|
-
*/
|
|
49
|
-
function Health(sdk, request) {
|
|
50
|
-
var organizationId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
51
|
-
|
|
52
|
-
_classCallCheck(this, Health);
|
|
53
|
-
|
|
54
|
-
var baseUrl = sdk.config.audiences.health.host + '/v1';
|
|
55
|
-
|
|
56
|
-
this._baseUrl = baseUrl;
|
|
57
|
-
this._request = request;
|
|
58
|
-
this._sdk = sdk;
|
|
59
|
-
|
|
60
|
-
this._organizationId = organizationId;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The health status option constants
|
|
65
|
-
* @enum {string}
|
|
66
|
-
* @static
|
|
67
|
-
* @example
|
|
68
|
-
* console.log(Health.GOOD) //healthy
|
|
69
|
-
* console.log(Health.BAD) //unhealthy
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_createClass(Health, [{
|
|
74
|
-
key: 'getAll',
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Gets all of an organization's assets and their most recent health status
|
|
79
|
-
*
|
|
80
|
-
* API Endpoint: '/:organizationId/assets'
|
|
81
|
-
* Method: GET
|
|
82
|
-
*
|
|
83
|
-
* @param {Object} options
|
|
84
|
-
* @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
|
|
85
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
86
|
-
* @returns {Promise}
|
|
87
|
-
* @fulfill {HealthAssetPaginatedResponse} Information about all contxt applications
|
|
88
|
-
* @reject {Error}
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* contxtSdk.health
|
|
92
|
-
* .getAll({
|
|
93
|
-
* organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'
|
|
94
|
-
* }, {
|
|
95
|
-
* limit: 50,
|
|
96
|
-
* offset: 100
|
|
97
|
-
* })
|
|
98
|
-
* .then((healthAssetRecords) => console.log(healthAssetRecords))
|
|
99
|
-
* .catch((err) => console.log(err));
|
|
100
|
-
*/
|
|
101
|
-
value: function getAll(_ref, paginationOptions) {
|
|
102
|
-
var _ref$organizationId = _ref.organizationId,
|
|
103
|
-
organizationId = _ref$organizationId === undefined ? this._organizationId : _ref$organizationId;
|
|
104
|
-
|
|
105
|
-
if (!organizationId) {
|
|
106
|
-
return Promise.reject(new Error('An organization ID is required'));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return this._request.get(this._baseUrl + '/' + organizationId + '/assets', {
|
|
110
|
-
params: paginationOptions
|
|
111
|
-
}).then(function (response) {
|
|
112
|
-
return formatPaginatedDataFromServer(response);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Gets a list of health statuses for a single asset
|
|
118
|
-
*
|
|
119
|
-
* API Endpoint: '/:organizationId/assets/:assetId'
|
|
120
|
-
* Method: GET
|
|
121
|
-
*
|
|
122
|
-
* @param {Object} options
|
|
123
|
-
* @param {string} options.assetId The asset id to get the health for
|
|
124
|
-
* @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
|
|
125
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
126
|
-
* @returns {Promise}
|
|
127
|
-
* @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications
|
|
128
|
-
* @reject {Error}
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* contxtSdk.health
|
|
132
|
-
* .getByAssetId({
|
|
133
|
-
* assetId: '9859f22d-cc45-4015-8674-1671f54d1888',
|
|
134
|
-
* organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'
|
|
135
|
-
* }, {
|
|
136
|
-
* limit: 50,
|
|
137
|
-
* offset: 100
|
|
138
|
-
* })
|
|
139
|
-
* .then((healthStatusRecords) => console.log(healthStatusRecords))
|
|
140
|
-
* .catch((err) => console.log(err));
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
}, {
|
|
144
|
-
key: 'getByAssetId',
|
|
145
|
-
value: function getByAssetId(_ref2, paginationOptions) {
|
|
146
|
-
var assetId = _ref2.assetId,
|
|
147
|
-
_ref2$organizationId = _ref2.organizationId,
|
|
148
|
-
organizationId = _ref2$organizationId === undefined ? this._organizationId : _ref2$organizationId;
|
|
149
|
-
|
|
150
|
-
if (!assetId) {
|
|
151
|
-
return Promise.reject(new Error('An asset ID is required'));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!organizationId) {
|
|
155
|
-
return Promise.reject(new Error('An organization ID is required'));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return this._request.get(this._baseUrl + '/' + organizationId + '/assets/' + assetId, {
|
|
159
|
-
params: paginationOptions
|
|
160
|
-
}).then(function (response) {
|
|
161
|
-
return formatPaginatedDataFromServer(response);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Creates a new health status entry for an asset
|
|
167
|
-
*
|
|
168
|
-
* API Endpoint: '/:organizationId/assets/:assetId'
|
|
169
|
-
* Method: POST
|
|
170
|
-
*
|
|
171
|
-
* @param {Object} options
|
|
172
|
-
* @param {string} options.assetId The asset id to get the health for
|
|
173
|
-
* @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
|
|
174
|
-
* @param {string} options.status The health of the asset. One of type Health.status.GOOD or Health.status.BAD
|
|
175
|
-
* @param {string} [options.timestamp] Defaults to now. ISO 8601 Extended Format date/time string
|
|
176
|
-
* @returns {Promise}
|
|
177
|
-
* @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications
|
|
178
|
-
* @reject {Error}
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* contxtSdk.health
|
|
182
|
-
* .post({
|
|
183
|
-
* assetId: '9859f22d-cc45-4015-8674-1671f54d1888',
|
|
184
|
-
* organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83',
|
|
185
|
-
* status: contxtSdk.health.status.GOOD
|
|
186
|
-
* })
|
|
187
|
-
* .then((healthStatus) => console.log(healthStatus))
|
|
188
|
-
* .catch((err) => console.log(err));
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
|
-
}, {
|
|
192
|
-
key: 'post',
|
|
193
|
-
value: function post(_ref3) {
|
|
194
|
-
var assetId = _ref3.assetId,
|
|
195
|
-
_ref3$organizationId = _ref3.organizationId,
|
|
196
|
-
organizationId = _ref3$organizationId === undefined ? this._organizationId : _ref3$organizationId,
|
|
197
|
-
status = _ref3.status,
|
|
198
|
-
timestamp = _ref3.timestamp;
|
|
199
|
-
|
|
200
|
-
if (!assetId) {
|
|
201
|
-
return Promise.reject(new Error('An asset ID is required'));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (!organizationId) {
|
|
205
|
-
return Promise.reject(new Error('An organization ID is required'));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!Object.values(Health.status).includes(status)) {
|
|
209
|
-
return Promise.reject(new Error('Status must equal one of: ' + Object.values(Health.status).join(', ')));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return this._request.post(this._baseUrl + '/' + organizationId + '/assets/' + assetId, {
|
|
213
|
-
status: status,
|
|
214
|
-
timestamp: timestamp
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}]);
|
|
218
|
-
|
|
219
|
-
return Health;
|
|
220
|
-
}();
|
|
221
|
-
|
|
222
|
-
Health.status = {
|
|
223
|
-
GOOD: 'healthy',
|
|
224
|
-
BAD: 'unhealthy'
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
export default Health;
|
|
229
|
-
//# sourceMappingURL=index.js.map
|
package/esm/health/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["health/index.js"],"names":["formatPaginatedDataFromServer","Health","sdk","request","organizationId","baseUrl","config","audiences","health","host","_baseUrl","_request","_sdk","_organizationId","paginationOptions","Promise","reject","Error","get","params","then","response","assetId","status","timestamp","Object","values","includes","join","post","GOOD","BAD"],"mappings":";;;;AAAA,SAASA,6BAAT,QAA8C,qBAA9C;;AAEA;;;;;;AAMA;;;;;;AAMA;;;;;;;;;;AAUA;;;;AAIA;;;;AAIA;;;;;;IAKMC,M;AACJ;;;;;AAKA,kBAAYC,GAAZ,EAAiBC,OAAjB,EAAiD;AAAA,QAAvBC,cAAuB,uEAAN,IAAM;;AAAA;;AAC/C,QAAMC,UAAaH,IAAII,MAAJ,CAAWC,SAAX,CAAqBC,MAArB,CAA4BC,IAAzC,QAAN;;AAEA,SAAKC,QAAL,GAAgBL,OAAhB;AACA,SAAKM,QAAL,GAAgBR,OAAhB;AACA,SAAKS,IAAL,GAAYV,GAAZ;;AAEA,SAAKW,eAAL,GAAuBT,cAAvB;AACD;;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SAAa,SAAbA,SAAa;;AAC1E,UAAI,CAACF,OAAL,EAAc;AACZ,eAAOP,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAU,yBAAV,CAAf,CAAP;AACD;;AAED,UAAI,CAACb,cAAL,EAAqB;AACnB,eAAOW,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAU,gCAAV,CAAf,CAAP;AACD;;AAED,UAAI,CAACQ,OAAOC,MAAP,CAAczB,OAAOsB,MAArB,EAA6BI,QAA7B,CAAsCJ,MAAtC,CAAL,EAAoD;AAClD,eAAOR,QAAQC,MAAR,CACL,IAAIC,KAAJ,gCAC+BQ,OAAOC,MAAP,CAAczB,OAAOsB,MAArB,EAA6BK,IAA7B,CAAkC,IAAlC,CAD/B,CADK,CAAP;AAKD;;AAED,aAAO,KAAKjB,QAAL,CAAckB,IAAd,CACF,KAAKnB,QADH,SACeN,cADf,gBACwCkB,OADxC,EAEL;AACEC,sBADF;AAEEC;AAFF,OAFK,CAAP;AAOD;;;;;;AA/JGvB,M,CAwBGsB,M,GAAS;AACdO,QAAM,SADQ;AAEdC,OAAK;AAFS,C;;;AA0IlB,eAAe9B,MAAf","file":"index.js","sourcesContent":["import { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} HealthStatus\n * @property {string} status A health status of value 'healthy' or 'unhealthy'\n * @property {string} timestamp ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} HealthAsset\n * @augments Asset\n * @property {HealthStatus} health\n */\n\n/**\n * @interface PaginatedResponse\n * @template RecordType\n * @typedef {Object} PaginatedResponse\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 {Array.<RecordType>} records\n */\n\n/**\n * @typedef {PaginatedResponse.<HealthAsset>} HealthAssetPaginatedResponse\n */\n\n/**\n * @typedef {PaginatedResponse.<HealthStatus>} HealthStatusPaginatedResponse\n */\n\n/**\n * Module that provides access to the Contxt Health Service\n *\n * @typicalname contxtSdk.health\n */\nclass Health {\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} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(sdk, request, organizationId = null) {\n const baseUrl = `${sdk.config.audiences.health.host}/v1`;\n\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n\n this._organizationId = organizationId;\n }\n\n /**\n * The health status option constants\n * @enum {string}\n * @static\n * @example\n * console.log(Health.GOOD) //healthy\n * console.log(Health.BAD) //unhealthy\n */\n static status = {\n GOOD: 'healthy',\n BAD: 'unhealthy'\n };\n\n /**\n * Gets all of an organization's assets and their most recent health status\n *\n * API Endpoint: '/:organizationId/assets'\n * Method: GET\n *\n * @param {Object} options\n * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.\n * @param {PaginationOptions} [paginationOptions]\n * @returns {Promise}\n * @fulfill {HealthAssetPaginatedResponse} Information about all contxt applications\n * @reject {Error}\n *\n * @example\n * contxtSdk.health\n * .getAll({\n * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'\n * }, {\n * limit: 50,\n * offset: 100\n * })\n * .then((healthAssetRecords) => console.log(healthAssetRecords))\n * .catch((err) => console.log(err));\n */\n getAll({ organizationId = this._organizationId }, paginationOptions) {\n if (!organizationId) {\n return Promise.reject(new Error('An organization ID is required'));\n }\n\n return this._request\n .get(`${this._baseUrl}/${organizationId}/assets`, {\n params: paginationOptions\n })\n .then((response) => formatPaginatedDataFromServer(response));\n }\n\n /**\n * Gets a list of health statuses for a single asset\n *\n * API Endpoint: '/:organizationId/assets/:assetId'\n * Method: GET\n *\n * @param {Object} options\n * @param {string} options.assetId The asset id to get the health for\n * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.\n * @param {PaginationOptions} [paginationOptions]\n * @returns {Promise}\n * @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications\n * @reject {Error}\n *\n * @example\n * contxtSdk.health\n * .getByAssetId({\n * assetId: '9859f22d-cc45-4015-8674-1671f54d1888',\n * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'\n * }, {\n * limit: 50,\n * offset: 100\n * })\n * .then((healthStatusRecords) => console.log(healthStatusRecords))\n * .catch((err) => console.log(err));\n */\n getByAssetId(\n { assetId, organizationId = this._organizationId },\n paginationOptions\n ) {\n if (!assetId) {\n return Promise.reject(new Error('An asset ID is required'));\n }\n\n if (!organizationId) {\n return Promise.reject(new Error('An organization ID is required'));\n }\n\n return this._request\n .get(`${this._baseUrl}/${organizationId}/assets/${assetId}`, {\n params: paginationOptions\n })\n .then((response) => formatPaginatedDataFromServer(response));\n }\n\n /**\n * Creates a new health status entry for an asset\n *\n * API Endpoint: '/:organizationId/assets/:assetId'\n * Method: POST\n *\n * @param {Object} options\n * @param {string} options.assetId The asset id to get the health for\n * @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.\n * @param {string} options.status The health of the asset. One of type Health.status.GOOD or Health.status.BAD\n * @param {string} [options.timestamp] Defaults to now. ISO 8601 Extended Format date/time string\n * @returns {Promise}\n * @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications\n * @reject {Error}\n *\n * @example\n * contxtSdk.health\n * .post({\n * assetId: '9859f22d-cc45-4015-8674-1671f54d1888',\n * organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83',\n * status: contxtSdk.health.status.GOOD\n * })\n * .then((healthStatus) => console.log(healthStatus))\n * .catch((err) => console.log(err));\n */\n post({ assetId, organizationId = this._organizationId, status, timestamp }) {\n if (!assetId) {\n return Promise.reject(new Error('An asset ID is required'));\n }\n\n if (!organizationId) {\n return Promise.reject(new Error('An organization ID is required'));\n }\n\n if (!Object.values(Health.status).includes(status)) {\n return Promise.reject(\n new Error(\n `Status must equal one of: ${Object.values(Health.status).join(', ')}`\n )\n );\n }\n\n return this._request.post(\n `${this._baseUrl}/${organizationId}/assets/${assetId}`,\n {\n status,\n timestamp\n }\n );\n }\n}\n\nexport default Health;\n"]}
|