import {z} from 'zod' export type FundingCreate = {id?: number | undefined, title?: string | undefined}; 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 TimelineUpdate = {firstOnline?: string | undefined, publisherPublication?: string | undefined, publisherAcceptance?: string | undefined}; export type CollectionUpdate = {funding?: string | undefined, funding_list?: Array | undefined, title?: string | undefined, description?: string | undefined, articles?: Array | undefined, authors?: Array> | undefined, categories?: Array | undefined, categories_by_source_id?: Array | undefined, tags?: Array | undefined, keywords?: Array | undefined, references?: Array | undefined, related_materials?: Array | undefined, custom_fields?: Record | undefined, custom_fields_list?: Array | undefined, doi?: string | undefined, handle?: string | undefined, resource_id?: string | undefined, resource_doi?: string | undefined, resource_link?: string | undefined, resource_title?: string | undefined, resource_version?: number | undefined, group_id?: number | undefined, timeline?: TimelineUpdate | undefined}; export type UpdateApiAccountCollectionsCollectionIdArgs = {collection_id: number, body: CollectionUpdate}; export type UpdateApiAccountCollectionsCollectionIdOptions = {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 }; /** * Update collection * * PUT /account/collections/{collection_id} */ export const updateApiAccountCollectionsCollectionId = async (args: UpdateApiAccountCollectionsCollectionIdArgs, options?: UpdateApiAccountCollectionsCollectionIdOptions) => { 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/collections/${encodeURIComponent(String(args.collection_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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()) };