From 602196197a1bf8a20b13db6556154dd907a2d047 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Thu, 2 May 2024 14:07:42 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 14 ++++++++++++-- ts/00_commitinfo_data.ts | 2 +- ts/classes.zitadelclient.ts | 33 ++++++++++++++++++++++++++------- ts/classes.zitadeluser.ts | 21 ++++++++++++--------- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/test/test.ts b/test/test.ts index 36ae438..5fda5d5 100644 --- a/test/test.ts +++ b/test/test.ts @@ -16,13 +16,23 @@ tap.test('first test', async () => { }); tap.test('should list own user', async () => { - await testZitadel.listOwnUser(); + const user = await testZitadel.listOwnUser(); + console.log(user); }) tap.test('should list users', async () => { const users = await testZitadel.listUsers(); expect(users).toBeArray(); expect(users[0]).toBeInstanceOf(zitadel.ZitaldelUser); + console.log(users); }) -tap.start() +tap.test('should invite user', async () => { + await testZitadel.createUser({ + email: await testQenv.getEnvVarOnDemand('ZITADEL_TEST_EMAIL'), + firstName: 'firstname', + lastName: 'lastname', + }) +}) + +export default tap.start() diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 50a902b..f67d86a 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@apiclient.xyz/zitadel', - version: '1.0.2', + version: '1.0.3', description: 'an unofficial zitadel client' } diff --git a/ts/classes.zitadelclient.ts b/ts/classes.zitadelclient.ts index 2e271b3..0f3bedd 100644 --- a/ts/classes.zitadelclient.ts +++ b/ts/classes.zitadelclient.ts @@ -26,22 +26,41 @@ export class ZitaldelClient { public async listOwnUser() { const response = await this.authClient.getMyUser({}); - console.log(response.user) + const zitadelUser = new ZitaldelUser(this, { + id: response.user.id, + lastLogin: response.lastLogin, + username: response.user.userName, + }); + return zitadelUser; } public async listUsers() { const response = await this.userClient.listUsers({}); const returnArray: ZitaldelUser[] = []; for (const userObject of response.result) { - returnArray.push(await ZitaldelUser.fromApiUserObject(userObject)); + returnArray.push(new ZitaldelUser(this, { + id: userObject.userId, + username: userObject.username, + lastLogin: null, + })); } return returnArray; } - /** - * invites a new user by email - */ - public async inviteNewUserByEmail() { - + public async createUser(optionsArg: { + email: string; + firstName: string; + lastName: string; + }) { + const response = await this.userClient.addHumanUser({ + email: { + email: optionsArg.email, + }, + profile: { + givenName: optionsArg.firstName, + familyName: optionsArg.lastName, + } + }); + console.log(response); } } diff --git a/ts/classes.zitadeluser.ts b/ts/classes.zitadeluser.ts index aa9068e..5b937eb 100644 --- a/ts/classes.zitadeluser.ts +++ b/ts/classes.zitadeluser.ts @@ -1,17 +1,20 @@ +import type { ZitaldelClient } from './classes.zitadelclient.js'; import * as plugins from './zitadel.plugins.js'; -export type IZitadelApiUserObject = plugins.tsclass.typeFest.AsyncReturnType< - plugins.zitadel.UserServiceClient['listUsers'] ->['result'][0]; +export interface IZitadelUserData { + id: string; + lastLogin: Date; + username: string; +}; export class ZitaldelUser { - // STATIC - static async fromApiUserObject(apiUserObject: IZitadelApiUserObject) { - const newUser = new ZitaldelUser(); - newUser.data = apiUserObject; - return newUser; + zitadelclientRef: ZitaldelClient; + + constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) { + this.zitadelclientRef = zitadelclientRefArg; + this.data = dataArg; } // INSTANCE - data: IZitadelApiUserObject; + data: IZitadelUserData; }