6 Commits

Author SHA1 Message Date
19a4c9ef48 1.0.6 2024-05-03 10:39:25 +02:00
02a01ca35c fix(core): update 2024-05-03 10:39:24 +02:00
13fdbcebdc 1.0.5 2024-05-02 17:43:31 +02:00
6246a3d915 fix(core): update 2024-05-02 17:43:31 +02:00
13e67d9012 1.0.4 2024-05-02 16:07:26 +02:00
62714c0166 fix(core): update 2024-05-02 16:07:25 +02:00
10 changed files with 241 additions and 34 deletions

View File

@ -5,10 +5,17 @@
"githost": "code.foss.global",
"gitscope": "apiclient.xyz",
"gitrepo": "zitadel",
"description": "an unofficial zitadel client",
"description": "An unofficial client for interacting with Zitadel API.",
"npmPackagename": "@apiclient.xyz/zitadel",
"license": "MIT",
"projectDomain": "apiclient.xyz"
"projectDomain": "apiclient.xyz",
"keywords": [
"Zitadel",
"API client",
"TypeScript",
"authentication",
"user management"
]
}
},
"npmci": {

View File

@ -1,8 +1,8 @@
{
"name": "@apiclient.xyz/zitadel",
"version": "1.0.3",
"version": "1.0.6",
"private": false,
"description": "an unofficial zitadel client",
"description": "An unofficial client for interacting with Zitadel API.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -48,5 +48,12 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"keywords": [
"Zitadel",
"API client",
"TypeScript",
"authentication",
"user management"
]
}

0
readme.hints.md Normal file
View File

122
readme.md
View File

@ -1,31 +1,107 @@
# @apiclient.xyz/zitadel
an unofficial zitadel client
## Availabililty and Links
* [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/)
## Install
## Status for master
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:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://code.foss.global/apiclient.xyz/zitadel/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://code.foss.global/apiclient.xyz/zitadel/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@apiclient.xyz/zitadel)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/apiclient.xyz/zitadel)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@apiclient.xyz/zitadel)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@apiclient.xyz/zitadel)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiclient.xyz/zitadel)](https://lossless.cloud)
```bash
npm install @apiclient.xyz/zitadel --save
```
Ensure you have TypeScript installed for development purposes. If you haven't, install it using:
```bash
npm install -g typescript
```
## Usage
Use TypeScript for best in class intellisense
For further information read the linked docs at the top of this readme.
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
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:
```typescript
import { ZitaldelClient, ZitaldelUser } from '@apiclient.xyz/zitadel';
```
Instantiate the `ZitaldelClient` by providing connection options, including the Zitadel instance URL and an 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
});
```
### 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:
```typescript
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:
```typescript
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:
```typescript
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](https://docs.zitadel.ch/) 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

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/zitadel',
version: '1.0.3',
description: 'an unofficial zitadel client'
version: '1.0.6',
description: 'An unofficial client for interacting with Zitadel API.'
}

View File

@ -1,5 +1,6 @@
import { ZitadelProject } from './classes.zitadelproject.js';
import { ZitaldelUser } from './classes.zitadeluser.js';
import * as plugins from './zitadel.plugins.js';
import * as plugins from './plugins.js';
export interface IZitadelContructorOptions {
url: string;
@ -10,6 +11,7 @@ export class ZitaldelClient {
private options: IZitadelContructorOptions;
public authClient: plugins.zitadel.AuthServiceClient;
public userClient: plugins.zitadel.UserServiceClient;
public managementClient: plugins.zitadel.ManagementServiceClient;
constructor(optionsArg: IZitadelContructorOptions) {
this.options = optionsArg;
@ -22,6 +24,10 @@ export class ZitaldelClient {
this.options.url,
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
);
this.managementClient = plugins.zitadel.createManagementClient(
this.options.url,
plugins.zitadel.createAccessTokenInterceptor(this.options.accessToken)
);
}
public async listOwnUser() {
@ -34,6 +40,18 @@ export class ZitaldelClient {
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() {
const response = await this.userClient.listUsers({});
const returnArray: ZitaldelUser[] = [];

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

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

View File

@ -1,20 +1,67 @@
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 {
id: string;
lastLogin: Date;
username: string;
};
}
export class ZitaldelUser {
// INSTANCE
zitadelclientRef: ZitaldelClient;
data: IZitadelUserData;
constructor(zitadelclientRefArg: ZitaldelClient, dataArg: IZitadelUserData) {
this.zitadelclientRef = zitadelclientRefArg;
this.data = dataArg;
}
// INSTANCE
data: IZitadelUserData;
public async addRole(projectRole: ZitadelProjectRole) {
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,
});
}
}