import {z} from 'zod' export type DocumentFieldCreate = {document_type: string, 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', text_unit_type?: ('sentence' | 'paragraph' | 'section') | undefined, value_detection_strategy?: ('disabled' | 'use_regexps_only' | 'use_formula_only' | 'regexp_table' | 'text_based_ml_only' | '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, confidence?: ('High' | 'Medium' | 'Low' | null) | undefined, requires_text_annotations?: boolean | undefined, read_only?: boolean | undefined, category?: (number | null) | undefined, family?: (number | null) | undefined, default_value?: (Record | null) | undefined, choices?: (string | null) | 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, display_yes_no?: boolean | 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, warning_message?: string | undefined}; export type PatchApiApiV1DocumentDocumentFieldsUidArgs = {uid: string, body: DocumentFieldCreate}; export type PatchApiApiV1DocumentDocumentFieldsUidOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentFieldCreate = z.object({document_type: z.string(), code: z.string().max(50), long_code: z.string().max(150).optional(), title: z.string().max(100), description: z.string().nullable().optional(), type: z.enum(["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"]), text_unit_type: z.enum(["sentence", "paragraph", "section"]).optional(), value_detection_strategy: z.enum(["disabled", "use_regexps_only", "use_formula_only", "regexp_table", "text_based_ml_only", "mlflow_model"]).optional(), classifier_init_script: z.string().nullable().optional(), formula: z.string().nullable().optional(), convert_decimals_to_floats_in_formula_args: z.boolean().optional(), value_regexp: z.string().nullable().optional(), depends_on_fields: z.array(z.string()).optional(), confidence: z.enum(["High", "Medium", "Low"]).nullable().optional(), requires_text_annotations: z.boolean().optional(), read_only: z.boolean().optional(), category: z.number().int().nullable().optional(), family: z.number().int().nullable().optional(), default_value: z.object({}).nullable().optional(), choices: z.string().nullable().optional(), allow_values_not_specified_in_choices: z.boolean().optional(), metadata: z.object({}).nullable().optional(), training_finished: z.boolean().optional(), dirty: z.boolean().optional(), order: z.number().int().gte(0).lte(32767).optional(), trained_after_documents_number: z.number().int().gte(1).lte(2147483647).optional(), hidden_always: z.boolean().optional(), hide_until_python: z.string().nullable().optional(), hide_until_js: z.string().nullable().optional(), display_yes_no: z.boolean().optional(), vectorizer_stop_words: z.string().nullable().optional(), unsure_choice_value: z.string().max(256).nullable().optional(), unsure_thresholds_by_value: z.object({}).nullable().optional(), mlflow_model_uri: z.string().max(1024).nullable().optional(), mlflow_detect_on_document_level: z.boolean().optional(), warning_message: z.string().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 }; /** * Partial Update Document Field * * PATCH /api/v1/document/document-fields/{uid}/ */ export const patchApiApiV1DocumentDocumentFieldsUid = async (args: PatchApiApiV1DocumentDocumentFieldsUidArgs, options: PatchApiApiV1DocumentDocumentFieldsUidOptions) => { 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))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(documentFieldCreate, await res.json()) };