import {z} from 'zod' export type SortType = 'asc' | 'desc'; export type Sort = {column: string, direction: SortType}; export type WorkspaceExportRequest = {filters?: (Array | null) | undefined, sort?: (Sort | null) | undefined, search?: (string | null) | undefined, column_ids?: (Array | null) | undefined, institution_ids?: (Array | null) | undefined}; export type CreateApiApiV3ExportWorkspacesWorkspaceIdArgs = {workspace_id: string, body: WorkspaceExportRequest}; export type CreateApiApiV3ExportWorkspacesWorkspaceIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV3ExportWorkspacesWorkspaceIdResponse = z.unknown(); 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 }; /** * Export Workspace Csv * * POST /api/v3/export/workspaces/{workspace_id} */ export const createApiApiV3ExportWorkspacesWorkspaceId = async (args: CreateApiApiV3ExportWorkspacesWorkspaceIdArgs, options: CreateApiApiV3ExportWorkspacesWorkspaceIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/export/workspaces/${encodeURIComponent(String(args.workspace_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiApiV3ExportWorkspacesWorkspaceIdResponse, await res.json()) };