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 🙏

© 2025 – Pkg Stats / Ryan Hefner

strap-sdk-node

v1.0.3

Published

Easy API service communication with Strap

Readme

NodeJS > Strap Server-Side SDK

Strap Server-Side SDK provides an easy to use, chainable API for interacting with our API services. Its purpose is to abstract away resource information from our primary API, i.e. not having to manually track API information for your custom API endpoint.

Strap Server-Side SDK keys off of a global API discovery object using the read token for the API. The Strap Server-Side SDK extracts the need for developers to know, manage, and integrate the API endpoints.

The a Project API discovery can be found here:

HEADERS: "X-Auth-Token": GET https://api2.straphq.com/discover

Installation

npm install strap-sdk-node

Initialization

Once you create your strap instance, a call to strap.discover() must be made before interacting with any strap API. Once complete, strap will emit a ready event.

// Setup strap SDK, passing in the Read Token for the Project
var StrapSDK = require('strap-sdk-node'),
    strap = new StrapSDK({ token: '{Read Token for Strap Project}' });

// Tell Strap to get started
Strap.discover();

// Listen for ready before interacting with Strap
Strap.once('ready', function () {
    // Okay to use strap
});

Basic Usage

Once strap has initialized, all available resources will be exposed directly on your sdk instance. Each resource will expose a get method for fetching data via the API.

strap.once('ready', function () {

    // Provided parameters are delivered with the request
    strap.users.get({}, function (err, users) {

    });

    // is equivalent to for requests without URL parameteres
    strap.users.get(function (err, users) {

    });

    // If the resource has a path parameter, you may pass it short hand
    // like this
    strap.activity.get('userguid', function (err, activity) {

    });
});

Pagination

Several strap APIs are paginated using a "page" parameter. You have a couple options for dealing with this.

First, you can use the resource all method to instruct the SDK to handle pagination for you and build a list of all records. This may be a bad idea for a large dataset.

The parameters provided to all may be omitted.

strap.once('ready', function () {

    strap.week.all({}, function (err, reports) {

    });

    // is equivalent to
    strap.week.all(function (err, reports) {

    });
});

The second option for handling paginated requests is to create an iterator and parse it yourself. Here, we will use async.whilst.

strap.once('ready', function () {

    // Can provide request parameters here
    var iter = strap.week.iter();

    async.whilst(function () {
        // Whether to continue
        return iter.hasNext();
    }, function (cb) {
        // Fetch next batch
        iter.getNext(function (err, reports) {

            /* handle reports */

            cb();
        });
    }, function (err) {
        // Iter complete
    });
});

API

    // List available endpoints
    Strap.endpoints();
    // No Params

    // Muliple Optional Param can be passed in as an object
    // Strap.activity.get( {day: "YYYY-MM-DD", guid: "demo-strap"}, callback )
    // URL resources can be passed as Strings or in the Array
    // Strap.activity.get( "demo-strap", callback )

    // Every endpoint has the get() method
    // Get a record or set of records
    Strap.activity.get( params, callback ); 

    // Fetch a user's activity
    // URL resource: "guid"
    // Optional: "date", "count", "start", "end"  >> "start" and "end" use "YYYY-MM-DD" format
    Strap.activity.get("guid", function (err, data) {
        /* etc */
    });

    // Fetch a user's behavior profile
    // URL resource: "guid"
    // Optional: none
    Strap.behavior.get("guid", function (err, data) {
        /* etc */
    });

    // Fetch the micro-segmentation job list or a individual micro-segmentation job
    // URL resource: "id"
    // Optional: "id", "status"
    Strap.job.get({params}}, function (err, data) {
        /* etc */
    });

    // Create a micro-segmentation job
    // URL resource: none
    // Required: "name"
    // Optional: "description", "guids", "startDate", "endDate", "notificationUrl"  >> "guids" is an array of guid strings
    Strap.job.post({params}, function (err, data) {
        /* etc */
    });

    // Update a micro-segmentation job
    // URL resource: "id"
    // Optional: "name", "description"
    Strap.job.put({params}, function (err, data) {
        /* etc */
    });

    // Delete a micro-segmentation job
    // URL resource: "id"
    Strap.job.delete("job-id", function (err, data) {
        /* etc */
    });

    // Fetch the micro-segmentation job data
    // URL resource: "id"
    // Optional: "id"
    Strap.job_data.get({params}}, function (err, data) {
        /* etc */
    });

    // Fetch all user data for month
    // URL resource: none
    // Optional: "guid", "page", "per_page"
    Strap.month.get({}, function (err, data) {
        /* etc */
    });

    // Fetch a report's data
    // URL resource: "id"
    // Optional: none
    Strap.report.get("id", function (err, data) {
        /* etc */
    });

    // Fetch a report's food data
    // URL resource: "id"
    // Optional: "food"
    Strap.report_food.get({params}, function (err, data) {
        /* etc */
    });

    // Fetch a report's raw data
    // URL resource: "id"
    // Optional: "type"
    Strap.report_raw.get({params}, function (err, data) {
        /* etc */
    });

    // Fetch a report's workout data
    // URL resource: "id"
    // Optional: "workout"
    Strap.report_workout.get({params}, function (err, data) {
        /* etc */
    });

    // Fetch the segmentation for the projet
    // URL resource: none
    // Optional: "date", "period"
    Strap.segmentation.get({}, function (err, data) {
        /* etc */
    });

    // Fetch all user data for today
    // URL resource: none
    // Optional: "guid", "page", "per_page"
    Strap.today.get({}, function (err, data) {
        /* etc */
    });

    // Fetch a project or user's trend data
    // URL resource: none
    // Optional: "guid"
    Strap.trend.get({}, function (err, data) {
        /* etc */
    });

    // List project triggers or specific trigger
    // URL resource: none
    // Required: none
    // Optional: "id", "key", "type", "actionType"
    Strap.trigger.get({params}, function (err, data) {
        /* etc */
    });

    // Create a trigger
    // URL resource: none
    // Required: "active", "name", "type", "range", "conditions"
    // Optional: "actionType", "actionUrl"
    Strap.trigger.post({params}, function (err, data) {
        /* etc */
    });

    // Update a trigger
    // URL resource: "id"
    // Optional: "active", "name", "type", "range", "conditions", "actionType", "actionUrl"
    Strap.trigger.put({params}, function (err, data) {
        /* etc */
    });

    // Delete a trigger
    // URL resource: "id"
    Strap.trigger.delete("trigger-id", function (err, data) {
        /* etc */
    });

    // Fetch trigger data
    // URL resource: "id"
    // Optional: "count"
    Strap.trigger_data.get({id: "trigger-id"}, function (err, data) {
        /* etc */
    });

    // Fetch a simple user object
    // URL resource: "guid"
    // Optional: none
    Strap.user.get({}, function (err, data) {
        /* etc */
    });

    // Fetch a user list for the Project
    // URL resource: none
    // Optional: "platform", "count"
    Strap.users.get({}, function (err, data) {
        /* etc */
    });

    // Fetch all user data for week
    // URL resource: none
    // Optional: "guid", "page", "per_page"
    Strap.week.get({}, function (err, data) {
        /* etc */
    });

    // Fetch a project or user's wordcloud
    // URL resource: none
    // Optional: "guid"
    Strap.wordcloud.get({}, function (err, data) {
        /* etc */
    });
});

REPL

Strap also ships with a repl should you be interested in playing around with it. And example screen shot is included: