@mondart/nestjs-common-module 2.7.0 → 2.7.6

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.
@@ -1,7 +1,6 @@
1
1
  export * from './keycloak.module';
2
2
  export * from './services/keycloak.service';
3
3
  export * from './interfaces';
4
- export * from '@keycloak/keycloak-admin-client/lib';
5
4
  import type { Users, UserQuery } from '@keycloak/keycloak-admin-client/lib/resources/users';
6
5
  import type RealmRepresentation from '@keycloak/keycloak-admin-client/lib/defs/realmRepresentation';
7
6
  export { RealmRepresentation, UserQuery, Users };
@@ -17,4 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./keycloak.module"), exports);
18
18
  __exportStar(require("./services/keycloak.service"), exports);
19
19
  __exportStar(require("./interfaces"), exports);
20
- __exportStar(require("@keycloak/keycloak-admin-client/lib"), exports);
@@ -1,12 +1,29 @@
1
1
  import { OnModuleInit } from '@nestjs/common';
2
- import { KeycloakAdminClient } from '@keycloak/keycloak-admin-client/lib/client';
3
2
  import { KeycloakModuleOptions } from '../interfaces';
4
- export declare class KeycloakService extends KeycloakAdminClient implements OnModuleInit {
3
+ export declare class KeycloakService implements OnModuleInit {
5
4
  private readonly options;
6
5
  private readonly logger;
6
+ private kc;
7
7
  constructor(options: KeycloakModuleOptions);
8
8
  onModuleInit(): Promise<void>;
9
+ get users(): import("@keycloak/keycloak-admin-client/lib/resources/users").Users;
10
+ get realms(): import("@keycloak/keycloak-admin-client/lib/resources/realms").Realms;
11
+ get clients(): import("@keycloak/keycloak-admin-client/lib/resources/clients").Clients;
12
+ get roles(): import("@keycloak/keycloak-admin-client/lib/resources/roles").Roles;
13
+ get groups(): import("@keycloak/keycloak-admin-client/lib/resources/groups").Groups;
14
+ get organizations(): import("@keycloak/keycloak-admin-client/lib/resources/organizations").Organizations;
15
+ get userStorageProvider(): import("@keycloak/keycloak-admin-client/lib/resources/userStorageProvider").UserStorageProvider;
16
+ get clientScopes(): import("@keycloak/keycloak-admin-client/lib/resources/clientScopes").ClientScopes;
17
+ get clientPolicies(): import("@keycloak/keycloak-admin-client/lib/resources/clientPolicies").ClientPolicies;
18
+ get identityProviders(): import("@keycloak/keycloak-admin-client/lib/resources/identityProviders").IdentityProviders;
19
+ get components(): import("@keycloak/keycloak-admin-client/lib/resources/components").Components;
20
+ get serverInfo(): import("@keycloak/keycloak-admin-client/lib/resources/serverInfo").ServerInfo;
21
+ get whoAmI(): import("@keycloak/keycloak-admin-client/lib/resources/whoAmI").WhoAmI;
22
+ get attackDetection(): import("@keycloak/keycloak-admin-client/lib/resources/attackDetection").AttackDetection;
23
+ get authenticationManagement(): import("@keycloak/keycloak-admin-client/lib/resources/authenticationManagement").AuthenticationManagement;
24
+ get cache(): import("@keycloak/keycloak-admin-client/lib/resources/cache").Cache;
9
25
  private handleToken;
10
26
  private getAccessTokenWithPassword;
11
27
  private getAccessTokenWithRefreshToken;
28
+ private importKC;
12
29
  }
@@ -15,30 +15,84 @@ var KeycloakService_1;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.KeycloakService = void 0;
17
17
  const common_1 = require("@nestjs/common");
18
- const client_1 = require("@keycloak/keycloak-admin-client/lib/client");
19
18
  const interfaces_1 = require("../interfaces");
20
19
  const jwt_util_1 = require("../utils/jwt.util");
21
- let KeycloakService = KeycloakService_1 = class KeycloakService extends client_1.KeycloakAdminClient {
20
+ let KeycloakService = KeycloakService_1 = class KeycloakService {
22
21
  constructor(options) {
23
- super({
24
- baseUrl: options.baseUrl,
25
- realmName: options.realmName,
26
- });
27
22
  this.options = options;
28
23
  this.logger = new common_1.Logger(KeycloakService_1.name);
29
24
  }
30
25
  async onModuleInit() {
31
- this.logger.debug('Initializing Keycloak client');
26
+ const KcAdminClient = await this.importKC();
27
+ if (!this.kc) {
28
+ this.logger.debug(`start initiating`);
29
+ this.kc = new KcAdminClient({
30
+ baseUrl: this.options.baseUrl,
31
+ realmName: this.options.realmName,
32
+ });
33
+ }
34
+ this.kc.setConfig({
35
+ baseUrl: this.options.baseUrl,
36
+ realmName: this.options.realmName,
37
+ });
32
38
  await this.getAccessTokenWithPassword();
33
- super.registerTokenProvider({
39
+ this.kc.registerTokenProvider({
34
40
  getAccessToken: async () => {
35
41
  await this.handleToken();
36
- return this.accessToken;
42
+ return this.kc.accessToken;
37
43
  },
38
44
  });
39
45
  }
46
+ get users() {
47
+ return this.kc.users;
48
+ }
49
+ get realms() {
50
+ return this.kc.realms;
51
+ }
52
+ get clients() {
53
+ return this.kc.clients;
54
+ }
55
+ get roles() {
56
+ return this.kc.roles;
57
+ }
58
+ get groups() {
59
+ return this.kc.groups;
60
+ }
61
+ get organizations() {
62
+ return this.kc.organizations;
63
+ }
64
+ get userStorageProvider() {
65
+ return this.kc.userStorageProvider;
66
+ }
67
+ get clientScopes() {
68
+ return this.kc.clientScopes;
69
+ }
70
+ get clientPolicies() {
71
+ return this.kc.clientPolicies;
72
+ }
73
+ get identityProviders() {
74
+ return this.kc.identityProviders;
75
+ }
76
+ get components() {
77
+ return this.kc.components;
78
+ }
79
+ get serverInfo() {
80
+ return this.kc.serverInfo;
81
+ }
82
+ get whoAmI() {
83
+ return this.kc.whoAmI;
84
+ }
85
+ get attackDetection() {
86
+ return this.kc.attackDetection;
87
+ }
88
+ get authenticationManagement() {
89
+ return this.kc.authenticationManagement;
90
+ }
91
+ get cache() {
92
+ return this.kc.cache;
93
+ }
40
94
  async handleToken() {
41
- const refreshTokenExpireIn = jwt_util_1.JwtUtils.getTokenExpiry(this.refreshToken);
95
+ const refreshTokenExpireIn = jwt_util_1.JwtUtils.getTokenExpiry(this.kc.refreshToken);
42
96
  const expireIn = refreshTokenExpireIn > 15 ? refreshTokenExpireIn - 15 : 0;
43
97
  if (expireIn <= 0) {
44
98
  await this.getAccessTokenWithPassword();
@@ -54,7 +108,7 @@ let KeycloakService = KeycloakService_1 = class KeycloakService extends client_1
54
108
  }
55
109
  }
56
110
  async getAccessTokenWithPassword() {
57
- await this.auth({
111
+ await this.kc.auth({
58
112
  clientId: this.options.clientId,
59
113
  clientSecret: this.options.clientSecret,
60
114
  grantType: 'password',
@@ -63,13 +117,17 @@ let KeycloakService = KeycloakService_1 = class KeycloakService extends client_1
63
117
  });
64
118
  }
65
119
  async getAccessTokenWithRefreshToken() {
66
- await this.auth({
120
+ await this.kc.auth({
67
121
  clientId: this.options.clientId,
68
122
  clientSecret: this.options.clientSecret,
69
123
  grantType: 'refresh_token',
70
- refreshToken: this.refreshToken,
124
+ refreshToken: this.kc.refreshToken,
71
125
  });
72
126
  }
127
+ async importKC() {
128
+ const { default: KeycloakAdminClient } = await eval(`import('@keycloak/keycloak-admin-client')`);
129
+ return KeycloakAdminClient;
130
+ }
73
131
  };
74
132
  exports.KeycloakService = KeycloakService;
75
133
  exports.KeycloakService = KeycloakService = KeycloakService_1 = __decorate([