@astralibx/email-account-manager 3.0.0 → 4.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/README.md CHANGED
@@ -52,6 +52,15 @@ app.use('/webhooks/ses', eam.webhookRoutes.ses);
52
52
  // Unsubscribe pages (public)
53
53
  app.use('/unsubscribe', eam.unsubscribeRoutes);
54
54
 
55
+ // Create an account with metadata
56
+ await eam.accounts.create({
57
+ email: 'outreach@yourdomain.com',
58
+ senderName: 'Your Company',
59
+ provider: 'gmail',
60
+ smtp: { host: 'smtp.gmail.com', port: 587, user: 'outreach@yourdomain.com', pass: 'app-password' },
61
+ metadata: { sender_names: ['Sales', 'Support'], contact_number: '+1-555-0100' },
62
+ });
63
+
55
64
  // Send an email programmatically
56
65
  const result = await eam.smtp.send({
57
66
  to: 'recipient@example.com',
@@ -66,7 +75,7 @@ app.listen(3000);
66
75
 
67
76
  ## Features
68
77
 
69
- - **Multi-account management** -- Gmail and AWS SES providers with credential storage and status tracking. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-account-manager/docs/account-management.md)
78
+ - **Multi-account management** -- Gmail and AWS SES providers with credential storage, status tracking, and freeform metadata. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-account-manager/docs/account-management.md)
70
79
  - **Health tracking** -- Automatic scoring (+1/-5/-10) with auto-disable on threshold breach. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-account-manager/docs/health-tracking.md)
71
80
  - **Account warmup** -- Phased volume ramp-up with configurable schedules stored per-account. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-account-manager/docs/warmup-system.md)
72
81
  - **Capacity-based rotation** -- Health-weighted account selection with daily limit enforcement. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-account-manager/docs/capacity-selection.md)
package/dist/index.d.mts CHANGED
@@ -392,6 +392,7 @@ interface EmailAccount {
392
392
  limits: AccountLimits;
393
393
  health: AccountHealthData;
394
394
  warmup: AccountWarmupData;
395
+ metadata?: Record<string, unknown>;
395
396
  totalEmailsSent: number;
396
397
  lastSuccessfulSendAt?: Date;
397
398
  createdAt: Date;
@@ -408,6 +409,7 @@ interface CreateEmailAccountInput {
408
409
  warmup?: {
409
410
  schedule?: WarmupPhase[];
410
411
  };
412
+ metadata?: Record<string, unknown>;
411
413
  health?: {
412
414
  thresholds?: Partial<HealthThresholds>;
413
415
  };
@@ -420,6 +422,7 @@ interface UpdateEmailAccountInput {
420
422
  ses?: Partial<SesConfig>;
421
423
  limits?: Partial<AccountLimits>;
422
424
  warmup?: Partial<AccountWarmupData>;
425
+ metadata?: Record<string, unknown>;
423
426
  health?: {
424
427
  thresholds?: Partial<HealthThresholds>;
425
428
  };
package/dist/index.d.ts CHANGED
@@ -392,6 +392,7 @@ interface EmailAccount {
392
392
  limits: AccountLimits;
393
393
  health: AccountHealthData;
394
394
  warmup: AccountWarmupData;
395
+ metadata?: Record<string, unknown>;
395
396
  totalEmailsSent: number;
396
397
  lastSuccessfulSendAt?: Date;
397
398
  createdAt: Date;
@@ -408,6 +409,7 @@ interface CreateEmailAccountInput {
408
409
  warmup?: {
409
410
  schedule?: WarmupPhase[];
410
411
  };
412
+ metadata?: Record<string, unknown>;
411
413
  health?: {
412
414
  thresholds?: Partial<HealthThresholds>;
413
415
  };
@@ -420,6 +422,7 @@ interface UpdateEmailAccountInput {
420
422
  ses?: Partial<SesConfig>;
421
423
  limits?: Partial<AccountLimits>;
422
424
  warmup?: Partial<AccountWarmupData>;
425
+ metadata?: Record<string, unknown>;
423
426
  health?: {
424
427
  thresholds?: Partial<HealthThresholds>;
425
428
  };
package/dist/index.js CHANGED
@@ -2210,6 +2210,16 @@ function createApprovalProcessor(EmailDraft, smtpService, queueService, logger)
2210
2210
  }
2211
2211
 
2212
2212
  // src/controllers/account.controller.ts
2213
+ var MAX_METADATA_SIZE = 64e3;
2214
+ function sanitizeMetadata(raw) {
2215
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return {};
2216
+ const json2 = JSON.stringify(raw);
2217
+ if (json2.length > MAX_METADATA_SIZE) {
2218
+ throw new Error(`metadata exceeds ${MAX_METADATA_SIZE} byte limit`);
2219
+ }
2220
+ const { __proto__: _a, constructor: _b, prototype: _c, ...safe } = raw;
2221
+ return safe;
2222
+ }
2213
2223
  function createAccountController(EmailAccount, capacityManager, healthTracker, warmupManager, smtpService, imapBounceChecker, config) {
2214
2224
  return {
2215
2225
  async list(req, res) {
@@ -2270,6 +2280,7 @@ function createAccountController(EmailAccount, capacityManager, healthTracker, w
2270
2280
  schedule: input.warmup?.schedule || warmupDefaults || []
2271
2281
  },
2272
2282
  status: "warmup",
2283
+ ...input.metadata !== void 0 ? { metadata: sanitizeMetadata(input.metadata) } : {},
2273
2284
  totalEmailsSent: 0
2274
2285
  };
2275
2286
  const account = await EmailAccount.create(accountData);
@@ -2304,6 +2315,7 @@ function createAccountController(EmailAccount, capacityManager, healthTracker, w
2304
2315
  }
2305
2316
  }
2306
2317
  if (input.limits?.dailyMax !== void 0) updates["limits.dailyMax"] = input.limits.dailyMax;
2318
+ if (input.metadata !== void 0) updates.metadata = sanitizeMetadata(input.metadata);
2307
2319
  const account = await EmailAccount.findByIdAndUpdate(
2308
2320
  req.params.id,
2309
2321
  { $set: updates },