🧱 Product blocks
Product blocks are reusable domain operations and error classes exported through blocks from @nodeblocks/backend-sdk. Operations that return a Result keep failures explicit; route pipelines map relevant block errors through orThrow.
Inventory
| Export | Kind | Inputs | Result / behavior / errors |
|---|---|---|---|
ProductBlockError | Error class | Message, optional data | Base BlockError for product failures. |
ProductNotFoundBlockError | Error class | Message, optional data | Product not-found subtype of ProductBlockError. |
ProductUnexpectedDBError | Error class | Message, optional data | Unexpected database subtype of ProductBlockError. |
ProductImageNotFoundBlockError | Error class | Message, optional data | Product-image not-found subtype of ProductBlockError. |
ProductVariantError | Error class | Message, optional data | Base BlockError for variant failures. |
ProductDbError | Error class | Message, optional data | Database subtype of ProductBlockError. |
ProductVariantDbError | Error class | Message, optional data | Database subtype of ProductVariantError. |
ProductVariantNotFoundError | Error class | Message, optional data | Not-found subtype of ProductVariantError. |
generateProductImageUploadUrl | Function | fileStorageDriver, contentType, contentLength | A Result containing a signed upload URL and generated image object ID; storage failures propagate. |
createProductImage | Function | products collection, productId, image payload | A Result containing the newly appended product image or product/database errors. |
getProductById | Function | products collection, productId | A Result containing the product or ProductNotFoundBlockError/database failure. |
findProducts | Function | products collection, optional Mongo filter | A Result containing matching products or a database failure. |
normalizeProduct | Function | product document | Returns the document without MongoDB _id. |
normalizeProducts | Function | product documents | Returns all documents without MongoDB _id. |
normalizeProductImage | Function | file-storage driver, stored product image | A Result with a public signed URL and image type. |
normalizeImagesOfProduct | Function | file-storage driver, product | A Result with that product’s images normalized to public URLs. |
normalizeImagesOfProducts | Function | file-storage driver, products | A Result with every product’s images normalized to public URLs. |
getProductImageById | Function | products collection, productId, imageId | A Result containing the image or product/image-not-found error. |
deleteProductImage | Function | file-storage driver, products collection, IDs | A Result after removing the image from storage and the product. |
createProductVariant | Function | product-variants collection, payload, productId | A Result containing the created variant; database failures use variant errors. |
getProductVariantById | Function | product-variants collection, variant ID, optional product ID | A Result containing one variant or ProductVariantNotFoundError. |
updateProductVariant | Function | product-variants collection, update payload, IDs/filter | A Result containing the updated variant or variant errors. |
deleteProductVariant | Function | product-variants collection, variant ID | A Result confirming deletion or variant errors. |
buildFilterToGetProductVariantsByProductId | Function | productId | A Result with the product-ID MongoDB filter. |
buildFilterToGetProductVariantsByIds | Function | variant IDs | A Result with the MongoDB $in filter. |
findProductVariants | Function | product-variants collection, filter | A Result with matching variants or a database failure. |
deleteImagesOfProduct | Function | file-storage driver, products collection, productId | A Result after deleting all stored images for the product. |
createProductVariantBulk | Function | product-variants collection, variants, productId | A Result with the created variants. |
updateProductVariantBulk | Function | product-variants collection, variant IDs, update payload | A Result with the updated variants. |
deleteProductVariantBulk | Function | product-variants collection, variant IDs | A Result confirming bulk deletion. |
findProductResources | Function | products collection, filter, find options | A Result with resources returned by the shared finder. |
buildProductLikersByLikeProductIdQuery | Function | productId | Returns the MongoDB $elemMatch query for product likes. |
Details
ProductBlockError
Implementation
ProductBlockError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
ProductNotFoundBlockError
Implementation
ProductNotFoundBlockError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
Used by createProductRoute, findProductsRoute, createProductBatchRoute, updateProductBatchRoute, getProductRoute, updateProductRoute, deleteProductRoute, copyProductRoute, copyProductBatchRoute, createProductImageRoute, deleteProductImageRoute.
ProductUnexpectedDBError
Implementation
ProductUnexpectedDBError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
Used by createProductImageRoute, deleteProductImageRoute, findProductsByOrganizationIdRoute.
ProductImageNotFoundBlockError
Implementation
ProductImageNotFoundBlockError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
ProductVariantError
Implementation
ProductVariantError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
Used by Custom composition only.
ProductDbError
Implementation
ProductDbError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
Used by Custom composition only.
ProductVariantDbError
Implementation
ProductVariantDbError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
Used by createProductVariantRoute, getProductVariantRoute, updateProductVariantRoute, deleteProductVariantRoute, findProductVariantsRoute, createProductVariantBulkRoute, updateProductVariantBulkRoute, deleteProductVariantBulkRoute.
ProductVariantNotFoundError
Implementation
ProductVariantNotFoundError accepts an error message and is classified by its source inheritance. It does not assign an HTTP status itself; the consuming route's orThrow mapping is authoritative.
Used by createProductVariantRoute, getProductVariantRoute, updateProductVariantRoute, updateProductVariantBulkRoute.
generateProductImageUploadUrl
Implementation
Accepts fileStorageDriver, contentType, contentLength. A Result containing a signed upload URL and generated image object ID; storage failures propagate. Used by getProductImageUploadUrlRoute.
createProductImage
Implementation
Accepts products collection, productId, image payload. A Result containing the newly appended product image or product/database errors. Used by createProductImageRoute.
getProductById
Implementation
Accepts products collection, productId. A Result containing the product or ProductNotFoundBlockError/database failure. Used by createProductRoute, getProductRoute, updateProductRoute, copyProductRoute.
findProducts
Implementation
Accepts products collection, optional Mongo filter. A Result containing matching products or a database failure. Used by findProductsRoute, findProductsByOrganizationIdRoute.
normalizeProduct
Implementation
Accepts product document. Returns the document without MongoDB _id. Used by createProductRoute, findProductsRoute, createProductBatchRoute, updateProductBatchRoute, getProductRoute, updateProductRoute, copyProductRoute, copyProductBatchRoute, createProductImageRoute, findProductsByOrganizationIdRoute.
normalizeProducts
Implementation
Accepts product documents. Returns all documents without MongoDB _id. Used by findProductsRoute, createProductBatchRoute, updateProductBatchRoute, copyProductBatchRoute, findProductsByOrganizationIdRoute.
normalizeProductImage
Implementation
Accepts file-storage driver, stored product image. A Result with a public signed URL and image type. Used by createProductImageRoute.
normalizeImagesOfProduct
Implementation
Accepts file-storage driver, product. A Result with that product’s images normalized to public URLs. Used by findProductsRoute, updateProductBatchRoute, getProductRoute, updateProductRoute, copyProductRoute, copyProductBatchRoute, findProductsByOrganizationIdRoute.
normalizeImagesOfProducts
Implementation
Accepts file-storage driver, products. A Result with every product’s images normalized to public URLs. Used by findProductsRoute, updateProductBatchRoute, copyProductBatchRoute, findProductsByOrganizationIdRoute.
getProductImageById
Implementation
Accepts products collection, productId, imageId. A Result containing the image or product/image-not-found error. Used by createProductImageRoute.
deleteProductImage
Implementation
Accepts file-storage driver, products collection, IDs. A Result after removing the image from storage and the product. Used by deleteProductImageRoute.
createProductVariant
Implementation
Accepts product-variants collection, payload, productId. A Result containing the created variant; database failures use variant errors. Used by createProductVariantRoute, createProductVariantBulkRoute.
getProductVariantById
Implementation
Accepts product-variants collection, variant ID, optional product ID. A Result containing one variant or ProductVariantNotFoundError. Used by createProductVariantRoute, getProductVariantRoute, updateProductVariantRoute.
updateProductVariant
Implementation
Accepts product-variants collection, update payload, IDs/filter. A Result containing the updated variant or variant errors. Used by updateProductVariantRoute, updateProductVariantBulkRoute.
deleteProductVariant
Implementation
Accepts product-variants collection, variant ID. A Result confirming deletion or variant errors. Used by deleteProductVariantRoute, deleteProductVariantBulkRoute.
buildFilterToGetProductVariantsByProductId
Implementation
Accepts productId. A Result with the product-ID MongoDB filter. Used by findProductVariantsRoute.
buildFilterToGetProductVariantsByIds
Implementation
Accepts variant IDs. A Result with the MongoDB $in filter. Used by createProductVariantBulkRoute, updateProductVariantBulkRoute.
findProductVariants
Implementation
Accepts product-variants collection, filter. A Result with matching variants or a database failure. Used by findProductVariantsRoute, createProductVariantBulkRoute, updateProductVariantBulkRoute.
deleteImagesOfProduct
Implementation
Accepts file-storage driver, products collection, productId. A Result after deleting all stored images for the product. Used by deleteProductRoute.
createProductVariantBulk
Implementation
Accepts product-variants collection, variants, productId. A Result with the created variants. Used by createProductVariantBulkRoute.
updateProductVariantBulk
Implementation
Accepts product-variants collection, variant IDs, update payload. A Result with the updated variants. Used by updateProductVariantBulkRoute.
deleteProductVariantBulk
Implementation
Accepts product-variants collection, variant IDs. A Result confirming bulk deletion. Used by deleteProductVariantBulkRoute.
findProductResources
Implementation
Accepts products collection, filter, find options. A Result with resources returned by the shared finder. Used by findProductsByOrganizationIdRoute.
buildProductLikersByLikeProductIdQuery
Implementation
Accepts productId. Returns the MongoDB $elemMatch query for product likes. Used by Custom composition only.