@astralibx/email-account-manager 10.0.1 → 10.2.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 +40 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.mjs +40 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -484,7 +484,6 @@ function createEmailIdentifierSchema(options) {
|
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
486
|
);
|
|
487
|
-
schema.index({ email: 1 }, { unique: true });
|
|
488
487
|
return schema;
|
|
489
488
|
}
|
|
490
489
|
function createEmailDraftSchema(options) {
|
|
@@ -506,6 +505,8 @@ function createEmailDraftSchema(options) {
|
|
|
506
505
|
sentAt: Date,
|
|
507
506
|
scheduledAt: Date,
|
|
508
507
|
failureReason: String,
|
|
508
|
+
source: { type: String },
|
|
509
|
+
identifierId: { type: String },
|
|
509
510
|
metadata: { type: mongoose.Schema.Types.Mixed }
|
|
510
511
|
},
|
|
511
512
|
{
|
|
@@ -807,6 +808,9 @@ var IdentifierService = class {
|
|
|
807
808
|
);
|
|
808
809
|
return doc;
|
|
809
810
|
}
|
|
811
|
+
async findById(id) {
|
|
812
|
+
return this.EmailIdentifier.findById(id);
|
|
813
|
+
}
|
|
810
814
|
async findByEmail(email) {
|
|
811
815
|
return this.EmailIdentifier.findOne({ email: email.toLowerCase().trim() });
|
|
812
816
|
}
|
|
@@ -1138,6 +1142,26 @@ var WarmupManager = class {
|
|
|
1138
1142
|
delayRange: phase ? { min: phase.delayMinMs, max: phase.delayMaxMs } : { min: 0, max: 0 }
|
|
1139
1143
|
};
|
|
1140
1144
|
}
|
|
1145
|
+
async advanceAllAccounts() {
|
|
1146
|
+
const accounts = await this.EmailAccount.find({
|
|
1147
|
+
status: ACCOUNT_STATUS.Warmup,
|
|
1148
|
+
"warmup.enabled": true
|
|
1149
|
+
});
|
|
1150
|
+
let advanced = 0;
|
|
1151
|
+
let errors = 0;
|
|
1152
|
+
for (const account of accounts) {
|
|
1153
|
+
try {
|
|
1154
|
+
await this.advanceDay(account._id.toString());
|
|
1155
|
+
advanced++;
|
|
1156
|
+
} catch (err) {
|
|
1157
|
+
errors++;
|
|
1158
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
1159
|
+
this.logger.error(`Failed to advance warmup for ${account.email}: ${msg}`);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
this.logger.info("Advance all accounts completed", { advanced, errors });
|
|
1163
|
+
return { advanced, errors };
|
|
1164
|
+
}
|
|
1141
1165
|
async updateSchedule(accountId, schedule) {
|
|
1142
1166
|
await this.EmailAccount.findByIdAndUpdate(accountId, {
|
|
1143
1167
|
$set: { "warmup.schedule": schedule }
|
|
@@ -1672,7 +1696,8 @@ var ApprovalService = class {
|
|
|
1672
1696
|
this.hooks?.onDraftApproved?.({
|
|
1673
1697
|
draftId,
|
|
1674
1698
|
to: draft.to,
|
|
1675
|
-
scheduledAt
|
|
1699
|
+
scheduledAt,
|
|
1700
|
+
draft: draft.toObject()
|
|
1676
1701
|
});
|
|
1677
1702
|
}
|
|
1678
1703
|
async reject(draftId, reason) {
|
|
@@ -2190,7 +2215,7 @@ function createSendProcessor(smtpService, logger) {
|
|
|
2190
2215
|
}
|
|
2191
2216
|
|
|
2192
2217
|
// src/queues/approval.queue.ts
|
|
2193
|
-
function createApprovalProcessor(EmailDraft, smtpService, queueService, logger) {
|
|
2218
|
+
function createApprovalProcessor(EmailDraft, smtpService, queueService, logger, identifierService) {
|
|
2194
2219
|
return async (job) => {
|
|
2195
2220
|
const { draftId } = job.data;
|
|
2196
2221
|
const draft = await EmailDraft.findById(draftId);
|
|
@@ -2214,6 +2239,10 @@ function createApprovalProcessor(EmailDraft, smtpService, queueService, logger)
|
|
|
2214
2239
|
html: d.htmlBody,
|
|
2215
2240
|
text: d.textBody || ""
|
|
2216
2241
|
});
|
|
2242
|
+
if (d.identifierId && identifierService) {
|
|
2243
|
+
await identifierService.incrementSentCount(d.to);
|
|
2244
|
+
logger.info("Identifier sentCount incremented for draft", { draftId, to: d.to, identifierId: d.identifierId });
|
|
2245
|
+
}
|
|
2217
2246
|
};
|
|
2218
2247
|
}
|
|
2219
2248
|
|
|
@@ -2960,18 +2989,21 @@ function createEmailAccountManager(config) {
|
|
|
2960
2989
|
EmailDraft,
|
|
2961
2990
|
smtpService,
|
|
2962
2991
|
queueService,
|
|
2963
|
-
logger
|
|
2992
|
+
logger,
|
|
2993
|
+
identifierService
|
|
2964
2994
|
);
|
|
2965
2995
|
queueService.init({ sendProcessor, approvalProcessor }).catch((err) => {
|
|
2966
2996
|
logger.error("Failed to initialize queues", {
|
|
2967
2997
|
error: err instanceof Error ? err.message : "Unknown error"
|
|
2968
2998
|
});
|
|
2969
2999
|
});
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
error
|
|
3000
|
+
if (config.options?.imap?.autoStart !== false) {
|
|
3001
|
+
imapBounceChecker.start().catch((err) => {
|
|
3002
|
+
logger.error("Failed to start IMAP bounce checker", {
|
|
3003
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
3004
|
+
});
|
|
2973
3005
|
});
|
|
2974
|
-
}
|
|
3006
|
+
}
|
|
2975
3007
|
const accountController = createAccountController(
|
|
2976
3008
|
EmailAccount,
|
|
2977
3009
|
capacityManager,
|