@dibs-tech/mail-client
Advanced tools
Comparing version 1.5.6 to 1.6.0
57
index.js
@@ -22,7 +22,14 @@ const SparkPost = require('sparkpost'); | ||
*/ | ||
function MailClient() { | ||
this.client = new SparkPost(process.env.SPARKPOST_API_KEY); | ||
function MailClient(apiKey = process.env.SPARKPOST_API_KEY) { | ||
this.apiKey = apiKey; | ||
this.client = new SparkPost(apiKey); | ||
} | ||
Object.defineProperty(MailClient.prototype, 'sparkPostPrefix', { | ||
get() { | ||
return 'https://api.sparkpost.com/api/v1'; | ||
}, | ||
}); | ||
/** | ||
@@ -180,2 +187,48 @@ * sendEmail - Description | ||
MailClient.prototype.addEmailToTransactionalSupressionList = function addEmailToTransactionalSupressionList(email, cb) { | ||
this.client.suppressionList.upsert({ | ||
recipient: email, | ||
type: 'transactional' | ||
}, cb) | ||
} | ||
MailClient.prototype.addEmailToNonTransactionalSupressionList = function addEmailToTransactionalSupressionList(email, cb) { | ||
this.client.suppressionList.upsert({ | ||
recipient: email, | ||
type: 'non_transactional' | ||
}, cb) | ||
} | ||
MailClient.prototype.removeEmailFromTransactionalSupressionList = function removeEmailFromTransactionalSupressionList(email, cb) { | ||
if (typeof cb !== 'function') cb = () => {}; | ||
axios.delete(`${this.sparkPostPrefix}/suppression-list/${email}`, { | ||
headers: { | ||
Authorization: this.apiKey, | ||
Accept: 'application/json', | ||
}, | ||
data: { | ||
type: 'transactional' | ||
} | ||
}).then(response => cb(null, response.data)) | ||
.catch((err => cb(err.response.data))); | ||
}; | ||
MailClient.prototype.removeEmailFromNonTransactionalSupressionList = function removeEmailFromNonTransactionalSupressionList(email, cb) { | ||
if (typeof cb !== 'function') cb = () => {}; | ||
axios.delete(`${this.sparkPostPrefix}/suppression-list/${email}`, { | ||
headers: { | ||
Authorization: this.apiKey, | ||
Accept: 'application/json', | ||
}, | ||
data: { | ||
type: 'non_transactional' | ||
} | ||
}).then(response => cb(null, response.data)) | ||
.catch((err => cb(err.response.data))); | ||
}; | ||
module.exports = MailClient; |
{ | ||
"name": "@dibs-tech/mail-client", | ||
"version": "1.5.6", | ||
"version": "1.6.0", | ||
"description": "A mail client implementation, using sparkpost", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10834
7
224