import {z} from 'zod' export type GetApiProjectsProjectNameOrIdMembersArgs = {'X-Request-Id'?: string | undefined, 'X-Is-Resource-Name'?: boolean | undefined, project_name_or_id: string, page?: number | undefined, page_size?: number | undefined, entityname?: string | undefined}; export type GetApiProjectsProjectNameOrIdMembersOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const projectMemberEntity = z.object({id: z.number().int().optional(), project_id: z.number().int().optional(), entity_name: z.string().optional(), role_name: z.string().optional(), role_id: z.number().int().optional(), entity_id: z.number().int().optional(), entity_type: z.string().optional()}); export const getApiProjectsProjectNameOrIdMembersResponse = z.array(projectMemberEntity); 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 }; /** * Get all project member information * * GET /projects/{project_name_or_id}/members */ export const getApiProjectsProjectNameOrIdMembers = async (args: GetApiProjectsProjectNameOrIdMembersArgs, options?: GetApiProjectsProjectNameOrIdMembersOptions) => { const {baseUrl = "http://localhost/api/v2.0", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (args['X-Is-Resource-Name'] != null) headers.set("X-Is-Resource-Name", String(args['X-Is-Resource-Name'])) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.entityname != null) query.append("entityname", String(args.entityname)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_name_or_id))}/members${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(getApiProjectsProjectNameOrIdMembersResponse, await res.json()) };