import {z} from 'zod' export type CreateApiV2CostformationDefinitionVersionsArgs = {'cloudzero-idempotency-key'?: string | undefined, 'cloudzero-test-key'?: string | undefined, validate_only?: string | undefined, namespace?: string | undefined, body: BodyInit}; export type CreateApiV2CostformationDefinitionVersionsOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const epoch = z.string(); export const costformationDefinitionVersionWithUrl = z.object({version: z.string(), last_updated: epoch.optional(), last_updated_by: z.string().optional(), uri: z.string()}); export const createApiV2CostformationDefinitionVersionsResponse = z.union([z.object({version: costformationDefinitionVersionWithUrl.optional()}), z.object({})]); 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 a new CloudZero CostFormation Definition version. Ten (10) MB is the general payload size limitation and it cannot be raised. For more information, see the [Sample Python CostFormation Script](https://docs.cloudzero.com/docs/sample-python-costformation-script). * * POST /v2/costformation/definition/versions */ export const createApiV2CostformationDefinitionVersions = async (args: CreateApiV2CostformationDefinitionVersionsArgs, options?: CreateApiV2CostformationDefinitionVersionsOptions) => { const {baseUrl = "https://api.cloudzero.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['cloudzero-idempotency-key'] != null) headers.set("cloudzero-idempotency-key", String(args['cloudzero-idempotency-key'])) if (args['cloudzero-test-key'] != null) headers.set("cloudzero-test-key", String(args['cloudzero-test-key'])) if (args.validate_only != null) query.append("validate_only", String(args.validate_only)) if (args.namespace != null) query.append("namespace", String(args.namespace)) if (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/costformation/definition/versions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV2CostformationDefinitionVersionsResponse, await res.json()) };