eh-commons 0.0.2-testing.81 → 0.0.2-testing.83
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/clients/logger.client.d.ts +7 -4
- package/dist/clients/logger.client.js +27 -22
- package/dist/clients/logger.client.js.map +1 -1
- package/dist/modules/session/guards/permission.guard.js +3 -0
- package/dist/modules/session/guards/permission.guard.js.map +1 -1
- package/dist/modules/session/models/interfaces/index.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/logger.client.ts +34 -32
- package/src/modules/session/guards/permission.guard.ts +4 -0
- package/src/modules/session/models/interfaces/index.ts +1 -1
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -0
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Kafka, Producer, RecordMetadata
|
|
2
|
-
import { Observable, catchError, from,
|
|
1
|
+
import { Kafka, Producer, RecordMetadata } from 'kafkajs';
|
|
2
|
+
import { Observable, catchError, from, mergeMap, of } from 'rxjs';
|
|
3
3
|
|
|
4
4
|
export class LoggerClient {
|
|
5
5
|
private kafka: Kafka;
|
|
6
6
|
private kafkaTopic: string;
|
|
7
7
|
private producer: Producer;
|
|
8
|
+
private connected = false;
|
|
9
|
+
private connecting: Promise<void> | null = null;
|
|
10
|
+
|
|
8
11
|
constructor(
|
|
9
12
|
kafkaBrokers: string[],
|
|
10
13
|
kafkaClientId: string,
|
|
@@ -15,43 +18,42 @@ export class LoggerClient {
|
|
|
15
18
|
this.producer = this.kafka.producer();
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
private async ensureConnected(): Promise<void> {
|
|
22
|
+
if (this.connected) return;
|
|
23
|
+
if (this.connecting) return this.connecting;
|
|
24
|
+
this.connecting = this.producer
|
|
25
|
+
.connect()
|
|
26
|
+
.then(() => {
|
|
27
|
+
this.connected = true;
|
|
28
|
+
})
|
|
29
|
+
.finally(() => {
|
|
30
|
+
this.connecting = null;
|
|
31
|
+
});
|
|
32
|
+
return this.connecting;
|
|
23
33
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
|
|
35
|
+
sendLog(log: any, key?: string): Observable<RecordMetadata[]> {
|
|
36
|
+
const messageString = JSON.stringify(log);
|
|
37
|
+
return from(this.ensureConnected()).pipe(
|
|
38
|
+
mergeMap(() =>
|
|
39
|
+
from(
|
|
40
|
+
this.producer.send({
|
|
41
|
+
topic: this.kafkaTopic,
|
|
42
|
+
messages: [{ key, value: messageString }],
|
|
32
43
|
}),
|
|
33
|
-
)
|
|
34
|
-
|
|
44
|
+
),
|
|
45
|
+
),
|
|
35
46
|
catchError((err) => {
|
|
47
|
+
this.connected = false;
|
|
36
48
|
return of(err);
|
|
37
49
|
}),
|
|
38
50
|
);
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.producer.send({
|
|
47
|
-
topic: this.kafkaTopic,
|
|
48
|
-
messages: [
|
|
49
|
-
{
|
|
50
|
-
key,
|
|
51
|
-
value: messageString,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
53
|
+
async disconnect(): Promise<void> {
|
|
54
|
+
if (this.connected) {
|
|
55
|
+
await this.producer.disconnect();
|
|
56
|
+
this.connected = false;
|
|
57
|
+
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
@@ -75,6 +75,10 @@ export class PermissionGuard implements CanActivate {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
private _checkPermission(userPermissions: IPermission[], allowedPermission: string): boolean {
|
|
78
|
+
if (userPermissions?.some((item) => item.keyword === 'eh.root')) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
if (allowedPermission) {
|
|
79
83
|
if (!userPermissions || !userPermissions.length) {
|
|
80
84
|
throw new RESTError('forbidden', null, HttpStatus.FORBIDDEN);
|