1.2.8 • Published 20 days ago

@smooai/utils v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
20 days ago

About SmooAI

SmooAI is an AI-powered platform for helping businesses multiply their customer, employee, and developer experience.

Learn more on smoo.ai

SmooAI Packages

Check out other SmooAI packages at npmjs.com/org/smooai

About @smooai/utils

A collection of shared utilities and tools used across SmooAI projects. This package provides common functionality to standardize and simplify development across all SmooAI repositories.

NPM Version NPM Downloads NPM Last Update

GitHub License GitHub Actions Workflow Status GitHub Repo stars

Installation

pnpm add @smooai/utils

Available Utilities

API Handling

  • ApiError - Custom error class for handling API-specific errors with status codes and standardized error responses
  • apiHandler - Lambda function wrapper for standardized API error handling and responses, supporting both synchronous and asynchronous handlers
  • createAwsLambdaHonoApp - Factory for creating Hono apps configured for AWS Lambda with built-in request ID tracking, logging, and error handling

Collections

  • CaseInsensitiveMap - Map implementation with case-insensitive string keys, perfect for HTTP headers and configuration management
  • CaseInsensitiveSet - Set implementation with case-insensitive string values, useful for unique string collections where case doesn't matter

Error Handling

  • errorHandler - Generic error handler with logging and type-specific error processing, supporting both synchronous and asynchronous operations
  • HumanReadableSchemaError - Error class that wraps Standard Schema validation errors with human-readable messages and detailed validation information

File Operations

  • findFile - Async utility to find files in parent directories, useful for locating configuration files or project roots
  • findFileSync - Synchronous version of findFile for simpler use cases

Environment

  • isRunningLocally - Check if code is running in local development environment
  • isRunningInProd - Check if code is running in production environment

Data Validation

  • validateAndTransformPhoneNumber - Zod validator for phone numbers with E.164 formatting, ensuring consistent phone number formats across the application
  • handleSchemaValidation - Type-safe validator for Standard Schema with human-readable error messages, supporting both synchronous and asynchronous validation
  • formatStandardSchemaErrorToHumanReadable - Formats Standard Schema validation issues into readable messages with field paths and error details
  • HumanReadableSchemaError - Error class that wraps Standard Schema validation errors with human-readable messages and access to original validation details

Utilities

  • sleep - Promise-based delay function for rate limiting, testing, and async operations

Features

  • AWS Lambda Integration

    • Full support for AWS Lambda functions with proper error handling
    • Built-in request ID tracking and logging
    • Support for API Gateway, EventBridge, and SQS events
  • Standardized Error Handling

    • Consistent error handling across all handlers
    • Human-readable error messages
    • Proper error logging with context
    • Support for API errors, validation errors, and unexpected errors
  • Case-insensitive Collections

    • Optimized for HTTP headers and configuration
    • Type-safe implementations
    • Full Map and Set API support
  • File System Utilities

    • Async and sync file finding capabilities
    • Parent directory traversal
    • Configuration file location support
  • Environment Detection

    • Simple environment checks
    • Type-safe environment variables
    • Development vs production detection
  • Data Validation Tools

    • Phone number validation and formatting
    • Standard Schema validation with type safety
    • Human-readable validation errors
    • Support for both Zod and Standard Schema
  • HTTP Request Handling

    • Hono integration for AWS Lambda
    • Built-in middleware for logging and request tracking
    • Pretty JSON formatting in development
    • Standardized error responses

Key Benefits

  • Type Safety: Full TypeScript support with proper type inference
  • Developer Experience: Human-readable errors and consistent APIs
  • Production Ready: Built-in logging, error handling, and monitoring
  • AWS Integration: Seamless integration with AWS Lambda and related services
  • Validation: Robust data validation with clear error messages
  • Flexibility: Support for both sync and async operations

Testing

pnpm test

Linting

pnpm lint

Contributing

We're currently developing our contribution processes. If you're interested in contributing to this package or have questions, please reach out to us through the contact information below.

Contact

Brent Rager - Email Instagram LinkedIn Threads

Smoo Github: https://github.com/SmooAI

1.2.8

20 days ago

1.2.7

27 days ago

1.2.6

1 month ago

1.2.5

1 month ago

1.2.4

1 month ago

1.2.3

2 months ago

1.2.2

2 months ago

1.2.1

2 months ago

1.2.0

2 months ago

1.1.0

2 months ago

1.0.21

3 months ago

1.0.20

3 months ago

1.0.19

3 months ago

1.0.18

3 months ago

1.0.17

3 months ago

1.0.16

3 months ago

1.0.15

3 months ago

1.0.14

3 months ago

1.0.13

3 months ago

1.0.12

3 months ago

1.0.11

3 months ago

1.0.10

3 months ago

1.0.9

3 months ago

1.0.8

3 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

0.0.1

4 months ago