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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ze-preguica-services

v1.0.7

Published

services for ze preguica

Readme

ze-preguica-services

A collection of utility services and helpers for the Ze-Preguica platform, designed to be easily imported and used across different projects.

📋 Description

This package provides essential utility services including AWS Secrets Manager integration and JWT authentication helpers. It's built with TypeScript and optimized for AWS Lambda environments.

✨ Available Services

🔐 AWS Secrets Manager

  • Secure secret retrieval with built-in caching
  • TypeScript support with full type definitions
  • Error handling for missing or invalid secrets

🔑 JWT Authentication

  • Token verification for API Gateway requests
  • Request authentication helpers
  • AWS Lambda integration ready

🚀 Installation

npm install ze-preguica-services

📦 Dependencies

Production

  • aws-sdk: ^2.1692.0 - AWS SDK for cloud services
  • jsonwebtoken: ^9.0.2 - JWT token handling
  • aws-lambda: ^1.0.7 - AWS Lambda types

Development

  • typescript: ^5.8.3 - TypeScript compiler
  • @types/node: ^24.0.10 - Node.js type definitions
  • @types/jsonwebtoken: ^9.0.10 - JWT type definitions
  • @types/aws-lambda: ^8.10.150 - Lambda type definitions

💻 Usage

AWS Secrets Manager

import { getSecretValue } from 'ze-preguica-services';

// Retrieve a secret from AWS Secrets Manager
async function getApiKey() {
  try {
    const apiKey = await getSecretValue({
      secretId: 'my-api-key',
      region: 'us-east-1'
    });
    
    console.log('Secret retrieved:', apiKey);
    return apiKey;
  } catch (error) {
    console.error('Error retrieving secret:', error);
    throw error;
  }
}

JWT Authentication

import { authenticateRequest, verifyJwt } from 'ze-preguica-services';
import { APIGatewayProxyEvent } from 'aws-lambda';

// Authenticate API Gateway request
export async function handler(event: APIGatewayProxyEvent) {
  const jwtSecret = process.env.JWT_SECRET || 'your-secret-key';
  
  const authResult = authenticateRequest(event, jwtSecret);
  
  if (authResult.statusCode) {
    // Authentication failed
    return authResult;
  }
  
  // Authentication successful
  const { token, payload } = authResult;
  console.log('Authenticated user:', payload);
  
  // Your business logic here
  return {
    statusCode: 200,
    body: JSON.stringify({ message: 'Authenticated successfully' })
  };
}

// Verify JWT token directly
function verifyToken(token: string) {
  const secret = process.env.JWT_SECRET || 'your-secret-key';
  const decoded = verifyJwt(token, secret);
  
  if (typeof decoded === 'object' && decoded.statusCode) {
    // Token verification failed
    return null;
  }
  
  return decoded;
}

🔧 Configuration

AWS Secrets Manager

Make sure your AWS credentials are properly configured:

# AWS CLI
aws configure

# Or environment variables
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_REGION=us-east-1

JWT Authentication

Set your JWT secret in environment variables:

export JWT_SECRET=your-super-secret-jwt-key

📁 Project Structure

src/
├── index.ts              # Main exports
├── getSecretOptions/     # AWS Secrets Manager utilities
│   └── index.ts         # getSecretValue function
├── auth-jwt/            # JWT authentication utilities
│   └── index.ts         # Authentication functions
└── types/               # TypeScript type definitions
    └── types.ts         # Shared types

🏗️ Development

Build

npm run build

Publishing

npm publish

The package automatically builds before publishing thanks to the prepublishOnly script.

📝 API Reference

getSecretValue(options: GetSecretOptions): Promise

Retrieves a secret from AWS Secrets Manager with caching.

Parameters:

  • options.secretId (string): The name or ARN of the secret
  • options.region (string): The AWS region

Returns: Promise - The secret value

authenticateRequest(event: APIGatewayProxyEvent, secret: string)

Authenticates an API Gateway request using JWT.

Parameters:

  • event (APIGatewayProxyEvent): The API Gateway event
  • secret (string): The JWT secret key

Returns:

  • Success: { token: string, payload: any }
  • Failure: { statusCode: 401, body: string }

verifyJwt(token: string, secret: string)

Verifies a JWT token.

Parameters:

  • token (string): The JWT token to verify
  • secret (string): The JWT secret key

Returns:

  • Success: The decoded token payload
  • Failure: { statusCode: 401, body: string }

🔒 Security Features

  • In-memory caching for AWS Secrets Manager (performance optimization)
  • JWT token validation with proper error handling
  • Authorization header parsing for Bearer tokens
  • Type-safe operations with TypeScript

⚠️ Important Notes

  • Cache behavior: Secrets are cached in memory and persist for the lifetime of the process
  • JWT format: Expects Bearer tokens in the format Bearer <token>
  • AWS permissions: Requires secretsmanager:GetSecretValue permission
  • Environment: Optimized for AWS Lambda but works in any Node.js environment

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-utility)
  3. Add your utility service
  4. Update the main index.ts to export your new service
  5. Add tests and documentation
  6. Submit a pull request

📝 License

MIT - see LICENSE file for details.

👨‍💻 Author

Matheus Mangueira


Built with ❤️ for the Ze-Preguica platform