zitadel/readme.md

118 lines
3.7 KiB
Markdown
Raw Normal View History

2024-05-02 10:52:21 +00:00
# @apiclient.xyz/zitadel
2024-05-03 08:53:50 +00:00
An unofficial client for interacting with Zitadel API.
2024-05-02 10:52:21 +00:00
2024-05-02 14:07:25 +00:00
## Install
2024-05-03 08:53:50 +00:00
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:
2024-05-02 14:07:25 +00:00
```bash
npm install @apiclient.xyz/zitadel --save
```
2024-05-03 08:53:50 +00:00
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:
2024-05-02 14:07:25 +00:00
```bash
npm install -g typescript
```
2024-05-02 10:52:21 +00:00
## Usage
2024-05-03 08:53:50 +00:00
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.
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
### Getting Started
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
First, ensure you import the core client class from the package:
2024-05-02 14:07:25 +00:00
```typescript
2024-05-03 08:53:50 +00:00
import { ZitaldelClient } from '@apiclient.xyz/zitadel';
2024-05-02 14:07:25 +00:00
```
2024-05-03 08:53:50 +00:00
Initialize the `ZitaldelClient` with your Zitadel instance URL and access token:
2024-05-02 14:07:25 +00:00
```typescript
const zitadelClient = new ZitaldelClient({
2024-05-03 08:53:50 +00:00
url: 'https://your-zitadel-instance.com', // Replace with your Zitadel instance URL.
accessToken: 'your_access_token_here' // Replace with your actual access token.
2024-05-02 14:07:25 +00:00
});
```
2024-05-03 08:53:50 +00:00
### User Management
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
The library allows performing user operations such as listing all users, getting info of the current user, and creating new users.
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
#### List All Users
2024-05-02 14:07:25 +00:00
```typescript
async function listUsers() {
2024-05-03 08:53:50 +00:00
const users = await zitadelClient.listUsers();
console.log(users); // Outputs user list
2024-05-02 14:07:25 +00:00
}
listUsers();
```
2024-05-03 08:53:50 +00:00
#### Get Current User Information
2024-05-02 14:07:25 +00:00
```typescript
2024-05-03 08:53:50 +00:00
async function getCurrentUser() {
const user = await zitadelClient.listOwnUser();
console.log(user); // Outputs current user information.
2024-05-02 14:07:25 +00:00
}
2024-05-03 08:53:50 +00:00
getCurrentUser();
```
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
#### 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();
2024-05-02 14:07:25 +00:00
```
2024-05-03 08:53:50 +00:00
### Project Management
Beyond user management, the client also supports actions on projects—like listing and managing project roles.
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
#### List Projects
2024-05-02 14:07:25 +00:00
```typescript
2024-05-03 08:53:50 +00:00
async function listProjects() {
const projects = await zitadelClient.listProjects();
console.log(projects); // Outputs list of projects
2024-05-02 14:07:25 +00:00
}
2024-05-03 08:53:50 +00:00
listProjects();
```
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
#### 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);
}
2024-05-02 14:07:25 +00:00
```
2024-05-03 08:53:50 +00:00
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.
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
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.
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
---
2024-05-02 14:07:25 +00:00
2024-05-03 08:53:50 +00:00
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.
2024-05-02 14:07:25 +00:00
undefined