import { default as default_2 } from 'react'; /** * A purchasable item defined by a publisher for their application. * Items are session-scoped; they expire when the session ends. */ export declare interface ApplicationItem { /** Unique item identifier (UUID) */ id: string; /** Display name (3–80 characters) */ name: string; /** Item description (0–500 characters) */ description: string; /** Publisher's USD rate per purchase (e.g. 2.00) */ baseRateUsd: number; /** Derived wholesale token cost: floor(baseRateUsd / 0.10) */ wholesaleTokenCost: number; /** Derived user token cost: ceil(baseRateUsd * 1.35 / 0.10) */ userTokenCost: number; /** Lifecycle status — inactive blocks purchases */ status: "active" | "inactive" | "deleted"; /** Display visibility — hidden items are sold only via requestPurchase */ visibility: "visible" | "hidden"; /** Optimistic locking version */ version: number; /** ISO 8601 creation timestamp */ createdAt: string; /** ISO 8601 last-updated timestamp */ updatedAt: string; /** * Minimum Privy level required to purchase this item. * 0 = no Privy requirement; 1 = Privy 1 required. * When > 0, item cards should display a Privy badge. */ minimumPrivyLevel?: number; } declare type ButtonSize = "sm" | "md" | "lg"; declare type ButtonVariant = "primary" | "secondary" | "outline"; /** * Styleable purchase button component. * * Supports render props for full customisation while providing a sensible * default UI out of the box. * * @example * ```tsx * // Default usage * console.log(r)} /> * * // Render prop — full control * * {({ purchase, isPurchasing, canPurchase }) => ( * * {isPurchasing ? 'Buying…' : 'Purchase'} * * )} * * ``` */ export declare function GWPurchaseButton({ itemId, quantity, className, style, theme, variant, size, fullWidth, children, showPrice, showIcon, showPrivyBadge, onSuccess, onError, render, }: GWPurchaseButtonProps): default_2.ReactElement; /** * Props for GWPurchaseButton. */ export declare interface GWPurchaseButtonProps { /** ID of the marketplace item to purchase */ itemId: string; /** Number of units to purchase (default: 1) */ quantity?: number; /** Additional CSS class names */ className?: string; /** Inline style overrides */ style?: default_2.CSSProperties; /** Theme colour overrides */ theme?: GWPurchaseButtonTheme; /** Visual variant (default: "primary") */ variant?: ButtonVariant; /** Size preset (default: "md") */ size?: ButtonSize; /** Whether the button should occupy full width */ fullWidth?: boolean; /** Button label; falls back to the item name when omitted */ children?: default_2.ReactNode; /** Whether to show the token price next to the label (default: true) */ showPrice?: boolean; /** Whether to show a cart icon (default: false) */ showIcon?: boolean; /** * Whether to show a "Privy 1" badge when the item requires Privy * verification (default: true). */ showPrivyBadge?: boolean; /** Called with the purchase result on success */ onSuccess?: (result: PurchaseResult) => void; /** Called with the error on failure */ onError?: (error: PurchaseError) => void; /** * Render prop for full customisation. * When provided, the default button is not rendered. */ render?: (props: GWPurchaseButtonRenderProps) => default_2.ReactNode; } /** * Render prop payload passed to the children function. */ export declare interface GWPurchaseButtonRenderProps { /** Execute the purchase */ purchase: () => Promise; /** Whether a purchase is in flight */ isPurchasing: boolean; /** Whether the purchase can proceed */ canPurchase: boolean; /** Whether the user has insufficient balance */ insufficientFunds: boolean; /** * Whether the item requires Privy verification the user has not yet * completed. When true, show an upgrade prompt rather than a generic error. */ privyRequired: boolean; /** Privy-specific error detail when privyRequired is true, else null */ privyError: PrivyRequiredError | null; /** Token cost for the item */ price: number | undefined; /** Any error from the last purchase */ error: PurchaseError | null; /** Whether this item requires Privy verification (badge indicator) */ requiresPrivy: boolean; } /** * Theme overrides for GWPurchaseButton. */ export declare interface GWPurchaseButtonTheme { /** Background colour for the default (idle) state */ backgroundColor?: string; /** Text colour */ color?: string; /** Border radius */ borderRadius?: string; } /** * Error detail returned when a purchase is blocked by an insufficient Privy level. * Only `requiredLevel` is exposed to the publisher; raw eligibility data is NOT forwarded. */ export declare interface PrivyRequiredError { /** Always 'insufficient_privy_level' */ code: "insufficient_privy_level"; /** Human-readable message */ message: string; /** Current Privy level of the user (e.g. 0) */ currentLevel: number; /** Minimum Privy level required to purchase (e.g. 1) */ requiredLevel: number; } /** * Purchase state constants. * Use these to handle distinct purchase outcomes in your UI. * * - INSUFFICIENT_FUNDS: user's token balance is too low * - PRIVY_REQUIRED: item requires Privy 1 verification; surface upgrade flow */ export declare const PURCHASE_STATE: { readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS"; readonly PRIVY_REQUIRED: "PRIVY_REQUIRED"; }; /** * Error detail returned when a purchase fails. */ export declare interface PurchaseError { /** Machine-readable error code */ code: PurchaseErrorCode; /** Human-readable message */ message: string; /** Item ID that the purchase failed for */ itemId: string; /** Current balance (present for insufficient_balance errors) */ currentBalance?: number; /** Item cost (present for insufficient_balance errors) */ itemCost?: number; } /** * In-Session Purchase Types for Marketplace SDK * * Types for the purchase API endpoints within an active session. * All purchase operations require a valid session JWT. * * Per PRP-044: In-Session Purchases */ /** * Discriminated union of all purchase error codes */ export declare type PurchaseErrorCode = "insufficient_balance" | "price_changed" | "session_expired" | "item_not_found" | "item_inactive" | "self_purchase_blocked" | "duplicate_purchase" | "rate_limited" | "validation_failed" | "insufficient_privy_level"; /** * Request body for creating an in-session purchase. */ export declare interface PurchaseRequest { /** ID of the item to purchase */ itemId: string; /** Number of units to purchase (default 1, range 1–1000) */ quantity?: number; /** Client-generated UUIDv4 for idempotency */ idempotencyKey: string; /** Expected unit price (in tokens) — rejects if server price has changed */ expectedUnitPrice: number; } /** * Successful purchase confirmation returned by the API. */ export declare interface PurchaseResult { /** Unique purchase identifier */ purchaseId: string; /** Item that was purchased */ itemId: string; /** Item display name at purchase time */ itemName: string; /** Number of units purchased */ quantity: number; /** Total tokens deducted (quantity × unit price) */ totalTokenCost: number; /** Organization token balance after the deduction */ remainingBalance: number; /** ISO 8601 timestamp of purchase */ purchasedAt: string; /** Always 'completed' on success */ status: "completed"; } export declare type PurchaseState = (typeof PURCHASE_STATE)[keyof typeof PURCHASE_STATE]; /** * A purchase record from the session's purchase history. */ export declare interface SessionPurchase { /** Unique purchase identifier */ purchaseId: string; /** Session in which the purchase was made */ sessionId: string; /** Item that was purchased */ itemId: string; /** Item display name at purchase time (denormalized snapshot) */ itemName: string; /** Item description at purchase time (denormalized snapshot) */ itemDescription: string; /** Number of units purchased */ quantity: number; /** Token cost per unit at purchase time */ unitPrice: number; /** Total tokens charged (quantity × unitPrice) */ totalTokens: number; /** Purchase outcome */ status: "completed" | "failed"; /** ISO 8601 timestamp of purchase */ createdAt: string; } /** * React hook for subscribing to the user's SMART token balance. * * Uses MarketplaceSDK.getInstance() to retrieve the SDK instance and * calls the balance API endpoint. Supports automatic polling and * focus-based refetching. * * @param options - Optional configuration for refetch behaviour. * * @example * ```tsx * function BalanceWidget() { * const { formattedBalance, isLoading, refetch } = useGWBalance({ refetchOnFocus: true }); * return {isLoading ? 'Loading...' : formattedBalance}; * } * ``` */ export declare function useGWBalance(options?: UseGWBalanceOptions): UseGWBalanceResult; /** * Options for configuring the useGWBalance hook. */ export declare interface UseGWBalanceOptions { /** * Interval in milliseconds at which to automatically refetch the balance. * When not set (or set to 0), automatic refetching is disabled. */ refetchInterval?: number; /** * Whether to refetch balance when the window regains focus. * Defaults to true. */ refetchOnFocus?: boolean; } /** * Result returned by the useGWBalance hook. */ export declare interface UseGWBalanceResult { /** Current token balance, or null if not yet loaded */ balance: number | null; /** Whether a fetch is currently in progress */ isLoading: boolean; /** Whether the cached balance may be outdated */ isStale: boolean; /** Any error encountered during fetch, or null */ error: Error | null; /** Manually trigger a balance refresh */ refetch: () => void; /** Timestamp of the last successful fetch, or null */ lastUpdated: Date | null; /** Formatted balance string, e.g. "27 tokens" */ formattedBalance: string; } /** * React hook for fetching the list of purchasable session items. * * Uses MarketplaceSDK.getInstance() to retrieve the SDK instance and * calls the session items endpoint. Supports automatic polling. * * @param options - Optional configuration for refetch behaviour. * * @example * ```tsx * function ItemList() { * const { items, isLoading, error } = useGWItems(); * if (isLoading) return

Loading items\u2026

; * if (error) return

Error: {error.message}

; * return ; * } * ``` */ export declare function useGWItems(options?: UseGWItemsOptions): UseGWItemsResult; /** * Options for configuring the useGWItems hook. */ export declare interface UseGWItemsOptions { /** * Interval in milliseconds at which to automatically refetch the item list. * When not set (or set to 0), automatic refetching is disabled. */ refetchInterval?: number; } /** * Result returned by the useGWItems hook. */ export declare interface UseGWItemsResult { /** List of available marketplace items */ items: ApplicationItem[]; /** Whether a fetch is currently in progress */ isLoading: boolean; /** Any error encountered during fetch, or null */ error: Error | null; /** Manually trigger a refetch of the item list */ refetch: () => void; /** Look up a single item by its ID from the current item list */ getItem: (id: string) => ApplicationItem | undefined; /** * Filter items by status. * Passing "active" returns only purchasable items; "inactive" returns * unavailable items. Defaults to filtering by the provided value. */ getItemsByType: (status: ApplicationItem["status"]) => ApplicationItem[]; } /** * React hook for executing and validating marketplace purchases. * * Uses MarketplaceSDK.getInstance() to retrieve the SDK instance and * delegates to the purchase API. Works with React 18 concurrent features — * state updates are batched automatically. * * @example * ```tsx * function BuyButton({ itemId }: { itemId: string }) { * const { purchase, isPurchasing, error, clearError } = useGWPurchase(); * * const handleBuy = async () => { * clearError(); * try { * const result = await purchase({ itemId, idempotencyKey: crypto.randomUUID(), expectedUnitPrice: item.userTokenCost }); * console.log('Purchased! Remaining:', result.remainingBalance); * } catch { * // error state is already set by the hook * } * }; * * return ( * <> * * {error &&

{error.message}

} * * ); * } * ``` */ export declare function useGWPurchase(): UseGWPurchaseResult; /** * Result returned by the useGWPurchase hook. */ export declare interface UseGWPurchaseResult { /** * Execute a purchase for an item. * Resolves with the purchase result or rejects with a PurchaseError. */ purchase: (request: PurchaseRequest) => Promise; /** * Validate whether a purchase is possible without committing it. * Resolves with a ValidationResult indicating balance sufficiency. */ validate: (itemId: string, quantity?: number) => Promise; /** Whether a purchase is currently in flight */ isPurchasing: boolean; /** The result of the most recent successful purchase, or null */ lastPurchase: PurchaseResult | null; /** Any purchase-specific error from the last operation, or null */ error: PurchaseError | null; /** Clear the current error state */ clearError: () => void; } /** * Combined convenience hook that aggregates balance, items, and purchase * state into a single object. * * @example * ```tsx * function StorePage() { * const { balance, items, isLoading, purchase, canPurchase } = useGWStore(); * if (isLoading) return

Loading\u2026

; * return ( *
    * {items.map(item => ( *
  • * {item.name} \u2014 {item.userTokenCost} tokens * *
  • * ))} *
* ); * } * ``` */ export declare function useGWStore(options?: UseGWStoreOptions): UseGWStoreResult; /** * Options for the useGWStore convenience hook. */ export declare interface UseGWStoreOptions { /** Balance polling/refetch options */ balance?: UseGWBalanceOptions; /** Items polling options */ items?: UseGWItemsOptions; } /** * Combined result of the useGWStore hook. */ export declare interface UseGWStoreResult { /** Current SMART token balance, or null if not yet loaded */ balance: number | null; /** Formatted balance string, e.g. "27 tokens" */ formattedBalance: string; /** List of available marketplace items */ items: ApplicationItem[]; /** Whether any data is currently loading */ isLoading: boolean; /** Any error from balance or items fetches, or null */ error: Error | null; /** Execute a purchase for an item */ purchase: (request: PurchaseRequest) => Promise; /** Whether a purchase is currently in flight */ isPurchasing: boolean; /** * Whether the user can afford to purchase the given item. * Returns false when balance or item cost is unknown. */ canPurchase: (itemId: string, quantity?: number) => boolean; } /** * Headless hook for driving a purchase button for a specific item. * * Fetches the item and current balance, derives canPurchase / insufficientFunds * / privyRequired, and exposes a zero-argument purchase() function bound to * the given itemId. * * @param itemId - ID of the marketplace item to purchase. * @param quantity - Number of units to purchase (default: 1). * * @example * ```tsx * function BuyButton({ itemId }: { itemId: string }) { * const { * item, canPurchase, insufficientFunds, privyRequired, * purchase, isPurchasing, error, privyError, * } = usePurchaseButton(itemId); * * return ( * <> * * {insufficientFunds &&

Not enough tokens

} * {privyRequired &&

Privy {privyError?.requiredLevel} required

} * {error && !privyRequired &&

{error.message}

} * * ); * } * ``` */ export declare function usePurchaseButton(itemId: string, quantity?: number): UsePurchaseButtonResult; /** * Result returned by the usePurchaseButton hook. */ export declare interface UsePurchaseButtonResult { /** The marketplace item for the given itemId, or undefined if not loaded */ item: ApplicationItem | undefined; /** Current token balance, or null if not loaded */ balance: number | null; /** * Whether the purchase can proceed (item exists, is active, balance is * sufficient, and no Privy gate blocks it). */ canPurchase: boolean; /** Whether the user has insufficient funds to complete the purchase */ insufficientFunds: boolean; /** * Whether the item requires Privy verification that the user has not yet * completed. When true, show a Privy upgrade prompt rather than a * generic error. */ privyRequired: boolean; /** Execute the purchase for the configured item */ purchase: () => Promise; /** Whether a purchase is currently in flight */ isPurchasing: boolean; /** Any error from the last purchase attempt, or null */ error: PurchaseError | null; /** * Privy-specific error detail when the last purchase failed due to an * insufficient Privy level. Null in all other cases. */ privyError: PrivyRequiredError | null; } /** * Pre-flight validation result for a proposed purchase. * Use validatePurchase() before showing a confirm UI to surface issues early. */ export declare interface ValidationResult { /** Whether the purchase would succeed at this moment */ canPurchase: boolean; /** Human-readable reason when canPurchase is false */ reason?: string; /** Current organization token balance */ currentBalance: number; /** Token cost of the item */ itemCost: number; /** True when session has less than 2 minutes remaining */ nearExpiry?: boolean; } export { }