Skip to content
← Public packages

@kentcdodds/wise

Call Wise profiles, balances, quotes, recipients, and transfers with wiseApiToken.

src/list-transfers.ts

57 lines · 1.7 KB · TypeScript
import { resolveProfileId, wiseRequest, type ProfileRef } from './core.ts'

/**
 * List recent Wise transfers for a profile.
 * Read-only; uses GET /v1/transfers?profile={profileId}.
 *
 * @param input.profileId - Wise profile id; omit to use profileType.
 * @param input.profileType - personal or business when profileId is omitted (default business).
 * @param input.status - Optional transfer status filter.
 * @param input.limit - Max items (default 20, max 100).
 * @param input.offset - Offset for pagination.
 *
 * @example
 * import listTransfers from 'kody:@kentcdodds/wise/list-transfers'
 * const { transfers } = await listTransfers({ limit: 5 })
 */
export default async function listTransfers(
	input: ProfileRef & {
		status?: string
		limit?: number
		offset?: number
	} = {},
) {
	const profileId = await resolveProfileId(input)
	const limit = Math.min(100, Math.max(1, Math.floor(Number(input.limit) || 20)))
	const offset = Math.max(0, Math.floor(Number(input.offset) || 0))
	const raw = (await wiseRequest({
		path: '/v1/transfers',
		query: {
			profile: profileId,
			limit,
			offset,
			...(input.status ? { status: input.status } : {}),
		},
		label: 'Wise transfers',
	})) as Array<{
		id?: number
		status?: string
		sourceCurrency?: string
		targetCurrency?: string
		sourceValue?: number
		targetValue?: number
		created?: string
		reference?: string
	}>
	const transfers = (Array.isArray(raw) ? raw : []).map((t) => ({
		id: t.id ?? null,
		status: t.status || null,
		sourceCurrency: t.sourceCurrency || null,
		targetCurrency: t.targetCurrency || null,
		sourceValue: t.sourceValue ?? null,
		targetValue: t.targetValue ?? null,
		created: t.created || null,
		reference: t.reference || null,
	}))
	return { profileId, transfers, count: transfers.length }
}