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

mezon-sdk

v2.7.65

Published

Mezon typescript SDK.

Downloads

887

Readme

Mezon JavaScript Client

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

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

Full documentation is online - https://mezon.ai/docs/javascript-client-guide

Getting Started

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

  1. Import the client into your project. It's available on NPM.
npm install mezon-sdk

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 "mezon-sdk";
const client = new Client("apiKey");

Usage

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

Authenticate

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

const appId = "<AppId>";

client.authenticate(appId)
  .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 Mezon 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 mezon-sdk package:

npm install --workspace=mezon-sdk && npm run build --workspace=mezon-sdk

Run Tests

To run tests you will need access to an instance of the Mezon 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=mezon-sdk-test

Release Process

To release onto NPM if you have access to the "@mezon" 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.