@buildbase/sdk 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +4 -5
- package/dist/index.js +4 -5
- package/dist/saas-os.css +1 -1
- package/package.json +3 -2
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/api/currency-utils.d.ts +0 -44
- package/dist/types/api/index.d.ts +0 -12
- package/dist/types/api/pricing-variant-utils.d.ts +0 -66
- package/dist/types/api/quota-utils.d.ts +0 -24
- package/dist/types/api/types.d.ts +0 -495
- package/dist/types/components/ErrorBoundary.d.ts +0 -81
- package/dist/types/components/beta/BetaForm.d.ts +0 -24
- package/dist/types/components/beta/api.d.ts +0 -48
- package/dist/types/components/beta/hooks.d.ts +0 -11
- package/dist/types/components/beta/schema.d.ts +0 -6
- package/dist/types/components/beta/types.d.ts +0 -8
- package/dist/types/components/dropdowns/country/countries.d.ts +0 -7
- package/dist/types/components/dropdowns/country/selectCountry.d.ts +0 -6
- package/dist/types/components/dropdowns/currency/currencies.d.ts +0 -6
- package/dist/types/components/dropdowns/currency/selectCurrency.d.ts +0 -6
- package/dist/types/components/dropdowns/language/languages.d.ts +0 -6
- package/dist/types/components/dropdowns/language/selectLanguage.d.ts +0 -6
- package/dist/types/components/dropdowns/timezone/selectTimeZone.d.ts +0 -6
- package/dist/types/components/dropdowns/timezone/timezones.d.ts +0 -8
- package/dist/types/components/features/index.d.ts +0 -130
- package/dist/types/components/pricing/PricingPage.d.ts +0 -49
- package/dist/types/components/pricing/index.d.ts +0 -2
- package/dist/types/components/quota/index.d.ts +0 -121
- package/dist/types/components/subscription/index.d.ts +0 -182
- package/dist/types/components/ui/alert-dialog.d.ts +0 -20
- package/dist/types/components/ui/avatar.d.ts +0 -6
- package/dist/types/components/ui/button.d.ts +0 -18
- package/dist/types/components/ui/command-select.d.ts +0 -13
- package/dist/types/components/ui/command.d.ts +0 -82
- package/dist/types/components/ui/dialog.d.ts +0 -19
- package/dist/types/components/ui/form.d.ts +0 -23
- package/dist/types/components/ui/input.d.ts +0 -5
- package/dist/types/components/ui/label.d.ts +0 -5
- package/dist/types/components/ui/popover.d.ts +0 -6
- package/dist/types/components/ui/radio-group.d.ts +0 -5
- package/dist/types/components/ui/scroll-area.d.ts +0 -5
- package/dist/types/components/ui/select.d.ts +0 -11
- package/dist/types/components/ui/separator.d.ts +0 -4
- package/dist/types/components/ui/skeleton.d.ts +0 -3
- package/dist/types/components/ui/switch.d.ts +0 -4
- package/dist/types/components/user/auth.d.ts +0 -76
- package/dist/types/components/user/role.d.ts +0 -84
- package/dist/types/contexts/AuthContext/AuthContext.d.ts +0 -9
- package/dist/types/contexts/AuthContext/actions.d.ts +0 -12
- package/dist/types/contexts/AuthContext/index.d.ts +0 -4
- package/dist/types/contexts/AuthContext/reducer.d.ts +0 -19
- package/dist/types/contexts/AuthContext/types.d.ts +0 -18
- package/dist/types/contexts/OSContext/OSContext.d.ts +0 -9
- package/dist/types/contexts/OSContext/actions.d.ts +0 -11
- package/dist/types/contexts/OSContext/index.d.ts +0 -4
- package/dist/types/contexts/OSContext/reducer.d.ts +0 -11
- package/dist/types/contexts/OSContext/types.d.ts +0 -16
- package/dist/types/contexts/QuotaUsageContext/QuotaUsageContext.d.ts +0 -22
- package/dist/types/contexts/QuotaUsageContext/index.d.ts +0 -2
- package/dist/types/contexts/QuotaUsageContext/quotaUsageInvalidation.d.ts +0 -21
- package/dist/types/contexts/QuotaUsageContext/types.d.ts +0 -14
- package/dist/types/contexts/SDKContext/SDKContextProvider.d.ts +0 -18
- package/dist/types/contexts/SDKContext/index.d.ts +0 -2
- package/dist/types/contexts/SDKContext/types.d.ts +0 -12
- package/dist/types/contexts/SubscriptionContext/SubscriptionContext.d.ts +0 -22
- package/dist/types/contexts/SubscriptionContext/index.d.ts +0 -2
- package/dist/types/contexts/SubscriptionContext/subscriptionInvalidation.d.ts +0 -21
- package/dist/types/contexts/SubscriptionContext/types.d.ts +0 -14
- package/dist/types/contexts/WorkspaceContext/WorkspaceContext.d.ts +0 -8
- package/dist/types/contexts/WorkspaceContext/actions.d.ts +0 -19
- package/dist/types/contexts/WorkspaceContext/index.d.ts +0 -4
- package/dist/types/contexts/WorkspaceContext/reducer.d.ts +0 -10
- package/dist/types/contexts/WorkspaceContext/types.d.ts +0 -52
- package/dist/types/contexts/index.d.ts +0 -14
- package/dist/types/contexts/shared/createContext.d.ts +0 -27
- package/dist/types/contexts/shared/types.d.ts +0 -21
- package/dist/types/contexts/shared/useAppDispatch.d.ts +0 -20
- package/dist/types/contexts/shared/useAppSelector.d.ts +0 -26
- package/dist/types/contexts/shared/useSelectWithEquality.d.ts +0 -10
- package/dist/types/contexts/shared/utils/reducerHelpers.d.ts +0 -11
- package/dist/types/contexts/shared/utils/storage.d.ts +0 -25
- package/dist/types/hooks/use-seat-status.d.ts +0 -42
- package/dist/types/hooks/use-trial-status.d.ts +0 -28
- package/dist/types/index.d.ts +0 -39
- package/dist/types/lib/api-base.d.ts +0 -49
- package/dist/types/lib/api-client.d.ts +0 -25
- package/dist/types/lib/api-utils.d.ts +0 -182
- package/dist/types/lib/error-handler.d.ts +0 -118
- package/dist/types/lib/logger.d.ts +0 -27
- package/dist/types/lib/useAsyncEffect.d.ts +0 -29
- package/dist/types/lib/utils.d.ts +0 -7
- package/dist/types/providers/ContextConfigProvider.d.ts +0 -15
- package/dist/types/providers/PortalContainer.d.ts +0 -9
- package/dist/types/providers/SaaSOSProvider.d.ts +0 -7
- package/dist/types/providers/auth/api.d.ts +0 -12
- package/dist/types/providers/auth/hooks.d.ts +0 -75
- package/dist/types/providers/auth/provider.d.ts +0 -13
- package/dist/types/providers/auth/types.d.ts +0 -62
- package/dist/types/providers/auth/utils.d.ts +0 -40
- package/dist/types/providers/constants.d.ts +0 -3
- package/dist/types/providers/events/EventEmitter.d.ts +0 -81
- package/dist/types/providers/events/index.d.ts +0 -2
- package/dist/types/providers/events/types.d.ts +0 -61
- package/dist/types/providers/os/api.d.ts +0 -11
- package/dist/types/providers/os/hooks.d.ts +0 -50
- package/dist/types/providers/os/types.d.ts +0 -19
- package/dist/types/providers/types.d.ts +0 -9
- package/dist/types/providers/user/api.d.ts +0 -16
- package/dist/types/providers/user/hooks.d.ts +0 -80
- package/dist/types/providers/user/provider.d.ts +0 -17
- package/dist/types/providers/workspace/WorkspaceSettingsProvider.d.ts +0 -9
- package/dist/types/providers/workspace/api.d.ts +0 -155
- package/dist/types/providers/workspace/hooks.d.ts +0 -161
- package/dist/types/providers/workspace/provider.d.ts +0 -8
- package/dist/types/providers/workspace/settings-manager.d.ts +0 -36
- package/dist/types/providers/workspace/subscription-hooks.d.ts +0 -741
- package/dist/types/providers/workspace/types.d.ts +0 -61
- package/dist/types/providers/workspace/ui/SettingsDanger.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsDialog.d.ts +0 -17
- package/dist/types/providers/workspace/ui/SettingsFeatures.d.ts +0 -5
- package/dist/types/providers/workspace/ui/SettingsGeneral.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsInvoices.d.ts +0 -12
- package/dist/types/providers/workspace/ui/SettingsProfile.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsSubscription.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsUsage.d.ts +0 -3
- package/dist/types/providers/workspace/ui/SettingsUsers.d.ts +0 -6
- package/dist/types/providers/workspace/ui/Sidebar.d.ts +0 -10
- package/dist/types/providers/workspace/ui/Skeleton.d.ts +0 -1
- package/dist/types/providers/workspace/ui/SubscriptionDialog.d.ts +0 -19
- package/dist/types/providers/workspace/ui/utils.d.ts +0 -2
- package/dist/types/providers/workspace/utils.d.ts +0 -28
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized formatting for subscription/quota display: cents, overage rates, included + overage text.
|
|
3
|
-
* Currency must be provided by the caller (e.g. workspace.billingCurrency, plan.currency, or selected currency).
|
|
4
|
-
*/
|
|
5
|
-
/** Common currency display (code or symbol). Use lowercase Stripe codes (usd, eur, etc.). */
|
|
6
|
-
export declare const CURRENCY_DISPLAY: Record<string, string>;
|
|
7
|
-
/** Currency code to flag emoji (country/region associated with the currency). Use for dropdowns. */
|
|
8
|
-
export declare const CURRENCY_FLAG: Record<string, string>;
|
|
9
|
-
/** Get flag emoji for a currency code. Returns empty string when unknown or empty. */
|
|
10
|
-
export declare function getCurrencyFlag(currency: string): string;
|
|
11
|
-
/** Get currency symbol for display. Use lowercase Stripe codes (usd, eur). Returns code when unknown; empty string when currency is empty. */
|
|
12
|
-
export declare function getCurrencySymbol(currency: string): string;
|
|
13
|
-
/** Allowed plan/pricing currency codes (must match server ALLOWED_BILLING_CURRENCIES). Use for dropdowns and validation. */
|
|
14
|
-
export declare const PLAN_CURRENCY_CODES: readonly ["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny", "hkd", "sgd", "inr", "mxn", "brl", "nzd", "sek", "nok", "dkk", "pln", "thb"];
|
|
15
|
-
/** Options for plan currency select: { value, label } with symbol. Use in CreateOrEditPlan and anywhere a currency dropdown is needed. */
|
|
16
|
-
export declare const PLAN_CURRENCY_OPTIONS: {
|
|
17
|
-
value: "usd" | "eur" | "gbp" | "jpy" | "cad" | "aud" | "chf" | "cny" | "hkd" | "sgd" | "inr" | "mxn" | "brl" | "nzd" | "sek" | "nok" | "dkk" | "pln" | "thb";
|
|
18
|
-
label: string;
|
|
19
|
-
}[];
|
|
20
|
-
/** Format cents as money string (e.g. 1999, "usd" -> "$19.99"). Caller must pass currency (e.g. from plan or workspace). */
|
|
21
|
-
export declare function formatCents(cents: number, currency: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Format overage rate for display. When unitSize > 1: "$1.00/1,000 units"; else "$1.00/unit".
|
|
24
|
-
* Returns null if overageCents is missing or negative.
|
|
25
|
-
*/
|
|
26
|
-
export declare function formatOverageRate(overageCents: number | undefined, unitSize: number | undefined, currency: string): string | null;
|
|
27
|
-
/**
|
|
28
|
-
* Format overage rate with optional unit label for comparison/preview UIs.
|
|
29
|
-
* e.g. formatOverageRateWithLabel(50, 1000, "video") -> "$0.50/1,000 videos"
|
|
30
|
-
* formatOverageRateWithLabel(46, 1, "video") -> "$0.46/video"
|
|
31
|
-
* When unitLabel is omitted, falls back to formatOverageRate behavior.
|
|
32
|
-
*/
|
|
33
|
-
export declare function formatOverageRateWithLabel(overageCents: number | undefined, unitSize: number | undefined, unitLabel: string | undefined, currency: string): string | null;
|
|
34
|
-
/**
|
|
35
|
-
* Get singular unit label from item name or slug (e.g. "Videos" -> "video", "reels" -> "reel").
|
|
36
|
-
* Used for quota display in comparison and preview.
|
|
37
|
-
*/
|
|
38
|
-
export declare function getQuotaUnitLabelFromName(nameOrSlug: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Format quota "included + overage" for display.
|
|
41
|
-
* When unitSize >= 2: "Included: 1,000, after that $1.00/1,000 emails".
|
|
42
|
-
* Otherwise: "Included: 5, after that $0.30/image".
|
|
43
|
-
*/
|
|
44
|
-
export declare function formatQuotaIncludedOverage(included: number | undefined, overageCents: number | undefined, unitLabel: string, currency: string, unitSize?: number): string;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type { IBetaConfig } from '../components/beta/api';
|
|
2
|
-
/** Central SDK APIs – all extend BaseApi for shared URL/auth/request handling. */
|
|
3
|
-
export { BaseApi } from '../lib/api-base';
|
|
4
|
-
export type { IBaseApiConfig } from '../lib/api-base';
|
|
5
|
-
export { SettingsApi } from '../providers/os/api';
|
|
6
|
-
export { UserApi } from '../providers/user/api';
|
|
7
|
-
export { WorkspaceApi } from '../providers/workspace/api';
|
|
8
|
-
/** Currency utilities */
|
|
9
|
-
export { CURRENCY_DISPLAY, CURRENCY_FLAG, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, getCurrencyFlag, getCurrencySymbol, getQuotaUnitLabelFromName, } from './currency-utils';
|
|
10
|
-
/** Pricing variant (multi-currency) utilities */
|
|
11
|
-
export { getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getDisplayCurrency, getPricingVariant, getQuotaDisplayWithVariant, getQuotaOverageCents, getStripePriceIdForInterval, } from './pricing-variant-utils';
|
|
12
|
-
export type { PlanVersionWithPricingVariants, QuotaDisplayWithOverage, } from './pricing-variant-utils';
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers for multi-currency plan version pricing (pricingVariants).
|
|
3
|
-
*/
|
|
4
|
-
import type { BillingInterval, IPlanVersion, IPlanVersionWithPlan, IPricingVariant } from './types';
|
|
5
|
-
/** Get the pricing variant for a currency, or null if not available. */
|
|
6
|
-
export declare function getPricingVariant(planVersion: IPlanVersion, currency: string): IPricingVariant | null;
|
|
7
|
-
/**
|
|
8
|
-
* Get base price in cents for a plan version and currency/interval.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getBasePriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
|
|
11
|
-
/**
|
|
12
|
-
* Get Stripe price ID for the given plan version, currency, and interval.
|
|
13
|
-
*/
|
|
14
|
-
export declare function getStripePriceIdForInterval(planVersion: IPlanVersion, currency: string, interval: BillingInterval): string | null;
|
|
15
|
-
/**
|
|
16
|
-
* Get overage amount in cents for a quota in a given currency and interval.
|
|
17
|
-
* Returns undefined if not defined in the pricing variant.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getQuotaOverageCents(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): number | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Get display currency for a plan version when using a given currency.
|
|
22
|
-
* Returns the requested currency if the variant exists; otherwise plan.currency or null.
|
|
23
|
-
*/
|
|
24
|
-
export declare function getDisplayCurrency(planVersion: IPlanVersionWithPlan, currency: string): string;
|
|
25
|
-
/** Minimal shape for extracting currencies (IPlanVersionWithPlan or IPublicPlanVersion). */
|
|
26
|
-
export type PlanVersionWithPricingVariants = {
|
|
27
|
-
pricingVariants?: IPricingVariant[];
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Collect all unique currency codes from plan versions (from their pricingVariants).
|
|
31
|
-
* Use for currency selector. Accepts IPlanVersionWithPlan[] or IPublicPlanVersion[].
|
|
32
|
-
*/
|
|
33
|
-
export declare function getAvailableCurrenciesFromPlans(planVersions: PlanVersionWithPricingVariants[]): string[];
|
|
34
|
-
/**
|
|
35
|
-
* Quota display shape: included count and optional overage (cents) and unitSize from plan + variant.
|
|
36
|
-
*/
|
|
37
|
-
export type QuotaDisplayWithOverage = {
|
|
38
|
-
included: number;
|
|
39
|
-
overage?: number;
|
|
40
|
-
unitSize?: number;
|
|
41
|
-
} | null;
|
|
42
|
-
/**
|
|
43
|
-
* Get quota display value for a slug/interval, merging plan version quotas (included, unitSize)
|
|
44
|
-
* with pricing variant overage (cents) when available.
|
|
45
|
-
*/
|
|
46
|
-
export declare function getQuotaDisplayWithVariant(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): QuotaDisplayWithOverage;
|
|
47
|
-
/**
|
|
48
|
-
* Resolve billing interval and currency from a Stripe price ID by checking all plan versions' pricingVariants.
|
|
49
|
-
*/
|
|
50
|
-
export declare function getBillingIntervalAndCurrencyFromPriceId(priceId: string | null | undefined, planVersions: IPlanVersionWithPlan[]): {
|
|
51
|
-
interval: BillingInterval;
|
|
52
|
-
currency: string;
|
|
53
|
-
} | null;
|
|
54
|
-
/** Get per-seat pricing config for a plan version and currency. Null if not enabled. */
|
|
55
|
-
export declare function getSeatPricing(planVersion: IPlanVersion, currency: string): IPricingVariant['seatPricing'] | null;
|
|
56
|
-
/** Get per-seat price in cents for a billing interval. Null if seat pricing not enabled. */
|
|
57
|
-
export declare function getPerSeatPriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
|
|
58
|
-
/** Calculate billable seats: max(0, currentSeats - includedSeats). */
|
|
59
|
-
export declare function calculateBillableSeats(currentSeatCount: number, includedSeats: number): number;
|
|
60
|
-
/** Calculate total seat overage cost in cents. Null if seat pricing not enabled. */
|
|
61
|
-
export declare function calculateSeatOverageCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount: number): number | null;
|
|
62
|
-
/**
|
|
63
|
-
* Calculate total subscription price in cents: base + seat overage (if enabled).
|
|
64
|
-
* Does not include metered usage (billed at period end).
|
|
65
|
-
*/
|
|
66
|
-
export declare function calculateTotalSubscriptionCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount?: number): number | null;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { BillingInterval, IQuotaByInterval } from './types';
|
|
2
|
-
export type QuotaDisplayValue = {
|
|
3
|
-
included: number;
|
|
4
|
-
overage?: number;
|
|
5
|
-
unitSize?: number;
|
|
6
|
-
} | null;
|
|
7
|
-
/**
|
|
8
|
-
* Normalize a per-interval quota value to a display shape for the given billing interval.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getQuotaDisplayValue(value: IQuotaByInterval | null | undefined, interval?: BillingInterval): QuotaDisplayValue;
|
|
11
|
-
/** Options for formatting quota with price. */
|
|
12
|
-
export interface FormatQuotaWithPriceOptions {
|
|
13
|
-
/** If true, overage is in cents (Stripe); format as dollars. Default true. */
|
|
14
|
-
overageInCents?: boolean;
|
|
15
|
-
/** Currency symbol override. When omitted, derived from `currency` (empty if no currency). */
|
|
16
|
-
currencySymbol?: string;
|
|
17
|
-
/** Stripe currency code (e.g. 'usd', 'inr'). Used to resolve symbol when currencySymbol is not set. */
|
|
18
|
-
currency?: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Format a quota display value as "X included, then $Y.YY / unit" (e.g. "10 included, then $10.00 / video").
|
|
22
|
-
* Assumes overage is the per-unit price (in cents when overageInCents is true).
|
|
23
|
-
*/
|
|
24
|
-
export declare function formatQuotaWithPrice(value: QuotaDisplayValue, unitName: string, options?: FormatQuotaWithPriceOptions): string;
|
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
export interface IDocument {
|
|
2
|
-
_id: string;
|
|
3
|
-
/** Optional; some APIs only return _id. Prefer _id for identity. */
|
|
4
|
-
id?: string;
|
|
5
|
-
createdAt: string;
|
|
6
|
-
updatedAt: string;
|
|
7
|
-
deleted: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface IAssetBucket {
|
|
10
|
-
name: string;
|
|
11
|
-
url: string;
|
|
12
|
-
path: string;
|
|
13
|
-
}
|
|
14
|
-
export interface IUser extends IDocument {
|
|
15
|
-
_id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
email: string;
|
|
18
|
-
/** Profile image URL. Often omitted or empty from API. */
|
|
19
|
-
image?: string;
|
|
20
|
-
role: string;
|
|
21
|
-
/** ISO country code. May be omitted. */
|
|
22
|
-
country?: string;
|
|
23
|
-
/** IANA timezone. May be omitted. */
|
|
24
|
-
timezone?: string;
|
|
25
|
-
/** Language code. May be omitted. */
|
|
26
|
-
language?: string;
|
|
27
|
-
/** Currency code. May be omitted. */
|
|
28
|
-
currency?: string;
|
|
29
|
-
attributes?: Record<string, string | number | boolean>;
|
|
30
|
-
}
|
|
31
|
-
export interface IAsset extends IDocument {
|
|
32
|
-
_id: string;
|
|
33
|
-
createdAt: string;
|
|
34
|
-
updatedAt: string;
|
|
35
|
-
deleted: boolean;
|
|
36
|
-
name: string;
|
|
37
|
-
uniqueName: string;
|
|
38
|
-
mimeType: string;
|
|
39
|
-
size: number;
|
|
40
|
-
encoding: string;
|
|
41
|
-
bucket: {
|
|
42
|
-
name: string;
|
|
43
|
-
url: string;
|
|
44
|
-
path: string;
|
|
45
|
-
};
|
|
46
|
-
metadata: {
|
|
47
|
-
[key: string]: string | number | boolean | object | null;
|
|
48
|
-
};
|
|
49
|
-
image?: {
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
};
|
|
53
|
-
tags: string[];
|
|
54
|
-
public: boolean;
|
|
55
|
-
creator: string | IUser;
|
|
56
|
-
}
|
|
57
|
-
export type BillingInterval = 'monthly' | 'yearly' | 'quarterly';
|
|
58
|
-
export interface ISubscription {
|
|
59
|
-
_id: string;
|
|
60
|
-
subscriptionStatus: 'active' | 'trialing' | 'canceled' | 'past_due' | 'paused' | 'incomplete' | 'unpaid';
|
|
61
|
-
stripePriceId?: string;
|
|
62
|
-
stripeCurrentPeriodEnd?: string;
|
|
63
|
-
cancelAtPeriodEnd: boolean;
|
|
64
|
-
billingInterval?: BillingInterval;
|
|
65
|
-
/** Trial start date (ISO string). Set when subscription is in trial. */
|
|
66
|
-
trialStart?: string;
|
|
67
|
-
/** Trial end date (ISO string). Set when subscription is in trial. */
|
|
68
|
-
trialEnd?: string;
|
|
69
|
-
/** When the subscription was canceled (ISO string). Soft-delete marker. */
|
|
70
|
-
canceledAt?: string;
|
|
71
|
-
/** Dunning state: 'none', 'notified', 'warning', 'final', 'suspended'. */
|
|
72
|
-
dunningState?: string;
|
|
73
|
-
/** Whether this subscription uses per-seat pricing. */
|
|
74
|
-
seatPricingEnabled?: boolean;
|
|
75
|
-
/** Current billable seat count. */
|
|
76
|
-
currentSeatCount?: number;
|
|
77
|
-
createdAt: string;
|
|
78
|
-
updatedAt: string;
|
|
79
|
-
plan?: {
|
|
80
|
-
_id: string;
|
|
81
|
-
name: string;
|
|
82
|
-
slug: string;
|
|
83
|
-
description?: string;
|
|
84
|
-
/** Stripe currency code (e.g. 'usd', 'inr', 'eur'). */
|
|
85
|
-
currency?: string;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
export interface ISubscriptionItem {
|
|
89
|
-
_id: string;
|
|
90
|
-
type: 'feature' | 'limit' | 'quota';
|
|
91
|
-
name: string;
|
|
92
|
-
slug: string;
|
|
93
|
-
description?: string;
|
|
94
|
-
category: string;
|
|
95
|
-
}
|
|
96
|
-
/** Per-interval quota value (plan-group/versions and public plans schema). */
|
|
97
|
-
export interface IQuotaIntervalValue {
|
|
98
|
-
included: number;
|
|
99
|
-
/** Overage price in cents. Omitted in public plans; use pricingVariant.quotaOverages for display. */
|
|
100
|
-
overage?: number;
|
|
101
|
-
/** Stripe price ID for overage. Omitted in public plans; use pricingVariant.quotaOveragePriceIds. */
|
|
102
|
-
priceId?: string;
|
|
103
|
-
/** Unit size for overage pricing (e.g. 1000 = price per 1000 units). */
|
|
104
|
-
unitSize?: number;
|
|
105
|
-
}
|
|
106
|
-
/** Quota defined per billing interval (new plan-group/versions schema) */
|
|
107
|
-
export interface IQuotaByInterval {
|
|
108
|
-
monthly?: IQuotaIntervalValue;
|
|
109
|
-
yearly?: IQuotaIntervalValue;
|
|
110
|
-
quarterly?: IQuotaIntervalValue;
|
|
111
|
-
}
|
|
112
|
-
/** Base pricing per interval. Values are often in cents (Stripe); convert for display. */
|
|
113
|
-
export interface IBasePricing {
|
|
114
|
-
monthly: number;
|
|
115
|
-
yearly: number;
|
|
116
|
-
quarterly: number;
|
|
117
|
-
}
|
|
118
|
-
/** Stripe price IDs per billing interval (for a single currency variant). */
|
|
119
|
-
export interface IStripePricesByInterval {
|
|
120
|
-
monthlyPriceId?: string;
|
|
121
|
-
yearlyPriceId?: string;
|
|
122
|
-
quarterlyPriceId?: string;
|
|
123
|
-
monthly?: string;
|
|
124
|
-
yearly?: string;
|
|
125
|
-
}
|
|
126
|
-
/** Overage amounts in cents per interval, keyed by quota slug. Used in pricing variants. */
|
|
127
|
-
export type IQuotaOveragesByInterval = Record<string, {
|
|
128
|
-
monthly?: number;
|
|
129
|
-
yearly?: number;
|
|
130
|
-
quarterly?: number;
|
|
131
|
-
}>;
|
|
132
|
-
/** Overage Stripe price IDs per interval, keyed by quota slug. Used in pricing variants. */
|
|
133
|
-
export type IQuotaOveragePriceIdsByInterval = Record<string, {
|
|
134
|
-
monthly?: string;
|
|
135
|
-
yearly?: string;
|
|
136
|
-
quarterly?: string;
|
|
137
|
-
}>;
|
|
138
|
-
/**
|
|
139
|
-
* Multi-currency pricing variant at plan version level.
|
|
140
|
-
* Each plan version can have multiple variants (e.g. usd, eur, inr, sgd).
|
|
141
|
-
*/
|
|
142
|
-
export interface IPricingVariant {
|
|
143
|
-
_id: string;
|
|
144
|
-
currency: string;
|
|
145
|
-
basePricing: IBasePricing;
|
|
146
|
-
stripePrices: IStripePricesByInterval;
|
|
147
|
-
/** Per-seat pricing config. When enabled, a second recurring item is on the subscription. */
|
|
148
|
-
seatPricing?: {
|
|
149
|
-
enabled: boolean;
|
|
150
|
-
includedSeats: number;
|
|
151
|
-
/** Maximum seats allowed. 0 or undefined = unlimited. */
|
|
152
|
-
maxSeats?: number;
|
|
153
|
-
perSeat: IBasePricing;
|
|
154
|
-
};
|
|
155
|
-
/** Stripe Price IDs for the per-seat recurring price. */
|
|
156
|
-
seatStripePrices?: IStripePricesByInterval;
|
|
157
|
-
/** Overage cents per quota slug per interval. */
|
|
158
|
-
quotaOverages?: IQuotaOveragesByInterval;
|
|
159
|
-
/** Stripe price IDs for overage per quota slug per interval. */
|
|
160
|
-
quotaOveragePriceIds?: IQuotaOveragePriceIdsByInterval;
|
|
161
|
-
}
|
|
162
|
-
export interface IPlanVersion {
|
|
163
|
-
_id: string;
|
|
164
|
-
version: number;
|
|
165
|
-
name: string;
|
|
166
|
-
status: 'draft' | 'published';
|
|
167
|
-
features?: Record<string, boolean>;
|
|
168
|
-
limits?: Record<string, number>;
|
|
169
|
-
/** Per-interval quotas (included, unitSize; overage from pricingVariant.quotaOverages). */
|
|
170
|
-
quotas?: Record<string, IQuotaByInterval>;
|
|
171
|
-
/** Multi-currency pricing. Each variant has currency, basePricing, stripePrices, quotaOverages. */
|
|
172
|
-
pricingVariants?: IPricingVariant[];
|
|
173
|
-
subscriptionItems?: ISubscriptionItem[];
|
|
174
|
-
isCurrent?: boolean;
|
|
175
|
-
isLegacy?: boolean;
|
|
176
|
-
archived?: boolean;
|
|
177
|
-
deleted?: boolean;
|
|
178
|
-
createdAt?: string;
|
|
179
|
-
updatedAt?: string;
|
|
180
|
-
id?: string;
|
|
181
|
-
stripeProductId?: string;
|
|
182
|
-
}
|
|
183
|
-
/** Plan version summary (e.g. plan.latestVersion from subscription API) with subscriptionItems as IDs. */
|
|
184
|
-
export interface IPlanVersionSummary extends Omit<IPlanVersion, 'subscriptionItems'> {
|
|
185
|
-
subscriptionItems?: string[];
|
|
186
|
-
}
|
|
187
|
-
export interface IPlan {
|
|
188
|
-
_id: string;
|
|
189
|
-
name: string;
|
|
190
|
-
slug: string;
|
|
191
|
-
description?: string;
|
|
192
|
-
/** Stripe currency code (e.g. 'usd', 'inr', 'eur'). Used for pricing display. */
|
|
193
|
-
currency?: string;
|
|
194
|
-
latestVersion?: IPlanVersionSummary;
|
|
195
|
-
archived?: boolean;
|
|
196
|
-
deleted?: boolean;
|
|
197
|
-
createdAt?: string;
|
|
198
|
-
updatedAt?: string;
|
|
199
|
-
id?: string;
|
|
200
|
-
}
|
|
201
|
-
export interface IPlanGroupLatestVersion {
|
|
202
|
-
_id: string;
|
|
203
|
-
version: number;
|
|
204
|
-
planVersionIds: string[];
|
|
205
|
-
requiredItems: string[];
|
|
206
|
-
status: 'draft' | 'published';
|
|
207
|
-
isCurrent?: boolean;
|
|
208
|
-
isLegacy?: boolean;
|
|
209
|
-
archived?: boolean;
|
|
210
|
-
deleted?: boolean;
|
|
211
|
-
createdAt?: string;
|
|
212
|
-
updatedAt?: string;
|
|
213
|
-
description?: string;
|
|
214
|
-
}
|
|
215
|
-
export interface IPlanGroup {
|
|
216
|
-
_id: string;
|
|
217
|
-
name: string;
|
|
218
|
-
slug: string;
|
|
219
|
-
description?: string;
|
|
220
|
-
latestVersion?: IPlanGroupLatestVersion;
|
|
221
|
-
archived?: boolean;
|
|
222
|
-
deleted?: boolean;
|
|
223
|
-
createdAt?: string;
|
|
224
|
-
updatedAt?: string;
|
|
225
|
-
id?: string;
|
|
226
|
-
}
|
|
227
|
-
export interface IPlanGroupVersion {
|
|
228
|
-
_id: string;
|
|
229
|
-
version: number;
|
|
230
|
-
description?: string;
|
|
231
|
-
group?: {
|
|
232
|
-
_id: string;
|
|
233
|
-
name: string;
|
|
234
|
-
description?: string;
|
|
235
|
-
};
|
|
236
|
-
planVersionIds: IPlanVersionWithPlan[] | string[];
|
|
237
|
-
requiredItems?: string[];
|
|
238
|
-
status?: 'draft' | 'published';
|
|
239
|
-
isCurrent?: boolean;
|
|
240
|
-
isLegacy?: boolean;
|
|
241
|
-
archived?: boolean;
|
|
242
|
-
deleted?: boolean;
|
|
243
|
-
createdAt?: string;
|
|
244
|
-
updatedAt?: string;
|
|
245
|
-
id?: string;
|
|
246
|
-
}
|
|
247
|
-
export interface ISubscriptionResponse {
|
|
248
|
-
subscription: ISubscription | null;
|
|
249
|
-
planVersion: IPlanVersion | null;
|
|
250
|
-
plan: IPlan | null;
|
|
251
|
-
group: IPlanGroup | null;
|
|
252
|
-
groupVersion: IPlanGroupVersion | null;
|
|
253
|
-
}
|
|
254
|
-
/** Plan version with nested plan info (name, slug, currency for display). */
|
|
255
|
-
export interface IPlanVersionWithPlan extends IPlanVersion {
|
|
256
|
-
plan: IPlan;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Plan group version with full plan versions (for GET .../plan-group/versions).
|
|
260
|
-
* Each plan has plan, subscriptionItems, quotas (per-interval), pricingVariants.
|
|
261
|
-
*/
|
|
262
|
-
export interface IPlanGroupVersionWithPlans {
|
|
263
|
-
_id: string;
|
|
264
|
-
version: number;
|
|
265
|
-
description?: string;
|
|
266
|
-
/** Full plan versions with nested plan (name, slug, currency). */
|
|
267
|
-
plans: IPlanVersionWithPlan[];
|
|
268
|
-
isCurrent?: boolean;
|
|
269
|
-
whatsNew?: {
|
|
270
|
-
newPlans: IPlanVersionWithPlan[];
|
|
271
|
-
updatedPlans: IPlanVersionWithPlan[];
|
|
272
|
-
removedPlans: IPlanVersionWithPlan[];
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
export interface IPlanGroupInfo {
|
|
276
|
-
_id: string;
|
|
277
|
-
name: string;
|
|
278
|
-
slug: string;
|
|
279
|
-
description?: string;
|
|
280
|
-
}
|
|
281
|
-
/** Response from GET workspaces/:id/subscription/plan-group (and by version). */
|
|
282
|
-
export interface IPlanGroupResponse {
|
|
283
|
-
/** Plan group with latestVersion, archived, deleted, timestamps. May be null in some API responses. */
|
|
284
|
-
group: IPlanGroup | null;
|
|
285
|
-
/** Current group version with populated planVersionIds (or IDs). */
|
|
286
|
-
groupVersion: IPlanGroupVersion;
|
|
287
|
-
/** Full plan versions for display (subscriptionItems, pricingVariants, quotas). */
|
|
288
|
-
plans: IPlanVersionWithPlan[];
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Response from GET workspaces/:workspaceId/subscription/plan-group/versions.
|
|
292
|
-
* Group summary plus current and available group versions; each version has plans with
|
|
293
|
-
* per-interval quotas and pricingVariants.
|
|
294
|
-
*/
|
|
295
|
-
export interface IPlanGroupVersionsResponse {
|
|
296
|
-
/** Plan group summary (_id, name, slug). */
|
|
297
|
-
group: IPlanGroupInfo;
|
|
298
|
-
/** Current group version (user's version when subscribed, or latest published when not). */
|
|
299
|
-
currentVersion: IPlanGroupVersionWithPlans;
|
|
300
|
-
/** Newer versions when user has subscription; empty when no subscription. */
|
|
301
|
-
availableVersions: IPlanGroupVersionWithPlans[];
|
|
302
|
-
}
|
|
303
|
-
/** Request body for POST .../workspaces/:id/subscription/checkout. Only these fields are allowed. */
|
|
304
|
-
export interface ICheckoutSessionRequest {
|
|
305
|
-
planVersionId: string;
|
|
306
|
-
billingInterval?: BillingInterval;
|
|
307
|
-
currency?: string;
|
|
308
|
-
successUrl?: string;
|
|
309
|
-
cancelUrl?: string;
|
|
310
|
-
}
|
|
311
|
-
export interface ICheckoutSessionResponse {
|
|
312
|
-
/** Response type discriminator. Added for centralized checkout flow. */
|
|
313
|
-
type?: 'checkout' | 'trial_started' | 'existing';
|
|
314
|
-
success: boolean;
|
|
315
|
-
checkoutUrl: string;
|
|
316
|
-
sessionId: string;
|
|
317
|
-
message: string;
|
|
318
|
-
planVersion?: {
|
|
319
|
-
_id: string;
|
|
320
|
-
version: number;
|
|
321
|
-
name: string;
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
/** No-card trial started server-side; no redirect needed. */
|
|
325
|
-
export interface ICheckoutTrialResult {
|
|
326
|
-
type: 'trial_started';
|
|
327
|
-
success: boolean;
|
|
328
|
-
checkoutUrl: null;
|
|
329
|
-
sessionId: null;
|
|
330
|
-
subscription: ISubscription;
|
|
331
|
-
message: string;
|
|
332
|
-
}
|
|
333
|
-
/** Workspace already has a matching active subscription. */
|
|
334
|
-
export interface ICheckoutExistingResult {
|
|
335
|
-
type: 'existing';
|
|
336
|
-
success: boolean;
|
|
337
|
-
checkoutUrl: null;
|
|
338
|
-
sessionId: null;
|
|
339
|
-
message: string;
|
|
340
|
-
existingSubscription?: {
|
|
341
|
-
_id: string;
|
|
342
|
-
subscriptionStatus: string;
|
|
343
|
-
stripePriceId?: string;
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Discriminated union for POST /subscription/checkout responses.
|
|
348
|
-
* - `checkout`: Stripe checkout session created, redirect user to checkoutUrl
|
|
349
|
-
* - `trial_started`: No-card trial started server-side, no redirect needed
|
|
350
|
-
* - `existing`: Workspace already has a matching subscription
|
|
351
|
-
*/
|
|
352
|
-
export type CheckoutResult = (ICheckoutSessionResponse & {
|
|
353
|
-
type: 'checkout';
|
|
354
|
-
}) | ICheckoutTrialResult | ICheckoutExistingResult;
|
|
355
|
-
/** Request body for PATCH .../workspaces/:id/subscription. Only these fields are allowed. */
|
|
356
|
-
export interface ISubscriptionUpdateRequest {
|
|
357
|
-
planVersionId: string;
|
|
358
|
-
billingInterval?: BillingInterval;
|
|
359
|
-
successUrl?: string;
|
|
360
|
-
cancelUrl?: string;
|
|
361
|
-
}
|
|
362
|
-
export interface ISubscriptionUpdateResponse {
|
|
363
|
-
_id: string;
|
|
364
|
-
subscriptionStatus: string;
|
|
365
|
-
workspace: string;
|
|
366
|
-
planVersion: string;
|
|
367
|
-
plan: string;
|
|
368
|
-
planGroup?: string;
|
|
369
|
-
planGroupVersion?: string;
|
|
370
|
-
cancelAtPeriodEnd: boolean;
|
|
371
|
-
createdAt: string;
|
|
372
|
-
updatedAt: string;
|
|
373
|
-
}
|
|
374
|
-
export interface IPublicPlanItemCategory {
|
|
375
|
-
name: string;
|
|
376
|
-
slug: string;
|
|
377
|
-
}
|
|
378
|
-
export interface IPublicPlanItem {
|
|
379
|
-
_id: string;
|
|
380
|
-
name: string;
|
|
381
|
-
slug: string;
|
|
382
|
-
description?: string;
|
|
383
|
-
type: 'feature' | 'limit' | 'quota';
|
|
384
|
-
category: IPublicPlanItemCategory;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Public plan version (e.g. from GET /api/v1/public/:orgId/plans/:slug).
|
|
388
|
-
* Each plan has _id, name (plan display name), version, status, pricingVariants, quotas, features, limits.
|
|
389
|
-
* Pricing is in cents (see response.notes).
|
|
390
|
-
*/
|
|
391
|
-
export interface IPublicPlanVersion {
|
|
392
|
-
_id: string;
|
|
393
|
-
/** Plan display name (e.g. "Pro", "Base Plan"). */
|
|
394
|
-
name: string;
|
|
395
|
-
version: number;
|
|
396
|
-
status: 'draft' | 'published';
|
|
397
|
-
/** Multi-currency pricing. Use getBasePriceCents(plan, currency, interval) and getQuotaDisplayWithVariant for display. */
|
|
398
|
-
pricingVariants?: IPricingVariant[];
|
|
399
|
-
/** Keyed by item slug. Per-interval: included, unitSize; overage from pricingVariant.quotaOverages. */
|
|
400
|
-
quotas: Record<string, IQuotaByInterval>;
|
|
401
|
-
features: Record<string, boolean>;
|
|
402
|
-
limits: Record<string, number>;
|
|
403
|
-
}
|
|
404
|
-
export interface IPublicPlansResponse {
|
|
405
|
-
items: IPublicPlanItem[];
|
|
406
|
-
plans: IPublicPlanVersion[];
|
|
407
|
-
/** Optional note from API (e.g. "Pricing is in cents. Please convert to dollars for display."). */
|
|
408
|
-
notes?: string;
|
|
409
|
-
}
|
|
410
|
-
export type InvoiceStatus = 'draft' | 'open' | 'paid' | 'uncollectible' | 'void';
|
|
411
|
-
export interface IInvoice {
|
|
412
|
-
id: string;
|
|
413
|
-
amount_due: number;
|
|
414
|
-
number: string | null;
|
|
415
|
-
amount_paid: number;
|
|
416
|
-
currency: string;
|
|
417
|
-
status: InvoiceStatus;
|
|
418
|
-
created: number;
|
|
419
|
-
due_date: number | null;
|
|
420
|
-
hosted_invoice_url: string;
|
|
421
|
-
invoice_pdf: string | null;
|
|
422
|
-
description: string | null;
|
|
423
|
-
subscription: string;
|
|
424
|
-
}
|
|
425
|
-
export interface IInvoiceListResponse {
|
|
426
|
-
success: boolean;
|
|
427
|
-
invoices: IInvoice[];
|
|
428
|
-
has_more: boolean;
|
|
429
|
-
}
|
|
430
|
-
export interface IInvoiceResponse {
|
|
431
|
-
success: boolean;
|
|
432
|
-
invoice: IInvoice;
|
|
433
|
-
}
|
|
434
|
-
/** Request body for POST .../workspaces/:id/subscription/usage */
|
|
435
|
-
export interface IRecordUsageRequest {
|
|
436
|
-
quotaSlug: string;
|
|
437
|
-
quantity: number;
|
|
438
|
-
metadata?: Record<string, unknown>;
|
|
439
|
-
source?: string;
|
|
440
|
-
idempotencyKey?: string;
|
|
441
|
-
}
|
|
442
|
-
/** Response from POST .../workspaces/:id/subscription/usage */
|
|
443
|
-
export interface IRecordUsageResponse {
|
|
444
|
-
used: number;
|
|
445
|
-
consumed: number;
|
|
446
|
-
included: number;
|
|
447
|
-
available: number;
|
|
448
|
-
overage: number;
|
|
449
|
-
billedAsync: boolean;
|
|
450
|
-
}
|
|
451
|
-
/** Single quota usage status (shared between status and all endpoints). */
|
|
452
|
-
export interface IQuotaUsageStatus {
|
|
453
|
-
consumed: number;
|
|
454
|
-
included: number;
|
|
455
|
-
available: number;
|
|
456
|
-
overage: number;
|
|
457
|
-
hasOverage: boolean;
|
|
458
|
-
}
|
|
459
|
-
/** Response from GET .../workspaces/:id/subscription/usage/status?quotaSlug=X */
|
|
460
|
-
export interface IQuotaUsageStatusResponse extends IQuotaUsageStatus {
|
|
461
|
-
quotaSlug: string;
|
|
462
|
-
}
|
|
463
|
-
/** Response from GET .../workspaces/:id/subscription/usage/all */
|
|
464
|
-
export interface IAllQuotaUsageResponse {
|
|
465
|
-
quotas: Record<string, IQuotaUsageStatus>;
|
|
466
|
-
}
|
|
467
|
-
/** Single usage log entry from GET .../usage/logs */
|
|
468
|
-
export interface IUsageLogEntry {
|
|
469
|
-
_id: string;
|
|
470
|
-
quotaSlug: string;
|
|
471
|
-
quantity: number;
|
|
472
|
-
source?: string;
|
|
473
|
-
workspace: string;
|
|
474
|
-
createdAt: string;
|
|
475
|
-
updatedAt: string;
|
|
476
|
-
}
|
|
477
|
-
/** Query parameters for GET .../workspaces/:id/subscription/usage/logs */
|
|
478
|
-
export interface IUsageLogsQuery {
|
|
479
|
-
quotaSlug?: string;
|
|
480
|
-
from?: string;
|
|
481
|
-
to?: string;
|
|
482
|
-
source?: string;
|
|
483
|
-
page?: number;
|
|
484
|
-
limit?: number;
|
|
485
|
-
}
|
|
486
|
-
/** Paginated response from GET .../workspaces/:id/subscription/usage/logs */
|
|
487
|
-
export interface IUsageLogsResponse {
|
|
488
|
-
docs: IUsageLogEntry[];
|
|
489
|
-
totalDocs: number;
|
|
490
|
-
limit: number;
|
|
491
|
-
page: number;
|
|
492
|
-
totalPages: number;
|
|
493
|
-
hasNextPage: boolean;
|
|
494
|
-
hasPrevPage: boolean;
|
|
495
|
-
}
|