import {z} from 'zod' export type RelatedMaterial = {id?: number | undefined, identifier?: string | undefined, title?: string | undefined, relation?: ('IsCitedBy' | 'Cites' | 'IsSupplementTo' | 'IsSupplementedBy' | 'IsContinuedBy' | 'Continues' | 'Describes' | 'IsDescribedBy' | 'HasMetadata' | 'IsMetadataFor' | 'HasVersion' | 'IsVersionOf' | 'IsNewVersionOf' | 'IsPreviousVersionOf' | 'IsPartOf' | 'HasPart' | 'IsPublishedIn' | 'IsReferencedBy' | 'References' | 'IsDocumentedBy' | 'Documents' | 'IsCompiledBy' | 'Compiles' | 'IsVariantFormOf' | 'IsOriginalFormOf' | 'IsIdenticalTo' | 'IsReviewedBy' | 'Reviews' | 'IsDerivedFrom' | 'IsSourceOf' | 'IsRequiredBy' | 'Requires' | 'IsObsoletedBy' | 'Obsoletes') | undefined, identifier_type?: ('ARK' | 'arXiv' | 'bibcode' | 'DOI' | 'EAN13' | 'EISSN' | 'Handle' | 'IGSN' | 'ISBN' | 'ISSN' | 'ISTC' | 'LISSN' | 'LSID' | 'PMID' | 'PURL' | 'UPC' | 'URL' | 'URN' | 'w3id') | undefined, is_linkout?: boolean | undefined, link?: string | undefined}; export type CustomArticleFieldAdd = {name: string, value: string | Array | Record | null}; export type FundingCreate = {id?: number | undefined, title?: string | undefined}; export type TimelineUpdate = {firstOnline?: string | undefined, publisherPublication?: string | undefined, publisherAcceptance?: string | undefined}; export type ArticleUpdate = {title?: string | undefined, description?: string | undefined, is_metadata_record?: boolean | undefined, metadata_reason?: string | undefined, tags?: Array | undefined, keywords?: Array | undefined, references?: Array | undefined, related_materials?: Array | undefined, categories?: Array | undefined, categories_by_source_id?: Array | undefined, authors?: Array> | undefined, custom_fields?: Record | undefined, custom_fields_list?: Array | undefined, defined_type?: string | undefined, funding?: string | undefined, funding_list?: Array | undefined, license?: number | undefined, doi?: string | undefined, handle?: string | undefined, resource_doi?: string | undefined, resource_title?: string | undefined, timeline?: TimelineUpdate | undefined, download_disabled?: boolean | undefined, group_id?: number | undefined}; export type PatchApiAccountArticlesArticleIdArgs = {article_id: number, body: ArticleUpdate}; export type PatchApiAccountArticlesArticleIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const locationWarningsUpdate = z.object({location: z.string(), warnings: z.array(z.string())}); 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 }; /** * Partially update article * * PATCH /account/articles/{article_id} */ export const patchApiAccountArticlesArticleId = async (args: PatchApiAccountArticlesArticleIdArgs, options?: PatchApiAccountArticlesArticleIdOptions) => { const {baseUrl = "https://api.figshare.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/account/articles/${encodeURIComponent(String(args.article_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(locationWarningsUpdate, await res.json()) };