Creates a new ProductBuilder instance.
The base URL of the supplier's website, used for resolving relative URLs
Sets the data for the product by merging the provided data object.
The builder instance for method chaining
Sets the basic information for the product including title, URL, and supplier name.
The display name/title of the product
The URL where the product can be found (can be relative to baseURL)
The name of the supplier/vendor
The builder instance for method chaining
Sets the formula for the product.
Optional
formula: stringThe formula to set
The builder instance for method chaining
Sets the grade/purity level of the product. Only sets the grade if a non-empty string is provided.
The grade or purity level of the product
The builder instance for method chaining
Sets the price for the product. This is useful for if the price and currency are easier to add separately (eg: getting the currency code is done in a different request handler)
The price to set
The builder instance for method chaining
Sets the currency symbol for the product. This is useful for if the price and currency are easier to add separately (eg: getting the currency code is done in a different request handler). If no currency symbol is set, then it will be inferred from the currencyCode
The currency symbol to set
The builder instance for method chaining
Sets the currency code for the product. This is useful for if the price and currency are easier to add separately (eg: getting the currency code is done in a different request handler).
The currency code to set
The builder instance for method chaining
Overload
Sets the pricing information for the product including price and currency details when given a parsedPrice object
ParsedPrice instance
The builder instance for method chaining
Overload
Sets the pricing information for the product including price and currency details when given a price
Price in string format
The builder instance for method chaining
Overload
Sets the pricing information for the product including price and currency details when given a price
Price in number format
The ISO currency code (e.g., 'USD', 'EUR')
The currency symbol (e.g., '$', '€')
The builder instance for method chaining
Overload
Sets the quantity information for the product.
QuantityObject format
The builder instance for method chaining
Overload
Sets the quantity information for the product.
Quantity in string format
The builder instance for method chaining
Overload
Sets the quantity information for the product.
Quantity in number format
The unit of measure (e.g., 'g', 'ml', 'kg')
The builder instance for method chaining
Sets the unit of measure for the product.
The unit of measure for the product
The builder instance for method chaining
Sets the country of the supplier.
The country of the supplier
The builder instance for method chaining
Sets the shipping scope of the supplier.
The shipping scope of the supplier
The builder instance for method chaining
Sets the payment methods accepted by the supplier.
The payment methods accepted by the supplier
The builder instance for method chaining
Sets the product description.
The detailed description of the product
The builder instance for method chaining
Sets the CAS (Chemical Abstracts Service) registry number for the product. Validates the CAS number format before setting.
The CAS registry number in format "XXXXX-XX-X"
The builder instance for method chaining
Sets the ID for the product.
Optional
id: string | numberThe unique identifier for the product
The builder instance for method chaining
Sets the UUID for the product.
The UUID string for the product
The builder instance for method chaining
Sets the SKU (Stock Keeping Unit) for the product.
The SKU string for the product
The builder instance for method chaining
Sets the vendor for the product.
Optional
vendor: stringThe vendor name
The builder instance for method chaining
Tries to determine the availability of the product based on variable input.
Optional
availability: string | booleanThe availability of the product
The availability of the product
// In stock
builder.determineAvailability("instock");
builder.determineAvailability(true);
builder.determineAvailability("outofstock");
builder.determineAvailability("unavailable");
builder.determineAvailability(false);
builder.determineAvailability("preorder");
builder.determineAvailability("backorder");
builder.determineAvailability("discontinued");
Sets the availability of the product.
The availability of the product
The builder instance for method chaining
Sets the availability of the product.
The availability of the product
The builder instance for method chaining
Sets the availability of the product.
The availability of the product
The builder instance for method chaining
Just a place to hold the products original response object.
Optional
data: Record<string, unknown>The raw data to add the raw data.
The builder instance for method chaining
Adds a single variant to the product.
The builder instance for method chaining
Adds multiple variants to the product at once.
The builder instance for method chaining
Sets the variants for the product. Slightly different from addVariants in that it will replace the existing variants with the new ones.
The builder instance for method chaining
Gets a specific variant from the product.
The index of the variant to get
The variant object
Private
hrefConverts a relative or partial URL to an absolute URL using the base URL.
The URL or path to convert
The absolute URL as a string
Builds and validates the final Product object. Performs the following steps:
Static
createCreates an array of ProductBuilder instances from cached product data. This is used to restore builders from cache storage.
The base URL of the supplier's website
Array of cached product data (from .dump())
Array of ProductBuilder instances
Builder class for constructing Product objects with a fluent interface. Implements the Builder pattern to handle complex product construction with optional fields and data validation.
Remarks
This is a utility class for building product data up over different requests. It is used to build the product data up over different requests, and then return a complete product object.
Example