import {z} from 'zod' export type Workspace = {type?: string | undefined, id?: string | undefined, attributes?: ({branch?: string | undefined, description?: string | undefined, folder?: string | undefined, locked?: boolean | undefined, name?: string | undefined, source?: string | undefined, terraformVersion?: string | undefined}) | undefined, relationships?: ({history?: ({id?: string | undefined, type?: 'history' | undefined}) | undefined, job?: ({id?: string | undefined, type?: 'job' | undefined}) | undefined, organization?: ({id?: string | undefined, type?: 'organization' | undefined}) | undefined, schedule?: ({id?: string | undefined, type?: 'schedule' | undefined}) | undefined, ssh?: ({id?: string | undefined, type?: 'ssh' | undefined}) | undefined, variable?: ({id?: string | undefined, type?: 'variable' | undefined}) | undefined, vcs?: ({id?: string | undefined, type?: 'vcs' | undefined}) | undefined}) | undefined}; export type CreateApiOrganizationOrganizationIdWorkspaceArgs = {body: {data?: Workspace | undefined}}; export type CreateApiOrganizationOrganizationIdWorkspaceOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const workspace = z.object({type: z.string().optional(), id: z.string().optional(), attributes: z.object({branch: z.string().optional(), description: z.string().optional(), folder: z.string().optional(), locked: z.boolean().optional(), name: z.string().optional(), source: z.string().optional(), terraformVersion: z.string().optional()}).optional(), relationships: z.object({history: z.object({id: z.string().optional(), type: z.literal("history").optional()}).optional(), job: z.object({id: z.string().optional(), type: z.literal("job").optional()}).optional(), organization: z.object({id: z.string().optional(), type: z.literal("organization").optional()}).optional(), schedule: z.object({id: z.string().optional(), type: z.literal("schedule").optional()}).optional(), ssh: z.object({id: z.string().optional(), type: z.literal("ssh").optional()}).optional(), variable: z.object({id: z.string().optional(), type: z.literal("variable").optional()}).optional(), vcs: z.object({id: z.string().optional(), type: z.literal("vcs").optional()}).optional()}).optional()}); export const createApiOrganizationOrganizationIdWorkspaceResponse = z.object({data: workspace.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 }; /** * Creates an item of type workspace and adds it to workspace * * POST /organization/{organizationId}/workspace */ export const createApiOrganizationOrganizationIdWorkspace = async (args: CreateApiOrganizationOrganizationIdWorkspaceArgs, options: CreateApiOrganizationOrganizationIdWorkspaceOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") const url = `${baseUrl.replace(/\/+$/, '')}/organization/${encodeURIComponent(String(args.organizationId))}/workspace${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(createApiOrganizationOrganizationIdWorkspaceResponse, await res.json()) };