import {z} from 'zod' export type LedgerAccount = {id?: string | undefined, version?: string | undefined, accountNumber?: string | undefined, automatic?: boolean | undefined, balanceSheetItem?: ('ABSCHREIBUNGEN_GWG_ACCOUNTS' | 'ABSCHREIBUNGEN_UND_ANLAGEVERMOEGEN_ACCOUNTS' | 'BESONDERE_AUFWENDUNGEN_ACCOUNTS' | 'BUCHWERT_ANLAGENABGAENGE_ACCOUNTS' | 'FREMDLEISTUNGEN_ACCOUNTS' | 'GAS_STROM_ACCOUNTS' | 'GELEISTETE_ANZAHLUNGEN_ACCOUNTS' | 'GESETZLICHE_SOZIALE_AUFWENDUNGEN_ACCOUNTS' | 'HEIZUNG_ACCOUNTS' | 'INSTANDHALTUNG_ACCOUNTS' | 'INSTANDHALTUNG_UND_WERKZEUGE_ACCOUNTS' | 'KFZ_SONSTIGE_ACCOUNTS' | 'KFZ_STEUER_ACCOUNTS' | 'KFZ_VERSICHERUNG_ACCOUNTS' | 'KOSTEN_DER_WARENABGABE_ACCOUNTS' | 'LOEHENE_UND_GEHAELTER_ACCOUNTS' | 'MIETE_PACHT_ACCOUNTS' | 'NEUTRALE_AUFWENDUNGEN_ACCOUNTS' | 'NEUTRALE_ERTRAEGE_ACCOUNTS' | 'PRIVAT_ANTEILE_ACCOUNTS' | 'REVENUE_ACCOUNTS' | 'ROH_HILFS_UNDBETRIE_BSSTOFFE_ACCOUNTS' | 'SALDO_DER_STATISTISCHEN_KONTEN_ACCOUNTS' | 'SONSTIGE_ERLOESE_ACCOUNTS' | 'SONSTIGE_KONTEN_ACCOUNTS' | 'SONSTIGE_RAUMKOSTEN_ACCOUNTS' | 'STEUERN_VERSICHERUNGEN_BEITRAEGE_ACCOUNTS' | 'UMSATZSTEUER_ACCOUNTS' | 'UMSATZSTEUER_ZAHLUNGEN_ACCOUNTS' | 'VERSCHIEDENE_KOSTEN_ACCOUNTS' | 'VORSTEUER_ACCOUNTS' | 'WERBE_UND_REISEKOSTEN_ACCOUNTS') | undefined, createdDate?: number | undefined, description?: string | undefined, lastModifiedDate?: number | undefined, parentAccountId?: string | undefined, type: 'CARRY_FORWARD_ACCOUNT' | 'IMPERSONAL_ACCOUNT' | 'PERSONAL_ACCOUNT'}; export type CreateApiLedgerAccountArgs = {dryRun?: boolean | undefined, body: LedgerAccount}; export type CreateApiLedgerAccountOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const ledgerAccount = z.object({id: z.string().optional(), version: z.string().optional(), accountNumber: z.string().optional(), automatic: z.boolean().optional(), balanceSheetItem: z.enum(["ABSCHREIBUNGEN_GWG_ACCOUNTS", "ABSCHREIBUNGEN_UND_ANLAGEVERMOEGEN_ACCOUNTS", "BESONDERE_AUFWENDUNGEN_ACCOUNTS", "BUCHWERT_ANLAGENABGAENGE_ACCOUNTS", "FREMDLEISTUNGEN_ACCOUNTS", "GAS_STROM_ACCOUNTS", "GELEISTETE_ANZAHLUNGEN_ACCOUNTS", "GESETZLICHE_SOZIALE_AUFWENDUNGEN_ACCOUNTS", "HEIZUNG_ACCOUNTS", "INSTANDHALTUNG_ACCOUNTS", "INSTANDHALTUNG_UND_WERKZEUGE_ACCOUNTS", "KFZ_SONSTIGE_ACCOUNTS", "KFZ_STEUER_ACCOUNTS", "KFZ_VERSICHERUNG_ACCOUNTS", "KOSTEN_DER_WARENABGABE_ACCOUNTS", "LOEHENE_UND_GEHAELTER_ACCOUNTS", "MIETE_PACHT_ACCOUNTS", "NEUTRALE_AUFWENDUNGEN_ACCOUNTS", "NEUTRALE_ERTRAEGE_ACCOUNTS", "PRIVAT_ANTEILE_ACCOUNTS", "REVENUE_ACCOUNTS", "ROH_HILFS_UNDBETRIE_BSSTOFFE_ACCOUNTS", "SALDO_DER_STATISTISCHEN_KONTEN_ACCOUNTS", "SONSTIGE_ERLOESE_ACCOUNTS", "SONSTIGE_KONTEN_ACCOUNTS", "SONSTIGE_RAUMKOSTEN_ACCOUNTS", "STEUERN_VERSICHERUNGEN_BEITRAEGE_ACCOUNTS", "UMSATZSTEUER_ACCOUNTS", "UMSATZSTEUER_ZAHLUNGEN_ACCOUNTS", "VERSCHIEDENE_KOSTEN_ACCOUNTS", "VORSTEUER_ACCOUNTS", "WERBE_UND_REISEKOSTEN_ACCOUNTS"]).optional(), createdDate: z.number().int().optional(), description: z.string().optional(), lastModifiedDate: z.number().int().optional(), parentAccountId: z.string().optional(), type: z.enum(["CARRY_FORWARD_ACCOUNT", "IMPERSONAL_ACCOUNT", "PERSONAL_ACCOUNT"])}); 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 }; /** * create a ledgerAccount * * POST /ledgerAccount */ export const createApiLedgerAccount = async (args: CreateApiLedgerAccountArgs, options: CreateApiLedgerAccountOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/ledgerAccount${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(ledgerAccount, await res.json()) };