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

pager-duty-js

v0.1.5

Published

PagerDuty API Client

Downloads

7

Readme

PagerDuty JS

GitHub issues GitHub code size in bytes GitHub repo file count GitHub top language GitHub contributors GitHub package.json dependency version (prod) npm NPM

This module provides a set of functions to help JavaScript Developers working with PagerDuty to authenticate and access API endpoints using JavaScript promises.

Requirements (MacOS/Windows)

  • NodeJs
    • Minimum: v14.x
    • Recommended: v16.x
  • npm
    • Tested on: v8.12.x
  • PagerDuty API
    • REST API v2
    • Events API v2

Note: Depending on your Windows setup windows-build-tools may need to be installed first. Also, for MacOS users, you should have xcode-select or entire Xcode App installed.

Install

npm install pager-duty-js --save

Uninstall

npm uninstall pager-duty-js

Release notes and versions

Change log

Class Constructor

{
  // Indicates if the HTTP request to the PagerDuty API server should use
  // HTTPS (secure) or HTTP (non-secure) protocol
  https: true,
  // If https is true, then provide client certificate, client key and
  // the root CA cert (PagerDuty API uses DigiCert one)
  // Client cert and key are optional now
  cert: './client.crt',
  key: './client.key',
  cacert: './ca.crt',
  // Indicate the PagerDuty API URL,
  // all paths are relative to this one
  baseUrl: 'https://api.pagerduty.com',
  // HTTP request timeout in milliseconds
  timeout: 1000,
  // If should use a proxy or not by the HTTP request
  // Example:
  // proxy: { host: proxy.ip, port: proxy.port }
  proxy: false
}

Module usage

Note: This package covers some auth methods and secret engines. Check Coverage and Limitations section for more details.

Rest API

Production

const PagerDuty = require('pager-duty-js');

const pd = new PagerDuty( {
    https: true,
    cert: './client.crt',
    key: './client.key',
    cacert: './digicert-ca.crt',
    baseUrl: 'https://api.pagerduty.com',
    timeout: 1000,
    proxy: false
});

Development

const PagerDuty = require('pager-duty-js');

const pd = new PagerDuty( {
    https: true,
    baseUrl: 'https://api.pagerduty.com',
    timeout: 3000,
    proxy: false
});

Events API

Alerts

const PagerDuty = require('pager-duty-js');

const pd = new PagerDuty( {
    https: true,
    cert: './client.crt',
    key: './client.key',
    cacert: './digicert-ca.crt',
    baseUrl: 'https://events.pagerduty.com/v2',
    rootPath: 'enqueue',
    timeout: 1000,
    proxy: false
});

Change

const PagerDuty = require('pager-duty-js');

const pd = new PagerDuty( {
    https: true,
    cert: './client.crt',
    key: './client.key',
    cacert: './digicert-ca.crt',
    baseUrl: 'https://events.pagerduty.com/v2',
    rootPath: 'change/enqueue',
    timeout: 1000,
    proxy: false
});

Code Sniplets

  • Check abilities for a given Rest API Token:
const status = await pd.listAbilities(token);
  • Create a new user through the Rest API:
const status = await pd.createUser(token, data, requesterEmail);
  • List alls teams through the Rest API:
const status = await pd.listTeams(token, params);
  • Trigger an alert through the Events API:
const status = await pd.triggerEventAlert(integrationKey, data);

Error handling

This package extends the error stack to differentiate if the exception occurred on the PagerDuty API layer or not. Also, adds a help message from the PagerDuty API docs.

try {
  pd.function(...);
}
// An exception happened and it was thrown
catch(err) {
  if(err.isPagerDutyError) {
    // This an error from PagerDuty API
    // Check PagerDuty hint on this error
    console.log(err.pagerDutyHelpMessage);
  }
  else {
    // Here is still the full Axios error, e.g. err.isAxiosError, err.response, err.request
    // This allows handling of network/tls related issues
    // Or just re-throw if you don't care
    throw err;
  }
}

Check below docs for more information on specific function groups.

List of available functions

Rest API

| Group | Link | |:---------------------------------------|:--------------:| | Abilities | Doc | | Teams | Doc | | Users | Doc | | | |

Events API

| Group | Link | |:---------------------------------------|:--------------:| | Alert | Doc | | Change | Doc | | | |

Coverage and Limitations

API rate limiting

  • Check the PagerDuty API rate limits here

Rest API Coverage

The following PagerDuty API groups are currently covered:

  • Abilities (Partially)
  • Teams (Partially)
  • Users (Partially)

Events API Coverage

  • Alert (Full)
    • trigger
    • acknowledge
    • resolve
  • Change (Full)
    • send

Creating your developer account on PagerDuty

Follow the detailed instructions from this site

Contributing

If you want to contribute to the module and make it better, your help is very welcome. You can do so submitting a Pull Request. It will be reviewed and merged to main branch if accepted.

Reporting an issue

If you have found what you believe to be an issue with pager-duty-js please do not hesitate to file an issue on the GitHub repository here.

Suggesting a new feature

If you want to see new features or enhancements to the current ones, we would love to hear them. Please submit an issue on the GitHub repository here.

Authors

Written by Rod Anami [email protected], June 2022.

Contributors

  • None

License

This project is licensed under the Eclipse Public License 2.0.

PagerDuty API usage follows the PagerDuty Developer Agreement.