# @bunq-community/bunq-js-client 中文文档

规范地址：https://npmcn.com/package/%40bunq-community/bunq-js-client/

版本：1\.1\.2
npm 元数据更新时间：2022-06-12T15:34:04.559Z
中文译文更新时间：2026-11-08T20:02:21.892Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40bunq-community/bunq-js-client
原文对照：https://npmcn.com/package/%40bunq-community/bunq-js-client/?lang=original
项目主页：https://github.com/bunqCommunity/bunqJSClient#readme
源码仓库：https://github.com/bunqCommunity/bunqJSClient

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

- 包体积（解压后）：297 kB，197 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10\.0\.0
- 运行依赖：6 个
- 首次发布：2017-10-17T13:50:54.115Z
- 最新版本发布：2020-04-29T09:56:18.678Z
- 近 30 天下载量：3058（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：116（近 12 个月 0 个）

## 中文简介

 [![NPM  Version](https://img.shields.io/npm/v/@bunq-community/bunq-js-client.svg)](https://www.npmjs.com/package/@bunq-community/bunq-js-client)\[![NPM Downloads](https://img.shields.io/npm/dt/@bunq-community/bunq-js-client.svg) \[(\][https://www.npmjs.com/p (中文(简体) )](https://www.npmjs.com/p)

## 安装

```sh
npm install @bunq-community/bunq-js-client
```

也可以使用：`pnpm add @bunq-community/bunq-js-client`、`yarn add @bunq-community/bunq-js-client`、`bun add @bunq-community/bunq-js-client`

## README

# 宽度

 [![NPM  Version](https://img.shields.io/npm/v/@bunq-community/bunq-js-client.svg)](https://www.npmjs.com/package/@bunq-community/bunq-js-client)[![NPM Downloads](https://img.shields.io/npm/dt/@bunq-community/bunq-js-client.svg) ](https://www.npmjs.com/package/@bunq-community/bunq-js-client)[![build status for master branch](https://api.travis-ci.org/bunqCommunity/bunqJSClient.svg?branch=master) ](https://travis-ci.org/bunqCommunity/bunqJSClient)[![MIT License](https://img.shields.io/npm/l/@bunq-community/bunq-js-client.svg)](https://github.com/bunqCommunity/bunqJSClient/blob/master/LICENSE) [![codecov](https://codecov.io/gh/bunqCommunity/bunqJSClient/branch/master/graph/badge.svg)](https://codecov.io/gh/bunqCommunity/bunqJSClient)

一个非官方的 Javascript SDK 为bunq API。 它旨在允许单页应用程序在不通过其他服务代理的情况下进行与bunq的所有交互.

API 会话细节被加密并使用 [伪造](https://github.com/digitalbazaar/forge)。 。 。 .

这个项目最初是为浏览器而建造的,但此后一直被测试并被与NodeJS服务器一起使用. 如果您真的想要使用节点JS, 您仍可以轻松创建自定义存储处理器( 默认为本地存储器) , 如 [安装](https://npmcn.com/package/%40bunq-community/bunq-js-client/#readme-installation) 节.

## 安装

安装库

```bash
yarn add @bunq-community/bunq-js-client
```

接下来创建一个带有可选存储界面的新实例作为第一个参数. 此默认为 [存储.js](https://github.com/marcuswestin/store.js/) 但任何类 采用下列方法: `get(key)`, (中文(简体) ), `set(key, data)`, (中文(简体) ), `remove(key)`。 。 。 .

## 使用量

使用 LocalStorage 创建新客户端 .

```js
const bunqJSClient = new BunqJSClient();
```

默认安装尝试使用仅与浏览器相容的 LocalStorage 。 你可以检查 `src/Stores/*` 用于其他兼容存储处理器的文件夹。 此示例使用 JSON 商店将数据写入本地的 JSON 文件 .

```js
import JSONFileStore from "@bunq-community/bunq-js-client/dist/Stores/JSONFileStore"; 

// run the file store with a location to store the data
const storageInstance = JSONFileStore("./bunq-js-client-data.json");

// create a new bunqJSClient with the new storage instance
const bunqJSClientCustom = new bunqJSClient(storageInstance);

// disables the automatic requests to keep the current session alive
// instead it'll create a new session when it is required
bunqJSClient.setKeepAlive(false);
```

下次运行要启动的设置功能

```js
/**
 * A 16-byte encryption key, check the examples (create_encryption_key.js) 
 * on how to create one
 * @see https://github.com/digitalbazaar/forge#pkcs5
 */
const ENCRYPTION_KEY = "3c7a4d431a846ed33a3bb1b1fa9b5c26";
const API_KEY = "abcd-1234-abcd-1234"; // Your bunq API key
/**
 * The device name which will show in the installation notification that bunq sends
 * this also lets users manage their keys more easily
 */ 
const DEVICE_NAME = "My Device"; 
const ENVIRONMENT = "SANDBOX"; // OR you can use PRODUCTION

/**
 * Permitted IPs, allowed values are:
 *  - Empty if you're not sure (bunq will use the current IP)
 *  - An array of allowed IP addresses 
 *  - The "*" character to enable wildcard mode
 */
const PERMITTED_IPS = []; 

const setup = async () => {
    // run the bunq application with our API key
    await bunqJSClient.run(API_KEY, PERMITTED_IPS, ENVIRONMENT, ENCRYPTION_KEY);
    
    // install a new keypair 
    await bunqJSClient.install();
    
    // register this device
    await bunqJSClient.registerDevice(DEVICE_NAME);
    
    // register a new session
    await bunqJSClient.registerSession();
}
```

现在您可以使用 bunq 客户端中的 API 来完成请求并获得当前用户.

```js
// force that the user info is retrieved from the API instead of the data currently in the object
const forceUpdate = true;

// all users connected to the api key
const users = await bunqJSClient.getUsers(forceUpdate);

// get only the userCompany account if one is set
const userCompany = await bunqJSClient.getUser("UserCompany", forceUpdate);

// get all payments for a user and monetary account
const payments = await bunqJSClient.api.payment.list(userId, accountId);
```

## OAuth 认证

您可以使用帮助器函数格式化正确的url来启动登录流程 :

```js
const url = bunqJSClient.formatOAuthAuthorizationRequestUrl(
    clientId, 
    redirectUri, 
    optionalState: string | false = false,
    sandbox: boolean = false
);
```

当用户授予访问权限时,下一次使用返回的代码参数为:

```js
const authorizationCode = await bunqJSClient.exchangeOAuthToken(
    clientId, 
    clientSecret, 
    redirectUri, 
    code, 
    state: string | false = false,
    sandbox: boolean = false
    grantType: string = "authorization_code",
)
```

这将返回如果成功 `access_token` 它是一个有效的 API 密钥。 使用此密钥可以访问有限的 `UserApiKey` 用户对象。 关于 OAuth 连接的局限性的更详细信息请检查官方主题 [这里](https://together.bunq.com/d/3016-oauth)。 。 。 .

## 实例

有一些例子可见于 `examples/` 文件夹. `create_sandbox_apikey` 将创建并输出一个新的沙盒密钥,与其他示例一起使用.

实例 [多腾v](https://github.com/motdotla/dotenv) 所以请务必复制 `.env.example` 文件为 `.env` 并输入正确的值.

不同实例的基本概述可以是: [在这里找到的](https://npmcn.com/package/%40bunq-community/bunq-js-client/examples/)。 。 。 .

## 支持的 APIs

详细情况请查看在 `src/Api/*`。添加终点相对容易,但在需要或提出要求时往往会得到。 最常见的端点现在已经全部被执行,但可以随意请求(或最好创建一个拉取请求)任何缺失端点.

## 联系人

[![Telegram chat badge](https://img.shields.io/badge/Telegram-Discuss-blue.svg)](https://t.me/bunqcommunity)

我们有一个公众 [电报聊天组](https://t.me/bunqcommunity) 。您可以随意为 Github 上的任何建议、错误或一般想法创建一个新问题,也可以通过上述其中之一与我们联系.

## 贡献者 ![Contributer count](https://img.shields.io/github/contributors/bunqcommunity/bunqjsclient.svg)

[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/0)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/0)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/1)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/1)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/2)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/2)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/3)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/3)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/4)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/4)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/5)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/5)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/6)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/6)[![](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/images/7)](https://sourcerer.io/fame/crecket/bunqCommunity/bunqJSClient/links/7)

## 许可证

除非另有说明,否则bunqJSClient源文件将按在下列文件中发现的麻省理工学院许可证分发: [自由主义](https://github.com/bunqCommunity/bunqJSClient/blob/master/LICENSE) 文档.

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FbunqCommunity%2FbunqJSClient.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FbunqCommunity%2FbunqJSClient?ref=badge_large)

## 常见问题

### @bunq-community/bunq-js-client 是什么？

\[ \[\(\]https://www\.npmjs\.com/p \(中文\(简体\) \)

### 如何安装 @bunq-community/bunq-js-client？

在项目目录运行 npm install @bunq-community/bunq-js-client，或使用 pnpm add / yarn add / bun add。

### @bunq-community/bunq-js-client 支持 TypeScript 吗？

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

### @bunq-community/bunq-js-client 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @bunq-community/bunq-js-client 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=10\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @bunq-community/bunq-js-client 可以商用吗？

@bunq-community/bunq-js-client 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @bunq-community/bunq-js-client 的下载量有多少？

根据 npm 官方下载统计，@bunq-community/bunq-js-client 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,058 次，日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bunq-community/bunq-js-client 还在维护吗？

最新版本 1\.1\.2 发布于 2020/04/29（6 年前）；至今共发布 116 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/10/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

