@astralibx/email-account-manager 3.0.0 → 5.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
@@ -2202,6 +2202,16 @@ function createApprovalProcessor(EmailDraft, smtpService, queueService, logger)
2202
2202
  }
2203
2203
 
2204
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
+ }
2205
2215
  function createAccountController(EmailAccount, capacityManager, healthTracker, warmupManager, smtpService, imapBounceChecker, config) {
2206
2216
  return {
2207
2217
  async list(req, res) {
@@ -2262,6 +2272,7 @@ function createAccountController(EmailAccount, capacityManager, healthTracker, w
2262
2272
  schedule: input.warmup?.schedule || warmupDefaults || []
2263
2273
  },
2264
2274
  status: "warmup",
2275
+ ...input.metadata !== void 0 ? { metadata: sanitizeMetadata(input.metadata) } : {},
2265
2276
  totalEmailsSent: 0
2266
2277
  };
2267
2278
  const account = await EmailAccount.create(accountData);
@@ -2296,6 +2307,7 @@ function createAccountController(EmailAccount, capacityManager, healthTracker, w
2296
2307
  }
2297
2308
  }
2298
2309
  if (input.limits?.dailyMax !== void 0) updates["limits.dailyMax"] = input.limits.dailyMax;
2310
+ if (input.metadata !== void 0) updates.metadata = sanitizeMetadata(input.metadata);
2299
2311
  const account = await EmailAccount.findByIdAndUpdate(
2300
2312
  req.params.id,
2301
2313
  { $set: updates },