🛍️ Product Blocks
Product blocks provide pure business logic helpers for product-related operations in NodeBlocks applications.
🎯 Overview
Product blocks are designed to:
- Support file upload flows for product media via signed URLs
- Integrate with file storage drivers while keeping logic pure
- Return Result types for proper error handling
📋 Available Product Blocks
generateProductImageUploadUrl
Generates signed upload URL for product image files with unique object ID.
Purpose: Create pre-signed URL for uploading a product image and return the generated storage objectId.
Parameters:
logger: Pick<Logger, 'error'>
— Logger instance for error loggingfileStorageDriver: FileStorageDriver
— File storage driver for generating signed URLscontentType: string
— MIME type of the file to be uploadedcontentLength: number
— Size of the file in bytes
Returns: Promise<Result<{ objectId: string; url: string }, FileStorageServiceError | ProductBlockError>>
Handler Process:
- Input: Logger, file storage driver,
contentType
,contentLength
- Process: Generates a UUID objectId with extension inferred from
contentType
, and asks the driver for a signed upload URL - Output:
{ objectId, url }
whereobjectId
is the storage key andurl
is the signed upload URL - Errors:
FileStorageServiceError
if signing fails;ProductBlockError
for domain-specific failures
Example Usage:
import { blocks } from '@nodeblocks/backend-sdk';
const uploadResult = await blocks.generateProductImageUploadUrl(
logger,
fileStorageDriver,
'image/jpeg',
1024 * 1024
);
if (uploadResult.isOk()) {
const { objectId, url } = uploadResult.value;
// Use url to upload and persist objectId alongside the product
}