fix(core): update
This commit is contained in:
parent
13e67d9012
commit
6246a3d915
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/zitadel',
|
name: '@apiclient.xyz/zitadel',
|
||||||
version: '1.0.4',
|
version: '1.0.5',
|
||||||
description: 'An unofficial client for interacting with Zitadel API.'
|
description: 'An unofficial client for interacting with Zitadel API.'
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
import { ZitadelProject } from './classes.zitadelproject.js';
|
||||||
import { ZitaldelUser } from './classes.zitadeluser.js';
|
import { ZitaldelUser } from './classes.zitadeluser.js';
|
||||||
import * as plugins from './zitadel.plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
export interface IZitadelContructorOptions {
|
export interface IZitadelContructorOptions {
|
||||||
url: string;
|
url: string;
|
||||||
@ -10,6 +11,7 @@ export class ZitaldelClient {
|
|||||||
private options: IZitadelContructorOptions;
|
private options: IZitadelContructorOptions;
|
||||||
public authClient: plugins.zitadel.AuthServiceClient;
|
public authClient: plugins.zitadel.AuthServiceClient;
|
||||||
public userClient: plugins.zitadel.UserServiceClient;
|
public userClient: plugins.zitadel.UserServiceClient;
|
||||||
|
public managementClient: plugins.zitadel.ManagementServiceClient;
|
||||||
|
|
||||||
constructor(optionsArg: IZitadelContructorOptions) {
|
constructor(optionsArg: IZitadelContructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
@ -22,6 +24,10 @@ export class ZitaldelClient {
|
|||||||
this.options.url,
|
this.options.url,
|
||||||
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
|
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
|
||||||
);
|
);
|
||||||
|
this.managementClient = plugins.zitadel.createManagementClient(
|
||||||
|
this.options.url,
|
||||||
|
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async listOwnUser() {
|
public async listOwnUser() {
|
||||||
@ -34,6 +40,18 @@ export class ZitaldelClient {
|
|||||||
return zitadelUser;
|
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() {
|
public async listUsers() {
|
||||||
const response = await this.userClient.listUsers({});
|
const response = await this.userClient.listUsers({});
|
||||||
const returnArray: ZitaldelUser[] = [];
|
const returnArray: ZitaldelUser[] = [];
|
||||||
|
33
ts/classes.zitadelproject.ts
Normal file
33
ts/classes.zitadelproject.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
19
ts/classes.zitadelprojectrole.ts
Normal file
19
ts/classes.zitadelprojectrole.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import type { ZitaldelClient } from './classes.zitadelclient.js';
|
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 {
|
export interface IZitadelUserData {
|
||||||
id: string;
|
id: string;
|
||||||
@ -8,13 +9,21 @@ export interface IZitadelUserData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class ZitaldelUser {
|
export class ZitaldelUser {
|
||||||
|
// INSTANCE
|
||||||
zitadelclientRef: ZitaldelClient;
|
zitadelclientRef: ZitaldelClient;
|
||||||
|
data: IZitadelUserData;
|
||||||
|
|
||||||
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
|
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
|
||||||
this.zitadelclientRef = zitadelclientRefArg;
|
this.zitadelclientRef = zitadelclientRefArg;
|
||||||
this.data = dataArg;
|
this.data = dataArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
public async addRole(projectRole: ZitadelProjectRole) {
|
||||||
data: IZitadelUserData;
|
this.zitadelclientRef.managementClient.addUserGrant({
|
||||||
|
userId: this.data.id,
|
||||||
|
roleKeys: [projectRole.data.key],
|
||||||
|
projectId: projectRole.data.project.data.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user