@ asinative/ 整合
BaseNative apps的无头第三方集成包件——平板链接+账户/传输,和纯浮产优化数学
部分 基础 生态系统——一个基于信号的网络运行时间超过本土的HTML.
安装
npm install @basenative/integrations
每个子路径是一个单独的切入点——只导入您需要的东西:
import { createPlaidLink, createPlaidClient } from '@basenative/integrations/plaid';
import { findBestYieldAccount, optimizeFloatAllocation } from '@basenative/integrations/yield';
快速启动
平板链接( 客户端)
import { createPlaidLink } from '@basenative/integrations/plaid';
import { signal } from '@basenative/runtime';
const { linkStatus, open, destroy } = await createPlaidLink({
token: linkToken, // from createLinkToken() below, fetched from your server
onSuccess: (publicToken, metadata) => {
// send publicToken to your server to exchange it
},
signals: { signal },
});
open(); // launches the Plaid Link UI; linkStatus updates as the user completes it
平板账户+转账(服务器侧)
import { createLinkToken, exchangePublicToken, createPlaidClient } from '@basenative/integrations/plaid';
const credentials = { clientId: process.env.PLAID_CLIENT_ID, secret: process.env.PLAID_SECRET, env: 'sandbox' };
const { linkToken } = await createLinkToken({ userId: 'user_123' }, credentials);
const { accessToken } = await exchangePublicToken(publicTokenFromClient, credentials);
const plaid = createPlaidClient({ clientId: credentials.clientId, secret: credentials.secret, environment: credentials.env });
const { accounts } = await plaid.getAccounts(accessToken);
Yield 优化( 纯函数, 无网络调用)
import { findBestYieldAccount, optimizeFloatAllocation } from '@basenative/integrations/yield';
const best = findBestYieldAccount([
{ id: 'a1', name: 'Checking', balance: 5000, apy: 0.005 },
{ id: 'a2', name: 'High-yield savings', balance: 20000, apy: 0.045 },
]);
// { accountId: 'a2', accountName: 'High-yield savings', apy: 0.045, expectedMonthlyYield: 75 }
API 密码
@basenative/integrations/plaid
客户端( 需要浏览器 ):
loadPlaidScript()——装入平板链接滴入脚本一次;准备时解决.createPlaidLink(config)——以信号为主的链接处理器.config数字 :token, (中文(简体) ),onSuccess(publicToken, metadata), (中文(简体) ),onExit?, (中文(简体) ),onEvent?, (中文(简体) ),signals(物体曝光)signal(),比如说.@basenative/runtime) (中文(简体) ). 回返{ linkToken, linkStatus, open(), destroy() }—— 说linkToken编号 :linkStatus是信号,当signals.signal提供,null否则.openPlaidLink(options)低级 没有信号的链接处理器 .options数字 :token, (中文(简体) ),onSuccess, (中文(简体) ),onExit?, (中文(简体) ),onEvent?. 回归{ open(), destroy() }。 。 。 .
服务器侧面(节点或Cloudflare工人-使用) fetch没有SDK:
createPlaidClient(config)- 工厂将证书捆绑在一起exchangePublicToken, (中文(简体) ),getAccounts, (中文(简体) ),getBalance, (中文(简体) ),createTransfer, (中文(简体) ),getTransferStatus。 。 。 .config数字 :clientId, (中文(简体) ),secret, (中文(简体) ),environment?(单位:千美元)'sandbox'|'development'|'production'默认值'sandbox') (中文(简体) ).createLinkToken(options, credentials)——创建链接符.options数字 :userId, (中文(简体) ),clientName?, (中文(简体) ),products?(默认)['transactions'], (中文(简体) ),countryCodes?(默认)['US'], (中文(简体) ),language?. 回归{ linkToken, expiration, requestId }。 。 。 .exchangePublicToken(publicToken, credentials)- 交换链接onSuccess公共信使是访问信使 回返{ accessToken, itemId, requestId }。 。 。 .getAccounts(accessToken, credentials)——取出无余额的关联账户.getBalances(accessToken, credentials)编号 :getBalance(accessToken, credentials)- 以余额获取账户(getBalance是一个别名).createTransfer(params, credentials)启动平板传输.params数字 :accessToken, (中文(简体) ),accountId, (中文(简体) ),type(单位:千美元)'debit'|'credit', (中文(简体) ),amount(分数),description, (中文(简体) ),network?(单位:千美元)'rtp'对于RTP/FedNow,在失败时回到ACH,user?(单位:千美元){ name, email }) (中文(简体) ). 回返{ transferId, status, network }。 。 。 .getTransferStatus(transferId, credentials)- 回返{ transferId, status, amount, network }。 。 。 .
credentials 总是 { clientId, secret, env? }。所有服务器函数直接通过 Plaid REST API 调用 fetch 没有 plaid npm SDK依赖.
@basenative/integrations/yield
纯函数——无外部 API 调用,无 I/O :
findBestYieldAccount(accounts)- 从APY账户中选择最高的账户[{ id, name, balance, apy }]. 回归{ accountId, accountName, apy, expectedMonthlyYield }。 。 。 .optimizeFloatAllocation(accounts, totalFloat)- 贪婪地分配totalFloat跨账户(最高APY第一,尊重每个账户的可选性)maxBalance) (中文(简体) ). 回返[{ accountId, accountName, allocation, expectedYield }]。 。 。 .calculateOptimalTransferTiming(liabilities, accounts)——构建一个转移调度表,将最高收益账户中浮动到每个负债到期日前2天. 回返[{ transferDate, fromAccountId, amount, reason }]。 。 。 .calculateBreakEven(amount, fromApy, toApy, transferCostCents?, daysFloat?)——确定是否移动amount从一个APY到一个更高的PY(分)值 固定转帐成本超过daysFloat几天时间 回返{ profitable, yieldGain, breakEvenDays }。 。 。 .
测试
cd packages/integrations && node --test
许可证
阿帕奇 - 2.0