import {z} from 'zod' export type KubernetesCostAllocationV1CreateSchema = {projectId?: string | undefined, kubernetesClusterId: string, clusterName: string, k8sClusterEntityKey?: string | undefined, windowStart: string, windowEnd: string, namespace?: string | undefined, controllerKind?: string | undefined, controllerName?: string | undefined, podName?: string | undefined, containerName?: string | undefined, nodeName?: string | undefined, providerId?: string | undefined, labels?: {[key: string]: string} | undefined, labelKeys?: Array | undefined, cpuCoreHours?: number | undefined, cpuCoreRequestAverage?: number | undefined, cpuCoreUsageAverage?: number | undefined, cpuCoreLimitAverage?: number | undefined, cpuCost?: number | undefined, gpuHours?: number | undefined, gpuCost?: number | undefined, ramByteHours?: number | undefined, ramBytesRequestAverage?: number | undefined, ramBytesUsageAverage?: number | undefined, ramBytesLimitAverage?: number | undefined, ramBytesUsageMax?: number | undefined, ramCost?: number | undefined, pvByteHours?: number | undefined, pvCost?: number | undefined, networkCost?: number | undefined, loadBalancerCost?: number | undefined, sharedCost?: number | undefined, externalCost?: number | undefined, totalCost?: number | undefined, cpuEfficiency?: number | undefined, ramEfficiency?: number | undefined, totalEfficiency?: number | undefined, currency?: string | undefined, shipmentId?: string | undefined, shipmentChunk?: number | undefined}; export type CreateApiKubernetesCostAllocationArgs = {body: {data: KubernetesCostAllocationV1CreateSchema}}; export type CreateApiKubernetesCostAllocationOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const kubernetesCostAllocationV1ReadSchema = z.object({projectId: z.string(), kubernetesClusterId: z.string(), clusterName: z.string(), k8sClusterEntityKey: z.string().optional(), windowStart: z.string().optional(), windowEnd: z.string().optional(), namespace: z.string().optional(), controllerKind: z.string().optional(), controllerName: z.string().optional(), podName: z.string().optional(), containerName: z.string().optional(), nodeName: z.string().optional(), providerId: z.string().optional(), labels: z.string().optional(), labelKeys: z.array(z.string()).optional(), cpuCoreHours: z.number().optional(), cpuCoreRequestAverage: z.number().optional(), cpuCoreUsageAverage: z.number().optional(), cpuCoreLimitAverage: z.number().optional(), cpuCost: z.number().optional(), gpuHours: z.number().optional(), gpuCost: z.number().optional(), ramByteHours: z.number().optional(), ramBytesRequestAverage: z.number().optional(), ramBytesUsageAverage: z.number().optional(), ramBytesLimitAverage: z.number().optional(), ramBytesUsageMax: z.number().optional(), ramCost: z.number().optional(), pvByteHours: z.number().optional(), pvCost: z.number().optional(), networkCost: z.number().optional(), loadBalancerCost: z.number().optional(), sharedCost: z.number().optional(), externalCost: z.number().optional(), totalCost: z.number().optional(), cpuEfficiency: z.number().optional(), ramEfficiency: z.number().optional(), totalEfficiency: z.number().optional(), currency: z.string().optional(), shipmentId: z.string().optional(), shipmentChunk: z.number().optional()}); export const createApiKubernetesCostAllocationResponse = z.object({data: kubernetesCostAllocationV1ReadSchema.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 }; /** * Create Kubernetes Cost Allocation * * POST /kubernetes-cost-allocation */ export const createApiKubernetesCostAllocation = async (args: CreateApiKubernetesCostAllocationArgs, options?: CreateApiKubernetesCostAllocationOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/kubernetes-cost-allocation${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiKubernetesCostAllocationResponse, await res.json()) };