import {z} from 'zod' export type GetApiProvidersPreprintsProviderIdCitationStylesArgs = {provider_id: string, 'filter[default]'?: boolean | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiProvidersPreprintsProviderIdCitationStylesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiProvidersPreprintsProviderIdCitationStylesResponse = z.object({data: z.array(z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({social_instagram: z.string().optional(), advisory_board: z.string().optional(), email_support: z.string().optional(), banner_path: z.string().optional(), logo_path: z.string().optional(), subjects_acceptable: z.string().optional(), description: z.string().optional(), social_facebook: z.string().optional(), email_contact: z.string().optional(), example: z.string().optional(), name: z.string().optional(), domain: z.string().optional(), domain_redirect_enabled: z.boolean().optional()}).optional(), relationships: z.object({licenses_acceptable: z.string().optional(), taxonomies: z.string().optional(), preprints: z.string().optional()}).optional(), links: z.object({external_url: z.string().optional(), preprints: z.string().optional(), self: z.string().optional()}).optional()})).optional(), links: z.object({self: z.string().optional(), next: z.string().optional(), prev: z.string().optional()}).optional(), meta: z.object({}).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 }; /** * List Citation Styles for a Preprint Provider * * GET /providers/preprints/{provider_id}/citation_styles/ */ export const getApiProvidersPreprintsProviderIdCitationStyles = async (args: GetApiProvidersPreprintsProviderIdCitationStylesArgs, options?: GetApiProvidersPreprintsProviderIdCitationStylesOptions) => { const {baseUrl = "https://api.test.osf.io/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['filter[default]'] != null) query.append("filter[default]", String(args['filter[default]'])) 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(/\/+$/, '')}/providers/preprints/${encodeURIComponent(String(args.provider_id))}/citation_styles/${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(getApiProvidersPreprintsProviderIdCitationStylesResponse, await res.json()) };