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

sxt-nodejs-sdk

v2.1.5

Published

An SDK to easily interact with Space and Time

Downloads

192

Readme

SxT-NodeJS-SDK

JavaScript(NodeJS) SDK for Space and Time Gateway (javascript version >= 19.8.0)

Installation Instructions

Installation using a package

npm install sxt-nodejs-sdk

or

yarn add sxt-nodejs-sdk

Then add the following environment values to your .env file

BASEURL_GENERAL="SXT_BASE_URL"
SCHEME=ed25519

Working with source code

Note: Before running the code, rename .env.sample to .env and ensure that your credentials are setup in the .env file properly

npm install

or

yarn

The code in examples/index.ts demonstrates how to call the SDK

Running your project

To run your code, configure the package.json of your project like the following

"scripts": {
    "build": "node --experimental-wasm-modules <YOUR_PROJECT_ENTRY_POINT.js>",
}

The --experimental-wasm-modules flag is required as Web Assembly is used in some parts of the codebase which requires this flag to run the code.

Features

  • Sessions The SDK implements persistent storage in 1. File based sessions

  • Encryption It supports ED25519 Public key encryption for Biscuit Authorization and securing data in the platform.

  • SQL Support

    • Support for DDL : creating own schema(namespace), tables, altering and deleting tables
    • Support for DML: CRUD operation support.
    • Support for SQL: select operations support.
    • Support for SQL Views
  • Platform Discovery For fetching metadata and information about the database resources.

    • Schemas
    • Tables
    • Table Columns
    • Table Indexes
    • Table Primary Keys
    • Table Relationships
    • Table Primary Key References
    • Table Foreign Key References
  • Platform Blockchain For fetching blockchain metadata and information

    • Blockchains
    • Blockchain Schemas
    • Blockchain Information

Examples

  • Initializing the SDK
// Initializing the Space and Time SDK for use.
import { SpaceAndTime } from "sxt-nodejs-sdk";

// Instantiate SXT
const sxt = new SpaceAndTime();
  • Authenticating with the Space and Time Platform

Make sure to save your private key used in authentication and biscuit generation or else you will not be able to have access to the user and the tables created using the key.

The generated AccessToken is valid for 25 minutes and the RefreshToken for 30 minutes.

// Authenticate a user using the Space and Time SDK.
// Auth code
const authentication = sxt.Authentication();

const authCode = await authentication.GenerateAuthCode(userId);
// console.log("Auth Code", authCode.data.authCode);

// Check user
const userExists = await authentication.CheckUser(userId);

const authorization = sxt.Authorization();
if (!userExists.data) {
    // Generate new key pair
    const keyPair = await authorization.GenerateKeyPair();
    keypair = keyPair;
}

// Sign message
const sign = await authorization.GenerateSignature(
    new TextEncoder().encode(authCode.data.authCode),
    keypair.privateKey_64
);
// console.log("Signature", sign.signature);

// Get access token
const accessToken = await authentication.GenerateToken(
    userId,
    authCode.data.authCode,
    sign.signature,
    keypair.publicKeyB64_32
);
// console.log("Access Token", accessToken);
return accessToken.data;

console.log(tokenResponse, tokenError);
  • Generating Biscuits, DDL, DML and DQL

You can create multiple biscuit tokens for a table allowing you to provide different access levels for users. For the list of all capabilities, refer our documentation.

Sample biscuit generation with permissions for select query,insert query, update query, delete query, create table.

const requiredBiscuit = [
    {
        operation: "ddl_create",
        resource: resourceName,
    },
    {
        operation: "ddl_drop",
        resource: resourceName,
    },
    {
        operation: "ddl_alter",
        resource: resourceName,
    },
    {
        operation: "dml_insert",
        resource: resourceName,
    },
    {
        operation: "dml_delete",
        resource: resourceName,
    },
    {
        operation: "dml_update",
        resource: resourceName,
    },
    {
        operation: "dql_select",
        resource: resourceName,
    },
];

const authorization = sxt.Authorization();
const biscuit = await authorization.CreateBiscuitToken(
    requiredBiscuit,
    keypair.biscuitPrivateKeyHex_32
);

Note:

To create a new schema, ddl_create permission is needed.

// Create a table
const createTable = await sqlAPI.DDL(
    `CREATE TABLE ${resourceName}  (id INT PRIMARY KEY, test VARCHAR)`,
    biscuitArray
);
// console.log("CREATE TABLE", createTable);

// Insert
const insertData = await sqlAPI.DML(
    `INSERT INTO ${resourceName} VALUES (5, 'x5')`,
    biscuitArray,
    resourceArray
);
// console.log("INSERT DATA", insertData);

// READ
const readData = await sqlAPI.DQL(
    `SELECT * FROM ${resourceName}`,
    biscuitArray,
    resourceArray
);
// console.log("READ DATA", readData);

// Drop table after test
const dropTable = await sqlAPI.DDL(`DROP TABLE ${resourceName}`, biscuitArray);
// console.log("DROP TABLE", dropTable);
  • DISCOVERY

    Discovery SDK calls need a user to be logged in.

const discovery = sxt.DiscoveryAPI();

// List schemas
const schemas = await discovery.ListSchemas();
console.log(schemas);

// // List tables
const tables = await discovery.ListTables("PUBLIC", "ETHEREUM");

// List table columns
const columns = await discovery.ListColumns("ETHEREUM", "TRANSACTIONS");

// List table indexes
const indexes = await discovery.ListTableIndexes("ETHEREUM", "TRANSACTIONS");