import {z} from 'zod' export type GetApiV1OrganizationsInfrastructureSummaryArgs = {billing_month?: (string | null) | undefined}; export type GetApiV1OrganizationsInfrastructureSummaryOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceAllocation = z.object({cpu_request: z.string(), cpu_limit: z.string(), memory_request: z.string(), memory_limit: z.string(), gpu: z.number().int().optional()}); export const scalingConfig = z.object({min_replicas: z.number().int(), max_replicas: z.number().int()}); export const extractorComputeSummary = z.object({extractor_name: z.string(), version: z.string(), gke_profile: z.string(), workload_type: z.string(), head: resourceAllocation, cpu_workers: resourceAllocation, cpu_worker_scaling: scalingConfig, gpu_workers: resourceAllocation, gpu_worker_scaling: scalingConfig, cost_per_hour_usd: z.number()}); export const dataPlaneComponentSummary = z.object({component: z.string(), component_label: z.string(), replicas: z.number().int(), scaling: scalingConfig.nullable().optional(), resources: resourceAllocation}); export const cloudCostLineItem = z.object({service: z.string(), description: z.string(), category: z.string(), cloud_cost_usd: z.number(), margin_usd: z.number(), total_usd: z.number(), usage_amount: z.number().nullable().optional(), usage_unit: z.string().nullable().optional(), region: z.string().nullable().optional()}); export const cloudCostCategorySummary = z.object({category: z.string(), category_label: z.string(), cloud_cost_usd: z.number(), margin_usd: z.number(), total_usd: z.number(), line_items: z.array(cloudCostLineItem)}); export const costBreakdownSummary = z.object({billing_month: z.string(), cloud_provider: z.string(), data_as_of: z.string().nullable().optional(), data_delay_note: z.string().nullable().optional(), cost_unavailable: z.boolean().optional(), attribution_scope: z.string().optional(), total_cloud_cost_usd: z.number().optional(), margin_pct: z.number().optional(), total_margin_usd: z.number().optional(), platform_fee_usd: z.number().optional(), platform_fee_billed_externally: z.boolean().optional(), total_invoice_usd: z.number().optional(), categories: z.array(cloudCostCategorySummary).optional(), all_line_items: z.array(cloudCostLineItem).optional()}); export const computeCostSummary = z.object({cpu_hours: z.number().optional(), gpu_hours: z.number().optional(), base_cost_usd: z.number().optional(), daily_breakdown: z.array(z.record(z.string(), z.unknown())).optional()}); export const billingPeriodSummary = z.object({billing_month: z.string(), platform_fee_usd: z.number().optional(), compute_base_cost_usd: z.number().optional(), usage_cost_usd: z.number().optional(), total_base_cost_usd: z.number().optional(), note: z.string().optional()}); export const infrastructureSummaryResponse = z.object({tenant_id: z.string(), namespace: z.string().nullable().optional(), region: z.string().optional(), billing_mode: z.string().optional(), extractors: z.array(extractorComputeSummary).optional(), data_plane_components: z.array(dataPlaneComponentSummary).optional(), cost_breakdown: costBreakdownSummary, compute_costs: computeCostSummary.optional(), billing_period: billingPeriodSummary.nullable().optional()}); 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 }; /** * Get Infrastructure * * GET /v1/organizations/infrastructure/summary */ export const getApiV1OrganizationsInfrastructureSummary = async (args: GetApiV1OrganizationsInfrastructureSummaryArgs, options?: GetApiV1OrganizationsInfrastructureSummaryOptions) => { const {baseUrl = "https://api.mixpeek.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.billing_month != null) query.append("billing_month", String(args.billing_month)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/infrastructure/summary${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(infrastructureSummaryResponse, await res.json()) };