# @basis-theory/basis-theory-js 中文文档

规范地址：https://npmcn.com/package/%40basis-theory/basis-theory-js/

版本：4\.30\.2
npm 元数据更新时间：2026-11-02T18:33:29.715Z
中文译文更新时间：2026-11-07T17:59:21.654Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：201 kB，210 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10\.12\.0
- 运行依赖：7 个
- 首次发布：2021-08-13T13:18:36.964Z
- 最新版本发布：2026-07-08T15:00:10.967Z
- 近 30 天下载量：163149（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：191（近 12 个月 2 个）

## 中文简介

> \[! \] 这个SDK已经贬值了. > > 时间轴 我们的新节点Js SDK可以在 [https://github.com/Basis-Theory/node-sdk 页面存档备份,存于互联网档案馆](https://github.com/Basis-Theory/node-sdk) > 更多信息见我们的文献网站. [https://developers.basistheory.com/docs/sdks/server-side/node 页面存档备份,存于互联网档案馆](https://developers.basistheory.com/docs/sdks/server-side/node)

## 安装

```sh
npm install @basis-theory/basis-theory-js
```

也可以使用：`pnpm add @basis-theory/basis-theory-js`、`yarn add @basis-theory/basis-theory-js`、`bun add @basis-theory/basis-theory-js`

## README

# 基础理论 JS SDK(aka Basic Theory.js)

> \[叹息\] 这个SDK已经贬值了.
> 
> 我们的新节点Js SDK可以在 [https://github.com/Basis-Theory/node-sdk 页面存档备份,存于互联网档案馆](https://github.com/Basis-Theory/node-sdk)
> 
> 更多信息请查看我们的文献网站. [https://developers.basistheory.com/docs/sdks/server-side/node 页面存档备份,存于互联网档案馆](https://developers.basistheory.com/docs/sdks/server-side/node)

[![Version](https://img.shields.io/npm/v/@basis-theory/basis-theory-js.svg)](https://www.npmjs.org/package/@basis-theory/basis-theory-js) [![Downloads](https://img.shields.io/npm/dm/@basis-theory/basis-theory-js.svg)](https://www.npmjs.org/package/@basis-theory/basis-theory-js) [![Verify](https://github.com/Basis-Theory/basis-theory-js/actions/workflows/release.yml/badge.svg)](https://github.com/Basis-Theory/basis-theory-js/actions/workflows/release.yml)

这个 [基础理论](https://basistheory.com/) 联合来文SDK

## 安装

使用 [节点软件包管理器](https://docs.npmjs.com/)

```sh
npm install --save @basis-theory/basis-theory-js
```

使用 [雅伦](https://classic.yarnpkg.com/en/docs/)

```sh
yarn add @basis-theory/basis-theory-js
```

## 文档

关于终点和例子的完整清单,请参见我们 [API 文件](https://docs.basistheory.com/api-reference/?javascript#introduction)

## 使用量

### 初始化

```javascript
import { BasisTheory } from '@basis-theory/basis-theory-js';

const bt = await new BasisTheory().init('<API Key>'); // replace with your application key
```

### 按请求配置

所有服务方法都接受可选 `RequestOptions` 对象。 如果您想要设置每个请求, 则使用此选项 `BT-TRACE-ID`, (中文(简体) ), `BT-API-KEY` 和(或) `BT-IDEMPOTENCY-KEY`。 。 。 .

```javascript
import { v4 as uuid } from 'uuid';

await bt.applications.list(
  {},
  {
    apiKey: '<Management API Key>',
    correlationId: 'aa5d3379-6385-4ef4-9fdb-ca1341572153',
    idempotencyKey: 'bb5d3379-6385-4ef4-9fdb-ca1341572154',
  }
);

await bt.tokens.create(
  {
    type: "token",
    data: "Sensitive Value",
  },
  {
    apiKey: '<API Key>',
    correlationId: 'aa5d3379-6385-4ef4-9fdb-ca1341572153',
    idempotencyKey: 'bb5d3379-6385-4ef4-9fdb-ca1341572154',
  }
);
```

### 设置自定义 API Url

您可以设置一个自定义的 API Url , 在创建新的 SDK 实例时适用于所有客户端 .

```javascript
import { BasisTheory } from '@basis-theory/basis-theory-js';

const bt = await new BasisTheory().init('<API Key>', {
  apiBaseUrl: 'https://api.somedomain.com',
}); // replace with your application key and api base URL.
```

### 要件

请参考 [要点文档](https://docs.basistheory.com/elements) 关于如何使用它.

## 发展

提供SDK的脚本将检查所有依赖,启动嵌入,构建解决方案,并运行所有测试.

### 依赖关系

-   [夹克](https://www.docker.com/products/docker-desktop)
-   [多克编曲](https://www.docker.com/products/docker-desktop)
-   [节点JS](https://nodejs.org/en/) > 10.12.0
-   [雅伦](https://classic.yarnpkg.com/en/docs/)

### 构建 SDK 并运行测试

从工程根部运行以下命令 :

```sh
make verify
```

## 常见问题

### @basis-theory/basis-theory-js 是什么？

\[\! \] 这个SDK已经贬值了\. \> \> 时间轴 我们的新节点Js SDK可以在 https://github\.com/Basis-Theory/node-sdk 页面存档备份,存于互联网档案馆 \> 更多信息见我们的文献网站\. https://developers\.basistheory\.com/docs/sdks/server-side/node 页面存档备份,存于互联网档案馆

### 如何安装 @basis-theory/basis-theory-js？

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

### @basis-theory/basis-theory-js 支持 TypeScript 吗？

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

### @basis-theory/basis-theory-js 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @basis-theory/basis-theory-js 需要什么版本的 Node\.js？

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

### @basis-theory/basis-theory-js 可以商用吗？

@basis-theory/basis-theory-js 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @basis-theory/basis-theory-js 的下载量有多少？

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

### @basis-theory/basis-theory-js 还在维护吗？

最新版本 4\.30\.2 发布于 2026/07/08（4 个月前）；至今共发布 191 个版本，其中过去 12 个月发布了 2 个；首次发布于 2021/08/13。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

