@astralibx/email-rule-engine 9.0.0 → 11.0.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/dist/index.d.mts CHANGED
@@ -66,7 +66,7 @@ interface RuleRunStats {
66
66
  sent: number;
67
67
  skipped: number;
68
68
  skippedByThrottle: number;
69
- errors: number;
69
+ errorCount: number;
70
70
  }
71
71
  interface QueryTarget {
72
72
  mode: 'query';
@@ -426,7 +426,7 @@ interface IEmailRuleRunLog {
426
426
  sent: number;
427
427
  skipped: number;
428
428
  skippedByThrottle: number;
429
- errors: number;
429
+ errorCount: number;
430
430
  };
431
431
  perRuleStats: Array<{
432
432
  ruleId: Types.ObjectId;
@@ -435,7 +435,7 @@ interface IEmailRuleRunLog {
435
435
  sent: number;
436
436
  skipped: number;
437
437
  skippedByThrottle: number;
438
- errors: number;
438
+ errorCount: number;
439
439
  }>;
440
440
  }
441
441
  type EmailRuleRunLogDocument = HydratedDocument<IEmailRuleRunLog>;
package/dist/index.d.ts CHANGED
@@ -66,7 +66,7 @@ interface RuleRunStats {
66
66
  sent: number;
67
67
  skipped: number;
68
68
  skippedByThrottle: number;
69
- errors: number;
69
+ errorCount: number;
70
70
  }
71
71
  interface QueryTarget {
72
72
  mode: 'query';
@@ -426,7 +426,7 @@ interface IEmailRuleRunLog {
426
426
  sent: number;
427
427
  skipped: number;
428
428
  skippedByThrottle: number;
429
- errors: number;
429
+ errorCount: number;
430
430
  };
431
431
  perRuleStats: Array<{
432
432
  ruleId: Types.ObjectId;
@@ -435,7 +435,7 @@ interface IEmailRuleRunLog {
435
435
  sent: number;
436
436
  skipped: number;
437
437
  skippedByThrottle: number;
438
- errors: number;
438
+ errorCount: number;
439
439
  }>;
440
440
  }
441
441
  type EmailRuleRunLogDocument = HydratedDocument<IEmailRuleRunLog>;
package/dist/index.mjs CHANGED
@@ -85,7 +85,7 @@ function createEmailTemplateSchema(platformValues, audienceValues, categoryValue
85
85
  },
86
86
  variables: [{ type: String }],
87
87
  version: { type: Number, default: 1 },
88
- isActive: { type: Boolean, default: true, index: true }
88
+ isActive: { type: Boolean, default: true }
89
89
  },
90
90
  {
91
91
  timestamps: true,
@@ -152,13 +152,13 @@ function createEmailRuleSchema(platformValues, audienceValues, collectionPrefix)
152
152
  sent: { type: Number, default: 0 },
153
153
  skipped: { type: Number, default: 0 },
154
154
  skippedByThrottle: { type: Number, default: 0 },
155
- errors: { type: Number, default: 0 }
155
+ errorCount: { type: Number, default: 0 }
156
156
  }, { _id: false });
157
157
  const schema = new Schema(
158
158
  {
159
159
  name: { type: String, required: true },
160
160
  description: String,
161
- isActive: { type: Boolean, default: false, index: true },
161
+ isActive: { type: Boolean, default: false },
162
162
  sortOrder: { type: Number, default: 10 },
163
163
  target: { type: RuleTargetSchema, required: true },
164
164
  templateId: { type: Schema.Types.ObjectId, ref: "EmailTemplate", required: true, index: true },
@@ -270,14 +270,14 @@ function createEmailRuleRunLogSchema(collectionPrefix) {
270
270
  sent: { type: Number, default: 0 },
271
271
  skipped: { type: Number, default: 0 },
272
272
  skippedByThrottle: { type: Number, default: 0 },
273
- errors: { type: Number, default: 0 }
273
+ errorCount: { type: Number, default: 0 }
274
274
  }, { _id: false });
275
275
  const TotalStatsSchema = new Schema({
276
276
  matched: { type: Number, default: 0 },
277
277
  sent: { type: Number, default: 0 },
278
278
  skipped: { type: Number, default: 0 },
279
279
  skippedByThrottle: { type: Number, default: 0 },
280
- errors: { type: Number, default: 0 }
280
+ errorCount: { type: Number, default: 0 }
281
281
  }, { _id: false });
282
282
  const schema = new Schema(
283
283
  {
@@ -1026,7 +1026,7 @@ var RuleRunnerService = class {
1026
1026
  triggeredBy,
1027
1027
  duration: Date.now() - runStartTime,
1028
1028
  rulesProcessed: 0,
1029
- totalStats: { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errors: 0 },
1029
+ totalStats: { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errorCount: 0 },
1030
1030
  perRuleStats: [],
1031
1031
  status: "completed"
1032
1032
  });
@@ -1062,9 +1062,9 @@ var RuleRunnerService = class {
1062
1062
  });
1063
1063
  const stats = await this.executeRule(rule, throttleMap, throttleConfig, templateMap, runId);
1064
1064
  totalSent += stats.sent;
1065
- totalFailed += stats.errors;
1065
+ totalFailed += stats.errorCount;
1066
1066
  totalSkipped += stats.skipped + stats.skippedByThrottle;
1067
- totalInvalid += stats.matched - stats.sent - stats.skipped - stats.skippedByThrottle - stats.errors;
1067
+ totalInvalid += stats.matched - stats.sent - stats.skipped - stats.skippedByThrottle - stats.errorCount;
1068
1068
  perRuleStats.push({
1069
1069
  ruleId: rule._id.toString(),
1070
1070
  ruleName: rule.name,
@@ -1088,9 +1088,9 @@ var RuleRunnerService = class {
1088
1088
  sent: acc.sent + s.sent,
1089
1089
  skipped: acc.skipped + s.skipped,
1090
1090
  skippedByThrottle: acc.skippedByThrottle + s.skippedByThrottle,
1091
- errors: acc.errors + s.errors
1091
+ errorCount: acc.errorCount + s.errorCount
1092
1092
  }),
1093
- { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errors: 0 }
1093
+ { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errorCount: 0 }
1094
1094
  );
1095
1095
  await this.EmailRuleRunLog.create({
1096
1096
  runId,
@@ -1121,11 +1121,11 @@ var RuleRunnerService = class {
1121
1121
  return { runId };
1122
1122
  }
1123
1123
  async executeRule(rule, throttleMap, throttleConfig, templateMap, runId) {
1124
- const stats = { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errors: 0 };
1124
+ const stats = { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errorCount: 0 };
1125
1125
  const template = templateMap?.get(rule.templateId.toString()) ?? await this.EmailTemplate.findById(rule.templateId);
1126
1126
  if (!template) {
1127
1127
  this.logger.error(`Rule "${rule.name}": template ${rule.templateId} not found`);
1128
- stats.errors = 1;
1128
+ stats.errorCount = 1;
1129
1129
  return stats;
1130
1130
  }
1131
1131
  const isListMode = rule.target?.mode === "list";
@@ -1260,7 +1260,7 @@ var RuleRunnerService = class {
1260
1260
  finalSubject = modified.subject;
1261
1261
  } catch (hookErr) {
1262
1262
  this.logger.error(`beforeSend hook failed for email ${email}: ${hookErr.message}`);
1263
- stats.errors++;
1263
+ stats.errorCount++;
1264
1264
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email, status: "error" });
1265
1265
  continue;
1266
1266
  }
@@ -1303,7 +1303,7 @@ var RuleRunnerService = class {
1303
1303
  }
1304
1304
  }
1305
1305
  } catch (err) {
1306
- stats.errors++;
1306
+ stats.errorCount++;
1307
1307
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email, status: "error" });
1308
1308
  this.logger.error(`Rule "${rule.name}" failed for identifier ${email}`, { error: err });
1309
1309
  }
@@ -1336,7 +1336,7 @@ var RuleRunnerService = class {
1336
1336
  users = await this.config.adapters.queryUsers(rule.target, rule.maxPerRun || this.config.options?.defaultMaxPerRun || 500);
1337
1337
  } catch (err) {
1338
1338
  this.logger.error(`Rule "${rule.name}": query failed`, { error: err });
1339
- stats.errors = 1;
1339
+ stats.errorCount = 1;
1340
1340
  return stats;
1341
1341
  }
1342
1342
  stats.matched = users.length;
@@ -1466,7 +1466,7 @@ var RuleRunnerService = class {
1466
1466
  finalSubject = modified.subject;
1467
1467
  } catch (hookErr) {
1468
1468
  this.logger.error(`beforeSend hook failed for email ${email}: ${hookErr.message}`);
1469
- stats.errors++;
1469
+ stats.errorCount++;
1470
1470
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email, status: "error" });
1471
1471
  continue;
1472
1472
  }
@@ -1509,7 +1509,7 @@ var RuleRunnerService = class {
1509
1509
  }
1510
1510
  }
1511
1511
  } catch (err) {
1512
- stats.errors++;
1512
+ stats.errorCount++;
1513
1513
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email: user.email || "unknown", status: "error" });
1514
1514
  this.logger.error(`Rule "${rule.name}" failed for user ${user._id?.toString()}`, { error: err });
1515
1515
  }
@@ -1605,7 +1605,7 @@ var RuleRunnerService = class {
1605
1605
  }
1606
1606
  }
1607
1607
  progress.sent = stats.sent;
1608
- progress.failed = stats.errors;
1608
+ progress.failed = stats.errorCount;
1609
1609
  progress.skipped = stats.skipped + stats.skippedByThrottle;
1610
1610
  await this.redis.hset(key, "progress", JSON.stringify(progress));
1611
1611
  await this.redis.expire(key, 3600);