import {z} from 'zod' export type SepaDirectDebitMandate = {id?: string | undefined, version?: string | undefined, bankAccountId?: string | undefined, cancellationDate?: number | undefined, createdDate?: number | undefined, description?: string | undefined, firstDebit?: boolean | undefined, lastModifiedDate?: number | undefined, mandateReference?: string | undefined, partyBankAccountId?: string | undefined, runtime?: ('ONE_OFF_MANDATE' | 'RECURRING_MANDATE') | undefined, signatureDate?: number | undefined, type?: ('B2B' | 'CORE') | undefined}; export type UpdateApiSepaDirectDebitMandateIdIdArgs = {id: string, dryRun?: boolean | undefined, body: SepaDirectDebitMandate}; export type UpdateApiSepaDirectDebitMandateIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const sepaDirectDebitMandate = z.object({id: z.string().optional(), version: z.string().optional(), bankAccountId: z.string().optional(), cancellationDate: z.number().int().optional(), createdDate: z.number().int().optional(), description: z.string().optional(), firstDebit: z.boolean().optional(), lastModifiedDate: z.number().int().optional(), mandateReference: z.string().optional(), partyBankAccountId: z.string().optional(), runtime: z.enum(["ONE_OFF_MANDATE", "RECURRING_MANDATE"]).optional(), signatureDate: z.number().int().optional(), type: z.enum(["B2B", "CORE"]).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 sepaDirectDebitMandate * * PUT /sepaDirectDebitMandate/id/{id} */ export const updateApiSepaDirectDebitMandateIdId = async (args: UpdateApiSepaDirectDebitMandateIdIdArgs, options: UpdateApiSepaDirectDebitMandateIdIdOptions) => { 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(/\/+$/, '')}/sepaDirectDebitMandate/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(sepaDirectDebitMandate, await res.json()) };