import {z} from 'zod' export type SweepCounterparty = {balanceAccountId?: string | undefined, merchantAccount?: string | undefined, transferInstrumentId?: string | undefined}; export type SweepSchedule = {cronExpression?: string | undefined, type: 'daily' | 'weekly' | 'monthly' | 'balance' | 'cron'}; export type Amount = {currency: string, value: number}; export type UpdateSweepConfigurationV2 = {category?: ('bank' | 'internal' | 'platformPayment') | undefined, counterparty?: SweepCounterparty | undefined, currency?: string | undefined, description?: string | undefined, id?: string | undefined, priorities?: (Array<'crossBorder' | 'fast' | 'instant' | 'internal' | 'regular' | 'wire'>) | undefined, reason?: ('accountHierarchyNotActive' | 'amountLimitExceeded' | 'approved' | 'counterpartyAccountBlocked' | 'counterpartyAccountClosed' | 'counterpartyAccountNotFound' | 'counterpartyAddressRequired' | 'counterpartyBankTimedOut' | 'counterpartyBankUnavailable' | 'directDebitNotSupported' | 'error' | 'notEnoughBalance' | 'refusedByCounterpartyBank' | 'routeNotFound' | 'transferInstrumentDoesNotExist' | 'unknown') | undefined, reasonDetail?: string | undefined, reference?: string | undefined, referenceForBeneficiary?: string | undefined, schedule?: SweepSchedule | undefined, status?: ('active' | 'inactive') | undefined, sweepAmount?: Amount | undefined, targetAmount?: Amount | undefined, triggerAmount?: Amount | undefined, type?: ('pull' | 'push') | undefined}; export type PatchApiBalanceAccountsBalanceAccountIdSweepsSweepIdArgs = {balanceAccountId: string, sweepId: string, body: UpdateSweepConfigurationV2}; export type PatchApiBalanceAccountsBalanceAccountIdSweepsSweepIdOptions = {baseUrl?: string | undefined, clientKey?: string | undefined, fetch?: typeof fetch | undefined}; export const sweepCounterparty = z.object({balanceAccountId: z.string().optional(), merchantAccount: z.string().optional(), transferInstrumentId: z.string().optional()}); export const sweepSchedule = z.object({cronExpression: z.string().optional(), type: z.enum(["daily", "weekly", "monthly", "balance", "cron"])}); export const amount = z.object({currency: z.string(), value: z.number().int()}); export const sweepConfigurationV2 = z.object({category: z.enum(["bank", "internal", "platformPayment"]).optional(), counterparty: sweepCounterparty, currency: z.string(), description: z.string().optional(), id: z.string(), priorities: z.array(z.enum(["crossBorder", "fast", "instant", "internal", "regular", "wire"])).optional(), reason: z.enum(["accountHierarchyNotActive", "amountLimitExceeded", "approved", "counterpartyAccountBlocked", "counterpartyAccountClosed", "counterpartyAccountNotFound", "counterpartyAddressRequired", "counterpartyBankTimedOut", "counterpartyBankUnavailable", "directDebitNotSupported", "error", "notEnoughBalance", "refusedByCounterpartyBank", "routeNotFound", "transferInstrumentDoesNotExist", "unknown"]).optional(), reasonDetail: z.string().optional(), reference: z.string().max(80).optional(), referenceForBeneficiary: z.string().max(80).optional(), schedule: sweepSchedule, status: z.enum(["active", "inactive"]).optional(), sweepAmount: amount.optional(), targetAmount: amount.optional(), triggerAmount: amount.optional(), type: z.enum(["pull", "push"]).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 sweep * * PATCH /balanceAccounts/{balanceAccountId}/sweeps/{sweepId} * * Also accepts auth: BasicAuth, ApiKeyAuth */ export const patchApiBalanceAccountsBalanceAccountIdSweepsSweepId = async (args: PatchApiBalanceAccountsBalanceAccountIdSweepsSweepIdArgs, options?: PatchApiBalanceAccountsBalanceAccountIdSweepsSweepIdOptions) => { const {baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2", fetch: fetchFn = fetch, clientKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (clientKey !== undefined) query.set("clientKey", clientKey) const url = `${baseUrl.replace(/\/+$/, '')}/balanceAccounts/${encodeURIComponent(String(args.balanceAccountId))}/sweeps/${encodeURIComponent(String(args.sweepId))}${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(sweepConfigurationV2, await res.json()) };