import {z} from 'zod' export type DiskPrice = {availability_zone?: string | undefined, cost_per_gb_hour?: number | undefined, cost_per_iops_hour?: number | undefined, cost_per_throughput_mbps_hour?: number | undefined, created_at?: string | undefined, currency?: string | undefined, id?: string | undefined, max_capacity_gb?: number | undefined, max_iops?: number | undefined, max_throughput_mbps?: number | undefined, min_capacity_gb?: number | undefined, min_iops?: number | undefined, min_throughput_mbps?: number | undefined, native_cost_per_gb_hour?: number | undefined, native_cost_per_iops_hour?: number | undefined, native_cost_per_throughput_mbps_hour?: number | undefined, period_billing_hours?: number | undefined, provider?: string | undefined, raw_pricing_data?: Record | undefined, region?: string | undefined, service?: string | undefined, tags?: Record | undefined, type?: string | undefined, updated_at?: string | undefined, usage_type?: string | undefined}; export type DiskPricesRequest = {entries: Array}; export type CreateApiMarketplaceProvidersDisksArgs = {body: DiskPricesRequest}; export type CreateApiMarketplaceProvidersDisksOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const diskPrice = z.object({availability_zone: z.string().optional(), cost_per_gb_hour: z.number().optional(), cost_per_iops_hour: z.number().optional(), cost_per_throughput_mbps_hour: z.number().optional(), created_at: z.string().optional(), currency: z.string().optional(), id: z.string().optional(), max_capacity_gb: z.number().optional(), max_iops: z.number().optional(), max_throughput_mbps: z.number().optional(), min_capacity_gb: z.number().optional(), min_iops: z.number().optional(), min_throughput_mbps: z.number().optional(), native_cost_per_gb_hour: z.number().optional(), native_cost_per_iops_hour: z.number().optional(), native_cost_per_throughput_mbps_hour: z.number().optional(), period_billing_hours: z.number().optional(), provider: z.string().optional(), raw_pricing_data: z.object({}).optional(), region: z.string().optional(), service: z.string().optional(), tags: z.object({}).optional(), type: z.string().optional(), updated_at: z.string().optional(), usage_type: z.string().optional()}); export const registrationStatus = z.enum(["Registered", "Deleted"]); export const registeredDiskPrices = z.object({entries: z.array(diskPrice).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 disk provider * * POST /marketplace/providers/disks * * Also accepts auth: BearerAuth */ export const createApiMarketplaceProvidersDisks = async (args: CreateApiMarketplaceProvidersDisksArgs, options?: CreateApiMarketplaceProvidersDisksOptions) => { 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/disks${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(registeredDiskPrices, await res.json()) };