import {z} from 'zod' export type IamV1CreateMenuRequest = {code?: string | undefined, component?: string | undefined, external?: boolean | undefined, icon?: string | undefined, keepAlive?: boolean | undefined, name?: string | undefined, parentId?: string | undefined, path?: string | undefined, permCode?: string | undefined, redirect?: string | undefined, sortOrder?: number | undefined, type?: number | undefined, visible?: boolean | undefined}; export type CreateApiV1IamMenusArgs = {body: IamV1CreateMenuRequest}; export type CreateApiV1IamMenusOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const iamV1Menu: z.ZodType = z.object({children: z.array(z.lazy(() => iamV1Menu)).optional(), code: z.string().optional(), component: z.string().optional(), createdAt: z.string().optional(), external: z.boolean().optional(), icon: z.string().optional(), id: z.string().optional(), isBuiltin: z.boolean().optional(), keepAlive: z.boolean().optional(), name: z.string().optional(), parentId: z.string().optional(), path: z.string().optional(), permCode: z.string().optional(), redirect: z.string().optional(), sortOrder: z.number().int().optional(), status: z.number().int().optional(), type: z.number().int().optional(), updatedAt: z.string().optional(), visible: z.boolean().optional()}); export const iamV1CreateMenuReply = z.object({menu: iamV1Menu.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 }; /** * CreateMenu 创建菜单。code/name 必填,code 唯一;visible 不传时默认为 true。 * * POST /v1/iam/menus */ export const createApiV1IamMenus = async (args: CreateApiV1IamMenusArgs, options: CreateApiV1IamMenusOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/iam/menus${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(iamV1CreateMenuReply, await res.json()) };