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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cess-js-sdk-nodejs

v0.2.6

Published

A js-sdk for Cess Project with file storage

Downloads

53

Readme

cess-js-sdk-nodejs

About

JS-SDK for Cess Project with file storage.

Supports CommonJS and ES Module import type.

Support usage in both node.js and browsers. If used in browser, please install the Polkadot.js extension in the browser.

Installation

# npm
npm i cess-js-sdk-nodejs --save
# yarn
yarn add cess-js-sdk-nodejs -S
# pnpm
pnpm add cess-js-sdk-nodejs

Example

const { Space, InitAPI, Common, defaultConfig } = require("cess-js-sdk-nodejs");
const wellKnownAcct = {
  addr: "cXgaee2N8E77JJv9gdsGAckv1Qsf3hqWYf7NL4q6ZuQzuAUtB",
  mnemonic: "bottom drive obey lake curtain smoke basket hold race lonely fit walk",
  gatewayAddr: "cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9",
};

async function main() {
  const { api, keyring } = await InitAPI(defaultConfig);
  const { addr, mnemonic } = wellKnownAcct;

  const space = new Space(api, keyring);
  /*
    const bucket = new Bucket(api, keyring, true);
    const space2 = new Space2(api, keyring, true);
    const authorizeHandle = new Authorize(api, keyring, true);
    const fileHandle = new File(
      api,
      keyring,
      config.gatewayURL,
      true
    );
  */
  const common = new Common(api, keyring);

  console.log("query userOwnedSpace:");
  let result = await space.userOwnedSpace(addr);
  const blockHeight = await common.queryBlockHeight();

  result = common.formatSpaceInfo(result.data, blockHeight);
  console.log(result);

  function getDataIfOk(result) {
    return result.msg === "ok" ? result.data : result;
  }

  if (result.totalSpace) {
    console.log("expansionSpace:");
    result = await space.expansionSpace(mnemonic, 1);
    console.log(getDataIfOk(result), "\n");

    console.log("renewalSpace:");
    result = await space.renewalSpace(mnemonic, 1);
    console.log(getDataIfOk(result), "\n");
  } else {
    console.log("buySpace:");
    result = await space.buySpace(mnemonic, 1);
    console.log(getDataIfOk(result), "\n");
  }

  console.log("query userOwnedSpace:");
  result = await space.userOwnedSpace(addr);
  result = common.formatSpaceInfo(result.data, blockHeight);
  console.log(result);
}

main()
  .catch(console.error)
  .finally(() => process.exit());

More examples are in the examples directory.

To run them all, run the command:

pnpm examples

All examples connect to the Testnet and use the account cXgaee2N8E77JJv9gdsGAckv1Qsf3hqWYf7NL4q6ZuQzuAUtB as default with the following mnemonic:

bottom drive obey lake curtain smoke basket hold race lonely fit walk

This is the well-known development account in Substrate. If you don't have the token needed, please fetch it from the Testnet faucet.

CESS Testnet RPC Endpoints

'wss://testnet-rpc.cess.cloud/ws/',
'wss://testnet-rpc.cess.network/ws/',

CESS Testnet Faucet

https://testnet-faucet.cess.cloud/

CESS Testnet Public Gateway

Address: https://deoss-pub-gateway.cess.cloud/
Account: cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9

APIs

CESS Config

The config object of CESSConfig type is:

const testnetConfig = {
  nodeURL: "wss://testnet-rpc0.cess.cloud/ws/",
  keyringOption: { type: "sr25519", ss58Format: 42 },
  gatewayURL: "http://deoss-pub-gateway.cess.cloud/",
};

function buildConfig(nodeURL, gatewayURL, keyringOption) {
  return {
    nodeURL,
    gatewayURL,
    // default value for keyring option
    keyringOption: keyringOption || {
      type: "sr25519",
      ss58Format: 42,
    },
  };
}

Space

  • userOwnedSpace(accountId32: string): Promise<APIReturnedData>
  • buySpace(mnemonic: string, gibCount: number): Promise<any>
  • expansionSpace(mnemonicOrAccountId32: string, gibCount: number): Promise<any>
  • renewalSpace(mnemonic: string, days: number): Promise<any>

Authorize

  • authorityList(accountId32: string): Promise<APIReturnedData>
  • authorize(mnemonic: string, operator: string): Promise<any>
  • cancelAuthorize(mnemonic: string, operator: string): Promise<any>

Bucket

  • queryBucketNames(accountId32: string): Promise<APIReturnedData>
  • queryBucketList(accountId32: string): Promise<APIReturnedData>
  • queryBucketInfo(accountId32: string, name: string): Promise<APIReturnedData>
  • createBucket(mnemonic: string, accountId32: string, name: string): Promise<any>
  • deleteBucket(mnemonic: string, accountId32: string, name: string): Promise<any>

File

  • queryFileListFull(accountId32: string): Promise<APIReturnedData>
  • queryFileList(accountId32: string): Promise<APIReturnedData>
  • queryFileMetadata(fileHash: string): Promise<APIReturnedData>
  • uploadFile(mnemonic: string, accountId32: string, filePath: string, bucketName: string): Promise<any>
  • downloadFile(fileHash: string, savePath: string): Promise<any>
  • deleteFile(mnemonic: string, accountId32: string, fileHashArray: string[]): Promise<any>