@resolveio/server-lib 20.10.7 → 20.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collections/report-builder-report.collection.js +0 -44
- package/collections/report-builder-report.collection.js.map +1 -1
- package/http/auth.js +42 -8
- package/http/auth.js.map +1 -1
- package/http/home.js +21 -2
- package/http/home.js.map +1 -1
- package/managers/method.manager.d.ts +2 -1
- package/managers/method.manager.js +59 -50
- package/managers/method.manager.js.map +1 -1
- package/managers/subscription.manager.js +60 -41
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +29 -6
- package/methods/accounts.js.map +1 -1
- package/methods/cron-jobs.js +1 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/logs.js +20 -10
- package/methods/logs.js.map +1 -1
- package/methods/report-builder.js +4 -256
- package/methods/report-builder.js.map +1 -1
- package/methods.ts +4 -4
- package/models/report-builder-report.model.d.ts +0 -2
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.d.ts +0 -14
- package/models/report-builder.model.js.map +1 -1
- package/package.json +9 -8
- package/server-app.d.ts +1 -0
- package/server-app.js +54 -33
- package/server-app.js.map +1 -1
- package/util/error-reporter.d.ts +52 -0
- package/util/error-reporter.js +332 -0
- package/util/error-reporter.js.map +1 -0
- package/util/schema-report-builder.js +2 -9
- package/util/schema-report-builder.js.map +1 -1
|
@@ -108,6 +108,7 @@ var report_builder_1 = require("../methods/report-builder");
|
|
|
108
108
|
var support_1 = require("../methods/support");
|
|
109
109
|
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
110
110
|
var common_1 = require("../util/common");
|
|
111
|
+
var error_reporter_1 = require("../util/error-reporter");
|
|
111
112
|
var error_tracking_1 = require("../util/error-tracking");
|
|
112
113
|
function appendCorrelationIdToSubject(subject, correlationId) {
|
|
113
114
|
if (!correlationId) {
|
|
@@ -216,7 +217,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
216
217
|
this._debugSendQueueHits = 0;
|
|
217
218
|
this._enableDebug = false;
|
|
218
219
|
this.clientDir = '';
|
|
219
|
-
this.serverConfig =
|
|
220
|
+
this.serverConfig = {};
|
|
220
221
|
}
|
|
221
222
|
MethodManager.create = function (websocketManager, monitorManagerFunction, isWorkersEnabled, isWorkerInstance) {
|
|
222
223
|
var methodManager = new MethodManager();
|
|
@@ -345,6 +346,36 @@ var MethodManager = /** @class */ (function () {
|
|
|
345
346
|
MethodManager.prototype.methods = function (method) {
|
|
346
347
|
this._methods = Object.assign(this._methods, method);
|
|
347
348
|
};
|
|
349
|
+
MethodManager.prototype.reportMethodError = function (subject, correlationId, context, meta, stack) {
|
|
350
|
+
var _a, _b;
|
|
351
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
352
|
+
var metadata;
|
|
353
|
+
return __generator(this, function (_c) {
|
|
354
|
+
switch (_c.label) {
|
|
355
|
+
case 0:
|
|
356
|
+
metadata = Object.assign({}, meta || {});
|
|
357
|
+
if (correlationId && !metadata.correlationId) {
|
|
358
|
+
metadata.correlationId = correlationId;
|
|
359
|
+
}
|
|
360
|
+
return [4 /*yield*/, error_reporter_1.ErrorReporter.report({
|
|
361
|
+
sourceApp: 'method-manager',
|
|
362
|
+
message: subject,
|
|
363
|
+
environment: (_a = this.serverConfig) === null || _a === void 0 ? void 0 : _a.ROOT_URL,
|
|
364
|
+
clientSlug: resolveio_server_app_1.ResolveIOServer.getClientName(),
|
|
365
|
+
clientName: (_b = this.serverConfig) === null || _b === void 0 ? void 0 : _b.CLIENT_NAME,
|
|
366
|
+
severity: 'error',
|
|
367
|
+
stack: stack,
|
|
368
|
+
context: context,
|
|
369
|
+
metadata: metadata,
|
|
370
|
+
correlationId: correlationId
|
|
371
|
+
})];
|
|
372
|
+
case 1:
|
|
373
|
+
_c.sent();
|
|
374
|
+
return [2 /*return*/];
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
};
|
|
348
379
|
MethodManager.prototype.callMethodCron = function (method) {
|
|
349
380
|
var methodData = [];
|
|
350
381
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -368,13 +399,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
368
399
|
cronMethod = this._methods[method];
|
|
369
400
|
if (!!cronMethod) return [3 /*break*/, 2];
|
|
370
401
|
console.log('No Method: ' + method);
|
|
371
|
-
return [4 /*yield*/, this.
|
|
372
|
-
correlationId: correlationId,
|
|
373
|
-
meta: {
|
|
374
|
-
context: 'callMethodCron',
|
|
375
|
-
method: method
|
|
376
|
-
}
|
|
377
|
-
})];
|
|
402
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], correlationId, { message: 'No Method registered for cron execution', method: method }, { context: 'callMethodCron', method: method })];
|
|
378
403
|
case 1:
|
|
379
404
|
_d.sent();
|
|
380
405
|
throw new Error('No Method: ' + method);
|
|
@@ -382,26 +407,14 @@ var MethodManager = /** @class */ (function () {
|
|
|
382
407
|
if (!((methodData.length > 1 || methodData[0]) && !cronMethod.skipValidation)) return [3 /*break*/, 10];
|
|
383
408
|
if (!!cronMethod.check) return [3 /*break*/, 4];
|
|
384
409
|
console.error(new Date(), 'No Check Function For Cron Method ' + method);
|
|
385
|
-
return [4 /*yield*/, this.
|
|
386
|
-
correlationId: correlationId,
|
|
387
|
-
meta: {
|
|
388
|
-
context: 'callMethodCron-validation',
|
|
389
|
-
method: method
|
|
390
|
-
}
|
|
391
|
-
})];
|
|
410
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], correlationId, { message: 'Missing check function for cron method', method: method }, { context: 'callMethodCron-validation', method: method })];
|
|
392
411
|
case 3:
|
|
393
412
|
_d.sent();
|
|
394
413
|
throw new Error('No Check Function For Cron Method ' + method);
|
|
395
414
|
case 4:
|
|
396
415
|
if (!!cronMethod.check._schema) return [3 /*break*/, 6];
|
|
397
416
|
console.error(new Date(), 'No Check Schema For Cron Method ' + method);
|
|
398
|
-
return [4 /*yield*/, this.
|
|
399
|
-
correlationId: correlationId,
|
|
400
|
-
meta: {
|
|
401
|
-
context: 'callMethodCron-validation',
|
|
402
|
-
method: method
|
|
403
|
-
}
|
|
404
|
-
})];
|
|
417
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], correlationId, { message: 'Missing check schema for cron method', method: method }, { context: 'callMethodCron-validation', method: method })];
|
|
405
418
|
case 5:
|
|
406
419
|
_d.sent();
|
|
407
420
|
throw new Error('No Check Schema For Cron Method ' + method);
|
|
@@ -421,13 +434,12 @@ var MethodManager = /** @class */ (function () {
|
|
|
421
434
|
err_1 = _d.sent();
|
|
422
435
|
console.error(new Date(), 'Error in Cron Method Check (' + method + ')', err_1);
|
|
423
436
|
_a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_1, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
|
|
424
|
-
return [4 /*yield*/, this.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
})];
|
|
437
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
438
|
+
message: 'Match error on cron method',
|
|
439
|
+
method: method,
|
|
440
|
+
data: valObj,
|
|
441
|
+
validationError: normalizedError
|
|
442
|
+
}, { context: 'callMethodCron-validation-error', method: method }, normalizedError.stack)];
|
|
431
443
|
case 9:
|
|
432
444
|
_d.sent();
|
|
433
445
|
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Cron Method Check (").concat(method, "): ").concat(normalizedError.message);
|
|
@@ -444,13 +456,12 @@ var MethodManager = /** @class */ (function () {
|
|
|
444
456
|
case 13:
|
|
445
457
|
err_2 = _d.sent();
|
|
446
458
|
_b = (0, error_tracking_1.ensureErrorWithCorrelation)(err_2, correlationId), normalizedError = _b.error, resolvedCorrelationId = _b.correlationId;
|
|
447
|
-
return [4 /*yield*/, this.
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
})];
|
|
459
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
460
|
+
message: 'Error detected during cron method execution',
|
|
461
|
+
method: method,
|
|
462
|
+
data: methodData,
|
|
463
|
+
error: normalizedError
|
|
464
|
+
}, { context: 'callMethodCron-execution', method: method }, normalizedError.stack)];
|
|
454
465
|
case 14:
|
|
455
466
|
_d.sent();
|
|
456
467
|
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Cron Method (").concat(method, "): ").concat(normalizedError.message);
|
|
@@ -605,13 +616,12 @@ var MethodManager = /** @class */ (function () {
|
|
|
605
616
|
stack: normalizedError.stack,
|
|
606
617
|
correlationId: resolvedCorrelationId
|
|
607
618
|
}], null, 2));
|
|
608
|
-
return [4 /*yield*/, this.
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
})];
|
|
619
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
620
|
+
message: 'Error detected during method execution (new session)',
|
|
621
|
+
method: methodName,
|
|
622
|
+
data: methodData,
|
|
623
|
+
error: normalizedError
|
|
624
|
+
}, { context: 'callMethod-new-session', methodName: methodName }, normalizedError.stack)];
|
|
615
625
|
case 4:
|
|
616
626
|
_c.sent();
|
|
617
627
|
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method With Session (").concat(methodName, ") - New Session: ").concat(normalizedError.message);
|
|
@@ -667,13 +677,12 @@ var MethodManager = /** @class */ (function () {
|
|
|
667
677
|
stack: normalizedError.stack,
|
|
668
678
|
correlationId: resolvedCorrelationId
|
|
669
679
|
}], null, 2));
|
|
670
|
-
return [4 /*yield*/, this.
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
})];
|
|
680
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
681
|
+
message: 'Error detected during method execution (existing session)',
|
|
682
|
+
method: methodName,
|
|
683
|
+
data: methodData,
|
|
684
|
+
error: normalizedError
|
|
685
|
+
}, { context: 'callMethod-existing-session', methodName: methodName }, normalizedError.stack)];
|
|
677
686
|
case 9:
|
|
678
687
|
_c.sent();
|
|
679
688
|
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method (").concat(methodName, ") - Existing Session: ").concat(normalizedError.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/method.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwC;AACxC,uBAAyB;AACzB,uCAAyC;AACzC,uDAAyD;AACzD,2BAA6B;AAC7B,oFAAyE;AACzE,kEAAuD;AACvD,gEAAqD;AACrD,mDAA2D;AAC3D,yCAAkD;AAClD,gDAAyD;AACzD,sCAAgD;AAChD,sDAA+D;AAC/D,gDAAyD;AACzD,kDAA0D;AAC1D,wDAAiE;AACjE,0CAAmD;AACnD,wCAAiD;AACjD,8CAAwD;AACxD,sCAAgD;AAChD,4DAAqE;AACrE,8CAAwD;AAGxD,gEAA0D;AAC1D,yCAAkE;AAClE,yDAAiH;AASjH,SAAS,4BAA4B,CAAC,OAAe,EAAE,aAAsB;IAC5E,IAAI,CAAC,aAAa,EAAE;QACnB,OAAO,OAAO,CAAC;KACf;IAED,IAAM,cAAc,GAAG,WAAI,aAAa,MAAG,CAAC;IAE5C,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;QAChD,OAAO,OAAO,CAAC;KAC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AAC,OAAO,GAAG,8BAAuB,GAAG,CAAC,OAAO,CAAE,CAAC;oBACnD,MAAM,GAAG,CAAC;iBACV;aACD;SACD;QAED,MAAM,IAAI,KAAK,CAAE,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAEM,sCAAc,GAArB;QACC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IACF,oBAAC;AAAD,CArjCA,AAqjCC,IAAA;AArjCY,sCAAa","file":"method.manager.js","sourcesContent":["import { S3 } from '@aws-sdk/client-s3';\nimport * as fs from 'fs';\nimport * as nodemailer from 'nodemailer';\nimport * as sesTransport from 'nodemailer-ses-transport';\nimport * as path from 'path';\nimport { EmailHistories } from '../collections/email-history.collection';\nimport { Flags } from '../collections/flag.collection';\nimport { Logs } from '../collections/log.collection';\nimport { loadServerCronJobs } from '../fixtures/cron-jobs';\nimport { loadServerInit } from '../fixtures/init';\nimport { loadAccountMethods } from '../methods/accounts';\nimport { loadAWSMethods } from '../methods/aws';\nimport { loadCollectionMethods } from '../methods/collections';\nimport { loadCounterMethods } from '../methods/counters';\nimport { loadCronJobMethods } from '../methods/cron-jobs';\nimport { loadFlagUpdatesMethods } from '../methods/flag-updates';\nimport { loadFlagMethods } from '../methods/flags';\nimport { loadLogMethods } from '../methods/logs';\nimport { loadMonitorMethods } from '../methods/monitor';\nimport { loadPDFMethods } from '../methods/pdf';\nimport { loadReportBuilderMethods } from '../methods/report-builder';\nimport { loadSupportMethods } from '../methods/support';\nimport { EmailHistoryModel, EmailHistoryOccurrence } from '../models/email-history.model';\nimport { MethodAllModel, MethodModel } from '../models/method.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { getBinarySize, objectIdHexString } from '../util/common';\nimport { ensureErrorWithCorrelation, getCorrelationId, runWithCorrelationContext } from '../util/error-tracking';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { WebSocketManager } from './websocket.manager';\n\ninterface SendEmailOptions {\n\tcorrelationId?: string;\n\tmeta?: Record<string, any>;\n}\n\nfunction appendCorrelationIdToSubject(subject: string, correlationId?: string): string {\n\tif (!correlationId) {\n\t\treturn subject;\n\t}\n\n\tconst correlationTag = `[${correlationId}]`;\n\n\tif (subject && subject.includes(correlationTag)) {\n\t\treturn subject;\n\t}\n\n\treturn `${subject} ${correlationTag}`.trim();\n}\n\nfunction createEmailOccurrence(subject: string, text?: string, html?: string, meta?: Record<string, any>): EmailHistoryOccurrence {\n\treturn {\n\t\t_id: objectIdHexString(),\n\t\tcreatedAt: new Date(),\n\t\tsubject,\n\t\ttext,\n\t\thtml,\n\t\tmeta\n\t};\n}\n\nfunction formatGroupedEmailContent(correlationId: string, occurrences: EmailHistoryOccurrence[]): { text: string; html: string } {\n\tconst lines: string[] = [];\n\tlines.push(`Correlation ID: ${correlationId}`);\n\n\toccurrences.forEach((occurrence, index) => {\n\t\tconst timestamp = occurrence.createdAt instanceof Date ? occurrence.createdAt.toISOString() : new Date(occurrence.createdAt).toISOString();\n\t\tlines.push('');\n\t\tlines.push(`Occurrence #${index + 1} (${timestamp})`);\n\t\tlines.push(`Subject: ${occurrence.subject}`);\n\t\tif (occurrence.text) {\n\t\t\tlines.push(occurrence.text);\n\t\t}\n\t});\n\n\tconst htmlSections = occurrences.map((occurrence, index) => {\n\t\tconst timestamp = occurrence.createdAt instanceof Date ? occurrence.createdAt.toISOString() : new Date(occurrence.createdAt).toISOString();\n\t\tconst escapedText = occurrence.text ? occurrence.text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') : '';\n\t\treturn `<div><h4>Occurrence #${index + 1} (${timestamp})</h4><p><strong>Subject:</strong> ${occurrence.subject}</p>${escapedText ? `<pre>${escapedText}</pre>` : ''}</div>`;\n\t});\n\n\tconst html = [\n\t\t`<p><strong>Correlation ID:</strong> ${correlationId}</p>`,\n\t\t...htmlSections\n\t].join('');\n\n\treturn {\n\t\ttext: lines.join('\\n'),\n\t\thtml\n\t};\n}\n\nexport class AWS {\n\tprivate _s3: S3 = null;\n\tprivate _s3USEast1: S3 = null;\n\n\tconstructor() {}\n\n\tpublic create() {\n\t\tconst aws = new AWS();\n\t\taws.initialize();\n\t\treturn aws;\n\t}\n\n\tprivate initialize() {\n\n\t}\n\n\tpublic s3(): S3 {\n\t\tif (this._s3) {\n\t\t\treturn this._s3;\n\t\t}\n\n\t\tthis._s3 = new S3({\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: process.env.AWS_ACCESS_KEY,\n\t\t\t\tsecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY\n\t\t\t},\n\t\t\tregion: process.env.AWS_REGION,\n\t\t\tapiVersion: '2006-03-01'\n\t\t});\n\n\t\treturn this._s3;\n\t}\n\n\tpublic s3USEast1(): S3 {\n\t\tif (process.env.AWS_REGION === 'us-east-1') {\n\t\t\treturn this.s3();\n\t\t}\n\t\telse {\n\t\t\tif (this._s3USEast1) {\n\t\t\t\treturn this._s3USEast1;\n\t\t\t}\n\t\t\t\n\t\t\tthis._s3USEast1 = new S3({\n\t\t\t\tcredentials: {\n\t\t\t\t\taccessKeyId: process.env.AWS_ACCESS_KEY,\n\t\t\t\t\tsecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY\n\t\t\t\t},\n\t\t\t\tregion: 'us-east-1',\n\t\t\t\tapiVersion: '2006-03-01'\n\t\t\t});\n\t\n\t\t\treturn this._s3USEast1;\n\t\t}\n\t}\n}\n\nexport class MethodManager {\n\tprivate _websocketManager: WebSocketManager;\n\tpublic _methods: MethodModel = {};\n\tprivate _mailerSES: nodemailer.Transporter;\n\tprivate _mailerCustom: nodemailer.Transporter;\n\tprivate _aws: AWS;\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\tprivate _isWorkersEnabled = false;\n\tprivate _isWorkerInstance = false;\n\n\tprivate emailQueue: Set<string> = new Set(); // Set to store pending email IDs\n\tprivate isEmailProcessing = false;\n\tprivate readonly _emailProcessingDelayMs = 5000;\n\n\tprivate _debugcallMethodHits = 0;\n\tprivate _debugCallMethodHits = 0;\n\tprivate _debugCallMethodCronJobHits = 0;\n\tprivate _debugSendQueueHits = 0;\n\tprivate _enableDebug = false;\n\n\tpublic clientDir = '';\n\tpublic serverConfig = '';\n\n\tconstructor() {}\n\n\tstatic create(websocketManager: WebSocketManager, monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled, isWorkerInstance) {\n\t\tconst methodManager = new MethodManager();\n\t\tmethodManager.initialize(websocketManager, monitorManagerFunction, isWorkersEnabled, isWorkerInstance);\n\t\treturn methodManager;\n\t}\n\n\tprivate initialize(websocketManager: WebSocketManager, monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled, isWorkerInstance) {\n\t\tthis._websocketManager = websocketManager;\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\t\tthis._isWorkersEnabled = isWorkersEnabled;\n\t\tthis._isWorkerInstance = isWorkerInstance;\n\t\t\n\t\tthis.clientDir = ResolveIOServer.getClientDir();\n\t\tthis.serverConfig = ResolveIOServer.getServerConfig();\n\n\t\t// Fixtures\n\t\tif (!process.env.IS_WORKERS_ENABLED || process.env.IS_WORKERS_ENABLED === 'false' || (process.env.IS_WORKER_INSTANCE === 'true' && process.env.WORKER_INDEX === '0')) {\n\t\t\tif (!process.env.NODE_APP_INSTANCE || process.env.NODE_APP_INSTANCE === '0') {\n\t\t\t\tsetTimeout(async () => {\n\t\t\t\t\tconsole.log(new Date(), 'Start Server Fixture');\n\t\t\t\t\tawait loadServerInit();\n\t\t\t\t\tconsole.log(new Date(), 'End Server Fixture');\n\t\t\t\t}, 5000);\n\t\t\t}\n\t\t}\n\t\t\n\t\tsetImmediate(async () => {\n\t\t\t// Methods\n\t\t\tawait loadServerCronJobs();\n\n\t\t\tloadAccountMethods(this);\n\t\t\tloadAWSMethods(this);\n\t\t\tloadCollectionMethods(this);\n\t\t\tloadCounterMethods(this);\n\t\t\tloadLogMethods(this);\n\t\t\tloadPDFMethods(this);\n\t\t\tloadCronJobMethods(this);\n\t\t\tloadFlagMethods(this);\n\t\t\tloadFlagUpdatesMethods(this);\n\t\t\tloadReportBuilderMethods(this);\n\t\t\tloadSupportMethods(this);\n\t\t\tloadMonitorMethods(this);\n\n\t\t\tlet flag = await Flags.findOne({type: 'Enable Debug'});\n\t\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\n\t\t\tawait this.loadPendingEmails();\n\t\t});\n\t\t\n\t\tthis._aws = new AWS();\n\n\t\tthis._mailerSES = nodemailer.createTransport(sesTransport({\n\t\t\taccessKeyId: process.env.AWS_ACCESS_KEY,\n\t\t\tsecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,\n\t\t\tregion: process.env.AWS_SES_REGION\n\t\t}));\n\t\t\n\t\tif (!ResolveIOServer.getSESMail()) {\n\t\t\tthis._mailerCustom = nodemailer.createTransport({\n\t\t\t\thost: ResolveIOServer.getServerConfig()['MAIL_HOST'], // 'smtp.office365.com', // Office 365 server\n\t\t\t\tport: ResolveIOServer.getServerConfig()['MAIL_PORT'], //587, // secure SMTP\n\t\t\t\tsecure: false, // false for TLS - as a boolean not string - but the default is false so just remove this completely\n\t\t\t\tauth: {\n\t\t\t\t\tuser: ResolveIOServer.getServerConfig()['MAIL_USERNAME'],\n\t\t\t\t\tpass: ResolveIOServer.getServerConfig()['MAIL_PASSWORD']\n\t\t\t\t},\n\t\t\t\ttls: {\n\t\t\t\t\tciphers: 'SSLv3'\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tsetInterval(async () => {\n\t\t\tlet flag = await Flags.findOne({type: 'Enable Debug'});\n\t\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Call Method Internal Hits', this._debugcallMethodHits);\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Call Method Hits', this._debugCallMethodHits);\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Call Method Cron Hits', this._debugCallMethodCronJobHits);\n\t\t\t}\n\n\t\t\tthis._debugcallMethodHits = 0;\n\t\t\tthis._debugCallMethodHits = 0;\n\t\t\tthis._debugCallMethodCronJobHits = 0;\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t}, 60000);\n\n\t\tif (!this._isWorkersEnabled || this._isWorkerInstance) {\n\t\t\tthis.setupEmailWatcher();\n\t\t}\n\t}\n\n\tpublic getMethod(methodName: string): MethodAllModel {\n\t\treturn this._methods[methodName];\n\t}\n\n\t// Add methods to private methods object\n\tpublic methods(method: MethodModel) {\n\t\tthis._methods = Object.assign(this._methods, method);\n\t}\n\n\tpublic async callMethodCron(method: string, ...methodData: any[]) {\n\t\tthis._debugCallMethodCronJobHits += 1;\n\n\t\tconst existingCorrelationId = getCorrelationId();\n\t\tconst correlationId = existingCorrelationId || objectIdHexString();\n\n\t\tconst execute = async () => {\n\t\t\tconst cronMethod = this._methods[method];\n\n\t\t\tif (!cronMethod) {\n\t\t\t\tconsole.log('No Method: ' + method);\n\n\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t'No Method: ' + method,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\tcontext: 'callMethodCron',\n\t\t\t\t\t\t\tmethod\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tthrow new Error('No Method: ' + method);\n\t\t\t}\n\t\t\t\n\t\t\tif ((methodData.length > 1 || methodData[0]) && !cronMethod.skipValidation) {\n\t\t\t\tif (!cronMethod.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Cron Method ' + method);\n\n\t\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t\t'No Check Function For Cron Method ' + method,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\tcontext: 'callMethodCron-validation',\n\t\t\t\t\t\t\t\tmethod\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\n\t\t\t\t\tthrow new Error('No Check Function For Cron Method ' + method);\n\t\t\t\t}\n\t\t\t\telse if (!cronMethod.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Cron Method ' + method);\n\n\t\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t\t'No Check Function For Cron Method ' + method,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\tcontext: 'callMethodCron-validation',\n\t\t\t\t\t\t\t\tmethod\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\n\t\t\t\t\tthrow new Error('No Check Schema For Cron Method ' + method);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tconst valObj = {};\n\t\t\t\t\tconst valKeys = Object.keys(cronMethod.check._schema);\n\n\t\t\t\t\tconst rootKeys = valKeys.filter(a => !a.includes('.'));\n\t\t\t\t\t\n\t\t\t\t\tfor (let i = 0; i < methodData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = methodData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcronMethod.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\tconsole.error(new Date(), 'Error in Cron Method Check (' + method + ')', err);\n\n\t\t\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t\t\t'Match Error On Cron Method ' + method + '\\n\\nData Being Checked\\n' + JSON.stringify(valObj, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(normalizedError, null, 2),\n\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcorrelationId: resolvedCorrelationId,\n\t\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t\tcontext: 'callMethodCron-validation-error',\n\t\t\t\t\t\t\t\t\tmethod\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Cron Method Check (${method}): ${normalizedError.message}`;\n\n\t\t\t\t\t\tthrow normalizedError;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst monitor = this._monitorManagerFunction.startMonitorFunction('Cron Method', method, '', '', methodData);\n\n\t\t\ttry {\n\t\t\t\tconst res = await cronMethod.function.call(Object.assign({}, this, MethodManager.prototype, {id_user: '', user: '', id_ws: ''}), ...methodData);\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t'Error Detected During Cron Method ' + method + ' - (callMethodCron)\\n\\nData \\n' + JSON.stringify(methodData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(normalizedError, null, 2),\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\tcorrelationId: resolvedCorrelationId,\n\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\tcontext: 'callMethodCron-execution',\n\t\t\t\t\t\t\tmethod\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Cron Method (${method}): ${normalizedError.message}`;\n\t\t\t\t\n\t\t\t\tthrow normalizedError;\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t}\n\t\t};\n\n\t\treturn await runWithCorrelationContext(correlationId, execute);\n\t}\n\n\t// Call/run method internal (No Emit on Socket)\n\tpublic async callMethod(methodName: string, ...methodData: any[]): Promise<any> {\n\t\tthis._debugcallMethodHits += 1;\n\n\t\tconst existingCorrelationId = getCorrelationId();\n\t\tconst correlationId = existingCorrelationId || objectIdHexString();\n\n\t\treturn await runWithCorrelationContext(correlationId, async () => await this.callMethodInternal(correlationId, methodName, methodData));\n\t}\n\n\tprivate async callMethodInternal(correlationId: string, methodName: string, methodData: any[]): Promise<any> {\n\t\tconst method = this.getMethod(methodName);\n\n\t\tif (!method) {\n\t\t\tconsole.log('No Method: ' + methodName);\n\t\t\tthrow new Error(`No Method: ${methodName}`);\n\t\t}\n\n\t\tif ((methodData.length > 1 || (methodData[0] && typeof methodData[0] !== 'function')) && !method.skipValidation) {\n\t\t\tif (!method.check) {\n\t\t\t\tconsole.error(new Date(), 'No Check Function For Method ' + methodName);\n\t\t\t\tthrow new Error(`No Check Function For Method: ${methodName}`);\n\t\t\t}\n\t\t\telse if (!method.check._schema) {\n\t\t\t\tconsole.error(new Date(), 'No Check Schema For Method ' + methodName);\n\t\t\t\tthrow new Error(`No Check Schema For Method: ${methodName}`);\n\t\t\t}\n\t\t}\n\n\t\tif (methodName !== 'insertSubscriptionLog' && methodName !== 'getDataURIfromURL' && methodName !== 'processAirdropDistribution' && methodName !== 'incCounter' && methodName !== 'supportCreateBillingUser' && methodName !== 'countCollectionWithQuery') {\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t\t) {\n\t\t\t\tResolveIOServer.getLocalLogManager().writeLog({\n\t\t\t\t\ttype: 'log',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\ttype: 'callMethod',\n\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([methodData])) < 1000000 ? JSON.stringify([methodData], null, 2) : 'Too Big',\n\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\tid_user: this['id_user'] || '',\n\t\t\t\t\t\tuser: this['user'] || '', \n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: '',\n\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tawait Logs.insertOne({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\ttype: 'callMethod',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tid_document: '',\n\t\t\t\t\tpayload: getBinarySize(JSON.stringify([methodData])) < 1000000 ? JSON.stringify([methodData], null, 2) : 'Too Big',\n\t\t\t\t\tmethod: methodName,\n\t\t\t\t\tid_user: this['id_user'] || '',\n\t\t\t\t\tuser: this['user'] || '',\n\t\t\t\t\tmessageId: 0,\n\t\t\t\t\troute: '',\n\t\t\t\t\tclient: 'ResolveIO',\n\t\t\t\t\tinstance: 'backend.resolveio.com',\n\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '',\n\t\t\t\t\tcorrelationId\n\t\t\t\t})\n\t\t\t};\n\t\t}\n\n\t\tconst functionMethodData = typeof(methodData[methodData.length - 1]) === 'function' ? methodData.slice(0, -1) : methodData;\n\n\t\tconst session = ResolveIOServer.getMongoManager().getSession();\n\n\t\tif (!method.bypassSession &&\n\t\t\t!session && \n\t\t\t![\n\t\t\t\t'insertErrorLog', // CIRCULAR LOOP - DO NOT REMOVE\n\t\t\t\t'countWithQuery', // MONGO SESSIONS/TRANSACTIONS DONT WORK WITH COUNTS\n\t\t\t\t'sendEmail' // ALWAYS SEND SO ALWAYS HAVE RECORD - DONT ROLL BACK - BYPASS SESSION\n\t\t\t].includes(methodName) &&\n\t\t\t!methodName.startsWith('monitor-') &&\n\t\t\t!methodName.startsWith('log')\n\t\t) {\n\t\t\tlet monitor = null;\n\t\t\t\n\t\t\treturn ResolveIOServer.getMongoManager().oneTimeTransaction(async () => {\n\t\t\t\t// console.log(new Date(), 'Calling Method - New Session', methodName);\n\n\t\t\t\tmonitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await method.function.call(Object.assign({}, this, MethodManager.prototype), ...functionMethodData);\n\n\t\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\t\tmethodData[methodData.length - 1](null, res);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn res;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tif (err.code === 112 || err.codeName === 'WriteConflict' || err.code === 251 || err.codeName === 'NoSuchTransaction') {\n\t\t\t\t\t\tthrow err; // Write error, retry\n\t\t\t\t\t}\n\n\t\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\t\tconsole.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - New Session', methodName, {\n\t\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\t\tcodeName: normalizedError.codeName,\n\t\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t\t}], null, 2));\n\n\t\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t\t'Error Detected During Method ' + methodName + ' - (callMethod)\\n\\nData \\n' + JSON.stringify(methodData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(normalizedError, null, 2),\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcorrelationId: resolvedCorrelationId,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\tcontext: 'callMethod-new-session',\n\t\t\t\t\t\t\t\tmethodName\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Method With Session (${methodName}) - New Session: ${normalizedError.message}`;\n\n\t\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\t\tmethodData[methodData.length - 1](normalizedError, null);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!process.env.IS_WORKER_INSTANCE) {\n\t\t\t\t\t\tawait this.callMethod(\n\t\t\t\t\t\t\t'insertErrorLog',\n\t\t\t\t\t\t\t`Error in Method: ${methodName}`,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\t\t\tmethodData,\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\t\t\t\t\tcodeName: normalizedError.codeName\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow normalizedError;\n\t\t\t\t}\n\t\t\t\tfinally {\n\t\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\t// console.log(new Date(), 'Calling Method - Existing Session', methodName);\n\n\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);\n\t\t\t\n\t\t\ttry {\n\t\t\t\tlet res = await method.function.call(Object.assign({}, this, MethodManager.prototype), ...functionMethodData);\n\n\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\tmethodData[methodData.length - 1](null, res);\n\t\t\t\t}\n\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tif (err.code === 112 || err.codeName === 'WriteConflict' || err.code === 251 || err.codeName === 'NoSuchTransaction') {\n\t\t\t\t\tthrow err; // Write error, retry\n\t\t\t\t}\n\n\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\tconsole.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - Existing Session', methodName, {\n\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\tcodeName: normalizedError.codeName,\n\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t}], null, 2));\n\n\t\t\t\tawait this.sendEmail(\n\t\t\t\t\t'dev@resolveio.com',\n\t\t\t\t\t'SERVER - Error Detected - ' + ResolveIOServer.getServerConfig()['CLIENT_NAME'],\n\t\t\t\t\t'Error Detected During Method ' + methodName + ' - (callMethod)\\n\\nData \\n' + JSON.stringify(methodData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(normalizedError, null, 2),\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\tcorrelationId: resolvedCorrelationId,\n\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\tcontext: 'callMethod-existing-session',\n\t\t\t\t\t\t\tmethodName\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Method (${methodName}) - Existing Session: ${normalizedError.message}`;\n\t\t\t\t\n\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\tmethodData[methodData.length - 1](normalizedError, null);\n\t\t\t\t}\n\n\t\t\t\tif (!process.env.IS_WORKER_INSTANCE) {\n\t\t\t\t\tawait this.callMethod(\n\t\t\t\t\t\t'insertErrorLog',\n\t\t\t\t\t\t`Error in Method: ${methodName}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\t\tmethodData,\n\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\t\t\t\tcodeName: normalizedError.codeName\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tthrow normalizedError;\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t}\n\t\t}\n\t}\n\n\tsetupEmailWatcher() {\n\t\tconst changeStream = EmailHistories.watchCollection([]);\n\n\t\tchangeStream.on('change', async (change) => {\n\t\t\tif (change.operationType === 'insert' && change.fullDocument && change.fullDocument.status === 'pending') {\n\t\t\t\tthis.emailQueue.add(change.fullDocument._id.toString());\n\t\t\t\tawait this.tryProcessEmail();\n\t\t\t}\n\t\t\telse if (change.operationType === 'update' || change.operationType === 'replace') {\n\t\t\t\tconst updatedEmail = change.fullDocument;\n\t\t\t\tif (updatedEmail && updatedEmail.status !== 'pending' && this.emailQueue.has(updatedEmail._id.toString())) {\n\t\t\t\t\tthis.emailQueue.delete(updatedEmail._id.toString());\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.on('error', async err => {\n\t\t\tconsole.error('Email history changestream error', err);\n\t\t\tawait changeStream.close();\n\t\t})\n\t\t.on('close', () => {\n\t\t\tthis.setupEmailWatcher();\n\t\t});\n\t}\n\n\tasync loadPendingEmails() {\n\t\t// Load any pending emails on startup\n\t\tconst pendingEmails = await EmailHistories.find({ status: 'pending' }, {sort: {_id: 1}});\n\t\tfor (const email of pendingEmails) {\n\t\t\tthis.emailQueue.add(email._id.toString());\n\t\t}\n\t\t// Try to process emails\n\t\tawait this.tryProcessEmail();\n\t}\n\n\tasync tryProcessEmail() {\n\t\tif (this.isEmailProcessing || this.emailQueue.size === 0) {\n\t\t\treturn;\n\t\t}\n\t\n\t\tthis.isEmailProcessing = true;\n\t\n\t\ttry {\n\t\t\twhile (this.emailQueue.size > 0) {\n\t\t\t\tconst emailId = this.emailQueue.values().next().value;\n\t\t\t\tthis.emailQueue.delete(emailId);\n\t\n\t\t\t\tconst pendingEmail = await EmailHistories.findOne(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: emailId,\n\t\t\t\t\t\tstatus: 'pending',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif (!pendingEmail) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet queuedAt: Date;\n\t\t\t\tif (pendingEmail.date instanceof Date) {\n\t\t\t\t\tqueuedAt = pendingEmail.date;\n\t\t\t\t}\n\t\t\t\telse if (pendingEmail.createdAt instanceof Date) {\n\t\t\t\t\tqueuedAt = pendingEmail.createdAt;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tqueuedAt = new Date();\n\t\t\t\t}\n\n\t\t\t\tconst timeSinceQueued = Date.now() - queuedAt.getTime();\n\t\t\t\tconst remainingDelay = this._emailProcessingDelayMs - timeSinceQueued;\n\n\t\t\t\tif (remainingDelay > 0) {\n\t\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, remainingDelay));\n\t\t\t\t}\n\n\t\t\t\tconst emailHistory = await EmailHistories.findOneAndUpdate(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: emailId,\n\t\t\t\t\t\tstatus: 'pending',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$set: { status: 'processing', processingAt: new Date() },\n\t\t\t\t\t}\n\t\t\t\t);\n\t\n\t\t\t\tif (!emailHistory) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\n\t\t\t\t// Fetch and process attachments\n if (emailHistory.attachments && emailHistory.attachments.length > 0) {\n\t\t\t\t\tconst validAttachments: any[] = [];\n\t\t\t\t\tlet attachmentError = false;\n\n\t\t\t\t\tfor (const att of emailHistory.attachments) {\n\t\t\t\t\t\tif (att.path && att.path.startsWith('http')) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst response = await fetch(att.path);\n\t\t\t\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\t\t\t\tattachmentError = true;\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst arrayBuffer = await response.arrayBuffer();\n\t\t\t\t\t\t\t\tconst buffer = Buffer.from(arrayBuffer);\n\n\t\t\t\t\t\t\t\t// Check the size of the attachment\n\t\t\t\t\t\t\t\tconst maxSize = 20 * 1024 * 1024; // 20MB in bytes\n\t\t\t\t\t\t\t\tif (buffer.length <= maxSize) {\n\t\t\t\t\t\t\t\t\t// Attachment is within size limits, include it\n\t\t\t\t\t\t\t\t\tatt.content = buffer;\n\t\t\t\t\t\t\t\t\tdelete att.path;\n\t\t\t\t\t\t\t\t\tvalidAttachments.push(att);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\tconsole.error('Failed to fetch attachment:', err);\n\t\t\t\t\t\t\t\tattachmentError = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tvalidAttachments.push(att);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\temailHistory.attachments = validAttachments;\n\t\t\t\t\tif (attachmentError) {\n\t\t\t\t\t\t\temailHistory.text =\n\t\t\t\t\t\t\t\t\t(typeof emailHistory.text === 'string' ? emailHistory.text : '') +\n\t\t\t\t\t\t\t\t\t'\\n\\nCould not load attachments.';\n\t\t\t\t\t\t\temailHistory.html =\n\t\t\t\t\t\t\t\t\t(typeof emailHistory.html === 'string' ? emailHistory.html : '') +\n\t\t\t\t\t\t\t\t\t'<p>Could not load attachments.</p>';\n\t\t\t\t\t}\n }\n\t\n\t\t\t\t// Prepare email options\n\t\t\t\tconst mailOptions: any = {\n\t\t\t\t\treplyTo: emailHistory.reply_to || (ResolveIOServer.getServerConfig()['MAIL_REPLY_TO'] || undefined),\n\t\t\t\t\tfrom: emailHistory.send_from || ResolveIOServer.getServerConfig().MAIL_FROM,\n\t\t\t\t\tto: emailHistory.email,\n\t\t\t\t\tsubject:\n\t\t\t\t\t\t(ResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/dev\\./) ||\n\t\t\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/www\\.dev\\./)\n\t\t\t\t\t\t\t? '(DEV SERVER) - '\n\t\t\t\t\t\t\t: '') + emailHistory.subject,\n\t\t\t\t\ttext: typeof emailHistory.text === 'string' ? emailHistory.text : '',\n\t\t\t\t\thtml: typeof emailHistory.html === 'string' ? emailHistory.html : '',\n\t\t\t\t\tattachments: emailHistory.attachments || [],\n\t\t\t\t\tforce_ses: emailHistory.force_ses\n\t\t\t\t};\n\t\n\t\t\t\t// Process attachments before sending\n\t\t\t\tif (mailOptions.attachments && mailOptions.attachments.length > 0) {\n\t\t\t\t\tmailOptions.attachments = mailOptions.attachments.map((att) => {\n\t\t\t\t\t\tconst newAtt = { ...att };\n\t\t\t\t\t\t// Handle attachments stored as BinData or Buffer\n\t\t\t\t\t\tif (newAtt.content && typeof newAtt.content === 'object' && !(newAtt.content instanceof Buffer)) {\n\t\t\t\t\t\t\t// Convert MongoDB's Binary data to Buffer\n\t\t\t\t\t\t\tif (newAtt.content._bsontype === 'Binary' && newAtt.content.sub_type === 0) {\n\t\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content.buffer);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t// Handle other types if necessary\n\t\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Handle attachments stored as Base64 strings\n\t\t\t\t\t\telse if (typeof newAtt.content === 'string' && newAtt.encoding === 'base64') {\n\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content, 'base64');\n\t\t\t\t\t\t\tdelete newAtt.encoding;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Ensure the content is a Buffer\n\t\t\t\t\t\telse if (typeof newAtt.content === 'string') {\n\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn newAtt;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\n\t\t\t\t// Send the email\n\t\t\t\t(!mailOptions.force_ses && this._mailerCustom ? this._mailerCustom : this._mailerSES).sendMail(mailOptions, async err => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\tconsole.error('Failed to send email:', err);\n\t\t\t\t\t\t\tawait EmailHistories.updateOne(\n\t\t\t\t\t\t\t\t{ _id: emailHistory._id },\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$set: {\n\t\t\t\t\t\t\t\t\t\tstatus: 'failed',\n\t\t\t\t\t\t\t\t\t\terror: typeof err === 'string' ? err : this.safeStringify(err),\n\t\t\t\t\t\t\t\t\t\tcompletedAt: new Date(),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tif (emailHistory.email === 'dev@resolveio.com') {\n\t\t\t\t\t\t\t\tawait EmailHistories.deleteOne({ _id: emailHistory._id });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tawait EmailHistories.updateOne(\n\t\t\t\t\t\t\t\t\t{ _id: emailHistory._id },\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$set: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\t\t\t\t\t\t\tcompletedAt: new Date(),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (error) {\n\t\t\t\t\t\tconsole.error('Error in sendMail callback:', error);\n\t\t\t\t\t\tawait EmailHistories.updateOne(\n\t\t\t\t\t\t\t{ _id: emailHistory._id },\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$set: {\n\t\t\t\t\t\t\t\t\tstatus: 'failed',\n\t\t\t\t\t\t\t\t\terror: typeof error === 'string' ? error : this.safeStringify(error),\n\t\t\t\t\t\t\t\t\tcompletedAt: new Date(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t} \n\t\t\t\t});\n\t\n\t\t\t\t// Wait for at least one second before sending the next email\n\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000));\n\t\t\t}\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error('Error processing email queue:', err);\n\t\t}\n\t\tfinally {\n\t\t\tthis.isEmailProcessing = false;\n\t\t\t// Check if new emails arrived while processing\n\t\t\tif (this.emailQueue.size > 0) {\n\t\t\t\tawait this.tryProcessEmail();\n\t\t\t}\n\t\t}\n\t}\n\n\tsafeStringify(obj)\n\t{\n\t\ttry\n\t\t{\n\t\t\treturn JSON.stringify(obj, this.getCircularReplacer());\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treturn `Error in JSON stringifying: ${e.message}`;\n\t\t}\n\t}\n\n\tgetCircularReplacer()\n\t{\n\t\tconst seen = new WeakSet();\n\t\treturn (key, value) =>\n\t\t{\n\t\t\tif (typeof value === \"object\" && value !== null)\n\t\t\t{\n\t\t\t\tif (seen.has(value))\n\t\t\t\t{\n\t\t\t\t\treturn \"[Circular]\";\n\t\t\t\t}\n\t\t\t\tseen.add(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t};\n\t}\n\n\tprivate async tryMergeEmailOccurrence(\n\t\temail: string,\n\t\tsubject: string,\n\t\tcorrelationId: string,\n\t\toccurrence: EmailHistoryOccurrence,\n\t\tmeta?: Record<string, any>\n\t): Promise<EmailHistoryModel | null> {\n\t\tconst existing = await EmailHistories.findOne(\n\t\t\t{\n\t\t\t\temail,\n\t\t\t\tcorrelationId,\n\t\t\t\tstatus: 'pending'\n\t\t\t},\n\t\t\t{ sort: { date: 1 } }\n\t\t);\n\n\t\tif (!existing) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst normalizedOccurrences: EmailHistoryOccurrence[] = Array.isArray(existing.occurrences) && existing.occurrences.length\n\t\t\t? existing.occurrences.map((item: EmailHistoryOccurrence) => ({\n\t\t\t\t_id: item._id || objectIdHexString(),\n\t\t\t\tcreatedAt: item.createdAt instanceof Date ? item.createdAt : new Date(item.createdAt),\n\t\t\t\tsubject: item.subject || existing.subject || '',\n\t\t\t\ttext: item.text,\n\t\t\t\thtml: item.html,\n\t\t\t\tmeta: item.meta\n\t\t\t}))\n\t\t\t: [createEmailOccurrence(\n\t\t\t\texisting.subject || '',\n\t\t\t\ttypeof existing.text === 'string' ? existing.text : undefined,\n\t\t\t\ttypeof existing.html === 'string' ? existing.html : undefined,\n\t\t\t\texisting.meta\n\t\t\t)];\n\n\t\tnormalizedOccurrences.push(occurrence);\n\n\t\tconst { text: aggregatedText, html: aggregatedHtml } = formatGroupedEmailContent(correlationId, normalizedOccurrences);\n\n\t\tconst updated = await EmailHistories.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: existing._id,\n\t\t\t\tstatus: 'pending'\n\t\t\t},\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tsubject,\n\t\t\t\t\ttext: aggregatedText,\n\t\t\t\t\thtml: aggregatedHtml,\n\t\t\t\t\toccurrences: normalizedOccurrences,\n\t\t\t\t\tmeta: meta || existing.meta,\n\t\t\t\t\tupdatedAt: new Date()\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ returnDocument: 'after' }\n\t\t);\n\n\t\treturn updated || null;\n\t}\n\n\tpublic async sendEmail(\n\t\tsendTo: string,\n\t\tsubject: string,\n\t\ttext?: string | null,\n\t\thtml?: string | null,\n\t\tattachments?: any[] | null,\n\t\tsend_from?: string | null,\n\t\treply_to?: string | null,\n\t\tforce_ses = false,\n\t\tlocal_override = false,\n\t\toptions?: SendEmailOptions\n\t) {\n\t\t// Modify sendTo in development environments\n\t\tif (\n\t\t\t(ResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/dev\\./) ||\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/www\\.dev\\./) ||\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200') &&\n\t\t\t!sendTo.match(/\\@resolveio\\.com/)\n\t\t) {\n\t\t\tsendTo = 'dev@resolveio.com';\n\t\t}\n\n\t\tconst normalizedSubject = subject || '';\n\t\tconst correlationId = options?.correlationId;\n\t\tconst finalSubject = appendCorrelationIdToSubject(normalizedSubject, correlationId);\n\t\tconst groupByCorrelationId = !!correlationId;\n\t\tconst normalizedText = typeof text === 'string' ? text : '';\n\t\tconst normalizedHtml = typeof html === 'string' ? html : '';\n\t\tconst occurrence = groupByCorrelationId\n\t\t\t? createEmailOccurrence(normalizedSubject, normalizedText, normalizedHtml, options?.meta)\n\t\t\t: null;\n\t\tlet allowGrouping = groupByCorrelationId;\n\n\t\tif (sendTo) {\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200' ||\n\t\t\t\tlocal_override\n\t\t\t) {\n\t\t\t\tlet normalizedAttachments: any[] = [];\n\t\t\t\tif (Array.isArray(attachments)) {\n\t\t\t\t\tnormalizedAttachments = attachments.slice();\n\t\t\t\t}\n\t\t\t\telse if (attachments) {\n\t\t\t\t\tnormalizedAttachments = [attachments];\n\t\t\t\t}\n\n\t\t\t\tnormalizedAttachments = normalizedAttachments.map(att => {\n\t\t\t\t\tconst newAtt = { ...att };\n\t\t\t\t\tif (Buffer.isBuffer(newAtt.content)) {\n\t\t\t\t\t\tnewAtt.content = newAtt.content.toString('base64');\n\t\t\t\t\t\tnewAtt.encoding = 'base64';\n\t\t\t\t\t}\n\t\t\t\t\treturn newAtt;\n\t\t\t\t});\n\n\t\t\t\tif (normalizedAttachments.length > 0) {\n\t\t\t\t\tallowGrouping = false;\n\t\t\t\t}\n\n\t\t\t\tif (allowGrouping && occurrence && correlationId) {\n\t\t\t\t\tconst merged = await this.tryMergeEmailOccurrence(sendTo, finalSubject, correlationId, occurrence, options?.meta);\n\t\t\t\t\tif (merged) {\n\t\t\t\t\t\treturn merged;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst emailHistory: EmailHistoryModel = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tid_user: this['id_user'] || '',\n\t\t\t\t\tuser: this['user'] || '',\n\t\t\t\t\temail: sendTo,\n\t\t\t\t\tsubject: finalSubject,\n\t\t\t\t\ttext: normalizedText,\n\t\t\t\t\thtml: normalizedHtml,\n\t\t\t\t\tattachments: normalizedAttachments,\n\t\t\t\t\tsend_from: send_from || '',\n\t\t\t\t\treply_to: reply_to || '',\n\t\t\t\t\tstatus: 'pending',\n\t\t\t\t\terror: '',\n\t\t\t\t\tforce_ses\n\t\t\t\t};\n\n\t\t\t\tif (allowGrouping && occurrence && correlationId) {\n\t\t\t\t\tconst { text: aggregatedText, html: aggregatedHtml } = formatGroupedEmailContent(correlationId, [occurrence]);\n\t\t\t\t\temailHistory.text = aggregatedText;\n\t\t\t\t\temailHistory.html = aggregatedHtml;\n\t\t\t\t\temailHistory.occurrences = [occurrence];\n\t\t\t\t\temailHistory.correlationId = correlationId;\n\t\t\t\t\tif (options?.meta) {\n\t\t\t\t\t\temailHistory.meta = options.meta;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (correlationId) {\n\t\t\t\t\t\temailHistory.correlationId = correlationId;\n\t\t\t\t\t}\n\t\t\t\t\tif (options?.meta) {\n\t\t\t\t\t\temailHistory.meta = options.meta;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tlet history = await EmailHistories.insertOne(emailHistory);\n\t\t\t\t\treturn history;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tconsole.error('Failed to queue email:', err);\n\t\t\t\t\terr.message = `Failed to queue email: ${err.message}`;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconsole.log(\n\t\t\t\t\t'Send email',\n\t\t\t\t\tsendTo,\n\t\t\t\t\tfinalSubject,\n\t\t\t\t\tnormalizedText,\n\t\t\t\t\tnormalizedHtml,\n\t\t\t\t\tattachments,\n\t\t\t\t\tsend_from,\n\t\t\t\t\tforce_ses,\n\t\t\t\t\tcorrelationId\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tpublic getAWS(): AWS {\n\t\treturn this._aws;\n\t}\n\n\tpublic readFile(fileName) {\n\t\tif (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {\n\t\t\ttry {\n\t\t\t\treturn fs.readFileSync(path.join(__dirname, ('../private/' + fileName)), 'utf-8');\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\terr.message = `Error in readFile: ${err.message}`;\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (fs.existsSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)))) {\n\t\t\t\ttry {\n\t\t\t\t\treturn fs.readFileSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)), 'utf-8');\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.message = `Error in readFile: ${err.message}`;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error ('Error in readFile: File Not Found');\n\t}\n\n\tpublic readImage(fileName) {\n\t\tif (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {\n\t\t\ttry {\n\t\t\t\treturn fs.readFileSync(path.join(__dirname, ('../private/' + fileName)), 'base64');\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\terr.message = `Error in readImage: ${err.message}`;\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (fs.existsSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)))) {\n\t\t\t\ttry {\n\t\t\t\t\treturn fs.readFileSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)), 'base64');\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.message = `Error in readImage: ${err.message}`;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error ('Error in readImage: File Not Found');\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/method.manager.ts"],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G,CAAC,OAAO,GAAG,8BAAuB,GAAG,CAAC,OAAO,CAAE,CAAC;gBACnD,MAAM,GAAG,CAAC;aACV;SACD;aACI;YACJ,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAe,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE;gBACxF,IAAI;oBACH,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAe,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,GAAG,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;iBACvG;gBACD,OAAO,GAAG,EAAE;oBACX,GAAG,CAAC,OAAO,GAAG,8BAAuB,GAAG,CAAC,OAAO,CAAE,CAAC;oBACnD,MAAM,GAAG,CAAC;iBACV;aACD;SACD;QAED,MAAM,IAAI,KAAK,CAAE,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAEM,sCAAc,GAArB;QACC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IACF,oBAAC;AAAD,CAnhCA,AAmhCC,IAAA;AAnhCY,sCAAa","file":"method.manager.js","sourcesContent":["import { S3 } from '@aws-sdk/client-s3';\nimport * as fs from 'fs';\nimport * as nodemailer from 'nodemailer';\nimport * as sesTransport from 'nodemailer-ses-transport';\nimport * as path from 'path';\nimport { EmailHistories } from '../collections/email-history.collection';\nimport { Flags } from '../collections/flag.collection';\nimport { Logs } from '../collections/log.collection';\nimport { loadServerCronJobs } from '../fixtures/cron-jobs';\nimport { loadServerInit } from '../fixtures/init';\nimport { loadAccountMethods } from '../methods/accounts';\nimport { loadAWSMethods } from '../methods/aws';\nimport { loadCollectionMethods } from '../methods/collections';\nimport { loadCounterMethods } from '../methods/counters';\nimport { loadCronJobMethods } from '../methods/cron-jobs';\nimport { loadFlagUpdatesMethods } from '../methods/flag-updates';\nimport { loadFlagMethods } from '../methods/flags';\nimport { loadLogMethods } from '../methods/logs';\nimport { loadMonitorMethods } from '../methods/monitor';\nimport { loadPDFMethods } from '../methods/pdf';\nimport { loadReportBuilderMethods } from '../methods/report-builder';\nimport { loadSupportMethods } from '../methods/support';\nimport { EmailHistoryModel, EmailHistoryOccurrence } from '../models/email-history.model';\nimport { MethodAllModel, MethodModel } from '../models/method.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { getBinarySize, objectIdHexString } from '../util/common';\nimport { ErrorReporter } from '../util/error-reporter';\nimport { ensureErrorWithCorrelation, getCorrelationId, runWithCorrelationContext } from '../util/error-tracking';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { WebSocketManager } from './websocket.manager';\n\ninterface SendEmailOptions {\n\tcorrelationId?: string;\n\tmeta?: Record<string, any>;\n}\n\nfunction appendCorrelationIdToSubject(subject: string, correlationId?: string): string {\n\tif (!correlationId) {\n\t\treturn subject;\n\t}\n\n\tconst correlationTag = `[${correlationId}]`;\n\n\tif (subject && subject.includes(correlationTag)) {\n\t\treturn subject;\n\t}\n\n\treturn `${subject} ${correlationTag}`.trim();\n}\n\nfunction createEmailOccurrence(subject: string, text?: string, html?: string, meta?: Record<string, any>): EmailHistoryOccurrence {\n\treturn {\n\t\t_id: objectIdHexString(),\n\t\tcreatedAt: new Date(),\n\t\tsubject,\n\t\ttext,\n\t\thtml,\n\t\tmeta\n\t};\n}\n\nfunction formatGroupedEmailContent(correlationId: string, occurrences: EmailHistoryOccurrence[]): { text: string; html: string } {\n\tconst lines: string[] = [];\n\tlines.push(`Correlation ID: ${correlationId}`);\n\n\toccurrences.forEach((occurrence, index) => {\n\t\tconst timestamp = occurrence.createdAt instanceof Date ? occurrence.createdAt.toISOString() : new Date(occurrence.createdAt).toISOString();\n\t\tlines.push('');\n\t\tlines.push(`Occurrence #${index + 1} (${timestamp})`);\n\t\tlines.push(`Subject: ${occurrence.subject}`);\n\t\tif (occurrence.text) {\n\t\t\tlines.push(occurrence.text);\n\t\t}\n\t});\n\n\tconst htmlSections = occurrences.map((occurrence, index) => {\n\t\tconst timestamp = occurrence.createdAt instanceof Date ? occurrence.createdAt.toISOString() : new Date(occurrence.createdAt).toISOString();\n\t\tconst escapedText = occurrence.text ? occurrence.text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') : '';\n\t\treturn `<div><h4>Occurrence #${index + 1} (${timestamp})</h4><p><strong>Subject:</strong> ${occurrence.subject}</p>${escapedText ? `<pre>${escapedText}</pre>` : ''}</div>`;\n\t});\n\n\tconst html = [\n\t\t`<p><strong>Correlation ID:</strong> ${correlationId}</p>`,\n\t\t...htmlSections\n\t].join('');\n\n\treturn {\n\t\ttext: lines.join('\\n'),\n\t\thtml\n\t};\n}\n\nexport class AWS {\n\tprivate _s3: S3 = null;\n\tprivate _s3USEast1: S3 = null;\n\n\tconstructor() {}\n\n\tpublic create() {\n\t\tconst aws = new AWS();\n\t\taws.initialize();\n\t\treturn aws;\n\t}\n\n\tprivate initialize() {\n\n\t}\n\n\tpublic s3(): S3 {\n\t\tif (this._s3) {\n\t\t\treturn this._s3;\n\t\t}\n\n\t\tthis._s3 = new S3({\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: process.env.AWS_ACCESS_KEY,\n\t\t\t\tsecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY\n\t\t\t},\n\t\t\tregion: process.env.AWS_REGION,\n\t\t\tapiVersion: '2006-03-01'\n\t\t});\n\n\t\treturn this._s3;\n\t}\n\n\tpublic s3USEast1(): S3 {\n\t\tif (process.env.AWS_REGION === 'us-east-1') {\n\t\t\treturn this.s3();\n\t\t}\n\t\telse {\n\t\t\tif (this._s3USEast1) {\n\t\t\t\treturn this._s3USEast1;\n\t\t\t}\n\t\t\t\n\t\t\tthis._s3USEast1 = new S3({\n\t\t\t\tcredentials: {\n\t\t\t\t\taccessKeyId: process.env.AWS_ACCESS_KEY,\n\t\t\t\t\tsecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY\n\t\t\t\t},\n\t\t\t\tregion: 'us-east-1',\n\t\t\t\tapiVersion: '2006-03-01'\n\t\t\t});\n\t\n\t\t\treturn this._s3USEast1;\n\t\t}\n\t}\n}\n\nexport class MethodManager {\n\tprivate _websocketManager: WebSocketManager;\n\tpublic _methods: MethodModel = {};\n\tprivate _mailerSES: nodemailer.Transporter;\n\tprivate _mailerCustom: nodemailer.Transporter;\n\tprivate _aws: AWS;\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\tprivate _isWorkersEnabled = false;\n\tprivate _isWorkerInstance = false;\n\n\tprivate emailQueue: Set<string> = new Set(); // Set to store pending email IDs\n\tprivate isEmailProcessing = false;\n\tprivate readonly _emailProcessingDelayMs = 5000;\n\n\tprivate _debugcallMethodHits = 0;\n\tprivate _debugCallMethodHits = 0;\n\tprivate _debugCallMethodCronJobHits = 0;\n\tprivate _debugSendQueueHits = 0;\n\tprivate _enableDebug = false;\n\n\tpublic clientDir = '';\n\tpublic serverConfig: Record<string, any> = {};\n\n\tconstructor() {}\n\n\tstatic create(websocketManager: WebSocketManager, monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled, isWorkerInstance) {\n\t\tconst methodManager = new MethodManager();\n\t\tmethodManager.initialize(websocketManager, monitorManagerFunction, isWorkersEnabled, isWorkerInstance);\n\t\treturn methodManager;\n\t}\n\n\tprivate initialize(websocketManager: WebSocketManager, monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled, isWorkerInstance) {\n\t\tthis._websocketManager = websocketManager;\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\t\tthis._isWorkersEnabled = isWorkersEnabled;\n\t\tthis._isWorkerInstance = isWorkerInstance;\n\t\t\n\t\tthis.clientDir = ResolveIOServer.getClientDir();\n\t\tthis.serverConfig = ResolveIOServer.getServerConfig();\n\n\t\t// Fixtures\n\t\tif (!process.env.IS_WORKERS_ENABLED || process.env.IS_WORKERS_ENABLED === 'false' || (process.env.IS_WORKER_INSTANCE === 'true' && process.env.WORKER_INDEX === '0')) {\n\t\t\tif (!process.env.NODE_APP_INSTANCE || process.env.NODE_APP_INSTANCE === '0') {\n\t\t\t\tsetTimeout(async () => {\n\t\t\t\t\tconsole.log(new Date(), 'Start Server Fixture');\n\t\t\t\t\tawait loadServerInit();\n\t\t\t\t\tconsole.log(new Date(), 'End Server Fixture');\n\t\t\t\t}, 5000);\n\t\t\t}\n\t\t}\n\t\t\n\t\tsetImmediate(async () => {\n\t\t\t// Methods\n\t\t\tawait loadServerCronJobs();\n\n\t\t\tloadAccountMethods(this);\n\t\t\tloadAWSMethods(this);\n\t\t\tloadCollectionMethods(this);\n\t\t\tloadCounterMethods(this);\n\t\t\tloadLogMethods(this);\n\t\t\tloadPDFMethods(this);\n\t\t\tloadCronJobMethods(this);\n\t\t\tloadFlagMethods(this);\n\t\t\tloadFlagUpdatesMethods(this);\n\t\t\tloadReportBuilderMethods(this);\n\t\t\tloadSupportMethods(this);\n\t\t\tloadMonitorMethods(this);\n\n\t\t\tlet flag = await Flags.findOne({type: 'Enable Debug'});\n\t\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\n\t\t\tawait this.loadPendingEmails();\n\t\t});\n\t\t\n\t\tthis._aws = new AWS();\n\n\t\tthis._mailerSES = nodemailer.createTransport(sesTransport({\n\t\t\taccessKeyId: process.env.AWS_ACCESS_KEY,\n\t\t\tsecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,\n\t\t\tregion: process.env.AWS_SES_REGION\n\t\t}));\n\t\t\n\t\tif (!ResolveIOServer.getSESMail()) {\n\t\t\tthis._mailerCustom = nodemailer.createTransport({\n\t\t\t\thost: ResolveIOServer.getServerConfig()['MAIL_HOST'], // 'smtp.office365.com', // Office 365 server\n\t\t\t\tport: ResolveIOServer.getServerConfig()['MAIL_PORT'], //587, // secure SMTP\n\t\t\t\tsecure: false, // false for TLS - as a boolean not string - but the default is false so just remove this completely\n\t\t\t\tauth: {\n\t\t\t\t\tuser: ResolveIOServer.getServerConfig()['MAIL_USERNAME'],\n\t\t\t\t\tpass: ResolveIOServer.getServerConfig()['MAIL_PASSWORD']\n\t\t\t\t},\n\t\t\t\ttls: {\n\t\t\t\t\tciphers: 'SSLv3'\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tsetInterval(async () => {\n\t\t\tlet flag = await Flags.findOne({type: 'Enable Debug'});\n\t\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Call Method Internal Hits', this._debugcallMethodHits);\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Call Method Hits', this._debugCallMethodHits);\n\t\t\t\tconsole.log(new Date(), 'Method Manager', 'Call Method Cron Hits', this._debugCallMethodCronJobHits);\n\t\t\t}\n\n\t\t\tthis._debugcallMethodHits = 0;\n\t\t\tthis._debugCallMethodHits = 0;\n\t\t\tthis._debugCallMethodCronJobHits = 0;\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t}, 60000);\n\n\t\tif (!this._isWorkersEnabled || this._isWorkerInstance) {\n\t\t\tthis.setupEmailWatcher();\n\t\t}\n\t}\n\n\tpublic getMethod(methodName: string): MethodAllModel {\n\t\treturn this._methods[methodName];\n\t}\n\n\t// Add methods to private methods object\n\tpublic methods(method: MethodModel) {\n\t\tthis._methods = Object.assign(this._methods, method);\n\t}\n\n\tprivate async reportMethodError(\n\t\tsubject: string,\n\t\tcorrelationId: string,\n\t\tcontext: Record<string, any> | string,\n\t\tmeta: Record<string, any>,\n\t\tstack?: string\n\t) {\n\t\tconst metadata = Object.assign({}, meta || {});\n\t\tif (correlationId && !metadata.correlationId) {\n\t\t\tmetadata.correlationId = correlationId;\n\t\t}\n\n\t\tawait ErrorReporter.report({\n\t\t\tsourceApp: 'method-manager',\n\t\t\tmessage: subject,\n\t\t\tenvironment: this.serverConfig?.ROOT_URL,\n\t\t\tclientSlug: ResolveIOServer.getClientName(),\n\t\t\tclientName: this.serverConfig?.CLIENT_NAME,\n\t\t\tseverity: 'error',\n\t\t\tstack,\n\t\t\tcontext,\n\t\t\tmetadata,\n\t\t\tcorrelationId\n\t\t});\n\t}\n\n\tpublic async callMethodCron(method: string, ...methodData: any[]) {\n\t\tthis._debugCallMethodCronJobHits += 1;\n\n\t\tconst existingCorrelationId = getCorrelationId();\n\t\tconst correlationId = existingCorrelationId || objectIdHexString();\n\n\t\tconst execute = async () => {\n\t\t\tconst cronMethod = this._methods[method];\n\n\t\t\tif (!cronMethod) {\n\t\t\t\tconsole.log('No Method: ' + method);\n\n\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\tcorrelationId,\n\t\t\t\t\t{ message: 'No Method registered for cron execution', method },\n\t\t\t\t\t{ context: 'callMethodCron', method }\n\t\t\t\t);\n\n\t\t\t\tthrow new Error('No Method: ' + method);\n\t\t\t}\n\t\t\t\n\t\t\tif ((methodData.length > 1 || methodData[0]) && !cronMethod.skipValidation) {\n\t\t\t\tif (!cronMethod.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Cron Method ' + method);\n\n\t\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t{ message: 'Missing check function for cron method', method },\n\t\t\t\t\t\t{ context: 'callMethodCron-validation', method }\n\t\t\t\t\t);\n\t\t\n\t\t\t\t\tthrow new Error('No Check Function For Cron Method ' + method);\n\t\t\t\t}\n\t\t\t\telse if (!cronMethod.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Cron Method ' + method);\n\n\t\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t{ message: 'Missing check schema for cron method', method },\n\t\t\t\t\t\t{ context: 'callMethodCron-validation', method }\n\t\t\t\t\t);\n\t\t\n\t\t\t\t\tthrow new Error('No Check Schema For Cron Method ' + method);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tconst valObj = {};\n\t\t\t\t\tconst valKeys = Object.keys(cronMethod.check._schema);\n\n\t\t\t\t\tconst rootKeys = valKeys.filter(a => !a.includes('.'));\n\t\t\t\t\t\n\t\t\t\t\tfor (let i = 0; i < methodData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = methodData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcronMethod.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Cron Method Check (' + method + ')', err);\n\n\t\t\t\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\t\t\tresolvedCorrelationId,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmessage: 'Match error on cron method',\n\t\t\t\t\t\t\t\t\tmethod,\n\t\t\t\t\t\t\t\t\tdata: valObj,\n\t\t\t\t\t\t\t\t\tvalidationError: normalizedError\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{ context: 'callMethodCron-validation-error', method },\n\t\t\t\t\t\t\t\tnormalizedError.stack\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Cron Method Check (${method}): ${normalizedError.message}`;\n\n\t\t\t\t\t\t\tthrow normalizedError;\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst monitor = this._monitorManagerFunction.startMonitorFunction('Cron Method', method, '', '', methodData);\n\n\t\t\ttry {\n\t\t\t\tconst res = await cronMethod.function.call(Object.assign({}, this, MethodManager.prototype, {id_user: '', user: '', id_ws: ''}), ...methodData);\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\tresolvedCorrelationId,\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: 'Error detected during cron method execution',\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tdata: methodData,\n\t\t\t\t\t\terror: normalizedError\n\t\t\t\t\t},\n\t\t\t\t\t{ context: 'callMethodCron-execution', method },\n\t\t\t\t\tnormalizedError.stack\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Cron Method (${method}): ${normalizedError.message}`;\n\t\t\t\t\n\t\t\t\tthrow normalizedError;\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t}\n\t\t};\n\n\t\treturn await runWithCorrelationContext(correlationId, execute);\n\t}\n\n\t// Call/run method internal (No Emit on Socket)\n\tpublic async callMethod(methodName: string, ...methodData: any[]): Promise<any> {\n\t\tthis._debugcallMethodHits += 1;\n\n\t\tconst existingCorrelationId = getCorrelationId();\n\t\tconst correlationId = existingCorrelationId || objectIdHexString();\n\n\t\treturn await runWithCorrelationContext(correlationId, async () => await this.callMethodInternal(correlationId, methodName, methodData));\n\t}\n\n\tprivate async callMethodInternal(correlationId: string, methodName: string, methodData: any[]): Promise<any> {\n\t\tconst method = this.getMethod(methodName);\n\n\t\tif (!method) {\n\t\t\tconsole.log('No Method: ' + methodName);\n\t\t\tthrow new Error(`No Method: ${methodName}`);\n\t\t}\n\n\t\tif ((methodData.length > 1 || (methodData[0] && typeof methodData[0] !== 'function')) && !method.skipValidation) {\n\t\t\tif (!method.check) {\n\t\t\t\tconsole.error(new Date(), 'No Check Function For Method ' + methodName);\n\t\t\t\tthrow new Error(`No Check Function For Method: ${methodName}`);\n\t\t\t}\n\t\t\telse if (!method.check._schema) {\n\t\t\t\tconsole.error(new Date(), 'No Check Schema For Method ' + methodName);\n\t\t\t\tthrow new Error(`No Check Schema For Method: ${methodName}`);\n\t\t\t}\n\t\t}\n\n\t\tif (methodName !== 'insertSubscriptionLog' && methodName !== 'getDataURIfromURL' && methodName !== 'processAirdropDistribution' && methodName !== 'incCounter' && methodName !== 'supportCreateBillingUser' && methodName !== 'countCollectionWithQuery') {\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t\t) {\n\t\t\t\tResolveIOServer.getLocalLogManager().writeLog({\n\t\t\t\t\ttype: 'log',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\ttype: 'callMethod',\n\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([methodData])) < 1000000 ? JSON.stringify([methodData], null, 2) : 'Too Big',\n\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\tid_user: this['id_user'] || '',\n\t\t\t\t\t\tuser: this['user'] || '', \n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: '',\n\t\t\t\t\t\tcorrelationId\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tawait Logs.insertOne({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\ttype: 'callMethod',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tid_document: '',\n\t\t\t\t\tpayload: getBinarySize(JSON.stringify([methodData])) < 1000000 ? JSON.stringify([methodData], null, 2) : 'Too Big',\n\t\t\t\t\tmethod: methodName,\n\t\t\t\t\tid_user: this['id_user'] || '',\n\t\t\t\t\tuser: this['user'] || '',\n\t\t\t\t\tmessageId: 0,\n\t\t\t\t\troute: '',\n\t\t\t\t\tclient: 'ResolveIO',\n\t\t\t\t\tinstance: 'backend.resolveio.com',\n\t\t\t\t\tinstance_index: process.env.NODE_APP_INSTANCE || '',\n\t\t\t\t\tcorrelationId\n\t\t\t\t})\n\t\t\t};\n\t\t}\n\n\t\tconst functionMethodData = typeof(methodData[methodData.length - 1]) === 'function' ? methodData.slice(0, -1) : methodData;\n\n\t\tconst session = ResolveIOServer.getMongoManager().getSession();\n\n\t\tif (!method.bypassSession &&\n\t\t\t!session && \n\t\t\t![\n\t\t\t\t'insertErrorLog', // CIRCULAR LOOP - DO NOT REMOVE\n\t\t\t\t'countWithQuery', // MONGO SESSIONS/TRANSACTIONS DONT WORK WITH COUNTS\n\t\t\t\t'sendEmail' // ALWAYS SEND SO ALWAYS HAVE RECORD - DONT ROLL BACK - BYPASS SESSION\n\t\t\t].includes(methodName) &&\n\t\t\t!methodName.startsWith('monitor-') &&\n\t\t\t!methodName.startsWith('log')\n\t\t) {\n\t\t\tlet monitor = null;\n\t\t\t\n\t\t\treturn ResolveIOServer.getMongoManager().oneTimeTransaction(async () => {\n\t\t\t\t// console.log(new Date(), 'Calling Method - New Session', methodName);\n\n\t\t\t\tmonitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await method.function.call(Object.assign({}, this, MethodManager.prototype), ...functionMethodData);\n\n\t\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\t\tmethodData[methodData.length - 1](null, res);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn res;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tif (err.code === 112 || err.codeName === 'WriteConflict' || err.code === 251 || err.codeName === 'NoSuchTransaction') {\n\t\t\t\t\t\tthrow err; // Write error, retry\n\t\t\t\t\t}\n\n\t\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\t\tconsole.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - New Session', methodName, {\n\t\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\t\tcodeName: normalizedError.codeName,\n\t\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t\t}], null, 2));\n\n\t\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\t\tresolvedCorrelationId,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmessage: 'Error detected during method execution (new session)',\n\t\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\t\tdata: methodData,\n\t\t\t\t\t\t\terror: normalizedError\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ context: 'callMethod-new-session', methodName },\n\t\t\t\t\t\tnormalizedError.stack\n\t\t\t\t\t);\n\t\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Method With Session (${methodName}) - New Session: ${normalizedError.message}`;\n\n\t\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\t\tmethodData[methodData.length - 1](normalizedError, null);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!process.env.IS_WORKER_INSTANCE) {\n\t\t\t\t\t\tawait this.callMethod(\n\t\t\t\t\t\t\t'insertErrorLog',\n\t\t\t\t\t\t\t`Error in Method: ${methodName}`,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\t\t\tmethodData,\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\t\t\t\t\tcodeName: normalizedError.codeName\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow normalizedError;\n\t\t\t\t}\n\t\t\t\tfinally {\n\t\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\t// console.log(new Date(), 'Calling Method - Existing Session', methodName);\n\n\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);\n\t\t\t\n\t\t\ttry {\n\t\t\t\tlet res = await method.function.call(Object.assign({}, this, MethodManager.prototype), ...functionMethodData);\n\n\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\tmethodData[methodData.length - 1](null, res);\n\t\t\t\t}\n\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tif (err.code === 112 || err.codeName === 'WriteConflict' || err.code === 251 || err.codeName === 'NoSuchTransaction') {\n\t\t\t\t\tthrow err; // Write error, retry\n\t\t\t\t}\n\n\t\t\t\tconst { error: normalizedError, correlationId: resolvedCorrelationId } = ensureErrorWithCorrelation(err, correlationId);\n\n\t\t\t\tconsole.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - Existing Session', methodName, {\n\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\tcodeName: normalizedError.codeName,\n\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t}], null, 2));\n\n\t\t\t\tawait this.reportMethodError(\n\t\t\t\t\t'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],\n\t\t\t\t\tresolvedCorrelationId,\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: 'Error detected during method execution (existing session)',\n\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\tdata: methodData,\n\t\t\t\t\t\terror: normalizedError\n\t\t\t\t\t},\n\t\t\t\t\t{ context: 'callMethod-existing-session', methodName },\n\t\t\t\t\tnormalizedError.stack\n\t\t\t\t);\n\t\t\t\tnormalizedError.message = `${new Date().toISOString()} - Error in Method (${methodName}) - Existing Session: ${normalizedError.message}`;\n\t\t\t\t\n\t\t\t\tif (methodData[methodData.length - 1] && typeof(methodData[methodData.length - 1]) === 'function') {\n\t\t\t\t\tmethodData[methodData.length - 1](normalizedError, null);\n\t\t\t\t}\n\n\t\t\t\tif (!process.env.IS_WORKER_INSTANCE) {\n\t\t\t\t\tawait this.callMethod(\n\t\t\t\t\t\t'insertErrorLog',\n\t\t\t\t\t\t`Error in Method: ${methodName}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmethod: methodName,\n\t\t\t\t\t\t\tmethodData,\n\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\tmessage: normalizedError.message,\n\t\t\t\t\t\t\t\tstack: normalizedError.stack,\n\t\t\t\t\t\t\t\tcode: normalizedError.code,\n\t\t\t\t\t\t\t\tcodeName: normalizedError.codeName\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcorrelationId: resolvedCorrelationId\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tthrow normalizedError;\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t}\n\t\t}\n\t}\n\n\tsetupEmailWatcher() {\n\t\tconst changeStream = EmailHistories.watchCollection([]);\n\n\t\tchangeStream.on('change', async (change) => {\n\t\t\tif (change.operationType === 'insert' && change.fullDocument && change.fullDocument.status === 'pending') {\n\t\t\t\tthis.emailQueue.add(change.fullDocument._id.toString());\n\t\t\t\tawait this.tryProcessEmail();\n\t\t\t}\n\t\t\telse if (change.operationType === 'update' || change.operationType === 'replace') {\n\t\t\t\tconst updatedEmail = change.fullDocument;\n\t\t\t\tif (updatedEmail && updatedEmail.status !== 'pending' && this.emailQueue.has(updatedEmail._id.toString())) {\n\t\t\t\t\tthis.emailQueue.delete(updatedEmail._id.toString());\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.on('error', async err => {\n\t\t\tconsole.error('Email history changestream error', err);\n\t\t\tawait changeStream.close();\n\t\t})\n\t\t.on('close', () => {\n\t\t\tthis.setupEmailWatcher();\n\t\t});\n\t}\n\n\tasync loadPendingEmails() {\n\t\t// Load any pending emails on startup\n\t\tconst pendingEmails = await EmailHistories.find({ status: 'pending' }, {sort: {_id: 1}});\n\t\tfor (const email of pendingEmails) {\n\t\t\tthis.emailQueue.add(email._id.toString());\n\t\t}\n\t\t// Try to process emails\n\t\tawait this.tryProcessEmail();\n\t}\n\n\tasync tryProcessEmail() {\n\t\tif (this.isEmailProcessing || this.emailQueue.size === 0) {\n\t\t\treturn;\n\t\t}\n\t\n\t\tthis.isEmailProcessing = true;\n\t\n\t\ttry {\n\t\t\twhile (this.emailQueue.size > 0) {\n\t\t\t\tconst emailId = this.emailQueue.values().next().value;\n\t\t\t\tthis.emailQueue.delete(emailId);\n\t\n\t\t\t\tconst pendingEmail = await EmailHistories.findOne(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: emailId,\n\t\t\t\t\t\tstatus: 'pending',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif (!pendingEmail) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet queuedAt: Date;\n\t\t\t\tif (pendingEmail.date instanceof Date) {\n\t\t\t\t\tqueuedAt = pendingEmail.date;\n\t\t\t\t}\n\t\t\t\telse if (pendingEmail.createdAt instanceof Date) {\n\t\t\t\t\tqueuedAt = pendingEmail.createdAt;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tqueuedAt = new Date();\n\t\t\t\t}\n\n\t\t\t\tconst timeSinceQueued = Date.now() - queuedAt.getTime();\n\t\t\t\tconst remainingDelay = this._emailProcessingDelayMs - timeSinceQueued;\n\n\t\t\t\tif (remainingDelay > 0) {\n\t\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, remainingDelay));\n\t\t\t\t}\n\n\t\t\t\tconst emailHistory = await EmailHistories.findOneAndUpdate(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: emailId,\n\t\t\t\t\t\tstatus: 'pending',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$set: { status: 'processing', processingAt: new Date() },\n\t\t\t\t\t}\n\t\t\t\t);\n\t\n\t\t\t\tif (!emailHistory) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\n\t\t\t\t// Fetch and process attachments\n if (emailHistory.attachments && emailHistory.attachments.length > 0) {\n\t\t\t\t\tconst validAttachments: any[] = [];\n\t\t\t\t\tlet attachmentError = false;\n\n\t\t\t\t\tfor (const att of emailHistory.attachments) {\n\t\t\t\t\t\tif (att.path && att.path.startsWith('http')) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst response = await fetch(att.path);\n\t\t\t\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\t\t\t\tattachmentError = true;\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst arrayBuffer = await response.arrayBuffer();\n\t\t\t\t\t\t\t\tconst buffer = Buffer.from(arrayBuffer);\n\n\t\t\t\t\t\t\t\t// Check the size of the attachment\n\t\t\t\t\t\t\t\tconst maxSize = 20 * 1024 * 1024; // 20MB in bytes\n\t\t\t\t\t\t\t\tif (buffer.length <= maxSize) {\n\t\t\t\t\t\t\t\t\t// Attachment is within size limits, include it\n\t\t\t\t\t\t\t\t\tatt.content = buffer;\n\t\t\t\t\t\t\t\t\tdelete att.path;\n\t\t\t\t\t\t\t\t\tvalidAttachments.push(att);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\tconsole.error('Failed to fetch attachment:', err);\n\t\t\t\t\t\t\t\tattachmentError = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tvalidAttachments.push(att);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\temailHistory.attachments = validAttachments;\n\t\t\t\t\tif (attachmentError) {\n\t\t\t\t\t\t\temailHistory.text =\n\t\t\t\t\t\t\t\t\t(typeof emailHistory.text === 'string' ? emailHistory.text : '') +\n\t\t\t\t\t\t\t\t\t'\\n\\nCould not load attachments.';\n\t\t\t\t\t\t\temailHistory.html =\n\t\t\t\t\t\t\t\t\t(typeof emailHistory.html === 'string' ? emailHistory.html : '') +\n\t\t\t\t\t\t\t\t\t'<p>Could not load attachments.</p>';\n\t\t\t\t\t}\n }\n\t\n\t\t\t\t// Prepare email options\n\t\t\t\tconst mailOptions: any = {\n\t\t\t\t\treplyTo: emailHistory.reply_to || (ResolveIOServer.getServerConfig()['MAIL_REPLY_TO'] || undefined),\n\t\t\t\t\tfrom: emailHistory.send_from || ResolveIOServer.getServerConfig().MAIL_FROM,\n\t\t\t\t\tto: emailHistory.email,\n\t\t\t\t\tsubject:\n\t\t\t\t\t\t(ResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/dev\\./) ||\n\t\t\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/www\\.dev\\./)\n\t\t\t\t\t\t\t? '(DEV SERVER) - '\n\t\t\t\t\t\t\t: '') + emailHistory.subject,\n\t\t\t\t\ttext: typeof emailHistory.text === 'string' ? emailHistory.text : '',\n\t\t\t\t\thtml: typeof emailHistory.html === 'string' ? emailHistory.html : '',\n\t\t\t\t\tattachments: emailHistory.attachments || [],\n\t\t\t\t\tforce_ses: emailHistory.force_ses\n\t\t\t\t};\n\t\n\t\t\t\t// Process attachments before sending\n\t\t\t\tif (mailOptions.attachments && mailOptions.attachments.length > 0) {\n\t\t\t\t\tmailOptions.attachments = mailOptions.attachments.map((att) => {\n\t\t\t\t\t\tconst newAtt = { ...att };\n\t\t\t\t\t\t// Handle attachments stored as BinData or Buffer\n\t\t\t\t\t\tif (newAtt.content && typeof newAtt.content === 'object' && !(newAtt.content instanceof Buffer)) {\n\t\t\t\t\t\t\t// Convert MongoDB's Binary data to Buffer\n\t\t\t\t\t\t\tif (newAtt.content._bsontype === 'Binary' && newAtt.content.sub_type === 0) {\n\t\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content.buffer);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t// Handle other types if necessary\n\t\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Handle attachments stored as Base64 strings\n\t\t\t\t\t\telse if (typeof newAtt.content === 'string' && newAtt.encoding === 'base64') {\n\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content, 'base64');\n\t\t\t\t\t\t\tdelete newAtt.encoding;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Ensure the content is a Buffer\n\t\t\t\t\t\telse if (typeof newAtt.content === 'string') {\n\t\t\t\t\t\t\tnewAtt.content = Buffer.from(newAtt.content);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn newAtt;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\n\t\t\t\t// Send the email\n\t\t\t\t(!mailOptions.force_ses && this._mailerCustom ? this._mailerCustom : this._mailerSES).sendMail(mailOptions, async err => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\tconsole.error('Failed to send email:', err);\n\t\t\t\t\t\t\tawait EmailHistories.updateOne(\n\t\t\t\t\t\t\t\t{ _id: emailHistory._id },\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$set: {\n\t\t\t\t\t\t\t\t\t\tstatus: 'failed',\n\t\t\t\t\t\t\t\t\t\terror: typeof err === 'string' ? err : this.safeStringify(err),\n\t\t\t\t\t\t\t\t\t\tcompletedAt: new Date(),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tif (emailHistory.email === 'dev@resolveio.com') {\n\t\t\t\t\t\t\t\tawait EmailHistories.deleteOne({ _id: emailHistory._id });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tawait EmailHistories.updateOne(\n\t\t\t\t\t\t\t\t\t{ _id: emailHistory._id },\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$set: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\t\t\t\t\t\t\tcompletedAt: new Date(),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (error) {\n\t\t\t\t\t\tconsole.error('Error in sendMail callback:', error);\n\t\t\t\t\t\tawait EmailHistories.updateOne(\n\t\t\t\t\t\t\t{ _id: emailHistory._id },\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$set: {\n\t\t\t\t\t\t\t\t\tstatus: 'failed',\n\t\t\t\t\t\t\t\t\terror: typeof error === 'string' ? error : this.safeStringify(error),\n\t\t\t\t\t\t\t\t\tcompletedAt: new Date(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t} \n\t\t\t\t});\n\t\n\t\t\t\t// Wait for at least one second before sending the next email\n\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000));\n\t\t\t}\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error('Error processing email queue:', err);\n\t\t}\n\t\tfinally {\n\t\t\tthis.isEmailProcessing = false;\n\t\t\t// Check if new emails arrived while processing\n\t\t\tif (this.emailQueue.size > 0) {\n\t\t\t\tawait this.tryProcessEmail();\n\t\t\t}\n\t\t}\n\t}\n\n\tsafeStringify(obj)\n\t{\n\t\ttry\n\t\t{\n\t\t\treturn JSON.stringify(obj, this.getCircularReplacer());\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treturn `Error in JSON stringifying: ${e.message}`;\n\t\t}\n\t}\n\n\tgetCircularReplacer()\n\t{\n\t\tconst seen = new WeakSet();\n\t\treturn (key, value) =>\n\t\t{\n\t\t\tif (typeof value === \"object\" && value !== null)\n\t\t\t{\n\t\t\t\tif (seen.has(value))\n\t\t\t\t{\n\t\t\t\t\treturn \"[Circular]\";\n\t\t\t\t}\n\t\t\t\tseen.add(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t};\n\t}\n\n\tprivate async tryMergeEmailOccurrence(\n\t\temail: string,\n\t\tsubject: string,\n\t\tcorrelationId: string,\n\t\toccurrence: EmailHistoryOccurrence,\n\t\tmeta?: Record<string, any>\n\t): Promise<EmailHistoryModel | null> {\n\t\tconst existing = await EmailHistories.findOne(\n\t\t\t{\n\t\t\t\temail,\n\t\t\t\tcorrelationId,\n\t\t\t\tstatus: 'pending'\n\t\t\t},\n\t\t\t{ sort: { date: 1 } }\n\t\t);\n\n\t\tif (!existing) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst normalizedOccurrences: EmailHistoryOccurrence[] = Array.isArray(existing.occurrences) && existing.occurrences.length\n\t\t\t? existing.occurrences.map((item: EmailHistoryOccurrence) => ({\n\t\t\t\t_id: item._id || objectIdHexString(),\n\t\t\t\tcreatedAt: item.createdAt instanceof Date ? item.createdAt : new Date(item.createdAt),\n\t\t\t\tsubject: item.subject || existing.subject || '',\n\t\t\t\ttext: item.text,\n\t\t\t\thtml: item.html,\n\t\t\t\tmeta: item.meta\n\t\t\t}))\n\t\t\t: [createEmailOccurrence(\n\t\t\t\texisting.subject || '',\n\t\t\t\ttypeof existing.text === 'string' ? existing.text : undefined,\n\t\t\t\ttypeof existing.html === 'string' ? existing.html : undefined,\n\t\t\t\texisting.meta\n\t\t\t)];\n\n\t\tnormalizedOccurrences.push(occurrence);\n\n\t\tconst { text: aggregatedText, html: aggregatedHtml } = formatGroupedEmailContent(correlationId, normalizedOccurrences);\n\n\t\tconst updated = await EmailHistories.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: existing._id,\n\t\t\t\tstatus: 'pending'\n\t\t\t},\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tsubject,\n\t\t\t\t\ttext: aggregatedText,\n\t\t\t\t\thtml: aggregatedHtml,\n\t\t\t\t\toccurrences: normalizedOccurrences,\n\t\t\t\t\tmeta: meta || existing.meta,\n\t\t\t\t\tupdatedAt: new Date()\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ returnDocument: 'after' }\n\t\t);\n\n\t\treturn updated || null;\n\t}\n\n\tpublic async sendEmail(\n\t\tsendTo: string,\n\t\tsubject: string,\n\t\ttext?: string | null,\n\t\thtml?: string | null,\n\t\tattachments?: any[] | null,\n\t\tsend_from?: string | null,\n\t\treply_to?: string | null,\n\t\tforce_ses = false,\n\t\tlocal_override = false,\n\t\toptions?: SendEmailOptions\n\t) {\n\t\t// Modify sendTo in development environments\n\t\tif (\n\t\t\t(ResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/dev\\./) ||\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'].match(/https:\\/\\/www\\.dev\\./) ||\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200') &&\n\t\t\t!sendTo.match(/\\@resolveio\\.com/)\n\t\t) {\n\t\t\tsendTo = 'dev@resolveio.com';\n\t\t}\n\n\t\tconst normalizedSubject = subject || '';\n\t\tconst correlationId = options?.correlationId;\n\t\tconst finalSubject = appendCorrelationIdToSubject(normalizedSubject, correlationId);\n\t\tconst groupByCorrelationId = !!correlationId;\n\t\tconst normalizedText = typeof text === 'string' ? text : '';\n\t\tconst normalizedHtml = typeof html === 'string' ? html : '';\n\t\tconst occurrence = groupByCorrelationId\n\t\t\t? createEmailOccurrence(normalizedSubject, normalizedText, normalizedHtml, options?.meta)\n\t\t\t: null;\n\t\tlet allowGrouping = groupByCorrelationId;\n\n\t\tif (sendTo) {\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200' ||\n\t\t\t\tlocal_override\n\t\t\t) {\n\t\t\t\tlet normalizedAttachments: any[] = [];\n\t\t\t\tif (Array.isArray(attachments)) {\n\t\t\t\t\tnormalizedAttachments = attachments.slice();\n\t\t\t\t}\n\t\t\t\telse if (attachments) {\n\t\t\t\t\tnormalizedAttachments = [attachments];\n\t\t\t\t}\n\n\t\t\t\tnormalizedAttachments = normalizedAttachments.map(att => {\n\t\t\t\t\tconst newAtt = { ...att };\n\t\t\t\t\tif (Buffer.isBuffer(newAtt.content)) {\n\t\t\t\t\t\tnewAtt.content = newAtt.content.toString('base64');\n\t\t\t\t\t\tnewAtt.encoding = 'base64';\n\t\t\t\t\t}\n\t\t\t\t\treturn newAtt;\n\t\t\t\t});\n\n\t\t\t\tif (normalizedAttachments.length > 0) {\n\t\t\t\t\tallowGrouping = false;\n\t\t\t\t}\n\n\t\t\t\tif (allowGrouping && occurrence && correlationId) {\n\t\t\t\t\tconst merged = await this.tryMergeEmailOccurrence(sendTo, finalSubject, correlationId, occurrence, options?.meta);\n\t\t\t\t\tif (merged) {\n\t\t\t\t\t\treturn merged;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst emailHistory: EmailHistoryModel = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tid_user: this['id_user'] || '',\n\t\t\t\t\tuser: this['user'] || '',\n\t\t\t\t\temail: sendTo,\n\t\t\t\t\tsubject: finalSubject,\n\t\t\t\t\ttext: normalizedText,\n\t\t\t\t\thtml: normalizedHtml,\n\t\t\t\t\tattachments: normalizedAttachments,\n\t\t\t\t\tsend_from: send_from || '',\n\t\t\t\t\treply_to: reply_to || '',\n\t\t\t\t\tstatus: 'pending',\n\t\t\t\t\terror: '',\n\t\t\t\t\tforce_ses\n\t\t\t\t};\n\n\t\t\t\tif (allowGrouping && occurrence && correlationId) {\n\t\t\t\t\tconst { text: aggregatedText, html: aggregatedHtml } = formatGroupedEmailContent(correlationId, [occurrence]);\n\t\t\t\t\temailHistory.text = aggregatedText;\n\t\t\t\t\temailHistory.html = aggregatedHtml;\n\t\t\t\t\temailHistory.occurrences = [occurrence];\n\t\t\t\t\temailHistory.correlationId = correlationId;\n\t\t\t\t\tif (options?.meta) {\n\t\t\t\t\t\temailHistory.meta = options.meta;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (correlationId) {\n\t\t\t\t\t\temailHistory.correlationId = correlationId;\n\t\t\t\t\t}\n\t\t\t\t\tif (options?.meta) {\n\t\t\t\t\t\temailHistory.meta = options.meta;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tlet history = await EmailHistories.insertOne(emailHistory);\n\t\t\t\t\treturn history;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tconsole.error('Failed to queue email:', err);\n\t\t\t\t\terr.message = `Failed to queue email: ${err.message}`;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconsole.log(\n\t\t\t\t\t'Send email',\n\t\t\t\t\tsendTo,\n\t\t\t\t\tfinalSubject,\n\t\t\t\t\tnormalizedText,\n\t\t\t\t\tnormalizedHtml,\n\t\t\t\t\tattachments,\n\t\t\t\t\tsend_from,\n\t\t\t\t\tforce_ses,\n\t\t\t\t\tcorrelationId\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tpublic getAWS(): AWS {\n\t\treturn this._aws;\n\t}\n\n\tpublic readFile(fileName) {\n\t\tif (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {\n\t\t\ttry {\n\t\t\t\treturn fs.readFileSync(path.join(__dirname, ('../private/' + fileName)), 'utf-8');\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\terr.message = `Error in readFile: ${err.message}`;\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (fs.existsSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)))) {\n\t\t\t\ttry {\n\t\t\t\t\treturn fs.readFileSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)), 'utf-8');\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.message = `Error in readFile: ${err.message}`;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error ('Error in readFile: File Not Found');\n\t}\n\n\tpublic readImage(fileName) {\n\t\tif (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {\n\t\t\ttry {\n\t\t\t\treturn fs.readFileSync(path.join(__dirname, ('../private/' + fileName)), 'base64');\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\terr.message = `Error in readImage: ${err.message}`;\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (fs.existsSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)))) {\n\t\t\t\ttry {\n\t\t\t\t\treturn fs.readFileSync(path.join(ResolveIOServer.getClientDir(), ('./private/' + fileName)), 'base64');\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.message = `Error in readImage: ${err.message}`;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error ('Error in readImage: File Not Found');\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n}\n"]}
|