@astralibx/email-rule-engine 12.7.1 → 12.7.2
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 +43 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.mjs +42 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10416,13 +10416,22 @@ var EMAIL_SEND_STATUS = {
|
|
|
10416
10416
|
Invalid: "invalid",
|
|
10417
10417
|
Throttled: "throttled"
|
|
10418
10418
|
};
|
|
10419
|
+
var TARGET_MODE = {
|
|
10420
|
+
Query: "query",
|
|
10421
|
+
List: "list"
|
|
10422
|
+
};
|
|
10423
|
+
var RUN_LOG_STATUS = {
|
|
10424
|
+
Completed: "completed",
|
|
10425
|
+
Cancelled: "cancelled",
|
|
10426
|
+
Failed: "failed"
|
|
10427
|
+
};
|
|
10419
10428
|
|
|
10420
10429
|
// src/schemas/template.schema.ts
|
|
10421
10430
|
function createEmailTemplateSchema(platformValues, audienceValues, categoryValues, collectionPrefix) {
|
|
10422
10431
|
const schema = new mongoose.Schema(
|
|
10423
10432
|
{
|
|
10424
10433
|
name: { type: String, required: true },
|
|
10425
|
-
slug: { type: String, required: true, unique: true },
|
|
10434
|
+
slug: { type: String, required: true, unique: true, maxlength: 200 },
|
|
10426
10435
|
description: String,
|
|
10427
10436
|
category: { type: String, enum: categoryValues || Object.values(TEMPLATE_CATEGORY), required: true },
|
|
10428
10437
|
audience: { type: String, enum: audienceValues || Object.values(TEMPLATE_AUDIENCE), required: true },
|
|
@@ -10447,6 +10456,15 @@ function createEmailTemplateSchema(platformValues, audienceValues, categoryValue
|
|
|
10447
10456
|
}
|
|
10448
10457
|
},
|
|
10449
10458
|
variables: [{ type: String }],
|
|
10459
|
+
attachments: {
|
|
10460
|
+
type: [{
|
|
10461
|
+
_id: false,
|
|
10462
|
+
filename: { type: String, required: true },
|
|
10463
|
+
url: { type: String, required: true },
|
|
10464
|
+
contentType: { type: String, required: true }
|
|
10465
|
+
}],
|
|
10466
|
+
default: []
|
|
10467
|
+
},
|
|
10450
10468
|
version: { type: Number, default: 1 },
|
|
10451
10469
|
isActive: { type: Boolean, default: true }
|
|
10452
10470
|
},
|
|
@@ -10483,6 +10501,7 @@ function createEmailTemplateSchema(platformValues, audienceValues, categoryValue
|
|
|
10483
10501
|
preheaders: input.preheaders || [],
|
|
10484
10502
|
fields: input.fields || {},
|
|
10485
10503
|
variables: input.variables || [],
|
|
10504
|
+
attachments: input.attachments || [],
|
|
10486
10505
|
version: 1,
|
|
10487
10506
|
isActive: true
|
|
10488
10507
|
});
|
|
@@ -10501,7 +10520,7 @@ function createEmailRuleSchema(platformValues, audienceValues, collectionPrefix)
|
|
|
10501
10520
|
value: { type: mongoose.Schema.Types.Mixed }
|
|
10502
10521
|
}, { _id: false });
|
|
10503
10522
|
const RuleTargetSchema = new mongoose.Schema({
|
|
10504
|
-
mode: { type: String, enum:
|
|
10523
|
+
mode: { type: String, enum: Object.values(TARGET_MODE), required: true },
|
|
10505
10524
|
role: { type: String, enum: audienceValues || Object.values(TEMPLATE_AUDIENCE) },
|
|
10506
10525
|
platform: {
|
|
10507
10526
|
type: String,
|
|
@@ -10665,7 +10684,7 @@ function createEmailRuleRunLogSchema(collectionPrefix) {
|
|
|
10665
10684
|
{
|
|
10666
10685
|
runId: { type: String, index: true },
|
|
10667
10686
|
runAt: { type: Date, required: true, default: () => /* @__PURE__ */ new Date() },
|
|
10668
|
-
status: { type: String, enum:
|
|
10687
|
+
status: { type: String, enum: Object.values(RUN_LOG_STATUS), default: RUN_LOG_STATUS.Completed },
|
|
10669
10688
|
triggeredBy: { type: String, enum: Object.values(RUN_TRIGGER), required: true },
|
|
10670
10689
|
duration: { type: Number, required: true },
|
|
10671
10690
|
rulesProcessed: { type: Number, required: true },
|
|
@@ -10960,6 +10979,9 @@ var DuplicateSlugError = class extends AlxEmailError {
|
|
|
10960
10979
|
};
|
|
10961
10980
|
|
|
10962
10981
|
// src/services/template.service.ts
|
|
10982
|
+
function stripScriptTags(text) {
|
|
10983
|
+
return text.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
|
|
10984
|
+
}
|
|
10963
10985
|
var UPDATEABLE_FIELDS = /* @__PURE__ */ new Set([
|
|
10964
10986
|
"name",
|
|
10965
10987
|
"description",
|
|
@@ -10972,7 +10994,8 @@ var UPDATEABLE_FIELDS = /* @__PURE__ */ new Set([
|
|
|
10972
10994
|
"preheaders",
|
|
10973
10995
|
"variables",
|
|
10974
10996
|
"isActive",
|
|
10975
|
-
"fields"
|
|
10997
|
+
"fields",
|
|
10998
|
+
"attachments"
|
|
10976
10999
|
]);
|
|
10977
11000
|
function slugify(name) {
|
|
10978
11001
|
return name.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
@@ -11003,7 +11026,8 @@ var TemplateService = class {
|
|
|
11003
11026
|
if (existing) {
|
|
11004
11027
|
throw new DuplicateSlugError(slug);
|
|
11005
11028
|
}
|
|
11006
|
-
const
|
|
11029
|
+
const subjects = input.subjects.map((s) => stripScriptTags(s));
|
|
11030
|
+
const bodies = input.bodies.map((b) => stripScriptTags(b));
|
|
11007
11031
|
if (subjects.length === 0) throw new TemplateSyntaxError("At least one subject is required", ["At least one subject is required"]);
|
|
11008
11032
|
if (bodies.length === 0) throw new TemplateSyntaxError("At least one body is required", ["At least one body is required"]);
|
|
11009
11033
|
for (const b of bodies) {
|
|
@@ -11025,6 +11049,12 @@ var TemplateService = class {
|
|
|
11025
11049
|
async update(id, input) {
|
|
11026
11050
|
const template = await this.EmailTemplate.findById(id);
|
|
11027
11051
|
if (!template) return null;
|
|
11052
|
+
if (input.subjects) {
|
|
11053
|
+
input.subjects = input.subjects.map((s) => stripScriptTags(s));
|
|
11054
|
+
}
|
|
11055
|
+
if (input.bodies) {
|
|
11056
|
+
input.bodies = input.bodies.map((b) => stripScriptTags(b));
|
|
11057
|
+
}
|
|
11028
11058
|
if (input.subjects && input.subjects.length === 0) {
|
|
11029
11059
|
throw new TemplateSyntaxError("At least one subject is required", ["At least one subject is required"]);
|
|
11030
11060
|
}
|
|
@@ -11133,7 +11163,8 @@ var TemplateService = class {
|
|
|
11133
11163
|
testEmail,
|
|
11134
11164
|
`[TEST] ${rendered.subject}`,
|
|
11135
11165
|
rendered.html,
|
|
11136
|
-
rendered.text
|
|
11166
|
+
rendered.text,
|
|
11167
|
+
template.attachments || []
|
|
11137
11168
|
);
|
|
11138
11169
|
return { success: true };
|
|
11139
11170
|
} catch (error) {
|
|
@@ -11704,7 +11735,8 @@ var RuleRunnerService = class {
|
|
|
11704
11735
|
htmlBody: finalHtml,
|
|
11705
11736
|
textBody: finalText,
|
|
11706
11737
|
ruleId,
|
|
11707
|
-
autoApprove: rule.autoApprove ?? true
|
|
11738
|
+
autoApprove: rule.autoApprove ?? true,
|
|
11739
|
+
attachments: template.attachments || []
|
|
11708
11740
|
});
|
|
11709
11741
|
await this.EmailRuleSend.logSend(
|
|
11710
11742
|
ruleId,
|
|
@@ -11919,7 +11951,8 @@ var RuleRunnerService = class {
|
|
|
11919
11951
|
htmlBody: finalHtml,
|
|
11920
11952
|
textBody: finalText,
|
|
11921
11953
|
ruleId,
|
|
11922
|
-
autoApprove: rule.autoApprove ?? true
|
|
11954
|
+
autoApprove: rule.autoApprove ?? true,
|
|
11955
|
+
attachments: template.attachments || []
|
|
11923
11956
|
});
|
|
11924
11957
|
await this.EmailRuleSend.logSend(
|
|
11925
11958
|
ruleId,
|
|
@@ -30176,12 +30209,14 @@ exports.EMAIL_SEND_STATUS = EMAIL_SEND_STATUS;
|
|
|
30176
30209
|
exports.EMAIL_TYPE = EMAIL_TYPE;
|
|
30177
30210
|
exports.LockAcquisitionError = LockAcquisitionError;
|
|
30178
30211
|
exports.RULE_OPERATOR = RULE_OPERATOR;
|
|
30212
|
+
exports.RUN_LOG_STATUS = RUN_LOG_STATUS;
|
|
30179
30213
|
exports.RUN_TRIGGER = RUN_TRIGGER;
|
|
30180
30214
|
exports.RuleNotFoundError = RuleNotFoundError;
|
|
30181
30215
|
exports.RuleRunnerService = RuleRunnerService;
|
|
30182
30216
|
exports.RuleService = RuleService;
|
|
30183
30217
|
exports.RuleTemplateIncompatibleError = RuleTemplateIncompatibleError;
|
|
30184
30218
|
exports.SchedulerService = SchedulerService;
|
|
30219
|
+
exports.TARGET_MODE = TARGET_MODE;
|
|
30185
30220
|
exports.TEMPLATE_AUDIENCE = TEMPLATE_AUDIENCE;
|
|
30186
30221
|
exports.TEMPLATE_CATEGORY = TEMPLATE_CATEGORY;
|
|
30187
30222
|
exports.THROTTLE_WINDOW = THROTTLE_WINDOW;
|