import {z} from 'zod' export type GetApiMarketplaceProvidersDatabasesArgs = {limit?: number | undefined, offset?: number | undefined, service?: string | undefined, region?: string | undefined, engine?: string | undefined, edition?: string | undefined, instance_type?: string | undefined, usage_type?: string | undefined}; export type GetApiMarketplaceProvidersDatabasesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const databasePrice = z.object({architecture: z.string().optional(), availability_zone: z.string().optional(), billing_config: z.string().optional(), capacity_unit: z.string().optional(), cost_per_capacity_unit: z.number().optional(), cost_per_hour: z.number().optional(), cost_per_io_request: z.number().optional(), cost_per_iops_hour: z.number().optional(), cost_per_storage_gb_hour: z.number().optional(), cost_per_throughput_mbps_hour: z.number().optional(), cost_per_vcpu_license_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(), deployment_option: z.string().optional(), edition: z.string().optional(), engine: z.string().optional(), id: z.string().optional(), instance_type: z.string().optional(), max_iops: z.number().optional(), max_storage_gb: z.number().optional(), max_throughput_mbps: z.number().optional(), min_iops: z.number().optional(), min_storage_gb: z.number().optional(), min_throughput_mbps: z.number().optional(), native_cost_per_hour: z.number().optional(), native_cost_per_storage_gb_hour: z.number().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(), service: z.string().optional(), storage_type: z.string().optional(), tags: z.object({}).optional(), updated_at: z.string().optional(), usage_type: z.string().optional()}); export const databasePriceList = z.object({providers: z.array(databasePrice).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 database pricing entries * * GET /marketplace/providers/databases * * Also accepts auth: BearerAuth */ export const getApiMarketplaceProvidersDatabases = async (args: GetApiMarketplaceProvidersDatabasesArgs, options?: GetApiMarketplaceProvidersDatabasesOptions) => { 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.engine != null) query.append("engine", String(args.engine)) if (args.edition != null) query.append("edition", String(args.edition)) 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/databases${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(databasePriceList, await res.json()) };