import {z} from 'zod' export type GetApiApiV0MembersArgs = {company?: (string | null) | undefined, location?: (string | null) | undefined, ordering?: ('created_at' | '-created_at' | 'updated_at' | '-updated_at' | 'name' | '-name' | 'login' | '-login' | null) | undefined, page?: number | undefined, page_size?: number | undefined}; export type GetApiApiV0MembersOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const member = z.object({avatar_url: z.string(), created_at: z.string(), login: z.string(), name: z.string(), updated_at: z.string(), url: z.string()}); export const pagedMember = z.object({current_page: z.number().int(), has_next: z.boolean(), has_previous: z.boolean(), items: z.array(member), total_count: z.number().int(), total_pages: z.number().int()}); 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 }; /** * List members * * GET /api/v0/members/ */ export const getApiApiV0Members = async (args: GetApiApiV0MembersArgs, options?: GetApiApiV0MembersOptions) => { const {baseUrl = "https://nest.owasp.org", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.company != null) query.append("company", String(args.company)) if (args.location != null) query.append("location", String(args.location)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (ApiKey !== undefined) headers.set("X-API-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v0/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(pagedMember, await res.json()) };