UNPKG

autumn-js

Version:
90 lines (87 loc) 4.63 kB
import { a as CheckResult, T as TrackResult, C as CancelResult, S as SetupPaymentResult } from '../genTypes-DT5O0rCP.mjs'; import { A as AttachResult, C as CheckoutResult } from '../attachTypes-BNlJ6XXa.mjs'; import { a as AutumnPromise, C as CreateReferralCodeResult, R as RedeemReferralCodeResult, S as Success, A as AutumnClient } from '../ReactAutumnClient-C66sT2jI.mjs'; import { A as AutumnError } from '../error-DHbclCVh.mjs'; import { a as CustomerExpandOption, E as ExpandedCustomer, B as BillingPortalResult, c as Entity } from '../cusTypes-yC81DC2o.mjs'; import React__default from 'react'; import { SWRConfiguration } from 'swr'; import { ConvexAutumnClient } from '../client/ConvexAutumnClient.mjs'; import { AttachParams, CheckoutParams } from '../client/types/clientAttachTypes.mjs'; import { CreateEntityParams } from '../client/types/clientEntTypes.mjs'; import { TrackParams, CancelParams, SetupPaymentParams, OpenBillingPortalParams, CheckParams } from '../client/types/clientGenTypes.mjs'; import { CreateReferralCodeParams, RedeemReferralCodeParams } from '../client/types/clientReferralTypes.mjs'; import '../prodTypes-C4aZSZfO.mjs'; import 'zod/v4'; import '../eventTypes-5iJYcv30.mjs'; import '../client/types/clientAnalyticsTypes.mjs'; 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 useCustomerBase: <const T extends readonly CustomerExpandOption[] = readonly []>({ params, AutumnContext, client, }: { params?: UseCustomerParams<T>; AutumnContext?: React__default.Context<any>; client?: AutumnClient | ConvexAutumnClient; }) => UseCustomerResult<T>; export { type UseCustomerParams, type UseCustomerResult, useCustomerBase };