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

@bitcapital/core-sdk

v2.121.1

Published

bitcapital-core-sdk ===================

Downloads

306

Readme

bitcapital-core-sdk

A multi-platform SDK for accessing the Bitcapital Core services in JS and TS environments.

Getting started (From GitHub)

Install as a project dependency using Yarn, remember to specify the desired version.

yarn add "@bitcapital/core-sdk";

Or use NPM:

npm install "@bitcapital/core-sdk";

Getting started (From source)

Install the dependencies and make sure everything is OK by running the automated tests.

yarn install
yarn test

Prepare the changes for publishing using the Typescript compiler

yarn run build

Configuring your Client

To start using this SDK you need both a Client ID and a Client Secret, emitted by the Bitcapital Core Team. If you don't have yours yet, contact them at https://bitcapital.com.br/developers.

Configure your Bitcapital SDK instance.

  import Bitcapital, { Session, StorageUtil, MemoryStorage } from '@bitcapital/core-sdk';

  let bitcapital: Bitcapital;
  bitcapital = Bitcapital.getInstance();

  // Initialize the session instance to authenticate
  const sessionConfig = {
    baseURL: 'https://your-instance.btcore.app',
    clientId:'< YOUR CLIENT_ID HERE >',
    clientSecret: '< YOUR CLIENT_SECRET HERE >',
    instanceId:  '< YOUR INSTANCE_ID HERE >',
  };

  const session = new Session({
    http: sessionConfig,
    oauth: sessionConfig,
    storage: new StorageUtil('session', new MemoryStorage()),
    sessionUnauthorizedHandler: async () => {
      await bitcapital.session().clientCredentials();
    },
  });

  bitcapital = Bitcapital.initialize({ session, ...sessionConfig });

  try {
    // Authenticate in the Bitcapital Platform 
    await bitcapital.session().clientCredentials();

    const user = await bitcapital.session().password({
      email: '[email protected]',
      password: '12345678',
    });
    const { current } = bitcapital.session(); 
    console.log(`Successfully authenticated in the Bitcapital platform: ${user}`)
  } catch (exception) { 
    console.error(exception);
  }
  

Accessing library modules

Library modules:

  • bitcapital.assets(): Handles asset creation, emition and destruction.
  • bitcapital.consumers(): Creates, updates, validates and deactivates consumer accounts.
  • bitcapital.domains(): Creates, updates and removes domains from the network.
  • bitcapital.payments(): Send payments between wallets and access its history.
  • bitcapital.users(): Manages user accounts in the network.
  • bitcapital.wallets(): Creates, updates and deactivates wallets in the network.

Internal Modules:

  • bitcapital.session(): Manages credentials in the SDK.
  • bitcapital.oauth(): Manages authentication in the Bitcapital OAuth 2.0 provider.

Utility Modules:

  • bitcapital.sign(): Handles requests signature. Automatically called in required API requests.

Documentation

Library Reference

Full API specification is located at: https://sdk.btcore.app.

Using a Custom Session

The SDK comes with a built-in set of Storage providers: Memory and Local. In NodeJS environments, only Memory is available.

To override the default storage for your platform, pass it in the Session constructor:

// Initialize a custom session with desired storage
const session = Session.initialize({
  storage: new StorageUtil('session', new MemoryStorage()),
  oauth: {
    baseURL: data.baseURL,
    clientId: data.clientId,
    clientSecret: data.clientSecret,
  },
  http: {
    baseURL: data.baseURL,
    clientId: data.clientId,
    clientSecret: data.clientSecret,
  }
});

// Initialize bitcapital service with specified credentials
const bitcapital = Bitcapital.initialize({
  // Pass your custom session instance
  session,
  // Other initialization configs...
  baseURL: data.baseURL,
  clientId: data.clientId,
  clientSecret: data.clientSecret,
});

Creating a custom Storage provider

To implement another Storage mechanism, extend the StorageUtilEngine interface.

import { StorageUtilEngine } from "@bitcapital/core-sdk";

export default class MemoryStorage implements StorageUtilEngine {
  protected data: any = {};

  async setItem(key: string, value: string): Promise<any> {
    this.data[key] = value;
    return value;
  }
  async getItem(key: string): Promise<any> {
    return this.data[key];
  }
  async removeItem(key: string): Promise<void> {
    delete this.data[key];
  }
  async clear(): Promise<void> {
    this.data = {};
  }
}

LICENSE

UNLICENSED