From 02a01ca35c647f7ae247c4a65f396509f27adaf9 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 3 May 2024 10:39:24 +0200 Subject: [PATCH] fix(core): update --- ts/00_commitinfo_data.ts | 2 +- ts/classes.zitadeluser.ts | 42 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 4a2ed0d..a5eebb8 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.5', + version: '1.0.6', description: 'An unofficial client for interacting with Zitadel API.' } diff --git a/ts/classes.zitadeluser.ts b/ts/classes.zitadeluser.ts index b821da2..bbacdd7 100644 --- a/ts/classes.zitadeluser.ts +++ b/ts/classes.zitadeluser.ts @@ -6,7 +6,7 @@ export interface IZitadelUserData { id: string; lastLogin: Date; username: string; -}; +} export class ZitaldelUser { // INSTANCE @@ -19,11 +19,49 @@ export class ZitaldelUser { } public async addRole(projectRole: ZitadelProjectRole) { - this.zitadelclientRef.managementClient.addUserGrant({ + const response = await this.zitadelclientRef.managementClient.addUserGrant({ userId: this.data.id, roleKeys: [projectRole.data.key], projectId: projectRole.data.project.data.id, }); } + /** + * change email address of user, + * optionally supply own url for email verification + * @param emailAddress + * @param verificationUrl + */ + public async changeEmail(optionsArg: { emailAddress: string; verificationUrl?: string }) { + const response = await this.zitadelclientRef.userClient.setEmail({ + userId: this.data.id, + email: optionsArg.emailAddress, + ...(optionsArg.verificationUrl + ? { + sendCode: { + urlTemplate: optionsArg.verificationUrl, + }, + } + : {}), + }); + } + + public async setPassword(optionsArg: { password: string; changeRequired?: boolean }) { + const response = await this.zitadelclientRef.userClient.setPassword({ + userId: this.data.id, + newPassword: { + password: optionsArg.password, + ...(optionsArg.changeRequired ? { changeRequired: optionsArg.changeRequired } : {}), + }, + }); + } + + /** + * triggers a password reset action for the user + */ + public async resetPassword() { + const response = await this.zitadelclientRef.userClient.passwordReset({ + userId: this.data.id, + }); + } }