import {z} from 'zod' export type SharedCredentialAccount = {service?: ('as400' | 'cifs' | 'cifshash' | 'cvs' | 'db2' | 'ftp' | 'http' | 'ms-sql' | 'mysql' | 'notes' | 'oracle' | 'oracle-service-name' | 'pop' | 'postgresql' | 'remote-exec' | 'snmp' | 'snmpv3' | 'ssh' | 'ssh-key' | 'sybase' | 'telnet' | 'kerberos' | 'hana' | 'scan-assistant' | 'vmware') | undefined}; export type SharedCredential = {account: SharedCredentialAccount, description?: string | undefined, hostRestriction?: string | undefined, id?: number | undefined, name: string, portRestriction?: number | undefined, siteAssignment: string, sites?: Array | undefined}; export type UpdateApiApi3SharedCredentialsIdArgs = {id: number, body: SharedCredential}; export type UpdateApiApi3SharedCredentialsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({deprecation: z.string().optional(), href: z.string().optional(), hreflang: z.string().optional(), media: z.string().optional(), rel: z.string().optional(), title: z.string().optional(), type: z.string().optional()}); export const links = z.object({links: z.array(link).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 }; /** * Shared Credential * * PUT /api/3/shared_credentials/{id} */ export const updateApiApi3SharedCredentialsId = async (args: UpdateApiApi3SharedCredentialsIdArgs, options?: UpdateApiApi3SharedCredentialsIdOptions) => { const {baseUrl = "https://:", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json;charset=UTF-8") const url = `${baseUrl.replace(/\/+$/, '')}/api/3/shared_credentials/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(links, await res.json()) };