import {z} from 'zod' export type Metadata = Record; export type ModifiedBy = string | null; export type ModifiedAt = string | null; export type Grid = {row_types?: Array | undefined, default_row_type?: string | undefined, row_types_to_extract?: Array | undefined}; export type DatapointConstraintsRegex = {pattern?: string | undefined}; export type DatapointEnumOptionsItem = {value?: string | undefined, label?: string | undefined}; export type ContentDatapoint = {type?: 'string' | undefined, id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'datapoint' | undefined, can_export?: boolean | undefined, can_collapse?: boolean | undefined, rir_field_names?: Array | undefined, default_value?: (string | number | boolean | null) | undefined, ui_configuration?: ({type?: ('captured' | 'data' | 'manual' | 'formula' | 'reasoning' | 'lookup' | 'null' | null) | undefined, edit?: ('enabled' | 'disabled' | 'enabled_without_warning') | undefined}) | undefined, width?: number | undefined, stretch?: boolean | undefined, width_chars?: number | undefined, score_threshold?: number | undefined, formula?: string | undefined, prompt?: string | undefined, context?: Array | undefined, matching?: ({hook_interface?: string | undefined, type?: string | undefined, configuration?: Record | undefined}) | undefined, constraints?: ({length?: ({min?: (number | null) | undefined, max?: (number | null) | undefined, exact?: (number | null) | undefined}) | undefined, required?: boolean | undefined, regex?: DatapointConstraintsRegex | undefined}) | undefined} | {type?: 'number' | undefined, id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'datapoint' | undefined, can_export?: boolean | undefined, can_collapse?: boolean | undefined, rir_field_names?: Array | undefined, default_value?: (string | number | boolean | null) | undefined, ui_configuration?: ({type?: ('captured' | 'data' | 'manual' | 'formula' | 'reasoning' | 'lookup' | 'null' | null) | undefined, edit?: ('enabled' | 'disabled' | 'enabled_without_warning') | undefined}) | undefined, width?: number | undefined, stretch?: boolean | undefined, width_chars?: number | undefined, score_threshold?: number | undefined, formula?: string | undefined, prompt?: string | undefined, context?: Array | undefined, matching?: ({hook_interface?: string | undefined, type?: string | undefined, configuration?: Record | undefined}) | undefined, format?: string | undefined, aggregations?: ({sum?: ({label?: string | undefined}) | undefined}) | undefined, constraints?: ({length?: ({min?: (number | null) | undefined, max?: (number | null) | undefined, exact?: (number | null) | undefined}) | undefined, required?: boolean | undefined, regex?: DatapointConstraintsRegex | undefined}) | undefined} | {type?: 'date' | undefined, id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'datapoint' | undefined, can_export?: boolean | undefined, can_collapse?: boolean | undefined, rir_field_names?: Array | undefined, default_value?: (string | number | boolean | null) | undefined, ui_configuration?: ({type?: ('captured' | 'data' | 'manual' | 'formula' | 'reasoning' | 'lookup' | 'null' | null) | undefined, edit?: ('enabled' | 'disabled' | 'enabled_without_warning') | undefined}) | undefined, width?: number | undefined, stretch?: boolean | undefined, width_chars?: number | undefined, score_threshold?: number | undefined, formula?: string | undefined, prompt?: string | undefined, context?: Array | undefined, matching?: ({hook_interface?: string | undefined, type?: string | undefined, configuration?: Record | undefined}) | undefined, format?: string | undefined, constraints?: ({length?: ({min?: (number | null) | undefined, max?: (number | null) | undefined, exact?: (number | null) | undefined}) | undefined, required?: boolean | undefined, regex?: DatapointConstraintsRegex | undefined}) | undefined} | {type?: 'enum' | undefined, id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'datapoint' | undefined, can_export?: boolean | undefined, can_collapse?: boolean | undefined, rir_field_names?: Array | undefined, default_value?: (string | number | boolean | null) | undefined, ui_configuration?: ({type?: ('captured' | 'data' | 'manual' | 'formula' | 'reasoning' | 'lookup' | 'null' | null) | undefined, edit?: ('enabled' | 'disabled' | 'enabled_without_warning') | undefined}) | undefined, width?: number | undefined, stretch?: boolean | undefined, width_chars?: number | undefined, score_threshold?: number | undefined, formula?: string | undefined, prompt?: string | undefined, context?: Array | undefined, matching?: ({hook_interface?: string | undefined, type?: string | undefined, configuration?: Record | undefined}) | undefined, enum_value_type?: ('string' | 'number' | 'date') | undefined, constraints?: ({length?: ({min?: (number | null) | undefined, max?: (number | null) | undefined, exact?: (number | null) | undefined}) | undefined, required?: boolean | undefined, regex?: DatapointConstraintsRegex | undefined}) | undefined, options?: Array | undefined} | {type?: 'button' | undefined, id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'datapoint' | undefined, can_export?: boolean | undefined, can_collapse?: boolean | undefined, rir_field_names?: Array | undefined, default_value?: (string | number | boolean | null) | undefined, ui_configuration?: ({type?: ('captured' | 'data' | 'manual' | 'formula' | 'reasoning' | 'lookup' | 'null' | null) | undefined, edit?: ('enabled' | 'disabled' | 'enabled_without_warning') | undefined}) | undefined, width?: number | undefined, stretch?: boolean | undefined, width_chars?: number | undefined, score_threshold?: number | undefined, formula?: string | undefined, prompt?: string | undefined, context?: Array | undefined, matching?: ({hook_interface?: string | undefined, type?: string | undefined, configuration?: Record | undefined}) | undefined, popup_url?: string | undefined, can_obtain_token?: boolean | undefined, constraints?: ({length?: ({min?: (number | null) | undefined, max?: (number | null) | undefined, exact?: (number | null) | undefined}) | undefined, required?: boolean | undefined, regex?: DatapointConstraintsRegex | undefined}) | undefined}; export type ContentTuple = {id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'tuple' | undefined, rir_field_names?: Array | undefined, children?: Array | undefined}; export type Multivalue = {id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'multivalue' | undefined, min_occurrences?: (number | null) | undefined, max_occurrences?: (number | null) | undefined, show_grid_by_default?: boolean | undefined, rir_field_names?: (Array | null) | undefined, grid?: Grid | undefined, children?: (ContentTuple | ContentDatapoint) | undefined}; export type Section = {id?: string | undefined, label?: string | undefined, hidden?: boolean | undefined, disable_prediction?: boolean | undefined, category?: 'section' | undefined, icon?: (string | null) | undefined, children?: (Array) | undefined}; export type SchemaBase = {id?: number | undefined, name?: string | undefined, url?: string | undefined, queues?: Array | undefined, metadata?: Metadata | undefined, modified_by?: ModifiedBy | undefined, modified_at?: ModifiedAt | undefined, content?: Array
| undefined}; export type PatchApiApiV1SchemasSchemaIDArgs = {schemaID: number, body: SchemaBase}; export type PatchApiApiV1SchemasSchemaIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.object({}); export const modifiedBy = z.string().nullable(); export const modifiedAt = z.string().nullable(); export const grid = z.object({row_types: z.array(z.string()).optional(), default_row_type: z.string().optional(), row_types_to_extract: z.array(z.string()).optional()}); export const datapointConstraintsRegex = z.object({pattern: z.string().optional()}); export const datapointEnumOptionsItem = z.object({value: z.string().optional(), label: z.string().optional()}); export const contentDatapoint = z.union([z.object({type: z.literal("string").optional(), id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("datapoint").optional(), can_export: z.boolean().optional(), can_collapse: z.boolean().optional(), rir_field_names: z.array(z.string()).optional(), default_value: z.union([z.string(), z.number(), z.boolean()]).nullable().optional(), ui_configuration: z.object({type: z.enum(["captured", "data", "manual", "formula", "reasoning", "lookup", "null"]).nullable().optional(), edit: z.enum(["enabled", "disabled", "enabled_without_warning"]).optional()}).optional(), width: z.number().int().optional(), stretch: z.boolean().optional(), width_chars: z.number().int().optional(), score_threshold: z.number().gte(0).lte(1).optional(), formula: z.string().max(2000).optional(), prompt: z.string().max(5000).optional(), context: z.array(z.string()).optional(), matching: z.object({hook_interface: z.string().optional(), type: z.string().optional(), configuration: z.object({}).optional()}).optional(), constraints: z.object({length: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional(), exact: z.number().int().gte(0).nullable().optional()}).optional(), required: z.boolean().optional(), regex: datapointConstraintsRegex.optional()}).optional()}), z.object({type: z.literal("number").optional(), id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("datapoint").optional(), can_export: z.boolean().optional(), can_collapse: z.boolean().optional(), rir_field_names: z.array(z.string()).optional(), default_value: z.union([z.string(), z.number(), z.boolean()]).nullable().optional(), ui_configuration: z.object({type: z.enum(["captured", "data", "manual", "formula", "reasoning", "lookup", "null"]).nullable().optional(), edit: z.enum(["enabled", "disabled", "enabled_without_warning"]).optional()}).optional(), width: z.number().int().optional(), stretch: z.boolean().optional(), width_chars: z.number().int().optional(), score_threshold: z.number().gte(0).lte(1).optional(), formula: z.string().max(2000).optional(), prompt: z.string().max(5000).optional(), context: z.array(z.string()).optional(), matching: z.object({hook_interface: z.string().optional(), type: z.string().optional(), configuration: z.object({}).optional()}).optional(), format: z.string().optional(), aggregations: z.object({sum: z.object({label: z.string().optional()}).optional()}).optional(), constraints: z.object({length: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional(), exact: z.number().int().gte(0).nullable().optional()}).optional(), required: z.boolean().optional(), regex: datapointConstraintsRegex.optional()}).optional()}), z.object({type: z.literal("date").optional(), id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("datapoint").optional(), can_export: z.boolean().optional(), can_collapse: z.boolean().optional(), rir_field_names: z.array(z.string()).optional(), default_value: z.union([z.string(), z.number(), z.boolean()]).nullable().optional(), ui_configuration: z.object({type: z.enum(["captured", "data", "manual", "formula", "reasoning", "lookup", "null"]).nullable().optional(), edit: z.enum(["enabled", "disabled", "enabled_without_warning"]).optional()}).optional(), width: z.number().int().optional(), stretch: z.boolean().optional(), width_chars: z.number().int().optional(), score_threshold: z.number().gte(0).lte(1).optional(), formula: z.string().max(2000).optional(), prompt: z.string().max(5000).optional(), context: z.array(z.string()).optional(), matching: z.object({hook_interface: z.string().optional(), type: z.string().optional(), configuration: z.object({}).optional()}).optional(), format: z.string().optional(), constraints: z.object({length: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional(), exact: z.number().int().gte(0).nullable().optional()}).optional(), required: z.boolean().optional(), regex: datapointConstraintsRegex.optional()}).optional()}), z.object({type: z.literal("enum").optional(), id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("datapoint").optional(), can_export: z.boolean().optional(), can_collapse: z.boolean().optional(), rir_field_names: z.array(z.string()).optional(), default_value: z.union([z.string(), z.number(), z.boolean()]).nullable().optional(), ui_configuration: z.object({type: z.enum(["captured", "data", "manual", "formula", "reasoning", "lookup", "null"]).nullable().optional(), edit: z.enum(["enabled", "disabled", "enabled_without_warning"]).optional()}).optional(), width: z.number().int().optional(), stretch: z.boolean().optional(), width_chars: z.number().int().optional(), score_threshold: z.number().gte(0).lte(1).optional(), formula: z.string().max(2000).optional(), prompt: z.string().max(5000).optional(), context: z.array(z.string()).optional(), matching: z.object({hook_interface: z.string().optional(), type: z.string().optional(), configuration: z.object({}).optional()}).optional(), enum_value_type: z.enum(["string", "number", "date"]).optional(), constraints: z.object({length: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional(), exact: z.number().int().gte(0).nullable().optional()}).optional(), required: z.boolean().optional(), regex: datapointConstraintsRegex.optional()}).optional(), options: z.array(datapointEnumOptionsItem).optional()}), z.object({type: z.literal("button").optional(), id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("datapoint").optional(), can_export: z.boolean().optional(), can_collapse: z.boolean().optional(), rir_field_names: z.array(z.string()).optional(), default_value: z.union([z.string(), z.number(), z.boolean()]).nullable().optional(), ui_configuration: z.object({type: z.enum(["captured", "data", "manual", "formula", "reasoning", "lookup", "null"]).nullable().optional(), edit: z.enum(["enabled", "disabled", "enabled_without_warning"]).optional()}).optional(), width: z.number().int().optional(), stretch: z.boolean().optional(), width_chars: z.number().int().optional(), score_threshold: z.number().gte(0).lte(1).optional(), formula: z.string().max(2000).optional(), prompt: z.string().max(5000).optional(), context: z.array(z.string()).optional(), matching: z.object({hook_interface: z.string().optional(), type: z.string().optional(), configuration: z.object({}).optional()}).optional(), popup_url: z.string().optional(), can_obtain_token: z.boolean().optional(), constraints: z.object({length: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional(), exact: z.number().int().gte(0).nullable().optional()}).optional(), required: z.boolean().optional(), regex: datapointConstraintsRegex.optional()}).optional()})]); export const contentTuple = z.object({id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("tuple").optional(), rir_field_names: z.array(z.string()).optional(), children: z.array(contentDatapoint).optional()}); export const multivalue = z.object({id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("multivalue").optional(), min_occurrences: z.number().int().gte(0).nullable().optional(), max_occurrences: z.number().int().gte(1).nullable().optional(), show_grid_by_default: z.boolean().optional(), rir_field_names: z.array(z.string()).nullable().optional(), grid: grid.optional(), children: z.union([contentTuple, contentDatapoint]).optional()}); export const section = z.object({id: z.string().max(50).optional(), label: z.string().optional(), hidden: z.boolean().optional(), disable_prediction: z.boolean().optional(), category: z.literal("section").optional(), icon: z.string().nullable().optional(), children: z.array(z.union([multivalue, contentDatapoint])).optional()}); export const schema = z.object({id: z.number().int(), name: z.string(), url: z.string(), queues: z.array(z.string()), metadata: metadata, modified_by: modifiedBy, modified_at: modifiedAt, content: z.array(section)}); 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 schema * * PATCH /api/v1/schemas/{schemaID} */ export const patchApiApiV1SchemasSchemaID = async (args: PatchApiApiV1SchemasSchemaIDArgs, options?: PatchApiApiV1SchemasSchemaIDOptions) => { const {baseUrl = "https://example.rossum.app", 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/schemas/${encodeURIComponent(String(args.schemaID))}${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(schema, await res.json()) };