Skip to content

v3.0.0

Latest
Compare
Choose a tag to compare
@dr-dimitru dr-dimitru released this 14 Apr 20:34
b6f43ba

📦 NPM @3.0.0
☄️ Packosphere @3.0.0

Major Changes

  • ☝️ NPM release skipped v2.x in order to match Meteor's version (NPM release happened one generation later)
  • ⚠️ New way to import and require the package import { MailTime, MongoQueue, RedisQueue } from 'mail-time';
  • ⚠️ Decouple from storage, now requires {queue} passed to constructor new MailTime({})
  • ⚠️ Removed callback from .sendMail() method
  • 🟥 Added support for Redis as Queue storage driver 🥳
  • 🍃 MongoDB as optional Queue storage driver 🥳
  • ☝️ Now josk task manager and Queue driver can use different databases

Whats' new

  • ping() method
  • cancelMail() method
  • onSent() callback option
  • ✨ new opts.josk option for josk library-specific options
  • ✨ new opts.queue option for storage-driver
  • opts.retryDelay retry delay in ms, successor to opts.interval
  • opts.retries quantity of retry attempts, successor to opts.maxTries
  • opts.concatDelay concatenation delay in ms, successor to opts.concatThrottling
  • 👨‍🔬 A lot of new improved tests
  • 📔 Custom Queue API

Changes

  • ☝️ .sendMail() now returns {Promise<string>} that can get passed into .cancelMail() method

Dependencies

Dev Dependencies

Migrate to v3

Import was in v1/v2:

import MailTime from 'mail-time';

Changed in v3 to:

import { MailTime, MongoQueue, RedisQueue } from 'mail-time';

new MailTime in v3

Constructor was in v1/v2:

new MailTime({
  db,
})

Changed in v3 to:

new MailTime({
  queue: new MongoQueue({ db }),
  josk: {
    adapter: {
      type: 'mongo',
      db: db
    }
  }
})

prefix in v3

Constructor was in v1/v2:

new MailTime({
  db,
  prefix: 'prefix'
})

prefix need to get duplicated in queue constructor in v3:

new MailTime({
  prefix: 'prefix',
  queue: new MongoQueue({
    db: db,
    prefix: 'prefix',
  }),
  josk: {
    adapter: {
      type: 'mongo',
      db: db,
    }
  }
})

sent/failed callback in v3

Constructor was in v1/v2:

MailTime#sendMail(message, (error, details) => {
  console.log({error, details})
});

Callbacks are removed in v3, onError and onSent should be used instead:

const mailQueue = new MailTime({
  queue: new MongoQueue({ db }),
  josk: {
    adapter: { type: 'mongo', db }
  },
  onError(error, email, details) {
    console.log(`Email "${email.mailOptions.subject}" wasn't sent to ${email.mailOptions.to}`, error, details);
  },
  onSent(email, details) {
    console.log(`Email "${email.mailOptions.subject}" successfully sent to ${email.mailOptions.to}`, details);
  },
});

await mailQueue.sendMail(message);