contensis-management-api
Advanced tools
Comparing version 2.1.9 to 2.2.0
@@ -54,2 +54,3 @@ import * as Contensis from '../index'; | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -185,2 +186,3 @@ pageSize: 25, | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -541,2 +543,3 @@ pageSize: 25, | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -543,0 +546,0 @@ pageSize: 25, |
@@ -1,8 +0,4 @@ | ||
import { PageOptions } from 'contensis-core-api'; | ||
export interface GroupChildListOptions { | ||
includeInherited?: boolean; | ||
excludedGroups?: string[]; | ||
pageOptions?: PageOptions; | ||
order?: string[]; | ||
zenQL?: string; | ||
import { GroupUserListOptions } from './GroupUserListOptions'; | ||
export interface GroupChildListOptions extends GroupUserListOptions { | ||
includeSelf?: boolean; | ||
} |
@@ -1,3 +0,8 @@ | ||
import { GroupChildListOptions } from './GroupChildListOptions'; | ||
export interface GroupUserListOptions extends GroupChildListOptions { | ||
import { PageOptions } from 'contensis-core-api'; | ||
export interface GroupUserListOptions { | ||
includeInherited?: boolean; | ||
excludedGroups?: string[]; | ||
pageOptions?: PageOptions; | ||
order?: string[]; | ||
zenQL?: string; | ||
} |
@@ -18,2 +18,3 @@ import { Group, GroupToCreate } from './Group'; | ||
addChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
addChildGroups(groupId: string, childGroupIds: string[]): Promise<void>; | ||
removeChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
@@ -20,0 +21,0 @@ getUsersByGroupId(groupId: string, options?: GroupUserListOptions): Promise<PagedList<User>>; |
import { User, UserToCreate } from './User'; | ||
import { PagedList } from 'contensis-core-api'; | ||
import { ManagementQuery, PagedList } from 'contensis-core-api'; | ||
import { UserListOptions } from './UserListOptions'; | ||
@@ -13,2 +13,3 @@ import { Group } from './Group'; | ||
list(options?: UserListOptions): Promise<PagedList<User>>; | ||
search(query: ManagementQuery): Promise<PagedList<User>>; | ||
getUserGroups(userIdOrOptions: string | UserGroupsOptions): Promise<PagedList<Group>>; | ||
@@ -20,2 +21,3 @@ create(user: UserToCreate, suspended?: boolean): Promise<User>; | ||
userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>; | ||
setPasswordToExpirable(userId: string): Promise<void>; | ||
suspendUser(userId: string): Promise<void>; | ||
@@ -22,0 +24,0 @@ unlockUser(userId: string): Promise<void>; |
@@ -90,3 +90,4 @@ import * as Contensis from '../index'; | ||
primaryLanguage: 'en-GB', | ||
supportedLanguages: ['fr-FR', 'de-DE'] | ||
supportedLanguages: ['fr-FR', 'de-DE'], | ||
deliverySysExclusions: [], | ||
}; | ||
@@ -93,0 +94,0 @@ let project = await client.projects.create(newProject); |
@@ -18,2 +18,3 @@ import { ContensisClient, Group, GroupListOptions, IGroupOperations, User, GroupUserListOptions, GroupChildListOptions, GroupToCreate } from '../../models'; | ||
addChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
addChildGroups(groupId: string, childGroupIds: string[]): Promise<void>; | ||
removeChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
@@ -20,0 +21,0 @@ getUsersByGroupId(groupId: string, options?: GroupUserListOptions): Promise<PagedList<User>>; |
@@ -6,3 +6,11 @@ import { UrlBuilder } from 'contensis-core-api'; | ||
order: (value) => (value && value.length > 0) ? value : null, | ||
q: (value) => (!!value) ? value : null, | ||
zenql: (value) => (!!value) ? value : null, | ||
}; | ||
let childListMappers = { | ||
pageIndex: (value, options, params) => (options && options.pageOptions && options.pageOptions.pageIndex) || (params.pageIndex), | ||
pageSize: (value, options, params) => (options && options.pageOptions && options.pageOptions.pageSize) || (params.pageSize), | ||
order: (value) => (value && value.length > 0) ? value : null, | ||
excludedGroups: (value) => (value && value.length > 0) ? value.join(',') : null, | ||
includeSelf: (value) => (!!value) ? value : null, | ||
}; | ||
@@ -14,2 +22,3 @@ let userListMappers = { | ||
excludedGroups: (value) => (value && value.length > 0) ? value.join(',') : null, | ||
includeInherited: (value) => (!!value) ? value : null, | ||
}; | ||
@@ -194,2 +203,21 @@ export class GroupOperations { | ||
} | ||
addChildGroups(groupId, childGroupIds) { | ||
if (!groupId) { | ||
throw new Error('A valid group id needs to be specified.'); | ||
} | ||
if (!childGroupIds || childGroupIds.length === 0) { | ||
throw new Error('At least one valid child group id needs to be specified.'); | ||
} | ||
let url = UrlBuilder.create('/api/security/groups/:groupId/groups', {}) | ||
.addOptions(groupId, 'groupId') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
headers: this.contensisClient.getHeaders(), | ||
method: 'POST', | ||
body: JSON.stringify(childGroupIds) | ||
}); | ||
}); | ||
} | ||
removeChildGroup(groupId, childGroupId) { | ||
@@ -263,7 +291,7 @@ if (!groupId) { | ||
getChildGroups(idOrName, options) { | ||
let url = UrlBuilder.create('/api/security/groups/:idOrName/groups', !options ? {} : { includeInherited: null, excludedGroups: null, q: null, pageIndex: null, pageSize: null, order: null, zenQL: null }) | ||
let url = UrlBuilder.create('/api/security/groups/:idOrName/groups', !options ? {} : { includeSelf: null, includeInherited: null, excludedGroups: null, q: null, pageIndex: null, pageSize: null, order: null, zenQL: null }) | ||
.addOptions(idOrName, 'idOrName') | ||
.addOptions(options) | ||
.setParams(this.contensisClient.getParams()) | ||
.addMappers(listMappers) | ||
.addMappers(childListMappers) | ||
.toUrl(); | ||
@@ -270,0 +298,0 @@ return this.contensisClient.ensureBearerToken().then(() => { |
@@ -297,2 +297,22 @@ import * as Contensis from '../../index'; | ||
}); | ||
describe('Add child groups to group', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, null); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch, | ||
}); | ||
}); | ||
it('for valid group and child groups', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let result = await client.security.groups.addChildGroups(defaultGroups[0].id, [defaultGroups[1].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/groups/${defaultGroups[0].id}/groups`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify([defaultGroups[1].id])), | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
}); | ||
describe('Remove child group from group', () => { | ||
@@ -476,7 +496,8 @@ beforeEach(() => { | ||
pageOptions: { pageIndex: 1, pageSize: 50 }, | ||
order: ['name'] | ||
order: ['name'], | ||
includeSelf: true | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].id}/groups?includeInherited=true&order=name&pageIndex=1&pageSize=50`, | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].id}/groups?includeInherited=true&includeSelf=true&order=name&pageIndex=1&pageSize=50`, | ||
getDefaultFetchRequest() | ||
@@ -505,7 +526,8 @@ ]); | ||
pageOptions: { pageIndex: 1, pageSize: 50 }, | ||
order: ['name'] | ||
order: ['name'], | ||
includeSelf: true | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].name}/groups?includeInherited=true&order=name&pageIndex=1&pageSize=50`, | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].name}/groups?includeInherited=true&includeSelf=true&order=name&pageIndex=1&pageSize=50`, | ||
getDefaultFetchRequest() | ||
@@ -512,0 +534,0 @@ ]); |
import { ContensisClient, IUserOperations, User, UserListOptions, Group, UserGroupsOptions, UserUpdatePasswordOptions, UserToCreate } from '../../models'; | ||
import { IHttpClient, PagedList } from 'contensis-core-api'; | ||
import { IHttpClient, ManagementQuery, PagedList } from 'contensis-core-api'; | ||
export declare class UserOperations implements IUserOperations { | ||
@@ -12,2 +12,3 @@ private httpClient; | ||
list(options?: UserListOptions): Promise<PagedList<User>>; | ||
search(query: ManagementQuery): Promise<PagedList<User>>; | ||
getUserGroups(userIdOrOptions: string | UserGroupsOptions): Promise<PagedList<Group>>; | ||
@@ -19,2 +20,3 @@ create(user: UserToCreate, suspended?: boolean): Promise<User>; | ||
userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>; | ||
setPasswordToExpirable(userId: string): Promise<void>; | ||
suspendUser(userId: string): Promise<void>; | ||
@@ -25,2 +27,4 @@ unlockUser(userId: string): Promise<void>; | ||
private getUser; | ||
private searchUsingManagementQuery; | ||
private searchUsingPost; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { UrlBuilder } from 'contensis-core-api'; | ||
import { isBrowser, isIE, UrlBuilder } from 'contensis-core-api'; | ||
let listMappers = { | ||
@@ -51,2 +51,8 @@ pageIndex: (value, options, params) => (options && options.pageOptions && options.pageOptions.pageIndex) || (params.pageIndex), | ||
} | ||
search(query) { | ||
if (!query) { | ||
return new Promise((resolve) => { resolve(null); }); | ||
} | ||
return this.searchUsingManagementQuery(query); | ||
} | ||
getUserGroups(userIdOrOptions) { | ||
@@ -156,2 +162,5 @@ let url = UrlBuilder.create('/api/security/users/:userId/groups', { order: null, pageIndex: null, pageSize: null, includeInherited: null, excludedGroups: null }) | ||
} | ||
setPasswordToExpirable(userId) { | ||
return this.performUserAction(userId, 'setPasswordToExpirable'); | ||
} | ||
suspendUser(userId) { | ||
@@ -194,2 +203,43 @@ return this.performUserAction(userId, 'suspend'); | ||
} | ||
searchUsingManagementQuery(query) { | ||
let params = this.contensisClient.getParams(); | ||
let pageSize = query.pageSize || params.pageSize; | ||
let pageIndex = query.pageIndex || 0; | ||
let orderBy = (query.orderBy && (query.orderBy._items || query.orderBy)); | ||
let { clientType, clientDetails, projectId, language, responseHandler, rootUrl, versionStatus, ...requestParams } = params; | ||
let payload = { | ||
...requestParams, | ||
pageSize, | ||
pageIndex, | ||
where: JSON.stringify(query.where), | ||
}; | ||
if (query.orderBy && (!Array.isArray(query.orderBy) || query.orderBy.length > 0)) { | ||
payload['orderBy'] = JSON.stringify(orderBy); | ||
} | ||
let url = UrlBuilder.create('/api/security/users/search', { ...payload }) | ||
.setParams(payload) | ||
.toUrl(); | ||
let absoluteUrl = (!params.rootUrl || params.rootUrl === '/') ? url : params.rootUrl + url; | ||
if (isBrowser() && isIE() && absoluteUrl.length > 2083) { | ||
return this.searchUsingPost(query); | ||
} | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
method: 'GET', | ||
headers: this.contensisClient.getHeaders(), | ||
}); | ||
}); | ||
} | ||
searchUsingPost(query) { | ||
let url = UrlBuilder.create('/api/security/users/search') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
method: 'POST', | ||
headers: this.contensisClient.getHeaders(), | ||
body: JSON.stringify(query) | ||
}); | ||
}); | ||
} | ||
} |
import * as Contensis from '../../index'; | ||
import { defaultUsers, getDefaultAuthenticateUrl, getDefaultConfig, getDefaultFetchRequest, setDefaultSpy, defaultGroups } from '../../specs-utils.spec'; | ||
import fetch from 'cross-fetch'; | ||
import { toQuery } from 'contensis-core-api'; | ||
const Zengenti = { Contensis }; | ||
@@ -149,2 +150,224 @@ const global = window || this; | ||
}); | ||
describe('Search users', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, { | ||
pageIndex: 0, | ||
pageSize: 25, | ||
totalCount: 2, | ||
items: defaultUsers | ||
}); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
}); | ||
it('with query as Object', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let orderBy = [{ | ||
desc: 'optOutOfNotifications' | ||
}, { | ||
asc: 'username' | ||
}]; | ||
let where = [{ | ||
field: 'email', | ||
equalTo: 'EEEEEE2@test.com' | ||
}, { | ||
field: 'username', | ||
in: ['UUUUUU1', 'UUUUUU2'] | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
...query, | ||
orderBy: JSON.stringify(orderBy), | ||
where: JSON.stringify(where) | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search${expectedQueryString}`, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as the default Query instance ', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let query = new Contensis.Query(); | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
pageIndex: 0, | ||
pageSize: 20, | ||
where: JSON.stringify([]) | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search${expectedQueryString}`, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as a specific Query instance ', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', 'EEEEEE2')); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy: JSON.stringify([{ | ||
asc: 'email' | ||
}]), | ||
where: JSON.stringify([{ | ||
field: 'email', | ||
startsWith: 'EEEEEE2' | ||
}]) | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search${expectedQueryString}`, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
}); | ||
describe('Search users in IE browser', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
pageSize: 25, | ||
totalCount: 2, | ||
items: defaultUsers | ||
}); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
global.document.documentMode = 11; | ||
}); | ||
it('with query as Object and url length = 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let orderBy = [{ | ||
asc: 'email' | ||
}]; | ||
// use string with length = 1896 | ||
let where = [{ | ||
field: 'email', | ||
// tslint:disable-next-line:max-line-length | ||
startsWith: 'r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwK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UdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w' | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
...query, | ||
orderBy: JSON.stringify(orderBy), | ||
where: JSON.stringify(where) | ||
}); | ||
let url = `http://my-website.com/api/security/users/search${expectedQueryString}`; | ||
expect(url.length).toEqual(2083); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
url, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as Object and url length > 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let orderBy = [{ | ||
asc: 'email' | ||
}]; | ||
// use string with length = 1897 | ||
let where = [{ | ||
field: 'email', | ||
// tslint:disable-next-line:max-line-length | ||
startsWith: '1r2PxHazYJ4W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KzMuzw4YD3GeXA7qqGjeQqcJQiF4KMbYzqXPUj7KVH2tg8pVXiFYqYuxEf61TzGab7WcEE7fU9V7rq1M6uqLiZC1KaPr8jM08DYMhjrmaJT6S9ZxfuqUdh6rjJJr5NvxZikhr9XXAKeL7RhgQjq12ZCDMjpDaPmKMufEVt9UTZcve6P7v1q6XYT7qJkpbYBfhn6vSh4XJBjuXDk4SkNu4cxC8F0D8zmU9jH7N1RNJ9nMEeSStafMV01W7aqABTXzz0eKkTUJuCX9UNTLuV2gAHnPkT3MGSjGC9UaJe5qbGUdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w' | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify(query)) | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as Query instance and url length = 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
// use string with length = 1896 | ||
// tslint:disable-next-line:max-line-length | ||
const startsWithText = 'r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrVhPaZw5pSjD8kZi30i82Zh8VEMmXgEiLFPc8jHJ45wRzpu898NgjKv53bYBHYWqgyEpZF5pg2B1cqq5fLnfarUFKENCaPqxiqhjhMJ1SHC0e8kfLM4zR0TdkC6r7G9Dp4WLc3v0wcveapUjtzL3LEWFYJZpHix9RNCBd7AWzY0PDXih9DMc59frTe7U7GEqXzd36LrYVR8Auv5vwiXzu4fdwihCbeiinHnWnZwtQTJHYKZHLDdD9zMj1CAyEbNTm327NfuDZMQGEYjU8JB0yjhND05MNraL9FXx29iNVTht3j4PxMb3CMQqcBwH22UejpUzxE0mcbKEPvTPVEuP8d6ptBQN3mKc6v5MZ47YqdBqWSxBKDbxDpr7eGNHqrKXP0jUXwavNcAhMWmnE8zxSVKEHWhwdrZnJP1hNz0XtKQaTPBxHZErHcic8z806iHEdVaPGG7Q76ySVh58rNGX8tinEYCNT9eAJizCCKGpvCvkL52VHjChKcMc50ggDHTa6dwmhx6Q9Gjj4YE0XTbcVLQxHf0B4aPgcegRyG82MmBgUz8cwi5R4T8LhyeazQd3ER46DKt9YJBp9LAJXarc7WV6Axn88CviugeSEqH2vaF6Cy0Q6Xcx8tTE9QeiyTtHmMZrKKzMuzw4YD3GeXA7qqGjeQqcJQiF4KMbYzqXPUj7KVH2tg8pVXiFYqYuxEf61TzGab7WcEE7fU9V7rq1M6uqLiZC1KaPr8jM08DYMhjrmaJT6S9ZxfuqUdh6rjJJr5NvxZikhr9XXAKeL7RhgQjq12ZCDMjpDaPmKMufEVt9UTZcve6P7v1q6XYT7qJkpbYBfhn6vSh4XJBjuXDk4SkNu4cxC8F0D8zmU9jH7N1RNJ9nMEeSStafMV01W7aqABTXzz0eKkTUJuCX9UNTLuV2gAHnPkT3MGSjGC9UaJe5qbGUdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w'; | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', startsWithText)); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy: JSON.stringify([{ | ||
asc: 'email' | ||
}]), | ||
where: JSON.stringify([{ | ||
field: 'email', | ||
startsWith: startsWithText | ||
}]) | ||
}); | ||
let url = `http://my-website.com/api/security/users/search${expectedQueryString}`; | ||
expect(url.length).toEqual(2083); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
url, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as Query instance and url length > 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
// use string with length = 1897 | ||
// tslint:disable-next-line:max-line-length | ||
const startsWithText = '1r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrVhPaZw5pSjD8kZi30i82Zh8VEMmXgEiLFPc8jHJ45wRzpu898NgjKv53bYBHYWqgyEpZF5pg2B1cqq5fLnfarUFKENCaPqxiqhjhMJ1SHC0e8kfLM4zR0T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iaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w'; | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', startsWithText)); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify(query)) | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
}); | ||
describe('Create user', () => { | ||
@@ -433,2 +656,13 @@ beforeEach(() => { | ||
}); | ||
it('setPasswordToExpirable', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let result = await client.security.users.setPasswordToExpirable(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`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify({ type: 'setPasswordToExpirable' })) | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
it('suspend', async () => { | ||
@@ -435,0 +669,0 @@ let client = Zengenti.Contensis.Client.create(getDefaultConfig()); |
@@ -8,2 +8,13 @@ # Changelog | ||
## [2.2.0] - 2024-10-10 | ||
### Added | ||
- users: supports *search* in user operations | ||
- users: supports *setPasswordToExpirable* action in user operations | ||
- groups: add child groups to a group in bulk with *addChildGroups* in group operations | ||
- groups: added *includeSelf* option when getting child groups of a group | ||
### Changed | ||
- updated project README | ||
## [2.1.9] - 2024-03-04 | ||
@@ -10,0 +21,0 @@ |
@@ -42,3 +42,9 @@ // Karma configuration | ||
autoWatchBatchDelay: 1000, | ||
browsers: ['Chrome'], | ||
browsers: ['ChromeDebugging'], | ||
customLaunchers: { | ||
ChromeDebugging: { | ||
base: 'Chrome', | ||
flags: [ '--remote-debugging-port=9333' ] | ||
} | ||
}, | ||
// browserDisconnectTimeout : 0, | ||
@@ -45,0 +51,0 @@ // browserNoActivityTimeout : 0, |
@@ -56,2 +56,3 @@ "use strict"; | ||
(0, specs_utils_spec_1.setDefaultSpy)(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -187,2 +188,3 @@ pageSize: 25, | ||
(0, specs_utils_spec_1.setDefaultSpy)(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -527,2 +529,3 @@ pageSize: 25, | ||
(0, specs_utils_spec_1.setDefaultSpy)(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -529,0 +532,0 @@ pageSize: 25, |
@@ -1,8 +0,4 @@ | ||
import { PageOptions } from 'contensis-core-api'; | ||
export interface GroupChildListOptions { | ||
includeInherited?: boolean; | ||
excludedGroups?: string[]; | ||
pageOptions?: PageOptions; | ||
order?: string[]; | ||
zenQL?: string; | ||
import { GroupUserListOptions } from './GroupUserListOptions'; | ||
export interface GroupChildListOptions extends GroupUserListOptions { | ||
includeSelf?: boolean; | ||
} |
@@ -1,3 +0,8 @@ | ||
import { GroupChildListOptions } from './GroupChildListOptions'; | ||
export interface GroupUserListOptions extends GroupChildListOptions { | ||
import { PageOptions } from 'contensis-core-api'; | ||
export interface GroupUserListOptions { | ||
includeInherited?: boolean; | ||
excludedGroups?: string[]; | ||
pageOptions?: PageOptions; | ||
order?: string[]; | ||
zenQL?: string; | ||
} |
@@ -18,2 +18,3 @@ import { Group, GroupToCreate } from './Group'; | ||
addChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
addChildGroups(groupId: string, childGroupIds: string[]): Promise<void>; | ||
removeChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
@@ -20,0 +21,0 @@ getUsersByGroupId(groupId: string, options?: GroupUserListOptions): Promise<PagedList<User>>; |
import { User, UserToCreate } from './User'; | ||
import { PagedList } from 'contensis-core-api'; | ||
import { ManagementQuery, PagedList } from 'contensis-core-api'; | ||
import { UserListOptions } from './UserListOptions'; | ||
@@ -13,2 +13,3 @@ import { Group } from './Group'; | ||
list(options?: UserListOptions): Promise<PagedList<User>>; | ||
search(query: ManagementQuery): Promise<PagedList<User>>; | ||
getUserGroups(userIdOrOptions: string | UserGroupsOptions): Promise<PagedList<Group>>; | ||
@@ -20,2 +21,3 @@ create(user: UserToCreate, suspended?: boolean): Promise<User>; | ||
userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>; | ||
setPasswordToExpirable(userId: string): Promise<void>; | ||
suspendUser(userId: string): Promise<void>; | ||
@@ -22,0 +24,0 @@ unlockUser(userId: string): Promise<void>; |
@@ -92,3 +92,4 @@ "use strict"; | ||
primaryLanguage: 'en-GB', | ||
supportedLanguages: ['fr-FR', 'de-DE'] | ||
supportedLanguages: ['fr-FR', 'de-DE'], | ||
deliverySysExclusions: [], | ||
}; | ||
@@ -95,0 +96,0 @@ let project = await client.projects.create(newProject); |
@@ -18,2 +18,3 @@ import { ContensisClient, Group, GroupListOptions, IGroupOperations, User, GroupUserListOptions, GroupChildListOptions, GroupToCreate } from '../../models'; | ||
addChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
addChildGroups(groupId: string, childGroupIds: string[]): Promise<void>; | ||
removeChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
@@ -20,0 +21,0 @@ getUsersByGroupId(groupId: string, options?: GroupUserListOptions): Promise<PagedList<User>>; |
@@ -9,3 +9,11 @@ "use strict"; | ||
order: (value) => (value && value.length > 0) ? value : null, | ||
q: (value) => (!!value) ? value : null, | ||
zenql: (value) => (!!value) ? value : null, | ||
}; | ||
let childListMappers = { | ||
pageIndex: (value, options, params) => (options && options.pageOptions && options.pageOptions.pageIndex) || (params.pageIndex), | ||
pageSize: (value, options, params) => (options && options.pageOptions && options.pageOptions.pageSize) || (params.pageSize), | ||
order: (value) => (value && value.length > 0) ? value : null, | ||
excludedGroups: (value) => (value && value.length > 0) ? value.join(',') : null, | ||
includeSelf: (value) => (!!value) ? value : null, | ||
}; | ||
@@ -17,2 +25,3 @@ let userListMappers = { | ||
excludedGroups: (value) => (value && value.length > 0) ? value.join(',') : null, | ||
includeInherited: (value) => (!!value) ? value : null, | ||
}; | ||
@@ -195,2 +204,21 @@ class GroupOperations { | ||
} | ||
addChildGroups(groupId, childGroupIds) { | ||
if (!groupId) { | ||
throw new Error('A valid group id needs to be specified.'); | ||
} | ||
if (!childGroupIds || childGroupIds.length === 0) { | ||
throw new Error('At least one valid child group id needs to be specified.'); | ||
} | ||
let url = contensis_core_api_1.UrlBuilder.create('/api/security/groups/:groupId/groups', {}) | ||
.addOptions(groupId, 'groupId') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
headers: this.contensisClient.getHeaders(), | ||
method: 'POST', | ||
body: JSON.stringify(childGroupIds) | ||
}); | ||
}); | ||
} | ||
removeChildGroup(groupId, childGroupId) { | ||
@@ -264,7 +292,7 @@ if (!groupId) { | ||
getChildGroups(idOrName, options) { | ||
let url = contensis_core_api_1.UrlBuilder.create('/api/security/groups/:idOrName/groups', !options ? {} : { includeInherited: null, excludedGroups: null, q: null, pageIndex: null, pageSize: null, order: null, zenQL: null }) | ||
let url = contensis_core_api_1.UrlBuilder.create('/api/security/groups/:idOrName/groups', !options ? {} : { includeSelf: null, includeInherited: null, excludedGroups: null, q: null, pageIndex: null, pageSize: null, order: null, zenQL: null }) | ||
.addOptions(idOrName, 'idOrName') | ||
.addOptions(options) | ||
.setParams(this.contensisClient.getParams()) | ||
.addMappers(listMappers) | ||
.addMappers(childListMappers) | ||
.toUrl(); | ||
@@ -271,0 +299,0 @@ return this.contensisClient.ensureBearerToken().then(() => { |
@@ -299,2 +299,22 @@ "use strict"; | ||
}); | ||
describe('Add child groups to group', () => { | ||
beforeEach(() => { | ||
(0, specs_utils_spec_1.setDefaultSpy)(global, null); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch, | ||
}); | ||
}); | ||
it('for valid group and child groups', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let result = await client.security.groups.addChildGroups(specs_utils_spec_1.defaultGroups[0].id, [specs_utils_spec_1.defaultGroups[1].id]); | ||
expect(global.fetch).toHaveBeenCalledTimes(2); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${specs_utils_spec_1.defaultGroups[0].id}/groups`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)('POST', false, JSON.stringify([specs_utils_spec_1.defaultGroups[1].id])), | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
}); | ||
describe('Remove child group from group', () => { | ||
@@ -478,7 +498,8 @@ beforeEach(() => { | ||
pageOptions: { pageIndex: 1, pageSize: 50 }, | ||
order: ['name'] | ||
order: ['name'], | ||
includeSelf: true | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${specs_utils_spec_1.defaultGroups[0].id}/groups?includeInherited=true&order=name&pageIndex=1&pageSize=50`, | ||
`http://my-website.com/api/security/groups/${specs_utils_spec_1.defaultGroups[0].id}/groups?includeInherited=true&includeSelf=true&order=name&pageIndex=1&pageSize=50`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
@@ -507,7 +528,8 @@ ]); | ||
pageOptions: { pageIndex: 1, pageSize: 50 }, | ||
order: ['name'] | ||
order: ['name'], | ||
includeSelf: true | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${specs_utils_spec_1.defaultGroups[0].name}/groups?includeInherited=true&order=name&pageIndex=1&pageSize=50`, | ||
`http://my-website.com/api/security/groups/${specs_utils_spec_1.defaultGroups[0].name}/groups?includeInherited=true&includeSelf=true&order=name&pageIndex=1&pageSize=50`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
@@ -514,0 +536,0 @@ ]); |
import { ContensisClient, IUserOperations, User, UserListOptions, Group, UserGroupsOptions, UserUpdatePasswordOptions, UserToCreate } from '../../models'; | ||
import { IHttpClient, PagedList } from 'contensis-core-api'; | ||
import { IHttpClient, ManagementQuery, PagedList } from 'contensis-core-api'; | ||
export declare class UserOperations implements IUserOperations { | ||
@@ -12,2 +12,3 @@ private httpClient; | ||
list(options?: UserListOptions): Promise<PagedList<User>>; | ||
search(query: ManagementQuery): Promise<PagedList<User>>; | ||
getUserGroups(userIdOrOptions: string | UserGroupsOptions): Promise<PagedList<Group>>; | ||
@@ -19,2 +20,3 @@ create(user: UserToCreate, suspended?: boolean): Promise<User>; | ||
userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>; | ||
setPasswordToExpirable(userId: string): Promise<void>; | ||
suspendUser(userId: string): Promise<void>; | ||
@@ -25,2 +27,4 @@ unlockUser(userId: string): Promise<void>; | ||
private getUser; | ||
private searchUsingManagementQuery; | ||
private searchUsingPost; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UserOperations = void 0; | ||
const tslib_1 = require("tslib"); | ||
const contensis_core_api_1 = require("contensis-core-api"); | ||
@@ -52,2 +53,8 @@ let listMappers = { | ||
} | ||
search(query) { | ||
if (!query) { | ||
return new Promise((resolve) => { resolve(null); }); | ||
} | ||
return this.searchUsingManagementQuery(query); | ||
} | ||
getUserGroups(userIdOrOptions) { | ||
@@ -157,2 +164,5 @@ let url = contensis_core_api_1.UrlBuilder.create('/api/security/users/:userId/groups', { order: null, pageIndex: null, pageSize: null, includeInherited: null, excludedGroups: null }) | ||
} | ||
setPasswordToExpirable(userId) { | ||
return this.performUserAction(userId, 'setPasswordToExpirable'); | ||
} | ||
suspendUser(userId) { | ||
@@ -195,3 +205,40 @@ return this.performUserAction(userId, 'suspend'); | ||
} | ||
searchUsingManagementQuery(query) { | ||
let params = this.contensisClient.getParams(); | ||
let pageSize = query.pageSize || params.pageSize; | ||
let pageIndex = query.pageIndex || 0; | ||
let orderBy = (query.orderBy && (query.orderBy._items || query.orderBy)); | ||
let { clientType, clientDetails, projectId, language, responseHandler, rootUrl, versionStatus } = params, requestParams = tslib_1.__rest(params, ["clientType", "clientDetails", "projectId", "language", "responseHandler", "rootUrl", "versionStatus"]); | ||
let payload = Object.assign(Object.assign({}, requestParams), { pageSize, | ||
pageIndex, where: JSON.stringify(query.where) }); | ||
if (query.orderBy && (!Array.isArray(query.orderBy) || query.orderBy.length > 0)) { | ||
payload['orderBy'] = JSON.stringify(orderBy); | ||
} | ||
let url = contensis_core_api_1.UrlBuilder.create('/api/security/users/search', Object.assign({}, payload)) | ||
.setParams(payload) | ||
.toUrl(); | ||
let absoluteUrl = (!params.rootUrl || params.rootUrl === '/') ? url : params.rootUrl + url; | ||
if ((0, contensis_core_api_1.isBrowser)() && (0, contensis_core_api_1.isIE)() && absoluteUrl.length > 2083) { | ||
return this.searchUsingPost(query); | ||
} | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
method: 'GET', | ||
headers: this.contensisClient.getHeaders(), | ||
}); | ||
}); | ||
} | ||
searchUsingPost(query) { | ||
let url = contensis_core_api_1.UrlBuilder.create('/api/security/users/search') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
method: 'POST', | ||
headers: this.contensisClient.getHeaders(), | ||
body: JSON.stringify(query) | ||
}); | ||
}); | ||
} | ||
} | ||
exports.UserOperations = UserOperations; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const cross_fetch_1 = require("cross-fetch"); | ||
const contensis_core_api_1 = require("contensis-core-api"); | ||
const Zengenti = { Contensis }; | ||
@@ -153,2 +154,216 @@ const global = window || this; | ||
}); | ||
describe('Search users', () => { | ||
beforeEach(() => { | ||
(0, specs_utils_spec_1.setDefaultSpy)(global, { | ||
pageIndex: 0, | ||
pageSize: 25, | ||
totalCount: 2, | ||
items: specs_utils_spec_1.defaultUsers | ||
}); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
}); | ||
it('with query as Object', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let orderBy = [{ | ||
desc: 'optOutOfNotifications' | ||
}, { | ||
asc: 'username' | ||
}]; | ||
let where = [{ | ||
field: 'email', | ||
equalTo: 'EEEEEE2@test.com' | ||
}, { | ||
field: 'username', | ||
in: ['UUUUUU1', 'UUUUUU2'] | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = (0, contensis_core_api_1.toQuery)(Object.assign(Object.assign({}, query), { orderBy: JSON.stringify(orderBy), where: JSON.stringify(where) })); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search${expectedQueryString}`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
it('with query as the default Query instance ', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let query = new Contensis.Query(); | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = (0, contensis_core_api_1.toQuery)({ | ||
pageIndex: 0, | ||
pageSize: 20, | ||
where: JSON.stringify([]) | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search${expectedQueryString}`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
it('with query as a specific Query instance ', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', 'EEEEEE2')); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = (0, contensis_core_api_1.toQuery)({ | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy: JSON.stringify([{ | ||
asc: 'email' | ||
}]), | ||
where: JSON.stringify([{ | ||
field: 'email', | ||
startsWith: 'EEEEEE2' | ||
}]) | ||
}); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search${expectedQueryString}`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
}); | ||
describe('Search users in IE browser', () => { | ||
beforeEach(() => { | ||
(0, specs_utils_spec_1.setDefaultSpy)(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
pageSize: 25, | ||
totalCount: 2, | ||
items: specs_utils_spec_1.defaultUsers | ||
}); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
global.document.documentMode = 11; | ||
}); | ||
it('with query as Object and url length = 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let orderBy = [{ | ||
asc: 'email' | ||
}]; | ||
// use string with length = 1896 | ||
let where = [{ | ||
field: 'email', | ||
// tslint:disable-next-line:max-line-length | ||
startsWith: 'r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrV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mK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w' | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = (0, contensis_core_api_1.toQuery)(Object.assign(Object.assign({}, query), { orderBy: JSON.stringify(orderBy), where: JSON.stringify(where) })); | ||
let url = `http://my-website.com/api/security/users/search${expectedQueryString}`; | ||
expect(url.length).toEqual(2083); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
url, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
it('with query as Object and url length > 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let orderBy = [{ | ||
asc: 'email' | ||
}]; | ||
// use string with length = 1897 | ||
let where = [{ | ||
field: 'email', | ||
// tslint:disable-next-line:max-line-length | ||
startsWith: '1r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62W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ab7WcEE7fU9V7rq1M6uqLiZC1KaPr8jM08DYMhjrmaJT6S9ZxfuqUdh6rjJJr5NvxZikhr9XXAKeL7RhgQjq12ZCDMjpDaPmKMufEVt9UTZcve6P7v1q6XYT7qJkpbYBfhn6vSh4XJBjuXDk4SkNu4cxC8F0D8zmU9jH7N1RNJ9nMEeSStafMV01W7aqABTXzz0eKkTUJuCX9UNTLuV2gAHnPkT3MGSjGC9UaJe5qbGUdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w' | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)('POST', false, JSON.stringify(query)) | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
it('with query as Query instance and url length = 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
// use string with length = 1896 | ||
// tslint:disable-next-line:max-line-length | ||
const startsWithText = 'r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrVhPaZw5pSjD8kZi30i82Zh8VEMmXgEiLFPc8jHJ45wRzpu898NgjKv53bYBHYWqgyEpZF5pg2B1cqq5fLnfarUFKENCaPqxiqhjhMJ1SHC0e8kfLM4zR0TdkC6r7G9Dp4WLc3v0wcveapUjtzL3LEWFYJZpHix9RNCBd7AWzY0PDXih9DMc59frTe7U7GEqXzd36LrYVR8Auv5vwiXzu4fdwihCbeiinHnWnZwtQTJHYKZHLDdD9zMj1CAyEbNTm327NfuDZMQGEYjU8JB0yjhND05MNraL9FXx29iNVTht3j4PxMb3CMQqcBwH22UejpUzxE0mcbKEPvTPVEuP8d6ptBQN3mKc6v5MZ47YqdBqWSxBKDbxDpr7eGNHqrKXP0jUXwavNcAhMWmnE8zxSVKEHWhwdrZnJP1hNz0XtKQaTPBxHZErHcic8z806iHEdVaPGG7Q76ySVh58rNGX8tinEYCNT9eAJizCCKGpvCvkL52VHjChKcMc50ggDHTa6dwmhx6Q9Gjj4YE0XTbcVLQxHf0B4aPgcegRyG82MmBgUz8cwi5R4T8LhyeazQd3ER46DKt9YJBp9LAJXarc7WV6Axn88CviugeSEqH2vaF6Cy0Q6Xcx8tTE9QeiyTtHmMZrKKzMuzw4YD3GeXA7qqGjeQqcJQiF4KMbYzqXPUj7KVH2tg8pVXiFYqYuxEf61TzGab7WcEE7fU9V7rq1M6uqLiZC1KaPr8jM08DYMhjrmaJT6S9ZxfuqUdh6rjJJr5NvxZikhr9XXAKeL7RhgQjq12ZCDMjpDaPmKMufEVt9UTZcve6P7v1q6XYT7qJkpbYBfhn6vSh4XJBjuXDk4SkNu4cxC8F0D8zmU9jH7N1RNJ9nMEeSStafMV01W7aqABTXzz0eKkTUJuCX9UNTLuV2gAHnPkT3MGSjGC9UaJe5qbGUdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w'; | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', startsWithText)); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = (0, contensis_core_api_1.toQuery)({ | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy: JSON.stringify([{ | ||
asc: 'email' | ||
}]), | ||
where: JSON.stringify([{ | ||
field: 'email', | ||
startsWith: startsWithText | ||
}]) | ||
}); | ||
let url = `http://my-website.com/api/security/users/search${expectedQueryString}`; | ||
expect(url.length).toEqual(2083); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
url, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
it('with query as Query instance and url length > 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
// use string with length = 1897 | ||
// tslint:disable-next-line:max-line-length | ||
const startsWithText = '1r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrVhPaZw5pSjD8kZi30i82Zh8VEMmXgEiLFPc8jHJ45wRzpu898NgjKv53b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ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w'; | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', startsWithText)); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, specs_utils_spec_1.getDefaultAuthenticateUrl)()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/users/search`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)('POST', false, JSON.stringify(query)) | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(specs_utils_spec_1.defaultUsers[1].username); | ||
}); | ||
}); | ||
describe('Create user', () => { | ||
@@ -437,2 +652,13 @@ beforeEach(() => { | ||
}); | ||
it('setPasswordToExpirable', async () => { | ||
let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); | ||
let result = await client.security.users.setPasswordToExpirable(specs_utils_spec_1.defaultUsers[0].id); | ||
expect(global.fetch).toHaveBeenCalledTimes(2); | ||
expect(global.fetch.calls.first().args[0]).toEqual((0, 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`, | ||
(0, specs_utils_spec_1.getDefaultFetchRequest)('POST', false, JSON.stringify({ type: 'setPasswordToExpirable' })) | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
it('suspend', async () => { | ||
@@ -439,0 +665,0 @@ let client = Zengenti.Contensis.Client.create((0, specs_utils_spec_1.getDefaultConfig)()); |
{ | ||
"name": "contensis-management-api", | ||
"version": "2.1.9", | ||
"description": "Contensis Javascript Management API", | ||
"version": "2.2.0", | ||
"description": "Client for managing content using the Contensis Management API", | ||
"engines": { | ||
@@ -30,3 +30,3 @@ "node": ">=14" | ||
}, | ||
"homepage": "https://github.com/contensis/contensis-management-api#readme", | ||
"homepage": "https://www.contensis.com/help-and-docs/apis/management-js", | ||
"devDependencies": { | ||
@@ -56,3 +56,3 @@ "@types/jasmine": "3.6.2", | ||
"@types/graceful-fs": "^4.1.3", | ||
"contensis-core-api": "1.1.0", | ||
"contensis-core-api": "^1.1.2", | ||
"cross-fetch": "^3.0.6", | ||
@@ -71,5 +71,11 @@ "es6-promise": "^4.2.8", | ||
"contensis", | ||
"cms", | ||
"dxp", | ||
"content", | ||
"management", | ||
"api" | ||
"api", | ||
"js", | ||
"library", | ||
"client" | ||
] | ||
} |
211
README.md
@@ -1,79 +0,178 @@ | ||
# 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. This version targets Contensis 14.0 and above. | ||
# [![Contensis](https://github.com/contensis/cli/raw/refs/heads/main/assets/contensis-logo--tiny.svg)](https://www.contensis.com) contensis-management-api [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![NPM version](https://img.shields.io/npm/v/contensis-management-api.svg?style=flat)](https://www.npmjs.com/package/contensis-management-api) | ||
The *[contensis-management-api-examples](https://github.com/contensis/contensis-management-api-examples)* repo contains Express and React examples. | ||
[![JavaScript](https://img.shields.io/badge/JavaScript-323330?style=for-the-badge&logo=javascript&logoColor=F7DF1E)](https://developer.mozilla.org/en-US/docs/Web/JavaScript) | ||
[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) | ||
[![Node.js](https://img.shields.io/badge/Node%20js-339933?style=for-the-badge&logo=nodedotjs&logoColor=white)](https://nodejs.org/en) | ||
<!-- The following paragraphs are taken from https://github.com/contensis/docs-management-js/blob/master/key-concepts/api-instantiation.md --> | ||
[![Angular](https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white)](https://angular.dev/) [![Electron](https://img.shields.io/badge/Electron-2B2E3A?style=for-the-badge&logo=electron&logoColor=9FEAF9)](https://electronjs.org/) [![Express.js](https://img.shields.io/badge/Express%20js-000000?style=for-the-badge&logo=express&logoColor=white)](https://expressjs.com/) [![React](https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB)](https://react.dev/) [![React Native](https://img.shields.io/badge/React_Native-20232A?style=for-the-badge&logo=react&logoColor=61DAFB)](https://reactnative.dev/) [![Vue.js](https://img.shields.io/badge/Vue%20js-35495E?style=for-the-badge&logo=vuedotjs&logoColor=4FC08D)](https://vuejs.org/) | ||
## Installing and importing the client *npm* package | ||
[![Contensis](https://img.shields.io/badge/Contensis-00304d?style=for-the-badge&logoColor=white&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA2NCIgaGVpZ2h0PSIxOCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0ibTQ3Ljc2MiAxOC40OTQtMy42MTItMi4wNmMuMzU4IDEuNjU1LjYzMSAzLjI5Ljc5OSA0Ljg1OS4xNDQgMS4zNTMuMzU4IDQuMzA5LjM1OCA0LjQ1djE5Ljk3NWMwIC40MjctLjUxOCAxLjMxMS0uODkyIDEuNTI2TDI2Ljg5MyA1Ny4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gtMS4xMTQtLjQ4Mi05LjgxNS40NC0xMi4yNjQuNTI3IDMuNzc4IDEuNjE2IDcuMjY1IDIuMDIgOC40ODNhMTEzLjk0OCAxMTMuOTQ4IDAgMCAwIDIuNzQ2LTQuNjg1Yy0uMDgzLTIuMjEzLS4zMTMtMTAuMDA4LjQ2LTExLjc5NC4yMDUgMi41NzUgMS4xNjMgNS44NTIgMS43MzggNy42MzcuNzY0LTEuNTIzIDEuMTgzLTIuNDUgMS4xOTMtMi40NzJsMi43MDUtNi4wMTYtLjcxIDYuNTQ1Yy0uMDA0LjAzNC0uMjQyIDIuMTkzLS44MiA1LjQ3OCAxLjU4Ni0xLjI4OSA0LjEwNC0zLjQ1NyA1LjMyOC01LjE2LjEwNSAyLjA1NC00LjQ0NCA3LjU1Ni02LjE5MyA5LjU5NC0uMTgzLjg0OS0uMzgyIDEuNzMtLjYgMi42MzUtLjE1NC42NC0uMzEyIDEuMjctLjQ3MyAxLjg5IDEuNTE3LS44NDIgNC45OTItMi44NiA2LjkzMi00LjY5Ny0uMjk0IDIuMDk1LTYuNDYgNy40MTktOC4wOSA4Ljc5NGE4MC4xNjEgODAuMTYxIDAgMCAxLTEuMzM2IDMuOThjMy43NDQtLjIxMyA3LjY3Ni0yLjEgMTAuOTY4LTYuMTM2QzQ5LjQwNyAyNC45NiAzNS42NzItMy43NjUgMzMuMjAyLjQxMVoiLz48L3N2Zz4=)](https://www.contensis.com) | ||
[![Contensis Slack](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge&logo=slack&logoColor=white)](https://contensis.slack.com) | ||
The Contensis JS Management API client is delivered as an [*npm*](https://www.npmjs.com/package/contensis-management-api) package, with publicly available [source code](https://github.com/contensis/contensis-management-api) and [examples](https://github.com/contensis/contensis-management-api-examples). | ||
The client package can be used in a modern browser, in Node.js or as cross-platform client (e.g. a React.js application, a Node.js console application, an Express.js web application, a JavaScript or TypeScript library). | ||
Create a Contensis client that allows you to manage various aspects of your Contensis environment, content or deployments. It can be used in all your JavaScript / TypeScript projects, whether it runs in a browser, Node.js app, or both. | ||
[**Explore the docs on contensis.com**](https://www.contensis.com/help-and-docs/apis/management-js) and the [contensis-management-api-examples](https://github.com/contensis/contensis-management-api-examples) repository containing Express.js and React examples. | ||
Use with Contensis version 14.0 and above. This library requires Node.js 14 or above. | ||
## Installation | ||
Install the package to your project `dependencies` using npm, or your preferred Node.js package manager. | ||
```shell | ||
npm install --save contensis-management-api | ||
``` | ||
> ### Note | ||
> Before following the rest of the examples we assume you have an existing Node.js or Express.js application that is already created, that targets Node.js >= 10 and uses the *CommonJS* module system (you can also use native JavaScript modules - see [examples](https://github.com/contensis/contensis-management-api-examples)). | ||
> The Contensis JS Management API client is using the *fetch* API to maintain consistency with the Contensis JS Delivery API client. The *fetch* API is not a native Node.js API and it is loaded from the *node-fetch* npm package when the Contensis JS Management API client runs in a Node.js environment (if it runs in a browser enviroment the native *fetch* API will be used instead). | ||
> | ||
> Before following the rest of the examples we assume you have an existing Node.js / Express.js application that is already created. | ||
> | ||
> To get started with a new Node.js app, inside a terminal, `cd` to your chosen directory and run `npm init` | ||
To install the required packages for the Contensis JS Management API client please run the following Node.js command: | ||
## Import the correct client | ||
Depending on how and where your code is used you may need to find the right Client flavour to import that creates the Management Client best suited to your use case | ||
### Browser app | ||
The default `Client` import targets primarily a modern browser and assumes the `fetch` API is already available. | ||
```typescript | ||
// Using TypeScript, or ES Module syntax | ||
import { Client } from "contensis-management-api"; | ||
// Using Common JS syntax | ||
const Client = require("contensis-management-api").Client; | ||
``` | ||
npm install contensis-management-api | ||
### Universal JS app | ||
Universal JavaScript describes a JavaScript application which runs both on the client and the server. | ||
If your API interactions will be made using a part of your application that runs [Universal or Isomorphic JavaScript](https://en.wikipedia.org/wiki/Isomorphic_JavaScript) you should instead use the `UniversalClient` | ||
```typescript | ||
// Using TypeScript, or ES Module syntax | ||
import { UniversalClient } from "contensis-management-api"; | ||
// Using Common JS syntax | ||
const UniversalClient = require("contensis-management-api").UniversalClient; | ||
``` | ||
Import default *Client* if you are using *CommonJS* modules: | ||
```js | ||
const Client = require('contensis-management-api').Client; | ||
### Node.js app | ||
For applications that run exclusively on a server, or via a terminal script you will likely want to import and use the `NodejsClient` | ||
Some Management API functionality is only available in a Node.js environment for example creating and updating assets. The `NodejsClient` class ensures `fetch` API is made available and allows us to perform file operations with the `fs` API. | ||
```typescript | ||
// Using TypeScript, or ES Module syntax | ||
import { NodejsClient } from "contensis-management-api/lib/client"; | ||
// Using Common JS syntax | ||
const NodejsClient = | ||
require("contensis-management-api/lib/client").NodejsClient; | ||
``` | ||
Import the default *Client* if you are using native JavaScript modules: | ||
```js | ||
import { Client } from 'contensis-management-api'; | ||
## Configure and create a client | ||
The `config` argument passed to the `Client.create(...)` method represents the shared configuration that will be used by all Management API calls | ||
Use the provided intellisense to guide you where it is available | ||
```typescript | ||
// Import the additional "Config" type when using TypeScript | ||
import { Client, Config } from "contensis-management-api"; | ||
// Remove ": Config" annotation when NOT using TypeScript | ||
const config: Config = { | ||
rootUrl: "https://cms-example.cloud.contensis.com", | ||
projectId: "website", | ||
clientType: "client_credentials", | ||
clientDetails: { | ||
clientId: "6f8cf1e8-b2ee-49ad-9b94-2dbb09871903", | ||
clientSecret: | ||
"6d80c9a356ce4317bd71d92c5734d67a-4a837b1336344f63b1b24ce2dfa73945-ef09daa8d0f74b1e8e223779c392a67b", | ||
}, | ||
}; | ||
// Using the default Client | ||
const client = Client.create(config); | ||
// Using the UniversalClient | ||
const client = UniversalClient.create(config); | ||
// Using the NodejsClient | ||
const client = NodejsClient.create(config); | ||
``` | ||
The default *Client* class exported in the *contensis-management-api* package targets primarily a modern browser and assumes the *fetch* API is already made available. | ||
## Using the client | ||
As an alternative you can use the *UniversalClient* class that ensures *fetch* API is always made available regardless if you are in a browser context or a Node.js context. | ||
All of the API operations are available under the `client` instance returned by `Client.create({ ...options })` | ||
Import *UniversalClient* if you are using *CommonJS* modules: | ||
```js | ||
const UniversalClient = require('contensis-management-api/lib/client').UniversalClient; | ||
```typescript | ||
// Using async / await syntax | ||
const listContentTypes = async () => { | ||
try { | ||
const result = await client.contentTypes.list(); | ||
console.log("API call result: ", result); | ||
return result; | ||
} catch (error) { | ||
console.log("API call fetch error: ", error); | ||
throw error; | ||
} | ||
}; | ||
listContentTypes(); | ||
``` | ||
Import *UniversalClient* if you are using native JavaScript modules: | ||
```js | ||
import { UniversalClient } from 'contensis-management-api/lib/client'; | ||
``` | ||
Some Contensis JS Management API functionality is only available in a Node.js environment (e.g. creating and updating assets). In this scenario you need to use the *NodejsClient* class ensures *fetch* API is made available. | ||
Import *NodejsClient* if you are using *CommonJS* modules: | ||
```js | ||
const NodejsClient = require('contensis-management-api/lib/client').NodejsClient; | ||
``` | ||
Import *NodejsClient* if you are using native JavaScript modules: | ||
```js | ||
import { NodejsClient } from 'contensis-management-api/lib/client'; | ||
```typescript | ||
// Using Promises and callbacks | ||
function listContentTypes() { | ||
client.contentTypes | ||
.list() | ||
.then((result) => { | ||
console.log("API call result: ", result); | ||
return result; | ||
}) | ||
.catch((error) => { | ||
console.log("API call fetch error: ", error); | ||
throw error; | ||
}); | ||
} | ||
listContentTypes(); | ||
``` | ||
## Creating and using the client instance | ||
All operations for the API hang off the `Client` type (or `UniversalClient` and `NodejsClient` if you are using those), which is created using the static method call `Client.create(options)`. The `options` object represents the shared configuration that will be used by all Management API calls and is of type [Config](/model/config.md): | ||
_For more examples refer to our [documentation on contensis.com](https://www.contensis.com/help-and-docs/apis/management-js)_ | ||
```js | ||
## Fetch API | ||
This library uses the `fetch` API and relies on it being available at runtime. | ||
### Browser support | ||
In modern browsers `fetch` is available natively, a polyfill is provided for older browsers. | ||
### Node.js support | ||
When using this library in Node.js the `fetch` API is already polyfilled with [`cross-fetch`](https://www.npmjs.com/package/cross-fetch) package (which uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) when used with a Node.js runtime). | ||
Node.js [version 16](https://nodejs.org/docs/latest-v16.x/api/globals.html#fetch) introduced experimental support for a native global `fetch` API and shipped as standard with Node.js versions [18](https://nodejs.org/docs/latest-v18.x/api/globals.html#fetch) and [20](https://nodejs.org/docs/latest-v20.x/api/globals.html#fetch). The global `fetch` support in Node.js [version 21](https://nodejs.org/docs/latest-v21.x/api/globals.html#fetch) and greater is marked as stable. | ||
### Use your own fetch | ||
You can override the built-in fetch API by providing your own `fetchFn` method when creating the Client. | ||
Method calls that require fetch invoked from this client instance will be made using your chosen API. | ||
```typescript | ||
import { Client } from "contensis-management-api"; | ||
import enterpriseFetch from "enterprise-fetch"; | ||
const client = Client.create({ | ||
clientType: "client_credentials", | ||
clientDetails: { | ||
clientId: '6f8cf1e8-b2ee-49ad-9b94-2dbb09871903', | ||
clientSecret: '6d80c9a356ce4317bd71d92c5734d67a-4a837b1336344f63b1b24ce2dfa73945-ef09daa8d0f74b1e8e223779c392a67b' | ||
} | ||
projectId: 'website', | ||
rootUrl: 'https://cms-example.cloud.contensis.com' | ||
...config | ||
fetchFn: enterpriseFetch, | ||
}); | ||
client.contentTypes.list() | ||
.then(result => { | ||
console.log('API call result: ', result); | ||
return result; | ||
}) | ||
.catch(error => { | ||
console.log('API call fetch error: ', error); | ||
throw error; | ||
}); | ||
``` | ||
``` |
@@ -73,2 +73,3 @@ import * as Contensis from '../index'; | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -236,2 +237,3 @@ pageSize: 25, | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -683,2 +685,3 @@ pageSize: 25, | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
@@ -685,0 +688,0 @@ pageSize: 25, |
@@ -1,10 +0,5 @@ | ||
import { PageOptions } from 'contensis-core-api'; | ||
import { GroupUserListOptions } from './GroupUserListOptions'; | ||
export interface GroupChildListOptions { | ||
includeInherited?: boolean; | ||
excludedGroups?: string[]; | ||
pageOptions?: PageOptions; | ||
order?: string[]; | ||
zenQL?: string; | ||
export interface GroupChildListOptions extends GroupUserListOptions { | ||
includeSelf?: boolean; | ||
} |
@@ -1,5 +0,9 @@ | ||
import { GroupChildListOptions } from './GroupChildListOptions'; | ||
import { PageOptions } from 'contensis-core-api'; | ||
export interface GroupUserListOptions extends GroupChildListOptions { | ||
export interface GroupUserListOptions { | ||
includeInherited?: boolean; | ||
excludedGroups?: string[]; | ||
pageOptions?: PageOptions; | ||
order?: string[]; | ||
zenQL?: string; | ||
} |
@@ -19,2 +19,3 @@ import { Group, GroupToCreate } from './Group'; | ||
addChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
addChildGroups(groupId: string, childGroupIds: string[]): Promise<void>; | ||
removeChildGroup(groupId: string, childGroupId: string): Promise<void>; | ||
@@ -21,0 +22,0 @@ getUsersByGroupId(groupId: string, options?: GroupUserListOptions): Promise<PagedList<User>>; |
import { User, UserToCreate } from './User'; | ||
import { PagedList } from 'contensis-core-api'; | ||
import { ManagementQuery, PagedList } from 'contensis-core-api'; | ||
import { UserListOptions } from './UserListOptions'; | ||
@@ -14,2 +14,3 @@ import { Group } from './Group'; | ||
list(options?: UserListOptions): Promise<PagedList<User>>; | ||
search(query: ManagementQuery): Promise<PagedList<User>>; | ||
getUserGroups(userIdOrOptions: string | UserGroupsOptions): Promise<PagedList<Group>>; | ||
@@ -21,2 +22,3 @@ create(user: UserToCreate, suspended?: boolean): Promise<User>; | ||
userIsMemberOf(userId: string, ...groupIdsOrNames: string[]): Promise<boolean>; | ||
setPasswordToExpirable(userId: string): Promise<void>; | ||
suspendUser(userId: string): Promise<void>; | ||
@@ -23,0 +25,0 @@ unlockUser(userId: string): Promise<void>; |
@@ -117,3 +117,4 @@ import * as Contensis from '../index'; | ||
primaryLanguage: 'en-GB', | ||
supportedLanguages: ['fr-FR', 'de-DE'] | ||
supportedLanguages: ['fr-FR', 'de-DE'], | ||
deliverySysExclusions: [], | ||
}; | ||
@@ -120,0 +121,0 @@ let project = await client.projects.create(newProject); |
@@ -415,2 +415,35 @@ import * as Contensis from '../../index'; | ||
describe('Add child groups to group', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, null); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch, | ||
}); | ||
}); | ||
it('for valid group and child groups', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let result = await client.security.groups.addChildGroups( | ||
defaultGroups[0].id, | ||
[defaultGroups[1].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/groups/${defaultGroups[0].id}/groups`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify([defaultGroups[1].id])), | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
}); | ||
describe('Remove child group from group', () => { | ||
@@ -643,3 +676,4 @@ beforeEach(() => { | ||
pageOptions: { pageIndex: 1, pageSize: 50 }, | ||
order: ['name'] | ||
order: ['name'], | ||
includeSelf: true | ||
}); | ||
@@ -650,3 +684,3 @@ | ||
expect((global.fetch as any).calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].id}/groups?includeInherited=true&order=name&pageIndex=1&pageSize=50`, | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].id}/groups?includeInherited=true&includeSelf=true&order=name&pageIndex=1&pageSize=50`, | ||
getDefaultFetchRequest() | ||
@@ -681,3 +715,4 @@ ]); | ||
pageOptions: { pageIndex: 1, pageSize: 50 }, | ||
order: ['name'] | ||
order: ['name'], | ||
includeSelf: true | ||
}); | ||
@@ -688,3 +723,3 @@ | ||
expect((global.fetch as any).calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].name}/groups?includeInherited=true&order=name&pageIndex=1&pageSize=50`, | ||
`http://my-website.com/api/security/groups/${defaultGroups[0].name}/groups?includeInherited=true&includeSelf=true&order=name&pageIndex=1&pageSize=50`, | ||
getDefaultFetchRequest() | ||
@@ -691,0 +726,0 @@ ]); |
@@ -8,3 +8,12 @@ import { ContensisClient, Group, GroupListOptions, IGroupOperations, User, UserListOptions, GroupUserListOptions, GroupChildListOptions, GroupToCreate } from '../../models'; | ||
order: (value: string[]) => (value && value.length > 0) ? value : null, | ||
q: (value: string) => (!!value) ? value : null, | ||
zenql: (value: string) => (!!value) ? value : null, | ||
}; | ||
let childListMappers: { [key: string]: MapperFn } = { | ||
pageIndex: (value: number, options: GroupListOptions, params: ClientParams) => (options && options.pageOptions && options.pageOptions.pageIndex) || (params.pageIndex), | ||
pageSize: (value: number, options: GroupListOptions, params: ClientParams) => (options && options.pageOptions && options.pageOptions.pageSize) || (params.pageSize), | ||
order: (value: string[]) => (value && value.length > 0) ? value : null, | ||
excludedGroups: (value: string[]) => (value && value.length > 0) ? value.join(',') : null, | ||
includeSelf: (value: boolean) => (!!value) ? value : null, | ||
}; | ||
@@ -17,2 +26,3 @@ | ||
excludedGroups: (value: string[]) => (value && value.length > 0) ? value.join(',') : null, | ||
includeInherited: (value: boolean) => (!!value) ? value : null, | ||
}; | ||
@@ -240,2 +250,26 @@ | ||
addChildGroups(groupId: string, childGroupIds: string[]): Promise<void> { | ||
if (!groupId) { | ||
throw new Error('A valid group id needs to be specified.'); | ||
} | ||
if (!childGroupIds || childGroupIds.length === 0) { | ||
throw new Error('At least one valid child group id needs to be specified.'); | ||
} | ||
let url = UrlBuilder.create('/api/security/groups/:groupId/groups', | ||
{}) | ||
.addOptions(groupId, 'groupId') | ||
.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(childGroupIds) | ||
}); | ||
}); | ||
} | ||
removeChildGroup(groupId: string, childGroupId: string): Promise<void> { | ||
@@ -324,7 +358,7 @@ if (!groupId) { | ||
let url = UrlBuilder.create('/api/security/groups/:idOrName/groups', | ||
!options ? {} : { includeInherited: null, excludedGroups: null, q: null, pageIndex: null, pageSize: null, order: null, zenQL: null }) | ||
!options ? {} : { includeSelf: null, includeInherited: null, excludedGroups: null, q: null, pageIndex: null, pageSize: null, order: null, zenQL: null }) | ||
.addOptions(idOrName, 'idOrName') | ||
.addOptions(options) | ||
.setParams(this.contensisClient.getParams()) | ||
.addMappers(listMappers) | ||
.addMappers(childListMappers) | ||
.toUrl(); | ||
@@ -331,0 +365,0 @@ return this.contensisClient.ensureBearerToken().then(() => { |
import * as Contensis from '../../index'; | ||
import { defaultUsers, getDefaultAuthenticateUrl, getDefaultConfig, getDefaultFetchRequest, setDefaultSpy, defaultGroups } from '../../specs-utils.spec'; | ||
import fetch from 'cross-fetch'; | ||
import { PagedList, toQuery } from 'contensis-core-api'; | ||
import { User, Group, UserUpdatePasswordOptions } from '../../models'; | ||
import { PagedList } from 'contensis-core-api'; | ||
@@ -204,2 +204,281 @@ const Zengenti = { Contensis }; | ||
describe('Search users', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, { | ||
pageIndex: 0, | ||
pageSize: 25, | ||
totalCount: 2, | ||
items: defaultUsers | ||
} as PagedList<Partial<User>>); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
}); | ||
it('with query as Object', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let orderBy = [{ | ||
desc: 'optOutOfNotifications' | ||
}, { | ||
asc: 'username' | ||
}]; | ||
let where = [{ | ||
field: 'email', | ||
equalTo: 'EEEEEE2@test.com' | ||
}, { | ||
field: 'username', | ||
in: ['UUUUUU1', 'UUUUUU2'] | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query as any); | ||
let expectedQueryString = toQuery({ | ||
...query, | ||
orderBy: JSON.stringify(orderBy), | ||
where: JSON.stringify(where) | ||
}); | ||
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/search${expectedQueryString}`, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as the default Query instance ', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let query = new Contensis.Query(); | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
pageIndex: 0, | ||
pageSize: 20, | ||
where: JSON.stringify([]) | ||
}); | ||
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/search${expectedQueryString}`, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as a specific Query instance ', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', 'EEEEEE2')); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy: JSON.stringify([{ | ||
asc: 'email' | ||
}]), | ||
where: JSON.stringify([{ | ||
field: 'email', | ||
startsWith: 'EEEEEE2' | ||
}]) | ||
}); | ||
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/search${expectedQueryString}`, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
}); | ||
describe('Search users in IE browser', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, { | ||
pageCount: 1, | ||
pageIndex: 0, | ||
pageSize: 25, | ||
totalCount: 2, | ||
items: defaultUsers | ||
} as PagedList<Partial<User>>); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
(global.document as any).documentMode = 11; | ||
}); | ||
it('with query as Object and url length = 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let orderBy = [{ | ||
asc: 'email' | ||
}]; | ||
// use string with length = 1896 | ||
let where = [{ | ||
field: 'email', | ||
// tslint:disable-next-line:max-line-length | ||
startsWith: 'r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrVhPaZw5pSjD8kZi30i82Zh8VEMmXgEiLFPc8jHJ45wRzpu898NgjKv53bYBHYWqgyEpZF5pg2B1cqq5fLnfarUFKENCaPqxiqhj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SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w' | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query as any); | ||
let expectedQueryString = toQuery({ | ||
...query, | ||
orderBy: JSON.stringify(orderBy), | ||
where: JSON.stringify(where) | ||
}); | ||
let url = `http://my-website.com/api/security/users/search${expectedQueryString}`; | ||
expect(url.length).toEqual(2083); | ||
expect((global.fetch as any).calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect((global.fetch as any).calls.mostRecent().args).toEqual([ | ||
url, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as Object and url length > 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let orderBy = [{ | ||
asc: 'email' | ||
}]; | ||
// use string with length = 1897 | ||
let where = [{ | ||
field: 'email', | ||
// tslint:disable-next-line:max-line-length | ||
startsWith: '1r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4ze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0D8zmU9jH7N1RNJ9nMEeSStafMV01W7aqABTXzz0eKkTUJuCX9UNTLuV2gAHnPkT3MGSjGC9UaJe5qbGUdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w' | ||
}]; | ||
let query = { | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy, | ||
where | ||
}; | ||
let users = await client.security.users.search(query as any); | ||
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/search`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify(query)) | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as Query instance and url length = 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
// use string with length = 1896 | ||
// tslint:disable-next-line:max-line-length | ||
const startsWithText = 'r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH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xEf61TzGab7WcEE7fU9V7rq1M6uqLiZC1KaPr8jM08DYMhjrmaJT6S9ZxfuqUdh6rjJJr5NvxZikhr9XXAKeL7RhgQjq12ZCDMjpDaPmKMufEVt9UTZcve6P7v1q6XYT7qJkpbYBfhn6vSh4XJBjuXDk4SkNu4cxC8F0D8zmU9jH7N1RNJ9nMEeSStafMV01W7aqABTXzz0eKkTUJuCX9UNTLuV2gAHnPkT3MGSjGC9UaJe5qbGUdcXqDjc6UgA9xCq2MUHRP2CQuxHTRHdKur2uyNi9M7Q2gULbVryeW3R38XRvekMSnHYSqSdDrx0dQRTZ4edMuA2t58LdA8kf6LxZrhdjH2FkGcXhAa8ZP4wjGe1ujPrPtnmK8TMmRr4AELcmLkb0AfX3QUNfv1DR2kqyT8Ja2WmGQHR35huMgek3ePB4NMCY6kZH09wfiSLxy68Pyir0huGVYHb4HdhMEEf89SmNaFHuFYgiTGRZexDfTSiaj4Rn04TR359AkNVibyT2E93ee8PN2Qv0vbBTG1nebXyuX7KRYQqBaSrchJFrc0jCGHgCR7mfMAgpPyCEd0Piyg3P3fCQFP0Uq7ADFAfEDgHa9SXHJmhJVwwYC7EUGBqHpFuQZiJAKFdZSUtNFEGDztmjEBwadeVT6vuZW3QUnpYUL4q9t7nQgYqf03jfnh90pzBTFqLTaebr8QkMxGSpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w'; | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', startsWithText)); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
let expectedQueryString = toQuery({ | ||
pageIndex: 1, | ||
pageSize: 50, | ||
orderBy: JSON.stringify([{ | ||
asc: 'email' | ||
}]), | ||
where: JSON.stringify([{ | ||
field: 'email', | ||
startsWith: startsWithText | ||
}]) | ||
}); | ||
let url = `http://my-website.com/api/security/users/search${expectedQueryString}`; | ||
expect(url.length).toEqual(2083); | ||
expect((global.fetch as any).calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect((global.fetch as any).calls.mostRecent().args).toEqual([ | ||
url, | ||
getDefaultFetchRequest() | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
it('with query as Query instance and url length > 2083', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
// use string with length = 1897 | ||
// tslint:disable-next-line:max-line-length | ||
const startsWithText = '1r2PxHazYJ4WFg6tgJwvNyW03bYFkE6xvnpzJyQHdjXEn4H3rAX0HY08iTHa5mqH7zzjH56xC1j62WYKG759S6YZyP158S4Z3ZqtkTf1KwTKAJEKur45qpXZ7rtt5RTXEkt0waDQy96dLFZjYdQYR9rNRurHtWyahtMgQW9vE3aVwKrHTYM0X817uYpTyCZmq4nr8k5ACijrS9FrSNcNVUgFdVaeEuFHaB6tKGQ1Jew4zeMaeZrqbF4v11GaA754ykEDWN8GbY3qhf5RuVaPktFYNJK6PeZkkmxEAVk7DQ2x7W62Y4n3GUmZbi6nwKXrLUrfGHeqR2h2b79A12CzpFHWxhnZ8hm3jRP0AP5085Sh2VtLGbCFMcVEC1bVrr5gFN26LPyTn1gvv6BJ1jUNfZ8JJGV0QA63VQJiqLLigvpYQJU1FJzFhj7rFBREaFCrVhPaZw5pSjD8kZi30i82Zh8VEMmXgEiLFPc8jHJ45wRzpu898NgjKv53bYBHYWqgyEpZF5pg2B1cqq5fLnfarUFKENCaPqxiqhjhMJ1SHC0e8kfLM4zR0TdkC6r7G9Dp4WLc3v0wcveapUjtzL3LEWFYJZpHix9RNCBd7AWzY0PDXih9DMc59frTe7U7GEqXzd36LrYVR8Auv5vwiXzu4fdwihCbeiinHnWnZwtQTJHYKZHLDdD9zMj1CAyEbNTm327NfuDZMQGEYjU8JB0yjhND05MNraL9FXx29iNVTht3j4PxMb3CMQqcBwH22UejpUzxE0mcbKEPvTPVEu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SpHezJnevrBu8SKteUG5vjPEC0kdQKDnXn563AdxdD0w'; | ||
let query = new Contensis.Query(Contensis.Op.startsWith('email', startsWithText)); | ||
query.orderBy = Contensis.OrderBy.asc('email'); | ||
query.pageIndex = 1; | ||
query.pageSize = 50; | ||
let users = await client.security.users.search(query); | ||
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/search`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify(query)) | ||
]); | ||
expect(users).not.toBeNull(); | ||
expect(users.items.length).toEqual(2); | ||
expect(users.items[1].username).toEqual(defaultUsers[1].username); | ||
}); | ||
}); | ||
describe('Create user', () => { | ||
@@ -592,2 +871,19 @@ beforeEach(() => { | ||
it('setPasswordToExpirable', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
let result = await client.security.users.setPasswordToExpirable(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`, | ||
getDefaultFetchRequest('POST', false, JSON.stringify({ type: 'setPasswordToExpirable' })) | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
it('suspend', async () => { | ||
@@ -594,0 +890,0 @@ let client = Zengenti.Contensis.Client.create(getDefaultConfig()); |
import { ContensisClient, IUserOperations, User, UserListOptions, Group, UserGroupsOptions, UserUpdatePasswordOptions, UserToCreate } from '../../models'; | ||
import { ClientParams, IHttpClient, MapperFn, PagedList, UrlBuilder } from 'contensis-core-api'; | ||
import { ClientParams, IHttpClient, isBrowser, isIE, ManagementQuery, MapperFn, PagedList, UrlBuilder } from 'contensis-core-api'; | ||
@@ -11,3 +11,3 @@ let listMappers: { [key: string]: MapperFn } = { | ||
type UserActionType = 'suspend' | 'unlock' | 'unsuspend'; | ||
type UserActionType = 'suspend' | 'unlock' | 'unsuspend' | 'setPasswordToExpirable'; | ||
@@ -65,2 +65,10 @@ export class UserOperations implements IUserOperations { | ||
search(query: ManagementQuery): Promise<PagedList<User>> { | ||
if (!query) { | ||
return new Promise((resolve) => { resolve(null); }); | ||
} | ||
return this.searchUsingManagementQuery(query); | ||
} | ||
getUserGroups(userIdOrOptions: string | UserGroupsOptions): Promise<PagedList<Group>> { | ||
@@ -196,2 +204,6 @@ let url = UrlBuilder.create('/api/security/users/:userId/groups', | ||
setPasswordToExpirable(userId: string): Promise<void> { | ||
return this.performUserAction(userId, 'setPasswordToExpirable'); | ||
} | ||
suspendUser(userId: string): Promise<void> { | ||
@@ -241,2 +253,53 @@ return this.performUserAction(userId, 'suspend'); | ||
} | ||
private searchUsingManagementQuery(query: ManagementQuery): Promise<PagedList<User>> { | ||
let params = this.contensisClient.getParams(); | ||
let pageSize = query.pageSize || params.pageSize; | ||
let pageIndex = query.pageIndex || 0; | ||
let orderBy = (query.orderBy && ((query.orderBy as any)._items || query.orderBy)); | ||
let { clientType, clientDetails, projectId, language, responseHandler, rootUrl, versionStatus, ...requestParams } = params; | ||
let payload = { | ||
...requestParams, | ||
pageSize, | ||
pageIndex, | ||
where: JSON.stringify(query.where), | ||
}; | ||
if (query.orderBy && (!Array.isArray(query.orderBy) || (query.orderBy as any).length > 0)) { | ||
payload['orderBy'] = JSON.stringify(orderBy); | ||
} | ||
let url = UrlBuilder.create('/api/security/users/search', { ...payload }) | ||
.setParams(payload as any) | ||
.toUrl(); | ||
let absoluteUrl = (!params.rootUrl || params.rootUrl === '/') ? url : params.rootUrl + url; | ||
if (isBrowser() && isIE() && absoluteUrl.length > 2083) { | ||
return this.searchUsingPost(query); | ||
} | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request<PagedList<User>>(url, { | ||
method: 'GET', | ||
headers: this.contensisClient.getHeaders(), | ||
}); | ||
}); | ||
} | ||
private searchUsingPost(query: any): Promise<PagedList<User>> { | ||
let url = UrlBuilder.create('/api/security/users/search') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request<PagedList<User>>(url, { | ||
method: 'POST', | ||
headers: this.contensisClient.getHeaders(), | ||
body: JSON.stringify(query) | ||
}); | ||
}); | ||
} | ||
} |
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
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
899247
499
18683
179
16
+ Addedcontensis-core-api@1.1.2(transitive)
- Removedcontensis-core-api@1.1.0(transitive)
Updatedcontensis-core-api@^1.1.2