🛠️ Utilities
The Nodeblocks SDK provides a comprehensive set of utility functions to help you build robust, maintainable backend services. These utilities are organized by category and designed to work seamlessly with the functional programming patterns used throughout the SDK.
🔐 Authentication Utilities
Comprehensive authentication and token management utilities for secure API endpoints:
getBearerTokenInfo
: Default bearer token authentication from Authorization headergetCookieTokenInfo
: Cookie-based token authentication for web applicationsgenerateUserAccessToken
: Create user access tokens with security validationgenerateAppAccessToken
: Create app access tokens for service-to-service communicationgenerateRefreshToken
: Create refresh tokens for session managementgenerateOnetimeToken
: Create one-time tokens for temporary accessdecryptAndVerifyJWT
: Decrypt and verify encrypted JWTstokenPassesSecurityCheck
: Validate fingerprint/IP/user-agent against tokendefaultRefreshTokenBodyAuth
: Validate refresh token from request bodydefaultRefreshTokenCookieAuth
: Validate refresh token from cookies
Learn Authentication Utilities →
🆔 Entity Utilities
Essential utilities for creating and managing database entities with automatic field generation:
createBaseEntity
: Create entities with auto-generatedid
,createdAt
, andupdatedAt
fieldsupdateBaseEntity
: Update entities with automaticupdatedAt
timestamp- UUID Generation: Automatic UUID v4 generation for entity IDs
🔧 Composition Utilities
Essential utilities for composing handlers, handling asynchronous operations, and building complex business logic pipelines:
compose
: Combine multiple functions into a single pipelinelift
: Transform regular functions to work with Result typesflatMap
: Chain synchronous operations that return ResultsflatMapAsync
: Chain asynchronous operations that return ResultsapplyPayloadArgs
: Extract arguments from payload and apply to pure functionsorThrow
: Map error types to HTTP codes and extract success datamatch
: Predicate helper for nested path checksifElse
: Functional conditional for branchinghasValue
: Non-empty predicate (not null/undefined/empty)
🎭 Handler Wrappers
Cross-cutting concerns and middleware-like utilities that can be applied to any handler:
withLogging
: Add comprehensive logging to any functionwithPagination
: Add automatic pagination to database operations
🔧 Common Utilities
General-purpose utility functions for common operations:
generateUUID
: Generate UUID v4 stringsisObject
: Check if a value is an object type- Type Guards: Helper functions for type checking and validation
📝 Logging Utilities
Pre-configured logging setup with Pino for structured logging:
nodeblocksLogger
: Pre-configured Pino logger with pretty formattingnodeblocksHTTPLogger
: HTTP request/response logging middleware- Logger Type: TypeScript types for logger integration
🔄 Coming Soon
More utility categories will be added here:
- Validation Utilities: Helper functions for common validation patterns
- HTTP Utilities: Request/response helpers and middleware utilities
- Database Utilities: Common database operation helpers
➡️ Next Steps
- Check out Concepts for the underlying principles
- Explore Authentication for detailed auth patterns