@basis-theory/basis-theory-js

中文文档
4.30.2发布于 2026/07/08Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 16.3万

[!CAUTION] > This SDK has been deprecated. > > Our new Node.js SDK can be found at https://github.com/Basis-Theory/node-sdk > > See our documentation site for more information. https://developers.basistheory.com/docs/sdks/server-side/node

原始使用文档
文档目录10 节
  1. Installation
  2. Documentation
  3. Usage
  4. Initialization
  5. Per-request configuration
  6. Setting a custom API Url
  7. Elements
  8. Development
  9. Dependencies
  10. Build the SDK and run Tests

Basis Theory JS SDK (aka BasisTheory.js)

[!CAUTION] This SDK has been deprecated.

Our new Node.js SDK can be found at https://github.com/Basis-Theory/node-sdk

See our documentation site for more information. https://developers.basistheory.com/docs/sdks/server-side/node

Version Downloads Verify

The Basis Theory JS SDK

Installation

Using Node Package Manager

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

Using Yarn

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

Documentation

For a complete list of endpoints and examples, please refer to our API docs

Usage

Initialization

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

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

Per-request configuration

All of the service methods accept an optional RequestOptions object. This is used if you want to set a per-request BT-TRACE-ID, BT-API-KEY and/or BT-IDEMPOTENCY-KEY.

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',
  }
);

Setting a custom API Url

You can set a custom API Url to be used across all clients when creating a new SDK instance.

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.

Elements

Please, refer to the Elements Documentation on how to use it.

Development

The provided scripts with the SDK will check for all dependencies, start docker, build the solution, and run all tests.

Dependencies

Build the SDK and run Tests

Run the following command from the root of the project:

make verify

版本与发布记录

@basis-theory/basis-theory-js 共发布 191 个版本,首次发布于 2021/08/13;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.30.2latest2026/07/084 个月前
4.30.12026/06/114 个月前
4.30.02025/07/191.3 年前
4.29.02025/07/171.3 年前
4.28.22025/03/121.7 年前
4.28.12025/02/221.7 年前

其他发布通道:main → 1.0.0-alpha.30。

关于 @basis-theory/basis-theory-js 的常见问题

@basis-theory/basis-theory-js 是什么?

[!CAUTION] > This SDK has been deprecated. > > Our new Node.js SDK can be found at https://github.com/Basis-Theory/node-sdk > > See our documentation site for more information. 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 和提交记录判断。