zitadel/ts/classes.zitadelclient.ts

48 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-05-02 10:52:21 +00:00
import { ZitaldelUser } from './classes.zitadeluser.js';
import * as plugins from './zitadel.plugins.js';
export interface IZitadelContructorOptions {
url: string;
accessToken: string;
}
export class ZitaldelClient {
private options: IZitadelContructorOptions;
public authClient: plugins.zitadel.AuthServiceClient;
public userClient: plugins.zitadel.UserServiceClient;
constructor(optionsArg: IZitadelContructorOptions) {
this.options = optionsArg;
console.log(this.options);
this.authClient = plugins.zitadel.createAuthClient(
this.options.url,
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
);
this.userClient = plugins.zitadel.createUserClient(
this.options.url,
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
);
}
public async listOwnUser() {
const response = await this.authClient.getMyUser({});
console.log(response.user)
}
public async listUsers() {
const response = await this.userClient.listUsers({});
const returnArray: ZitaldelUser[] = [];
for (const userObject of response.result) {
returnArray.push(await ZitaldelUser.fromApiUserObject(userObject));
}
return returnArray;
}
/**
* invites a new user by email
*/
public async inviteNewUserByEmail() {
}
}