autumn-js
Version:
Autumn JS Library
124 lines (118 loc) • 3.17 kB
TypeScript
import { A as AppEnv, I as Infinite, P as ProductItemIntervalType, U as UsageModel, F as FreeTrialDuration, g as UsageModelType, C as CustomerData } from './cusTypes-Cf-s9PYP.js';
import { A as AutumnError } from './error-CG2LXoa7.js';
interface ProductItem {
feature_id?: string;
included_usage?: number | typeof Infinite;
interval?: ProductItemIntervalType;
usage_model?: UsageModel;
price?: number;
billing_units?: number;
entity_feature_id?: string;
reset_usage_on_billing?: boolean;
reset_usage_when_enabled?: boolean;
}
interface FreeTrial {
duration: FreeTrialDuration;
length: number;
unique_fingerprint: boolean;
}
interface Product {
autumn_id: string;
created_at: number;
id: string;
name: string;
env: AppEnv;
is_add_on: boolean;
is_default: boolean;
group: string;
version: number;
items: ProductItem[];
free_trial: FreeTrial | null;
}
type CheckFeatureScenario = "usage_limit" | "feature_flag";
interface CheckFeatureFormattedPreview {
scenario: CheckFeatureScenario;
title: string;
message: string;
feature_id: string;
feature_name: string;
products: Product[];
}
type CheckProductScenario = "scheduled" | "active" | "new" | "renew" | "upgrade" | "downgrade" | "cancel";
interface CheckProductFormattedPreview {
scenario: CheckProductScenario;
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;
};
}
interface CancelResult {
success: boolean;
customer_id: string;
product_id: string;
}
interface AttachResult {
checkout_url?: string;
customer_id: string;
product_ids: string[];
code: string;
message: string;
customer_data?: CustomerData;
}
interface TrackResult {
id: string;
code: string;
customer_id: string;
feature_id?: string;
event_name?: string;
}
interface CheckResult {
customer_id: string;
allowed: boolean;
code: string;
feature_id?: string;
required_balance?: number;
unlimited?: boolean;
balance?: number | null;
product_id?: string;
status?: string;
preview?: CheckProductFormattedPreview | CheckFeatureFormattedPreview;
}
type Success<T> = {
data: T;
error: null;
statusCode?: number;
};
type Failure<E> = {
data: null;
error: E;
statusCode?: number;
};
type Result<T, E> = Success<T> | Failure<E>;
type AutumnPromise<T> = Promise<Result<T, AutumnError>>;
export type { AutumnPromise as A, CancelResult as C, Result as R, TrackResult as T, AttachResult as a, CheckResult as b };