Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contensis-management-api

Package Overview
Dependencies
Maintainers
5
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contensis-management-api - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2-beta.1

3

bundle-es2015/models/IUserOperations.d.ts

@@ -19,2 +19,5 @@ import { User } from './User';

userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>;
suspendUser(userId: string): Promise<void>;
unlockUser(userId: string): Promise<void>;
unsuspendUser(userId: string): Promise<void>;
}

@@ -18,3 +18,7 @@ import { ContensisClient, IUserOperations, User, UserListOptions, Group, UserGroupsOptions, UserUpdatePasswordOptions } from '../../models';

userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>;
suspendUser(userId: string): Promise<void>;
unlockUser(userId: string): Promise<void>;
unsuspendUser(userId: string): Promise<void>;
private performUserAction;
private getUser;
}

@@ -134,3 +134,3 @@ import { UrlBuilder } from 'contensis-core-api';

if (!userId) {
throw new Error('A valid users id needs to be specified.');
throw new Error('A valid user id needs to be specified.');
}

@@ -152,2 +152,27 @@ if (!groupIdsOrNames || groupIdsOrNames.length === 0) {

}
suspendUser(userId) {
return this.performUserAction(userId, 'suspend');
}
unlockUser(userId) {
return this.performUserAction(userId, 'unlock');
}
unsuspendUser(userId) {
return this.performUserAction(userId, 'unsuspend');
}
performUserAction(userId, userActionType) {
if (!userId) {
throw new Error('A valid user id needs to be specified.');
}
let url = UrlBuilder.create('/api/security/users/:id/actions', {})
.addOptions(userId, 'id')
.setParams(this.contensisClient.getParams())
.toUrl();
return this.contensisClient.ensureBearerToken().then(() => {
return this.httpClient.request(url, {
headers: this.contensisClient.getHeaders(),
method: 'POST',
body: JSON.stringify({ type: userActionType })
});
});
}
getUser(idOrNameOrEmail) {

@@ -154,0 +179,0 @@ let url = UrlBuilder.create('/api/security/users/:idOrNameOrEmail', {})

@@ -335,2 +335,44 @@ import * as Contensis from '../../index';

});
describe('Perform user actions', () => {
beforeEach(() => {
setDefaultSpy(global, null);
Zengenti.Contensis.Client.defaultClientConfig = null;
Zengenti.Contensis.Client.configure({
fetchFn: global.fetch
});
});
it('suspend', async () => {
let client = Zengenti.Contensis.Client.create(getDefaultConfig());
let result = await client.security.users.suspendUser(defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl());
expect(global.fetch.calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${defaultUsers[0].id}/actions`,
getDefaultRequest('POST', false, JSON.stringify({ type: 'suspend' }))
]);
expect(result).toEqual(null);
});
it('unsuspend', async () => {
let client = Zengenti.Contensis.Client.create(getDefaultConfig());
let result = await client.security.users.unsuspendUser(defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl());
expect(global.fetch.calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${defaultUsers[0].id}/actions`,
getDefaultRequest('POST', false, JSON.stringify({ type: 'unsuspend' }))
]);
expect(result).toEqual(null);
});
it('unlock', async () => {
let client = Zengenti.Contensis.Client.create(getDefaultConfig());
let result = await client.security.users.unlockUser(defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl());
expect(global.fetch.calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${defaultUsers[0].id}/actions`,
getDefaultRequest('POST', false, JSON.stringify({ type: 'unlock' }))
]);
expect(result).toEqual(null);
});
});
});

@@ -7,2 +7,6 @@ # Changelog

## [1.0.2-beta.1] - 2020-11-17
### Added
- users: added suspend, unlock, unsuspend operations
## [1.0.1] - 2020-11-04

@@ -9,0 +13,0 @@ ### Changed

@@ -19,2 +19,5 @@ import { User } from './User';

userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>;
suspendUser(userId: string): Promise<void>;
unlockUser(userId: string): Promise<void>;
unsuspendUser(userId: string): Promise<void>;
}

@@ -18,3 +18,7 @@ import { ContensisClient, IUserOperations, User, UserListOptions, Group, UserGroupsOptions, UserUpdatePasswordOptions } from '../../models';

userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>;
suspendUser(userId: string): Promise<void>;
unlockUser(userId: string): Promise<void>;
unsuspendUser(userId: string): Promise<void>;
private performUserAction;
private getUser;
}

@@ -136,3 +136,3 @@ "use strict";

if (!userId) {
throw new Error('A valid users id needs to be specified.');
throw new Error('A valid user id needs to be specified.');
}

@@ -154,2 +154,27 @@ if (!groupIdsOrNames || groupIdsOrNames.length === 0) {

}
suspendUser(userId) {
return this.performUserAction(userId, 'suspend');
}
unlockUser(userId) {
return this.performUserAction(userId, 'unlock');
}
unsuspendUser(userId) {
return this.performUserAction(userId, 'unsuspend');
}
performUserAction(userId, userActionType) {
if (!userId) {
throw new Error('A valid user id needs to be specified.');
}
let url = contensis_core_api_1.UrlBuilder.create('/api/security/users/:id/actions', {})
.addOptions(userId, 'id')
.setParams(this.contensisClient.getParams())
.toUrl();
return this.contensisClient.ensureBearerToken().then(() => {
return this.httpClient.request(url, {
headers: this.contensisClient.getHeaders(),
method: 'POST',
body: JSON.stringify({ type: userActionType })
});
});
}
getUser(idOrNameOrEmail) {

@@ -156,0 +181,0 @@ let url = contensis_core_api_1.UrlBuilder.create('/api/security/users/:idOrNameOrEmail', {})

@@ -338,2 +338,44 @@ "use strict";

});
describe('Perform user actions', () => {
beforeEach(() => {
specs_utils_spec_1.setDefaultSpy(global, null);
Zengenti.Contensis.Client.defaultClientConfig = null;
Zengenti.Contensis.Client.configure({
fetchFn: global.fetch
});
});
it('suspend', async () => {
let client = Zengenti.Contensis.Client.create(specs_utils_spec_1.getDefaultConfig());
let result = await client.security.users.suspendUser(specs_utils_spec_1.defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch.calls.first().args[0]).toEqual(specs_utils_spec_1.getDefaultAuthenticateUrl());
expect(global.fetch.calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${specs_utils_spec_1.defaultUsers[0].id}/actions`,
specs_utils_spec_1.getDefaultRequest('POST', false, JSON.stringify({ type: 'suspend' }))
]);
expect(result).toEqual(null);
});
it('unsuspend', async () => {
let client = Zengenti.Contensis.Client.create(specs_utils_spec_1.getDefaultConfig());
let result = await client.security.users.unsuspendUser(specs_utils_spec_1.defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch.calls.first().args[0]).toEqual(specs_utils_spec_1.getDefaultAuthenticateUrl());
expect(global.fetch.calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${specs_utils_spec_1.defaultUsers[0].id}/actions`,
specs_utils_spec_1.getDefaultRequest('POST', false, JSON.stringify({ type: 'unsuspend' }))
]);
expect(result).toEqual(null);
});
it('unlock', async () => {
let client = Zengenti.Contensis.Client.create(specs_utils_spec_1.getDefaultConfig());
let result = await client.security.users.unlockUser(specs_utils_spec_1.defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch.calls.first().args[0]).toEqual(specs_utils_spec_1.getDefaultAuthenticateUrl());
expect(global.fetch.calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${specs_utils_spec_1.defaultUsers[0].id}/actions`,
specs_utils_spec_1.getDefaultRequest('POST', false, JSON.stringify({ type: 'unlock' }))
]);
expect(result).toEqual(null);
});
});
});

6

package.json
{
"name": "contensis-management-api",
"version": "1.0.1",
"version": "1.0.2-beta.1",
"description": "Contensis Javascript Management API",

@@ -55,7 +55,7 @@ "engines": {

"contensis-core-api": "^1.0.1",
"cross-fetch": "^3.0.5",
"cross-fetch": "^3.0.6",
"es6-promise": "^4.2.8",
"form-data": "^3.0.0",
"graceful-fs": "^4.2.4",
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.1",
"tslib": "^1.13.0",

@@ -62,0 +62,0 @@ "whatwg-fetch": "^3.4.0"

# contensis-management-api [![NPM version](https://img.shields.io/npm/v/contensis-management-api.svg?style=flat)](https://www.npmjs.com/package/contensis-management-api)
Contensis JavaScript Management API implementation written in TypeScript.
Contensis JavaScript Management API implementation written in TypeScript. This version targets Contensis 14.0 and above.
The *[contensis-management-api-examples](https://github.com/contensis/contensis-management-api-examples)* repo contains Express and React examples.

@@ -20,2 +20,5 @@ import { User } from './User';

userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>;
suspendUser(userId: string): Promise<void>;
unlockUser(userId: string): Promise<void>;
unsuspendUser(userId: string): Promise<void>;
}

@@ -462,2 +462,66 @@ import * as Contensis from '../../index';

});
describe('Perform user actions', () => {
beforeEach(() => {
setDefaultSpy(global, null);
Zengenti.Contensis.Client.defaultClientConfig = null;
Zengenti.Contensis.Client.configure({
fetchFn: global.fetch
});
});
it('suspend', async () => {
let client = Zengenti.Contensis.Client.create(getDefaultConfig());
let result = await client.security.users.suspendUser(defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect((global.fetch as any).calls.first().args[0]).toEqual(getDefaultAuthenticateUrl());
expect((global.fetch as any).calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${defaultUsers[0].id}/actions`,
getDefaultRequest('POST', false, JSON.stringify({ type: 'suspend' }))
]);
expect(result).toEqual(null);
});
it('unsuspend', async () => {
let client = Zengenti.Contensis.Client.create(getDefaultConfig());
let result = await client.security.users.unsuspendUser(defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect((global.fetch as any).calls.first().args[0]).toEqual(getDefaultAuthenticateUrl());
expect((global.fetch as any).calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${defaultUsers[0].id}/actions`,
getDefaultRequest('POST', false, JSON.stringify({ type: 'unsuspend' }))
]);
expect(result).toEqual(null);
});
it('unlock', async () => {
let client = Zengenti.Contensis.Client.create(getDefaultConfig());
let result = await client.security.users.unlockUser(defaultUsers[0].id);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect((global.fetch as any).calls.first().args[0]).toEqual(getDefaultAuthenticateUrl());
expect((global.fetch as any).calls.mostRecent().args).toEqual([
`http://my-website.com/api/security/users/${defaultUsers[0].id}/actions`,
getDefaultRequest('POST', false, JSON.stringify({ type: 'unlock' }))
]);
expect(result).toEqual(null);
});
});
});

@@ -10,2 +10,4 @@ import { ContensisClient, IUserOperations, User, UserListOptions, Group, UserGroupsOptions, UserUpdatePasswordOptions } from '../../models';

type UserActionType = 'suspend' | 'unlock' | 'unsuspend';
export class UserOperations implements IUserOperations {

@@ -169,3 +171,3 @@

if (!userId) {
throw new Error('A valid users id needs to be specified.');
throw new Error('A valid user id needs to be specified.');
}

@@ -192,2 +194,34 @@

suspendUser(userId: string): Promise<void> {
return this.performUserAction(userId, 'suspend');
}
unlockUser(userId: string): Promise<void> {
return this.performUserAction(userId, 'unlock');
}
unsuspendUser(userId: string): Promise<void> {
return this.performUserAction(userId, 'unsuspend');
}
private performUserAction(userId: string, userActionType: UserActionType): Promise<void> {
if (!userId) {
throw new Error('A valid user id needs to be specified.');
}
let url = UrlBuilder.create('/api/security/users/:id/actions',
{})
.addOptions(userId, 'id')
.setParams(this.contensisClient.getParams())
.toUrl();
return this.contensisClient.ensureBearerToken().then(() => {
return this.httpClient.request<void>(url, {
headers: this.contensisClient.getHeaders(),
method: 'POST',
body: JSON.stringify({ type: userActionType })
});
});
}
private getUser(idOrNameOrEmail: string) {

@@ -194,0 +228,0 @@ let url = UrlBuilder.create('/api/security/users/:idOrNameOrEmail', {})

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc