@btffamily/chekaam 1.0.1

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.
Files changed (52) hide show
  1. package/build/brokers/nats/listener.ev.d.ts +29 -0
  2. package/build/brokers/nats/listener.ev.js +44 -0
  3. package/build/brokers/nats/publisher.ev.d.ts +19 -0
  4. package/build/brokers/nats/publisher.ev.js +28 -0
  5. package/build/brokers/nats/subjects.ev.d.ts +84 -0
  6. package/build/brokers/nats/subjects.ev.js +91 -0
  7. package/build/brokers/rabbitMQ/consumer.d.ts +35 -0
  8. package/build/brokers/rabbitMQ/consumer.js +74 -0
  9. package/build/brokers/rabbitMQ/exchanges.d.ts +54 -0
  10. package/build/brokers/rabbitMQ/exchanges.js +61 -0
  11. package/build/brokers/rabbitMQ/producer.d.ts +17 -0
  12. package/build/brokers/rabbitMQ/producer.js +40 -0
  13. package/build/dtos/auth.dto.d.ts +5 -0
  14. package/build/dtos/auth.dto.js +2 -0
  15. package/build/dtos/word.dto.d.ts +11 -0
  16. package/build/dtos/word.dto.js +2 -0
  17. package/build/index.d.ts +15 -0
  18. package/build/index.js +110 -0
  19. package/build/middleware/async.mw.d.ts +3 -0
  20. package/build/middleware/async.mw.js +4 -0
  21. package/build/middleware/auth.mw.d.ts +4 -0
  22. package/build/middleware/auth.mw.js +91 -0
  23. package/build/middleware/db.mw.d.ts +6 -0
  24. package/build/middleware/db.mw.js +43 -0
  25. package/build/middleware/redis.mw.d.ts +19 -0
  26. package/build/middleware/redis.mw.js +28 -0
  27. package/build/middleware/role.mw.d.ts +4 -0
  28. package/build/middleware/role.mw.js +19 -0
  29. package/build/services/auth.service.d.ts +13 -0
  30. package/build/services/auth.service.js +37 -0
  31. package/build/services/mongo.service.d.ts +7 -0
  32. package/build/services/mongo.service.js +14 -0
  33. package/build/services/random.service.d.ts +8 -0
  34. package/build/services/random.service.js +30 -0
  35. package/build/services/word.service.d.ts +8 -0
  36. package/build/services/word.service.js +73 -0
  37. package/build/src/ca-certificate.crt +32 -0
  38. package/build/src/index.ts +196 -0
  39. package/build/utils/cache.util.d.ts +3 -0
  40. package/build/utils/cache.util.js +7 -0
  41. package/build/utils/encryption.util.d.ts +66 -0
  42. package/build/utils/encryption.util.js +208 -0
  43. package/build/utils/functions.util.d.ts +134 -0
  44. package/build/utils/functions.util.js +1039 -0
  45. package/build/utils/interfaces.util.d.ts +25 -0
  46. package/build/utils/interfaces.util.js +2 -0
  47. package/build/utils/snippets/decryption.snippet.d.ts +0 -0
  48. package/build/utils/snippets/decryption.snippet.js +255 -0
  49. package/build/utils/types.util.d.ts +58 -0
  50. package/build/utils/types.util.js +2 -0
  51. package/package.json +49 -0
  52. package/readme.md +0 -0
package/build/index.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dateIsYesterday = exports.dateIsToday = exports.checkTimeFormat = exports.checkDateFormat = exports.isZero = exports.rearrangeArray = exports.sortData = exports.urlToBase64 = exports.convertUrlToBase64 = exports.isEmptyObject = exports.dateToday = exports.formatDate = exports.leadingNum = exports.dateToWordRaw = exports.dateToWord = exports.rangeFromMinutes = exports.timeToMinutes = exports.listIncludes = exports.arrayIncludesEs6 = exports.arrayIncludes = exports.strIncludesEs6 = exports.strIncludes = exports.strToArrayEs6 = exports.strToArray = exports.getBase64Mime = exports.isBase64 = exports.isArray = exports.isString = exports.isNumber = exports.isNeg = exports.isPos = exports.isObjectId = exports.isObject = exports.Encryption = exports.permit = exports.authorize = exports.protect = exports.asyncHandler = exports.Mongo = exports.Random = exports.DEVExchanges = exports.STGSExchanges = exports.Exchanges = exports.Producer = exports.Consumer = exports.DEVSubjects = exports.STGSubjects = exports.Listener = exports.Publisher = exports.Subjects = void 0;
7
+ exports.pickFrom = exports.toMongoId = exports.weekEndDate = exports.weekStartDate = exports.daysFromDates = exports.dateFromWeekNumber = exports.base64ToString = exports.stringToBase64 = exports.enumToArray = exports.arrayToSingleObject = exports.arrayToObject = exports.isJson = exports.objectToArray = exports.slugit = exports.wordLen = exports.charLen = exports.hasSAC = exports.formatISO = exports.toDecimal = exports.hasDecimal = exports.isPrecise = exports.capitalize = exports.monthsOfYear = exports.daysOfWeek = exports.firstDayOfMonth = exports.lastDayOfMonth = exports.getDaysFromDates = exports.getCodeFromName = exports.validateBase64 = exports.getWeeksInMonth = exports.getDatesInRange = exports.getWeeksDates = exports.compareISODate = exports.UIID = exports.isDefined = exports.notDefined = exports.generate = exports.yesterdayFromDate = exports.dateIsFuture = exports.dateIsPast = exports.dateIsEqual = void 0;
8
+ const async_mw_1 = __importDefault(require("./middleware/async.mw"));
9
+ exports.asyncHandler = async_mw_1.default;
10
+ const auth_mw_1 = require("./middleware/auth.mw");
11
+ Object.defineProperty(exports, "protect", { enumerable: true, get: function () { return auth_mw_1.protect; } });
12
+ Object.defineProperty(exports, "authorize", { enumerable: true, get: function () { return auth_mw_1.authorize; } });
13
+ Object.defineProperty(exports, "permit", { enumerable: true, get: function () { return auth_mw_1.permit; } });
14
+ const subjects_ev_1 = require("./brokers/nats/subjects.ev");
15
+ Object.defineProperty(exports, "Subjects", { enumerable: true, get: function () { return subjects_ev_1.Subjects; } });
16
+ Object.defineProperty(exports, "STGSubjects", { enumerable: true, get: function () { return subjects_ev_1.STGSubjects; } });
17
+ Object.defineProperty(exports, "DEVSubjects", { enumerable: true, get: function () { return subjects_ev_1.DEVSubjects; } });
18
+ const exchanges_1 = require("./brokers/rabbitMQ/exchanges");
19
+ Object.defineProperty(exports, "Exchanges", { enumerable: true, get: function () { return exchanges_1.Exchanges; } });
20
+ Object.defineProperty(exports, "STGSExchanges", { enumerable: true, get: function () { return exchanges_1.STGSExchanges; } });
21
+ Object.defineProperty(exports, "DEVExchanges", { enumerable: true, get: function () { return exchanges_1.DEVExchanges; } });
22
+ const publisher_ev_1 = __importDefault(require("./brokers/nats/publisher.ev"));
23
+ exports.Publisher = publisher_ev_1.default;
24
+ const publisher_ev_2 = __importDefault(require("./brokers/nats/publisher.ev"));
25
+ exports.Listener = publisher_ev_2.default;
26
+ const consumer_1 = __importDefault(require("./brokers/rabbitMQ/consumer"));
27
+ exports.Consumer = consumer_1.default;
28
+ const producer_1 = __importDefault(require("./brokers/rabbitMQ/producer"));
29
+ exports.Producer = producer_1.default;
30
+ const random_service_1 = __importDefault(require("./services/random.service"));
31
+ exports.Random = random_service_1.default;
32
+ const mongo_service_1 = __importDefault(require("./services/mongo.service"));
33
+ exports.Mongo = mongo_service_1.default;
34
+ const encryption_util_1 = __importDefault(require("./utils/encryption.util"));
35
+ exports.Encryption = encryption_util_1.default;
36
+ const functions_util_1 = require("./utils/functions.util");
37
+ Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return functions_util_1.isObject; } });
38
+ Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return functions_util_1.isString; } });
39
+ Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return functions_util_1.isArray; } });
40
+ Object.defineProperty(exports, "strToArray", { enumerable: true, get: function () { return functions_util_1.strToArray; } });
41
+ Object.defineProperty(exports, "strToArrayEs6", { enumerable: true, get: function () { return functions_util_1.strToArrayEs6; } });
42
+ Object.defineProperty(exports, "strIncludes", { enumerable: true, get: function () { return functions_util_1.strIncludes; } });
43
+ Object.defineProperty(exports, "strIncludesEs6", { enumerable: true, get: function () { return functions_util_1.strIncludesEs6; } });
44
+ Object.defineProperty(exports, "arrayIncludes", { enumerable: true, get: function () { return functions_util_1.arrayIncludes; } });
45
+ Object.defineProperty(exports, "arrayIncludesEs6", { enumerable: true, get: function () { return functions_util_1.arrayIncludesEs6; } });
46
+ Object.defineProperty(exports, "listIncludes", { enumerable: true, get: function () { return functions_util_1.listIncludes; } });
47
+ Object.defineProperty(exports, "timeToMinutes", { enumerable: true, get: function () { return functions_util_1.timeToMinutes; } });
48
+ Object.defineProperty(exports, "rangeFromMinutes", { enumerable: true, get: function () { return functions_util_1.rangeFromMinutes; } });
49
+ Object.defineProperty(exports, "dateToWord", { enumerable: true, get: function () { return functions_util_1.dateToWord; } });
50
+ Object.defineProperty(exports, "dateToWordRaw", { enumerable: true, get: function () { return functions_util_1.dateToWordRaw; } });
51
+ Object.defineProperty(exports, "leadingNum", { enumerable: true, get: function () { return functions_util_1.leadingNum; } });
52
+ Object.defineProperty(exports, "dateToday", { enumerable: true, get: function () { return functions_util_1.dateToday; } });
53
+ Object.defineProperty(exports, "isEmptyObject", { enumerable: true, get: function () { return functions_util_1.isEmptyObject; } });
54
+ Object.defineProperty(exports, "convertUrlToBase64", { enumerable: true, get: function () { return functions_util_1.convertUrlToBase64; } });
55
+ Object.defineProperty(exports, "urlToBase64", { enumerable: true, get: function () { return functions_util_1.urlToBase64; } });
56
+ Object.defineProperty(exports, "sortData", { enumerable: true, get: function () { return functions_util_1.sortData; } });
57
+ Object.defineProperty(exports, "rearrangeArray", { enumerable: true, get: function () { return functions_util_1.rearrangeArray; } });
58
+ Object.defineProperty(exports, "isObjectId", { enumerable: true, get: function () { return functions_util_1.isObjectId; } });
59
+ Object.defineProperty(exports, "isPos", { enumerable: true, get: function () { return functions_util_1.isPos; } });
60
+ Object.defineProperty(exports, "isNeg", { enumerable: true, get: function () { return functions_util_1.isNeg; } });
61
+ Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return functions_util_1.isNumber; } });
62
+ Object.defineProperty(exports, "isZero", { enumerable: true, get: function () { return functions_util_1.isZero; } });
63
+ Object.defineProperty(exports, "checkDateFormat", { enumerable: true, get: function () { return functions_util_1.checkDateFormat; } });
64
+ Object.defineProperty(exports, "checkTimeFormat", { enumerable: true, get: function () { return functions_util_1.checkTimeFormat; } });
65
+ Object.defineProperty(exports, "dateIsToday", { enumerable: true, get: function () { return functions_util_1.dateIsToday; } });
66
+ Object.defineProperty(exports, "dateIsYesterday", { enumerable: true, get: function () { return functions_util_1.dateIsYesterday; } });
67
+ Object.defineProperty(exports, "dateIsEqual", { enumerable: true, get: function () { return functions_util_1.dateIsEqual; } });
68
+ Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return functions_util_1.generate; } });
69
+ Object.defineProperty(exports, "notDefined", { enumerable: true, get: function () { return functions_util_1.notDefined; } });
70
+ Object.defineProperty(exports, "UIID", { enumerable: true, get: function () { return functions_util_1.UIID; } });
71
+ Object.defineProperty(exports, "compareISODate", { enumerable: true, get: function () { return functions_util_1.compareISODate; } });
72
+ Object.defineProperty(exports, "getWeeksDates", { enumerable: true, get: function () { return functions_util_1.getWeeksDates; } });
73
+ Object.defineProperty(exports, "getDatesInRange", { enumerable: true, get: function () { return functions_util_1.getDatesInRange; } });
74
+ Object.defineProperty(exports, "getWeeksInMonth", { enumerable: true, get: function () { return functions_util_1.getWeeksInMonth; } });
75
+ Object.defineProperty(exports, "validateBase64", { enumerable: true, get: function () { return functions_util_1.validateBase64; } });
76
+ Object.defineProperty(exports, "getCodeFromName", { enumerable: true, get: function () { return functions_util_1.getCodeFromName; } });
77
+ Object.defineProperty(exports, "getDaysFromDates", { enumerable: true, get: function () { return functions_util_1.getDaysFromDates; } });
78
+ Object.defineProperty(exports, "lastDayOfMonth", { enumerable: true, get: function () { return functions_util_1.lastDayOfMonth; } });
79
+ Object.defineProperty(exports, "firstDayOfMonth", { enumerable: true, get: function () { return functions_util_1.firstDayOfMonth; } });
80
+ Object.defineProperty(exports, "isBase64", { enumerable: true, get: function () { return functions_util_1.isBase64; } });
81
+ Object.defineProperty(exports, "getBase64Mime", { enumerable: true, get: function () { return functions_util_1.getBase64Mime; } });
82
+ Object.defineProperty(exports, "daysOfWeek", { enumerable: true, get: function () { return functions_util_1.daysOfWeek; } });
83
+ Object.defineProperty(exports, "monthsOfYear", { enumerable: true, get: function () { return functions_util_1.monthsOfYear; } });
84
+ Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return functions_util_1.capitalize; } });
85
+ Object.defineProperty(exports, "isPrecise", { enumerable: true, get: function () { return functions_util_1.isPrecise; } });
86
+ Object.defineProperty(exports, "hasDecimal", { enumerable: true, get: function () { return functions_util_1.hasDecimal; } });
87
+ Object.defineProperty(exports, "formatISO", { enumerable: true, get: function () { return functions_util_1.formatISO; } });
88
+ Object.defineProperty(exports, "hasSAC", { enumerable: true, get: function () { return functions_util_1.hasSAC; } });
89
+ Object.defineProperty(exports, "toDecimal", { enumerable: true, get: function () { return functions_util_1.toDecimal; } });
90
+ Object.defineProperty(exports, "charLen", { enumerable: true, get: function () { return functions_util_1.charLen; } });
91
+ Object.defineProperty(exports, "wordLen", { enumerable: true, get: function () { return functions_util_1.wordLen; } });
92
+ Object.defineProperty(exports, "slugit", { enumerable: true, get: function () { return functions_util_1.slugit; } });
93
+ Object.defineProperty(exports, "isDefined", { enumerable: true, get: function () { return functions_util_1.isDefined; } });
94
+ Object.defineProperty(exports, "objectToArray", { enumerable: true, get: function () { return functions_util_1.objectToArray; } });
95
+ Object.defineProperty(exports, "isJson", { enumerable: true, get: function () { return functions_util_1.isJson; } });
96
+ Object.defineProperty(exports, "arrayToObject", { enumerable: true, get: function () { return functions_util_1.arrayToObject; } });
97
+ Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return functions_util_1.formatDate; } });
98
+ Object.defineProperty(exports, "arrayToSingleObject", { enumerable: true, get: function () { return functions_util_1.arrayToSingleObject; } });
99
+ Object.defineProperty(exports, "dateIsPast", { enumerable: true, get: function () { return functions_util_1.dateIsPast; } });
100
+ Object.defineProperty(exports, "dateIsFuture", { enumerable: true, get: function () { return functions_util_1.dateIsFuture; } });
101
+ Object.defineProperty(exports, "yesterdayFromDate", { enumerable: true, get: function () { return functions_util_1.yesterdayFromDate; } });
102
+ Object.defineProperty(exports, "daysFromDates", { enumerable: true, get: function () { return functions_util_1.daysFromDates; } });
103
+ Object.defineProperty(exports, "enumToArray", { enumerable: true, get: function () { return functions_util_1.enumToArray; } });
104
+ Object.defineProperty(exports, "stringToBase64", { enumerable: true, get: function () { return functions_util_1.stringToBase64; } });
105
+ Object.defineProperty(exports, "base64ToString", { enumerable: true, get: function () { return functions_util_1.base64ToString; } });
106
+ Object.defineProperty(exports, "dateFromWeekNumber", { enumerable: true, get: function () { return functions_util_1.dateFromWeekNumber; } });
107
+ Object.defineProperty(exports, "weekStartDate", { enumerable: true, get: function () { return functions_util_1.weekStartDate; } });
108
+ Object.defineProperty(exports, "weekEndDate", { enumerable: true, get: function () { return functions_util_1.weekEndDate; } });
109
+ Object.defineProperty(exports, "toMongoId", { enumerable: true, get: function () { return functions_util_1.toMongoId; } });
110
+ Object.defineProperty(exports, "pickFrom", { enumerable: true, get: function () { return functions_util_1.pickFrom; } });
@@ -0,0 +1,3 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ declare const asyncHandler: (fn: any) => (req: Request, res: Response, next: NextFunction) => Promise<any>;
3
+ export default asyncHandler;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const asyncHandler = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
4
+ exports.default = asyncHandler;
@@ -0,0 +1,4 @@
1
+ import { IPermitOptions, IRedisConnOptions, IVerifyJWT } from '../utils/interfaces.util';
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>;
4
+ export declare const permit: (data: IPermitOptions) => Promise<boolean>;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.permit = exports.authorize = exports.protect = void 0;
7
+ const role_mw_1 = require("./role.mw");
8
+ const functions_util_1 = require("../utils/functions.util");
9
+ const db_mw_1 = require("./db.mw");
10
+ const auth_service_1 = __importDefault(require("../services/auth.service"));
11
+ const checkRole = (roleIds, roles) => {
12
+ let flag = false;
13
+ let mappedRoles = roles.map((x) => {
14
+ if (x._id || x.id || x.name) {
15
+ return x._id;
16
+ }
17
+ else {
18
+ return x;
19
+ }
20
+ });
21
+ for (let i = 0; i < roleIds.length; i++) {
22
+ for (let j = 0; j < mappedRoles.length; j++) {
23
+ if (roleIds[i] !== undefined && roleIds[i].toString() === mappedRoles[j].toString()) {
24
+ flag = true;
25
+ }
26
+ }
27
+ }
28
+ return flag;
29
+ };
30
+ const protect = (token, secret) => {
31
+ let result = { error: false, data: null };
32
+ if (token) {
33
+ result = auth_service_1.default.verifyJWT({
34
+ token: token,
35
+ secret: secret,
36
+ isApiKey: true
37
+ });
38
+ }
39
+ else {
40
+ result = {
41
+ error: true,
42
+ data: null
43
+ };
44
+ }
45
+ return result;
46
+ };
47
+ exports.protect = protect;
48
+ const authorize = async (roles, userRoles, authType, authDB, options) => {
49
+ let result = false;
50
+ try {
51
+ const conn = await (0, db_mw_1.connectDB)(authType, authDB);
52
+ const allRoles = await (0, role_mw_1.getRoles)({ conn, roles });
53
+ // get authorized IDs //
54
+ const roleIds = allRoles.map((role) => {
55
+ if (role !== undefined && role !== null) {
56
+ return role._id;
57
+ }
58
+ });
59
+ // check if user roles matches the authorized roles
60
+ const flag = checkRole(roleIds, userRoles);
61
+ if (flag) {
62
+ result = true;
63
+ }
64
+ else {
65
+ result = false;
66
+ }
67
+ }
68
+ catch (err) {
69
+ result = false;
70
+ }
71
+ return result;
72
+ };
73
+ exports.authorize = authorize;
74
+ const permit = async (data) => {
75
+ let flag = false;
76
+ const { actions, group, roles, userPermissions, userType } = data;
77
+ if (group && actions && roles) {
78
+ if ((0, functions_util_1.arrayIncludes)(roles, userType)) {
79
+ const permission = userPermissions.find((x) => x.group.toLowerCase() === group.toLowerCase());
80
+ if (permission && (0, functions_util_1.listIncludes)({ arr: permission.actions, list: actions, type: 'some' })) {
81
+ flag = true;
82
+ }
83
+ }
84
+ }
85
+ else {
86
+ // permit if condition is not met
87
+ flag = true;
88
+ }
89
+ return flag;
90
+ };
91
+ exports.permit = permit;
@@ -0,0 +1,6 @@
1
+ import { Model } from 'mongoose';
2
+ export declare const connectDB: (authType: string, authDB: string) => Promise<any>;
3
+ export declare const getModel: (data: {
4
+ conn: any;
5
+ name: string;
6
+ }) => Promise<Model<any>>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getModel = exports.connectDB = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ let connection = null;
9
+ const options = {
10
+ autoIndex: true,
11
+ maxPoolSize: 50000,
12
+ wtimeoutMS: 60000,
13
+ connectTimeoutMS: 60000,
14
+ socketTimeoutMS: 60000,
15
+ serverSelectionTimeoutMS: 60000,
16
+ family: 4,
17
+ };
18
+ const cert = `${__dirname.split('middleware')[0]}src/ca-certificate.crt`;
19
+ // console.log(__dirname);
20
+ const connectDB = async (authType, authDB) => {
21
+ try {
22
+ if (authType === 'development' || authType === 'production' || authType === 'staging') {
23
+ connection = mongoose_1.default.createConnection(authDB, options);
24
+ }
25
+ else if (authType === 'cloud') {
26
+ const cloudDBString = authDB + `&tls=true&tlsCAFile=${cert}`;
27
+ connection = mongoose_1.default.createConnection(cloudDBString, options);
28
+ }
29
+ else {
30
+ throw new Error(`Authentication type is required`);
31
+ }
32
+ return connection;
33
+ }
34
+ catch (err) {
35
+ throw new Error(`${err}`);
36
+ }
37
+ };
38
+ exports.connectDB = connectDB;
39
+ const getModel = async (data) => {
40
+ const { conn, name } = data;
41
+ return await conn.collection(name.toLowerCase());
42
+ };
43
+ exports.getModel = getModel;
@@ -0,0 +1,19 @@
1
+ import { RedisClientType } from 'redis';
2
+ interface IOptions {
3
+ host: string;
4
+ port: number | string;
5
+ password: string;
6
+ user: string;
7
+ }
8
+ interface IData {
9
+ key: string;
10
+ value: any;
11
+ }
12
+ declare class redisWrapper {
13
+ client: RedisClientType | any;
14
+ connect(options: IOptions): Promise<void>;
15
+ keepData(data: IData, exp: number): Promise<void>;
16
+ fetchData(key: string): Promise<any>;
17
+ }
18
+ declare const _default: redisWrapper;
19
+ export default _default;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const redis_1 = require("redis");
4
+ class redisWrapper {
5
+ client;
6
+ async connect(options) {
7
+ this.client = (0, redis_1.createClient)({
8
+ url: `rediss://${options.user}:${options.password}@${options.host}:${options.port}`
9
+ });
10
+ this.client.on('error', (err) => {
11
+ // console.log(`Common: ${err}`);
12
+ });
13
+ await this.client.connect();
14
+ // console.log(colors.yellow.inverse('Connected to REDIS'));
15
+ }
16
+ async keepData(data, exp) {
17
+ const parsed = JSON.stringify(data.value);
18
+ this.client.set(data.key, parsed, {
19
+ EX: exp,
20
+ NX: false
21
+ });
22
+ }
23
+ async fetchData(key) {
24
+ const data = await this.client.get(key);
25
+ return data === null ? null : JSON.parse(data);
26
+ }
27
+ }
28
+ exports.default = new redisWrapper();
@@ -0,0 +1,4 @@
1
+ export declare const getRoles: (data: {
2
+ conn: any;
3
+ roles: Array<string>;
4
+ }) => Promise<Array<any>>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRoles = void 0;
4
+ const db_mw_1 = require("./db.mw");
5
+ const getRoles = async (data) => {
6
+ let result = [];
7
+ const { conn, roles } = data;
8
+ const Role = await (0, db_mw_1.getModel)({ conn, name: 'roles' });
9
+ if (Role) {
10
+ for (let i = 0; i < roles.length; i++) {
11
+ let role = await Role.findOne({ name: roles[i] });
12
+ if (role) {
13
+ result.push(role);
14
+ }
15
+ }
16
+ }
17
+ return result;
18
+ };
19
+ exports.getRoles = getRoles;
@@ -0,0 +1,13 @@
1
+ import { VerifyJWTDTO } from '../dtos/auth.dto';
2
+ import { IVerifyJWT } from '../utils/interfaces.util';
3
+ declare class AuthService {
4
+ constructor();
5
+ /**
6
+ * @name verifyJWT
7
+ * @param data
8
+ * @returns
9
+ */
10
+ verifyJWT(data: VerifyJWTDTO): IVerifyJWT;
11
+ }
12
+ declare const _default: AuthService;
13
+ export default _default;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
7
+ class AuthService {
8
+ constructor() {
9
+ }
10
+ /**
11
+ * @name verifyJWT
12
+ * @param data
13
+ * @returns
14
+ */
15
+ verifyJWT(data) {
16
+ let result = { error: false, data: null };
17
+ const { isApiKey, secret, token } = data;
18
+ jsonwebtoken_1.default.verify(token, secret, (err, decoded) => {
19
+ if (err) {
20
+ if (isApiKey) {
21
+ // return the token (API Key) instead if there is an error decoding (works for API keys)
22
+ result.error = false;
23
+ result.data = token;
24
+ }
25
+ else {
26
+ result.error = true;
27
+ result.data = null;
28
+ }
29
+ }
30
+ else {
31
+ result.data = decoded ? decoded : null; // return the decoded JWTPayload signature
32
+ }
33
+ });
34
+ return result;
35
+ }
36
+ }
37
+ exports.default = new AuthService();
@@ -0,0 +1,7 @@
1
+ import { Types } from 'mongoose';
2
+ declare class Mongo {
3
+ constructor();
4
+ toMongoId(id: string): Types.ObjectId;
5
+ }
6
+ declare const _default: Mongo;
7
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const mongoose_1 = __importDefault(require("mongoose"));
7
+ class Mongo {
8
+ constructor() { }
9
+ toMongoId(id) {
10
+ return new mongoose_1.default.Types.ObjectId(id);
11
+ }
12
+ ;
13
+ }
14
+ exports.default = new Mongo();
@@ -0,0 +1,8 @@
1
+ declare class Random {
2
+ constructor();
3
+ randomCode(size: number, alpha: boolean): string;
4
+ randomAlpha(size: number): string;
5
+ randomNum(size: number): string;
6
+ }
7
+ declare const _default: Random;
8
+ export default _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Random {
4
+ constructor() { }
5
+ randomCode(size, alpha) {
6
+ const pool = alpha ? 'ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789abcdefghijklmnpqrstuvwxyz' : '0123456789';
7
+ const rand = [];
8
+ let i = -1;
9
+ while (++i < size)
10
+ rand.push(pool.charAt(Math.floor(Math.random() * pool.length)));
11
+ return rand.join('');
12
+ }
13
+ randomAlpha(size) {
14
+ const pool = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz';
15
+ const rand = [];
16
+ let i = -1;
17
+ while (++i < size)
18
+ rand.push(pool.charAt(Math.floor(Math.random() * pool.length)));
19
+ return rand.join('');
20
+ }
21
+ randomNum(size) {
22
+ const pool = '0123456789';
23
+ const rand = [];
24
+ let i = -1;
25
+ while (++i < size)
26
+ rand.push(pool.charAt(Math.floor(Math.random() * pool.length)));
27
+ return rand.join('');
28
+ }
29
+ }
30
+ exports.default = new Random();
@@ -0,0 +1,8 @@
1
+ import { ISentCompDTO, ISentCompResultDTO } from "../dtos/word.dto";
2
+ declare class Word {
3
+ constructor();
4
+ sentcomp(data: ISentCompDTO): ISentCompResultDTO;
5
+ private processScore;
6
+ }
7
+ declare const _default: Word;
8
+ export default _default;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Word {
4
+ constructor() {
5
+ }
6
+ sentcomp(data) {
7
+ let score = 0;
8
+ const { text1, text2, pattern } = data;
9
+ // remove all '_', '-', other chars and split
10
+ const spl_1 = text1.toLowerCase().replace(/[^a-z ]/g, ' ').replaceAll(' ', ' ').replaceAll(' ', ' ').split(' ');
11
+ const spl_2 = text2.toLowerCase().replace(/[^a-z ]/g, ' ').replaceAll(' ', ' ').replaceAll(' ', ' ').split(' ');
12
+ if (pattern === 'in-order') {
13
+ let score = text1.length;
14
+ if (text1.length === text2.length) {
15
+ for (let i = 0; i < spl_1.length; i++) {
16
+ if (spl_1[i] !== spl_2[i]) {
17
+ score--;
18
+ }
19
+ }
20
+ score = Math.round(100 * (score / text1.length));
21
+ }
22
+ }
23
+ if (pattern === 'random') {
24
+ let score_1 = 0;
25
+ let score_2 = 0;
26
+ for (let i = 0; i < spl_2.length; i++) {
27
+ if (spl_1.includes(spl_2[i])) {
28
+ score_1++;
29
+ }
30
+ }
31
+ for (let i = 0; i < spl_1.length; i++) {
32
+ if (spl_2.includes(spl_1[i])) {
33
+ score_2++;
34
+ }
35
+ }
36
+ score_1 = Math.round(100 * (score_1 / spl_1.length));
37
+ score_2 = Math.round(100 * (score_2 / spl_2.length));
38
+ score = (score_1 + score_2) / 2;
39
+ }
40
+ const result = this.processScore(score);
41
+ return result;
42
+ }
43
+ processScore(score) {
44
+ let result = { score: 0, likely: 'different', message: '' };
45
+ if (score === 100) {
46
+ result.score = score;
47
+ result.likely = 'equal';
48
+ result.message = 'supplied strings are equal';
49
+ }
50
+ else if (score === 0) {
51
+ result.score = score;
52
+ result.likely = 'not-equal';
53
+ result.message = 'supplied strings are not equal';
54
+ }
55
+ else {
56
+ result.score = score;
57
+ if (score > 70 && score < 100) {
58
+ result.likely = 'mostly-equal';
59
+ result.message = 'supplied strings contains more equal words';
60
+ }
61
+ else if (score > 40 && score < 70) {
62
+ result.likely = 'less-equal';
63
+ result.message = 'supplied strings contains less equal words';
64
+ }
65
+ else if (score > 0 && score < 40) {
66
+ result.likely = 'almost-different';
67
+ result.message = 'supplied strings contains much less equal words';
68
+ }
69
+ }
70
+ return result;
71
+ }
72
+ }
73
+ exports.default = new Word();
@@ -0,0 +1,32 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFgT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