keycloak-api 0.2.5 → 1.0.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.
@@ -0,0 +1,490 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ function notEmpty(value) {
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
+ };
66
+
67
+ /**
68
+ * @summary Get account
69
+ * @description Get user details for currently logged in user
70
+ * @link /account/
71
+ */ async function getAccount({ queryParams, config } = {}) {
72
+ const { client: request = client, ...requestConfig } = config ?? {};
73
+ const data = await request({
74
+ method: "GET",
75
+ url: `/account/`,
76
+ queryParams,
77
+ ...requestConfig,
78
+ headers: {
79
+ ...requestConfig.headers
80
+ }
81
+ });
82
+ return data;
83
+ }
84
+ /**
85
+ * @summary Update account
86
+ * @link /account/
87
+ */ async function updateAccount({ body, config } = {}) {
88
+ const { client: request = client, ...requestConfig } = config ?? {};
89
+ const data = await request({
90
+ method: "POST",
91
+ url: `/account/`,
92
+ body: body,
93
+ ...requestConfig,
94
+ headers: {
95
+ ...requestConfig.headers
96
+ }
97
+ });
98
+ return data;
99
+ }
100
+ /**
101
+ * @summary Get applications
102
+ * @link /account/applications
103
+ */ async function getApplications({ queryParams, config } = {}) {
104
+ const { client: request = client, ...requestConfig } = config ?? {};
105
+ const data = await request({
106
+ method: "GET",
107
+ url: `/account/applications`,
108
+ queryParams,
109
+ ...requestConfig,
110
+ headers: {
111
+ ...requestConfig.headers
112
+ }
113
+ });
114
+ return data;
115
+ }
116
+ /**
117
+ * @summary Get consent
118
+ * @link /account/applications/{clientId}/consent
119
+ */ async function getConsent({ pathParams, config } = {}) {
120
+ const { client: request = client, ...requestConfig } = config ?? {};
121
+ if (!pathParams.clientId) {
122
+ throw new Error(`Missing required path parameter: clientId`);
123
+ }
124
+ const data = await request({
125
+ method: "GET",
126
+ url: `/account/applications/${pathParams.clientId}/consent`,
127
+ ...requestConfig,
128
+ headers: {
129
+ ...requestConfig.headers
130
+ }
131
+ });
132
+ return data;
133
+ }
134
+ /**
135
+ * @summary Create consent
136
+ * @link /account/applications/{clientId}/consent
137
+ */ async function createConsent({ pathParams, config } = {}) {
138
+ const { client: request = client, ...requestConfig } = config ?? {};
139
+ if (!pathParams.clientId) {
140
+ throw new Error(`Missing required path parameter: clientId`);
141
+ }
142
+ const data = await request({
143
+ method: "POST",
144
+ url: `/account/applications/${pathParams.clientId}/consent`,
145
+ ...requestConfig,
146
+ headers: {
147
+ ...requestConfig.headers
148
+ }
149
+ });
150
+ return data;
151
+ }
152
+ /**
153
+ * @summary Update consent
154
+ * @link /account/applications/{clientId}/consent
155
+ */ async function updateConsent({ pathParams, config } = {}) {
156
+ const { client: request = client, ...requestConfig } = config ?? {};
157
+ if (!pathParams.clientId) {
158
+ throw new Error(`Missing required path parameter: clientId`);
159
+ }
160
+ const data = await request({
161
+ method: "PUT",
162
+ url: `/account/applications/${pathParams.clientId}/consent`,
163
+ ...requestConfig,
164
+ headers: {
165
+ ...requestConfig.headers
166
+ }
167
+ });
168
+ return data;
169
+ }
170
+ /**
171
+ * @summary Delete consent
172
+ * @link /account/applications/{clientId}/consent
173
+ */ async function deleteConsent({ pathParams, config } = {}) {
174
+ const { client: request = client, ...requestConfig } = config ?? {};
175
+ if (!pathParams.clientId) {
176
+ throw new Error(`Missing required path parameter: clientId`);
177
+ }
178
+ const data = await request({
179
+ method: "DELETE",
180
+ url: `/account/applications/${pathParams.clientId}/consent`,
181
+ ...requestConfig,
182
+ headers: {
183
+ ...requestConfig.headers
184
+ }
185
+ });
186
+ return data;
187
+ }
188
+ /**
189
+ * @summary Get credentials
190
+ * @description Get credentials for currently logged in user
191
+ * @link /account/credentials
192
+ */ async function getCredentials({ queryParams, config } = {}) {
193
+ const { client: request = client, ...requestConfig } = config ?? {};
194
+ const data = await request({
195
+ method: "GET",
196
+ url: `/account/credentials`,
197
+ queryParams,
198
+ ...requestConfig,
199
+ headers: {
200
+ ...requestConfig.headers
201
+ }
202
+ });
203
+ return data;
204
+ }
205
+ /**
206
+ * @summary Delete the credential
207
+ * @link /account/credentials/{credentialId}
208
+ */ async function deleteCredential({ pathParams, config } = {}) {
209
+ const { client: request = client, ...requestConfig } = config ?? {};
210
+ if (!pathParams.credentialId) {
211
+ throw new Error(`Missing required path parameter: credentialId`);
212
+ }
213
+ const data = await request({
214
+ method: "DELETE",
215
+ url: `/account/credentials/${pathParams.credentialId}`,
216
+ ...requestConfig,
217
+ headers: {
218
+ ...requestConfig.headers
219
+ }
220
+ });
221
+ return data;
222
+ }
223
+ /**
224
+ * @summary Update a user label of specified credential of current user
225
+ * @link /account/credentials/{credentialId}/label
226
+ */ async function updateCredentialLabel({ pathParams, body, config } = {}) {
227
+ const { client: request = client, ...requestConfig } = config ?? {};
228
+ if (!pathParams.credentialId) {
229
+ throw new Error(`Missing required path parameter: credentialId`);
230
+ }
231
+ const data = await request({
232
+ method: "PUT",
233
+ url: `/account/credentials/${pathParams.credentialId}/label`,
234
+ body: body,
235
+ ...requestConfig,
236
+ headers: {
237
+ ...requestConfig.headers
238
+ }
239
+ });
240
+ return data;
241
+ }
242
+ /**
243
+ * @summary Get sessions
244
+ * @description Get sessions for currently logged in user
245
+ * @link /account/sessions
246
+ */ async function getSessions({ config } = {}) {
247
+ const { client: request = client, ...requestConfig } = config ?? {};
248
+ const data = await request({
249
+ method: "GET",
250
+ url: `/account/sessions`,
251
+ ...requestConfig,
252
+ headers: {
253
+ ...requestConfig.headers
254
+ }
255
+ });
256
+ return data;
257
+ }
258
+ /**
259
+ * @summary Delete current session
260
+ * @link /account/sessions
261
+ */ async function deleteCurrentSession({ config } = {}) {
262
+ const { client: request = client, ...requestConfig } = config ?? {};
263
+ const data = await request({
264
+ method: "DELETE",
265
+ url: `/account/sessions`,
266
+ ...requestConfig,
267
+ headers: {
268
+ ...requestConfig.headers
269
+ }
270
+ });
271
+ return data;
272
+ }
273
+ /**
274
+ * @summary Get devices
275
+ * @description Get devices for currently logged in user
276
+ * @link /account/sessions/devices
277
+ */ async function getDevices({ config } = {}) {
278
+ const { client: request = client, ...requestConfig } = config ?? {};
279
+ const data = await request({
280
+ method: "GET",
281
+ url: `/account/sessions/devices`,
282
+ ...requestConfig,
283
+ headers: {
284
+ ...requestConfig.headers
285
+ }
286
+ });
287
+ return data;
288
+ }
289
+ /**
290
+ * @summary Delete the session
291
+ * @link /account/sessions/{sessionId}
292
+ */ async function deleteSession({ pathParams, config } = {}) {
293
+ const { client: request = client, ...requestConfig } = config ?? {};
294
+ if (!pathParams.sessionId) {
295
+ throw new Error(`Missing required path parameter: sessionId`);
296
+ }
297
+ const data = await request({
298
+ method: "DELETE",
299
+ url: `/account/sessions/${pathParams.sessionId}`,
300
+ ...requestConfig,
301
+ headers: {
302
+ ...requestConfig.headers
303
+ }
304
+ });
305
+ return data;
306
+ }
307
+ /**
308
+ * @summary Get linked accounts
309
+ * @description Get linked accounts for currently logged in user
310
+ * @link /account/linked-accounts
311
+ */ async function getLinkedAccounts({ config } = {}) {
312
+ const { client: request = client, ...requestConfig } = config ?? {};
313
+ const data = await request({
314
+ method: "GET",
315
+ url: `/account/linked-accounts`,
316
+ ...requestConfig,
317
+ headers: {
318
+ ...requestConfig.headers
319
+ }
320
+ });
321
+ return data;
322
+ }
323
+ /**
324
+ * @summary Build account linking URI
325
+ * @description Build account linking URI
326
+ * @link /account/linked-accounts/{providerId}
327
+ */ async function buildLinkingUri({ pathParams, queryParams, config } = {}) {
328
+ const { client: request = client, ...requestConfig } = config ?? {};
329
+ if (!pathParams.providerId) {
330
+ throw new Error(`Missing required path parameter: providerId`);
331
+ }
332
+ const data = await request({
333
+ method: "GET",
334
+ url: `/account/linked-accounts/${pathParams.providerId}`,
335
+ queryParams,
336
+ ...requestConfig,
337
+ headers: {
338
+ ...requestConfig.headers
339
+ }
340
+ });
341
+ return data;
342
+ }
343
+ /**
344
+ * @summary Delete the linked provider
345
+ * @link /account/linked-accounts/{providerId}
346
+ */ async function deleteLinkedProvider({ pathParams, config } = {}) {
347
+ const { client: request = client, ...requestConfig } = config ?? {};
348
+ if (!pathParams.providerId) {
349
+ throw new Error(`Missing required path parameter: providerId`);
350
+ }
351
+ const data = await request({
352
+ method: "DELETE",
353
+ url: `/account/linked-accounts/${pathParams.providerId}`,
354
+ ...requestConfig,
355
+ headers: {
356
+ ...requestConfig.headers
357
+ }
358
+ });
359
+ return data;
360
+ }
361
+ /**
362
+ * @summary Get groups that this user is a member of
363
+ * @link /account/groups
364
+ */ async function getGroups({ queryParams, config } = {}) {
365
+ const { client: request = client, ...requestConfig } = config ?? {};
366
+ const data = await request({
367
+ method: "GET",
368
+ url: `/account/groups`,
369
+ queryParams,
370
+ ...requestConfig,
371
+ headers: {
372
+ ...requestConfig.headers
373
+ }
374
+ });
375
+ return data;
376
+ }
377
+ /**
378
+ * @summary Get organizations
379
+ * @description Get organizations for currently logged in user
380
+ * @link /account/organizations
381
+ */ async function getOrganizations({ config } = {}) {
382
+ const { client: request = client, ...requestConfig } = config ?? {};
383
+ const data = await request({
384
+ method: "GET",
385
+ url: `/account/organizations`,
386
+ ...requestConfig,
387
+ headers: {
388
+ ...requestConfig.headers
389
+ }
390
+ });
391
+ return data;
392
+ }
393
+ const operationsByPath = {
394
+ "GET /account/": getAccount,
395
+ "POST /account/": updateAccount,
396
+ "GET /account/applications": getApplications,
397
+ "GET /account/applications/{clientId}/consent": getConsent,
398
+ "POST /account/applications/{clientId}/consent": createConsent,
399
+ "PUT /account/applications/{clientId}/consent": updateConsent,
400
+ "DELETE /account/applications/{clientId}/consent": deleteConsent,
401
+ "GET /account/credentials": getCredentials,
402
+ "DELETE /account/credentials/{credentialId}": deleteCredential,
403
+ "PUT /account/credentials/{credentialId}/label": updateCredentialLabel,
404
+ "GET /account/sessions": getSessions,
405
+ "DELETE /account/sessions": deleteCurrentSession,
406
+ "GET /account/sessions/devices": getDevices,
407
+ "DELETE /account/sessions/{sessionId}": deleteSession,
408
+ "GET /account/linked-accounts": getLinkedAccounts,
409
+ "GET /account/linked-accounts/{providerId}": buildLinkingUri,
410
+ "DELETE /account/linked-accounts/{providerId}": deleteLinkedProvider,
411
+ "GET /account/groups": getGroups,
412
+ "GET /account/organizations": getOrganizations
413
+ };
414
+ const operationsByTag = {
415
+ "account": {
416
+ getAccount,
417
+ updateAccount,
418
+ getApplications,
419
+ getConsent,
420
+ createConsent,
421
+ updateConsent,
422
+ deleteConsent,
423
+ getCredentials,
424
+ deleteCredential,
425
+ updateCredentialLabel,
426
+ getSessions,
427
+ deleteCurrentSession,
428
+ getDevices,
429
+ deleteSession,
430
+ getLinkedAccounts,
431
+ buildLinkingUri,
432
+ deleteLinkedProvider,
433
+ getGroups,
434
+ getOrganizations
435
+ }
436
+ };
437
+ const tagDictionary = {
438
+ "account": {
439
+ "GET": [
440
+ "getAccount",
441
+ "getApplications",
442
+ "getConsent",
443
+ "getCredentials",
444
+ "getSessions",
445
+ "getDevices",
446
+ "getLinkedAccounts",
447
+ "buildLinkingUri",
448
+ "getGroups",
449
+ "getOrganizations"
450
+ ],
451
+ "POST": [
452
+ "updateAccount",
453
+ "createConsent"
454
+ ],
455
+ "PUT": [
456
+ "updateConsent",
457
+ "updateCredentialLabel"
458
+ ],
459
+ "DELETE": [
460
+ "deleteConsent",
461
+ "deleteCredential",
462
+ "deleteCurrentSession",
463
+ "deleteSession",
464
+ "deleteLinkedProvider"
465
+ ]
466
+ }
467
+ };
468
+
469
+ exports.buildLinkingUri = buildLinkingUri;
470
+ exports.createConsent = createConsent;
471
+ exports.deleteConsent = deleteConsent;
472
+ exports.deleteCredential = deleteCredential;
473
+ exports.deleteCurrentSession = deleteCurrentSession;
474
+ exports.deleteLinkedProvider = deleteLinkedProvider;
475
+ exports.deleteSession = deleteSession;
476
+ exports.getAccount = getAccount;
477
+ exports.getApplications = getApplications;
478
+ exports.getConsent = getConsent;
479
+ exports.getCredentials = getCredentials;
480
+ exports.getDevices = getDevices;
481
+ exports.getGroups = getGroups;
482
+ exports.getLinkedAccounts = getLinkedAccounts;
483
+ exports.getOrganizations = getOrganizations;
484
+ exports.getSessions = getSessions;
485
+ exports.operationsByPath = operationsByPath;
486
+ exports.operationsByTag = operationsByTag;
487
+ exports.tagDictionary = tagDictionary;
488
+ exports.updateAccount = updateAccount;
489
+ exports.updateConsent = updateConsent;
490
+ exports.updateCredentialLabel = updateCredentialLabel;