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

@testboxlab/node-sdk

v0.0.1

Published

A Node.js helper library to integrate products into TestBox

Downloads

9

Readme

TestBox Node.js SDK

Test, build, publish code style: prettier Conventional Commits

Usage

Installation

First, install the SDK into your project.

npm install @testboxlab/node-sdk
yarn add @testboxlab/node-sdk

Configure the SDK

When your project is initialized, you need to configure the SDK. You can configure wherever you'd like, but you must configure the SDK before trying to accept trial requests from TestBox.

import { configureTestBox } from "@testboxlab/node-sdk";

configureTestBox({
    productId: "my-slugified-product-name",
});

The productId is provided to you by TestBox. It's important to use the correct one, as this value is used in verifying JWT signatures.

Set up a route

TestBox requests trials from its partners as needed using a webhook. Create a webhook in your web application to accept these requests. For example, in an Express project...

const app = express();

// The exact URL does not matter, this is just for illustration purposes
app.post("/api/testbox/trial", (req, res) => {
    // See the next step below...
});

This SDK provides some helper functions for popular web frameworks. For example, Express projects can use this helper...

import { TestBoxTrialRequest } from "@testboxlab/node-sdk";

const app = express();

app.post("/api/testbox/trial", (req, res) => {
    const trialRequest = TestBoxTrialRequest.fromExpressRequest(req);

    // First, call your business logic to create an account/trial

    // See the next step...
});

However, if you do not wish to use a helper, here is an example of instantiating the class and authenticating the request from TestBox.

import { TestBoxTrialRequest, TestBoxTrial } from "@testboxlab/node-sdk";

const app = express();

app.post("/api/testbox/trial", async (req, res) => {
    const trialRequest = new TestBoxTrialRequest(req.body);
    
    const tokenVerified = await trialRequest.verifyToken(req.headers["authorization"]);
    if (!tokenVerified) {
        // The token verification failed, meaning someone is trying to pretend to be
        // TestBox! Do not process their request.
        return res.status(401);
    }

    // You may now safely provision an account for TestBox to use. Here is an illustration.
    const myTrial = new Account();
    myTrial.email = "[email protected]"
    myTrial.subdomain = "tbx-random-sudomain";
    await myTrial.save();

    // Once you have provisioned an account, we need to start telling TestBox about it.
    const testboxTrial = new TestBoxTrial();
    testboxTrial.setEmail(myTrial.email) // we use the randomly generated email for SSO login
        .setSubdomain(myTrial.subdomain) // we need the subdomain in order to put users into your applicatio
        .setApiKey(myTrial.apiKey) // we use API keys to ingest data into a trial
        .setJwtSecret(myTrial.sso.jwt.secret); // you may use JWT SSO to authenticate our mutual users into your application

    // Once we have finished populating the details of our trial, we need
    // to fulfill the request. Whenever possible, respond to TestBox synchronously
    // using a 201 HTTP code. 200 HTTP codes will be ignored, as we will assume
    // that you are creating the trial asynchronously.
    trialRequest.express.fulfill(trial, res);
});

Report bugs or security issues

To report a bug, please feel free to open an issue on this repository.

To report a security issue, please email us directly.