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

@heroiclabs/satori-js

v2.7.1

Published

JavaScript client for Satori server written in TypeScript.

Downloads

28

Readme

Satori JavaScript Client

JavaScript client for Satori server written in TypeScript. For browser and React Native projects.

This client implements the full API for interacting with Satori server. It's written in TypeScript with minimal dependencies to be compatible with all modern browsers and React Native.

Full documentation is online - https://heroiclabs.com/docs/javascript-client-guide

Getting Started

You'll need access to an instance of the Satori server before you can connect with the client.

  1. Import the client into your project. It's available on NPM.
npm install @heroiclabs/satori-js

You'll now see the code in the "node_modules" folder and package listed in your "package.json".

  1. Use the connection credentials to build a client object.
import {Client} from "@heroiclabs/satori-js";

const useSSL = false;
const client = new Client("apiKey", "127.0.0.1", 7450, useSSL);

Usage

The client object has many method to execute various features in the server.

Authenticate

To authenticate with the Satori server you must provide an identifier for the user.

const userId = "<UniqueUserId>";

client.authenticate(userId)
  .then(session => {
    _session = session;
    console.info("Authenticated:", session);
  }).catch(error => {
    console.error("Error:", error);
  });

Sessions

When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a Session object.

console.info(session.token); // raw JWT token
console.info(session.refreshToken); // refresh token
console.info("Session has expired?", session.isexpired(Date.now() / 1000));
const expiresAt = session.expires_at;
console.warn("Session will expire at:", new Date(expiresAt * 1000).toISOString());

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

// Assume we've stored the auth token in browser Web Storage.
const authtoken = window.localStorage.getItem("satori_authtoken");
const refreshtoken = window.localStorage.getItem("satori_refreshtoken");

let session = satorijs.Session.restore(authtoken, refreshtoken);

// Check whether a session is close to expiry.

const unixTimeInFuture = Date.now() + 8.64e+7; // one day from now

if (session.isexpired(unixTimeInFuture / 1000)) {
    try
    {
        session = await client.sessionRefresh(session);
    }
    catch (e)
    {
        console.info("Session can no longer be refreshed. Must reauthenticate!");
    }
}

Requests

The client includes lots of builtin APIs for various featyures of the Satori server. These can be accessed with the methods which return Promise objects.

Most requests are sent with a session object which authorizes the client.

const flags = await client.getFlags(session);
console.info("Flags:", flags);

Contribute

The development roadmap is managed as GitHub issues and pull requests are welcome. If you're interested in enhancing the code please open an issue to discuss the changes or drop in and discuss it in the community forum.

Source Builds

Ensure you are using Node v18>.

The codebase is multi-package monorepo written in TypeScript and can be built with esbuild. All dependencies are managed with Yarn.

To build from source, install dependencies and build the satori-js package:

npm install --workspace=@heroiclabs/satori-js && npm run build --workspace=@heroiclabs/satori-js

Run Tests

To run tests you will need access to an instance of the Satori server.

Tests are run against each workspace bundle; if you have made source code changes, you should npm run build --workspace=<workspace> prior to running tests.

npm run test --workspace=@heroiclabs/satori-js-test

Release Process

To release onto NPM if you have access to the "@heroiclabs" organization you can use NPM.

npm run build --workspace=<workspace> && npm publish --access=public --workspace=<workspace>

Generate Docs

API docs are generated with typedoc and deployed to GitHub pages.

To run typedoc:

npm install && npm run docs

License

This project is licensed under the Apache-2 License.