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

ohdear-js-sdk

v0.2.0

Published

An SDK to easily work with the Oh Dear API

Downloads

3

Readme

Oh Dear JS SDK

This SDK lets you perform API calls to Oh Dear.

Documentation

List of contents

  • Installation
  • Authentication
  • Sites
    • Get all sites in your account
    • Get site by id
    • Get site by url
    • Create new site
    • Delete a site
    • The Site Object
  • Checks
    • Enabling a check
    • Disabling a check
    • Request a check run
  • Uptime
    • Uptime Object
  • Downtime
    • Downtime Object
  • BrokenLinks
    • BrokenLink Object
  • MixedContent
    • MixedContent Object
  • Certificate Health
    • CertificateHealth Object
  • Errors

Installation #

Using npm:

npm install ohdear-js-sdk

and then import OhDear from ohdear-js-sdk

import OhDear from 'ohdear-js-sdk'

Authentication #

  1. Get your api token from your ohdear app, Please, refer to this link for more information.
  2. create new instance from OhDear and pass the api token via the constructor.
const ohdear = new OhDear(token)

Sites #

Get, create or delete site

Get all sites in your account #

ohdear.sites(options): list all your sites in your account, This will return a promise that resolves with an array of Site or rejects with an error.

the Site # object has the following properties

id: ...
url: '...',
sortUrl: '...',
checks: [
    {
        id: ...,
        type: '...',
        label: '...',
        enabled: true|false
    }
]

The options object have the following structure:

options = {
    page: {
        size: 1,
        number: 200
    },
    sort: null,
    filter: {
        teamID: null
    }
}

You're allowd to use sites method without providing any parameters. To know more about the provided parameters, please refer to this link.

Get site by id #

ohdear.site(siteID) : It will return a promise that resolves with Site object or rejects with an error.

Get site by url #

ohdear.siteByUrl(url) : It will return a promise that resolves with Site object or rejects with an error.

Create new site #

ohdear.createSite(url, teamID): let's you add a site through SDK, url is the new site url while teamID is your team id. It will return a promise that resolves with Site object or rejects with an error.

Delete a site #

ohdear.deleteSite(id) where id is the site ID, It will return a promise that resolves with boolean or rejects with an error.

Checks #

manage the Oh Dear! checks per site

Enabeling a check #

ohdear.enableCheck(id) where id is the check id, It will return a promise that resolves with boolean or rejects with an error.

Disabling a check #

ohdear.disableCheck(id) where id is the check id, It will return a promise that resolves with boolean or rejects with an error.

Request a check run #

If you want Oh Dear! to perform a specific check now, call the requestRun(id) method

ohdear.requestRun(id) where id is the check id, It will return a promise that resolves with boolean or rejects with an error.

Uptime #

ohdear.uptime(id, startedAt, endedAt, split='day') lets you get uptime for site, The method expects four parameters

  • id: site id.
  • startedAt: a date in the form of YmdHis that determines the start of the range you want to get uptime for.
  • endedAt: a date in the form of YmdHis that determines the start of the range you want to get uptime for.
  • split: a string that determines how fine grained the answer periods should be. Valid values are hour, day and month.

It will return a promise that resolves with an array of Uptime objects or rejects with an error.

the Uptime # object has the following properties

{
    datetime: '...',
    uptimePercentage: ...
}

Downtime #

ohdear.downtime(id: number, startedAt: string, endedAt: string) lets you get downtime for site, The method expects three parameters

  • id: site id.
  • startedAt: a date in the form of YmdHis that determines the start of the range you want to get uptime for.
  • endedAt: a date in the form of YmdHis that determines the start of the range you want to get uptime for.

It will return a promise that resolves with an array of Downtime objects or rejects with an error.

the Downtime # object has the following properties

{
    startedAt: '...',
    endedAt: '...',
}

Broken Links #

ohdear.brokenLinks(id) where id is the site id, lets you get list of broken links in the site. It will return a promise that resolves with and array of BrokenLink objects or rejects with an error.

the BrokenLink # object has the following properties

{
    statusCode: ...,
    crawledUrl: '...',
    foundOnUrl: '...'
}

Mixed Content #

ohdear.mixedContent(id) where id is the site id, . It will return a promise that resolves with and array of MixedContent objects or rejects with an error.

the MixedContent # object has the following properties

{
    elementName: '...',
    mixedContentUrl: '...',
    foundOnUrl: '...'
}

Certificate Health #

ohdear.certificateHealth(id) where id is the site id, . It will return a promise that resolves with and array of CertificateHealth objects or rejects with an error.

the CertificateHealth # object has the following properties

{
    //The details of the certificate that was found for the site.
    certificateDetails: {
        issuer: '...',
        valid_from: '...',
        valid_until: '...',
    } ,

    //An array of checks that were performed on the certificate
    certificateChecks: [
        {
            type: '...',
            label: '...'
            passed: '...'
        },
        ...
    ],

    //An array with all the issuer names in the chain of the certificate.
    certificateChainIssuers: ['...', '...']
}

Errors #

All available methods will return a Promise that will reject with different types of errors when an error occurs, here's the list of available errors. All errors has a code property that identifies the error.

Here's a list of error with their properties

FailedActionError

thrown when method fails getting the data

{
    code: 400,
    message: '...'
}

ValidationError

thrown when there's a validation error

{
    code: 422,
    message: '...'
    errors: [] // an array of errors
}

NotFoundError

thrown when site or check was not found

{
    code: 404,
    message: '...'
}

UnknownError

thrown when some unknown error happens

{
    code: 0,
    message: '...'
}

Credits

License

The MIT License (MIT).