Models
@hv/cart/models
exports zod
schemas and corresponding inferred types. These models are the types for the exported interfaces as well as the normalize inputs and outputs of those interfaces.
This is an overview of the models of this package, not an exhaustive listing
Reference
CartIntegration<TCartModes extends CartModes>
Type signature of the Cart Integration Function export.
VendorCartIntegration<TCartModes extends CartModes>
Type signature of the Cart Integration Function exported by Vendor packages. Extends CartIntegration
, adding attributes specifying the CartModes
for the integration.
e.g, With Shopify as the cart provider, which returns expanded product line items and manages line item pricing internally:
export function Cart(...) {
return {
lineItemPricing: 'internal',
lineItemType: 'expanded'.
async addToCart() {
....
},
}
...
}
CartModes
Cart integrations may behave differently depending on how you want to combine your data models. CartModes
defines the modes available.
lineItemPricing = 'external' | 'internal'
external
The cart integration expects pricing to be provided externally. In this mode, the cart does not know how to price line items by itself. Typical if the cart is provided by a simple persistance layer instead of a commerce vendor.
internal
The cart integration can price line items on its own. Typical if the cart is provided by a commerce vendor.
lineItemType = 'expanded' | 'reference'
expanded
Line items have full product models attached.
reference
Line items returned will have references to products which will need to be dereferenced to get a full product model.
LineItemContainer<TContainer>
Defines lineItems
attribute type for a line item container (such as a Cart
or an Order
)
A line item container will have different types for the lineItems
attribute depending on the lineItemType
for the CartMode
lineItemType === 'product'
:
ProductLineItem[]
lineItemType === 'reference'
:
ProductReferenceLineItem[]
Cart<TCartModes>
Extends LineItemContainer
and BaseCart
to represent a customer cart
Order<TCartModes>
Extends LineItemContainer
and BaseOrder
to represent a customer cart that has been placed
BaseCart
Defines common attributes for carts of all cart modes
BaseOrder
Defines common attributes for orders of all cart modes