import {z} from 'zod' export type BmcImportConfigurationRequest = {file?: string | undefined, shutdown_type?: string | undefined}; export type CreateApiV1BmcConfigureImportArgs = {nodeset?: string | undefined, tags?: string | undefined, Accept?: string | undefined, body: BmcImportConfigurationRequest}; export type CreateApiV1BmcConfigureImportOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jobMessage = z.object({data: z.string().optional(), host: z.string().optional(), msg: z.string().optional(), redfish_error: z.object({code: z.string().optional(), error: z.object({"@Message.ExtendedInfo": z.array(z.object({Message: z.string().optional(), "MessageArgs.@odata.count": z.number().int().optional(), MessageId: z.string().optional(), "RelatedProperties.@odata.count": z.number().int().optional(), Resolution: z.string().optional(), Severity: z.string().optional()})).nullable().optional(), code: z.string().optional(), message: z.string().optional()}).optional()}).optional(), status: z.string().optional()}); export const createApiV1BmcConfigureImportResponse = z.array(jobMessage); 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 }; /** * bmc import configuration * * POST /v1/bmc/configure/import * * Also accepts auth: cookieAuth */ export const createApiV1BmcConfigureImport = async (args: CreateApiV1BmcConfigureImportArgs, options?: CreateApiV1BmcConfigureImportOptions) => { const {baseUrl = "https://127.0.0.1:8080", fetch: fetchFn = fetch, headerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.nodeset != null) query.append("nodeset", String(args.nodeset)) if (args.tags != null) query.append("tags", String(args.tags)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (headerAuth !== undefined) headers.set('authorization', `Bearer ${headerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bmc/configure/import${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(createApiV1BmcConfigureImportResponse, await res.json()) };