autumn-js
Version:
Autumn JS Library
286 lines (276 loc) • 8.42 kB
text/typescript
import * as react_jsx_runtime from 'react/jsx-runtime';
import { z } from 'zod';
declare const Infinite = "inf";
declare enum FreeTrialDuration {
Day = "day"
}
declare enum UsageModel {
Prepaid = "prepaid",
PayPerUse = "pay_per_use"
}
type UsageModelType = "prepaid" | "pay_per_use";
declare enum ProductItemInterval {
Minute = "minute",
Hour = "hour",
Day = "day",
Week = "week",
Month = "month",
Quarter = "quarter",
SemiAnnual = "semi_annual",
Year = "year",
Multiple = "multiple"
}
type ProductItemIntervalType = "minute" | "hour" | "day" | "week" | "month" | "quarter" | "semi_annual" | "year" | "multiple";
type CheckFeatureScenario = "usage_limit" | "feature_flag";
interface CheckFeatureResult extends CoreCustomerFeature {
allowed: boolean;
feature_id: string;
customer_id: string;
entity_id?: string;
required_balance: number;
code: string;
usage_limit?: number;
preview?: CheckFeaturePreview;
}
interface CheckFeaturePreview {
scenario: CheckFeatureScenario;
title: string;
message: string;
feature_id: string;
feature_name: string;
products: Product[];
}
type ProductScenario = "scheduled" | "active" | "new" | "renew" | "upgrade" | "downgrade" | "cancel";
interface CheckProductResult {
allowed: boolean;
customer_id: string;
product_id: string;
code: string;
status?: string;
preview?: CheckProductPreview;
}
interface CheckProductPreview {
scenario: ProductScenario;
product_id: string;
product_name: string;
recurring: boolean;
error_on_attach?: boolean;
next_cycle_at?: number;
current_product_name?: string;
items?: {
price: string;
description: string;
usage_model?: UsageModelType;
}[];
options?: {
feature_id: string;
feature_name: string;
billing_units: number;
price?: number;
tiers?: {
to: number | string;
amount: number;
}[];
}[];
due_today?: {
price: number;
currency: string;
};
due_next_cycle?: {
price: number;
currency: string;
};
}
declare enum AppEnv {
Sandbox = "sandbox",
Live = "live"
}
interface Feature {
id: string;
name: string;
type: "boolean" | "continuous_use" | "single_use" | "credit_system";
}
interface ProductItem {
type?: "feature" | "priced_feature" | "price";
feature_id?: string;
included_usage?: number | typeof Infinite;
interval?: ProductItemIntervalType;
feature?: Feature;
usage_model?: UsageModel;
price?: number;
billing_units?: number;
entity_feature_id?: string;
reset_usage_when_enabled?: boolean;
quantity?: number;
next_cycle_quantity?: number;
display?: {
primary_text?: string;
secondary_text?: string;
};
}
interface FreeTrial {
duration: FreeTrialDuration;
length: number;
unique_fingerprint: boolean;
trial_available?: boolean;
}
interface Product {
id: string;
created_at: number;
name: string;
env: AppEnv;
is_add_on: boolean;
is_default: boolean;
group: string;
version: number;
items: ProductItem[];
free_trial: FreeTrial | null;
scenario?: ProductScenario;
base_variant_id: string | null;
properties: {
is_free: boolean;
is_one_off: boolean;
interval_group: string;
has_trial: boolean;
updateable: boolean;
};
display?: {
name?: string;
description?: string;
button_text?: string;
recommend_text?: string;
everything_from?: string;
button_url?: string;
};
}
declare enum ProductStatus {
Active = "active",
Expired = "expired",
Trialing = "trialing",
Scheduled = "scheduled",
PastDue = "past_due"
}
type CustomerExpandOption = "invoices" | "rewards" | "trials_used" | "entities" | "referrals" | "payment_method";
interface CoreCustomerFeature {
unlimited?: boolean;
interval?: ProductItemInterval | null;
balance?: number;
usage?: number;
included_usage?: number;
next_reset_at?: number | null;
overage_allowed?: boolean;
usage_limit?: number;
breakdown?: {
interval: ProductItemInterval;
balance?: number;
usage?: number;
included_usage?: number;
next_reset_at?: number;
}[];
credit_schema?: {
feature_id: string;
credit_amount: number;
}[];
}
interface CustomerFeature extends CoreCustomerFeature {
id: string;
name: string;
type: "static" | "single_use" | "continuous_use";
}
interface CustomerProduct {
id: string;
name: string | null;
group: string | null;
status: ProductStatus;
started_at: number;
canceled_at: number | null;
version: number;
subscription_ids?: string[] | null;
current_period_start?: number | null;
current_period_end?: number | null;
trial_ends_at?: number;
entity_id?: string;
is_add_on: boolean;
is_default: boolean;
items: ProductItem[];
}
interface Customer {
id: string | null;
created_at: number;
name: string | null;
email: string | null;
fingerprint: string | null;
stripe_id: string | null;
env: AppEnv;
metadata: Record<string, any>;
products: CustomerProduct[];
features: Record<string, CustomerFeature>;
invoices?: CustomerInvoice[];
}
declare const CustomerDataSchema: 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;
}>;
type CustomerData = z.infer<typeof CustomerDataSchema>;
declare const CreateCustomerParamsSchema: z.ZodObject<{
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
fingerprint: z.ZodOptional<z.ZodNullable<z.ZodString>>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
expand: z.ZodOptional<z.ZodArray<z.ZodEnum<["invoices", "rewards", "trials_used", "entities", "referrals", "payment_method"]>, "many">>;
}, "strip", z.ZodTypeAny, {
name?: string | null | undefined;
email?: string | null | undefined;
fingerprint?: string | null | undefined;
id?: string | null | undefined;
metadata?: Record<string, any> | undefined;
expand?: ("invoices" | "rewards" | "trials_used" | "entities" | "referrals" | "payment_method")[] | undefined;
}, {
name?: string | null | undefined;
email?: string | null | undefined;
fingerprint?: string | null | undefined;
id?: string | null | undefined;
metadata?: Record<string, any> | undefined;
expand?: ("invoices" | "rewards" | "trials_used" | "entities" | "referrals" | "payment_method")[] | undefined;
}>;
type CreateCustomerParams = z.infer<typeof CreateCustomerParamsSchema>;
interface BillingPortalResult {
customer_id: string;
url: string;
}
interface CustomerInvoice {
product_ids: string[];
stripe_id: string;
status: string;
total: number;
currency: string;
created_at: number;
hosted_invoice_url: string;
}
interface AuthPluginOptions {
provider: "better-auth" | "supabase" | "clerk";
instance?: any;
useOrg?: boolean;
useUser?: boolean;
}
declare global {
var __autumnAuth: AuthPluginOptions;
}
interface AutumnProviderProps {
customerId?: string;
customerData?: CustomerData;
authPlugin?: AuthPluginOptions;
children?: React.ReactNode;
}
declare const AutumnProvider: ({ customerId, customerData, authPlugin, children, }: AutumnProviderProps) => react_jsx_runtime.JSX.Element;
export { AutumnProvider as A, type BillingPortalResult as B, type CheckFeatureResult as C, type ProductItem as P, type CheckProductResult as a, type Product as b, type ProductScenario as c, type CustomerProduct as d, type CustomerFeature as e, type CustomerInvoice as f, type CustomerData as g, type CreateCustomerParams as h, type Customer as i, type CustomerExpandOption as j };