npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@saibotsivad/aws-ses

v1.1.0

Published

Minimalist request generator for SES (AWS Simple Email Service).

Downloads

80

Readme

@saibotsivad/aws-ses

Minimalist request generator for SES (AWS Simple Email Service).

Generates the url, headers, and body for a POST request to the AWS SES API, using the v4 signing algorithm.

Install

Any of the normal ways:

npm install @saibotsivad/aws-ses

Example

Following the documentation, e.g. for sending an email:

import { awsSes, extractResponse } from '@saibotsivad/aws-ses'
import { post } from 'httpie'

const generateRequest = awsSes({
	credentials: {
		region: process.env.AWS_REGION,
		accessKeyId: process.env.AWS_ACCESS_KEY_ID,
		secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
	}
})

const sendEmail = async email => {
	const { url, headers, body } = await generateRequest('SendEmail', email)

	let response
	try {
		response = await post(url, { headers, body })
	} catch (error) {
		response = error
	}

	return {
		success: response.statusCode === 200,
		data: response.data
	}
}

// ...then later:
const { data, success } = await sendEmail({
	Destination: {
		ToAddresses: [
			'[email protected]'
		]
	},
	Message: {
		Body: {
			Text: {
				Charset: 'UTF-8',
				Data: 'Plaintext message body.'
			}
		},
		Subject: {
			Charset: 'UTF-8',
			Data: 'Hello user!'
		},
	},
	ReplyToAddresses: [
		'[email protected]'
	],
	Source: '[email protected]'
})

// convenience helper function
console.log(extractResponse(data)) // => { messageId, ... }

API

This library exports two functions, extractResponse and awsSes.

extractResponse: function ( String ) => Object

A convenience function which uses a regular expression to extract the <MessageId /> value from the response data, which is an XML string.

Note: If you have an XML parsing library in your project already, it would be safer to use that instead.

Returns an object with the following possible properties:

  • messageId: String The id of the sent message, if appropriate to the action.
  • requestId: String The id of the API request, generated by AWS.
  • errorType: String The error type, if present, e.g. Sender.
  • errorCode: String The error code, if present, e.g. MessageRejected.
  • errorMessage: String The full error message, if present.

awsSes: function ( Object<{ credentials: Object, url?: String }> ) => generateRequest: function

Instantiates a request generator. Pass in an object with the property credentials containing the AWS configuration and credentials.

The credentials object takes the following properties:

  • region: String (required) The AWS region, e.g. us-east-1.
  • accessKeyId (required) The identifier of the access key.
  • secretAccessKey (required) The key secret.

If the url string is set, it will be used instead of the AWS region-based URL.

generateRequest: async function ( action: String, params: Object ) => Object<{ url, headers, body }>

Generate the request parameters using the v4 signature algorithm.

  • action: String (required) Any valid action defined in the documentation.
  • params: Object (required) Whatever the parameters are for that action.

Returns an object with parameters necessary for making the POST request.

  • url: String The URL for the specified region, e.g. https://email.us-west-2.amazonaws.com/
  • headers: Object<String, String> The headers map containing the signed authorization headers.
  • body: String The form-url encoded body string.

License

Published and released with love under the Very Open License.