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 newly appended product image or product/database errors.
getProductByIdFunctionproducts collection, productIdA Result containing the product or ProductNotFoundBlockError/database failure.
findProductsFunctionproducts collection, optional 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 or product/image-not-found error.
deleteProductImageFunctionfile-storage driver, products collection, IDsA Result after removing the image from storage and the product.
createProductVariantFunctionproduct-variants collection, payload, productIdA Result containing the created variant; 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 the updated variant 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 created variants.
updateProductVariantBulkFunctionproduct-variants collection, variant IDs, update payloadA Result with the updated variants.
deleteProductVariantBulkFunctionproduct-variants collection, variant IDsA Result confirming bulk deletion.
findProductResourcesFunctionproducts collection, filter, find optionsA Result with resources returned by the shared finder.
buildProductLikersByLikeProductIdQueryFunctionproductIdReturns 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.

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.

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.

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

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.