import {z} from 'zod' export type GetApiOrgsOrgNameTeamsArgs = {org_name: string, search?: Array | undefined, name?: Array | undefined, member?: Array | undefined, page?: number | undefined, 'per-page'?: number | undefined}; export type GetApiOrgsOrgNameTeamsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const team = z.object({name: z.string(), description: z.string().optional(), id: z.string(), slug: z.string(), member_count: z.number().int().optional()}); export const teamList = z.object({page: z.number().int(), per_page: z.number().int(), next_page: z.number().int().optional(), page_count: z.number().int(), total_count: z.number().int(), resources: z.array(team)}); 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 Teams * * GET /orgs/{org_name}/teams */ export const getApiOrgsOrgNameTeams = async (args: GetApiOrgsOrgNameTeamsArgs, options: GetApiOrgsOrgNameTeamsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.search ?? []) query.append("search", String(item)) for (const item of args.name ?? []) query.append("name", String(item)) for (const item of args.member ?? []) query.append("member", String(item)) if (args.page != null) query.append("page", String(args.page)) if (args['per-page'] != null) query.append("per-page", String(args['per-page'])) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.org_name))}/teams${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(teamList, await res.json()) };