@appium/strongbox

中文文档
3.0.0发布于 2026/11/15Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 308.8万

Persistent storage for Appium extensions

原始使用文档
文档目录6 节
  1. Summary
  2. Usage
  3. API
  4. Customization
  5. Default Behavior, For the Curious
  6. License

@appium/strongbox

Persistent storage for Appium extensions

Summary

This package is intended to be used in Appium extensions which need to persist data between Appium runs. An example of such data may be a device token or key.

@appium/strongbox provides a simple and extensible API for managing such data, while abstracting the underlying storage mechanism.

Note: This module is not intended for storing sensitive data.

Usage

First, create an instance of Strongbox:

import {strongbox} from '@appium/strongbox';

const box = strongbox('my-pkg');

This instance corresponds to a unique collection of data.

From here, create a placeholder for data (you will need to provide the type of data you intend to store):

const item = await box.createItem<string>('my unique name');

...or, if you already have the data on-hand:

const item: Buffer|string = getSomeData();

const item = await box.createItemWithContents('my unique name', data);

Either way, you can read its contents:

// if the item doesn't exist, this result will be undefined
const contents = await item.read();

Or write new data to the item:

await item.write('new stuff');

To list persisted items without knowing their names in advance:

const items = await box.listItems();

listItems does not read each file’s contents; call read() on an item when you need them. Item order follows the filesystem directory walk (not lexicographic). It returns every item in one array; for large containers that can use a lot of memory, prefer async iteration, which streams directory entries with opendir instead of buffering all names first:

for await (const item of box) {
  // ...
}

The last-read contents of the Item will be available on the contents property, but the value of this property is only current as of the last read():

const {contents} = item;

API

In lieu of actual documentation, look at the type definitions that this package ships.

Customization

  1. Create a class that implements the Item interface:

    import {strongbox, Item} from '@appium/strongbox';
    import {Foo, getFoo} from 'somewhere/else';
    
    class FooItem implements Item<Foo> {
      // ...
    }
    
  2. Provide this class as the defaultCtor option to strongbox():

    const box = strongbox('my-pkg', {defaultCtor: FooItem});
    
  3. Use like you would any other Strongbox instance:

    const foo: Foo = getFoo();
    const item = await box.createItemWithValue('my unique name', Foo);
    

Default Behavior, For the Curious

Out-of-the-box, a Strongbox instance corresponds to a directory on-disk, and each Item (returned by createItem()/createItemWithContents()) corresponds to a file within that directory.

The directory of the Strongbox instance is determined by the env-paths package, and is platform-specific.

License

Copyright © 2023 OpenJS Foundation. Licensed Apache-2.0

版本与发布记录

@appium/strongbox 共发布 20 个版本,首次发布于 2023/04/08;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.0latest2026/11/15今天
3.0.0-beta.1beta2026/10/051 个月前
2.0.12026/09/251 个月前
3.0.0-beta.02026/09/201 个月前
2.0.02026/08/252 个月前
1.1.32026/07/253 个月前

其他发布通道:rc → 1.0.0-rc.1,beta → 3.0.0-beta.1。

关于 @appium/strongbox 的常见问题

@appium/strongbox 是什么?

Persistent storage for Appium extensions

如何安装 @appium/strongbox?

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

@appium/strongbox 支持 TypeScript 吗?

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

@appium/strongbox 支持 ESM 还是 CommonJS?

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

@appium/strongbox 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.22.2 || ^24.15.0 || >=26.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@appium/strongbox 可以商用吗?

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

@appium/strongbox 的下载量有多少?

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

@appium/strongbox 还在维护吗?

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