keycloak-api 0.2.6 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +75 -4
  2. package/dist/account/components.cjs +371 -0
  3. package/dist/account/components.d.mts +252 -0
  4. package/dist/account/components.d.mts.map +1 -0
  5. package/dist/account/components.mjs +348 -0
  6. package/dist/account/schemas.cjs +76 -0
  7. package/dist/account/schemas.d.mts +749 -0
  8. package/dist/account/schemas.d.mts.map +1 -0
  9. package/dist/account/schemas.mjs +1 -0
  10. package/dist/account/types.cjs +1 -0
  11. package/dist/account/types.d.mts +689 -0
  12. package/dist/account/types.d.mts.map +1 -0
  13. package/dist/account/types.mjs +1 -0
  14. package/dist/admin/components.cjs +9323 -0
  15. package/dist/admin/components.d.mts +5131 -0
  16. package/dist/admin/components.d.mts.map +1 -0
  17. package/dist/admin/components.mjs +8918 -0
  18. package/dist/admin/schemas.cjs +1880 -0
  19. package/dist/admin/schemas.d.mts +39445 -0
  20. package/dist/admin/schemas.d.mts.map +1 -0
  21. package/dist/admin/schemas.mjs +1 -0
  22. package/dist/admin/types.cjs +16 -0
  23. package/dist/admin/types.d.mts +16468 -0
  24. package/dist/admin/types.d.mts.map +1 -0
  25. package/dist/admin/types.mjs +1 -0
  26. package/dist/fetcher-aq8636lm.cjs +65 -0
  27. package/dist/fetcher-caoilmfh.d.ts +38 -0
  28. package/dist/fetcher-caoilmfh.d.ts.map +1 -0
  29. package/dist/fetcher-letfyywe.js +65 -0
  30. package/dist/index.cjs +66 -1790
  31. package/dist/index.d.ts +67619 -10138
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.mjs +56 -1788
  34. package/dist/schemas-ckfznbee.js +340 -0
  35. package/dist/schemas-f1u0t5ee.cjs +430 -0
  36. package/dist/schemas-g9c8wc66.cjs +10203 -0
  37. package/dist/schemas-pbtpxjsr.js +8309 -0
  38. package/dist/types-6yzhv6is.cjs +73 -0
  39. package/dist/types-iyze6mys.js +63 -0
  40. package/package.json +68 -18
  41. package/.turbo/turbo-build.log +0 -14
  42. package/CHANGELOG.md +0 -49
  43. package/dist/index.d.cts +0 -11999
  44. package/dist/index.d.mts +0 -11999
  45. package/specs/account.yaml +0 -578
  46. package/tsconfig.json +0 -19
package/README.md CHANGED
@@ -1,8 +1,79 @@
1
- # Keycloak API JavaScript SDK
1
+ # keycloak-api
2
2
 
3
- Unofficial Keycloak API JavaScript SDK built from the OpenAPI specification and with TypeScript types.
3
+ Auto-generated, fully typed client for the [Keycloak Admin and Account REST APIs](https://www.keycloak.org/docs-api/latest/rest-api/index.html).
4
+
5
+ ## Features
6
+
7
+ - **Fully typed** - every endpoint, parameter and response is generated from the official OpenAPI specs
8
+ - **Admin and Account APIs** - separate clients for the two Keycloak surfaces
9
+ - **Tree-shakable** - only the operations you import end up in your bundle
10
+ - **Runtime agnostic** - uses the global `fetch`, or bring your own implementation
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install keycloak-api
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ Keycloak is self-hosted, so both clients require the `baseUrl` of your server. Endpoints are addressed
21
+ as `"<METHOD> <path>"`.
22
+
23
+ ### Admin API
4
24
 
5
25
  ```ts
6
- const keycloak = new KeycloakApi({ token: 'token' });
7
- const realms = await keycloak.request('GET /admin/realms', {});
26
+ import { KeycloakAdminApi } from "keycloak-api";
27
+
28
+ const admin = new KeycloakAdminApi({
29
+ baseUrl: "https://keycloak.example.com",
30
+ token: process.env.KEYCLOAK_TOKEN ?? null,
31
+ });
32
+
33
+ const realms = await admin.request("GET /admin/realms", {});
34
+ const realm = await admin.request("GET /admin/realms/{realm}", {
35
+ pathParams: { realm: "master" },
36
+ });
8
37
  ```
38
+
39
+ ### Account API
40
+
41
+ The Account API is scoped to a single realm, passed at construction time.
42
+
43
+ ```ts
44
+ import { KeycloakAccountApi } from "keycloak-api";
45
+
46
+ const account = new KeycloakAccountApi({
47
+ baseUrl: "https://keycloak.example.com",
48
+ realm: "master",
49
+ token: process.env.KEYCLOAK_TOKEN ?? null,
50
+ });
51
+
52
+ const me = await account.request("GET /account/", {});
53
+ ```
54
+
55
+ ### Custom fetch
56
+
57
+ ```ts
58
+ const admin = new KeycloakAdminApi({
59
+ baseUrl: "https://keycloak.example.com",
60
+ token: process.env.KEYCLOAK_TOKEN ?? null,
61
+ fetch: myFetchImplementation,
62
+ });
63
+ ```
64
+
65
+ ## Entrypoints
66
+
67
+ | Import | Contents |
68
+ | --- | --- |
69
+ | `keycloak-api` | both client classes, plus admin/account operations, schemas and types |
70
+ | `keycloak-api/admin/components` | admin operations grouped by tag and by path |
71
+ | `keycloak-api/admin/schemas` | Zod schemas for admin operations |
72
+ | `keycloak-api/admin/types` | TypeScript types for admin operations |
73
+ | `keycloak-api/account/components` | account operations grouped by tag and by path |
74
+ | `keycloak-api/account/schemas` | Zod schemas for account operations |
75
+ | `keycloak-api/account/types` | TypeScript types for account operations |
76
+
77
+ ## License
78
+
79
+ ISC
@@ -0,0 +1,371 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var fetcher = require('../fetcher-aq8636lm.cjs');
4
+
5
+ /**
6
+ * @description Get user details for currently logged in user
7
+ * @summary Get account
8
+ * {@link /account/}
9
+ */ async function getAccount({ queryParams, config = {} }) {
10
+ const { client: request = fetcher.client, ...requestConfig } = config;
11
+ const data = await request({
12
+ method: "GET",
13
+ url: `/account/`,
14
+ queryParams,
15
+ ...requestConfig
16
+ });
17
+ return data;
18
+ }
19
+ /**
20
+ * @summary Update account
21
+ * {@link /account/}
22
+ */ async function updateAccount({ body, config = {} }) {
23
+ const { client: request = fetcher.client, ...requestConfig } = config;
24
+ const data = await request({
25
+ method: "POST",
26
+ url: `/account/`,
27
+ body,
28
+ ...requestConfig
29
+ });
30
+ return data;
31
+ }
32
+ /**
33
+ * @summary Get applications
34
+ * {@link /account/applications}
35
+ */ async function getApplications({ queryParams, config = {} }) {
36
+ const { client: request = fetcher.client, ...requestConfig } = config;
37
+ const data = await request({
38
+ method: "GET",
39
+ url: `/account/applications`,
40
+ queryParams,
41
+ ...requestConfig
42
+ });
43
+ return data;
44
+ }
45
+ /**
46
+ * @summary Get consent
47
+ * {@link /account/applications/:clientId/consent}
48
+ */ async function getConsent({ pathParams: { clientId }, config = {} }) {
49
+ const { client: request = fetcher.client, ...requestConfig } = config;
50
+ if (!clientId) {
51
+ throw new Error(`Missing required path parameter: clientId`);
52
+ }
53
+ const data = await request({
54
+ method: "GET",
55
+ url: `/account/applications/${clientId}/consent`,
56
+ ...requestConfig
57
+ });
58
+ return data;
59
+ }
60
+ /**
61
+ * @summary Create consent
62
+ * {@link /account/applications/:clientId/consent}
63
+ */ async function createConsent({ pathParams: { clientId }, config = {} }) {
64
+ const { client: request = fetcher.client, ...requestConfig } = config;
65
+ if (!clientId) {
66
+ throw new Error(`Missing required path parameter: clientId`);
67
+ }
68
+ const data = await request({
69
+ method: "POST",
70
+ url: `/account/applications/${clientId}/consent`,
71
+ ...requestConfig
72
+ });
73
+ return data;
74
+ }
75
+ /**
76
+ * @summary Update consent
77
+ * {@link /account/applications/:clientId/consent}
78
+ */ async function updateConsent({ pathParams: { clientId }, config = {} }) {
79
+ const { client: request = fetcher.client, ...requestConfig } = config;
80
+ if (!clientId) {
81
+ throw new Error(`Missing required path parameter: clientId`);
82
+ }
83
+ const data = await request({
84
+ method: "PUT",
85
+ url: `/account/applications/${clientId}/consent`,
86
+ ...requestConfig
87
+ });
88
+ return data;
89
+ }
90
+ /**
91
+ * @summary Delete consent
92
+ * {@link /account/applications/:clientId/consent}
93
+ */ async function deleteConsent({ pathParams: { clientId }, config = {} }) {
94
+ const { client: request = fetcher.client, ...requestConfig } = config;
95
+ if (!clientId) {
96
+ throw new Error(`Missing required path parameter: clientId`);
97
+ }
98
+ const data = await request({
99
+ method: "DELETE",
100
+ url: `/account/applications/${clientId}/consent`,
101
+ ...requestConfig
102
+ });
103
+ return data;
104
+ }
105
+ /**
106
+ * @description Get credentials for currently logged in user
107
+ * @summary Get credentials
108
+ * {@link /account/credentials}
109
+ */ async function getCredentials({ queryParams, config = {} }) {
110
+ const { client: request = fetcher.client, ...requestConfig } = config;
111
+ const data = await request({
112
+ method: "GET",
113
+ url: `/account/credentials`,
114
+ queryParams,
115
+ ...requestConfig
116
+ });
117
+ return data;
118
+ }
119
+ /**
120
+ * @summary Delete the credential
121
+ * {@link /account/credentials/:credentialId}
122
+ */ async function deleteCredential({ pathParams: { credentialId }, config = {} }) {
123
+ const { client: request = fetcher.client, ...requestConfig } = config;
124
+ if (!credentialId) {
125
+ throw new Error(`Missing required path parameter: credentialId`);
126
+ }
127
+ const data = await request({
128
+ method: "DELETE",
129
+ url: `/account/credentials/${credentialId}`,
130
+ ...requestConfig
131
+ });
132
+ return data;
133
+ }
134
+ /**
135
+ * @summary Update a user label of specified credential of current user
136
+ * {@link /account/credentials/:credentialId/label}
137
+ */ async function updateCredentialLabel({ pathParams: { credentialId }, body, config = {} }) {
138
+ const { client: request = fetcher.client, ...requestConfig } = config;
139
+ if (!credentialId) {
140
+ throw new Error(`Missing required path parameter: credentialId`);
141
+ }
142
+ const data = await request({
143
+ method: "PUT",
144
+ url: `/account/credentials/${credentialId}/label`,
145
+ body,
146
+ ...requestConfig
147
+ });
148
+ return data;
149
+ }
150
+ /**
151
+ * @description Get sessions for currently logged in user
152
+ * @summary Get sessions
153
+ * {@link /account/sessions}
154
+ */ async function getSessions({ config = {} }) {
155
+ const { client: request = fetcher.client, ...requestConfig } = config;
156
+ const data = await request({
157
+ method: "GET",
158
+ url: `/account/sessions`,
159
+ ...requestConfig
160
+ });
161
+ return data;
162
+ }
163
+ /**
164
+ * @summary Delete current session
165
+ * {@link /account/sessions}
166
+ */ async function deleteCurrentSession({ config = {} }) {
167
+ const { client: request = fetcher.client, ...requestConfig } = config;
168
+ const data = await request({
169
+ method: "DELETE",
170
+ url: `/account/sessions`,
171
+ ...requestConfig
172
+ });
173
+ return data;
174
+ }
175
+ /**
176
+ * @description Get devices for currently logged in user
177
+ * @summary Get devices
178
+ * {@link /account/sessions/devices}
179
+ */ async function getDevices({ config = {} }) {
180
+ const { client: request = fetcher.client, ...requestConfig } = config;
181
+ const data = await request({
182
+ method: "GET",
183
+ url: `/account/sessions/devices`,
184
+ ...requestConfig
185
+ });
186
+ return data;
187
+ }
188
+ /**
189
+ * @summary Delete the session
190
+ * {@link /account/sessions/:sessionId}
191
+ */ async function deleteSession({ pathParams: { sessionId }, config = {} }) {
192
+ const { client: request = fetcher.client, ...requestConfig } = config;
193
+ if (!sessionId) {
194
+ throw new Error(`Missing required path parameter: sessionId`);
195
+ }
196
+ const data = await request({
197
+ method: "DELETE",
198
+ url: `/account/sessions/${sessionId}`,
199
+ ...requestConfig
200
+ });
201
+ return data;
202
+ }
203
+ /**
204
+ * @description Get linked accounts for currently logged in user
205
+ * @summary Get linked accounts
206
+ * {@link /account/linked-accounts}
207
+ */ async function getLinkedAccounts({ config = {} }) {
208
+ const { client: request = fetcher.client, ...requestConfig } = config;
209
+ const data = await request({
210
+ method: "GET",
211
+ url: `/account/linked-accounts`,
212
+ ...requestConfig
213
+ });
214
+ return data;
215
+ }
216
+ /**
217
+ * @description Build account linking URI
218
+ * @summary Build account linking URI
219
+ * {@link /account/linked-accounts/:providerId}
220
+ */ async function buildLinkingUri({ pathParams: { providerId }, queryParams, config = {} }) {
221
+ const { client: request = fetcher.client, ...requestConfig } = config;
222
+ if (!providerId) {
223
+ throw new Error(`Missing required path parameter: providerId`);
224
+ }
225
+ const data = await request({
226
+ method: "GET",
227
+ url: `/account/linked-accounts/${providerId}`,
228
+ queryParams,
229
+ ...requestConfig
230
+ });
231
+ return data;
232
+ }
233
+ /**
234
+ * @summary Delete the linked provider
235
+ * {@link /account/linked-accounts/:providerId}
236
+ */ async function deleteLinkedProvider({ pathParams: { providerId }, config = {} }) {
237
+ const { client: request = fetcher.client, ...requestConfig } = config;
238
+ if (!providerId) {
239
+ throw new Error(`Missing required path parameter: providerId`);
240
+ }
241
+ const data = await request({
242
+ method: "DELETE",
243
+ url: `/account/linked-accounts/${providerId}`,
244
+ ...requestConfig
245
+ });
246
+ return data;
247
+ }
248
+ /**
249
+ * @summary Get groups that this user is a member of
250
+ * {@link /account/groups}
251
+ */ async function getGroups({ queryParams, config = {} }) {
252
+ const { client: request = fetcher.client, ...requestConfig } = config;
253
+ const data = await request({
254
+ method: "GET",
255
+ url: `/account/groups`,
256
+ queryParams,
257
+ ...requestConfig
258
+ });
259
+ return data;
260
+ }
261
+ /**
262
+ * @description Get organizations for currently logged in user
263
+ * @summary Get organizations
264
+ * {@link /account/organizations}
265
+ */ async function getOrganizations({ config = {} }) {
266
+ const { client: request = fetcher.client, ...requestConfig } = config;
267
+ const data = await request({
268
+ method: "GET",
269
+ url: `/account/organizations`,
270
+ ...requestConfig
271
+ });
272
+ return data;
273
+ }
274
+ const operationsByPath = {
275
+ "GET /account/": getAccount,
276
+ "POST /account/": updateAccount,
277
+ "GET /account/applications": getApplications,
278
+ "GET /account/applications/{clientId}/consent": getConsent,
279
+ "POST /account/applications/{clientId}/consent": createConsent,
280
+ "PUT /account/applications/{clientId}/consent": updateConsent,
281
+ "DELETE /account/applications/{clientId}/consent": deleteConsent,
282
+ "GET /account/credentials": getCredentials,
283
+ "DELETE /account/credentials/{credentialId}": deleteCredential,
284
+ "PUT /account/credentials/{credentialId}/label": updateCredentialLabel,
285
+ "GET /account/sessions": getSessions,
286
+ "DELETE /account/sessions": deleteCurrentSession,
287
+ "GET /account/sessions/devices": getDevices,
288
+ "DELETE /account/sessions/{sessionId}": deleteSession,
289
+ "GET /account/linked-accounts": getLinkedAccounts,
290
+ "GET /account/linked-accounts/{providerId}": buildLinkingUri,
291
+ "DELETE /account/linked-accounts/{providerId}": deleteLinkedProvider,
292
+ "GET /account/groups": getGroups,
293
+ "GET /account/organizations": getOrganizations
294
+ };
295
+ const operationsByTag = {
296
+ account: {
297
+ getAccount,
298
+ updateAccount,
299
+ getApplications,
300
+ getConsent,
301
+ createConsent,
302
+ updateConsent,
303
+ deleteConsent,
304
+ getCredentials,
305
+ deleteCredential,
306
+ updateCredentialLabel,
307
+ getSessions,
308
+ deleteCurrentSession,
309
+ getDevices,
310
+ deleteSession,
311
+ getLinkedAccounts,
312
+ buildLinkingUri,
313
+ deleteLinkedProvider,
314
+ getGroups,
315
+ getOrganizations
316
+ }
317
+ };
318
+ const tagDictionary = {
319
+ account: {
320
+ GET: [
321
+ "getAccount",
322
+ "getApplications",
323
+ "getConsent",
324
+ "getCredentials",
325
+ "getSessions",
326
+ "getDevices",
327
+ "getLinkedAccounts",
328
+ "buildLinkingUri",
329
+ "getGroups",
330
+ "getOrganizations"
331
+ ],
332
+ POST: [
333
+ "updateAccount",
334
+ "createConsent"
335
+ ],
336
+ PUT: [
337
+ "updateConsent",
338
+ "updateCredentialLabel"
339
+ ],
340
+ DELETE: [
341
+ "deleteConsent",
342
+ "deleteCredential",
343
+ "deleteCurrentSession",
344
+ "deleteSession",
345
+ "deleteLinkedProvider"
346
+ ]
347
+ }
348
+ };
349
+
350
+ exports.buildLinkingUri = buildLinkingUri;
351
+ exports.createConsent = createConsent;
352
+ exports.deleteConsent = deleteConsent;
353
+ exports.deleteCredential = deleteCredential;
354
+ exports.deleteCurrentSession = deleteCurrentSession;
355
+ exports.deleteLinkedProvider = deleteLinkedProvider;
356
+ exports.deleteSession = deleteSession;
357
+ exports.getAccount = getAccount;
358
+ exports.getApplications = getApplications;
359
+ exports.getConsent = getConsent;
360
+ exports.getCredentials = getCredentials;
361
+ exports.getDevices = getDevices;
362
+ exports.getGroups = getGroups;
363
+ exports.getLinkedAccounts = getLinkedAccounts;
364
+ exports.getOrganizations = getOrganizations;
365
+ exports.getSessions = getSessions;
366
+ exports.operationsByPath = operationsByPath;
367
+ exports.operationsByTag = operationsByTag;
368
+ exports.tagDictionary = tagDictionary;
369
+ exports.updateAccount = updateAccount;
370
+ exports.updateConsent = updateConsent;
371
+ exports.updateCredentialLabel = updateCredentialLabel;