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 GetApiV2FolderContentsArgs = {teamId: string, itemType: SvflowPubapimodelsFolderItemType, folderId?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined}; export type GetApiV2FolderContentsOptions = {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 svflowPublicapiListFolderContentsResponse = z.object({data: z.array(svflowPubapimodelsFolderItem).optional(), nextPageToken: z.string().nullable().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 Folder Contents * * GET /v2/folder-contents */ export const getApiV2FolderContents = async (args: GetApiV2FolderContentsArgs, options?: GetApiV2FolderContentsOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.itemType != null) query.append("itemType", String(args.itemType)) if (args.folderId != null) query.append("folderId", String(args.folderId)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/folder-contents${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(svflowPublicapiListFolderContentsResponse, await res.json()) };