/** * SvelteKit-specific Autumn client with SSR support. * * Extends the vanilla Svelte client with SvelteKit features. */ import type { AutumnConvexApi, Customer, Product, CheckParams, CheckResult, CheckoutParams, CheckoutResult, TrackParams, TrackResult, AttachParams, AttachResult, CancelParams, BillingPortalParams, BillingPortalResult, CreateEntityParams, GetEntityParams, SetupPaymentParams, SetupPaymentResult, CreateReferralCodeParams, CreateReferralCodeResult, RedeemReferralCodeParams, RedeemReferralCodeResult, SetUsageParams, SetUsageResult, QueryParams, QueryResult, EventListParams, EventListResult, EventAggregateParams, Entity, LocalCheckResult, RefetchOptions } from "../svelte/types.js"; /** * Server state for SSR hydration. */ export interface AutumnServerState { customer: Customer | null; _timeFetched: number; } /** * SvelteKit's invalidate function type. * * Import from '$app/navigation' in your consuming application and pass it to the client. */ export type InvalidateFunction = (url: string | URL) => Promise; /** * Create an Autumn client for SvelteKit with SSR support. * * @param params - Configuration options * @param params.convexApi - The Autumn Convex API object * @param params.getServerState - Optional function to retrieve server state * @param params.invalidate - Optional SvelteKit invalidate function for data refetching * @returns The Autumn client API with reactive state and methods */ export declare function createAutumnClientSvelteKit({ convexApi, getServerState, invalidate, }: { convexApi: AutumnConvexApi; getServerState?: () => AutumnServerState; invalidate?: InvalidateFunction; }): { readonly customer: Customer | null; allowed: (params: CheckParams) => LocalCheckResult; check: (params: CheckParams, options?: RefetchOptions) => Promise; checkout: (params: CheckoutParams, options?: RefetchOptions) => Promise; track: (params: TrackParams, options?: RefetchOptions) => Promise; attach: (params: AttachParams, options?: RefetchOptions) => Promise; cancel: (params: CancelParams, options?: RefetchOptions) => Promise; openBillingPortal: (params?: BillingPortalParams) => Promise; createEntity: (params: CreateEntityParams, options?: RefetchOptions) => Promise; getEntity: (params: GetEntityParams) => Promise; setupPayment: (params?: SetupPaymentParams, options?: RefetchOptions) => Promise; createReferralCode: (params: CreateReferralCodeParams, options?: RefetchOptions) => Promise; redeemReferralCode: (params: RedeemReferralCodeParams, options?: RefetchOptions) => Promise; listProducts: () => Promise; usage: (params: SetUsageParams) => Promise; query: (params: QueryParams) => Promise; listEvents: (params: EventListParams) => Promise; aggregateEvents: (params: EventAggregateParams) => Promise; refetch: () => Promise; }; /** * Set the Autumn client in the context. * * @param autumnClient - The Autumn client instance * @returns The Autumn client instance */ export declare function setAutumnContext(autumnClient: ReturnType): { readonly customer: Customer | null; allowed: (params: CheckParams) => LocalCheckResult; check: (params: CheckParams, options?: RefetchOptions) => Promise; checkout: (params: CheckoutParams, options?: RefetchOptions) => Promise; track: (params: TrackParams, options?: RefetchOptions) => Promise; attach: (params: AttachParams, options?: RefetchOptions) => Promise; cancel: (params: CancelParams, options?: RefetchOptions) => Promise; openBillingPortal: (params?: BillingPortalParams) => Promise; createEntity: (params: CreateEntityParams, options?: RefetchOptions) => Promise; getEntity: (params: GetEntityParams) => Promise; setupPayment: (params?: SetupPaymentParams, options?: RefetchOptions) => Promise; createReferralCode: (params: CreateReferralCodeParams, options?: RefetchOptions) => Promise; redeemReferralCode: (params: RedeemReferralCodeParams, options?: RefetchOptions) => Promise; listProducts: () => Promise; usage: (params: SetUsageParams) => Promise; query: (params: QueryParams) => Promise; listEvents: (params: EventListParams) => Promise; aggregateEvents: (params: EventAggregateParams) => Promise; refetch: () => Promise; }; /** * Get the Autumn client from the context. * * @returns The Autumn client instance from context */ export declare function getAutumnContext(): { readonly customer: Customer | null; allowed: (params: CheckParams) => LocalCheckResult; check: (params: CheckParams, options?: RefetchOptions) => Promise; checkout: (params: CheckoutParams, options?: RefetchOptions) => Promise; track: (params: TrackParams, options?: RefetchOptions) => Promise; attach: (params: AttachParams, options?: RefetchOptions) => Promise; cancel: (params: CancelParams, options?: RefetchOptions) => Promise; openBillingPortal: (params?: BillingPortalParams) => Promise; createEntity: (params: CreateEntityParams, options?: RefetchOptions) => Promise; getEntity: (params: GetEntityParams) => Promise; setupPayment: (params?: SetupPaymentParams, options?: RefetchOptions) => Promise; createReferralCode: (params: CreateReferralCodeParams, options?: RefetchOptions) => Promise; redeemReferralCode: (params: RedeemReferralCodeParams, options?: RefetchOptions) => Promise; listProducts: () => Promise; usage: (params: SetUsageParams) => Promise; query: (params: QueryParams) => Promise; listEvents: (params: EventListParams) => Promise; aggregateEvents: (params: EventAggregateParams) => Promise; refetch: () => Promise; }; /** * Check if Autumn has been set up. * * @returns True if the Autumn context exists */ export declare function hasAutumnContext(): boolean; /** * Creates reactive state for an Autumn operation with loading, error, and result tracking. * * This helper reduces boilerplate for managing loading states, error handling, and results * when calling Autumn billing operations. Perfect for operations triggered by user actions * like checkout, track, attach, etc. * * @template TParams - The parameters type for the operation * @template TResult - The result type returned by the operation * @param operation - The Autumn operation function to wrap (e.g., autumn.checkout) * @param defaultOptions - Default RefetchOptions to use for all executions * @returns Object with execute function and reactive state (isLoading, error, result, reset) * * @example * ```svelte * * * * * {#if upgrade.error} *

{upgrade.error.message}

* {/if} * ``` * * @example * ```svelte * * * {#if checkout.error} *
* {checkout.error.message} * *
* {/if} * * * ``` * * @example * ```svelte * * * ``` */ export declare function useAutumnOperation(operation: (params: TParams, options?: RefetchOptions) => Promise, defaultOptions?: RefetchOptions): { execute: (params: TParams, executeOptions?: RefetchOptions) => Promise; readonly isLoading: boolean; readonly error: Error | null; readonly result: TResult | null; reset: () => void; }; //# sourceMappingURL=client.svelte.d.ts.map