@mondart/nestjs-common-module 2.6.7 → 2.7.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/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/kafka-timestamp.decorator.d.ts +1 -0
- package/dist/decorators/kafka-timestamp.decorator.js +28 -0
- package/dist/filters/global-exception.filter.js +2 -1
- package/dist/lib/keycloak/index.d.ts +5 -1
- package/dist/lib/keycloak/index.js +2 -1
- package/dist/lib/keycloak/keycloak.module.d.ts +2 -7
- package/dist/lib/keycloak/keycloak.module.js +10 -40
- package/dist/lib/keycloak/services/keycloak.service.d.ts +12 -0
- package/dist/lib/keycloak/services/keycloak.service.js +79 -0
- package/dist/lib/keycloak/utils/jwt.util.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +49 -0
- package/package.json +3 -3
- package/dist/lib/keycloak/keycloak.service.d.ts +0 -14
- package/dist/lib/keycloak/keycloak.service.js +0 -85
package/eslint.config.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const {
|
|
2
|
+
defineConfig,
|
|
3
|
+
globalIgnores,
|
|
4
|
+
} = require("eslint/config");
|
|
5
|
+
|
|
6
|
+
const tsParser = require("@typescript-eslint/parser");
|
|
7
|
+
const typescriptEslintEslintPlugin = require("@typescript-eslint/eslint-plugin");
|
|
8
|
+
const globals = require("globals");
|
|
9
|
+
const js = require("@eslint/js");
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
FlatCompat,
|
|
13
|
+
} = require("@eslint/eslintrc");
|
|
14
|
+
|
|
15
|
+
const compat = new FlatCompat({
|
|
16
|
+
baseDirectory: __dirname,
|
|
17
|
+
recommendedConfig: js.configs.recommended,
|
|
18
|
+
allConfig: js.configs.all
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
module.exports = defineConfig([{
|
|
22
|
+
languageOptions: {
|
|
23
|
+
parser: tsParser,
|
|
24
|
+
sourceType: "module",
|
|
25
|
+
|
|
26
|
+
parserOptions: {
|
|
27
|
+
project: "tsconfig.json",
|
|
28
|
+
tsconfigRootDir: __dirname,
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
globals: {
|
|
32
|
+
...globals.node,
|
|
33
|
+
...globals.jest,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
plugins: {
|
|
38
|
+
"@typescript-eslint": typescriptEslintEslintPlugin,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
extends: compat.extends("plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"),
|
|
42
|
+
|
|
43
|
+
rules: {
|
|
44
|
+
"@typescript-eslint/interface-name-prefix": "off",
|
|
45
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
46
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
47
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
48
|
+
},
|
|
49
|
+
}, globalIgnores(["**/.eslintrc.js"])]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondart/nestjs-common-module",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mondart"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@sentry/nestjs": "^8.32.0",
|
|
38
38
|
"@sentry/profiling-node": "^8.32.0",
|
|
39
39
|
"@types/redis": "^4.0.11",
|
|
40
|
-
"axios": "
|
|
40
|
+
"axios": "1.12.0",
|
|
41
41
|
"bottleneck": "^2.19.5",
|
|
42
42
|
"cache-manager": "^6.4.0",
|
|
43
43
|
"cache-manager-ioredis-yet": "^2.1.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"class-validator": "^0.14.1",
|
|
46
46
|
"express-basic-auth": "^1.2.1",
|
|
47
47
|
"kafkajs": "^2.2.4",
|
|
48
|
-
"nestjs-paginate": "^11.1.0",
|
|
49
48
|
"moment-timezone": "^0.6.0",
|
|
49
|
+
"nestjs-paginate": "^11.1.0",
|
|
50
50
|
"npm": "^10.8.1",
|
|
51
51
|
"reflect-metadata": "^0.2.0",
|
|
52
52
|
"rxjs": "^7.8.1",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { KeycloakAdminClient } from '@keycloak/keycloak-admin-client/lib/client';
|
|
2
|
-
import { KeycloakModuleOptions } from './interfaces';
|
|
3
|
-
export declare class KeycloakService {
|
|
4
|
-
private readonly options;
|
|
5
|
-
kc: KeycloakAdminClient;
|
|
6
|
-
private readonly logger;
|
|
7
|
-
private accessTokenExpireIn;
|
|
8
|
-
constructor(options: KeycloakModuleOptions);
|
|
9
|
-
init(): Promise<void>;
|
|
10
|
-
private authenticate;
|
|
11
|
-
private getAccessTokenWithRefreshToken;
|
|
12
|
-
private getAccessToken;
|
|
13
|
-
private importKC;
|
|
14
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var KeycloakService_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.KeycloakService = void 0;
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
const interfaces_1 = require("./interfaces");
|
|
19
|
-
const jwt_util_1 = require("./utils/jwt.util");
|
|
20
|
-
let KeycloakService = KeycloakService_1 = class KeycloakService {
|
|
21
|
-
constructor(options) {
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.logger = new common_1.Logger(KeycloakService_1.name);
|
|
24
|
-
}
|
|
25
|
-
async init() {
|
|
26
|
-
const KcAdminClient = await this.importKC();
|
|
27
|
-
if (!this.kc) {
|
|
28
|
-
this.logger.debug(`start initiating`);
|
|
29
|
-
this.kc = new KcAdminClient();
|
|
30
|
-
}
|
|
31
|
-
this.kc.setConfig({
|
|
32
|
-
baseUrl: this.options.baseUrl,
|
|
33
|
-
});
|
|
34
|
-
await this.authenticate();
|
|
35
|
-
}
|
|
36
|
-
async authenticate() {
|
|
37
|
-
await this.getAccessToken();
|
|
38
|
-
const accessTokenInterval = setInterval(async () => {
|
|
39
|
-
const refreshTokenExpireIn = jwt_util_1.JwtUtils.getTokenExpiry(this.kc.refreshToken);
|
|
40
|
-
const expireIn = refreshTokenExpireIn > 15 ? refreshTokenExpireIn - 15 : 0;
|
|
41
|
-
if (expireIn <= 0) {
|
|
42
|
-
await this.getAccessToken();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
await this.getAccessTokenWithRefreshToken().catch(async (err) => {
|
|
46
|
-
this.logger.error(err);
|
|
47
|
-
await this.getAccessToken().catch((err) => {
|
|
48
|
-
this.logger.error(err);
|
|
49
|
-
clearInterval(accessTokenInterval);
|
|
50
|
-
throw err;
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}, (this.accessTokenExpireIn - 15) * 1000);
|
|
55
|
-
}
|
|
56
|
-
async getAccessTokenWithRefreshToken() {
|
|
57
|
-
await this.kc.auth({
|
|
58
|
-
clientId: this.options?.clientId,
|
|
59
|
-
grantType: 'refresh_token',
|
|
60
|
-
clientSecret: this.options?.clientSecret,
|
|
61
|
-
refreshToken: this.kc.refreshToken,
|
|
62
|
-
});
|
|
63
|
-
this.accessTokenExpireIn = jwt_util_1.JwtUtils.getTokenExpiry(this.kc.accessToken);
|
|
64
|
-
}
|
|
65
|
-
async getAccessToken() {
|
|
66
|
-
await this.kc.auth({
|
|
67
|
-
clientId: this.options?.clientId,
|
|
68
|
-
clientSecret: this.options?.clientSecret,
|
|
69
|
-
grantType: 'password',
|
|
70
|
-
username: this.options?.username,
|
|
71
|
-
password: this.options?.password,
|
|
72
|
-
});
|
|
73
|
-
this.accessTokenExpireIn = jwt_util_1.JwtUtils.getTokenExpiry(this.kc.accessToken);
|
|
74
|
-
}
|
|
75
|
-
async importKC() {
|
|
76
|
-
const { default: KeycloakAdminClient } = await eval(`import('@keycloak/keycloak-admin-client')`);
|
|
77
|
-
return KeycloakAdminClient;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
exports.KeycloakService = KeycloakService;
|
|
81
|
-
exports.KeycloakService = KeycloakService = KeycloakService_1 = __decorate([
|
|
82
|
-
(0, common_1.Injectable)(),
|
|
83
|
-
__param(0, (0, common_1.Inject)(interfaces_1.KEYCLOAK_MODULE_OPTIONS)),
|
|
84
|
-
__metadata("design:paramtypes", [Object])
|
|
85
|
-
], KeycloakService);
|