@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.
Files changed (169) hide show
  1. package/.gitattributes +1 -0
  2. package/.nvmrc +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/docs/Facilities.md +0 -144
  5. package/docs/FacilityGroupings.md +0 -160
  6. package/docs/Nionic.md +63 -0
  7. package/docs/README.md +3 -29
  8. package/docs/Typedefs.md +0 -101
  9. package/esm/config/audiences.js +13 -13
  10. package/esm/config/audiences.js.map +1 -1
  11. package/esm/index.js +3 -6
  12. package/esm/index.js.map +1 -1
  13. package/esm/nionic/index.js +126 -0
  14. package/esm/nionic/index.js.map +1 -0
  15. package/lib/config/audiences.js +13 -13
  16. package/lib/config/audiences.js.map +1 -1
  17. package/lib/index.js +19 -13
  18. package/lib/index.js.map +1 -1
  19. package/lib/nionic/index.js +130 -0
  20. package/lib/nionic/index.js.map +1 -0
  21. package/meta.yaml +11 -0
  22. package/package.json +9 -10
  23. package/src/bus/index.spec.js +3 -2
  24. package/src/bus/webSocketConnection.spec.js +31 -31
  25. package/src/config/audiences.js +13 -13
  26. package/src/config/index.spec.js +6 -6
  27. package/src/coordinator/applications.spec.js +8 -8
  28. package/src/coordinator/consent.spec.js +1 -1
  29. package/src/coordinator/edgeNodes.spec.js +3 -3
  30. package/src/coordinator/organizations.spec.js +4 -4
  31. package/src/coordinator/permissions.spec.js +4 -4
  32. package/src/coordinator/roles.spec.js +3 -3
  33. package/src/coordinator/users.spec.js +14 -15
  34. package/src/events/index.spec.js +16 -16
  35. package/src/files/index.spec.js +7 -7
  36. package/src/index.js +3 -6
  37. package/src/index.spec.js +8 -22
  38. package/src/iot/feeds.spec.js +4 -4
  39. package/src/iot/fieldCategories.spec.js +4 -4
  40. package/src/iot/fieldGroupings.spec.js +5 -5
  41. package/src/iot/outputs.spec.js +6 -6
  42. package/src/nionic/index.js +151 -0
  43. package/src/request.spec.js +3 -3
  44. package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
  45. package/src/sessionTypes/index.spec.js +3 -3
  46. package/src/sessionTypes/machineAuth.spec.js +3 -3
  47. package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
  48. package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
  49. package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
  50. package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
  51. package/src/utils/url/stringifyParams.spec.js +2 -3
  52. package/support/fixtures/factories/IOSDevice.js +3 -3
  53. package/support/fixtures/factories/applicationGrouping.js +4 -4
  54. package/support/fixtures/factories/applicationModule.js +2 -2
  55. package/support/fixtures/factories/asset.js +1 -1
  56. package/support/fixtures/factories/assetAttribute.js +2 -2
  57. package/support/fixtures/factories/assetAttributeValue.js +2 -2
  58. package/support/fixtures/factories/assetMetric.js +1 -1
  59. package/support/fixtures/factories/assetMetricValue.js +3 -3
  60. package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
  61. package/support/fixtures/factories/assetType.js +1 -1
  62. package/support/fixtures/factories/authResults.js +3 -3
  63. package/support/fixtures/factories/channel.js +1 -1
  64. package/support/fixtures/factories/contxtApplication.js +5 -5
  65. package/support/fixtures/factories/contxtOrganization.js +2 -2
  66. package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
  67. package/support/fixtures/factories/contxtProject.js +2 -2
  68. package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
  69. package/support/fixtures/factories/contxtRole.js +3 -3
  70. package/support/fixtures/factories/contxtRoleApplication.js +1 -1
  71. package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
  72. package/support/fixtures/factories/contxtUser.js +2 -2
  73. package/support/fixtures/factories/contxtUserApplication.js +1 -1
  74. package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
  75. package/support/fixtures/factories/contxtUserPermissions.js +5 -5
  76. package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
  77. package/support/fixtures/factories/contxtUserRole.js +2 -2
  78. package/support/fixtures/factories/costCenter.js +2 -2
  79. package/support/fixtures/factories/costCenterFacility.js +3 -3
  80. package/support/fixtures/factories/edgeNode.js +1 -1
  81. package/support/fixtures/factories/event.js +5 -5
  82. package/support/fixtures/factories/eventType.js +4 -4
  83. package/support/fixtures/factories/eventUser.js +5 -5
  84. package/support/fixtures/factories/facility.js +4 -4
  85. package/support/fixtures/factories/facilityGrouping.js +3 -3
  86. package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
  87. package/support/fixtures/factories/facilityInfo.js +2 -2
  88. package/support/fixtures/factories/facilityTag.js +1 -1
  89. package/support/fixtures/factories/feedStatus.js +1 -1
  90. package/support/fixtures/factories/feedType.js +1 -1
  91. package/support/fixtures/factories/feeds.js +5 -5
  92. package/support/fixtures/factories/fieldCategory.js +3 -3
  93. package/support/fixtures/factories/fieldGrouping.js +4 -4
  94. package/support/fixtures/factories/fieldGroupingField.js +3 -3
  95. package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
  96. package/support/fixtures/factories/file.js +1 -1
  97. package/support/fixtures/factories/fileUploadInfo.js +1 -1
  98. package/support/fixtures/factories/organization.js +1 -1
  99. package/support/fixtures/factories/outputField.js +10 -10
  100. package/support/fixtures/factories/outputFieldData.js +1 -1
  101. package/support/fixtures/factories/owner.js +2 -2
  102. package/support/fixtures/factories/paginationMetadata.js +2 -2
  103. package/support/fixtures/factories/triggeredEvent.js +4 -4
  104. package/support/fixtures/factories/userEventSubscription.js +1 -1
  105. package/support/fixtures/factories/userMobileNumber.js +1 -1
  106. package/support/fixtures/factories/userPermissionsMap.js +2 -2
  107. package/.envrc +0 -0
  108. package/.huskyrc.js +0 -11
  109. package/.nycrc +0 -12
  110. package/esm/assets/assetAttributes.js +0 -574
  111. package/esm/assets/assetAttributes.js.map +0 -1
  112. package/esm/assets/assetMetrics.js +0 -690
  113. package/esm/assets/assetMetrics.js.map +0 -1
  114. package/esm/assets/assetTypes.js +0 -273
  115. package/esm/assets/assetTypes.js.map +0 -1
  116. package/esm/assets/index.js +0 -283
  117. package/esm/assets/index.js.map +0 -1
  118. package/esm/facilities/costCenters.js +0 -306
  119. package/esm/facilities/costCenters.js.map +0 -1
  120. package/esm/facilities/groupings.js +0 -323
  121. package/esm/facilities/groupings.js.map +0 -1
  122. package/esm/facilities/index.js +0 -343
  123. package/esm/facilities/index.js.map +0 -1
  124. package/esm/health/index.js +0 -229
  125. package/esm/health/index.js.map +0 -1
  126. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  127. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  128. package/esm/utils/facilities/index.js +0 -4
  129. package/esm/utils/facilities/index.js.map +0 -1
  130. package/lib/assets/assetAttributes.js +0 -588
  131. package/lib/assets/assetAttributes.js.map +0 -1
  132. package/lib/assets/assetMetrics.js +0 -705
  133. package/lib/assets/assetMetrics.js.map +0 -1
  134. package/lib/assets/assetTypes.js +0 -287
  135. package/lib/assets/assetTypes.js.map +0 -1
  136. package/lib/assets/index.js +0 -302
  137. package/lib/assets/index.js.map +0 -1
  138. package/lib/facilities/costCenters.js +0 -316
  139. package/lib/facilities/costCenters.js.map +0 -1
  140. package/lib/facilities/groupings.js +0 -333
  141. package/lib/facilities/groupings.js.map +0 -1
  142. package/lib/facilities/index.js +0 -360
  143. package/lib/facilities/index.js.map +0 -1
  144. package/lib/health/index.js +0 -232
  145. package/lib/health/index.js.map +0 -1
  146. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  147. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  148. package/lib/utils/facilities/index.js +0 -15
  149. package/lib/utils/facilities/index.js.map +0 -1
  150. package/src/assets/assetAttributes.js +0 -619
  151. package/src/assets/assetAttributes.spec.js +0 -1143
  152. package/src/assets/assetMetrics.js +0 -736
  153. package/src/assets/assetMetrics.spec.js +0 -1180
  154. package/src/assets/assetTypes.js +0 -260
  155. package/src/assets/assetTypes.spec.js +0 -556
  156. package/src/assets/index.js +0 -271
  157. package/src/assets/index.spec.js +0 -515
  158. package/src/facilities/costCenters.js +0 -295
  159. package/src/facilities/costCenters.spec.js +0 -529
  160. package/src/facilities/groupings.js +0 -320
  161. package/src/facilities/groupings.spec.js +0 -567
  162. package/src/facilities/index.js +0 -343
  163. package/src/facilities/index.spec.js +0 -551
  164. package/src/health/index.js +0 -200
  165. package/src/health/index.spec.js +0 -501
  166. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  167. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  168. package/src/utils/facilities/index.js +0 -3
  169. package/tmp/package.json +0 -11
@@ -1 +0,0 @@
1
- {"version":3,"sources":["assets/index.js"],"names":["isPlainObject","AssetAttributes","AssetMetrics","AssetTypes","toCamelCase","toSnakeCase","formatPaginatedDataFromServer","Assets","sdk","request","baseUrl","config","audiences","facilities","host","_baseUrl","_request","_sdk","attributes","types","metrics","asset","requiredFields","i","length","field","Promise","reject","Error","post","then","assetId","delete","get","paginationOptions","params","assetsData","organizationId","options","update","formattedUpdate","excludeKeys","put"],"mappings":";;;;AAAA,OAAOA,aAAP,MAA0B,sBAA1B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,UAAP,MAAuB,cAAvB;;AAEA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;AACA,SAASC,6BAAT,QAA8C,qBAA9C;;AAEA;;;;;;;;;;;AAWA;;;;;;;;AAQA;;;;;;IAKMC,M;AACJ;;;;AAIA,kBAAYC,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,S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b,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,iFADF,CADK,CAAP;AAKD;;AAED,UAAMY,kBAAkBnC,YAAYkC,OAAZ,EAAoB;AAC1CE,qBAAa,CAAC,aAAD,EAAgB,IAAhB,EAAsB,OAAtB,EAA+B,gBAA/B;AAD6B,OAApB,CAAxB;;AAIA,aAAO,KAAKzB,QAAL,CACJ0B,GADI,CACG,KAAK3B,QADR,gBAC2BgB,OAD3B,EACsCS,eADtC,EAEJV,IAFI,CAEC,UAACT,KAAD;AAAA,eAAWjB,YAAYiB,KAAZ,CAAX;AAAA,OAFD,CAAP;AAGD;;;;;;AAGH,eAAed,MAAf","file":"index.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport AssetAttributes from './assetAttributes';\nimport AssetMetrics from './assetMetrics';\nimport AssetTypes from './assetTypes';\n\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\nimport { formatPaginatedDataFromServer } from '../utils/pagination';\n\n/**\n * @typedef {Object} Asset\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} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} AssetsFromServer\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 {Asset[]} records\n */\n\n/**\n * Module that provides access to, and the manipulation of, information about different assets\n *\n * @typicalname contxtSdk.assets\n */\nclass Assets {\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.attributes = new AssetAttributes(sdk, request, baseUrl);\n this.types = new AssetTypes(sdk, request, baseUrl);\n this.metrics = new AssetMetrics(sdk, request, baseUrl);\n }\n\n /**\n * Creates a new asset\n *\n * API Endpoint: '/assets'\n * Method: POST\n *\n * @param {Object} asset\n * @param {string} asset.assetTypeId UUID\n * @param {string} [asset.description]\n * @param {string} asset.label\n * @param {string} asset.organizationId UUID\n *\n * @returns {Promise}\n * @fulfill {Asset} information about the new asset\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .create({\n * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d',\n * description: '221B Baker Street, London',\n * label: 'Sherlock Homes Museum',\n * organizationId: 'b47e45af-3e18-408a-8070-008f9e6d7b42'\n * })\n * .then((asset) => console.log(asset))\n * .catch((err) => console.log(err));\n */\n create(asset = {}) {\n const requiredFields = ['assetTypeId', 'label', 'organizationId'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!asset[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new asset.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/assets`, toSnakeCase(asset))\n .then((asset) => toCamelCase(asset));\n }\n\n /**\n * Deletes an asset\n *\n * API Endpoint: '/assets/:assetId'\n * Method: DELETE\n *\n * @param {string} assetId The ID of the asset (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets.delete('0b51429f-91a0-48ba-b144-fd2db697000e');\n */\n delete(assetId) {\n if (!assetId) {\n return Promise.reject(\n new Error('An asset ID is required for deleting an asset.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/assets/${assetId}`);\n }\n\n /**\n * Gets information about an asset\n *\n * API Endpoint: '/assets/:assetId'\n * Method: GET\n *\n * @param {string} assetId The ID of the asset (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {Asset} Information about the asset\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .get('0b51429f-91a0-48ba-b144-fd2db697000e')\n * .then((asset) => console.log(asset))\n * .catch((err) => console.log(err));\n */\n get(assetId) {\n if (!assetId) {\n return Promise.reject(\n new Error(\n 'An asset ID is required for getting information about an asset.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/assets/${assetId}`)\n .then((asset) => toCamelCase(asset));\n }\n\n /**\n * Get a list of all assets\n *\n * API Endpoint: '/assets'\n * Method: GET\n *\n * @param {PaginationOptions} [paginationOptions]\n *\n * @returns {Promise}\n * @fulfill {AssetsFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .getAll()\n * .then((assets) => console.log(assets))\n * .catch((err) => console.log(err));\n */\n getAll(paginationOptions) {\n return this._request\n .get(`${this._baseUrl}/assets`, {\n params: toSnakeCase(paginationOptions)\n })\n .then((assetsData) => formatPaginatedDataFromServer(assetsData));\n }\n\n /**\n * Get a list of all assets that belong to a particular organization\n *\n * API Endpoint: '/organizations/:organizationId/assets'\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 {string} [options.assetTypeId] UUID of the asset type to use for filtering\n * @param {Number} [options.limit] Maximum number of records to return per query\n * @param {Number} [options.offset] How many records from the first record to start\n * @param {boolean} [options.includeTypeDescendents] When true will look for all asset types that are descendendents from options.assetTypeId\n * @param {string} [options.includeMetricId] If asset has an associated metric value the latest metric will be returned.\n *\n * @returns {Promise}\n * @fulfill {AssetsFromServer}\n * @reject {Error}\n *\n * @example\n * contxtSdk.assets\n * .getAllByOrganizationId('53fba880-70b7-47a2-b4e3-ad9ecfb67d5c', {\n * assetTypeId: '4f0e51c6-728b-4892-9863-6d002e61204d'\n * })\n * .then((assets) => console.log(assets))\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 assets.\"\n )\n );\n }\n\n const params = toSnakeCase(options);\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/assets`, {\n params\n })\n .then((assetsData) => formatPaginatedDataFromServer(assetsData));\n }\n\n /**\n * Updates an asset's data\n *\n * API Endpoint: '/assets/:assetId'\n * Method: PUT\n *\n * @param {string} assetId The ID of the asset to update (formatted as a UUID)\n * @param {Object} update An object containing the updated data for the asset\n * @param {string} update.description\n *\n * @example\n * contxtSdk.assets\n * .update({\n * description: 'A new description'\n * })\n * .then((asset) => console.log(asset))\n * .catch((err) => console.log(err));\n */\n update(assetId, update) {\n if (!assetId) {\n return Promise.reject(\n new Error('An asset ID is required to update an asset.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update an asset.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The asset 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', 'label', 'organizationId']\n });\n\n return this._request\n .put(`${this._baseUrl}/assets/${assetId}`, formattedUpdate)\n .then((asset) => toCamelCase(asset));\n }\n}\n\nexport default Assets;\n"]}
@@ -1,306 +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 { toCamelCase, toSnakeCase } from '../utils/objects';
7
-
8
- /**
9
- * @typedef {Object} CostCenter
10
- * @param {string} createdAt ISO 8601 Extended Format date/time string
11
- * @param {string} [description]
12
- * @param {string} id UUID
13
- * @param {string} name
14
- * @param {string} organizationId UUID
15
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
16
- */
17
-
18
- /**
19
- * @typedef {Object} CostCenterFacility
20
- * @param {string} costCenterId UUID
21
- * @param {string} createdAt ISO 8601 Extended Format date/time string
22
- * @param {number} facilityId
23
- * @param {string} id UUID
24
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
25
- */
26
-
27
- /**
28
- * Module that provides access to cost centers, and helps manage
29
- * the relationship between those cost centers and facilities
30
- *
31
- * @typicalname contxtSdk.facilities.costCenters
32
- */
33
-
34
- var CostCenters = function () {
35
- /**
36
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules
37
- * @param {Object} request An instance of the request module tied to this module's audience.
38
- * @param {string} baseUrl The base URL provided by the parent module
39
- */
40
- function CostCenters(sdk, request, baseUrl) {
41
- _classCallCheck(this, CostCenters);
42
-
43
- this._baseUrl = baseUrl;
44
- this._request = request;
45
- this._sdk = sdk;
46
- }
47
-
48
- /**
49
- * Adds a facility to a cost center
50
- *
51
- * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'
52
- * Method: POST
53
- *
54
- * @param {string} costCenterId UUID corresponding with a cost center
55
- * @param {number} facilityId The ID of a facility
56
- *
57
- * @returns {Promise}
58
- * @fulfill {CostCenterFacility} Information about the new cost center facility relationship
59
- * @reject {Error}
60
- *
61
- * @example
62
- * contxtSdk.facilities.costCenters
63
- * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
64
- * .then((costCenter) => console.log(costCenter))
65
- * .catch((err) => console.log(err));
66
- */
67
-
68
-
69
- _createClass(CostCenters, [{
70
- key: 'addFacility',
71
- value: function addFacility(costCenterId, facilityId) {
72
- var errorMsg = void 0;
73
-
74
- if (!costCenterId) {
75
- errorMsg = 'A costCenterId is required to create a relationship between a cost center and a facility.';
76
- } else if (!facilityId) {
77
- errorMsg = 'A facilityId is required to create a relationship between a cost center and a facility.';
78
- }
79
-
80
- if (errorMsg) {
81
- return Promise.reject(new Error(errorMsg));
82
- }
83
-
84
- return this._request.post(this._baseUrl + '/costcenters/' + costCenterId + '/facility/' + facilityId).then(function (costCenterFacility) {
85
- return toCamelCase(costCenterFacility);
86
- });
87
- }
88
-
89
- /**
90
- * Creates a new cost center
91
- *
92
- * API Endpoint: '/costcenters'
93
- * Method: POST
94
- *
95
- * @param {Object} costCenter
96
- * @param {string} [costCenter.description]
97
- * @param {string} costCenter.name
98
- * @param {string} costCenter.organizationId UUID
99
- *
100
- * @returns {Promise}
101
- * @fulfill {CostCenter} Information about the new cost center
102
- * @reject {Error}
103
- *
104
- * @example
105
- * contxtSdk.facilities.costCenters
106
- * .create({
107
- * decsription: 'Cost center number 1',
108
- * name: 'North Carolina, USA',
109
- * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5'
110
- * })
111
- * .then((costCenter) => console.log(costCenter))
112
- * .catch((err) => console.log(err));
113
- */
114
-
115
- }, {
116
- key: 'create',
117
- value: function create() {
118
- var costCenter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
119
-
120
- var requiredFields = ['name', 'organizationId'];
121
-
122
- for (var i = 0; i < requiredFields.length; i++) {
123
- var field = requiredFields[i];
124
-
125
- if (!costCenter[field]) {
126
- return Promise.reject(new Error('A ' + field + ' is required to create a new cost center.'));
127
- }
128
- }
129
-
130
- return this._request.post(this._baseUrl + '/costcenters', toSnakeCase(costCenter)).then(function (costCenter) {
131
- return toCamelCase(costCenter);
132
- });
133
- }
134
-
135
- /**
136
- * Delete a cost center
137
- *
138
- * API Endpoint: '/costcenters/:costCenterId'
139
- * Method: DELETE
140
- *
141
- * @param {string} costCenterId The ID of the cost center (formatted as a UUID)
142
- *
143
- * @returns {Promise}
144
- * @fulfill {undefined}
145
- * @reject {Error}
146
- *
147
- * @example
148
- * contxtSdk.facilities.costCenters.delete(
149
- * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'
150
- * );
151
- */
152
-
153
- }, {
154
- key: 'delete',
155
- value: function _delete(costCenterId) {
156
- if (!costCenterId) {
157
- return Promise.reject(new Error('A cost center id is required for deleting a cost center.'));
158
- }
159
-
160
- return this._request.delete(this._baseUrl + '/costcenters/' + costCenterId);
161
- }
162
-
163
- /**
164
- * Get a listing of all cost centers
165
- *
166
- * API Endpoint: '/costcenters'
167
- * METHOD: GET
168
- *
169
- * @returns {Promise}
170
- * @fulfill {CostCenter[]}
171
- * @reject {Error}
172
- *
173
- * @example
174
- * contxtSdk.facilities.costCenters
175
- * .getAll()
176
- * .then((costCenters) => console.log(costCenters))
177
- * .catch((err) => console.log(err));
178
- */
179
-
180
- }, {
181
- key: 'getAll',
182
- value: function getAll() {
183
- return this._request.get(this._baseUrl + '/costcenters').then(function (costCenters) {
184
- return toCamelCase(costCenters);
185
- });
186
- }
187
-
188
- /**
189
- * Get a listing of all cost centers for an organization
190
- *
191
- * API Endpoint: '/organizations/:organizationId/costcenters'
192
- * METHOD: GET
193
- *
194
- * @param {string} organizationId The ID of the organization (formatted as a UUID)
195
- *
196
- * @returns {Promise}
197
- * @fulfill {CostCenter[]}
198
- * @reject {Error}
199
- *
200
- * @example
201
- * contxtSdk.facilities.costCenters
202
- * .getAllByOrganizationId('59270c25-4de9-4b22-8e0b-ab287ac344ce')
203
- * .then((costCenters) => console.log(costCenters))
204
- * .catch((err) => console.log(err));
205
- */
206
-
207
- }, {
208
- key: 'getAllByOrganizationId',
209
- value: function getAllByOrganizationId(organizationId) {
210
- if (!organizationId) {
211
- return Promise.reject(new Error("An organization id is required for getting a list of an organization's cost centers."));
212
- }
213
-
214
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/costcenters').then(function (costCenters) {
215
- return toCamelCase(costCenters);
216
- });
217
- }
218
-
219
- /**
220
- * Removes a facility from a cost center
221
- *
222
- * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'
223
- * Method: DELETE
224
- *
225
- * @param {string} costCenterId UUID corresponding with a cost center
226
- * @param {number} facilityId ID corresponding with the facility
227
- *
228
- * @returns {Promise}
229
- * @fulfill {undefined}
230
- * @reject {Error}
231
- *
232
- * @example
233
- * contxtSdk.facilities.costCenters
234
- * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
235
- * .catch((err) => console.log(err));
236
- */
237
-
238
- }, {
239
- key: 'removeFacility',
240
- value: function removeFacility(costCenterId, facilityId) {
241
- var errorMsg = void 0;
242
-
243
- if (!costCenterId) {
244
- errorMsg = 'A costCenterId is required to remove a relationship between a cost center and a facility.';
245
- } else if (!facilityId) {
246
- errorMsg = 'A facilityId is required to remove a relationship between a cost center and a facility.';
247
- }
248
-
249
- if (errorMsg) {
250
- return Promise.reject(new Error(errorMsg));
251
- }
252
-
253
- return this._request.delete(this._baseUrl + '/costcenters/' + costCenterId + '/facility/' + facilityId);
254
- }
255
-
256
- /**
257
- * Updates an existing cost center
258
- *
259
- * API Endpoint: '/costcenters/:costCenterId'
260
- * Method: PUT
261
- *
262
- * @param {String} costCenterId
263
- * @param {Object} update
264
- * @param {string} [update.description]
265
- * @param {string} [update.name]
266
- *
267
- * @returns {Promise}
268
- * @fulfill {FacilityGrouping} Information about the updated cost center
269
- * @reject {Error}
270
- *
271
- * @example
272
- * contxtSdk.facilities.costCenters
273
- * .update({
274
- * description: 'Refrigeration compressors throughout the facility',
275
- * name: 'Compressors',
276
- * })
277
- * .then((costCenter) => console.log(costCenter))
278
- * .catch((err) => console.log(err));
279
- */
280
-
281
- }, {
282
- key: 'update',
283
- value: function update(costCenterId, _update) {
284
- if (!costCenterId) {
285
- return Promise.reject(new Error('A cost center id is required to update a cost center.'));
286
- }
287
-
288
- if (!_update) {
289
- return Promise.reject(new Error('An update is required to update a cost center.'));
290
- }
291
-
292
- if (!isPlainObject(_update)) {
293
- return Promise.reject(new Error('The cost center update must be a well-formed object with the data you wish to update.'));
294
- }
295
-
296
- return this._request.put(this._baseUrl + '/costcenters/' + costCenterId, toSnakeCase(_update)).then(function (costCenter) {
297
- return toCamelCase(costCenter);
298
- });
299
- }
300
- }]);
301
-
302
- return CostCenters;
303
- }();
304
-
305
- export default CostCenters;
306
- //# sourceMappingURL=costCenters.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["facilities/costCenters.js"],"names":["isPlainObject","toCamelCase","toSnakeCase","CostCenters","sdk","request","baseUrl","_baseUrl","_request","_sdk","costCenterId","facilityId","errorMsg","Promise","reject","Error","post","then","costCenterFacility","costCenter","requiredFields","i","length","field","delete","get","costCenters","organizationId","update","put"],"mappings":";;;;AAAA,OAAOA,aAAP,MAA0B,sBAA1B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;AAUA;;;;;;;;;AASA;;;;;;;IAMMC,W;AACJ;;;;;AAKA,uBAAYC,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,Y,EAAcC,U,EAAY;AACpC,UAAIC,iBAAJ;;AAEA,UAAI,CAACF,YAAL,EAAmB;AACjBE,mBACE,2FADF;AAED,OAHD,MAGO,IAAI,CAACD,UAAL,EAAiB;AACtBC,mBACE,yFADF;AAED;;AAED,UAAIA,QAAJ,EAAc;AACZ,eAAOC,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAUH,QAAV,CAAf,CAAP;AACD;;AAED,aAAO,KAAKJ,QAAL,CACJQ,IADI,CAEA,KAAKT,QAFL,qBAE6BG,YAF7B,kBAEsDC,UAFtD,EAIJM,IAJI,CAIC,UAACC,kBAAD;AAAA,eAAwBjB,YAAYiB,kBAAZ,CAAxB;AAAA,OAJD,CAAP;AAKD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyBwB;AAAA,UAAjBC,UAAiB,uEAAJ,EAAI;;AACtB,UAAMC,iBAAiB,CAAC,MAAD,EAAS,gBAAT,CAAvB;;AAEA,WAAK,IAAIC,IAAI,CAAb,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AAEA,UAAI,CAACF,YAAL,EAAmB;AACjBE,mBACE,2FADF;AAED,OAHD,MAGO,IAAI,CAACD,UAAL,EAAiB;AACtBC,mBACE,yFADF;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,qBAC2BG,YAD3B,kBACoDC,UADpD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAwBOD,Y,EAAckB,O,EAAQ;AAC3B,UAAI,CAAClB,YAAL,EAAmB;AACjB,eAAOG,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACa,OAAL,EAAa;AACX,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,gDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACf,cAAc4B,OAAd,CAAL,EAA4B;AAC1B,eAAOf,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,uFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CACJqB,GADI,CACG,KAAKtB,QADR,qBACgCG,YADhC,EACgDR,YAAY0B,OAAZ,CADhD,EAEJX,IAFI,CAEC,UAACE,UAAD;AAAA,eAAgBlB,YAAYkB,UAAZ,CAAhB;AAAA,OAFD,CAAP;AAGD;;;;;;AAGH,eAAehB,WAAf","file":"costCenters.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} CostCenter\n * @param {string} createdAt ISO 8601 Extended Format date/time string\n * @param {string} [description]\n * @param {string} id UUID\n * @param {string} name\n * @param {string} organizationId UUID\n * @param {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} CostCenterFacility\n * @param {string} costCenterId UUID\n * @param {string} createdAt ISO 8601 Extended Format date/time string\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 cost centers, and helps manage\n * the relationship between those cost centers and facilities\n *\n * @typicalname contxtSdk.facilities.costCenters\n */\nclass CostCenters {\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 cost center\n *\n * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'\n * Method: POST\n *\n * @param {string} costCenterId UUID corresponding with a cost center\n * @param {number} facilityId The ID of a facility\n *\n * @returns {Promise}\n * @fulfill {CostCenterFacility} Information about the new cost center facility relationship\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .then((costCenter) => console.log(costCenter))\n * .catch((err) => console.log(err));\n */\n addFacility(costCenterId, facilityId) {\n let errorMsg;\n\n if (!costCenterId) {\n errorMsg =\n 'A costCenterId is required to create a relationship between a cost center and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to create a relationship between a cost center and a facility.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .post(\n `${this._baseUrl}/costcenters/${costCenterId}/facility/${facilityId}`\n )\n .then((costCenterFacility) => toCamelCase(costCenterFacility));\n }\n\n /**\n * Creates a new cost center\n *\n * API Endpoint: '/costcenters'\n * Method: POST\n *\n * @param {Object} costCenter\n * @param {string} [costCenter.description]\n * @param {string} costCenter.name\n * @param {string} costCenter.organizationId UUID\n *\n * @returns {Promise}\n * @fulfill {CostCenter} Information about the new cost center\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .create({\n * decsription: 'Cost center number 1',\n * name: 'North Carolina, USA',\n * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5'\n * })\n * .then((costCenter) => console.log(costCenter))\n * .catch((err) => console.log(err));\n */\n create(costCenter = {}) {\n const requiredFields = ['name', 'organizationId'];\n\n for (let i = 0; i < requiredFields.length; i++) {\n const field = requiredFields[i];\n\n if (!costCenter[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new cost center.`)\n );\n }\n }\n\n return this._request\n .post(`${this._baseUrl}/costcenters`, toSnakeCase(costCenter))\n .then((costCenter) => toCamelCase(costCenter));\n }\n\n /**\n * Delete a cost center\n *\n * API Endpoint: '/costcenters/:costCenterId'\n * Method: DELETE\n *\n * @param {string} costCenterId The ID of the cost center (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters.delete(\n * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'\n * );\n */\n delete(costCenterId) {\n if (!costCenterId) {\n return Promise.reject(\n new Error('A cost center id is required for deleting a cost center.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/costcenters/${costCenterId}`);\n }\n\n /**\n * Get a listing of all cost centers\n *\n * API Endpoint: '/costcenters'\n * METHOD: GET\n *\n * @returns {Promise}\n * @fulfill {CostCenter[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .getAll()\n * .then((costCenters) => console.log(costCenters))\n * .catch((err) => console.log(err));\n */\n getAll() {\n return this._request\n .get(`${this._baseUrl}/costcenters`)\n .then((costCenters) => toCamelCase(costCenters));\n }\n\n /**\n * Get a listing of all cost centers for an organization\n *\n * API Endpoint: '/organizations/:organizationId/costcenters'\n * METHOD: GET\n *\n * @param {string} organizationId The ID of the organization (formatted as a UUID)\n *\n * @returns {Promise}\n * @fulfill {CostCenter[]}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .getAllByOrganizationId('59270c25-4de9-4b22-8e0b-ab287ac344ce')\n * .then((costCenters) => console.log(costCenters))\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 cost centers.\"\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/costcenters`)\n .then((costCenters) => toCamelCase(costCenters));\n }\n\n /**\n * Removes a facility from a cost center\n *\n * API Endpoint: '/costcenters/:costCenterId/facility/:facilityId'\n * Method: DELETE\n *\n * @param {string} costCenterId UUID corresponding with a cost center\n * @param {number} facilityId ID corresponding with the facility\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)\n * .catch((err) => console.log(err));\n */\n removeFacility(costCenterId, facilityId) {\n let errorMsg;\n\n if (!costCenterId) {\n errorMsg =\n 'A costCenterId is required to remove a relationship between a cost center and a facility.';\n } else if (!facilityId) {\n errorMsg =\n 'A facilityId is required to remove a relationship between a cost center 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}/costcenters/${costCenterId}/facility/${facilityId}`\n );\n }\n\n /**\n * Updates an existing cost center\n *\n * API Endpoint: '/costcenters/:costCenterId'\n * Method: PUT\n *\n * @param {String} costCenterId\n * @param {Object} update\n * @param {string} [update.description]\n * @param {string} [update.name]\n *\n * @returns {Promise}\n * @fulfill {FacilityGrouping} Information about the updated cost center\n * @reject {Error}\n *\n * @example\n * contxtSdk.facilities.costCenters\n * .update({\n * description: 'Refrigeration compressors throughout the facility',\n * name: 'Compressors',\n * })\n * .then((costCenter) => console.log(costCenter))\n * .catch((err) => console.log(err));\n */\n update(costCenterId, update) {\n if (!costCenterId) {\n return Promise.reject(\n new Error('A cost center id is required to update a cost center.')\n );\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a cost center.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The cost center update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n return this._request\n .put(`${this._baseUrl}/costcenters/${costCenterId}`, toSnakeCase(update))\n .then((costCenter) => toCamelCase(costCenter));\n }\n}\n\nexport default CostCenters;\n"]}
@@ -1,323 +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 { toCamelCase, toSnakeCase } from '../utils/objects';
7
-
8
- /**
9
- * @typedef {Object} FacilityGrouping
10
- * @param {string} createdAt ISO 8601 Extended Format date/time string
11
- * @param {string} [description]
12
- * @param {Facility[]} [facilities]
13
- * @param {string} id UUID
14
- * @param {boolean} isPrivate
15
- * @param {string} name
16
- * @param {string} organizationId UUID
17
- * @param {string} ownerId Auth0 identifer of the user
18
- * @param {string} [parentGroupingId] UUID
19
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
20
- */
21
-
22
- /**
23
- * @typedef {Object} FacilityGroupingFacility
24
- * @param {string} createdAt ISO 8601 Extended Format date/time string
25
- * @param {string} facilityGroupingId UUID
26
- * @param {number} facilityId
27
- * @param {string} id UUID
28
- * @param {string} updatedAt ISO 8601 Extended Format date/time string
29
- */
30
-
31
- /**
32
- * Module that provides access to facility groupings, and helps manage
33
- * the relationship between those groupings and facilities
34
- *
35
- * @typicalname contxtSdk.facilities.groupings
36
- */
37
-
38
- var FacilityGroupings = function () {
39
- /**
40
- * @param {Object} sdk An instance of the SDK so the module can communicate with other modules
41
- * @param {Object} request An instance of the request module tied to this module's audience.
42
- * @param {string} baseUrl The base URL provided by the parent module
43
- */
44
- function FacilityGroupings(sdk, request, baseUrl) {
45
- _classCallCheck(this, FacilityGroupings);
46
-
47
- this._baseUrl = baseUrl;
48
- this._request = request;
49
- this._sdk = sdk;
50
- }
51
-
52
- /**
53
- * Adds a facility to a facility grouping
54
- *
55
- * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'
56
- * Method: POST
57
- *
58
- * @param {string} facilityGroupingId UUID corresponding with a facility grouping
59
- * @param {number} facilityId
60
- *
61
- * @returns {Promise}
62
- * @fulfill {FacilityGroupingFacility} Information about the new facility/grouping relationship
63
- * @reject {Error}
64
- *
65
- * @example
66
- * contxtSdk.facilities.groupings
67
- * .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
68
- * .then((grouping) => console.log(grouping))
69
- * .catch((err) => console.log(err));
70
- */
71
-
72
-
73
- _createClass(FacilityGroupings, [{
74
- key: 'addFacility',
75
- value: function addFacility(facilityGroupingId, facilityId) {
76
- var errorMsg = void 0;
77
-
78
- if (!facilityGroupingId) {
79
- errorMsg = 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.';
80
- } else if (!facilityId) {
81
- errorMsg = 'A facilityId is required to create a relationship between a facility grouping and a facility.';
82
- }
83
-
84
- if (errorMsg) {
85
- return Promise.reject(new Error(errorMsg));
86
- }
87
-
88
- return this._request.post(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId).then(function (groupingFacility) {
89
- return toCamelCase(groupingFacility);
90
- });
91
- }
92
-
93
- /**
94
- * Creates a new facility grouping
95
- *
96
- * API Endpoint: '/groupings'
97
- * Method: POST
98
- *
99
- * @param {Object} facilityGrouping
100
- * @param {string} [facilityGrouping.description]
101
- * @param {boolean} [facilityGrouping.isPrivate = false]
102
- * @param {string} facilityGrouping.name
103
- * @param {string} facilityGrouping.organizationId UUID
104
- * @param {string} [facilityGrouping.parentGroupingId] UUID
105
- *
106
- * @returns {Promise}
107
- * @fulfill {FacilityGrouping} Information about the new facility grouping
108
- * @reject {Error}
109
- *
110
- * @example
111
- * contxtSdk.facilities.groupings
112
- * .create({
113
- * description: 'US States of CT, MA, ME, NH, RI, VT',
114
- * isPrivate: false,
115
- * name: 'New England, USA',
116
- * organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5',
117
- * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'
118
- * })
119
- * .then((grouping) => console.log(grouping))
120
- * .catch((err) => console.log(err));
121
- */
122
-
123
- }, {
124
- key: 'create',
125
- value: function create() {
126
- var grouping = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
127
-
128
- var requiredFields = ['name', 'organizationId'];
129
-
130
- for (var i = 0; requiredFields.length > i; i++) {
131
- var field = requiredFields[i];
132
-
133
- if (!grouping[field]) {
134
- return Promise.reject(new Error('A ' + field + ' is required to create a new facility grouping.'));
135
- }
136
- }
137
-
138
- return this._request.post(this._baseUrl + '/groupings', toSnakeCase(grouping)).then(function (grouping) {
139
- return toCamelCase(grouping);
140
- });
141
- }
142
-
143
- /**
144
- * Delete a facility groupings
145
- *
146
- * API Endpoint: '/groupings/:facilityGroupingId'
147
- * Method: DELETE
148
- *
149
- * @param {string} facilityGroupingId The id of the facility grouping (formatted as a UUID)
150
- *
151
- * @returns {Promise}
152
- * @fulfill {undefined}
153
- * @reject {Error}
154
- *
155
- * @example
156
- * contxtSdk.facilities.groupings.delete(
157
- * 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d'
158
- * );
159
- */
160
-
161
- }, {
162
- key: 'delete',
163
- value: function _delete(facilityGroupingId) {
164
- if (!facilityGroupingId) {
165
- return Promise.reject(new Error('A facility grouping id is required for deleting a facility grouping.'));
166
- }
167
-
168
- return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId);
169
- }
170
-
171
- /**
172
- * Get a listing of all facility groupings available to a user. Includes public groupings across
173
- * any organization the user has access to and the user's private groupings.
174
- *
175
- * API Endpoint: '/groupings'
176
- * Method: GET
177
- *
178
- * @returns {Promise}
179
- * @fulfill {FacilityGrouping[]}
180
- * @reject {Error}
181
- *
182
- * @example
183
- * contxtSdk.facilites.groupings
184
- * .getAll()
185
- * .then((groupings) => console.log(groupings))
186
- * .catch((err) => console.log(err));
187
- */
188
-
189
- }, {
190
- key: 'getAll',
191
- value: function getAll() {
192
- return this._request.get(this._baseUrl + '/groupings').then(function (groupings) {
193
- return toCamelCase(groupings);
194
- });
195
- }
196
-
197
- /**
198
- * Get a listing of all facility groupings for an organization. Includes public groupings
199
- * across that specific organization and the user's private groupings for that organization.
200
- *
201
- * API Endpoint: '/organizations/:organizationId/groupings'
202
- * Method: GET
203
- *
204
- * @param {string} organizationId UUID corresponding with an organization
205
- *
206
- * @returns {Promise}
207
- * @fulfill {FacilityGrouping[]}
208
- * @reject {Error}
209
- *
210
- * @example
211
- * contxtSdk.facilites.groupings
212
- * .getAllByOrganizationId('349dbd36-5dca-4a10-b54d-d0f71c3c8709')
213
- * .then((groupings) => console.log(groupings))
214
- * .catch((err) => console.log(err));
215
- */
216
-
217
- }, {
218
- key: 'getAllByOrganizationId',
219
- value: function getAllByOrganizationId(organizationId) {
220
- if (!organizationId) {
221
- return Promise.reject(new Error("An organization id is required for getting a list of an organization's facility groupings"));
222
- }
223
-
224
- return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/groupings').then(function (groupings) {
225
- return toCamelCase(groupings);
226
- });
227
- }
228
-
229
- /**
230
- * Removes a facility from a facility grouping
231
- *
232
- * API Endpoint: '/groupings/:facilityGroupingId/facilities/:facilityId'
233
- * Method: DELETE
234
- *
235
- * @param {string} facilityGroupingId UUID corresponding with a facility grouping
236
- * @param {number} facilityId
237
- *
238
- * @returns {Promise}
239
- * @reject {Error}
240
- *
241
- * @example
242
- * contxtSdk.facilities.groupings
243
- * .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4)
244
- * .catch((err) => console.log(err));
245
- */
246
-
247
- }, {
248
- key: 'removeFacility',
249
- value: function removeFacility(facilityGroupingId, facilityId) {
250
- var errorMsg = void 0;
251
-
252
- if (!facilityGroupingId) {
253
- errorMsg = 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.';
254
- } else if (!facilityId) {
255
- errorMsg = 'A facilityId is required to remove a relationship between a facility grouping and a facility.';
256
- }
257
-
258
- if (errorMsg) {
259
- return Promise.reject(new Error(errorMsg));
260
- }
261
-
262
- return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId);
263
- }
264
-
265
- /**
266
- * Updates an existing facility grouping
267
- *
268
- * API Endpoint: '/groupings/:facilityGroupingId'
269
- * Method: PUT
270
- *
271
- * @param {String} facilityGroupingId
272
- * @param {Object} update
273
- * @param {string} [update.description]
274
- * @param {boolean} [update.isPrivate]
275
- * @param {string} [update.name]
276
- * @param {string} [update.parentGroupingId] UUID corresponding with another facility grouping
277
- *
278
- * @returns {Promise}
279
- * @fulfill {FacilityGrouping} Information about the updated facility grouping
280
- * @reject {Error}
281
- *
282
- * @example
283
- * contxtSdk.facilities.groupings
284
- * .update('b3dbaae3-25dd-475b-80dc-66296630a8d0', {
285
- * description: 'US States of CT, MA, ME, NH, RI, VT',
286
- * isPrivate: false,
287
- * name: 'New England, USA',
288
- * parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'
289
- * })
290
- * .then((grouping) => console.log(grouping))
291
- * .catch((err) => console.log(err));
292
- */
293
-
294
- }, {
295
- key: 'update',
296
- value: function update(facilityGroupingId, _update) {
297
- if (!facilityGroupingId) {
298
- return Promise.reject(new Error('A facility grouping id is required to update a facility grouping.'));
299
- }
300
-
301
- if (!_update) {
302
- return Promise.reject(new Error('An update is required to update a facility grouping'));
303
- }
304
-
305
- if (!isPlainObject(_update)) {
306
- return Promise.reject(new Error('The facility grouping update must be a well-formed object with the data you wish to update.'));
307
- }
308
-
309
- var formattedUpdate = toSnakeCase(_update, {
310
- excludeKeys: ['id', 'organizationId', 'ownerId']
311
- });
312
-
313
- return this._request.put(this._baseUrl + '/groupings/' + facilityGroupingId, formattedUpdate).then(function (grouping) {
314
- return toCamelCase(grouping);
315
- });
316
- }
317
- }]);
318
-
319
- return FacilityGroupings;
320
- }();
321
-
322
- export default FacilityGroupings;
323
- //# sourceMappingURL=groupings.js.map