UNPKG

autumn-js

Version:

Autumn JS Library

173 lines (168 loc) 6.27 kB
import { CreateEntityParams, GetEntityParams } from './client/types/clientEntTypes.js'; import { OpenBillingPortalParams, SetupPaymentParams } from './client/types/clientGenTypes.js'; import { A as AutumnError } from './error-DHbclCVh.js'; import { R as Result, A as AutumnPromise, a as CheckResult, S as SetupPaymentResult } from './response-C7P_oYqV.js'; import { C as CheckoutResult } from './attachTypes-1Dbkyo_d.js'; import { h as ProductItem, k as ProductScenario, C as CustomerData, a as CreateCustomerParams, b as Customer, B as BillingPortalResult, P as Product } from './cusTypes-COIU0NG3.js'; import { E as Entity, D as DeleteEntityResult } from './entTypes-Ck3_WfOz.js'; interface PricingTableProduct { id: string; name: string; description?: string; button_text?: string; recommend_text?: string; everything_from?: string; price: { primary_text: string; secondary_text?: string; } & ProductItem; items: ({ primary_text: string; secondary_text?: string; } & ProductItem)[]; scenario: ProductScenario; } interface CreateReferralCodeResult { code: string; customer_id: string; created_at: number; } interface RedeemReferralCodeResult { id: string; customer_id: string; reward_id: string; applied: boolean; } interface ErrorResponse { message: string; code: string; } type OmitCustomerType = "id" | "name" | "email" | "fingerprint" | "customer_id"; interface AutumnClientConfig { backendUrl?: string; getBearerToken?: () => Promise<string | null | undefined>; customerData?: CustomerData; includeCredentials?: boolean; betterAuthUrl?: string; } declare class AutumnClient { readonly backendUrl?: string; protected readonly getBearerToken?: () => Promise<string | null | undefined>; protected readonly customerData?: CustomerData; protected includeCredentials?: boolean; readonly prefix: string; constructor({ backendUrl, getBearerToken, customerData, includeCredentials, betterAuthUrl, }: AutumnClientConfig); /** * Detects if the backend supports CORS credentials by making an OPTIONS request */ private detectCors; /** * Automatically determines whether to include credentials based on CORS detection */ private shouldIncludeCredentials; getHeaders(): Promise<any>; handleFetch({ path, method, body, }: { path: string; method: string; body?: any; }): Promise<Result<any, AutumnError>>; post(path: string, body: any): Promise<Result<any, AutumnError>>; get(path: string): Promise<Result<any, AutumnError>>; delete(path: string): Promise<Result<any, AutumnError>>; createCustomer(params: Omit<CreateCustomerParams, "id" | "data"> & { errorOnNotFound?: boolean; }): Promise<Result<Customer, AutumnError>>; getPricingTable(): Promise<Result<{ list: PricingTableProduct[]; }, AutumnError>>; attach: (params: { options?: { quantity: number; featureId: string; }[] | undefined; metadata?: Record<string, string> | undefined; reward?: string | undefined; productId?: string | undefined; entityId?: string | undefined; dialog?: any; entityData?: any; productIds?: string[] | undefined; freeTrial?: boolean | undefined; successUrl?: string | undefined; forceCheckout?: boolean | undefined; openInNewTab?: boolean | undefined; checkoutSessionParams?: Record<string, any> | undefined; }) => AutumnPromise<{ code: string; message: string; customer_id: string; product_ids: string[]; customer_data?: any; checkout_url?: string | undefined; }>; checkout: (params: { productId: string; options?: { quantity: number; featureId: string; }[] | undefined; entityId?: string | undefined; dialog?: any; successUrl?: string | undefined; openInNewTab?: boolean | undefined; }) => AutumnPromise<CheckoutResult>; cancel: (params: { productId: string; entityId?: string | undefined; cancelImmediately?: boolean | undefined; }) => AutumnPromise<{ customer_id: string; product_id: string; success: boolean; }>; check: (params: { productId?: string | undefined; entityId?: string | undefined; featureId?: string | undefined; requiredBalance?: number | undefined; sendEvent?: boolean | undefined; withPreview?: boolean | undefined; dialog?: any; entityData?: any; }) => AutumnPromise<CheckResult>; track: (params: { value?: number | undefined; entityId?: string | undefined; featureId?: string | undefined; entityData?: any; eventName?: string | undefined; idempotencyKey?: string | undefined; }) => AutumnPromise<{ id: string; code: string; customer_id: string; feature_id?: string | undefined; event_name?: string | undefined; }>; openBillingPortal: (params?: OpenBillingPortalParams | undefined) => AutumnPromise<BillingPortalResult>; setupPayment: (params: SetupPaymentParams) => AutumnPromise<SetupPaymentResult>; entities: { create: (params: CreateEntityParams | CreateEntityParams[]) => AutumnPromise<Entity | Entity[]>; get: (entityId: string, params?: GetEntityParams | undefined) => AutumnPromise<Entity>; delete: (entityId: string) => AutumnPromise<DeleteEntityResult>; }; referrals: { createCode: (params: { programId: string; }) => AutumnPromise<CreateReferralCodeResult>; redeemCode: (params: { code: string; }) => AutumnPromise<RedeemReferralCodeResult>; }; products: { list: () => AutumnPromise<{ list: Product[]; }>; }; } export { AutumnClient as A, type CreateReferralCodeResult as C, type ErrorResponse as E, type OmitCustomerType as O, type PricingTableProduct as P, type RedeemReferralCodeResult as R, type AutumnClientConfig as a };