@ndustrial/contxt-sdk
Advanced tools
Comparing version 2.7.0 to 2.8.0
@@ -0,1 +1,7 @@ | ||
## [v2.8.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v2.8.0) (2020-01-29) | ||
**Added** | ||
- Added `Events#getUserInfo` for getting information about a contxt user. | ||
## [v2.7.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v2.7.0) (2020-01-28) | ||
@@ -2,0 +8,0 @@ |
@@ -16,2 +16,3 @@ <a name="Events"></a> | ||
* [.getEventsByTypeId(eventTypeId, [latest])](#Events+getEventsByTypeId) ⇒ <code>Promise</code> | ||
* [.getUserInfo(userId)](#Events+getUserInfo) ⇒ <code>Promise</code> | ||
* [.subscribeUser(userId, eventId)](#Events+subscribeUser) ⇒ <code>Promise</code> | ||
@@ -168,2 +169,25 @@ * [.unsubscribeUser(userId, userEventSubscriptionId)](#Events+unsubscribeUser) ⇒ <code>Promise</code> | ||
``` | ||
<a name="Events+getUserInfo"></a> | ||
### contxtSdk.events.getUserInfo(userId) ⇒ <code>Promise</code> | ||
Gets information about a contxt user with additional information related to event subscriptions | ||
API Endpoint: '/users/:userId' | ||
Method: GET | ||
**Kind**: instance method of [<code>Events</code>](#Events) | ||
**Fulfill**: [<code>EventUser</code>](./Typedefs.md#EventUser) Information about an event user | ||
**Reject**: <code>Error</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| userId | <code>string</code> | The ID of the user | | ||
**Example** | ||
```js | ||
contxtSdk.events | ||
.getUserInfo('auth0|saklafjheuaiweh') | ||
.then((user) => console.log(user)) | ||
.catch((err) => console.log(err)); | ||
``` | ||
<a name="Events+subscribeUser"></a> | ||
@@ -170,0 +194,0 @@ |
@@ -238,2 +238,4 @@ ## Classes | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#EventUser">EventUser</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#EventsFromServer">EventsFromServer</a> : <code>Object</code></dt> | ||
@@ -240,0 +242,0 @@ <dd></dd> |
@@ -656,2 +656,32 @@ <a name="Asset"></a> | ||
<a name="EventUser"></a> | ||
## EventUser : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| email | <code>string</code> | | | ||
| firstName | <code>string</code> | | | ||
| id | <code>string</code> | | | ||
| isMachineUser | <code>boolean</code> | | | ||
| [IOSDevices] | <code>Array.<Object></code> | | | ||
| [IOSDevices.createdAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [IOSDevices.isActive] | <code>boolean</code> | | | ||
| [IOSDevices.snsEndpointArn] | <code>string</code> | | | ||
| [IOSDevices.userId] | <code>string</code> | | | ||
| [IOSDevices.updatedAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| lastName | <code>string</code> | | | ||
| [userMobileNumbers] | <code>Array.<Object></code> | | | ||
| [userMobileNumbers.createdAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [userMobileNumbers.name] | <code>string</code> | | | ||
| [userMobileNumbers.isActive] | <code>boolean</code> | | | ||
| [userMobileNumbers.phoneNumber] | <code>string</code> | | | ||
| [userMobileNumbers.updatedAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [userMobileNumbers.userId] | <code>string</code> | | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| records | [<code>Array.<UserEventSubscription></code>](#UserEventSubscription) | | | ||
<a name="EventsFromServer"></a> | ||
@@ -1149,7 +1179,9 @@ | ||
| --- | --- | --- | | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [endpointArn] | <code>string</code> | | | ||
| eventId | <code>string</code> | | | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| id | <code>string</code> | | | ||
| mediumType | <code>string</code> | | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| userId | <code>string</code> | | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
@@ -1156,0 +1188,0 @@ <a name="UserProfile"></a> |
@@ -46,2 +46,27 @@ 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} EventUser | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} email | ||
* @property {string} firstName | ||
* @property {string} id | ||
* @property {boolean} isMachineUser | ||
* @property {Object[]} [IOSDevices] | ||
* @property {string} [IOSDevices.createdAt] ISO 8601 Extended Format date/time string | ||
* @property {boolean} [IOSDevices.isActive] | ||
* @property {string} [IOSDevices.snsEndpointArn] | ||
* @property {string} [IOSDevices.userId] | ||
* @property {string} [IOSDevices.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} lastName | ||
* @property {Object[]} [userMobileNumbers] | ||
* @property {string} [userMobileNumbers.createdAt] ISO 8601 Extended Format date/time string | ||
* @property {string} [userMobileNumbers.name] | ||
* @property {boolean} [userMobileNumbers.isActive] | ||
* @property {string} [userMobileNumbers.phoneNumber] | ||
* @property {string} [userMobileNumbers.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} [userMobileNumbers.userId] | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
* @property {UserEventSubscription[]} records | ||
*/ | ||
/** | ||
* @typedef {Object} EventsFromServer | ||
@@ -78,7 +103,9 @@ * @property {Object} _metadata Metadata about the pagination settings | ||
* @typedef {Object} UserEventSubscription | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} [endpointArn] | ||
* @property {string} eventId | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} id | ||
* @property {string} mediumType | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
* @property {string} userId | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
@@ -299,2 +326,33 @@ | ||
/** | ||
* Gets information about a contxt user with additional information related to event subscriptions | ||
* | ||
* API Endpoint: '/users/:userId' | ||
* Method: GET | ||
* | ||
* @param {string} userId The ID of the user | ||
* | ||
* @returns {Promise} | ||
* @fulfill {EventUser} Information about an event user | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.events | ||
* .getUserInfo('auth0|saklafjheuaiweh') | ||
* .then((user) => console.log(user)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'getUserInfo', | ||
value: function getUserInfo(userId) { | ||
if (!userId) { | ||
return Promise.reject(new Error('A user ID is required for getting information about a user')); | ||
} | ||
return this._request.get(this._baseUrl + '/users/' + userId).then(function (user) { | ||
return toCamelCase(user); | ||
}); | ||
} | ||
/** | ||
* Subscribes an user to an event | ||
@@ -301,0 +359,0 @@ * |
@@ -62,2 +62,27 @@ 'use strict'; | ||
/** | ||
* @typedef {Object} EventUser | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} email | ||
* @property {string} firstName | ||
* @property {string} id | ||
* @property {boolean} isMachineUser | ||
* @property {Object[]} [IOSDevices] | ||
* @property {string} [IOSDevices.createdAt] ISO 8601 Extended Format date/time string | ||
* @property {boolean} [IOSDevices.isActive] | ||
* @property {string} [IOSDevices.snsEndpointArn] | ||
* @property {string} [IOSDevices.userId] | ||
* @property {string} [IOSDevices.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} lastName | ||
* @property {Object[]} [userMobileNumbers] | ||
* @property {string} [userMobileNumbers.createdAt] ISO 8601 Extended Format date/time string | ||
* @property {string} [userMobileNumbers.name] | ||
* @property {boolean} [userMobileNumbers.isActive] | ||
* @property {string} [userMobileNumbers.phoneNumber] | ||
* @property {string} [userMobileNumbers.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} [userMobileNumbers.userId] | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
* @property {UserEventSubscription[]} records | ||
*/ | ||
/** | ||
* @typedef {Object} EventsFromServer | ||
@@ -94,7 +119,9 @@ * @property {Object} _metadata Metadata about the pagination settings | ||
* @typedef {Object} UserEventSubscription | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} [endpointArn] | ||
* @property {string} eventId | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} id | ||
* @property {string} mediumType | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
* @property {string} userId | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
@@ -314,2 +341,33 @@ | ||
/** | ||
* Gets information about a contxt user with additional information related to event subscriptions | ||
* | ||
* API Endpoint: '/users/:userId' | ||
* Method: GET | ||
* | ||
* @param {string} userId The ID of the user | ||
* | ||
* @returns {Promise} | ||
* @fulfill {EventUser} Information about an event user | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.events | ||
* .getUserInfo('auth0|saklafjheuaiweh') | ||
* .then((user) => console.log(user)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'getUserInfo', | ||
value: function getUserInfo(userId) { | ||
if (!userId) { | ||
return Promise.reject(new Error('A user ID is required for getting information about a user')); | ||
} | ||
return this._request.get(this._baseUrl + '/users/' + userId).then(function (user) { | ||
return (0, _objects.toCamelCase)(user); | ||
}); | ||
} | ||
/** | ||
* Subscribes an user to an event | ||
@@ -316,0 +374,0 @@ * |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -42,2 +42,27 @@ import has from 'lodash.has'; | ||
/** | ||
* @typedef {Object} EventUser | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} email | ||
* @property {string} firstName | ||
* @property {string} id | ||
* @property {boolean} isMachineUser | ||
* @property {Object[]} [IOSDevices] | ||
* @property {string} [IOSDevices.createdAt] ISO 8601 Extended Format date/time string | ||
* @property {boolean} [IOSDevices.isActive] | ||
* @property {string} [IOSDevices.snsEndpointArn] | ||
* @property {string} [IOSDevices.userId] | ||
* @property {string} [IOSDevices.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} lastName | ||
* @property {Object[]} [userMobileNumbers] | ||
* @property {string} [userMobileNumbers.createdAt] ISO 8601 Extended Format date/time string | ||
* @property {string} [userMobileNumbers.name] | ||
* @property {boolean} [userMobileNumbers.isActive] | ||
* @property {string} [userMobileNumbers.phoneNumber] | ||
* @property {string} [userMobileNumbers.updatedAt] ISO 8601 Extended Format date/time string | ||
* @property {string} [userMobileNumbers.userId] | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
* @property {UserEventSubscription[]} records | ||
*/ | ||
/** | ||
* @typedef {Object} EventsFromServer | ||
@@ -74,7 +99,9 @@ * @property {Object} _metadata Metadata about the pagination settings | ||
* @typedef {Object} UserEventSubscription | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} [endpointArn] | ||
* @property {string} eventId | ||
* @property {string} createdAt ISO 8601 Extended Format date/time string | ||
* @property {string} id | ||
* @property {string} mediumType | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
* @property {string} userId | ||
* @property {string} updatedAt ISO 8601 Extended Format date/time string | ||
*/ | ||
@@ -284,2 +311,32 @@ | ||
/** | ||
* Gets information about a contxt user with additional information related to event subscriptions | ||
* | ||
* API Endpoint: '/users/:userId' | ||
* Method: GET | ||
* | ||
* @param {string} userId The ID of the user | ||
* | ||
* @returns {Promise} | ||
* @fulfill {EventUser} Information about an event user | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.events | ||
* .getUserInfo('auth0|saklafjheuaiweh') | ||
* .then((user) => console.log(user)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
getUserInfo(userId) { | ||
if (!userId) { | ||
return Promise.reject( | ||
new Error('A user ID is required for getting information about a user') | ||
); | ||
} | ||
return this._request | ||
.get(`${this._baseUrl}/users/${userId}`) | ||
.then((user) => toCamelCase(user)); | ||
} | ||
/** | ||
* Subscribes an user to an event | ||
@@ -286,0 +343,0 @@ * |
@@ -432,2 +432,62 @@ import omit from 'lodash.omit'; | ||
describe('getUserInfo', function() { | ||
context('the user ID is provided', function() { | ||
let userFromServerAfterFormat; | ||
let userFromServerBeforeFormat; | ||
let promise; | ||
let request; | ||
let toCamelCase; | ||
beforeEach(function() { | ||
userFromServerAfterFormat = fixture.build('eventUser'); | ||
userFromServerBeforeFormat = fixture.build( | ||
'eventUser', | ||
userFromServerAfterFormat, | ||
{ fromServer: true } | ||
); | ||
request = { | ||
...baseRequest, | ||
get: sinon.stub().resolves(userFromServerBeforeFormat) | ||
}; | ||
toCamelCase = sinon | ||
.stub(objectUtils, 'toCamelCase') | ||
.returns(userFromServerAfterFormat); | ||
const events = new Events(baseSdk, request, expectedHost); | ||
events._baseUrl = expectedHost; | ||
promise = events.getUserInfo(userFromServerAfterFormat.id); | ||
}); | ||
it('gets the user from the server', function() { | ||
expect(request.get).to.be.calledWith( | ||
`${expectedHost}/users/${userFromServerAfterFormat.id}` | ||
); | ||
}); | ||
it('formats the user object', function() { | ||
return promise.then(() => { | ||
expect(toCamelCase).to.be.calledWith(userFromServerBeforeFormat); | ||
}); | ||
}); | ||
it('returns the requested user', function() { | ||
return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal( | ||
userFromServerAfterFormat | ||
); | ||
}); | ||
}); | ||
context('the user ID is not provided', function() { | ||
it('throws an error', function() { | ||
const events = new Events(baseSdk, baseRequest, expectedHost); | ||
const promise = events.getUserInfo(); | ||
return expect(promise).to.be.rejectedWith( | ||
'A user ID is required for getting information about a user' | ||
); | ||
}); | ||
}); | ||
}); | ||
describe('update', function() { | ||
@@ -434,0 +494,0 @@ context('when all required information is available', function() { |
@@ -10,5 +10,7 @@ 'use strict'; | ||
.attrs({ | ||
createdAt: () => faker.date.past().toISOString(), | ||
endpointArn: () => null, | ||
eventId: () => factory.build('event').id, | ||
createdAt: () => faker.date.past().toISOString(), | ||
id: () => faker.random.uuid(), | ||
mediumType: () => faker.random.arrayElement(['email', 'sms']), | ||
updatedAt: () => faker.date.recent().toISOString(), | ||
@@ -21,8 +23,14 @@ userId: () => factory.build('contxtUser').id | ||
if (options.fromServer) { | ||
userEvent.event_id = userEvent.eventId; | ||
delete userEvent.applicationId; | ||
userEvent.created_at = userEvent.createdAt; | ||
delete userEvent.createdAt; | ||
userEvent.endpoint_arn = userEvent.endpointArn; | ||
delete userEvent.endpointArn; | ||
userEvent.event_id = userEvent.eventId; | ||
delete userEvent.eventId; | ||
userEvent.medium_type = userEvent.mediumType; | ||
delete userEvent.mediumType; | ||
userEvent.updated_at = userEvent.updatedAt; | ||
@@ -29,0 +37,0 @@ delete userEvent.updatedAt; |
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
2847179
416
46505