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

@chenyufei2022/hive-js-sdk

v2.2.4

Published

Elastos Hive JS SDK

Downloads

7

Readme

Elastos Hive JS SDK

Elastos Hive is an essential service infrastructure as a decentralized network of Hive nodes presenting data storage capabilities to dApps. And the JS SDK provides a group of APIs for Elastos dApps to easily access and store application data to remote Vault services on Hive nodes with the following features:

  • Subscribe/unsubscribe to vault or backup vault
  • Scripting execution
  • Upload/Download files
  • Structured data object access and store onto MongoDB (Not supported yet)
  • Key/Values (Not supported yet);

Elastos Hive will keep the promise that users remain in full control of their own data and committing the practice on it.

SDK integration with NodeJS

To add the Hive JS SDK dependency to your project, run the following command from your source folder:

npm i --save @elastosfoundation/hive-js-sdk

Build from source

Preparing with the developer tool git, and then run the following commands to clone the source:

git clone https://github.com/elastos/Elastos.NET.Hive.JS.SDK
cd Elastos.NET.Hive.JS.SDK
npm install
npm run types
npm run build

Test configuration

Before running tests, the local user directory must be defined with the following command:

export HIVE_USER_DIR=/path/to/user/dir

Then, modify the "provider" field tests/src/res/custom.json to point to your own local hive node.

Run NodeJS tests

From the source folder, build the project, then run the following commands:

cd tests
npm run clean
npm install
npm run test:node

Run Browser tests

From the source folder, build the project, then run the following commands:

cd tests
npm run clean
npm install
npm run test:browser

Writing tests

The test context is based on the TestData class located in /tests/src/config/testdata.ts. The creation of this class will create the test context and set the user directory. The class should be created before each test using the following code:

testData = await TestData.getInstance("TEST SUITE NAME", CONFIGURATION, "OPTIONAL USER DIRECTORY");

Example:

testData = await TestData.getInstance("My service tests", ClientConfig.LOCAL);

Note: The optional third parameter of the TestData.getInstance method is the user directory which defaults to the path defined by the HIVE_USER_DIR environment variable (See Test configuration. You may also specify a custom folder, but it's recommended to only use this parameter on a local workstation for validation.

Test example

import {
  VaultSubscriptionService,
  PricingPlan,
} from "@elastosfoundation/hive-js-sdk";
import { ClientConfig } from "../config/clientconfig";
import { TestData } from "../config/testdata";

describe("pricing plans", () => {
  let testData: TestData;
  let vaultSubscriptionService: VaultSubscriptionService;

  beforeEach(async () => {
    testData = await TestData.getInstance(
      "pricingplans.test",
      ClientConfig.TESTNET
    );
    vaultsubscriptionService = new VaultSubscriptionService(
      testData.getAppContext(),
      testData.getProviderAddress()
    );
  });

  test("get vault pricing plans", async () => {
    let plans: PricingPlan[] =
      await vaultsubscriptionService.getPricingPlanList();
    expect(plans).not.toBeNull();
    expect(plans.length).toBeGreaterThan(0);
  });
});

Usage

In order to subscribe to a vault (create) a user needs to implement AppContextProvider

export class ApiServiceContextProvider implements AppContextProvider {
    getLocalDataDir = () : string => {
        ...
    };

    getAppInstanceDocument = async () : Promise<DIDDocument> => {
       ...
    };

    getAuthorization = async (authenticationChallengeJWtCode: string): Promise<string> => {
      ...
    }
}

let vaultSubscriptionService : VaultSubscription = new VaultSubscription(appContext, "[hiveNode address]");
let vaultInfo = await vaultSubscriptionService.subscribe();

The same mechanics is used by VaultService, which provides all services to interact with hive vault

let vaultServices = new Vault(appContext, "[hiveNode address]");
let scriptingService = vaultServices.getScriptingService();
let filesService = vaultServices.getFilesService();
let databaseService = vaultServices.getDatabaseService();
...