import {z} from 'zod' export type GetApiAccountInstitutionReviewsArgs = {group_id?: number | undefined, article_id?: number | undefined, status?: ('pending' | 'approved' | 'rejected' | 'closed') | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiAccountInstitutionReviewsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const curation = z.object({id: z.number().int(), group_id: z.number().int(), account_id: z.number().int(), assigned_to: z.number().int(), article_id: z.number().int(), version: z.number().int(), comments_count: z.number().int(), status: z.enum(["pending", "approved", "rejected", "closed"]), created_date: z.string(), modified_date: z.string(), request_number: z.number().int(), resolution_comment: z.string(), review_date: z.string().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 }; /** * Institution Curation Reviews * * GET /account/institution/reviews */ export const getApiAccountInstitutionReviews = async (args: GetApiAccountInstitutionReviewsArgs, options?: GetApiAccountInstitutionReviewsOptions) => { const {baseUrl = "https://api.figshare.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.group_id != null) query.append("group_id", String(args.group_id)) if (args.article_id != null) query.append("article_id", String(args.article_id)) if (args.status != null) query.append("status", String(args.status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/account/institution/reviews${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(curation, await res.json()) };