├── .babelrc ├── .gitignore ├── README.md ├── lib └── index.js ├── package.json └── src └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # parse-server-sendgrid-adapter 2 | Simple sendgrid adapter for parse server 3 | 4 | ## Configuration 5 | 6 | ``` 7 | var express = require('express'); 8 | var ParseServer = require('parse-server').ParseServer; 9 | var app = express(); 10 | var SimpleSendGridAdapter = require('parse-server-sendgrid-adapter'); 11 | 12 | // Specify the connection string for your mongodb database 13 | // and the location to your Parse cloud code 14 | var api = new ParseServer({ 15 | databaseURI: 'mongodb://localhost:27017/dev', 16 | cloud: '/home/myApp/cloud/main.js', // Provide an absolute path 17 | appId: 'myAppId', 18 | masterKey: 'myMasterKey', // Keep this key secret! 19 | fileKey: 'optionalFileKey', 20 | serverURL: 'http://localhost:1337/parse', // Don't forget to change to https if needed 21 | appName: 'myAppName', 22 | publicServerURL: 'http://localhost:1337/parse', 23 | emailAdapter: SimpleSendGridAdapter({ 24 | apiKey: 'sendgridApiKey', 25 | fromAddress: 'fromEmailAddress', 26 | }) 27 | }); 28 | 29 | // Serve the Parse API on the /parse URL prefix 30 | app.use('/parse', api); 31 | 32 | app.listen(1337, function() { 33 | console.log('parse-server-example running on port 1337.'); 34 | }); 35 | 36 | ``` 37 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var _sendgrid = require('sendgrid'); 4 | 5 | var _sendgrid2 = _interopRequireDefault(_sendgrid); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 8 | 9 | var SimpleSendGridAdapter = function SimpleSendGridAdapter(mailOptions) { 10 | if (!mailOptions || !mailOptions.apiKey || !mailOptions.fromAddress) { 11 | throw 'SimpleSendGridAdapter requires an API Key.'; 12 | } 13 | var sendgrid = (0, _sendgrid2.default)(mailOptions.apiKey); 14 | 15 | var sendMail = function sendMail(_ref) { 16 | var to = _ref.to; 17 | var subject = _ref.subject; 18 | var text = _ref.text; 19 | 20 | return new Promise(function (resolve, reject) { 21 | sendgrid.send({ 22 | from: mailOptions.fromAddress, 23 | to: to, 24 | subject: subject, 25 | text: text 26 | }, function (err, json) { 27 | if (err) { 28 | reject(err); 29 | } 30 | resolve(json); 31 | }); 32 | }); 33 | }; 34 | 35 | return Object.freeze({ 36 | sendMail: sendMail 37 | }); 38 | }; 39 | 40 | module.exports = SimpleSendGridAdapter; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "parse-server-sendgrid-adapter", 3 | "version": "1.0.0", 4 | "description": "Simple sendgrid adapter for parse server", 5 | "main": "lib/index.js", 6 | "dependencies": { 7 | "sendgrid": "^2.0.0" 8 | }, 9 | "devDependencies": { 10 | "babel-cli": "^6.6.5", 11 | "babel-preset-es2015": "^6.6.0" 12 | }, 13 | "scripts": { 14 | "build": "./node_modules/.bin/babel src/ -d lib/", 15 | "test": "echo \"Error: no test specified\" && exit 1" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/oursky/parse-server-sendgrid-adapter.git" 20 | }, 21 | "keywords": [ 22 | "parse-server", 23 | "sendgrid" 24 | ], 25 | "author": "Oursky", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/oursky/parse-server-sendgrid-adapter/issues" 29 | }, 30 | "homepage": "https://github.com/oursky/parse-server-sendgrid-adapter#readme" 31 | } 32 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import SendGrid from 'sendgrid'; 2 | 3 | let SimpleSendGridAdapter = mailOptions => { 4 | if (!mailOptions || !mailOptions.apiKey || !mailOptions.fromAddress) { 5 | throw 'SimpleSendGridAdapter requires an API Key.'; 6 | } 7 | let sendgrid = SendGrid(mailOptions.apiKey); 8 | 9 | let sendMail = ({to, subject, text}) => { 10 | return new Promise((resolve, reject) => { 11 | sendgrid.send({ 12 | from: mailOptions.fromAddress, 13 | to: to, 14 | subject: subject, 15 | text: text, 16 | }, function(err, json) { 17 | if (err) { 18 | reject(err); 19 | } 20 | resolve(json); 21 | }); 22 | }); 23 | } 24 | 25 | return Object.freeze({ 26 | sendMail: sendMail 27 | }); 28 | } 29 | 30 | module.exports = SimpleSendGridAdapter 31 | --------------------------------------------------------------------------------