メインコンテンツまでスキップ
バージョン: 🚧 Canary

🛠️ 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 header
  • getCookieTokenInfo: Cookie-based token authentication for web applications
  • generateUserAccessToken: Create user access tokens with security validation
  • generateAppAccessToken: Create app access tokens for service-to-service communication
  • generateRefreshToken: Create refresh tokens for session management
  • generateOnetimeToken: Create one-time tokens for temporary access
  • decryptAndVerifyJWT: Decrypt and verify encrypted JWTs
  • tokenPassesSecurityCheck: Validate fingerprint/IP/user-agent against token
  • defaultRefreshTokenBodyAuth: Validate refresh token from request body
  • defaultRefreshTokenCookieAuth: 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-generated id, createdAt, and updatedAt fields
  • updateBaseEntity: Update entities with automatic updatedAt timestamp
  • UUID Generation: Automatic UUID v4 generation for entity IDs

Learn Entity Utilities →


🔧 Composition Utilities

Essential utilities for composing handlers, handling asynchronous operations, and building complex business logic pipelines:

  • compose: Combine multiple functions into a single pipeline
  • lift: Transform regular functions to work with Result types
  • flatMap: Chain synchronous operations that return Results
  • flatMapAsync: Chain asynchronous operations that return Results
  • applyPayloadArgs: Extract arguments from payload and apply to pure functions
  • orThrow: Map error types to HTTP codes and extract success data
  • match: Predicate helper for nested path checks
  • ifElse: Functional conditional for branching
  • hasValue: Non-empty predicate (not null/undefined/empty)

Learn Composition Utilities →


🎭 Handler Wrappers

Cross-cutting concerns and middleware-like utilities that can be applied to any handler:

  • withLogging: Add comprehensive logging to any function
  • withPagination: Add automatic pagination to database operations

Learn Handler Wrappers →


🔧 Common Utilities

General-purpose utility functions for common operations:

  • generateUUID: Generate UUID v4 strings
  • isObject: Check if a value is an object type
  • Type Guards: Helper functions for type checking and validation

Learn Common Utilities →


📝 Logging Utilities

Pre-configured logging setup with Pino for structured logging:

  • nodeblocksLogger: Pre-configured Pino logger with pretty formatting
  • nodeblocksHTTPLogger: HTTP request/response logging middleware
  • Logger Type: TypeScript types for logger integration

Learn Logging Utilities →


🔄 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