@ndustrial/contxt-sdk
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -0,1 +1,15 @@ | ||
## [v0.0.16](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.15) | ||
**Added** | ||
* Added IOT module, with ability to get field data and field information | ||
**Changed** | ||
* `asset_id` added as an optional field when getting facilities | ||
**Fixed** | ||
* Fixed bug where calls would return with a 401 when making simultanous requests while using the `MachineAuth` session typ. | ||
## [v0.0.15](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.15) (2018-06-21) | ||
@@ -2,0 +16,0 @@ |
@@ -68,3 +68,3 @@ <a name="CostCenters"></a> | ||
| costCenter | <code>Object</code> | | | ||
| costCenter.description | <code>string</code> | | | ||
| [costCenter.description] | <code>string</code> | | | ||
| costCenter.name | <code>string</code> | | | ||
@@ -102,3 +102,5 @@ | costCenter.organizationId | <code>string</code> | UUID | | ||
```js | ||
contxtSdk.facilities.costCenters.delete('e4fec739-56aa-4b50-8dab-e9d6b9c91a5d') | ||
contxtSdk.facilities.costCenters.delete( | ||
'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d' | ||
); | ||
``` | ||
@@ -165,3 +167,4 @@ <a name="CostCenters+getAll"></a> | ||
```js | ||
contxtSdk.facilities.costCenters.removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
contxtSdk.facilities.costCenters | ||
.removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
.catch((err) => console.log(err)); | ||
@@ -168,0 +171,0 @@ ``` |
@@ -45,2 +45,3 @@ <a name="Facilities"></a> | ||
| [facility.address2] | <code>string</code> | | | ||
| [facility.assetId] | <code>string</code> | UUID corresponding with an asset | | ||
| [facility.city] | <code>string</code> | | | ||
@@ -63,3 +64,3 @@ | [facility.geometryId] | <code>string</code> | UUID corresponding with a geometry | | ||
}) | ||
.then((facilities) => console.log(facilities)); | ||
.then((facilities) => console.log(facilities)) | ||
.catch((err) => console.log(err)); | ||
@@ -108,3 +109,3 @@ ``` | ||
```js | ||
contxtSdk.facilities.delete(25) | ||
contxtSdk.facilities.delete(25); | ||
``` | ||
@@ -129,4 +130,5 @@ <a name="Facilities+get"></a> | ||
```js | ||
contxtSdk.facilities.get(25) | ||
.then((facility) => console.log(facility)); | ||
contxtSdk.facilities | ||
.get(25) | ||
.then((facility) => console.log(facility)) | ||
.catch((err) => console.log(err)); | ||
@@ -147,4 +149,5 @@ ``` | ||
```js | ||
contxtSdk.facilities.getAll() | ||
.then((facilities) => console.log(facilities)); | ||
contxtSdk.facilities | ||
.getAll() | ||
.then((facilities) => console.log(facilities)) | ||
.catch((err) => console.log(err)); | ||
@@ -172,4 +175,5 @@ ``` | ||
```js | ||
contxtSdk.facilities.getAllByOrganizationId(25, {includeGroupings: true}) | ||
.then((facilities) => console.log(facilities)); | ||
contxtSdk.facilities | ||
.getAllByOrganizationId(25, { includeGroupings: true }) | ||
.then((facilities) => console.log(facilities)) | ||
.catch((err) => console.log(err)); | ||
@@ -195,2 +199,3 @@ ``` | ||
| [update.address2] | <code>string</code> | | | ||
| [update.assetId] | <code>string</code> | UUID corresponding with an asset | | ||
| [update.city] | <code>string</code> | | | ||
@@ -197,0 +202,0 @@ | [update.geometryId] | <code>string</code> | UUID corresponding with a geometry | |
@@ -48,3 +48,4 @@ <a name="FacilityGroupings"></a> | ||
```js | ||
contxtSdk.facilities.groupings.addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
contxtSdk.facilities.groupings | ||
.addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
.then((grouping) => console.log(grouping)) | ||
@@ -81,3 +82,3 @@ .catch((err) => console.log(err)); | ||
name: 'New England, USA', | ||
organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5' | ||
organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5', | ||
parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e' | ||
@@ -106,3 +107,5 @@ }) | ||
```js | ||
contxtSdk.facilities.groupings.delete('e4fec739-56aa-4b50-8dab-e9d6b9c91a5d') | ||
contxtSdk.facilities.groupings.delete( | ||
'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d' | ||
); | ||
``` | ||
@@ -123,3 +126,4 @@ <a name="FacilityGroupings+getAll"></a> | ||
```js | ||
contxtSdk.facilites.groupings.getAll() | ||
contxtSdk.facilites.groupings | ||
.getAll() | ||
.then((groupings) => console.log(groupings)) | ||
@@ -147,3 +151,4 @@ .catch((err) => console.log(err)); | ||
```js | ||
contxtSdk.facilites.groupings.getAll() | ||
contxtSdk.facilites.groupings | ||
.getAllByOrganizationId('349dbd36-5dca-4a10-b54d-d0f71c3c8709') | ||
.then((groupings) => console.log(groupings)) | ||
@@ -170,3 +175,4 @@ .catch((err) => console.log(err)); | ||
```js | ||
contxtSdk.facilities.groupings.removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
contxtSdk.facilities.groupings | ||
.removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
.catch((err) => console.log(err)); | ||
@@ -173,0 +179,0 @@ ``` |
@@ -36,2 +36,8 @@ ## Classes | ||
</dd> | ||
<dt><a href="./Fields.md">Fields</a></dt> | ||
<dd><p>Module that provides access to field information</p> | ||
</dd> | ||
<dt><a href="./Iot.md">Iot</a></dt> | ||
<dd><p>Module that provides access to real time IOT feeds and fields.</p> | ||
</dd> | ||
<dt><a href="./MachineAuth.md">MachineAuth</a> : <code><a href="./Typedefs.md#SessionType">SessionType</a></code></dt> | ||
@@ -42,2 +48,5 @@ <dd><p>A SessionType that allows machine to machine communication between Node.js servers. This would | ||
</dd> | ||
<dt><a href="./Outputs.md">Outputs</a></dt> | ||
<dd><p>Module that provides access to output information</p> | ||
</dd> | ||
<dt><a href="./Request.md">Request</a></dt> | ||
@@ -84,2 +93,8 @@ <dd></dd> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#OutputField">OutputField</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#OutputFieldData">OutputFieldData</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#OutputFieldDataResponse">OutputFieldDataResponse</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#SessionType">SessionType</a> : <code>Object</code></dt> | ||
@@ -86,0 +101,0 @@ <dd><p>An adapter that allows the SDK to authenticate with different services and manage various tokens. |
@@ -109,7 +109,8 @@ <a name="Audience"></a> | ||
| --- | --- | --- | | ||
| address1 | <code>string</code> | | | ||
| address2 | <code>string</code> | | | ||
| city | <code>string</code> | | | ||
| [address1] | <code>string</code> | | | ||
| [address2] | <code>string</code> | | | ||
| [assetId] | <code>string</code> | UUID corresponding with an asset | | ||
| [city] | <code>string</code> | | | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| geometryId | <code>string</code> | UUID corresponding with a geometry | | ||
| [geometryId] | <code>string</code> | UUID corresponding with a geometry | | ||
| id | <code>number</code> | | | ||
@@ -123,3 +124,3 @@ | [Info] | <code>Object</code> | User declared information | | ||
| [Organization.updatedAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| state | <code>string</code> | | | ||
| [state] | <code>string</code> | | | ||
| [tags] | <code>Array.<Object></code> | | | ||
@@ -132,4 +133,4 @@ | [tags[].createdAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| timezone | <code>string</code> | An IANA Time Zone Database string, i.e. America/Los_Angeles | | ||
| weatherLocationId | <code>number</code> | | | ||
| zip | <code>string</code> | US Zip Code | | ||
| [weatherLocationId] | <code>number</code> | | | ||
| [zip] | <code>string</code> | US Zip Code | | ||
@@ -144,3 +145,3 @@ <a name="FacilityGrouping"></a> | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| description | <code>string</code> | | | ||
| [description] | <code>string</code> | | | ||
| [facilities] | [<code>Array.<Facility></code>](#Facility) | | | ||
@@ -152,3 +153,3 @@ | id | <code>string</code> | UUID | | ||
| ownerId | <code>string</code> | Auth0 identifer of the user | | ||
| parentGroupingId | <code>string</code> | UUID | | ||
| [parentGroupingId] | <code>string</code> | UUID | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
@@ -180,2 +181,57 @@ | ||
<a name="OutputField"></a> | ||
## OutputField : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| [canAggregate] | <code>Boolean</code> | | | ||
| [divisor] | <code>Number</code> | | | ||
| feedKey | <code>String</code> | | | ||
| fieldDescriptor | <code>String</code> | | | ||
| fieldHumanName | <code>String</code> | | | ||
| [fieldName] | <code>String</code> | | | ||
| id | <code>Number</code> | | | ||
| [isDefault] | <code>Boolean</code> | | | ||
| [isHidden] | <code>Boolean</code> | | | ||
| [isTotalizer] | <code>Boolean</code> | | | ||
| [isWindowed] | <code>Boolean</code> | | | ||
| [label] | <code>String</code> | | | ||
| outputId | <code>Number</code> | | | ||
| [scalar] | <code>Number</code> | | | ||
| [status] | <code>String</code> | | | ||
| [units] | <code>String</code> | | | ||
| valueType | <code>String</code> | What type of value can be coming from the feed. One of `boolean`, `numeric`, and `string` | | ||
<a name="OutputFieldData"></a> | ||
## OutputFieldData : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| eventTime | <code>String</code> | ISO 8601 Extended Format date/time string | | ||
| value | <code>String</code> | | | ||
<a name="OutputFieldDataResponse"></a> | ||
## OutputFieldDataResponse : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| meta | <code>Object</code> | | | ||
| meta.count | <code>Number</code> | Total number of field data records | | ||
| meta.hasMore | <code>Boolean</code> | Indicates if there are more records to retrieve | | ||
| [meta.limit] | <code>Number</code> | Number of records to return | | ||
| [nextRecordTime] | <code>Number</code> | UNIX timestamp indicating a `timeStart` that would return new values | | ||
| [meta.timeEnd] | <code>Number</code> | UNIX timestamp indicating the end of the query window | | ||
| [meta.timeStart] | <code>Number</code> | UNIX timestamp indicating the start of the query window | | ||
| [meta.window] | <code>Number</code> | The sampling window for records. Required if including a timeEnd or timeStart. Valid options include: `0`, `60`, `900`, and `3600` | | ||
| records | [<code>Array.<OutputFieldData></code>](#OutputFieldData) | | | ||
<a name="SessionType"></a> | ||
@@ -182,0 +238,0 @@ |
411
es/index.js
@@ -24,2 +24,12 @@ import axios from 'axios'; | ||
} | ||
}, | ||
iot: { | ||
staging: { | ||
clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES', | ||
host: 'https://feeds-staging.api.ndustrial.io' | ||
}, | ||
production: { | ||
clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA', | ||
host: 'https://feeds.api.ndustrial.io' | ||
} | ||
} | ||
@@ -371,2 +381,3 @@ }; | ||
address2: input.address2, | ||
assetId: input.asset_id, | ||
city: input.city, | ||
@@ -413,2 +424,3 @@ createdAt: input.created_at, | ||
address2: input.address2, | ||
asset_id: input.assetId, | ||
city: input.city, | ||
@@ -896,138 +908,48 @@ geometry_id: input.geometryId, | ||
var Request = function () { | ||
function formatOutputFieldFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
function Request(sdk, audienceName) { | ||
classCallCheck(this, Request); | ||
return { | ||
canAggregate: input.can_aggregate, | ||
divisor: input.divisor, | ||
feedKey: input.feed_key, | ||
fieldDescriptor: input.field_descriptor, | ||
fieldHumanName: input.field_human_name, | ||
fieldName: input.field_name, | ||
id: input.id, | ||
isDefault: input.is_default, | ||
isHidden: input.is_hidden, | ||
isTotalizer: input.is_totalizer, | ||
isWindowed: input.is_windowed, | ||
label: input.label, | ||
outputId: input.output_id, | ||
scalar: input.scalar, | ||
status: input.status, | ||
units: input.units, | ||
valueType: input.value_type | ||
}; | ||
} | ||
this._audienceName = audienceName; | ||
this._axios = axios.create(); | ||
this._insertHeaders = this._insertHeaders.bind(this); | ||
this._sdk = sdk; | ||
function formatOutputFieldDataFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
this._attachInterceptors(); | ||
} | ||
var meta = input.meta || {}; | ||
var query = parseOutputFieldNextPageUrlMetadata(meta.next_page_url); | ||
var records = input.records || []; | ||
createClass(Request, [{ | ||
key: 'delete', | ||
value: function _delete() { | ||
var _axios; | ||
return { | ||
meta: _extends({}, query, { | ||
count: meta.count, | ||
hasMore: meta.has_more, | ||
nextRecordTime: meta.next_record_time | ||
}), | ||
records: records.map(function (record) { | ||
return { | ||
eventTime: record.event_time, | ||
value: record.value | ||
}; | ||
}) | ||
}; | ||
} | ||
return (_axios = this._axios).delete.apply(_axios, arguments).then(function (_ref) { | ||
var data = _ref.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get$$1() { | ||
var _axios2; | ||
return (_axios2 = this._axios).get.apply(_axios2, arguments).then(function (_ref2) { | ||
var data = _ref2.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'head', | ||
value: function head() { | ||
var _axios3; | ||
return (_axios3 = this._axios).head.apply(_axios3, arguments).then(function (_ref3) { | ||
var data = _ref3.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'options', | ||
value: function options() { | ||
var _axios4; | ||
return (_axios4 = this._axios).options.apply(_axios4, arguments).then(function (_ref4) { | ||
var data = _ref4.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'patch', | ||
value: function patch() { | ||
var _axios5; | ||
return (_axios5 = this._axios).patch.apply(_axios5, arguments).then(function (_ref5) { | ||
var data = _ref5.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'post', | ||
value: function post() { | ||
var _axios6; | ||
return (_axios6 = this._axios).post.apply(_axios6, arguments).then(function (_ref6) { | ||
var data = _ref6.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'put', | ||
value: function put() { | ||
var _axios7; | ||
return (_axios7 = this._axios).put.apply(_axios7, arguments).then(function (_ref7) { | ||
var data = _ref7.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'request', | ||
value: function request() { | ||
var _axios8; | ||
return (_axios8 = this._axios).request.apply(_axios8, arguments).then(function (_ref8) { | ||
var data = _ref8.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: '_attachInterceptors', | ||
value: function _attachInterceptors() { | ||
var _this = this; | ||
var requestInterceptors = [{ fulfilled: this._insertHeaders }].concat(toConsumableArray(this._sdk.config.interceptors.request)); | ||
var responseInterceptors = [].concat(toConsumableArray(this._sdk.config.interceptors.response)); | ||
requestInterceptors.forEach(function (_ref9) { | ||
var fulfilled = _ref9.fulfilled, | ||
rejected = _ref9.rejected; | ||
_this._axios.interceptors.request.use(fulfilled, rejected); | ||
}); | ||
responseInterceptors.forEach(function (_ref10) { | ||
var fulfilled = _ref10.fulfilled, | ||
rejected = _ref10.rejected; | ||
_this._axios.interceptors.response.use(fulfilled, rejected); | ||
}); | ||
} | ||
}, { | ||
key: '_insertHeaders', | ||
value: function _insertHeaders(config) { | ||
return this._sdk.auth.getCurrentApiToken(this._audienceName).then(function (apiToken) { | ||
config.headers.common.Authorization = 'Bearer ' + apiToken; | ||
return config; | ||
}); | ||
} | ||
}]); | ||
return Request; | ||
}(); | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
@@ -1384,2 +1306,219 @@ | ||
function parseOutputFieldNextPageUrlMetadata(url) { | ||
var query = new urlParse(url, true).query; | ||
return ['limit', 'timeEnd', 'timeStart', 'window'].reduce(function (memo, key) { | ||
if (memo[key]) { | ||
memo[key] = parseInt(memo[key], 10); | ||
} | ||
return memo; | ||
}, query); | ||
} | ||
var Fields = function () { | ||
function Fields(sdk, request, baseUrl) { | ||
classCallCheck(this, Fields); | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
} | ||
createClass(Fields, [{ | ||
key: 'get', | ||
value: function get$$1(outputFieldId) { | ||
if (!outputFieldId) { | ||
return Promise.reject(new Error('An outputFieldId is required for getting information about an output field')); | ||
} | ||
return this._request.get(this._baseUrl + '/fields/' + outputFieldId).then(function (outputField) { | ||
return formatOutputFieldFromServer(outputField); | ||
}); | ||
} | ||
}]); | ||
return Fields; | ||
}(); | ||
var Outputs = function () { | ||
function Outputs(sdk, request, baseUrl) { | ||
classCallCheck(this, Outputs); | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
} | ||
createClass(Outputs, [{ | ||
key: 'getFieldData', | ||
value: function getFieldData(outputId, fieldHumanName, options) { | ||
if (!outputId) { | ||
return Promise.reject(new Error('An outputId is required for getting data about a specific output')); | ||
} | ||
if (!fieldHumanName) { | ||
return Promise.reject(new Error("A fieldHumanName is required for getting a specific field's output data")); | ||
} | ||
return this._request.get(this._baseUrl + '/outputs/' + outputId + '/fields/' + fieldHumanName + '/data', { params: options }).then(function (fieldData) { | ||
return formatOutputFieldDataFromServer(fieldData); | ||
}); | ||
} | ||
}]); | ||
return Outputs; | ||
}(); | ||
var Iot = | ||
function Iot(sdk, request) { | ||
classCallCheck(this, Iot); | ||
var baseUrl = sdk.config.audiences.iot.host + '/v1'; | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
this.fields = new Fields(sdk, request, baseUrl); | ||
this.outputs = new Outputs(sdk, request, baseUrl); | ||
}; | ||
var Request = function () { | ||
function Request(sdk, audienceName) { | ||
classCallCheck(this, Request); | ||
this._audienceName = audienceName; | ||
this._axios = axios.create(); | ||
this._insertHeaders = this._insertHeaders.bind(this); | ||
this._sdk = sdk; | ||
this._attachInterceptors(); | ||
} | ||
createClass(Request, [{ | ||
key: 'delete', | ||
value: function _delete() { | ||
var _axios; | ||
return (_axios = this._axios).delete.apply(_axios, arguments).then(function (_ref) { | ||
var data = _ref.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get$$1() { | ||
var _axios2; | ||
return (_axios2 = this._axios).get.apply(_axios2, arguments).then(function (_ref2) { | ||
var data = _ref2.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'head', | ||
value: function head() { | ||
var _axios3; | ||
return (_axios3 = this._axios).head.apply(_axios3, arguments).then(function (_ref3) { | ||
var data = _ref3.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'options', | ||
value: function options() { | ||
var _axios4; | ||
return (_axios4 = this._axios).options.apply(_axios4, arguments).then(function (_ref4) { | ||
var data = _ref4.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'patch', | ||
value: function patch() { | ||
var _axios5; | ||
return (_axios5 = this._axios).patch.apply(_axios5, arguments).then(function (_ref5) { | ||
var data = _ref5.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'post', | ||
value: function post() { | ||
var _axios6; | ||
return (_axios6 = this._axios).post.apply(_axios6, arguments).then(function (_ref6) { | ||
var data = _ref6.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'put', | ||
value: function put() { | ||
var _axios7; | ||
return (_axios7 = this._axios).put.apply(_axios7, arguments).then(function (_ref7) { | ||
var data = _ref7.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'request', | ||
value: function request() { | ||
var _axios8; | ||
return (_axios8 = this._axios).request.apply(_axios8, arguments).then(function (_ref8) { | ||
var data = _ref8.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: '_attachInterceptors', | ||
value: function _attachInterceptors() { | ||
var _this = this; | ||
var requestInterceptors = [{ fulfilled: this._insertHeaders }].concat(toConsumableArray(this._sdk.config.interceptors.request)); | ||
var responseInterceptors = [].concat(toConsumableArray(this._sdk.config.interceptors.response)); | ||
requestInterceptors.forEach(function (_ref9) { | ||
var fulfilled = _ref9.fulfilled, | ||
rejected = _ref9.rejected; | ||
_this._axios.interceptors.request.use(fulfilled, rejected); | ||
}); | ||
responseInterceptors.forEach(function (_ref10) { | ||
var fulfilled = _ref10.fulfilled, | ||
rejected = _ref10.rejected; | ||
_this._axios.interceptors.response.use(fulfilled, rejected); | ||
}); | ||
} | ||
}, { | ||
key: '_insertHeaders', | ||
value: function _insertHeaders(config) { | ||
return this._sdk.auth.getCurrentApiToken(this._audienceName).then(function (apiToken) { | ||
config.headers.common.Authorization = 'Bearer ' + apiToken; | ||
return config; | ||
}); | ||
} | ||
}]); | ||
return Request; | ||
}(); | ||
var Auth0WebAuth = function () { | ||
@@ -1689,2 +1828,3 @@ | ||
this._sessionInfo = {}; | ||
this._tokenPromises = {}; | ||
@@ -1740,4 +1880,4 @@ if (!this._sdk.config.auth.clientId) { | ||
if (!this._tokenPromise) { | ||
this._tokenPromise = axios.post(this._sdk.config.audiences.contxtAuth.host + '/v1/oauth/token', { | ||
if (!this._tokenPromises[audienceName]) { | ||
this._tokenPromises[audienceName] = axios.post(this._sdk.config.audiences.contxtAuth.host + '/v1/oauth/token', { | ||
audience: audience.clientId, | ||
@@ -1756,3 +1896,3 @@ client_id: this._sdk.config.auth.clientId, | ||
_this._saveSession(audienceName, sessionInfo); | ||
_this._tokenPromise = null; | ||
_this._tokenPromises[audienceName] = null; | ||
@@ -1769,3 +1909,3 @@ return sessionInfo; | ||
return this._tokenPromise; | ||
return this._tokenPromises[audienceName]; | ||
} | ||
@@ -1803,2 +1943,3 @@ | ||
this.facilities = new Facilities(this, this._createRequest('facilities')); | ||
this.iot = new Iot(this, this._createRequest('iot')); | ||
@@ -1805,0 +1946,0 @@ this._decorate(externalModules); |
411
lib/index.js
@@ -28,2 +28,12 @@ 'use strict'; | ||
} | ||
}, | ||
iot: { | ||
staging: { | ||
clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES', | ||
host: 'https://feeds-staging.api.ndustrial.io' | ||
}, | ||
production: { | ||
clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA', | ||
host: 'https://feeds.api.ndustrial.io' | ||
} | ||
} | ||
@@ -375,2 +385,3 @@ }; | ||
address2: input.address2, | ||
assetId: input.asset_id, | ||
city: input.city, | ||
@@ -417,2 +428,3 @@ createdAt: input.created_at, | ||
address2: input.address2, | ||
asset_id: input.assetId, | ||
city: input.city, | ||
@@ -900,138 +912,48 @@ geometry_id: input.geometryId, | ||
var Request = function () { | ||
function formatOutputFieldFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
function Request(sdk, audienceName) { | ||
classCallCheck(this, Request); | ||
return { | ||
canAggregate: input.can_aggregate, | ||
divisor: input.divisor, | ||
feedKey: input.feed_key, | ||
fieldDescriptor: input.field_descriptor, | ||
fieldHumanName: input.field_human_name, | ||
fieldName: input.field_name, | ||
id: input.id, | ||
isDefault: input.is_default, | ||
isHidden: input.is_hidden, | ||
isTotalizer: input.is_totalizer, | ||
isWindowed: input.is_windowed, | ||
label: input.label, | ||
outputId: input.output_id, | ||
scalar: input.scalar, | ||
status: input.status, | ||
units: input.units, | ||
valueType: input.value_type | ||
}; | ||
} | ||
this._audienceName = audienceName; | ||
this._axios = axios.create(); | ||
this._insertHeaders = this._insertHeaders.bind(this); | ||
this._sdk = sdk; | ||
function formatOutputFieldDataFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
this._attachInterceptors(); | ||
} | ||
var meta = input.meta || {}; | ||
var query = parseOutputFieldNextPageUrlMetadata(meta.next_page_url); | ||
var records = input.records || []; | ||
createClass(Request, [{ | ||
key: 'delete', | ||
value: function _delete() { | ||
var _axios; | ||
return { | ||
meta: _extends({}, query, { | ||
count: meta.count, | ||
hasMore: meta.has_more, | ||
nextRecordTime: meta.next_record_time | ||
}), | ||
records: records.map(function (record) { | ||
return { | ||
eventTime: record.event_time, | ||
value: record.value | ||
}; | ||
}) | ||
}; | ||
} | ||
return (_axios = this._axios).delete.apply(_axios, arguments).then(function (_ref) { | ||
var data = _ref.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get$$1() { | ||
var _axios2; | ||
return (_axios2 = this._axios).get.apply(_axios2, arguments).then(function (_ref2) { | ||
var data = _ref2.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'head', | ||
value: function head() { | ||
var _axios3; | ||
return (_axios3 = this._axios).head.apply(_axios3, arguments).then(function (_ref3) { | ||
var data = _ref3.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'options', | ||
value: function options() { | ||
var _axios4; | ||
return (_axios4 = this._axios).options.apply(_axios4, arguments).then(function (_ref4) { | ||
var data = _ref4.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'patch', | ||
value: function patch() { | ||
var _axios5; | ||
return (_axios5 = this._axios).patch.apply(_axios5, arguments).then(function (_ref5) { | ||
var data = _ref5.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'post', | ||
value: function post() { | ||
var _axios6; | ||
return (_axios6 = this._axios).post.apply(_axios6, arguments).then(function (_ref6) { | ||
var data = _ref6.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'put', | ||
value: function put() { | ||
var _axios7; | ||
return (_axios7 = this._axios).put.apply(_axios7, arguments).then(function (_ref7) { | ||
var data = _ref7.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'request', | ||
value: function request() { | ||
var _axios8; | ||
return (_axios8 = this._axios).request.apply(_axios8, arguments).then(function (_ref8) { | ||
var data = _ref8.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: '_attachInterceptors', | ||
value: function _attachInterceptors() { | ||
var _this = this; | ||
var requestInterceptors = [{ fulfilled: this._insertHeaders }].concat(toConsumableArray(this._sdk.config.interceptors.request)); | ||
var responseInterceptors = [].concat(toConsumableArray(this._sdk.config.interceptors.response)); | ||
requestInterceptors.forEach(function (_ref9) { | ||
var fulfilled = _ref9.fulfilled, | ||
rejected = _ref9.rejected; | ||
_this._axios.interceptors.request.use(fulfilled, rejected); | ||
}); | ||
responseInterceptors.forEach(function (_ref10) { | ||
var fulfilled = _ref10.fulfilled, | ||
rejected = _ref10.rejected; | ||
_this._axios.interceptors.response.use(fulfilled, rejected); | ||
}); | ||
} | ||
}, { | ||
key: '_insertHeaders', | ||
value: function _insertHeaders(config) { | ||
return this._sdk.auth.getCurrentApiToken(this._audienceName).then(function (apiToken) { | ||
config.headers.common.Authorization = 'Bearer ' + apiToken; | ||
return config; | ||
}); | ||
} | ||
}]); | ||
return Request; | ||
}(); | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
@@ -1388,2 +1310,219 @@ | ||
function parseOutputFieldNextPageUrlMetadata(url) { | ||
var query = new urlParse(url, true).query; | ||
return ['limit', 'timeEnd', 'timeStart', 'window'].reduce(function (memo, key) { | ||
if (memo[key]) { | ||
memo[key] = parseInt(memo[key], 10); | ||
} | ||
return memo; | ||
}, query); | ||
} | ||
var Fields = function () { | ||
function Fields(sdk, request, baseUrl) { | ||
classCallCheck(this, Fields); | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
} | ||
createClass(Fields, [{ | ||
key: 'get', | ||
value: function get$$1(outputFieldId) { | ||
if (!outputFieldId) { | ||
return Promise.reject(new Error('An outputFieldId is required for getting information about an output field')); | ||
} | ||
return this._request.get(this._baseUrl + '/fields/' + outputFieldId).then(function (outputField) { | ||
return formatOutputFieldFromServer(outputField); | ||
}); | ||
} | ||
}]); | ||
return Fields; | ||
}(); | ||
var Outputs = function () { | ||
function Outputs(sdk, request, baseUrl) { | ||
classCallCheck(this, Outputs); | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
} | ||
createClass(Outputs, [{ | ||
key: 'getFieldData', | ||
value: function getFieldData(outputId, fieldHumanName, options) { | ||
if (!outputId) { | ||
return Promise.reject(new Error('An outputId is required for getting data about a specific output')); | ||
} | ||
if (!fieldHumanName) { | ||
return Promise.reject(new Error("A fieldHumanName is required for getting a specific field's output data")); | ||
} | ||
return this._request.get(this._baseUrl + '/outputs/' + outputId + '/fields/' + fieldHumanName + '/data', { params: options }).then(function (fieldData) { | ||
return formatOutputFieldDataFromServer(fieldData); | ||
}); | ||
} | ||
}]); | ||
return Outputs; | ||
}(); | ||
var Iot = | ||
function Iot(sdk, request) { | ||
classCallCheck(this, Iot); | ||
var baseUrl = sdk.config.audiences.iot.host + '/v1'; | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
this.fields = new Fields(sdk, request, baseUrl); | ||
this.outputs = new Outputs(sdk, request, baseUrl); | ||
}; | ||
var Request = function () { | ||
function Request(sdk, audienceName) { | ||
classCallCheck(this, Request); | ||
this._audienceName = audienceName; | ||
this._axios = axios.create(); | ||
this._insertHeaders = this._insertHeaders.bind(this); | ||
this._sdk = sdk; | ||
this._attachInterceptors(); | ||
} | ||
createClass(Request, [{ | ||
key: 'delete', | ||
value: function _delete() { | ||
var _axios; | ||
return (_axios = this._axios).delete.apply(_axios, arguments).then(function (_ref) { | ||
var data = _ref.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get$$1() { | ||
var _axios2; | ||
return (_axios2 = this._axios).get.apply(_axios2, arguments).then(function (_ref2) { | ||
var data = _ref2.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'head', | ||
value: function head() { | ||
var _axios3; | ||
return (_axios3 = this._axios).head.apply(_axios3, arguments).then(function (_ref3) { | ||
var data = _ref3.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'options', | ||
value: function options() { | ||
var _axios4; | ||
return (_axios4 = this._axios).options.apply(_axios4, arguments).then(function (_ref4) { | ||
var data = _ref4.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'patch', | ||
value: function patch() { | ||
var _axios5; | ||
return (_axios5 = this._axios).patch.apply(_axios5, arguments).then(function (_ref5) { | ||
var data = _ref5.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'post', | ||
value: function post() { | ||
var _axios6; | ||
return (_axios6 = this._axios).post.apply(_axios6, arguments).then(function (_ref6) { | ||
var data = _ref6.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'put', | ||
value: function put() { | ||
var _axios7; | ||
return (_axios7 = this._axios).put.apply(_axios7, arguments).then(function (_ref7) { | ||
var data = _ref7.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: 'request', | ||
value: function request() { | ||
var _axios8; | ||
return (_axios8 = this._axios).request.apply(_axios8, arguments).then(function (_ref8) { | ||
var data = _ref8.data; | ||
return data; | ||
}); | ||
} | ||
}, { | ||
key: '_attachInterceptors', | ||
value: function _attachInterceptors() { | ||
var _this = this; | ||
var requestInterceptors = [{ fulfilled: this._insertHeaders }].concat(toConsumableArray(this._sdk.config.interceptors.request)); | ||
var responseInterceptors = [].concat(toConsumableArray(this._sdk.config.interceptors.response)); | ||
requestInterceptors.forEach(function (_ref9) { | ||
var fulfilled = _ref9.fulfilled, | ||
rejected = _ref9.rejected; | ||
_this._axios.interceptors.request.use(fulfilled, rejected); | ||
}); | ||
responseInterceptors.forEach(function (_ref10) { | ||
var fulfilled = _ref10.fulfilled, | ||
rejected = _ref10.rejected; | ||
_this._axios.interceptors.response.use(fulfilled, rejected); | ||
}); | ||
} | ||
}, { | ||
key: '_insertHeaders', | ||
value: function _insertHeaders(config) { | ||
return this._sdk.auth.getCurrentApiToken(this._audienceName).then(function (apiToken) { | ||
config.headers.common.Authorization = 'Bearer ' + apiToken; | ||
return config; | ||
}); | ||
} | ||
}]); | ||
return Request; | ||
}(); | ||
var Auth0WebAuth = function () { | ||
@@ -1693,2 +1832,3 @@ | ||
this._sessionInfo = {}; | ||
this._tokenPromises = {}; | ||
@@ -1744,4 +1884,4 @@ if (!this._sdk.config.auth.clientId) { | ||
if (!this._tokenPromise) { | ||
this._tokenPromise = axios.post(this._sdk.config.audiences.contxtAuth.host + '/v1/oauth/token', { | ||
if (!this._tokenPromises[audienceName]) { | ||
this._tokenPromises[audienceName] = axios.post(this._sdk.config.audiences.contxtAuth.host + '/v1/oauth/token', { | ||
audience: audience.clientId, | ||
@@ -1760,3 +1900,3 @@ client_id: this._sdk.config.auth.clientId, | ||
_this._saveSession(audienceName, sessionInfo); | ||
_this._tokenPromise = null; | ||
_this._tokenPromises[audienceName] = null; | ||
@@ -1773,3 +1913,3 @@ return sessionInfo; | ||
return this._tokenPromise; | ||
return this._tokenPromises[audienceName]; | ||
} | ||
@@ -1807,2 +1947,3 @@ | ||
this.facilities = new Facilities(this, this._createRequest('facilities')); | ||
this.iot = new Iot(this, this._createRequest('iot')); | ||
@@ -1809,0 +1950,0 @@ this._decorate(externalModules); |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -21,3 +21,13 @@ export default { | ||
} | ||
}, | ||
iot: { | ||
staging: { | ||
clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES', | ||
host: 'https://feeds-staging.api.ndustrial.io' | ||
}, | ||
production: { | ||
clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA', | ||
host: 'https://feeds.api.ndustrial.io' | ||
} | ||
} | ||
}; |
@@ -95,3 +95,3 @@ import isPlainObject from 'lodash.isplainobject'; | ||
* @param {Object} costCenter | ||
* @param {string} costCenter.description | ||
* @param {string} [costCenter.description] | ||
* @param {string} costCenter.name | ||
@@ -147,3 +147,5 @@ * @param {string} costCenter.organizationId UUID | ||
* @example | ||
* contxtSdk.facilities.costCenters.delete('e4fec739-56aa-4b50-8dab-e9d6b9c91a5d') | ||
* contxtSdk.facilities.costCenters.delete( | ||
* 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d' | ||
* ); | ||
*/ | ||
@@ -228,3 +230,4 @@ delete(costCenterId) { | ||
* @example | ||
* contxtSdk.facilities.costCenters.removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
* contxtSdk.facilities.costCenters | ||
* .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
* .catch((err) => console.log(err)); | ||
@@ -231,0 +234,0 @@ */ |
@@ -11,3 +11,3 @@ import isPlainObject from 'lodash.isplainobject'; | ||
* @param {string} createdAt ISO 8601 Extended Format date/time string | ||
* @param {string} description | ||
* @param {string} [description] | ||
* @param {Facility[]} [facilities] | ||
@@ -19,3 +19,3 @@ * @param {string} id UUID | ||
* @param {string} ownerId Auth0 identifer of the user | ||
* @param {string} parentGroupingId UUID | ||
* @param {string} [parentGroupingId] UUID | ||
* @param {string} updatedAt ISO 8601 Extended Format date/time string | ||
@@ -65,3 +65,4 @@ */ | ||
* @example | ||
* contxtSdk.facilities.groupings.addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
* contxtSdk.facilities.groupings | ||
* .addFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
* .then((grouping) => console.log(grouping)) | ||
@@ -119,3 +120,3 @@ * .catch((err) => console.log(err)); | ||
* name: 'New England, USA', | ||
* organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5' | ||
* organizationId: '61f5fe1d-d202-4ae7-af76-8f37f5bbeec5', | ||
* parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e' | ||
@@ -159,3 +160,5 @@ * }) | ||
* @example | ||
* contxtSdk.facilities.groupings.delete('e4fec739-56aa-4b50-8dab-e9d6b9c91a5d') | ||
* contxtSdk.facilities.groupings.delete( | ||
* 'e4fec739-56aa-4b50-8dab-e9d6b9c91a5d' | ||
* ); | ||
*/ | ||
@@ -188,3 +191,4 @@ delete(facilityGroupingId) { | ||
* @example | ||
* contxtSdk.facilites.groupings.getAll() | ||
* contxtSdk.facilites.groupings | ||
* .getAll() | ||
* .then((groupings) => console.log(groupings)) | ||
@@ -213,3 +217,4 @@ * .catch((err) => console.log(err)); | ||
* @example | ||
* contxtSdk.facilites.groupings.getAll() | ||
* contxtSdk.facilites.groupings | ||
* .getAllByOrganizationId('349dbd36-5dca-4a10-b54d-d0f71c3c8709') | ||
* .then((groupings) => console.log(groupings)) | ||
@@ -245,3 +250,4 @@ * .catch((err) => console.log(err)); | ||
* @example | ||
* contxtSdk.facilities.groupings.removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
* contxtSdk.facilities.groupings | ||
* .removeFacility('b3dbaae3-25dd-475b-80dc-66296630a8d0', 4) | ||
* .catch((err) => console.log(err)); | ||
@@ -248,0 +254,0 @@ */ |
@@ -12,7 +12,8 @@ import isPlainObject from 'lodash.isplainobject'; | ||
* @typedef {Object} Facility | ||
* @property {string} address1 | ||
* @property {string} address2 | ||
* @property {string} city | ||
* @property {string} [address1] | ||
* @property {string} [address2] | ||
* @property {string} [assetId] UUID corresponding with an asset | ||
* @property {string} [city] | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} geometryId UUID corresponding with a geometry | ||
* @property {string} [geometryId] UUID corresponding with a geometry | ||
* @property {number} id | ||
@@ -26,3 +27,3 @@ * @property {Object} [Info] User declared information | ||
* @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} state | ||
* @property {string} [state] | ||
* @property {Object[]} [tags] | ||
@@ -35,4 +36,4 @@ * @property {string} [tags[].createdAt] ISO 8601 Extended Format date/time string | ||
* @property {string} timezone An IANA Time Zone Database string, i.e. America/Los_Angeles | ||
* @property {number} weatherLocationId | ||
* @property {string} zip US Zip Code | ||
* @property {number} [weatherLocationId] | ||
* @property {string} [zip] US Zip Code | ||
*/ | ||
@@ -71,2 +72,3 @@ | ||
* @param {string} [facility.address2] | ||
* @param {string} [facility.assetId] UUID corresponding with an asset | ||
* @param {string} [facility.city] | ||
@@ -92,3 +94,3 @@ * @param {string} [facility.geometryId] UUID corresponding with a geometry | ||
* }) | ||
* .then((facilities) => console.log(facilities)); | ||
* .then((facilities) => console.log(facilities)) | ||
* .catch((err) => console.log(err)); | ||
@@ -181,3 +183,3 @@ */ | ||
* @example | ||
* contxtSdk.facilities.delete(25) | ||
* contxtSdk.facilities.delete(25); | ||
*/ | ||
@@ -207,4 +209,5 @@ delete(facilityId) { | ||
* @example | ||
* contxtSdk.facilities.get(25) | ||
* .then((facility) => console.log(facility)); | ||
* contxtSdk.facilities | ||
* .get(25) | ||
* .then((facility) => console.log(facility)) | ||
* .catch((err) => console.log(err)); | ||
@@ -237,4 +240,5 @@ */ | ||
* @example | ||
* contxtSdk.facilities.getAll() | ||
* .then((facilities) => console.log(facilities)); | ||
* contxtSdk.facilities | ||
* .getAll() | ||
* .then((facilities) => console.log(facilities)) | ||
* .catch((err) => console.log(err)); | ||
@@ -265,4 +269,5 @@ */ | ||
* @example | ||
* contxtSdk.facilities.getAllByOrganizationId(25, {includeGroupings: true}) | ||
* .then((facilities) => console.log(facilities)); | ||
* contxtSdk.facilities | ||
* .getAllByOrganizationId(25, { includeGroupings: true }) | ||
* .then((facilities) => console.log(facilities)) | ||
* .catch((err) => console.log(err)); | ||
@@ -300,2 +305,3 @@ */ | ||
* @param {string} [update.address2] | ||
* @param {string} [update.assetId] UUID corresponding with an asset | ||
* @param {string} [update.city] | ||
@@ -302,0 +308,0 @@ * @param {string} [update.geometryId] UUID corresponding with a geometry |
@@ -284,3 +284,3 @@ import omit from 'lodash.omit'; | ||
it('gets a list of facilities from the server', function() { | ||
it('gets the facility from the server', function() { | ||
expect(request.get).to.be.calledWith( | ||
@@ -287,0 +287,0 @@ `${expectedHost}/facilities/${expectedFacilityId}` |
import Config from './config'; | ||
import Facilities from './facilities'; | ||
import Iot from './iot'; | ||
import Request from './request'; | ||
@@ -71,2 +72,3 @@ import * as sessionTypes from './sessionTypes'; | ||
this.facilities = new Facilities(this, this._createRequest('facilities')); | ||
this.iot = new Iot(this, this._createRequest('iot')); | ||
@@ -123,3 +125,6 @@ this._decorate(externalModules); | ||
Object.keys(modules).forEach((moduleName) => { | ||
this[moduleName] = new modules[moduleName].module(this, this._createRequest(moduleName)); | ||
this[moduleName] = new modules[moduleName].module( | ||
this, | ||
this._createRequest(moduleName) | ||
); | ||
}); | ||
@@ -126,0 +131,0 @@ } |
@@ -5,2 +5,3 @@ import times from 'lodash.times'; | ||
import Facilities from './facilities'; | ||
import Iot from './iot'; | ||
import Request from './request'; | ||
@@ -77,2 +78,10 @@ import * as sessionTypes from './sessionTypes'; | ||
it('creates an instance of the request module for IOT', function() { | ||
expect(createRequest).to.be.calledWith('iot'); | ||
}); | ||
it('sets an instance of IOT', function() { | ||
expect(contxtSdk.iot).to.be.an.instanceof(Iot); | ||
}); | ||
it('decorates the additional custom modules', function() { | ||
@@ -79,0 +88,0 @@ expect(decorate).to.be.calledWith(expectedExternalModules); |
@@ -38,2 +38,3 @@ import axios from 'axios'; | ||
this._sessionInfo = {}; | ||
this._tokenPromises = {}; | ||
@@ -105,4 +106,4 @@ if (!this._sdk.config.auth.clientId) { | ||
if (!this._tokenPromise) { | ||
this._tokenPromise = axios | ||
if (!this._tokenPromises[audienceName]) { | ||
this._tokenPromises[audienceName] = axios | ||
.post(`${this._sdk.config.audiences.contxtAuth.host}/v1/oauth/token`, { | ||
@@ -122,3 +123,3 @@ audience: audience.clientId, | ||
this._saveSession(audienceName, sessionInfo); | ||
this._tokenPromise = null; | ||
this._tokenPromises[audienceName] = null; | ||
@@ -138,3 +139,3 @@ return sessionInfo; | ||
return this._tokenPromise; | ||
return this._tokenPromises[audienceName]; | ||
} | ||
@@ -141,0 +142,0 @@ |
@@ -279,3 +279,3 @@ import axios from 'axios'; | ||
it('saves the axios promise to the instance', function() { | ||
expect(machineAuth._tokenPromise).to.equal(promise); | ||
expect(machineAuth._tokenPromises[audienceName]).to.equal(promise); | ||
}); | ||
@@ -294,3 +294,3 @@ | ||
return promise.then(() => { | ||
expect(machineAuth._tokenPromise).to.be.null; | ||
expect(machineAuth._tokenPromises[audienceName]).to.be.null; | ||
}); | ||
@@ -316,3 +316,5 @@ }); | ||
const machineAuth = new MachineAuth(sdk); | ||
machineAuth._tokenPromise = expectedPromise; | ||
machineAuth._tokenPromises = { | ||
[audienceName]: expectedPromise | ||
}; | ||
promise = machineAuth._getNewSessionInfo(audienceName); | ||
@@ -327,2 +329,34 @@ }); | ||
context( | ||
'when tokens are requested for two different audiences', | ||
function() { | ||
let expectedPromiseOne; | ||
let expectedPromiseTwo; | ||
let promiseOne; | ||
let promiseTwo; | ||
beforeEach(function() { | ||
const audienceNameOne = faker.hacker.adjective(); | ||
const audienceNameTwo = faker.hacker.adjective(); | ||
expectedPromiseOne = Promise.resolve(); | ||
expectedPromiseTwo = Promise.resolve(); | ||
sdk.config.audiences[audienceNameOne] = fixture.build('audience'); | ||
sdk.config.audiences[audienceNameTwo] = fixture.build('audience'); | ||
const machineAuth = new MachineAuth(sdk); | ||
machineAuth._tokenPromises = { | ||
[audienceNameOne]: expectedPromiseOne, | ||
[audienceNameTwo]: expectedPromiseTwo | ||
}; | ||
promiseOne = machineAuth._getNewSessionInfo(audienceNameOne); | ||
promiseTwo = machineAuth._getNewSessionInfo(audienceNameTwo); | ||
}); | ||
it('should return two different promises', function() { | ||
expect(promiseOne).to.equal(expectedPromiseOne); | ||
expect(promiseTwo).to.equal(expectedPromiseTwo); | ||
}); | ||
} | ||
); | ||
context( | ||
'when there is not a configuration for chosen audience', | ||
@@ -329,0 +363,0 @@ function() { |
@@ -14,2 +14,3 @@ import { | ||
* @param {string} input.address2 | ||
* @param {string} [input.asset_id] UUID corresponding with an asset | ||
* @param {string} input.city | ||
@@ -59,2 +60,3 @@ * @param {Object[]} [input.cost_centers] | ||
address2: input.address2, | ||
assetId: input.asset_id, | ||
city: input.city, | ||
@@ -61,0 +63,0 @@ createdAt: input.created_at, |
@@ -40,2 +40,3 @@ import omit from 'lodash.omit'; | ||
...facility, | ||
assetId: facility.asset_id, | ||
createdAt: facility.created_at, | ||
@@ -49,2 +50,3 @@ geometryId: facility.geometry_id, | ||
[ | ||
'asset_id', | ||
'created_at', | ||
@@ -51,0 +53,0 @@ 'geometry_id', |
@@ -9,2 +9,3 @@ /** | ||
* @returns {string} output.address2 | ||
* @returns {string} output.asset_id | ||
* @returns {string} output.city | ||
@@ -26,2 +27,3 @@ * @returns {string} output.geometry_id UUID corresponding with a geometry | ||
address2: input.address2, | ||
asset_id: input.assetId, | ||
city: input.city, | ||
@@ -28,0 +30,0 @@ geometry_id: input.geometryId, |
@@ -14,2 +14,3 @@ import omit from 'lodash.omit'; | ||
...facility, | ||
asset_id: facility.assetId, | ||
geometry_id: facility.geometryId, | ||
@@ -21,2 +22,3 @@ Info: facility.info, | ||
[ | ||
'assetId', | ||
'createdAt', | ||
@@ -23,0 +25,0 @@ 'facility_groupings', |
@@ -14,2 +14,3 @@ 'use strict'; | ||
address2: () => faker.address.secondaryAddress(), | ||
assetId: () => faker.random.uuid(), | ||
city: () => faker.address.city(), | ||
@@ -16,0 +17,0 @@ createdAt: () => faker.date.past().toISOString(), |
@@ -14,2 +14,4 @@ 'use strict'; | ||
require('./facilityTag'); | ||
require('./outputField'); | ||
require('./outputFieldData'); | ||
require('./organization'); | ||
@@ -16,0 +18,0 @@ require('./userProfile'); |
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
741345
106
10829