@resolveio/server-lib 22.2.17 → 22.2.19

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.
@@ -82,6 +82,7 @@ export declare class ErrorAutoFixManager {
82
82
  private resolveEnvironmentForTask;
83
83
  private buildEmailFromReport;
84
84
  private classifyEmail;
85
+ private isMongoOriginError;
85
86
  private generateRawEmailHash;
86
87
  private generateIssueHash;
87
88
  private normalizeTextForHash;
@@ -144,6 +144,21 @@ var INFRA_SUBJECT_KEYWORDS = [
144
144
  'high cpu usage',
145
145
  'high ram usage'
146
146
  ];
147
+ var MONGO_SOURCE_KEYWORDS = [
148
+ 'mongo-explorer',
149
+ 'mongo explorer',
150
+ 'mongo-manager',
151
+ 'mongo manager',
152
+ 'mongomanager',
153
+ 'mongodb'
154
+ ];
155
+ var MONGO_TEXT_PATTERNS = [
156
+ /\[mongo\]/i,
157
+ /\bmongo(?:db)?\s+(?:server\s+)?error\b/i,
158
+ /\bmongoservererror\b/i,
159
+ /\bmongonetwork(?:timeout)?error\b/i,
160
+ /\bmongonetworktimeouterror\b/i
161
+ ];
147
162
  var DEFAULT_ERROR_ALERT_EMAIL = 'dev@resolveio.com';
148
163
  var MAX_LOCAL_NOTIFICATION_USERS = 5000;
149
164
  var LIBRARY_MARKER_PATTERNS = [
@@ -534,6 +549,14 @@ var ErrorAutoFixManager = /** @class */ (function () {
534
549
  (normalizedBody.includes('auto-fix workflow') || normalizedBody.includes('autofix workflow'))) {
535
550
  return { source: 'noise', skip: true, reason: 'AutoFix status notification' };
536
551
  }
552
+ if (this.isMongoOriginError(email)) {
553
+ return {
554
+ source: 'infrastructure',
555
+ skip: true,
556
+ reason: 'Mongo-origin error ignored for auto-fix',
557
+ markIgnored: true
558
+ };
559
+ }
537
560
  if (subject.includes('[database]') || subject.includes('[server]')) {
538
561
  return { source: 'infrastructure', skip: true, reason: 'Infrastructure alert (subject tag)' };
539
562
  }
@@ -553,6 +576,20 @@ var ErrorAutoFixManager = /** @class */ (function () {
553
576
  }
554
577
  return { source: 'app', skip: false };
555
578
  };
579
+ ErrorAutoFixManager.prototype.isMongoOriginError = function (email) {
580
+ var sourceApp = String((email === null || email === void 0 ? void 0 : email.sourceApp) || '').toLowerCase();
581
+ var sourceEnvironment = String((email === null || email === void 0 ? void 0 : email.sourceEnvironment) || '').toLowerCase();
582
+ var subject = String((email === null || email === void 0 ? void 0 : email.subject) || '').toLowerCase();
583
+ var body = String((email === null || email === void 0 ? void 0 : email.body) || '');
584
+ var sourceMatches = MONGO_SOURCE_KEYWORDS.some(function (keyword) {
585
+ return sourceApp.includes(keyword) || sourceEnvironment.includes(keyword);
586
+ });
587
+ if (sourceMatches) {
588
+ return true;
589
+ }
590
+ var text = "".concat(subject, "\n").concat(body);
591
+ return MONGO_TEXT_PATTERNS.some(function (pattern) { return pattern.test(text); });
592
+ };
556
593
  ErrorAutoFixManager.prototype.generateRawEmailHash = function (email) {
557
594
  return (0, crypto_1.createHash)('sha256').update("".concat(email.subject || '', "\n").concat(email.body || ''), 'utf8').digest('hex');
558
595
  };
@@ -1849,6 +1886,7 @@ var ErrorAutoFixManager = /** @class */ (function () {
1849
1886
  if (!classification.skip) return [3 /*break*/, 10];
1850
1887
  return [4 /*yield*/, this.updateLog(email.logId, {
1851
1888
  status: 'skipped',
1889
+ ignored: !!classification.markIgnored,
1852
1890
  last_error: classification.reason || 'Ignored non-app alert',
1853
1891
  last_result_at: new Date()
1854
1892
  })];
@@ -1912,7 +1950,7 @@ var ErrorAutoFixManager = /** @class */ (function () {
1912
1950
  };
1913
1951
  ErrorAutoFixManager.prototype.runLog = function (logId) {
1914
1952
  return __awaiter(this, void 0, void 0, function () {
1915
- var log, now, email, inProgressLog, result;
1953
+ var log, now, email, classification, ignoredLog, inProgressLog, result;
1916
1954
  return __generator(this, function (_a) {
1917
1955
  switch (_a.label) {
1918
1956
  case 0:
@@ -1936,26 +1974,43 @@ var ErrorAutoFixManager = /** @class */ (function () {
1936
1974
  }
1937
1975
  now = new Date();
1938
1976
  email = this.buildEmailFromLog(log);
1939
- return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: logId }, {
1940
- $inc: {
1941
- attempt_count: 1
1942
- },
1943
- $set: {
1944
- status: 'in_progress',
1945
- last_attempt_at: now,
1946
- last_error: '',
1947
- ignored: false
1948
- }
1949
- }, {
1950
- returnDocument: 'after'
1977
+ classification = this.classifyEmail(email);
1978
+ if (!(classification.skip && classification.markIgnored)) return [3 /*break*/, 3];
1979
+ return [4 /*yield*/, this.updateLog(logId, {
1980
+ status: 'skipped',
1981
+ ignored: true,
1982
+ last_error: classification.reason || 'Mongo-origin error ignored for auto-fix',
1983
+ last_result_at: now
1951
1984
  })];
1952
1985
  case 2:
1986
+ ignoredLog = _a.sent();
1987
+ return [2 /*return*/, {
1988
+ status: 'skipped',
1989
+ email: email,
1990
+ reason: 'classified',
1991
+ error: classification.reason || 'Mongo-origin error ignored for auto-fix',
1992
+ log: ignoredLog
1993
+ }];
1994
+ case 3: return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: logId }, {
1995
+ $inc: {
1996
+ attempt_count: 1
1997
+ },
1998
+ $set: {
1999
+ status: 'in_progress',
2000
+ last_attempt_at: now,
2001
+ last_error: '',
2002
+ ignored: false
2003
+ }
2004
+ }, {
2005
+ returnDocument: 'after'
2006
+ })];
2007
+ case 4:
1953
2008
  inProgressLog = (_a.sent()) || log;
1954
2009
  return [4 /*yield*/, this.processEmail(email, inProgressLog)];
1955
- case 3:
2010
+ case 5:
1956
2011
  result = _a.sent();
1957
2012
  return [4 /*yield*/, this.notify(result)];
1958
- case 4:
2013
+ case 6:
1959
2014
  _a.sent();
1960
2015
  return [2 /*return*/, result];
1961
2016
  }