import {z} from 'zod' export type DocumentFieldDetail = {uid?: string | undefined, document_type: string, document_type__title?: string | undefined, code: string, long_code?: string | undefined, title: string, description?: (string | null) | undefined, type?: ('address' | 'choice' | 'company' | 'date' | 'date_recurring' | 'datetime' | 'duration' | 'float' | 'geography' | 'int' | 'linked_documents' | 'money' | 'multi_choice' | 'percent' | 'person' | 'ratio' | 'related_info' | 'string' | 'string_no_word_wrap' | 'text') | undefined, text_unit_type?: ('sentence' | 'paragraph' | 'section') | undefined, value_detection_strategy?: ('disabled' | 'use_regexps_only' | 'use_formula_only' | 'regexp_table' | 'text_based_ml_only' | 'fields_based_ml_only' | 'fields_based_prob_ml_only' | 'field_based_regexps' | 'mlflow_model') | undefined, classifier_init_script?: (string | null) | undefined, formula?: (string | null) | undefined, convert_decimals_to_floats_in_formula_args?: boolean | undefined, value_regexp?: (string | null) | undefined, depends_on_fields?: Array | undefined, value_detection_strategy_name?: string | undefined, confidence?: ('High' | 'Medium' | 'Low' | null) | undefined, requires_text_annotations?: boolean | undefined, read_only?: boolean | undefined, category?: string | undefined, family?: (number | null) | undefined, default_value?: (Record | null) | undefined, choices?: Array | undefined, allow_values_not_specified_in_choices?: boolean | undefined, metadata?: (Record | null) | undefined, training_finished?: boolean | undefined, dirty?: boolean | undefined, order?: number | undefined, trained_after_documents_number?: number | undefined, hidden_always?: boolean | undefined, hide_until_python?: (string | null) | undefined, hide_until_js?: (string | null) | undefined, is_value_detection_strategy_disabled?: boolean | undefined, display_yes_no?: boolean | undefined, value_aware?: boolean | undefined, created_by__name?: string | undefined, modified_by__name?: string | undefined, created_date?: string | undefined, modified_date?: string | undefined, vectorizer_stop_words?: (string | null) | undefined, unsure_choice_value?: (string | null) | undefined, unsure_thresholds_by_value?: (Record | null) | undefined, mlflow_model_uri?: (string | null) | undefined, mlflow_detect_on_document_level?: boolean | undefined}; export type CreateApiApiV1DocumentDocumentFieldsUidPreDeleteArgs = {uid: string, body: DocumentFieldDetail}; export type CreateApiApiV1DocumentDocumentFieldsUidPreDeleteOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1DocumentDocumentFieldsUidPreDeleteResponse = z.record(z.string(), z.object({})); 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 }; /** * Get info about related objects for ready-to-delete document type. * * POST /api/v1/document/document-fields/{uid}/pre_delete/ */ export const createApiApiV1DocumentDocumentFieldsUidPreDelete = async (args: CreateApiApiV1DocumentDocumentFieldsUidPreDeleteArgs, options: CreateApiApiV1DocumentDocumentFieldsUidPreDeleteOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/document/document-fields/${encodeURIComponent(String(args.uid))}/pre_delete/${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(createApiApiV1DocumentDocumentFieldsUidPreDeleteResponse, await res.json()) };