@basenative/integrations

中文文档
3.3.0发布于 2026/11/03Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 1934

Headless third-party integration wrappers for BaseNative apps

原始使用文档
文档目录10 节
  1. Install
  2. Quick Start
  3. Plaid Link (client-side)
  4. Plaid accounts + transfers (server-side)
  5. Yield optimization (pure functions, no network calls)
  6. API
  7. @basenative/integrations/plaid
  8. @basenative/integrations/yield
  9. Tests
  10. License

@basenative/integrations

Headless third-party integration wrappers for BaseNative apps — Plaid Link + accounts/transfers, and pure float-yield optimization math

Part of the BaseNative ecosystem — a signal-based web runtime over native HTML.

Install

npm install @basenative/integrations

Each subpath is a separate entry point — import only what you need:

import { createPlaidLink, createPlaidClient } from '@basenative/integrations/plaid';
import { findBestYieldAccount, optimizeFloatAllocation } from '@basenative/integrations/yield';

Quick Start

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

Plaid accounts + transfers (server-side)

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 optimization (pure functions, no network calls)

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

Client-side (requires a browser):

  • loadPlaidScript() — Loads the Plaid Link drop-in script once; resolves when ready.
  • createPlaidLink(config) — Signal-based Link handler. config: token, onSuccess(publicToken, metadata), onExit?, onEvent?, signals (an object exposing signal(), e.g. @basenative/runtime). Returns { linkToken, linkStatus, open(), destroy() } — linkToken/linkStatus are signals when signals.signal is provided, null otherwise.
  • openPlaidLink(options) — Lower-level Link handler without signals. options: token, onSuccess, onExit?, onEvent?. Returns { open(), destroy() }.

Server-side (Node.js or Cloudflare Workers — uses fetch, no SDK):

  • createPlaidClient(config) — Factory bundling credentials into exchangePublicToken, getAccounts, getBalance, createTransfer, getTransferStatus. config: clientId, secret, environment? ('sandbox' | 'development' | 'production', default 'sandbox').
  • createLinkToken(options, credentials) — Creates a Link token. options: userId, clientName?, products? (default ['transactions']), countryCodes? (default ['US']), language?. Returns { linkToken, expiration, requestId }.
  • exchangePublicToken(publicToken, credentials) — Exchanges a Link onSuccess public token for an access token. Returns { accessToken, itemId, requestId }.
  • getAccounts(accessToken, credentials) — Fetches linked accounts without balances.
  • getBalances(accessToken, credentials) / getBalance(accessToken, credentials) — Fetches accounts with balances (getBalance is an alias).
  • createTransfer(params, credentials) — Initiates a Plaid Transfer. params: accessToken, accountId, type ('debit' | 'credit'), amount (cents), description, network? ('rtp' for RTP/FedNow, falls back to ACH on failure), user? ({ name, email }). Returns { transferId, status, network }.
  • getTransferStatus(transferId, credentials) — Returns { transferId, status, amount, network }.

credentials is always { clientId, secret, env? }. All server functions call the Plaid REST API directly via fetch — no plaid npm SDK dependency.

@basenative/integrations/yield

Pure functions — no external API calls, no I/O:

  • findBestYieldAccount(accounts) — Picks the highest-APY account from [{ id, name, balance, apy }]. Returns { accountId, accountName, apy, expectedMonthlyYield }.
  • optimizeFloatAllocation(accounts, totalFloat) — Greedily allocates totalFloat across accounts (highest APY first, respecting each account's optional maxBalance). Returns [{ accountId, accountName, allocation, expectedYield }].
  • calculateOptimalTransferTiming(liabilities, accounts) — Builds a transfer schedule that keeps float in the best-yield account until 2 days before each liability's due date. Returns [{ transferDate, fromAccountId, amount, reason }].
  • calculateBreakEven(amount, fromApy, toApy, transferCostCents?, daysFloat?) — Determines whether moving amount (cents) from one APY to a higher one is worth a fixed transfer cost over daysFloat days. Returns { profitable, yieldGain, breakEvenDays }.

Tests

cd packages/integrations && node --test

License

Apache-2.0

版本与发布记录

@basenative/integrations 共发布 14 个版本,首次发布于 2026/10/18;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.3.0latest2026/11/035 天前
3.2.02026/11/035 天前
3.1.02026/11/017 天前
3.0.02026/10/317 天前
2.4.02026/10/2613 天前
2.3.22026/10/2217 天前

关于 @basenative/integrations 的常见问题

@basenative/integrations 是什么?

Headless third-party integration wrappers for BaseNative apps

如何安装 @basenative/integrations?

在项目目录运行 npm install @basenative/integrations,或使用 pnpm add / yarn add / bun add。

@basenative/integrations 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@basenative/integrations 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@basenative/integrations 可以商用吗?

@basenative/integrations 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@basenative/integrations 的下载量有多少?

根据 npm 官方下载统计,@basenative/integrations 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,934 次,日均约 64 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@basenative/integrations 还在维护吗?

最新版本 3.3.0 发布于 2026/11/03(5 天前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/10/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。