import {z} from 'zod' export type Organization = {type?: string | undefined, id?: string | undefined, attributes?: ({description?: string | undefined, disabled?: boolean | undefined, name?: string | undefined}) | undefined, relationships?: ({globalvar?: ({id?: string | undefined, type?: 'globalvar' | undefined}) | undefined, job?: ({id?: string | undefined, type?: 'job' | undefined}) | undefined, module?: ({id?: string | undefined, type?: 'module' | undefined}) | undefined, provider?: ({id?: string | undefined, type?: 'provider' | undefined}) | undefined, ssh?: ({id?: string | undefined, type?: 'ssh' | undefined}) | undefined, team?: ({id?: string | undefined, type?: 'team' | undefined}) | undefined, template?: ({id?: string | undefined, type?: 'template' | undefined}) | undefined, vcs?: ({id?: string | undefined, type?: 'vcs' | undefined}) | undefined, workspace?: ({id?: string | undefined, type?: 'workspace' | undefined}) | undefined}) | undefined}; export type CreateApiTemplateTemplateIdOrganizationArgs = {body: {data?: Organization | undefined}}; export type CreateApiTemplateTemplateIdOrganizationOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const organization = z.object({type: z.string().optional(), id: z.string().optional(), attributes: z.object({description: z.string().optional(), disabled: z.boolean().optional(), name: z.string().optional()}).optional(), relationships: z.object({globalvar: z.object({id: z.string().optional(), type: z.literal("globalvar").optional()}).optional(), job: z.object({id: z.string().optional(), type: z.literal("job").optional()}).optional(), module: z.object({id: z.string().optional(), type: z.literal("module").optional()}).optional(), provider: z.object({id: z.string().optional(), type: z.literal("provider").optional()}).optional(), ssh: z.object({id: z.string().optional(), type: z.literal("ssh").optional()}).optional(), team: z.object({id: z.string().optional(), type: z.literal("team").optional()}).optional(), template: z.object({id: z.string().optional(), type: z.literal("template").optional()}).optional(), vcs: z.object({id: z.string().optional(), type: z.literal("vcs").optional()}).optional(), workspace: z.object({id: z.string().optional(), type: z.literal("workspace").optional()}).optional()}).optional()}); export const createApiTemplateTemplateIdOrganizationResponse = z.object({data: organization.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 organization and adds it to organization * * POST /template/{templateId}/organization */ export const createApiTemplateTemplateIdOrganization = async (args: CreateApiTemplateTemplateIdOrganizationArgs, options: CreateApiTemplateTemplateIdOrganizationOptions) => { 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(/\/+$/, '')}/template/${encodeURIComponent(String(args.templateId))}/organization${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(createApiTemplateTemplateIdOrganizationResponse, await res.json()) };