import {z} from 'zod' export type CxSastEngineServersApplicationContractsDTOsEngineServerDedicationDto = {itemType?: ('Scan' | 'Project' | 'Team') | undefined, itemId?: number | undefined}; export type CxSastEngineServersApplicationContractsModelsEngineServerPatchModelV5 = {dedications?: Array | undefined, name?: string | undefined, uri?: string | undefined, minLoc?: number | undefined, maxLoc?: number | undefined, isBlocked?: boolean | undefined, maxScans?: number | undefined}; export type PatchApiSastEngineServersIdArgs = {id: number, body: CxSastEngineServersApplicationContractsModelsEngineServerPatchModelV5}; export type PatchApiSastEngineServersIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const cxSuperTypesAPIDtosLinkDtoBase = z.object({rel: z.string().optional(), uri: z.string().optional()}); export const cxSuperTypesAPIDtosLinkedResource = z.object({id: z.number().int().optional(), link: cxSuperTypesAPIDtosLinkDtoBase.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 }; /** * Updates an Engine Server by edit single field * * PATCH /sast/engineServers/{id} */ export const patchApiSastEngineServersId = async (args: PatchApiSastEngineServersIdArgs, options?: PatchApiSastEngineServersIdOptions) => { const {baseUrl = "https://desktop-rmvpboc/cxrestapi/help", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json;v=5.0") headers.set('accept', "application/json;v=5.0") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/sast/engineServers/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(cxSuperTypesAPIDtosLinkedResource, await res.json()) };