@ndustrial/contxt-sdk
Advanced tools
Comparing version 1.0.0-beta.5 to 1.0.0-beta.6
@@ -16,2 +16,10 @@ ## [v1.0.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v1.0.0) (2019-xx-xx) | ||
## [v0.0.49](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.49) (2019-04-22) | ||
**Added** | ||
- Added `Coordinator#inviteNewUserToOrganization` for inviting new users to organizations | ||
- Added `Coordinator#activateNewUser` for activating a user account with an initial password | ||
- Added `Coordinator#removeUserFromOrganization` for removing a user from an organization | ||
## [v0.0.48](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.48) (2019-04-02) | ||
@@ -18,0 +26,0 @@ |
@@ -10,2 +10,3 @@ <a name="Coordinator"></a> | ||
* [new Coordinator(sdk, request)](#new_Coordinator_new) | ||
* [.activateNewUser(userId, user)](#Coordinator+activateNewUser) ⇒ <code>Promise</code> | ||
* [.createFavoriteApplication(applicationId)](#Coordinator+createFavoriteApplication) ⇒ <code>Promise</code> | ||
@@ -21,2 +22,4 @@ * [.deleteFavoriteApplication(applicationId)](#Coordinator+deleteFavoriteApplication) ⇒ <code>Promise</code> | ||
* [.getUserPermissionsMap(userId)](#Coordinator+getUserPermissionsMap) ⇒ <code>Promise</code> | ||
* [.inviteNewUserToOrganization(organizationId, user)](#Coordinator+inviteNewUserToOrganization) ⇒ <code>Promise</code> | ||
* [.removeUserFromOrganization(organizationId, userId)](#Coordinator+removeUserFromOrganization) ⇒ <code>Promise</code> | ||
@@ -32,2 +35,35 @@ <a name="new_Coordinator_new"></a> | ||
<a name="Coordinator+activateNewUser"></a> | ||
### contxtSdk.coordinator.activateNewUser(userId, user) ⇒ <code>Promise</code> | ||
Activates a new user | ||
API Endpoint: '/users/:userId/activate' | ||
Method: POST | ||
Note: Only valid for web users using auth0WebAuth session type | ||
**Kind**: instance method of [<code>Coordinator</code>](#Coordinator) | ||
**Fulfill**: <code>undefined</code> | ||
**Reject**: <code>Error</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| userId | <code>string</code> | The ID of the user to activate | | ||
| user | <code>Object</code> | | | ||
| user.email | <code>string</code> | The email address of the user | | ||
| user.password | <code>string</code> | The password to set for the user | | ||
| user.userToken | <code>string</code> | The JWT token provided by the invite link | | ||
**Example** | ||
```js | ||
contxtSdk.coordinator. | ||
.activateNewUser('7bb79bdf-7492-45c2-8640-2dde63535827', { | ||
email: 'bob.sagat56@gmail.com', | ||
password: 'ds32jX32jaMM1Nr', | ||
userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' | ||
}) | ||
.then(() => console.log("User Activated")) | ||
.catch((err) => console.log(err)); | ||
``` | ||
<a name="Coordinator+createFavoriteApplication"></a> | ||
@@ -258,1 +294,60 @@ | ||
``` | ||
<a name="Coordinator+inviteNewUserToOrganization"></a> | ||
### contxtSdk.coordinator.inviteNewUserToOrganization(organizationId, user) ⇒ <code>Promise</code> | ||
Creates a new contxt user, adds them to an organization, and | ||
sends them an email invite link to do final account setup. | ||
API Endpoint: '/organizations/:organizationId/users' | ||
Method: POST | ||
Note: Only valid for web users using auth0WebAuth session type | ||
**Kind**: instance method of [<code>Coordinator</code>](#Coordinator) | ||
**Fulfill**: [<code>ContxtUser</code>](./Typedefs.md#ContxtUser) The new user | ||
**Reject**: <code>Error</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| organizationId | <code>string</code> | The ID of the organization | | ||
| user | <code>Object</code> | | | ||
| user.email | <code>string</code> | The email address of the new user | | ||
| user.firstName | <code>string</code> | The first name of the new user | | ||
| user.lastName | <code>string</code> | The last name of the new user | | ||
| user.redirectUrl | <code>string</code> | The url that the user will be redirected to after using the invite email link. Typically this is an /activate endpoint that accepts url query params userToken and userId and uses them to do final activation on the user's account. | | ||
**Example** | ||
```js | ||
contxtSdk.coordinator. | ||
.inviteNewUserToOrganization('fdf01507-a26a-4dfe-89a2-bc91861169b8', { | ||
email: 'bob.sagat56@gmail.com', | ||
firstName: 'Bob', | ||
lastName: 'Sagat', | ||
redirectUrl: 'https://contxt.ndustrial.io/activate' | ||
}) | ||
.then((newUser) => console.log(newUser)) | ||
.catch((err) => console.log(err)); | ||
``` | ||
<a name="Coordinator+removeUserFromOrganization"></a> | ||
### contxtSdk.coordinator.removeUserFromOrganization(organizationId, userId) ⇒ <code>Promise</code> | ||
Removes a user from an organization | ||
API Endpoint: '/organizations/:organizationId/users/:userId' | ||
Method: DELETE | ||
**Kind**: instance method of [<code>Coordinator</code>](#Coordinator) | ||
**Fulfill**: <code>undefined</code> | ||
**Reject**: <code>Error</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| organizationId | <code>string</code> | The ID of the organization | | ||
| userId | <code>string</code> | The ID of the user | | ||
**Example** | ||
```js | ||
contxtSdk.coordinator | ||
.removeUserFromOrganization('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52') | ||
.catch((err) => console.log(err)); | ||
``` |
@@ -6,3 +6,3 @@ 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; }; }(); | ||
import EdgeNodes from './edgeNodes'; | ||
import { toCamelCase } from '../utils/objects'; | ||
import { toCamelCase, toSnakeCase } from '../utils/objects'; | ||
@@ -88,5 +88,5 @@ /** | ||
/** | ||
* Adds an application to the current user's list of favorited applications | ||
* Activates a new user | ||
* | ||
* API Endpoint: '/applications/:applicationId/favorites' | ||
* API Endpoint: '/users/:userId/activate' | ||
* Method: POST | ||
@@ -96,12 +96,20 @@ * | ||
* | ||
* @param {number} applicationId The ID of the application | ||
* @param {string} userId The ID of the user to activate | ||
* @param {Object} user | ||
* @param {string} user.email The email address of the user | ||
* @param {string} user.password The password to set for the user | ||
* @param {string} user.userToken The JWT token provided by the invite link | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUserFavoriteApplication} Information about the contxt application favorite | ||
* @fulfill {undefined} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .createFavoriteApplication(25) | ||
* .then((favoriteApplication) => console.log(favoriteApplication)) | ||
* contxtSdk.coordinator. | ||
* .activateNewUser('7bb79bdf-7492-45c2-8640-2dde63535827', { | ||
* email: 'bob.sagat56@gmail.com', | ||
* password: 'ds32jX32jaMM1Nr', | ||
* userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' | ||
* }) | ||
* .then(() => console.log("User Activated")) | ||
* .catch((err) => console.log(err)); | ||
@@ -112,2 +120,45 @@ */ | ||
_createClass(Coordinator, [{ | ||
key: 'activateNewUser', | ||
value: function activateNewUser(userId) { | ||
var user = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!userId) { | ||
return Promise.reject(new Error('A user ID is required for activating a user')); | ||
} | ||
var requiredFields = ['email', 'password', 'userToken']; | ||
for (var i = 0; requiredFields.length > i; i++) { | ||
var field = requiredFields[i]; | ||
if (!user[field]) { | ||
return Promise.reject(new Error('A ' + field + ' is required to activate a user.')); | ||
} | ||
} | ||
return this._request.post(this._baseUrl + '/users/' + userId + '/activate', toSnakeCase(user)); | ||
} | ||
/** | ||
* Adds an application to the current user's list of favorited applications | ||
* | ||
* API Endpoint: '/applications/:applicationId/favorites' | ||
* Method: POST | ||
* | ||
* Note: Only valid for web users using auth0WebAuth session type | ||
* | ||
* @param {number} applicationId The ID of the application | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUserFavoriteApplication} Information about the contxt application favorite | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .createFavoriteApplication(25) | ||
* .then((favoriteApplication) => console.log(favoriteApplication)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'createFavoriteApplication', | ||
@@ -394,2 +445,94 @@ value: function createFavoriteApplication(applicationId) { | ||
} | ||
/** | ||
* Creates a new contxt user, adds them to an organization, and | ||
* sends them an email invite link to do final account setup. | ||
* | ||
* API Endpoint: '/organizations/:organizationId/users' | ||
* Method: POST | ||
* | ||
* Note: Only valid for web users using auth0WebAuth session type | ||
* | ||
* @param {string} organizationId The ID of the organization | ||
* @param {Object} user | ||
* @param {string} user.email The email address of the new user | ||
* @param {string} user.firstName The first name of the new user | ||
* @param {string} user.lastName The last name of the new user | ||
* @param {string} user.redirectUrl The url that the user will be redirected | ||
* to after using the invite email link. Typically this is an /activate | ||
* endpoint that accepts url query params userToken and userId and uses them | ||
* to do final activation on the user's account. | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUser} The new user | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator. | ||
* .inviteNewUserToOrganization('fdf01507-a26a-4dfe-89a2-bc91861169b8', { | ||
* email: 'bob.sagat56@gmail.com', | ||
* firstName: 'Bob', | ||
* lastName: 'Sagat', | ||
* redirectUrl: 'https://contxt.ndustrial.io/activate' | ||
* }) | ||
* .then((newUser) => console.log(newUser)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'inviteNewUserToOrganization', | ||
value: function inviteNewUserToOrganization(organizationId) { | ||
var user = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!organizationId) { | ||
return Promise.reject(new Error('An organization ID is required for inviting a new user')); | ||
} | ||
var requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl']; | ||
for (var i = 0; requiredFields.length > i; i++) { | ||
var field = requiredFields[i]; | ||
if (!user[field]) { | ||
return Promise.reject(new Error('A ' + field + ' is required to create a new user.')); | ||
} | ||
} | ||
return this._request.post(this._baseUrl + '/organizations/' + organizationId + '/users', toSnakeCase(user)).then(function (response) { | ||
return toCamelCase(response); | ||
}); | ||
} | ||
/** | ||
* Removes a user from an organization | ||
* | ||
* API Endpoint: '/organizations/:organizationId/users/:userId' | ||
* Method: DELETE | ||
* | ||
* @param {string} organizationId The ID of the organization | ||
* @param {string} userId The ID of the user | ||
* | ||
* @returns {Promise} | ||
* @fulfill {undefined} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .removeUserFromOrganization('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52') | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'removeUserFromOrganization', | ||
value: function removeUserFromOrganization(organizationId, userId) { | ||
if (!organizationId) { | ||
return Promise.reject(new Error('An organization ID is required for removing a user from an organization')); | ||
} | ||
if (!userId) { | ||
return Promise.reject(new Error('A user ID is required for removing a user from an organization')); | ||
} | ||
return this._request.delete(this._baseUrl + '/organizations/' + organizationId + '/users/' + userId); | ||
} | ||
}]); | ||
@@ -396,0 +539,0 @@ |
@@ -97,5 +97,5 @@ 'use strict'; | ||
/** | ||
* Adds an application to the current user's list of favorited applications | ||
* Activates a new user | ||
* | ||
* API Endpoint: '/applications/:applicationId/favorites' | ||
* API Endpoint: '/users/:userId/activate' | ||
* Method: POST | ||
@@ -105,12 +105,20 @@ * | ||
* | ||
* @param {number} applicationId The ID of the application | ||
* @param {string} userId The ID of the user to activate | ||
* @param {Object} user | ||
* @param {string} user.email The email address of the user | ||
* @param {string} user.password The password to set for the user | ||
* @param {string} user.userToken The JWT token provided by the invite link | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUserFavoriteApplication} Information about the contxt application favorite | ||
* @fulfill {undefined} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .createFavoriteApplication(25) | ||
* .then((favoriteApplication) => console.log(favoriteApplication)) | ||
* contxtSdk.coordinator. | ||
* .activateNewUser('7bb79bdf-7492-45c2-8640-2dde63535827', { | ||
* email: 'bob.sagat56@gmail.com', | ||
* password: 'ds32jX32jaMM1Nr', | ||
* userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' | ||
* }) | ||
* .then(() => console.log("User Activated")) | ||
* .catch((err) => console.log(err)); | ||
@@ -121,2 +129,45 @@ */ | ||
_createClass(Coordinator, [{ | ||
key: 'activateNewUser', | ||
value: function activateNewUser(userId) { | ||
var user = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!userId) { | ||
return Promise.reject(new Error('A user ID is required for activating a user')); | ||
} | ||
var requiredFields = ['email', 'password', 'userToken']; | ||
for (var i = 0; requiredFields.length > i; i++) { | ||
var field = requiredFields[i]; | ||
if (!user[field]) { | ||
return Promise.reject(new Error('A ' + field + ' is required to activate a user.')); | ||
} | ||
} | ||
return this._request.post(this._baseUrl + '/users/' + userId + '/activate', (0, _objects.toSnakeCase)(user)); | ||
} | ||
/** | ||
* Adds an application to the current user's list of favorited applications | ||
* | ||
* API Endpoint: '/applications/:applicationId/favorites' | ||
* Method: POST | ||
* | ||
* Note: Only valid for web users using auth0WebAuth session type | ||
* | ||
* @param {number} applicationId The ID of the application | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUserFavoriteApplication} Information about the contxt application favorite | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .createFavoriteApplication(25) | ||
* .then((favoriteApplication) => console.log(favoriteApplication)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'createFavoriteApplication', | ||
@@ -403,2 +454,94 @@ value: function createFavoriteApplication(applicationId) { | ||
} | ||
/** | ||
* Creates a new contxt user, adds them to an organization, and | ||
* sends them an email invite link to do final account setup. | ||
* | ||
* API Endpoint: '/organizations/:organizationId/users' | ||
* Method: POST | ||
* | ||
* Note: Only valid for web users using auth0WebAuth session type | ||
* | ||
* @param {string} organizationId The ID of the organization | ||
* @param {Object} user | ||
* @param {string} user.email The email address of the new user | ||
* @param {string} user.firstName The first name of the new user | ||
* @param {string} user.lastName The last name of the new user | ||
* @param {string} user.redirectUrl The url that the user will be redirected | ||
* to after using the invite email link. Typically this is an /activate | ||
* endpoint that accepts url query params userToken and userId and uses them | ||
* to do final activation on the user's account. | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUser} The new user | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator. | ||
* .inviteNewUserToOrganization('fdf01507-a26a-4dfe-89a2-bc91861169b8', { | ||
* email: 'bob.sagat56@gmail.com', | ||
* firstName: 'Bob', | ||
* lastName: 'Sagat', | ||
* redirectUrl: 'https://contxt.ndustrial.io/activate' | ||
* }) | ||
* .then((newUser) => console.log(newUser)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'inviteNewUserToOrganization', | ||
value: function inviteNewUserToOrganization(organizationId) { | ||
var user = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!organizationId) { | ||
return Promise.reject(new Error('An organization ID is required for inviting a new user')); | ||
} | ||
var requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl']; | ||
for (var i = 0; requiredFields.length > i; i++) { | ||
var field = requiredFields[i]; | ||
if (!user[field]) { | ||
return Promise.reject(new Error('A ' + field + ' is required to create a new user.')); | ||
} | ||
} | ||
return this._request.post(this._baseUrl + '/organizations/' + organizationId + '/users', (0, _objects.toSnakeCase)(user)).then(function (response) { | ||
return (0, _objects.toCamelCase)(response); | ||
}); | ||
} | ||
/** | ||
* Removes a user from an organization | ||
* | ||
* API Endpoint: '/organizations/:organizationId/users/:userId' | ||
* Method: DELETE | ||
* | ||
* @param {string} organizationId The ID of the organization | ||
* @param {string} userId The ID of the user | ||
* | ||
* @returns {Promise} | ||
* @fulfill {undefined} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .removeUserFromOrganization('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52') | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
}, { | ||
key: 'removeUserFromOrganization', | ||
value: function removeUserFromOrganization(organizationId, userId) { | ||
if (!organizationId) { | ||
return Promise.reject(new Error('An organization ID is required for removing a user from an organization')); | ||
} | ||
if (!userId) { | ||
return Promise.reject(new Error('A user ID is required for removing a user from an organization')); | ||
} | ||
return this._request.delete(this._baseUrl + '/organizations/' + organizationId + '/users/' + userId); | ||
} | ||
}]); | ||
@@ -405,0 +548,0 @@ |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "1.0.0-beta.5", | ||
"version": "1.0.0-beta.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -11,8 +11,2 @@ # contxt-sdk [![wercker status](https://app.wercker.com/status/869ef086297da79ddd0cbf3564f7cba6/s/master 'wercker status')](https://app.wercker.com/project/byKey/869ef086297da79ddd0cbf3564f7cba6) | ||
There are three peer dependencies for `contxt-sdk`: `auth0-js`, `axios`, and `ws`. If you don't already have a compatible version installed, run: | ||
```bash | ||
npm install --save auth0-js@^9.0.0 axios@~0.17.0 ws@~6.1.3 | ||
``` | ||
## Getting Started | ||
@@ -19,0 +13,0 @@ |
import EdgeNodes from './edgeNodes'; | ||
import { toCamelCase } from '../utils/objects'; | ||
import { toCamelCase, toSnakeCase } from '../utils/objects'; | ||
@@ -80,2 +80,55 @@ /** | ||
/** | ||
* Activates a new user | ||
* | ||
* API Endpoint: '/users/:userId/activate' | ||
* Method: POST | ||
* | ||
* Note: Only valid for web users using auth0WebAuth session type | ||
* | ||
* @param {string} userId The ID of the user to activate | ||
* @param {Object} user | ||
* @param {string} user.email The email address of the user | ||
* @param {string} user.password The password to set for the user | ||
* @param {string} user.userToken The JWT token provided by the invite link | ||
* | ||
* @returns {Promise} | ||
* @fulfill {undefined} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator. | ||
* .activateNewUser('7bb79bdf-7492-45c2-8640-2dde63535827', { | ||
* email: 'bob.sagat56@gmail.com', | ||
* password: 'ds32jX32jaMM1Nr', | ||
* userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' | ||
* }) | ||
* .then(() => console.log("User Activated")) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
activateNewUser(userId, user = {}) { | ||
if (!userId) { | ||
return Promise.reject( | ||
new Error('A user ID is required for activating a user') | ||
); | ||
} | ||
const requiredFields = ['email', 'password', 'userToken']; | ||
for (let i = 0; requiredFields.length > i; i++) { | ||
const field = requiredFields[i]; | ||
if (!user[field]) { | ||
return Promise.reject( | ||
new Error(`A ${field} is required to activate a user.`) | ||
); | ||
} | ||
} | ||
return this._request.post( | ||
`${this._baseUrl}/users/${userId}/activate`, | ||
toSnakeCase(user) | ||
); | ||
} | ||
/** | ||
* Adds an application to the current user's list of favorited applications | ||
@@ -379,4 +432,105 @@ * | ||
} | ||
/** | ||
* Creates a new contxt user, adds them to an organization, and | ||
* sends them an email invite link to do final account setup. | ||
* | ||
* API Endpoint: '/organizations/:organizationId/users' | ||
* Method: POST | ||
* | ||
* Note: Only valid for web users using auth0WebAuth session type | ||
* | ||
* @param {string} organizationId The ID of the organization | ||
* @param {Object} user | ||
* @param {string} user.email The email address of the new user | ||
* @param {string} user.firstName The first name of the new user | ||
* @param {string} user.lastName The last name of the new user | ||
* @param {string} user.redirectUrl The url that the user will be redirected | ||
* to after using the invite email link. Typically this is an /activate | ||
* endpoint that accepts url query params userToken and userId and uses them | ||
* to do final activation on the user's account. | ||
* | ||
* @returns {Promise} | ||
* @fulfill {ContxtUser} The new user | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator. | ||
* .inviteNewUserToOrganization('fdf01507-a26a-4dfe-89a2-bc91861169b8', { | ||
* email: 'bob.sagat56@gmail.com', | ||
* firstName: 'Bob', | ||
* lastName: 'Sagat', | ||
* redirectUrl: 'https://contxt.ndustrial.io/activate' | ||
* }) | ||
* .then((newUser) => console.log(newUser)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
inviteNewUserToOrganization(organizationId, user = {}) { | ||
if (!organizationId) { | ||
return Promise.reject( | ||
new Error('An organization ID is required for inviting a new user') | ||
); | ||
} | ||
const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl']; | ||
for (let i = 0; requiredFields.length > i; i++) { | ||
const field = requiredFields[i]; | ||
if (!user[field]) { | ||
return Promise.reject( | ||
new Error(`A ${field} is required to create a new user.`) | ||
); | ||
} | ||
} | ||
return this._request | ||
.post( | ||
`${this._baseUrl}/organizations/${organizationId}/users`, | ||
toSnakeCase(user) | ||
) | ||
.then((response) => toCamelCase(response)); | ||
} | ||
/** | ||
* Removes a user from an organization | ||
* | ||
* API Endpoint: '/organizations/:organizationId/users/:userId' | ||
* Method: DELETE | ||
* | ||
* @param {string} organizationId The ID of the organization | ||
* @param {string} userId The ID of the user | ||
* | ||
* @returns {Promise} | ||
* @fulfill {undefined} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.coordinator | ||
* .removeUserFromOrganization('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52') | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
removeUserFromOrganization(organizationId, userId) { | ||
if (!organizationId) { | ||
return Promise.reject( | ||
new Error( | ||
'An organization ID is required for removing a user from an organization' | ||
) | ||
); | ||
} | ||
if (!userId) { | ||
return Promise.reject( | ||
new Error( | ||
'A user ID is required for removing a user from an organization' | ||
) | ||
); | ||
} | ||
return this._request.delete( | ||
`${this._baseUrl}/organizations/${organizationId}/users/${userId}` | ||
); | ||
} | ||
} | ||
export default Coordinator; |
@@ -0,1 +1,3 @@ | ||
import omit from 'lodash.omit'; | ||
import Coordinator from './index'; | ||
@@ -54,2 +56,95 @@ import * as objectUtils from '../utils/objects'; | ||
describe('activateNewUser', function() { | ||
context('when all the required parameters are provided', function() { | ||
let user; | ||
let userActivationPayload; | ||
let userActivationPayloadToServer; | ||
let promise; | ||
let request; | ||
let toSnakeCase; | ||
beforeEach(function() { | ||
user = fixture.build('contxtUser'); | ||
userActivationPayload = { | ||
email: user.email, | ||
password: faker.internet.password(), | ||
userToken: faker.random.uuid() | ||
}; | ||
userActivationPayloadToServer = { | ||
email: userActivationPayload.email, | ||
password: userActivationPayload.password, | ||
user_token: userActivationPayload.userToken | ||
}; | ||
request = { | ||
...baseRequest, | ||
post: this.sandbox.stub().resolves() | ||
}; | ||
toSnakeCase = this.sandbox | ||
.stub(objectUtils, 'toSnakeCase') | ||
.callsFake(() => userActivationPayloadToServer); | ||
const coordinator = new Coordinator(baseSdk, request); | ||
coordinator._baseUrl = expectedHost; | ||
promise = coordinator.activateNewUser(user.id, userActivationPayload); | ||
}); | ||
it('formats the user payload', function() { | ||
return promise.then(() => { | ||
expect(toSnakeCase).to.be.calledWith(userActivationPayload); | ||
}); | ||
}); | ||
it('posts the new user to the server', function() { | ||
expect(request.post).to.be.calledWith( | ||
`${expectedHost}/users/${user.id}/activate`, | ||
userActivationPayloadToServer | ||
); | ||
}); | ||
it('returns a fulfilled promise', function() { | ||
return expect(promise).to.be.fulfilled; | ||
}); | ||
}); | ||
context('when the organization ID is not provided', function() { | ||
it('throws an error', function() { | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
const promise = coordinator.activateNewUser(); | ||
return expect(promise).to.be.rejectedWith( | ||
'A user ID is required for activating a user' | ||
); | ||
}); | ||
}); | ||
context('when there is missing required user information', function() { | ||
const requiredFields = ['email', 'password', 'userToken']; | ||
requiredFields.forEach((field) => { | ||
it(`it throws an error when ${field} is missing`, function() { | ||
const payload = { | ||
email: faker.internet.email(), | ||
password: faker.internet.password(), | ||
userToken: faker.random.uuid() | ||
}; | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
const promise = coordinator.activateNewUser( | ||
faker.random.uuid(), | ||
omit(payload, [field]) | ||
); | ||
return expect(promise).to.be.rejectedWith( | ||
`A ${field} is required to activate a user.` | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('createFavoriteApplication', function() { | ||
@@ -650,2 +745,179 @@ context('when the application ID is provided', function() { | ||
}); | ||
describe('inviteNewUserToOrganization', function() { | ||
context('when all the required parameters are provided', function() { | ||
let organization; | ||
let newUserPayload; | ||
let newUserPayloadToServer; | ||
let expectedNewUser; | ||
let newUserFromServer; | ||
let promise; | ||
let request; | ||
let toCamelCase; | ||
let toSnakeCase; | ||
beforeEach(function() { | ||
organization = fixture.build('contxtOrganization'); | ||
expectedNewUser = fixture.build('contxtUser'); | ||
newUserFromServer = fixture.build('contxtUser', expectedNewUser, { | ||
fromServer: true | ||
}); | ||
newUserPayload = { | ||
email: expectedNewUser.email, | ||
firstName: expectedNewUser.firstName, | ||
lastName: expectedNewUser.lastName, | ||
redirectUrl: faker.internet.url() | ||
}; | ||
newUserPayloadToServer = { | ||
email: newUserPayload.email, | ||
first_name: newUserPayload.firstName, | ||
last_name: newUserPayload.lastName, | ||
redirect_url: newUserPayload.redirectUrl | ||
}; | ||
request = { | ||
...baseRequest, | ||
post: this.sandbox.stub().resolves(newUserFromServer) | ||
}; | ||
toCamelCase = this.sandbox | ||
.stub(objectUtils, 'toCamelCase') | ||
.callsFake(() => expectedNewUser); | ||
toSnakeCase = this.sandbox | ||
.stub(objectUtils, 'toSnakeCase') | ||
.callsFake(() => newUserPayloadToServer); | ||
const coordinator = new Coordinator(baseSdk, request); | ||
coordinator._baseUrl = expectedHost; | ||
promise = coordinator.inviteNewUserToOrganization( | ||
organization.id, | ||
newUserPayload | ||
); | ||
}); | ||
it('formats the user payload', function() { | ||
return promise.then(() => { | ||
expect(toSnakeCase).to.be.calledWith(newUserPayload); | ||
}); | ||
}); | ||
it('posts the new user to the server', function() { | ||
expect(request.post).to.be.calledWith( | ||
`${expectedHost}/organizations/${organization.id}/users`, | ||
newUserPayloadToServer | ||
); | ||
}); | ||
it('formats the user response', function() { | ||
return promise.then(() => { | ||
expect(toCamelCase).to.be.calledWith(newUserFromServer); | ||
}); | ||
}); | ||
it('returns a fulfilled promise with the new user', function() { | ||
return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal( | ||
expectedNewUser | ||
); | ||
}); | ||
}); | ||
context('when the organization ID is not provided', function() { | ||
it('throws an error', function() { | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
const promise = coordinator.inviteNewUserToOrganization(); | ||
return expect(promise).to.be.rejectedWith( | ||
'An organization ID is required for inviting a new user' | ||
); | ||
}); | ||
}); | ||
context('when there is missing required user information', function() { | ||
const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl']; | ||
requiredFields.forEach((field) => { | ||
it(`it throws an error when ${field} is missing`, function() { | ||
const newUserPayload = { | ||
email: faker.internet.email(), | ||
firstName: faker.name.firstName(), | ||
lastName: faker.name.lastName(), | ||
redirectUrl: faker.internet.url() | ||
}; | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
const promise = coordinator.inviteNewUserToOrganization( | ||
faker.random.uuid(), | ||
omit(newUserPayload, [field]) | ||
); | ||
return expect(promise).to.be.rejectedWith( | ||
`A ${field} is required to create a new user.` | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('removeUserFromOrganization', function() { | ||
context('when all required parameters are provided', function() { | ||
let organization; | ||
let user; | ||
let promise; | ||
beforeEach(function() { | ||
organization = fixture.build('contxtOrganization'); | ||
user = fixture.build('contxtUser'); | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
coordinator._baseUrl = expectedHost; | ||
promise = coordinator.removeUserFromOrganization( | ||
organization.id, | ||
user.id | ||
); | ||
}); | ||
it('sends a request to remove the user from the organization', function() { | ||
expect(baseRequest.delete).to.be.calledWith( | ||
`${expectedHost}/organizations/${organization.id}/users/${user.id}` | ||
); | ||
}); | ||
it('returns a resolved promise', function() { | ||
return expect(promise).to.be.fulfilled; | ||
}); | ||
}); | ||
context('when the organization ID is not provided', function() { | ||
it('throws an error', function() { | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
const promise = coordinator.removeUserFromOrganization( | ||
null, | ||
faker.random.uuid() | ||
); | ||
return expect(promise).to.be.rejectedWith( | ||
'An organization ID is required for removing a user from an organization' | ||
); | ||
}); | ||
}); | ||
context('when the user ID is not provided', function() { | ||
it('throws an error', function() { | ||
const coordinator = new Coordinator(baseSdk, baseRequest); | ||
const promise = coordinator.removeUserFromOrganization( | ||
faker.random.uuid(), | ||
null | ||
); | ||
return expect(promise).to.be.rejectedWith( | ||
'A user ID is required for removing a user from an organization' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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
2187499
35208
154