import {z} from 'zod' export type CreateApiWalletsSendInitiateBankArgs = {'api-key': string, Authorization: string, body: {userId: string, sourceAccountId: string, memo?: string | undefined, amount: string, destination?: {iban: string, bic: string} | undefined, fixedFee?: string | undefined, percentFeeBps?: string | undefined, paymentType?: string | undefined, whitelistedIbanId?: string | undefined, verificationMethod?: ('sms' | 'totp' | 'passkey') | undefined, name?: string | undefined}}; export type CreateApiWalletsSendInitiateBankOptions = {baseUrl?: string | undefined, sec0?: string | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiWalletsSendInitiateBankResponse = z.object({challengeId: z.string().optional(), dateExpires: z.string().optional(), transaction: z.object({syncedOwnerId: z.string().optional(), sourceAccountId: z.string().optional(), iban: z.string().optional(), bic: z.string().optional(), amount: z.string().optional(), memo: z.string().optional(), status: z.string().optional(), txType: z.string().optional(), parentWalletId: z.string().optional(), currency: z.string().optional()}).optional(), feeEstimate: z.object({totalFee: z.string().optional(), networkFee: z.string().optional(), ourFee: z.string().optional(), theirFee: z.string().optional(), feeCurrency: z.string().optional(), fixedFeeDetails: z.object({amount: z.string().optional(), exchangeRate: z.string().optional(), appliedFeeCents: z.string().optional()}).optional(), percentageFeeDetails: z.object({amount: z.string().optional(), appliedFeeBps: z.string().optional()}).optional()}).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 }; /** * Initiate SEPA Payment * * POST /wallets/send/initiate/bank */ export const createApiWalletsSendInitiateBank = async (args: CreateApiWalletsSendInitiateBankArgs, options?: CreateApiWalletsSendInitiateBankOptions) => { const {baseUrl = "https://www.sandbox.striga.com/api/v1", fetch: fetchFn = fetch, sec0, sec1} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['api-key'] != null) headers.set("api-key", String(args['api-key'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (sec0 !== undefined) headers.set("api-key", sec0) if (sec1 !== undefined) headers.set("Authorization", sec1) const url = `${baseUrl.replace(/\/+$/, '')}/wallets/send/initiate/bank${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(createApiWalletsSendInitiateBankResponse, await res.json()) };