import {z} from 'zod' export type UnifiedFilestorageFolderInput = {name: string | null, size: string | null, folder_url: string | null, description: string, drive_id: string | null, parent_folder_id: string | null, shared_link: string | null, permission: string | null, field_mappings?: ({[key: string]: unknown} | null) | undefined}; export type CreateApiFilestorageFoldersArgs = {'x-connection-token': string, remote_data?: boolean | undefined, body: UnifiedFilestorageFolderInput}; export type CreateApiFilestorageFoldersOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const unifiedFilestorageFolderOutput = z.object({name: z.string().nullable(), size: z.string().nullable(), folder_url: z.string().nullable(), description: z.string(), drive_id: z.string().nullable(), parent_folder_id: z.string().nullable(), shared_link: z.string().nullable(), permission: z.string().nullable(), field_mappings: z.record(z.string(), z.unknown()).nullable().optional(), id: z.string().nullable().optional(), remote_id: z.string().nullable().optional(), remote_data: z.record(z.string(), z.unknown()).nullable().optional(), created_at: z.string().nullable().optional(), modified_at: 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 }; /** * Create Folders * * POST /filestorage/folders */ export const createApiFilestorageFolders = async (args: CreateApiFilestorageFoldersArgs, options?: CreateApiFilestorageFoldersOptions) => { const {baseUrl = "https://api.panora.dev", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-connection-token'] != null) headers.set("x-connection-token", String(args['x-connection-token'])) if (args.remote_data != null) query.append("remote_data", String(args.remote_data)) if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/filestorage/folders${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(unifiedFilestorageFolderOutput, await res.json()) };