@smooai/utils v1.2.8
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.
Installation
pnpm add @smooai/utils
Available Utilities
API Handling
ApiError
- Custom error class for handling API-specific errors with status codes and standardized error responsesapiHandler
- Lambda function wrapper for standardized API error handling and responses, supporting both synchronous and asynchronous handlerscreateAwsLambdaHonoApp
- 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 managementCaseInsensitiveSet
- 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 operationsHumanReadableSchemaError
- 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 rootsfindFileSync
- Synchronous version of findFile for simpler use cases
Environment
isRunningLocally
- Check if code is running in local development environmentisRunningInProd
- 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 applicationhandleSchemaValidation
- Type-safe validator for Standard Schema with human-readable error messages, supporting both synchronous and asynchronous validationformatStandardSchemaErrorToHumanReadable
- Formats Standard Schema validation issues into readable messages with field paths and error detailsHumanReadableSchemaError
- 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
20 days ago
27 days ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago