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

@interlink-sa/strings-api

v2.2.3

Published

API for Strings Services

Downloads

16

Readme

strings-api v2.0

The API allows you to use the Strings Services

How to use

Devices Functions

import {createDevices, getDevice, listDevices, deleteDevice} from './api';

let devices = [
    {
        "device_type" : "cmts",
        "short_name" : "DEV001",
        "name" : "Device Name",
        "ip" : "127.0.0.1",
        "password" : "snmp-community",
        "region" : "Santa Fe",
        "city" : "Rosario",
        "location" : {
            "latitude" : -32.9580172,
            "longitude" : -60.6326825
        },
        "extra_data" : {
            "mark" : "CASA Systems",
            "model" : "C40G",
            "docsis" : 3
        },
        string: null
    }
];

/**
 *  Create devices
 * 
 * @param {array} devices - Array with devices objects
 */
createDevices(devices)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get a device
 * 
 * @param {string} deviceId
 */
getDevice("5c9e534dbf29163a949eaa5a")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Search for devices
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 * @param {boolean} aggregate -> Aggregate the String and Parent Device if any
 */
listDevices({city: "Rosario"}, 0, 20, '+ip')
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 *  Search for devices executing complex filters
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
let filter = {device_type: 'cmts', $or: [ { 'stats_powers.rx': {$gte: 20} }, { 'stats_powers.rx': {$lte: 15} } ]};
listDevices(filter, 0, 20)
    .then((result) => {console.log(result)})
    .catch((error) => {console.log(error)});

/**
 * Delete a device
 * 
 * @param {string} deviceId
 */
deleteDevice("5c9e534dbf29163a949eaa5a")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

Metrics Functions

import {saveMetrics, getMetrics, deleteMetrics} from './api';

/* {d:device, t:tags, v: values({time: {tag1:value, tag2:value}})} */

const metrics = [
    {
        "d" : "cmts:EX01",
        "t" : ["aux_xx","aux_yy"],
        "v" : [
            {"1548268817" : {"aux_xx" : 254102, "aux_yy" : 125410}},
            {"1548269117" : {"aux_xx" : 286185, "aux_yy" : 135200}}
        ]
    },{
        "d" : "cmts:EX01",
        "t" : ["aux_yy","aux_xx"],
        "v" : [
            {"1548272817" : {"aux_xx" : 254102, "aux_yy" : 125410}},
            {"1548275117" : {"aux_xx" : 386185, "aux_yy" : 155200}},
            {"1548278117" : {"aux_xx" : 296185, "aux_yy" : 165200}}
        ]
    },
    "cmts:EX01 aux_xx:254103,aux_yy:125025 1548308117",
    "cmts:EX01 aux_xx:true,aux_yy:false 1548308118",
    "cmts:EX01 aux_xx:null,aux_yy:null 1548308119",
    "cmts:EX01 aux_xx:000.45,aux_yy:125.52 1548308120",
    "cmts:EX01 aux_xx:false,aux_yy:125.52 1548308130",
    "cmts:EX01 aux_xx:25 1548308125"
];

/**
 * Save metrics
 * 
 * @param {array} metrics - Array with metrics objects
 */
saveMetrics(metrics)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});


/**
 * Get metrics
 * 
 * @param {array} series - Array with series objects
 */
let series = [{"d" : "cmts:EX01", "t" : ["aux_xx","aux_yy"], "from" : 1548268817, "to" : 1548308240000}];
getMetrics(series)
    .then((result) => {
        let series = result.series;
        console.log(series['cmts:EX01']['aux_xx']);
        console.log(result);
    })
    .catch((error) => {console.log(error); process.exit(0);})

/**
 * Delete metrics
 * 
 * @param {array} metrics - Array with metrics objects
 */
deleteMetrics(series)
    .then((result) => {console.log(result); process.exit(0);})
    .catch((error) => {console.log(error); process.exit(0);})

Strings Functions

import {devicesToString, listStrings, createString, getString, getDevicesWithoutString, deleteString} from './api';

let variable = Date.now();
let stringNname = `New string ${variable}`;

/**
 * Create a string
 * 
 * @param {array} string - Object of string
 */
createString({name: stringNname})
    .then((result) => {console.log(result)})
    .catch((error) => {console.log(error)});

/**
 * Update a string
 * 
 * @param {string} stringId
 * @param {Object} string - Object of string
 */
updateString("5c9e54e3719ace3c59f0fec9", {name: stringNname})
    .then((result) => {console.log(result)})
    .catch((error) => {console.log(error)});


/**
 * Get a string
 * 
 * @param {string} stringId
 */
getString("5c9e54e3719ace3c59f0fec9")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Search for strings
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
listStrings({name: stringName}, 0, 20)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get Status of a string
 * 
 * @param {array} stringId
 */
getStatusOfString(["5c9e54e3719ace3c59f0fec9"])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get Status of a device
 * 
 * @param {array} deviceId
 */
getStatusOfDevice(["5c9e534dbf29163a949eaa5a"])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get Strings attached to a device or a parent device
 * 
 * @param {array} deviceId
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
getStringsOfDevice(["5c9e534dbf29163a949eaa5a"])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Delete a string
 * 
 * @param {string} stringId
 */
deleteString("5c9e54e3719ace3c59f0fec9")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Attach devices to a string
 * 
 * @param {string} stringId
 * @param {array} devices - Array with devicesIds
 */
attachDevicesToString('5c9e54e3719ace3c59f0fec9',['5c9e534dbf29163a949eaa5a','5c9e534dbf29163a949eaa5b'])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Detach devices of string
 * 
 * @param {string} stringId
 * @param {array} devices - Array with devicesIds
 */
detachDevicesOfString('5c9e54e3719ace3c59f0fec9',['5c9e534dbf29163a949eaa5a','5c9e534dbf29163a949eaa5b'])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Search for devices without a string configured
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
getDevicesWithoutString({}, 0, 20)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

Anomalies Functions

/**
 * Search types of anomalies for cablemodems
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
getAnomalies({device_type:'cm'}, 0, 20)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});