import {z} from 'zod' export type SvflowPubapimodelsFolderItemType = 'FOLDER_ITEM_TYPE_UNSPECIFIED' | 'FOLDER_ITEM_TYPE_FOLDER' | 'FOLDER_ITEM_TYPE_WORKFLOW' | 'FOLDER_ITEM_TYPE_GUIDANCE'; export type SvflowPubapimodelsFolderItem = {itemType?: SvflowPubapimodelsFolderItemType | undefined, itemId?: string | undefined}; export type SvflowPublicapiSetFolderItemLocationRequest = {item: SvflowPubapimodelsFolderItem, folderId?: (string | null) | undefined}; export type UpdateApiV2FolderItemLocationsArgs = {body: SvflowPublicapiSetFolderItemLocationRequest}; export type UpdateApiV2FolderItemLocationsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svflowPubapimodelsFolderItemType = z.enum(["FOLDER_ITEM_TYPE_UNSPECIFIED", "FOLDER_ITEM_TYPE_FOLDER", "FOLDER_ITEM_TYPE_WORKFLOW", "FOLDER_ITEM_TYPE_GUIDANCE"]); export const svflowPubapimodelsFolderItem = z.object({itemType: svflowPubapimodelsFolderItemType.optional(), itemId: z.string().optional()}); export const svflowPubapimodelsFolderItemLocation = z.object({item: svflowPubapimodelsFolderItem.optional(), folderId: z.string().nullable().optional()}); export const svflowPublicapiSetFolderItemLocationResponse = z.object({data: svflowPubapimodelsFolderItemLocation.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 }; /** * Set Folder Item Location * * PUT /v2/folder-item-locations */ export const updateApiV2FolderItemLocations = async (args: UpdateApiV2FolderItemLocationsArgs, options?: UpdateApiV2FolderItemLocationsOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/folder-item-locations${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(svflowPublicapiSetFolderItemLocationResponse, await res.json()) };