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

status-jockey

v2.0.3

Published

Response filter for Statuspage.io API

Downloads

6

Readme

status-jockey

Coverage Status npm version

Incidents response filter for the Statuspage.io Incidents API

Note: Version 2 makes a huge number of breaking changes to the usage of this package. V1 documentation can be found in the wiki

Features

  • Makes API calls to the Status and Manage APIs at Statuspage.io. See more information comparing these two APIs here
  • Can filter and manipulate the response based on the following criteria:
    • filterByStatus: only include incidents which match specific statuses.
    • customFilter: only include incidents which match a provided filter function
    • maps: map an incident datum to a new key
    • keys: only include specific keys (including keys generated by maps)
  • Returns Promise from axios-based fetch
  • Function imports optimized for tree shaking for minimized browser use in Webpack.

Installation

yarn add status-jockey
# OR
npm install status-jockey

Usage

Configuration

const config = {
    // only return incidents with the following statuses.
    // Otherwise, return all.
    filterByStatus: ["investigating", "completed"],
    // Only return incidents which return true for a filter function
    customFilter: ({ backfilled }) => backfilled,
    // Maps incident values to custom key values.
    maps: {
      // can map each entry to a new key based on a string identifying old key
      title: "name",
      incident_link: "shortlink",
      // or based on a function which takes the incident item object
      most_recent_message: ({ incident_updates }) => incident_updates[0].body,
      status: ({ status }) => {
        switch (status) {
          case "investigating":
            return "red";
          case "identified":
            return "orange";
          case "monitoring":
            return "green";
          default:
            return "red";
        }
      },
      hashtags: ({ incident_updates }) => {
        const body = incident_updates[0].body;
        return body && body.match(/#\w+/g) ? body.match(/#\w+/g).map(v => v.replace('#', '')) : [];
      }
    },
    // Only return the following keys for each incident
    // Non-mapped keys are given their default values.
    keys: ["id", "most_recent_message", "incident_link", "created_at", "status", "hashtags"],
  }
};

statusApi: Public Status API (v2)

statusApi(config) -> statusApiFetcher({ page_id, type, limit })

  • page_id (required): Queries the incidents of the corresponding statuspage.io page id.
  • type (optional): Queries one .json files specified in the Statuspage public API (default: incidents)
    • components
    • incidents
    • incidents/unresolved
    • incidents/unresolved
    • scheduled-maintenances
    • scheduled-maintenances/upcoming
    • scheduled-maintenances/active
  • limit (optional): Limits to the X most recent incidents in response (default: no limit).
const config = {
  // your configuration
}

const { statusApi } = require('status-jockey');
const fetchStatusApi = statusApi(config)

fetchStatusApi({ page_id: 'abcd123', type: 'incidents', limit: 5 })
  .then(dataList => {
    // do something with dataList (array of incidents/maintenances)
  });

manageApi: Manage API (v1)

manageApi(config) -> manageApiFetcher({ page_id, type, limit })

  • page_id (required): Queries the incidents of the corresponding statuspage.io page id.
  • type (optional): Queries scheduled, unresolved, or incidents (default: incidents)
  • limit (optional): Limits to the X most recent incidents in response (default: no limit).
const config = {
  // your configuration
}

const { manageApi } = require('status-jockey');

const key = '1234567890' // SECRET Statuspage.io API key goes here
const fetchManageApi  = manageApi(config, key)=

fetchManageApi({ page_id: 'abcd123', type: 'incidents', limit: 5 })
  .then(dataList => {
    // do something with dataList (array of incidents/maintenances)
  })
  .catch(err => {
    // handle error
  })

incidentsFilter

If you would like to fetch the data yourself but utilize the status-jockey response filters. This is useful if would like to exclude axios from your browser package.

Example (pre-Webpacked JS)

import { incidentsFilter } from 'status-jockey' // tree shaking will exclude other imports from the package
const config = {
  // your configuration
}

const filterIncidents = incidentsFilter(config);

$.ajax('http://abcdefg.statuspage.io/api/v2/incidents/unresolved.json')
  .then({ incidents } => {
    // do something...
    return incidents
  }.then(filterIncidents)
  .catch(err => {
    // handle error
  })