import {z} from 'zod' export type GetApiRegistriesRegistryNameMaintainersArgs = {registryName: string, page?: number | undefined, per_page?: number | undefined, created_after?: string | undefined, updated_after?: string | undefined, sort?: ('login' | 'packages_count' | 'updated_at' | 'created_at' | 'name' | 'uuid') | undefined, order?: string | undefined}; export type GetApiRegistriesRegistryNameMaintainersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const maintainer = z.object({uuid: z.string(), login: z.string().nullable(), name: z.string().nullable(), email: z.string().nullable(), url: z.string().nullable(), created_at: z.string(), updated_at: z.string(), packages_count: z.number().int(), packages_url: z.string(), total_downloads: z.number().int(), html_url: z.string().nullable(), role: z.string().nullable()}); export const getApiRegistriesRegistryNameMaintainersResponse = z.array(maintainer); 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 a list of maintainers from a registry * * GET /registries/{registryName}/maintainers */ export const getApiRegistriesRegistryNameMaintainers = async (args: GetApiRegistriesRegistryNameMaintainersArgs, options?: GetApiRegistriesRegistryNameMaintainersOptions) => { const {baseUrl = "https://packages.ecosyste.ms/api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) const url = `${baseUrl.replace(/\/+$/, '')}/registries/${encodeURIComponent(String(args.registryName))}/maintainers${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(getApiRegistriesRegistryNameMaintainersResponse, await res.json()) };