mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-06-03 00:19:01 +00:00
41 lines
1010 B
TypeScript
41 lines
1010 B
TypeScript
import type { ApiFetcher } from './fetch-utils';
|
|
import { paths } from './schema';
|
|
|
|
export const PLAID_ROUTES = {
|
|
LINK_TOKEN: '/api/banking/plaid/link-token',
|
|
EXCHANGE_TOKEN: '/api/banking/plaid/exchange-token',
|
|
} as const satisfies Record<string, keyof paths>;
|
|
|
|
export interface PlaidLinkTokenResponse {
|
|
linkToken?: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
export interface PlaidExchangeTokenBody {
|
|
publicToken: string;
|
|
institutionId?: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
export async function fetchPlaidLinkToken(
|
|
fetcher: ApiFetcher
|
|
): Promise<PlaidLinkTokenResponse> {
|
|
const post = fetcher
|
|
.path(PLAID_ROUTES.LINK_TOKEN)
|
|
.method('post')
|
|
.create();
|
|
const { data } = await post({});
|
|
return (data ?? {}) as PlaidLinkTokenResponse;
|
|
}
|
|
|
|
export async function fetchPlaidExchangeToken(
|
|
fetcher: ApiFetcher,
|
|
body: PlaidExchangeTokenBody
|
|
): Promise<void> {
|
|
const post = fetcher
|
|
.path(PLAID_ROUTES.EXCHANGE_TOKEN)
|
|
.method('post')
|
|
.create();
|
|
await post(body as never);
|
|
}
|