fix(core): update

This commit is contained in:
Philipp Kunz 2024-05-02 17:43:31 +02:00
parent 13e67d9012
commit 6246a3d915
6 changed files with 84 additions and 5 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/zitadel',
version: '1.0.4',
version: '1.0.5',
description: 'An unofficial client for interacting with Zitadel API.'
}

View File

@ -1,5 +1,6 @@
import { ZitadelProject } from './classes.zitadelproject.js';
import { ZitaldelUser } from './classes.zitadeluser.js';
import * as plugins from './zitadel.plugins.js';
import * as plugins from './plugins.js';
export interface IZitadelContructorOptions {
url: string;
@ -10,6 +11,7 @@ export class ZitaldelClient {
private options: IZitadelContructorOptions;
public authClient: plugins.zitadel.AuthServiceClient;
public userClient: plugins.zitadel.UserServiceClient;
public managementClient: plugins.zitadel.ManagementServiceClient;
constructor(optionsArg: IZitadelContructorOptions) {
this.options = optionsArg;
@ -22,6 +24,10 @@ export class ZitaldelClient {
this.options.url,
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
);
this.managementClient = plugins.zitadel.createManagementClient(
this.options.url,
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
);
}
public async listOwnUser() {
@ -34,6 +40,18 @@ export class ZitaldelClient {
return zitadelUser;
}
public async listProjects() {
const returnProjects: ZitadelProject[] = [];
const response = await this.managementClient.listProjects({});
for (const projectObject of response.result) {
returnProjects.push(new ZitadelProject(this, {
id: projectObject.id,
name: projectObject.name,
}));
}
return returnProjects;
}
public async listUsers() {
const response = await this.userClient.listUsers({});
const returnArray: ZitaldelUser[] = [];

View File

@ -0,0 +1,33 @@
import type { ZitaldelClient } from './classes.zitadelclient.js';
import { ZitadelProjectRole } from './classes.zitadelprojectrole.js';
import * as plugins from './plugins.js';
export class IZitadelProjectData {
id: string;
name: string;
}
export class ZitadelProject {
ziadelclientRef: ZitaldelClient;
public data: IZitadelProjectData;
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelProjectData) {
this.ziadelclientRef = zitadelclientRefArg;
this.data = dataArg;
}
public async listProjectRoles() {
const returnRoles: ZitadelProjectRole[] = [];
const response = await this.ziadelclientRef.managementClient.listProjectRoles({
projectId: this.data.id,
});
for (const roleObject of response.result) {
returnRoles.push(new ZitadelProjectRole(this.ziadelclientRef, {
project: this,
name: roleObject.displayName,
key: roleObject.key,
}));
}
return returnRoles;
}
}

View File

@ -0,0 +1,19 @@
import type { ZitaldelClient } from './classes.zitadelclient.js';
import type { ZitadelProject } from './classes.zitadelproject.js';
import * as plugins from './plugins.js';
export interface IZitadelProjectRoleData {
project: ZitadelProject;
key: string;
name: string;
}
export class ZitadelProjectRole {
ziadelclientRef: ZitaldelClient;
public data: IZitadelProjectRoleData;
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelProjectRoleData) {
this.ziadelclientRef = zitadelclientRefArg;
this.data = dataArg;
}
}

View File

@ -1,5 +1,6 @@
import type { ZitaldelClient } from './classes.zitadelclient.js';
import * as plugins from './zitadel.plugins.js';
import type { ZitadelProjectRole } from './classes.zitadelprojectrole.js';
import * as plugins from './plugins.js';
export interface IZitadelUserData {
id: string;
@ -8,13 +9,21 @@ export interface IZitadelUserData {
};
export class ZitaldelUser {
// INSTANCE
zitadelclientRef: ZitaldelClient;
data: IZitadelUserData;
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
this.zitadelclientRef = zitadelclientRefArg;
this.data = dataArg;
}
// INSTANCE
data: IZitadelUserData;
public async addRole(projectRole: ZitadelProjectRole) {
this.zitadelclientRef.managementClient.addUserGrant({
userId: this.data.id,
roleKeys: [projectRole.data.key],
projectId: projectRole.data.project.data.id,
});
}
}