UNPKG

autumn-js

Version:

Autumn JS Library

490 lines (480 loc) 17.4 kB
import { C as CustomerData, a as CheckFeatureResult, b as CheckProductResult, P as ProductItem, c as Product, G as GetCustomerParams, d as Customer, e as CreateCustomerParams, U as UpdateCustomerParams, B as BillingPortalParams, f as BillingPortalResult, g as CreateProductParams, L as ListProductsParams, h as CustomerProduct, i as CustomerFeature, j as CustomerInvoice } from './cusTypes-_GDUnrai.mjs'; import { z } from 'zod'; import { R as Result, A as AutumnError } from './response-eH4S4sg0.mjs'; declare const CancelParamsSchema: z.ZodObject<{ customer_id: z.ZodString; product_id: z.ZodString; entity_id: z.ZodOptional<z.ZodString>; cancel_immediately: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { customer_id: string; product_id: string; entity_id?: string | undefined; cancel_immediately?: boolean | undefined; }, { customer_id: string; product_id: string; entity_id?: string | undefined; cancel_immediately?: boolean | undefined; }>; type CancelParams = z.infer<typeof CancelParamsSchema>; declare const TrackParamsSchema: z.ZodObject<{ customer_id: z.ZodString; value: z.ZodOptional<z.ZodNumber>; feature_id: z.ZodOptional<z.ZodString>; event_name: z.ZodOptional<z.ZodString>; entity_id: z.ZodOptional<z.ZodString>; customer_data: z.ZodOptional<z.ZodAny>; idempotency_key: z.ZodOptional<z.ZodString>; entity_data: z.ZodOptional<z.ZodAny>; }, "strip", z.ZodTypeAny, { customer_id: string; value?: number | undefined; feature_id?: string | undefined; entity_id?: string | undefined; customer_data?: any; entity_data?: any; event_name?: string | undefined; idempotency_key?: string | undefined; }, { customer_id: string; value?: number | undefined; feature_id?: string | undefined; entity_id?: string | undefined; customer_data?: any; entity_data?: any; event_name?: string | undefined; idempotency_key?: string | undefined; }>; type TrackParams = z.infer<typeof TrackParamsSchema>; declare const CheckParamsSchema: z.ZodObject<{ customer_id: z.ZodString; feature_id: z.ZodOptional<z.ZodString>; product_id: z.ZodOptional<z.ZodString>; entity_id: z.ZodOptional<z.ZodString>; customer_data: z.ZodOptional<z.ZodAny>; required_balance: z.ZodOptional<z.ZodNumber>; send_event: z.ZodOptional<z.ZodBoolean>; with_preview: z.ZodOptional<z.ZodBoolean>; entity_data: z.ZodOptional<z.ZodObject<{ name: z.ZodOptional<z.ZodString>; feature_id: z.ZodString; }, "strip", z.ZodTypeAny, { feature_id: string; name?: string | undefined; }, { feature_id: string; name?: string | undefined; }>>; }, "strip", z.ZodTypeAny, { customer_id: string; feature_id?: string | undefined; entity_id?: string | undefined; required_balance?: number | undefined; product_id?: string | undefined; customer_data?: any; entity_data?: { feature_id: string; name?: string | undefined; } | undefined; send_event?: boolean | undefined; with_preview?: boolean | undefined; }, { customer_id: string; feature_id?: string | undefined; entity_id?: string | undefined; required_balance?: number | undefined; product_id?: string | undefined; customer_data?: any; entity_data?: { feature_id: string; name?: string | undefined; } | undefined; send_event?: boolean | undefined; with_preview?: boolean | undefined; }>; type CheckParams = z.infer<typeof CheckParamsSchema>; type CheckResult = CheckFeatureResult & CheckProductResult; interface UsageParams { customer_id: string; feature_id: string; value: number; customer_data?: CustomerData; } interface UsageResult { code: string; customer_id: string; feature_id: string; } interface SetupPaymentParams { customer_id: string; success_url?: string; checkout_session_params?: Record<string, any>; } interface SetupPaymentResult { customer_id: string; url: string; } declare const AttachFeatureOptionsSchema: z.ZodObject<{ feature_id: z.ZodString; quantity: z.ZodNumber; }, "strip", z.ZodTypeAny, { feature_id: string; quantity: number; }, { feature_id: string; quantity: number; }>; type AttachFeatureOptions = z.infer<typeof AttachFeatureOptionsSchema>; declare const AttachParamsSchema: z.ZodObject<{ customer_id: z.ZodString; product_id: z.ZodOptional<z.ZodString>; entity_id: z.ZodOptional<z.ZodString>; options: z.ZodOptional<z.ZodArray<z.ZodObject<{ feature_id: z.ZodString; quantity: z.ZodNumber; }, "strip", z.ZodTypeAny, { feature_id: string; quantity: number; }, { feature_id: string; quantity: number; }>, "many">>; product_ids: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; free_trial: z.ZodOptional<z.ZodBoolean>; success_url: z.ZodOptional<z.ZodString>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; force_checkout: z.ZodOptional<z.ZodBoolean>; customer_data: z.ZodOptional<z.ZodObject<{ name: z.ZodOptional<z.ZodNullable<z.ZodString>>; email: z.ZodOptional<z.ZodNullable<z.ZodString>>; fingerprint: z.ZodOptional<z.ZodNullable<z.ZodString>>; }, "strip", z.ZodTypeAny, { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; }, { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; }>>; entity_data: z.ZodOptional<z.ZodAny>; checkout_session_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>; reward: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { customer_id: string; options?: { feature_id: string; quantity: number; }[] | undefined; entity_id?: string | undefined; metadata?: Record<string, string> | undefined; product_id?: string | undefined; product_ids?: string[] | undefined; free_trial?: boolean | undefined; success_url?: string | undefined; force_checkout?: boolean | undefined; customer_data?: { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; } | undefined; entity_data?: any; checkout_session_params?: Record<string, any> | undefined; reward?: string | undefined; }, { customer_id: string; options?: { feature_id: string; quantity: number; }[] | undefined; entity_id?: string | undefined; metadata?: Record<string, string> | undefined; product_id?: string | undefined; product_ids?: string[] | undefined; free_trial?: boolean | undefined; success_url?: string | undefined; force_checkout?: boolean | undefined; customer_data?: { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; } | undefined; entity_data?: any; checkout_session_params?: Record<string, any> | undefined; reward?: string | undefined; }>; type AttachParams = z.infer<typeof AttachParamsSchema>; declare const CheckoutParamsSchema: z.ZodObject<{ customer_id: z.ZodString; product_id: z.ZodString; entity_id: z.ZodOptional<z.ZodString>; success_url: z.ZodOptional<z.ZodString>; customer_data: z.ZodOptional<z.ZodObject<{ name: z.ZodOptional<z.ZodNullable<z.ZodString>>; email: z.ZodOptional<z.ZodNullable<z.ZodString>>; fingerprint: z.ZodOptional<z.ZodNullable<z.ZodString>>; }, "strip", z.ZodTypeAny, { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; }, { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; }>>; options: z.ZodOptional<z.ZodArray<z.ZodObject<{ feature_id: z.ZodString; quantity: z.ZodNumber; }, "strip", z.ZodTypeAny, { feature_id: string; quantity: number; }, { feature_id: string; quantity: number; }>, "many">>; }, "strip", z.ZodTypeAny, { customer_id: string; product_id: string; options?: { feature_id: string; quantity: number; }[] | undefined; entity_id?: string | undefined; success_url?: string | undefined; customer_data?: { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; } | undefined; }, { customer_id: string; product_id: string; options?: { feature_id: string; quantity: number; }[] | undefined; entity_id?: string | undefined; success_url?: string | undefined; customer_data?: { name?: string | null | undefined; email?: string | null | undefined; fingerprint?: string | null | undefined; } | undefined; }>; type CheckoutParams = z.infer<typeof CheckoutParamsSchema>; type CheckoutResult = { url?: string; customer_id: string; has_prorations: boolean; lines: { description: string; amount: number; item: ProductItem; }[]; total: number; currency: string; options: AttachFeatureOptions[]; product: Product; current_product: Product; next_cycle?: { starts_at: number; total: number; }; }; declare class Autumn { private readonly secretKey; private readonly publishableKey; private headers; private url; private logger; constructor(options?: { secretKey?: string; publishableKey?: string; url?: string; version?: string; headers?: Record<string, string>; logLevel?: string; }); 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<BillingPortalResult, AutumnError>>; }; static products: { get: (id: string) => Promise<Result<Product, AutumnError>>; create: (params?: CreateProductParams) => Promise<Result<Product, AutumnError>>; list: (params?: ListProductsParams) => Promise<Result<{ list: Product[]; }, AutumnError>>; }; static entities: { get: (customer_id: string, entity_id: string, params?: GetEntityParams$1) => Promise<Result<Entity, AutumnError>>; create: (customer_id: string, params?: CreateEntityParams$1 | CreateEntityParams$1[]) => 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<BillingPortalResult, AutumnError>>; }; products: { get: (id: string) => Promise<Result<Product, AutumnError>>; create: (params?: CreateProductParams) => Promise<Result<Product, AutumnError>>; list: (params?: ListProductsParams) => Promise<Result<{ list: Product[]; }, AutumnError>>; }; entities: { get: (customer_id: string, entity_id: string, params?: GetEntityParams$1) => Promise<Result<Entity, AutumnError>>; create: (customer_id: string, params?: CreateEntityParams$1 | CreateEntityParams$1[]) => 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 checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>; checkout(params: CheckoutParams): Promise<Result<CheckoutResult, AutumnError>>; static attach: (params: AttachParams) => Promise<Result<{ code: string; message: string; customer_id: string; product_ids: string[]; customer_data?: any; checkout_url?: string | undefined; }, AutumnError>>; static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>; attach(params: AttachParams): Promise<Result<{ code: string; message: string; customer_id: string; product_ids: string[]; customer_data?: any; checkout_url?: string | undefined; }, AutumnError>>; static setupPayment: (params: SetupPaymentParams) => Promise<Result<SetupPaymentResult, AutumnError>>; setupPayment(params: SetupPaymentParams): Promise<Result<SetupPaymentResult, AutumnError>>; static cancel: (params: CancelParams) => Promise<Result<{ customer_id: string; product_id: string; success: boolean; }, AutumnError>>; cancel(params: CancelParams): Promise<Result<{ customer_id: string; product_id: string; success: boolean; }, AutumnError>>; static check: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>; check(params: CheckParams): Promise<Result<CheckResult, AutumnError>>; static track: (params: TrackParams) => Promise<Result<{ code: string; customer_id: string; id: string; feature_id?: string | undefined; event_name?: string | undefined; }, AutumnError>>; track(params: TrackParams): Promise<Result<{ code: string; customer_id: string; id: string; feature_id?: string | undefined; event_name?: string | undefined; }, AutumnError>>; usage(params: UsageParams): Promise<Result<UsageResult, AutumnError>>; } type EntityExpandOption = "invoices"; interface CreateEntityParams$1 { id: string; name: string; feature_id: string; customer_data?: CustomerData; } interface CreateEntityResult { success: boolean; } interface DeleteEntityResult { success: boolean; } interface GetEntityParams$1 { expand?: EntityExpandOption[]; } interface Entity { id: string; name: string; customer_id: string; created_at: number; env: string; products: CustomerProduct[]; features: Record<string, CustomerFeature>; invoices?: CustomerInvoice[]; } declare const CreateReferralCodeParamsSchema: z.ZodObject<{ customer_id: z.ZodString; program_id: z.ZodString; }, "strip", z.ZodTypeAny, { customer_id: string; program_id: string; }, { customer_id: string; program_id: string; }>; type CreateReferralCodeParams = z.infer<typeof CreateReferralCodeParamsSchema>; declare const RedeemReferralCodeParamsSchema: z.ZodObject<{ code: z.ZodString; customer_id: z.ZodString; }, "strip", z.ZodTypeAny, { code: string; customer_id: string; }, { code: string; customer_id: string; }>; type RedeemReferralCodeParams = z.infer<typeof RedeemReferralCodeParamsSchema>; interface CreateEntityParams { id: string; name?: string; featureId: string; } interface GetEntityParams { expand?: string[]; } declare const createAutumnClient: (publishableKey?: string) => Autumn; declare const createCusAction: (args: Omit<{ customerId: string; customerData?: CustomerData; params?: CreateCustomerParams; }, "customerId"> & { encryptedCustomerId?: string; }, request?: Request) => Promise<any>; declare const getEntityAction: (args: Omit<{ customerId: string; entityId: string; params?: GetEntityParams; }, "customerId"> & { encryptedCustomerId?: string; }, request?: Request) => Promise<any>; declare const createEntityAction: (args: Omit<{ customerId: string; entity: CreateEntityParams | CreateEntityParams[]; }, "customerId"> & { encryptedCustomerId?: string; }, request?: Request) => Promise<any>; declare const deleteEntityAction: (args: Omit<{ customerId: string; entityId: string; }, "customerId"> & { encryptedCustomerId?: string; }, request?: Request) => Promise<any>; export { createAutumnClient, createCusAction, createEntityAction, deleteEntityAction, getEntityAction };