Skip to main content
Version: 🚧 Canary

🛍️ Product Blocks

Product blocks provide comprehensive functionality for product management in Nodeblocks applications. These blocks handle product lifecycle operations including creation, catalog management, and inventory tracking.


🎯 Overview

Product blocks are designed to:

  • Manage product catalog with full CRUD operations
  • Handle product variants for inventory and customization management
  • Handle product images with metadata and automatic entity generation
  • Normalize product data with signed URLs for images in API responses
  • Handle product attributes and variations
  • Provide product validation and business rules
  • Support inventory management and tracking
  • Enable product administration with comprehensive controls

📦 Block Types

🔍 Schemas

JSON Schema definitions for product data validation:

  • productSchema: Base product entity structure
  • productImageSchema: Product image metadata structure
  • createProductImageSchema: Product image creation validation
  • deleteProductImageSchema: Product image deletion validation
  • imageIdPathParameter: Path parameter for image ID
  • ProductImage: TypeScript type for product image data
  • NormalizedProductImage: TypeScript type for normalized product image with URL
  • createProductSchema: Product creation validation with images
  • updateProductSchema: Product update validation
  • createProductBatchSchema: Batch creation validation with images
  • updateProductBatchSchema: Batch update validation
  • deleteProductBatchSchema: Batch deletion validation
  • copyProductBatchSchema: Batch copy validation
  • getProductSchema: Single product retrieval validation
  • deleteProductSchema: Product deletion validation
  • copyProductSchema: Product copy validation
  • findProductsSchema: Product search with filtering and pagination
  • createProductVariantBulkSchema: Product variant bulk creation with array validation
  • updateProductVariantBulkSchema: Product variant bulk update with bulk operation validation
  • deleteProductVariantBulkSchema: Product variant bulk deletion with variant ID array validation
  • createProductVariantSchema: Product variant creation with required title validation
  • getProductVariantSchema: Product variant retrieval with path parameters
  • updateProductVariantSchema: Product variant update with optional fields
  • deleteProductVariantSchema: Product variant deletion with path parameters
  • findProductVariantsSchema: Product variant listing with pagination validation
  • getProductLikersSchema: Product likers retrieval validation

View Product Schemas →

🧱 Block Functions

Pure functions for product operations and data transformation:

Product Retrieval:

  • getProductById: Retrieves a product by ID from the products collection
  • findProducts: Retrieves products from database collection based on filter criteria

Product Variant Management:

  • createProductVariant: Creates a new product variant for an existing product
  • createProductVariantBulk: Creates multiple product variants in bulk within single database operation
  • updateProductVariant: Updates a single product variant
  • updateProductVariantBulk: Updates multiple product variants in bulk via database collection update operation
  • deleteProductVariant: Deletes a single product variant
  • deleteProductVariantBulk: Deletes multiple product variants in bulk from MongoDB collection
  • getProductVariantById: Retrieves a product variant by ID with optional product scoping
  • findProductVariants: Finds product variants for a specific product
  • buildFilterToGetProductVariantsByProductId: Builds database filter to retrieve product variants by product ID
  • buildFilterToGetProductVariantsByIds: Builds database filter to retrieve product variants by their IDs

Product Normalization:

  • normalizeProduct: Normalizes a single product by removing _id field
  • normalizeProducts: Normalizes multiple products by removing _id fields

Product Image Normalization:

  • normalizeProductImage: Normalizes a single product image by generating signed download URL
  • normalizeImagesOfProduct: Normalizes images for a single product with signed URLs
  • normalizeImagesOfProducts: Normalizes images for multiple products with signed URLs

Product Image Management:

  • generateProductImageUploadUrl: Generates signed URL for product image upload
  • createProductImage: Creates a new product image and adds it to the product's images array
  • getProductImageById: Retrieves a specific product image by its ID
  • deleteProductImage: Deletes a specific product image from a product
  • deleteImagesOfProduct: Deletes all images associated with a product from file storage

Query Builder Blocks:

  • findProductResources: Finds product resources with flexible filtering
  • buildProductLikersByLikeProductIdQuery: Builds MongoDB query for product likers

Error Classes:

  • ProductBlockError: Base error class for product-related block operations
  • ProductNotFoundBlockError: Product not found error
  • ProductUnexpectedDBError: Unexpected database error for products
  • ProductImageNotFoundBlockError: Product image not found error
  • ProductDbError: Product database operation error
  • ProductVariantError: Base error class for product variant operations
  • ProductVariantDbError: Product variant database operation error
  • ProductVariantNotFoundError: Product variant not found error

View Product Block Functions →

⚙️ Handlers

Core business logic for product operations:

  • createProduct: Product creation
  • createProductBatch: Batch product creation
  • getProductById: Product data retrieval (deprecated - use block function instead)
  • getProductsByIds: Retrieve multiple products by IDs
  • updateProduct: Product updates
  • updateProductBatch: Batch product updates
  • deleteProduct: Product deletion
  • deleteProductBatch: Batch product deletion
  • copyProduct: Product copying
  • copyProductBatch: Batch product copying
  • findProducts: Product search and filtering (deprecated - use block function instead)
  • normalizeProductTerminator: Normalize single product response
  • normalizeProductsListTerminator: Normalize products list response
  • deleteProductTerminator: Format 204 response for product deletion
  • deleteBatchProductsTerminator: Format 204 response for batch product deletion

View Product Handlers →

🛣️ Routes

HTTP endpoint definitions for product operations:

  • createProductRoute: POST /products with creation handler
  • createProductBatchRoute: POST /products/batch with batch creation handler
  • createProductVariantRoute: POST /products/:productId/variants for creating product variants
  • createProductVariantBulkRoute: POST /product/:productId/variants/bulk for bulk creating product variants
  • updateProductVariantBulkRoute: PATCH /product/:productId/variants/bulk for bulk updating product variants
  • deleteProductVariantBulkRoute: POST /product/:productId/variants/bulk-delete for bulk deleting product variants
  • findProductVariantsRoute: GET /products/:productId/variants for listing product variants with pagination
  • getProductVariantRoute: GET /products/:productId/variants/:productVariantId for retrieving product variants
  • updateProductVariantRoute: PATCH /products/:productId/variants/:productVariantId for updating product variants
  • deleteProductVariantRoute: DELETE /products/:productId/variants/:productVariantId for deleting product variants
  • getProductRoute: GET /products/:productId with retrieval handler
  • findProductsRoute: GET /products with search and pagination
  • getProductImageUploadUrlRoute: GET /products/:productId/image-upload-url for signed upload URLs
  • createProductImageRoute: POST /products/:productId/images for adding images to products
  • deleteProductImageRoute: DELETE /products/:productId/images/:imageId for removing images from products
  • updateProductRoute: PATCH /products/:productId with update handler
  • updateProductBatchRoute: PATCH /products/batch with batch update handler
  • deleteProductRoute: DELETE /products/:productId with deletion handler
  • deleteProductBatchRoute: DELETE /products/batch with batch deletion handler
  • copyProductRoute: POST /products/:productId/copy with copy handler
  • copyProductBatchRoute: POST /products/batch/copy with batch copy handler
  • findProductsByOrganizationIdRoute: GET /products/organizations/:organizationId with organization-scoped product retrieval
  • getProductLikersRoute: GET /products/:productId/likers with product likers retrieval and pagination

View Product Routes →

🚀 Features

Complete product management features combining schemas, routes, and handlers:

  • createProductFeature: Product creation with schema validation and routing
  • createProductBatchFeature: Batch product creation with schema validation and routing
  • createProductVariantFeature: Product variant creation with schema validation and routing
  • createProductVariantBulkFeature: Product variant bulk creation with schema validation and routing
  • updateProductVariantBulkFeature: Product variant bulk update with schema validation and routing
  • deleteProductVariantBulkFeature: Product variant bulk deletion with schema validation and routing
  • findProductVariantsFeature: Product variant listing with pagination, schema validation and routing
  • getProductVariantFeature: Product variant retrieval with schema validation and routing
  • updateProductVariantFeature: Product variant update with schema validation and routing
  • deleteProductVariantFeature: Product variant deletion with schema validation and routing
  • getProductFeatures: Product retrieval for getting individual product data
  • findProductsFeatures: Product search with filtering and pagination
  • editProductFeatures: Product update with schema validation and routing
  • editProductBatchFeatures: Batch product update with schema validation and routing
  • deleteProductFeatures: Product deletion with routing
  • deleteProductBatchFeatures: Batch product deletion with schema validation and routing
  • copyProductFeatures: Product copying with routing
  • copyProductBatchFeatures: Batch product copying with schema validation and routing
  • getProductImageUploadUrlFeature: Product image upload URL generation
  • createProductImageFeature: Product image creation with schema validation and routing
  • deleteProductImageFeature: Product image deletion with schema validation and file storage cleanup
  • findProductsByOrganizationIdFeature: Organization-scoped product retrieval with pagination
  • getProductLikersFeature: Product likers retrieval with pagination and avatar normalization

View Product Features →