@ndustrial/contxt-sdk
Advanced tools
Comparing version 2.9.0 to 2.10.0
@@ -0,1 +1,7 @@ | ||
## [v2.10.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v2.10.0) (2020-02-05) | ||
**Added** | ||
- Added `Feeds#getStatusForFacility` to fetch feed status for every feed in a given facility. | ||
## [v2.9.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v2.9.0) (2020-02-01) | ||
@@ -2,0 +8,0 @@ |
@@ -11,2 +11,3 @@ <a name="Feeds"></a> | ||
* [.getByFacilityId(facilityId)](#Feeds+getByFacilityId) ⇒ <code>Promise</code> | ||
* [.getStatusForFacility(facilityId)](#Feeds+getStatusForFacility) ⇒ <code>Promise</code> | ||
@@ -37,3 +38,3 @@ <a name="new_Feeds_new"></a> | ||
| --- | --- | | ||
| facilityId | <code>number</code> | | ||
| facilityId | <code>Number</code> | | ||
@@ -47,1 +48,24 @@ **Example** | ||
``` | ||
<a name="Feeds+getStatusForFacility"></a> | ||
### contxtSdk.iot.feeds.getStatusForFacility(facilityId) ⇒ <code>Promise</code> | ||
Gets current Feed and Grouping status for a given Facility | ||
API Endpoint: '/facilities/:facilityId/status' | ||
Method: GET | ||
**Kind**: instance method of [<code>Feeds</code>](#Feeds) | ||
**Fulfill**: [<code>FacilityStatusFromServer</code>](./Typedefs.md#FacilityStatusFromServer) Information about the Facility feed status | ||
**Reject**: <code>Error</code> | ||
| Param | Type | | ||
| --- | --- | | ||
| facilityId | <code>Number</code> | | ||
**Example** | ||
```js | ||
contxtSdk.iot.feeds | ||
.getStatusForFacility(563) | ||
.then((status) => console.log(status.feeds)) | ||
.catch((err) => console.log(err)); | ||
``` |
@@ -248,2 +248,4 @@ ## Classes | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#FacilityFeedStatus">FacilityFeedStatus</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#FacilityGrouping">FacilityGrouping</a> : <code>Object</code></dt> | ||
@@ -253,2 +255,6 @@ <dd></dd> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#FacilityGroupingStatus">FacilityGroupingStatus</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#FacilityStatusFromServer">FacilityStatusFromServer</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#Feed">Feed</a> : <code>Object</code></dt> | ||
@@ -255,0 +261,0 @@ <dd></dd> |
@@ -746,2 +746,19 @@ <a name="Asset"></a> | ||
<a name="FacilityFeedStatus"></a> | ||
## FacilityFeedStatus : <code>Object</code> | ||
**Kind**: global typedef | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| groupings | [<code>Array.<FacilityGroupingStatus></code>](#FacilityGroupingStatus) | An array of field groupings associated with the feed | | ||
| feedType | <code>Object</code> | | | ||
| feedType.id | <code>Number</code> | | | ||
| feedType.type | <code>String</code> | The human readable type of the feed, e.g. "egauge" | | ||
| id | <code>Number</code> | | | ||
| key | <code>String</code> | The unique key for the feed | | ||
| status | <code>String</code> | The most recent status of the feed, e.g. "Healthy" | | ||
| statusEventId | <code>String</code> | UUID of the feed status event | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
<a name="FacilityGrouping"></a> | ||
@@ -778,2 +795,24 @@ | ||
<a name="FacilityGroupingStatus"></a> | ||
## FacilityGroupingStatus : <code>Object</code> | ||
**Kind**: global typedef | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>String</code> | UUID | | ||
| label | <code>String</code> | The human readable name of the field grouping | | ||
| status | <code>String</code> | The most recent status of the field grouping | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
<a name="FacilityStatusFromServer"></a> | ||
## FacilityStatusFromServer : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | | ||
| --- | --- | | ||
| feeds | [<code>Array.<FacilityFeedStatus></code>](#FacilityFeedStatus) | | ||
<a name="Feed"></a> | ||
@@ -780,0 +819,0 @@ |
@@ -47,2 +47,28 @@ 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; }; }(); | ||
/** | ||
* @typedef {Object} FacilityFeedStatus | ||
* @param {FacilityGroupingStatus[]} groupings An array of field groupings associated with the feed | ||
* @param {Object} feedType | ||
* @param {Number} feedType.id | ||
* @param {String} feedType.type The human readable type of the feed, e.g. "egauge" | ||
* @param {Number} id | ||
* @param {String} key The unique key for the feed | ||
* @param {String} status The most recent status of the feed, e.g. "Healthy" | ||
* @param {String} statusEventId UUID of the feed status event | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
/** | ||
* @typedef {Object} FacilityGroupingStatus | ||
* @param {String} id UUID | ||
* @param {String} label The human readable name of the field grouping | ||
* @param {String} status The most recent status of the field grouping | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
/** | ||
* @typedef {Object} FacilityStatusFromServer | ||
* @property {FacilityFeedStatus[]} feeds | ||
*/ | ||
/** | ||
* Module that provides access to feed information | ||
@@ -75,3 +101,3 @@ * | ||
* | ||
* @param {number} facilityId | ||
* @param {Number} facilityId | ||
* | ||
@@ -89,2 +115,3 @@ * @returns {Promise} | ||
_createClass(Feeds, [{ | ||
@@ -94,3 +121,3 @@ key: 'getByFacilityId', | ||
if (!facilityId) { | ||
return Promise.reject(new Error('A facilityId is required get feeds.')); | ||
return Promise.reject(new Error('A facilityId is required to get feeds.')); | ||
} | ||
@@ -104,2 +131,33 @@ | ||
} | ||
/** | ||
* Gets current Feed and Grouping status for a given Facility | ||
* | ||
* API Endpoint: '/facilities/:facilityId/status' | ||
* Method: GET | ||
* | ||
* @param {Number} facilityId | ||
* | ||
* @returns {Promise} | ||
* @fulfill {FacilityStatusFromServer} Information about the Facility feed status | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.iot.feeds | ||
* .getStatusForFacility(563) | ||
* .then((status) => console.log(status.feeds)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'getStatusForFacility', | ||
value: function getStatusForFacility(facilityId) { | ||
if (!facilityId) { | ||
return Promise.reject(new Error('A facilityId is required to get facility feed status.')); | ||
} | ||
return this._request.get(this._baseUrl + '/facilities/' + facilityId + '/status').then(function (response) { | ||
return toCamelCase(response); | ||
}); | ||
} | ||
}]); | ||
@@ -106,0 +164,0 @@ |
@@ -53,2 +53,28 @@ 'use strict'; | ||
/** | ||
* @typedef {Object} FacilityFeedStatus | ||
* @param {FacilityGroupingStatus[]} groupings An array of field groupings associated with the feed | ||
* @param {Object} feedType | ||
* @param {Number} feedType.id | ||
* @param {String} feedType.type The human readable type of the feed, e.g. "egauge" | ||
* @param {Number} id | ||
* @param {String} key The unique key for the feed | ||
* @param {String} status The most recent status of the feed, e.g. "Healthy" | ||
* @param {String} statusEventId UUID of the feed status event | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
/** | ||
* @typedef {Object} FacilityGroupingStatus | ||
* @param {String} id UUID | ||
* @param {String} label The human readable name of the field grouping | ||
* @param {String} status The most recent status of the field grouping | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
/** | ||
* @typedef {Object} FacilityStatusFromServer | ||
* @property {FacilityFeedStatus[]} feeds | ||
*/ | ||
/** | ||
* Module that provides access to feed information | ||
@@ -80,3 +106,3 @@ * | ||
* | ||
* @param {number} facilityId | ||
* @param {Number} facilityId | ||
* | ||
@@ -94,2 +120,3 @@ * @returns {Promise} | ||
_createClass(Feeds, [{ | ||
@@ -99,3 +126,3 @@ key: 'getByFacilityId', | ||
if (!facilityId) { | ||
return Promise.reject(new Error('A facilityId is required get feeds.')); | ||
return Promise.reject(new Error('A facilityId is required to get feeds.')); | ||
} | ||
@@ -109,2 +136,33 @@ | ||
} | ||
/** | ||
* Gets current Feed and Grouping status for a given Facility | ||
* | ||
* API Endpoint: '/facilities/:facilityId/status' | ||
* Method: GET | ||
* | ||
* @param {Number} facilityId | ||
* | ||
* @returns {Promise} | ||
* @fulfill {FacilityStatusFromServer} Information about the Facility feed status | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.iot.feeds | ||
* .getStatusForFacility(563) | ||
* .then((status) => console.log(status.feeds)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'getStatusForFacility', | ||
value: function getStatusForFacility(facilityId) { | ||
if (!facilityId) { | ||
return Promise.reject(new Error('A facilityId is required to get facility feed status.')); | ||
} | ||
return this._request.get(this._baseUrl + '/facilities/' + facilityId + '/status').then(function (response) { | ||
return (0, _objects.toCamelCase)(response); | ||
}); | ||
} | ||
}]); | ||
@@ -111,0 +169,0 @@ |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "2.9.0", | ||
"version": "2.10.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -43,2 +43,28 @@ import { toCamelCase, toSnakeCase } from '../utils/objects'; | ||
/** | ||
* @typedef {Object} FacilityFeedStatus | ||
* @param {FacilityGroupingStatus[]} groupings An array of field groupings associated with the feed | ||
* @param {Object} feedType | ||
* @param {Number} feedType.id | ||
* @param {String} feedType.type The human readable type of the feed, e.g. "egauge" | ||
* @param {Number} id | ||
* @param {String} key The unique key for the feed | ||
* @param {String} status The most recent status of the feed, e.g. "Healthy" | ||
* @param {String} statusEventId UUID of the feed status event | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
/** | ||
* @typedef {Object} FacilityGroupingStatus | ||
* @param {String} id UUID | ||
* @param {String} label The human readable name of the field grouping | ||
* @param {String} status The most recent status of the field grouping | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
/** | ||
* @typedef {Object} FacilityStatusFromServer | ||
* @property {FacilityFeedStatus[]} feeds | ||
*/ | ||
/** | ||
* Module that provides access to feed information | ||
@@ -68,3 +94,3 @@ * | ||
* | ||
* @param {number} facilityId | ||
* @param {Number} facilityId | ||
* | ||
@@ -81,6 +107,7 @@ * @returns {Promise} | ||
*/ | ||
getByFacilityId(facilityId) { | ||
if (!facilityId) { | ||
return Promise.reject(new Error('A facilityId is required get feeds.')); | ||
return Promise.reject( | ||
new Error('A facilityId is required to get feeds.') | ||
); | ||
} | ||
@@ -94,4 +121,34 @@ | ||
} | ||
/** | ||
* Gets current Feed and Grouping status for a given Facility | ||
* | ||
* API Endpoint: '/facilities/:facilityId/status' | ||
* Method: GET | ||
* | ||
* @param {Number} facilityId | ||
* | ||
* @returns {Promise} | ||
* @fulfill {FacilityStatusFromServer} Information about the Facility feed status | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.iot.feeds | ||
* .getStatusForFacility(563) | ||
* .then((status) => console.log(status.feeds)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
getStatusForFacility(facilityId) { | ||
if (!facilityId) { | ||
return Promise.reject( | ||
new Error('A facilityId is required to get facility feed status.') | ||
); | ||
} | ||
return this._request | ||
.get(`${this._baseUrl}/facilities/${facilityId}/status`) | ||
.then((response) => toCamelCase(response)); | ||
} | ||
} | ||
export default Feeds; |
@@ -116,3 +116,3 @@ import Feeds from './feeds'; | ||
return expect(promise).to.be.rejectedWith( | ||
'A facilityId is required get feeds.' | ||
'A facilityId is required to get feeds.' | ||
); | ||
@@ -122,2 +122,90 @@ }); | ||
}); | ||
describe('getStatusForFacility', function() { | ||
context('the facility ID is provided', function() { | ||
let expectedResult; | ||
let promise; | ||
let rawResult; | ||
let request; | ||
let toCamelCase; | ||
let facilityId; | ||
beforeEach(function() { | ||
facilityId = fixture.build('facility').id; | ||
expectedResult = { | ||
feeds: fixture.buildList( | ||
'feed', | ||
faker.random.number({ | ||
min: 1, | ||
max: 10 | ||
}) | ||
) | ||
}; | ||
expectedResult.feeds.forEach((feed) => { | ||
feed.groupings = fixture.buildList( | ||
'fieldGroupingStatus', | ||
faker.random.number({ min: 1, max: 4 }) | ||
); | ||
}); | ||
rawResult = { | ||
feeds: expectedResult.feeds.map((feed) => | ||
fixture.build('feed', feed, { fromServer: true }) | ||
) | ||
}; | ||
rawResult.feeds.forEach((feed) => { | ||
feed.groupings = feed.groupings.map((groupingStatus) => { | ||
fixture.build('fieldGroupingStatus', groupingStatus, { | ||
fromServer: true | ||
}); | ||
}); | ||
}); | ||
request = { | ||
...baseRequest, | ||
get: sinon.stub().resolves(rawResult) | ||
}; | ||
toCamelCase = sinon | ||
.stub(objectUtils, 'toCamelCase') | ||
.returns(expectedResult); | ||
const feeds = new Feeds(baseSdk, request); | ||
feeds._baseUrl = expectedHost; | ||
promise = feeds.getStatusForFacility(facilityId); | ||
}); | ||
it('gets feeds from provided facility from the server', function() { | ||
expect(request.get).to.be.calledWith( | ||
`${expectedHost}/facilities/${facilityId}/status` | ||
); | ||
}); | ||
it('formats the status response', function() { | ||
return promise.then(() => { | ||
expect(toCamelCase).to.be.calledWith(rawResult); | ||
}); | ||
}); | ||
it('returns the requested feed status', function() { | ||
return expect(promise).to.be.fulfilled.and.to.eventually.equal( | ||
expectedResult | ||
); | ||
}); | ||
}); | ||
context('the facility ID is not provided', function() { | ||
it('throws an error', function() { | ||
const feeds = new Feeds(baseSdk, baseRequest); | ||
const promise = feeds.getStatusForFacility(); | ||
return expect(promise).to.be.rejectedWith( | ||
'A facilityId is required to get facility feed status.' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2887137
418
47083