import {z} from 'zod' export type FileTypes = 'application/pdf' | 'application/json' | 'text/xml' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/msword' | 'text/plain' | 'text/csv' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/vnd.ms-powerpoint' | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' | 'application/zip' | 'URL' | 'IMAGE' | 'application/vnd.google-apps.document' | 'text/markdown' | 'application/epub+zip' | 'application/mbox' | 'application/rtf' | 'text/html' | 'application/vnd.google-apps.spreadsheet'; export type GetApiConversationsSharedExportZapierArgs = {type?: FileTypes | undefined, user_tz?: string | undefined, last_n_hours?: number | undefined, kb_name?: string | undefined}; export type GetApiConversationsSharedExportZapierOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiConversationsSharedExportZapierResponse = 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 Conversation Zapier * * GET /conversations/shared/export/zapier * * Also accepts auth: OAuth2PasswordBearer */ export const getApiConversationsSharedExportZapier = async (args: GetApiConversationsSharedExportZapierArgs, options: GetApiConversationsSharedExportZapierOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.user_tz != null) query.append("user_tz", String(args.user_tz)) if (args.last_n_hours != null) query.append("last_n_hours", String(args.last_n_hours)) if (args.kb_name != null) query.append("kb_name", String(args.kb_name)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/conversations/shared/export/zapier${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(getApiConversationsSharedExportZapierResponse, await res.json()) };