🔧 Common Blocks
Common blocks provide reusable schemas, routes, handlers, and features that can be used across multiple entities in Nodeblocks applications. These blocks are designed to be shared and reused to maintain consistency and reduce duplication.
🎯 Overview
Common blocks are designed to:
- Provide reusable components across multiple entities
- Maintain consistency in data validation and API patterns
- Reduce code duplication through shared schemas and utilities
- Support standardization of common operations like pagination and responses
- Enable composition with entity-specific blocks
📦 Block Types
🔍 Schemas
JSON Schema definitions for common data validation:
- Address Schemas: Address validation for different formats and regions
- Pagination Schemas: Standardized pagination parameters and metadata
- Response Schemas: Common API response structures
- Utility Schemas: Reusable utility schemas for common operations
🔧 Blocks
Reusable logic shared across domains:
- redirectTo: Issue HTTP redirects in route chains
- generateRandomPassword: Create secure random passwords
- normalizeRawDocument: Remove MongoDB
_idfields from API responses - normalizeDocuments: Remove MongoDB
_idfields from arrays of documents - normalizeEmptyBody: Normalize empty response body for API handlers
✅ Validators
Generic validation functions for reuse across domains:
- checkIdentityType: Gate access based on identity type configuration
- validateResourceAccess: Generic access control validator for any resource type (deprecated)
- some: Compose validators with OR semantics
- requireParam: Factory function to create parameter requirement validators
- isUUID: Factory function to create UUID format validators
- isNumber: Factory function to create numeric format validators
- ownsResource: Check if authenticated user owns a resource in the database
🔗 Related Documentation
- Common Schemas - Common data validation and contracts
- Common Validators - Common validation functions
- User Blocks - User-specific blocks
- Product Blocks - Product-specific blocks
- Organization Blocks - Organization-specific blocks