import {z} from 'zod' export type Currency = {id?: string | undefined, version?: string | undefined, createdDate?: number | undefined, currencySymbol?: string | undefined, lastModifiedDate?: number | undefined, name: string}; export type PaymentRunItem = {id?: string | undefined, version?: string | undefined, amountDiscount?: unknown | undefined, amountPayment?: unknown | undefined, bankAccountId?: string | undefined, bankTransactionId?: string | undefined, cleared?: boolean | undefined, conversionRate?: unknown | undefined, conversionRateDate?: number | undefined, createdDate?: number | undefined, lastModifiedDate?: number | undefined, partyBankAccountId?: string | undefined, paymentRunId?: string | undefined, paymentRunPaymentType?: ('NONE' | 'ONLINE' | 'SEPA' | 'SWIFT') | undefined, purchaseOpenItemId?: string | undefined, purpose?: string | undefined, recordCurrency?: Currency | undefined}; export type PaymentRun = {id?: string | undefined, version?: string | undefined, createdDate?: number | undefined, lastModifiedDate?: number | undefined, paymentRunDate?: number | undefined, paymentRunItems?: Array | undefined, paymentRunNumber?: string | undefined, runByUserId?: string | undefined, totalAmount?: unknown | undefined}; export type UpdateApiPaymentRunIdIdArgs = {id: string, dryRun?: boolean | undefined, body: PaymentRun}; export type UpdateApiPaymentRunIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const currency = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), currencySymbol: z.string().optional(), lastModifiedDate: z.number().int().optional(), name: z.string()}); export const paymentRunItem = z.object({id: z.string().optional(), version: z.string().optional(), amountDiscount: z.string().optional(), amountPayment: z.string().optional(), bankAccountId: z.string().optional(), bankTransactionId: z.string().optional(), cleared: z.boolean().optional(), conversionRate: z.string().optional(), conversionRateDate: z.number().int().optional(), createdDate: z.number().int().optional(), lastModifiedDate: z.number().int().optional(), partyBankAccountId: z.string().optional(), paymentRunId: z.string().optional(), paymentRunPaymentType: z.enum(["NONE", "ONLINE", "SEPA", "SWIFT"]).optional(), purchaseOpenItemId: z.string().optional(), purpose: z.string().optional(), recordCurrency: currency.optional()}); export const paymentRun = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), lastModifiedDate: z.number().int().optional(), paymentRunDate: z.number().int().optional(), paymentRunItems: z.array(paymentRunItem).optional(), paymentRunNumber: z.string().optional(), runByUserId: z.string().optional(), totalAmount: 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 }; /** * update paymentRun * * PUT /paymentRun/id/{id} */ export const updateApiPaymentRunIdId = async (args: UpdateApiPaymentRunIdIdArgs, options: UpdateApiPaymentRunIdIdOptions) => { 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(/\/+$/, '')}/paymentRun/id/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(paymentRun, await res.json()) };