import {z} from 'zod' export type CreateApiApiV1BillingStatusOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1BillingStatusResponse = z.object({status: z.enum(["payment_required", "pending", "active", "prepaid_active", "past_due", "canceled"]), paid_until: z.string().nullable().optional(), price_usd_monthly: z.string(), plan: z.record(z.string(), z.unknown()), billing_portal_available: z.boolean(), launch_accepted: z.boolean(), usage: z.record(z.string(), z.unknown())}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Read the authenticated tenant's hosted billing and usage status * * POST /api/v1/billing/status */ export const createApiApiV1BillingStatus = async (options?: CreateApiApiV1BillingStatusOptions) => { const {baseUrl = "https://agent.getaxonflow.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/billing/status${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1BillingStatusResponse, await res.json()) };