import {z} from 'zod' export type CreateApiWalletsCorporateTransactionConfirmArgs = {'api-key': string, Authorization: string, body: {applicationId: string, challengeId: string, verificationCode: string, ip: string}}; export type CreateApiWalletsCorporateTransactionConfirmOptions = {baseUrl?: string | undefined, sec0?: string | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiWalletsCorporateTransactionConfirmResponse = z.object({id: z.string().optional(), accountId: z.string().optional(), syncedOwnerId: z.string().optional(), sourceSyncedOwnerId: z.string().optional(), debit: z.string().optional(), timestamp: z.string().optional(), txType: z.string().optional(), memo: z.string().optional(), currency: z.string().optional(), exchangeRate: z.string().optional(), balanceBefore: z.object({amount: z.string().optional(), balance: z.string().optional(), currency: z.string().optional()}).optional(), balanceAfter: z.object({amount: z.string().optional(), balance: z.string().optional(), currency: z.string().optional()}).optional(), bankingTransactionAmount: z.string().optional(), bankingSenderBic: z.string().optional(), bankingSenderIban: z.string().optional(), bankingSenderName: z.string().optional(), bankingPaymentType: z.string().optional(), bankingBeneficiaryBic: z.string().optional(), bankingBeneficiaryIban: 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 }; /** * Confirm transaction with OTP * * POST /wallets/corporate/transaction/confirm */ export const createApiWalletsCorporateTransactionConfirm = async (args: CreateApiWalletsCorporateTransactionConfirmArgs, options?: CreateApiWalletsCorporateTransactionConfirmOptions) => { 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/corporate/transaction/confirm${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(createApiWalletsCorporateTransactionConfirmResponse, await res.json()) };