Skip to main content
Version: 🚧 Canary

🧱 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​

ExportKindInputsResult / behavior / errors
ProductBlockErrorError classMessage, optional dataBase BlockError for product failures.
ProductNotFoundBlockErrorError classMessage, optional dataProduct not-found subtype of ProductBlockError.
ProductUnexpectedDBErrorError classMessage, optional dataUnexpected database subtype of ProductBlockError.
ProductImageNotFoundBlockErrorError classMessage, optional dataProduct-image not-found subtype of ProductBlockError.
ProductVariantErrorError classMessage, optional dataBase BlockError for variant failures.
ProductDbErrorError classMessage, optional dataDatabase subtype of ProductBlockError.
ProductVariantDbErrorError classMessage, optional dataDatabase subtype of ProductVariantError.
ProductVariantNotFoundErrorError classMessage, optional dataNot-found subtype of ProductVariantError.
generateProductImageUploadUrlFunctionfileStorageDriver, contentType, contentLengthA Result containing a signed upload URL and generated image object ID; storage failures propagate.
createProductImageFunctionproducts collection, productId, image payloadA Result containing the generated image ID or product/database errors.
getProductByIdFunctionproducts collection, productIdA Result containing the product or ProductNotFoundBlockError/database failure.
findProductsFunctionproducts collection, required Mongo filterA Result containing matching products or a database failure.
normalizeProductFunctionproduct documentReturns the document without MongoDB _id.
normalizeProductsFunctionproduct documentsReturns all documents without MongoDB _id.
normalizeProductImageFunctionfile-storage driver, stored product imageA Result with a public signed URL and image type.
normalizeImagesOfProductFunctionfile-storage driver, productA Result with that product’s images normalized to public URLs.
normalizeImagesOfProductsFunctionfile-storage driver, productsA Result with every product’s images normalized to public URLs.
getProductImageByIdFunctionproducts collection, productId, imageIdA Result containing the image, ProductImageNotFoundBlockError, or ProductUnexpectedDBError (including when the product is absent).
deleteProductImageFunctionfile-storage driver, products collection, IDsA Result after removing the image from storage and the product.
createProductVariantFunctionproduct-variants collection, payload, productIdA Result containing the generated variant ID; database failures use variant errors.
getProductVariantByIdFunctionproduct-variants collection, variant ID, optional product IDA Result containing one variant or ProductVariantNotFoundError.
updateProductVariantFunctionproduct-variants collection, update payload, IDs/filterA Result containing boolean update success or variant errors.
deleteProductVariantFunctionproduct-variants collection, variant IDA Result confirming deletion or variant errors.
buildFilterToGetProductVariantsByProductIdFunctionproductIdA Result with the product-ID MongoDB filter.
buildFilterToGetProductVariantsByIdsFunctionvariant IDsA Result with the MongoDB $in filter.
findProductVariantsFunctionproduct-variants collection, filterA Result with matching variants or a database failure.
deleteImagesOfProductFunctionfile-storage driver, products collection, productIdA Result after deleting all stored images for the product.
createProductVariantBulkFunctionproduct-variants collection, variants, productIdA Result with the generated variant ID array.
updateProductVariantBulkFunctionproduct-variants collection, variant IDs, update payload, optional filterA Result with boolean update success.
deleteProductVariantBulkFunctionproduct-variants collection, variant IDsA Result confirming bulk deletion.
findProductResourcesFunctionproducts collection, filter, find optionsA Result with resources returned by the shared finder.
buildProductLikersByLikeProductIdQueryFunctionlikeProductIdReturns a Result with a profile-collection $elemMatch filter 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.

Used by findProductsRoute, getProductImageUploadUrlRoute.

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, getProductLikersRoute, createProductLikeRoute, deleteProductLikeRoute.

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, getProductLikersRoute.

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.

Used by createProductImageRoute, deleteProductImageRoute.

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 generated image ID 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, getProductLikersRoute, createProductLikeRoute, deleteProductLikeRoute.

findProducts​

Implementation

Accepts products collection, required Mongo filter. A Result containing matching products or a database failure. Used by findProductsRoute.

normalizeProduct​

Implementation

Accepts product document. Returns the document without MongoDB _id. Used by createProductRoute, getProductRoute, updateProductRoute, copyProductRoute.

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 getProductRoute, updateProductRoute, copyProductRoute.

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, ProductImageNotFoundBlockError, or ProductUnexpectedDBError (including when the product is absent). 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 generated variant ID; database failures use variant errors. Used by createProductVariantRoute.

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 boolean update success or variant errors. Used by updateProductVariantRoute.

deleteProductVariant​

Implementation

Accepts product-variants collection, variant ID. A Result confirming deletion or variant errors. Used by deleteProductVariantRoute.

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.

A missing product returns ProductNotFoundBlockError at runtime despite its omission from the declared error union. Image metadata remains in the database.

createProductVariantBulk​

Implementation

Accepts product-variants collection, variants, productId. A Result with the generated variant ID array. Used by createProductVariantBulkRoute.

updateProductVariantBulk​

Implementation

Accepts product-variants collection, variant IDs, update payload, optional filter. A Result with boolean update success. 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 likeProductId. Returns a Result with a profile-collection $elemMatch filter for product likes. Used by getProductLikersRoute.