import type { Endpoint } from '../api.js'; import type { ApiBillingUsageMetrics, BillingCustomer, BillingInvoicingDetails, BreakdownDimensions } from '../billing/types.js'; import type { MetricUsageSummary, UsageMetric } from '../usage/index.js'; import type { ReplaceInObject } from '../utils.js'; import type { DBPlan } from './db.js'; export type ApiPlan = ReplaceInObject; export type PostPlanExtendTrial = Endpoint<{ Method: 'POST'; Path: '/api/v1/plans/trial/extension'; Querystring: { env: string; }; Success: { data: { success: boolean; }; }; }>; export interface PlanDefinition { /** * Maps to orb external plan id */ code: DBPlan['name']; title: string; description: string; canChange: boolean; nextPlan: string[] | null; prevPlan: string[] | null; basePrice?: number; cta?: string; hidden?: boolean; flags: Omit, 'id' | 'account_id' | 'name'>; } export type GetPlans = Endpoint<{ Method: 'GET'; Path: '/api/v1/plans'; Querystring: { env: string; }; Success: { data: PlanDefinition[]; }; }>; export type GetPlan = Endpoint<{ Method: 'GET'; Path: '/api/v1/plans/current'; Querystring: { env: string; }; Success: { data: ApiPlan; }; }>; export type GetUsage = Endpoint<{ Method: 'GET'; Path: '/api/v1/plans/usage'; Querystring: { env: string; }; Success: { data: Record; }; }>; export type GetBillingUsageTopDimensionValues = Endpoint<{ Method: 'GET'; Path: '/api/v1/plans/billing-usage/top-dimension-values'; Querystring: { [M in UsageMetric]: { env: string; metric: M; dimension: BreakdownDimensions[M]; from: string; to: string; search?: string | undefined; page?: string | undefined; }; }[UsageMetric]; Success: { data: { values: { id: string; label: string; }[]; pagination: { page: number; limit: number; hasMore: boolean; }; }; }; }>; export type GetBillingUsage = Endpoint<{ Method: 'GET'; Path: '/api/v1/plans/billing-usage'; Querystring: { env: string; from?: string | undefined; to?: string | undefined; source?: 'clickhouse' | 'orb' | undefined; metrics?: UsageMetric[] | undefined; breakdown?: { [M in UsageMetric]?: BreakdownDimensions[M] | undefined; } | undefined; top?: string | undefined; filter?: Partial> | undefined; avgPerDay?: boolean | undefined; }; Success: { data: { customer: BillingCustomer; usage: ApiBillingUsageMetrics; }; }; }>; export type PutBillingInvoicingDetails = Endpoint<{ Method: 'PUT'; Path: '/api/v1/plans/billing/invoicing'; Querystring: { env: string; }; Body: BillingInvoicingDetails; Success: { data: BillingCustomer; }; }>; export type PostPlanChange = Endpoint<{ Method: 'POST'; Path: '/api/v1/plans/change'; Querystring: { env: string; }; Body: { orbId: string; }; Success: { data: { success: true; } | { paymentIntent: any; }; }; }>;