@resolveio/server-lib 20.0.28 → 20.1.0
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/client-server-app.js +1 -1
- package/client-server-app.js.map +1 -1
- package/cron/cron.js +1 -1
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +1 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +1 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +1 -1
- package/http/auth.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +1 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +1 -1
- package/managers/method.manager.js.map +1 -1
- 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.js +1 -1
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +1 -1
- package/methods/aws.js.map +1 -1
- package/methods/counters.js +1 -1
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/logs.js +1 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +1 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +1 -1
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +1 -1
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +1 -1
- package/methods/support.js.map +1 -1
- package/methods.ts +34 -0
- package/package.json +1 -1
- package/publications/report-builder-libraries.js +1 -1
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications.ts +31 -0
- package/server-app.js +1 -1
- package/server-app.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":"knDAGAA,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,EAAYC,EAAYC,EAAuBC,EAAcC,GAA7D,IAAAC,EAAAC,KAzCQA,KAAAC,cAA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ACpCzH,UAAWH,EAAOG,UAClBoH,SAAU,CAAA,EACV1I,KAAMwB,C,EAGPhG,EAAKiN,OAAOjJ,EAAIuJ,CAAS,EAG5B,CAAC,EAED5C,EAAO3E,CAAG,CACX,CAAC,IA5JGd,EAAWE,aAAaoF,SAC3BvK,KAAK2B,WAAW4L,IAAItI,EAAWE,aAAaoF,OAAO,EAGgJ,GAAhMvK,KAAKE,eAAeuH,UAAU,SAAApE,GAAK,OAAAA,EAAEI,cAAgBwB,EAAWE,aAAa1B,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,EAAAqI,UAAAiF,OAAR,SAAejJ,EAAeQ,GAC7BvE,KAAKM,WAAWoE,OAAO,EAAG,EAAG,CAC5BT,MAAOF,EAAc,UACrBQ,KAAMA,C,CACN,CACF,EAEO7E,EAAAqI,UAAAjF,eAAP,WACC,OAAO9C,KAAKa,YACb,EACDnB,CAAA,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}, 25);\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","_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,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oF,SAC3BvK,KAAK2B,WAAW4L,IAAItI,EAAWE,aAAaoF,OAAO,EAGgJ,GAAhMvK,KAAKE,eAAeuH,UAAU,SAAApE,GAAK,OAAAA,EAAEI,cAAgBwB,EAAWE,aAAa1B,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}, 25);\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"]}
|
package/methods/accounts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,
|
|
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,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},u={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function verb(n){return function(e){var r=[n,e];if(s)throw new TypeError("Generator is already executing.");for(;l=u&&r[u=0]?0:l;)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 l.label++,{value:r[1],done:!1};case 5:l.label++,o=r[1],r=[0];continue;case 7:r=l.ops.pop(),l.trys.pop();continue;default:if(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===r[0]||2===r[0])){l=0;continue}if(3===r[0]&&(!a||r[1]>a[0]&&r[1]<a[3]))l.label=r[1];else if(6===r[0]&&l.label<a[1])l.label=a[1],a=r;else{if(!(a&&l.label<a[2])){a[2]&&l.ops.pop(),l.trys.pop();continue}l.label=a[2],l.ops.push(r)}}r=i.call(t,l)}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().getWS(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().getWS(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().getWS(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().getWS(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":"44CAAAA,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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AAQ,CAACK,IAAKuB,CAAM,CAAC,G,aAExC7C,EAFAA,EAAOoB,EAAAC,KAAA,IAEErB,EAAKsD,MAAMC,YAApB,CAAA,EAAA,GACH,CAAA,EAAM1F,kBAAA8C,MAAM6C,YAAYxD,EAAMqD,CAAQ,G,cAAtCjC,EAAAC,KAAA,EAEAjC,EAAQ,CAAA,CAAI,E,aAGZC,EAAO,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","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,EAEzDT,KAAKU,UAAU,oBAAqB,kCAAoCV,KAAKW,aAA0B,YAAG,yBAA2BC,KAAKC,UAAUR,EAAI,KAAM,CAAC,EAAI,iBAAmBL,KAAKc,KAAO,mBAAqBd,KAAKe,QAAU,2BAA6BH,KAAKC,UAAU/B,QAAAwB,gBAAgBC,cA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,EAAKwB,SAAU2B,SAAU,CAAC,CAAC,CAAC,EAAEhB,KAAK,WACrFlD,EAAKiD,SAAS,sCAAsC,EAAEC,KAAK,SAAAC,GACtDC,EAAWvE,WAAWwE,QAAQF,CAAI,EACtCtE,WAAWyE,eAAe,SAAU,SAACC,EAAGC,GACvC,OAAOD,IAAMC,CACd,CAAC,EAEDxD,EAAKW,UAAUI,EAAKmB,MAAO,cAAgBnD,QAAAwB,gBAAgBkD,cAAa,EAAK,sBAAuB,GAAIL,EAASS,CAAS,EAAG,KAAM,KAAM,EAAE,EAE3I1D,EAAQ,CAAA,CAAI,CACb,EAAG,SAAAuD,GAAY,OAAAtD,EAAOsD,CAAQ,CAAf,CAAgB,CAChC,EAAG,YAAQ,G,SAEZ,CACF,C,EAEDS,gBAAiB,CAChB9E,MAAO,IAAIX,eAAAY,QAAa,CACvBsE,OAAQ,CACPpE,KAAM4B,M,EAEPgD,SAAU,CACT5E,KAAM4B,M,EAEP,EACDrB,SAAU,SAAS6D,EAAgBQ,GAAzB,IAAApE,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iEAC7B,MAAA,CAAA,EAAMpB,kBAAA8C,MAAMM,QAAQ,CAACK,IAAKuB,CAAM,CAAC,G,aAExC7C,EAFAA,EAAOoB,EAAAC,KAAA,IAEErB,EAAKsD,MAAMC,YAApB,CAAA,EAAA,GACH,CAAA,EAAM1F,kBAAA8C,MAAM6C,YAAYxD,EAAMqD,CAAQ,G,cAAtCjC,EAAAC,KAAA,EAEAjC,EAAQ,CAAA,CAAI,E,aAGZC,EAAO,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}"]}
|
package/methods/aws.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,s,c,a){return new(c=c||Promise)(function(n,t){function i(e){try{o(a.next(e))}catch(e){t(e)}}function r(e){try{o(a.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}o((a=a.apply(e,s||[])).next())})},__generator=this&&this.__generator||function(i,r){var o,s,c,a={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]},l={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function e(n){return function(e){var t=[n,e];if(o)throw new TypeError("Generator is already executing.");for(;a=l&&t[l=0]?0:a;)try{if(o=1,s&&(c=2&t[0]?s.return:t[0]?s.throw||((c=s.return)&&c.call(s),0):s.next)&&!(c=c.call(s,t[1])).done)return c;switch(s=0,(t=c?[2&t[0],c.value]:t)[0]){case 0:case 1:c=t;break;case 4:return a.label++,{value:t[1],done:!1};case 5:a.label++,s=t[1],t=[0];continue;case 7:t=a.ops.pop(),a.trys.pop();continue;default:if(!(c=0<(c=a.trys).length&&c[c.length-1])&&(6===t[0]||2===t[0])){a=0;continue}if(3===t[0]&&(!c||t[1]>c[0]&&t[1]<c[3]))a.label=t[1];else if(6===t[0]&&a.label<c[1])a.label=c[1],c=t;else{if(!(c&&a.label<c[2])){c[2]&&a.ops.pop(),a.trys.pop();continue}a.label=c[2],a.ops.push(t)}}t=r.call(i,a)}catch(e){t=[6,e],s=0}finally{o=c=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},file_collection_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadAWSMethods=void 0,require("../collections/file.collection")),simpl_schema_1=require("simpl-schema"),index_1=require("../index"),mongo_manager_1=require("../managers/mongo.manager"),client_s3_1=require("@aws-sdk/client-s3"),s3_request_presigner_1=require("@aws-sdk/s3-request-presigner"),request=require("request").defaults({encoding:null}),fs=require("fs"),pdfCnt=1e6;function loadAWSMethods(e){e.methods({uploadFileAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:String},fileSize:{type:Number},fileOrder:{type:Number},fileType:{type:String},compress:{type:Boolean}}),function:function(a,l,u,f,_,e){var t=this;return new Promise(function(s,c){return __awaiter(t,void 0,void 0,function(){var t,n,i,r,o;return __generator(this,function(e){return a?(t="uploads/"+Date.now()+"-"+pdfCnt+++"-"+a,n=this.getAWS().s3(),i=3,r=0,(o=function(){n.putObject({Bucket:process.env.AWS_S3_BUCKET,Key:t,Body:Buffer.from(l.replace("data:"+l.split(",")[0].split(":")[1].split(";")[0]+";base64,",""),"base64"),ACL:"private",ContentType:l.split(",")[0].split(":")[1].split(";")[0],ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:a,size:u,key:t,order:f,type:_}).then(function(e){s(e)}).catch(function(e){c(e)}):s(null)}).catch(function(e){var t;++r<=i?(t=1e3*Math.pow(2,r),console.warn("Attempt ".concat(r," failed. Retrying in ").concat(t/1e3," seconds...")),setTimeout(o,t)):c(new Error("Failed to upload after ".concat(i," attempts: ").concat(e.message)))})})()):c(new Error("Invalid fileName provided")),[2]})})})}},uploadNonPDFFileAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:String},fileSize:{type:Number},fileOrder:{type:Number},fileType:{type:String}}),function:function(r,e,o,s,c){var a=this;return new Promise(function(t,n){var i;r&&(i="uploads/"+Date.now()+"-"+r,a.getAWS().s3().putObject({Bucket:process.env.AWS_S3_BUCKET,Key:i,Body:Buffer.from(e),ACL:"private",ContentType:"application/gzip",ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:r,size:o,key:i,order:s,type:c}).then(function(e){t(e)},function(e){return n(e)}):t(null)},function(e){n(e)}))})}},uploadNonPDFBufferAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:Buffer},fileSize:{type:Number},fileOrder:{type:Number},fileType:{type:String}}),function:function(r,e,o,s,c){var a=this;return new Promise(function(t,n){var i;r&&(i="uploads/"+Date.now()+"-"+r,a.getAWS().s3().putObject({Bucket:process.env.AWS_S3_BUCKET,Key:i,Body:e,ACL:"private",ContentType:"application/gzip",ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:r,size:o,key:i,order:s,type:c}).then(function(e){t(e)},function(e){return n(e)}):t(null)},function(e){n(e)}))})}},uploadNonPDFStreamAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:String},fileOrder:{type:Number},fileType:{type:String}}),function:function(r,e,o,s){var c=this;return new Promise(function(t,n){var i;r&&(i="uploads/"+Date.now()+"-"+r,c.getAWS().s3().putObject({Bucket:process.env.AWS_S3_BUCKET,Key:i,Body:fs.createReadStream(e),ACL:"private",ContentType:"application/gzip",ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:r,size:1,key:i,order:o,type:s}).then(function(e){t(e)},function(e){return n(e)}):t(null)},function(e){n(e)}))})}},deleteFiles:{check:new simpl_schema_1.default({keys:{type:Array},"keys.$":{type:String}}),function:function(o){var t=this;return new Promise(function(r,e){return __awaiter(t,void 0,void 0,function(){var t,n,i=this;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.find({key:{$in:o}})];case 1:return t=e.sent(),n=t.length,t.forEach(function(e){file_collection_1.Files.deleteOne({_id:e._id}),i.getAWS().s3().deleteObject({Bucket:process.env.AWS_S3_BUCKET,Key:e.key}).then(function(e){!e||--n||r(t.length)})}),[2]}})})})}},deleteFile:{check:new simpl_schema_1.default({key:{type:String}}),function:function(r){var e=this;return new Promise(function(n,i){return __awaiter(e,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findOne({key:r})];case 1:return(t=e.sent())&&file_collection_1.Files.deleteOne({_id:t._id}),this.getAWS().s3().deleteObject({Bucket:process.env.AWS_S3_BUCKET,Key:r}).then(function(e){n(e)},function(e){i(e)}),[2]}})})})}},deleteFileWithId:{check:new simpl_schema_1.default({id_file:{type:String}}),function:function(r){var e=this;return new Promise(function(n,i){return __awaiter(e,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findOne({_id:r})];case 1:return(t=e.sent())||i("Could not find file"),this.getAWS().s3().deleteObject({Bucket:process.env.AWS_S3_BUCKET,Key:t.key}).then(function(e){n(e)},function(e){i(e)}),file_collection_1.Files.deleteOne({_id:t._id}),[2]}})})})}},getSignedUrlsAndFilesWithId:{check:new simpl_schema_1.default({ids:{type:Array},"ids.$":{type:String},expires:{type:Number}}),function:function(l,u){var t=this;return new Promise(function(a,e){return __awaiter(t,void 0,void 0,function(){var t,n,i,r,o,s,c;return __generator(this,function(e){switch(e.label){case 0:return t=[],[4,file_collection_1.Files.find({_id:{$in:l}})];case 1:n=e.sent(),i=0,e.label=2;case 2:return i<n.length?(o=n[i],r=this.getAWS().s3(),o=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:o.key}),c=(s=t).push,[4,(0,s3_request_presigner_1.getSignedUrl)(r,o,{expiresIn:u})]):[3,5];case 3:c.apply(s,[e.sent()]),e.label=4;case 4:return i++,[3,2];case 5:return a({res:t,fileArray:n.map(function(e){return e.name})}),[2]}})})})}},getSignedUrlWithId:{check:new simpl_schema_1.default({id_file:{type:String},expires:{type:Number}}),function:function(o,s){var e=this;return new Promise(function(i,r){return __awaiter(e,void 0,void 0,function(){var t,n;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findOne({_id:o})];case 1:return n=e.sent(),t=this.getAWS().s3(),n=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:n.key}),(0,s3_request_presigner_1.getSignedUrl)(t,n,{expiresIn:s}).then(function(e){i(e)},function(e){r(e)}),[2]}})})})}},getSignedUrlUSEast1BucketAndKey:{check:new simpl_schema_1.default({bucket:{type:String},key:{type:String},expires:{type:Number}}),function:function(r,o,s){var c=this;return new Promise(function(t,n){var e=c.getAWS().s3USEast1(),i=new client_s3_1.GetObjectCommand({Bucket:r,Key:o});(0,s3_request_presigner_1.getSignedUrl)(e,i,{expiresIn:s}).then(function(e){t(e)},function(e){n(e)})})}},getSignedUrl:{check:new simpl_schema_1.default({key:{type:String},expires:{type:Number}}),function:function(r,o){var s=this;return new Promise(function(t,n){var e=s.getAWS().s3(),i=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:r});(0,s3_request_presigner_1.getSignedUrl)(e,i,{expiresIn:o}).then(function(e){t(e)},function(e){n(e)})})}},getSignedUrls:{check:new simpl_schema_1.default({keys:{type:Array},"keys.$":{type:String},expires:{type:Number}}),function:function(a,l){var t=this;return new Promise(function(c,e){return __awaiter(t,void 0,void 0,function(){var t,n,i,r,o,s;return __generator(this,function(e){switch(e.label){case 0:t=[],n=0,e.label=1;case 1:return n<a.length?(r=a[n],i=this.getAWS().s3(),r=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:r}),s=(o=t).push,[4,(0,s3_request_presigner_1.getSignedUrl)(i,r,{expiresIn:l})]):[3,4];case 2:s.apply(o,[e.sent()]),e.label=3;case 3:return n++,[3,1];case 4:return c(t),[2]}})})})}},getDataURIfromURL:{check:new simpl_schema_1.default({url:{type:String}}),function:function(e){return new Promise(function(i,r){request.get(e,function(e,t,n){e||200!==t.statusCode?r(e):(e="data:"+t.headers["content-type"]+";base64,"+new Buffer(n).toString("base64"),i(e))})})}},emailFile:{check:new simpl_schema_1.default({id_file:{type:String},email:{type:String},additional_message:{type:String}}),function:function(t,c,a){var e=this;return new Promise(function(o,s){return __awaiter(e,void 0,void 0,function(){var i,r=this;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findById(t)];case 1:return(i=e.sent())?this.callMethodInternal("getSignedUrl",i.key,259200,function(e,t){var n;t?(i.size<5e6?(n="Attached is the file requested for email.\n"+(""!==a?"\nAdditional Message:\n"+a+"\n":""),r.sendEmail(c,index_1.ResolveIOServer.getClientName()+" File - "+i.name,n,"",[{filename:i.name,path:t}],null,"")):(n="Please click the link to the requested file.\n"+(""!==a?"\nAdditional Message:\n"+a+"\n":""),r.sendEmail(c,index_1.ResolveIOServer.getClientName()+" File - "+i.name,n+t,"",null,null,"")),o(!0)):s("Could not get file URL")}):s("Could not find file"),[2]}})})})}}})}exports.loadAWSMethods=loadAWSMethods;
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,i,r,o){return new(r=r||Promise)(function(n,t){function fulfilled(e){try{step(o.next(e))}catch(e){t(e)}}function rejected(e){try{step(o.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?n(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(fulfilled,rejected)}step((o=o.apply(e,i||[])).next())})},__generator=this&&this.__generator||function(i,r){var o,s,c,l={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]},a={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function verb(n){return function(e){var t=[n,e];if(o)throw new TypeError("Generator is already executing.");for(;l=a&&t[a=0]?0:l;)try{if(o=1,s&&(c=2&t[0]?s.return:t[0]?s.throw||((c=s.return)&&c.call(s),0):s.next)&&!(c=c.call(s,t[1])).done)return c;switch(s=0,(t=c?[2&t[0],c.value]:t)[0]){case 0:case 1:c=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,s=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!(c=0<(c=l.trys).length&&c[c.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!c||t[1]>c[0]&&t[1]<c[3]))l.label=t[1];else if(6===t[0]&&l.label<c[1])l.label=c[1],c=t;else{if(!(c&&l.label<c[2])){c[2]&&l.ops.pop(),l.trys.pop();continue}l.label=c[2],l.ops.push(t)}}t=r.call(i,l)}catch(e){t=[6,e],s=0}finally{o=c=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},file_collection_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadAWSMethods=void 0,require("../collections/file.collection")),simpl_schema_1=require("simpl-schema"),index_1=require("../index"),mongo_manager_1=require("../managers/mongo.manager"),client_s3_1=require("@aws-sdk/client-s3"),s3_request_presigner_1=require("@aws-sdk/s3-request-presigner"),request=require("request").defaults({encoding:null}),fs=require("fs"),pdfCnt=1e6;function loadAWSMethods(e){e.methods({uploadFileAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:String},fileSize:{type:Number},fileOrder:{type:Number},fileType:{type:String},compress:{type:Boolean}}),function:function(l,a,u,f,_,e){var t=this;return new Promise(function(s,c){return __awaiter(t,void 0,void 0,function(){var t,n,i,r,o;return __generator(this,function(e){return l?(t="uploads/"+Date.now()+"-"+pdfCnt+++"-"+l,n=this.getAWS().s3(),i=3,r=0,(o=function(){n.putObject({Bucket:process.env.AWS_S3_BUCKET,Key:t,Body:Buffer.from(a.replace("data:"+a.split(",")[0].split(":")[1].split(";")[0]+";base64,",""),"base64"),ACL:"private",ContentType:a.split(",")[0].split(":")[1].split(";")[0],ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:l,size:u,key:t,order:f,type:_}).then(function(e){s(e)}).catch(function(e){c(e)}):s(null)}).catch(function(e){var t;++r<=i?(t=1e3*Math.pow(2,r),console.warn("Attempt ".concat(r," failed. Retrying in ").concat(t/1e3," seconds...")),setTimeout(o,t)):c(new Error("Failed to upload after ".concat(i," attempts: ").concat(e.message)))})})()):c(new Error("Invalid fileName provided")),[2]})})})}},uploadNonPDFFileAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:String},fileSize:{type:Number},fileOrder:{type:Number},fileType:{type:String}}),function:function(r,e,o,s,c){var l=this;return new Promise(function(t,n){var i;r&&(i="uploads/"+Date.now()+"-"+r,l.getAWS().s3().putObject({Bucket:process.env.AWS_S3_BUCKET,Key:i,Body:Buffer.from(e),ACL:"private",ContentType:"application/gzip",ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:r,size:o,key:i,order:s,type:c}).then(function(e){t(e)},function(e){return n(e)}):t(null)},function(e){n(e)}))})}},uploadNonPDFBufferAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:Buffer},fileSize:{type:Number},fileOrder:{type:Number},fileType:{type:String}}),function:function(r,e,o,s,c){var l=this;return new Promise(function(t,n){var i;r&&(i="uploads/"+Date.now()+"-"+r,l.getAWS().s3().putObject({Bucket:process.env.AWS_S3_BUCKET,Key:i,Body:e,ACL:"private",ContentType:"application/gzip",ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:r,size:o,key:i,order:s,type:c}).then(function(e){t(e)},function(e){return n(e)}):t(null)},function(e){n(e)}))})}},uploadNonPDFStreamAndSave:{check:new simpl_schema_1.default({fileName:{type:String},fileData:{type:String},fileOrder:{type:Number},fileType:{type:String}}),function:function(r,e,o,s){var c=this;return new Promise(function(t,n){var i;r&&(i="uploads/"+Date.now()+"-"+r,c.getAWS().s3().putObject({Bucket:process.env.AWS_S3_BUCKET,Key:i,Body:fs.createReadStream(e),ACL:"private",ContentType:"application/gzip",ContentDisposition:"inline"}).then(function(e){e?file_collection_1.Files.create({_id:(0,mongo_manager_1.objectIdHexString)(),__v:0,name:r,size:1,key:i,order:o,type:s}).then(function(e){t(e)},function(e){return n(e)}):t(null)},function(e){n(e)}))})}},deleteFiles:{check:new simpl_schema_1.default({keys:{type:Array},"keys.$":{type:String}}),function:function(o){var t=this;return new Promise(function(r,e){return __awaiter(t,void 0,void 0,function(){var t,n,i=this;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.find({key:{$in:o}})];case 1:return t=e.sent(),n=t.length,t.forEach(function(e){file_collection_1.Files.deleteOne({_id:e._id}),i.getAWS().s3().deleteObject({Bucket:process.env.AWS_S3_BUCKET,Key:e.key}).then(function(e){!e||--n||r(t.length)})}),[2]}})})})}},deleteFile:{check:new simpl_schema_1.default({key:{type:String}}),function:function(r){var e=this;return new Promise(function(n,i){return __awaiter(e,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findOne({key:r})];case 1:return(t=e.sent())&&file_collection_1.Files.deleteOne({_id:t._id}),this.getAWS().s3().deleteObject({Bucket:process.env.AWS_S3_BUCKET,Key:r}).then(function(e){n(e)},function(e){i(e)}),[2]}})})})}},deleteFileWithId:{check:new simpl_schema_1.default({id_file:{type:String}}),function:function(r){var e=this;return new Promise(function(n,i){return __awaiter(e,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findOne({_id:r})];case 1:return(t=e.sent())||i("Could not find file"),this.getAWS().s3().deleteObject({Bucket:process.env.AWS_S3_BUCKET,Key:t.key}).then(function(e){n(e)},function(e){i(e)}),file_collection_1.Files.deleteOne({_id:t._id}),[2]}})})})}},getSignedUrlsAndFilesWithId:{check:new simpl_schema_1.default({ids:{type:Array},"ids.$":{type:String},expires:{type:Number}}),function:function(a,u){var t=this;return new Promise(function(l,e){return __awaiter(t,void 0,void 0,function(){var t,n,i,r,o,s,c;return __generator(this,function(e){switch(e.label){case 0:return t=[],[4,file_collection_1.Files.find({_id:{$in:a}})];case 1:n=e.sent(),i=0,e.label=2;case 2:return i<n.length?(o=n[i],r=this.getAWS().s3(),o=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:o.key}),c=(s=t).push,[4,(0,s3_request_presigner_1.getSignedUrl)(r,o,{expiresIn:u})]):[3,5];case 3:c.apply(s,[e.sent()]),e.label=4;case 4:return i++,[3,2];case 5:return l({res:t,fileArray:n.map(function(e){return e.name})}),[2]}})})})}},getSignedUrlWithId:{check:new simpl_schema_1.default({id_file:{type:String},expires:{type:Number}}),function:function(o,s){var e=this;return new Promise(function(i,r){return __awaiter(e,void 0,void 0,function(){var t,n;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findOne({_id:o})];case 1:return n=e.sent(),t=this.getAWS().s3(),n=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:n.key}),(0,s3_request_presigner_1.getSignedUrl)(t,n,{expiresIn:s}).then(function(e){i(e)},function(e){r(e)}),[2]}})})})}},getSignedUrlUSEast1BucketAndKey:{check:new simpl_schema_1.default({bucket:{type:String},key:{type:String},expires:{type:Number}}),function:function(r,o,s){var c=this;return new Promise(function(t,n){var e=c.getAWS().s3USEast1(),i=new client_s3_1.GetObjectCommand({Bucket:r,Key:o});(0,s3_request_presigner_1.getSignedUrl)(e,i,{expiresIn:s}).then(function(e){t(e)},function(e){n(e)})})}},getSignedUrl:{check:new simpl_schema_1.default({key:{type:String},expires:{type:Number}}),function:function(r,o){var s=this;return new Promise(function(t,n){var e=s.getAWS().s3(),i=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:r});(0,s3_request_presigner_1.getSignedUrl)(e,i,{expiresIn:o}).then(function(e){t(e)},function(e){n(e)})})}},getSignedUrls:{check:new simpl_schema_1.default({keys:{type:Array},"keys.$":{type:String},expires:{type:Number}}),function:function(l,a){var t=this;return new Promise(function(c,e){return __awaiter(t,void 0,void 0,function(){var t,n,i,r,o,s;return __generator(this,function(e){switch(e.label){case 0:t=[],n=0,e.label=1;case 1:return n<l.length?(r=l[n],i=this.getAWS().s3(),r=new client_s3_1.GetObjectCommand({Bucket:process.env.AWS_S3_BUCKET,Key:r}),s=(o=t).push,[4,(0,s3_request_presigner_1.getSignedUrl)(i,r,{expiresIn:a})]):[3,4];case 2:s.apply(o,[e.sent()]),e.label=3;case 3:return n++,[3,1];case 4:return c(t),[2]}})})})}},getDataURIfromURL:{check:new simpl_schema_1.default({url:{type:String}}),function:function(e){return new Promise(function(i,r){request.get(e,function(e,t,n){e||200!==t.statusCode?r(e):(e="data:"+t.headers["content-type"]+";base64,"+new Buffer(n).toString("base64"),i(e))})})}},emailFile:{check:new simpl_schema_1.default({id_file:{type:String},email:{type:String},additional_message:{type:String}}),function:function(t,c,l){var e=this;return new Promise(function(o,s){return __awaiter(e,void 0,void 0,function(){var i,r=this;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.findById(t)];case 1:return(i=e.sent())?this.callMethodInternal("getSignedUrl",i.key,259200,function(e,t){var n;t?(i.size<5e6?(n="Attached is the file requested for email.\n"+(""!==l?"\nAdditional Message:\n"+l+"\n":""),r.sendEmail(c,index_1.ResolveIOServer.getClientName()+" File - "+i.name,n,"",[{filename:i.name,path:t}],null,"")):(n="Please click the link to the requested file.\n"+(""!==l?"\nAdditional Message:\n"+l+"\n":""),r.sendEmail(c,index_1.ResolveIOServer.getClientName()+" File - "+i.name,n+t,"",null,null,"")),o(!0)):s("Could not get file URL")}):s("Could not find file"),[2]}})})})}}})}exports.loadAWSMethods=loadAWSMethods;
|
|
2
2
|
//# sourceMappingURL=aws.js.map
|