bởi Hassan

A Node.js SDK for interacting with the Zitadel identity platform APIs, supporting Private Key JWT, Client Credentials, and Personal Access Token authentication for service users.
This block provides the complete source of the @zitadel/sdk Node.js client for the Zitadel identity platform. It exposes typed service APIs for managing users, sessions, organizations, projects, OIDC configuration, actions, and more. The typical buyer is a backend Node.js/TypeScript service that needs to call Zitadel's management or admin APIs using machine-to-machine credentials.
index.ts - Main entry point; exports the Zitadel default class and re-exports all models, APIs, and auth helpersconfiguration.ts - Configuration class controlling base URL, headers, and fetch behaviorruntime.ts - BaseAPI base class used by all generated service API classesapi-exception.ts - ApiException thrown on non-2xx HTTP responseszitadel-exception.ts - ZitadelException for SDK-level errorstransport-options.ts - TransportOptions type for configuring fetch/HTTP behaviorversion.ts - SDK version constantapis/ - One file per Zitadel service (e.g. user-service-api.ts, session-service-api.ts); each exports a typed class extending BaseAPIauth/ - Authenticator implementations: private key JWT, client credentials, personal access token, web token, no-authmodels/ - Auto-generated request/response model types for every API operationnpm install jose oauth4webapi undici
No native modules, no pod install, no Android linking, no Expo prebuild required. Node.js 20 or higher is required at runtime.
Copy the source/ directory into your project, e.g. as src/zitadel/.
Update tsconfig.json to include the source and enable ESM-compatible settings:
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"esModuleInterop": true,
"strict": true,
"rootDir": "src",
"outDir": "dist"
}
}
Because the source uses .js extensions on imports (ESM style), ensure is set in your , or configure a bundler (esbuild, Vite, tsx) to handle it. When using , add or use .
Khởi chạy sandbox cách ly và chạy phía máy chủ — không cần cài đặt cục bộ.
Tetrees AI Review cho phiên bản này
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Quy trình avcp-2026-08-04.1 · SHA-256 0833fe532b2f05f4…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Đã đánh giá 4 thg 8, 2026
Đưa sản phẩm này thẳng vào AI IDE, trình tạo web hoặc cloud IDE của bạn.
Kết nối Tetrees với AI IDE tương thích để liệt kê sản phẩm bạn sở hữu và nhận ZIP đã xác minh mà không cấp quyền tải lên của người bán.
Chưa có đánh giá.
Sign in to join the discussion
Loading discussion…
"type": "module"package.jsonts-node--esmtsxSet environment variables used by your authenticator setup:
ZITADEL_DOMAIN=https://example.us1.zitadel.cloud
ZITADEL_CLIENT_ID=your-service-user-client-id
ZITADEL_CLIENT_SECRET=your-service-user-client-secret
ZITADEL_PAT=your-personal-access-token
ZITADEL_KEY_PATH=path/to/jwt-key.json
import Zitadel from './zitadel/index.js';
export default class Zitadel {
public readonly actions: ActionServiceApi;
public readonly applications: ApplicationServiceApi;
public readonly authorizations: AuthorizationServiceApi;
public readonly users: UserServiceApi;
public readonly sessions: SessionServiceApi;
public readonly organizations: OrganizationServiceApi;
public readonly projects: ProjectServiceApi;
public readonly settings: SettingsServiceApi;
// ... all other service APIs
static withPrivateKey(domain: string, keyPath: string): Promise<Zitadel>;
static withClientCredentials(domain: string, clientId: string, clientSecret: string): Promise<Zitadel>;
static withPersonalAccessToken(domain: string, token: string): Zitadel;
}
The Zitadel class is the single entry point. Instantiate it with one of the static factory methods corresponding to your auth method, then access API services as properties.
export class ApiException extends Error {
constructor(
public status: number,
public headers: { [key: string]: string[] },
public body: string,
) {}
}
Thrown by any service API method when the HTTP response status is outside 200-299. Inspect status and body for error details. Always wrap API calls in a try/catch and check instanceof ApiException.
export class Configuration {
constructor(params?: {
basePath?: string;
headers?: HTTPHeaders;
credentials?: RequestCredentials;
fetchApi?: FetchAPI;
middleware?: Middleware[];
});
}
Controls how all HTTP requests are made. Pass a custom fetchApi to intercept or mock requests in tests, or add middleware for logging and retry logic. Used internally by BaseAPI and all service classes.
Authenticate as a service user via OAuth2 client credentials and create a new human user in Zitadel.
import Zitadel, { ApiException } from './zitadel/index.js';
const zitadel = await Zitadel.withClientCredentials(
process.env.ZITADEL_DOMAIN!,
process.env.ZITADEL_CLIENT_ID!,
process.env.ZITADEL_CLIENT_SECRET!,
);
try {
const response = await zitadel.users.addHumanUser({
userServiceAddHumanUserRequest: {
username: 'jane.doe',
profile: {
givenName: 'Jane',
familyName: 'Doe',
},
email: {
email: 'jane@example.com',
isVerified: true,
},
},
});
console.log('Created user:', response.userId);
} catch (e) {
if (e instanceof ApiException) {
console.error('API error', e.status, e.body);
} else {
throw e;
}
}
Use a PAT (service account token from the Zitadel console) to list all current sessions.
import Zitadel, { ApiException } from './zitadel/index.js';
const zitadel = Zitadel.withPersonalAccessToken(
process.env.ZITADEL_DOMAIN!,
process.env.ZITADEL_PAT!,
);
try {
const response = await zitadel.sessions.listSessions({
sessionServiceListSessionsRequest: {
queries: [],
},
});
console.log('Sessions:', JSON.stringify(response.sessions, null, 2));
} catch (e) {
if (e instanceof ApiException) {
console.error('Failed to list sessions:', e.status, e.body);
}
}
Use a JSON key file (downloaded from the Zitadel console) to authenticate via JWT and register a webhook target for an action.
import Zitadel, { ApiException } from './zitadel/index.js';
const zitadel = await Zitadel.withPrivateKey(
process.env.ZITADEL_DOMAIN!,
process.env.ZITADEL_KEY_PATH!,
);
try {
const response = await zitadel.actions.createTarget({
actionServiceCreateTargetRequest: {
name: 'my-webhook',
restWebhook: {
url: 'https://my-service.example.com/webhook',
interruptOnError: true,
},
timeout: '10s',
},
});
console.log('Target created:', response.id);
} catch (e) {
if (e instanceof ApiException) {
console.error('Error creating target:', e.status, e.body);
}
}
index.ts - Instantiates all service API classes from a shared Configuration and exposes them as typed properties on the Zitadel class; also re-exports everything from models/, auth/, and core files.configuration.ts - Holds the Configuration class; controls basePath, request headers, custom fetch, and middleware pipeline.runtime.ts - BaseAPI handles actual fetch calls, JSON/MIME detection, and throws ApiException on error responses.api-exception.ts - Defines ApiException with HTTP status, headers, and raw body; thrown by BaseAPI.request.zitadel-exception.ts - SDK-level ZitadelException for errors not tied to a specific HTTP response.transport-options.ts - Exports the TransportOptions type for configuring low-level HTTP transport.version.ts - Exports the SDK version string.apis/ - Auto-generated API service classes; one per Zitadel service group. Each class extends BaseAPI and exposes methods matching the Zitadel REST API operations.auth/ - Authenticator strategy classes and their builders. PersonalAccessAuthenticator, ClientCredentialsAuthenticator, and WebTokenAuthenticator each inject the appropriate Authorization header into Configuration.models/ - Auto-generated TypeScript interfaces for all request and response body shapes across every API service..js extensions. If your bundler or ts-node setup does not support this, use tsx (npx tsx src/index.ts) or configure moduleResolution: "Node16" in tsconfig.json.fetch and crypto.subtle are required; upgrade to Node.js 20+ or polyfill with undici explicitly via import { fetch } from 'undici' and pass it as fetchApi to Configuration."type": "module" missing: Without ESM mode in package.json, .js extension imports from the source will fail with ERR_REQUIRE_ESM; add "type": "module" or switch to a bundler.https://example.us1.zitadel.cloud), not just the hostname; omitting https:// causes TypeError: Invalid URL.jose / oauth4webapi version mismatch: These packages use ESM-only builds; installing versions older than their ESM-stable releases can break imports. Pin to the versions declared in @zitadel/sdk@4.1.2's lockfile.I have copied the source of the @zitadel/sdk (version 4.1.2) Node.js SDK into
my project under src/zitadel/. I also have USAGE.md describing the full API.
Please help me integrate this SDK into my existing Express/TypeScript project
step by step:
1. Read USAGE.md and src/zitadel/index.ts to understand available services
and authentication methods.
2. Add the required runtime dependencies (jose, oauth4webapi, undici) to
package.json.
3. Create a singleton Zitadel client in src/zitadel-client.ts using the
correct auth method for my environment (I will tell you which one).
4. Show me how to call the specific Zitadel API I need (I will specify the
operation), using real method names and model types from src/zitadel/models/.
5. Add proper error handling using ApiException from src/zitadel/api-exception.ts.
6. Ensure all imports use the correct paths relative to src/zitadel/index.ts
and that ESM module resolution is configured correctly.
My project uses: [describe your stack - Express/Fastify, ts-node/tsx/esbuild, etc.]
My auth method: [withPrivateKey / withClientCredentials / withPersonalAccessToken]
The operation I need: [describe what you want to do with Zitadel]
See source/LICENSE if present for the full license text. This block packages the upstream npm package @zitadel/sdk@4.1.2, published by the Zitadel team. Refer to the Zitadel GitHub repository for the original source and contribution guidelines.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
Hướng dẫn cài đặt đầy đủ và prompt tích hợp sẽ mở khóa sau khi mua.
Automation, Utilities & Developer Tools
Miễn phí