index.js 859 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. const config = require('config');
  3. const enabled = config.get('apis.mailgun.enabled');
  4. let mailgun = null;
  5. if (enabled) {
  6. mailgun = require('mailgun-js')({
  7. apiKey: config.get("apis.mailgun.key"),
  8. domain: config.get("apis.mailgun.domain")
  9. });
  10. }
  11. let initialized = false;
  12. let lockdown = false;
  13. let lib = {
  14. schemas: {},
  15. init: (cb) => {
  16. lib.schemas = {
  17. verifyEmail: require('./schemas/verifyEmail'),
  18. resetPasswordRequest: require('./schemas/resetPasswordRequest'),
  19. passwordRequest: require('./schemas/passwordRequest')
  20. };
  21. initialized = true;
  22. if (lockdown) return this._lockdown();
  23. cb();
  24. },
  25. sendMail: (data, cb) => {
  26. if (lockdown) return cb('Lockdown');
  27. if (!cb) cb = ()=>{};
  28. if (enabled) mailgun.messages().send(data, cb);
  29. else cb();
  30. },
  31. _lockdown: () => {
  32. lockdown = true;
  33. }
  34. };
  35. module.exports = lib;