UNPKG

autumn-js

Version:
88 lines (83 loc) 4.37 kB
import { b as CustomerExpandOption, c as ExpandedCustomer, B as BillingPortalResult, E as Entity } from '../cusTypes-CQtEzl50.mjs'; import { A as AttachParams, f as CheckResult, T as TrackParams, a as TrackResult, C as CancelParams, b as CancelResult, S as SetupPaymentParams, c as SetupPaymentResult, O as OpenBillingPortalParams, d as CheckoutParams, e as CheckParams } from '../clientAttachTypes-rRBh7kw-.mjs'; import { A as AttachResult, C as CheckoutResult, a as CreateEntityParams, b as CreateReferralCodeResult, R as RedeemReferralCodeResult } from '../clientEntTypes-jltPLNQ5.mjs'; import { A as AutumnPromise, S as Success } from '../response-DKQ_cb7U.mjs'; import { A as AutumnError } from '../error-DHbclCVh.mjs'; import { SWRConfiguration } from 'swr'; import { z } from 'zod/v4'; import '../prodTypes-G6W3NUPg.mjs'; declare const CreateReferralCodeParamsSchema: z.ZodObject<{ programId: z.ZodString; }, z.core.$strip>; type CreateReferralCodeParams = z.infer<typeof CreateReferralCodeParamsSchema>; declare const RedeemReferralCodeParamsSchema: z.ZodObject<{ code: z.ZodString; }, z.core.$strip>; type RedeemReferralCodeParams = z.infer<typeof RedeemReferralCodeParamsSchema>; interface UseCustomerResult<T extends readonly CustomerExpandOption[] = readonly []> { /** The current customer data including subscription and feature information */ customer: ExpandedCustomer<T> | null; /** Whether customer data is currently being loaded */ isLoading: boolean; /** Any error that occurred while fetching customer data */ error: AutumnError | null; /** * Attaches a product to the current customer, enabling access and handling billing. * Activates a product and applies all product items with automatic payment handling. */ attach: (params: AttachParams) => AutumnPromise<AttachResult | CheckResult>; /** * Tracks usage events for metered features. * Records feature usage and updates customer balances server-side. */ track: (params: TrackParams) => AutumnPromise<TrackResult>; /** * Cancels a customer's subscription or product attachment. * Can cancel immediately or at the end of the billing cycle. */ cancel: (params: CancelParams) => AutumnPromise<CancelResult>; /** * Sets up a payment method for the customer. * Collects payment information without immediately charging. */ setupPayment: (params?: SetupPaymentParams) => AutumnPromise<SetupPaymentResult>; /** * Opens the Stripe billing portal for the customer. * Allows customers to manage their subscription and payment methods. */ openBillingPortal: (params?: OpenBillingPortalParams) => AutumnPromise<BillingPortalResult>; /** * Initiates a checkout flow for product purchase. * Handles payment collection and redirects to Stripe checkout when needed. */ checkout: (params: CheckoutParams) => AutumnPromise<CheckoutResult>; /** Refetches the customer data from the server */ refetch: () => Promise<ExpandedCustomer<T> | null>; /** * Creates new entities for granular feature tracking. * Entities allow per-user or per-workspace feature limits. */ createEntity: (params: CreateEntityParams | CreateEntityParams[]) => AutumnPromise<Entity | Entity[]>; /** * Creates a referral code for the customer. * Generates codes that can be shared for referral programs. */ createReferralCode: (params: CreateReferralCodeParams) => AutumnPromise<CreateReferralCodeResult>; /** * Redeems a referral code for the customer. * Applies referral benefits when a valid code is provided. */ redeemReferralCode: (params: RedeemReferralCodeParams) => AutumnPromise<RedeemReferralCodeResult>; /** * Checks if a customer has access to a feature and shows paywalls if needed. * Client-side feature gating with optional dialog display for upgrades. */ check: (params: CheckParams) => Success<CheckResult>; } interface UseCustomerParams<T extends readonly CustomerExpandOption[] = readonly []> { errorOnNotFound?: boolean; expand?: T; swrConfig?: SWRConfiguration; } declare const useCustomer: <const T extends readonly CustomerExpandOption[] = readonly []>(params?: UseCustomerParams<T>) => UseCustomerResult<T>; export { useCustomer };