keycloak-api 1.0.0 → 1.1.0
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.
- package/README.md +79 -0
- package/dist/account/components.cjs +26 -88
- package/dist/account/components.d.mts +32 -547
- package/dist/account/components.d.mts.map +1 -1
- package/dist/account/components.mjs +7 -69
- package/dist/account/schemas.cjs +72 -270
- package/dist/account/schemas.d.mts +3 -3
- package/dist/account/schemas.d.mts.map +1 -1
- package/dist/account/schemas.mjs +1 -183
- package/dist/account/types.d.mts +197 -820
- package/dist/account/types.d.mts.map +1 -1
- package/dist/admin/components.cjs +526 -588
- package/dist/admin/components.d.mts +1769 -6465
- package/dist/admin/components.d.mts.map +1 -1
- package/dist/admin/components.mjs +113 -175
- package/dist/admin/schemas.cjs +2928 -7511
- package/dist/admin/schemas.d.mts +15807 -1703
- package/dist/admin/schemas.d.mts.map +1 -1
- package/dist/admin/schemas.mjs +1 -4790
- package/dist/admin/types.cjs +13 -57
- package/dist/admin/types.d.mts +8584 -21398
- package/dist/admin/types.d.mts.map +1 -1
- package/dist/admin/types.mjs +1 -49
- package/dist/fetcher-aq8636lm.cjs +65 -0
- package/dist/fetcher-caoilmfh.d.ts +38 -0
- package/dist/fetcher-caoilmfh.d.ts.map +1 -0
- package/dist/fetcher-letfyywe.js +65 -0
- package/dist/index.cjs +19 -18758
- package/dist/index.d.ts +28078 -27708
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +8 -18727
- package/dist/schemas-abkntf15.js +7543 -0
- package/dist/schemas-c8nj5m3b.cjs +10490 -0
- package/dist/schemas-jfivc3px.cjs +349 -0
- package/dist/schemas-mx94q7di.js +258 -0
- package/dist/types-fb17fnxy.cjs +73 -0
- package/dist/types-pvupsyob.js +63 -0
- package/package.json +9 -10
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# keycloak-api
|
|
2
|
+
|
|
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
|
|
24
|
+
|
|
25
|
+
```ts
|
|
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
|
+
});
|
|
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
|
|
@@ -1,75 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return value !== null && value !== undefined;
|
|
5
|
-
}
|
|
6
|
-
function compactObject(obj) {
|
|
7
|
-
return Object.fromEntries(Object.entries(obj).filter(([, value])=>notEmpty(value)));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function client({ url, method, body, headers, pathParams, queryParams, signal, baseUrl = "", token = null, fetchImpl = fetch }) {
|
|
11
|
-
try {
|
|
12
|
-
const requestHeaders = compactObject({
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
Authorization: token ? `Bearer ${token}` : undefined,
|
|
15
|
-
Accept: "application/json",
|
|
16
|
-
...headers
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* As the fetch API is being used, when multipart/form-data is specified
|
|
20
|
-
* the Content-Type header must be deleted so that the browser can set
|
|
21
|
-
* the correct boundary.
|
|
22
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects#sending_files_using_a_formdata_object
|
|
23
|
-
*/ if (requestHeaders["Content-Type"]?.toLowerCase().includes("multipart/form-data")) {
|
|
24
|
-
delete requestHeaders["Content-Type"];
|
|
25
|
-
}
|
|
26
|
-
const payload = body instanceof FormData ? body : requestHeaders["Content-Type"] === "application/json" ? JSON.stringify(body) : body;
|
|
27
|
-
const fullUrl = `${baseUrl}${resolveUrl(url, queryParams, pathParams)}`;
|
|
28
|
-
const response = await fetchImpl(fullUrl, {
|
|
29
|
-
signal,
|
|
30
|
-
method: method.toUpperCase(),
|
|
31
|
-
body: payload,
|
|
32
|
-
headers: requestHeaders
|
|
33
|
-
});
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
let error;
|
|
36
|
-
try {
|
|
37
|
-
error = await response.json();
|
|
38
|
-
} catch (e) {
|
|
39
|
-
error = {
|
|
40
|
-
status: "unknown",
|
|
41
|
-
payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error"
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
if (response.headers?.get("content-type")?.includes("json")) {
|
|
47
|
-
return await response.json();
|
|
48
|
-
} else {
|
|
49
|
-
// if it is not a json response, assume it is a blob and cast it to TData
|
|
50
|
-
return await response.text();
|
|
51
|
-
}
|
|
52
|
-
} catch (e) {
|
|
53
|
-
const errorObject = {
|
|
54
|
-
name: "unknown",
|
|
55
|
-
message: e instanceof Error ? `Network error (${e.message})` : "Network error",
|
|
56
|
-
stack: e
|
|
57
|
-
};
|
|
58
|
-
throw errorObject;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
62
|
-
let query = new URLSearchParams(queryParams).toString();
|
|
63
|
-
if (query) query = `?${query}`;
|
|
64
|
-
return url.replace(/\{\w*\}/g, (key)=>pathParams[key.slice(1, -1)] ?? "") + query;
|
|
65
|
-
};
|
|
3
|
+
var fetcher = require('../fetcher-aq8636lm.cjs');
|
|
66
4
|
|
|
67
5
|
/**
|
|
68
6
|
* @summary Get account
|
|
69
7
|
* @description Get user details for currently logged in user
|
|
70
8
|
* @link /account/
|
|
71
9
|
*/ async function getAccount({ queryParams, config } = {}) {
|
|
72
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
10
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
73
11
|
const data = await request({
|
|
74
12
|
method: "GET",
|
|
75
13
|
url: `/account/`,
|
|
@@ -85,7 +23,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
85
23
|
* @summary Update account
|
|
86
24
|
* @link /account/
|
|
87
25
|
*/ async function updateAccount({ body, config } = {}) {
|
|
88
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
26
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
89
27
|
const data = await request({
|
|
90
28
|
method: "POST",
|
|
91
29
|
url: `/account/`,
|
|
@@ -101,7 +39,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
101
39
|
* @summary Get applications
|
|
102
40
|
* @link /account/applications
|
|
103
41
|
*/ async function getApplications({ queryParams, config } = {}) {
|
|
104
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
42
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
105
43
|
const data = await request({
|
|
106
44
|
method: "GET",
|
|
107
45
|
url: `/account/applications`,
|
|
@@ -117,7 +55,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
117
55
|
* @summary Get consent
|
|
118
56
|
* @link /account/applications/{clientId}/consent
|
|
119
57
|
*/ async function getConsent({ pathParams, config } = {}) {
|
|
120
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
58
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
121
59
|
if (!pathParams.clientId) {
|
|
122
60
|
throw new Error(`Missing required path parameter: clientId`);
|
|
123
61
|
}
|
|
@@ -135,7 +73,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
135
73
|
* @summary Create consent
|
|
136
74
|
* @link /account/applications/{clientId}/consent
|
|
137
75
|
*/ async function createConsent({ pathParams, config } = {}) {
|
|
138
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
76
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
139
77
|
if (!pathParams.clientId) {
|
|
140
78
|
throw new Error(`Missing required path parameter: clientId`);
|
|
141
79
|
}
|
|
@@ -153,7 +91,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
153
91
|
* @summary Update consent
|
|
154
92
|
* @link /account/applications/{clientId}/consent
|
|
155
93
|
*/ async function updateConsent({ pathParams, config } = {}) {
|
|
156
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
94
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
157
95
|
if (!pathParams.clientId) {
|
|
158
96
|
throw new Error(`Missing required path parameter: clientId`);
|
|
159
97
|
}
|
|
@@ -171,7 +109,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
171
109
|
* @summary Delete consent
|
|
172
110
|
* @link /account/applications/{clientId}/consent
|
|
173
111
|
*/ async function deleteConsent({ pathParams, config } = {}) {
|
|
174
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
112
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
175
113
|
if (!pathParams.clientId) {
|
|
176
114
|
throw new Error(`Missing required path parameter: clientId`);
|
|
177
115
|
}
|
|
@@ -190,7 +128,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
190
128
|
* @description Get credentials for currently logged in user
|
|
191
129
|
* @link /account/credentials
|
|
192
130
|
*/ async function getCredentials({ queryParams, config } = {}) {
|
|
193
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
131
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
194
132
|
const data = await request({
|
|
195
133
|
method: "GET",
|
|
196
134
|
url: `/account/credentials`,
|
|
@@ -206,7 +144,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
206
144
|
* @summary Delete the credential
|
|
207
145
|
* @link /account/credentials/{credentialId}
|
|
208
146
|
*/ async function deleteCredential({ pathParams, config } = {}) {
|
|
209
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
147
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
210
148
|
if (!pathParams.credentialId) {
|
|
211
149
|
throw new Error(`Missing required path parameter: credentialId`);
|
|
212
150
|
}
|
|
@@ -224,7 +162,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
224
162
|
* @summary Update a user label of specified credential of current user
|
|
225
163
|
* @link /account/credentials/{credentialId}/label
|
|
226
164
|
*/ async function updateCredentialLabel({ pathParams, body, config } = {}) {
|
|
227
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
165
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
228
166
|
if (!pathParams.credentialId) {
|
|
229
167
|
throw new Error(`Missing required path parameter: credentialId`);
|
|
230
168
|
}
|
|
@@ -244,7 +182,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
244
182
|
* @description Get sessions for currently logged in user
|
|
245
183
|
* @link /account/sessions
|
|
246
184
|
*/ async function getSessions({ config } = {}) {
|
|
247
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
185
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
248
186
|
const data = await request({
|
|
249
187
|
method: "GET",
|
|
250
188
|
url: `/account/sessions`,
|
|
@@ -259,7 +197,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
259
197
|
* @summary Delete current session
|
|
260
198
|
* @link /account/sessions
|
|
261
199
|
*/ async function deleteCurrentSession({ config } = {}) {
|
|
262
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
200
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
263
201
|
const data = await request({
|
|
264
202
|
method: "DELETE",
|
|
265
203
|
url: `/account/sessions`,
|
|
@@ -275,7 +213,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
275
213
|
* @description Get devices for currently logged in user
|
|
276
214
|
* @link /account/sessions/devices
|
|
277
215
|
*/ async function getDevices({ config } = {}) {
|
|
278
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
216
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
279
217
|
const data = await request({
|
|
280
218
|
method: "GET",
|
|
281
219
|
url: `/account/sessions/devices`,
|
|
@@ -290,7 +228,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
290
228
|
* @summary Delete the session
|
|
291
229
|
* @link /account/sessions/{sessionId}
|
|
292
230
|
*/ async function deleteSession({ pathParams, config } = {}) {
|
|
293
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
231
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
294
232
|
if (!pathParams.sessionId) {
|
|
295
233
|
throw new Error(`Missing required path parameter: sessionId`);
|
|
296
234
|
}
|
|
@@ -309,7 +247,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
309
247
|
* @description Get linked accounts for currently logged in user
|
|
310
248
|
* @link /account/linked-accounts
|
|
311
249
|
*/ async function getLinkedAccounts({ config } = {}) {
|
|
312
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
250
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
313
251
|
const data = await request({
|
|
314
252
|
method: "GET",
|
|
315
253
|
url: `/account/linked-accounts`,
|
|
@@ -325,7 +263,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
325
263
|
* @description Build account linking URI
|
|
326
264
|
* @link /account/linked-accounts/{providerId}
|
|
327
265
|
*/ async function buildLinkingUri({ pathParams, queryParams, config } = {}) {
|
|
328
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
266
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
329
267
|
if (!pathParams.providerId) {
|
|
330
268
|
throw new Error(`Missing required path parameter: providerId`);
|
|
331
269
|
}
|
|
@@ -344,7 +282,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
344
282
|
* @summary Delete the linked provider
|
|
345
283
|
* @link /account/linked-accounts/{providerId}
|
|
346
284
|
*/ async function deleteLinkedProvider({ pathParams, config } = {}) {
|
|
347
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
285
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
348
286
|
if (!pathParams.providerId) {
|
|
349
287
|
throw new Error(`Missing required path parameter: providerId`);
|
|
350
288
|
}
|
|
@@ -362,7 +300,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
362
300
|
* @summary Get groups that this user is a member of
|
|
363
301
|
* @link /account/groups
|
|
364
302
|
*/ async function getGroups({ queryParams, config } = {}) {
|
|
365
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
303
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
366
304
|
const data = await request({
|
|
367
305
|
method: "GET",
|
|
368
306
|
url: `/account/groups`,
|
|
@@ -379,7 +317,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
|
|
|
379
317
|
* @description Get organizations for currently logged in user
|
|
380
318
|
* @link /account/organizations
|
|
381
319
|
*/ async function getOrganizations({ config } = {}) {
|
|
382
|
-
const { client: request = client, ...requestConfig } = config ?? {};
|
|
320
|
+
const { client: request = fetcher.client, ...requestConfig } = config ?? {};
|
|
383
321
|
const data = await request({
|
|
384
322
|
method: "GET",
|
|
385
323
|
url: `/account/organizations`,
|
|
@@ -412,7 +350,7 @@ const operationsByPath = {
|
|
|
412
350
|
"GET /account/organizations": getOrganizations
|
|
413
351
|
};
|
|
414
352
|
const operationsByTag = {
|
|
415
|
-
|
|
353
|
+
account: {
|
|
416
354
|
getAccount,
|
|
417
355
|
updateAccount,
|
|
418
356
|
getApplications,
|
|
@@ -435,8 +373,8 @@ const operationsByTag = {
|
|
|
435
373
|
}
|
|
436
374
|
};
|
|
437
375
|
const tagDictionary = {
|
|
438
|
-
|
|
439
|
-
|
|
376
|
+
account: {
|
|
377
|
+
GET: [
|
|
440
378
|
"getAccount",
|
|
441
379
|
"getApplications",
|
|
442
380
|
"getConsent",
|
|
@@ -448,15 +386,15 @@ const tagDictionary = {
|
|
|
448
386
|
"getGroups",
|
|
449
387
|
"getOrganizations"
|
|
450
388
|
],
|
|
451
|
-
|
|
389
|
+
POST: [
|
|
452
390
|
"updateAccount",
|
|
453
391
|
"createConsent"
|
|
454
392
|
],
|
|
455
|
-
|
|
393
|
+
PUT: [
|
|
456
394
|
"updateConsent",
|
|
457
395
|
"updateCredentialLabel"
|
|
458
396
|
],
|
|
459
|
-
|
|
397
|
+
DELETE: [
|
|
460
398
|
"deleteConsent",
|
|
461
399
|
"deleteCredential",
|
|
462
400
|
"deleteCurrentSession",
|