Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sendgrid-template-helper

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sendgrid-template-helper - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

43

lib/index.js

@@ -1,9 +0,9 @@

"use strict";
'use strict';
const fs = require("fs");
const fspath = require("path");
const crypto = require("crypto");
const { Client } = require("@sendgrid/client");
const { MailService } = require("@sendgrid/mail");
const _ = require("lodash");
const fs = require('fs');
const fspath = require('path');
const crypto = require('crypto');
const { Client } = require('@sendgrid/client');
const { MailService } = require('@sendgrid/mail');
const _ = require('lodash');

@@ -17,10 +17,10 @@ function Email(settings) {

if (_.isUndefined(settings.apiKey) || _.isEmpty(settings.apiKey)) {
throw new Error("SendGird API Key is required");
throw new Error('SendGird API Key is required');
}
this.apiKey = settings.apiKey;
this.prefix = settings.prefix ? settings.prefix : "sendgrid_template_helper_";
this.prefix = settings.prefix ? settings.prefix : 'sendgrid_template_helper_';
this.postfix = `_${this.createHash(this.prefix + this.apiKey)}`;
this.sgClient = new Client();
this.sgClient.setApiKey(this.apiKey);
this.sgClient.setDefaultRequest("baseUrl", "https://api.sendgrid.com/v3");
this.sgClient.setDefaultRequest('baseUrl', 'https://api.sendgrid.com/v3');
this.sgMail = new MailService();

@@ -63,8 +63,3 @@ this.sgMail.setApiKey(this.apiKey);

.then(resolve)
.catch((err) => {
if (err.code === 401 || err.code === 403) {
err = new Error("Invalid SendGrid API Key");
}
reject(err);
});
.catch(reject);
});

@@ -125,3 +120,3 @@ });

Email.prototype.getTemplates = function () {
return this.sgRequest("GET", "/templates?generations=dynamic").then(
return this.sgRequest('GET', '/templates?generations=dynamic').then(
(body) => body.templates

@@ -140,5 +135,5 @@ );

Email.prototype.createTemplate = function (templateName) {
return this.sgRequest("POST", "/templates", {
return this.sgRequest('POST', '/templates', {
name: templateName,
generation: "dynamic",
generation: 'dynamic',
});

@@ -162,3 +157,3 @@ };

) {
return this.sgRequest("POST", `/templates/${templateId}/versions`, {
return this.sgRequest('POST', `/templates/${templateId}/versions`, {
template_id: templateId,

@@ -168,3 +163,3 @@ name: versionName,

active: 1,
subject: "{{subject}}",
subject: '{{subject}}',
});

@@ -191,3 +186,3 @@ };

return this.sgRequest(
"PATCH",
'PATCH',
`/templates/${templateId}/versions/${versionId}`,

@@ -216,3 +211,3 @@ {

}
const templateContent = fs.readFileSync(templatePath, "utf-8");
const templateContent = fs.readFileSync(templatePath, 'utf-8');
const versionName = this.createHash(templateContent);

@@ -273,5 +268,5 @@

Email.prototype.createHash = function (message) {
return crypto.createHash("md5").update(message).digest("hex");
return crypto.createHash('md5').update(message).digest('hex');
};
module.exports = Email;
{
"name": "sendgrid-template-helper",
"version": "1.0.1",
"version": "1.0.2",
"description": "The Sendgrid wrapper helps to send an email with a dynamic template stored on disk.",

@@ -27,4 +27,4 @@ "main": "./lib/index.js",

"dependencies": {
"@sendgrid/client": "^7.0.1",
"@sendgrid/mail": "^7.0.1",
"@sendgrid/client": "^7.1.1",
"@sendgrid/mail": "^7.1.1",
"lodash": "^4.17.15"

@@ -31,0 +31,0 @@ },

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