@optimiser/common 1.0.243 → 1.0.247
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/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/lib/connection.d.ts +13 -1
- package/dist/lib/connection.js +96 -0
- package/dist/lib/helper.d.ts +3 -1
- package/dist/lib/helper.js +16 -6
- package/dist/lib/memoryserverclient.d.ts +39 -0
- package/dist/lib/memoryserverclient.js +203 -0
- package/dist/lib/operautilitycommon.d.ts +60 -1
- package/dist/lib/operautilitycommon.js +512 -1
- package/dist/lib/utility.d.ts +8 -1
- package/dist/lib/utility.js +89 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * as helperLib from "./lib/helper";
|
|
|
8
8
|
export * as _activity from "./lib/activity";
|
|
9
9
|
export * as _operaUtilCommon from "./lib/operautilitycommon";
|
|
10
10
|
export * as taskutils from "./lib/taskutils";
|
|
11
|
+
export { MemoryDBConnect } from "./lib/memoryserverclient";
|
|
11
12
|
export * from "./modals/connection.modal";
|
|
12
13
|
export * from "./modals/redisconfig.modal";
|
|
13
14
|
export * from "./modals/notificationData.modal";
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ exports.helperLib = __importStar(require("./lib/helper"));
|
|
|
38
38
|
exports._activity = __importStar(require("./lib/activity"));
|
|
39
39
|
exports._operaUtilCommon = __importStar(require("./lib/operautilitycommon"));
|
|
40
40
|
exports.taskutils = __importStar(require("./lib/taskutils"));
|
|
41
|
+
var memoryserverclient_1 = require("./lib/memoryserverclient");
|
|
42
|
+
Object.defineProperty(exports, "MemoryDBConnect", { enumerable: true, get: function () { return memoryserverclient_1.MemoryDBConnect; } });
|
|
41
43
|
// Interface Exports
|
|
42
44
|
__exportStar(require("./modals/connection.modal"), exports);
|
|
43
45
|
__exportStar(require("./modals/redisconfig.modal"), exports);
|
package/dist/lib/connection.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from "mongodb";
|
|
1
|
+
import { Db, MongoClient, ClientSession } from "mongodb";
|
|
2
2
|
import { NextFunction, Response } from "express";
|
|
3
3
|
import IORedis from "ioredis";
|
|
4
4
|
import { Sequelize } from "sequelize";
|
|
@@ -100,5 +100,17 @@ declare class Connection {
|
|
|
100
100
|
* @description Helper function to send response
|
|
101
101
|
*/
|
|
102
102
|
ReturnJsonResponse: (req: OPT_Request, res: Response, params: ResponseStructure) => void;
|
|
103
|
+
/**
|
|
104
|
+
* @param DBName
|
|
105
|
+
* @returns Promise
|
|
106
|
+
* @description return session from client
|
|
107
|
+
*/
|
|
108
|
+
GetDBSession(dbName: string, dbAddress: string): Promise<[Error?, ClientSession?]>;
|
|
109
|
+
/**
|
|
110
|
+
* @param DBName
|
|
111
|
+
* @returns Promise
|
|
112
|
+
* @description return session from client
|
|
113
|
+
*/
|
|
114
|
+
GetDBClient(dbName: string, dbAddress: string): Promise<[Error?, MongoClient?]>;
|
|
103
115
|
}
|
|
104
116
|
export { Connection };
|
package/dist/lib/connection.js
CHANGED
|
@@ -458,6 +458,102 @@ var Connection = /** @class */ (function () {
|
|
|
458
458
|
Connection.prototype.GetActiveDBConnections = function () {
|
|
459
459
|
return Object.keys(this.connections);
|
|
460
460
|
};
|
|
461
|
+
/**
|
|
462
|
+
* @param DBName
|
|
463
|
+
* @returns Promise
|
|
464
|
+
* @description return session from client
|
|
465
|
+
*/
|
|
466
|
+
Connection.prototype.GetDBSession = function (dbName, dbAddress) {
|
|
467
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
468
|
+
var _this = this;
|
|
469
|
+
return __generator(this, function (_a) {
|
|
470
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
471
|
+
try {
|
|
472
|
+
// if (this.connections && this.connections[Buffer.from(this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')]) {
|
|
473
|
+
//return this.FindAndReturnDBConnection(DBName, DBAddress)
|
|
474
|
+
// if (dbName == this.masterConfig.MASTER_DB_NAME) {
|
|
475
|
+
// resolve([undefined, this.connections[Buffer.from(this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')].startSession()]);
|
|
476
|
+
// }
|
|
477
|
+
if (_this.connections[Buffer.from(dbAddress).toString('base64')]) {
|
|
478
|
+
resolve([undefined, _this.connections[Buffer.from(_this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')].startSession()]);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
_this.ConnectToDb({
|
|
482
|
+
DBAddress: dbAddress,
|
|
483
|
+
DBName: dbName
|
|
484
|
+
}).then(function (success) {
|
|
485
|
+
if (_this.connections[Buffer.from(dbAddress).toString('base64')]) {
|
|
486
|
+
resolve([undefined, _this.connections[Buffer.from(dbAddress).toString('base64')].startSession()]);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
resolve([undefined, undefined]);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
// } else {
|
|
494
|
+
// let masterdb = await this.ConnectToDb({
|
|
495
|
+
// DBAddress: this.masterConfig.MASTER_CONNECTION_STRING,
|
|
496
|
+
// DBName: this.masterConfig.MASTER_DB_NAME
|
|
497
|
+
// })
|
|
498
|
+
// return this.FindAndReturnDBConnection(DBName, DBAddress)
|
|
499
|
+
// }
|
|
500
|
+
}
|
|
501
|
+
catch (ex) {
|
|
502
|
+
//To Do: Error pass properly
|
|
503
|
+
resolve([new Error('Error in Get db session'), undefined]);
|
|
504
|
+
}
|
|
505
|
+
})];
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* @param DBName
|
|
511
|
+
* @returns Promise
|
|
512
|
+
* @description return session from client
|
|
513
|
+
*/
|
|
514
|
+
Connection.prototype.GetDBClient = function (dbName, dbAddress) {
|
|
515
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
516
|
+
var _this = this;
|
|
517
|
+
return __generator(this, function (_a) {
|
|
518
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
519
|
+
try {
|
|
520
|
+
// if (this.connections && this.connections[Buffer.from(this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')]) {
|
|
521
|
+
//return this.FindAndReturnDBConnection(DBName, DBAddress)
|
|
522
|
+
// if (dbName == this.masterConfig.MASTER_DB_NAME) {
|
|
523
|
+
// resolve([undefined, this.connections[Buffer.from(this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')].startSession()]);
|
|
524
|
+
// }
|
|
525
|
+
if (_this.connections[Buffer.from(dbAddress).toString('base64')]) {
|
|
526
|
+
resolve([undefined, _this.connections[Buffer.from(_this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')]]);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
_this.ConnectToDb({
|
|
530
|
+
DBAddress: dbAddress,
|
|
531
|
+
DBName: dbName
|
|
532
|
+
}).then(function (success) {
|
|
533
|
+
if (_this.connections[Buffer.from(dbAddress).toString('base64')]) {
|
|
534
|
+
resolve([undefined, _this.connections[Buffer.from(dbAddress).toString('base64')]]);
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
resolve([undefined, undefined]);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
// } else {
|
|
542
|
+
// let masterdb = await this.ConnectToDb({
|
|
543
|
+
// DBAddress: this.masterConfig.MASTER_CONNECTION_STRING,
|
|
544
|
+
// DBName: this.masterConfig.MASTER_DB_NAME
|
|
545
|
+
// })
|
|
546
|
+
// return this.FindAndReturnDBConnection(DBName, DBAddress)
|
|
547
|
+
// }
|
|
548
|
+
}
|
|
549
|
+
catch (ex) {
|
|
550
|
+
//To Do: Error pass properly
|
|
551
|
+
resolve([new Error('Error in Get db session'), undefined]);
|
|
552
|
+
}
|
|
553
|
+
})];
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
};
|
|
461
557
|
return Connection;
|
|
462
558
|
}());
|
|
463
559
|
exports.Connection = Connection;
|
package/dist/lib/helper.d.ts
CHANGED
|
@@ -47,8 +47,10 @@ declare const GetEmailSubscribeStatus: (db: Db, email: string) => Promise<Error
|
|
|
47
47
|
* @param {isSubscribe} boolean
|
|
48
48
|
* @param {companyID} mongodb object id, comany id of email
|
|
49
49
|
* @param {comment} string , to add comment
|
|
50
|
+
* @param {mongodbQueryOptions} object, params to pass on db queries
|
|
51
|
+
* @returns resolve success | error object
|
|
50
52
|
*/
|
|
51
|
-
declare const SubscribeEmailForAllDomains: (db: Db, email: string, isSubscribe: boolean, companyID: ObjectID, comment?: string) => Promise<unknown>;
|
|
53
|
+
declare const SubscribeEmailForAllDomains: (db: Db, email: string, isSubscribe: boolean, companyID: ObjectID, comment?: string, mongodbQueryOptions?: any) => Promise<unknown>;
|
|
52
54
|
/**
|
|
53
55
|
* checking phone number is valid and has dialing code
|
|
54
56
|
* if it has dialing code then get country code, get its optimiser country phone code
|
package/dist/lib/helper.js
CHANGED
|
@@ -687,18 +687,25 @@ exports.GetEmailSubscribeStatus = GetEmailSubscribeStatus;
|
|
|
687
687
|
* @param {isSubscribe} boolean
|
|
688
688
|
* @param {companyID} mongodb object id, comany id of email
|
|
689
689
|
* @param {comment} string , to add comment
|
|
690
|
+
* @param {mongodbQueryOptions} object, params to pass on db queries
|
|
691
|
+
* @returns resolve success | error object
|
|
690
692
|
*/
|
|
691
|
-
var SubscribeEmailForAllDomains = function (db, email, isSubscribe, companyID, comment) {
|
|
693
|
+
var SubscribeEmailForAllDomains = function (db, email, isSubscribe, companyID, comment, mongodbQueryOptions) {
|
|
692
694
|
if (comment === void 0) { comment = ""; }
|
|
695
|
+
if (mongodbQueryOptions === void 0) { mongodbQueryOptions = null; }
|
|
693
696
|
return new Promise(function (resolve, reject) {
|
|
694
697
|
return __awaiter(this, void 0, void 0, function () {
|
|
695
|
-
var marketingSettingDetail, marketingCategoryKeys, domainIds_1, domainDetail, existEmailSub, isRequireUpdate, marketingCategoryData, _loop_2, i, error_2;
|
|
698
|
+
var mongodbQueryOpts, marketingSettingDetail, marketingCategoryKeys, domainIds_1, domainDetail, existEmailSub, isRequireUpdate, marketingCategoryData, _loop_2, i, error_2;
|
|
696
699
|
return __generator(this, function (_a) {
|
|
697
700
|
switch (_a.label) {
|
|
698
701
|
case 0:
|
|
699
702
|
_a.trys.push([0, 7, , 8]);
|
|
703
|
+
mongodbQueryOpts = {};
|
|
704
|
+
if (mongodbQueryOptions) {
|
|
705
|
+
mongodbQueryOpts = mongodbQueryOptions;
|
|
706
|
+
}
|
|
700
707
|
if (!email) return [3 /*break*/, 6];
|
|
701
|
-
return [4 /*yield*/, db.collection('Company').findOne({ IsActive: true }, { projection: { "Setting.MarketingSetting": 1 } })];
|
|
708
|
+
return [4 /*yield*/, db.collection('Company').findOne({ IsActive: true }, { projection: { "Setting.MarketingSetting": 1 } }, mongodbQueryOpts)];
|
|
702
709
|
case 1:
|
|
703
710
|
marketingSettingDetail = _a.sent();
|
|
704
711
|
marketingCategoryKeys = [], domainIds_1 = [];
|
|
@@ -714,7 +721,7 @@ var SubscribeEmailForAllDomains = function (db, email, isSubscribe, companyID, c
|
|
|
714
721
|
}
|
|
715
722
|
existEmailSub = {}, isRequireUpdate = false;
|
|
716
723
|
if (!(domainIds_1 && domainIds_1.length > 0)) return [3 /*break*/, 4];
|
|
717
|
-
return [4 /*yield*/, db.collection('EmailStatus').findOne({ 'EmailID': new RegExp("^" + email + "$", "i"), CompanyID: companyID }, { projection: { "Domains": 1 } })];
|
|
724
|
+
return [4 /*yield*/, db.collection('EmailStatus').findOne({ 'EmailID': new RegExp("^" + email + "$", "i"), CompanyID: companyID }, { projection: { "Domains": 1 } }, mongodbQueryOpts)];
|
|
718
725
|
case 2:
|
|
719
726
|
existEmailSub = _a.sent();
|
|
720
727
|
isRequireUpdate = true;
|
|
@@ -725,7 +732,7 @@ var SubscribeEmailForAllDomains = function (db, email, isSubscribe, companyID, c
|
|
|
725
732
|
Domains: []
|
|
726
733
|
};
|
|
727
734
|
}
|
|
728
|
-
return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: "CampaignCategory", "Data": { "$elemMatch": { "DomainID": { $in: domainIds_1 } } } }, { projection: { "Data.DomainID": 1, "Data.Key": 1, "Data.IsActive": 1 } })];
|
|
735
|
+
return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: "CampaignCategory", "Data": { "$elemMatch": { "DomainID": { $in: domainIds_1 } } } }, { projection: { "Data.DomainID": 1, "Data.Key": 1, "Data.IsActive": 1 } }, mongodbQueryOpts)];
|
|
729
736
|
case 3:
|
|
730
737
|
marketingCategoryData = _a.sent();
|
|
731
738
|
_loop_2 = function (i) {
|
|
@@ -791,9 +798,12 @@ var SubscribeEmailForAllDomains = function (db, email, isSubscribe, companyID, c
|
|
|
791
798
|
}
|
|
792
799
|
_a.label = 4;
|
|
793
800
|
case 4:
|
|
801
|
+
mongodbQueryOpts["upsert"] = true;
|
|
794
802
|
if (!isRequireUpdate) return [3 /*break*/, 6];
|
|
795
|
-
|
|
803
|
+
//await db.collection('EmailStatus').updateOne({ 'EmailID': email, CompanyID: companyID }, { $set: { Domains: existEmailSub.Domains } }, { upsert: true })
|
|
804
|
+
return [4 /*yield*/, db.collection('EmailStatus').updateOne({ 'EmailID': email, CompanyID: companyID }, { $set: { Domains: existEmailSub.Domains } }, mongodbQueryOpts)];
|
|
796
805
|
case 5:
|
|
806
|
+
//await db.collection('EmailStatus').updateOne({ 'EmailID': email, CompanyID: companyID }, { $set: { Domains: existEmailSub.Domains } }, { upsert: true })
|
|
797
807
|
_a.sent();
|
|
798
808
|
_a.label = 6;
|
|
799
809
|
case 6:
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as net from 'net';
|
|
3
|
+
import { AnyObjectInterface } from '../modals/utility.modal';
|
|
4
|
+
declare class MemoryDBConnect {
|
|
5
|
+
private client?;
|
|
6
|
+
private portNo;
|
|
7
|
+
private host;
|
|
8
|
+
private isConnected;
|
|
9
|
+
private messages;
|
|
10
|
+
/**
|
|
11
|
+
* @param masterConfig Master Connectivity Object
|
|
12
|
+
* @param redisClient Redisclient
|
|
13
|
+
* @description connect to master database and maintain master config and redis client for furture ref
|
|
14
|
+
*/
|
|
15
|
+
constructor(portNumber: number, hostName: string);
|
|
16
|
+
/**
|
|
17
|
+
* @description connect to memory server on specified port and host
|
|
18
|
+
* @returns Promise with error first approach and success | failed.
|
|
19
|
+
*/
|
|
20
|
+
Initialize(): Promise<[Error?, string?]>;
|
|
21
|
+
/**
|
|
22
|
+
* @param method specifies the function of memory server which needs to execute
|
|
23
|
+
* @param data an object which has data for memory server
|
|
24
|
+
* @param data.CompanyID
|
|
25
|
+
* @param data.DataSet name of dataset to refer the data in memory server
|
|
26
|
+
* @param data.findQuery query by data need to retrieve from memory server
|
|
27
|
+
* @param data.FullDoc data to add, update and delete in memeory server
|
|
28
|
+
* @description write to server stream of memory server and data data from memory server by specific message id
|
|
29
|
+
* LOV:
|
|
30
|
+
* method : search | execute | insertInDataSet | updateInDataSet | deleteInDataSet
|
|
31
|
+
*/
|
|
32
|
+
Fetch(method: string, data: AnyObjectInterface): Promise<[any?, AnyObjectInterface?]>;
|
|
33
|
+
/**
|
|
34
|
+
* @description get connection object of memory server if already created other wise create and provide.
|
|
35
|
+
* @returns null | socket client
|
|
36
|
+
*/
|
|
37
|
+
Connect(): Promise<net.Socket | undefined>;
|
|
38
|
+
}
|
|
39
|
+
export { MemoryDBConnect };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.MemoryDBConnect = void 0;
|
|
59
|
+
//var net = require('net');
|
|
60
|
+
var net = __importStar(require("net"));
|
|
61
|
+
var crypto = __importStar(require("crypto"));
|
|
62
|
+
var MemoryDBConnect = /** @class */ (function () {
|
|
63
|
+
/**
|
|
64
|
+
* @param masterConfig Master Connectivity Object
|
|
65
|
+
* @param redisClient Redisclient
|
|
66
|
+
* @description connect to master database and maintain master config and redis client for furture ref
|
|
67
|
+
*/
|
|
68
|
+
function MemoryDBConnect(portNumber, hostName) {
|
|
69
|
+
this.client = undefined;
|
|
70
|
+
this.portNo = 0;
|
|
71
|
+
this.host = "";
|
|
72
|
+
this.isConnected = false;
|
|
73
|
+
this.messages = {};
|
|
74
|
+
this.portNo = portNumber;
|
|
75
|
+
this.host = hostName;
|
|
76
|
+
// this.Initialize().then(([error, result]) => {
|
|
77
|
+
// if (result == 'failed') {
|
|
78
|
+
// console.log('connection to memory server failed');
|
|
79
|
+
// }
|
|
80
|
+
// })
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @description connect to memory server on specified port and host
|
|
84
|
+
* @returns Promise with error first approach and success | failed.
|
|
85
|
+
*/
|
|
86
|
+
MemoryDBConnect.prototype.Initialize = function () {
|
|
87
|
+
var _this = this;
|
|
88
|
+
return new Promise(function (resolve, reject) {
|
|
89
|
+
var newConnectRequest = true;
|
|
90
|
+
_this.client = new net.Socket();
|
|
91
|
+
_this.client.connect(_this.portNo, _this.host, function () {
|
|
92
|
+
_this.isConnected = true;
|
|
93
|
+
console.log("client connected to " + _this.portNo + ":" + _this.host);
|
|
94
|
+
if (newConnectRequest) {
|
|
95
|
+
resolve([undefined, 'success']);
|
|
96
|
+
newConnectRequest = false;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
_this.client.on('data', function (data) {
|
|
100
|
+
console.log("Data from MemServer", (data || "").toString());
|
|
101
|
+
//console.log("")
|
|
102
|
+
var message = null;
|
|
103
|
+
try {
|
|
104
|
+
data = JSON.parse(data);
|
|
105
|
+
message = _this.messages[data.id];
|
|
106
|
+
if (message) {
|
|
107
|
+
delete _this.messages[data.id];
|
|
108
|
+
message(data);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.log("Error in parsing MemServer data", error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
_this.client.on('close', function () {
|
|
116
|
+
_this.isConnected = false;
|
|
117
|
+
console.log("Client closed for port:host - " + _this.portNo + ":" + _this.host);
|
|
118
|
+
if (newConnectRequest) {
|
|
119
|
+
resolve([undefined, 'failed']);
|
|
120
|
+
newConnectRequest = false;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
_this.client.on('error', function (err) {
|
|
124
|
+
console.error('Error in Memory server socket', err);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @param method specifies the function of memory server which needs to execute
|
|
130
|
+
* @param data an object which has data for memory server
|
|
131
|
+
* @param data.CompanyID
|
|
132
|
+
* @param data.DataSet name of dataset to refer the data in memory server
|
|
133
|
+
* @param data.findQuery query by data need to retrieve from memory server
|
|
134
|
+
* @param data.FullDoc data to add, update and delete in memeory server
|
|
135
|
+
* @description write to server stream of memory server and data data from memory server by specific message id
|
|
136
|
+
* LOV:
|
|
137
|
+
* method : search | execute | insertInDataSet | updateInDataSet | deleteInDataSet
|
|
138
|
+
*/
|
|
139
|
+
MemoryDBConnect.prototype.Fetch = function (method, data) {
|
|
140
|
+
var _this = this;
|
|
141
|
+
return new Promise(function (resolve, reject) {
|
|
142
|
+
var _a;
|
|
143
|
+
try {
|
|
144
|
+
console.log('socket connected==>', (_a = _this.client) === null || _a === void 0 ? void 0 : _a.connect);
|
|
145
|
+
var id = crypto.randomBytes(16).toString("hex");
|
|
146
|
+
var message_1 = { id: id, method: method, data: data, status: "0" };
|
|
147
|
+
_this.messages[id] = function (res) {
|
|
148
|
+
if (message_1.status == "0") {
|
|
149
|
+
resolve([undefined, res]);
|
|
150
|
+
message_1.status = "1";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
//timeout event binding : after 30seconds request willbe timeout
|
|
154
|
+
setTimeout(function () {
|
|
155
|
+
if (message_1.status == "0") {
|
|
156
|
+
console.log("memory server request timed out");
|
|
157
|
+
resolve([new Error("REQUEST_TIMEDOUT"), undefined]);
|
|
158
|
+
message_1.status = "-1";
|
|
159
|
+
}
|
|
160
|
+
}, 30000);
|
|
161
|
+
if (_this.client && _this.isConnected) {
|
|
162
|
+
_this.client.write(JSON.stringify(message_1));
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
//to avoid again resolve by set timeout
|
|
166
|
+
message_1.status = "-1";
|
|
167
|
+
resolve([new Error('CLIENT_NOT_CONNECTED'), undefined]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
resolve([err, undefined]);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* @description get connection object of memory server if already created other wise create and provide.
|
|
177
|
+
* @returns null | socket client
|
|
178
|
+
*/
|
|
179
|
+
MemoryDBConnect.prototype.Connect = function () {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
var _a, error, result;
|
|
182
|
+
return __generator(this, function (_b) {
|
|
183
|
+
switch (_b.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
if (!(this.client == null || this.isConnected == false)) return [3 /*break*/, 2];
|
|
186
|
+
return [4 /*yield*/, this.Initialize()];
|
|
187
|
+
case 1:
|
|
188
|
+
_a = _b.sent(), error = _a[0], result = _a[1];
|
|
189
|
+
if (result != 'success') {
|
|
190
|
+
console.log('memory server socket connection not initialized');
|
|
191
|
+
//To Do : add code for handling this situation after getting some clarity on work.
|
|
192
|
+
}
|
|
193
|
+
_b.label = 2;
|
|
194
|
+
case 2:
|
|
195
|
+
//check client connected code : to do list by satyam
|
|
196
|
+
return [2 /*return*/, this.client];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
return MemoryDBConnect;
|
|
202
|
+
}());
|
|
203
|
+
exports.MemoryDBConnect = MemoryDBConnect;
|
|
@@ -3,4 +3,63 @@ import { AnyObjectInterface } from "../modals/utility.modal";
|
|
|
3
3
|
declare const GetIntegrationSettings: (db: Db, hotelCode: string) => Promise<Error | AnyObjectInterface | null>;
|
|
4
4
|
declare const SyncContactWithOperaOnEmailUnsubscribe: (db: Db, email: string) => void;
|
|
5
5
|
declare const OperaErrorHandler: (db: Db, ex: Error) => void;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* This function is used to search profiles by dynamics fields in both Memory server and db.
|
|
8
|
+
* If data found in memory server then it search data by _id in db the return data.
|
|
9
|
+
*
|
|
10
|
+
* @param params.ModuleName Name of Module either Account | Contact.
|
|
11
|
+
* @param params.MappingFields fields which is used for searching
|
|
12
|
+
* @param params.ModuleData Data of fields
|
|
13
|
+
* @param params.db database objects
|
|
14
|
+
* @param params.MongodbTransactionQueryOptions Mongodb query option, it may have transaction as well.
|
|
15
|
+
* @param params.SelectedFields to get only selected fields
|
|
16
|
+
* @param params.AllowInactive to search data without IsActive field.
|
|
17
|
+
* @param params.SearchFromMemoryServer to indicate searcing is to do from memory server
|
|
18
|
+
* @param params.MemoryServerClient memory server client object to get data from memory server
|
|
19
|
+
* @param params.CompanyId to indicate searcing is to do from memory server
|
|
20
|
+
* @param params.DataSet to indicate searcing is to do from memory server
|
|
21
|
+
*
|
|
22
|
+
* @returns [error,ResultData]
|
|
23
|
+
*/
|
|
24
|
+
declare const GetProfileDetailByDynamicFields: (params: AnyObjectInterface) => Promise<any[]>;
|
|
25
|
+
/**
|
|
26
|
+
* This function is used to update data.
|
|
27
|
+
* @param params.ModuleName Name of Module either Account | Contact.
|
|
28
|
+
* @param params.Collection Name of Collection
|
|
29
|
+
* @param params.Id which doucment has to update
|
|
30
|
+
* @param params.db database objects
|
|
31
|
+
* @param params.MongodbTransactionQueryOptions Mongodb query option object , it may have transaction as well.
|
|
32
|
+
* @param params.UpdateObj to update data in collection.
|
|
33
|
+
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
declare const UpdateInitialSyncData: (params: AnyObjectInterface) => Promise<unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* This function is used to stop unnecessary databse hits for checking any data available send to opera.
|
|
39
|
+
* this flag will be in reddis
|
|
40
|
+
* @param params.RedisClient reddis client
|
|
41
|
+
* @param params.CompanyId to create/check opera key with company id
|
|
42
|
+
* @param params.Mode GET/SET operation to perform on reddis
|
|
43
|
+
* @param params.db database objects
|
|
44
|
+
* @param params.isAvailable value to set in reddis
|
|
45
|
+
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
declare const AddToQueueForOpera: (params: AnyObjectInterface) => Promise<any[] | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* This function is used to search data in case of contact from memory server using email
|
|
51
|
+
* @param params.db database objects
|
|
52
|
+
* @param params.ProfileType profile type account/contact
|
|
53
|
+
* @param params.PrimaryEmail primary email
|
|
54
|
+
* @param params.SecondaryEmail secondary email
|
|
55
|
+
* @param params.MongodbTransactionQueryOptions Mongodb query option, it may have transaction as well.
|
|
56
|
+
* @param params.SelectedFields to get only selected fields
|
|
57
|
+
* @param params.SearchFromMemoryServer to indicate searcing is to do from memory server
|
|
58
|
+
* @param params.MemoryServerClient memory server client object to get data from memory server
|
|
59
|
+
* @param params.CompanyId to indicate searcing is to do from memory server
|
|
60
|
+
* @param params.DataSet to indicate searcing is to do from memory server
|
|
61
|
+
*
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
declare const EmailPrioritySearch: (params: AnyObjectInterface) => Promise<unknown>;
|
|
65
|
+
export { GetIntegrationSettings, SyncContactWithOperaOnEmailUnsubscribe, OperaErrorHandler, GetProfileDetailByDynamicFields, UpdateInitialSyncData, AddToQueueForOpera, EmailPrioritySearch };
|