Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
756e5eac36 | |||
6ab9ab2c59 | |||
66a4bf6142 | |||
d71197c6f7 | |||
fd07270149 | |||
d7444aa901 | |||
26dd8ac6cd | |||
78720a5e50 | |||
19a4c9ef48 | |||
02a01ca35c | |||
13fdbcebdc | |||
6246a3d915 | |||
13e67d9012 | |||
62714c0166 | |||
5f54bd07d7 | |||
602196197a |
24
changelog.md
Normal file
24
changelog.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-08-27 - 1.1.0 - feat(core)
|
||||||
|
Add delete user functionality and necessary tests
|
||||||
|
|
||||||
|
- Implemented delete method in ZitadelUser class.
|
||||||
|
- Extended tests to cover user deletion functionality.
|
||||||
|
- Refactored createUser method to return a ZitadelUser instance.
|
||||||
|
|
||||||
|
## 2024-08-26 - 1.0.9 - fix(dependencies)
|
||||||
|
Update dependencies to latest versions
|
||||||
|
|
||||||
|
- Updated @git.zone/tsbuild from ^2.1.25 to ^2.1.84
|
||||||
|
- Updated @git.zone/tsrun from ^1.2.46 to ^1.2.49
|
||||||
|
- Updated @push.rocks/tapbundle from ^5.0.15 to ^5.0.24
|
||||||
|
- Updated @types/node from ^20.8.7 to ^22.5.0
|
||||||
|
- Updated @tsclass/tsclass from ^4.0.54 to ^4.1.2
|
||||||
|
- Updated @zitadel/node from ^2.0.8 to 2.0.17
|
||||||
|
|
||||||
|
## 2024-05-02 to 2024-05-03 - 1.0.1 to 1.0.8 - Fixes and Updates
|
||||||
|
General updates and fixes to the core functionality across multiple versions.
|
||||||
|
|
||||||
|
- Various fixes in core functionality
|
||||||
|
- Incremental improvements and updates
|
@ -5,10 +5,22 @@
|
|||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "apiclient.xyz",
|
"gitscope": "apiclient.xyz",
|
||||||
"gitrepo": "zitadel",
|
"gitrepo": "zitadel",
|
||||||
"description": "an unofficial zitadel client",
|
"description": "An unofficial client for interacting with Zitadel API, enabling user and project management functionalities.",
|
||||||
"npmPackagename": "@apiclient.xyz/zitadel",
|
"npmPackagename": "@apiclient.xyz/zitadel",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "apiclient.xyz"
|
"projectDomain": "apiclient.xyz",
|
||||||
|
"keywords": [
|
||||||
|
"Zitadel",
|
||||||
|
"API client",
|
||||||
|
"TypeScript",
|
||||||
|
"authentication",
|
||||||
|
"user management",
|
||||||
|
"project management",
|
||||||
|
"unofficial client",
|
||||||
|
"node.js",
|
||||||
|
"access control",
|
||||||
|
"software development"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
|
28
package.json
28
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/zitadel",
|
"name": "@apiclient.xyz/zitadel",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial zitadel client",
|
"description": "An unofficial client for interacting with Zitadel API, enabling user and project management functionalities.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -14,17 +14,17 @@
|
|||||||
"buildDocs": "(tsdoc)"
|
"buildDocs": "(tsdoc)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.25",
|
"@git.zone/tsbuild": "^2.1.84",
|
||||||
"@git.zone/tsbundle": "^2.0.5",
|
"@git.zone/tsbundle": "^2.0.5",
|
||||||
"@git.zone/tsrun": "^1.2.46",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"@git.zone/tstest": "^1.0.44",
|
"@git.zone/tstest": "^1.0.44",
|
||||||
"@push.rocks/qenv": "^6.0.5",
|
"@push.rocks/qenv": "^6.0.5",
|
||||||
"@push.rocks/tapbundle": "^5.0.15",
|
"@push.rocks/tapbundle": "^5.0.24",
|
||||||
"@types/node": "^20.8.7"
|
"@types/node": "^22.5.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tsclass/tsclass": "^4.0.54",
|
"@tsclass/tsclass": "^4.1.2",
|
||||||
"@zitadel/node": "^2.0.8"
|
"@zitadel/node": "2.0.17"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -48,5 +48,17 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"Zitadel",
|
||||||
|
"API client",
|
||||||
|
"TypeScript",
|
||||||
|
"authentication",
|
||||||
|
"user management",
|
||||||
|
"project management",
|
||||||
|
"unofficial client",
|
||||||
|
"node.js",
|
||||||
|
"access control",
|
||||||
|
"software development"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
6518
pnpm-lock.yaml
generated
6518
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
0
readme.hints.md
Normal file
0
readme.hints.md
Normal file
135
readme.md
135
readme.md
@ -1,31 +1,118 @@
|
|||||||
# @apiclient.xyz/zitadel
|
# @apiclient.xyz/zitadel
|
||||||
an unofficial zitadel client
|
|
||||||
|
|
||||||
## Availabililty and Links
|
An unofficial client for interacting with Zitadel API.
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiclient.xyz/zitadel)
|
|
||||||
* [gitlab.com (source)](https://code.foss.global/apiclient.xyz/zitadel)
|
|
||||||
* [github.com (source mirror)](https://github.com/apiclient.xyz/zitadel)
|
|
||||||
* [docs (typedoc)](https://apiclient.xyz.gitlab.io/zitadel/)
|
|
||||||
|
|
||||||
## Status for master
|
## Install
|
||||||
|
|
||||||
Status Category | Status Badge
|
To get started with `@apiclient.xyz/zitadel`, ensure you have Node.js installed on your machine. Then, you can add this package to your project by running:
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
```bash
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
npm install @apiclient.xyz/zitadel --save
|
||||||
npm | [](https://lossless.cloud)
|
```
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
This module is written in TypeScript to take advantage of type safety and autocompletion in IDEs. If you haven't installed TypeScript globally, you can do so by running:
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [](https://lossless.cloud)
|
```bash
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
npm install -g typescript
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
```
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Use TypeScript for best in class intellisense
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
## Legal
|
The `@apiclient.xyz/zitadel` package provides an unofficial TypeScript client for easy interaction with Zitadel's API, allowing for convenient management operations such as user and project management.
|
||||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
### Getting Started
|
||||||
|
|
||||||
|
First, ensure you import the core client class from the package:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { ZitaldelClient } from '@apiclient.xyz/zitadel';
|
||||||
|
```
|
||||||
|
|
||||||
|
Initialize the `ZitaldelClient` with your Zitadel instance URL and access token:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const zitadelClient = new ZitaldelClient({
|
||||||
|
url: 'https://your-zitadel-instance.com', // Replace with your Zitadel instance URL.
|
||||||
|
accessToken: 'your_access_token_here' // Replace with your actual access token.
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### User Management
|
||||||
|
|
||||||
|
The library allows performing user operations such as listing all users, getting info of the current user, and creating new users.
|
||||||
|
|
||||||
|
#### List All Users
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function listUsers() {
|
||||||
|
const users = await zitadelClient.listUsers();
|
||||||
|
console.log(users); // Outputs user list
|
||||||
|
}
|
||||||
|
listUsers();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Current User Information
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function getCurrentUser() {
|
||||||
|
const user = await zitadelClient.listOwnUser();
|
||||||
|
console.log(user); // Outputs current user information.
|
||||||
|
}
|
||||||
|
getCurrentUser();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create a New User
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function createUser() {
|
||||||
|
await zitadelClient.createUser({
|
||||||
|
email: 'newuser@example.com',
|
||||||
|
firstName: 'First',
|
||||||
|
lastName: 'Last'
|
||||||
|
});
|
||||||
|
console.log('User created successfully.');
|
||||||
|
}
|
||||||
|
createUser();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Project Management
|
||||||
|
|
||||||
|
Beyond user management, the client also supports actions on projects—like listing and managing project roles.
|
||||||
|
|
||||||
|
#### List Projects
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function listProjects() {
|
||||||
|
const projects = await zitadelClient.listProjects();
|
||||||
|
console.log(projects); // Outputs list of projects
|
||||||
|
}
|
||||||
|
listProjects();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Project Roles
|
||||||
|
|
||||||
|
Each project comes with roles that can be managed through the client.
|
||||||
|
|
||||||
|
##### Listing Project Roles
|
||||||
|
|
||||||
|
To inspect roles within a project:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function listProjectRoles(projectId: string) {
|
||||||
|
const projectRoles = await someProject.listProjectRoles(); // Assume `someProject` is an instance of `ZitadelProject`.
|
||||||
|
console.log(projectRoles);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: The `ZitadelProject` object would typically be obtained as part of the list from `listProjects`.
|
||||||
|
|
||||||
|
### Advanced Topics
|
||||||
|
|
||||||
|
For more complex scenarios, such as direct interaction with Zitadel's gRPC APIs, or detailed configuration, please refer to the comprehensive [official Zitadel documentation](https://docs.zitadel.ch/). This client offers a simplified abstraction over Zitadel's API functionalities but can be extended or used in conjunction with direct API calls to meet specific needs.
|
||||||
|
|
||||||
|
For instance, the `ZitaldelClient` class can be tweaked to support custom interceptors for logging, authentication flow enhancements, or to integrate with Zitadel's event system for real-time updates on resources.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This is a basic introduction to `@apiclient.xyz/zitadel`. The client simplifies the interaction with Zitadel's API, focusing on core functionalities like user and project management. For specific use cases, detailed configurations, or advanced features, you may need to extend the client or use it as a foundation for more complex interactions with the Zitadel API.
|
||||||
|
undefined
|
23
test/test.ts
23
test/test.ts
@ -16,13 +16,32 @@ 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(JSON.stringify(users, null, 2));
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.start()
|
const createUserTest = tap.test('should invite user', async (toolsArg) => {
|
||||||
|
const user = await testZitadel.createUser({
|
||||||
|
email: await testQenv.getEnvVarOnDemand('ZITADEL_TEST_EMAIL'),
|
||||||
|
firstName: 'firstname',
|
||||||
|
lastName: 'lastname',
|
||||||
|
})
|
||||||
|
await toolsArg.delayFor(5000);
|
||||||
|
return user;
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('should delete user', async () => {
|
||||||
|
const createdUser: zitadel.ZitaldelUser = (await createUserTest.testResultPromise) as any;
|
||||||
|
expect(createdUser).toBeInstanceOf(zitadel.ZitaldelUser);
|
||||||
|
await createdUser.delete();
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
export default tap.start()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/zitadel',
|
name: '@apiclient.xyz/zitadel',
|
||||||
version: '1.0.2',
|
version: '1.1.0',
|
||||||
description: 'an unofficial zitadel client'
|
description: 'An unofficial client for interacting with Zitadel API, enabling user and project management functionalities.'
|
||||||
}
|
}
|
||||||
|
@ -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,26 +24,67 @@ 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() {
|
||||||
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 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[] = [];
|
||||||
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,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// const allUsers = await this.listUsers();
|
||||||
|
// console.log(JSON.stringify(allUsers, null, 2));
|
||||||
|
return new ZitaldelUser(this, {
|
||||||
|
id: response.userId,
|
||||||
|
lastLogin: null,
|
||||||
|
username: optionsArg.email,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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,17 +1,76 @@
|
|||||||
import * as plugins from './zitadel.plugins.js';
|
import type { ZitaldelClient } from './classes.zitadelclient.js';
|
||||||
|
import type { ZitadelProjectRole } from './classes.zitadelprojectrole.js';
|
||||||
|
import * as plugins from './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
|
// INSTANCE
|
||||||
static async fromApiUserObject(apiUserObject: IZitadelApiUserObject) {
|
zitadelclientRef: ZitaldelClient;
|
||||||
const newUser = new ZitaldelUser();
|
data: IZitadelUserData;
|
||||||
newUser.data = apiUserObject;
|
|
||||||
return newUser;
|
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
|
||||||
|
this.zitadelclientRef = zitadelclientRefArg;
|
||||||
|
this.data = dataArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
public async addRole(projectRole: ZitadelProjectRole) {
|
||||||
data: IZitadelApiUserObject;
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes the user
|
||||||
|
*/
|
||||||
|
public async delete() {
|
||||||
|
const response = await this.zitadelclientRef.userClient.deleteUser({
|
||||||
|
userId: this.data.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user