import {z} from 'zod' export type GetApiV1BmcUpgradeDellRepoArgs = {nodeset?: string | undefined, tags?: string | undefined, Accept?: string | undefined}; export type GetApiV1BmcUpgradeDellRepoOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const redfishDellUpgradeFirmware = z.object({Message: z.string().optional(), Name: z.string().optional(), Status: z.string().optional(), UpdateCount: z.number().int().optional(), UpdateList: z.array(z.object({BaseLocation: z.string().optional(), ComponentID: z.string().optional(), ComponentInfoName: z.string().optional(), ComponentInfoValue: z.string().optional(), ComponentType: z.string().optional(), Criticality: z.string().optional(), DisplayName: z.string().optional(), InstalledVersion: z.string().optional(), JobID: z.string().optional(), Name: z.string().optional(), PackageName: z.string().optional(), PackagePath: z.string().optional(), PackageVersion: z.string().optional(), RebootType: z.string().optional(), Target: z.string().optional()}).nullable()).nullable().optional(), UpdateRebootType: z.string().optional()}); export const getApiV1BmcUpgradeDellRepoResponse = z.array(redfishDellUpgradeFirmware); 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 dell get repo update list * * GET /v1/bmc/upgrade/dell/repo * * Also accepts auth: cookieAuth */ export const getApiV1BmcUpgradeDellRepo = async (args: GetApiV1BmcUpgradeDellRepoArgs, options?: GetApiV1BmcUpgradeDellRepoOptions) => { const {baseUrl = "https://127.0.0.1:8080", fetch: fetchFn = fetch, headerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/upgrade/dell/repo${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1BmcUpgradeDellRepoResponse, await res.json()) };