Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/plaid

src/index.ts

84 lines · 2.9 KB · TypeScript
export {
	ACCESS_TOKEN_SETUP_URL,
	CLIENT_ID_SETUP_URL,
	DASHBOARD_KEYS_URL,
	DEFAULT_ACCESS_TOKEN_SECRET,
	DEFAULT_CLIENT_ID_SECRET,
	DEFAULT_COUNTRY_CODES,
	DEFAULT_PRODUCTS,
	DEFAULT_SECRET_SECRET,
	PLAID_VERSION,
	PRODUCTION_API_BASE_URL,
	PRODUCTION_API_HOST,
	PlaidApiError,
	SANDBOX_API_BASE_URL,
	SANDBOX_API_HOST,
	SANDBOX_INSTITUTION_ID,
	SECRET_SETUP_URL,
	accessTokenForPreview,
	accessTokenForRequest,
	accessTokenSetupUrl,
	clientIdSetupUrl,
	getPlaidApiBaseUrl,
	getPlaidApiHost,
	mutationPreview,
	plaidRequest,
	resolveAccessTokenSecretName,
	resolveClientIdSecretName,
	resolveEnvironment,
	resolveSecretSecretName,
	secretSetupUrl,
} from './plaid-core.ts'
export { getAccounts, getBalances } from './accounts.ts'
export { getIdentity } from './identity.ts'
export { getInstitution, listInstitutions, searchInstitutions } from './institutions.ts'
export { exchangePublicToken, getItem, removeItem, updateItemWebhook } from './item.ts'
export { createLinkToken } from './link.ts'
export { createSandboxPublicToken } from './sandbox.ts'
export { smokeTest } from './smoke-test.ts'
export { listTransactions, refreshTransactions, syncTransactions } from './transactions.ts'

import { getAccounts, getBalances } from './accounts.ts'
import { getIdentity } from './identity.ts'
import { getInstitution, listInstitutions, searchInstitutions } from './institutions.ts'
import { exchangePublicToken, getItem, removeItem, updateItemWebhook } from './item.ts'
import { createLinkToken } from './link.ts'
import { parseAction } from './plaid-core.ts'
import { createSandboxPublicToken } from './sandbox.ts'
import { smokeTest } from './smoke-test.ts'
import { listTransactions, refreshTransactions, syncTransactions } from './transactions.ts'

const actions = {
	'smoke-test': smokeTest,
	'get-item': getItem,
	'exchange-public-token': exchangePublicToken,
	'remove-item': removeItem,
	'update-item-webhook': updateItemWebhook,
	'get-accounts': getAccounts,
	'get-balances': getBalances,
	'get-identity': getIdentity,
	'sync-transactions': syncTransactions,
	'list-transactions': listTransactions,
	'refresh-transactions': refreshTransactions,
	'list-institutions': listInstitutions,
	'get-institution': getInstitution,
	'search-institutions': searchInstitutions,
	'create-link-token': createLinkToken,
	'create-sandbox-public-token': createSandboxPublicToken,
} as const

export type PlaidAction = keyof typeof actions

const actionNames = Object.keys(actions) as PlaidAction[]

/**
 * Root dispatcher for Plaid helpers. Defaults to the read-only smoke test.
 * @example
 * import plaid from 'kody:@kody/plaid'
 * const result = await plaid({ action: 'list-institutions', count: 5 })
 */
export default async function plaid(input: Record<string, unknown> = {}) {
	const action = parseAction(input.action, actionNames, 'smoke-test', 'Plaid')
	const handler = actions[action]
	return await handler(input as never)
}