import {z} from 'zod' export type TextPart = {name: string, content: string}; export type ReconciliationTextUpdateRequest = {name?: string | undefined, name_en?: string | undefined, name_fr?: string | undefined, name_nl?: string | undefined, handle?: string | undefined, text?: string | undefined, text_parts?: Array | undefined, auto_hide_formula?: string | undefined, text_configuration?: string | undefined, virtual_account_number?: string | undefined, reconciliation_type?: string | undefined, public?: boolean | undefined, allow_duplicate_reconciliations?: boolean | undefined, is_active?: boolean | undefined, use_full_width?: boolean | undefined, downloadable_as_docx?: boolean | undefined, externally_managed?: boolean | undefined, tests?: string | undefined, version_comment: string}; export type CreateApiApiV4FFirmIdReconciliationsReconciliationIdArgs = {Accept?: string | undefined, firm_id: number, reconciliation_id: number, body: ReconciliationTextUpdateRequest}; export type CreateApiApiV4FFirmIdReconciliationsReconciliationIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const textPart = z.object({name: z.string(), content: z.string()}); export const reconciliationTextUpdateResponse = z.object({name: z.string().optional(), name_en: z.string().optional(), name_fr: z.string().optional(), name_nl: z.string().optional(), handle: z.string().optional(), text: z.string().optional(), text_parts: z.array(textPart).optional(), auto_hide_formula: z.string().optional(), text_configuration: z.string().optional(), virtual_account_number: z.string().optional(), reconciliation_type: z.string().optional(), public: z.boolean().optional(), allow_duplicate_reconciliations: z.boolean().optional(), is_active: z.boolean().optional(), use_full_width: z.boolean().optional(), downloadable_as_docx: z.boolean().optional(), externally_managed: z.boolean().optional(), tests: z.string().optional(), id: z.number().int().optional(), marketplace_template_id: z.number().int().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 }; /** * Update a reconciliation template * * POST /api/v4/f/{firm_id}/reconciliations/{reconciliation_id} */ export const createApiApiV4FFirmIdReconciliationsReconciliationId = async (args: CreateApiApiV4FFirmIdReconciliationsReconciliationIdArgs, options?: CreateApiApiV4FFirmIdReconciliationsReconciliationIdOptions) => { const {baseUrl = "https://live.getsilverfin.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/f/${encodeURIComponent(String(args.firm_id))}/reconciliations/${encodeURIComponent(String(args.reconciliation_id))}${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(reconciliationTextUpdateResponse, await res.json()) };