Skip to content

Commit 4253292

Browse files
authored
feat(sdk): generate SDK for version v4.0.0 (#71)
* feat(sdk): generate SDK for version v4.0.0 * fix(tests): updated the tests to comply with the new connect-rpc changes * fix(tests): updated the tests to comply with the new connect-rpc changes * docs: added the readme for the project * fix: added all services to the zitadel entry point
1 parent a97c991 commit 4253292

File tree

1,417 files changed

+118965
-33497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,417 files changed

+118965
-33497
lines changed

README.md

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
# Node.js SDK for Zitadel
2+
3+
This is the Zitadel Node.js SDK, designed to provide a convenient and idiomatic
4+
way to interact with the Zitadel APIs in Node.js. The SDK provides a seamless
5+
wrapping of the Zitadel API, making it easy to authenticate service users and
6+
perform API operations.
7+
8+
The SDK enables efficient integration with the Zitadel API, allowing you to
9+
manage resources and execute actions. However, it's important to note that
10+
this SDK is tailored for service users and is not intended for user
11+
authentication scenarios. It does not support authentication mechanisms
12+
like OAuth2, OIDC, or SAML for client applications, including web, mobile,
13+
or other environments. For these types of user authentication, you should
14+
use other libraries that are designed for the specific platform and
15+
authentication method.
16+
17+
**Disclaimer**: This SDK is not suitable for implementing user authentication.
18+
It does not handle authentication for client applications using OAuth2, OIDC,
19+
or SAML and should not be used for scenarios requiring such functionality.
20+
For those use cases, consider using other solutions that are designed for
21+
user authentication across various platforms like web, mobile, or other
22+
client environments.
23+
24+
> [!IMPORTANT]
25+
> Please be aware that this SDK is currently in an incubating stage. We are releasing it to the community to gather
26+
> feedback and learn how it is being used. While you are welcome to use it, please note that the API and functionality may
27+
> evolve based on community input. We encourage you to try it out and share your experiences, but advise caution when
28+
> considering it for production environments as future updates may introduce changes.
29+
30+
## Getting Started
31+
32+
### Sign up for Zitadel
33+
34+
To use this SDK, you need a Zitadel account. Sign up at the official
35+
Zitadel website and obtain the necessary credentials to access the API.
36+
37+
### Minimum Requirements
38+
39+
Ensure you have Node.js 20 or higher installed. You also need npm to
40+
install dependencies.
41+
42+
## Using the SDK
43+
44+
### Installation
45+
46+
Install the SDK by running one of the following commands:
47+
48+
```bash
49+
npm install @zitadel/zitadel-node
50+
```
51+
52+
## Authentication Methods
53+
54+
Your SDK offers three ways to authenticate with Zitadel. Each method has its
55+
own benefits—choose the one that fits your situation best.
56+
57+
#### 1. Private Key JWT Authentication
58+
59+
**What is it?**
60+
You use a JSON Web Token (JWT) that you sign with a private key stored in a
61+
JSON file. This process creates a secure token.
62+
63+
**When should you use it?**
64+
65+
- **Best for production:** It offers strong security.
66+
- **Advanced control:** You can adjust token settings like expiration.
67+
68+
**How do you use it?**
69+
70+
1. Save your private key in a JSON file.
71+
2. Use the provided method to load this key and create a JWT-based
72+
authenticator.
73+
74+
**Example:**
75+
76+
```ts
77+
import Zitadel, { ApiException } from '@zitadel/zitadel-node';
78+
79+
const zitadel = await Zitadel.withPrivateKey(
80+
'https://example.us1.zitadel.cloud',
81+
'path/to/jwt-key.json',
82+
);
83+
84+
try {
85+
const response = await zitadel.users.addHumanUser({
86+
userServiceAddHumanUserRequest: {
87+
username: 'john.doe',
88+
profile: {
89+
givenName: 'John',
90+
familyName: 'Doe',
91+
},
92+
email: {
93+
94+
},
95+
},
96+
});
97+
console.log('User created: ' + JSON.stringify(response, null, 2));
98+
} catch (e) {
99+
if (e instanceof ApiException) {
100+
console.log('Error: ' + e.message);
101+
}
102+
}
103+
```
104+
105+
#### 2. Client Credentials Grant
106+
107+
**What is it?**
108+
This method uses a client ID and client secret to get a secure access token,
109+
which is then used to authenticate.
110+
111+
**When should you use it?**
112+
113+
- **Simple and straightforward:** Good for server-to-server communication.
114+
- **Trusted environments:** Use it when both servers are owned or trusted.
115+
116+
**How do you use it?**
117+
118+
1. Provide your client ID and client secret.
119+
2. Build the authenticator
120+
121+
**Example:**
122+
123+
```ts
124+
import Zitadel, { ApiException } from '@zitadel/zitadel-node';
125+
126+
const zitadel = await Zitadel.withClientCredentials(
127+
'https://example.us1.zitadel.cloud',
128+
'id',
129+
'secret',
130+
);
131+
132+
try {
133+
const response = await zitadel.users.addHumanUser({
134+
userServiceAddHumanUserRequest: {
135+
username: 'john.doe',
136+
profile: {
137+
givenName: 'John',
138+
familyName: 'Doe',
139+
},
140+
email: {
141+
142+
},
143+
},
144+
});
145+
console.log('User created: ' + JSON.stringify(response, null, 2));
146+
} catch (e) {
147+
if (e instanceof ApiException) {
148+
console.log('Error: ' + e.message);
149+
}
150+
}
151+
```
152+
153+
#### 3. Personal Access Tokens (PATs)
154+
155+
**What is it?**
156+
A Personal Access Token (PAT) is a pre-generated token that you can use to
157+
authenticate without exchanging credentials every time.
158+
159+
**When should you use it?**
160+
161+
- **Easy to use:** Great for development or testing scenarios.
162+
- **Quick setup:** No need for dynamic token generation.
163+
164+
**How do you use it?**
165+
166+
1. Obtain a valid personal access token from your account.
167+
2. Create the authenticator with: `PersonalAccessTokenAuthenticator`
168+
169+
**Example:**
170+
171+
```ts
172+
import Zitadel, { ApiException } from '@zitadel/zitadel-node';
173+
174+
const zitadel = Zitadel.withAccessToken(
175+
'https://example.us1.zitadel.cloud',
176+
'token',
177+
);
178+
179+
try {
180+
const response = await zitadel.users.addHumanUser({
181+
userServiceAddHumanUserRequest: {
182+
username: 'john.doe',
183+
profile: {
184+
givenName: 'John',
185+
familyName: 'Doe',
186+
},
187+
email: {
188+
189+
},
190+
},
191+
});
192+
console.log('User created: ' + JSON.stringify(response, null, 2));
193+
} catch (e) {
194+
if (e instanceof ApiException) {
195+
console.log('Error: ' + e.message);
196+
}
197+
}
198+
```
199+
200+
---
201+
202+
Choose the authentication method that best suits your needs based on your
203+
environment and security requirements. For more details, please refer to the
204+
[Zitadel documentation on authenticating service users](https://zitadel.com/docs/guides/integrate/service-users/authenticate-service-users).
205+
206+
## Design and Dependencies
207+
208+
This SDK is designed to be lean and efficient, focusing on providing a
209+
streamlined way to interact with the Zitadel API. It relies on standard
210+
HTTP libraries for making requests, which ensures that
211+
the SDK integrates well with other libraries and provides flexibility
212+
in terms of request handling and error management.
213+
214+
## Versioning
215+
216+
A key aspect of our strategy is that the SDK's major version is synchronized with the ZITADEL core project's major
217+
version to ensure compatibility. For a detailed explanation of this policy and our release schedule, please see
218+
our [Versioning Guide](VERSIONING.md).
219+
220+
## Contributing
221+
222+
This repository is autogenerated. We do not accept direct contributions.
223+
Instead, please open an issue for any bugs or feature requests.
224+
225+
## Reporting Issues
226+
227+
If you encounter any issues or have suggestions for improvements, please
228+
open an issue in the [issue tracker](https://github.com/zitadel/client-nodejs/issues).
229+
When reporting an issue, please provide the following information to help
230+
us address it more effectively:
231+
232+
- A detailed description of the problem or feature request
233+
- Steps to reproduce the issue (if applicable)
234+
- Any relevant error messages or logs
235+
- Environment details (e.g., OS version, relevant configurations)
236+
237+
## Support
238+
239+
If you need help setting up or configuring the SDK (or anything
240+
Zitadel), please head over to the [Zitadel Community on Discord](https://zitadel.com/chat).
241+
242+
There are many helpful people in our Discord community who are ready to
243+
assist you.
244+
245+
Cloud and enterprise customers can additionally reach us privately via our
246+
[support communication channels](https://zitadel.com/docs/legal/service-description/support-services).
247+
248+
## License
249+
250+
This SDK is distributed under the Apache 2.0 License.

eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import mridangPlugin from '@mridang/eslint-defaults';
22

33
export default [
4-
...mridangPlugin.configs.recommended, // Spread if it's an array
4+
...mridangPlugin.configs.recommended,
55
{
6-
ignores: ['src/apis/*', 'src/models/*'],
6+
ignores: ['src/apis/*', 'src/models/*', 'README.md'],
77
},
88
];

spec/auth/use-access-token.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('UseAccessTokenSpec', () => {
2424
it('testRetrievesGeneralSettingsWithValidAuth', async () => {
2525
const client = Zitadel.withAccessToken(context.baseUrl, context.authToken);
2626

27-
await client.settings.settingsServiceGetGeneralSettings();
27+
await client.settings.getGeneralSettings({ body: {} });
2828
});
2929

3030
/**
@@ -35,7 +35,7 @@ describe('UseAccessTokenSpec', () => {
3535
const invalid = Zitadel.withAccessToken(context.baseUrl, 'invalid');
3636

3737
await expect(
38-
invalid.settings.settingsServiceGetGeneralSettings(),
38+
invalid.settings.getGeneralSettings({ body: {} }),
3939
).rejects.toThrow(ZitadelException);
4040
}, 120000);
4141
});

spec/auth/use-client-credentials.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('UseClientCredentialsSpec', () => {
116116
credentials.clientSecret,
117117
);
118118

119-
await client.settings.settingsServiceGetGeneralSettings();
119+
await client.settings.getGeneralSettings({ body: {} });
120120
}, 120000);
121121

122122
/**
@@ -131,7 +131,7 @@ describe('UseClientCredentialsSpec', () => {
131131
);
132132

133133
await expect(
134-
invalid.settings.settingsServiceGetGeneralSettings(),
134+
invalid.settings.getGeneralSettings({ body: {} }),
135135
).rejects.toThrow(ZitadelException);
136136
}, 120000);
137137
});

spec/auth/use-private-key.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('UsePrivateKeySpec', () => {
2727
context.baseUrl,
2828
context.jwtKey,
2929
);
30-
await client.settings.settingsServiceGetGeneralSettings();
30+
await client.settings.getGeneralSettings({ body: {} });
3131
}, 120000);
3232

3333
/**
@@ -40,7 +40,7 @@ describe('UsePrivateKeySpec', () => {
4040
context.jwtKey,
4141
);
4242
await expect(
43-
invalid.settings.settingsServiceGetGeneralSettings(),
43+
invalid.settings.getGeneralSettings({ body: {} }),
4444
).rejects.toThrow(ZitadelException);
4545
}, 120000);
4646
});

spec/session-service-sanity.spec.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('SessionServiceSanityCheckSpec', () => {
3939
*/
4040
beforeEach(async () => {
4141
const username = crypto.randomUUID().substring(0, 8);
42-
await client.users.userServiceAddHumanUser({
42+
await client.users.addHumanUser({
4343
userServiceAddHumanUserRequest: {
4444
username: username,
4545
profile: {
@@ -63,15 +63,16 @@ describe('SessionServiceSanityCheckSpec', () => {
6363
},
6464
};
6565

66-
const response = await client.sessions.sessionServiceCreateSession(request);
66+
const response = await client.sessions.createSession(request);
6767
sessionId = response.sessionId || '';
6868
});
6969

7070
afterEach(async () => {
7171
try {
72-
await client.sessions.sessionServiceDeleteSession({
73-
sessionId,
74-
sessionServiceDeleteSessionRequest: {},
72+
await client.sessions.deleteSession({
73+
sessionServiceDeleteSessionRequest: {
74+
sessionId,
75+
},
7576
});
7677
} catch {
7778
// Ignore cleanup errors
@@ -82,8 +83,10 @@ describe('SessionServiceSanityCheckSpec', () => {
8283
* @throws ApiException
8384
*/
8485
it('testRetrievesTheSessionDetailsById', async () => {
85-
const response = await client.sessions.sessionServiceGetSession({
86-
sessionId,
86+
const response = await client.sessions.getSession({
87+
sessionServiceGetSessionRequest: {
88+
sessionId,
89+
},
8790
});
8891
expect(response.session?.id).toBe(sessionId);
8992
});
@@ -97,7 +100,7 @@ describe('SessionServiceSanityCheckSpec', () => {
97100
queries: [],
98101
},
99102
};
100-
const response = await client.sessions.sessionServiceListSessions(request);
103+
const response = await client.sessions.listSessions(request);
101104
const ids = response.sessions?.map((session) => session.id);
102105
expect(ids).toContain(sessionId);
103106
});
@@ -106,9 +109,9 @@ describe('SessionServiceSanityCheckSpec', () => {
106109
* @throws ApiException
107110
*/
108111
it('testUpdatesTheSessionLifetimeAndReturnsANewToken', async () => {
109-
const response = await client.sessions.sessionServiceSetSession({
110-
sessionId: sessionId,
112+
const response = await client.sessions.setSession({
111113
sessionServiceSetSessionRequest: {
114+
sessionId: sessionId,
112115
lifetime: '36000s',
113116
},
114117
});
@@ -118,7 +121,9 @@ describe('SessionServiceSanityCheckSpec', () => {
118121
it('testRaisesAnApiExceptionWhenRetrievingANonExistentSession', async () => {
119122
const nonExistentId = crypto.randomUUID();
120123
await expect(
121-
client.sessions.sessionServiceGetSession({ sessionId: nonExistentId }),
124+
client.sessions.getSession({
125+
sessionServiceGetSessionRequest: { sessionId: nonExistentId },
126+
}),
122127
).rejects.toThrow(ApiException);
123128
});
124129
});

0 commit comments

Comments
 (0)