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

@two00/core

v1.0.3

Published

[![npm](https://img.shields.io/npm/v/@two00/core.svg?style=flat-square)](https://www.npmjs.com/package/@two00/core) [![Travis branch](https://img.shields.io/travis/two00-com/core/master.svg?style=flat-square)](https://travis-ci.org/two00-com/core) [![Code

Downloads

6

Readme

@two00/core

npm Travis branch Codecov branch

The core of the public api for two00

Table of Contents

Installation

$ npm i @two00/core -S

Functions

This package exposes some Functions with different use cases:

api

This Function creates a new Object. Wich exposes the public api of two00.

Syntax

const { api } = require("@two00/core");

const myApi = api(options);
Parameters
  • options: Object - options to change api url, routes, etc...

Default options

const defaultOptions = {
  config: {
    // `String`
    apiVersion: "0", // holds the actual two00 public api version
    // `Object`
    api: {
      // `Boolean`
      enableMonitors: true,
      // `Number`
      timeout: 3000,
      // `String`
      url: "https://api.two00.xyz",
      // `Object`
      routes: {
        // `Object`
        serverMonitor: {
          // `String`
          healthCheck: "/rest/health-check",
        },
      },
    },
  },
  // `Function`
  onError: () => {},
  // `Function`
  onUpdateAvailable: () => {},
};
Return value

Returns a new Object.

  • Object holds two keys
    • fetch: Function - async function to call the public two00 api
    • serverMonitor: Object holds one key
      • ping: Function - function to be used within the fetch function to POST the health-check status

Usage

const { api, serverMonitor } = require("@two00/core");

// you can pass a default options `Object` or call setConfig() or setOptions() before api()
const myApi = api();

// serverMonitor() is an asynchronous `Function`
const sm = await serverMonitor();

const response = async () =>
  // myApi.fetch() is an asynchronous `Function`
  await myApi.fetch(api.serverMonitor.ping("UUID", { serverMonitor: sm }));

api fetch

This asynchronous Function calls the public two00 api.

Syntax

const { api } = require("@two00/core");

const myApi = api();

const response = myApi.fetch(apiFunction);
Parameters
Return value

Returns a new Object. The response from the api.

  • Object holds seven keys
    • status: Number - the status code returend from the request
    • data: ObjectString | Number - the data returned from the request
    • headers: Object - the headers returned from the request
    • config: Object - the config for axios
    • errors: Object - the errors returned from the request
    • ok: Boolean - status >= 200 && status <= 299
    • duration: Number - duration (milliseconds) of the request

Usage

const { api, serverMonitor } = require("@two00/core");

const myApi = api();

// serverMonitor() is an asynchronous `Function`
const sm = await serverMonitor();

const response = async () =>
  // myApi.fetch() is an asynchronous `Function`
  await myApi.fetch(api.serverMonitor.ping("UUID", { serverMonitor: sm }));

api serverMonitor ping

This Function calls the public two00 api.

Syntax

const { api } = require("@two00/core");

const myApi = api();

const response = myApi.fetch(myApi.serverMonitor.ping(id, serverMonitor));
Parameters
  • id: String - UUID of the serverMonitor from two00
  • serverMonitor: Object - information about cpu, memory and filesystem usage. to generate the serverMonitor Object use the serverMonitor function of this package
Return value

Returns a new Object. The response from the api.

Usage

const { api, serverMonitor } = require("@two00/core");

const myApi = api();

// serverMonitor() is an asynchronous `Function`
const sm = await serverMonitor();

const response = async () =>
  // myApi.fetch() is an asynchronous `Function`
  await myApi.fetch(api.serverMonitor.ping("UUID", { serverMonitor: sm }));

setConfig

This Function overwrites the default config Object.

Syntax

const { setConfig } = require("@two00/core");

setConfig(config);
Parameters
  • config: Object

Default config:

const defaultConfig = {
  // `String`
  apiVersion: "0", // holds the actual two00 public api version
  // `Object`
  api: {
    // `Boolean`
    enableMonitors: true,
    // `Number`
    timeout: 3000,
    // `String`
    url: "https://api.two00.xyz",
    // `Object`
    routes: {
      // `Object`
      serverMonitor: {
        // `String`
        healthCheck: "/rest/health-check",
      },
    },
  },
};
Return value

Returns undefined.

Usage

const { api, setConfig } = require("@two00/core");

// important to call setConfig() before api()
setConfig({
  apiVersion: "1",
  api: {
    enableMonitors: false,
    timeout: 5000,
    url: "https://my-api.com",
    routes: {
      serverMonitor: {
        healthCheck: "/my/health-check",
      },
    },
  },
});

const myApi = api();

setOptions

This Function overwrites the default options Object.

Syntax

const { setOptions } = require("@two00/core");

setOptions(options);
Parameters
  • options: Object

Default options

const defaultOptions = {
  config: {
    // `String`
    apiVersion: "0", // holds the actual two00 public api version
    // `Object`
    api: {
      // `Boolean`
      enableMonitors: true,
      // `Number`
      timeout: 3000,
      // `String`
      url: "https://api.two00.xyz",
      // `Object`
      routes: {
        // `Object`
        serverMonitor: {
          // `String`
          healthCheck: "/rest/health-check",
        },
      },
    },
  },
  // `Function`
  onError: () => {},
  // `Function`
  onUpdateAvailable: () => {},
};
Return value

Returns undefined.

Usage

const { api, setOptions } = require("@two00/core");

// important to call setConfig() before api()
setOptions({
  config: {
    apiVersion: "1",
    api: {
      enableMonitors: false,
      timeout: 5000,
      url: "https://my-api.com",
      routes: {
        serverMonitor: {
          healthCheck: "/my/health-check",
        },
      },
    },
  },
  onError: err => console.log(err),
  onUpdateAvailable: version =>
    console.log(`Update to new api version: ${version}`),
});

const myApi = api();

serverMonitor

This asynchronous Function returns a new Object. This Object holds information about the cpu, memory, and disc space usage of the computer on which this Function is executed.

Syntax

const { serverMonitor } = require("@two00/core");

// serverMonitor() is an asynchronous `Function`
await serverMonitor();
Parameters

This Function does not take any parameters

Return value

Returns a new Object. The information about the cpu, memory, and disc space usage of the computer on which this Function is executed.

Usage

const { serverMonitor } = require("@two00/core");

// serverMonitor() is an asynchronous `Function`
const systemInformation = await serverMonitor();

Objects

This package exposes some Objects:

apiOptions

This Object holds the default options for the api Function

Default options

const defaultOptions = {
  config: {
    // `String`
    apiVersion: "0", // holds the actual two00 public api version
    // `Object`
    api: {
      // `Boolean`
      enableMonitors: true,
      // `Number`
      timeout: 3000,
      // `String`
      url: "https://api.two00.xyz",
      // `Object`
      routes: {
        // `Object`
        serverMonitor: {
          // `String`
          healthCheck: "/rest/health-check",
        },
      },
    },
  },
  // `Function`
  onError: () => {},
  // `Function`
  onUpdateAvailable: () => {},
};

Use without two00

This software was built with the intend to be used with two00, however you are not bound to any limitations whatsoever, except to the terms under the MIT © Lukas Aichbauer.

If you wish to change the url and routes of this api make use of setConfig, setOptions, or simply fork this repo and build your own solution

LICENSE

MIT © Lukas Aichbauer