@astralibx/email-account-manager 2.0.2 → 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/dist/index.mjs CHANGED
@@ -306,6 +306,10 @@ function createEmailAccountSchema(options) {
306
306
  required: true,
307
307
  _id: false
308
308
  },
309
+ metadata: {
310
+ type: Schema.Types.Mixed,
311
+ default: {}
312
+ },
309
313
  totalEmailsSent: { type: Number, default: 0 },
310
314
  lastSuccessfulSendAt: Date,
311
315
  lastImapCheckAt: Date
@@ -2198,6 +2202,16 @@ function createApprovalProcessor(EmailDraft, smtpService, queueService, logger)
2198
2202
  }
2199
2203
 
2200
2204
  // src/controllers/account.controller.ts
2205
+ var MAX_METADATA_SIZE = 64e3;
2206
+ function sanitizeMetadata(raw) {
2207
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return {};
2208
+ const json2 = JSON.stringify(raw);
2209
+ if (json2.length > MAX_METADATA_SIZE) {
2210
+ throw new Error(`metadata exceeds ${MAX_METADATA_SIZE} byte limit`);
2211
+ }
2212
+ const { __proto__: _a, constructor: _b, prototype: _c, ...safe } = raw;
2213
+ return safe;
2214
+ }
2201
2215
  function createAccountController(EmailAccount, capacityManager, healthTracker, warmupManager, smtpService, imapBounceChecker, config) {
2202
2216
  return {
2203
2217
  async list(req, res) {
@@ -2258,6 +2272,7 @@ function createAccountController(EmailAccount, capacityManager, healthTracker, w
2258
2272
  schedule: input.warmup?.schedule || warmupDefaults || []
2259
2273
  },
2260
2274
  status: "warmup",
2275
+ ...input.metadata !== void 0 ? { metadata: sanitizeMetadata(input.metadata) } : {},
2261
2276
  totalEmailsSent: 0
2262
2277
  };
2263
2278
  const account = await EmailAccount.create(accountData);
@@ -2292,6 +2307,7 @@ function createAccountController(EmailAccount, capacityManager, healthTracker, w
2292
2307
  }
2293
2308
  }
2294
2309
  if (input.limits?.dailyMax !== void 0) updates["limits.dailyMax"] = input.limits.dailyMax;
2310
+ if (input.metadata !== void 0) updates.metadata = sanitizeMetadata(input.metadata);
2295
2311
  const account = await EmailAccount.findByIdAndUpdate(
2296
2312
  req.params.id,
2297
2313
  { $set: updates },