@btffamily/chekaam 1.0.7 → 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,4 +1,4 @@
1
- import { IPermitOptions, IRedisConnOptions, IVerifyJWT } from '../utils/interfaces.util';
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: (roles: Array<string>, userRoles: Array<any>, authType: string, authDB: string, _options: IRedisConnOptions) => Promise<boolean>;
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 (roles, userRoles, authType, authDB, _options) => {
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btffamily/chekaam",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "common node.js codebase for chekaam platform",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",