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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eh-commons",
3
3
  "type": "commonjs",
4
- "version": "0.0.2-testing.81",
4
+ "version": "0.0.2-testing.83",
5
5
  "description": "eh-commons",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1,10 +1,13 @@
1
- import { Kafka, Producer, RecordMetadata, TopicMessages } from 'kafkajs';
2
- import { Observable, catchError, from, map, mergeMap, of } from 'rxjs';
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 connectProducer(): Observable<void> {
19
- return from(this.producer.connect());
20
- }
21
- private disconnectProducer(): Observable<void> {
22
- return from(this.producer.disconnect());
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
- private sendLog(log: any, key?: string): Observable<RecordMetadata[]> {
25
- let messageString = JSON.stringify(log);
26
- return this.connectProducer().pipe(
27
- mergeMap(() => {
28
- return this.send(messageString, key).pipe(
29
- map((recordMetadata) => {
30
- this.disconnectProducer().subscribe();
31
- return recordMetadata;
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
- private send(
42
- messageString: string,
43
- key?: string,
44
- ): Observable<RecordMetadata[]> {
45
- return from(
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);
@@ -41,7 +41,7 @@ export interface IUserScope {
41
41
  export interface IUserSessionData {
42
42
  userId: string;
43
43
  username: string;
44
- fistName: string;
44
+ firstName: string;
45
45
  lastName: string;
46
46
  contacts: IContact[];
47
47
  pid: string;
package/tsconfig.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "target": "es2017",
10
10
  "sourceMap": true,
11
11
  "outDir": "./dist",
12
- "baseUrl": "./",
12
+ "rootDir": "./src",
13
13
  "incremental": true,
14
14
  "skipLibCheck": true,
15
15
  "strictNullChecks": false,