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/client

v1.28.5

Published

Communicate with Percy's API to create builds and snapshots, upload resources, and finalize builds and snapshots. Uses [`@percy/env`](.packages/env) to send environment information with new builds. Can also be used to query for a project's builds using a

Downloads

1,822,457

Readme

@percy/client

Communicate with Percy's API to create builds and snapshots, upload resources, and finalize builds and snapshots. Uses @percy/env to send environment information with new builds. Can also be used to query for a project's builds using a read access token.

Usage

import PercyClient from '@percy/client'

const client = new PercyClient(options)

Options

  • token — Your project's PERCY_TOKEN (default process.env.PERCY_TOKEN)
  • clientInfo — Client info sent to Percy via a user-agent string
  • environmentInfo — Environment info also sent with the user-agent string

Create a build

Creates a percy build. Only one build can be created at a time per instance. During this step, various environment information is collected via @percy/env and associated with the new build. If PERCY_PARALLEL_TOTAL and PERCY_PARALLEL_NONCE are present, a build shard is created as part of a parallelized Percy build.

await client.createBuild()

Create, upload, and finalize snapshots

This method combines the work of creating a snapshot, uploading any missing resources, and finally finalizng the snapshot.

await client.sendSnapshot(buildId, snapshotOptions)

Options

  • name — Snapshot name
  • widths — Widths to take screenshots at
  • minHeight — Miniumum screenshot height
  • enableJavaScript — Enable JavaScript for screenshots
  • clientInfo — Additional client info
  • environmentInfo — Additional environment info
  • resources — Array of snapshot resources
    • url — Resource URL (required)
    • mimetype — Resource mimetype (required)
    • content — Resource content (required)
    • sha — Resource content sha
    • root — Boolean indicating a root resource## Create, upload, and finalize snapshots

Create, upload, and finalize comparisons

This method combines the work of creating a snapshot, creating an associated comparison, uploading associated comparison tiles, and finally finalizing the comparison.

await client.sendComparison(buildId, comparisonOptions)

Options

  • name — Snapshot name (required)
  • clientInfo — Additional client info
  • environmentInfo — Additional environment info
  • externalDebugUrl — External debug URL
  • tag — Tagged information about this comparison
    • name — The tag name for this comparison, e.g. "iPhone 14 Pro" (required)
    • osName - OS name for the comparison tag; e.g. "iOS"
    • osVersion - OS version for the comparison tag; e.g. "16"
    • width - The width for this type of comparison
    • height - The height for this type of comparison
    • orientation - Either "portrait" or "landscape"
  • tiles — Array of comparison tiles
    • sha — Tile file contents SHA-256 hash
    • filepath — Tile filepath in the filesystem (required when missing content)
    • content — Tile contents as a string or buffer (required when missing filepath)
    • statusBarHeight — Height of any status bar in this tile
    • navBarHeight — Height of any nav bar in this tile
    • headerHeight — Height of any header area in this tile
    • footerHeight — Height of any footer area in this tile
    • fullscreen — Boolean indicating this is a fullscreen tile

Finalize a build

Finalizes a build. When all is true, all-shards=true is added as a query param so the API finalizes all other parallel build shards associated with the build.

// finalize a build
await client.finalizeBuild(buildId)

// finalize all parallel build shards
await client.finalizeBuild(buildId, { all: true })

Query for a build

Retrieves build data by id.

Requires a read access token

await client.getBuild(buildId)

Query for a project's builds

Retrieves project builds, optionally filtered. The project slug can be found as part of the project's URL. For example, the project slug for https://percy.io/percy/example is "percy/example".

Requires a read access token

// get all builds for a project
await client.getBuilds(projectSlug)

// get all builds for a project's "master" branch
await client.getBuilds(projectSlug, { branch: 'master' })

Filters

  • sha — A single commit sha
  • shas — An array of commit shas
  • branch — The name of a branch
  • state — The build state ("pending", "finished", etc.)

Wait for a build to be finished

This method resolves when the build has finished and is no longer pending or processing. By default, it will time out if there is no update after 10 minutes.

Requires a read access token

// wait for a specific project build by commit sha
await client.waitForBuild({
  project: 'percy/example',
  commit: '40-char-sha'
}, data => {
  // called whenever data changes
  console.log(JSON.stringify(data));
})

Options

  • build — Build ID (required when missing commit)
  • commit — Commit SHA (required when missing build)
  • project — Project slug (required when using commit)
  • timeout — Timeout in milliseconds to wait with no updates (default 10 * 60 * 1000)
  • interval — Interval in miliseconds to check for updates (default 10000)