import {z} from 'zod' export type GetApiCcV1GroupsNameGroupNameArgs = {groupName: string}; export type GetApiCcV1GroupsNameGroupNameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const group = z.object({id: z.number().int().optional(), name: z.string().optional(), groupType: z.string().optional(), subsystemId: z.number().int().optional(), subsystemName: z.string().optional(), remarks: z.string().optional(), enableFlag: z.number().int().optional(), departmentId: z.string().optional(), departmentName: z.string().optional(), clusterName: z.string().optional(), rmb_dcn: z.string().optional(), rmb_idc: z.string().optional(), service_id: z.number().int().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 }; /** * Returns a Group. * * GET /cc/v1/groups/name/{groupName} */ export const getApiCcV1GroupsNameGroupName = async (args: GetApiCcV1GroupsNameGroupNameArgs, options?: GetApiCcV1GroupsNameGroupNameOptions) => { const {baseUrl = "https://gateway.mlss.cc", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/cc/v1/groups/name/${encodeURIComponent(String(args.groupName))}${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(group, await res.json()) };