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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ditwaru-aws-helpers

v1.1.5

Published

AWS helper utilities and functions for common AWS operations

Readme

AWS Helpers

AWS helper utilities and functions for common AWS operations including DynamoDB, Cognito, and SES.

Installation

npm install ditwaru-aws-helpers

Features

  • DynamoDB: CRUD operations, table management, and query utilities
  • Cognito: User management, authentication, and OAuth flows
  • SES: Email sending and template management

Cognito OAuth Usage

Basic OAuth Flow

import { 
  getCognitoOAuthUrl, 
  exchangeCodeForTokens,
  refreshTokens,
  revokeToken,
  decodeJWT,
  getUserInfoFromToken 
} from 'ditwaru-aws-helpers';

// 1. Generate OAuth URL for user to visit
const oauthUrl = getCognitoOAuthUrl(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  'http://localhost:3000/auth/callback',
  'openid email profile'
);

// 2. After user authenticates, exchange the code for tokens
const tokens = await exchangeCodeForTokens(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  'authorization-code-from-callback',
  'http://localhost:3000/auth/callback'
  // clientSecret is optional - defaults to empty string for public clients
);

// 3. Use the tokens
const accessToken = tokens.access_token;
const idToken = tokens.id_token;
const refreshToken = tokens.refresh_token;

// 4. Decode and use the ID token
const userInfo = getUserInfoFromToken(idToken);
console.log('User email:', userInfo.email);
console.log('User name:', userInfo.name);

// 5. Refresh tokens when they expire
const newTokens = await refreshTokens(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  refreshToken
);

// 6. Revoke tokens when user signs out
await revokeToken(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  accessToken
);

Identity Provider Specific URLs

import { 
  getGoogleOAuthUrl, 
  getFacebookOAuthUrl, 
  getAppleOAuthUrl 
} from 'ditwaru-aws-helpers';

// Google OAuth
const googleUrl = getGoogleOAuthUrl(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  'http://localhost:3000/auth/callback'
);

// Facebook OAuth
const facebookUrl = getFacebookOAuthUrl(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  'http://localhost:3000/auth/callback'
);

// Apple OAuth
const appleUrl = getAppleOAuthUrl(
  'https://your-domain.auth.region.amazoncognito.com',
  'your-client-id',
  'http://localhost:3000/auth/callback'
);

Token Utilities

import { decodeJWT, isTokenExpired } from 'ditwaru-aws-helpers';

// Check if token is expired
if (isTokenExpired(accessToken)) {
  // Token is expired, need to refresh
  const newTokens = await refreshTokens(/* ... */);
}

// Decode JWT manually
const decoded = decodeJWT(idToken);
console.log('Token expires at:', new Date(decoded.exp * 1000));

DynamoDB Usage

import { 
  get, 
  put, 
  update, 
  delete: deleteItem,
  listApplications 
} from 'ditwaru-aws-helpers';

// Get a page
const page = await get('table-name', 'page-id');

// Put a page
await put('table-name', 'page-id', { content: 'Hello World' });

// Update a page
await update('table-name', 'page-id', { content: 'Updated content' });

// Delete a page
await deleteItem('table-name', 'page-id');

// List all applications (tables)
const apps = await listApplications();

SES Usage

import { sendEmail } from 'ditwaru-aws-helpers';

await sendEmail({
  to: '[email protected]',
  subject: 'Hello',
  text: 'Hello world',
  html: '<h1>Hello world</h1>'
});

Configuration

Set these environment variables:

AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1

Important Notes

OAuth Configuration

  • Cognito Domain: Use the actual domain from your Cognito User Pool, not the User Pool ID
  • Client Secret: For public clients, the functions automatically include an empty client_secret
  • Redirect URI: Must match exactly what's configured in your Cognito App Client

Security

  • Always validate tokens on the server side
  • Store refresh tokens securely
  • Use HTTPS in production
  • Implement proper CSRF protection with state parameters

Changelog

v1.1.1

  • FIXED: OAuth implementation completely rewritten
  • ADDED: Proper token exchange with client_secret handling
  • ADDED: Token refresh and revocation functions
  • ADDED: JWT decoding utilities
  • ADDED: Identity provider specific OAuth URLs
  • REMOVED: Broken initiateOAuthAuth function
  • IMPROVED: Better error handling and TypeScript types

v1.0.2

  • Initial release with basic DynamoDB and Cognito functions