From c5637547f4c6e7f10f9c76dc3723dd7c0253014f Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 5 Mar 2021 11:52:15 +0100 Subject: [PATCH] Fixing some typing issues (#142) * fixes: #40 * fixes: #133 * fixing: #127 --- package.json | 2 +- src/resources/clients.ts | 19 ++++++++++++++----- src/resources/roles.ts | 2 +- src/utils/auth.ts | 4 ++-- test/groupUser.spec.ts | 5 ++++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 813dff09..ee209624 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@keycloak/keycloak-admin-client", - "version": "1.14.7", + "version": "1.14.9", "description": "keycloak admin client", "main": "lib/index.js", "files": [ diff --git a/src/resources/clients.ts b/src/resources/clients.ts index 58c27072..202b450f 100644 --- a/src/resources/clients.ts +++ b/src/resources/clients.ts @@ -21,7 +21,16 @@ export interface ClientQuery { } export interface PolicyQuery { - name: string; + id?: string; + name?: string; + type?: string; + resource?: string; + scope?: string; + permission?: string; + owner?: string; + fields?: string; + first?: number; + max?: number; } export class Clients extends Resource<{realm?: string}> { @@ -501,7 +510,7 @@ export class Clients extends Resource<{realm?: string}> { * Policy */ public listPolicies = this.makeRequest< - {id: string, name: string}, + PolicyQuery, PolicyRepresentation[] >({ method: 'GET', @@ -509,7 +518,7 @@ export class Clients extends Resource<{realm?: string}> { urlParamKeys: ['id'], }); - public findByName = this.makeRequest< + public findPolicyByName = this.makeRequest< {id: string; name: string}, PolicyRepresentation >({ @@ -559,7 +568,7 @@ export class Clients extends Resource<{realm?: string}> { policyName: string; policy: PolicyRepresentation; }): Promise { - const policyFound = await this.findByName({ + const policyFound = await this.findPolicyByName({ id: payload.id, name: payload.policyName, }); @@ -568,7 +577,7 @@ export class Clients extends Resource<{realm?: string}> { {id: payload.id, policyId: policyFound.id, type: payload.policy.type}, payload.policy, ); - return this.findByName({id: payload.id, name: payload.policyName}); + return this.findPolicyByName({id: payload.id, name: payload.policyName}); } else { return this.createPolicy( {id: payload.id, type: payload.policy.type}, diff --git a/src/resources/roles.ts b/src/resources/roles.ts index 1f088ff3..541e9826 100644 --- a/src/resources/roles.ts +++ b/src/resources/roles.ts @@ -47,7 +47,7 @@ export class Roles extends Resource<{realm?: string}> { }); public findUsersWithRole = this.makeRequest< - {name: string}, + {name: string; first?: number; max?: number}, UserRepresentation[] >({ method: 'GET', diff --git a/src/utils/auth.ts b/src/utils/auth.ts index e6f6372a..adeb4d5a 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -6,8 +6,8 @@ import {defaultBaseUrl, defaultRealm} from './constants'; export type GrantTypes = 'client_credentials' | 'password'; export interface Credentials { - username: string; - password: string; + username?: string; + password?: string; grantType: GrantTypes; clientId: string; clientSecret?: string; diff --git a/test/groupUser.spec.ts b/test/groupUser.spec.ts index d8e24057..6f98dbf5 100644 --- a/test/groupUser.spec.ts +++ b/test/groupUser.spec.ts @@ -138,12 +138,15 @@ describe('Group user integration', () => { resourceName: permissions.resource, }); + const policies = await kcAdminClient.clients.listPolicies({id: managementClient.id, resource: permissions.resource, max: 2}); + expect(policies).to.have.length(2); + expect(scopes).to.have.length(5); // Search for the id of the management role const roleId = scopes.find(scope => scope.name === 'manage').id; - const userPolicy = await kcAdminClient.clients.findByName({id: managementClient.id, name: `policy.manager.${currentGroup.id}`}); + const userPolicy = await kcAdminClient.clients.findPolicyByName({id: managementClient.id, name: `policy.manager.${currentGroup.id}`}); expect(userPolicy).to.deep.include({ name: `policy.manager.${currentGroup.id}`,