UNPKG

@redotech/redo-hydrogen

Version:

Utilities to enable and disable Redo coverage on Hydrogen stores

82 lines (74 loc) 3.1 kB
import { CartReturn, OptimisticCart } from '@shopify/hydrogen'; import { ReactNode, DependencyList } from 'react'; import { CartWithActionsDocs } from '@shopify/hydrogen-react/dist/types/cart-types'; import { ProductVariant } from '@shopify/hydrogen-react/storefront-api-types'; import * as react_jsx_runtime from 'react/jsx-runtime'; type CartProductVariantFragment = Omit<ProductVariant, "components" | "metafields" | "quantityPriceBreaks" | "quantityRule" | "requiresComponents" | "requiresShipping" | "storeAvailability" | "taxable" | "weightUnit">; type CartAttributeKey = string; interface RedoCoverageClient { enable(): Promise<boolean>; disable(): Promise<boolean>; get loading(): boolean; get enabled(): boolean; get eligible(): boolean; get price(): number | undefined; get storeId(): string | undefined; get cart(): CartReturn | CartWithActionsDocs | OptimisticCart | undefined; get cartProduct(): CartProductVariantFragment | undefined; get cartAttribute(): CartAttributeKey | undefined; get errors(): RedoError[] | undefined; } type CartInfoToEnable = { productId: string; variantId: string; cartAttribute: CartAttributeKey; selectedVariant: CartProductVariantFragment; }; type RedoContextValue = { enabled: boolean; loading: boolean; storeId?: string; cartInfoToEnable?: CartInfoToEnable; cart?: CartReturn | CartWithActionsDocs | OptimisticCart; errors?: RedoError[]; }; declare enum RedoErrorType { ApiBadRequest = "API_BAD_REQUEST", ApiServerError = "API_SERVER_ERROR", ApiUnknownError = "API_UNKNOWN_ERROR" } type RedoError = { type: RedoErrorType; message: string; context: any; }; declare const RedoProvider: ({ cart, storeId, children }: { cart: CartReturn | CartWithActionsDocs | OptimisticCart; storeId: string; children: ReactNode; }) => ReactNode; declare const useRedoCoverageClient: () => RedoCoverageClient; declare const RedoCheckoutButtons: (props: { children?: ReactNode; onClick?: (enabled: boolean) => void; }) => react_jsx_runtime.JSX.Element; declare const REDO_REQUIRED_HOSTNAMES: string[]; interface Loader<T> { (abort: AbortSignal): Promise<T>; } interface LoadState<T> { error?: any; pending: boolean; value?: T; } declare function useLoad<T>(fn: Loader<T>, deps: DependencyList): LoadState<T>; interface RedoInfoModalProps { showInfoIcon?: boolean; onInfoClick?: () => void; infoCardImageUrl?: string; infoModalLogoUrl?: string; infoModalImageUrl?: string; infoModalContent?: ReactNode; } declare const RedoInfoCard: ({ showInfoIcon, onInfoClick, infoCardImageUrl, infoModalLogoUrl, infoModalImageUrl, infoModalContent, }: RedoInfoModalProps) => react_jsx_runtime.JSX.Element; export { type CartAttributeKey, type CartInfoToEnable, type CartProductVariantFragment, type LoadState, type Loader, REDO_REQUIRED_HOSTNAMES, RedoCheckoutButtons, type RedoContextValue, type RedoCoverageClient, type RedoError, RedoErrorType, RedoInfoCard, RedoProvider, useLoad, useRedoCoverageClient };