@resolveio/server-lib 9.2.19 → 9.2.20
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 +55 -1
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +40 -1
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +40 -1
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +43 -1
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +71 -1
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +74 -1
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +55 -1
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +50 -1
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +62 -1
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +44 -1
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +53 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +57 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +72 -1
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +58 -1
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +51 -1
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +55 -1
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +57 -1
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +66 -1
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +74 -1
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +68 -1
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +62 -1
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +40 -1
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +93 -1
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +76 -1
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +138 -1
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +79 -1
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +46 -1
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +248 -1
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +161 -1
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +72 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +62 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +697 -1
- package/http/auth.js.map +1 -1
- package/http/health.js +10 -1
- package/http/health.js.map +1 -1
- package/http/home.js +64 -1
- package/http/home.js.map +1 -1
- package/index.js +123 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +205 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +599 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1682 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +334 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +867 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +100 -1
- package/managers/subscription.performance.js.map +1 -1
- package/methods/accounts.js +224 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +449 -1
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +214 -1
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +526 -1
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +121 -1
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1284 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +8 -1
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +370 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +384 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +685 -1
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +826 -1
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +263 -1
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +3 -1
- package/models/app-status.model.js.map +1 -1
- package/models/app-version.model.js +3 -1
- package/models/app-version.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +3 -1
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +3 -1
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +3 -1
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +3 -1
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +3 -1
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +3 -1
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +3 -1
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +3 -1
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +3 -1
- package/models/file.model.js.map +1 -1
- package/models/flag.model.js +3 -1
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +3 -1
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +3 -1
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +3 -1
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +3 -1
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-call.model.js +3 -1
- package/models/method-call.model.js.map +1 -1
- package/models/method-response.model.js +3 -1
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.js +3 -1
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +3 -1
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-https-inbound.model.js +3 -1
- package/models/monitor-https-inbound.model.js.map +1 -1
- package/models/monitor-https-outbound.model.js +3 -1
- package/models/monitor-https-outbound.model.js.map +1 -1
- package/models/monitor-memory.model.js +3 -1
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +3 -1
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +3 -1
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +23 -1
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +3 -1
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +3 -1
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +3 -1
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +3 -1
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +3 -1
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +3 -1
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-response.model.js +3 -1
- package/models/server-response.model.js.map +1 -1
- package/models/subscription.model.js +3 -1
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +3 -1
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +3 -1
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +3 -1
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +3 -1
- package/models/user.model.js.map +1 -1
- package/package.json +1 -2
- package/public_api.js +78 -1
- package/public_api.js.map +1 -1
- package/publications/app-status.js +16 -1
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +16 -1
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +32 -1
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +36 -1
- package/publications/files.js.map +1 -1
- package/publications/flags.js +22 -1
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +90 -1
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +16 -1
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +16 -1
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +16 -1
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +42 -1
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +89 -1
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +50 -1
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +16 -1
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +16 -1
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +16 -1
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +682 -1
- package/server-app.js.map +1 -1
- package/util/common.js +498 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +452 -1
- package/util/schema-report-builder.js.map +1 -1
|
@@ -1,2 +1,600 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,o,r){return new(o||(o=Promise))((function(n,i){function fulfilled(e){try{step(r.next(e))}catch(e){i(e)}}function rejected(e){try{step(r.throw(e))}catch(e){i(e)}}function step(e){e.done?n(e.value):function adopt(e){return e instanceof o?e:new o((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((r=r.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var o,r,n,i,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return i={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function verb(i){return function(a){return function step(i){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,r&&(n=2&i[0]?r.return:i[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,i[1])).done)return n;switch(r=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){s.label=i[1];break}if(6===i[0]&&s.label<n[1]){s.label=n[1],n=i;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(i);break}n[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{o=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},__spreadArrays=this&&this.__spreadArrays||function(){for(var e=0,t=0,o=arguments.length;t<o;t++)e+=arguments[t].length;var r=Array(e),n=0;for(t=0;t<o;t++)for(var i=arguments[t],s=0,a=i.length;s<a;s++,n++)r[n]=i[s];return r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MethodManager=void 0;var collections_1=require("../methods/collections"),logs_1=require("../methods/logs"),counters_1=require("../methods/counters"),pdf_1=require("../methods/pdf"),aws_1=require("../methods/aws"),cloudconvert_1=require("../methods/cloudconvert"),path=require("path"),fs=require("fs"),nodemailer=require("nodemailer"),aws=require("aws-sdk"),accounts_1=require("../methods/accounts"),init_1=require("../fixtures/init"),cron_jobs_1=require("../fixtures/cron-jobs"),cron_jobs_2=require("../methods/cron-jobs"),flags_1=require("../methods/flags"),method_response_collection_1=require("../collections/method-response.collection"),common_1=require("../util/common"),log_collection_1=require("../collections/log.collection"),log_method_latency_collection_1=require("../collections/log-method-latency.collection"),moment=require("moment"),report_builder_1=require("../methods/report-builder"),support_1=require("../methods/support"),monitor_1=require("../methods/monitor"),email_history_collection_1=require("../collections/email-history.collection"),mongo_manager_1=require("./mongo.manager"),Verifier=require("email-verifier"),MethodManager=function(){function MethodManager(e,t,o){var r=this;this._methods={},this._sendQueue=[],this._runningQueue=!1,this._mainServer=e,this.serverConfig=t,this.clientDir=o,init_1.loadServerInit(),cron_jobs_1.loadServerCronJobs(),accounts_1.loadAccountMethods(this),aws_1.loadAWSMethods(this),cloudconvert_1.loadCloudConvertMethods(this),collections_1.loadCollectionMethods(this),counters_1.loadCounterMethods(this),logs_1.loadLogMethods(this),pdf_1.loadPDFMethods(this),cron_jobs_2.loadCronJobMethods(this),flags_1.loadFlagMethods(this),report_builder_1.loadReportBuilderMethods(this),support_1.loadSupportMethods(this),monitor_1.loadMonitorMethods(this),e.sesMail?this._mailer=nodemailer.createTransport({SES:new aws.SES({apiVersion:"2010-12-01",accessKeyId:t.AWSACCESSKEYID,secretAccessKey:t.AWSSECRETACCESSKEY,region:t.AWSSES_REGION})}):this._mailer=nodemailer.createTransport({host:this.serverConfig.MAIL_HOST,port:this.serverConfig.MAIL_PORT,secure:!1,auth:{user:this.serverConfig.MAIL_USERNAME,pass:this.serverConfig.MAIL_PASSWORD},tls:{ciphers:"SSLv3"}}),this._aws=new aws.S3({accessKeyId:t.AWSACCESSKEYID,secretAccessKey:t.AWSSECRETACCESSKEY,region:t.AWSREGION}),setInterval((function(){if(!r._runningQueue&&r._sendQueue.length){r._runningQueue=!0;for(var _loop_1=function(e){var t=r._mainServer.getWS(r._sendQueue[e].id_ws);if(t&&t.readyState===t.OPEN){if(t.bufferedAmount<20480){var o=r._sendQueue.pop();t.send(JSON.stringify(o.data),(function(e){e&&(console.log("Error on WS: ",e),r._mainServer.unsubscribeWS(t))})),"reportBuilderGetResults"!==o.method&&"reportBuilderGetDistinctValue"!==o.method&&"reportBuilderBuildTree"!==o.method&&"generatePDF"!==o.method&&"getWOOfflineData"!==o.method&&"countQuery"!==o.method&&"countWithQuery"!==o.method&&"countCollectionWithQuery"!==o.method&&"find"!==o.method&&"findOne"!==o.method&&"findWithOptions"!==o.method&&"setWSAppVersion"!==o.method&&"uploadFileAndSave"!==o.method&&"getDrivers"!==o.method&&log_collection_1.Logs.insertOne({_id:mongo_manager_1.objectIdHexString(),type:"client-response",collection:"",id_document:"",payload:common_1.getBinarySize(JSON.stringify([o.methodData,o.data]))<2e5?JSON.stringify([o.methodData,o.data],null,2):"Too Big",method:o.method,id_user:t.id_user||"",user:t.user||"",messageId:o.data.messageId,route:""}),method_response_collection_1.MethodResponses.create({_id:mongo_manager_1.objectIdHexString(),__v:0,id_user:t.id_user,message_id:o.data.messageId,response:common_1.getBinarySize(JSON.stringify(o.data))<2e5?o.data:{error:"Too Big"},method:o.method,date:o.date})}}else r._sendQueue.splice(e,1)},e=r._sendQueue.length-1;e>=0;e--)_loop_1(e);r._runningQueue=!1}}),10)}return MethodManager.prototype.getMainServer=function(){return this._mainServer},MethodManager.prototype.methods=function(e){this._methods=Object.assign(this._methods,e)},MethodManager.prototype.callMethodCron=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this;if(!n._methods[e])return console.log("No Method: "+e),void n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+n.serverConfig.CLIENT_NAME,"No Method: "+e);if((o.length>1||o[0])&&!n._methods[e].skipValidation){if(!n._methods[e].check)return console.error("No Check Function For Method "+e),void n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+n.serverConfig.CLIENT_NAME,"No Check Function For Method "+e);if(!n._methods[e].check._schema)return console.error("No Check Schema For Method "+e),void n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+n.serverConfig.CLIENT_NAME,"No Check Function For Method "+e);for(var i={},s=Object.keys(n._methods[e].check._schema),a=s.filter((function(e){return!e.includes(".")})),d=0;d<o.length;d++)i[a[d]]=o[d];try{n._methods[e].check.validate(i)}catch(t){if(t)return console.error("Error in Method Check ("+e+")",t),void n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+n.serverConfig.CLIENT_NAME,"Match Error On Method "+e+"\n\nData Being Checked\n"+JSON.stringify(i,null,2)+"\n\nErrors\n"+JSON.stringify(t,null,2))}}(t=n._methods[e].function).call.apply(t,__spreadArrays([Object.assign({},n,MethodManager.prototype,{id_user:"",user:"",id_ws:""})],o)).catch((function(t){n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+n.serverConfig.CLIENT_NAME,"Error Detected During Method "+e+" - (callMethodCron)\n\nData \n"+JSON.stringify(o,null,2)+"\n\nErrors\n"+JSON.stringify(t,null,2))}))},MethodManager.prototype.callMethod=function(e,t,o,r,n){for(var i,s=this,a=[],d=5;d<arguments.length;d++)a[d-5]=arguments[d];var c=this;if(!c._methods[n]){console.log("No Method: "+n),c.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+c.serverConfig.CLIENT_NAME,"No Method: "+n);var l={messageId:r,hasError:!0,data:"Internal Error"};return this.sendWS(t,o,n,a,l),void log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:e})}if((a.length>1||a[0])&&!c._methods[n].skipValidation){if(!c._methods[n].check){console.error("No Check Function For Method "+n),c.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+c.serverConfig.CLIENT_NAME,"No Check Function For Method "+n);l={messageId:r,hasError:!0,data:"Internal Error"};return this.sendWS(t,o,n,a,l),void log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:e})}if(!c._methods[n].check._schema){console.error("No Check Schema For Method "+n),c.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+c.serverConfig.CLIENT_NAME,"No Check Function For Method "+n);l={messageId:r,hasError:!0,data:"Internal Error"};return log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:e}),void this.sendWS(t,o,n,a,l)}for(var h={},u=Object.keys(c._methods[n].check._schema),_=u.filter((function(e){return!e.includes(".")})),m=0;m<a.length;m++)h[_[m]]=a[m];try{c._methods[n].check.validate(h)}catch(i){if(i){console.error("Error in Method Check ("+n+")",i),c.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+c.serverConfig.CLIENT_NAME,"Match Error On Method "+n+"\n\nData Being Checked\n"+JSON.stringify(h,null,2)+"\n\nErrors\n"+JSON.stringify(i,null,2));l={messageId:r,hasError:!0,data:"Internal Error"};return this.sendWS(t,o,n,a,l),void log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:e})}}}(i=c._methods[n].function).call.apply(i,__spreadArrays([Object.assign({},c,MethodManager.prototype,{id_user:t.id_user,user:t.user,id_ws:t.id_socket})],a)).catch((function(e){c.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+c.serverConfig.CLIENT_NAME,"Error Detected During Method "+n+" - (callMethod)\n\nData \n"+JSON.stringify(a,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))})).then((function(i){return __awaiter(s,void 0,void 0,(function(){var s,d;return __generator(this,(function(c){switch(c.label){case 0:return s={messageId:r,hasError:!1,data:i},this.sendWS(t,o,n,a,s),[4,log_method_latency_collection_1.LogMethodLatencies.findById(e)];case 1:return(d=c.sent())&&log_method_latency_collection_1.LogMethodLatencies.updateOne({_id:e},{$set:{date_end:new Date,latency_ms:moment().diff(moment(d.date_start),"milliseconds",!0)}}),[2]}}))}))}),(function(i){var d={messageId:r,hasError:!0,data:i};s.sendWS(t,o,n,a,d),log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:e})}))},MethodManager.prototype.callMethodInternal=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this;if(!n._methods[e])return console.log("No Method: "+e),null;if((o.length>1||o[0]&&"function"!=typeof o[0])&&!n._methods[e].skipValidation){if(!n._methods[e].check)return console.error("No Check Function For Method "+e),null;if(!n._methods[e].check._schema)return console.error("No Check Schema For Method "+e),null}"insertSubscriptionLog"!==e&&log_collection_1.Logs.insertOne({_id:mongo_manager_1.objectIdHexString(),type:"callMethodInternal",collection:"",id_document:"",payload:common_1.getBinarySize(JSON.stringify([o]))<2e5?JSON.stringify([o],null,2):"Too Big",method:e,id_user:this.id_user||"",user:this.user||"",messageId:0,route:""});var i=(t=n._methods[e].function).call.apply(t,__spreadArrays([Object.assign({},n,MethodManager.prototype)],o)).catch((function(t){n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+n.serverConfig.CLIENT_NAME,"Error Detected During Method "+e+" - (callMethodInternal)\n\nData \n"+JSON.stringify(o,null,2)+"\n\nErrors\n"+JSON.stringify(t,null,2))}));return o[o.length-1]&&"function"==typeof o[o.length-1]&&i.then((function(e){return o[o.length-1](null,e)}),(function(e){return o[o.length-1](e,null)})),i},MethodManager.prototype.sendWS=function(e,t,o,r,n){this._sendQueue.splice(0,0,{id_ws:e.id_socket,method:o,methodData:r,data:n,date:t})},MethodManager.prototype.sendEmail=function(e,t,o,r,n,i){var s=this;return new Promise((function(a,d){return __awaiter(s,void 0,void 0,(function(){var s=this;return __generator(this,(function(d){return!this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/dev\./))&&!this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/www\.dev\./))&&"http://localhost:4200"!==this.serverConfig.ROOT_URL||e.match(new RegExp(/\@resolveio\.com/))||(e="dev@resolveio.com"),e&&("http://localhost:4200"!==this.serverConfig.ROOT_URL?this._mailer.sendMail({replyTo:void 0,from:i||this.serverConfig.MAIL_FROM,to:e,subject:(this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/dev\./))||this.serverConfig.ROOT_URL.match(new RegExp(/https\:\/\/www\.dev\./))?"(DEV SERVER) - ":"")+t,text:o,html:r,attachments:n},(function(t,o){t?(console.log(t),email_history_collection_1.EmailHistories.create({_id:mongo_manager_1.objectIdHexString(),__v:0,date:new Date,id_user:s.id_user||"",user:s.user||"",email:e,success:!1,verified:!1})):email_history_collection_1.EmailHistories.create({_id:mongo_manager_1.objectIdHexString(),__v:0,date:new Date,id_user:s.id_user||"",user:s.user||"",email:e,success:!0,verified:!1})})):console.log("Send email",e,t,o,r,n,i),a(!0)),[2]}))}))}))},MethodManager.prototype.getAWS=function(){return this._aws},MethodManager.prototype.readFile=function(e){var t=this;return new Promise((function(o,r){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"utf-8",(function(e,t){e?r(e):o(t)})):fs.existsSync(path.join(t.clientDir,"./private/"+e))&&fs.readFile(path.join(t.clientDir,"./private/"+e),"utf-8",(function(e,t){e?r(e):o(t)}))}))},MethodManager.prototype.readImage=function(e){var t=this;return new Promise((function(o,r){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"base64",(function(e,t){e?r(e):o(t)})):fs.existsSync(path.join(t.clientDir,"./private/"+e))&&fs.readFile(path.join(t.clientDir,"./private/"+e),"base64",(function(e,t){e?r(e):o(t)}))}))},MethodManager}();exports.MethodManager=MethodManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
39
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
40
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
41
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
42
|
+
r[k] = a[j];
|
|
43
|
+
return r;
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.MethodManager = void 0;
|
|
47
|
+
var collections_1 = require("../methods/collections");
|
|
48
|
+
var logs_1 = require("../methods/logs");
|
|
49
|
+
var counters_1 = require("../methods/counters");
|
|
50
|
+
var pdf_1 = require("../methods/pdf");
|
|
51
|
+
var aws_1 = require("../methods/aws");
|
|
52
|
+
var cloudconvert_1 = require("../methods/cloudconvert");
|
|
53
|
+
var path = require("path");
|
|
54
|
+
var fs = require("fs");
|
|
55
|
+
var nodemailer = require("nodemailer");
|
|
56
|
+
var aws = require("aws-sdk");
|
|
57
|
+
var accounts_1 = require("../methods/accounts");
|
|
58
|
+
var init_1 = require("../fixtures/init");
|
|
59
|
+
var cron_jobs_1 = require("../fixtures/cron-jobs");
|
|
60
|
+
var cron_jobs_2 = require("../methods/cron-jobs");
|
|
61
|
+
var flags_1 = require("../methods/flags");
|
|
62
|
+
var method_response_collection_1 = require("../collections/method-response.collection");
|
|
63
|
+
var common_1 = require("../util/common");
|
|
64
|
+
var log_collection_1 = require("../collections/log.collection");
|
|
65
|
+
var log_method_latency_collection_1 = require("../collections/log-method-latency.collection");
|
|
66
|
+
var moment = require("moment");
|
|
67
|
+
var report_builder_1 = require("../methods/report-builder");
|
|
68
|
+
var support_1 = require("../methods/support");
|
|
69
|
+
var monitor_1 = require("../methods/monitor");
|
|
70
|
+
var email_history_collection_1 = require("../collections/email-history.collection");
|
|
71
|
+
var mongo_manager_1 = require("./mongo.manager");
|
|
72
|
+
var Verifier = require('email-verifier');
|
|
73
|
+
var MethodManager = /** @class */ (function () {
|
|
74
|
+
function MethodManager(mainServer, serverConfig, clientDir) {
|
|
75
|
+
var _this = this;
|
|
76
|
+
this._methods = {};
|
|
77
|
+
this._sendQueue = [];
|
|
78
|
+
this._runningQueue = false;
|
|
79
|
+
this._mainServer = mainServer;
|
|
80
|
+
this.serverConfig = serverConfig;
|
|
81
|
+
this.clientDir = clientDir;
|
|
82
|
+
// Fixtures
|
|
83
|
+
init_1.loadServerInit();
|
|
84
|
+
cron_jobs_1.loadServerCronJobs();
|
|
85
|
+
// Methods
|
|
86
|
+
accounts_1.loadAccountMethods(this);
|
|
87
|
+
aws_1.loadAWSMethods(this);
|
|
88
|
+
cloudconvert_1.loadCloudConvertMethods(this);
|
|
89
|
+
collections_1.loadCollectionMethods(this);
|
|
90
|
+
counters_1.loadCounterMethods(this);
|
|
91
|
+
logs_1.loadLogMethods(this);
|
|
92
|
+
pdf_1.loadPDFMethods(this);
|
|
93
|
+
cron_jobs_2.loadCronJobMethods(this);
|
|
94
|
+
flags_1.loadFlagMethods(this);
|
|
95
|
+
report_builder_1.loadReportBuilderMethods(this);
|
|
96
|
+
support_1.loadSupportMethods(this);
|
|
97
|
+
monitor_1.loadMonitorMethods(this);
|
|
98
|
+
if (mainServer.sesMail) {
|
|
99
|
+
this._mailer = nodemailer.createTransport({
|
|
100
|
+
SES: new aws.SES({
|
|
101
|
+
apiVersion: '2010-12-01',
|
|
102
|
+
accessKeyId: serverConfig.AWSACCESSKEYID,
|
|
103
|
+
secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
|
|
104
|
+
region: serverConfig.AWSSES_REGION
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this._mailer = nodemailer.createTransport({
|
|
110
|
+
host: this.serverConfig['MAIL_HOST'],
|
|
111
|
+
port: this.serverConfig['MAIL_PORT'],
|
|
112
|
+
secure: false,
|
|
113
|
+
auth: {
|
|
114
|
+
user: this.serverConfig['MAIL_USERNAME'],
|
|
115
|
+
pass: this.serverConfig['MAIL_PASSWORD']
|
|
116
|
+
},
|
|
117
|
+
tls: {
|
|
118
|
+
ciphers: 'SSLv3'
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// this._imap = new imap({
|
|
123
|
+
// user: this.serverConfig['ORDERS_EMAIL'],
|
|
124
|
+
// password: this.serverConfig['ORDERS_PASSWORD'],
|
|
125
|
+
// host: this.serverConfig['ORDERS_HOST'],
|
|
126
|
+
// port: this.serverConfig['ORDERS_PORT'],
|
|
127
|
+
// tls: this.serverConfig['ORDERS_TLS']
|
|
128
|
+
// });
|
|
129
|
+
// let that = this;
|
|
130
|
+
// let chemicalNames = await Chemicals.find({}).select('description');
|
|
131
|
+
// let jobNames = await Jobs.find({status: 'Active'}).select('well');
|
|
132
|
+
// console.log(jobNames.map(a => a.well));
|
|
133
|
+
// this._imap.once('ready', () => {
|
|
134
|
+
// this._imap.openBox('INBOX', true, function(err, box) {
|
|
135
|
+
// if (err) {
|
|
136
|
+
// throw err;
|
|
137
|
+
// }
|
|
138
|
+
// that._imap.search([ 'NEW' ], function(err, results) {
|
|
139
|
+
// console.log(err, results);
|
|
140
|
+
// if (err || !results.length) {
|
|
141
|
+
// return that._imap.end();
|
|
142
|
+
// }
|
|
143
|
+
// let f = that._imap.fetch(results[0], { bodies: ['HEADER.FIELDS (FROM)', 'TEXT'] });
|
|
144
|
+
// f.on('message', function(msg, seqno) {
|
|
145
|
+
// // console.log('Message #%d', seqno);
|
|
146
|
+
// let prefix = '(#' + seqno + ') ';
|
|
147
|
+
// msg.on('body', function(stream, info) {
|
|
148
|
+
// let buffer = '', count = 0;
|
|
149
|
+
// stream.on('data', function(chunk) {
|
|
150
|
+
// count += chunk.length;
|
|
151
|
+
// buffer += chunk.toString('utf8');
|
|
152
|
+
// });
|
|
153
|
+
// stream.once('end', function() {
|
|
154
|
+
// if (info.which === 'TEXT') {
|
|
155
|
+
// // console.log(buffer);
|
|
156
|
+
// // console.log(typeof(buffer));
|
|
157
|
+
// let lines = buffer.split('\r\n');
|
|
158
|
+
// // console.log(lines);
|
|
159
|
+
// // let i = 0;
|
|
160
|
+
// // lines.forEach(line => {
|
|
161
|
+
// // let date: Date;
|
|
162
|
+
// // let dateString;
|
|
163
|
+
// // if (line.includes('From')) {
|
|
164
|
+
// // console.log(line);
|
|
165
|
+
// // }
|
|
166
|
+
// // if (!line.includes('class=3D') && !line.includes('style=3D')) {
|
|
167
|
+
// // if (line.includes('Well') || line.includes('Well Name') || line.includes('Job') || line.includes('Pad')) {
|
|
168
|
+
// // let best = stringSimilarity.findBestMatch(line, jobNames.map(a => a.well)).bestMatch;
|
|
169
|
+
// // if (best && best.rating > 0.5) {
|
|
170
|
+
// // console.log('Well', line);
|
|
171
|
+
// // }
|
|
172
|
+
// // }
|
|
173
|
+
// // if (line.includes('Product') || line.includes('Chemical')) {
|
|
174
|
+
// // let best = stringSimilarity.findBestMatch(line, chemicalNames.map(a => a.description)).bestMatch;
|
|
175
|
+
// // if (best && best.rating > 0.5) {
|
|
176
|
+
// // console.log('Chemical', line);
|
|
177
|
+
// // }
|
|
178
|
+
// // }
|
|
179
|
+
// // if (line.includes('Quantity') || line.includes('Qty') || line.includes('Amount')) {
|
|
180
|
+
// // console.log('Qty', line);
|
|
181
|
+
// // }
|
|
182
|
+
// // if (line.includes('Date')) {
|
|
183
|
+
// // console.log('Date', line);
|
|
184
|
+
// // console.log(moment(Date.parse(line)));
|
|
185
|
+
// // date = moment(Date.parse(line)).toDate();
|
|
186
|
+
// // dateString = line;
|
|
187
|
+
// // }
|
|
188
|
+
// // if (line.includes('Time')) {
|
|
189
|
+
// // console.log('Time', line);
|
|
190
|
+
// // console.log(moment(Date.parse(line)));
|
|
191
|
+
// // console.log(moment(date.setTime(Date.parse(line))));
|
|
192
|
+
// // }
|
|
193
|
+
// // }
|
|
194
|
+
// // });
|
|
195
|
+
// }
|
|
196
|
+
// });
|
|
197
|
+
// });
|
|
198
|
+
// msg.once('attributes', function(attrs) {
|
|
199
|
+
// console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
|
|
200
|
+
// });
|
|
201
|
+
// msg.once('end', function() {
|
|
202
|
+
// console.log(prefix + 'Finished');
|
|
203
|
+
// });
|
|
204
|
+
// });
|
|
205
|
+
// f.once('error', function(error) {
|
|
206
|
+
// console.log('Fetch error: ' + error);
|
|
207
|
+
// });
|
|
208
|
+
// f.once('end', function() {
|
|
209
|
+
// console.log('Done fetching all messages!');
|
|
210
|
+
// that._imap.end();
|
|
211
|
+
// });
|
|
212
|
+
// });
|
|
213
|
+
// });
|
|
214
|
+
// });
|
|
215
|
+
// this._imap.connect();
|
|
216
|
+
this._aws = new aws.S3({
|
|
217
|
+
accessKeyId: serverConfig.AWSACCESSKEYID,
|
|
218
|
+
secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
|
|
219
|
+
region: serverConfig.AWSREGION
|
|
220
|
+
});
|
|
221
|
+
setInterval(function () {
|
|
222
|
+
if (!_this._runningQueue) {
|
|
223
|
+
if (_this._sendQueue.length) {
|
|
224
|
+
_this._runningQueue = true;
|
|
225
|
+
var _loop_1 = function (i) {
|
|
226
|
+
var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
|
|
227
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
228
|
+
if (ws.bufferedAmount < 20480) {
|
|
229
|
+
var sendItem = _this._sendQueue.pop();
|
|
230
|
+
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
231
|
+
if (error) {
|
|
232
|
+
console.log('Error on WS: ', error);
|
|
233
|
+
_this._mainServer.unsubscribeWS(ws);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
if (sendItem.method !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {
|
|
237
|
+
log_collection_1.Logs.insertOne({
|
|
238
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
239
|
+
type: 'client-response',
|
|
240
|
+
collection: '',
|
|
241
|
+
id_document: '',
|
|
242
|
+
payload: common_1.getBinarySize(JSON.stringify([sendItem.methodData, sendItem.data])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.data], null, 2) : 'Too Big',
|
|
243
|
+
method: sendItem.method,
|
|
244
|
+
id_user: ws['id_user'] || '',
|
|
245
|
+
user: ws['user'] || '',
|
|
246
|
+
messageId: sendItem.data.messageId,
|
|
247
|
+
route: ''
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
method_response_collection_1.MethodResponses.create({
|
|
251
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
252
|
+
__v: 0,
|
|
253
|
+
id_user: ws['id_user'],
|
|
254
|
+
message_id: sendItem.data.messageId,
|
|
255
|
+
response: common_1.getBinarySize(JSON.stringify(sendItem.data)) < 200000 ? sendItem.data : { error: 'Too Big' },
|
|
256
|
+
method: sendItem.method,
|
|
257
|
+
date: sendItem.date
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
_this._sendQueue.splice(i, 1);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
266
|
+
_loop_1(i);
|
|
267
|
+
}
|
|
268
|
+
_this._runningQueue = false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}, 10);
|
|
272
|
+
}
|
|
273
|
+
MethodManager.prototype.getMainServer = function () {
|
|
274
|
+
return this._mainServer;
|
|
275
|
+
};
|
|
276
|
+
// Add methods to private methods object
|
|
277
|
+
MethodManager.prototype.methods = function (method) {
|
|
278
|
+
this._methods = Object.assign(this._methods, method);
|
|
279
|
+
};
|
|
280
|
+
MethodManager.prototype.callMethodCron = function (method) {
|
|
281
|
+
var _a;
|
|
282
|
+
var methodData = [];
|
|
283
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
284
|
+
methodData[_i - 1] = arguments[_i];
|
|
285
|
+
}
|
|
286
|
+
var that = this;
|
|
287
|
+
if (!that._methods[method]) {
|
|
288
|
+
console.log('No Method: ' + method);
|
|
289
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + method);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if ((methodData.length > 1 || methodData[0]) && !that._methods[method].skipValidation) {
|
|
293
|
+
if (!that._methods[method].check) {
|
|
294
|
+
console.error('No Check Function For Method ' + method);
|
|
295
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
else if (!that._methods[method].check._schema) {
|
|
299
|
+
console.error('No Check Schema For Method ' + method);
|
|
300
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
var valObj = {};
|
|
305
|
+
var valKeys = Object.keys(that._methods[method].check._schema);
|
|
306
|
+
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
307
|
+
for (var i = 0; i < methodData.length; i++) {
|
|
308
|
+
valObj[rootKeys[i]] = methodData[i];
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
that._methods[method].check.validate(valObj);
|
|
312
|
+
}
|
|
313
|
+
catch (errors) {
|
|
314
|
+
if (errors) {
|
|
315
|
+
console.error('Error in Method Check (' + method + ')', errors);
|
|
316
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
(_a = that._methods[method].function).call.apply(_a, __spreadArrays([Object.assign({}, that, MethodManager.prototype, { id_user: '', user: '', id_ws: '' })], methodData)).catch(function (methodErrs) {
|
|
323
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Error Detected During Method ' + method + ' - (callMethodCron)\n\nData \n' + JSON.stringify(methodData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
// Call/run method (Emit on Socket)
|
|
327
|
+
MethodManager.prototype.callMethod = function (id_methodLatency, ws, messageDate, messageId, method) {
|
|
328
|
+
var _a;
|
|
329
|
+
var _this = this;
|
|
330
|
+
var methodData = [];
|
|
331
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
|
332
|
+
methodData[_i - 5] = arguments[_i];
|
|
333
|
+
}
|
|
334
|
+
var that = this;
|
|
335
|
+
if (!that._methods[method]) {
|
|
336
|
+
console.log('No Method: ' + method);
|
|
337
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + method);
|
|
338
|
+
var serverRes = {
|
|
339
|
+
messageId: messageId,
|
|
340
|
+
hasError: true,
|
|
341
|
+
data: 'Internal Error'
|
|
342
|
+
};
|
|
343
|
+
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
344
|
+
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if ((methodData.length > 1 || methodData[0]) && !that._methods[method].skipValidation) {
|
|
348
|
+
if (!that._methods[method].check) {
|
|
349
|
+
console.error('No Check Function For Method ' + method);
|
|
350
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
351
|
+
var serverRes = {
|
|
352
|
+
messageId: messageId,
|
|
353
|
+
hasError: true,
|
|
354
|
+
data: 'Internal Error'
|
|
355
|
+
};
|
|
356
|
+
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
357
|
+
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
else if (!that._methods[method].check._schema) {
|
|
361
|
+
console.error('No Check Schema For Method ' + method);
|
|
362
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + method);
|
|
363
|
+
var serverRes = {
|
|
364
|
+
messageId: messageId,
|
|
365
|
+
hasError: true,
|
|
366
|
+
data: 'Internal Error'
|
|
367
|
+
};
|
|
368
|
+
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
369
|
+
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
var valObj = {};
|
|
374
|
+
var valKeys = Object.keys(that._methods[method].check._schema);
|
|
375
|
+
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
376
|
+
for (var i = 0; i < methodData.length; i++) {
|
|
377
|
+
valObj[rootKeys[i]] = methodData[i];
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
that._methods[method].check.validate(valObj);
|
|
381
|
+
}
|
|
382
|
+
catch (errors) {
|
|
383
|
+
if (errors) {
|
|
384
|
+
console.error('Error in Method Check (' + method + ')', errors);
|
|
385
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
386
|
+
var serverRes = {
|
|
387
|
+
messageId: messageId,
|
|
388
|
+
hasError: true,
|
|
389
|
+
data: 'Internal Error'
|
|
390
|
+
};
|
|
391
|
+
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
392
|
+
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
(_a = that._methods[method].function).call.apply(_a, __spreadArrays([Object.assign({}, that, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })], methodData)).catch(function (methodErrs) {
|
|
399
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Error Detected During Method ' + method + ' - (callMethod)\n\nData \n' + JSON.stringify(methodData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
400
|
+
})
|
|
401
|
+
.then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
402
|
+
var serverRes, latency;
|
|
403
|
+
return __generator(this, function (_a) {
|
|
404
|
+
switch (_a.label) {
|
|
405
|
+
case 0:
|
|
406
|
+
serverRes = {
|
|
407
|
+
messageId: messageId,
|
|
408
|
+
hasError: false,
|
|
409
|
+
data: res
|
|
410
|
+
};
|
|
411
|
+
this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
412
|
+
return [4 /*yield*/, log_method_latency_collection_1.LogMethodLatencies.findById(id_methodLatency)];
|
|
413
|
+
case 1:
|
|
414
|
+
latency = _a.sent();
|
|
415
|
+
if (latency) {
|
|
416
|
+
log_method_latency_collection_1.LogMethodLatencies.updateOne({ _id: id_methodLatency }, { $set: { date_end: new Date(), latency_ms: moment().diff(moment(latency.date_start), 'milliseconds', true) } });
|
|
417
|
+
}
|
|
418
|
+
return [2 /*return*/];
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}); }, function (err) {
|
|
422
|
+
var serverRes = {
|
|
423
|
+
messageId: messageId,
|
|
424
|
+
hasError: true,
|
|
425
|
+
data: err
|
|
426
|
+
};
|
|
427
|
+
_this.sendWS(ws, messageDate, method, methodData, serverRes);
|
|
428
|
+
log_method_latency_collection_1.LogMethodLatencies.deleteOne({ _id: id_methodLatency });
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
// Call/run method internal (No Emit on Socket)
|
|
432
|
+
MethodManager.prototype.callMethodInternal = function (method) {
|
|
433
|
+
var _a;
|
|
434
|
+
var methodData = [];
|
|
435
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
436
|
+
methodData[_i - 1] = arguments[_i];
|
|
437
|
+
}
|
|
438
|
+
var that = this;
|
|
439
|
+
if (!that._methods[method]) {
|
|
440
|
+
console.log('No Method: ' + method);
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !that._methods[method].skipValidation) {
|
|
444
|
+
if (!that._methods[method].check) {
|
|
445
|
+
console.error('No Check Function For Method ' + method);
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
else if (!that._methods[method].check._schema) {
|
|
449
|
+
console.error('No Check Schema For Method ' + method);
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (method !== 'insertSubscriptionLog') {
|
|
454
|
+
log_collection_1.Logs.insertOne({
|
|
455
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
456
|
+
type: 'callMethodInternal',
|
|
457
|
+
collection: '',
|
|
458
|
+
id_document: '',
|
|
459
|
+
payload: common_1.getBinarySize(JSON.stringify([methodData])) < 200000 ? JSON.stringify([methodData], null, 2) : 'Too Big',
|
|
460
|
+
method: method,
|
|
461
|
+
id_user: this['id_user'] || '',
|
|
462
|
+
user: this['user'] || '',
|
|
463
|
+
messageId: 0,
|
|
464
|
+
route: ''
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
var promise = (_a = that._methods[method].function).call.apply(_a, __spreadArrays([Object.assign({}, that, MethodManager.prototype)], methodData)).catch(function (methodErrs) {
|
|
468
|
+
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Error Detected During Method ' + method + ' - (callMethodInternal)\n\nData \n' + JSON.stringify(methodData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
469
|
+
});
|
|
470
|
+
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
471
|
+
promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
|
|
472
|
+
}
|
|
473
|
+
return promise;
|
|
474
|
+
};
|
|
475
|
+
MethodManager.prototype.sendWS = function (ws, messageDate, method, methodData, data) {
|
|
476
|
+
this._sendQueue.splice(0, 0, {
|
|
477
|
+
id_ws: ws['id_socket'],
|
|
478
|
+
method: method,
|
|
479
|
+
methodData: methodData,
|
|
480
|
+
data: data,
|
|
481
|
+
date: messageDate
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
MethodManager.prototype.sendEmail = function (sendTo, subject, text, html, attachments, send_from) {
|
|
485
|
+
var _this = this;
|
|
486
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
487
|
+
var _this = this;
|
|
488
|
+
return __generator(this, function (_a) {
|
|
489
|
+
if ((this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/dev\./)) || this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/www\.dev\./)) || this.serverConfig['ROOT_URL'] === 'http://localhost:4200') && !sendTo.match(new RegExp(/\@resolveio\.com/))) {
|
|
490
|
+
sendTo = 'dev@resolveio.com';
|
|
491
|
+
}
|
|
492
|
+
if (sendTo) {
|
|
493
|
+
if (this.serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
|
|
494
|
+
this._mailer.sendMail({
|
|
495
|
+
replyTo: undefined,
|
|
496
|
+
from: send_from ? send_from : this.serverConfig.MAIL_FROM,
|
|
497
|
+
to: sendTo,
|
|
498
|
+
subject: (this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/dev\./)) || this.serverConfig['ROOT_URL'].match(new RegExp(/https\:\/\/www\.dev\./)) ? '(DEV SERVER) - ' : '') + subject,
|
|
499
|
+
text: text,
|
|
500
|
+
html: html,
|
|
501
|
+
attachments: attachments
|
|
502
|
+
}, function (err, info) {
|
|
503
|
+
if (err) {
|
|
504
|
+
console.log(err);
|
|
505
|
+
email_history_collection_1.EmailHistories.create({
|
|
506
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
507
|
+
__v: 0,
|
|
508
|
+
date: new Date(),
|
|
509
|
+
id_user: _this['id_user'] || '',
|
|
510
|
+
user: _this['user'] || '',
|
|
511
|
+
email: sendTo,
|
|
512
|
+
success: false,
|
|
513
|
+
verified: false
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
email_history_collection_1.EmailHistories.create({
|
|
518
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
519
|
+
__v: 0,
|
|
520
|
+
date: new Date(),
|
|
521
|
+
id_user: _this['id_user'] || '',
|
|
522
|
+
user: _this['user'] || '',
|
|
523
|
+
email: sendTo,
|
|
524
|
+
success: true,
|
|
525
|
+
verified: false
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
console.log('Send email', sendTo, subject, text, html, attachments, send_from);
|
|
532
|
+
}
|
|
533
|
+
resolve(true);
|
|
534
|
+
}
|
|
535
|
+
return [2 /*return*/];
|
|
536
|
+
});
|
|
537
|
+
}); });
|
|
538
|
+
};
|
|
539
|
+
MethodManager.prototype.getAWS = function () {
|
|
540
|
+
return this._aws;
|
|
541
|
+
};
|
|
542
|
+
MethodManager.prototype.readFile = function (fileName) {
|
|
543
|
+
var _this = this;
|
|
544
|
+
return new Promise(function (resolve, reject) {
|
|
545
|
+
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
546
|
+
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
|
|
547
|
+
if (err) {
|
|
548
|
+
reject(err);
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
resolve(res);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
557
|
+
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'utf-8', function (err, res) {
|
|
558
|
+
if (err) {
|
|
559
|
+
reject(err);
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
resolve(res);
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
MethodManager.prototype.readImage = function (fileName) {
|
|
570
|
+
var _this = this;
|
|
571
|
+
return new Promise(function (resolve, reject) {
|
|
572
|
+
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
573
|
+
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
|
|
574
|
+
if (err) {
|
|
575
|
+
reject(err);
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
resolve(res);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
584
|
+
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'base64', function (err, res) {
|
|
585
|
+
if (err) {
|
|
586
|
+
reject(err);
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
resolve(res);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
};
|
|
596
|
+
return MethodManager;
|
|
597
|
+
}());
|
|
598
|
+
exports.MethodManager = MethodManager;
|
|
599
|
+
|
|
2
600
|
//# sourceMappingURL=method.manager.js.map
|