import {z} from 'zod' export type PatchedChartAccountSettings = {id?: number | undefined, uncategorized_name_and_number?: string | undefined, accounts_payable_name_and_number?: string | undefined, accounts_receivable_name_and_number?: string | undefined, deferred_revenue_name_and_number?: string | undefined, accrued_revenue_name_and_number?: string | undefined, unrealized_gain_loss_name_and_number?: string | undefined, realized_gain_loss_name_and_number?: string | undefined, rounding_account_name_and_number?: string | undefined, unapplied_credits_name_and_number?: string | undefined, unapplied_debits_name_and_number?: string | undefined, unbilled_revenue_name_and_number?: string | undefined, default_clearing_name_and_number?: string | undefined, discount_account_name_and_number?: string | undefined, accrued_discount_account_name_and_number?: string | undefined, unbilled_discount_account_name_and_number?: string | undefined, refund_account_name_and_number?: string | undefined, processing_fees_name_and_number?: string | undefined, platform_fees_name_and_number?: string | undefined, deferred_processing_fees_name_and_number?: string | undefined, tax_account_name_and_number?: string | undefined, payout_account_name_and_number?: string | undefined, cta_account_name_and_number?: string | undefined, oci_translation_account_name_and_number?: string | undefined, fixed_asset_disposal_name_and_number?: string | undefined, bad_debt_account_name_and_number?: string | undefined, dispute_expense_account_name_and_number?: string | undefined, dispute_reinstatement_account_name_and_number?: string | undefined, recognize_discounts_as_contra_revenue?: boolean | undefined, enable_mid_month_convention?: boolean | undefined, mid_month_threshold?: number | undefined, use_whole_month_accounting_for_prepaids?: boolean | undefined, split_invoice_payments_by_line?: (boolean | null) | undefined, split_eliminations_by_department?: boolean | undefined, customer?: number | undefined, uncategorized?: (number | null) | undefined, accounts_payable?: (number | null) | undefined, accounts_receivable?: (number | null) | undefined, deferred_revenue?: (number | null) | undefined, accrued_revenue?: (number | null) | undefined, unrealized_gain_loss?: (number | null) | undefined, realized_gain_loss?: (number | null) | undefined, rounding_account?: (number | null) | undefined, unapplied_credits?: (number | null) | undefined, unapplied_debits?: (number | null) | undefined, unbilled_revenue?: (number | null) | undefined, default_clearing?: (number | null) | undefined, discount_account?: (number | null) | undefined, accrued_discount_account?: (number | null) | undefined, unbilled_discount_account?: (number | null) | undefined, refund_account?: (number | null) | undefined, processing_fees?: (number | null) | undefined, platform_fees?: (number | null) | undefined, deferred_processing_fees?: (number | null) | undefined, tax_account?: (number | null) | undefined, payout_account?: (number | null) | undefined, cta_account?: (number | null) | undefined, oci_translation_account?: (number | null) | undefined, fixed_asset_disposal?: (number | null) | undefined, bad_debt_account?: (number | null) | undefined, dispute_expense_account?: (number | null) | undefined, dispute_reinstatement_account?: (number | null) | undefined}; export type PatchApiCoaApiChartAccountSettingsArgs = {body: PatchedChartAccountSettings}; export type PatchApiCoaApiChartAccountSettingsOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const chartAccountSettings = z.object({id: z.number().int(), uncategorized_name_and_number: z.string(), accounts_payable_name_and_number: z.string(), accounts_receivable_name_and_number: z.string(), deferred_revenue_name_and_number: z.string(), accrued_revenue_name_and_number: z.string(), unrealized_gain_loss_name_and_number: z.string(), realized_gain_loss_name_and_number: z.string(), rounding_account_name_and_number: z.string(), unapplied_credits_name_and_number: z.string(), unapplied_debits_name_and_number: z.string(), unbilled_revenue_name_and_number: z.string(), default_clearing_name_and_number: z.string(), discount_account_name_and_number: z.string(), accrued_discount_account_name_and_number: z.string(), unbilled_discount_account_name_and_number: z.string(), refund_account_name_and_number: z.string(), processing_fees_name_and_number: z.string(), platform_fees_name_and_number: z.string(), deferred_processing_fees_name_and_number: z.string(), tax_account_name_and_number: z.string(), payout_account_name_and_number: z.string(), cta_account_name_and_number: z.string(), oci_translation_account_name_and_number: z.string(), fixed_asset_disposal_name_and_number: z.string(), bad_debt_account_name_and_number: z.string(), dispute_expense_account_name_and_number: z.string(), dispute_reinstatement_account_name_and_number: z.string(), recognize_discounts_as_contra_revenue: z.boolean().optional(), enable_mid_month_convention: z.boolean().optional(), mid_month_threshold: z.number().int().gte(0).lte(31).optional(), use_whole_month_accounting_for_prepaids: z.boolean().optional(), split_invoice_payments_by_line: z.boolean().nullable().optional(), split_eliminations_by_department: z.boolean().optional(), customer: z.number().int(), uncategorized: z.number().int().nullable().optional(), accounts_payable: z.number().int().nullable().optional(), accounts_receivable: z.number().int().nullable().optional(), deferred_revenue: z.number().int().nullable().optional(), accrued_revenue: z.number().int().nullable().optional(), unrealized_gain_loss: z.number().int().nullable().optional(), realized_gain_loss: z.number().int().nullable().optional(), rounding_account: z.number().int().nullable().optional(), unapplied_credits: z.number().int().nullable().optional(), unapplied_debits: z.number().int().nullable().optional(), unbilled_revenue: z.number().int().nullable().optional(), default_clearing: z.number().int().nullable().optional(), discount_account: z.number().int().nullable().optional(), accrued_discount_account: z.number().int().nullable().optional(), unbilled_discount_account: z.number().int().nullable().optional(), refund_account: z.number().int().nullable().optional(), processing_fees: z.number().int().nullable().optional(), platform_fees: z.number().int().nullable().optional(), deferred_processing_fees: z.number().int().nullable().optional(), tax_account: z.number().int().nullable().optional(), payout_account: z.number().int().nullable().optional(), cta_account: z.number().int().nullable().optional(), oci_translation_account: z.number().int().nullable().optional(), fixed_asset_disposal: z.number().int().nullable().optional(), bad_debt_account: z.number().int().nullable().optional(), dispute_expense_account: z.number().int().nullable().optional(), dispute_reinstatement_account: z.number().int().nullable().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 }; /** * Partially Update Chart Account Settings * * PATCH /coa/api/chart-account-settings */ export const patchApiCoaApiChartAccountSettings = async (args: PatchApiCoaApiChartAccountSettingsArgs, options?: PatchApiCoaApiChartAccountSettingsOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/chart-account-settings${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(chartAccountSettings, await res.json()) };