@resolveio/server-lib 20.5.12 → 20.5.14
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/collections/log-method-latency.collection.js +1 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +1 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +1 -1
- package/collections/log.collection.js.map +1 -1
- package/managers/local-log.manager.d.ts +0 -1
- package/managers/local-log.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/methods/logs.js +1 -1
- package/methods/logs.js.map +1 -1
- package/models/log-method-latency.model.d.ts +2 -0
- package/models/log-subscription.model.d.ts +2 -0
- package/models/log.model.d.ts +2 -0
- package/package.json +1 -1
- package/server-app.js +1 -1
- package/server-app.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogMethodLatencies=void 0;var resolveio_server_app_1=require("../resolveio-server-app"),mongo_manager_1=require("../managers/mongo.manager"),schema={_id:{type:String,optional:!0},__v:{type:Number,optional:!0},updatedAt:{type:Date,optional:!0},createdAt:{type:Date,optional:!0},date_start:{type:Date},date_end:{type:Date,optional:!0},latency_ms:{type:Number},method:{type:String}};function initializeCollection(){var e;resolveio_server_app_1.ResolveIOServer&&resolveio_server_app_1.ResolveIOServer.getMainDB()?(e=new mongo_manager_1.MongoManagerModel({collectionName:"log-method-latencies",schema:schema,useVersionCollection:!1,useReportBuilder:!0,reportBuilderLookupTables:[],timestamps:!0,createLogs:!1,checkSchema:!0,collectionOptions:null}),exports.LogMethodLatencies=e.collection_main,exports.LogMethodLatencies.createIndex({createdAt:1},{expireAfterSeconds:2592e3}),exports.LogMethodLatencies.createIndex({latency_ms:1}),exports.LogMethodLatencies.createIndex({method:1})):setTimeout(function(){initializeCollection()},1)}exports.LogMethodLatencies=null,initializeCollection();
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogMethodLatencies=void 0;var resolveio_server_app_1=require("../resolveio-server-app"),mongo_manager_1=require("../managers/mongo.manager"),schema={_id:{type:String,optional:!0},__v:{type:Number,optional:!0},updatedAt:{type:Date,optional:!0},createdAt:{type:Date,optional:!0},date_start:{type:Date},date_end:{type:Date,optional:!0},latency_ms:{type:Number},method:{type:String},client:{type:String},instance:{type:String}};function initializeCollection(){var e;resolveio_server_app_1.ResolveIOServer&&resolveio_server_app_1.ResolveIOServer.getMainDB()?(e=new mongo_manager_1.MongoManagerModel({collectionName:"log-method-latencies",schema:schema,useVersionCollection:!1,useReportBuilder:!0,reportBuilderLookupTables:[],timestamps:!0,createLogs:!1,checkSchema:!0,collectionOptions:null}),exports.LogMethodLatencies=e.collection_main,exports.LogMethodLatencies.createIndex({createdAt:1},{expireAfterSeconds:2592e3}),exports.LogMethodLatencies.createIndex({createdAt:-1,client:1}),exports.LogMethodLatencies.createIndex({latency_ms:1}),exports.LogMethodLatencies.createIndex({method:1})):setTimeout(function(){initializeCollection()},1)}exports.LogMethodLatencies=null,initializeCollection();
|
|
2
2
|
//# sourceMappingURL=log-method-latency.collection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/log-method-latency.collection.ts"],"names":["resolveio_server_app_1","require","mongo_manager_1","schema","_id","type","String","optional","__v","Number","updatedAt","Date","createdAt","date_start","date_end","latency_ms","method","initializeCollection","model","ResolveIOServer","getMainDB","MongoManagerModel","collectionName","useVersionCollection","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","collectionOptions","exports","LogMethodLatencies","collection_main","createIndex","expireAfterSeconds","setTimeout"],"mappings":"sGAAA,IAAAA,uBAAAC,QAAA,yBAAA,EACAC,gBAAAD,QAAA,2BAAA,EAGIE,OAAc,CACjBC,IAAK,CACJC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,IAAK,CACJH,KAAMI,OACNF,SAAU,CAAA,C,EAEXG,UAAW,CACVL,KAAMM,KACNJ,SAAU,CAAA,C,EAEXK,UAAW,CACVP,KAAMM,KACNJ,SAAU,CAAA,C,EAEXM,WAAY,CACXR,KAAMM,I,EAEPG,SAAU,CACTT,KAAMM,KACNJ,SAAU,CAAA,C,EAEXQ,WAAY,CACXV,KAAMI,M,EAEPO,OAAQ,CACPX,KAAMC,M,GAQR,
|
|
1
|
+
{"version":3,"sources":["../../src/collections/log-method-latency.collection.ts"],"names":["resolveio_server_app_1","require","mongo_manager_1","schema","_id","type","String","optional","__v","Number","updatedAt","Date","createdAt","date_start","date_end","latency_ms","method","client","instance","initializeCollection","model","ResolveIOServer","getMainDB","MongoManagerModel","collectionName","useVersionCollection","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","collectionOptions","exports","LogMethodLatencies","collection_main","createIndex","expireAfterSeconds","setTimeout"],"mappings":"sGAAA,IAAAA,uBAAAC,QAAA,yBAAA,EACAC,gBAAAD,QAAA,2BAAA,EAGIE,OAAc,CACjBC,IAAK,CACJC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,IAAK,CACJH,KAAMI,OACNF,SAAU,CAAA,C,EAEXG,UAAW,CACVL,KAAMM,KACNJ,SAAU,CAAA,C,EAEXK,UAAW,CACVP,KAAMM,KACNJ,SAAU,CAAA,C,EAEXM,WAAY,CACXR,KAAMM,I,EAEPG,SAAU,CACTT,KAAMM,KACNJ,SAAU,CAAA,C,EAEXQ,WAAY,CACXV,KAAMI,M,EAEPO,OAAQ,CACPX,KAAMC,M,EAEPW,OAAQ,CACPZ,KAAMC,M,EAEPY,SAAU,CACTb,KAAMC,M,GAQR,SAASa,uBACR,IACOC,EADHpB,uBAAAqB,iBAAmBrB,uBAAAqB,gBAAgBC,UAAS,GACzCF,EAAQ,IAAIlB,gBAAAqB,kBAAyC,CAC1DC,eAAgB,uBAChBrB,OAAQA,OACRsB,qBAAsB,CAAA,EACtBC,iBAAkB,CAAA,EAClBC,0BAA2B,GAC3BC,WAAY,CAAA,EACZC,WAAY,CAAA,EACZC,YAAa,CAAA,EACbC,kBAAmB,I,CACnB,EACDC,QAAAC,mBAAqBb,EAAMc,gBAC3BF,QAAAC,mBAAmBE,YAAY,CAACvB,UAAW,CAAC,EAAG,CAACwB,mBAAoB,MAAiB,CAAC,EACtFJ,QAAAC,mBAAmBE,YAAY,CAACvB,UAAW,CAAC,EAAGK,OAAQ,CAAC,CAAC,EACzDe,QAAAC,mBAAmBE,YAAY,CAACpB,WAAY,CAAC,CAAC,EAC9CiB,QAAAC,mBAAmBE,YAAY,CAACnB,OAAQ,CAAC,CAAC,GAG1CqB,WAAW,WACVlB,qBAAoB,CACrB,EAAG,CAAC,CAEN,CA5BWa,QAAAC,mBAAoE,KAE/Ed,qBAAoB","file":"log-method-latency.collection.js","sourcesContent":["import { ResolveIOServer } from '../resolveio-server-app';\nimport { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { LogMethodLatencyModel } from '../models/log-method-latency.model';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tdate_start: {\n\t\ttype: Date\n\t},\n\tdate_end: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tlatency_ms: {\n\t\ttype: Number\n\t},\n\tmethod: {\n\t\ttype: String\n\t},\n\tclient: {\n\t\ttype: String\n\t},\n\tinstance: {\n\t\ttype: String\n\t}\n};\n\nexport let LogMethodLatencies: MongoManagerCollection<LogMethodLatencyModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB()) {\n\t\tconst model = new MongoManagerModel<LogMethodLatencyModel>({\n\t\t\tcollectionName: 'log-method-latencies',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: true,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null\n\t\t});\n\t\tLogMethodLatencies = model.collection_main;\n\t\tLogMethodLatencies.createIndex({createdAt: 1}, {expireAfterSeconds: 60 * 60 * 24 * 30});\n\t\tLogMethodLatencies.createIndex({createdAt: -1, client: 1});\n\t\tLogMethodLatencies.createIndex({latency_ms: 1});\n\t\tLogMethodLatencies.createIndex({method: 1});\n\t}\n\telse {\n\t\tsetTimeout(() => {\n\t\t\tinitializeCollection();\n\t\t}, 1);\n\t}\n}"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogSubscriptions=void 0;var resolveio_server_app_1=require("../resolveio-server-app"),mongo_manager_1=require("../managers/mongo.manager"),schema={_id:{type:String,optional:!0},__v:{type:Number,optional:!0},updatedAt:{type:Date,optional:!0},createdAt:{type:Date,optional:!0},date:{type:Date},type:{type:String},subscription:{type:String},collection_name:{type:String},subData:{type:String}};function initializeCollection(){var e;resolveio_server_app_1.ResolveIOServer&&resolveio_server_app_1.ResolveIOServer.getMainDB()?(e=new mongo_manager_1.MongoManagerModel({collectionName:"log-subscriptions",schema:schema,useVersionCollection:!1,useReportBuilder:!0,reportBuilderLookupTables:[],timestamps:!0,createLogs:!1,checkSchema:!0,collectionOptions:null}),exports.LogSubscriptions=e.collection_main,exports.LogSubscriptions.createIndex({date:1},{expireAfterSeconds:2592e3}),exports.LogSubscriptions.createIndex({type:1}),exports.LogSubscriptions.createIndex({collection_name:1}),exports.LogSubscriptions.createIndex({date:1,type:1}),exports.LogSubscriptions.createIndex({createdAt:1})):setTimeout(function(){initializeCollection()},1)}exports.LogSubscriptions=null,initializeCollection();
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogSubscriptions=void 0;var resolveio_server_app_1=require("../resolveio-server-app"),mongo_manager_1=require("../managers/mongo.manager"),schema={_id:{type:String,optional:!0},__v:{type:Number,optional:!0},updatedAt:{type:Date,optional:!0},createdAt:{type:Date,optional:!0},date:{type:Date},type:{type:String},subscription:{type:String},collection_name:{type:String},subData:{type:String},client:{type:String},instance:{type:String}};function initializeCollection(){var e;resolveio_server_app_1.ResolveIOServer&&resolveio_server_app_1.ResolveIOServer.getMainDB()?(e=new mongo_manager_1.MongoManagerModel({collectionName:"log-subscriptions",schema:schema,useVersionCollection:!1,useReportBuilder:!0,reportBuilderLookupTables:[],timestamps:!0,createLogs:!1,checkSchema:!0,collectionOptions:null}),exports.LogSubscriptions=e.collection_main,exports.LogSubscriptions.createIndex({date:1},{expireAfterSeconds:2592e3}),exports.LogSubscriptions.createIndex({type:1}),exports.LogSubscriptions.createIndex({collection_name:1}),exports.LogSubscriptions.createIndex({date:1,type:1}),exports.LogSubscriptions.createIndex({createdAt:-1,client:1})):setTimeout(function(){initializeCollection()},1)}exports.LogSubscriptions=null,initializeCollection();
|
|
2
2
|
//# sourceMappingURL=log-subscription.collection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/log-subscription.collection.ts"],"names":["resolveio_server_app_1","require","mongo_manager_1","schema","_id","type","String","optional","__v","Number","updatedAt","Date","createdAt","date","subscription","collection_name","subData","initializeCollection","model","ResolveIOServer","getMainDB","MongoManagerModel","collectionName","useVersionCollection","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","collectionOptions","exports","LogSubscriptions","collection_main","createIndex","expireAfterSeconds","setTimeout"],"mappings":"oGAAA,IAAAA,uBAAAC,QAAA,yBAAA,EACAC,gBAAAD,QAAA,2BAAA,EAGIE,OAAc,CACjBC,IAAK,CACJC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,IAAK,CACJH,KAAMI,OACNF,SAAU,CAAA,C,EAEXG,UAAW,CACVL,KAAMM,KACNJ,SAAU,CAAA,C,EAEXK,UAAW,CACVP,KAAMM,KACNJ,SAAU,CAAA,C,EAEXM,KAAM,CACLR,KAAMM,I,EAEPN,KAAM,CACLA,KAAMC,M,EAEPQ,aAAc,CACbT,KAAMC,M,EAEPS,gBAAiB,CAChBV,KAAMC,M,EAEPU,QAAS,CACRX,KAAMC,M,GAQR,
|
|
1
|
+
{"version":3,"sources":["../../src/collections/log-subscription.collection.ts"],"names":["resolveio_server_app_1","require","mongo_manager_1","schema","_id","type","String","optional","__v","Number","updatedAt","Date","createdAt","date","subscription","collection_name","subData","client","instance","initializeCollection","model","ResolveIOServer","getMainDB","MongoManagerModel","collectionName","useVersionCollection","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","collectionOptions","exports","LogSubscriptions","collection_main","createIndex","expireAfterSeconds","setTimeout"],"mappings":"oGAAA,IAAAA,uBAAAC,QAAA,yBAAA,EACAC,gBAAAD,QAAA,2BAAA,EAGIE,OAAc,CACjBC,IAAK,CACJC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,IAAK,CACJH,KAAMI,OACNF,SAAU,CAAA,C,EAEXG,UAAW,CACVL,KAAMM,KACNJ,SAAU,CAAA,C,EAEXK,UAAW,CACVP,KAAMM,KACNJ,SAAU,CAAA,C,EAEXM,KAAM,CACLR,KAAMM,I,EAEPN,KAAM,CACLA,KAAMC,M,EAEPQ,aAAc,CACbT,KAAMC,M,EAEPS,gBAAiB,CAChBV,KAAMC,M,EAEPU,QAAS,CACRX,KAAMC,M,EAEPW,OAAQ,CACPZ,KAAMC,M,EAEPY,SAAU,CACTb,KAAMC,M,GAQR,SAASa,uBACR,IACOC,EADHpB,uBAAAqB,iBAAmBrB,uBAAAqB,gBAAgBC,UAAS,GACzCF,EAAQ,IAAIlB,gBAAAqB,kBAAwC,CACzDC,eAAgB,oBAChBrB,OAAQA,OACRsB,qBAAsB,CAAA,EACtBC,iBAAkB,CAAA,EAClBC,0BAA2B,GAC3BC,WAAY,CAAA,EACZC,WAAY,CAAA,EACZC,YAAa,CAAA,EACbC,kBAAmB,I,CACnB,EACDC,QAAAC,iBAAmBb,EAAMc,gBACzBF,QAAAC,iBAAiBE,YAAY,CAACtB,KAAM,CAAC,EAAG,CAACuB,mBAAoB,MAAiB,CAAC,EAC/EJ,QAAAC,iBAAiBE,YAAY,CAAC9B,KAAM,CAAC,CAAC,EACtC2B,QAAAC,iBAAiBE,YAAY,CAACpB,gBAAiB,CAAC,CAAC,EACjDiB,QAAAC,iBAAiBE,YAAY,CAACtB,KAAM,EAAGR,KAAM,CAAC,CAAC,EAC/C2B,QAAAC,iBAAiBE,YAAY,CAACvB,UAAW,CAAC,EAAGK,OAAQ,CAAC,CAAC,GAGvDoB,WAAW,WACVlB,qBAAoB,CACrB,EAAG,CAAC,CAEN,CA7BWa,QAAAC,iBAAiE,KAE5Ed,qBAAoB","file":"log-subscription.collection.js","sourcesContent":["import { ResolveIOServer } from '../resolveio-server-app';\nimport { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { LogSubscriptionModel } from '../models/log-subscription.model';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tdate: {\n\t\ttype: Date\n\t},\n\ttype: {\n\t\ttype: String\n\t},\n\tsubscription: {\n\t\ttype: String\n\t},\n\tcollection_name: {\n\t\ttype: String\n\t},\n\tsubData: {\n\t\ttype: String\t\n\t},\n\tclient: {\n\t\ttype: String\n\t},\n\tinstance: {\n\t\ttype: String\n\t}\n};\n\nexport let LogSubscriptions: MongoManagerCollection<LogSubscriptionModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB()) {\n\t\tconst model = new MongoManagerModel<LogSubscriptionModel>({\n\t\t\tcollectionName: 'log-subscriptions',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: true,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null\n\t\t});\n\t\tLogSubscriptions = model.collection_main;\n\t\tLogSubscriptions.createIndex({date: 1}, {expireAfterSeconds: 60 * 60 * 24 * 30});\n\t\tLogSubscriptions.createIndex({type: 1});\n\t\tLogSubscriptions.createIndex({collection_name: 1});\n\t\tLogSubscriptions.createIndex({date: 1, type: 1});\n\t\tLogSubscriptions.createIndex({createdAt: -1, client: 1});\n\t}\n\telse {\n\t\tsetTimeout(() => {\n\t\t\tinitializeCollection();\n\t\t}, 1);\n\t}\n}"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Logs=void 0;var resolveio_server_app_1=require("../resolveio-server-app"),mongo_manager_1=require("../managers/mongo.manager"),schema={_id:{type:String,optional:!0},__v:{type:Number,optional:!0},updatedAt:{type:Date,optional:!0},createdAt:{type:Date,optional:!0},type:{type:String},collection:{type:String},id_document:{type:String},payload:{type:String},method:{type:String},id_user:{type:String},user:{type:String},messageId:{type:Number},route:{type:String}};function initializeCollection(){var e;resolveio_server_app_1.ResolveIOServer&&resolveio_server_app_1.ResolveIOServer.getMainDB()?(e=new mongo_manager_1.MongoManagerModel({collectionName:"logs",schema:schema,useVersionCollection:!1,useReportBuilder:!1,reportBuilderLookupTables:[],timestamps:!0,createLogs:!1,checkSchema:!0,collectionOptions:null}),exports.Logs=e.collection_main,exports.Logs.createIndex({createdAt:1},{expireAfterSeconds:7776e3}),exports.Logs.createIndex({createdAt:-1,type:1,id_document:1})):setTimeout(function(){initializeCollection()},1)}exports.Logs=null,initializeCollection();
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Logs=void 0;var resolveio_server_app_1=require("../resolveio-server-app"),mongo_manager_1=require("../managers/mongo.manager"),schema={_id:{type:String,optional:!0},__v:{type:Number,optional:!0},updatedAt:{type:Date,optional:!0},createdAt:{type:Date,optional:!0},type:{type:String},collection:{type:String},id_document:{type:String},payload:{type:String},method:{type:String},id_user:{type:String},user:{type:String},messageId:{type:Number},route:{type:String},client:{type:String},instance:{type:String}};function initializeCollection(){var e;resolveio_server_app_1.ResolveIOServer&&resolveio_server_app_1.ResolveIOServer.getMainDB()?(e=new mongo_manager_1.MongoManagerModel({collectionName:"logs",schema:schema,useVersionCollection:!1,useReportBuilder:!1,reportBuilderLookupTables:[],timestamps:!0,createLogs:!1,checkSchema:!0,collectionOptions:null}),exports.Logs=e.collection_main,exports.Logs.createIndex({createdAt:1},{expireAfterSeconds:7776e3}),exports.Logs.createIndex({createdAt:-1,client:1,type:1,id_document:1})):setTimeout(function(){initializeCollection()},1)}exports.Logs=null,initializeCollection();
|
|
2
2
|
//# sourceMappingURL=log.collection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/log.collection.ts"],"names":["resolveio_server_app_1","require","mongo_manager_1","schema","_id","type","String","optional","__v","Number","updatedAt","Date","createdAt","collection","id_document","payload","method","id_user","user","messageId","route","initializeCollection","model","ResolveIOServer","getMainDB","MongoManagerModel","collectionName","useVersionCollection","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","collectionOptions","exports","Logs","collection_main","createIndex","expireAfterSeconds","setTimeout"],"mappings":"wFAAA,IAAAA,uBAAAC,QAAA,yBAAA,EACAC,gBAAAD,QAAA,2BAAA,EAGIE,OAAc,CACjBC,IAAK,CACJC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,IAAK,CACJH,KAAMI,OACNF,SAAU,CAAA,C,EAEXG,UAAW,CACVL,KAAMM,KACNJ,SAAU,CAAA,C,EAEXK,UAAW,CACVP,KAAMM,KACNJ,SAAU,CAAA,C,EAEXF,KAAM,CACLA,KAAMC,M,EAEPO,WAAY,CACXR,KAAMC,M,EAEPQ,YAAa,CACZT,KAAMC,M,EAEPS,QAAS,CACRV,KAAMC,M,EAEPU,OAAQ,CACPX,KAAMC,M,EAEPW,QAAS,CACRZ,KAAMC,M,EAEPY,KAAM,CACLb,KAAMC,M,EAEPa,UAAW,CACVd,KAAMI,M,EAEPW,MAAO,CACNf,KAAMC,M,GAQR,
|
|
1
|
+
{"version":3,"sources":["../../src/collections/log.collection.ts"],"names":["resolveio_server_app_1","require","mongo_manager_1","schema","_id","type","String","optional","__v","Number","updatedAt","Date","createdAt","collection","id_document","payload","method","id_user","user","messageId","route","client","instance","initializeCollection","model","ResolveIOServer","getMainDB","MongoManagerModel","collectionName","useVersionCollection","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","collectionOptions","exports","Logs","collection_main","createIndex","expireAfterSeconds","setTimeout"],"mappings":"wFAAA,IAAAA,uBAAAC,QAAA,yBAAA,EACAC,gBAAAD,QAAA,2BAAA,EAGIE,OAAc,CACjBC,IAAK,CACJC,KAAMC,OACNC,SAAU,CAAA,C,EAEXC,IAAK,CACJH,KAAMI,OACNF,SAAU,CAAA,C,EAEXG,UAAW,CACVL,KAAMM,KACNJ,SAAU,CAAA,C,EAEXK,UAAW,CACVP,KAAMM,KACNJ,SAAU,CAAA,C,EAEXF,KAAM,CACLA,KAAMC,M,EAEPO,WAAY,CACXR,KAAMC,M,EAEPQ,YAAa,CACZT,KAAMC,M,EAEPS,QAAS,CACRV,KAAMC,M,EAEPU,OAAQ,CACPX,KAAMC,M,EAEPW,QAAS,CACRZ,KAAMC,M,EAEPY,KAAM,CACLb,KAAMC,M,EAEPa,UAAW,CACVd,KAAMI,M,EAEPW,MAAO,CACNf,KAAMC,M,EAEPe,OAAQ,CACPhB,KAAMC,M,EAEPgB,SAAU,CACTjB,KAAMC,M,GAQR,SAASiB,uBACR,IACOC,EADHxB,uBAAAyB,iBAAmBzB,uBAAAyB,gBAAgBC,UAAS,GACzCF,EAAQ,IAAItB,gBAAAyB,kBAA4B,CAC7CC,eAAgB,OAChBzB,OAAQA,OACR0B,qBAAsB,CAAA,EACtBC,iBAAkB,CAAA,EAClBC,0BAA2B,GAC3BC,WAAY,CAAA,EACZC,WAAY,CAAA,EACZC,YAAa,CAAA,EACbC,kBAAmB,I,CACnB,EACDC,QAAAC,KAAOb,EAAMc,gBACbF,QAAAC,KAAKE,YAAY,CAAC3B,UAAW,CAAC,EAAG,CAAC4B,mBAAoB,MAAiB,CAAC,EACxEJ,QAAAC,KAAKE,YAAY,CAAC3B,UAAW,CAAC,EAAGS,OAAQ,EAAGhB,KAAM,EAAGS,YAAa,CAAC,CAAC,GAGpE2B,WAAW,WACVlB,qBAAoB,CACrB,EAAG,CAAC,CAEN,CA1BWa,QAAAC,KAAyC,KAEpDd,qBAAoB","file":"log.collection.js","sourcesContent":["import { ResolveIOServer } from '../resolveio-server-app';\nimport { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { LogModel } from '../models/log.model';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\ttype: {\n\t\ttype: String\n\t},\n\tcollection: {\n\t\ttype: String\n\t},\n\tid_document: {\n\t\ttype: String\n\t},\n\tpayload: {\n\t\ttype: String\n\t},\n\tmethod: {\n\t\ttype: String\n\t},\n\tid_user: {\n\t\ttype: String\n\t},\n\tuser: {\n\t\ttype: String\n\t},\n\tmessageId: {\n\t\ttype: Number\n\t},\n\troute: {\n\t\ttype: String\n\t},\n\tclient: {\n\t\ttype: String\n\t},\n\tinstance: {\n\t\ttype: String\n\t}\n};\n\nexport let Logs: MongoManagerCollection<LogModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB()) {\n\t\tconst model = new MongoManagerModel<LogModel>({\n\t\t\tcollectionName: 'logs',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: false,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null\n\t\t});\n\t\tLogs = model.collection_main;\n\t\tLogs.createIndex({createdAt: 1}, {expireAfterSeconds: 60 * 60 * 24 * 90});\n\t\tLogs.createIndex({createdAt: -1, client: 1, type: 1, id_document: 1});\n\t}\n\telse {\n\t\tsetTimeout(() => {\n\t\t\tinitializeCollection();\n\t\t}, 1);\n\t}\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/local-log.manager.ts"],"names":["fs","require","resolveio_server_app_1","LocalLogManager","ResolveIOServer","getServerConfig","existsSync","mkdirSync","this","_logFilePath","prototype","writeLog","logEntry","line","JSON","stringify","appendFileSync","encoding","err","console","error","Date","writeLogs","items","length","lines","map","item","join","offloadLogs","result","fileData","readFileSync","trim","split","filter","l","writeFileSync","exports"],"mappings":"mGAGA,IAAAA,GAAAC,QAAA,IAAA,EACAC,uBAAAD,QAAA,yBAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/managers/local-log.manager.ts"],"names":["fs","require","resolveio_server_app_1","LocalLogManager","ResolveIOServer","getServerConfig","existsSync","mkdirSync","this","_logFilePath","prototype","writeLog","logEntry","line","JSON","stringify","appendFileSync","encoding","err","console","error","Date","writeLogs","items","length","lines","map","item","join","offloadLogs","result","fileData","readFileSync","trim","split","filter","l","writeFileSync","exports"],"mappings":"mGAGA,IAAAA,GAAAC,QAAA,IAAA,EACAC,uBAAAD,QAAA,yBAAA,EAcAE,gBAAA,WAGC,SAAAA,kBAEoD,0BAAlDD,uBAAAE,gBAAgBC,gBAAe,EAAa,UACS,0BAAlDH,uBAAAE,gBAAgBC,gBAAe,EAAa,UAE1CL,GAAGM,WAAW,6BAA6B,GAC/CN,GAAGO,UAAU,6BAA6B,EAI5CC,KAAKC,aAAe,8CACrB,CAwDD,OArDQN,gBAAAO,UAAAC,SAAP,SAAgBC,GACf,IACC,IAAIC,EAAOC,KAAKC,UAAUH,CAAQ,EAAI,KACtCZ,GAAGgB,eAAeR,KAAKC,aAAcI,EAAM,CAAEI,SAAU,MAAM,CAAE,C,CAEhE,MAAMC,GAELC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,+BAAgCH,CAAG,C,CAElF,EAEOf,gBAAAO,UAAAY,UAAP,SAAiBC,GAChB,GAAKA,GAA0B,IAAjBA,EAAMC,OAIpB,IAEC,IAAIC,EAAQF,EAAMG,IAAI,SAAAC,GAAQ,OAAAb,KAAKC,UAAUY,CAAI,CAAnB,CAAoB,EAAEC,KAAK,IAAI,EAAI,KACjE5B,GAAGgB,eAAeR,KAAKC,aAAcgB,EAAO,CAAER,SAAU,MAAM,CAAE,C,CAEjE,MAAOC,GACNC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,8BAA+BH,CAAG,C,CAEjF,EAKOf,gBAAAO,UAAAmB,YAAP,WACC,IAAIC,EAAS,GAEb,IACC,GAAI,CAAC9B,GAAGM,WAAWE,KAAKC,YAAY,EACnC,OAAOqB,EAGR,IAAIC,EAAW/B,GAAGgC,aAAaxB,KAAKC,aAAc,MAAM,EACxD,GAA+B,IAA3BsB,EAASE,KAAI,EAAGT,OACnB,OAAOM,EAGRA,EAASC,EAASG,MAAM,IAAI,EAAEC,OAAO,SAAAC,GAAK,MAAa,KAAbA,EAAEH,KAAI,CAAN,CAAe,EAGzDjC,GAAGqC,cAAc7B,KAAKC,aAAc,EAAE,C,CAEvC,MAAMS,GACLC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,0BAA2BH,CAAG,C,CAG5E,OAAOY,CACR,EACD3B,eAAA,EAAC,EAtEYmC,QAAAnC,gBAAAA","file":"local-log.manager.js","sourcesContent":["/***************\nlocal-logs.manager.ts\n****************/\nimport * as fs from 'fs';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport type LocalLogType = 'monitor-mongo' \n\t| 'monitor-memory'\n\t| 'monitor-cpu'\n\t| 'log'\n\t| 'log-method-latency'\n\t| 'log-subscription';\n\nexport interface LocalLogModel {\n\ttype: LocalLogType;\n\tdata: any;\n}\n\nexport class LocalLogManager {\n\tprivate _logFilePath: string;\n\n\tconstructor() {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!fs.existsSync('/home/ubuntu/resolveio/logs')) {\n\t\t\t\tfs.mkdirSync('/home/ubuntu/resolveio/logs');\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis._logFilePath = '/home/ubuntu/resolveio/logs/local-logs.jsonl';\n\t}\n\n\t// Internal method to append a JSON line to the file\n\tpublic writeLog(logEntry: LocalLogModel): void {\n\t\ttry {\n\t\t\tlet line = JSON.stringify(logEntry) + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, line, { encoding: 'utf8' });\n\t\t}\n\t\tcatch(err) {\n\t\t\t// If there's an error writing logs, you might want to handle it or queue it\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write log to file:', err);\n\t\t}\n\t}\n\n\tpublic writeLogs(items: LocalLogModel[]): void {\n\t\tif (!items || items.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert each item to a JSON string, add newline\n\t\t\tlet lines = items.map(item => JSON.stringify(item)).join('\\n') + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, lines, { encoding: 'utf8' });\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write logs batch:', err);\n\t\t}\n\t}\n\n\t/**\n\t * Reads all logs from disk, then empties the file.\n\t */\n\tpublic offloadLogs(): any[] {\n\t\tlet result = [];\n\n\t\ttry {\n\t\t\tif (!fs.existsSync(this._logFilePath)) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tlet fileData = fs.readFileSync(this._logFilePath, 'utf8');\n\t\t\tif (fileData.trim().length === 0) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tresult = fileData.split('\\n').filter(l => l.trim() !== '');\n\n\t\t\t// Truncate the file so we don't send logs more than once\n\t\t\tfs.writeFileSync(this._logFilePath, '');\n\t\t}\n\t\tcatch(err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to offload logs:', err);\n\t\t}\n\n\t\treturn result;\n\t}\n}"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,o,n,i){return new(n=n||Promise)(function(r,t){function fulfilled(e){try{step(i.next(e))}catch(e){t(e)}}function rejected(e){try{step(i.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?r(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(fulfilled,rejected)}step((i=i.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(o,n){var i,s,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},c={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function verb(r){return function(e){var t=[r,e];if(i)throw new TypeError("Generator is already executing.");for(;l=c&&t[c=0]?0:l;)try{if(i=1,s&&(a=2&t[0]?s.return:t[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,t[1])).done)return a;switch(s=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=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(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3]))l.label=t[1];else if(6===t[0]&&l.label<a[1])l.label=a[1],a=t;else{if(!(a&&l.label<a[2])){a[2]&&l.ops.pop(),l.trys.pop();continue}l.label=a[2],l.ops.push(t)}}t=n.call(o,l)}catch(e){t=[6,e],s=0}finally{i=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},__read=this&&this.__read||function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,n,i=r.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return s},__spreadArray=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var o,n=0,i=t.length;n<i;n++)!o&&n in t||((o=o||Array.prototype.slice.call(t,0,n))[n]=t[n]);return e.concat(o||Array.prototype.slice.call(t))},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&o>=e.length?void 0:e)&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},collections_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MethodManager=exports.AWS=void 0,require("../methods/collections")),logs_1=require("../methods/logs"),counters_1=require("../methods/counters"),pdf_1=require("../methods/pdf"),aws_1=require("../methods/aws"),path=require("path"),fs=require("fs"),nodemailer=require("nodemailer"),sesTransport=require("nodemailer-ses-transport"),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"),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-timezone"),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"),client_s3_1=require("@aws-sdk/client-s3"),worker_task_request_collection_1=require("../collections/worker-task-request.collection"),worker_task_response_collection_1=require("../collections/worker-task-response.collection"),flag_updates_1=require("../methods/flag-updates"),resolveio_server_app_1=require("../resolveio-server-app"),AWS=function(){function AWS(){this._s3=null,this._s3USEast1=null}return AWS.prototype.s3=function(){return this._s3||(this._s3=new client_s3_1.S3({credentials:{accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY},region:process.env.AWS_REGION,apiVersion:"2006-03-01"})),this._s3},AWS.prototype.s3USEast1=function(){return"us-east-1"===process.env.AWS_REGION?this.s3():(this._s3USEast1||(this._s3USEast1=new client_s3_1.S3({credentials:{accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY},region:"us-east-1",apiVersion:"2006-03-01"})),this._s3USEast1)},AWS}(),MethodManager=(exports.AWS=AWS,function(){function MethodManager(e,t,r){var o=this;this._methods={},this._isWorkersEnabled=!1,this._isWorkerInstance=!1,this.emailQueue=new Set,this.isEmailProcessing=!1,this._debugCallMethodInternalHits=0,this._debugCallMethodHits=0,this._debugCallMethodCronJobHits=0,this._debugSendQueueHits=0,this.clientDir="",this.serverConfig="",this._websocketManager=resolveio_server_app_1.ResolveIOServer.getMainServer().getWebSocketManager(),this._monitorManagerFunction=e,this._isWorkersEnabled=t,this._isWorkerInstance=r,this.clientDir=resolveio_server_app_1.ResolveIOServer.getClientDir(),this.serverConfig=resolveio_server_app_1.ResolveIOServer.getServerConfig(),"false"!==process.env.IS_WORKERS_ENABLED&&("true"!==process.env.IS_WORKER_INSTANCE||"0"!==process.env.WORKER_INDEX)||process.env.NODE_APP_INSTANCE&&"0"!==process.env.NODE_APP_INSTANCE||setTimeout(function(){console.log(new Date,"Start Server Fixture"),(0,init_1.loadServerInit)(),console.log(new Date,"End Server Fixture")},5e3),(0,cron_jobs_1.loadServerCronJobs)(),(0,accounts_1.loadAccountMethods)(this),(0,aws_1.loadAWSMethods)(this),(0,collections_1.loadCollectionMethods)(this),(0,counters_1.loadCounterMethods)(this),(0,logs_1.loadLogMethods)(this),(0,pdf_1.loadPDFMethods)(this),(0,cron_jobs_2.loadCronJobMethods)(this),(0,flags_1.loadFlagMethods)(this),(0,flag_updates_1.loadFlagUpdatesMethods)(this),(0,report_builder_1.loadReportBuilderMethods)(this),(0,support_1.loadSupportMethods)(this),(0,monitor_1.loadMonitorMethods)(this),this._aws=new AWS,resolveio_server_app_1.ResolveIOServer.getSESMail()?this._mailer=nodemailer.createTransport(sesTransport({accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY,region:process.env.AWS_SES_REGION})):this._mailer=nodemailer.createTransport({host:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_HOST,port:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_PORT,secure:!1,auth:{user:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_USERNAME,pass:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_PASSWORD},tls:{ciphers:"SSLv3"}}),setInterval(function(){resolveio_server_app_1.ResolveIOServer.getMainServer().getSubscriptionManager()&&resolveio_server_app_1.ResolveIOServer.getMainServer().getSubscriptionManager().getEnableDebug()&&(console.log(new Date,"Method Manager","Send Queue Hits",o._debugSendQueueHits),console.log(new Date,"Method Manager","Call Method Internal Hits",o._debugCallMethodInternalHits),console.log(new Date,"Method Manager","Call Method Hits",o._debugCallMethodHits),console.log(new Date,"Method Manager","Call Method Cron Hits",o._debugCallMethodCronJobHits)),o._debugCallMethodInternalHits=0,o._debugCallMethodHits=0,o._debugCallMethodCronJobHits=0,o._debugSendQueueHits=0},6e4),this._isWorkersEnabled&&!this._isWorkerInstance||this.setupEmailWatcher()}return MethodManager.prototype.methods=function(e){this._methods=Object.assign(this._methods,e)},MethodManager.prototype.callMethodCron=function(t){for(var n=this,r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];if(this._debugCallMethodCronJobHits+=1,this._methods[t]){if((1<r.length||r[0])&&!this._methods[t].skipValidation){if(!this._methods[t].check)return console.error(new Date,"No Check Function For Method "+t),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Function For Method "+t);if(!this._methods[t].check._schema)return console.error(new Date,"No Check Schema For Method "+t),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Function For Method "+t);for(var o={},i=Object.keys(this._methods[t].check._schema).filter(function(e){return!e.includes(".")}),s=0;s<r.length;s++)o[i[s]]=r[s];try{this._methods[t].check.validate(o)}catch(e){if(e)return console.error(new Date,"Error in Method Check ("+t+")",e),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Match Error On Method "+t+"\n\nData Being Checked\n"+JSON.stringify(o,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))}}var a,l,c,u=null,_=JSON.stringify(r);return this._isWorkersEnabled&&!this._isWorkerInstance&&Buffer.byteLength(_,"utf8")<8388608&&"insertSubscriptionLog"!==t&&"countQuery"!==t&&"incCounter"!==t&&"supportCreateBillingUser"!==t&&"find"!==t&&"insertDocument"!==t&&"countWithQuery"!==t&&"findOne"!==t&&"updateDocumentProps"!==t&&"findWithOptions"!==t&&"getSignedUrl"!==t&&"updateDocument"!==t&&"insertErrorLog"!==t&&"getSignedUrls"!==t&&"removeDocument"!==t&&"getSignedUrlWithId"!==t&&"incorrectUser"!==t&&"reloadWS"!==t&&"reconnectWS"!==t&&"disconnectWS"!==t?(a=this._monitorManagerFunction.startMonitorFunction("Cron Method",t,"","",r),l=(0,common_1.objectIdHexString)(),u=new Promise(function(t,r){var o=worker_task_response_collection_1.WorkerTaskResponses.watchCollection([{$match:{"fullDocument.id_request":l}}],{fullDocument:"updateLookup"});o.on("change",function(e){"insert"===e.operationType&&(n._monitorManagerFunction.finishMonitorFunction(a),((e=e.fullDocument).has_error?r:t)(e.data),o.close())}),o.on("error",function(e){console.error("Error watching worker responses:",e),r(e),o.close()})}),worker_task_request_collection_1.WorkerTaskRequests.create({_id:l,method:t,params:r,status:"pending",id_user:this.id_user,user:this.user,id_ws:this.id_socket})):(c=this._monitorManagerFunction.startMonitorFunction("Cron Method",t,"","",r),u=(_=this._methods[t].function).call.apply(_,__spreadArray([Object.assign({},this,MethodManager.prototype,{id_user:"",user:"",id_ws:""})],__read(r),!1)).then(function(e){return n._monitorManagerFunction.finishMonitorFunction(c),e},function(e){return n._monitorManagerFunction.finishMonitorFunction(c),n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Error Detected During Method "+t+" - (callMethodCron)\n\nData \n"+JSON.stringify(r,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),e})),u}console.log("No Method: "+t),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Method: "+t)},MethodManager.prototype.callMethod=function(o,n,i,s,a){for(var t=this,l=[],e=5;e<arguments.length;e++)l[e-5]=arguments[e];if(this._debugCallMethodHits+=1,this._methods[a]){if((1<l.length||l[0])&&!this._methods[a].skipValidation){if(!this._methods[a].check)return console.error(new Date,"No Check Function For Method "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Function For Method "+a),this.sendWS(n,i,a,l,r={messageId:s,hasError:!0,data:"Internal Error"}),void(o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}));if(!this._methods[a].check._schema)return console.error(new Date,"No Check Schema For Method "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Schema For Method "+a),r={messageId:s,hasError:!0,data:"Internal Error"},o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}),void this.sendWS(n,i,a,l,r);for(var r,c={},u=Object.keys(this._methods[a].check._schema).filter(function(e){return!e.includes(".")}),_=0;_<l.length;_++)c[u[_]]=l[_];try{this._methods[a].check.validate(c)}catch(e){if(e)return console.error(new Date,"Error in Method Check ("+a+")",e),"processAirdropDistribution"!==a&&this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Match Error On Method "+a+"\n\nData Being Checked\n"+JSON.stringify(c,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),this.sendWS(n,i,a,l,r={messageId:s,hasError:!0,data:"Internal Error"}),void(o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}))}}var d,h,p,g=JSON.stringify(l);this._isWorkersEnabled&&!this._isWorkerInstance&&Buffer.byteLength(g,"utf8")<8388608&&"insertSubscriptionLog"!==a&&"countQuery"!==a&&"incCounter"!==a&&"supportCreateBillingUser"!==a&&"find"!==a&&"insertDocument"!==a&&"countWithQuery"!==a&&"findOne"!==a&&"updateDocumentProps"!==a&&"findWithOptions"!==a&&"getSignedUrl"!==a&&"updateDocument"!==a&&"insertErrorLog"!==a&&"getSignedUrls"!==a&&"removeDocument"!==a&&"getSignedUrlWithId"!==a&&"incorrectUser"!==a&&"reloadWS"!==a&&"reconnectWS"!==a&&"disconnectWS"!==a?(d=this._monitorManagerFunction.startMonitorFunction("Method",a,n.user||"",n.id_socket||"",l),g=(0,common_1.objectIdHexString)(),(h=worker_task_response_collection_1.WorkerTaskResponses.watchCollection([{$match:{"fullDocument.id_request":g}}],{fullDocument:"updateLookup"})).on("change",function(r){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return"insert"!==r.operationType?[3,3]:(this._monitorManagerFunction.finishMonitorFunction(d),t=r.fullDocument,t={messageId:s,hasError:t.has_error,data:t.data},this.sendWS(n,new Date,a,l,t),o?[4,log_method_latency_collection_1.LogMethodLatencies.findById(o)]:[3,2]);case 1:(t=e.sent())&&log_method_latency_collection_1.LogMethodLatencies.updateOne({_id:o},{$set:{date_end:new Date,latency_ms:moment().diff(moment(t.date_start),"milliseconds",!0)}}),e.label=2;case 2:h.close(),e.label=3;case 3:return[2]}})})}),h.on("error",function(e){console.error("Error watching worker responses:",e),h.close()}),worker_task_request_collection_1.WorkerTaskRequests.create({_id:g,method:a,params:l,status:"pending",id_user:n.id_user,user:n.user,id_ws:n.id_socket})):(p=this._monitorManagerFunction.startMonitorFunction("Method",a,n.user||"",n.id_socket||"",l),(g=this._methods[a].function).call.apply(g,__spreadArray([Object.assign({},this,MethodManager.prototype,{id_user:n.id_user,user:n.user,id_ws:n.id_socket})],__read(l),!1)).then(function(r){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return(this._monitorManagerFunction.finishMonitorFunction(p),t={messageId:s,hasError:!1,data:r},this.sendWS(n,i,a,l,t),o)?[4,log_method_latency_collection_1.LogMethodLatencies.findById(o)]:[3,2];case 1:(t=e.sent())&&log_method_latency_collection_1.LogMethodLatencies.updateOne({_id:o},{$set:{date_end:new Date,latency_ms:moment().diff(moment(t.date_start),"milliseconds",!0)}}),e.label=2;case 2:return[2]}})})},function(e){t._monitorManagerFunction.finishMonitorFunction(p),t.sendWS(n,i,a,l,{messageId:s,hasError:!0,data:e}),o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}),"processAirdropDistribution"!==a&&t.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Error Detected During Method "+a+" - (callMethod)\n\nData \n"+JSON.stringify(l,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))}))}else console.log("No Method: "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Method: "+a),r={messageId:s,hasError:!0,data:"Internal Error"},this.sendWS(n,new Date,a,l,r),o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o})},MethodManager.prototype.callMethodInternal=function(t){for(var n=this,r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];if(this._debugCallMethodInternalHits+=1,!this._methods[t])return console.log("No Method: "+t),null;if((1<r.length||r[0]&&"function"!=typeof r[0])&&!this._methods[t].skipValidation){if(!this._methods[t].check)return console.error(new Date,"No Check Function For Method "+t),null;if(!this._methods[t].check._schema)return console.error(new Date,"No Check Schema For Method "+t),null}"insertSubscriptionLog"!==t&&"getDataURIfromURL"!==t&&"processAirdropDistribution"!==t&&"incCounter"!==t&&"supportCreateBillingUser"!==t&&"countCollectionWithQuery"!==t&&log_collection_1.Logs.insertOne({_id:(0,common_1.objectIdHexString)(),type:"callMethodInternal",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([r]))<2e5?JSON.stringify([r],null,2):"Too Big",method:t,id_user:this.id_user||"",user:this.user||"",messageId:0,route:""});var i,s,o,a="function"==typeof r[r.length-1]?r.slice(0,-1):r,l=null,c=JSON.stringify(a);return this._isWorkersEnabled&&!this._isWorkerInstance&&Buffer.byteLength(c,"utf8")<8388608&&"insertSubscriptionLog"!==t&&"countQuery"!==t&&"incCounter"!==t&&"supportCreateBillingUser"!==t&&"find"!==t&&"insertDocument"!==t&&"countWithQuery"!==t&&"findOne"!==t&&"updateDocumentProps"!==t&&"findWithOptions"!==t&&"getSignedUrl"!==t&&"updateDocument"!==t&&"insertErrorLog"!==t&&"getSignedUrls"!==t&&"removeDocument"!==t&&"getSignedUrlWithId"!==t&&"incorrectUser"!==t&&"reloadWS"!==t&&"reconnectWS"!==t&&"disconnectWS"!==t?(i=this._monitorManagerFunction.startMonitorFunction("Internal Method",t,this.user||"","",a),s=(0,common_1.objectIdHexString)(),l=new Promise(function(t,r){var o=worker_task_response_collection_1.WorkerTaskResponses.watchCollection([{$match:{"fullDocument.id_request":s}}],{fullDocument:"updateLookup"});o.on("change",function(e){"insert"===e.operationType&&(n._monitorManagerFunction.finishMonitorFunction(i),((e=e.fullDocument).has_error?r:t)(e.data),o.close())}),o.on("error",function(e){console.error("Error watching worker responses:",e),r(e),o.close()})}),worker_task_request_collection_1.WorkerTaskRequests.create({_id:s,method:t,params:a,status:"pending",id_user:this.id_user,user:this.user,id_ws:this.id_socket})):(o=this._monitorManagerFunction.startMonitorFunction("Internal Method",t,this.user||"","",a),l=(c=this._methods[t].function).call.apply(c,__spreadArray([Object.assign({},this,MethodManager.prototype)],__read(a),!1)).then(function(e){return n._monitorManagerFunction.finishMonitorFunction(o),e},function(e){return n._monitorManagerFunction.finishMonitorFunction(o),n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Error Detected During Method "+t+" - (callMethodInternal)\n\nData \n"+JSON.stringify(r,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),e})),r[r.length-1]&&"function"==typeof r[r.length-1]&&l.then(function(e){return r[r.length-1](null,e)},function(e){return r[r.length-1](e,null)}),l},MethodManager.prototype.sendWS=function(e,t,r,o,n){this._websocketManager.send(e,n),"reportBuilderGetResults"!==r&&"reportBuilderGetDistinctValue"!==r&&"reportBuilderBuildTree"!==r&&"generatePDF"!==r&&"getWOOfflineData"!==r&&"countQuery"!==r&&"countWithQuery"!==r&&"countCollectionWithQuery"!==r&&"find"!==r&&"findOne"!==r&&"findWithOptions"!==r&&"uploadFileAndSave"!==r&&"getDrivers"!==r&&"processAirdropDistribution"!==r&&log_collection_1.Logs.insertOne({_id:(0,common_1.objectIdHexString)(),type:"client-response",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([o,n]))<2e5?JSON.stringify([o,n],null,2):"Too Big",method:r,id_user:e.id_user||"",user:e.user||"",messageId:n.messageId,route:""})},MethodManager.prototype.setupEmailWatcher=function(){return __awaiter(this,void 0,void 0,function(){var t,o=this;return __generator(this,function(e){switch(e.label){case 0:return(t=email_history_collection_1.EmailHistories.watchCollection([])).on("change",function(r){return __awaiter(o,void 0,void 0,function(){var t;return __generator(this,function(e){return"insert"===r.operationType&&r.fullDocument&&"pending"===r.fullDocument.status?(this.emailQueue.add(r.fullDocument._id.toString()),this.tryProcessEmail()):"update"!==r.operationType&&"replace"!==r.operationType||(t=r.fullDocument)&&"pending"!==t.status&&this.emailQueue.has(t._id.toString())&&this.emailQueue.delete(t._id.toString()),[2]})})}).on("error",function(e){console.error("Email history changestream error",e),t.close()}).on("close",function(){o.setupEmailWatcher()}),[4,this.loadPendingEmails()];case 1:return e.sent(),[2]}})})},MethodManager.prototype.loadPendingEmails=function(){return __awaiter(this,void 0,void 0,function(){var t,r,o,n,i,s;return __generator(this,function(e){switch(e.label){case 0:return[4,email_history_collection_1.EmailHistories.find({status:"pending"},{sort:{_id:1}})];case 1:t=e.sent();try{for(r=__values(t),o=r.next();!o.done;o=r.next())n=o.value,this.emailQueue.add(n._id.toString())}catch(e){i={error:e}}finally{try{o&&!o.done&&(s=r.return)&&s.call(r)}finally{if(i)throw i.error}}return this.tryProcessEmail(),[2]}})})},MethodManager.prototype.tryProcessEmail=function(){return __awaiter(this,void 0,void 0,function(){var t,_,r,d=this;return __generator(this,function(e){switch(e.label){case 0:if(this.isEmailProcessing||0===this.emailQueue.size)return[2];this.isEmailProcessing=!0,e.label=1;case 1:e.trys.push([1,5,6,7]),t=function(){var o,t,r,n,i,s,a,l,c,u;return __generator(this,function(e){switch(e.label){case 0:return i=_.emailQueue.values().next().value,_.emailQueue.delete(i),[4,email_history_collection_1.EmailHistories.findOneAndUpdate({_id:i,status:"pending"},{$set:{status:"processing",processingAt:new Date}})];case 1:if(!(o=e.sent()))return[2,"continue"];if(!(o.attachments&&0<o.attachments.length))return[3,14];e.label=2;case 2:e.trys.push([2,12,,14]),e.label=3;case 3:e.trys.push([3,9,10,11]),c=void 0,t=__values(o.attachments),r=t.next(),e.label=4;case 4:return r.done?[3,8]:(n=r.value).path&&n.path.startsWith("http")?[4,fetch(n.path)]:[3,7];case 5:if((i=e.sent()).ok)return[4,i.arrayBuffer()];throw new Error("Failed to fetch attachment: ".concat(n.path));case 6:s=e.sent(),s=Buffer.from(s),s.length<=20971520&&(n.content=s,delete n.path),e.label=7;case 7:return r=t.next(),[3,4];case 8:return[3,11];case 9:return s=e.sent(),c={error:s},[3,11];case 10:try{r&&!r.done&&(u=t.return)&&u.call(t)}finally{if(c)throw c.error}return[7];case 11:return[3,14];case 12:return a=e.sent(),console.error("Failed to fetch attachment:",a),[4,email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"failed",error:"string"==typeof a?a:_.safeStringify(a),completedAt:new Date}})];case 13:return e.sent(),[2,"continue"];case 14:return(l={replyTo:o.reply_to||resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_REPLY_TO||void 0,from:o.send_from||resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_FROM,to:o.email,subject:(resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/dev\./)||resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/www\.dev\./)?"(DEV SERVER) - ":"")+o.subject,text:"string"==typeof o.text?o.text:"",html:"string"==typeof o.html?o.html:"",attachments:o.attachments||[]}).attachments&&0<l.attachments.length&&(l.attachments=l.attachments.map(function(e){e=__assign({},e);return!e.content||"object"!=typeof e.content||e.content instanceof Buffer?"string"==typeof e.content&&"base64"===e.encoding?(e.content=Buffer.from(e.content,"base64"),delete e.encoding):"string"==typeof e.content&&(e.content=Buffer.from(e.content)):"Binary"===e.content._bsontype&&0===e.content.sub_type?e.content=Buffer.from(e.content.buffer):e.content=Buffer.from(e.content),e})),[4,new Promise(function(r){d._mailer.sendMail(l,function(t,e){return __awaiter(d,void 0,void 0,function(){return __generator(this,function(e){try{t?(console.error("Failed to send email:",t),email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"failed",error:"string"==typeof t?t:this.safeStringify(t),completedAt:new Date}})):"dev@resolveio.com"===o.email?email_history_collection_1.EmailHistories.deleteOne({_id:o._id}):email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"completed",completedAt:new Date}})}catch(e){console.error("Error in sendMail callback:",e),email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"failed",error:"string"==typeof e?e:this.safeStringify(e),completedAt:new Date}})}finally{r()}return[2]})})})})];case 15:return e.sent(),[4,new Promise(function(e){return setTimeout(e,1e3)})];case 16:return e.sent(),[2]}})},_=this,e.label=2;case 2:return 0<this.emailQueue.size?[5,t()]:[3,4];case 3:return e.sent(),[3,2];case 4:return[3,7];case 5:return r=e.sent(),console.error("Error processing email queue:",r),[3,7];case 6:return this.isEmailProcessing=!1,0<this.emailQueue.size&&this.tryProcessEmail(),[7];case 7:return[2]}})})},MethodManager.prototype.safeStringify=function(e){try{return JSON.stringify(e,this.getCircularReplacer())}catch(e){return"Error in JSON stringifying: ".concat(e.message)}},MethodManager.prototype.getCircularReplacer=function(){var r=new WeakSet;return function(e,t){if("object"==typeof t&&null!==t){if(r.has(t))return"[Circular]";r.add(t)}return t}},MethodManager.prototype.sendEmail=function(n,i,s,a,l,c,u,_){var e=this;return void 0===_&&(_=!1),new Promise(function(r,o){return __awaiter(e,void 0,void 0,function(){var t;return __generator(this,function(e){return(n=!resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/dev\./)&&!resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/www\.dev\./)&&"http://localhost:4200"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||n.match(/\@resolveio\.com/)?n:"dev@resolveio.com")?"http://localhost:4200"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||_?(l=l||[],l=(l=Array.isArray(l)?l:[l]).map(function(e){e=__assign({},e);return Buffer.isBuffer(e.content)&&(e.content=e.content.toString("base64"),e.encoding="base64"),e}),t={_id:(0,common_1.objectIdHexString)(),__v:0,date:new Date,id_user:this.id_user||"",user:this.user||"",email:n,subject:i||"",text:s||"",html:a||"",attachments:l||[],send_from:c||"",reply_to:u||"",status:"pending",error:""},email_history_collection_1.EmailHistories.insertOne(t).then(function(e){return r(e)},function(e){console.error("Failed to queue email:",e),o(e)})):(console.log("Send email",n,i,s,a,l,c),r(!0)):r(!0),[2]})})})},MethodManager.prototype.getAWS=function(){return this._aws},MethodManager.prototype.readFile=function(e){return new Promise(function(r,o){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"utf-8",function(e,t){e?o(e):r(t)}):fs.existsSync(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e))&&fs.readFile(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e),"utf-8",function(e,t){e?o(e):r(t)})})},MethodManager.prototype.readImage=function(e){return new Promise(function(r,o){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"base64",function(e,t){e?o(e):r(t)}):fs.existsSync(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e))&&fs.readFile(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e),"base64",function(e,t){e?o(e):r(t)})})},MethodManager}());exports.MethodManager=MethodManager;
|
|
1
|
+
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,o,n,i){return new(n=n||Promise)(function(r,t){function fulfilled(e){try{step(i.next(e))}catch(e){t(e)}}function rejected(e){try{step(i.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?r(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(fulfilled,rejected)}step((i=i.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(o,n){var i,s,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},c={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function verb(r){return function(e){var t=[r,e];if(i)throw new TypeError("Generator is already executing.");for(;l=c&&t[c=0]?0:l;)try{if(i=1,s&&(a=2&t[0]?s.return:t[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,t[1])).done)return a;switch(s=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=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(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3]))l.label=t[1];else if(6===t[0]&&l.label<a[1])l.label=a[1],a=t;else{if(!(a&&l.label<a[2])){a[2]&&l.ops.pop(),l.trys.pop();continue}l.label=a[2],l.ops.push(t)}}t=n.call(o,l)}catch(e){t=[6,e],s=0}finally{i=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},__read=this&&this.__read||function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,n,i=r.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return s},__spreadArray=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var o,n=0,i=t.length;n<i;n++)!o&&n in t||((o=o||Array.prototype.slice.call(t,0,n))[n]=t[n]);return e.concat(o||Array.prototype.slice.call(t))},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&o>=e.length?void 0:e)&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},collections_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MethodManager=exports.AWS=void 0,require("../methods/collections")),logs_1=require("../methods/logs"),counters_1=require("../methods/counters"),pdf_1=require("../methods/pdf"),aws_1=require("../methods/aws"),path=require("path"),fs=require("fs"),nodemailer=require("nodemailer"),sesTransport=require("nodemailer-ses-transport"),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"),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-timezone"),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"),client_s3_1=require("@aws-sdk/client-s3"),worker_task_request_collection_1=require("../collections/worker-task-request.collection"),worker_task_response_collection_1=require("../collections/worker-task-response.collection"),flag_updates_1=require("../methods/flag-updates"),resolveio_server_app_1=require("../resolveio-server-app"),AWS=function(){function AWS(){this._s3=null,this._s3USEast1=null}return AWS.prototype.s3=function(){return this._s3||(this._s3=new client_s3_1.S3({credentials:{accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY},region:process.env.AWS_REGION,apiVersion:"2006-03-01"})),this._s3},AWS.prototype.s3USEast1=function(){return"us-east-1"===process.env.AWS_REGION?this.s3():(this._s3USEast1||(this._s3USEast1=new client_s3_1.S3({credentials:{accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY},region:"us-east-1",apiVersion:"2006-03-01"})),this._s3USEast1)},AWS}(),MethodManager=(exports.AWS=AWS,function(){function MethodManager(e,t,r){var o=this;this._methods={},this._isWorkersEnabled=!1,this._isWorkerInstance=!1,this.emailQueue=new Set,this.isEmailProcessing=!1,this._debugCallMethodInternalHits=0,this._debugCallMethodHits=0,this._debugCallMethodCronJobHits=0,this._debugSendQueueHits=0,this.clientDir="",this.serverConfig="",this._websocketManager=resolveio_server_app_1.ResolveIOServer.getMainServer().getWebSocketManager(),this._monitorManagerFunction=e,this._isWorkersEnabled=t,this._isWorkerInstance=r,this.clientDir=resolveio_server_app_1.ResolveIOServer.getClientDir(),this.serverConfig=resolveio_server_app_1.ResolveIOServer.getServerConfig(),"false"!==process.env.IS_WORKERS_ENABLED&&("true"!==process.env.IS_WORKER_INSTANCE||"0"!==process.env.WORKER_INDEX)||process.env.NODE_APP_INSTANCE&&"0"!==process.env.NODE_APP_INSTANCE||setTimeout(function(){console.log(new Date,"Start Server Fixture"),(0,init_1.loadServerInit)(),console.log(new Date,"End Server Fixture")},5e3),(0,cron_jobs_1.loadServerCronJobs)(),(0,accounts_1.loadAccountMethods)(this),(0,aws_1.loadAWSMethods)(this),(0,collections_1.loadCollectionMethods)(this),(0,counters_1.loadCounterMethods)(this),(0,logs_1.loadLogMethods)(this),(0,pdf_1.loadPDFMethods)(this),(0,cron_jobs_2.loadCronJobMethods)(this),(0,flags_1.loadFlagMethods)(this),(0,flag_updates_1.loadFlagUpdatesMethods)(this),(0,report_builder_1.loadReportBuilderMethods)(this),(0,support_1.loadSupportMethods)(this),(0,monitor_1.loadMonitorMethods)(this),this._aws=new AWS,resolveio_server_app_1.ResolveIOServer.getSESMail()?this._mailer=nodemailer.createTransport(sesTransport({accessKeyId:process.env.AWS_ACCESS_KEY,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY,region:process.env.AWS_SES_REGION})):this._mailer=nodemailer.createTransport({host:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_HOST,port:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_PORT,secure:!1,auth:{user:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_USERNAME,pass:resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_PASSWORD},tls:{ciphers:"SSLv3"}}),setInterval(function(){resolveio_server_app_1.ResolveIOServer.getMainServer().getSubscriptionManager()&&resolveio_server_app_1.ResolveIOServer.getMainServer().getSubscriptionManager().getEnableDebug()&&(console.log(new Date,"Method Manager","Send Queue Hits",o._debugSendQueueHits),console.log(new Date,"Method Manager","Call Method Internal Hits",o._debugCallMethodInternalHits),console.log(new Date,"Method Manager","Call Method Hits",o._debugCallMethodHits),console.log(new Date,"Method Manager","Call Method Cron Hits",o._debugCallMethodCronJobHits)),o._debugCallMethodInternalHits=0,o._debugCallMethodHits=0,o._debugCallMethodCronJobHits=0,o._debugSendQueueHits=0},6e4),this._isWorkersEnabled&&!this._isWorkerInstance||this.setupEmailWatcher()}return MethodManager.prototype.methods=function(e){this._methods=Object.assign(this._methods,e)},MethodManager.prototype.callMethodCron=function(t){for(var n=this,r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];if(this._debugCallMethodCronJobHits+=1,this._methods[t]){if((1<r.length||r[0])&&!this._methods[t].skipValidation){if(!this._methods[t].check)return console.error(new Date,"No Check Function For Method "+t),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Function For Method "+t);if(!this._methods[t].check._schema)return console.error(new Date,"No Check Schema For Method "+t),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Function For Method "+t);for(var o={},i=Object.keys(this._methods[t].check._schema).filter(function(e){return!e.includes(".")}),s=0;s<r.length;s++)o[i[s]]=r[s];try{this._methods[t].check.validate(o)}catch(e){if(e)return console.error(new Date,"Error in Method Check ("+t+")",e),void this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Match Error On Method "+t+"\n\nData Being Checked\n"+JSON.stringify(o,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))}}var a,l,c,u=null,_=JSON.stringify(r);return this._isWorkersEnabled&&!this._isWorkerInstance&&Buffer.byteLength(_,"utf8")<8388608&&"insertSubscriptionLog"!==t&&"countQuery"!==t&&"incCounter"!==t&&"supportCreateBillingUser"!==t&&"find"!==t&&"insertDocument"!==t&&"countWithQuery"!==t&&"findOne"!==t&&"updateDocumentProps"!==t&&"findWithOptions"!==t&&"getSignedUrl"!==t&&"updateDocument"!==t&&"insertErrorLog"!==t&&"getSignedUrls"!==t&&"removeDocument"!==t&&"getSignedUrlWithId"!==t&&"incorrectUser"!==t&&"reloadWS"!==t&&"reconnectWS"!==t&&"disconnectWS"!==t?(a=this._monitorManagerFunction.startMonitorFunction("Cron Method",t,"","",r),l=(0,common_1.objectIdHexString)(),u=new Promise(function(t,r){var o=worker_task_response_collection_1.WorkerTaskResponses.watchCollection([{$match:{"fullDocument.id_request":l}}],{fullDocument:"updateLookup"});o.on("change",function(e){"insert"===e.operationType&&(n._monitorManagerFunction.finishMonitorFunction(a),((e=e.fullDocument).has_error?r:t)(e.data),o.close())}),o.on("error",function(e){console.error("Error watching worker responses:",e),r(e),o.close()})}),worker_task_request_collection_1.WorkerTaskRequests.create({_id:l,method:t,params:r,status:"pending",id_user:this.id_user,user:this.user,id_ws:this.id_socket})):(c=this._monitorManagerFunction.startMonitorFunction("Cron Method",t,"","",r),u=(_=this._methods[t].function).call.apply(_,__spreadArray([Object.assign({},this,MethodManager.prototype,{id_user:"",user:"",id_ws:""})],__read(r),!1)).then(function(e){return n._monitorManagerFunction.finishMonitorFunction(c),e},function(e){return n._monitorManagerFunction.finishMonitorFunction(c),n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Error Detected During Method "+t+" - (callMethodCron)\n\nData \n"+JSON.stringify(r,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),e})),u}console.log("No Method: "+t),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Method: "+t)},MethodManager.prototype.callMethod=function(o,n,i,s,a){for(var t=this,l=[],e=5;e<arguments.length;e++)l[e-5]=arguments[e];if(this._debugCallMethodHits+=1,this._methods[a]){if((1<l.length||l[0])&&!this._methods[a].skipValidation){if(!this._methods[a].check)return console.error(new Date,"No Check Function For Method "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Function For Method "+a),this.sendWS(n,i,a,l,r={messageId:s,hasError:!0,data:"Internal Error"}),void(o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}));if(!this._methods[a].check._schema)return console.error(new Date,"No Check Schema For Method "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Check Schema For Method "+a),r={messageId:s,hasError:!0,data:"Internal Error"},o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}),void this.sendWS(n,i,a,l,r);for(var r,c={},u=Object.keys(this._methods[a].check._schema).filter(function(e){return!e.includes(".")}),_=0;_<l.length;_++)c[u[_]]=l[_];try{this._methods[a].check.validate(c)}catch(e){if(e)return console.error(new Date,"Error in Method Check ("+a+")",e),"processAirdropDistribution"!==a&&this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Match Error On Method "+a+"\n\nData Being Checked\n"+JSON.stringify(c,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),this.sendWS(n,i,a,l,r={messageId:s,hasError:!0,data:"Internal Error"}),void(o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}))}}var d,h,p,g=JSON.stringify(l);this._isWorkersEnabled&&!this._isWorkerInstance&&Buffer.byteLength(g,"utf8")<8388608&&"insertSubscriptionLog"!==a&&"countQuery"!==a&&"incCounter"!==a&&"supportCreateBillingUser"!==a&&"find"!==a&&"insertDocument"!==a&&"countWithQuery"!==a&&"findOne"!==a&&"updateDocumentProps"!==a&&"findWithOptions"!==a&&"getSignedUrl"!==a&&"updateDocument"!==a&&"insertErrorLog"!==a&&"getSignedUrls"!==a&&"removeDocument"!==a&&"getSignedUrlWithId"!==a&&"incorrectUser"!==a&&"reloadWS"!==a&&"reconnectWS"!==a&&"disconnectWS"!==a?(d=this._monitorManagerFunction.startMonitorFunction("Method",a,n.user||"",n.id_socket||"",l),g=(0,common_1.objectIdHexString)(),(h=worker_task_response_collection_1.WorkerTaskResponses.watchCollection([{$match:{"fullDocument.id_request":g}}],{fullDocument:"updateLookup"})).on("change",function(r){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return"insert"!==r.operationType?[3,3]:(this._monitorManagerFunction.finishMonitorFunction(d),t=r.fullDocument,t={messageId:s,hasError:t.has_error,data:t.data},this.sendWS(n,new Date,a,l,t),o?[4,log_method_latency_collection_1.LogMethodLatencies.findById(o)]:[3,2]);case 1:(t=e.sent())&&log_method_latency_collection_1.LogMethodLatencies.updateOne({_id:o},{$set:{date_end:new Date,latency_ms:moment().diff(moment(t.date_start),"milliseconds",!0)}}),e.label=2;case 2:h.close(),e.label=3;case 3:return[2]}})})}),h.on("error",function(e){console.error("Error watching worker responses:",e),h.close()}),worker_task_request_collection_1.WorkerTaskRequests.create({_id:g,method:a,params:l,status:"pending",id_user:n.id_user,user:n.user,id_ws:n.id_socket})):(p=this._monitorManagerFunction.startMonitorFunction("Method",a,n.user||"",n.id_socket||"",l),(g=this._methods[a].function).call.apply(g,__spreadArray([Object.assign({},this,MethodManager.prototype,{id_user:n.id_user,user:n.user,id_ws:n.id_socket})],__read(l),!1)).then(function(r){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return(this._monitorManagerFunction.finishMonitorFunction(p),t={messageId:s,hasError:!1,data:r},this.sendWS(n,i,a,l,t),o)?[4,log_method_latency_collection_1.LogMethodLatencies.findById(o)]:[3,2];case 1:(t=e.sent())&&log_method_latency_collection_1.LogMethodLatencies.updateOne({_id:o},{$set:{date_end:new Date,latency_ms:moment().diff(moment(t.date_start),"milliseconds",!0)}}),e.label=2;case 2:return[2]}})})},function(e){t._monitorManagerFunction.finishMonitorFunction(p),t.sendWS(n,i,a,l,{messageId:s,hasError:!0,data:e}),o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o}),"processAirdropDistribution"!==a&&t.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Error Detected During Method "+a+" - (callMethod)\n\nData \n"+JSON.stringify(l,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2))}))}else console.log("No Method: "+a),this.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"No Method: "+a),r={messageId:s,hasError:!0,data:"Internal Error"},this.sendWS(n,new Date,a,l,r),o&&log_method_latency_collection_1.LogMethodLatencies.deleteOne({_id:o})},MethodManager.prototype.callMethodInternal=function(t){for(var n=this,r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];if(this._debugCallMethodInternalHits+=1,!this._methods[t])return console.log("No Method: "+t),null;if((1<r.length||r[0]&&"function"!=typeof r[0])&&!this._methods[t].skipValidation){if(!this._methods[t].check)return console.error(new Date,"No Check Function For Method "+t),null;if(!this._methods[t].check._schema)return console.error(new Date,"No Check Schema For Method "+t),null}"insertSubscriptionLog"!==t&&"getDataURIfromURL"!==t&&"processAirdropDistribution"!==t&&"incCounter"!==t&&"supportCreateBillingUser"!==t&&"countCollectionWithQuery"!==t&&("https://resolveio.com"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL&&"http://localhost:4200"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({type:"log",data:{_id:(0,common_1.objectIdHexString)(),type:"callMethodInternal",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([r]))<2e5?JSON.stringify([r],null,2):"Too Big",method:t,id_user:this.id_user||"",user:this.user||"",messageId:0,route:""}}):log_collection_1.Logs.insertOne({_id:(0,common_1.objectIdHexString)(),type:"callMethodInternal",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([r]))<2e5?JSON.stringify([r],null,2):"Too Big",method:t,id_user:this.id_user||"",user:this.user||"",messageId:0,route:"",client:"ResolveIO",instance:"backend.resolveio.com"}));var i,s,o,a="function"==typeof r[r.length-1]?r.slice(0,-1):r,l=null,c=JSON.stringify(a);return this._isWorkersEnabled&&!this._isWorkerInstance&&Buffer.byteLength(c,"utf8")<8388608&&"insertSubscriptionLog"!==t&&"countQuery"!==t&&"incCounter"!==t&&"supportCreateBillingUser"!==t&&"find"!==t&&"insertDocument"!==t&&"countWithQuery"!==t&&"findOne"!==t&&"updateDocumentProps"!==t&&"findWithOptions"!==t&&"getSignedUrl"!==t&&"updateDocument"!==t&&"insertErrorLog"!==t&&"getSignedUrls"!==t&&"removeDocument"!==t&&"getSignedUrlWithId"!==t&&"incorrectUser"!==t&&"reloadWS"!==t&&"reconnectWS"!==t&&"disconnectWS"!==t?(i=this._monitorManagerFunction.startMonitorFunction("Internal Method",t,this.user||"","",a),s=(0,common_1.objectIdHexString)(),l=new Promise(function(t,r){var o=worker_task_response_collection_1.WorkerTaskResponses.watchCollection([{$match:{"fullDocument.id_request":s}}],{fullDocument:"updateLookup"});o.on("change",function(e){"insert"===e.operationType&&(n._monitorManagerFunction.finishMonitorFunction(i),((e=e.fullDocument).has_error?r:t)(e.data),o.close())}),o.on("error",function(e){console.error("Error watching worker responses:",e),r(e),o.close()})}),worker_task_request_collection_1.WorkerTaskRequests.create({_id:s,method:t,params:a,status:"pending",id_user:this.id_user,user:this.user,id_ws:this.id_socket})):(o=this._monitorManagerFunction.startMonitorFunction("Internal Method",t,this.user||"","",a),l=(c=this._methods[t].function).call.apply(c,__spreadArray([Object.assign({},this,MethodManager.prototype)],__read(a),!1)).then(function(e){return n._monitorManagerFunction.finishMonitorFunction(o),e},function(e){return n._monitorManagerFunction.finishMonitorFunction(o),n.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME,"Error Detected During Method "+t+" - (callMethodInternal)\n\nData \n"+JSON.stringify(r,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),e})),r[r.length-1]&&"function"==typeof r[r.length-1]&&l.then(function(e){return r[r.length-1](null,e)},function(e){return r[r.length-1](e,null)}),l},MethodManager.prototype.sendWS=function(e,t,r,o,n){this._websocketManager.send(e,n),"reportBuilderGetResults"!==r&&"reportBuilderGetDistinctValue"!==r&&"reportBuilderBuildTree"!==r&&"generatePDF"!==r&&"getWOOfflineData"!==r&&"countQuery"!==r&&"countWithQuery"!==r&&"countCollectionWithQuery"!==r&&"find"!==r&&"findOne"!==r&&"findWithOptions"!==r&&"uploadFileAndSave"!==r&&"getDrivers"!==r&&"processAirdropDistribution"!==r&&("https://resolveio.com"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL&&"http://localhost:4200"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({type:"log",data:{_id:(0,common_1.objectIdHexString)(),type:"client-response",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([o,n]))<2e5?JSON.stringify([o,n],null,2):"Too Big",method:r,id_user:e.id_user||"",user:e.user||"",messageId:n.messageId,route:""}}):log_collection_1.Logs.insertOne({_id:(0,common_1.objectIdHexString)(),type:"client-response",collection:"",id_document:"",payload:(0,common_1.getBinarySize)(JSON.stringify([o,n]))<2e5?JSON.stringify([o,n],null,2):"Too Big",method:r,id_user:e.id_user||"",user:e.user||"",messageId:n.messageId,route:"",client:"ResolveIO",instance:"backend.resolveio.com"}))},MethodManager.prototype.setupEmailWatcher=function(){return __awaiter(this,void 0,void 0,function(){var t,o=this;return __generator(this,function(e){switch(e.label){case 0:return(t=email_history_collection_1.EmailHistories.watchCollection([])).on("change",function(r){return __awaiter(o,void 0,void 0,function(){var t;return __generator(this,function(e){return"insert"===r.operationType&&r.fullDocument&&"pending"===r.fullDocument.status?(this.emailQueue.add(r.fullDocument._id.toString()),this.tryProcessEmail()):"update"!==r.operationType&&"replace"!==r.operationType||(t=r.fullDocument)&&"pending"!==t.status&&this.emailQueue.has(t._id.toString())&&this.emailQueue.delete(t._id.toString()),[2]})})}).on("error",function(e){console.error("Email history changestream error",e),t.close()}).on("close",function(){o.setupEmailWatcher()}),[4,this.loadPendingEmails()];case 1:return e.sent(),[2]}})})},MethodManager.prototype.loadPendingEmails=function(){return __awaiter(this,void 0,void 0,function(){var t,r,o,n,i,s;return __generator(this,function(e){switch(e.label){case 0:return[4,email_history_collection_1.EmailHistories.find({status:"pending"},{sort:{_id:1}})];case 1:t=e.sent();try{for(r=__values(t),o=r.next();!o.done;o=r.next())n=o.value,this.emailQueue.add(n._id.toString())}catch(e){i={error:e}}finally{try{o&&!o.done&&(s=r.return)&&s.call(r)}finally{if(i)throw i.error}}return this.tryProcessEmail(),[2]}})})},MethodManager.prototype.tryProcessEmail=function(){return __awaiter(this,void 0,void 0,function(){var t,_,r,d=this;return __generator(this,function(e){switch(e.label){case 0:if(this.isEmailProcessing||0===this.emailQueue.size)return[2];this.isEmailProcessing=!0,e.label=1;case 1:e.trys.push([1,5,6,7]),t=function(){var o,t,r,n,i,s,a,l,c,u;return __generator(this,function(e){switch(e.label){case 0:return i=_.emailQueue.values().next().value,_.emailQueue.delete(i),[4,email_history_collection_1.EmailHistories.findOneAndUpdate({_id:i,status:"pending"},{$set:{status:"processing",processingAt:new Date}})];case 1:if(!(o=e.sent()))return[2,"continue"];if(!(o.attachments&&0<o.attachments.length))return[3,14];e.label=2;case 2:e.trys.push([2,12,,14]),e.label=3;case 3:e.trys.push([3,9,10,11]),c=void 0,t=__values(o.attachments),r=t.next(),e.label=4;case 4:return r.done?[3,8]:(n=r.value).path&&n.path.startsWith("http")?[4,fetch(n.path)]:[3,7];case 5:if((i=e.sent()).ok)return[4,i.arrayBuffer()];throw new Error("Failed to fetch attachment: ".concat(n.path));case 6:s=e.sent(),s=Buffer.from(s),s.length<=20971520&&(n.content=s,delete n.path),e.label=7;case 7:return r=t.next(),[3,4];case 8:return[3,11];case 9:return s=e.sent(),c={error:s},[3,11];case 10:try{r&&!r.done&&(u=t.return)&&u.call(t)}finally{if(c)throw c.error}return[7];case 11:return[3,14];case 12:return a=e.sent(),console.error("Failed to fetch attachment:",a),[4,email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"failed",error:"string"==typeof a?a:_.safeStringify(a),completedAt:new Date}})];case 13:return e.sent(),[2,"continue"];case 14:return(l={replyTo:o.reply_to||resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_REPLY_TO||void 0,from:o.send_from||resolveio_server_app_1.ResolveIOServer.getServerConfig().MAIL_FROM,to:o.email,subject:(resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/dev\./)||resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/www\.dev\./)?"(DEV SERVER) - ":"")+o.subject,text:"string"==typeof o.text?o.text:"",html:"string"==typeof o.html?o.html:"",attachments:o.attachments||[]}).attachments&&0<l.attachments.length&&(l.attachments=l.attachments.map(function(e){e=__assign({},e);return!e.content||"object"!=typeof e.content||e.content instanceof Buffer?"string"==typeof e.content&&"base64"===e.encoding?(e.content=Buffer.from(e.content,"base64"),delete e.encoding):"string"==typeof e.content&&(e.content=Buffer.from(e.content)):"Binary"===e.content._bsontype&&0===e.content.sub_type?e.content=Buffer.from(e.content.buffer):e.content=Buffer.from(e.content),e})),[4,new Promise(function(r){d._mailer.sendMail(l,function(t,e){return __awaiter(d,void 0,void 0,function(){return __generator(this,function(e){try{t?(console.error("Failed to send email:",t),email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"failed",error:"string"==typeof t?t:this.safeStringify(t),completedAt:new Date}})):"dev@resolveio.com"===o.email?email_history_collection_1.EmailHistories.deleteOne({_id:o._id}):email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"completed",completedAt:new Date}})}catch(e){console.error("Error in sendMail callback:",e),email_history_collection_1.EmailHistories.updateOne({_id:o._id},{$set:{status:"failed",error:"string"==typeof e?e:this.safeStringify(e),completedAt:new Date}})}finally{r()}return[2]})})})})];case 15:return e.sent(),[4,new Promise(function(e){return setTimeout(e,1e3)})];case 16:return e.sent(),[2]}})},_=this,e.label=2;case 2:return 0<this.emailQueue.size?[5,t()]:[3,4];case 3:return e.sent(),[3,2];case 4:return[3,7];case 5:return r=e.sent(),console.error("Error processing email queue:",r),[3,7];case 6:return this.isEmailProcessing=!1,0<this.emailQueue.size&&this.tryProcessEmail(),[7];case 7:return[2]}})})},MethodManager.prototype.safeStringify=function(e){try{return JSON.stringify(e,this.getCircularReplacer())}catch(e){return"Error in JSON stringifying: ".concat(e.message)}},MethodManager.prototype.getCircularReplacer=function(){var r=new WeakSet;return function(e,t){if("object"==typeof t&&null!==t){if(r.has(t))return"[Circular]";r.add(t)}return t}},MethodManager.prototype.sendEmail=function(n,i,s,a,l,c,u,_){var e=this;return void 0===_&&(_=!1),new Promise(function(r,o){return __awaiter(e,void 0,void 0,function(){var t;return __generator(this,function(e){return(n=!resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/dev\./)&&!resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL.match(/https:\/\/www\.dev\./)&&"http://localhost:4200"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||n.match(/\@resolveio\.com/)?n:"dev@resolveio.com")?"http://localhost:4200"!==resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||_?(l=l||[],l=(l=Array.isArray(l)?l:[l]).map(function(e){e=__assign({},e);return Buffer.isBuffer(e.content)&&(e.content=e.content.toString("base64"),e.encoding="base64"),e}),t={_id:(0,common_1.objectIdHexString)(),__v:0,date:new Date,id_user:this.id_user||"",user:this.user||"",email:n,subject:i||"",text:s||"",html:a||"",attachments:l||[],send_from:c||"",reply_to:u||"",status:"pending",error:""},email_history_collection_1.EmailHistories.insertOne(t).then(function(e){return r(e)},function(e){console.error("Failed to queue email:",e),o(e)})):(console.log("Send email",n,i,s,a,l,c),r(!0)):r(!0),[2]})})})},MethodManager.prototype.getAWS=function(){return this._aws},MethodManager.prototype.readFile=function(e){return new Promise(function(r,o){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"utf-8",function(e,t){e?o(e):r(t)}):fs.existsSync(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e))&&fs.readFile(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e),"utf-8",function(e,t){e?o(e):r(t)})})},MethodManager.prototype.readImage=function(e){return new Promise(function(r,o){fs.existsSync(path.join(__dirname,"../private/"+e))?fs.readFile(path.join(__dirname,"../private/"+e),"base64",function(e,t){e?o(e):r(t)}):fs.existsSync(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e))&&fs.readFile(path.join(resolveio_server_app_1.ResolveIOServer.getClientDir(),"./private/"+e),"base64",function(e,t){e?o(e):r(t)})})},MethodManager}());exports.MethodManager=MethodManager;
|
|
2
2
|
//# sourceMappingURL=method.manager.js.map
|