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 () => {
|
tap.test('should list own user', async () => {
|
||||||
await testZitadel.listOwnUser();
|
const user = await testZitadel.listOwnUser();
|
||||||
|
console.log(user);
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.test('should list users', async () => {
|
tap.test('should list users', async () => {
|
||||||
const users = await testZitadel.listUsers();
|
const users = await testZitadel.listUsers();
|
||||||
expect(users).toBeArray();
|
expect(users).toBeArray();
|
||||||
expect(users[0]).toBeInstanceOf(zitadel.ZitaldelUser);
|
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 = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/zitadel',
|
name: '@apiclient.xyz/zitadel',
|
||||||
version: '1.0.2',
|
version: '1.0.3',
|
||||||
description: 'an unofficial zitadel client'
|
description: 'an unofficial zitadel client'
|
||||||
}
|
}
|
||||||
|
@ -26,22 +26,41 @@ export class ZitaldelClient {
|
|||||||
|
|
||||||
public async listOwnUser() {
|
public async listOwnUser() {
|
||||||
const response = await this.authClient.getMyUser({});
|
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() {
|
public async listUsers() {
|
||||||
const response = await this.userClient.listUsers({});
|
const response = await this.userClient.listUsers({});
|
||||||
const returnArray: ZitaldelUser[] = [];
|
const returnArray: ZitaldelUser[] = [];
|
||||||
for (const userObject of response.result) {
|
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;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async createUser(optionsArg: {
|
||||||
* invites a new user by email
|
email: string;
|
||||||
*/
|
firstName: string;
|
||||||
public async inviteNewUserByEmail() {
|
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';
|
import * as plugins from './zitadel.plugins.js';
|
||||||
|
|
||||||
export type IZitadelApiUserObject = plugins.tsclass.typeFest.AsyncReturnType<
|
export interface IZitadelUserData {
|
||||||
plugins.zitadel.UserServiceClient['listUsers']
|
id: string;
|
||||||
>['result'][0];
|
lastLogin: Date;
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
|
||||||
export class ZitaldelUser {
|
export class ZitaldelUser {
|
||||||
// STATIC
|
zitadelclientRef: ZitaldelClient;
|
||||||
static async fromApiUserObject(apiUserObject: IZitadelApiUserObject) {
|
|
||||||
const newUser = new ZitaldelUser();
|
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
|
||||||
newUser.data = apiUserObject;
|
this.zitadelclientRef = zitadelclientRefArg;
|
||||||
return newUser;
|
this.data = dataArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
data: IZitadelApiUserObject;
|
data: IZitadelUserData;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user