import {z} from 'zod' export type ComputePrice = {architecture?: string | undefined, availability_zone?: string | undefined, cost_per_hour?: number | undefined, cpu_cores?: number | undefined, cpu_cores_cost_per_hour?: number | undefined, created_at?: string | undefined, currency?: string | undefined, gpu_cost_per_hour?: number | undefined, gpu_count?: number | undefined, gpu_type?: string | undefined, id?: string | undefined, instance_type?: string | undefined, native_cost_per_hour?: number | undefined, operating_system?: string | undefined, period_billing_hours?: number | undefined, provider?: string | undefined, ram_gb?: number | undefined, ram_gb_cost_per_hour?: number | undefined, raw_pricing_data?: Record | undefined, region?: string | undefined, resizable?: boolean | undefined, service?: string | undefined, tags?: Record | undefined, updated_at?: string | undefined, usage_type?: string | undefined}; export type ComputePricesRequest = {entries: Array}; export type CreateApiMarketplaceProvidersComputeArgs = {body: ComputePricesRequest}; export type CreateApiMarketplaceProvidersComputeOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const computePrice = z.object({architecture: z.string().optional(), availability_zone: z.string().optional(), cost_per_hour: z.number().optional(), cpu_cores: z.number().optional(), cpu_cores_cost_per_hour: z.number().optional(), created_at: z.string().optional(), currency: z.string().optional(), gpu_cost_per_hour: z.number().optional(), gpu_count: z.number().optional(), gpu_type: z.string().optional(), id: z.string().optional(), instance_type: z.string().optional(), native_cost_per_hour: z.number().optional(), operating_system: z.string().optional(), period_billing_hours: z.number().optional(), provider: z.string().optional(), ram_gb: z.number().optional(), ram_gb_cost_per_hour: z.number().optional(), raw_pricing_data: z.object({}).optional(), region: z.string().optional(), resizable: z.boolean().optional(), service: z.string().optional(), tags: z.object({}).optional(), updated_at: z.string().optional(), usage_type: z.string().optional()}); export const registrationStatus = z.enum(["Registered", "Deleted"]); export const registeredComputePrices = z.object({entries: z.array(computePrice).optional(), status: registrationStatus.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 }; /** * Register a custom provider * * POST /marketplace/providers/compute * * Also accepts auth: BearerAuth */ export const createApiMarketplaceProvidersCompute = async (args: CreateApiMarketplaceProvidersComputeArgs, options?: CreateApiMarketplaceProvidersComputeOptions) => { const {baseUrl = "https://pricing.baselinehq.cloud", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/marketplace/providers/compute${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(registeredComputePrices, await res.json()) };