UNPKG

autumn-js

Version:
89 lines (86 loc) 4.38 kB
import { A as AutumnError } from '../error-DHbclCVh.js'; import { a as CheckResult, T as TrackResult, C as CancelResult, S as SetupPaymentResult } from '../genTypes-CY6GNiAn.js'; import { A as AttachResult, C as CheckoutResult } from '../attachTypes-CKp1KMwX.js'; import { A as AutumnPromise, E as Entity, S as Success } from '../entTypes-n2T2wpRx.js'; import { c as CustomerExpandOption, b as Customer, B as BillingPortalResult } from '../cusTypes-D3QQXjif.js'; import { C as CreateReferralCodeResult, R as RedeemReferralCodeResult, A as AutumnClient } from '../ReactAutumnClient-DkAcY1X2.js'; import React__default from 'react'; import { SWRConfiguration } from 'swr'; import { AttachParams, CheckoutParams } from '../client/types/clientAttachTypes.js'; import { TrackParams, CancelParams, SetupPaymentParams, OpenBillingPortalParams, CheckParams } from '../client/types/clientGenTypes.js'; import { ConvexAutumnClient } from '../client/ConvexAutumnClient.js'; import { CreateEntityParams } from '../client/types/clientEntTypes.js'; import { CreateReferralCodeParams, RedeemReferralCodeParams } from '../client/types/clientReferralTypes.js'; import '../prodTypes-C4aZSZfO.js'; import 'zod/v4'; interface UseCustomerResult { /** The current customer data including subscription and feature information */ customer: Customer | 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<Customer | 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 { errorOnNotFound?: boolean; expand?: CustomerExpandOption[]; swrConfig?: SWRConfiguration; } declare const useCustomerBase: ({ params, AutumnContext, client, }: { params?: UseCustomerParams; AutumnContext?: React__default.Context<any>; client?: AutumnClient | ConvexAutumnClient; }) => UseCustomerResult; export { type UseCustomerParams, type UseCustomerResult, useCustomerBase };