@btffamily/chekaam 1.0.6 → 1.0.8
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,9 +1,10 @@
|
|
|
1
|
-
import { Channel, ConsumeMessage } from 'amqplib';
|
|
1
|
+
import { Channel, ConsumeMessage, Options } from 'amqplib';
|
|
2
2
|
interface IConsumer {
|
|
3
3
|
channel: Channel | null;
|
|
4
4
|
exchange: string;
|
|
5
5
|
queueName: string;
|
|
6
6
|
router: string;
|
|
7
|
+
queueOptions: Options.AssertQueue;
|
|
7
8
|
listen(): Promise<any>;
|
|
8
9
|
}
|
|
9
10
|
declare class Consumer implements IConsumer {
|
|
@@ -11,6 +12,7 @@ declare class Consumer implements IConsumer {
|
|
|
11
12
|
exchange: any;
|
|
12
13
|
queueName: any;
|
|
13
14
|
router: any;
|
|
15
|
+
queueOptions: Options.AssertQueue;
|
|
14
16
|
constructor(channel: Channel | null);
|
|
15
17
|
/**
|
|
16
18
|
* @name listen
|
|
@@ -18,7 +20,7 @@ declare class Consumer implements IConsumer {
|
|
|
18
20
|
* @param log
|
|
19
21
|
* @returns
|
|
20
22
|
*/
|
|
21
|
-
listen(log?: boolean): Promise<
|
|
23
|
+
listen(log?: boolean): Promise<void>;
|
|
22
24
|
/**
|
|
23
25
|
* @name parseMessage
|
|
24
26
|
* @param message
|
|
@@ -6,6 +6,10 @@ class Consumer {
|
|
|
6
6
|
exchange;
|
|
7
7
|
queueName;
|
|
8
8
|
router;
|
|
9
|
+
queueOptions = {
|
|
10
|
+
durable: true,
|
|
11
|
+
autoDelete: false,
|
|
12
|
+
};
|
|
9
13
|
constructor(channel) {
|
|
10
14
|
this.channel = channel;
|
|
11
15
|
}
|
|
@@ -24,15 +28,12 @@ class Consumer {
|
|
|
24
28
|
durable: true, // The queue will survive a broker restart,
|
|
25
29
|
});
|
|
26
30
|
// Assert a queue to ensure it exists.
|
|
27
|
-
const conQueue = await this.channel.assertQueue(this.queueName,
|
|
28
|
-
durable: true,
|
|
29
|
-
autoDelete: false
|
|
30
|
-
});
|
|
31
|
+
const conQueue = await this.channel.assertQueue(this.queueName, this.queueOptions);
|
|
31
32
|
// bind the queue to the exchange
|
|
32
33
|
await this.channel.bindQueue(conQueue.queue, this.exchange, this.router);
|
|
33
34
|
// consume message
|
|
34
35
|
// noAck means you want to acknowledge manually
|
|
35
|
-
this.channel.consume(conQueue.queue, (message) => {
|
|
36
|
+
await this.channel.consume(conQueue.queue, (message) => {
|
|
36
37
|
if (message) {
|
|
37
38
|
if (log === true) {
|
|
38
39
|
console.log(`Message recieved from ${this.exchange}/${this.queueName}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAuthorize, IPermitOptions, IVerifyJWT } from '../utils/interfaces.util';
|
|
2
2
|
export declare const protect: (token: string, secret: string) => IVerifyJWT;
|
|
3
|
-
export declare const authorize: (
|
|
3
|
+
export declare const authorize: (data: IAuthorize) => Promise<boolean>;
|
|
4
4
|
export declare const permit: (data: IPermitOptions) => Promise<boolean>;
|
|
@@ -40,11 +40,12 @@ const protect = (token, secret) => {
|
|
|
40
40
|
return result;
|
|
41
41
|
};
|
|
42
42
|
exports.protect = protect;
|
|
43
|
-
const authorize = async (
|
|
43
|
+
const authorize = async (data) => {
|
|
44
|
+
const { roles, userRoles, authType, authDB, _options, sharedConnection } = data;
|
|
44
45
|
if (!Array.isArray(roles) || !roles.length || !Array.isArray(userRoles) || !userRoles.length) {
|
|
45
46
|
return false;
|
|
46
47
|
}
|
|
47
|
-
const conn = await (0, db_mw_1.connectDB)(authType, authDB);
|
|
48
|
+
const conn = sharedConnection ?? await (0, db_mw_1.connectDB)(authType, authDB);
|
|
48
49
|
const allRoles = await (0, role_mw_1.getRoles)({ conn, roles });
|
|
49
50
|
const roleIds = allRoles.map((role) => role._id);
|
|
50
51
|
return checkRole(roleIds, userRoles);
|
|
@@ -9,9 +9,13 @@ const connections = new Map();
|
|
|
9
9
|
const options = {
|
|
10
10
|
autoIndex: false,
|
|
11
11
|
maxPoolSize: 10,
|
|
12
|
+
minPoolSize: 0,
|
|
13
|
+
maxIdleTimeMS: 60000,
|
|
14
|
+
maxConnecting: 2,
|
|
15
|
+
waitQueueTimeoutMS: 10000,
|
|
12
16
|
connectTimeoutMS: 10000,
|
|
13
17
|
serverSelectionTimeoutMS: 10000,
|
|
14
|
-
family: 4
|
|
18
|
+
family: 4,
|
|
15
19
|
};
|
|
16
20
|
const cert = `${__dirname.split('middleware')[0]}src/ca-certificate.crt`;
|
|
17
21
|
// console.log(__dirname);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JwtPayload } from "jsonwebtoken";
|
|
2
|
+
import { Connection } from "mongoose";
|
|
2
3
|
export interface IVerifyJWT {
|
|
3
4
|
error: boolean;
|
|
4
5
|
data: string | JwtPayload | null;
|
|
@@ -23,3 +24,11 @@ export interface IPermitOptions {
|
|
|
23
24
|
actions: Array<string>;
|
|
24
25
|
}>;
|
|
25
26
|
}
|
|
27
|
+
export interface IAuthorize {
|
|
28
|
+
roles: Array<string>;
|
|
29
|
+
userRoles: Array<any>;
|
|
30
|
+
authType: string;
|
|
31
|
+
authDB: string;
|
|
32
|
+
_options: IRedisConnOptions;
|
|
33
|
+
sharedConnection?: Connection;
|
|
34
|
+
}
|