autumn-js
Version:
Autumn JS Library
157 lines (150 loc) • 8.33 kB
TypeScript
import { AttachParams, AttachResult, UsageParams, UsageResult, CancelParams, CancelResult, CheckParams, CheckResult, TrackParams, TrackResult } from './general.js';
export { AttachFeatureOptions, EntitledBalance } from './general.js';
import { Product, CreateProductParams, ListProductsParams } from './products.js';
export { FreeTrial, PriceTier, ProductItem } from './products.js';
import { G as GetCustomerParams, C as Customer, a as CreateCustomerParams, U as UpdateCustomerParams, B as BillingPortalParams, b as BillingPortalResponse } from './cusTypes-BTV6ui4e.js';
export { e as CustomerData, g as CustomerExpandOption, c as CustomerFeature, f as CustomerInvoice, d as CustomerProduct, P as ProductStatus } from './cusTypes-BTV6ui4e.js';
import { G as GetEntityParams, E as Entity, C as CreateEntityParams, a as CreateEntityResult, D as DeleteEntityResult } from './entTypes-BwLV9Jn4.js';
export { b as EntityData, c as EntityExpandOption } from './entTypes-BwLV9Jn4.js';
import { CreateReferralCodeParams, RedeemReferralCodeParams } from './referrals.js';
export { CreateReferralCodeResult, RedeemReferralCodeResult } from './referrals.js';
export { CheckFeatureFormattedPreview, CheckFeatureScenario, CheckProductFormattedPreview, CheckProductScenario } from './check.js';
export { A as AppEnv, F as FreeTrialDuration, I as Infinite, P as ProductItemInterval, b as ProductItemIntervalType, U as UsageModel, a as UsageModelType } from './prodEnums-C1lccCWI.js';
interface ErrorResponse {
message: string;
code: string;
}
declare class AutumnError extends Error {
readonly message: string;
readonly code: string;
constructor(response: ErrorResponse);
toString(): string;
toJSON(): {
message: string;
code: string;
};
}
type Success<T> = {
data: T;
error: null;
statusCode?: number;
};
type Failure<E> = {
data: null;
error: E;
statusCode?: number;
};
declare const toContainerResult: (response: Response) => Promise<Result<any, AutumnError>>;
type Result<T, E> = Success<T> | Failure<E>;
type AutumnPromise<T> = Promise<Result<T, AutumnError>>;
declare class Autumn {
private readonly secretKey;
private readonly publishableKey;
private level;
private headers;
private url;
constructor(options?: {
secretKey?: string;
publishableKey?: string;
url?: string;
version?: string;
headers?: Record<string, string>;
});
getLevel(): "secret" | "publishable";
get(path: string): Promise<Result<any, AutumnError>>;
post(path: string, body: any): Promise<Result<any, AutumnError>>;
delete(path: string): Promise<Result<any, AutumnError>>;
static customers: {
get: (id: string, params?: GetCustomerParams) => Promise<Result<Customer, AutumnError>>;
create: (params?: CreateCustomerParams) => Promise<Result<Customer, AutumnError>>;
update: (id: string, params: UpdateCustomerParams) => Promise<Result<Customer, AutumnError>>;
delete: (id: string) => Promise<Result<Customer, AutumnError>>;
billingPortal: (id: string, params?: BillingPortalParams) => Promise<Result<BillingPortalResponse, AutumnError>>;
};
static products: {
get: (id: string) => Promise<Result<Product, AutumnError>>;
create: (params?: CreateProductParams) => Promise<Result<Product, AutumnError>>;
list: (params?: ListProductsParams) => Promise<Result<Product[], AutumnError>>;
};
static entities: {
get: (customer_id: string, entity_id: string, params?: GetEntityParams) => Promise<Result<Entity, AutumnError>>;
create: (customer_id: string, params?: CreateEntityParams | CreateEntityParams[]) => Promise<Result<CreateEntityResult, AutumnError>>;
delete: (customer_id: string, entity_id: string) => Promise<Result<DeleteEntityResult, AutumnError>>;
};
static referrals: {
createCode: (params: CreateReferralCodeParams) => Promise<Result<any, AutumnError>>;
redeemCode: (params: RedeemReferralCodeParams) => Promise<Result<any, AutumnError>>;
};
customers: {
get: (id: string, params?: GetCustomerParams) => Promise<Result<Customer, AutumnError>>;
create: (params?: CreateCustomerParams) => Promise<Result<Customer, AutumnError>>;
update: (id: string, params: UpdateCustomerParams) => Promise<Result<Customer, AutumnError>>;
delete: (id: string) => Promise<Result<Customer, AutumnError>>;
billingPortal: (id: string, params?: BillingPortalParams) => Promise<Result<BillingPortalResponse, AutumnError>>;
};
products: {
get: (id: string) => Promise<Result<Product, AutumnError>>;
create: (params?: CreateProductParams) => Promise<Result<Product, AutumnError>>;
list: (params?: ListProductsParams) => Promise<Result<Product[], AutumnError>>;
};
entities: {
get: (customer_id: string, entity_id: string, params?: GetEntityParams) => Promise<Result<Entity, AutumnError>>;
create: (customer_id: string, params?: CreateEntityParams | CreateEntityParams[]) => Promise<Result<CreateEntityResult, AutumnError>>;
delete: (customer_id: string, entity_id: string) => Promise<Result<DeleteEntityResult, AutumnError>>;
};
referrals: {
createCode: (params: CreateReferralCodeParams) => Promise<Result<any, AutumnError>>;
redeemCode: (params: RedeemReferralCodeParams) => Promise<Result<any, AutumnError>>;
};
static attach: (params: AttachParams) => Promise<Result<AttachResult, AutumnError>>;
static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
attach(params: AttachParams): Promise<Result<AttachResult, AutumnError>>;
static cancel: (params: CancelParams) => Promise<Result<CancelResult, AutumnError>>;
cancel(params: CancelParams): Promise<Result<CancelResult, AutumnError>>;
/**
* @deprecated This method is deprecated and will be removed in a future version.
* Please use the new check() method instead.
*/
static entitled: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>;
/**
* @deprecated This method is deprecated and will be removed in a future version.
* Please use the new check() method instead.
*/
entitled(params: CheckParams): Promise<Result<CheckResult, AutumnError>>;
static check: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>;
check(params: CheckParams): Promise<Result<CheckResult, AutumnError>>;
/**
* @deprecated This method is deprecated and will be removed in a future version.
* Please use the new track() method instead.
*/
static event: (params: TrackParams) => Promise<Result<TrackResult, AutumnError>>;
/**
* @deprecated This method is deprecated and will be removed in a future version.
* Please use the new track() method instead.
*/
event(params: TrackParams): Promise<Result<TrackResult, AutumnError>>;
static track: (params: TrackParams) => Promise<Result<TrackResult, AutumnError>>;
track(params: TrackParams): Promise<Result<TrackResult, AutumnError>>;
usage(params: UsageParams): Promise<Result<UsageResult, AutumnError>>;
}
interface GetPricingTableParams {
customer_id?: string;
}
interface PricingTableProduct {
id: string;
name: string;
buttonText: string;
price: {
primaryText: string;
secondaryText?: string;
};
items: {
primaryText: string;
secondaryText?: string;
}[];
}
declare const fetchPricingTable: ({ instance, params, }: {
instance: Autumn;
params?: GetPricingTableParams;
}) => AutumnPromise<PricingTableProduct[]>;
export { AttachParams, AttachResult, Autumn, AutumnError, type AutumnPromise, BillingPortalParams, BillingPortalResponse, CancelParams, CancelResult, CheckParams, CheckResult, CreateCustomerParams, CreateEntityParams, CreateEntityResult, CreateProductParams, CreateReferralCodeParams, Customer, DeleteEntityResult, Entity, type ErrorResponse, GetCustomerParams, GetEntityParams, type GetPricingTableParams, ListProductsParams, type PricingTableProduct, Product, RedeemReferralCodeParams, TrackParams, TrackResult, UpdateCustomerParams, UsageParams, UsageResult, fetchPricingTable, toContainerResult };