# @basenative/integrations 中文文档

规范地址：https://npmcn.com/package/%40basenative/integrations/

版本：3\.3\.0
npm 元数据更新时间：2026-11-03T01:38:46.001Z
中文译文更新时间：2026-11-08T01:40:35.909Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40basenative/integrations
原文对照：https://npmcn.com/package/%40basenative/integrations/?lang=original
项目主页：https://github.com/DuganLabs/BaseNative/tree/main/packages/integrations#readme
源码仓库：https://github.com/DuganLabs/BaseNative

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：35.8 kB，8 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2026-10-18T05:29:24.094Z
- 最新版本发布：2026-11-03T01:38:45.708Z
- 近 30 天下载量：1934（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：14（近 12 个月 14 个）

## 中文简介

BaseNative 应用程序的无头第三方集成包

## 安装

```sh
npm install @basenative/integrations
```

也可以使用：`pnpm add @basenative/integrations`、`yarn add @basenative/integrations`、`bun add @basenative/integrations`

## README

# @ asinative/ 整合

> BaseNative apps的无头第三方集成包件——平板链接+账户/传输,和纯浮产优化数学

部分 [基础](https://github.com/DuganLabs/BaseNative) 生态系统——一个基于信号的网络运行时间超过本土的HTML.

## 安装

```bash
npm install @basenative/integrations
```

每个子路径是一个单独的切入点——只导入您需要的东西:

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

## 快速启动

### 平板链接( 客户端)

```js
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
```

### 平板账户+转账(服务器侧)

```js
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 优化( 纯函数, 无网络调用)

```js
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 }`。 。 。 .

## 测试

```bash
cd packages/integrations && node --test
```

## 许可证

阿帕奇 - 2.0

## 常见问题

### @basenative/integrations 是什么？

BaseNative 应用程序的无头第三方集成包

### 如何安装 @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 和提交记录判断。

