@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.cjs CHANGED
@@ -93,7 +93,7 @@ function createEmailTemplateSchema(platformValues, audienceValues, categoryValue
93
93
  },
94
94
  variables: [{ type: String }],
95
95
  version: { type: Number, default: 1 },
96
- isActive: { type: Boolean, default: true, index: true }
96
+ isActive: { type: Boolean, default: true }
97
97
  },
98
98
  {
99
99
  timestamps: true,
@@ -160,13 +160,13 @@ function createEmailRuleSchema(platformValues, audienceValues, collectionPrefix)
160
160
  sent: { type: Number, default: 0 },
161
161
  skipped: { type: Number, default: 0 },
162
162
  skippedByThrottle: { type: Number, default: 0 },
163
- errors: { type: Number, default: 0 }
163
+ errorCount: { type: Number, default: 0 }
164
164
  }, { _id: false });
165
165
  const schema = new mongoose.Schema(
166
166
  {
167
167
  name: { type: String, required: true },
168
168
  description: String,
169
- isActive: { type: Boolean, default: false, index: true },
169
+ isActive: { type: Boolean, default: false },
170
170
  sortOrder: { type: Number, default: 10 },
171
171
  target: { type: RuleTargetSchema, required: true },
172
172
  templateId: { type: mongoose.Schema.Types.ObjectId, ref: "EmailTemplate", required: true, index: true },
@@ -278,14 +278,14 @@ function createEmailRuleRunLogSchema(collectionPrefix) {
278
278
  sent: { type: Number, default: 0 },
279
279
  skipped: { type: Number, default: 0 },
280
280
  skippedByThrottle: { type: Number, default: 0 },
281
- errors: { type: Number, default: 0 }
281
+ errorCount: { type: Number, default: 0 }
282
282
  }, { _id: false });
283
283
  const TotalStatsSchema = new mongoose.Schema({
284
284
  matched: { type: Number, default: 0 },
285
285
  sent: { type: Number, default: 0 },
286
286
  skipped: { type: Number, default: 0 },
287
287
  skippedByThrottle: { type: Number, default: 0 },
288
- errors: { type: Number, default: 0 }
288
+ errorCount: { type: Number, default: 0 }
289
289
  }, { _id: false });
290
290
  const schema = new mongoose.Schema(
291
291
  {
@@ -1034,7 +1034,7 @@ var RuleRunnerService = class {
1034
1034
  triggeredBy,
1035
1035
  duration: Date.now() - runStartTime,
1036
1036
  rulesProcessed: 0,
1037
- totalStats: { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errors: 0 },
1037
+ totalStats: { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errorCount: 0 },
1038
1038
  perRuleStats: [],
1039
1039
  status: "completed"
1040
1040
  });
@@ -1070,9 +1070,9 @@ var RuleRunnerService = class {
1070
1070
  });
1071
1071
  const stats = await this.executeRule(rule, throttleMap, throttleConfig, templateMap, runId);
1072
1072
  totalSent += stats.sent;
1073
- totalFailed += stats.errors;
1073
+ totalFailed += stats.errorCount;
1074
1074
  totalSkipped += stats.skipped + stats.skippedByThrottle;
1075
- totalInvalid += stats.matched - stats.sent - stats.skipped - stats.skippedByThrottle - stats.errors;
1075
+ totalInvalid += stats.matched - stats.sent - stats.skipped - stats.skippedByThrottle - stats.errorCount;
1076
1076
  perRuleStats.push({
1077
1077
  ruleId: rule._id.toString(),
1078
1078
  ruleName: rule.name,
@@ -1096,9 +1096,9 @@ var RuleRunnerService = class {
1096
1096
  sent: acc.sent + s.sent,
1097
1097
  skipped: acc.skipped + s.skipped,
1098
1098
  skippedByThrottle: acc.skippedByThrottle + s.skippedByThrottle,
1099
- errors: acc.errors + s.errors
1099
+ errorCount: acc.errorCount + s.errorCount
1100
1100
  }),
1101
- { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errors: 0 }
1101
+ { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errorCount: 0 }
1102
1102
  );
1103
1103
  await this.EmailRuleRunLog.create({
1104
1104
  runId,
@@ -1129,11 +1129,11 @@ var RuleRunnerService = class {
1129
1129
  return { runId };
1130
1130
  }
1131
1131
  async executeRule(rule, throttleMap, throttleConfig, templateMap, runId) {
1132
- const stats = { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errors: 0 };
1132
+ const stats = { matched: 0, sent: 0, skipped: 0, skippedByThrottle: 0, errorCount: 0 };
1133
1133
  const template = templateMap?.get(rule.templateId.toString()) ?? await this.EmailTemplate.findById(rule.templateId);
1134
1134
  if (!template) {
1135
1135
  this.logger.error(`Rule "${rule.name}": template ${rule.templateId} not found`);
1136
- stats.errors = 1;
1136
+ stats.errorCount = 1;
1137
1137
  return stats;
1138
1138
  }
1139
1139
  const isListMode = rule.target?.mode === "list";
@@ -1268,7 +1268,7 @@ var RuleRunnerService = class {
1268
1268
  finalSubject = modified.subject;
1269
1269
  } catch (hookErr) {
1270
1270
  this.logger.error(`beforeSend hook failed for email ${email}: ${hookErr.message}`);
1271
- stats.errors++;
1271
+ stats.errorCount++;
1272
1272
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email, status: "error" });
1273
1273
  continue;
1274
1274
  }
@@ -1311,7 +1311,7 @@ var RuleRunnerService = class {
1311
1311
  }
1312
1312
  }
1313
1313
  } catch (err) {
1314
- stats.errors++;
1314
+ stats.errorCount++;
1315
1315
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email, status: "error" });
1316
1316
  this.logger.error(`Rule "${rule.name}" failed for identifier ${email}`, { error: err });
1317
1317
  }
@@ -1344,7 +1344,7 @@ var RuleRunnerService = class {
1344
1344
  users = await this.config.adapters.queryUsers(rule.target, rule.maxPerRun || this.config.options?.defaultMaxPerRun || 500);
1345
1345
  } catch (err) {
1346
1346
  this.logger.error(`Rule "${rule.name}": query failed`, { error: err });
1347
- stats.errors = 1;
1347
+ stats.errorCount = 1;
1348
1348
  return stats;
1349
1349
  }
1350
1350
  stats.matched = users.length;
@@ -1474,7 +1474,7 @@ var RuleRunnerService = class {
1474
1474
  finalSubject = modified.subject;
1475
1475
  } catch (hookErr) {
1476
1476
  this.logger.error(`beforeSend hook failed for email ${email}: ${hookErr.message}`);
1477
- stats.errors++;
1477
+ stats.errorCount++;
1478
1478
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email, status: "error" });
1479
1479
  continue;
1480
1480
  }
@@ -1517,7 +1517,7 @@ var RuleRunnerService = class {
1517
1517
  }
1518
1518
  }
1519
1519
  } catch (err) {
1520
- stats.errors++;
1520
+ stats.errorCount++;
1521
1521
  this.config.hooks?.onSend?.({ ruleId, ruleName: rule.name, email: user.email || "unknown", status: "error" });
1522
1522
  this.logger.error(`Rule "${rule.name}" failed for user ${user._id?.toString()}`, { error: err });
1523
1523
  }
@@ -1613,7 +1613,7 @@ var RuleRunnerService = class {
1613
1613
  }
1614
1614
  }
1615
1615
  progress.sent = stats.sent;
1616
- progress.failed = stats.errors;
1616
+ progress.failed = stats.errorCount;
1617
1617
  progress.skipped = stats.skipped + stats.skippedByThrottle;
1618
1618
  await this.redis.hset(key, "progress", JSON.stringify(progress));
1619
1619
  await this.redis.expire(key, 3600);