Skip to content
Browse files

initial version

  • Loading branch information...
0 parents commit 4ac725a7da2ba70913fe13275c3eb549701bacce @tellnes committed Oct 23, 2012
Showing with 158 additions and 0 deletions.
  1. +59 −0 Readme.md
  2. +21 −0 example.js
  3. +48 −0 index.js
  4. +30 −0 package.json
59 Readme.md
@@ -0,0 +1,59 @@
+# AWS SES Feedback
+
+`aws-ses-feedback` makes it easy to handle feedback from aws ses.
+
+## Install
+
+ npm install aws-ses-feedback
+
+## Example
+
+```js
+var sesFeedback = require('aws-ses-feedback')
+
+var feedback = sesFeedback( { url: '/feedback'
+ , region: 'us-east-1'
+ , account: 'xxx'
+ , topic: 'xxx'
+ })
+
+feedback.on('bounce', function(message) {
+ console.log(message)
+})
+
+feedback.on('complaint', function(message) {
+ console.log(message)
+})
+
+feedback.on('error', function(err) {
+ console.error(err)
+})
+
+feedback.listen(8080)
+```
+
+## Connect / Express compatible
+
+```js
+var app = connect()
+ , feedback = sesFeedback()
+
+app.use(feedback)
+
+app.listen(8080)
+```
+
+## Options
+
+### `url`
+
+`req.url` must be equal to `options.url`. Defaults to `/`.
+
+### `region`, `account` and `topic`
+
+Used to verify incomming notification. Se [`aws-snsclient` request verification](https://github.com/mattrobenolt/node-snsclient#request-verification) for details.
+
+
+## Licence
+
+MIT
21 example.js
@@ -0,0 +1,21 @@
+var sesFeedback = require('./')
+
+var feedback = sesFeedback( { url: '/feedback'
+ , region: 'us-east-1'
+ , account: 'xxx'
+ , topic: 'xxx'
+ })
+
+feedback.on('bounce', function(message) {
+ console.log(message)
+})
+
+feedback.on('complaint', function(message) {
+ console.log(message)
+})
+
+feedback.on('error', function(err) {
+ console.error(err)
+})
+
+feedback.listen(8080)
48 index.js
@@ -0,0 +1,48 @@
+var SNSClient = require('aws-snsclient')
+ , EventEmitter = require('events').EventEmitter
+
+module.exports = function(options) {
+ options = options || {}
+
+ var url = options.url || '/'
+
+ var self = new EventEmitter()
+
+ var client = SNSClient(options, function(err, message) {
+ if (err) return self.emit('error', err)
+
+ var data
+
+ try {
+ data = JSON.parse(message.Message)
+ } catch(err) {
+ return self.emit('error', err)
+ }
+
+ self.emit(data.notificationType.toLowerCase(), data, message)
+ self.emit('feedback', data, message)
+ })
+
+ self.handle = function(req, res, next) {
+ if (req.method !== 'POST' || req.url !== url) return next()
+ client(req, res)
+ }
+
+ self.listen = function() {
+ var server = require('http').createServer(function() {
+ if (req.url === url) {
+ if (req.method === 'post') return client(req, res)
+
+ res.writeHead(405)
+ res.end('AWS SES Feedback - Method not allowed')
+ return
+ }
+
+ res.writeHead(404)
+ res.end('AWS SES Feedback - Not found')
+ })
+ return server.listen.apply(server, arguments)
+ }
+
+ return self
+}
30 package.json
@@ -0,0 +1,30 @@
+{
+ "name": "aws-ses-feedback",
+ "version": "0.0.0",
+ "description": "`aws-ses-feedback` makes it easy to handle feedback from aws ses.",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/tellnes/aws-ses-feedback.git"
+ },
+ "bugs": {
+ "url": "https://github.com/tellnes/aws-ses-feedback/issues"
+ },
+ "author": "Christian Tellnes <christian@tellnes.no> (http://christian.tellnes.com/)",
+ "license": "MIT",
+ "dependencies": {
+ "aws-snsclient": "~0.2.0"
+ },
+ "devDependencies": {},
+ "keywords": [
+ "aws",
+ "ses",
+ "feedback",
+ "amazon",
+ "email",
+ "mail"
+ ]
+}

0 comments on commit 4ac725a

Please sign in to comment.
Something went wrong with that request. Please try again.