New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@orbiting/backend-modules-mail

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orbiting/backend-modules-mail - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

21

CHANGELOG.md

@@ -1,6 +0,23 @@

<a name="1.0.0"></a>
# 1.0.0 (2018-01-18)
<a name="2.0.0"></a>
# 2.0.0 (2018-01-18)
<a name="2.0.0"></a>
# 2.0.0 (2018-01-18)
### Bug Fixes
* **mail:** fix check-env and mailchimp rate limit issues ([67041c2](https://github.com/orbiting/backend-modules/commit/67041c2))
### BREAKING CHANGES
* **mail:** affecting mail
ISSUES CLOSED: #27
<a name="1.0.0"></a>

@@ -7,0 +24,0 @@ # 1.0.0 (2018-01-18)

5

integration.test.js

@@ -12,4 +12,7 @@ require('dotenv').config({ path: '../../.test.env' })

// the mail address needs to stay the same while doing all the tests
const randomString = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
const user = (role) => ({
email: 'test8@test.project-r.construction',
email: `${randomString}@test.project-r.construction`,
roles: role ? [role] : []

@@ -16,0 +19,0 @@ })

@@ -12,84 +12,85 @@ const fetch = require('isomorphic-unfetch')

checkEnv([
'MAILCHIMP_API_KEY',
'MAILCHIMP_URL',
'MAILCHIMP_MAIN_LIST_ID'
])
const MINIMUM_HTTP_RESPONSE_STATUS_ERROR = 400
const MailchimpInterface = ({ logger }) => ({
buildApiUrl (path) {
return `${MAILCHIMP_URL}/3.0/lists/${MAILCHIMP_MAIN_LIST_ID}${path}`
},
buildMembersApiUrl (email) {
const hash = crypto
.createHash('md5')
.update(email)
.digest('hex')
.toLowerCase()
const MailchimpInterface = ({ logger }) => {
checkEnv([
'MAILCHIMP_API_KEY',
'MAILCHIMP_URL',
'MAILCHIMP_MAIN_LIST_ID'
])
return {
buildApiUrl (path) {
return `${MAILCHIMP_URL}/3.0/lists/${MAILCHIMP_MAIN_LIST_ID}${path}`
},
buildMembersApiUrl (email) {
const hash = crypto
.createHash('md5')
.update(email)
.digest('hex')
.toLowerCase()
return this.buildApiUrl(`/members/${hash}`)
},
async fetchAuthenticated (method, url, request = {}) {
logger.log(`mailchimp -> ${method} ${url}`)
const options = {
method,
headers: {
Authorization:
'Basic ' +
Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString(
'base64'
)
},
...request
}
return fetch(url, options)
},
async getMember (email) {
const url = this.buildMembersApiUrl(email)
try {
const response = await this.fetchAuthenticated('GET', url)
const json = await response.json()
if (response.status >= MINIMUM_HTTP_RESPONSE_STATUS_ERROR) {
logger.error(`mailchimp -> could not get member: ${email} ${json.detail}`)
return null
return this.buildApiUrl(`/members/${hash}`)
},
async fetchAuthenticated (method, url, request = {}) {
logger.log(`mailchimp -> ${method} ${url}`)
const options = {
method,
headers: {
Authorization:
'Basic ' +
Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString(
'base64'
)
},
...request
}
return json
} catch (error) {
logger.error(`mailchimp -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, email })
}
},
async updateMember (email, data) {
const url = this.buildMembersApiUrl(email)
try {
const request = { body: JSON.stringify(data) }
const response = await this.fetchAuthenticated('PUT', url, request)
const json = await response.json()
if (response.status >= MINIMUM_HTTP_RESPONSE_STATUS_ERROR) {
logger.error(`mailchimp -> could not update member: ${email} ${json.detail}`)
return null
return fetch(url, options)
},
async getMember (email) {
const url = this.buildMembersApiUrl(email)
try {
const response = await this.fetchAuthenticated('GET', url)
const json = await response.json()
if (response.status >= MINIMUM_HTTP_RESPONSE_STATUS_ERROR) {
logger.error(`mailchimp -> could not get member: ${email} ${json.detail}`)
return null
}
return json
} catch (error) {
logger.error(`mailchimp -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, email })
}
return json
} catch (error) {
logger.error(`mailchimp -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, email })
}
},
async deleteMember (email) {
const url = this.buildMembersApiUrl(email)
try {
const response = await this.fetchAuthenticated('DELETE', url)
if (response.status >= MINIMUM_HTTP_RESPONSE_STATUS_ERROR) {
logger.error(`mailchimp -> could not delete member: ${email}`)
return null
},
async updateMember (email, data) {
const url = this.buildMembersApiUrl(email)
try {
const request = { body: JSON.stringify(data) }
const response = await this.fetchAuthenticated('PUT', url, request)
const json = await response.json()
if (response.status >= MINIMUM_HTTP_RESPONSE_STATUS_ERROR) {
logger.error(`mailchimp -> could not update member: ${email} ${json.detail}`)
return null
}
return json
} catch (error) {
logger.error(`mailchimp -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, email })
}
return true
} catch (error) {
logger.error(`mailchimp -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, email })
},
async deleteMember (email) {
const url = this.buildMembersApiUrl(email)
try {
const response = await this.fetchAuthenticated('DELETE', url)
if (response.status >= MINIMUM_HTTP_RESPONSE_STATUS_ERROR) {
logger.error(`mailchimp -> could not delete member: ${email}`)
return null
}
return true
} catch (error) {
logger.error(`mailchimp -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, email })
}
}
}
})
}

@@ -96,0 +97,0 @@ MailchimpInterface.MemberStatus = {

@@ -9,43 +9,44 @@ const fetch = require('isomorphic-unfetch')

checkEnv([
'MANDRILL_API_KEY'
])
const MandrillInterface = ({ logger }) => ({
buildApiUrl (path) {
return `https://mandrillapp.com/api/1.0${path}`
},
async fetchAuthenticated (method, url, request = {}) {
return fetch(url, {
method,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
key: MANDRILL_API_KEY,
...request
const MandrillInterface = ({ logger }) => {
checkEnv([
'MANDRILL_API_KEY'
])
return {
buildApiUrl (path) {
return `https://mandrillapp.com/api/1.0${path}`
},
async fetchAuthenticated (method, url, request = {}) {
return fetch(url, {
method,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
key: MANDRILL_API_KEY,
...request
})
})
})
},
async send (message, templateName, templateContent) {
const url = this.buildApiUrl(
templateName
? '/messages/send-template.json'
: '/messages/send.json')
try {
const body = { message }
if (templateName) {
body['template_name'] = templateName
body['template_content'] = templateContent
},
async send (message, templateName, templateContent) {
const url = this.buildApiUrl(
templateName
? '/messages/send-template.json'
: '/messages/send.json')
try {
const body = { message }
if (templateName) {
body['template_name'] = templateName
body['template_content'] = templateContent
}
const response = await this.fetchAuthenticated('POST', url, body)
const json = await response.json()
return json
} catch (error) {
logger.error(`mandrill -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, message })
}
const response = await this.fetchAuthenticated('POST', url, body)
const json = await response.json()
return json
} catch (error) {
logger.error(`mandrill -> exception: ${error.message}`)
throw new NewsletterMemberMailError({ error, message })
}
}
})
}
module.exports = MandrillInterface
{
"name": "@orbiting/backend-modules-mail",
"version": "1.0.0",
"version": "2.0.0",
"description": "simple mails with mandrill, manage subscriptions on mailchimp",

@@ -20,3 +20,4 @@ "main": "index.js",

"scripts": {
"link": "yarn link"
"link": "yarn link",
"test": "NODE_ENV=development tape \"**/*.test.js\""
},

@@ -23,0 +24,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc