import { productsV3 } from '@wix/stores'; import { type Signal } from '@wix/services-definitions/core-services/signals'; /** * API interface for the Product service, providing reactive product data management. * This service handles loading and managing a single product's data, loading state, and errors. * * @interface ProductServiceAPI */ export interface ProductServiceAPI { /** Reactive signal containing the current product data */ product: Signal; /** Reactive signal indicating if a product is currently being loaded */ isLoading: Signal; /** Reactive signal containing any error message, or null if no error */ error: Signal; /** Function to load a product by its slug */ loadProduct: (slug: string) => Promise; /** Reports a ViewContent analytics event for the current product */ reportViewContentTrackEvent: () => void; /** Reports an AddToCart analytics event for the current product */ reportAddToCartTrackEvent: (options?: { quantity?: number; variant?: string; origin?: string; position?: string; }) => void; /** Reports a ClickProduct analytics event for the current product */ reportClickProductTrackEvent: (options?: { variant?: string; list?: string; position?: string; origin?: string; }) => void; } /** * Service definition for the Product service. * This defines the contract that the ProductService must implement. * * @constant */ export declare const ProductServiceDefinition: string & { __api: ProductServiceAPI; __config: {}; isServiceDefinition?: boolean; } & ProductServiceAPI; /** * Configuration interface required to initialize the ProductService. * Contains the initial product data that will be loaded into the service. * * @interface ProductServiceConfig */ export interface ProductServiceConfig { /** The initial product data to configure the service with */ product?: productsV3.V3Product; productSlug?: string; } /** * Implementation of the Product service that manages reactive product data. * This service provides signals for product data, loading state, and error handling, * along with methods to dynamically load products. * * @example * ```tsx * import { ProductService, ProductServiceDefinition } from '@wix/stores/services'; * import { useService } from '@wix/services-manager-react'; * * function ProductComponent({ productConfig }) { * return ( * * * * ); * } * * function ProductDisplay() { * const productService = useService(ProductServiceDefinition); * const product = productService.product.get(); * const isLoading = productService.isLoading.get(); * const error = productService.error.get(); * * if (isLoading) return
Loading...
; * if (error) return
Error: {error}
; * * return

{product.name}

; * } * ``` */ export declare const ProductService: import("@wix/services-definitions").ServiceFactory; /** * Success result interface for product service configuration loading. * Returned when a product is successfully found and loaded. * * @interface SuccessProductServiceConfigResult */ export interface SuccessProductServiceConfigResult { /** Type "success" means that the product was found and the config is valid */ type: 'success'; /** The product config containing the loaded product data */ config: ProductServiceConfig; } /** * Not found result interface for product service configuration loading. * Returned when a product with the given slug cannot be found. * * @interface NotFoundProductServiceConfigResult */ export interface NotFoundProductServiceConfigResult { /** Type "notFound" means that the product was not found */ type: 'notFound'; } /** * Loads product service configuration from the Wix Products API for SSR initialization. * This function is designed to be used during Server-Side Rendering (SSR) to preload * a specific product by slug that will be used to configure the ProductService. * * @param productSlug The product slug to load * @returns Promise that resolves to ProductServiceConfigResult (success with config or notFound) * * @example Astro - SSR product page * ```astro * --- * // Astro page example - pages/product/[slug].astro * import { loadProductServiceConfig } from '@wix/stores/services'; * import { Product } from '@wix/stores/components'; * * // Get product slug from URL params * const { slug } = Astro.params; * * // Load product data during SSR * const productResult = await loadProductServiceConfig(slug); * * // Handle not found case * if (productResult.type === 'notFound') { * return Astro.redirect('/404'); * } * --- * * * * {({ name }) =>

{name}

} *
*
* ``` * * @example Next.js - SSR product page * ```tsx * // Next.js page example - pages/product/[slug].tsx * import { GetServerSideProps } from 'next'; * import { loadProductServiceConfig } from '@wix/stores/services'; * import { Product } from '@wix/stores/components'; * * interface ProductPageProps { * product: Extract>, { type: 'success' }>['config']['product']; * } * * export const getServerSideProps: GetServerSideProps = async ({ params }) => { * const slug = params?.slug as string; * * // Load product data during SSR * const productResult = await loadProductServiceConfig(slug); * * // Handle not found case * if (productResult.type === 'notFound') { * return { * notFound: true, * }; * } * * return { * props: { * product: productResult.config.product, * }, * }; * }; * * export default function ProductPage({ product }: ProductPageProps) { * return ( * * * {({ name }) =>

{name}

} *
*
* ); * } * ``` */ export declare function loadProductServiceConfig(productSlug: string): Promise;