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

@percy.ai/sdk

v2.0.2

Published

PercySDK is a TypeScript-based SDK that allows sending signals from a frontend application to an endpoint using a POST request. It is designed to be configurable for different environments and follows good practices for front-end SDKs, such as using worke

Downloads

6

Readme

PercySDK

PercySDK is a TypeScript-based SDK that allows sending signals from a frontend application to an endpoint using a POST request. It is designed to be configurable for different environments and follows good practices for front-end SDKs, such as using workers to avoid blocking UI threads and implementing retries.

Installation

To install PercySDK, use pnpm, npm or yarn:

npm install percy-sdk

or

yarn add percy-sdk

Usage

Frontend Application

To use PercySDK in your frontend application, import and instantiate it with the necessary options:

import PercySDK from "percy-sdk";

const percySDK = new PercySDK({
  environment: "production",
  clientKey: "YOUR_CLIENT_KEY",
});

const signal: Signal = {
  id: "unique-signal-id",
  signal: "avm_view",
  body: {
    meta: "data",
  },
};

percySDK.sendSignal(signal);

HTML based Website

To use PercySDK in your website, import and instantiate it with the necessary options:

<body>
  <script src="https://cdn.jsdelivr.net/npm/@percy.ai/sdk@latest/dist/umd/percy-sdk.min.js></script>

  <script>
    const percySDK = new PercySDK.default({
      clientKey: "YOUR_CLIENT_KEY",
    });

    const percySnapshotButton = document.getElementById("percySnapshotButton");

    percySnapshotButton.addEventListener("click", async () => {
      percySDK.sendSignal({
        id: "unique-signal-id",
        signal: "avm_view",
        body: {
          meta: "data",
        },
      });
    });
  </script>
</body>

Configuration

The PercySDK constructor accepts an options object with the following properties:

  • clientKey (required): The Client key used for authentication when sending signals to the endpoint.
  • environment (optional): Specifies the environment. It can be either 'production' or 'development'. Defaults to 'production'.
  • maxRetries (optional): The maximum number of retries to attempt if a request fails. Defaults to 3.
  • retryDelay (optional): The delay (in milliseconds) between retries. Defaults to 1000.

Signal Interface

The Signal interface represents the structure of a signal that can be sent using PercySDK. It has the following properties:

  • id (required): A unique identifier for the signal.
  • topic (required): The topic or category of the signal.
  • body (required): The payload data of the signal.

Sending Signals

To send a signal using PercySDK, create a Signal object and pass it to the sendSignal method:

const signal: Signal = {
  id: "unique-signal-id",
  signal: "signal-topic",
  body: {
    // Signal data object
  },
};

percySDK.sendSignal(signal);

The sendSignal method posts a message to the worker with the signal data and SDK configuration options. The worker then sends the signal to the endpoint using a POST request with the specified headers and body.

Error Handling and Retries

PercySDK implements error handling and retries to ensure reliable signal delivery. If a request fails, the SDK will retry the request up to the specified maxRetries times with a delay of retryDelay milliseconds between each retry.

If the maximum number of retries is reached and the request still fails, the signal will be discarded, and no further attempts will be made.

Browser Support

PercySDK is compatible with modern browsers that support Web Workers and the Fetch API. It has been tested on the following browsers:

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

License

PercySDK is released under the MIT License.