zitadel/readme.md
2024-05-02 16:07:25 +02:00

3.5 KiB

@apiclient.xyz/zitadel

an unofficial zitadel client

Install

To install @apiclient.xyz/zitadel, you need to have Node.js installed on your system. You can then add it to your project using npm with the following command:

npm install @apiclient.xyz/zitadel --save

Ensure you have TypeScript installed for development purposes. If you haven't, install it using:

npm install -g typescript

Usage

The @apiclient.xyz/zitadel package provides a simplified, unofficial TypeScript client for interacting with Zitadel's APIs. This guide will walk you through setting up the client and executing various operations such as user management in a TypeScript project.

Let's get started by setting up and initializing the client in your project.

Setup and Initialization

First, import the necessary classes from the package:

import { ZitaldelClient, ZitaldelUser } from '@apiclient.xyz/zitadel';

Instantiate the ZitaldelClient by providing connection options, including the Zitadel instance URL and an access token:

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
});

Managing Users

The Zitadel client supports various user management operations such as listing users, getting user information, and creating new users.

Listing Users

To list users, you can use the listUsers method. This will return an array of ZitaldelUser objects:

async function listUsers() {
  try {
    const users = await zitadelClient.listUsers();
    console.log(users);
  } catch (error) {
    console.error('Failed to list users:', error);
  }
}

listUsers();

Getting User Information

To get information about a specific user, use the listOwnUser method. This method is handy for fetching details about the authenticated user:

async function getOwnUserInfo() {
  try {
    const user = await zitadelClient.listOwnUser();
    console.log(user);
  } catch (error) {
    console.error('Failed to get user info:', error);
  }
}

getOwnUserInfo();

Creating a User

To create a new user, the createUser method can be used. You need to provide user details such as email, first name, and last name:

async function createUser() {
  try {
    await zitadelClient.createUser({
      email: 'newuser@example.com',
      firstName: 'John',
      lastName: 'Doe'
    });
    console.log('User created successfully');
  } catch (error) {
    console.error('Failed to create user:', error);
  }
}

createUser();

Advanced Usage

For more advanced scenarios, refer to the official Zitadel documentation and the source code of this package. The @apiclient.xyz/zitadel client provides a straightforward interface to Zitadel's API but does not cover all possible use cases and functionalities of Zitadel. You might need to extend the client or use the official Zitadel client for complex scenarios.

Conclusion

The @apiclient.xyz/zitadel package makes it easier to interact with Zitadel's APIs from a TypeScript application. With it, you can manage users, handle authentication, and perform various other operations provided by Zitadel. This guide covered the basics of setting up the client, managing users, and performing some common operations. For further details or specific use cases, consult the Zitadel documentation and the package's source code. undefined