autumn-js
Version:
Autumn JS Library
185 lines (180 loc) • 7.21 kB
TypeScript
import { R as Result, b as AutumnPromise, C as CheckResult, O as OpenBillingPortalParams, S as SetupPaymentParams, f as SetupPaymentResult, A as AttachParams, d as CancelParams, e as CancelResult, a as CheckParams, T as TrackParams, c as TrackResult } from './clientAttachTypes-D0_L-cnv.js';
import { C as CheckoutResult, A as AttachResult } from './attachTypes-CJ7OSUSn.js';
import { P as ProductItem, f as ProductScenario, C as CustomerData, g as CreateCustomerParams, a as Customer, B as BillingPortalResult, b as Product } from './cusTypes-DT2ujoSl.js';
import { E as Entity, D as DeleteEntityResult } from './entTypes-C-7Uoct9.js';
import { C as CreateEntityParams, G as GetEntityParams, a as CreateReferralCodeResult, R as RedeemReferralCodeResult } from './clientEntTypes-BFkleT6a.js';
import { A as AutumnError } from './error-DHbclCVh.js';
import 'zod';
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 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?: {
featureId: string;
quantity: number;
}[] | undefined;
metadata?: Record<string, string> | undefined;
productId?: string | undefined;
entityId?: string | undefined;
productIds?: string[] | undefined;
freeTrial?: boolean | undefined;
successUrl?: string | undefined;
forceCheckout?: boolean | undefined;
dialog?: any;
entityData?: any;
openInNewTab?: boolean | undefined;
reward?: string | undefined;
checkoutSessionParams?: Record<string, any> | undefined;
}) => AutumnPromise<{
code: string;
message: string;
customer_id: string;
product_ids: string[];
checkout_url?: string | undefined;
customer_data?: any;
}>;
checkout: (params: {
productId: string;
options?: {
featureId: string;
quantity: number;
}[] | undefined;
entityId?: string | undefined;
successUrl?: string | undefined;
dialog?: any;
openInNewTab?: boolean | undefined;
}) => AutumnPromise<CheckoutResult>;
cancel: (params: {
productId: string;
entityId?: string | undefined;
cancelImmediately?: boolean | undefined;
}) => AutumnPromise<{
customer_id: string;
success: boolean;
product_id: string;
}>;
check: (params: {
productId?: string | undefined;
entityId?: string | undefined;
featureId?: string | undefined;
dialog?: any;
entityData?: any;
requiredBalance?: number | undefined;
sendEvent?: boolean | undefined;
withPreview?: boolean | undefined;
}) => AutumnPromise<CheckResult>;
track: (params: {
value?: number | undefined;
entityId?: string | undefined;
featureId?: string | undefined;
entityData?: any;
eventName?: string | undefined;
idempotencyKey?: string | undefined;
}) => AutumnPromise<{
code: string;
id: 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[];
}>;
};
}
interface ErrorResponse {
message: string;
code: string;
}
type OmitCustomerType = "id" | "name" | "email" | "fingerprint" | "customer_id";
interface NextAutumnClientConfig {
encryptedCustomerId?: string;
customerData?: CustomerData;
}
declare class NextAutumnClient extends AutumnClient {
private readonly encryptedCustomerId?;
constructor({ encryptedCustomerId, customerData }: NextAutumnClientConfig);
createCustomer(params: Omit<CreateCustomerParams, "id" | "data"> & {
errorOnNotFound?: boolean;
}): Promise<any>;
getPricingTable(): Promise<any>;
attach: (params: AttachParams) => AutumnPromise<AttachResult>;
cancel: (params: CancelParams) => AutumnPromise<CancelResult>;
check: (params: CheckParams) => AutumnPromise<CheckResult>;
track: (params: TrackParams) => AutumnPromise<TrackResult>;
openBillingPortal: (params?: OpenBillingPortalParams | undefined) => Promise<any>;
entities: {
create: (params: CreateEntityParams | CreateEntityParams[]) => AutumnPromise<Entity | Entity[]>;
get: (entityId: string, params?: GetEntityParams) => AutumnPromise<Entity>;
delete: (entityId: string) => AutumnPromise<DeleteEntityResult>;
};
referrals: any;
}
export { type ErrorResponse, NextAutumnClient, type NextAutumnClientConfig, type OmitCustomerType };