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

statewize-client-sdk

v2.7.4

Published

Report to STATEWIZE using this SDK

Downloads

75

Readme

STATEWIZE Client SDK 🔍 ✅

Used to report events to STATEWIZE.

Official docs: https://docs.statewize.com

USAGE

  1. Add package to your project (NodeJS / React / Anything JS)
yarn add statewize-client-sdk

OR

npm install statewize-client-sdk
  1. Import and initialize (using the API key from your account)
import {StatewizeClient} from 'statewize-client-sdk';

const sdk = new StatewizeClient(procee.env.YOUR_API_KEY);

You can fetch your API key here.

  1. Download your journey integration map from the journey planner canvas

  1. Report events as and when required
const {eventTrackingId} = await sdk.reportEvent({
  yourId: "Your Tracking ID",
  type: "started",
  slug: journeyMap.YOUR_STATE_NAME, // from step 3
  yourUserId: 'your-user-1',
});

... some time passes ...

await sdk.reportEvent({
  eventTrackingId,
  type: "finisned",
  slug: journeyMap.YOUR_STATE_NAME, // from step 3
  yourUserId: 'your-user-1'
});

Attachments

You can include attachments with state events. Simply provide the attachments in the attachments array.

Attachment types:

  1. Text
  2. JSON objects
  3. Files
  4. URLs

example:

  await sdk.reportEvent({
    yourId: `Your ID for this whole journey`,
    stateId: journeyMap.START_HERE, // from step 3 
    type: 'finished',

    // optional
  eventTrackingId: `Event Tracking ID received from reportEvent`,

    // optional:
    attachments: [
        {
            type: 'text',
            content: {content: `LOG: info: ${new Date().toISOString()} Selfie verification completed`}
        },
        {
            type: 'url',
            content: {url: 'https://images.unsplash.com/photo-1566241440091-ec10de8db2e1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2076&q=80'}
        },
        {
            type: 'file',
            content: {buffer: Buffer.from("test-buffer"), fileName: 'test-text.txt'}
        },
    ]
});

Enriching user data

You can provide additional user data for users that you track. We don't know who your users are, and we don't use their information for any purposes. But for your own logging purposes, if you're interested to attach some rich data about the users you track - you can do so using setUserData method.

For example:

await sdk.setUserData({yourUserId: 'user-1234', data: {something: 'important'}});

Switching the execution id

Let's say you've started tracking a journey using one id, but then you have another ID you'd like to use for this specific execution. For example, you may have started tracking an e-commerce order using an auto-generated ID on the marketing site, but now you'd like to use your own orderId - something you didn't have before - for the same execution.

You can do that by calling:

await sdk.switchId({oldId: 'your-old-id', newId: 'your-new-id'});

Please be aware that execution IDs are unique, so the switch may fail if the ID is already used by you in another execution.

For any questions and support, feel free to reach out to [email protected]

Feature Flags

You can use the STATEWIZE SDK in order to fetch available feature-flags. The feature flags will be returned for the environmend that you've initially passed to the SDK's constructor. If no environment is passed, the production environment will be used by default.

const featureFlags = await sdk.getFeatureFlags();
// Will return something like:
// {
//    'your-feature-flag-key': 'someValue',
//    'another-one': false,
//    'now-a-json-one': {
//        "zim": "zoom"
//    },
// }

We've also prepared a wrapper for you, which would execute its callback only if a feature flag has a truthy value.

For example:

await sdk.withFeatureFlag('your-feature-flag-key', async (featureFlagValue) => {
  // This code will be executed ONLY if the value of `your-feature-flag-key` is truthy.
  // The parameter received by the callback - `featureFlagValue` - will contain the
  // value of the feature flag.
  
  console.log("Hello!");
});