@adatechnology/keycloak-admin 0.1.0 → 0.1.2

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,89 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+
3
+ export interface KeycloakAdminConfig {
4
+ baseUrl: string;
5
+ realm: string;
6
+ adminUser: string;
7
+ adminPassword: string;
8
+ }
9
+
10
+ export interface GetAdminTokenResult {
11
+ accessToken: string;
12
+ expiresIn: number;
13
+ tokenType: string;
14
+ }
15
+
16
+ export interface UpdateUserParams {
17
+ userId: string;
18
+ userData: Record<string, unknown>;
19
+ adminToken: string;
20
+ }
21
+
22
+ export interface ResetPasswordParams {
23
+ userId: string;
24
+ password: string;
25
+ temporary: boolean;
26
+ adminToken: string;
27
+ }
28
+
29
+ export interface ToggleUserEnabledParams {
30
+ userId: string;
31
+ enabled: boolean;
32
+ adminToken: string;
33
+ }
34
+
35
+ export interface DeleteUserParams {
36
+ userId: string;
37
+ adminToken: string;
38
+ }
39
+
40
+ export interface UpdateUserAttributesParams {
41
+ userId: string;
42
+ attributes: Record<string, string | string[]>;
43
+ adminToken: string;
44
+ }
45
+
46
+ export interface SendVerifyEmailParams {
47
+ userId: string;
48
+ adminToken: string;
49
+ }
50
+
51
+ export interface KeycloakAdminClientInterface {
52
+ getAdminToken(): Promise<GetAdminTokenResult>;
53
+ updateUser(params: UpdateUserParams): Promise<void>;
54
+ resetPassword(params: ResetPasswordParams): Promise<void>;
55
+ toggleUserEnabled(params: ToggleUserEnabledParams): Promise<void>;
56
+ deleteUser(params: DeleteUserParams): Promise<void>;
57
+ updateUserAttributes(params: UpdateUserAttributesParams): Promise<void>;
58
+ sendVerifyEmail(params: SendVerifyEmailParams): Promise<void>;
59
+ }
60
+
61
+ export class KeycloakAdminError extends Error {
62
+ readonly statusCode?: number;
63
+ readonly code?: string;
64
+ readonly context?: Record<string, unknown>;
65
+ constructor(params: {
66
+ message: string;
67
+ statusCode?: number;
68
+ code?: string;
69
+ context?: Record<string, unknown>;
70
+ });
71
+ }
72
+
73
+ export class KeycloakAdminClient implements KeycloakAdminClientInterface {
74
+ getAdminToken(): Promise<GetAdminTokenResult>;
75
+ updateUser(params: UpdateUserParams): Promise<void>;
76
+ resetPassword(params: ResetPasswordParams): Promise<void>;
77
+ toggleUserEnabled(params: ToggleUserEnabledParams): Promise<void>;
78
+ deleteUser(params: DeleteUserParams): Promise<void>;
79
+ updateUserAttributes(params: UpdateUserAttributesParams): Promise<void>;
80
+ sendVerifyEmail(params: SendVerifyEmailParams): Promise<void>;
81
+ }
82
+
83
+ export class KeycloakAdminModule {
84
+ static forRoot(config: KeycloakAdminConfig): DynamicModule;
85
+ }
86
+
87
+ export const KEYCLOAK_ADMIN_CLIENT = "KEYCLOAK_ADMIN_CLIENT";
88
+ export const KEYCLOAK_ADMIN_CONFIG = "KEYCLOAK_ADMIN_CONFIG";
89
+ export const KEYCLOAK_ADMIN_PROVIDER = "KEYCLOAK_ADMIN_PROVIDER";
package/dist/index.js ADDED
@@ -0,0 +1,542 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ KEYCLOAK_ADMIN_CLIENT: () => KEYCLOAK_ADMIN_CLIENT,
24
+ KEYCLOAK_ADMIN_CONFIG: () => KEYCLOAK_ADMIN_CONFIG,
25
+ KEYCLOAK_ADMIN_PROVIDER: () => KEYCLOAK_ADMIN_PROVIDER,
26
+ KeycloakAdminClient: () => KeycloakAdminClient,
27
+ KeycloakAdminModule: () => KeycloakAdminModule
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+
31
+ // src/keycloak-admin.module.ts
32
+ var import_common2 = require("@nestjs/common");
33
+ var import_http_client2 = require("@adatechnology/http-client");
34
+
35
+ // src/keycloak-admin.token.ts
36
+ var KEYCLOAK_ADMIN_CLIENT = "KEYCLOAK_ADMIN_CLIENT";
37
+ var KEYCLOAK_ADMIN_CONFIG = "KEYCLOAK_ADMIN_CONFIG";
38
+ var KEYCLOAK_ADMIN_PROVIDER = "KEYCLOAK_ADMIN_PROVIDER";
39
+
40
+ // src/keycloak-admin.client.ts
41
+ var import_common = require("@nestjs/common");
42
+ var import_http_client = require("@adatechnology/http-client");
43
+ var import_logger = require("@adatechnology/logger");
44
+
45
+ // src/errors/keycloak-admin.error.ts
46
+ var _KeycloakAdminError = class _KeycloakAdminError extends Error {
47
+ statusCode;
48
+ code;
49
+ context;
50
+ constructor(params) {
51
+ super(params.message);
52
+ this.name = "KeycloakAdminError";
53
+ this.statusCode = params.statusCode;
54
+ this.code = params.code;
55
+ this.context = params.context;
56
+ Object.setPrototypeOf(this, _KeycloakAdminError.prototype);
57
+ }
58
+ };
59
+ __name(_KeycloakAdminError, "KeycloakAdminError");
60
+ var KeycloakAdminError = _KeycloakAdminError;
61
+
62
+ // src/constants/keycloak-admin.constants.ts
63
+ var KEYCLOAK_ADMIN_LIB_NAME = "@adatechnology/keycloak-admin";
64
+ var KEYCLOAK_ADMIN_LIB_VERSION = "0.1.2";
65
+ var KEYCLOAK_ADMIN_GRANT_TYPE_PASSWORD = "password";
66
+ var KEYCLOAK_ADMIN_CLIENT_ID_ADMIN_CLI = "admin-cli";
67
+ var KEYCLOAK_ADMIN_CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";
68
+ var KEYCLOAK_ADMIN_CONTENT_TYPE_JSON = "application/json";
69
+ var KEYCLOAK_ADMIN_AUTHORIZATION_HEADER = "Authorization";
70
+ var KEYCLOAK_ADMIN_BEARER_PREFIX = "Bearer ";
71
+ var KEYCLOAK_ADMIN_ENDPOINTS = {
72
+ MASTER_TOKEN: "/realms/master/protocol/openid-connect/token",
73
+ ADMIN_USERS: /* @__PURE__ */ __name((baseUrl, realm, userId) => `${baseUrl}/admin/realms/${realm}/users/${userId}`, "ADMIN_USERS"),
74
+ ADMIN_RESET_PASSWORD: /* @__PURE__ */ __name((baseUrl, realm, userId) => `${baseUrl}/admin/realms/${realm}/users/${userId}/reset-password`, "ADMIN_RESET_PASSWORD"),
75
+ ADMIN_SEND_VERIFY_EMAIL: /* @__PURE__ */ __name((baseUrl, realm, userId) => `${baseUrl}/admin/realms/${realm}/users/${userId}/send-verify-email`, "ADMIN_SEND_VERIFY_EMAIL")
76
+ };
77
+ var KEYCLOAK_ADMIN_ERROR_CODES = {
78
+ ADMIN_TOKEN_ERROR: "KEYCLOAK_ADMIN_TOKEN_ERROR",
79
+ UPDATE_USER_ERROR: "KEYCLOAK_UPDATE_USER_ERROR",
80
+ RESET_PASSWORD_ERROR: "KEYCLOAK_RESET_PASSWORD_ERROR",
81
+ TOGGLE_ENABLED_ERROR: "KEYCLOAK_TOGGLE_ENABLED_ERROR",
82
+ DELETE_USER_ERROR: "KEYCLOAK_DELETE_USER_ERROR",
83
+ UPDATE_ATTRIBUTES_ERROR: "KEYCLOAK_UPDATE_ATTRIBUTES_ERROR",
84
+ SEND_VERIFY_EMAIL_ERROR: "KEYCLOAK_SEND_VERIFY_EMAIL_ERROR"
85
+ };
86
+
87
+ // src/utils/extract-http-error.ts
88
+ function extractHttpError(err) {
89
+ const unknownErr = err;
90
+ const response = unknownErr == null ? void 0 : unknownErr.response;
91
+ const responseData = response == null ? void 0 : response.data;
92
+ let statusCode = void 0;
93
+ if (typeof (unknownErr == null ? void 0 : unknownErr.status) === "number") {
94
+ statusCode = unknownErr.status;
95
+ } else if (typeof (response == null ? void 0 : response.status) === "number") {
96
+ statusCode = response.status;
97
+ }
98
+ const details = responseData ?? (unknownErr == null ? void 0 : unknownErr.message);
99
+ const rawError = (responseData == null ? void 0 : responseData.error) ?? (responseData == null ? void 0 : responseData.errorMessage);
100
+ const errorCode = typeof rawError === "string" ? rawError : typeof (unknownErr == null ? void 0 : unknownErr.code) === "string" ? unknownErr.code : void 0;
101
+ return {
102
+ statusCode,
103
+ details,
104
+ errorCode
105
+ };
106
+ }
107
+ __name(extractHttpError, "extractHttpError");
108
+
109
+ // src/keycloak-admin.client.ts
110
+ function _ts_decorate(decorators, target, key, desc) {
111
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
112
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
113
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
114
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
115
+ }
116
+ __name(_ts_decorate, "_ts_decorate");
117
+ function _ts_metadata(k, v) {
118
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
119
+ }
120
+ __name(_ts_metadata, "_ts_metadata");
121
+ function _ts_param(paramIndex, decorator) {
122
+ return function(target, key) {
123
+ decorator(target, key, paramIndex);
124
+ };
125
+ }
126
+ __name(_ts_param, "_ts_param");
127
+ var _KeycloakAdminClient = class _KeycloakAdminClient {
128
+ config;
129
+ httpProvider;
130
+ logger;
131
+ className = this.constructor.name;
132
+ constructor(config, httpProvider, logger) {
133
+ this.config = config;
134
+ this.httpProvider = httpProvider;
135
+ this.logger = logger;
136
+ }
137
+ log(level, message, libMethod, meta) {
138
+ if (!this.logger) return;
139
+ const payload = {
140
+ message,
141
+ context: this.className,
142
+ lib: KEYCLOAK_ADMIN_LIB_NAME,
143
+ libVersion: KEYCLOAK_ADMIN_LIB_VERSION,
144
+ libMethod,
145
+ meta
146
+ };
147
+ if (level === "info") this.logger.info(payload);
148
+ else if (level === "warn") this.logger.warn(payload);
149
+ else if (level === "error") this.logger.error(payload);
150
+ }
151
+ async getAdminToken() {
152
+ const method = "getAdminToken";
153
+ this.log("info", `${method} - Start`, method, {
154
+ realm: this.config.realm
155
+ });
156
+ const url = `${this.config.baseUrl}${KEYCLOAK_ADMIN_ENDPOINTS.MASTER_TOKEN}`;
157
+ const body = new URLSearchParams();
158
+ body.append("grant_type", KEYCLOAK_ADMIN_GRANT_TYPE_PASSWORD);
159
+ body.append("client_id", KEYCLOAK_ADMIN_CLIENT_ID_ADMIN_CLI);
160
+ body.append("username", this.config.adminUser);
161
+ body.append("password", this.config.adminPassword);
162
+ try {
163
+ const response = await this.httpProvider.post({
164
+ url,
165
+ data: body,
166
+ config: {
167
+ headers: {
168
+ "Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_FORM
169
+ }
170
+ }
171
+ });
172
+ const result = {
173
+ accessToken: response.data.access_token,
174
+ expiresIn: response.data.expires_in,
175
+ tokenType: response.data.token_type
176
+ };
177
+ this.log("info", `${method} - Success`, method);
178
+ return result;
179
+ } catch (err) {
180
+ const { statusCode, details, errorCode } = extractHttpError(err);
181
+ this.log("error", `${method} - Failed`, method, {
182
+ statusCode,
183
+ errorCode
184
+ });
185
+ throw new KeycloakAdminError({
186
+ message: "Keycloak admin token request failed",
187
+ statusCode: statusCode ?? 502,
188
+ code: KEYCLOAK_ADMIN_ERROR_CODES.ADMIN_TOKEN_ERROR,
189
+ context: {
190
+ url,
191
+ method: "POST",
192
+ details,
193
+ errorCode
194
+ }
195
+ });
196
+ }
197
+ }
198
+ async updateUser(params) {
199
+ const method = "updateUser";
200
+ const { userId, userData, adminToken } = params;
201
+ this.log("info", `${method} - Start`, method, {
202
+ userId
203
+ });
204
+ const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_USERS(this.config.baseUrl, this.config.realm, userId);
205
+ try {
206
+ await this.httpProvider.put({
207
+ url,
208
+ data: userData,
209
+ config: {
210
+ headers: {
211
+ [KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`,
212
+ "Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_JSON
213
+ }
214
+ }
215
+ });
216
+ this.log("info", `${method} - Success`, method, {
217
+ userId
218
+ });
219
+ } catch (err) {
220
+ const { statusCode, details, errorCode } = extractHttpError(err);
221
+ this.log("error", `${method} - Failed`, method, {
222
+ userId,
223
+ statusCode,
224
+ errorCode
225
+ });
226
+ throw new KeycloakAdminError({
227
+ message: "Keycloak update user failed",
228
+ statusCode: statusCode ?? 502,
229
+ code: KEYCLOAK_ADMIN_ERROR_CODES.UPDATE_USER_ERROR,
230
+ context: {
231
+ url,
232
+ method: "PUT",
233
+ userId,
234
+ details,
235
+ errorCode
236
+ }
237
+ });
238
+ }
239
+ }
240
+ async resetPassword(params) {
241
+ const method = "resetPassword";
242
+ const { userId, password, temporary, adminToken } = params;
243
+ this.log("info", `${method} - Start`, method, {
244
+ userId,
245
+ temporary
246
+ });
247
+ const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_RESET_PASSWORD(this.config.baseUrl, this.config.realm, userId);
248
+ try {
249
+ await this.httpProvider.put({
250
+ url,
251
+ data: {
252
+ type: "password",
253
+ value: password,
254
+ temporary
255
+ },
256
+ config: {
257
+ headers: {
258
+ [KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`,
259
+ "Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_JSON
260
+ }
261
+ }
262
+ });
263
+ this.log("info", `${method} - Success`, method, {
264
+ userId
265
+ });
266
+ } catch (err) {
267
+ const { statusCode, details, errorCode } = extractHttpError(err);
268
+ this.log("error", `${method} - Failed`, method, {
269
+ userId,
270
+ statusCode,
271
+ errorCode
272
+ });
273
+ throw new KeycloakAdminError({
274
+ message: "Keycloak reset password failed",
275
+ statusCode: statusCode ?? 502,
276
+ code: KEYCLOAK_ADMIN_ERROR_CODES.RESET_PASSWORD_ERROR,
277
+ context: {
278
+ url,
279
+ method: "PUT",
280
+ userId,
281
+ details,
282
+ errorCode
283
+ }
284
+ });
285
+ }
286
+ }
287
+ async toggleUserEnabled(params) {
288
+ const method = "toggleUserEnabled";
289
+ const { userId, enabled, adminToken } = params;
290
+ this.log("info", `${method} - Start`, method, {
291
+ userId,
292
+ enabled
293
+ });
294
+ const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_USERS(this.config.baseUrl, this.config.realm, userId);
295
+ try {
296
+ await this.httpProvider.put({
297
+ url,
298
+ data: {
299
+ enabled
300
+ },
301
+ config: {
302
+ headers: {
303
+ [KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`,
304
+ "Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_JSON
305
+ }
306
+ }
307
+ });
308
+ this.log("info", `${method} - Success`, method, {
309
+ userId,
310
+ enabled
311
+ });
312
+ } catch (err) {
313
+ const { statusCode, details, errorCode } = extractHttpError(err);
314
+ this.log("error", `${method} - Failed`, method, {
315
+ userId,
316
+ enabled,
317
+ statusCode,
318
+ errorCode
319
+ });
320
+ throw new KeycloakAdminError({
321
+ message: "Keycloak toggle user enabled failed",
322
+ statusCode: statusCode ?? 502,
323
+ code: KEYCLOAK_ADMIN_ERROR_CODES.TOGGLE_ENABLED_ERROR,
324
+ context: {
325
+ url,
326
+ method: "PUT",
327
+ userId,
328
+ enabled,
329
+ details,
330
+ errorCode
331
+ }
332
+ });
333
+ }
334
+ }
335
+ async deleteUser(params) {
336
+ const method = "deleteUser";
337
+ const { userId, adminToken } = params;
338
+ this.log("info", `${method} - Start`, method, {
339
+ userId
340
+ });
341
+ const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_USERS(this.config.baseUrl, this.config.realm, userId);
342
+ try {
343
+ await this.httpProvider.delete({
344
+ url,
345
+ config: {
346
+ headers: {
347
+ [KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`
348
+ }
349
+ }
350
+ });
351
+ this.log("info", `${method} - Success`, method, {
352
+ userId
353
+ });
354
+ } catch (err) {
355
+ const { statusCode, details, errorCode } = extractHttpError(err);
356
+ this.log("error", `${method} - Failed`, method, {
357
+ userId,
358
+ statusCode,
359
+ errorCode
360
+ });
361
+ throw new KeycloakAdminError({
362
+ message: "Keycloak delete user failed",
363
+ statusCode: statusCode ?? 502,
364
+ code: KEYCLOAK_ADMIN_ERROR_CODES.DELETE_USER_ERROR,
365
+ context: {
366
+ url,
367
+ method: "DELETE",
368
+ userId,
369
+ details,
370
+ errorCode
371
+ }
372
+ });
373
+ }
374
+ }
375
+ async updateUserAttributes(params) {
376
+ const method = "updateUserAttributes";
377
+ const { userId, attributes, adminToken } = params;
378
+ this.log("info", `${method} - Start`, method, {
379
+ userId,
380
+ attributeKeys: Object.keys(attributes)
381
+ });
382
+ const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_USERS(this.config.baseUrl, this.config.realm, userId);
383
+ try {
384
+ await this.httpProvider.put({
385
+ url,
386
+ data: {
387
+ attributes
388
+ },
389
+ config: {
390
+ headers: {
391
+ [KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`,
392
+ "Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_JSON
393
+ }
394
+ }
395
+ });
396
+ this.log("info", `${method} - Success`, method, {
397
+ userId
398
+ });
399
+ } catch (err) {
400
+ const { statusCode, details, errorCode } = extractHttpError(err);
401
+ this.log("error", `${method} - Failed`, method, {
402
+ userId,
403
+ statusCode,
404
+ errorCode
405
+ });
406
+ throw new KeycloakAdminError({
407
+ message: "Keycloak update user attributes failed",
408
+ statusCode: statusCode ?? 502,
409
+ code: KEYCLOAK_ADMIN_ERROR_CODES.UPDATE_ATTRIBUTES_ERROR,
410
+ context: {
411
+ url,
412
+ method: "PUT",
413
+ userId,
414
+ details,
415
+ errorCode
416
+ }
417
+ });
418
+ }
419
+ }
420
+ async sendVerifyEmail(params) {
421
+ const method = "sendVerifyEmail";
422
+ const { userId, adminToken } = params;
423
+ this.log("info", `${method} - Start`, method, {
424
+ userId
425
+ });
426
+ const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_SEND_VERIFY_EMAIL(this.config.baseUrl, this.config.realm, userId);
427
+ try {
428
+ await this.httpProvider.put({
429
+ url,
430
+ data: {},
431
+ config: {
432
+ headers: {
433
+ [KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`,
434
+ "Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_JSON
435
+ }
436
+ }
437
+ });
438
+ this.log("info", `${method} - Success`, method, {
439
+ userId
440
+ });
441
+ } catch (err) {
442
+ const { statusCode, details, errorCode } = extractHttpError(err);
443
+ this.log("error", `${method} - Failed`, method, {
444
+ userId,
445
+ statusCode,
446
+ errorCode
447
+ });
448
+ throw new KeycloakAdminError({
449
+ message: "Keycloak send verify email failed",
450
+ statusCode: statusCode ?? 502,
451
+ code: KEYCLOAK_ADMIN_ERROR_CODES.SEND_VERIFY_EMAIL_ERROR,
452
+ context: {
453
+ url,
454
+ method: "PUT",
455
+ userId,
456
+ details,
457
+ errorCode
458
+ }
459
+ });
460
+ }
461
+ }
462
+ };
463
+ __name(_KeycloakAdminClient, "KeycloakAdminClient");
464
+ var KeycloakAdminClient = _KeycloakAdminClient;
465
+ KeycloakAdminClient = _ts_decorate([
466
+ (0, import_common.Injectable)(),
467
+ _ts_param(0, (0, import_common.Inject)(KEYCLOAK_ADMIN_CONFIG)),
468
+ _ts_param(1, (0, import_common.Inject)(import_http_client.HTTP_PROVIDER)),
469
+ _ts_param(2, (0, import_common.Optional)()),
470
+ _ts_param(2, (0, import_common.Inject)(import_logger.LOGGER_PROVIDER)),
471
+ _ts_metadata("design:type", Function),
472
+ _ts_metadata("design:paramtypes", [
473
+ typeof KeycloakAdminConfig === "undefined" ? Object : KeycloakAdminConfig,
474
+ typeof HttpProviderInterface === "undefined" ? Object : HttpProviderInterface,
475
+ typeof LoggerProviderInterface === "undefined" ? Object : LoggerProviderInterface
476
+ ])
477
+ ], KeycloakAdminClient);
478
+
479
+ // src/keycloak-admin.module.ts
480
+ function _ts_decorate2(decorators, target, key, desc) {
481
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
482
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
483
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
484
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
485
+ }
486
+ __name(_ts_decorate2, "_ts_decorate");
487
+ var _KeycloakAdminModule = class _KeycloakAdminModule {
488
+ static forRoot(config) {
489
+ return {
490
+ module: _KeycloakAdminModule,
491
+ global: true,
492
+ imports: [
493
+ import_http_client2.HttpModule.forRoot({
494
+ baseURL: config.baseUrl,
495
+ timeout: 5e3
496
+ }, {
497
+ logging: {
498
+ enabled: true,
499
+ includeBody: true,
500
+ context: "KeycloakAdminHttpClient",
501
+ environments: [
502
+ "development",
503
+ "test"
504
+ ]
505
+ }
506
+ })
507
+ ],
508
+ providers: [
509
+ {
510
+ provide: KEYCLOAK_ADMIN_CONFIG,
511
+ useValue: config
512
+ },
513
+ {
514
+ provide: KEYCLOAK_ADMIN_CLIENT,
515
+ useClass: KeycloakAdminClient
516
+ },
517
+ {
518
+ provide: KEYCLOAK_ADMIN_PROVIDER,
519
+ useExisting: KEYCLOAK_ADMIN_CLIENT
520
+ }
521
+ ],
522
+ exports: [
523
+ KEYCLOAK_ADMIN_CLIENT,
524
+ KEYCLOAK_ADMIN_PROVIDER,
525
+ KEYCLOAK_ADMIN_CONFIG
526
+ ]
527
+ };
528
+ }
529
+ };
530
+ __name(_KeycloakAdminModule, "KeycloakAdminModule");
531
+ var KeycloakAdminModule = _KeycloakAdminModule;
532
+ KeycloakAdminModule = _ts_decorate2([
533
+ (0, import_common2.Module)({})
534
+ ], KeycloakAdminModule);
535
+ // Annotate the CommonJS export names for ESM import in node:
536
+ 0 && (module.exports = {
537
+ KEYCLOAK_ADMIN_CLIENT,
538
+ KEYCLOAK_ADMIN_CONFIG,
539
+ KEYCLOAK_ADMIN_PROVIDER,
540
+ KeycloakAdminClient,
541
+ KeycloakAdminModule
542
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adatechnology/keycloak-admin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -26,7 +26,7 @@
26
26
  "@adatechnology/shared": "0.0.2"
27
27
  },
28
28
  "scripts": {
29
- "build": "rm -rf dist && tsup",
29
+ "build": "rm -rf dist && tsup && cp index.d.ts dist/index.d.ts",
30
30
  "build:watch": "tsup --watch",
31
31
  "check": "tsc -p tsconfig.json --noEmit"
32
32
  }