autumn-js
Version:
Autumn JS Library
295 lines (287 loc) • 8.58 kB
TypeScript
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;
};
}
interface CreateProductParams {
id: string;
name?: string;
is_add_on?: boolean;
is_default?: boolean;
items?: ProductItem[];
free_trial?: FreeTrial;
}
interface ListProductsParams {
customer_id?: 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>;
interface GetCustomerParams {
expand?: CustomerExpandOption[];
}
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 UpdateCustomerParams {
id?: string | null;
name?: string | null;
email?: string | null;
fingerprint?: string | null;
}
declare const BillingPortalParamsSchema: z.ZodObject<{
return_url: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
return_url?: string | undefined;
}, {
return_url?: string | undefined;
}>;
type BillingPortalParams = z.infer<typeof BillingPortalParamsSchema>;
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;
}
export type { BillingPortalParams as B, CustomerData as C, GetCustomerParams as G, ListProductsParams as L, ProductItem as P, UpdateCustomerParams as U, CheckFeatureResult as a, CheckProductResult as b, Product as c, Customer as d, CreateCustomerParams as e, BillingPortalResult as f, CreateProductParams as g, CustomerProduct as h, CustomerFeature as i, CustomerInvoice as j };