import {z} from 'zod' export type GetApiMarketplaceProvidersComputeArgs = {limit?: number | undefined, offset?: number | undefined, service?: string | undefined, region?: string | undefined, instance_type?: string | undefined, usage_type?: string | undefined}; export type GetApiMarketplaceProvidersComputeOptions = {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 computePriceList = z.object({providers: z.array(computePrice).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 your custom pricing entries * * GET /marketplace/providers/compute * * Also accepts auth: BearerAuth */ export const getApiMarketplaceProvidersCompute = async (args: GetApiMarketplaceProvidersComputeArgs, options?: GetApiMarketplaceProvidersComputeOptions) => { const {baseUrl = "https://pricing.baselinehq.cloud", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.service != null) query.append("service", String(args.service)) if (args.region != null) query.append("region", String(args.region)) if (args.instance_type != null) query.append("instance_type", String(args.instance_type)) if (args.usage_type != null) query.append("usage_type", String(args.usage_type)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(computePriceList, await res.json()) };