mailery 0.8.1 → 0.9.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.
@@ -378,6 +378,13 @@ interface Queues {
378
378
  type QueueDriverConfig = {
379
379
  driver: 'bull';
380
380
  redis: RedisOptions | IORedis;
381
+ /**
382
+ * Redis key prefix for all queue keys (BullMQ default: 'bull').
383
+ * Namespaces multiple mailery instances on one Redis cluster — e.g.
384
+ * 'mailery-dev' / 'mailery-prod' to isolate environments. Must not
385
+ * contain ':' (BullMQ uses it as the key separator).
386
+ */
387
+ prefix?: string;
381
388
  } | {
382
389
  driver: 'agenda';
383
390
  db?: Db;
@@ -1382,6 +1389,7 @@ declare class Mailer {
1382
1389
  * MAILER_MONGODB_URI — Mongo connection string (required)
1383
1390
  * MAILER_MONGODB_DB — database name (optional; defaults to the URI default)
1384
1391
  * MAILER_REDIS_URL — Redis connection URL (required)
1392
+ * MAILER_QUEUE_PREFIX — Redis key prefix to namespace this instance (optional)
1385
1393
  * MAILER_PUBLIC_URL — base for tracking/unsub URLs (required)
1386
1394
  * MAILER_UNSUBSCRIBE_SECRET — HMAC key (required)
1387
1395
  * MAILER_SENDER_ADDRESS — postal address for CAN-SPAM (optional)
@@ -378,6 +378,13 @@ interface Queues {
378
378
  type QueueDriverConfig = {
379
379
  driver: 'bull';
380
380
  redis: RedisOptions | IORedis;
381
+ /**
382
+ * Redis key prefix for all queue keys (BullMQ default: 'bull').
383
+ * Namespaces multiple mailery instances on one Redis cluster — e.g.
384
+ * 'mailery-dev' / 'mailery-prod' to isolate environments. Must not
385
+ * contain ':' (BullMQ uses it as the key separator).
386
+ */
387
+ prefix?: string;
381
388
  } | {
382
389
  driver: 'agenda';
383
390
  db?: Db;
@@ -1382,6 +1389,7 @@ declare class Mailer {
1382
1389
  * MAILER_MONGODB_URI — Mongo connection string (required)
1383
1390
  * MAILER_MONGODB_DB — database name (optional; defaults to the URI default)
1384
1391
  * MAILER_REDIS_URL — Redis connection URL (required)
1392
+ * MAILER_QUEUE_PREFIX — Redis key prefix to namespace this instance (optional)
1385
1393
  * MAILER_PUBLIC_URL — base for tracking/unsub URLs (required)
1386
1394
  * MAILER_UNSUBSCRIBE_SECRET — HMAC key (required)
1387
1395
  * MAILER_SENDER_ADDRESS — postal address for CAN-SPAM (optional)
package/dist/testing.cjs CHANGED
@@ -14636,7 +14636,7 @@ var BullDriver = class _BullDriver {
14636
14636
  bullQueues;
14637
14637
  workers = null;
14638
14638
  bull;
14639
- static async create(redisConfig) {
14639
+ static async create(redisConfig, prefix) {
14640
14640
  let bull;
14641
14641
  try {
14642
14642
  bull = await import('bullmq');
@@ -14645,14 +14645,22 @@ var BullDriver = class _BullDriver {
14645
14645
  "mailery: queue driver 'bull' requires the 'bullmq' peer dependency. Run `npm install bullmq ioredis`."
14646
14646
  );
14647
14647
  }
14648
+ if (prefix?.includes(":")) {
14649
+ throw new Error(
14650
+ `mailery: queue prefix "${prefix}" must not contain ':' \u2014 BullMQ uses it as the Redis key separator.`
14651
+ );
14652
+ }
14648
14653
  const redis = isRedisLike(redisConfig) ? redisConfig : connect(redisConfig);
14649
- return new _BullDriver(bull, redis);
14654
+ return new _BullDriver(bull, redis, prefix);
14650
14655
  }
14651
- constructor(bull, redis) {
14656
+ prefix;
14657
+ constructor(bull, redis, prefix) {
14652
14658
  this.bull = bull;
14653
14659
  this.redis = redis;
14660
+ this.prefix = prefix;
14654
14661
  const opts = {
14655
14662
  connection: redis,
14663
+ prefix,
14656
14664
  defaultJobOptions: {
14657
14665
  removeOnComplete: { age: 24 * 3600, count: 1e3 },
14658
14666
  removeOnFail: { age: 7 * 24 * 3600 }
@@ -14684,7 +14692,7 @@ var BullDriver = class _BullDriver {
14684
14692
  }
14685
14693
  async startWorkers(opts) {
14686
14694
  if (this.workers) return;
14687
- const base = { connection: this.redis };
14695
+ const base = { connection: this.redis, prefix: this.prefix };
14688
14696
  const { Worker } = this.bull;
14689
14697
  const tick = new Worker(
14690
14698
  QUEUE_NAMES.tick,
@@ -14936,7 +14944,7 @@ var NoopDriver = class {
14936
14944
  async function createQueueDriver(config, fallbackDb) {
14937
14945
  switch (config.driver) {
14938
14946
  case "bull":
14939
- return BullDriver.create(config.redis);
14947
+ return BullDriver.create(config.redis, config.prefix);
14940
14948
  case "agenda":
14941
14949
  return AgendaDriver.create({
14942
14950
  db: config.db ?? fallbackDb,
@@ -17364,6 +17372,7 @@ var Mailer = class _Mailer {
17364
17372
  * MAILER_MONGODB_URI — Mongo connection string (required)
17365
17373
  * MAILER_MONGODB_DB — database name (optional; defaults to the URI default)
17366
17374
  * MAILER_REDIS_URL — Redis connection URL (required)
17375
+ * MAILER_QUEUE_PREFIX — Redis key prefix to namespace this instance (optional)
17367
17376
  * MAILER_PUBLIC_URL — base for tracking/unsub URLs (required)
17368
17377
  * MAILER_UNSUBSCRIBE_SECRET — HMAC key (required)
17369
17378
  * MAILER_SENDER_ADDRESS — postal address for CAN-SPAM (optional)
@@ -17412,7 +17421,11 @@ var Mailer = class _Mailer {
17412
17421
  }
17413
17422
  const defaultProvider = env.MAILER_DEFAULT_PROVIDER ?? Object.keys(providers)[0];
17414
17423
  const driverEnv = env.MAILER_QUEUE_DRIVER ?? "bull";
17415
- const queue = driverEnv === "agenda" ? { driver: "agenda" } : driverEnv === "noop" ? { driver: "noop" } : { driver: "bull", redis: { url: required("MAILER_REDIS_URL") } };
17424
+ const queue = driverEnv === "agenda" ? { driver: "agenda" } : driverEnv === "noop" ? { driver: "noop" } : {
17425
+ driver: "bull",
17426
+ redis: { url: required("MAILER_REDIS_URL") },
17427
+ prefix: env.MAILER_QUEUE_PREFIX
17428
+ };
17416
17429
  return _Mailer.init({
17417
17430
  db,
17418
17431
  adapter,