Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@planorjs/core
Advanced tools
Readme
Email and sms sending library with parsable templates and plugins. ✈️
Planor is based on MIMEText. It has a simple template engine and a wrapper class PlanorService
to send emails and sms. Once you setup its very easy to use.
await planor.sendEmail('VERIFY_SIGNIN', {to: 'test@test.com'}, {code: '918273'})
// check your email for verification code!
npm i @planorjs/core
Choose the services you would like to use to send email and/or sms and install its plugin:
npm i @planorjs/plugin-gmail
npm i @planorjs/plugin-smtp
npm i @planorjs/plugin-postmark
import {Planor, PlanorService, PlanorTemplate} from 'planor'
or
const {Planor, PlanorService, PlanorTemplate} = require('planor')
This library is compatible with all node/lts versions. If your node version is < 14 then:
import {Planor, PlanorService, PlanorTemplate} from 'planor/node/lts'
const planor = new Planor()
Create a new PlanorTemplate
instance with channel
, id
, locale
and template
in order.
const emailTemplate = new PlanorTemplate('email', 'VERIFY_SIGNIN', 'en_US', [
'Your {{project}} Verification Code', // email subject
'You have requested to signin to {{project}} and your verification code is "{{code}}"' // email content
])
planor.addTemplate(emailTemplate)
Channel is one of email and sms. Id is the name you chose to remember when sending emails. locale is currently experimental state but you still need to specify it.
Template is an array of subject and content. The example above creates a plaintext template. To create an html template:
const emailTemplate = new PlanorTemplate('email', 'VERIFY_SIGNIN', 'en_US', [
'Your {{project}} Verification Code', // email subject
{type: 'text/html', template: 'You have requested to signin to {{project}} and your verification code is "{{code}}"'} // email content
])
planor.addTemplate(emailTemplate)
Just wrapped it in an object with a type property. It also supports parsing mjml templates:
const emailTemplate = new PlanorTemplate('email', 'VERIFY_SIGNIN', 'en_US', [
'Your {{project}} Verification Code', // email subject
{type: 'text/mjml', template: '<mjml>You have requested to signin to {{project}} and your verification code is "{{code}}"</mjml>'} // email content
])
planor.addTemplate(emailTemplate)
PlanorTemplate supports template literal parsing but template literals kept inside Planor not PlanorTemplate.
planor.updateTemplateLiterals({project: 'SomeApp'})
By default, there is no email service provider. You need to add one. Gmail service for example:
import PlanorServiceGmail from '@planorjs/plugin-gmail'
const credentials = {
sender: 'test@test.com',
gcloudProject: 'project-name',
googleApplicationCredentials: '/path/to/googleCloudServiceAccount.json'
}
await planor.addService(new PlanorServiceGmail(credentials))
Or SMTP server:
import PlanorServiceSmtp from '@planorjs/plugin-smtp'
const credentials = {
host: 'mail.test.net',
port: '465',
username: 'test@test.com',
password: '----'
}
const service = new PlanorServiceSmtp(credentials)
await planor.addService(service)
const result = await planor.sendEmail('VERIFY_SIGNIN', {to: 'some@email.tld'}, {code: '918273'})
The first argument is the id
of the template. The second argument is options for MIMEText and may contain service specific options. The third argument is one-time template literals.
As a result, you will get an object that contains a result.id
.
You can add as many services as you like. Planor will try to send until it sends successfully.
You can collect errors with planor.getErrors()
. sendEmail
won't throw you anything.
Messagebird, currently the only plugin available for sms:
import PlanorServiceMessagebird from '@planorjs/plugin-messagebird'
const credentials = {
origin: '...',
accessKey: '...'
}
const service = new PlanorServiceMessagebird(credentials)
const result = await planor.sendSms('VERIFY_SIGNIN', {recipients: ['+1234567890']}, {code: '918273'})
A template for the plugin:
class PlanorServiceTest extends PlanorService {
constructor() {
super('nameOfTheService', 'email')
this.credentialKeys = ['from', 'token']
}
// create client
async getClient() {
const creds = super.getCredentials()
process.env.TEST_API_KEY = creds.apiKey
this.client = 'Test Client'
}
// actually send the message
async send(mimemsg, mimeopts) {
return {
apiKey: process.env.TEST_API_KEY,
secret: super.getCredentials().secret
}
}
}
The mimemsg here is an instance of MIMEText
Version management of this repository done by releaser 🚀
Thanks for watching 🐬
FAQs
Email and sms sending library with parsable templates and plugins. ✈️
The npm package @planorjs/core receives a total of 44 weekly downloads. As such, @planorjs/core popularity was classified as not popular.
We found that @planorjs/core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.