@resolveio/server-lib 20.3.28 → 20.4.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.
- package/managers/cron.manager.js +1 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.d.ts +2 -2
- package/managers/method.manager.js +1 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +8 -24
- package/managers/mongo.manager.js +1 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +1 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +6 -6
- package/managers/subscription.manager.js +1 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +1 -1
- package/managers/subscription.performance.js.map +1 -1
- package/managers/websocket.manager.d.ts +25 -0
- package/managers/websocket.manager.js +2 -0
- package/managers/websocket.manager.js.map +1 -0
- package/methods/accounts.js +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/cron-jobs.js +1 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/report-builder.js +1 -1
- package/methods/report-builder.js.map +1 -1
- package/package.json +5 -2
- package/server-app.d.ts +4 -5
- package/server-app.js +1 -1
- package/server-app.js.map +1 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +1 -1
- package/util/schema-report-builder.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/subscription.manager.ts"],"names":["logs_1","require","app_status_1","files_1","super_admin_1","logged_in_users_collection_1","cron_jobs_1","flags_1","method_responses_1","index_1","notifications_1","report_builder_reports_1","report_builder_libraries_1","user_groups_1","user_guides_1","report_builder_dashboard_builders_1","mongo_manager_1","common_1","NodeCache","flag_collection_1","os_1","numCPUs","cpus","length","v8","SubscriptionManager","mainServer","wss","serverConfig","monitorManagerFunction","_this","this","_publications","_subscriptions","_loggedInUsers","_mongoQueue","_mongoQueueId","_sendQueue","_runningQueue","_cacheId","_heapStats","getHeapStatistics","_heapLimit","heap_size_limit","_enableDebug","_debugOplogCollections","_debugOplogHits","_debugSubCollections","_debugSubHits","_debugUnSubHits","_debugUnSubAllHits","_debugMongoQueueHits","_debugMongoQueueCollections","_debugSendQueueHits","_debugRemoveCacheHits","_oplogRetryCount","_mainServer","_monitorManagerFunction","_nodeCache","stdTTL","checkperiod","_wss","loadSuperAdminPublications","loadAppStatusPublications","loadLogPublications","loadFilePublications","loadCronJobPublications","loadFlagsPublications","loadMethodResponsePublications","loadNotificationPublications","loadReportBuilderReportPublications","loadReportBuilderLibraryPublications","loadUserGroupPublications","loadUserGuidePublications","loadReportBuilderDashboardBuilderPublications","tailOpLog","setInterval","getEnableDebug","console","log","Date","JSON","stringify","sort","a","b","collection","localeCompare","publication","type","__awaiter","i","this_1","sendItem","ws","getWS","id_ws","readyState","OPEN","bufferedAmount","pop","send","data","error","unsubscribeAll","splice","queueArr","filter","running","forEach","entry","this_2","mongoQueue","some","subscription","hits","push","user_specific","promises","j","clients","client","id_socket","sendDataToOne","messageId","catch","err","getMethodManager","sendEmail","id_user","Promise","all","then","run_again","map","_id","indexOf","sendDataToAll","_a","LoggedInUsers","find","_b","sent","userCopy","deepCopy","loggedInUser","date","now","getTime","this_3","sub","deleteOne","findIndex","this_4","Flags","findOne","flag","value","prototype","addToQueue","subscriptionData","invalidatePubsCache","ResolveIOServer","getMongoManager","invalidateQueryCache","collSubs","collections","includes","publications","method","Object","assign","loggedInLatency","updateOne","$set","latency","res","subscribe","messageRoute","messageDate","pub","check","_schema","valObj","rootKeys","keys","validate","errors","urlData","split","urlModule_1","urlNext","otherRouteSubs","startsWith","otherSub","unsubscribe","sub_1","getPublicationCollections","cacheId","createLoggedInUser","resolve","reject","user","objectIdHexString","__v","insertOne","userSubs","close","process","nextTick","CLOSING","terminate","getActiveSubscriptions","resumeToken","_oplog$","closed","removeAllListeners","setTimeout","exit","lastResumeToken_1","getMainDB","watch","resumeAfter","errOp","on","doc","ns","coll","operationType","endsWith","callMethodInternal","call","documentKey","monitor_1","startMonitorFunction","function","apply","__spreadArray","finishMonitorFunction","sendWS","hasError","cacheData","parse","get","dateReviver","serverRes","del","monitor_2","nodeCacheSize","getStats","vsize","deleteCount","subArr","zz","set","exports"],"mappings":"wqDAGAA,Q,0FAAAC,QAAA,sBAAA,GACAC,aAAAD,QAAA,4BAAA,EACAE,QAAAF,QAAA,uBAAA,EACAG,cAAAH,QAAA,6BAAA,EACAI,6BAAAJ,QAAA,2CAAA,EACAK,YAAAL,QAAA,2BAAA,EACAM,QAAAN,QAAA,uBAAA,EACAO,mBAAAP,QAAA,kCAAA,EAEAQ,QAAAR,QAAA,UAAA,EACAS,gBAAAT,QAAA,+BAAA,EACAU,yBAAAV,QAAA,wCAAA,EAIAW,2BAAAX,QAAA,0CAAA,EACAY,cAAAZ,QAAA,6BAAA,EACAa,cAAAb,QAAA,6BAAA,EACAc,oCAAAd,QAAA,mDAAA,EACAe,gBAAAf,QAAA,iBAAA,EACAgB,SAAAhB,QAAA,gBAAA,EACAiB,UAAAjB,QAAA,YAAA,EAEAkB,kBAAAlB,QAAA,gCAAA,EACAmB,KAAAnB,QAAA,IAAA,EACMoB,SAAU,EAAAD,KAAAE,MAAI,EAAGC,OACjBC,GAAKvB,QAAQ,IAAI,EA0BvBwB,oBAAA,WA4CC,SAAAA,oBAAYC,EAAYC,EAAuBC,EAAcC,GAA7D,IAAAC,EAAAC,KAzCQA,KAAAC,cAAmC,GACnCD,KAAAE,eAA4C,GAE5CF,KAAAG,eAAsC,GAEtCH,KAAAI,YAAiC,GACjCJ,KAAAK,cAAgB,EAEhBL,KAAAM,WAAa,GACbN,KAAAO,cAAgB,CAAA,EAKhBP,KAAAQ,SAAW,EAIXR,KAAAS,WAAahB,GAAGiB,kBAAiB,EACjCV,KAAAW,WAAaX,KAAKS,WAAWG,gBAAkBtB,QAAU,EAIzDU,KAAAa,aAAe,CAAA,EACfb,KAAAc,uBAAyB,GACzBd,KAAAe,gBAAkB,EAClBf,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1B,aAAeP,KAAKC,UAAUE,EAAE4E,gBAAgB,IAAM/E,KAAKC,UAAU8B,EAAWE,aAAa8C,gBAAgB,CAAvJ,CAAwJ,GAC9LjI,KAAKE,eAAewE,OAAO1E,KAAKE,eAAeuH,UAAU,SAAApE,GAAK,OAAAA,EAAEI,cAAgBwB,EAAWE,aAAa1B,aAAeP,KAAKC,UAAUE,EAAE4E,gBAAgB,IAAM/E,KAAKC,UAAU8B,EAAWE,aAAa8C,gBAAgB,CAAvJ,CAAwJ,EAAG,CAAC,EAG3NwC,EAAQ,CAAA,CAAK,G,QAsJd,CACF,EAEQ/K,oBAAAqI,UAAAiF,OAAR,SAAejJ,EAAeQ,GAC7BvE,KAAKM,WAAWoE,OAAO,EAAG,EAAG,CAC5BT,MAAOF,EAAc,UACrBQ,KAAMA,C,CACN,CACF,EAEO7E,oBAAAqI,UAAAjF,eAAP,WACC,OAAO9C,KAAKa,YACb,EACDnB,mBAAA,EAAC,EA/nCYsO,QAAAtO,oBAAAA","file":"subscription.manager.js","sourcesContent":["import { ServerResponseModel } from '../models/server-response.model';\nimport { ActiveSubscriptionModel, SubscriptionModel } from '../models/subscription.model';\nimport * as WebSocket from 'ws';\nimport { loadLogPublications } from '../publications/logs';\nimport { loadAppStatusPublications } from '../publications/app-status';\nimport { loadFilePublications } from '../publications/files';\nimport { loadSuperAdminPublications } from '../publications/super-admin';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { loadCronJobPublications } from '../publications/cron-jobs';\nimport { loadFlagsPublications } from '../publications/flags';\nimport { loadMethodResponsePublications } from '../publications/method-responses';\nimport ResolveIOMainServer from '../server-app';\nimport { ResolveIOServer } from '../index';\nimport { loadNotificationPublications } from '../publications/notifications';\nimport { loadReportBuilderReportPublications } from '../publications/report-builder-reports';\nimport { LoggedInUserModel } from '../models/logged-in-users.model';\n\nimport { ChangeStream, ChangeStreamDeleteDocument, ChangeStreamDocument, ChangeStreamInsertDocument, ChangeStreamReplaceDocument, ChangeStreamUpdateDocument, ResumeToken } from 'mongodb';\nimport { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';\nimport { loadUserGroupPublications } from '../publications/user-groups';\nimport { loadUserGuidePublications } from '../publications/user-guides';\nimport { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';\nimport { objectIdHexString } from './mongo.manager';\nimport { dateReviver, deepCopy } from '../util/common';\nimport * as NodeCache from 'node-cache';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { Flags } from '../collections/flag.collection';\nimport { cpus } from 'os';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\n\n// Performance Dependencies\n// import * as path from 'path';\n// import { Worker } from 'worker_threads';\n\ninterface MongoQueueModel {\n\t_id: number,\n\ttype: string;\n\tcollection: string;\n\tsubscription: ActiveSubscriptionModel;\n\trunning: boolean;\n\trun_again: boolean;\n}\n\n// interface CurrentPerformanceMonitor {\n// \t_id: number;\n// \tfunction: string;\n// \tpublication: string;\n// \tsubscriptionData: any[];\n// \tdate_start: Date;\n// \tdate_end: Date;\n// \tduration: number;\n// \tresult: string;\n// }\n\nexport class SubscriptionManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _publications: SubscriptionModel = {};\n\tprivate _subscriptions: ActiveSubscriptionModel[] = [];\n\tprivate _wss: WebSocket.Server;\n\tprivate _loggedInUsers: LoggedInUserModel[] = [];\n\n\tprivate _mongoQueue: MongoQueueModel[] = [];\n\tprivate _mongoQueueId = 0;\n\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\t\n\tprivate _oplog$: ChangeStream;\n\n\tprivate _nodeCache;\n\tprivate _cacheId = 1;\n\n\tprivate serverConfig;\n\n\tprivate _heapStats = v8.getHeapStatistics();\n\tprivate _heapLimit = this._heapStats.heap_size_limit / numCPUs / 8;\n\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\n\tprivate _enableDebug = false;\n\tprivate _debugOplogCollections = [];\n\tprivate _debugOplogHits = 0;\n\tprivate _debugSubCollections = [];\n\tprivate _debugSubHits = 0;\n\tprivate _debugUnSubHits = 0;\n\tprivate _debugUnSubAllHits = 0;\n\tprivate _debugMongoQueueHits = 0;\n\tprivate _debugMongoQueueCollections = [];\n\tprivate _debugSendQueueHits = 0;\n\tprivate _debugRemoveCacheHits = 0;\n\n\tprivate _oplogRetryCount = 0;\n\n\t// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];\n\t// private idPerformance: number = 0;\n\t// private performanceThread;\n\n\tconstructor(mainServer, wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\n\t\tthis._nodeCache = new NodeCache( { stdTTL: 0, checkperiod: 0 } );\n\n\t\t// setTimeout(() => {\n\t\t// \tconsole.log('Setting up performance thread');\n\n\t\t// \tthis.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));\n\n\t\t// \tthis.performanceThread.on('exit', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\n\t\t// \tthis.performanceThread.on('error', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\t\t// }, 5000);\n\n\t\t// setInterval(() => {\n\t\t// \tconsole.log('Post thread msg');\n\t\t// \tthis.performanceThread.postMessage(this.currentPerfomanceMonitor);\n\t\t// \tthis.currentPerfomanceMonitor = [];\n\t\t// }, 10000);\n\n\t\tthis.serverConfig = serverConfig;\n\t\tthis._wss = wss;\n\n\t\t// Publications\n\t\tloadSuperAdminPublications(this);\n\t\tloadAppStatusPublications(this);\n\t\tloadLogPublications(this);\n\t\tloadFilePublications(this);\n\t\tloadCronJobPublications(this);\n\t\tloadFlagsPublications(this);\n\t\tloadMethodResponsePublications(this);\n\t\tloadNotificationPublications(this);\n\t\tloadReportBuilderReportPublications(this);\n\t\tloadReportBuilderLibraryPublications(this);\n\t\tloadUserGroupPublications(this);\n\t\tloadUserGuidePublications(this);\n\t\tloadReportBuilderDashboardBuilderPublications(this);\n\n\t\tthis.tailOpLog();\n\n\t\tsetInterval(() => {\n\t\t\tthis._oplogRetryCount = 0;\n\t\t}, 15000);\n\n\t\tsetInterval(() => {\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Subs', this._subscriptions.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Logged In Users', this._loggedInUsers.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue', this._mongoQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', this._debugMongoQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(this._debugMongoQueueCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Hits', this._debugOplogHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(this._debugOplogCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Hits', this._debugSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(this._debugSubCollections.sort((a, b) => a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub Hits', this._debugUnSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub All Hits', this._debugUnSubAllHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', this._debugRemoveCacheHits);\n\t\t\t}\n\t\t\t\n\t\t\tthis._debugOplogHits = 0;\n\t\t\tthis._debugOplogCollections = [];\n\t\t\tthis._debugSubCollections = [];\n\t\t\tthis._debugMongoQueueHits = 0;\n\t\t\tthis._debugMongoQueueCollections = [];\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t\tthis._debugSubHits = 0;\n\t\t\tthis._debugUnSubHits = 0;\n\t\t\tthis._debugUnSubAllHits = 0;\n\t\t\tthis._debugRemoveCacheHits = 0;\n\t\t}, 60000);\n\n\t\tsetInterval(async () => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tthis._runningQueue = true;\n\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\t// let startDate = new Date();\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tthis._debugSendQueueHits += 1;\n\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.data), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 1);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._sendQueue.splice(i, 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendInterval',\n\t\t\t\t\t// \tpublication: '',\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Done'\n\t\t\t\t\t// });\n\t\t\t\t}\n\n\t\t\t\tconst queueArr = this._mongoQueue.filter(a => !a.running);\n\t\t\t\tif (queueArr.length) {\n\t\t\t\t\tqueueArr.forEach(entry => {\n\t\t\t\t\t\tentry.running = true;\n\t\t\t\t\t});\n\n\t\t\t\t\tfor (let i = queueArr.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tthis._debugMongoQueueHits += 1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tlet mongoQueue = queueArr[i];\n\n\t\t\t\t\t\tif (!this._debugMongoQueueCollections.some(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)) {\n\t\t\t\t\t\t\tthis._debugMongoQueueCollections.push({\n\t\t\t\t\t\t\t\tcollection: mongoQueue.collection,\n\t\t\t\t\t\t\t\tpublication: mongoQueue.subscription.publication,\n\t\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._debugMongoQueueCollections.filter(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)[0].hits += 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this._publications[mongoQueue.subscription.publication].user_specific) {\n\t\t\t\t\t\t\tlet promises = [];\n\t\t\t\t\t\t\tfor (let j = 0; j < mongoQueue.subscription.clients.length; j++) {\n\t\t\t\t\t\t\t\tlet client = mongoQueue.subscription.clients[j];\n\t\t\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\t\t\t\t\t\t\t\tif (ws && ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t\t\t\t\tpromises.push(this.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch((err) => {\n\t\t\t\t\t\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));\n\t\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tPromise.all(promises).then(() => {\n\t\t\t\t\t\t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t\t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t\t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis.sendDataToAll(mongoQueue).then(() => {\n\t\t\t\t\t\t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t\t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t\t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, () => {\n\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'mongoQueue',\n\t\t\t\t\t// \tpublication: '',\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Done'\n\t\t\t\t\t// });\n\t\t\t\t}\t\n\n\t\t\t\tthis._runningQueue = false;\n\t\t\t}\n\t\t}, 1);\n\n\t\tsetInterval(async () => {\n\t\t\tthis._loggedInUsers = await LoggedInUsers.find();\n\t\n\t\t\tlet userCopy = deepCopy(this._loggedInUsers);\n\t\t\tfor (let i = this._loggedInUsers.length - 1; i >= 0; i--) {\n\t\t\t\tlet loggedInUser = userCopy[i];\n\n\t\t\t\tif (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {\n\t\t\t\t\tif (this._mainServer.getWS(loggedInUser.id_ws)) {\n\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', this._mainServer.getWS(loggedInUser.id_ws)['user'], this._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.unsubscribeAll(this._mainServer.getWS(loggedInUser.id_ws));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._subscriptions.forEach(sub => {\n\t\t\t\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\t\t\t\tif (client.id_socket === loggedInUser.id_ws) {\n\t\t\t\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\n\t\t\t\t\t\tif (this._loggedInUsers.findIndex(a => a._id === loggedInUser._id) >= 0) {\n\t\t\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.findIndex(a => a._id === loggedInUser._id), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < this._subscriptions.length; i++) {\n\t\t\t\tlet sub = this._subscriptions[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\tif (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, 30000);\n\n\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addToQueue(mongoQueue: MongoQueueModel) {\n\t\t// let startDate = new Date();\n\n\t\tlet _mongoQueue = this._mongoQueue.filter(a => a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData))[0];\n\t\t\n\t\tif (_mongoQueue) {\n\t\t\tif (_mongoQueue.running) {\n\t\t\t\t_mongoQueue.run_again = true;\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'addToQueue',\n\t\t\t\t// \tpublication: mongoQueue.subscription.publication,\n\t\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Run Again'\n\t\t\t\t// });\n\t\t\t}\n\t\t\t// else {\n\t\t\t// \tlet endDate = new Date();\n\t\t\t// \tthis.currentPerfomanceMonitor.push({\n\t\t\t// \t\t_id: this.idPerformance++,\n\t\t\t// \t\tfunction: 'addToQueue',\n\t\t\t// \t\tpublication: mongoQueue.subscription.publication,\n\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t// \t\tsubscriptionData: [],\n\t\t\t// \t\tdate_start: startDate,\n\t\t\t// \t\tdate_end: endDate,\n\t\t\t// \t\tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \t\tresult: 'Not Running Yet'\n\t\t\t// \t});\n\t\t\t// }\n\t\t}\n\t\telse {\n\t\t\tmongoQueue._id = this._mongoQueueId;\n\t\t\tthis._mongoQueueId += 1;\n\n\t\t\tthis._mongoQueue.splice(0, 0, mongoQueue);\n\t\t\t\n\t\t\t// let endDate = new Date();\n\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t// \t_id: this.idPerformance++,\n\t\t\t// \tfunction: 'addToQueue',\n\t\t\t// \tpublication: mongoQueue.subscription.publication,\n\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t// \tsubscriptionData: [],\n\t\t\t// \tdate_start: startDate,\n\t\t\t// \tdate_end: endDate,\n\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \tresult: 'Add to Queue'\n\t\t\t// });\n\t\t}\n\t}\n\n\tpublic invalidatePubsCache(collection, type) {\n\t\t// let startDate = new Date();\n\n\t\tResolveIOServer.getMongoManager().invalidateQueryCache(collection);\n\t\t\n\t\tlet collSubs = this._subscriptions.filter(a => a.collections.includes(collection));\n\n\t\tfor (let i = collSubs.length - 1; i >= 0; i--) {\n\t\t\tlet sub = collSubs[i];\n\t\t\t\n\t\t\tthis.addToQueue({\n\t\t\t\t_id: 0,\n\t\t\t\ttype: type,\n\t\t\t\tcollection: collection,\n\t\t\t\tsubscription: sub,\n\t\t\t\trunning: false,\n\t\t\t\trun_again: false\n\t\t\t});\n\t\t}\n\n\t\t// let endDate = new Date();\n\t\t// this.currentPerfomanceMonitor.push({\n\t\t// \t_id: this.idPerformance++,\n\t\t// \tfunction: 'invalidatePubsCache',\n\t\t// \tpublication: collection,\n\t\t// \tsubscriptionData: [],\n\t\t// \tdate_start: startDate,\n\t\t// \tdate_end: endDate,\n\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t// \tresult: 'Done'\n\t\t// });\n\t}\n\n\t// Add all files to publications private object\n\tpublic publications(method: SubscriptionModel) {\n\t\tthis._publications = Object.assign(this._publications, method);\n\t}\n\n\tpublic loggedInLatency(ws: WebSocket) {\n\t\tlet loggedInUser = this._loggedInUsers.filter(a => a.id_ws === ws['id_socket'])[0];\n\n\t\tif (loggedInUser) {\n\t\t\tloggedInUser.date = new Date();\n\n\t\t\tLoggedInUsers.updateOne({id_ws: ws['id_socket']}, {$set: {latency: ws['latency'], date: loggedInUser.date}}).then(res => {\n\t\t\t\tif (!res) {\n\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 3);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {\n\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 4);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// Subscribe to publication\n\tpublic subscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\t// let startDate = new Date();\n\t\tthis._debugSubHits += 1;\n\n\t\tif (!this._debugSubCollections.some(a => a.publication === publication)) {\n\t\t\tthis._debugSubCollections.push({\n\t\t\t\tpublication: publication,\n\t\t\t\thits: 1\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._debugSubCollections.filter(a => a.publication === publication)[0].hits += 1;\n\t\t}\n\n\t\tlet pub = this._publications[publication];\n\n\t\tif (!pub) {\n\t\t\tconsole.error(new Date(), 'No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tif (subscriptionData.length > 1 || subscriptionData[0]) {\n\t\t\t\tif (!pub.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (!pub.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet valObj = {};\n\t\t\t\t\tlet valKeys = Object.keys(pub.check._schema);\n\n\t\t\t\t\tlet rootKeys = valKeys.filter(a => !a.includes('.'));\n\t\t\t\t\t\n\t\t\t\t\tfor (let i = 0; i < subscriptionData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = subscriptionData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tif (errors) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messageRoute !== 'Bypass') {\n\t\t\t\tlet urlData = messageRoute.split('/');\n\t\t\t\tlet urlModule = '';\n\t\t\t\tlet urlNext = urlData[0];\n\t\t\t\t\n\t\t\t\tif (urlData[0] === '') {\n\t\t\t\t\turlModule = '/';\n\t\t\t\t\turlNext = urlData[1];\n\t\t\t\t}\n\n\t\t\t\turlModule += urlNext;\n\n\t\t\t\tif (urlData.length > 1) {\n\t\t\t\t\turlModule += '/';\n\t\t\t\t}\n\n\t\t\t\tlet otherRouteSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule)));\n\t\t\t\n\t\t\t\tif (otherRouteSubs.length) {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));\n\n\t\t\t\t\totherRouteSubs.forEach(otherSub => {\n\t\t\t\t\t\totherSub.clients.filter(a => a.id_socket === ws['id_socket']).forEach(client => {\n\t\t\t\t\t\t\tthis.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet sub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\n\t\t\t// If sub found (another user watching same data), add client to same sub\n\t\t\tif (sub) {\n\t\t\t\tif (!sub.clients.some(a => a.id_socket === ws['id_socket'] && a.messageId === messageId)) {\n\t\t\t\t\tsub.clients.push({\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If sub not found, create new sub\n\t\t\telse {\n\t\t\t\tthis._subscriptions.push({\n\t\t\t\t\tpublication: publication,\n\t\t\t\t\tsubscriptionData: subscriptionData,\n\t\t\t\t\tcollections: this.getPublicationCollections(publication),\n\t\t\t\t\tclients: [{\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t}],\n\t\t\t\t\tcacheId: 0\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!sub) {\n\t\t\t\tsub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\t\t\t}\n\n\t\t\tif (!sub.cacheId && !this._mongoQueue.some(a => a.subscription.publication === sub.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub.subscriptionData))) {\n\t\t\t\tthis.addToQueue({\n\t\t\t\t\t_id: 0,\n\t\t\t\t\ttype: 'newSub',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tsubscription: sub,\n\t\t\t\t\trunning: false,\n\t\t\t\t\trun_again: false\n\t\t\t\t});\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'subscribe',\n\t\t\t\t// \tpublication: publication,\n\t\t\t\t// // \tsubscriptionData: subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Add to Queue'\n\t\t\t\t// });\n\t\t\t}\n\t\t\telse if (sub.cacheId) {\n\t\t\t\tthis.sendDataToOne(ws, messageId, sub, 'newSub', publication);\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'subscribe',\n\t\t\t\t// \tpublication: publication,\n\t\t\t\t// // \tsubscriptionData: subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Send Pub Data Once'\n\t\t\t\t// });\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async createLoggedInUser(id_ws: string): Promise<LoggedInUserModel> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tlet ws = this._mainServer.getWS(id_ws);\n\n\t\t\tif (ws) {\n\t\t\t\tlet user = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tid_ws: ws['id_socket']\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tthis._loggedInUsers.push(user);\n\t\t\t\tLoggedInUsers.insertOne(user);\n\t\t\t\t\n\t\t\t\tresolve(user);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tresolve(null);\n\t\t\t}\n\t\t});\n\t}\n\n\t// Unsubscribe from publication \n\tpublic unsubscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugUnSubHits += 1;\n\t\t// let startDate = new Date();\n\t\t// console.log('Before');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\n\t\tif (!this._publications[publication]) {\n\t\t\tconsole.log('No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet sub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\n\t\t\tif (sub) {\n\t\t\t\tfor (let i = sub.clients.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(i, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// let endDate = new Date();\n\t\t// this.currentPerfomanceMonitor.push({\n\t\t// \t_id: this.idPerformance++,\n\t\t// \tfunction: 'unsubscribe',\n\t\t// \tpublication: publication,\n\t\t// // \tsubscriptionData: subscriptionData,\n\t\t// \tsubscriptionData: [],\n\t\t// \tdate_start: startDate,\n\t\t// \tdate_end: endDate,\n\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t// \tresult: 'Done'\n\t\t// });\n\t}\n\n\t// Unsubscribe from publication\n\tpublic async unsubscribeAll(ws: WebSocket) {\n\t\tthis._debugUnSubAllHits += 1;\n\t\t// console.log('Before');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\n\t\t// let startDate = new Date();\n\n\t\tif (ws) {\n\t\t\tlet loggedInUser = await LoggedInUsers.findOne({id_ws: ws['id_socket']});\n\n\t\t\tif (loggedInUser) {\t\n\t\t\t\tif (this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id) >= 0) {\n\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id), 1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\t\t\t}\n\n\t\t\tlet userSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));\n\n\t\t\tfor (let i = userSubs.length - 1; i >= 0; i--) {\n\t\t\t\tlet sub = userSubs[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tif (sub.clients[j].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tws.close();\n\n\t\t\tprocess.nextTick(() => {\n\t\t\t\tif ([ws.OPEN, ws.CLOSING].includes(<any>ws.readyState)) {\n\t\t\t\t\t// Socket still hangs, hard close\n\t\t\t\t\tws.terminate();\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// let endDate = new Date();\n\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t// \t_id: this.idPerformance++,\n\t\t\t// \tfunction: 'unsubscribeAll',\n\t\t\t// \tpublication: '',\n\t\t\t// \tsubscriptionData: [],\n\t\t\t// \tdate_start: startDate,\n\t\t\t// \tdate_end: endDate,\n\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \tresult: 'Done'\n\t\t\t// });\n\t\t}\n\n\t\t// console.log('After');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\t}\n\n\tpublic getActiveSubscriptions() {\n\t\treturn this._subscriptions;\n\t}\n\n\t// Get publication collection\n\tprivate getPublicationCollections(publication: string) {\n\t\treturn this._publications[publication].collections;\n\t}\n\n\t// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)\n\tprivate async tailOpLog(resumeToken?: ResumeToken) {\n\t\tif (this._oplog$ && !this._oplog$.closed) {\n\t\t\tthis._oplog$.removeAllListeners();\n\t\t\tthis._oplog$.close();\n\t\t\tthis._oplog$ = null;\n\t\t}\n\t\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\n\t\tif (!this._oplog$ || this._oplog$.closed) {\n\t\t\tthis._oplogRetryCount += 1;\n\n\t\t\tif (this._oplogRetryCount > 5) {\n\t\t\t\tconsole.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************')\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tlet lastResumeToken: ResumeToken;\n\n\t\t\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._oplog$ = ResolveIOServer.getMainDB().watch([], {resumeAfter: resumeToken});\n\t\t\t\t}\n\t\t\t\tcatch(errOp) {\n\t\t\t\t\tif (this._oplog$) {\n\t\t\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\t\t\tthis._oplog$.close();\n\t\t\t\t\t\tthis._oplog$ = null;\n\t\t\t\t\t}\n\t\t\t\t\tthis.tailOpLog(resumeToken);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._oplog$ = ResolveIOServer.getMainDB().watch();\n\t\t\t}\n\n\t\t\tconsole.log(new Date(), 'oplog started');\n\n\t\t\tthis._oplog$.on('change', (doc: ChangeStreamInsertDocument | ChangeStreamUpdateDocument | ChangeStreamReplaceDocument | ChangeStreamDeleteDocument) => {\n\t\t\t\t// let startDate = new Date();\n\n\t\t\t\tif (doc.ns) {\n\t\t\t\t\tlet collection = doc.ns.coll;\n\n\t\t\t\t\tif (!this._debugOplogCollections.some(a => a.collection === doc.ns.coll && a.type === doc.operationType)) {\n\t\t\t\t\t\tthis._debugOplogCollections.push({\n\t\t\t\t\t\t\tcollection: doc.ns.coll,\n\t\t\t\t\t\t\ttype: doc.operationType,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugOplogCollections.filter(a => a.collection === doc.ns.coll && a.type === doc.operationType)[0].hits += 1;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t// console.log(new Date(), 'Op log doc', doc.operationType, collection);\n\n\t\t\t\t\tif (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {\n\t\t\t\t\t\tthis._debugOplogHits += 1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\t\t\tif (collection === 'support-tickets') {\n\t\t\t\t\t\t\t\tif (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {\n\t\t\t\t\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);\n\t\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Insert'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'update' || doc.operationType === 'replace') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'update');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Update'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'delete');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Delete'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection === 'flags') {\n\t\t\t\t\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\t\t\t\t\tif (flag && flag.value) {\n\t\t\t\t\t\t\t\tthis._enableDebug = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthis._enableDebug = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlastResumeToken = doc._id;\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tthis._oplog$.on('error', error => {\n\t\t\t\tconsole.log(new Date(), 'oplog error', error);\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$.close();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\n\t\t\tthis._oplog$.on('end', () => {\n\t\t\t\tconsole.log(new Date(), 'oplog end');\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$.close();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\n\t\t\tthis._oplog$.on('close', () => {\n\t\t\t\tconsole.log(new Date(), 'oplog close');\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate sendDataToOne(ws: WebSocket, messageId: number, subscription: ActiveSubscriptionModel, type: string, collection: string) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t// let startDate = new Date();\n\n\t\t\tif (!this._publications[subscription.publication].user_specific) { // Same pub for all users\n\t\t\t\tif (subscription.cacheId) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(subscription.cacheId), dateReviver);\n\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: cacheData\n\t\t\t\t\t\t};\n\t\n\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t}\n\t\t\t\t\tcatch(err) {\n\t\t\t\t\t\tthis._nodeCache.del(subscription.cacheId);\n\t\t\t\t\t\tsubscription.cacheId = 0;\n\n\t\t\t\t\t\tthis.addToQueue({\n\t\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\t\ttype: 'newSub',\n\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\t\trunning: false,\n\t\t\t\t\t\t\trun_again: false\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendDataToOne',\n\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Send cache'\n\t\t\t\t\t// });\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - No Cache! - ' + subscription.publication + '\\n\\nData \\n' + JSON.stringify(subscription.subscriptionData, null, 2));\n\n\t\t\t\t\tresolve(false);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]\n\t\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', '', subscription.subscriptionData);\n\t\t\t\tthis._publications[subscription.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ws['id_user'], ...subscription.subscriptionData)\n\t\t\t\t.then(res => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\tdata: res\n\t\t\t\t\t};\n\n\t\t\t\t\t// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendDataToOne',\n\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Send ws spec data'\n\t\t\t\t\t// });\n\n\t\t\t\t\tresolve(true);\n\n\t\t\t\t}, err => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\t\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\tdata: err\n\t\t\t\t\t};\n\n\t\t\t\t\t// console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendDataToOne - WS)\\n\\nData \\n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate sendDataToAll(mongoQueue: MongoQueueModel) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t// let startDate = new Date();\n\t\t\tif (!mongoQueue.subscription.clients.length) {\t\t\t\t\n\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t}\n\n\t\t\t\tif (this._subscriptions.findIndex(a => a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData)) >= 0) {\n\t\t\t\t\tthis._subscriptions.splice(this._subscriptions.findIndex(a => a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData)), 1);\n\t\t\t\t}\n\n\t\t\t\tresolve(false);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (mongoQueue.subscription.publication !== 'superadminAPM' && mongoQueue.subscription.publication !== 'loggedInUsers') {\n\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'insertSubscriptionLog', mongoQueue.type, mongoQueue.subscription.publication, mongoQueue.collection, JSON.stringify(mongoQueue.subscription.subscriptionData));\n\t\t\t\t}\n\n\t\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', '', mongoQueue.subscription.subscriptionData);\n\t\t\t\tthis._publications[mongoQueue.subscription.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ...mongoQueue.subscription.subscriptionData)\n\t\t\t\t.then(res => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tif (!mongoQueue.subscription.clients.length) {\n\t\t\t\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\tlet deleteCount = 0;\n\n\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\n\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\tthis._debugRemoveCacheHits += 1;\n\n\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\n\t\t\t\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tconsole.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\t\t\tmongoQueue.subscription.cacheId = cacheId;\n\n\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t// \tfunction: 'sendPubData',\n\t\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t// \tresult: 'No clients'\n\t\t\t\t\t\t// });\n\n\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!mongoQueue.subscription.cacheId || this._nodeCache.get(mongoQueue.subscription.cacheId) !== JSON.stringify(res)) {\n\t\t\t\t\t\t\tmongoQueue.subscription.clients.forEach(client => {\n\t\t\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\n\t\t\t\t\t\t\t\tif (ws) {\n\t\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\n\t\t\t\t\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\t\tlet deleteCount = 0;\n\n\t\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\t\n\t\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\t\n\t\t\t\t\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\t\n\t\t\t\t\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tconsole.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\t\t\t\tmongoQueue.subscription.cacheId = cacheId;\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'sendPubData',\n\t\t\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Same data'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + mongoQueue.subscription.publication + ' - (sendPubData)\\n\\nData \\n' + JSON.stringify(mongoQueue.subscription.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\n\t\t\t\t\tmongoQueue.subscription.clients.forEach(client => {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\n\t\t\t\t\t\tif (ws) {\n\t\t\t\t\t\t\tif (ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\t\t\t\tdata: err\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate sendWS(ws: WebSocket, data: ServerResponseModel) {\n\t\tthis._sendQueue.splice(0, 0, {\n\t\t\tid_ws: ws['id_socket'],\n\t\t\tdata: data\n\t\t});\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/subscription.manager.ts"],"names":["logs_1","require","app_status_1","files_1","super_admin_1","logged_in_users_collection_1","cron_jobs_1","flags_1","method_responses_1","index_1","notifications_1","report_builder_reports_1","report_builder_libraries_1","user_groups_1","user_guides_1","report_builder_dashboard_builders_1","mongo_manager_1","common_1","NodeCache","flag_collection_1","os_1","numCPUs","cpus","length","v8","SubscriptionManager","mainServer","wss","serverConfig","monitorManagerFunction","_this","this","_publications","_subscriptions","_loggedInUsers","_mongoQueue","_mongoQueueId","_cacheId","_heapSize","getHeapStatistics","_enableDebug","_debugOplogCollections","_debugOplogHits","_debugSubCollections","_debugSubHits","_debugUnSubHits","_debugUnSubAllHits","_debugMongoQueueHits","_debugMongoQueueCollections","_debugSendQueueHits","_debugRemoveCacheHits","_oplogRetryCount","_mainServer","_websocketManager","getWebSocketManager","_monitorManagerFunction","_nodeCache","stdTTL","checkperiod","_wss","loadSuperAdminPublications","loadAppStatusPublications","loadLogPublications","loadFilePublications","loadCronJobPublications","loadFlagsPublications","loadMethodResponsePublications","loadNotificationPublications","loadReportBuilderReportPublications","loadReportBuilderLibraryPublications","loadUserGroupPublications","loadUserGuidePublications","loadReportBuilderDashboardBuilderPublications","tailOpLog","setInterval","getEnableDebug","console","log","Date","JSON","stringify","sort","a","b","collection","localeCompare","publication","type","__awaiter","_a","LoggedInUsers","find","_b","sent","userCopy","deepCopy","i","loggedInUser","date","now","getTime","this_1","getWebSocket","id_ws","unsubscribeAll","forEach","sub","j","clients","id_socket","splice","deleteOne","_id","findIndex","client","this_2","some","Flags","findOne","then","flag","value","setCacheLimit","prototype","process","env","IS_WORKERS_ENABLED","_heapLimit","invalidatePubsCache","ResolveIOServer","getMongoManager","invalidateQueryCache","collSubs","filter","collections","includes","this_3","user_specific","Promise","all","map","ws","readyState","OPEN","sendDataToOne","messageId","getMethodManager","sendEmail","id_user","err_1","sendDataToAll","collSubs_1","_i","publications","method","Object","assign","loggedInLatency","updateOne","$set","latency","res","subscribe","messageRoute","messageDate","subscriptionData","pub","hits","push","check","error","_schema","valObj","rootKeys","keys","validate","errors","urlData","split","urlModule_1","urlNext","otherRouteSubs","startsWith","otherSub","unsubscribe","getPublicationCollections","cacheId","processSubscription","createLoggedInUser","resolve","reject","user","objectIdHexString","__v","insertOne","indexOf","userSubs","removeWebSocket","getActiveSubscriptions","resumeToken","_oplog$","closed","removeAllListeners","close","setTimeout","exit","lastResumeToken_1","getMainDB","watch","resumeAfter","errOp","on","doc","ns","coll","operationType","endsWith","callMethodInternal","call","documentKey","cacheData","parse","get","dateReviver","serverRes","hasError","data","sendWS","del","monitor","startMonitorFunction","function","apply","__spreadArray","finishMonitorFunction","err_3","subIndex","res_1","set","nodeCacheSize","getStats","vsize","deleteCount","subArr","zz","err_4","send","exports"],"mappings":"wqDAGAA,Q,0FAAAC,QAAA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B,KAAM,CAAC,EAAI,eAAiBtF,KAAKC,UAAUqK,EAAK,KAAM,CAAC,CAAC,E,6BAKtT5N,oBAAAkG,UAAAwG,OAAR,SAAetF,EAAeqF,GAC7BnM,KAAKsB,kBAAkBiM,KAAKzG,EAAIqF,CAAI,CACrC,EAEOzM,oBAAAkG,UAAAhD,eAAP,WACC,OAAO5C,KAAKS,YACb,EACDf,mBAAA,EAAC,EAruBY8N,QAAA9N,oBAAAA","file":"subscription.manager.js","sourcesContent":["import { ServerResponseModel } from '../models/server-response.model';\nimport { ActiveSubscriptionModel, SubscriptionModel } from '../models/subscription.model';\nimport * as WebSocket from 'ws';\nimport { loadLogPublications } from '../publications/logs';\nimport { loadAppStatusPublications } from '../publications/app-status';\nimport { loadFilePublications } from '../publications/files';\nimport { loadSuperAdminPublications } from '../publications/super-admin';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { loadCronJobPublications } from '../publications/cron-jobs';\nimport { loadFlagsPublications } from '../publications/flags';\nimport { loadMethodResponsePublications } from '../publications/method-responses';\nimport ResolveIOMainServer from '../server-app';\nimport { ResolveIOServer } from '../index';\nimport { loadNotificationPublications } from '../publications/notifications';\nimport { loadReportBuilderReportPublications } from '../publications/report-builder-reports';\nimport { LoggedInUserModel } from '../models/logged-in-users.model';\n\nimport { ChangeStream, ChangeStreamDeleteDocument, ChangeStreamDocument, ChangeStreamInsertDocument, ChangeStreamReplaceDocument, ChangeStreamUpdateDocument, ResumeToken } from 'mongodb';\nimport { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';\nimport { loadUserGroupPublications } from '../publications/user-groups';\nimport { loadUserGuidePublications } from '../publications/user-guides';\nimport { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';\nimport { objectIdHexString } from './mongo.manager';\nimport { dateReviver, deepCopy } from '../util/common';\nimport * as NodeCache from 'node-cache';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { Flags } from '../collections/flag.collection';\nimport { cpus } from 'os';\nimport { WebSocketManager } from './websocket.manager';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\n\n// Performance Dependencies\n// import * as path from 'path';\n// import { Worker } from 'worker_threads';\n\ninterface MongoQueueModel {\n\t_id: number,\n\ttype: string;\n\tcollection: string;\n\tsubscription: ActiveSubscriptionModel;\n\trunning: boolean;\n\trun_again: boolean;\n}\n\n// interface CurrentPerformanceMonitor {\n// \t_id: number;\n// \tfunction: string;\n// \tpublication: string;\n// \tsubscriptionData: any[];\n// \tdate_start: Date;\n// \tdate_end: Date;\n// \tduration: number;\n// \tresult: string;\n// }\n\nexport class SubscriptionManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _websocketManager: WebSocketManager;\n\tprivate _publications: SubscriptionModel = {};\n\tprivate _subscriptions: ActiveSubscriptionModel[] = [];\n\tprivate _wss: WebSocket.Server;\n\tprivate _loggedInUsers: LoggedInUserModel[] = [];\n\n\tprivate _mongoQueue: MongoQueueModel[] = [];\n\tprivate _mongoQueueId = 0;\n\t\n\tprivate _oplog$: ChangeStream;\n\n\tprivate _nodeCache;\n\tprivate _cacheId = 1;\n\n\tprivate _heapSize = v8.getHeapStatistics() / numCPUs;\n\tprivate _heapLimit: number;\n\n\tprivate serverConfig;\n\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\n\tprivate _enableDebug = false;\n\tprivate _debugOplogCollections = [];\n\tprivate _debugOplogHits = 0;\n\tprivate _debugSubCollections = [];\n\tprivate _debugSubHits = 0;\n\tprivate _debugUnSubHits = 0;\n\tprivate _debugUnSubAllHits = 0;\n\tprivate _debugMongoQueueHits = 0;\n\tprivate _debugMongoQueueCollections = [];\n\tprivate _debugSendQueueHits = 0;\n\tprivate _debugRemoveCacheHits = 0;\n\n\tprivate _oplogRetryCount = 0;\n\n\t// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];\n\t// private idPerformance: number = 0;\n\t// private performanceThread;\n\n\tconstructor(mainServer, wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._websocketManager = this._mainServer.getWebSocketManager();\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\n\t\tthis._nodeCache = new NodeCache( { stdTTL: 0, checkperiod: 0 } );\n\n\t\t// setTimeout(() => {\n\t\t// \tconsole.log('Setting up performance thread');\n\n\t\t// \tthis.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));\n\n\t\t// \tthis.performanceThread.on('exit', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\n\t\t// \tthis.performanceThread.on('error', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\t\t// }, 5000);\n\n\t\t// setInterval(() => {\n\t\t// \tconsole.log('Post thread msg');\n\t\t// \tthis.performanceThread.postMessage(this.currentPerfomanceMonitor);\n\t\t// \tthis.currentPerfomanceMonitor = [];\n\t\t// }, 10000);\n\n\t\tthis.serverConfig = serverConfig;\n\t\tthis._wss = wss;\n\n\t\t// Publications\n\t\tloadSuperAdminPublications(this);\n\t\tloadAppStatusPublications(this);\n\t\tloadLogPublications(this);\n\t\tloadFilePublications(this);\n\t\tloadCronJobPublications(this);\n\t\tloadFlagsPublications(this);\n\t\tloadMethodResponsePublications(this);\n\t\tloadNotificationPublications(this);\n\t\tloadReportBuilderReportPublications(this);\n\t\tloadReportBuilderLibraryPublications(this);\n\t\tloadUserGroupPublications(this);\n\t\tloadUserGuidePublications(this);\n\t\tloadReportBuilderDashboardBuilderPublications(this);\n\n\t\tthis.tailOpLog();\n\n\t\tsetInterval(() => {\n\t\t\tthis._oplogRetryCount = 0;\n\t\t}, 15000);\n\n\t\tsetInterval(() => {\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Subs', this._subscriptions.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Logged In Users', this._loggedInUsers.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue', this._mongoQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', this._debugMongoQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(this._debugMongoQueueCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Hits', this._debugOplogHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(this._debugOplogCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Hits', this._debugSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(this._debugSubCollections.sort((a, b) => a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub Hits', this._debugUnSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub All Hits', this._debugUnSubAllHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', this._debugRemoveCacheHits);\n\t\t\t}\n\t\t\t\n\t\t\tthis._debugOplogHits = 0;\n\t\t\tthis._debugOplogCollections = [];\n\t\t\tthis._debugSubCollections = [];\n\t\t\tthis._debugMongoQueueHits = 0;\n\t\t\tthis._debugMongoQueueCollections = [];\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t\tthis._debugSubHits = 0;\n\t\t\tthis._debugUnSubHits = 0;\n\t\t\tthis._debugUnSubAllHits = 0;\n\t\t\tthis._debugRemoveCacheHits = 0;\n\t\t}, 60000);\n\n\t\tsetInterval(async () => {\n\t\t\tthis._loggedInUsers = await LoggedInUsers.find();\n\t\n\t\t\tlet userCopy = deepCopy(this._loggedInUsers);\n\t\t\tfor (let i = this._loggedInUsers.length - 1; i >= 0; i--) {\n\t\t\t\tlet loggedInUser = userCopy[i];\n\n\t\t\t\tif (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {\n\t\t\t\t\tif (this._websocketManager.getWebSocket(loggedInUser.id_ws)) {\n\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', this._websocketManager.getWebSocket(loggedInUser.id_ws)['user'], this._websocketManager.getWebSocket(loggedInUser.id_ws)['id_socket'], 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.unsubscribeAll(this._websocketManager.getWebSocket(loggedInUser.id_ws));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._subscriptions.forEach(sub => {\n\t\t\t\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\t\t\t\tif (client.id_socket === loggedInUser.id_ws) {\n\t\t\t\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\n\t\t\t\t\t\tif (this._loggedInUsers.findIndex(a => a._id === loggedInUser._id) >= 0) {\n\t\t\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.findIndex(a => a._id === loggedInUser._id), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < this._subscriptions.length; i++) {\n\t\t\t\tlet sub = this._subscriptions[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\tif (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, 30000);\n\n\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\t\t});\n\n\t\tthis.setCacheLimit();\n\t}\n\n\tprivate setCacheLimit() {\t\n\t\tif (process.env.IS_WORKERS_ENABLED === 'true') {\n\t\t\tthis._heapLimit = this._heapSize * 0.4;\n\t\t}\n\t\telse {\n\t\t\tthis._heapLimit = this._heapSize * 0.3; // Use 50% of total heap size\n\t\t}\n\t}\n\n\tpublic async invalidatePubsCache(collection: string, type: string) {\n\t\tResolveIOServer.getMongoManager().invalidateQueryCache(collection);\n\n\t\tlet collSubs = this._subscriptions.filter(a => a.collections.includes(collection));\n\n\t\tfor (let sub of collSubs) {\n\t\t\tif (this._publications[sub.publication].user_specific) {\n\t\t\t\t// For user-specific publications, process each client separately\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tsub.clients.map(async client => {\n\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.sendDataToOne(ws, client.messageId, sub, type, collection);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t// Handle error\n\t\t\t\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + sub.publication + ', Err: ' + JSON.stringify(err, null, 2));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// For non-user-specific publications, send data to all clients\n\t\t\t\tawait this.sendDataToAll(sub);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add all files to publications private object\n\tpublic publications(method: SubscriptionModel) {\n\t\tthis._publications = Object.assign(this._publications, method);\n\t}\n\n\tpublic loggedInLatency(ws: WebSocket) {\n\t\tlet loggedInUser = this._loggedInUsers.find(a => a.id_ws === ws['id_socket']);\n\n\t\tif (loggedInUser) {\n\t\t\tloggedInUser.date = new Date();\n\n\t\t\tLoggedInUsers.updateOne({id_ws: ws['id_socket']}, {$set: {latency: ws['latency'], date: loggedInUser.date}}).then(res => {\n\t\t\t\tif (!res) {\n\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 3);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {\n\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 4);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// Subscribe to publication\n\tpublic subscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugSubHits += 1;\n\n\t\tif (!this._debugSubCollections.some(a => a.publication === publication)) {\n\t\t\tthis._debugSubCollections.push({\n\t\t\t\tpublication: publication,\n\t\t\t\thits: 1\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._debugSubCollections.find(a => a.publication === publication).hits += 1;\n\t\t}\n\n\t\tlet pub = this._publications[publication];\n\n\t\tif (!pub) {\n\t\t\tconsole.error(new Date(), 'No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tif (subscriptionData.length > 1 || subscriptionData[0]) {\n\t\t\t\tif (!pub.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (!pub.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet valObj = {};\n\t\t\t\t\tlet valKeys = Object.keys(pub.check._schema);\n\n\t\t\t\t\tlet rootKeys = valKeys.filter(a => !a.includes('.'));\n\n\t\t\t\t\tfor (let i = 0; i < subscriptionData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = subscriptionData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tif (errors) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messageRoute !== 'Bypass') {\n\t\t\t\tlet urlData = messageRoute.split('/');\n\t\t\t\tlet urlModule = '';\n\t\t\t\tlet urlNext = urlData[0];\n\n\t\t\t\tif (urlData[0] === '') {\n\t\t\t\t\turlModule = '/';\n\t\t\t\t\turlNext = urlData[1];\n\t\t\t\t}\n\n\t\t\t\turlModule += urlNext;\n\n\t\t\t\tif (urlData.length > 1) {\n\t\t\t\t\turlModule += '/';\n\t\t\t\t}\n\n\t\t\t\tlet otherRouteSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule)));\n\n\t\t\t\tif (otherRouteSubs.length) {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));\n\n\t\t\t\t\totherRouteSubs.forEach(otherSub => {\n\t\t\t\t\t\totherSub.clients.filter(a => a.id_socket === ws['id_socket']).forEach(client => {\n\t\t\t\t\t\t\tthis.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet sub = this._subscriptions.find(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData));\n\n\t\t\t// If sub found (another user watching same data), add client to same sub\n\t\t\tif (sub) {\n\t\t\t\tif (!sub.clients.some(a => a.id_socket === ws['id_socket'] && a.messageId === messageId)) {\n\t\t\t\t\tsub.clients.push({\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If sub not found, create new sub\n\t\t\telse {\n\t\t\t\tthis._subscriptions.push({\n\t\t\t\t\tpublication: publication,\n\t\t\t\t\tsubscriptionData: subscriptionData,\n\t\t\t\t\tcollections: this.getPublicationCollections(publication),\n\t\t\t\t\tclients: [{\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t}],\n\t\t\t\t\tcacheId: 0\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!sub) {\n\t\t\t\tsub = this._subscriptions.find(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData));\n\t\t\t}\n\n\t\t\t// Immediately send data to the new client\n\t\t\tthis.processSubscription(sub, ws, messageId);\n\t\t}\n\t}\n\n\tpublic async createLoggedInUser(id_ws: string): Promise<LoggedInUserModel> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tlet ws = this._websocketManager.getWebSocket(id_ws);\n\n\t\t\tif (ws) {\n\t\t\t\tlet user = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tid_ws: ws['id_socket']\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tthis._loggedInUsers.push(user);\n\t\t\t\tLoggedInUsers.insertOne(user);\n\t\t\t\t\n\t\t\t\tresolve(user);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tresolve(null);\n\t\t\t}\n\t\t});\n\t}\n\n\t// Unsubscribe from publication \n\tpublic unsubscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugUnSubHits += 1;\n\n\t\tif (!this._publications[publication]) {\n\t\t\tconsole.log('No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet sub = this._subscriptions.find(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData));\n\n\t\t\tif (sub) {\n\t\t\t\tfor (let i = sub.clients.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(i, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\t// Unsubscribe from publication\n\tpublic async unsubscribeAll(ws: WebSocket) {\n\t\tthis._debugUnSubAllHits += 1;\n\n\t\tif (ws) {\n\t\t\tlet loggedInUser = await LoggedInUsers.findOne({ id_ws: ws['id_socket'] });\n\n\t\t\tif (loggedInUser) {\n\t\t\t\tif (this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id) >= 0) {\n\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id), 1);\n\t\t\t\t}\n\n\t\t\t\tLoggedInUsers.deleteOne({ _id: loggedInUser._id });\n\t\t\t}\n\n\t\t\tlet userSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));\n\n\t\t\tfor (let i = userSubs.length - 1; i >= 0; i--) {\n\t\t\t\tlet sub = userSubs[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tif (sub.clients[j].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis._websocketManager.removeWebSocket(ws);\n\t\t}\n\t}\n\n\tpublic getActiveSubscriptions() {\n\t\treturn this._subscriptions;\n\t}\n\n\t// Get publication collection\n\tprivate getPublicationCollections(publication: string) {\n\t\treturn this._publications[publication].collections;\n\t}\n\n\t// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)\n\tprivate async tailOpLog(resumeToken?: ResumeToken) {\n\t\tif (this._oplog$ && !this._oplog$.closed) {\n\t\t\tthis._oplog$.removeAllListeners();\n\t\t\tthis._oplog$.close();\n\t\t\tthis._oplog$ = null;\n\t\t}\n\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\n\t\tif (!this._oplog$ || this._oplog$.closed) {\n\t\t\tthis._oplogRetryCount += 1;\n\n\t\t\tif (this._oplogRetryCount > 5) {\n\t\t\t\tconsole.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tlet lastResumeToken: ResumeToken;\n\n\t\t\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._oplog$ = ResolveIOServer.getMainDB().watch([], { resumeAfter: resumeToken });\n\t\t\t\t}\n\t\t\t\tcatch (errOp) {\n\t\t\t\t\tif (this._oplog$) {\n\t\t\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\t\t\tthis._oplog$.close();\n\t\t\t\t\t\tthis._oplog$ = null;\n\t\t\t\t\t}\n\t\t\t\t\tthis.tailOpLog(resumeToken);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._oplog$ = ResolveIOServer.getMainDB().watch();\n\t\t\t}\n\n\t\t\tconsole.log(new Date(), 'oplog started');\n\n\t\t\tthis._oplog$.on('change', (doc: ChangeStreamInsertDocument | ChangeStreamUpdateDocument | ChangeStreamReplaceDocument | ChangeStreamDeleteDocument) => {\n\t\t\t\tif (doc.ns) {\n\t\t\t\t\tlet collection = doc.ns.coll;\n\n\t\t\t\t\tif (!this._debugOplogCollections.some(a => a.collection === doc.ns.coll && a.type === doc.operationType)) {\n\t\t\t\t\t\tthis._debugOplogCollections.push({\n\t\t\t\t\t\t\tcollection: doc.ns.coll,\n\t\t\t\t\t\t\ttype: doc.operationType,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugOplogCollections.find(a => a.collection === doc.ns.coll && a.type === doc.operationType).hits += 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {\n\t\t\t\t\t\tthis._debugOplogHits += 1;\n\n\t\t\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\t\t\tif (collection === 'support-tickets') {\n\t\t\t\t\t\t\t\tif (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {\n\t\t\t\t\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);\n\t\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'update' || doc.operationType === 'replace') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'update');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'delete');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection === 'flags') {\n\t\t\t\t\t\tFlags.findOne({ type: 'Enable Debug' }).then(flag => {\n\t\t\t\t\t\t\tif (flag && flag.value) {\n\t\t\t\t\t\t\t\tthis._enableDebug = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthis._enableDebug = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlastResumeToken = doc._id;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis._oplog$.on('error', error => {\n\t\t\t\tconsole.log(new Date(), 'oplog error', error);\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$.close();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\n\t\t\tthis._oplog$.on('end', () => {\n\t\t\t\tconsole.log(new Date(), 'oplog end');\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$.close();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\n\t\t\tthis._oplog$.on('close', () => {\n\t\t\t\tconsole.log(new Date(), 'oplog close');\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async processSubscription(sub: ActiveSubscriptionModel, ws: WebSocket, messageId: number) {\n\t\tif (!this._publications[sub.publication].user_specific) {\n\t\t\tif (sub.cacheId) {\n\t\t\t\ttry {\n\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(sub.cacheId), dateReviver);\n\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\tdata: cacheData\n\t\t\t\t\t};\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t\t\tsub.cacheId = 0;\n\n\t\t\t\t\tawait this.sendDataToAll(sub);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tawait this.sendDataToAll(sub);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tawait this.sendDataToOne(ws, messageId, sub, 'newSub', sub.collections[0]);\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate async sendDataToOne(ws: WebSocket, messageId: number, sub: ActiveSubscriptionModel, type: string, collection: string) {\n\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', sub.publication, '', '', sub.subscriptionData);\n\t\ttry {\n\t\t\tlet res = await this._publications[sub.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ws['id_user'], ...sub.subscriptionData);\n\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\n\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\tmessageId: messageId,\n\t\t\t\thasError: false,\n\t\t\t\tdata: res\n\t\t\t};\n\n\t\t\tthis.sendWS(ws, serverRes);\n\t\t}\n\t\tcatch (err) {\n\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\n\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\tmessageId: messageId,\n\t\t\t\thasError: true,\n\t\t\t\tdata: err\n\t\t\t};\n\n\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + sub.publication + ' - (sendDataToOne - WS)\\n\\nData \\n' + JSON.stringify(sub.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate async sendDataToAll(sub: ActiveSubscriptionModel) {\n\t\tif (!sub.clients.length) {\n\t\t\tif (sub.cacheId) {\n\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t}\n\n\t\t\tlet subIndex = this._subscriptions.findIndex(a => a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData));\n\t\t\tif (subIndex >= 0) {\n\t\t\t\tthis._subscriptions.splice(subIndex, 1);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Publication', sub.publication, '', '', sub.subscriptionData);\n\n\t\t\ttry {\n\t\t\t\tlet res = await this._publications[sub.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ...sub.subscriptionData);\n\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tsub.clients.map(async client => {\n\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tif (sub.cacheId) {\n\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t\t}\n\n\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\tsub.cacheId = cacheId;\n\n\t\t\t\tconst nodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t// Evict cache entries as needed\n\t\t\t\t\tlet deleteCount = 0;\n\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\t\t\t \n\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\tthis._debugRemoveCacheHits += 1;\n\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\t\t\t\t\t\tdeleteCount += 1;\n\t\t\t\t\t\tif (this._nodeCache.getStats().vsize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t'Sub Cache: ' +\n\t\t\t\t\t\t\t'Too Big - ' +\n\t\t\t\t\t\t\tsub.publication +\n\t\t\t\t\t\t\t' - Deleted: ' +\n\t\t\t\t\t\t\tdeleteCount +\n\t\t\t\t\t\t\t' - ' +\n\t\t\t\t\t\t\tnodeCacheSize\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tsub.clients.map(async client => {\n\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\t\t\tdata: err\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + sub.publication + ' - (sendPubData)\\n\\nData \\n' + JSON.stringify(sub.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate sendWS(ws: WebSocket, data: ServerResponseModel) {\n\t\tthis._websocketManager.send(ws, data);\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var worker_threads_1=require("worker_threads"),totalPerfomanceMonitor=[];function processMsg(a){totalPerfomanceMonitor.length?(totalPerfomanceMonitor.forEach(function(n){var t=a.filter(function(t){return t.function===n.function&&t.publication===n.publication&&JSON.stringify(t.subscriptionData)===JSON.stringify(n.subscriptionData)});t.length?(n.data=n.data.concat(t),n.duration_total_max=Math.max.apply(Math,n.data.map(function(t){return t.duration})),n.duration_total_min=Math.min.apply(Math,n.data.map(function(t){return t.duration})),n.duration_total_avg=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var worker_threads_1=require("worker_threads"),common_1=require("../util/common"),totalPerfomanceMonitor=[];function processMsg(a){totalPerfomanceMonitor.length?(totalPerfomanceMonitor.forEach(function(n){var t=a.filter(function(t){return t.function===n.function&&t.publication===n.publication&&JSON.stringify(t.subscriptionData)===JSON.stringify(n.subscriptionData)});t.length?(n.data=n.data.concat(t),n.duration_total_max=Math.max.apply(Math,n.data.map(function(t){return t.duration})),n.duration_total_min=Math.min.apply(Math,n.data.map(function(t){return t.duration})),n.duration_total_avg=(0,common_1.round)(n.data.map(function(t){return t.duration}).reduce(function(t,n){return t+n},0)/n.data.length),n.hits_total=n.data.length,n.duration_current_max=Math.max.apply(Math,t.map(function(t){return t.duration})),n.duration_current_min=Math.min.apply(Math,t.map(function(t){return t.duration})),n.duration_current_avg=(0,common_1.round)(t.map(function(t){return t.duration}).reduce(function(t,n){return t+n},0)/t.length),n.hits_current=t.length):(n.duration_current_max=0,n.duration_current_min=0,n.duration_current_avg=0,n.hits_current=0),t.forEach(function(n){a.splice(a.findIndex(function(t){return t._id===n._id}),1)})}),a.forEach(function(n){var t=totalPerfomanceMonitor.find(function(t){return t.function===n.function&&t.publication===n.publication&&JSON.stringify(t.subscriptionData)===JSON.stringify(n.subscriptionData)});t?t.data.push(n):totalPerfomanceMonitor.push({function:n.function,publication:n.publication,subscriptionData:n.subscriptionData,data:[n],duration_total_max:0,duration_total_min:0,duration_total_avg:0,hits_total:0,duration_current_max:0,duration_current_min:0,duration_current_avg:0,hits_current:0})})):(a.forEach(function(n){var t=totalPerfomanceMonitor.find(function(t){return t.function===n.function&&t.publication===n.publication&&JSON.stringify(t.subscriptionData)===JSON.stringify(n.subscriptionData)});t?t.data.push(n):totalPerfomanceMonitor.push({function:n.function,publication:n.publication,subscriptionData:n.subscriptionData,data:[n],duration_total_max:0,duration_total_min:0,duration_total_avg:0,hits_total:0,duration_current_max:0,duration_current_min:0,duration_current_avg:0,hits_current:0})}),totalPerfomanceMonitor.forEach(function(t){t.duration_total_max=Math.max.apply(Math,t.data.map(function(t){return t.duration})),t.duration_total_min=Math.min.apply(Math,t.data.map(function(t){return t.duration})),t.duration_total_avg=(0,common_1.round)(t.data.map(function(t){return t.duration}).reduce(function(t,n){return t+n},0)/t.data.length),t.hits_total=t.data.length,t.duration_current_max=Math.max.apply(Math,t.data.map(function(t){return t.duration})),t.duration_current_min=Math.min.apply(Math,t.data.map(function(t){return t.duration})),t.duration_current_avg=(0,common_1.round)(t.data.map(function(t){return t.duration}).reduce(function(t,n){return t+n},0)/t.data.length),t.hits_current=t.data.length})),console.log("---------------------------------------------------------------------------------"),console.log("---------------------------------------------------------------------------------"),console.log("Performance",new Date),console.log("---------------------------------------------------------------------------------"),console.log("Function, Publication, Hits Total, Dur Tot Max, Dur Tot Min, Dur Tot Avg, Hits Current, Dur Curr Max, Dur Curr Min, Dur Curr Avg, Sub Data"),totalPerfomanceMonitor.sort(function(t,n){return n.hits_total-t.hits_total}).forEach(function(t){console.log(t.function+","+t.publication+","+t.hits_total+","+t.duration_total_max+","+t.duration_total_min+","+t.duration_total_avg+","+t.hits_current+","+t.duration_current_max+","+t.duration_current_min+","+t.duration_current_avg+","+JSON.stringify(t.subscriptionData))}),console.log("---------------------------------------------------------------------------------"),console.log("---------------------------------------------------------------------------------")}worker_threads_1.parentPort.on("message",function(t){console.log("Recv Msg"),processMsg(t)});
|
|
2
2
|
//# sourceMappingURL=subscription.performance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/subscription.performance.ts"],"names":["worker_threads_1","require","totalPerfomanceMonitor","processMsg","msg","length","forEach","total","currents","filter","a","function","publication","JSON","stringify","subscriptionData","data","concat","duration_total_max","Math","max","apply","map","duration","duration_total_min","min","duration_total_avg","round","reduce","b","hits_total","duration_current_max","duration_current_min","duration_current_avg","hits_current","current","splice","findIndex","_id","entry","push","console","log","Date","sort","parentPort","on"],"mappings":"oEAAA,IAAAA,iBAAAC,QAAA,gBAAA,EA4BIC,uBAAoD,GAOxD,SAASC,WAAWC,GACfF,uBAAuBG,QACpBH,uBAAuBI,QAAQ,SAAAC,GAC3B,IAAIC,EAAWJ,EAAIK,OAAO,SAAAC,GAAK,OAAAA,EAAEC,WAAaJ,EAAMI,UAAYD,EAAEE,cAAgBL,EAAMK,aAAeC,KAAKC,UAAUJ,EAAEK,gBAAgB,IAAMF,KAAKC,UAAUP,EAAMQ,gBAAgB,CAApJ,CAAqJ,EAEhLP,EAASH,QACTE,EAAMS,KAAOT,EAAMS,KAAKC,OAAOT,CAAQ,EACvCD,EAAMW,mBAAqBC,KAAKC,IAAGC,MAARF,KAAYZ,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,CAAC,EACtEhB,EAAMiB,mBAAqBL,KAAKM,IAAGJ,MAARF,KAAYZ,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,CAAC,EACtEhB,EAAMmB,mBAAqBP,KAAKQ,MAAMpB,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,EAAEK,OAAO,SAAClB,EAAGmB,GAAM,OAAAnB,EAAImB,CAAJ,EAAO,CAAC,EAAItB,EAAMS,KAAKX,MAAM,EACpHE,EAAMuB,WAAavB,EAAMS,KAAKX,OAC9BE,EAAMwB,qBAAuBZ,KAAKC,IAAGC,MAARF,KAAYX,EAASc,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,CAAC,EACtEhB,EAAMyB,qBAAuBb,KAAKM,IAAGJ,MAARF,KAAYX,EAAS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,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,EAAEK,OAAO,SAAClB,EAAGmB,GAAM,OAAAnB,EAAImB,CAAJ,EAAO,CAAC,EAAItB,EAAMS,KAAKX,MAAM,EACtHE,EAAM2B,aAAe3B,EAAMS,KAAKX,MACpC,CAAC,GAGLoC,QAAQC,IAAI,mFAAmF,EAC/FD,QAAQC,IAAI,mFAAmF,EAE/FD,QAAQC,IAAI,cAAe,IAAIC,IAAM,EACrCF,QAAQC,IAAI,mFAAmF,EAG/FD,QAAQC,IAAI,4IAA4I,EAExJxC,uBAAuB0C,KAAK,SAAClC,EAAGmB,GAAM,OAAAA,EAAEC,WAAapB,EAAEoB,UAAjB,CAA2B,EAAExB,QAAQ,SAAAC,GACvEkC,QAAQC,IAAInC,EAAMI,SAAW,IAAMJ,EAAMK,YAAc,IAAML,EAAMuB,WAAa,IAAMvB,EAAMW,mBAAqB,IAAMX,EAAMiB,mBAAqB,IAAMjB,EAAMmB,mBAAqB,IAAMnB,EAAM2B,aAAe,IAAM3B,EAAMwB,qBAAuB,IAAMxB,EAAMyB,qBAAuB,IAAMzB,EAAM0B,qBAAuB,IAAMpB,KAAKC,UAAUP,EAAMQ,gBAAgB,CAAC,CACvW,CAAC,EAED0B,QAAQC,IAAI,mFAAmF,EAC/FD,QAAQC,IAAI,mFAAmF,CACnG,CA3GA1C,iBAAA6C,WAAWC,GAAG,UAAW,SAAA1C,GACrBqC,QAAQC,IAAI,UAAU,EACzBvC,WAAWC,CAAG,CACf,CAAC","file":"subscription.performance.js","sourcesContent":["import { parentPort } from 'worker_threads';\n\ninterface CurrentPerformanceMonitor {\n\t_id: number;\n\tfunction: string;\n\tpublication: string;\n\tsubscriptionData: any[];\n\tdate_start: Date;\n\tdate_end: Date;\n\tduration: number;\n\tresult: string;\n}\n\ninterface TotalPerformanceMonitor {\n\tfunction: string;\n\tpublication: string;\n\tsubscriptionData: any[];\n\tdata: CurrentPerformanceMonitor[];\n\tduration_total_max: number;\n\tduration_total_min: number;\n\tduration_total_avg: number;\n\thits_total: number;\n\tduration_current_max: number;\n\tduration_current_min: number;\n\tduration_current_avg: number;\n\thits_current: number;\n}\n\nlet totalPerfomanceMonitor: TotalPerformanceMonitor[] = [];\n\nparentPort.on('message', msg => {\n console.log('Recv Msg');\n\tprocessMsg(msg);\n});\n\nfunction processMsg(msg: CurrentPerformanceMonitor[]) {\n\tif (totalPerfomanceMonitor.length) {\n totalPerfomanceMonitor.forEach(total => {\n let currents = msg.filter(a => a.function === total.function && a.publication === total.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(total.subscriptionData));\n\n if (currents.length) {\n total.data = total.data.concat(currents);\n total.duration_total_max = Math.max(...total.data.map(a => a.duration));\n total.duration_total_min = Math.min(...total.data.map(a => a.duration));\n total.duration_total_avg = Math.round(total.data.map(a => a.duration).reduce((a, b) => a + b, 0) / total.data.length);\n total.hits_total = total.data.length;\n total.duration_current_max = Math.max(...currents.map(a => a.duration));\n total.duration_current_min = Math.min(...currents.map(a => a.duration));\n total.duration_current_avg = Math.round(currents.map(a => a.duration).reduce((a, b) => a + b, 0) / currents.length);\n total.hits_current = currents.length;\n }\n else {\n total.duration_current_max = 0;\n total.duration_current_min = 0;\n total.duration_current_avg = 0;\n total.hits_current = 0;\n }\n\n currents.forEach(current => {\n msg.splice(msg.findIndex(a => a._id === current._id), 1);\n });\n });\n\n msg.forEach(entry => {\n let total = totalPerfomanceMonitor.filter(a => a.function === entry.function && a.publication === entry.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(entry.subscriptionData))[0];\n if (total) {\n total.data.push(entry);\n }\n else {\n totalPerfomanceMonitor.push({\n function: entry.function,\n publication: entry.publication,\n subscriptionData: entry.subscriptionData,\n data: [entry],\n duration_total_max: 0,\n duration_total_min: 0,\n duration_total_avg: 0,\n hits_total: 0,\n duration_current_max: 0,\n duration_current_min: 0,\n duration_current_avg: 0,\n hits_current: 0\n });\n }\n });\n }\n else {\n msg.forEach(entry => {\n let total = totalPerfomanceMonitor.filter(a => a.function === entry.function && a.publication === entry.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(entry.subscriptionData))[0];\n if (total) {\n total.data.push(entry);\n }\n else {\n totalPerfomanceMonitor.push({\n function: entry.function,\n publication: entry.publication,\n subscriptionData: entry.subscriptionData,\n data: [entry],\n duration_total_max: 0,\n duration_total_min: 0,\n duration_total_avg: 0,\n hits_total: 0,\n duration_current_max: 0,\n duration_current_min: 0,\n duration_current_avg: 0,\n hits_current: 0\n });\n }\n });\n\n totalPerfomanceMonitor.forEach(total => {\n total.duration_total_max = Math.max(...total.data.map(a => a.duration));\n total.duration_total_min = Math.min(...total.data.map(a => a.duration));\n total.duration_total_avg = Math.round(total.data.map(a => a.duration).reduce((a, b) => a + b, 0) / total.data.length);\n total.hits_total = total.data.length;\n total.duration_current_max = Math.max(...total.data.map(a => a.duration));\n total.duration_current_min = Math.min(...total.data.map(a => a.duration));\n total.duration_current_avg = Math.round(total.data.map(a => a.duration).reduce((a, b) => a + b, 0) / total.data.length);\n total.hits_current = total.data.length;\n });\n }\n\n console.log('---------------------------------------------------------------------------------');\n console.log('---------------------------------------------------------------------------------');\n\n console.log('Performance', new Date());\n console.log('---------------------------------------------------------------------------------');\n\n\n console.log('Function, Publication, Hits Total, Dur Tot Max, Dur Tot Min, Dur Tot Avg, Hits Current, Dur Curr Max, Dur Curr Min, Dur Curr Avg, Sub Data');\n\n totalPerfomanceMonitor.sort((a, b) => b.hits_total - a.hits_total).forEach(total => {\n console.log(total.function + ',' + total.publication + ',' + total.hits_total + ',' + total.duration_total_max + ',' + total.duration_total_min + ',' + total.duration_total_avg + ',' + total.hits_current + ',' + total.duration_current_max + ',' + total.duration_current_min + ',' + total.duration_current_avg + ',' + JSON.stringify(total.subscriptionData));\n });\n\n console.log('---------------------------------------------------------------------------------');\n console.log('---------------------------------------------------------------------------------');\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/subscription.performance.ts"],"names":["worker_threads_1","require","common_1","totalPerfomanceMonitor","processMsg","msg","length","forEach","total","currents","filter","a","function","publication","JSON","stringify","subscriptionData","data","concat","duration_total_max","Math","max","apply","map","duration","duration_total_min","min","duration_total_avg","round","reduce","b","hits_total","duration_current_max","duration_current_min","duration_current_avg","hits_current","current","splice","findIndex","_id","entry","find","push","console","log","Date","sort","parentPort","on"],"mappings":"oEAAA,IAAAA,iBAAAC,QAAA,gBAAA,EACAC,SAAAD,QAAA,gBAAA,EA4BIE,uBAAoD,GAOxD,SAASC,WAAWC,GACfF,uBAAuBG,QACpBH,uBAAuBI,QAAQ,SAAAC,GAC3B,IAAIC,EAAWJ,EAAIK,OAAO,SAAAC,GAAK,OAAAA,EAAEC,WAAaJ,EAAMI,UAAYD,EAAEE,cAAgBL,EAAMK,aAAeC,KAAKC,UAAUJ,EAAEK,gBAAgB,IAAMF,KAAKC,UAAUP,EAAMQ,gBAAgB,CAApJ,CAAqJ,EAEhLP,EAASH,QACTE,EAAMS,KAAOT,EAAMS,KAAKC,OAAOT,CAAQ,EACvCD,EAAMW,mBAAqBC,KAAKC,IAAGC,MAARF,KAAYZ,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,CAAC,EACtEhB,EAAMiB,mBAAqBL,KAAKM,IAAGJ,MAARF,KAAYZ,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,CAAC,EACtEhB,EAAMmB,oBAAqB,EAAAzB,SAAA0B,OAAMpB,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,EAAEK,OAAO,SAAClB,EAAGmB,GAAM,OAAAnB,EAAImB,CAAJ,EAAO,CAAC,EAAItB,EAAMS,KAAKX,MAAM,EAC/GE,EAAMuB,WAAavB,EAAMS,KAAKX,OAC9BE,EAAMwB,qBAAuBZ,KAAKC,IAAGC,MAARF,KAAYX,EAASc,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,CAAC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AU,CAAC,EACxEhB,EAAM0B,sBAAuB,EAAAhC,SAAA0B,OAAMpB,EAAMS,KAAKM,IAAI,SAAAZ,GAAK,OAAAA,EAAEa,QAAF,CAAU,EAAEK,OAAO,SAAClB,EAAGmB,GAAM,OAAAnB,EAAImB,CAAJ,EAAO,CAAC,EAAItB,EAAMS,KAAKX,MAAM,EACjHE,EAAM2B,aAAe3B,EAAMS,KAAKX,MACpC,CAAC,GAGLqC,QAAQC,IAAI,mFAAmF,EAC/FD,QAAQC,IAAI,mFAAmF,EAE/FD,QAAQC,IAAI,cAAe,IAAIC,IAAM,EACrCF,QAAQC,IAAI,mFAAmF,EAG/FD,QAAQC,IAAI,4IAA4I,EAExJzC,uBAAuB2C,KAAK,SAACnC,EAAGmB,GAAM,OAAAA,EAAEC,WAAapB,EAAEoB,UAAjB,CAA2B,EAAExB,QAAQ,SAAAC,GACvEmC,QAAQC,IAAIpC,EAAMI,SAAW,IAAMJ,EAAMK,YAAc,IAAML,EAAMuB,WAAa,IAAMvB,EAAMW,mBAAqB,IAAMX,EAAMiB,mBAAqB,IAAMjB,EAAMmB,mBAAqB,IAAMnB,EAAM2B,aAAe,IAAM3B,EAAMwB,qBAAuB,IAAMxB,EAAMyB,qBAAuB,IAAMzB,EAAM0B,qBAAuB,IAAMpB,KAAKC,UAAUP,EAAMQ,gBAAgB,CAAC,CACvW,CAAC,EAED2B,QAAQC,IAAI,mFAAmF,EAC/FD,QAAQC,IAAI,mFAAmF,CACnG,CA3GA5C,iBAAA+C,WAAWC,GAAG,UAAW,SAAA3C,GACrBsC,QAAQC,IAAI,UAAU,EACzBxC,WAAWC,CAAG,CACf,CAAC","file":"subscription.performance.js","sourcesContent":["import { parentPort } from 'worker_threads';\nimport { round } from '../util/common';\n\ninterface CurrentPerformanceMonitor {\n\t_id: number;\n\tfunction: string;\n\tpublication: string;\n\tsubscriptionData: any[];\n\tdate_start: Date;\n\tdate_end: Date;\n\tduration: number;\n\tresult: string;\n}\n\ninterface TotalPerformanceMonitor {\n\tfunction: string;\n\tpublication: string;\n\tsubscriptionData: any[];\n\tdata: CurrentPerformanceMonitor[];\n\tduration_total_max: number;\n\tduration_total_min: number;\n\tduration_total_avg: number;\n\thits_total: number;\n\tduration_current_max: number;\n\tduration_current_min: number;\n\tduration_current_avg: number;\n\thits_current: number;\n}\n\nlet totalPerfomanceMonitor: TotalPerformanceMonitor[] = [];\n\nparentPort.on('message', msg => {\n console.log('Recv Msg');\n\tprocessMsg(msg);\n});\n\nfunction processMsg(msg: CurrentPerformanceMonitor[]) {\n\tif (totalPerfomanceMonitor.length) {\n totalPerfomanceMonitor.forEach(total => {\n let currents = msg.filter(a => a.function === total.function && a.publication === total.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(total.subscriptionData));\n\n if (currents.length) {\n total.data = total.data.concat(currents);\n total.duration_total_max = Math.max(...total.data.map(a => a.duration));\n total.duration_total_min = Math.min(...total.data.map(a => a.duration));\n total.duration_total_avg = round(total.data.map(a => a.duration).reduce((a, b) => a + b, 0) / total.data.length);\n total.hits_total = total.data.length;\n total.duration_current_max = Math.max(...currents.map(a => a.duration));\n total.duration_current_min = Math.min(...currents.map(a => a.duration));\n total.duration_current_avg = round(currents.map(a => a.duration).reduce((a, b) => a + b, 0) / currents.length);\n total.hits_current = currents.length;\n }\n else {\n total.duration_current_max = 0;\n total.duration_current_min = 0;\n total.duration_current_avg = 0;\n total.hits_current = 0;\n }\n\n currents.forEach(current => {\n msg.splice(msg.findIndex(a => a._id === current._id), 1);\n });\n });\n\n msg.forEach(entry => {\n let total = totalPerfomanceMonitor.find(a => a.function === entry.function && a.publication === entry.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(entry.subscriptionData));\n if (total) {\n total.data.push(entry);\n }\n else {\n totalPerfomanceMonitor.push({\n function: entry.function,\n publication: entry.publication,\n subscriptionData: entry.subscriptionData,\n data: [entry],\n duration_total_max: 0,\n duration_total_min: 0,\n duration_total_avg: 0,\n hits_total: 0,\n duration_current_max: 0,\n duration_current_min: 0,\n duration_current_avg: 0,\n hits_current: 0\n });\n }\n });\n }\n else {\n msg.forEach(entry => {\n let total = totalPerfomanceMonitor.find(a => a.function === entry.function && a.publication === entry.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(entry.subscriptionData));\n if (total) {\n total.data.push(entry);\n }\n else {\n totalPerfomanceMonitor.push({\n function: entry.function,\n publication: entry.publication,\n subscriptionData: entry.subscriptionData,\n data: [entry],\n duration_total_max: 0,\n duration_total_min: 0,\n duration_total_avg: 0,\n hits_total: 0,\n duration_current_max: 0,\n duration_current_min: 0,\n duration_current_avg: 0,\n hits_current: 0\n });\n }\n });\n\n totalPerfomanceMonitor.forEach(total => {\n total.duration_total_max = Math.max(...total.data.map(a => a.duration));\n total.duration_total_min = Math.min(...total.data.map(a => a.duration));\n total.duration_total_avg = round(total.data.map(a => a.duration).reduce((a, b) => a + b, 0) / total.data.length);\n total.hits_total = total.data.length;\n total.duration_current_max = Math.max(...total.data.map(a => a.duration));\n total.duration_current_min = Math.min(...total.data.map(a => a.duration));\n total.duration_current_avg = round(total.data.map(a => a.duration).reduce((a, b) => a + b, 0) / total.data.length);\n total.hits_current = total.data.length;\n });\n }\n\n console.log('---------------------------------------------------------------------------------');\n console.log('---------------------------------------------------------------------------------');\n\n console.log('Performance', new Date());\n console.log('---------------------------------------------------------------------------------');\n\n\n console.log('Function, Publication, Hits Total, Dur Tot Max, Dur Tot Min, Dur Tot Avg, Hits Current, Dur Curr Max, Dur Curr Min, Dur Curr Avg, Sub Data');\n\n totalPerfomanceMonitor.sort((a, b) => b.hits_total - a.hits_total).forEach(total => {\n console.log(total.function + ',' + total.publication + ',' + total.hits_total + ',' + total.duration_total_max + ',' + total.duration_total_min + ',' + total.duration_total_avg + ',' + total.hits_current + ',' + total.duration_current_max + ',' + total.duration_current_min + ',' + total.duration_current_avg + ',' + JSON.stringify(total.subscriptionData));\n });\n\n console.log('---------------------------------------------------------------------------------');\n console.log('---------------------------------------------------------------------------------');\n}"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import ResolveIOMainServer from '../server-app';
|
|
3
|
+
interface ServerResponseModel {
|
|
4
|
+
messageId: number;
|
|
5
|
+
hasError: boolean;
|
|
6
|
+
data: any;
|
|
7
|
+
}
|
|
8
|
+
export declare class WebSocketManager {
|
|
9
|
+
private _mainServer;
|
|
10
|
+
private _messageBuffers;
|
|
11
|
+
private _batchingTimers;
|
|
12
|
+
private _maxMessageSize;
|
|
13
|
+
private _messageDelay;
|
|
14
|
+
private _webSockets;
|
|
15
|
+
constructor(mainServer: ResolveIOMainServer, maxMessageSize?: number, messageDelay?: number);
|
|
16
|
+
addWebSocket(ws: WebSocket): void;
|
|
17
|
+
removeWebSocket(ws: WebSocket): void;
|
|
18
|
+
getWebSocket(id_socket: string): WebSocket | undefined;
|
|
19
|
+
send(ws: WebSocket, data: ServerResponseModel | string): void;
|
|
20
|
+
private flushMessages;
|
|
21
|
+
private sendMessagesInChunks;
|
|
22
|
+
private handleSendError;
|
|
23
|
+
closeConnection(ws: WebSocket): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WebSocketManager=void 0;var WebSocketManager=function(){function WebSocketManager(e,t,s){void 0===t&&(t=20480),void 0===s&&(s=25),this._messageBuffers=new Map,this._batchingTimers=new Map,this._webSockets=new Map,this._mainServer=e,this._maxMessageSize=t,this._messageDelay=s}return WebSocketManager.prototype.addWebSocket=function(e){var t=e.id_socket;this._webSockets.set(t,e)},WebSocketManager.prototype.removeWebSocket=function(e){var t=e.id_socket;this._webSockets.delete(t),this.closeConnection(e)},WebSocketManager.prototype.getWebSocket=function(e){return this._webSockets.get(e)},WebSocketManager.prototype.send=function(e,t){var s=this,n=e.id_socket;this._messageBuffers.has(n)||this._messageBuffers.set(n,[]),"string"==typeof t?this._messageBuffers.get(n).push({messageId:null,hasError:!1,data:t}):this._messageBuffers.get(n).push(t),this._batchingTimers.has(n)||(t=setTimeout(function(){s.flushMessages(e)},this._messageDelay),this._batchingTimers.set(n,t))},WebSocketManager.prototype.flushMessages=function(t){var e,s=this,n=t.id_socket,i=this._messageBuffers.get(n);i&&0<i.length&&(e=JSON.stringify(i),Buffer.byteLength(e,"utf8")>this._maxMessageSize?this.sendMessagesInChunks(t,i):t.send(e,function(e){e&&s.handleSendError(t,e)}),this._messageBuffers.delete(n),clearTimeout(this._batchingTimers.get(n)),this._batchingTimers.delete(n))},WebSocketManager.prototype.sendMessagesInChunks=function(t,e){for(var s=this,n=[],i=0,r=0,a=e;r<a.length;r++){var o=a[r],c=JSON.stringify([o]),c=Buffer.byteLength(c,"utf8");i+c>this._maxMessageSize?(t.send(JSON.stringify(n),function(e){e&&s.handleSendError(t,e)}),n=[o],i=c):(n.push(o),i+=c)}0<n.length&&t.send(JSON.stringify(n),function(e){e&&s.handleSendError(t,e)})},WebSocketManager.prototype.handleSendError=function(e,t){this._mainServer.getSubscriptionManager().getEnableDebug()&&console.log(new Date,"WebSocketManager","Unsub WS",e.user,e.id_socket,t),this._mainServer.getSubscriptionManager().unsubscribeAll(e),this.removeWebSocket(e)},WebSocketManager.prototype.closeConnection=function(e){e.close();var t=e.id_socket;this._messageBuffers.delete(t),this._batchingTimers.has(t)&&(clearTimeout(this._batchingTimers.get(t)),this._batchingTimers.delete(t)),process.nextTick(function(){[e.OPEN,e.CLOSING].includes(e.readyState)&&e.terminate()})},WebSocketManager}();exports.WebSocketManager=WebSocketManager;
|
|
2
|
+
//# sourceMappingURL=websocket.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/managers/websocket.manager.ts"],"names":["WebSocketManager","mainServer","maxMessageSize","messageDelay","this","_messageBuffers","Map","_batchingTimers","_webSockets","_mainServer","_maxMessageSize","_messageDelay","prototype","addWebSocket","ws","wsId","set","removeWebSocket","delete","closeConnection","getWebSocket","id_socket","get","send","data","_this","has","push","messageId","hasError","timer","setTimeout","flushMessages","combinedData","messages","length","JSON","stringify","Buffer","byteLength","sendMessagesInChunks","error","handleSendError","clearTimeout","chunk","chunkSize","_i","messages_1","message","messageData","messageSize","getSubscriptionManager","getEnableDebug","console","log","Date","unsubscribeAll","close","process","nextTick","OPEN","CLOSING","includes","readyState","terminate","exports"],"mappings":"oGAUA,IAAAA,iBAAA,WAQC,SAAAA,iBAAYC,EAAiCC,EAAgCC,GAAhC,KAAA,IAAAD,IAAAA,EAAA,OAAgC,KAAA,IAAAC,IAAAA,EAAA,IANrEC,KAAAC,gBAAsD,IAAIC,IAC1DF,KAAAG,gBAA+C,IAAID,IAGnDF,KAAAI,YAAsC,IAAIF,IAGjDF,KAAKK,YAAcR,EACnBG,KAAKM,gBAAkBR,EACvBE,KAAKO,cAAgBR,CACtB,CAkID,OAhIQH,iBAAAY,UAAAC,aAAP,SAAoBC,GACnB,IAAMC,EAAOD,EAAc,UAC3BV,KAAKI,YAAYQ,IAAID,EAAMD,CAAE,CAC9B,EAEOd,iBAAAY,UAAAK,gBAAP,SAAuBH,GACtB,IAAMC,EAAOD,EAAc,UAC3BV,KAAKI,YAAYU,OAAOH,CAAI,EAC5BX,KAAKe,gBAAgBL,CAAE,CACxB,EAEOd,iBAAAY,UAAAQ,aAAP,SAAoBC,GACnB,OAAOjB,KAAKI,YAAYc,IAAID,CAAS,CACtC,EAEOrB,iBAAAY,UAAAW,KAAP,SAAYT,EAAeU,GAA3B,IAAAC,EAAArB,KACOW,EAAOD,EAAc,UAEtBV,KAAKC,gBAAgBqB,IAAIX,CAAI,GACjCX,KAAKC,gBAAgBW,IAAID,EAAM,EAAE,EAGd,UAAhB,OAAOS,EAEVpB,KAAKC,gBAAgBiB,IAAIP,CAAI,EAAEY,KAAK,CAAEC,UAAW,KAAMC,SAAU,CAAA,EAAOL,KAAMA,CAAI,CAAE,EAGpFpB,KAAKC,gBAAgBiB,IAAIP,CAAI,EAAEY,KAAKH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AfN,EAAMT,QACTrB,EAAGS,KAAKa,KAAKC,UAAUO,CAAK,EAAG,SAACH,GAC3BA,GACHhB,EAAKiB,gBAAgB5B,EAAI2B,CAAK,CAEhC,CAAC,CAEH,EAEQzC,iBAAAY,UAAA8B,gBAAR,SAAwB5B,EAAe2B,GAElCrC,KAAKK,YAAY0C,uBAAsB,EAAGC,eAAc,GAC3DC,QAAQC,IAAI,IAAIC,KAAQ,mBAAoB,WAAYzC,EAAS,KAAGA,EAAc,UAAG2B,CAAK,EAE3FrC,KAAKK,YAAY0C,uBAAsB,EAAGK,eAAe1C,CAAE,EAC3DV,KAAKa,gBAAgBH,CAAE,CACxB,EAEOd,iBAAAY,UAAAO,gBAAP,SAAuBL,GACtBA,EAAG2C,MAAK,EACR,IAAM1C,EAAOD,EAAc,UAE3BV,KAAKC,gBAAgBa,OAAOH,CAAI,EAC5BX,KAAKG,gBAAgBmB,IAAIX,CAAI,IAChC4B,aAAavC,KAAKG,gBAAgBe,IAAIP,CAAI,CAAC,EAC3CX,KAAKG,gBAAgBW,OAAOH,CAAI,GAG3B2C,QAAQC,SAAS,WACT,CAAC7C,EAAG8C,KAAM9C,EAAG+C,SAASC,SAAchD,EAAGiD,UAAU,GAEjDjD,EAAGkD,UAAS,CAEpB,CAAC,CACR,EACDhE,gBAAA,EAAC,EA9IYiE,QAAAjE,iBAAAA","file":"websocket.manager.js","sourcesContent":["import { WebSocket } from 'ws';\nimport { ResolveIOServer } from '../index';\nimport ResolveIOMainServer from '../server-app';\n\ninterface ServerResponseModel {\n\tmessageId: number;\n\thasError: boolean;\n\tdata: any;\n}\n\nexport class WebSocketManager {\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _messageBuffers: Map<string, ServerResponseModel[]> = new Map();\n\tprivate _batchingTimers: Map<string, NodeJS.Timeout> = new Map();\n\tprivate _maxMessageSize: number;\n\tprivate _messageDelay: number;\n\tprivate _webSockets: Map<string, WebSocket> = new Map();\n\n\tconstructor(mainServer: ResolveIOMainServer, maxMessageSize: number = 20480, messageDelay: number = 25) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._maxMessageSize = maxMessageSize;\n\t\tthis._messageDelay = messageDelay;\n\t}\n\n\tpublic addWebSocket(ws: WebSocket): void {\n\t\tconst wsId = ws['id_socket'];\n\t\tthis._webSockets.set(wsId, ws);\n\t}\n\n\tpublic removeWebSocket(ws: WebSocket): void {\n\t\tconst wsId = ws['id_socket'];\n\t\tthis._webSockets.delete(wsId);\n\t\tthis.closeConnection(ws);\n\t}\n\n\tpublic getWebSocket(id_socket: string): WebSocket | undefined {\n\t\treturn this._webSockets.get(id_socket);\n\t}\n\n\tpublic send(ws: WebSocket, data: ServerResponseModel | string): void {\n\t\tconst wsId = ws['id_socket'];\n\n\t\tif (!this._messageBuffers.has(wsId)) {\n\t\t\tthis._messageBuffers.set(wsId, []);\n\t\t}\n\n\t\tif (typeof data === 'string') {\n\t\t\t// Handle string messages like 'ping' or 'pong'\n\t\t\tthis._messageBuffers.get(wsId).push({ messageId: null, hasError: false, data: data });\n\t\t}\n\t\telse {\n\t\t\tthis._messageBuffers.get(wsId).push(data);\n\t\t}\n\n\t\tif (!this._batchingTimers.has(wsId)) {\n\t\t\t// Set a timer to send the batch after a short delay\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.flushMessages(ws);\n\t\t\t}, this._messageDelay);\n\t\t\tthis._batchingTimers.set(wsId, timer);\n\t\t}\n\t}\n\n\tprivate flushMessages(ws: WebSocket): void {\n\t\tconst wsId = ws['id_socket'];\n\t\tconst messages = this._messageBuffers.get(wsId);\n\n\t\tif (messages && messages.length > 0) {\n\t\t\t// Combine messages into one payload\n\t\t\tconst combinedData = JSON.stringify(messages);\n\t\t\tconst dataSize = Buffer.byteLength(combinedData, 'utf8');\n\n\t\t\tif (dataSize > this._maxMessageSize) {\n\t\t\t\t// Split messages to ensure each does not exceed max size\n\t\t\t\tthis.sendMessagesInChunks(ws, messages);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tws.send(combinedData, (error) => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthis.handleSendError(ws, error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Clear the buffer and timer\n\t\t\tthis._messageBuffers.delete(wsId);\n\t\t\tclearTimeout(this._batchingTimers.get(wsId));\n\t\t\tthis._batchingTimers.delete(wsId);\n\t\t}\n\t}\n\n\tprivate sendMessagesInChunks(ws: WebSocket, messages: ServerResponseModel[]): void {\n\t\tlet chunk: ServerResponseModel[] = [];\n\t\tlet chunkSize = 0;\n\n\t\tfor (const message of messages) {\n\t\t\tconst messageData = JSON.stringify([message]); // Wrap message in array for consistency\n\t\t\tconst messageSize = Buffer.byteLength(messageData, 'utf8');\n\n\t\t\tif (chunkSize + messageSize > this._maxMessageSize) {\n\t\t\t\t// Send current chunk\n\t\t\t\tws.send(JSON.stringify(chunk), (error) => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthis.handleSendError(ws, error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\t// Start new chunk\n\t\t\t\tchunk = [message];\n\t\t\t\tchunkSize = messageSize;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tchunk.push(message);\n\t\t\t\tchunkSize += messageSize;\n\t\t\t}\n\t\t}\n\n\t\t// Send any remaining messages\n\t\tif (chunk.length > 0) {\n\t\t\tws.send(JSON.stringify(chunk), (error) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tthis.handleSendError(ws, error);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate handleSendError(ws: WebSocket, error: Error): void {\n\t\t// Handle send error, e.g., unsubscribe, close connection\n\t\tif (this._mainServer.getSubscriptionManager().getEnableDebug()) {\n\t\t\tconsole.log(new Date(), 'WebSocketManager', 'Unsub WS', ws['user'], ws['id_socket'], error);\n\t\t}\n\t\tthis._mainServer.getSubscriptionManager().unsubscribeAll(ws);\n\t\tthis.removeWebSocket(ws);\n\t}\n\n\tpublic closeConnection(ws: WebSocket): void {\n\t\tws.close();\n\t\tconst wsId = ws['id_socket'];\n\t\t// Clean up buffers and timers\n\t\tthis._messageBuffers.delete(wsId);\n\t\tif (this._batchingTimers.has(wsId)) {\n\t\t\tclearTimeout(this._batchingTimers.get(wsId));\n\t\t\tthis._batchingTimers.delete(wsId);\n\t\t}\n \n process.nextTick(() => {\n if ([ws.OPEN, ws.CLOSING].includes(<any>ws.readyState)) {\n // Socket still hangs, hard close\n ws.terminate();\n }\n });\n\t}\n}"]}
|
package/methods/accounts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,s){return new(i=i||Promise)(function(n,r){function fulfilled(e){try{step(s.next(e))}catch(e){r(e)}}function rejected(e){try{step(s.throw(e))}catch(e){r(e)}}function step(e){var r;e.done?n(e.value):((r=e.value)instanceof i?r:new i(function(e){e(r)})).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(t,i){var s,o,a,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,s){return new(i=i||Promise)(function(n,r){function fulfilled(e){try{step(s.next(e))}catch(e){r(e)}}function rejected(e){try{step(s.throw(e))}catch(e){r(e)}}function step(e){var r;e.done?n(e.value):((r=e.value)instanceof i?r:new i(function(e){e(r)})).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(t,i){var s,o,a,c={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},l={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function verb(n){return function(e){var r=[n,e];if(s)throw new TypeError("Generator is already executing.");for(;c=l&&r[l=0]?0:c;)try{if(s=1,o&&(a=2&r[0]?o.return:r[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,r[1])).done)return a;switch(o=0,(r=a?[2&r[0],a.value]:r)[0]){case 0:case 1:a=r;break;case 4:return c.label++,{value:r[1],done:!1};case 5:c.label++,o=r[1],r=[0];continue;case 7:r=c.ops.pop(),c.trys.pop();continue;default:if(!(a=0<(a=c.trys).length&&a[a.length-1])&&(6===r[0]||2===r[0])){c=0;continue}if(3===r[0]&&(!a||r[1]>a[0]&&r[1]<a[3]))c.label=r[1];else if(6===r[0]&&c.label<a[1])c.label=a[1],a=r;else{if(!(a&&c.label<a[2])){a[2]&&c.ops.pop(),c.trys.pop();continue}c.label=a[2],c.ops.push(r)}}r=i.call(t,c)}catch(e){r=[6,e],o=0}finally{s=a=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}}},simpl_schema_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadAccountMethods=void 0,require("simpl-schema")),user_collection_1=require("../collections/user.collection"),handlebars=require("handlebars"),jwt=require("jsonwebtoken"),index_1=require("../index"),mongo_manager_1=require("../managers/mongo.manager");function loadAccountMethods(e){e.methods({incorrectUser:{check:new simpl_schema_1.default({old_user:{type:Object,blackbox:!0},new_user:{type:Object,blackbox:!0},client_subs:{type:Array},"client_subs.$":{type:Object,blackbox:!0}}),function:function(t,i,s){var r=this;return new Promise(function(n,e){return __awaiter(r,void 0,void 0,function(){var r;return __generator(this,function(e){return r=index_1.ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(this.id_ws),this.sendEmail("dev@resolveio.com","SERVER - WRONG USER Detected - "+this.serverConfig.CLIENT_NAME,"Wrong User Sent!\nWS: "+JSON.stringify(r,null,2)+"\nUserMethod: "+this.user+"\nIdUserMethod: "+this.id_user+"\nSubManagerActiveSubs: "+JSON.stringify(index_1.ResolveIOServer.getMainServer().getSubscriptionManager().getActiveSubscriptions(),null,2)+"\nOldUser: "+JSON.stringify(t,null,2)+"\nNewUser: "+JSON.stringify(i,null,2)+"\nClientSubs: "+JSON.stringify(s,null,2)),n(!0),[2]})})})}},reloadWS:{check:new simpl_schema_1.default({id_ws:String}),function:function(i){var e=this;return new Promise(function(n,t){return __awaiter(e,void 0,void 0,function(){var r;return __generator(this,function(e){return(r=index_1.ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(i))?(index_1.ResolveIOServer.getMainServer().unsubscribeWS(r),n(!0)):t("No WS"),[2]})})})}},reconnectWS:{check:new simpl_schema_1.default({id_ws:String}),function:function(i){var e=this;return new Promise(function(n,t){return __awaiter(e,void 0,void 0,function(){var r;return __generator(this,function(e){return(r=index_1.ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(i))?(index_1.ResolveIOServer.getMainServer().unsubscribeWS(r),n(!0)):t("No WS"),[2]})})})}},disconnectWS:{check:new simpl_schema_1.default({id_ws:String}),function:function(i){var e=this;return new Promise(function(n,t){return __awaiter(e,void 0,void 0,function(){var r;return __generator(this,function(e){return(r=index_1.ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(i))?(index_1.ResolveIOServer.getMainServer().unsubscribeWS(r),n(!0)):t("No WS"),[2]})})})}},createUserAndEmailEnrollment:{check:new simpl_schema_1.default({newUser:{type:user_collection_1.Users.simplschema},sendEnrollmentEmail:{type:Boolean,optional:!0}}),function:function(s,o){var e=this;return void 0===o&&(o=!0),new Promise(function(t,i){return __awaiter(e,void 0,void 0,function(){var r,n=this;return __generator(this,function(e){switch(e.label){case 0:return"admin"!==s.username.toLocaleLowerCase()?[3,1]:(i("Username can not be admin"),[2]);case 1:return[4,user_collection_1.Users.findOne({$or:[{username:s.username.toLocaleLowerCase()},{email:s.email.toLocaleLowerCase()}]})];case 2:if(e.sent())return i("Username/Email is already used"),[2];e.label=3;case 3:return s._id=(0,mongo_manager_1.objectIdHexString)(),s.services={enrollment:jwt.sign({id_user:s._id},this.serverConfig.JWT_SECRET,{expiresIn:2592e5})},s.is_customer=!1,[4,user_collection_1.Users.insertOne(s)];case 4:return e.sent(),o&&(r={fullname:s.fullname,user:this.user,url:this.serverConfig.ROOT_URL+"/enroll-account?"+encodeURIComponent(this.serverConfig.SERVER_URL)+"&"+s.services.enrollment},this.readFile("email-templates/enrollment.html").then(function(e){e=handlebars.compile(e);handlebars.registerHelper("equals",function(e,r){return e===r}),n.sendEmail(s.email,"ResolveIO ("+index_1.ResolveIOServer.getClientName()+") - Enrollment Email","",e(r),null,null,""),t(s)},function(e){return i(e)})),[2]}})})})}},resetUserPassword:{check:new simpl_schema_1.default({userId:{type:String}}),function:function(o){var e=this;return new Promise(function(i,s){return __awaiter(e,void 0,void 0,function(){var r,n,t=this;return __generator(this,function(e){switch(e.label){case 0:return[4,user_collection_1.Users.findOne({_id:o})];case 1:return(r=e.sent())&&(r.services||(r.services={}),r.services.forgot_password=jwt.sign({id_user:o},this.serverConfig.JWT_SECRET),n={userToChangePassword:r.fullname,userWhoResetPassword:this.user,url:this.serverConfig.ROOT_URL+"/forgot-password?"+encodeURIComponent(this.serverConfig.SERVER_URL)+"&"+r.services.forgot_password},user_collection_1.Users.updateOne({_id:r._id},{$set:{services:r.services,attempts:0}}).then(function(){t.readFile("email-templates/forgot-password.html").then(function(e){e=handlebars.compile(e);handlebars.registerHelper("equals",function(e,r){return e===r}),t.sendEmail(r.email,"ResolveIO ("+index_1.ResolveIOServer.getClientName()+") - Forgot Password","",e(n),null,null,""),i(!0)},function(e){return s(e)})},function(){})),[2]}})})})}},setUserPassword:{check:new simpl_schema_1.default({userId:{type:String},password:{type:String}}),function:function(i,s){var e=this;return new Promise(function(n,t){return __awaiter(e,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return[4,user_collection_1.Users.findOne({_id:i})];case 1:return!(r=e.sent())||r.roles.super_admin?[3,3]:[4,user_collection_1.Users.setPassword(r,s)];case 2:return e.sent(),n(!0),[3,4];case 3:t("Invalid User"),e.label=4;case 4:return[2]}})})})}}})}exports.loadAccountMethods=loadAccountMethods;
|
|
2
2
|
//# sourceMappingURL=accounts.js.map
|
package/methods/accounts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/methods/accounts.ts"],"names":["simpl_schema_1","require","user_collection_1","handlebars","jwt","index_1","mongo_manager_1","loadAccountMethods","methodManager","methods","incorrectUser","check","default","old_user","type","Object","blackbox","new_user","client_subs","Array","client_subs.$","function","_this","this","Promise","resolve","reject","__awaiter","ws","ResolveIOServer","getMainServer","getWS","id_ws","sendEmail","serverConfig","JSON","stringify","user","id_user","getSubscriptionManager","getActiveSubscriptions","reloadWS","String","unsubscribeWS","reconnectWS","disconnectWS","createUserAndEmailEnrollment","newUser","Users","sendEnrollmentEmail","Boolean","optional","username","toLocaleLowerCase","findOne","$or","email","_a","sent","_id","objectIdHexString","services","enrollment","sign","expiresIn","is_customer","insertOne","emailData_1","fullname","url","encodeURIComponent","readFile","then","html","template","compile","registerHelper","a","b","getClientName","errEmail","resetUserPassword","userId","emailData_2","userToChangePassword","userWhoResetPassword","updateOne","$set","attempts","setUserPassword","password","roles","super_admin","setPassword","exports"],"mappings":"k8CAAAA,gB,yFAAAC,QAAA,cAAA,GACAC,kBAAAD,QAAA,gCAAA,EACAE,WAAAF,QAAA,YAAA,EACAG,IAAAH,QAAA,cAAA,EAGAI,QAAAJ,QAAA,UAAA,EAEAK,gBAAAL,QAAA,2BAAA,EAEA,SAAgBM,mBAAmBC,GAClCA,EAAcC,QAAQ,CACrBC,cAAe,CACdC,MAAO,IAAIX,eAAAY,QAAa,CACvBC,SAAU,CACTC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,SAAU,CACTH,KAAMC,OACNC,SAAU,CAAA,C,EAEXE,YAAa,CACZJ,KAAMK,K,EAEPC,gBAAiB,CAChBN,KAAMC,OACNC,SAAU,CAAA,C,EAEX,EACDK,SAAU,SAASR,EAAUI,EAAUC,GAA7B,IAAAI,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iDACpCM,EAAKvB,QAAAwB,gBAAgBC,cAAa,EAAGC,MAAMR,KAAKS,KAAK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O,cAAc,E,gCAEtB,CACF,C,EAED,CACF,CAnNAoE,QAAAvF,mBAAAA","file":"accounts.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { Users } from '../collections/user.collection';\nimport * as handlebars from 'handlebars';\nimport * as jwt from 'jsonwebtoken';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../index';\nimport { UserModel } from '../models/user.model';\nimport { objectIdHexString } from '../managers/mongo.manager';\n\nexport function loadAccountMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tincorrectUser: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\told_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tnew_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tclient_subs: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'client_subs.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(old_user, new_user, client_subs) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWS(this.id_ws);\n\n\t\t\t\t\tthis.sendEmail('dev@resolveio.com', 'SERVER - WRONG USER Detected - ' + this.serverConfig['CLIENT_NAME'], 'Wrong User Sent!\\nWS: ' + JSON.stringify(ws, null, 2) + '\\nUserMethod: ' + this.user + '\\nIdUserMethod: ' + this.id_user + '\\nSubManagerActiveSubs: ' + JSON.stringify(ResolveIOServer.getMainServer().getSubscriptionManager().getActiveSubscriptions(), null, 2) + '\\nOldUser: ' + JSON.stringify(old_user, null, 2) + '\\nNewUser: ' + JSON.stringify(new_user, null, 2) + '\\nClientSubs: ' + JSON.stringify(client_subs, null, 2));\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\treloadWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: function(id_ws) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWS(id_ws);\n\n\t\t\t\t\tif (ws) {\n\t\t\t\t\t\tResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('No WS');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\treconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: function(id_ws) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWS(id_ws);\n\n\t\t\t\t\tif (ws) {\n\t\t\t\t\t\tResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('No WS');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tdisconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: function(id_ws) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWS(id_ws);\n\n\t\t\t\t\tif (ws) {\n\t\t\t\t\t\tResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('No WS');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcreateUserAndEmailEnrollment: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tnewUser: {\n\t\t\t\t\ttype: Users['simplschema']\n\t\t\t\t},\n\t\t\t\tsendEnrollmentEmail: {\n\t\t\t\t\ttype: Boolean,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(newUser: UserModel, sendEnrollmentEmail = true) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tif (newUser.username.toLocaleLowerCase() === 'admin') {\n\t\t\t\t\t\treject('Username can not be admin');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tlet otherUser = await Users.findOne({\n\t\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t\t{username: newUser.username.toLocaleLowerCase()},\n\t\t\t\t\t\t\t\t{email: newUser.email.toLocaleLowerCase()}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (otherUser) {\n\t\t\t\t\t\t\treject('Username/Email is already used');\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tnewUser._id = objectIdHexString();\n\n\t\t\t\t\tnewUser.services = {\n\t\t\t\t\t\tenrollment: jwt.sign({id_user: newUser._id}, this.serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 3 * 24 * 60 * 60 * 1000 // 3 days\n\t\t\t\t\t\t})\n\t\t\t\t\t};\n\n\t\t\t\t\tnewUser.is_customer = false;\n\t\t\t\t\t\n\t\t\t\t\tawait Users.insertOne(newUser);\n\n\t\t\t\t\tif (sendEnrollmentEmail) {\n\t\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\t\tfullname: newUser.fullname,\n\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/enroll-account?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + newUser.services['enrollment'])\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tthis.readFile('email-templates/enrollment.html').then(html => {\n\t\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\t\tthis.sendEmail(newUser.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Enrollment Email', '', template(emailData), null, null, '');\n\t\t\n\t\t\t\t\t\t\tresolve(newUser);\n\t\t\t\t\t\t}, errEmail => reject(errEmail));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tresetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(userId: string) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\t\t\t\t\n\t\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\t\n\t\t\t\t\tif (user) {\n\t\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: userId}, this.serverConfig['JWT_SECRET']);\n\n\t\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\t\tuserWhoResetPassword: this.user,\n\t\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tUsers.updateOne({_id: user._id}, {$set: {services: user.services, attempts: 0}}).then(() => {\n\t\t\t\t\t\t\tthis.readFile('email-templates/forgot-password.html').then(html => {\n\t\t\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\t\tthis.sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\t\t\n\t\t\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t\t\t}, errEmail => reject(errEmail));\n\t\t\t\t\t\t}, () => {});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tsetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(userId: string, password: string) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\t\t\t\t\n\t\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\t\n\t\t\t\t\tif (user && !user.roles.super_admin) {\n\t\t\t\t\t\tawait Users.setPassword(user, password);\n\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('Invalid User');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/methods/accounts.ts"],"names":["simpl_schema_1","require","user_collection_1","handlebars","jwt","index_1","mongo_manager_1","loadAccountMethods","methodManager","methods","incorrectUser","check","default","old_user","type","Object","blackbox","new_user","client_subs","Array","client_subs.$","function","_this","this","Promise","resolve","reject","__awaiter","ws","ResolveIOServer","getMainServer","getWebSocketManager","getWebSocket","id_ws","sendEmail","serverConfig","JSON","stringify","user","id_user","getSubscriptionManager","getActiveSubscriptions","reloadWS","String","unsubscribeWS","reconnectWS","disconnectWS","createUserAndEmailEnrollment","newUser","Users","sendEnrollmentEmail","Boolean","optional","username","toLocaleLowerCase","findOne","$or","email","_a","sent","_id","objectIdHexString","services","enrollment","sign","expiresIn","is_customer","insertOne","emailData_1","fullname","url","encodeURIComponent","readFile","then","html","template","compile","registerHelper","a","b","getClientName","errEmail","resetUserPassword","userId","emailData_2","userToChangePassword","userWhoResetPassword","updateOne","$set","attempts","setUserPassword","password","roles","super_admin","setPassword","exports"],"mappings":"k8CAAAA,gB,yFAAAC,QAAA,cAAA,GACAC,kBAAAD,QAAA,gCAAA,EACAE,WAAAF,QAAA,YAAA,EACAG,IAAAH,QAAA,cAAA,EAGAI,QAAAJ,QAAA,UAAA,EAEAK,gBAAAL,QAAA,2BAAA,EAEA,SAAgBM,mBAAmBC,GAClCA,EAAcC,QAAQ,CACrBC,cAAe,CACdC,MAAO,IAAIX,eAAAY,QAAa,CACvBC,SAAU,CACTC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,SAAU,CACTH,KAAMC,OACNC,SAAU,CAAA,C,EAEXE,YAAa,CACZJ,KAAMK,K,EAEPC,gBAAiB,CAChBN,KAAMC,OACNC,SAAU,CAAA,C,EAEX,EACDK,SAAU,SAASR,EAAUI,EAAUC,GAA7B,IAAAI,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iDACpCM,EAAKvB,QAAAwB,gBAAgBC,cAAa,EAAGC,oBAAmB,EAAGC,aAAaT,KAAKU,KAAK,EAEtFV,KAAKW,UAAU,oBAAqB,kCAAoCX,KAAKY,aAA0B,YAAG,yBAA2BC,KAAKC,UAAUT,EAAI,KAAM,CAAC,EAAI,iBAAmBL,KAAKe,KAAO,mBAAqBf,KAAKgB,QAAU,2BAA6BH,KAAKC,UAAUhC,QAAAwB,gBAAgBC,cAAa,EAAGU,uBAAsB,EAAGC,uBAAsB,EAAI,KAAM,CAAC,EAAI,cAAgBL,KAAKC,UAAUxB,EAAU,KAAM,CAAC,EAAI,cAAgBuB,KAAKC,UAAUpB,EAAU,KAAM,CAAC,EAAI,iBAAmBmB,KAAKC,UAAUnB,EAAa,KAAM,CAAC,CAAC,EA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E,eAAe,SAAU,SAACC,EAAGC,GACvC,OAAOD,IAAMC,CACd,CAAC,EAEDzD,EAAKY,UAAUI,EAAKmB,MAAO,cAAgBpD,QAAAwB,gBAAgBmD,cAAa,EAAK,sBAAuB,GAAIL,EAASS,CAAS,EAAG,KAAM,KAAM,EAAE,EAE3I3D,EAAQ,CAAA,CAAI,CACb,EAAG,SAAAwD,GAAY,OAAAvD,EAAOuD,CAAQ,CAAf,CAAgB,CAChC,EAAG,YAAQ,G,SAEZ,CACF,C,EAEDS,gBAAiB,CAChB/E,MAAO,IAAIX,eAAAY,QAAa,CACvBuE,OAAQ,CACPrE,KAAM6B,M,EAEPgD,SAAU,CACT7E,KAAM6B,M,EAEP,EACDtB,SAAU,SAAS8D,EAAgBQ,GAAzB,IAAArE,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iEAC7B,MAAA,CAAA,EAAMpB,kBAAA+C,MAAMM,QAAQ,CAACK,IAAKuB,CAAM,CAAC,G,aAExC7C,EAFAA,EAAOoB,EAAAC,KAAA,IAEErB,EAAKsD,MAAMC,YAApB,CAAA,EAAA,GACH,CAAA,EAAM3F,kBAAA+C,MAAM6C,YAAYxD,EAAMqD,CAAQ,G,cAAtCjC,EAAAC,KAAA,EAEAlC,EAAQ,CAAA,CAAI,E,aAGZC,EAAO,cAAc,E,gCAEtB,CACF,C,EAED,CACF,CAnNAqE,QAAAxF,mBAAAA","file":"accounts.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { Users } from '../collections/user.collection';\nimport * as handlebars from 'handlebars';\nimport * as jwt from 'jsonwebtoken';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../index';\nimport { UserModel } from '../models/user.model';\nimport { objectIdHexString } from '../managers/mongo.manager';\n\nexport function loadAccountMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tincorrectUser: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\told_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tnew_user: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tclient_subs: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'client_subs.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(old_user, new_user, client_subs) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(this.id_ws);\n\n\t\t\t\t\tthis.sendEmail('dev@resolveio.com', 'SERVER - WRONG USER Detected - ' + this.serverConfig['CLIENT_NAME'], 'Wrong User Sent!\\nWS: ' + JSON.stringify(ws, null, 2) + '\\nUserMethod: ' + this.user + '\\nIdUserMethod: ' + this.id_user + '\\nSubManagerActiveSubs: ' + JSON.stringify(ResolveIOServer.getMainServer().getSubscriptionManager().getActiveSubscriptions(), null, 2) + '\\nOldUser: ' + JSON.stringify(old_user, null, 2) + '\\nNewUser: ' + JSON.stringify(new_user, null, 2) + '\\nClientSubs: ' + JSON.stringify(client_subs, null, 2));\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\treloadWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: function(id_ws) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\t\tif (ws) {\n\t\t\t\t\t\tResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('No WS');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\treconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: function(id_ws) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\t\tif (ws) {\n\t\t\t\t\t\tResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('No WS');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tdisconnectWS: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_ws: String\n\t\t\t}),\n\t\t\tfunction: function(id_ws) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet ws = ResolveIOServer.getMainServer().getWebSocketManager().getWebSocket(id_ws);\n\n\t\t\t\t\tif (ws) {\n\t\t\t\t\t\tResolveIOServer.getMainServer().unsubscribeWS(ws);\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('No WS');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcreateUserAndEmailEnrollment: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tnewUser: {\n\t\t\t\t\ttype: Users['simplschema']\n\t\t\t\t},\n\t\t\t\tsendEnrollmentEmail: {\n\t\t\t\t\ttype: Boolean,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(newUser: UserModel, sendEnrollmentEmail = true) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tif (newUser.username.toLocaleLowerCase() === 'admin') {\n\t\t\t\t\t\treject('Username can not be admin');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tlet otherUser = await Users.findOne({\n\t\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t\t{username: newUser.username.toLocaleLowerCase()},\n\t\t\t\t\t\t\t\t{email: newUser.email.toLocaleLowerCase()}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (otherUser) {\n\t\t\t\t\t\t\treject('Username/Email is already used');\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tnewUser._id = objectIdHexString();\n\n\t\t\t\t\tnewUser.services = {\n\t\t\t\t\t\tenrollment: jwt.sign({id_user: newUser._id}, this.serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 3 * 24 * 60 * 60 * 1000 // 3 days\n\t\t\t\t\t\t})\n\t\t\t\t\t};\n\n\t\t\t\t\tnewUser.is_customer = false;\n\t\t\t\t\t\n\t\t\t\t\tawait Users.insertOne(newUser);\n\n\t\t\t\t\tif (sendEnrollmentEmail) {\n\t\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\t\tfullname: newUser.fullname,\n\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/enroll-account?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + newUser.services['enrollment'])\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tthis.readFile('email-templates/enrollment.html').then(html => {\n\t\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\t\tthis.sendEmail(newUser.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Enrollment Email', '', template(emailData), null, null, '');\n\t\t\n\t\t\t\t\t\t\tresolve(newUser);\n\t\t\t\t\t\t}, errEmail => reject(errEmail));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tresetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(userId: string) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\t\t\t\t\n\t\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\t\n\t\t\t\t\tif (user) {\n\t\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: userId}, this.serverConfig['JWT_SECRET']);\n\n\t\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\t\tuserWhoResetPassword: this.user,\n\t\t\t\t\t\t\turl: (this.serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tUsers.updateOne({_id: user._id}, {$set: {services: user.services, attempts: 0}}).then(() => {\n\t\t\t\t\t\t\tthis.readFile('email-templates/forgot-password.html').then(html => {\n\t\t\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\t\tthis.sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\t\t\n\t\t\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t\t\t}, errEmail => reject(errEmail));\n\t\t\t\t\t\t}, () => {});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tsetUserPassword: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(userId: string, password: string) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\t\t\t\t\n\t\t\t\t\tlet user = await Users.findOne({_id: userId});\n\t\t\n\t\t\t\t\tif (user && !user.roles.super_admin) {\n\t\t\t\t\t\tawait Users.setPassword(user, password);\n\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject('Invalid User');\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}"]}
|