import {z} from 'zod' export type CreateApiApiPreviewImportRunsArgs = {ws?: string | undefined, body: {configuration: {confirm_exposure?: boolean | undefined, mark_incomplete?: boolean | undefined, sources: Array<{create_type?: ({field_schema?: (Array<{columns?: (Array<{enum_values?: Array | undefined, name: string, precision?: number | undefined, required?: boolean | undefined, required_message?: string | undefined, rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, type: 'text' | 'number' | 'date' | 'datetime' | 'enum' | 'boolean', unit?: string | undefined}>) | undefined, derived?: ({column: string, op: 'sum' | 'avg' | 'min' | 'max' | 'count', source: string}) | undefined, enum_values?: Array | undefined, item_rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, name: string, precision?: number | undefined, reference_type_slug?: string | undefined, required?: boolean | undefined, required_message?: string | undefined, rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, type: 'text' | 'paragraph' | 'number' | 'datetime' | 'date' | 'boolean' | 'enum' | 'multi_enum' | 'reference' | 'multi_reference' | 'list' | 'table' | 'image' | 'file', unit?: string | undefined}>) | undefined, guidance?: string | undefined, name: string, slug?: string | undefined, summary?: string | undefined}) | undefined, source_type_slug: string, target_type_id?: string | undefined}>}, descriptors: Array<{bytes: number, index: number, sha256: string, source_type_slug: string}>, item_count: number, workspace_id?: (string | null) | undefined}}; export type CreateApiApiPreviewImportRunsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewImportRunsResponse = z.object({requires_review: z.boolean().optional(), run: z.object({expected_chunks: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), expires_at: z.string().optional(), finalized: z.record(z.string(), z.unknown()).nullable().optional(), id: z.string().max(36), revision: z.number().int().gte(-9007199254740991).lte(9007199254740991), selection_digest: z.string().max(64), uploaded_indexes: z.array(z.number().int().gte(-9007199254740991).lte(9007199254740991)).optional()}).and(z.record(z.string(), z.unknown())).optional()}).and(z.record(z.string(), 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 }; /** * Stage a complete selected Symbol export for one human review; unprotected selections use ordinary import * * POST /api/preview/import/runs * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewImportRuns = async (args: CreateApiApiPreviewImportRunsArgs, options: CreateApiApiPreviewImportRunsOptions) => { const {baseUrl, 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 (args.ws != null) query.append("ws", String(args.ws)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/import/runs${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(createApiApiPreviewImportRunsResponse, await res.json()) };