@heyframe/composables
Version:
HeyFrame Frontends composables for Vue
1,614 lines (1,578 loc) • 72.5 kB
TypeScript
import * as vue from 'vue';
import { CSSProperties, ComputedRef, AnchorHTMLAttributes, ImgHTMLAttributes, App, EffectScope, Ref } from 'vue';
import { createAPIClient, ApiError } from '@heyframe/api-client';
import { components, operations as operations$1 } from '@heyframe/api-client/store-api-types';
import { getListingFilters, TierPrice } from '@heyframe/helpers';
type operations = operations$1;
type Schemas = components["schemas"];
type ApiClient = ReturnType<typeof createAPIClient<operations>>;
type BlockType<SLOT_NAMES> = Schemas["CmsBlock"] & {
slots: Array<Schemas["CmsSlot"] & {
slot: SLOT_NAMES;
}>;
};
type THREE_COLUMNS = "left" | "center" | "right";
type TWO_COLUMNS = "left" | "right";
type CmsBlockText = BlockType<"content">;
type CmsBlockTextHero = BlockType<"content">;
type CmsBlockTextTeaser = BlockType<"content">;
type CmsBlockTextTeaserSection = BlockType<TWO_COLUMNS>;
type CmsBlockTextTwoColumn = BlockType<TWO_COLUMNS>;
type CmsBlockTextThreeColumn = BlockType<THREE_COLUMNS>;
type CmsBlockImage = BlockType<"image">;
type CmsBlockImageCover = BlockType<"image">;
type CmsBlockImageTwoColumn = BlockType<TWO_COLUMNS>;
type CmsBlockImageThreeColumn = BlockType<THREE_COLUMNS>;
type CmsBlockImageThreeCover = BlockType<THREE_COLUMNS>;
type CmsBlockImageFourColumn = BlockType<"left" | "center-left" | "center-right" | "right">;
type CmsBlockImageBubbleRow = BlockType<THREE_COLUMNS>;
type CmsBlockImageHighlightRow = BlockType<THREE_COLUMNS>;
type CmsBlockImageSimpleGrid = BlockType<"left-top" | "left-bottom" | "right">;
type CmsBlockImageSlider = BlockType<"imageSlider">;
type CmsBlockImageGallery = BlockType<"imageGallery">;
type CmsBlockYoutubeVideo = BlockType<"video">;
type CmsBlockVimeoVideo = BlockType<"video">;
type CmsBlockImageText = BlockType<TWO_COLUMNS>;
type CmsBlockImageTextCover = BlockType<TWO_COLUMNS>;
type CmsBlockCenterText = BlockType<THREE_COLUMNS>;
type CmsBlockImageTextRow = BlockType<"left-image" | "left-text" | "center-image" | "center-text" | "right-image" | "right-text">;
type CmsBlockImageTextGallery = BlockType<"left-image" | "left-text" | "center-image" | "center-text" | "right-image" | "right-text">;
type CmsBlockImageTextBubble = BlockType<"left-image" | "left-text" | "center-image" | "center-text" | "right-image" | "right-text">;
type CmsBlockTextOnImage = BlockType<"content">;
type CmsBlockSidebarFilter = BlockType<"content">;
type CmsBlockCategoryNavigation = BlockType<"content">;
type CmsBlockProductHeading = BlockType<TWO_COLUMNS>;
type CmsBlockProductThreeColumn = BlockType<THREE_COLUMNS>;
type CmsBlockProductListing = BlockType<"content">;
type CmsBlockProductSlider = BlockType<"productSlider">;
type CmsBlockGalleryBuybox = BlockType<TWO_COLUMNS>;
type CmsBlockProductDescriptionReviews = BlockType<"content">;
type CmsBlockCrossSelling = BlockType<"content">;
type CmsBlockForm = BlockType<"content">;
type CmsBlockHtml = BlockType<"content">;
type SourceType = "static" | "mapped";
type Position = "left" | "center" | "right";
type DisplayMode = Exclude<CSSProperties["objectFit"], undefined> | "standard";
type BoxLayout = "standard" | "image" | "minimal";
type VerticalAlign = "flex-start" | "center" | "flex-end" | "";
type ElementConfig<VALUE_TYPE> = {
source: SourceType;
value: VALUE_TYPE;
};
type TextElementConfig = {
content: ElementConfig<string>;
verticalAlign: ElementConfig<VerticalAlign>;
};
type ElementFieldConfig = {
name: string;
source: SourceType;
value: string | null;
apiAlias: string;
};
type CmsElementText = Omit<Schemas["CmsSlot"], "config"> & {
type: "text" | typeof String;
slot: typeof String;
config: TextElementConfig;
fieldConfig: ElementFieldConfig[];
data: {
content: string;
apiAlias: "cms_text";
};
translated: {
config: TextElementConfig;
};
};
type CmsElementHtml = Omit<Schemas["CmsSlot"], "config"> & {
type: "html";
data: {
content: string;
apiAlias: "cms_html";
};
};
type ImageElementConfig = {
url: ElementConfig<string>;
media: ElementConfig<string>;
newTab: ElementConfig<boolean>;
product: ElementConfig<string>;
boxLayout: ElementConfig<BoxLayout>;
displayMode: ElementConfig<DisplayMode>;
minHeight: ElementConfig<string | number>;
verticalAlign: ElementConfig<VerticalAlign>;
horizontalAlign: ElementConfig<VerticalAlign>;
};
type CmsElementImage = Omit<Schemas["CmsSlot"], "config"> & {
type: "image";
config: ImageElementConfig;
data: {
mediaId: string;
url: string;
newTab: boolean;
apiAlias: "cms_image";
media: Schemas["Media"];
};
};
type SliderElementConfig = {
minWidth?: ElementConfig<string>;
minHeight: ElementConfig<string | number>;
verticalAlign?: ElementConfig<VerticalAlign>;
displayMode?: ElementConfig<"standard" | "cover" | "contain">;
navigationDots?: ElementConfig<"outside" | "inside" | "">;
navigationArrows?: ElementConfig<"outside" | "inside" | "">;
};
type ImageSliderElementConfig = ImageElementConfig & SliderElementConfig & {
sliderItems: ElementConfig<Array<{
url: null | string;
newTab: boolean;
mediaId: string;
mediaUrl: string;
}>>;
};
type CmsElementImageSlider = Omit<Schemas["CmsSlot"], "config"> & {
type: "image-slider";
config: ImageSliderElementConfig;
data: {
apiAlias: "cms_image_slider";
navigation: unknown;
sliderItems: {
url: string;
newTab: boolean;
media: Schemas["Media"];
mediaId: string;
apiAlias: "cms_image_slider_item";
}[];
};
};
type ImageGalleryElementConfig = ImageSliderElementConfig & {
galleryPosition: ElementConfig<Position>;
magnifierOverGallery: ElementConfig<boolean>;
keepAspectRatioOnZoom: ElementConfig<boolean>;
fullScreen: ElementConfig<boolean>;
zoom: ElementConfig<boolean>;
};
type CmsElementImageGallery = Omit<Schemas["CmsSlot"], "config"> & {
type: "image-gallery";
config: ImageGalleryElementConfig;
data: {
apiAlias: "cms_image_slider";
navigation: unknown;
sliderItems: Array<{
url: null | string;
newTab: boolean;
media: Schemas["Media"];
apiAlias: "cms_image_slider_item";
} | Schemas["ProductMedia"]>;
};
};
type YouTubeVideoElementConfig = {
end: ElementConfig<string>;
url: ElementConfig<string>;
loop: ElementConfig<boolean>;
start: ElementConfig<string>;
videoID: ElementConfig<string>;
autoPlay: ElementConfig<boolean>;
displayMode: ElementConfig<DisplayMode>;
previewMedia: ElementConfig<string>;
showControls: ElementConfig<boolean>;
needsConfirmation: ElementConfig<boolean>;
advancedPrivacyMode: ElementConfig<boolean>;
};
type CmsElementYoutubeVideo = Omit<Schemas["CmsSlot"], "config"> & {
type: "youtube-video";
config: YouTubeVideoElementConfig;
data: {
mediaId: string | null;
url: null | string;
newTab: null | boolean;
media: null | Schemas["Media"];
apiAlias: "cms_image";
};
};
type VimeoVideoElementConfig = {
loop: ElementConfig<boolean>;
color: ElementConfig<string>;
title: ElementConfig<boolean>;
mute: ElementConfig<boolean>;
byLine: ElementConfig<boolean>;
videoID: ElementConfig<string>;
autoplay: ElementConfig<boolean>;
controls: ElementConfig<boolean>;
portrait: ElementConfig<boolean>;
doNotTrack: ElementConfig<boolean>;
previewMedia: ElementConfig<string>;
needsConfirmation: ElementConfig<boolean>;
};
type CmsElementVimeoVideo = Omit<Schemas["CmsSlot"], "config"> & {
type: "vimeo-video";
config: VimeoVideoElementConfig;
data: {
mediaId: string | null;
url: null | string;
newTab: null | boolean;
media: null | Schemas["Media"];
apiAlias: "cms_image";
};
};
type ProductBoxElementConfig = {
boxLayout: ElementConfig<BoxLayout>;
product: ElementConfig<string>;
};
type CmsElementProductBox = Omit<Schemas["CmsSlot"], "config"> & {
type: "product-box";
config: ProductBoxElementConfig;
data: {
productId: string;
product: Schemas["Product"];
apiAlias: "cms_product_box";
};
};
type ProductSliderElementConfig = {
title: ElementConfig<string>;
border: ElementConfig<boolean>;
rotate: ElementConfig<boolean>;
products: ElementConfig<string[]>;
boxLayout: ElementConfig<BoxLayout>;
elMinWidth: ElementConfig<string>;
navigation: ElementConfig<boolean>;
displayMode: ElementConfig<DisplayMode>;
verticalAlign: ElementConfig<VerticalAlign>;
productStream: ElementConfig<string>;
productStreamSorting: ElementConfig<string>;
};
type CmsElementProductSlider = Omit<Schemas["CmsSlot"], "config"> & {
type: "product-slider";
config: ProductSliderElementConfig;
data: {
apiAlias: "cms_product_slider";
products: Schemas["Product"][];
};
};
type CmsSidebarFilterElementConfig = {
boxLayout: ElementConfig<BoxLayout>;
content: ElementConfig<string>;
displayMode: ElementConfig<DisplayMode>;
media: ElementConfig<string>;
minHeight: ElementConfig<string | number>;
newTab: ElementConfig<boolean>;
url: ElementConfig<string>;
verticalAlign: ElementConfig<VerticalAlign>;
};
type CmsElementSidebarFilter = Omit<Schemas["CmsSlot"], "config"> & {
type: "sidebar-filter";
config: CmsSidebarFilterElementConfig;
};
type CmsProductListingElementConfig = {
filters: ElementConfig<string>;
boxLayout: ElementConfig<BoxLayout>;
showSorting: ElementConfig<boolean>;
defaultSorting: ElementConfig<string>;
useCustomSorting: ElementConfig<boolean>;
availableSortings: ElementConfig<string[]>;
propertyWhitelist: ElementConfig<string[]>;
};
type CmsElementProductListing = Omit<Schemas["CmsSlot"], "config"> & {
type: "product-listing";
config: CmsProductListingElementConfig;
data: {
apiAlias: "cms_product_listing";
listing: Schemas["ProductListingResult"];
};
};
type CategoryNavigationElementConfig = unknown;
type CmsElementCategoryNavigation = Omit<Schemas["CmsSlot"], "config"> & {
type: "category-navigation";
config: CategoryNavigationElementConfig;
};
type ProductDescriptionReviewsElementConfig = {
product: ElementConfig<string>;
alignment: ElementConfig<VerticalAlign>;
};
type CmsElementProductDescriptionReviews = Omit<Schemas["CmsSlot"], "config"> & {
type: "product-description-reviews";
config: ProductDescriptionReviewsElementConfig;
data: {
productId: null | string;
ratingSuccess: boolean;
product?: Schemas["Product"];
reviews: {
elements: Schemas["ProductReview"][];
};
apiAlias: "cms_product_description_reviews";
};
};
type BuyBoxElementConfig = ProductDescriptionReviewsElementConfig;
type CmsElementBuyBox = Omit<Schemas["CmsSlot"], "config"> & {
type: "buy-box";
config: BuyBoxElementConfig;
data: {
configuratorSettings: Schemas["PropertyGroup"][] | null;
productId: null | string;
ratingSuccess: boolean;
product?: Schemas["Product"];
reviews: Schemas["ProductReview"][];
apiAlias: "cms_product_description_reviews";
};
};
type CrossSellingElementConfig = {
product: ElementConfig<string>;
alignment: ElementConfig<VerticalAlign>;
boxLayout: ElementConfig<BoxLayout>;
elMinWidth: ElementConfig<string>;
displayMode: ElementConfig<DisplayMode>;
};
type CmsElementCrossSelling = Omit<Schemas["CmsSlot"], "config"> & {
type: "cross-selling";
config: CrossSellingElementConfig;
data: {
apiAlias: "cms_cross_selling";
crossSellings: Schemas["CrossSellingElement"][];
};
};
type FormElementConfig = {
type: ElementConfig<"contact" | "newsletter">;
title: ElementConfig<string>;
mailReceiver: ElementConfig<string[]>;
confirmationText: ElementConfig<string>;
defaultMailReceiver: ElementConfig<boolean>;
};
type CmsElementForm = Omit<Schemas["CmsSlot"], "config"> & {
type: "form";
config: FormElementConfig;
data: Schemas["Salutation"][];
};
type CmsElementProductName = Omit<Schemas["CmsSlot"], "config"> & {
type: "product-name";
config: TextElementConfig;
fieldConfig: ElementFieldConfig[];
data: {
content: string;
apiAlias: "cms_text";
};
translated: {
config: TextElementConfig;
};
};
type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
type: "manufacturer-logo";
config: ImageElementConfig;
data: {
mediaId: string;
url: string;
newTab: boolean;
apiAlias: "cms_manufacturer_logo";
media: Schemas["Media"];
};
};
type CmsSectionBlock<TYPE extends Schemas["CmsSection"]["type"], SECTION_POSITIONS> = Schemas["CmsSection"] & {
type: TYPE;
blocks: Array<Schemas["CmsBlock"] & {
sectionPosition: SECTION_POSITIONS;
}>;
};
type CmsSectionDefault = CmsSectionBlock<"default", "main">;
type CmsSectionSidebar = CmsSectionBlock<"sidebar", "sidebar" | "main">;
type ImageContainerAttrs = {
href?: string;
target?: string;
rel?: string;
};
type UseCmsElementImage = {
containerStyle: ComputedRef<CSSProperties>;
anchorAttrs: ComputedRef<AnchorHTMLAttributes>;
imageAttrs: ComputedRef<ImgHTMLAttributes>;
imageContainerAttrs: ComputedRef<ImageContainerAttrs>;
imageLink: ComputedRef<{
newTab: boolean;
url: string;
}>;
displayMode: ComputedRef<DisplayMode>;
isVideoElement: ComputedRef<boolean>;
mimeType: ComputedRef<string | undefined>;
};
/**
* Composable to get cms element image
*
* @category CMS (Shopping Experiences)
*/
declare function useCmsElementImage(element: CmsElementImage | CmsElementManufacturerLogo): UseCmsElementImage;
/**
* Composable to get cms element config
*
* @category CMS (Shopping Experiences)
*/
declare function useCmsElementConfig<T extends Omit<Schemas["CmsSlot"], "config"> & {
config: T["config"] extends {
[key in infer X extends keyof T["config"]]: ElementConfig<unknown>;
} ? {
[key in X]: ElementConfig<T["config"][key]["value"]>;
} : never;
}>(element: T): {
getConfigValue: <ELEMENT_CONFIG extends keyof T["config"]>(key: ELEMENT_CONFIG) => (typeof element.config)[ELEMENT_CONFIG]["value"];
};
declare function createHeyFrameContext(app: App, options: {
devStorefrontUrl?: string | null;
enableDevtools?: boolean;
browserLocale?: string;
}): vue.Raw<{
install(app: App): void;
_a: App<any>;
_e: EffectScope;
devStorefrontUrl: string | null | undefined;
state: {
interceptors: {};
} | undefined;
browserLocale: string;
}>;
type UseAddressReturn = {
/**
* List of customer addresses
*/
customerAddresses: ComputedRef<Schemas["CustomerAddress"][]>;
/**
* Loads the addresses that are available under `customerAddresses` property
*/
loadCustomerAddresses(): Promise<Schemas["CustomerAddress"][]>;
/**
* Allows to create new address for a current customer
*/
createCustomerAddress(customerAddress: Schemas["CustomerAddress"]): Promise<Schemas["CustomerAddress"]>;
/**
* Allows to update existing address for a current customer
*/
updateCustomerAddress(customerAddress: Schemas["CustomerAddress"]): Promise<Schemas["CustomerAddress"]>;
/**
* Allows to delete existing address for a current customer
*/
deleteCustomerAddress(addressId: string): Promise<void>;
/**
* Sets the address for given ID as default billing address
*/
setDefaultCustomerBillingAddress(addressId: string): Promise<string>;
/**
* Sets the address for given ID as default shipping address
*/
setDefaultCustomerShippingAddress(addressId: string): Promise<string>;
/**
* Returns formatted error message
*
* @param {HeyFrameError} error
*/
errorMessageBuilder(error: ApiError): string | null;
};
/**
* Composable to manage customer addresses
*
* With this composable you can:
* - Fetch customer addresses
* - Return customer addresses
* - Create new customer address
* - Update existing customer address
* - Delete existing customer address
* - Set default billing address
* - Set default shipping address
* - Format error message
*
* @public
*
* @category Cart & Checkout
*/
declare function useAddress(): UseAddressReturn;
type UseAddToCartReturn = {
/**
* Add to cart method
* @type {function}
*/
addToCart(): Promise<Schemas["Cart"]>;
/**
* If you want to add more that 1 product set quantity before invoking `addToCart`
*/
quantity: Ref<number>;
/**
* Returns product count in stock
*/
getStock: ComputedRef<number | undefined>;
/**
* Returns product count in available stock
*/
getAvailableStock: ComputedRef<number | undefined>;
/**
* Flag if product is already in cart
*/
isInCart: ComputedRef<boolean>;
/**
* count of the product quantity already in the cart
*/
count: ComputedRef<number>;
};
/**
* Composable to manage adding product to cart
*
* With this composable you can:
* - Add product to cart
* - Get product quantity
* - Get product stock
* - Get product available stock
* - Check if product is in cart
* - Get product count in cart
*
* @public
* @category Cart & Checkout
*/
declare function useAddToCart(product: Ref<Schemas["Product"] | undefined>): UseAddToCartReturn;
/**
* @internal
*/
type Breadcrumb = {
name: string;
path?: string;
} | Schemas["Breadcrumb"];
/**
* @public
*/
type UseBreadcrumbsReturn = {
/**
* Clear breadcrumbs store
*/
clearBreadcrumbs(): void;
/**
* List of breadcrumbs
*/
breadcrumbs: ComputedRef<Breadcrumb[]>;
/**
* Build breadcrumbs dynamically for a category by fetching them from the API
*
* @param {operations["readBreadcrumb get /breadcrumb/{id}"]["response"]} breadcrumbs
*/
buildDynamicBreadcrumbs(breadcrumbs: operations["readBreadcrumb get /breadcrumb/{id}"]["response"]): Promise<void>;
/**
* Add a breadcrumb to the breadcrumbs list
*
* @param {Breadcrumb} breadcrumb
*/
pushBreadcrumb(breadcrumb: Breadcrumb): void;
};
/**
* Composable for breadcrumbs management.
* Read the [guide](https://frontends.heyframe.com/getting-started/page-elements/breadcrumbs.html#building-breadcrumbs-for-cms-pages).
*
* @public
* @category CMS (Shopping Experiences)
*/
declare function useBreadcrumbs(newBreadcrumbs?: Breadcrumb[]): UseBreadcrumbsReturn;
/**
* Composable to manage cart
*
* @public
* @category Cart & Checkout
*/
type UseCartReturn = {
/**
* Add product by id and quantity
*/
addProduct(params: {
id: string;
quantity?: number;
}): Promise<Schemas["Cart"]>;
/**
* Add products by array of items
*/
addProducts(items: operations["addLineItem post /checkout/cart/line-item"]["body"]["items"]): Promise<Schemas["Cart"]>;
/**
* Adds a promotion code to the cart
*/
addPromotionCode(promotionCode: string): Promise<Schemas["Cart"]>;
/**
* Lists all applied and active promotion codes
*/
appliedPromotionCodes: ComputedRef<Schemas["LineItem"][]>;
/**
* Current Cart object
*/
cart: ComputedRef<Schemas["Cart"] | undefined>;
/**
* All items in the cart
*/
cartItems: ComputedRef<Schemas["LineItem"][]>;
/**
* Changes the quantity of a product in the cart
*/
changeProductQuantity(params: {
id: string;
quantity: number;
}): Promise<Schemas["Cart"]>;
/**
* The number of items in the cart
*/
count: ComputedRef<number>;
/**
* Refreshes the cart object and related data
* If @param newCart is provided, it will be used as a new cart object
*/
refreshCart(newCart?: Schemas["Cart"]): Promise<Schemas["Cart"]>;
/**
* Removes the provided LineItem from the cart
*/
removeItem(lineItem: Schemas["LineItem"]): Promise<Schemas["Cart"]>;
/**
* The total price of the cart (including calculated costs like shipping)
*/
totalPrice: ComputedRef<number>;
/**
* Shipping price
*
* @deprecated Use `shippingCosts` instead
*/
shippingTotal: ComputedRef<number>;
/**
* Shipping costs
*/
shippingCosts: ComputedRef<Schemas["CartDelivery"][]>;
/**
* The total price of all cart items
*/
subtotal: ComputedRef<number>;
/**
* `true` if the cart contains no items
*/
isEmpty: ComputedRef<boolean>;
/**
* `true` if cart contains only digital items
*/
isVirtualCart: ComputedRef<boolean>;
/**
* Get cart errors
*/
consumeCartErrors(): Schemas["Cart"]["errors"];
};
/**
* Cart management logic.
*
* Used as [Shared](https://frontends.heyframe.com/framework/composables/shared-composables.html) Composable `useCart`
*
* @category Cart & Checkout
*/
declare function useCartFunction(): UseCartReturn;
declare const useCart: typeof useCartFunction;
type UseCartItemReturn = {
/**
* Calculated price {number} for the current item
*/
itemRegularPrice: ComputedRef<number | undefined>;
/**
* Calculated price {number} for the current item if list price is set
*/
itemSpecialPrice: ComputedRef<number | undefined>;
/**
* Total price for the current item of given quantity in the cart
*/
itemTotalPrice: ComputedRef<number | undefined>;
/**
* Thumbnail url for the current item's entity
*/
itemImageThumbnailUrl: ComputedRef<string>;
/**
* Options (of variation) for the current item
*/
itemOptions: ComputedRef<Schemas["LineItem"]["payload"]["options"]>;
/**
* Type of the current item: "product" or "promotion"
*/
itemType: ComputedRef<Schemas["LineItem"]["type"] | undefined>;
/**
* Determines if the current item is a product
*/
isProduct: ComputedRef<boolean>;
/**
* Determines if the current item is a promotion
*/
isPromotion: ComputedRef<boolean>;
/**
* Determines if the current item can be removed from cart
*/
isRemovable: ComputedRef<boolean>;
/**
* Determines if the current item's quantity can be changed
*/
isStackable: ComputedRef<boolean>;
/**
* Determines if the current item is a digital product (to download)
*/
isDigital: ComputedRef<boolean>;
/**
* Stock information for the current item
*/
itemStock: ComputedRef<number | undefined>;
/**
* Quantity of the current item in the cart
*/
itemQuantity: ComputedRef<number | undefined>;
/**
* Changes the current item quantity in the cart
*/
changeItemQuantity(quantity: number): Promise<Schemas["Cart"]>;
/**
* Removes the current item from the cart
*/
removeItem(): Promise<Schemas["Cart"]>;
};
/**
* Composable to manage specific cart item
* @public
* @category Cart & Checkout
*/
declare function useCartItem(cartItem: Ref<Schemas["LineItem"]>): UseCartItemReturn;
type UseCategoryReturn = {
/**
* Current category entity
*/
category: ComputedRef<Schemas["Category"]>;
};
/**
* Composable to get the category from current CMS context
*
* @category Product
* @public
*/
declare function useCategory(category?: Ref<Schemas["Category"]>): UseCategoryReturn;
type UseCategorySearchReturn = {
/**
* Search for category by ID
* Accepts optional query params and associations
*/
search(categoryId: string, options?: {
withCmsAssociations?: boolean;
query?: Schemas["Criteria"];
}): Promise<Schemas["Category"]>;
/**
* Search based on the query
*/
advancedSearch(options: {
withCmsAssociations?: boolean;
query: Schemas["Criteria"];
}): Promise<Schemas["Category"][]>;
};
/**
* Composable for category search.
* @public
* @category Navigation & Routing
*/
declare function useCategorySearch(): UseCategorySearchReturn;
type UseCheckoutReturn = {
/**
* Fetches all available shipping methods
*/
getShippingMethods(options?: {
forceReload: boolean;
}): Promise<ComputedRef<Schemas["ShippingMethod"][]>>;
/**
* List of available shipping methods
*/
shippingMethods: ComputedRef<Schemas["ShippingMethod"][]>;
/**
* Fetches all available payment methods
*/
getPaymentMethods(options?: {
forceReload: boolean;
}): Promise<ComputedRef<Schemas["PaymentMethod"][]>>;
/**
* List of available payment methods
*/
paymentMethods: ComputedRef<Schemas["PaymentMethod"][]>;
/**
* Creates order based on the current cart
*/
createOrder(params?: operations["createOrder post /checkout/order"]["body"]): Promise<Schemas["Order"]>;
/**
* Shipping address for the current session
*/
shippingAddress: ComputedRef<Schemas["CustomerAddress"] | undefined>;
/**
* Billing address for the current session
*/
billingAddress: ComputedRef<Schemas["CustomerAddress"] | undefined>;
/**
* Selected shipping method for the current session
* Sugar for {@link useSessionContext.selectedShippingMethod}
*/
selectedShippingMethod: ComputedRef<Schemas["ShippingMethod"] | null>;
/**
* Sets shipping method for the current session
* Sugar for {@link useSessionContext.setShippingMethod}
*/
setShippingMethod(shippingMethod: {
id: string;
}): Promise<void>;
/**
* Selected payment method for the current session
* Sugar for {@link useSessionContext.selectedPaymentMethod}
*/
selectedPaymentMethod: ComputedRef<Schemas["PaymentMethod"] | null>;
/**
* Sets payment method for the current session
* Sugar for {@link useSessionContext.setPaymentMethod}
*/
setPaymentMethod(paymentMethod: {
id: string;
}): Promise<void>;
};
/**
* Composable to manage checkout process
* @public
* @category Cart & Checkout
*/
declare function useCheckout(): UseCheckoutReturn;
type ArrayElement$1<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
type UseCmsBlockReturn = {
/**
* Cms block content
*/
block: Schemas["CmsBlock"];
/**
* Get slot content by slot name (identifier)
* @example getSlotContent("main")
*/
getSlotContent(slotName: string): ArrayElement$1<Schemas["CmsBlock"]["slots"]>;
};
/**
* Composable to get cms block content
* @public
* @category CMS (Shopping Experiences)
*/
declare function useCmsBlock<BLOCK_TYPE extends Schemas["CmsBlock"]>(content: BLOCK_TYPE): UseCmsBlockReturn;
type UseCmsMetaReturn = {
/**
* Meta title for current page/entity
*/
title: ComputedRef<string>;
/**
* Meta tags for current page/entity
*/
meta: ComputedRef<{
name: string;
content: string;
}[]>;
};
/**
* TODO: remove parameter and use reactive state of cmsResponse provided by useCms composable
* @category CMS (Shopping Experiences)
*/
declare function useCmsMeta(entity: Schemas["Category"] | Schemas["Product"] | Schemas["LandingPage"]): UseCmsMetaReturn;
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
type UseCmsSectionType = {
/**
* CMS section
*/
section: Schemas["CmsSection"];
/**
* Position of the section
*/
getPositionContent(position: ArrayElement<Schemas["CmsSection"]["blocks"]>["sectionPosition"]): Array<Schemas["CmsBlock"]>;
};
/**
* Composable to get cms section content
* @public
* @category CMS (Shopping Experiences)
*/
declare function useCmsSection<SECTION_TYPE extends Schemas["CmsSection"]>(content: SECTION_TYPE): UseCmsSectionType;
/**
* @category CMS (Shopping Experiences)
* @returns
*/
declare function useCmsTranslations(): {};
/**
* Context helper composable to provide and inject data.
* It takes `injectionName` to inject the context. If no context is provided, it will create a new one and provide it.
* If `context` is provided in params, it will create new context, use param as value and provide it.
* If `replace` is provided, it will replace the existing context with the new value.
*
* @public
* @category Context & Language
*/
declare function useContext<T>(injectionName: string, params?: {
context?: Ref<T> | T;
replace?: T;
}): Ref<T, T>;
type UseCountriesReturn = {
mountedCallback(): Promise<void>;
getCountries: ComputedRef<Schemas["Country"][]>;
fetchCountries(): Promise<operations["readCountry post /country"]["response"]>;
getStatesForCountry(countryId: string): Schemas["CountryState"][] | null;
getCountriesOptions: ComputedRef<{
label: string;
value: string;
}[]>;
};
/**
* Composable to manage countries
* @public
* @category Context & Language
*/
declare function useCountries(): UseCountriesReturn;
type UseCustomerOrdersReturn = {
/**
* All placed orders belonging to the logged-in customer
*/
orders: Ref<Schemas["Order"][]>;
/**
* Changes the current page of the orders list
*
* In order to change a page with additional parameters please use `loadOrders` method.
*/
changeCurrentPage(pageNumber: number | string): Promise<void>;
/**
* Fetches the orders list and assigns the result to the `orders` property
*/
loadOrders(parameters?: operations["readOrder post /order"]["body"]): Promise<void>;
/**
* Current page number
*/
currentPage: ComputedRef<number>;
/**
* total pages
*/
totalPages: ComputedRef<number>;
/**
* Limit of orders per page
*/
limit: Ref<number>;
};
/**
* Composable for fetching the orders list.
* @public
* @category Customer & Account
*/
declare function useCustomerOrders(): UseCustomerOrdersReturn;
type UseCustomerPasswordReturn = {
/**
* Change customer's current password
*/
updatePassword(updatePasswordData: operations["changePassword post /account/change-password"]["body"]): Promise<operations["changePassword post /account/change-password"]["response"]>;
/**
* Reset customer's password
*/
resetPassword(resetPasswordData: operations["sendRecoveryMail post /account/recovery-password"]["body"]): Promise<operations["sendRecoveryMail post /account/recovery-password"]["response"]>;
};
/**
* Composable for customer password management.
* @public
* @category Customer & Account
*/
declare function useCustomerPassword(): UseCustomerPasswordReturn;
/**
* Returns default order associations. You can override this composable in your project.
* @public
* @category Order
*/
declare function useDefaultOrderAssociations(): Schemas["Criteria"]["associations"];
type UseInternationalizationReturn = {
/**
* StorefrontUrl is needed to specify language of emails
*
* @returns {string} storefront URL
*/
getStorefrontUrl(): string;
/**
* Get available languages from backend
*
* @returns {Promise<operations['readLanguages post /language']['body']>} list of languages
*/
getAvailableLanguages(): Promise<operations["readLanguages post /language"]["response"]>;
/**
* Change current language
*
* @param {string} languageId
* @returns {Promise<Schemas['ContextTokenResponse']>} context object
*/
changeLanguage(languageId: string): Promise<operations["updateContext patch /context"]["response"]>;
/**
* Get language code from backend language id
*
* @param {string} languageId
* @returns {string} language code
*/
getLanguageCodeFromId(languageId: string): string;
/**
* Get backend language id from language code
*
* @param {string} languageCode
* @returns {string} language
*/
getLanguageIdFromCode(languageCode: string): string;
/**
* Replace to dev url if it is set
*
* @param {string} url
* @returns {string} prefixed url
*/
replaceToDevStorefront(url: string): string;
/**
* List of available languages
*/
languages: Ref<Schemas["Language"][]>;
/**
* Currently used language
*/
currentLanguage: Ref<string>;
/**
* Current prefix from the context
*/
currentPrefix: Ref<string>;
/**
* Add prefix to the Url
* @param {string | RouteObject} link
*/
formatLink(link: string | RouteObject): string | RouteObject;
};
type RouteObject = {
path: string;
[key: string]: unknown;
};
/**
* Composable for internationalization management.
* @public
* @category Context & Language
*/
declare function useInternationalization(pathResolver?: (path: string) => string): UseInternationalizationReturn;
type UseLandingSearchReturn = {
/**
* Search for landing page by ID
* Accepts optional media associations
*/
search(navigationId: string, options?: {
withCmsAssociations?: boolean;
}): Promise<Schemas["LandingPage"]>;
};
/**
* Composable for landing page search.
* @public
* @category Navigation & Routing
*/
declare function useLandingSearch(): {
search: (navigationId: string, options?: {
withCmsAssociations?: boolean;
}) => Promise<Schemas["LandingPage"]>;
};
type ListingType = "productSearchListing" | "categoryListing";
type ShortcutFilterParam<T extends keyof Schemas["ProductListingCriteria"] = keyof Schemas["ProductListingCriteria"]> = {
code: T;
value: Schemas["ProductListingCriteria"][T];
};
type UseListingReturn = {
/**
* Listing that is currently set
* {@link ListingResult} object
*/
getInitialListing: ComputedRef<Schemas["ProductListingResult"] | null>;
/**
* Sets the initial listing - available synchronously
* @param {@link initialListing} - initial listing to set
* @returns
*/
setInitialListing(initialListing: Schemas["ProductListingResult"]): Promise<void>;
/**
* @deprecated - use `search` instead
* Searches for the listing based on the criteria
* @param criteria {@link Schemas['Criteria']}
* @returns
*/
initSearch(criteria: operations["searchPage post /search"]["body"]): Promise<Schemas["ProductListingResult"]>;
/**
* Searches for the listing based on the criteria
* @param criteria
* @returns
*/
search(criteria: operations["readProductListing post /product-listing/{categoryId}"]["body"] | operations["searchPage post /search"]["body"]): Promise<void>;
/**
* Loads more (next page) elements to the listing
*/
loadMore(criteria?: operations["searchPage post /search"]["body"]): Promise<void>;
/**
* Listing that is currently set
*/
getCurrentListing: ComputedRef<Schemas["ProductListingResult"] | null>;
/**
* Listing elements ({@link Product}) that are currently set
*/
getElements: ComputedRef<Schemas["ProductListingResult"]["elements"]>;
/**
* Available sorting orders
*/
getSortingOrders: ComputedRef<Schemas["ProductSorting"][] | {
key: string;
label: string;
}[] | undefined>;
/**
* Current sorting order
*/
getCurrentSortingOrder: ComputedRef<string | undefined>;
/**
* Changes the current sorting order
* @param order - i.e. "name-asc"
* @returns
*/
changeCurrentSortingOrder(order: string, query?: operations["searchPage post /search"]["body"]): Promise<void>;
/**
* Current page number
*/
getCurrentPage: ComputedRef<number>;
/**
* Changes the current page number
* @param pageNumber - page number to change to
* @returns
*/
changeCurrentPage(page: number, query?: operations["searchPage post /search"]["body"]): Promise<void>;
/**
* Total number of elements found for the current search criteria
*/
getTotal: ComputedRef<number>;
/**
* Total number of pages found for the current search criteria
*/
getTotalPagesCount: ComputedRef<number>;
/**
* Number of elements per page
*/
getLimit: ComputedRef<number>;
/**
* Initial filters
*/
getInitialFilters: ComputedRef<ReturnType<typeof getListingFilters>>;
/**
* All available filters
*/
getAvailableFilters: ComputedRef<ReturnType<typeof getListingFilters>>;
/**
* Filters that are currently set
*/
getCurrentFilters: ComputedRef<Schemas["ProductListingResult"]["currentFilters"]>;
/**
* Sets the filters to be applied for the listing
* @param filters
* @returns
*/
setCurrentFilters(filters: ShortcutFilterParam[]): Promise<void>;
/**
* Indicates if the listing is being fetched
*/
loading: ComputedRef<boolean>;
/**
* Indicates if the listing is being fetched via `loadMore` method
*/
loadingMore: ComputedRef<boolean>;
/**
* Resets the filters - clears the current filters
*/
resetFilters(): Promise<void>;
/**
* Change selected filters to the query object
*/
filtersToQuery(filters: Schemas["ProductListingCriteria"]): Record<string, unknown>;
};
/**
* @public
* @category Product
*/
declare function useListing(params?: {
listingType: ListingType;
categoryId?: string;
defaultSearchCriteria?: operations["searchPage post /search"]["body"];
}): UseListingReturn;
declare const createCategoryListingContext: () => UseListingReturn;
/**
* Temporary workaround over `useListing` to support shared data. This composable API will change in the future.
*
* You need to call `createCategoryListingContext` before this composable.
*/
declare const useCategoryListing: () => UseListingReturn;
/**
* Temporary workaround over `useListing` to support shared data. This composable API will change in the future.
*/
declare const useProductSearchListing: () => UseListingReturn;
/**
* Factory to create your own listing.
*
* By default you can use useListing composable, which provides you predefined listings for category(cms) listing and product search listing.
* Using factory you can provide our own compatible search method and use it for example for creating listing of orders in my account.
*
* @public
*/
declare function createListingComposable({ searchMethod, searchDefaults, listingKey, }: {
searchMethod(searchParams: operations["readProductListing post /product-listing/{categoryId}"]["body"] | operations["searchPage post /search"]["body"]): Promise<Schemas["ProductListingResult"]>;
searchDefaults: operations["searchPage post /search"]["body"];
listingKey: string;
}): UseListingReturn;
type UseLocalWishlistReturn = {
/**
* Get wishlist products from localstorage
*/
getWishlistProducts(): void;
/**
* Add product to wishlist by its id
*/
addToWishlist(id: string): Promise<void>;
/**
* Remove product from wishlist by its id
*/
removeFromWishlist(id: string): Promise<void>;
/**
* Remove all products from wishlist
*/
clearWishlist(): Promise<void>;
/**
* List of wishlist items
*/
items: ComputedRef<string[]>;
/**
* Count of wishlist items
*/
count: ComputedRef<number>;
};
/**
* Composable for wishlist management.
* @public
* @category Wishlist
*/
declare function useLocalWishlist(): UseLocalWishlistReturn;
/**
*
* Provides state for navigation trees depending on navigation type.
*/
type UseNavigationReturn = {
/**
* List of navigation elements
*/
navigationElements: ComputedRef<Schemas["NavigationRouteResponse"] | null>;
/**
* Load navigation elements
*/
loadNavigationElements(params: operations["readNavigation post /navigation/{activeId}/{rootId}"]["body"]): Promise<Schemas["NavigationRouteResponse"]>;
};
/**
* Composable for navigation.
* Provides state for navigation trees depending on navigation type.
*
* @example
* ```
* // get main navigation
* useNavigation()
* // get footer navigation
* useNavigation({ type: "footer-navigation" } )
* ```
* @public
* @category Navigation & Routing
*/
declare function useNavigation(params?: {
type?: Schemas["NavigationType"] | string;
}): UseNavigationReturn;
type UseNavigationContextReturn = {
/**
* SEO URL from the navigation context
*/
navigationContext: ComputedRef<Schemas["SeoUrl"] | null>;
/**
* Route name from the navigation context
*/
routeName: ComputedRef<Schemas["SeoUrl"]["routeName"] | undefined>;
/**
* Foreign key (ID) for current navigation context
*/
foreignKey: ComputedRef<string>;
};
/**
* Composable to get navigation context from the URL.
* @public
* @category Navigation & Routing
*/
declare function useNavigationContext(context?: Ref<Schemas["SeoUrl"] | null>): UseNavigationContextReturn;
type UseNavigationSearchReturn = {
/**
* Get {@link SeoUrl} entity for given path
* @example resolvePath("/my-category/my-product") or resolvePath("/") for home page
*/
resolvePath(path: string): Promise<Schemas["SeoUrl"] | null>;
};
/**
* Composable to get search for SeoUrl entity for given path.
* @public
* @category Navigation & Routing
*/
declare function useNavigationSearch(): UseNavigationSearchReturn;
type UseNewsletterReturn = {
/**
* Subscribes the user to the newsletter
* @param params {@link operations['subscribeToNewsletter post /newsletter/subscribe']['body']}
*/
newsletterSubscribe(params: Omit<operations["subscribeToNewsletter post /newsletter/subscribe"]["body"], "storefrontUrl">): Promise<void>;
/**
* Removes the email from the newsletter
* @param email
*/
newsletterUnsubscribe(email: string): Promise<void>;
/**
* Get newsletter status from the API call
*/
getNewsletterStatus(): Promise<Schemas["AccountNewsletterRecipient"]>;
/**
* Indicates if the user is subscribed to the newsletter
*
* Returns `true` if the user is subscribed to the newsletter, `false` otherwise
*/
isNewsletterSubscriber: ComputedRef<boolean>;
/**
* Newsletter status
*/
newsletterStatus: Ref<Schemas["AccountNewsletterRecipient"]["status"]>;
/**
* Inform about newsletter confirmation
*/
confirmationNeeded: ComputedRef<boolean>;
};
/**
* Composable for newsletter subscription.
* @public
* @category Customer & Account
*/
declare function useNewsletter(): UseNewsletterReturn;
type NotificationType = "info" | "warning" | "success" | "danger";
/**
* @private
*/
type Notification = {
type: NotificationType;
message: string;
id: number;
};
/**
* @private
*/
type NotificationOptions = {
/**
* @private
*/
type?: NotificationType;
timeout?: number;
persistent?: boolean;
};
/**
* @public
*/
type UseNotificationsReturn = {
/**
* List of active notifications
*/
notifications: ComputedRef<Notification[]>;
/**
* Removes a specific notification by its ID
*/
removeOne(id: number): void;
/**
* Resets the notification list - clear all notifications
*/
removeAll(): void;
/**
* Push an info notification to the current list
*/
pushInfo(message: string, options?: NotificationOptions): void;
/**
* Pushes a warning notification to the current list
*/
pushWarning(message: string, options?: NotificationOptions): void;
/**
* Pushes an error notification to the current list
*/
pushError(message: string, options?: NotificationOptions): void;
/**
* Pushes a success notification to the current list
*/
pushSuccess(message: string, options?: NotificationOptions): void;
};
/**
* Composable for managing notifications (flash messages) on frontend.
* @public
*/
declare function useNotifications(): UseNotificationsReturn;
type UseOrderDetailsReturn = {
/**
* {@link Schemas['Order']} object
*/
order: ComputedRef<Schemas["Order"] | undefined | null>;
/**
* Order status (e.g. 'Open', 'Cancelled')
*/
status: ComputedRef<string | undefined>;
/**
* Order status technical name (e.g. 'open', 'cancelled')
*/
statusTechnicalName: ComputedRef<string | undefined>;
/**
* Order total price
*/
total: ComputedRef<number | undefined>;
/**
* Order subtotal price for all items
*/
subtotal: ComputedRef<number | undefined>;
/**
* Order shipping costs
*/
shippingCosts: ComputedRef<number | undefined>;
/**
* Shipping address
*/
shippingAddress: ComputedRef<Schemas["OrderAddress"] | undefined>;
/**
* Billing address
*/
billingAddress: ComputedRef<Schemas["OrderAddress"] | undefined>;
/**
* Basic personal details
*/
personalDetails: ComputedRef<{
email: string | undefined;
firstName: string | undefined;
lastName: string | undefined;
}>;
/**
* Payment URL for external payment methods (e.g. async payment in external payment gateway)
*/
paymentUrl: Ref<null | string>;
/**
* Returns current selected shipping method for the order. Last element in delivery array.
*/
shippingMethod: ComputedRef<Schemas["ShippingMethod"] | undefined | null>;
/**
* Returns current selected payment method for the order. Last element in transactions array.
*/
paymentMethod: ComputedRef<Schemas["PaymentMethod"] | undefined | null>;
/**
* Get order object including additional associations.
* useDefaults describes what order object should look like.
*/
loadOrderDetails(): Promise<Schemas["OrderRouteResponse"]>;
/**
* Handle payment for existing error.
*
* Pass custom success and error URLs (optionally).
*/
handlePayment(successUrl?: string, errorUrl?: string, paymentDetails?: unknown): void;
/**
* Cancel an order.
*
* Action cannot be reverted.
*/
cancel(): Promise<Schemas["StateMachineState"]>;
/**
* Changes the payment method for current cart.
* @param paymentMethodId - ID of the payment method to be set
* @returns
*/
changePaymentMethod(paymentMethodId: string): Promise<Schemas["SuccessResponse"]>;
/**
* Get media content
*
* @param {string} downloadId
* @returns {Blob}
*/
getMediaFile: (downloadId: string) => Promise<Blob>;
/**
* Get order documents
* @param {string} documentId
* @param {string} deepLinkCode
* @returns
*/
getDocumentFile: (documentId: string, deepLinkCode: string) => Promise<Schemas["Document"]>;
/**
* Check if order has documents
*/
hasDocuments: ComputedRef<boolean>;
/**
* Get order documents
*/
documents: ComputedRef<Schemas["Document"][]>;
/**
* Fetches all available payment methods
*/
getPaymentMethods(): Promise<Schemas["PaymentMethod"][]>;
paymentChangeable: ComputedRef<boolean>;
};
/**
* Composable for managing an existing order.
* @public
* @category Customer & Account
*/
declare function useOrderDetails(orderId: string, associations?: Schemas["Criteria"]["associations"]): UseOrderDetailsReturn;
type UseOrderPaymentReturn = {
/**
* If the payment can be done after the order is placed
*/
isAsynchronous: ComputedRef<boolean | undefined>;
/**
* Active payment transaction
*/
activeTransaction: ComputedRef<Schemas["OrderTransaction"] | undefined>;
/**
* Payment status
*/
state: ComputedRef<Schemas["StateMachineState"] | null | undefined>;
paymentUrl: Ref<null | string>;
/**
* Payment method set for the order
*/
paymentMethod: ComputedRef<Schemas["PaymentMethod"] | undefined | null>;
/**
* Invokes the payment process for the order in the backend
*/
handlePayment(
/**
* URL to redirect after successful payment
*/
successUrl?: string,
/**
* URL to redirect after failed payment
*/
errorUrl?: string,
/**
* additional payment details to provide
*/
paymentDetails?: unknown): Promise<undefined | unknown>;
/**
* Change a payment method for the order
*/
changePaymentMethod(paymentMethodId: string): Promise<Schemas["SuccessResponse"] | undefined>;
};
/**
* Composable for managing an existing order.
* @public
* @category Customer & Account
*/
declare function useOrderPayment(order: ComputedRef<Schemas["Order"] | null | undefined>): UseOrderPaymentReturn;
type UsePriceReturn = {
/**
* Format price i.e. (2) -> 2.00 $
*/
getFormattedPrice(value: number | string | undefined): string;
/**
* Update configuration
*/
update(params: {
localeCode?: string | undefined;
currencyCode: string;
}): void;
/**
* Currency code
*/
currencyCode: ComputedRef<string>;
/**
* Currency locale
*/
currencyLocale: ComputedRef<string>;
};
/**
* Composable for getting formatted price
* Set the default currency code and locale in order to format a price correctly
*
* @public
* @category Product
*/
declare function _usePrice(params?: {
localeCode?: string | undefined;
currencyCode