Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
26dd8ac6cd | |||
78720a5e50 | |||
19a4c9ef48 | |||
02a01ca35c | |||
13fdbcebdc | |||
6246a3d915 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/zitadel",
|
"name": "@apiclient.xyz/zitadel",
|
||||||
"version": "1.0.4",
|
"version": "1.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "An unofficial client for interacting with Zitadel API.",
|
"description": "An unofficial client for interacting with Zitadel API.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/zitadel',
|
name: '@apiclient.xyz/zitadel',
|
||||||
version: '1.0.4',
|
version: '1.0.7',
|
||||||
description: 'An unofficial client for interacting with Zitadel API.'
|
description: 'An unofficial client for interacting with Zitadel API.'
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
import { ZitadelProject } from './classes.zitadelproject.js';
|
||||||
import { ZitaldelUser } from './classes.zitadeluser.js';
|
import { ZitaldelUser } from './classes.zitadeluser.js';
|
||||||
import * as plugins from './zitadel.plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
export interface IZitadelContructorOptions {
|
export interface IZitadelContructorOptions {
|
||||||
url: string;
|
url: string;
|
||||||
@ -10,6 +11,7 @@ export class ZitaldelClient {
|
|||||||
private options: IZitadelContructorOptions;
|
private options: IZitadelContructorOptions;
|
||||||
public authClient: plugins.zitadel.AuthServiceClient;
|
public authClient: plugins.zitadel.AuthServiceClient;
|
||||||
public userClient: plugins.zitadel.UserServiceClient;
|
public userClient: plugins.zitadel.UserServiceClient;
|
||||||
|
public managementClient: plugins.zitadel.ManagementServiceClient;
|
||||||
|
|
||||||
constructor(optionsArg: IZitadelContructorOptions) {
|
constructor(optionsArg: IZitadelContructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
@ -22,6 +24,10 @@ export class ZitaldelClient {
|
|||||||
this.options.url,
|
this.options.url,
|
||||||
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
|
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
|
||||||
);
|
);
|
||||||
|
this.managementClient = plugins.zitadel.createManagementClient(
|
||||||
|
this.options.url,
|
||||||
|
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async listOwnUser() {
|
public async listOwnUser() {
|
||||||
@ -34,6 +40,18 @@ export class ZitaldelClient {
|
|||||||
return zitadelUser;
|
return zitadelUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async listProjects() {
|
||||||
|
const returnProjects: ZitadelProject[] = [];
|
||||||
|
const response = await this.managementClient.listProjects({});
|
||||||
|
for (const projectObject of response.result) {
|
||||||
|
returnProjects.push(new ZitadelProject(this, {
|
||||||
|
id: projectObject.id,
|
||||||
|
name: projectObject.name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return returnProjects;
|
||||||
|
}
|
||||||
|
|
||||||
public async listUsers() {
|
public async listUsers() {
|
||||||
const response = await this.userClient.listUsers({});
|
const response = await this.userClient.listUsers({});
|
||||||
const returnArray: ZitaldelUser[] = [];
|
const returnArray: ZitaldelUser[] = [];
|
||||||
|
33
ts/classes.zitadelproject.ts
Normal file
33
ts/classes.zitadelproject.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { ZitaldelClient } from './classes.zitadelclient.js';
|
||||||
|
import { ZitadelProjectRole } from './classes.zitadelprojectrole.js';
|
||||||
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
|
export class IZitadelProjectData {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ZitadelProject {
|
||||||
|
ziadelclientRef: ZitaldelClient;
|
||||||
|
public data: IZitadelProjectData;
|
||||||
|
|
||||||
|
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelProjectData) {
|
||||||
|
this.ziadelclientRef = zitadelclientRefArg;
|
||||||
|
this.data = dataArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async listProjectRoles() {
|
||||||
|
const returnRoles: ZitadelProjectRole[] = [];
|
||||||
|
const response = await this.ziadelclientRef.managementClient.listProjectRoles({
|
||||||
|
projectId: this.data.id,
|
||||||
|
});
|
||||||
|
for (const roleObject of response.result) {
|
||||||
|
returnRoles.push(new ZitadelProjectRole(this.ziadelclientRef, {
|
||||||
|
project: this,
|
||||||
|
name: roleObject.displayName,
|
||||||
|
key: roleObject.key,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return returnRoles;
|
||||||
|
}
|
||||||
|
}
|
19
ts/classes.zitadelprojectrole.ts
Normal file
19
ts/classes.zitadelprojectrole.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import type { ZitaldelClient } from './classes.zitadelclient.js';
|
||||||
|
import type { ZitadelProject } from './classes.zitadelproject.js';
|
||||||
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
|
export interface IZitadelProjectRoleData {
|
||||||
|
project: ZitadelProject;
|
||||||
|
key: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ZitadelProjectRole {
|
||||||
|
ziadelclientRef: ZitaldelClient;
|
||||||
|
public data: IZitadelProjectRoleData;
|
||||||
|
|
||||||
|
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelProjectRoleData) {
|
||||||
|
this.ziadelclientRef = zitadelclientRefArg;
|
||||||
|
this.data = dataArg;
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,67 @@
|
|||||||
import type { ZitaldelClient } from './classes.zitadelclient.js';
|
import type { ZitaldelClient } from './classes.zitadelclient.js';
|
||||||
import * as plugins from './zitadel.plugins.js';
|
import type { ZitadelProjectRole } from './classes.zitadelprojectrole.js';
|
||||||
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
export interface IZitadelUserData {
|
export interface IZitadelUserData {
|
||||||
id: string;
|
id: string;
|
||||||
lastLogin: Date;
|
lastLogin: Date;
|
||||||
username: string;
|
username: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
export class ZitaldelUser {
|
export class ZitaldelUser {
|
||||||
|
// INSTANCE
|
||||||
zitadelclientRef: ZitaldelClient;
|
zitadelclientRef: ZitaldelClient;
|
||||||
|
data: IZitadelUserData;
|
||||||
|
|
||||||
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
|
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
|
||||||
this.zitadelclientRef = zitadelclientRefArg;
|
this.zitadelclientRef = zitadelclientRefArg;
|
||||||
this.data = dataArg;
|
this.data = dataArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
public async addRole(projectRole: ZitadelProjectRole) {
|
||||||
data: IZitadelUserData;
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user