fix(core): update
This commit is contained in:
parent
c91d056367
commit
602196197a
14
test/test.ts
14
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()
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/zitadel',
|
||||
version: '1.0.2',
|
||||
version: '1.0.3',
|
||||
description: 'an unofficial zitadel client'
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user