npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-metabox

v0.0.2

Published

MetaBox 多链版本SDK

Readme

MetaBox js sdk

MetaBox 多链版本SDK

Get Start

Install

npm install js-metabox

Usage

import {MetaBox, Box} from "js-metabox";
import {HttpAgent} from "@dfinity/agent";

(async () => {

  /**
   * ic 的身份
   */
  const agent = new HttpAgent({
    identity: Identity,
    host: "https://ic0.app"
  });
  /**
   * 创建MetaBox实例
   */
  const MBApi = new MetaBox(agent)
  /**
   *   在MetaBox中的account ID
   *   如果你想用 ICP 创建 Box 的话需要向这个地址打入足够的ICP
   *  目前只支持用 icp 创建 Box
   */
  const accountId = await MBApi.getICAccountID()

  /**
   * 获取创建 Box 需要的费用
   *
   */
  const amount = await MBApi.getRequiredToken("icp")

  /**
   * 可以通过多种代币 创建 Box
   * 目前支持只 icp
   */
  const boxId = await MBApi.createBox({
    'is_private': true,
    'box_name': "test"
  })

  /**
   * 获取用户所有的Box
   *
   */
  const boxes = await MBApi.getAllBoxes({ICP: UserID})

  /**
   * 升级Box
   *
   */
  const upgradeRes = await MBApi.upgradeBox({
    'canister_id': boxId,
    'is_private': true,
    'box_name': "test",
  })

  /**
   * 获取Box 最新版本
   *
   */
  const lastestVersion = Number(await MBApi.getBoxLatestVersion())


  /**
   * 创建Box实例
   *
   */
  const boxApi = new Box(boxId.toString(), agent)

  /**
   * 上传明文数据
   *
   */
  const fileKey = await boxApi.uploadPlaintextFile({
    data: "hello world",
    isPrivate: true,
    chain: "icp", // 目前只支持 icp
    fileKey: "xxx",//可指定该数据file Key
  })

  /**
   * 获取明文数据
   * @argument {string} file Key
   */
  const data = await boxApi.getPlaintextFile("xxx")

  /**
   * 删除明文数据
   *
   */
  const deleteRes = await boxApi.deletePlaintextFile("xxx")

  /**
   *
   * 获取指定file的信息
   *
   * @param {string} fileKey
   * @return {Result_2}
   */
  const fileInfo = await boxApi.getFileInfo("xxx")

  /**
   * 获取 Box 版本
   *
   */
  const version = Number(await boxApi.getBoxVersion())


  /**
   * 获取 Box 中所有文件的信息
   *
   */
  const allInfo = await boxApi.getAllFileInfo()

  /**
   *
   * 分享明文且private的文件
   *
   * @param shareFileArg
   */
  const shareRes = await boxApi.sharePrivatePlaintextFile({
    file_key: "xxx",
    to: Principal.from("xxxx")
  })

  /**
   * 取消分享
   *
   */
  const cancleShareRes = await boxApi.cancelSharePrivatePlaintextFile({
    file_key: "xxx",
    to: Principal.from("xxxx")
  })

  /**
   * 文件过多的时候,可以分批获取文件的信息
   *
   */
  const fileCount = await boxApi.getFileCount({'Plain': null})

  /**
   * 分页get数据
   *
   * @param {FileLocation} fileLocation 文件位置
   * @param {number} onePageFileCount 每一页的数据大小 不能超过5000
   * @param {number} pageIndex 取哪一页
   * @example
   * getFilesOfPage({Plain:null},2,0) 取明文数据,每一页有两个数据,取第一页
   */
  const filesInfo = await boxApi.getFilesOfPage({Plain: null}, 2, 0)

})()
/**
 * 监视Box状态函数
 *
 *
 */
import {Box, isSecurityThresholdReached} from "js-metabox";

const BoxApi = new Box(cid, agent)
try {
  await isSecurityThresholdReached(BoxApi)
} catch (e) {
  if (e.message === "Insufficient memory available in this box") {  //表示此box内存不足
    //....建议更换Box存储
  } else if (e.message === "The Box has hit its safe cycle limit") {//表示Box cycles不足以维持他静态存储40天
    const needCycle = e.data //至少需要充值 ${needCycle} 才能维持40天静态存储
  } else throw e
}