import {z} from 'zod' export type GetApiApi3SolutionsIdSupersedesArgs = {id: string}; export type GetApiApi3SolutionsIdSupersedesOptions = {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 additionalInformation = z.object({html: z.string().optional(), text: z.string().optional()}); export const steps = z.object({html: z.string().optional(), text: z.string().optional()}); export const summary = z.object({html: z.string().optional(), text: z.string().optional()}); export const solution = z.object({additionalInformation: additionalInformation.optional(), appliesTo: z.string().optional(), estimate: z.string().optional(), fixAvailable: z.boolean().optional(), id: z.object({}).optional(), links: z.array(link), steps: steps.optional(), summary: summary.optional(), type: z.enum(["configuration", "rollup-patch", "patch", "unknown"]).optional()}); export const collectionModelSolution = z.object({links: z.array(link), resources: z.array(solution).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 }; /** * Superseded Solutions * * GET /api/3/solutions/{id}/supersedes */ export const getApiApi3SolutionsIdSupersedes = async (args: GetApiApi3SolutionsIdSupersedesArgs, options?: GetApiApi3SolutionsIdSupersedesOptions) => { const {baseUrl = "https://:", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json;charset=UTF-8") const url = `${baseUrl.replace(/\/+$/, '')}/api/3/solutions/${encodeURIComponent(String(args.id))}/supersedes${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(collectionModelSolution, await res.json()) };