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

@trynova-ai/shadow-js

v1.0.11

Published

A TypeScript library for user session tracking.

Downloads

450

Readme

Shadow JS Client

The Shadow JS client allows you to capture and track user interactions on your web application. You can configure custom plugins, such as the BrowserPlugin, to capture events and scrub sensitive data based on user-defined rules.

Installation

To use the Shadow JS Client, install the package and initialize it in your application:

npm install @trynova-ai/shadow-js

Basic Usage

Below is an example of how to initialize the Shadow client with custom scrubbing rules, event buffering, and sample rate configuration.

// Define custom scrub rules
const customScrubRules = [
  { type: 'id', match: 'credit-card', method: 'mask' },
  { type: 'regex', match: '\\d{4}-\\d{4}-\\d{4}-\\d{4}', method: 'randomize' }
];

// Initialize Shadow client
Shadow.init({
  headers: {
    'X-API-KEY': 'MY_API_KEY', // Your API Key
  },
  url: 'http://localhost:8080', // API endpoint to send captured events
  plugins: [new BrowserPlugin(customScrubRules)], // Attach BrowserPlugin with scrub rules
  buffer: {
    enabled: true,  // Enable event buffering
    maxEvents: 20,  // Buffer up to 20 events before sending
    flushInterval: 10000,  // Flush events every 10 seconds
  },
  sampleRate: 0.1,  // Sample 10% of clients (default is 10%)
});

Configuration Options

  • headers: HTTP headers for authentication, such as API keys.
  • url: The API URL where events are sent.
  • plugins: Array of plugins (e.g., BrowserPlugin) to extend functionality.
  • buffer: Configuration for event buffering:
    • enabled: Enable or disable buffering.
    • maxEvents: The maximum number of events to buffer before sending them.
    • flushInterval: The interval (in milliseconds) to flush events automatically.
  • sampleRate: Percentage of clients that will be tracked (default: 10%).

Scrubbing Rules

You can define custom scrubbing rules to protect sensitive data captured in event payloads. The rules can be based on element IDs or regular expressions matching specific patterns.

Scrubbing Rule Example

const customScrubRules = [
  { type: 'id', match: 'credit-card', method: 'mask' },
  { type: 'regex', match: '\\d{4}-\\d{4}-\\d{4}-\\d{4}', method: 'randomize' }
];

Event Buffering

The client supports event buffering to optimize network usage. Instead of sending events one by one, you can batch multiple events together and send them at defined intervals or when the buffer is full.

buffer: {
  enabled: true,  // Enable event buffering
  maxEvents: 20,  // Buffer up to 20 events
  flushInterval: 10000,  // Flush every 10 seconds
}

Plugins

The Shadow JS client supports plugins to extend its functionality.

plugins: [new BrowserPlugin()];

Sample Rate

You can configure the percentage of users who will be tracked with the sampleRate option. The default value is 0.1 (10%).

sampleRate: 0.1,  // Sample 10% of clients

License

Apache License 2.0