From 404e362717bfa6e7665ba94ad99314ea8f8aadcd Mon Sep 17 00:00:00 2001 From: Adriean Khisbe Date: Fri, 1 Mar 2019 15:44:38 +0100 Subject: [PATCH 01/10] Let and Const all the things :hammer_and_wrench: --- lib/api/comment.js | 18 ++++---- lib/api/downtime.js | 16 +++---- lib/api/embed.js | 34 +++++++-------- lib/api/event.js | 44 +++++++++---------- lib/api/graph.js | 24 +++++----- lib/api/host.js | 22 +++++----- lib/api/index.js | 4 +- lib/api/infrastructure.js | 10 ++--- lib/api/metric.js | 48 ++++++++++---------- lib/api/monitor.js | 92 +++++++++++++++++++-------------------- lib/api/screenboard.js | 60 ++++++++++++------------- lib/api/search.js | 10 ++--- lib/api/serviceCheck.js | 14 +++--- lib/api/tag.js | 44 +++++++++---------- lib/api/timeboard.js | 64 +++++++++++++-------------- lib/api/user.js | 10 ++--- lib/client.js | 24 +++++----- 17 files changed, 269 insertions(+), 269 deletions(-) diff --git a/lib/api/comment.js b/lib/api/comment.js index 309c857..ddf9b59 100644 --- a/lib/api/comment.js +++ b/lib/api/comment.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var util = require("util"); +const client = require("../client"); +const util = require("util"); /*section: comment *comment: create a new comment @@ -29,7 +29,7 @@ function create(message, properties, callback){ properties = {}; } - var params = { + const params = { body: { message: message } @@ -73,7 +73,7 @@ function update(commentId, message, handle, callback){ handle = undefined; } - var params = { + const params = { body: { message: message } @@ -134,8 +134,8 @@ module.exports = { }, handleCli: function(subcommand, args, callback){ if(subcommand === "create"){ - var message = args._[4]; - var properties = {}; + const message = args._[4]; + const properties = {}; if(args["handle"]){ properties.handle = args["handle"]; } @@ -144,11 +144,11 @@ module.exports = { } create(message, properties, callback); } else if(subcommand === "update"){ - var commentId = args._[4]; - var message = args._[5]; + const commentId = args._[4]; + const message = args._[5]; update(commentId, message, args["handle"], callback); } else if(subcommand === "remove"){ - var commentId = args._[4]; + const commentId = args._[4]; remove(commentId, callback); } else { callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); diff --git a/lib/api/downtime.js b/lib/api/downtime.js index 5f35a96..b9bd59f 100644 --- a/lib/api/downtime.js +++ b/lib/api/downtime.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var util = require("util"); +const client = require("../client"); +const util = require("util"); /*section: downtime *comment: schedule a new downtime @@ -30,7 +30,7 @@ function create(scope, properties, callback){ properties = {}; } - var params = { + const params = { body: { scope: scope } @@ -81,7 +81,7 @@ function update(downtimeId, properties, callback){ callback = properties; properties = {}; } - var params = { + const params = { body: {} }; if(typeof properties === "object"){ @@ -207,8 +207,8 @@ module.exports = { } else if(subcommand === "remove"){ remove(args._[4], callback); } else if(subcommand === "create"){ - var scope = args._[4]; - var properties = {}; + const scope = args._[4]; + const properties = {}; if(args["start"]){ properties.start = parseInt(args["start"]); } @@ -220,8 +220,8 @@ module.exports = { } create(scope, properties, callback); } else if(subcommand === "update"){ - var downtimeId = args._[4]; - var properties = {}; + const downtimeId = args._[4]; + const properties = {}; if(args["scope"]){ properties.scope = args["scope"]; } diff --git a/lib/api/embed.js b/lib/api/embed.js index c7c33e3..3516e30 100644 --- a/lib/api/embed.js +++ b/lib/api/embed.js @@ -1,7 +1,7 @@ -var client = require("../client"); -var extend = require("extend"); -var json = require("../json"); -var querystring = require("querystring"); +const client = require("../client"); +const extend = require("extend"); +const json = require("../json"); +const querystring = require("querystring"); /*section: embed *comment: create an embed graph of a metric query @@ -15,14 +15,14 @@ var querystring = require("querystring"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var query = "system.cpu.idle{*}"; - * var graphJSON = { + * const query = "system.cpu.idle{*}"; + * const graphJSON = { * viz: "timeseries", * requests: [ * { @@ -33,7 +33,7 @@ var querystring = require("querystring"); * } * ] * } - * var options = { + * const options = { * timeframe: "1_hour", * size: "xlarge", * legend: "yes", @@ -49,7 +49,7 @@ function create(graphJSON, options, callback){ callback = options; options = {}; } - var body = { + const body = { graph_json: JSON.stringify(graphJSON) }; // Use `extend` to merge `options` into `body` @@ -57,7 +57,7 @@ function create(graphJSON, options, callback){ extend(body, options || {}); // Create the request - var params = { + const params = { body: querystring.stringify(body), contentType: "application/x-www-form-urlencoded" }; @@ -72,7 +72,7 @@ function create(graphJSON, options, callback){ * callback: function(err, res) *example: | * ```javascript - * var embedid = "foo"; + * const embedid = "foo"; * dogapi.embed.revoke(embedid, function(err, res){ * console.dir(res); * }); @@ -105,7 +105,7 @@ function getAll(callback) { * callback: function(err, res) *example: | * ```javascript - * var embedId = "foo"; + * const embedId = "foo"; * dogapi.embed.get(embedId, function(err, res){ * console.dir(res); * }); @@ -147,8 +147,8 @@ module.exports = { }, handleCli: function(subcommand, args, callback) { if (args._.length > 4 && subcommand === "create") { - var graph_json = json.parse(args._[4]); - var options = { + const graph_json = json.parse(args._[4]); + const options = { timeframe: args["timeframe"], size: args["size"], legend: args["legend"], @@ -156,10 +156,10 @@ module.exports = { }; create(graph_json, options, callback); } else if (args._.length > 4 && subcommand === "revoke") { - var embedId = args._[4]; + const embedId = args._[4]; revoke(embedId, callback); } else if (args._.length > 4 && subcommand === "get") { - var embedId = args._[4]; + const embedId = args._[4]; get(embedId, callback); } else if (subcommand === "getall") { getAll(callback); diff --git a/lib/api/event.js b/lib/api/event.js index 4c1be38..f568d5d 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var util = require("util"); +const client = require("../client"); +const util = require("util"); /*section: event *comment: | @@ -20,20 +20,20 @@ var util = require("util"); * function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var title = "some new event"; - * var text = "IT HAPPENED!"; + * const title = "some new event"; + * const text = "IT HAPPENED!"; * dogapi.event.create(title, text, function(err, res){ * console.dir(res); * }); * title = "another event"; * text = "IT HAPPENED AGAIN!"; - * var properties = { + * const properties = { * tags: ["some:tag"], * alert_type: "error" * }; @@ -54,7 +54,7 @@ function create(title, text, properties, callback){ properties.title = title; properties.text = text; - var params = { + const params = { body: properties }; client.request("POST", "/events", params, callback); @@ -70,8 +70,8 @@ function create(title, text, properties, callback){ * function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -100,15 +100,15 @@ function get(eventId, callback){ * function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var now = parseInt(new Date().getTime() / 1000); - * var then = now - 3600; // an hour ago - * var parameters = { + * const now = parseInt(new Date().getTime() / 1000); + * const then = now - 3600; // an hour ago + * const parameters = { * tags: "some:tag", * sources: "jenkins" * }; @@ -129,7 +129,7 @@ function query(start, end, parameters, callback){ parameters.start = start; parameters.end = end; - var params = { + const params = { query: parameters }; @@ -169,9 +169,9 @@ module.exports = { if(subcommand === "get" && args._.length > 4){ get(parseInt(args._[4]), callback); } else if(subcommand === "query" && args._.length > 5){ - var from = parseInt(args._[4]); - var to = parseInt(args._[5]); - var parameters = {}; + const from = parseInt(args._[4]); + const to = parseInt(args._[5]); + const parameters = {}; if(args["sources"]){ parameters.sources = args["sources"]; } @@ -180,9 +180,9 @@ module.exports = { } query(from, to, parameters, callback); } else if(subcommand === "create" && args._.length > 5){ - var title = args._[4]; - var text = args._[5]; - var properties = {}; + const title = args._[4]; + const text = args._[5]; + const properties = {}; if(args["priority"]){ properties.priority = args["priority"]; } diff --git a/lib/api/graph.js b/lib/api/graph.js index 7690690..fcbb8a8 100644 --- a/lib/api/graph.js +++ b/lib/api/graph.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var embed = require("./embed"); +const client = require("../client"); +const embed = require("./embed"); /*section: graph *comment: take a snapshot of a metric query @@ -11,15 +11,15 @@ var embed = require("./embed"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var query = "system.cpu.idle{*}"; - * var to = dogapi.now(); - * var from = to - 3600; // an hour ago + * const query = "system.cpu.idle{*}"; + * const to = dogapi.now(); + * const from = to - 3600; // an hour ago * dogapi.graph.snapshot(query, from, to, function(err, res){ * console.dir(res); * }); @@ -30,7 +30,7 @@ function snapshot(query, from, to, eventQuery, callback){ callback = eventQuery; eventQuery = undefined; } - var params = { + const params = { query: { metric_query: query, start: parseInt(from), @@ -63,10 +63,10 @@ module.exports = { }, handleCli: function(subcommand, args, callback){ if (args._.length > 5 && subcommand === "snapshot"){ - var query = args._[4]; - var from = parseInt(args._[5]); - var to = parseInt(args._[6]); - var eventQuery = args["events"]; + const query = args._[4]; + const from = parseInt(args._[5]); + const to = parseInt(args._[6]); + const eventQuery = args["events"]; snapshot(query, from, to, eventQuery, callback); } else { callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); diff --git a/lib/api/host.js b/lib/api/host.js index 7a88c93..dbe86d8 100644 --- a/lib/api/host.js +++ b/lib/api/host.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var util = require("util"); +const client = require("../client"); +const util = require("util"); /*section: host *comment: mute the given host, if it is not already muted @@ -12,8 +12,8 @@ var util = require("util"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -28,7 +28,7 @@ function mute(hostname, options, callback){ callback = options; options = {}; } - var params = {}; + const params = {}; if(typeof options === "object"){ params.body = {}; // create body property if(options.end){ @@ -50,8 +50,8 @@ function mute(hostname, options, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -62,7 +62,7 @@ function mute(hostname, options, callback){ * ``` */ function unmute(hostname, callback){ - var params = {body: ""}; // create empty body + const params = {body: ""}; // create empty body client.request("POST", util.format("/host/%s/unmute", hostname), params, callback); } @@ -89,8 +89,8 @@ module.exports = { }, handleCli: function(subcommand, args, callback){ if(subcommand === "mute"){ - var hostname = args._[4]; - var options = {}; + const hostname = args._[4]; + const options = {}; if(args["end"]){ options.end = parseInt(args["end"]); } @@ -99,7 +99,7 @@ module.exports = { } mute(hostname, options, callback); } else if(subcommand === "unmute"){ - var hostname = args._[4]; + const hostname = args._[4]; unmute(hostname, callback); } else { callback("unknown subcommand or arguments try `dogapi host --help` for help", false); diff --git a/lib/api/index.js b/lib/api/index.js index e96793c..b3914a6 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -1,4 +1,4 @@ -var api = { +const api = { comment: require("./comment"), downtime: require("./downtime"), embed: require("./embed"), @@ -17,7 +17,7 @@ var api = { }; module.exports = function(obj){ - for(var key in api){ + for(const key in api){ obj[key] = api[key]; } }; diff --git a/lib/api/infrastructure.js b/lib/api/infrastructure.js index b96f245..3d0de06 100644 --- a/lib/api/infrastructure.js +++ b/lib/api/infrastructure.js @@ -1,4 +1,4 @@ -var client = require("../client"); +const client = require("../client"); /*section: infrastructure *comment: | @@ -10,8 +10,8 @@ var client = require("../client"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -22,7 +22,7 @@ var client = require("../client"); * ``` */ function search(query, callback){ - var params = { + const params = { query: { q: query } @@ -46,7 +46,7 @@ module.exports = { ]; }, handleCli: function(subcommand, args, callback){ - var query = args._[4]; + const query = args._[4]; search(query, callback); } }; diff --git a/lib/api/metric.js b/lib/api/metric.js index e3b94b8..3750aa3 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -1,4 +1,4 @@ -var client = require("../client"); +const client = require("../client"); /*section: metric *comment: | @@ -17,8 +17,8 @@ var client = require("../client"); * function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -29,7 +29,7 @@ var client = require("../client"); * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ * console.dir(results); * }); - * var now = parseInt(new Date().getTime() / 1000); + * const now = parseInt(new Date().getTime() / 1000); * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ * console.dir(results); * }); @@ -44,7 +44,7 @@ function send(metric, points, extra, callback){ extra = {}; } extra = extra || {}; - var series = [ + const series = [ { metric: metric, points: points, @@ -73,14 +73,14 @@ function send(metric, points, extra, callback){ * function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var now = parseInt(new Date().getTime() / 1000); - * var metrics = [ + * const now = parseInt(new Date().getTime() / 1000); + * const metrics = [ * { * metric: "my.metric", * points: [[now, 1000]], @@ -101,15 +101,15 @@ function send(metric, points, extra, callback){ * ``` */ function send_all(metrics, callback){ - var now = parseInt(new Date().getTime() / 1000); - for(var i = 0; i < metrics.length; ++i){ + const now = parseInt(new Date().getTime() / 1000); + for(let i = 0; i < metrics.length; ++i){ // Try to normalize `points` // DEV: We need `points` to be an array of arrays regardless of what they give us // Always wrap points in an array, this way we will get: // 500 => [500] // [500, 100] => [[, 500], [, 1000]] // [[, 500]] => [[, 500]] - var points = metrics[i].points; + let points = metrics[i].points; if(!Array.isArray(metrics[i].points)){ points = [points]; } @@ -118,7 +118,7 @@ function send_all(metrics, callback){ // 500 => [, 500] // [, 500] => unchanged if(!Array.isArray(point)){ - var now = parseInt(new Date().getTime() / 1000); + const now = parseInt(new Date().getTime() / 1000); point = [now, point]; } return point; @@ -133,7 +133,7 @@ function send_all(metrics, callback){ delete metrics[i].metric_type; } - var params = { + const params = { body: { series: metrics } @@ -151,22 +151,22 @@ function send_all(metrics, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var now = parseInt(new Date().getTime() / 1000); - * var then = now - 3600; // one hour ago - * var query = "system.cpu.idle{*}by{host}"; + * const now = parseInt(new Date().getTime() / 1000); + * const then = now - 3600; // one hour ago + * const query = "system.cpu.idle{*}by{host}"; * dogapi.metric.query(then, now, query, function(err, res){ * console.dir(res); * }); * ``` */ function query(from, to, query, callback){ - var params = { + const params = { query: { from: from, to: to, @@ -201,7 +201,7 @@ module.exports = { }, handleCli: function(subcommand, args, callback){ if(args._.length > 5 && subcommand === "send"){ - var extra = {}; + const extra = {}; if(args.tags){ extra.tags = args.tags.split(","); } @@ -209,9 +209,9 @@ module.exports = { extra.type = args.type; send(args._[4], args._[5], extra, callback); } else if(subcommand === "query" && args._.length > 6){ - var from = parseInt(args._[4]); - var to = parseInt(args._[5]); - var q = args._[6]; + const from = parseInt(args._[4]); + const to = parseInt(args._[5]); + const q = args._[6]; query(from, to, q, callback); } else { callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); diff --git a/lib/api/monitor.js b/lib/api/monitor.js index d506891..381f14a 100644 --- a/lib/api/monitor.js +++ b/lib/api/monitor.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var util = require("util"); +const client = require("../client"); +const util = require("util"); /*section: monitor *comment: create a new monitor @@ -15,14 +15,14 @@ var util = require("util"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var metricType = "metric alert"; - * var query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; + * const metricType = "metric alert"; + * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; * dogapi.monitor.create(metricType, query, function(err, res){ * console.dir(res); * }); @@ -34,7 +34,7 @@ function create(type, query, properties, callback){ properties = {}; } - var params = { + const params = { body: { type: type, query: query @@ -66,8 +66,8 @@ function create(type, query, properties, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -83,7 +83,7 @@ function get(monitorId, groupStates, callback){ groupStates = undefined; } - var params = {}; + const params = {}; if(groupStates){ params.query = { group_states: groupStates.join(",") @@ -104,8 +104,8 @@ function get(monitorId, groupStates, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -120,7 +120,7 @@ function getAll(options, callback){ callback = options; options = {}; } - var params = {}; + const params = {}; if(typeof options === "object"){ params.query = {}; if(options.group_states){ @@ -150,13 +150,13 @@ function getAll(options, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; + * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; * dogapi.monitor.update(1234, query, function(err, res){ * console.dir(res); * }); @@ -168,7 +168,7 @@ function update(monitorId, query, properties, callback){ properties = {}; } - var params = { + const params = { body: { query: query } @@ -198,8 +198,8 @@ function update(monitorId, query, properties, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -224,8 +224,8 @@ function remove(monitorId, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -240,7 +240,7 @@ function mute(monitorId, options, callback){ callback = options; options = {}; } - var params = {}; + const params = {}; if(typeof options === "object"){ params.body = {}; if(options.scope){ @@ -261,8 +261,8 @@ function mute(monitorId, options, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -284,8 +284,8 @@ function muteAll(callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -300,7 +300,7 @@ function unmute(monitorId, scope, callback){ callback = scope; scope = undefined; } - var params = {}; + const params = {}; if(scope){ params.body = { scope: scope @@ -317,8 +317,8 @@ function unmute(monitorId, scope, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -379,24 +379,24 @@ module.exports = { ]; }, handleCli: function(subcommand, args, callback){ - var states = []; + const states = []; if(args["states"]){ states = args["states"].split(","); } - var tags = []; + const tags = []; if(args["tags"]){ tags = args["tags"].split(","); } - var name = args["name"]; - var message = args["message"]; + const name = args["name"]; + const message = args["message"]; if(subcommand === "get"){ - var monitorId = args._[4]; + const monitorId = args._[4]; get(monitorId, states, callback); } else if(subcommand === "getall"){ - var options = {}; + const options = {}; if(states.length){ options.group_states = states; } @@ -405,8 +405,8 @@ module.exports = { } getAll(options, callback); } else if(subcommand === "mute"){ - var monitorId = args._[4]; - var options = {}; + const monitorId = args._[4]; + const options = {}; if(args["scope"]){ options.scope = args["scope"]; } @@ -415,20 +415,20 @@ module.exports = { } mute(monitorId, options, callback); } else if(subcommand === "unmute"){ - var monitorId = args._[4]; - var scope = args["scope"]; + const monitorId = args._[4]; + const scope = args["scope"]; unmute(monitorId, scope, callback); } else if(subcommand === "unmuteall"){ unmuteAll(callback); } else if(subcommand === "muteall"){ muteAll(callback); } else if(subcommand === "remove"){ - var monitorId = args._[4]; + const monitorId = args._[4]; remove(monitorId, callback); } else if(subcommand === "create" && args._.length > 5){ - var type = args._[4]; - var query = args._[5]; - var properties = {}; + const type = args._[4]; + const query = args._[5]; + const properties = {}; if(name){ properties.name = name; } @@ -437,9 +437,9 @@ module.exports = { } create(type, query, properties, callback); } else if(subcommand === "update" && args._.length > 5){ - var monitorId = args._[4]; - var query = args._[5]; - var properties = {}; + const monitorId = args._[4]; + const query = args._[5]; + const properties = {}; if(name){ properties.name = name; } diff --git a/lib/api/screenboard.js b/lib/api/screenboard.js index 05ebc99..81d9686 100644 --- a/lib/api/screenboard.js +++ b/lib/api/screenboard.js @@ -1,6 +1,6 @@ -var client = require("../client"); -var json = require("../json"); -var util = require("util"); +const client = require("../client"); +const json = require("../json"); +const util = require("util"); /*section: screenboard @@ -22,14 +22,14 @@ var util = require("util"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var boardTitle = "my screenboard"; - * var widgets = [ + * const boardTitle = "my screenboard"; + * const widgets = [ * { * type: "image", * height: 20, @@ -39,7 +39,7 @@ var util = require("util"); * url: "https://path/to/image.jpg" * } * ]; - * var options = { + * const options = { * templateVariables: [ * { * name: "host1", @@ -66,7 +66,7 @@ function create(boardTitle, widgets, options, callback){ options = {}; } - var params = { + const params = { body: { board_title: boardTitle, widgets: widgets @@ -112,14 +112,14 @@ function create(boardTitle, widgets, options, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var boardTitle = "my screenboard"; - * var widgets = [ + * const boardTitle = "my screenboard"; + * const widgets = [ * { * type: "image", * height: 20, @@ -129,7 +129,7 @@ function create(boardTitle, widgets, options, callback){ * url: "https://path/to/image.jpg" * } * ]; - * var options = { + * const options = { * description: "it is super awesome" * }; * dogapi.screenboard.update( @@ -149,7 +149,7 @@ function update(boardId, boardTitle, widgets, options, callback) { options = {}; } - var params = { + const params = { body: { board_title: boardTitle, widgets: widgets @@ -182,8 +182,8 @@ function update(boardId, boardTitle, widgets, options, callback) { * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -204,8 +204,8 @@ function remove(boardId, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -225,8 +225,8 @@ function get(boardId, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -247,8 +247,8 @@ function getAll(callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -306,11 +306,11 @@ module.exports = { } else if(subcommand === "share"){ share(args._[4], callback); } else if (subcommand === "update"){ - var boardId = args._[4]; - var boardTitle = args._[5]; - var widgets = json.parse(args._[6]); + const boardId = args._[4]; + const boardTitle = args._[5]; + const widgets = json.parse(args._[6]); - var options = {}; + const options = {}; if(args["description"]) { options.description = args["description"]; } @@ -326,10 +326,10 @@ module.exports = { update(boardId, boardTitle, widgets, options, callback); } else if(subcommand === "create"){ - var boardTitle = args._[4]; - var widgets = json.parse(args._[5]); + const boardTitle = args._[4]; + const widgets = json.parse(args._[5]); - var options = {}; + const options = {}; if(args["description"]) { options.description = args["description"]; } diff --git a/lib/api/search.js b/lib/api/search.js index 39c700b..b62ee36 100644 --- a/lib/api/search.js +++ b/lib/api/search.js @@ -1,4 +1,4 @@ -var client = require("../client"); +const client = require("../client"); /*section: search *comment: | @@ -8,20 +8,20 @@ var client = require("../client"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var query = "app"; + * const query = "app"; * dogapi.search.query(query, function(err, res){ * console.dir(res); * }); * ``` */ function query(query, callback){ - var params = { + const params = { query: { q: query } diff --git a/lib/api/serviceCheck.js b/lib/api/serviceCheck.js index 6a6e7fe..1fb961d 100644 --- a/lib/api/serviceCheck.js +++ b/lib/api/serviceCheck.js @@ -1,4 +1,4 @@ -var client = require("../client"); +const client = require("../client"); /*section: serviceCheck *comment: | @@ -15,14 +15,14 @@ var client = require("../client"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var check = "app.ok"; - * var hostName = "some.machine"; + * const check = "app.ok"; + * const hostName = "some.machine"; * dogapi.serviceCheck.check( * check, hostName, dogapi.WARNING, function(err, res){ * console.dir(res); @@ -43,7 +43,7 @@ function check(check, hostName, status, parameters, callback){ parameters.host_name = hostName, parameters.status = status; - var params = { + const params = { body: parameters }; client.request("POST", "/check_run", params, callback); @@ -71,7 +71,7 @@ module.exports = { }, handleCli: function(subcommand, args, callback){ if(args._.length > 6){ - var parameters = {}; + const parameters = {}; if(args["time"]){ parameters.time = parseInt(args["time"]); } diff --git a/lib/api/tag.js b/lib/api/tag.js index 3094a36..3f00eab 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -1,5 +1,5 @@ -var client = require("../client"); -var util = require('util'); +const client = require("../client"); +const util = require('util'); /*section: tag @@ -12,8 +12,8 @@ var util = require('util'); * function callback(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -29,7 +29,7 @@ function getAll(source, callback){ source = undefined; } - var params = { + const params = { query: { source: source } @@ -52,8 +52,8 @@ function getAll(source, callback){ * function callback(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -70,7 +70,7 @@ function get(hostname, options, callback){ } options = options || {}; - var params = { + const params = { query: { } }; @@ -98,8 +98,8 @@ function get(hostname, options, callback){ * function callback(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -115,7 +115,7 @@ function create(hostname, tags, source, callback){ source = undefined; } - var params = { + const params = { body: { tags: tags, source: source @@ -140,8 +140,8 @@ function create(hostname, tags, source, callback){ * function callback(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -157,7 +157,7 @@ function update(hostname, tags, source, callback){ source = undefined; } - var params = { + const params = { body: { tags: tags, source: source @@ -178,8 +178,8 @@ function update(hostname, tags, source, callback){ * function callback(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -195,7 +195,7 @@ function remove(hostname, source, callback){ source = undefined; } - var params = { + const params = { query: { source: source } @@ -235,13 +235,13 @@ module.exports = { ]; }, handleCli: function(subcommand, args, callback){ - var source = args["source"]; - var host = args._[4]; + const source = args["source"]; + const host = args._[4]; if(subcommand === "getall"){ getAll(source, callback); } else if(subcommand === "get"){ - var options = {}; + const options = {}; if(source){ options.source = source; } @@ -250,10 +250,10 @@ module.exports = { } get(host, options, callback); } else if(subcommand === "create"){ - var tags = args._[5].split(","); + const tags = args._[5].split(","); create(host, tags, source, callback); } else if(subcommand === "update"){ - var tags = args._[5].split(","); + const tags = args._[5].split(","); update(host, tags, source, callback); } else if(subcommand === "delete"){ remove(host, source, callback); diff --git a/lib/api/timeboard.js b/lib/api/timeboard.js index d3dbe93..9dcf4c4 100644 --- a/lib/api/timeboard.js +++ b/lib/api/timeboard.js @@ -1,6 +1,6 @@ -var client = require("../client"); -var json = require("../json"); -var util = require("util"); +const client = require("../client"); +const json = require("../json"); +const util = require("util"); /*section: timeboard *comment: add a new timeboard @@ -19,15 +19,15 @@ var util = require("util"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var title = "Time Keeps on Slipping"; - * var description = "Into the Future"; - * var graphs = [ + * const title = "Time Keeps on Slipping"; + * const description = "Into the Future"; + * const graphs = [ * { * definition: { * events: [], @@ -39,7 +39,7 @@ var util = require("util"); * title: "Average Memory Free" * } * ]; - * var templateVariables = [ + * const templateVariables = [ * { * name: "host1", * prefix: "host", @@ -60,7 +60,7 @@ function create(title, description, graphs, templateVariables, callback){ templateVariables = []; } - var params = { + const params = { body: { title: title, description: description, @@ -92,15 +92,15 @@ function create(title, description, graphs, templateVariables, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var title = "Time Keeps on Slipping"; - * var description = "Into the Future"; - * var graphs = [ + * const title = "Time Keeps on Slipping"; + * const description = "Into the Future"; + * const graphs = [ * { * definition: { * events: [], @@ -112,7 +112,7 @@ function create(title, description, graphs, templateVariables, callback){ * title: "Average Memory Free" * } * ]; - * var templateVariables = [ + * const templateVariables = [ * { * name: "host1", * prefix: "host", @@ -133,7 +133,7 @@ function update(dashId, title, description, graphs, templateVariables, callback) templateVariables = []; } - var params = { + const params = { body: { title: title, description: description, @@ -154,8 +154,8 @@ function update(dashId, title, description, graphs, templateVariables, callback) * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -175,8 +175,8 @@ function remove(dashId, callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -197,8 +197,8 @@ function getAll(callback){ * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; @@ -248,21 +248,21 @@ module.exports = { } else if(subcommand === "remove"){ remove(args._[4], callback); } else if(subcommand === "create"){ - var title = args._[4]; - var description = args._[5]; - var graphs = json.parse(args._[6]); - var templateVariables = []; + const title = args._[4]; + const description = args._[5]; + const graphs = json.parse(args._[6]); + const templateVariables = []; if(args["tmpvars"]){ templateVariables = json.parse(args["tmpvars"]); } create(title, description, graphs, templateVariables, callback); } else if(subcommand === "update"){ - var dashId = parseInt(args._[4]); - var title = args._[5]; - var description = args._[6]; - var graphs = json.parse(args._[7]); - var templateVariables = []; + const dashId = parseInt(args._[4]); + const title = args._[5]; + const description = args._[6]; + const graphs = json.parse(args._[7]); + const templateVariables = []; if(args["tmpvars"]){ templateVariables = json.parse(args["tmpvars"]); } diff --git a/lib/api/user.js b/lib/api/user.js index e0f21f3..1c45a33 100644 --- a/lib/api/user.js +++ b/lib/api/user.js @@ -1,4 +1,4 @@ -var client = require("../client"); +const client = require("../client"); /*section: user *comment: invite users via e-mail @@ -7,20 +7,20 @@ var client = require("../client"); * callback: function(err, res) *example: | * ```javascript - * var dogapi = require("dogapi"); - * var options = { + * const dogapi = require("dogapi"); + * const options = { * api_key: "api_key", * app_key: "app_key" * }; * dogapi.initialize(options); - * var emails = ["me@domain.com", "you@domain.com"]; + * const emails = ["me@domain.com", "you@domain.com"]; * dogapi.user.invite(emails, fuction(err, res){ * console.dir(res): * }); * ``` */ function invite(emails, callback){ - var params = { + const params = { body: { emails: emails } diff --git a/lib/client.js b/lib/client.js index 275c6db..6f2e28e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,9 +1,9 @@ -var extend = require("extend"); -var https = require("https"); -var json = require("./json"); -var url = require("url"); -var util = require("util"); -var _ = require('lodash'); +const https = require("https"); +const url = require("url"); +const util = require("util"); +const extend = require("extend"); +const _ = require('lodash'); +const json = require("./json"); /*section: client *comment: | @@ -52,8 +52,8 @@ client.prototype.request = function(method, path, params, callback){ params = {body: ''}; // create params with empty body property } - var body = (typeof params["body"] === "object") ? json.stringify(params["body"]) : params["body"]; - var query = { + const body = (typeof params["body"] === "object") ? json.stringify(params["body"]) : params["body"]; + const query = { "api_key": this.api_key, "application_key": this.app_key, }; @@ -67,7 +67,7 @@ client.prototype.request = function(method, path, params, callback){ "query": query, }); - var http_options = _.assign({ + const http_options = _.assign({ hostname: this.api_host, port: 443, method: method.toUpperCase(), @@ -85,20 +85,20 @@ client.prototype.request = function(method, path, params, callback){ }; } - var req = https.request(http_options, function(res){ + const req = https.request(http_options, function(res){ res.on("error", function(err){ if(typeof callback == "function"){ callback(err, null, res.statusCode); } }); - var data = ""; + let data = ""; res.on("data", function(chunk){ data += chunk; }); res.on("end", function(){ - var error = null; + let error = null; try{ data = json.parse(data); }catch(e){} if(data["errors"]){ error = data["errors"]; From 45649fcde174e333b910c2994396de01d1b52a28 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Fri, 1 Mar 2019 18:01:20 +0100 Subject: [PATCH 02/10] Massive refactor trying to have instantiable client :hammer_and_pick: --- lib/api/comment.js | 281 ++++++------- lib/api/downtime.js | 451 ++++++++++---------- lib/api/embed.js | 316 +++++++------- lib/api/event.js | 393 ++++++++--------- lib/api/graph.js | 141 ++++--- lib/api/host.js | 197 ++++----- lib/api/index.js | 2 + lib/api/infrastructure.js | 96 ++--- lib/api/metric.js | 415 +++++++++--------- lib/api/monitor.js | 858 +++++++++++++++++++------------------- lib/api/screenboard.js | 652 ++++++++++++++--------------- lib/api/search.js | 98 ++--- lib/api/serviceCheck.js | 159 +++---- lib/api/tag.js | 481 ++++++++++----------- lib/api/timeboard.js | 513 +++++++++++------------ lib/api/user.js | 89 ++-- lib/client.js | 18 +- lib/index.js | 14 +- test/api/embed.js | 34 +- test/api/metric.js | 12 +- 20 files changed, 2625 insertions(+), 2595 deletions(-) diff --git a/lib/api/comment.js b/lib/api/comment.js index ddf9b59..df5b233 100644 --- a/lib/api/comment.js +++ b/lib/api/comment.js @@ -1,157 +1,158 @@ -const client = require("../client"); const util = require("util"); -/*section: comment - *comment: create a new comment - *params: - * message: the message of the comment - * properties: | - * optional, an object containing any of the following - * * handle: the handle to associate the comment with (e.g. "user@domain.com") - * * related_event_id: the event to associate the comment with - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.comment.create("a comment message", function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function create(message, properties, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = properties; - properties = {}; +module.exports = function (client) { + /*section: comment + *comment: create a new comment + *params: + * message: the message of the comment + * properties: | + * optional, an object containing any of the following + * * handle: the handle to associate the comment with (e.g. "user@domain.com") + * * related_event_id: the event to associate the comment with + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.comment.create("a comment message", function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function create(message, properties, callback) { + if (arguments.length < 3 && typeof arguments[1] === "function") { + callback = properties; + properties = {}; + } + + const params = { + body: { + message: message + } + }; + + if (typeof properties === "object") { + if (properties.handle) { + params.body.handle = properties.handle; + } + if (properties.related_event_id) { + params.body.related_event_id = properties.related_event_id; + } + } + + client.request("POST", "/comments", params, callback); } - const params = { - body: { - message: message + /*section: comment + *comment: update an existing comment + *params: + * commentId: the id of the comment to update + * message: the message of the comment + * handle: optional, the handle to associate the comment with (e.g. "user@domain.com") + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.comment.update(1234, "new message", function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function update(commentId, message, handle, callback) { + if (arguments.length < 4 && typeof arguments[2] === "function") { + callback = handle; + handle = undefined; } - }; - if(typeof properties === "object"){ - if(properties.handle){ + const params = { + body: { + message: message + } + }; + if (handle) { params.body.handle = properties.handle; } - if(properties.related_event_id){ - params.body.related_event_id = properties.related_event_id; - } - } - - client.request("POST", "/comments", params, callback); -} -/*section: comment - *comment: update an existing comment - *params: - * commentId: the id of the comment to update - * message: the message of the comment - * handle: optional, the handle to associate the comment with (e.g. "user@domain.com") - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.comment.update(1234, "new message", function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function update(commentId, message, handle, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = handle; - handle = undefined; + client.request("PUT", util.format("/comments/%s", commentId), params, callback); } - const params = { - body: { - message: message - } - }; - if(handle){ - params.body.handle = properties.handle; + /*section: comment + *comment: remove a comment + *params: + * commentId: the id of the comment to remove + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.comment.remove(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function remove(commentId, callback) { + client.request("DELETE", util.format("/comments/%s", commentId), callback); } - client.request("PUT", util.format("/comments/%s", commentId), params, callback); -} -/*section: comment - *comment: remove a comment - *params: - * commentId: the id of the comment to remove - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.comment.remove(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function remove(commentId, callback){ - client.request("DELETE" ,util.format("/comments/%s", commentId), callback); -} - - -module.exports = { - create: create, - update: update, - remove: remove, - getUsage: function(){ - return [ - " dogapi comment create [--handle ] [--event ]", - " dogapi comment update [--handle ]", - " dogapi comment remove " - ]; - }, - getHelp: function(){ - return [ - "Comment:", - " Subcommands:", - " create add a new comment", - " update update an existing comment", - " remove delete a comment", - "", - " Options:", - " --handle the handle to associate with the comment (e.g. \"user@domain.com\")", - " --event related event id to associate the comment with" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "create"){ - const message = args._[4]; - const properties = {}; - if(args["handle"]){ - properties.handle = args["handle"]; - } - if(args["event"]){ - properties.related_event_id = parseInt(args["event"]); + return { + create: create, + update: update, + remove: remove, + getUsage: function () { + return [ + " dogapi comment create [--handle ] [--event ]", + " dogapi comment update [--handle ]", + " dogapi comment remove " + ]; + }, + getHelp: function () { + return [ + "Comment:", + " Subcommands:", + " create add a new comment", + " update update an existing comment", + " remove delete a comment", + "", + " Options:", + " --handle the handle to associate with the comment (e.g. \"user@domain.com\")", + " --event related event id to associate the comment with" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "create") { + const message = args._[4]; + const properties = {}; + if (args["handle"]) { + properties.handle = args["handle"]; + } + if (args["event"]) { + properties.related_event_id = parseInt(args["event"]); + } + create(message, properties, callback); + } else if (subcommand === "update") { + const commentId = args._[4]; + const message = args._[5]; + update(commentId, message, args["handle"], callback); + } else if (subcommand === "remove") { + const commentId = args._[4]; + remove(commentId, callback); + } else { + callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); } - create(message, properties, callback); - } else if(subcommand === "update"){ - const commentId = args._[4]; - const message = args._[5]; - update(commentId, message, args["handle"], callback); - } else if(subcommand === "remove"){ - const commentId = args._[4]; - remove(commentId, callback); - } else { - callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); } - } + }; }; diff --git a/lib/api/downtime.js b/lib/api/downtime.js index b9bd59f..05eb600 100644 --- a/lib/api/downtime.js +++ b/lib/api/downtime.js @@ -1,242 +1,243 @@ -const client = require("../client"); const util = require("util"); -/*section: downtime - *comment: schedule a new downtime - *params: - * scope: string scope that the downtime should apply to (e.g. "env:staging") - * properties: | - * optional, an object containing any of the following - * * start: POSIX timestamp for when the downtime should start - * * end: POSIX timestamp for when the downtime should end - * * message: a string message to accompany the downtime - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.downtime.create("env:staging", function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function create(scope, properties, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = properties; - properties = {}; - } - - const params = { - body: { - scope: scope - } - }; - if(typeof properties === "object"){ - if(properties.start){ - params.body.start = parseInt(properties.start); +module.exports = function (client) { + /*section: downtime + *comment: schedule a new downtime + *params: + * scope: string scope that the downtime should apply to (e.g. "env:staging") + * properties: | + * optional, an object containing any of the following + * * start: POSIX timestamp for when the downtime should start + * * end: POSIX timestamp for when the downtime should end + * * message: a string message to accompany the downtime + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.downtime.create("env:staging", function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function create(scope, properties, callback) { + if (arguments.length < 3 && typeof arguments[1] === "function") { + callback = properties; + properties = {}; } - if(properties.end){ - params.body.end = parseInt(properties.end); - } - if(properties.message){ - params.body.message = properties.message; + + const params = { + body: { + scope: scope + } + }; + if (typeof properties === "object") { + if (properties.start) { + params.body.start = parseInt(properties.start); + } + if (properties.end) { + params.body.end = parseInt(properties.end); + } + if (properties.message) { + params.body.message = properties.message; + } } + client.request("POST", "/downtime", params, callback); } - client.request("POST", "/downtime", params, callback); -} -/*section: downtime - *comment: update an existing downtime - *params: - * downtimeId: the id the downtie to update - * properties: | - * optional, an object containing any of the following - * * scope: the scope the downtime should be changed to (e.g. "env:staging") - * * start: POSIX timestamp for when the downtime should start - * * end: POSIX timestamp for when the downtime should end - * * message: a string message to accompany the downtime - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * var properties = { - * scope: "env:staging" - * }; - * dogapi.downtime.update(1234, properties, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function update(downtimeId, properties, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = properties; - properties = {}; - } - const params = { - body: {} - }; - if(typeof properties === "object"){ - if(properties.scope){ - params.body.scope = properties.scope; + /*section: downtime + *comment: update an existing downtime + *params: + * downtimeId: the id the downtie to update + * properties: | + * optional, an object containing any of the following + * * scope: the scope the downtime should be changed to (e.g. "env:staging") + * * start: POSIX timestamp for when the downtime should start + * * end: POSIX timestamp for when the downtime should end + * * message: a string message to accompany the downtime + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * var properties = { + * scope: "env:staging" + * }; + * dogapi.downtime.update(1234, properties, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function update(downtimeId, properties, callback) { + if (arguments.length < 3 && typeof arguments[1] === "function") { + callback = properties; + properties = {}; } - if(properties.start){ - params.body.start = parseInt(properties.start); - } - if(properties.end){ - params.body.end = parseInt(properties.end); - } - if(properties.message){ - params.body.message = properties.message; + const params = { + body: {} + }; + if (typeof properties === "object") { + if (properties.scope) { + params.body.scope = properties.scope; + } + if (properties.start) { + params.body.start = parseInt(properties.start); + } + if (properties.end) { + params.body.end = parseInt(properties.end); + } + if (properties.message) { + params.body.message = properties.message; + } } + client.request("PUT", util.format("/downtime/%s", downtimeId), params, callback); } - client.request("PUT", util.format("/downtime/%s", downtimeId), params, callback); -} -/*section: downtime - *comment: delete a scheduled downtime - *params: - * downtimeId: the id of the downtime - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.downtime.remove(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function remove(downtimeId, callback){ - client.request("DELETE", util.format("/downtime/%s", downtimeId), callback); -} + /*section: downtime + *comment: delete a scheduled downtime + *params: + * downtimeId: the id of the downtime + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.downtime.remove(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function remove(downtimeId, callback) { + client.request("DELETE", util.format("/downtime/%s", downtimeId), callback); + } -/*section: downtime - *comment: get a scheduled downtimes details - *params: - * downtimeId: the id of the downtime - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.downtime.get(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function get(downtimeId, callback){ - client.request("GET", util.format("/downtime/%s", downtimeId), callback); -} + /*section: downtime + *comment: get a scheduled downtimes details + *params: + * downtimeId: the id of the downtime + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.downtime.get(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function get(downtimeId, callback) { + client.request("GET", util.format("/downtime/%s", downtimeId), callback); + } -/*section: downtime - *comment: get all downtimes details - *params: - * callback: function(err, res) - *example: | - * ```javascript - * var dogapi = require("dogapi"); - * var options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.downtime.getAll(function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function getAll(callback){ - client.request("GET", "/downtime", callback); -} + /*section: downtime + *comment: get all downtimes details + *params: + * callback: function(err, res) + *example: | + * ```javascript + * var dogapi = require("dogapi"); + * var options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.downtime.getAll(function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function getAll(callback) { + client.request("GET", "/downtime", callback); + } -module.exports = { - create: create, - update: update, - remove: remove, - get: get, - getAll: getAll, - getUsage: function(){ - return [ - " dogapi downtime create [--start ] [--end ] [--message ]", - " dogapi downtime update [--scope ] [--start ] [--end ] [--message ]", - " dogapi downtime remove ", - " dogapi downtime get ", - " dogapi downtime getall", - ]; - }, - getHelp: function(){ - return [ - "Downtime:", - " Subcommands:", - " create create a new downtime with the provided scope (e.g. \"env:staging\")", - " update update an existing downtime with the provided id", - " remove remove the downtime with the provided id", - " get get the details of the downtime with the provided id", - " getall get the details of all downtimes", - "", - " Options:", - " --start POSIX timestamp for when the downtime should start", - " --end POSIX timestamp for when the downtime should end", - " --message a string message to accompany the downtime", - " --scope the scope of the downtime (e.g. \"env:staging\")" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "get"){ - get(args._[4], callback); - } else if(subcommand === "getall"){ - getAll(callback); - } else if(subcommand === "remove"){ - remove(args._[4], callback); - } else if(subcommand === "create"){ - const scope = args._[4]; - const properties = {}; - if(args["start"]){ - properties.start = parseInt(args["start"]); - } - if(args["end"]){ - properties.end = parseInt(args["end"]); + return { + create: create, + update: update, + remove: remove, + get: get, + getAll: getAll, + getUsage: function () { + return [ + " dogapi downtime create [--start ] [--end ] [--message ]", + " dogapi downtime update [--scope ] [--start ] [--end ] [--message ]", + " dogapi downtime remove ", + " dogapi downtime get ", + " dogapi downtime getall", + ]; + }, + getHelp: function () { + return [ + "Downtime:", + " Subcommands:", + " create create a new downtime with the provided scope (e.g. \"env:staging\")", + " update update an existing downtime with the provided id", + " remove remove the downtime with the provided id", + " get get the details of the downtime with the provided id", + " getall get the details of all downtimes", + "", + " Options:", + " --start POSIX timestamp for when the downtime should start", + " --end POSIX timestamp for when the downtime should end", + " --message a string message to accompany the downtime", + " --scope the scope of the downtime (e.g. \"env:staging\")" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "get") { + get(args._[4], callback); + } else if (subcommand === "getall") { + getAll(callback); + } else if (subcommand === "remove") { + remove(args._[4], callback); + } else if (subcommand === "create") { + const scope = args._[4]; + const properties = {}; + if (args["start"]) { + properties.start = parseInt(args["start"]); + } + if (args["end"]) { + properties.end = parseInt(args["end"]); + } + if (args["message"]) { + properties.message = args["message"]; + } + create(scope, properties, callback); + } else if (subcommand === "update") { + const downtimeId = args._[4]; + const properties = {}; + if (args["scope"]) { + properties.scope = args["scope"]; + } + if (args["start"]) { + properties.start = parseInt(args["start"]); + } + if (args["end"]) { + properties.end = parseInt(args["end"]); + } + if (args["message"]) { + properties.message = args["message"]; + } + update(downtimeId, properties, callback); + } else { + callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false); } - if(args["message"]){ - properties.message = args["message"]; - } - create(scope, properties, callback); - } else if(subcommand === "update"){ - const downtimeId = args._[4]; - const properties = {}; - if(args["scope"]){ - properties.scope = args["scope"]; - } - if(args["start"]){ - properties.start = parseInt(args["start"]); - } - if(args["end"]){ - properties.end = parseInt(args["end"]); - } - if(args["message"]){ - properties.message = args["message"]; - } - update(downtimeId, properties, callback); - } else { - callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false); } - } + }; }; diff --git a/lib/api/embed.js b/lib/api/embed.js index 3516e30..3921ed1 100644 --- a/lib/api/embed.js +++ b/lib/api/embed.js @@ -1,170 +1,172 @@ -const client = require("../client"); const extend = require("extend"); -const json = require("../json"); +const json = require("../json"); // TODO inline lib const querystring = require("querystring"); -/*section: embed - *comment: create an embed graph of a metric query - *params: - * graph_json: The request array to pass create in the embed - * options: optional, object of extra parameters to pass to the embed create (see options[*] params) - * options["timeframe"]: optional, one of ("1_hour", "4_hours", "1_day", "2_days", and "1_week") - * options["size"]: optional, one of ("small", "medium", "large", "xlarge") - * options["legend"]: optional, "yes" or "no" - * options["title"]: optional, the title of the embed - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const query = "system.cpu.idle{*}"; - * const graphJSON = { - * viz: "timeseries", - * requests: [ - * { - * q: query, - * aggregator: "avg", - * conditional_formats: [], - * type: "area" - * } - * ] - * } - * const options = { - * timeframe: "1_hour", - * size: "xlarge", - * legend: "yes", - * title: "my awesome embed" - * }; - * dogapi.embed.create(graphJSON, options, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function create(graphJSON, options, callback){ - if(callback === undefined && typeof options === "function"){ - callback = options; - options = {}; - } - const body = { - graph_json: JSON.stringify(graphJSON) - }; - // Use `extend` to merge `options` into `body` - // DEV: `extend` will ignore any properties whose value is `undefined` - extend(body, options || {}); +module.exports = function (client) { - // Create the request - const params = { - body: querystring.stringify(body), - contentType: "application/x-www-form-urlencoded" - }; + /*section: embed + *comment: create an embed graph of a metric query + *params: + * graph_json: The request array to pass create in the embed + * options: optional, object of extra parameters to pass to the embed create (see options[*] params) + * options["timeframe"]: optional, one of ("1_hour", "4_hours", "1_day", "2_days", and "1_week") + * options["size"]: optional, one of ("small", "medium", "large", "xlarge") + * options["legend"]: optional, "yes" or "no" + * options["title"]: optional, the title of the embed + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const query = "system.cpu.idle{*}"; + * const graphJSON = { + * viz: "timeseries", + * requests: [ + * { + * q: query, + * aggregator: "avg", + * conditional_formats: [], + * type: "area" + * } + * ] + * } + * const options = { + * timeframe: "1_hour", + * size: "xlarge", + * legend: "yes", + * title: "my awesome embed" + * }; + * dogapi.embed.create(graphJSON, options, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function create(graphJSON, options, callback) { + if (callback === undefined && typeof options === "function") { + callback = options; + options = {}; + } + const body = { + graph_json: JSON.stringify(graphJSON) + }; + // Use `extend` to merge `options` into `body` + // DEV: `extend` will ignore any properties whose value is `undefined` + extend(body, options || {}); - client.request("POST", "/graph/embed", params, callback); -} + // Create the request + const params = { + body: querystring.stringify(body), + contentType: "application/x-www-form-urlencoded" + }; -/*section: embed - *comment: delete an embed with a specific id - *params: - * embedId: the id of the embed to delete - * callback: function(err, res) - *example: | - * ```javascript - * const embedid = "foo"; - * dogapi.embed.revoke(embedid, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function revoke(embedId, callback){ - client.request("GET", "/graph/embed/" + embedId + "/revoke", callback); -} + client.request("POST", "/graph/embed", params, callback); + } + /*section: embed + *comment: delete an embed with a specific id + *params: + * embedId: the id of the embed to delete + * callback: function(err, res) + *example: | + * ```javascript + * const embedid = "foo"; + * dogapi.embed.revoke(embedid, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function revoke(embedId, callback) { + client.request("GET", "/graph/embed/" + embedId + "/revoke", callback); + } -/*section: embed - *comment: get all embeds from datadog - *params: - * callback: function(err, res) - *example: | - * ```javascript - * dogapi.embed.getAll(function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function getAll(callback) { - client.request("GET", "/graph/embed", callback); -} -/*section: embed - *comment: get a single embed - *params: - * embedId: the id of the embed to get - * callback: function(err, res) - *example: | - * ```javascript - * const embedId = "foo"; - * dogapi.embed.get(embedId, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function get(embedId, callback) { - client.request("GET", "/graph/embed/" + embedId, callback); -} + /*section: embed + *comment: get all embeds from datadog + *params: + * callback: function(err, res) + *example: | + * ```javascript + * dogapi.embed.getAll(function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function getAll(callback) { + client.request("GET", "/graph/embed", callback); + } + + /*section: embed + *comment: get a single embed + *params: + * embedId: the id of the embed to get + * callback: function(err, res) + *example: | + * ```javascript + * const embedId = "foo"; + * dogapi.embed.get(embedId, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function get(embedId, callback) { + client.request("GET", "/graph/embed/" + embedId, callback); + } -module.exports = { - create: create, - revoke: revoke, - getAll: getAll, - get: get, - getUsage: function(){ - return [ - " dogapi embed create [--timeframe ] [--size ] [--legend ] [--title ]", - " dogapi embed revoke <embed_id>", - " dogapi embed get <embed_id>", - " dogapi embed getall" - ]; - }, - getHelp: function(){ - return [ - "Embed:", - " Subcommands:", - " create <embed_json> --timeframe <timeframe> --size <size> --legend <legend> --title <title> | create a new graph embed", - " revoke <embed_id> revoke/delete an embed", - " get <embed_id> gets a single embed object", - " getall gets all embed objects", - " Options:", - " --events <event-query> a query for event bands to add to the snapshot", - " --timeframe <timeframe> The timeframe for the embed (1_hour, 4_hours, 1_day, 2_days, and 1_week)", - " --size <size> The size of the embed to create (small, medium, large, xlarge)", - " --legend <legend> Whether or not to have a legend (yes, no)", - " --title <title> The title of the embed to create" + return { + create: create, + revoke: revoke, + getAll: getAll, + get: get, + getUsage: function () { + return [ + " dogapi embed create <embed_json> [--timeframe <timeframe>] [--size <size>] [--legend <legend>] [--title <title>]", + " dogapi embed revoke <embed_id>", + " dogapi embed get <embed_id>", + " dogapi embed getall" + ]; + }, + getHelp: function () { + return [ + "Embed:", + " Subcommands:", + " create <embed_json> --timeframe <timeframe> --size <size> --legend <legend> --title <title> | create a new graph embed", + " revoke <embed_id> revoke/delete an embed", + " get <embed_id> gets a single embed object", + " getall gets all embed objects", + " Options:", + " --events <event-query> a query for event bands to add to the snapshot", + " --timeframe <timeframe> The timeframe for the embed (1_hour, 4_hours, 1_day, 2_days, and 1_week)", + " --size <size> The size of the embed to create (small, medium, large, xlarge)", + " --legend <legend> Whether or not to have a legend (yes, no)", + " --title <title> The title of the embed to create" - ]; - }, - handleCli: function(subcommand, args, callback) { - if (args._.length > 4 && subcommand === "create") { - const graph_json = json.parse(args._[4]); - const options = { - timeframe: args["timeframe"], - size: args["size"], - legend: args["legend"], - title: args["title"] - }; - create(graph_json, options, callback); - } else if (args._.length > 4 && subcommand === "revoke") { - const embedId = args._[4]; - revoke(embedId, callback); - } else if (args._.length > 4 && subcommand === "get") { - const embedId = args._[4]; - get(embedId, callback); - } else if (subcommand === "getall") { - getAll(callback); - } else { - callback("unknown subcommand or arguments try `dogapi embed --help` for help", false); + ]; + }, + handleCli: function (subcommand, args, callback) { + if (args._.length > 4 && subcommand === "create") { + const graph_json = json.parse(args._[4]); + const options = { + timeframe: args["timeframe"], + size: args["size"], + legend: args["legend"], + title: args["title"] + }; + create(graph_json, options, callback); + } else if (args._.length > 4 && subcommand === "revoke") { + const embedId = args._[4]; + revoke(embedId, callback); + } else if (args._.length > 4 && subcommand === "get") { + const embedId = args._[4]; + get(embedId, callback); + } else if (subcommand === "getall") { + getAll(callback); + } else { + callback("unknown subcommand or arguments try `dogapi embed --help` for help", false); + } } - } + }; }; diff --git a/lib/api/event.js b/lib/api/event.js index f568d5d..3a31912 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -1,209 +1,210 @@ -const client = require("../client"); const util = require("util"); -/*section: event - *comment: | - * create a new event - *params: - * title: the title of the event - * text: the body of the event - * properties: | - * an optional object continaing any of the following additional optional properties - * * date_happened: POSIX timestamp of when it happened - * * priority: "normal" or "low" [defualt: "normal"] - * * host: the host name to associate with the event - * * tags: array of "tag:value"'s to associate with the event - * * alert_type: "error", "warning", "info" or "success" [defualt: "info"] - * * aggregation_key: an arbitrary string used to aggregate like events - * * source_type_name: options: "nagios", "hudson", "jenkins", "user", "my apps", "feed", "chef", "puppet", "git", "bitbucket", "fabric", "capistrano" - * callback: | - * function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const title = "some new event"; - * const text = "IT HAPPENED!"; - * dogapi.event.create(title, text, function(err, res){ - * console.dir(res); - * }); - * title = "another event"; - * text = "IT HAPPENED AGAIN!"; - * const properties = { - * tags: ["some:tag"], - * alert_type: "error" - * }; - * dogapi.event.create(title, text, properties, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function create(title, text, properties, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = properties; - properties = {}; - } - if(typeof properties !== "object"){ - properties = {}; - } - - properties.title = title; - properties.text = text; - - const params = { - body: properties - }; - client.request("POST", "/events", params, callback); -} +module.exports = function (client) { + /*section: event + *comment: | + * create a new event + *params: + * title: the title of the event + * text: the body of the event + * properties: | + * an optional object continaing any of the following additional optional properties + * * date_happened: POSIX timestamp of when it happened + * * priority: "normal" or "low" [defualt: "normal"] + * * host: the host name to associate with the event + * * tags: array of "tag:value"'s to associate with the event + * * alert_type: "error", "warning", "info" or "success" [defualt: "info"] + * * aggregation_key: an arbitrary string used to aggregate like events + * * source_type_name: options: "nagios", "hudson", "jenkins", "user", "my apps", "feed", "chef", "puppet", "git", "bitbucket", "fabric", "capistrano" + * callback: | + * function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const title = "some new event"; + * const text = "IT HAPPENED!"; + * dogapi.event.create(title, text, function(err, res){ + * console.dir(res); + * }); + * title = "another event"; + * text = "IT HAPPENED AGAIN!"; + * const properties = { + * tags: ["some:tag"], + * alert_type: "error" + * }; + * dogapi.event.create(title, text, properties, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function create(title, text, properties, callback) { + if (arguments.length < 4 && typeof arguments[2] === "function") { + callback = properties; + properties = {}; + } + if (typeof properties !== "object") { + properties = {}; + } -/*section: event - *comment: | - * get event details from the provided event id - *params: - * eventId: | - * the id of the event to fetch - * callback: | - * function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.event.get(10005, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function get(eventId, callback){ - client.request("GET", util.format("/events/%s", eventId), callback); -} + properties.title = title; + properties.text = text; -/*section: event - *comment: | - * query the event stream - *params: - * start: POSIX timestamp for start of query - * end: POSIX timestamp for end of query - * parameters: | - * optional parameters to use for the query - * * priority: "low" or "normal" - * * sources: comma separated list of sources (e.g. "jenkins,user") - * * tags: comma separated list of tags (e.g. "tag:value1,tag:value2") - * callback: | - * function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const now = parseInt(new Date().getTime() / 1000); - * const then = now - 3600; // an hour ago - * const parameters = { - * tags: "some:tag", - * sources: "jenkins" - * }; - * dogapi.event.query(then, now, parameters, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function query(start, end, parameters, callback){ - if(arguments.length < 4 && typeof argument[2] === "function"){ - callback = parameters; - parameters = {}; + const params = { + body: properties + }; + client.request("POST", "/events", params, callback); } - if(typeof parameters !== "object"){ - parameters = {} + /*section: event + *comment: | + * get event details from the provided event id + *params: + * eventId: | + * the id of the event to fetch + * callback: | + * function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.event.get(10005, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function get(eventId, callback) { + client.request("GET", util.format("/events/%s", eventId), callback); } - parameters.start = start; - parameters.end = end; - const params = { - query: parameters - }; + /*section: event + *comment: | + * query the event stream + *params: + * start: POSIX timestamp for start of query + * end: POSIX timestamp for end of query + * parameters: | + * optional parameters to use for the query + * * priority: "low" or "normal" + * * sources: comma separated list of sources (e.g. "jenkins,user") + * * tags: comma separated list of tags (e.g. "tag:value1,tag:value2") + * callback: | + * function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const now = parseInt(new Date().getTime() / 1000); + * const then = now - 3600; // an hour ago + * const parameters = { + * tags: "some:tag", + * sources: "jenkins" + * }; + * dogapi.event.query(then, now, parameters, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function query(start, end, parameters, callback) { + if (arguments.length < 4 && typeof argument[2] === "function") { + callback = parameters; + parameters = {}; + } - client.request("GET", "/events", params, callback); -} + if (typeof parameters !== "object") { + parameters = {} + } + parameters.start = start; + parameters.end = end; -module.exports = { - create: create, - get: get, - query: query, - getUsage: function(){ - return [ - " dogapi event get <event-id>", - " dogapi event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]", - " dogapi event create <title> <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]" - ]; - }, - getHelp: function(){ - return [ - "Event:", - " Subcommands:", - " get <event-id> get the event with the provided <event-id>", - " query <from> <to> query the event stream between <from> and <to> POSIX timestamps", - " create <title> <text> create a new event with <title> and <text>", - " Options:", - " --priority <priority> the priority of the event \"normal\" or \"low\"", - " --sources <sources> a comma separated list of sources (e.g. \"users,jenkins,chef\")", - " --tags <tags> a comma separated list of \"tag:value\"'s", - " --time <time> a POSIX timestamp for when the event happened", - " --host <host> the host to associate the event to", - " --type <type> the event type \"error\", \"warning\", \"info\" or \"success\"", - " --agg-key <agg-key> an aggregation key to use to associate like events", - " --source <source> the source to associate with this event (e.g. \"users\", \"jenkins\", etc)" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "get" && args._.length > 4){ - get(parseInt(args._[4]), callback); - } else if(subcommand === "query" && args._.length > 5){ - const from = parseInt(args._[4]); - const to = parseInt(args._[5]); - const parameters = {}; - if(args["sources"]){ - parameters.sources = args["sources"]; - } - if(args["tags"]){ - parameters.tags = args["tags"]; - } - query(from, to, parameters, callback); - } else if(subcommand === "create" && args._.length > 5){ - const title = args._[4]; - const text = args._[5]; - const properties = {}; - if(args["priority"]){ - properties.priority = args["priority"]; - } - if(args["host"]){ - properties.host = args["host"]; - } - if(args["time"]){ - properties.date_happened = parseInt(args["time"]); - } - if(args["tags"]){ - properties.tags = args["tags"].split(","); - } - if(args["agg-key"]){ - properties.aggregation_key = args["agg-key"]; - } - if(args["source"]){ - properties.source_type_name = args["source"]; + const params = { + query: parameters + }; + + client.request("GET", "/events", params, callback); + } + + return { + create: create, + get: get, + query: query, + getUsage: function () { + return [ + " dogapi event get <event-id>", + " dogapi event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]", + " dogapi event create <title> <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]" + ]; + }, + getHelp: function () { + return [ + "Event:", + " Subcommands:", + " get <event-id> get the event with the provided <event-id>", + " query <from> <to> query the event stream between <from> and <to> POSIX timestamps", + " create <title> <text> create a new event with <title> and <text>", + " Options:", + " --priority <priority> the priority of the event \"normal\" or \"low\"", + " --sources <sources> a comma separated list of sources (e.g. \"users,jenkins,chef\")", + " --tags <tags> a comma separated list of \"tag:value\"'s", + " --time <time> a POSIX timestamp for when the event happened", + " --host <host> the host to associate the event to", + " --type <type> the event type \"error\", \"warning\", \"info\" or \"success\"", + " --agg-key <agg-key> an aggregation key to use to associate like events", + " --source <source> the source to associate with this event (e.g. \"users\", \"jenkins\", etc)" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "get" && args._.length > 4) { + get(parseInt(args._[4]), callback); + } else if (subcommand === "query" && args._.length > 5) { + const from = parseInt(args._[4]); + const to = parseInt(args._[5]); + const parameters = {}; + if (args["sources"]) { + parameters.sources = args["sources"]; + } + if (args["tags"]) { + parameters.tags = args["tags"]; + } + query(from, to, parameters, callback); + } else if (subcommand === "create" && args._.length > 5) { + const title = args._[4]; + const text = args._[5]; + const properties = {}; + if (args["priority"]) { + properties.priority = args["priority"]; + } + if (args["host"]) { + properties.host = args["host"]; + } + if (args["time"]) { + properties.date_happened = parseInt(args["time"]); + } + if (args["tags"]) { + properties.tags = args["tags"].split(","); + } + if (args["agg-key"]) { + properties.aggregation_key = args["agg-key"]; + } + if (args["source"]) { + properties.source_type_name = args["source"]; + } + create(title, text, properties, callback); + } else { + callback("unknown subcommand or arguments try `dogapi event --help` for help", false); } - create(title, text, properties, callback); - } else { - callback("unknown subcommand or arguments try `dogapi event --help` for help", false); } - } + }; }; diff --git a/lib/api/graph.js b/lib/api/graph.js index fcbb8a8..fd2906e 100644 --- a/lib/api/graph.js +++ b/lib/api/graph.js @@ -1,75 +1,78 @@ -const client = require("../client"); -const embed = require("./embed"); +const Embed = require("./embed"); -/*section: graph - *comment: take a snapshot of a metric query - *params: - * query: the metric query to use for the snapshot - * from: POSIX timestamp for the beginning of the query - * to: POSIX timestamp for the end of the query - * eventQuery: optional, an event query to overlay event bands on the snapshot - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const query = "system.cpu.idle{*}"; - * const to = dogapi.now(); - * const from = to - 3600; // an hour ago - * dogapi.graph.snapshot(query, from, to, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function snapshot(query, from, to, eventQuery, callback){ - if(arguments.length < 5 && typeof arguments[3] === "function"){ - callback = eventQuery; - eventQuery = undefined; - } - const params = { - query: { - metric_query: query, - start: parseInt(from), - end: parseInt(to) +module.exports = function (client) { + const embed = Embed(client); + + /*section: graph + *comment: take a snapshot of a metric query + *params: + * query: the metric query to use for the snapshot + * from: POSIX timestamp for the beginning of the query + * to: POSIX timestamp for the end of the query + * eventQuery: optional, an event query to overlay event bands on the snapshot + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const query = "system.cpu.idle{*}"; + * const to = dogapi.now(); + * const from = to - 3600; // an hour ago + * dogapi.graph.snapshot(query, from, to, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function snapshot(query, from, to, eventQuery, callback) { + if (arguments.length < 5 && typeof arguments[3] === "function") { + callback = eventQuery; + eventQuery = undefined; + } + const params = { + query: { + metric_query: query, + start: parseInt(from), + end: parseInt(to) + } + }; + if (eventQuery) { + params.query.event_query = eventQuery; } - }; - if(eventQuery){ - params.query.event_query = eventQuery; - } - client.request("GET", "/graph/snapshot", params, callback); -} + client.request("GET", "/graph/snapshot", params, callback); + } -module.exports = { - snapshot: snapshot, - createEmbed: embed.create, - getUsage: function(){ - return [ - " dogapi graph snapshot <query> <from> <to> [--events <event-query>]" - ]; - }, - getHelp: function(){ - return [ - "Graph:", - " Subcommands:", - " snapshot <query> <from> <to> --events <event-query> | take a snapshot of a graph", - " Options:", - " --events <event-query> a query for event bands to add to the snapshot" - ]; - }, - handleCli: function(subcommand, args, callback){ - if (args._.length > 5 && subcommand === "snapshot"){ - const query = args._[4]; - const from = parseInt(args._[5]); - const to = parseInt(args._[6]); - const eventQuery = args["events"]; - snapshot(query, from, to, eventQuery, callback); - } else { - callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); + return { + snapshot: snapshot, + createEmbed: embed.create, + getUsage: function () { + return [ + " dogapi graph snapshot <query> <from> <to> [--events <event-query>]" + ]; + }, + getHelp: function () { + return [ + "Graph:", + " Subcommands:", + " snapshot <query> <from> <to> --events <event-query> | take a snapshot of a graph", + " Options:", + " --events <event-query> a query for event bands to add to the snapshot" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (args._.length > 5 && subcommand === "snapshot") { + const query = args._[4]; + const from = parseInt(args._[5]); + const to = parseInt(args._[6]); + const eventQuery = args["events"]; + snapshot(query, from, to, eventQuery, callback); + } else { + callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); + } } - } + }; }; diff --git a/lib/api/host.js b/lib/api/host.js index dbe86d8..d6a597d 100644 --- a/lib/api/host.js +++ b/lib/api/host.js @@ -1,108 +1,109 @@ -const client = require("../client"); const util = require("util"); -/*section: host - *comment: mute the given host, if it is not already muted - *params: - * hostname: the hostname of the host to mute - * options: | - * optional, an object containing any of the following - * * end: POSIX timestamp for when the mute should end - * * override: whether or not to override the end for an existing mute - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.host.mute("my.host.name", function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function mute(hostname, options, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = options; - options = {}; - } - const params = {}; - if(typeof options === "object"){ - params.body = {}; // create body property - if(options.end){ - params.body.end = parseInt(options.end); +module.exports = function (client) { + /*section: host + *comment: mute the given host, if it is not already muted + *params: + * hostname: the hostname of the host to mute + * options: | + * optional, an object containing any of the following + * * end: POSIX timestamp for when the mute should end + * * override: whether or not to override the end for an existing mute + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.host.mute("my.host.name", function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function mute(hostname, options, callback) { + if (arguments.length < 3 && typeof arguments[1] === "function") { + callback = options; + options = {}; } - if(options.override){ - params.body.override = options.override; + const params = {}; + if (typeof options === "object") { + params.body = {}; // create body property + if (options.end) { + params.body.end = parseInt(options.end); + } + if (options.override) { + params.body.override = options.override; + } + } else { + params.body = ""; // create empty body } - } else { - params.body = ""; // create empty body + client.request("POST", util.format("/host/%s/mute", hostname), params, callback); } - client.request("POST", util.format("/host/%s/mute", hostname), params, callback); -} -/*section: host - *comment: unmute the given host, if it is not already unmuted - *params: - * hostname: the hostname of the host to unmute - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.host.unmute("my.host.name", function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function unmute(hostname, callback){ - const params = {body: ""}; // create empty body - client.request("POST", util.format("/host/%s/unmute", hostname), params, callback); -} + /*section: host + *comment: unmute the given host, if it is not already unmuted + *params: + * hostname: the hostname of the host to unmute + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.host.unmute("my.host.name", function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function unmute(hostname, callback) { + const params = { body: "" }; // create empty body + client.request("POST", util.format("/host/%s/unmute", hostname), params, callback); + } -module.exports = { - mute: mute, - unmute: unmute, - getUsage: function(){ - return [ - " dogapi host mute <host> [--end <end>] [--override]", - " dogapi host unmute <host>" - ]; - }, - getHelp: function(){ - return [ - "Host:", - " Subcommands:", - " mute <host> mute the host with the provided hostname", - " unmute <host> unmute the host with the provided hostname", - "", - " Options:", - " --end <end> POSIX timestamp for when the mute should end", - " --override override an existing \"end\" for a mute on a host" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "mute"){ - const hostname = args._[4]; - const options = {}; - if(args["end"]){ - options.end = parseInt(args["end"]); - } - if(args["override"]){ - options.override = args["override"]; + return { + mute: mute, + unmute: unmute, + getUsage: function () { + return [ + " dogapi host mute <host> [--end <end>] [--override]", + " dogapi host unmute <host>" + ]; + }, + getHelp: function () { + return [ + "Host:", + " Subcommands:", + " mute <host> mute the host with the provided hostname", + " unmute <host> unmute the host with the provided hostname", + "", + " Options:", + " --end <end> POSIX timestamp for when the mute should end", + " --override override an existing \"end\" for a mute on a host" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "mute") { + const hostname = args._[4]; + const options = {}; + if (args["end"]) { + options.end = parseInt(args["end"]); + } + if (args["override"]) { + options.override = args["override"]; + } + mute(hostname, options, callback); + } else if (subcommand === "unmute") { + const hostname = args._[4]; + unmute(hostname, callback); + } else { + callback("unknown subcommand or arguments try `dogapi host --help` for help", false); } - mute(hostname, options, callback); - } else if(subcommand === "unmute"){ - const hostname = args._[4]; - unmute(hostname, callback); - } else { - callback("unknown subcommand or arguments try `dogapi host --help` for help", false); } - } + }; }; diff --git a/lib/api/index.js b/lib/api/index.js index b3914a6..41a315b 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -21,3 +21,5 @@ module.exports = function(obj){ obj[key] = api[key]; } }; + +module.exports.api = api; diff --git a/lib/api/infrastructure.js b/lib/api/infrastructure.js index 3d0de06..25caa6b 100644 --- a/lib/api/infrastructure.js +++ b/lib/api/infrastructure.js @@ -1,52 +1,52 @@ -const client = require("../client"); +module.exports = function (client) { -/*section: infrastructure - *comment: | - * search for metrics or hosts - *params: - * query: | - * the query to use for search see [datadog docs](http://docs.datadoghq.com/api/#search) - * for examples of the query (e.g. "hosts:database", "metrics:system" or "test") - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.infrastructure.search("hosts:database", function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function search(query, callback){ - const params = { - query: { - q: query - } - }; - - client.request("GET", "/search", params, callback); -} + /*section: infrastructure + *comment: | + * search for metrics or hosts + *params: + * query: | + * the query to use for search see [datadog docs](http://docs.datadoghq.com/api/#search) + * for examples of the query (e.g. "hosts:database", "metrics:system" or "test") + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.infrastructure.search("hosts:database", function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function search(query, callback) { + const params = { + query: { + q: query + } + }; -module.exports = { - search: search, - getUsage: function(){ - return [ - " dogapi infrastructure search <query>" - ] - }, - getHelp: function(){ - return [ - "Infrastructure:", - " Subcommands:", - " search <query> query for hosts or metrics with <query> (see http://docs.datadoghq.com/api/#search)", - ]; - }, - handleCli: function(subcommand, args, callback){ - const query = args._[4]; - search(query, callback); + client.request("GET", "/search", params, callback); } + return { + search: search, + getUsage: function () { + return [ + " dogapi infrastructure search <query>" + ] + }, + getHelp: function () { + return [ + "Infrastructure:", + " Subcommands:", + " search <query> query for hosts or metrics with <query> (see http://docs.datadoghq.com/api/#search)", + ]; + }, + handleCli: function (subcommand, args, callback) { + const query = args._[4]; + search(query, callback); + } + }; }; diff --git a/lib/api/metric.js b/lib/api/metric.js index 3750aa3..c8150f5 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -1,220 +1,221 @@ -const client = require("../client"); +module.exports = function (client) { -/*section: metric - *comment: | - * submit a new metric - *params: - * metric: the metric name - * points: | - * a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) - * or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) - * extra: | - * optional, object which can contain the following keys - * * host: the host source of the metric - * * tags: array of "tag:value"'s to use for the metric - * * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] - * callback: | - * function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.metric.send("my.metric", 1000, function(err, results){ - * console.dir(results); - * }); - * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ - * console.dir(results); - * }); - * const now = parseInt(new Date().getTime() / 1000); - * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ - * console.dir(results); - * }); - * dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function send(metric, points, extra, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = extra; - extra = {}; - } - extra = extra || {}; - const series = [ - { - metric: metric, - points: points, - host: extra.host, - tags: extra.tags, - // DEV: For backwards compatibility, allow `metric_type` - type: extra.type || extra.metric_type + /*section: metric + *comment: | + * submit a new metric + *params: + * metric: the metric name + * points: | + * a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) + * or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) + * extra: | + * optional, object which can contain the following keys + * * host: the host source of the metric + * * tags: array of "tag:value"'s to use for the metric + * * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] + * callback: | + * function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.metric.send("my.metric", 1000, function(err, results){ + * console.dir(results); + * }); + * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ + * console.dir(results); + * }); + * const now = parseInt(new Date().getTime() / 1000); + * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ + * console.dir(results); + * }); + * dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function send(metric, points, extra, callback) { + if (arguments.length < 4 && typeof arguments[2] === "function") { + callback = extra; + extra = {}; } - ]; + extra = extra || {}; + const series = [ + { + metric: metric, + points: points, + host: extra.host, + tags: extra.tags, + // DEV: For backwards compatibility, allow `metric_type` + type: extra.type || extra.metric_type + } + ]; - send_all(series, callback); -} + send_all(series, callback); + } -/*section: metric - *comment: | - * send a list of metrics - *params: - * metrics: | - * an array of metrics where each element is an object with the following keys - * * metric: the name of the metric - * * points: a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) - * * tags: an array of "tag:value"'s - * * host: the source hostname to use for the metrics - * * metric_type|type: the type of metric to use ("gauge" or "count") [default: gauge] - * callback: | - * function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const now = parseInt(new Date().getTime() / 1000); - * const metrics = [ - * { - * metric: "my.metric", - * points: [[now, 1000]], - * tags: ["tag:value"] - * }, - * { - * metric: "another.metric", - * points: [50, 1000] - * }, - * { - * metric: "another.metric", - * points: 1000 - * } - * ]; - * dogapi.metric.send_all(metrics, function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function send_all(metrics, callback){ - const now = parseInt(new Date().getTime() / 1000); - for(let i = 0; i < metrics.length; ++i){ - // Try to normalize `points` - // DEV: We need `points` to be an array of arrays regardless of what they give us - // Always wrap points in an array, this way we will get: - // 500 => [500] - // [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]] - // [[<timestamp>, 500]] => [[<timestamp>, 500]] - let points = metrics[i].points; - if(!Array.isArray(metrics[i].points)){ - points = [points]; - } - points = points.map(function(point){ - // Make sure each point is an array, if not make array with current timestamp - // 500 => [<timestamp>, 500] - // [<timestamp>, 500] => unchanged - if(!Array.isArray(point)){ - const now = parseInt(new Date().getTime() / 1000); - point = [now, point]; + /*section: metric + *comment: | + * send a list of metrics + *params: + * metrics: | + * an array of metrics where each element is an object with the following keys + * * metric: the name of the metric + * * points: a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) + * * tags: an array of "tag:value"'s + * * host: the source hostname to use for the metrics + * * metric_type|type: the type of metric to use ("gauge" or "count") [default: gauge] + * callback: | + * function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const now = parseInt(new Date().getTime() / 1000); + * const metrics = [ + * { + * metric: "my.metric", + * points: [[now, 1000]], + * tags: ["tag:value"] + * }, + * { + * metric: "another.metric", + * points: [50, 1000] + * }, + * { + * metric: "another.metric", + * points: 1000 + * } + * ]; + * dogapi.metric.send_all(metrics, function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function send_all(metrics, callback) { + const now = parseInt(new Date().getTime() / 1000); + for (let i = 0; i < metrics.length; ++i) { + // Try to normalize `points` + // DEV: We need `points` to be an array of arrays regardless of what they give us + // Always wrap points in an array, this way we will get: + // 500 => [500] + // [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]] + // [[<timestamp>, 500]] => [[<timestamp>, 500]] + let points = metrics[i].points; + if (!Array.isArray(metrics[i].points)) { + points = [points]; } - return point; - }); + points = points.map(function (point) { + // Make sure each point is an array, if not make array with current timestamp + // 500 => [<timestamp>, 500] + // [<timestamp>, 500] => unchanged + if (!Array.isArray(point)) { + const now = parseInt(new Date().getTime() / 1000); + point = [now, point]; + } + return point; + }); - metrics[i].points = points; + metrics[i].points = points; - // DEV: Change `metric_type` to `type` for backwards compatibility - metrics[i].type = metrics[i].type || metrics[i].metric_type; - // Remove `metric_type` if it was set - // DEV: This will not cause an error if `metric_type` does not exist - delete metrics[i].metric_type; - } - - const params = { - body: { - series: metrics + // DEV: Change `metric_type` to `type` for backwards compatibility + metrics[i].type = metrics[i].type || metrics[i].metric_type; + // Remove `metric_type` if it was set + // DEV: This will not cause an error if `metric_type` does not exist + delete metrics[i].metric_type; } - }; - client.request("POST", "/series", params, callback); -} -/*section: metric - *comment: | - * make a metric query - *params: - * from: POSIX timestamp for start of query - * to: POSIX timestamp for end of query - * query: the string query to perform (e.g. "system.cpu.idle{*}by{host}") - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const now = parseInt(new Date().getTime() / 1000); - * const then = now - 3600; // one hour ago - * const query = "system.cpu.idle{*}by{host}"; - * dogapi.metric.query(then, now, query, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function query(from, to, query, callback){ - const params = { - query: { - from: from, - to: to, - query: query - } - }; - client.request("GET", "/query", params, callback); -} + const params = { + body: { + series: metrics + } + }; + client.request("POST", "/series", params, callback); + } -module.exports = { - send: send, - send_all: send_all, - query: query, - getUsage: function(){ - return [ - " dogapi metric send <metric> <point> [--tags <tags>] [--host <host>] [--type <type>]", - " dogapi metric query <from> <to> <query>" - ] - }, - getHelp: function(){ - return [ - "Metric:", - " Subcommands:", - " send <metric> <point> add a new datapoint for <metric> for right now", - " query <from> <to> <query> query for <query> between <from> and <to> POSIX timestamps", - "", - " Options:", - " --tags <tags> a comma separated list of \"tag:value\"'s", - " --host <host> the hostname that should be associated with this metric", - " --type <type> the type of metric \"gauge\" or \"count\"" - ] - }, - handleCli: function(subcommand, args, callback){ - if(args._.length > 5 && subcommand === "send"){ - const extra = {}; - if(args.tags){ - extra.tags = args.tags.split(","); + /*section: metric + *comment: | + * make a metric query + *params: + * from: POSIX timestamp for start of query + * to: POSIX timestamp for end of query + * query: the string query to perform (e.g. "system.cpu.idle{*}by{host}") + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const now = parseInt(new Date().getTime() / 1000); + * const then = now - 3600; // one hour ago + * const query = "system.cpu.idle{*}by{host}"; + * dogapi.metric.query(then, now, query, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function query(from, to, query, callback) { + const params = { + query: { + from: from, + to: to, + query: query } - extra.host = args.host; - extra.type = args.type; - send(args._[4], args._[5], extra, callback); - } else if(subcommand === "query" && args._.length > 6){ - const from = parseInt(args._[4]); - const to = parseInt(args._[5]); - const q = args._[6]; - query(from, to, q, callback); - } else { - callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); - } + }; + client.request("GET", "/query", params, callback); } + + return { + send: send, + send_all: send_all, + query: query, + getUsage: function () { + return [ + " dogapi metric send <metric> <point> [--tags <tags>] [--host <host>] [--type <type>]", + " dogapi metric query <from> <to> <query>" + ] + }, + getHelp: function () { + return [ + "Metric:", + " Subcommands:", + " send <metric> <point> add a new datapoint for <metric> for right now", + " query <from> <to> <query> query for <query> between <from> and <to> POSIX timestamps", + "", + " Options:", + " --tags <tags> a comma separated list of \"tag:value\"'s", + " --host <host> the hostname that should be associated with this metric", + " --type <type> the type of metric \"gauge\" or \"count\"" + ] + }, + handleCli: function (subcommand, args, callback) { + if (args._.length > 5 && subcommand === "send") { + const extra = {}; + if (args.tags) { + extra.tags = args.tags.split(","); + } + extra.host = args.host; + extra.type = args.type; + send(args._[4], args._[5], extra, callback); + } else if (subcommand === "query" && args._.length > 6) { + const from = parseInt(args._[4]); + const to = parseInt(args._[5]); + const q = args._[6]; + query(from, to, q, callback); + } else { + callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); + } + } + }; }; diff --git a/lib/api/monitor.js b/lib/api/monitor.js index 381f14a..9f36def 100644 --- a/lib/api/monitor.js +++ b/lib/api/monitor.js @@ -1,454 +1,456 @@ -const client = require("../client"); const util = require("util"); -/*section: monitor - *comment: create a new monitor - *params: - * type: one of "metric alert" or "service check" - * query: the monitor query to use, you probably want to read datadog's [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs - * properties: | - * optional, an object containing any of the following - * * name: the name of the monitor - * * message: the message for the monitor - * * tags: a list of strings as tags to associate with the monitor - * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const metricType = "metric alert"; - * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; - * dogapi.monitor.create(metricType, query, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function create(type, query, properties, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = properties; - properties = {}; - } - - const params = { - body: { - type: type, - query: query - } - }; +module.exports = function(client){ - if(typeof properties === "object"){ - if(properties.name){ - params.body.name = properties.name; + /*section: monitor + *comment: create a new monitor + *params: + * type: one of "metric alert" or "service check" + * query: the monitor query to use, you probably want to read datadog's [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs + * properties: | + * optional, an object containing any of the following + * * name: the name of the monitor + * * message: the message for the monitor + * * tags: a list of strings as tags to associate with the monitor + * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const metricType = "metric alert"; + * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; + * dogapi.monitor.create(metricType, query, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function create(type, query, properties, callback){ + if(arguments.length < 4 && typeof arguments[2] === "function"){ + callback = properties; + properties = {}; } - if(properties.message){ - params.body.message = properties.message; - } - if(properties.tags){ - params.body.tags = properties.tags; - } - if(typeof properties.options === "object"){ - params.body.options = properties.options; - } - } - client.request("POST", "/monitor", params, callback); -} - -/*section: monitor - *comment: get an existing monitor's details - *params: - * monitorId: the id of the monitor - * groupStates: an array containing any of the following "all", "alert", "warn", or "no data" - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.get(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function get(monitorId, groupStates, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = groupStates; - groupStates = undefined; - } - - const params = {}; - if(groupStates){ - params.query = { - group_states: groupStates.join(",") + + const params = { + body: { + type: type, + query: query + } }; - } - - client.request("GET", util.format("/monitor/%s", monitorId), params, callback); -} - -/*section: monitor - *comment: get all monitors - *params: - * options: | - * optional, an object containing any of the following - * * group_states: an array containing any of the following "all", "alert", "warn", or "no data" - * * tags: an array of "tag:value"'s to filter on - * * monitor_tags: a comma separated list indicating what service and/or custom tags - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.getAll(function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function getAll(options, callback){ - if(arguments.length < 2 && typeof arguments[0] === "function"){ - callback = options; - options = {}; - } - const params = {}; - if(typeof options === "object"){ - params.query = {}; - if(options.group_states){ - params.query.group_states = options.group_states.join(","); + + if(typeof properties === "object"){ + if(properties.name){ + params.body.name = properties.name; + } + if(properties.message){ + params.body.message = properties.message; + } + if(properties.tags){ + params.body.tags = properties.tags; + } + if(typeof properties.options === "object"){ + params.body.options = properties.options; + } } - if(options.tags){ - params.query.tags = options.tags.join(","); + client.request("POST", "/monitor", params, callback); + } + + /*section: monitor + *comment: get an existing monitor's details + *params: + * monitorId: the id of the monitor + * groupStates: an array containing any of the following "all", "alert", "warn", or "no data" + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.get(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function get(monitorId, groupStates, callback){ + if(arguments.length < 3 && typeof arguments[1] === "function"){ + callback = groupStates; + groupStates = undefined; } - if(options.monitor_tags){ - params.query.monitor_tags = options.monitor_tags.join(","); + + const params = {}; + if(groupStates){ + params.query = { + group_states: groupStates.join(",") + }; } + + client.request("GET", util.format("/monitor/%s", monitorId), params, callback); } - client.request("GET", "/monitor", params, callback); -} - -/*section: monitor - *comment: update a monitor's details - *params: - * monitorId: the id of the monitor to edit - * query: the query that the monitor should have, see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs for more info - * properties: | - * optional, an object containing any of the following - * * name: the name of the monitor - * * message: the message for the monitor - * * tags: a list of strings as tags to associate with the monitor - * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; - * dogapi.monitor.update(1234, query, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function update(monitorId, query, properties, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = properties; - properties = {}; - } - - const params = { - body: { - query: query + + /*section: monitor + *comment: get all monitors + *params: + * options: | + * optional, an object containing any of the following + * * group_states: an array containing any of the following "all", "alert", "warn", or "no data" + * * tags: an array of "tag:value"'s to filter on + * * monitor_tags: a comma separated list indicating what service and/or custom tags + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.getAll(function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function getAll(options, callback){ + if(arguments.length < 2 && typeof arguments[0] === "function"){ + callback = options; + options = {}; } - }; - - if(typeof properties === "object"){ - if(properties.name){ - params.body.name = properties.name; - } - if(properties.message){ - params.body.message = properties.message; + const params = {}; + if(typeof options === "object"){ + params.query = {}; + if(options.group_states){ + params.query.group_states = options.group_states.join(","); + } + if(options.tags){ + params.query.tags = options.tags.join(","); + } + if(options.monitor_tags){ + params.query.monitor_tags = options.monitor_tags.join(","); + } } - if(properties.tags){ - params.body.tags = properties.tags; + client.request("GET", "/monitor", params, callback); + } + + /*section: monitor + *comment: update a monitor's details + *params: + * monitorId: the id of the monitor to edit + * query: the query that the monitor should have, see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs for more info + * properties: | + * optional, an object containing any of the following + * * name: the name of the monitor + * * message: the message for the monitor + * * tags: a list of strings as tags to associate with the monitor + * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; + * dogapi.monitor.update(1234, query, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function update(monitorId, query, properties, callback){ + if(arguments.length < 4 && typeof arguments[2] === "function"){ + callback = properties; + properties = {}; } - if(typeof properties.options === "object"){ - params.body.options = properties.options; + + const params = { + body: { + query: query + } + }; + + if(typeof properties === "object"){ + if(properties.name){ + params.body.name = properties.name; + } + if(properties.message){ + params.body.message = properties.message; + } + if(properties.tags){ + params.body.tags = properties.tags; + } + if(typeof properties.options === "object"){ + params.body.options = properties.options; + } } + client.request("PUT", util.format("/monitor/%s", monitorId), params, callback); } - client.request("PUT", util.format("/monitor/%s", monitorId), params, callback); -} - -/*section: monitor - *comment: delete an existing monitor - *params: - * monitorId: the id of the monitor to remove - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.remove(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function remove(monitorId, callback){ - client.request("DELETE", util.format("/monitor/%s", monitorId), callback); -} - -/*section: monitor - *comment: mute an existing monitor - *params: - * monitorId: the id of the monitor to mute - * options: | - * optional, an object containing any of the following - * * scope: the scope to mute (e.g. "role:db") - * * end: POSIX timestamp indicating when the mute should end - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.mute(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function mute(monitorId, options, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = options; - options = {}; + + /*section: monitor + *comment: delete an existing monitor + *params: + * monitorId: the id of the monitor to remove + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.remove(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function remove(monitorId, callback){ + client.request("DELETE", util.format("/monitor/%s", monitorId), callback); } - const params = {}; - if(typeof options === "object"){ - params.body = {}; - if(options.scope){ - params.body.scope = options.scope; + + /*section: monitor + *comment: mute an existing monitor + *params: + * monitorId: the id of the monitor to mute + * options: | + * optional, an object containing any of the following + * * scope: the scope to mute (e.g. "role:db") + * * end: POSIX timestamp indicating when the mute should end + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.mute(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function mute(monitorId, options, callback){ + if(arguments.length < 3 && typeof arguments[1] === "function"){ + callback = options; + options = {}; } - if(options.end){ - params.body.end = parseInt(options.end); + const params = {}; + if(typeof options === "object"){ + params.body = {}; + if(options.scope){ + params.body.scope = options.scope; + } + if(options.end){ + params.body.end = parseInt(options.end); + } + } else { + params.body = ""; // create empty body } - } else { - params.body = ""; // create empty body - } - client.request("POST", util.format("/monitor/%s/mute", monitorId), params, callback); -} - -/*section: monitor - *comment: mute all monitors - *params: - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.muteAll(function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function muteAll(callback){ - client.request("POST", "/monitor/mute_all", callback); -} - -/*section: monitor - *comment: unmute an existing monitor - *params: - * monitorId: the id of the monitor to unmute - * scope: optional, a scope to apply the unmute to (e.g. "role:db") - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.unmute(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function unmute(monitorId, scope, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = scope; - scope = undefined; + client.request("POST", util.format("/monitor/%s/mute", monitorId), params, callback); } - const params = {}; - if(scope){ - params.body = { - scope: scope - }; - } else { - params.body = ""; // create empty body + + /*section: monitor + *comment: mute all monitors + *params: + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.muteAll(function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function muteAll(callback){ + client.request("POST", "/monitor/mute_all", callback); } - client.request("POST", util.format("/monitor/%s/unmute", monitorId), params, callback); -} - -/*section: monitor - *comment: unmute all monitors - *params: - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.monitor.unmuteAll(function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function unmuteAll(callback){ - client.request("POST", "/monitor/unmute_all", callback); -} - -module.exports = { - create: create, - get: get, - update: update, - remove: remove, - getAll: getAll, - mute: mute, - muteAll: muteAll, - unmute: unmute, - unmuteAll: unmuteAll, - getUsage: function(){ - return [ - " dogapi monitor create <type> <query> [--name <name>] [--message <message>]", - " dogapi monitor get <monitor-id> [--states <states>]", - " dogapi monitor getall [--states <states>] [--tags <tags>]", - " dogapi monitor mute <monitor-id> [--scope <scope>] [--end <end>]", - " dogapi monitor muteall", - " dogapi monitor remove <monitor-id>", - " dogapi monitor unmute <monitor-id> [--scope <scope>]", - " dogapi monitor unmuteall", - " dogapi monitor update <monitor-id> <query> [--name <name>] [--message <message>]" - ]; - }, - getHelp: function(){ - return [ - "Monitor:", - " Subcommands:", - " create <type> <query> create a new monitor", - " get <monitor-id> get a monitors details", - " getall get a list of all monitors", - " mute <monitor-id> mute the monitor with the id <monitor-id>", - " muteall mute all monitors", - " remove <monitor-id> delete the monitor with the id <monitor-id>", - " unmute <monitor-id> unmute the monitor with the id <monitor-id>", - " unmuteall unmute all monitors", - " update <monitor-id> <query> update an existing monitor", - "", - " Options:", - " --states <states> a comma separated list containing any of \"all\", \"alert\", \"warn\", or \"no data\"", - " --tags <tags> a comma separated list of \"tag:value\"'s", - " --scope <scope> the scope of the monitor to mute (e.g. \"role:db\")", - " --end <end> POSIX timestamp for when the mute should end", - " --name <name> the name for the monitor", - " --message <message> the message for the monitor" - ]; - }, - handleCli: function(subcommand, args, callback){ - const states = []; - if(args["states"]){ - states = args["states"].split(","); + + /*section: monitor + *comment: unmute an existing monitor + *params: + * monitorId: the id of the monitor to unmute + * scope: optional, a scope to apply the unmute to (e.g. "role:db") + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.unmute(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function unmute(monitorId, scope, callback){ + if(arguments.length < 3 && typeof arguments[1] === "function"){ + callback = scope; + scope = undefined; } - - const tags = []; - if(args["tags"]){ - tags = args["tags"].split(","); + const params = {}; + if(scope){ + params.body = { + scope: scope + }; + } else { + params.body = ""; // create empty body } - - const name = args["name"]; - const message = args["message"]; - - if(subcommand === "get"){ - const monitorId = args._[4]; - get(monitorId, states, callback); - } else if(subcommand === "getall"){ - const options = {}; - if(states.length){ - options.group_states = states; - } - if(tags.length){ - options.tags = tags; - } - getAll(options, callback); - } else if(subcommand === "mute"){ - const monitorId = args._[4]; - const options = {}; - if(args["scope"]){ - options.scope = args["scope"]; - } - if(args["end"]){ - options.end = args["end"]; - } - mute(monitorId, options, callback); - } else if(subcommand === "unmute"){ - const monitorId = args._[4]; - const scope = args["scope"]; - unmute(monitorId, scope, callback); - } else if(subcommand === "unmuteall"){ - unmuteAll(callback); - } else if(subcommand === "muteall"){ - muteAll(callback); - } else if(subcommand === "remove"){ - const monitorId = args._[4]; - remove(monitorId, callback); - } else if(subcommand === "create" && args._.length > 5){ - const type = args._[4]; - const query = args._[5]; - const properties = {}; - if(name){ - properties.name = name; - } - if(message){ - properties.message = message; + client.request("POST", util.format("/monitor/%s/unmute", monitorId), params, callback); + } + + /*section: monitor + *comment: unmute all monitors + *params: + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.monitor.unmuteAll(function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function unmuteAll(callback){ + client.request("POST", "/monitor/unmute_all", callback); + } + + return { + create: create, + get: get, + update: update, + remove: remove, + getAll: getAll, + mute: mute, + muteAll: muteAll, + unmute: unmute, + unmuteAll: unmuteAll, + getUsage: function(){ + return [ + " dogapi monitor create <type> <query> [--name <name>] [--message <message>]", + " dogapi monitor get <monitor-id> [--states <states>]", + " dogapi monitor getall [--states <states>] [--tags <tags>]", + " dogapi monitor mute <monitor-id> [--scope <scope>] [--end <end>]", + " dogapi monitor muteall", + " dogapi monitor remove <monitor-id>", + " dogapi monitor unmute <monitor-id> [--scope <scope>]", + " dogapi monitor unmuteall", + " dogapi monitor update <monitor-id> <query> [--name <name>] [--message <message>]" + ]; + }, + getHelp: function(){ + return [ + "Monitor:", + " Subcommands:", + " create <type> <query> create a new monitor", + " get <monitor-id> get a monitors details", + " getall get a list of all monitors", + " mute <monitor-id> mute the monitor with the id <monitor-id>", + " muteall mute all monitors", + " remove <monitor-id> delete the monitor with the id <monitor-id>", + " unmute <monitor-id> unmute the monitor with the id <monitor-id>", + " unmuteall unmute all monitors", + " update <monitor-id> <query> update an existing monitor", + "", + " Options:", + " --states <states> a comma separated list containing any of \"all\", \"alert\", \"warn\", or \"no data\"", + " --tags <tags> a comma separated list of \"tag:value\"'s", + " --scope <scope> the scope of the monitor to mute (e.g. \"role:db\")", + " --end <end> POSIX timestamp for when the mute should end", + " --name <name> the name for the monitor", + " --message <message> the message for the monitor" + ]; + }, + handleCli: function(subcommand, args, callback){ + const states = []; + if(args["states"]){ + states = args["states"].split(","); } - create(type, query, properties, callback); - } else if(subcommand === "update" && args._.length > 5){ - const monitorId = args._[4]; - const query = args._[5]; - const properties = {}; - if(name){ - properties.name = name; + + const tags = []; + if(args["tags"]){ + tags = args["tags"].split(","); } - if(message){ - properties.message = message; + + const name = args["name"]; + const message = args["message"]; + + if(subcommand === "get"){ + const monitorId = args._[4]; + get(monitorId, states, callback); + } else if(subcommand === "getall"){ + const options = {}; + if(states.length){ + options.group_states = states; + } + if(tags.length){ + options.tags = tags; + } + getAll(options, callback); + } else if(subcommand === "mute"){ + const monitorId = args._[4]; + const options = {}; + if(args["scope"]){ + options.scope = args["scope"]; + } + if(args["end"]){ + options.end = args["end"]; + } + mute(monitorId, options, callback); + } else if(subcommand === "unmute"){ + const monitorId = args._[4]; + const scope = args["scope"]; + unmute(monitorId, scope, callback); + } else if(subcommand === "unmuteall"){ + unmuteAll(callback); + } else if(subcommand === "muteall"){ + muteAll(callback); + } else if(subcommand === "remove"){ + const monitorId = args._[4]; + remove(monitorId, callback); + } else if(subcommand === "create" && args._.length > 5){ + const type = args._[4]; + const query = args._[5]; + const properties = {}; + if(name){ + properties.name = name; + } + if(message){ + properties.message = message; + } + create(type, query, properties, callback); + } else if(subcommand === "update" && args._.length > 5){ + const monitorId = args._[4]; + const query = args._[5]; + const properties = {}; + if(name){ + properties.name = name; + } + if(message){ + properties.message = message; + } + update(monitorId, query, properties, callback); + } else { + callback("unknown subcommand or arguments try `dogapi monitor --help` for help", false); } - update(monitorId, query, properties, callback); - } else { - callback("unknown subcommand or arguments try `dogapi monitor --help` for help", false); } - } + }; }; diff --git a/lib/api/screenboard.js b/lib/api/screenboard.js index 81d9686..b4253b7 100644 --- a/lib/api/screenboard.js +++ b/lib/api/screenboard.js @@ -1,351 +1,351 @@ -const client = require("../client"); const json = require("../json"); const util = require("util"); +module.exports = function (client) { + /*section: screenboard + *comment: create a new screenboard + *params: + * boardTitle: the name of the screenboard + * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info + * options: | + * optional, a object which can contain any of the following keys + * * description: description of the screenboard + * * templateVariables: | + * an array of objects with the following keys + * * name: the name of the variable + * * prefix: optional, the tag prefix for this variable + * * default: optional, the default value for this tag + * * width: the width of the screenboard in pixels + * * height: the height of the screenboard in pixels + * * readOnly: the read-only status of the screenboard + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const boardTitle = "my screenboard"; + * const widgets = [ + * { + * type: "image", + * height: 20, + * width: 32, + * y: 7, + * x: 32, + * url: "https://path/to/image.jpg" + * } + * ]; + * const options = { + * templateVariables: [ + * { + * name: "host1", + * prefix: "host", + * "default": "host:my-host" + * } + * ], + * description: "it is super awesome" + * }; + * dogapi.screenboard.create( + * boardTitle, widgets, options, + * function(err, res){ + * console.dir(res); + * } + * ); + * ``` + */ + function create(boardTitle, widgets, options, callback) { + if (arguments.length < 4 && typeof arguments[2] === "function") { + callback = options; + options = {}; + } + if (typeof options !== "object") { + options = {}; + } -/*section: screenboard - *comment: create a new screenboard - *params: - * boardTitle: the name of the screenboard - * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info - * options: | - * optional, a object which can contain any of the following keys - * * description: description of the screenboard - * * templateVariables: | - * an array of objects with the following keys - * * name: the name of the variable - * * prefix: optional, the tag prefix for this variable - * * default: optional, the default value for this tag - * * width: the width of the screenboard in pixels - * * height: the height of the screenboard in pixels - * * readOnly: the read-only status of the screenboard - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const boardTitle = "my screenboard"; - * const widgets = [ - * { - * type: "image", - * height: 20, - * width: 32, - * y: 7, - * x: 32, - * url: "https://path/to/image.jpg" - * } - * ]; - * const options = { - * templateVariables: [ - * { - * name: "host1", - * prefix: "host", - * "default": "host:my-host" - * } - * ], - * description: "it is super awesome" - * }; - * dogapi.screenboard.create( - * boardTitle, widgets, options, - * function(err, res){ - * console.dir(res); - * } - * ); - * ``` - */ -function create(boardTitle, widgets, options, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = options; - options = {}; - } - if(typeof options !== "object"){ - options = {}; - } + const params = { + body: { + board_title: boardTitle, + widgets: widgets + } + }; - const params = { - body: { - board_title: boardTitle, - widgets: widgets + if (options.description) { + params.body.description = options.description; + } + if (options.templateVariables) { + params.body.template_variables = options.templateVariables; + } + if (options.width) { + params.body.width = options.width; + } + if (options.height) { + params.body.height = options.height; + } + if (options.readOnly) { + params.body.read_only = options.readOnly; } - }; - if(options.description){ - params.body.description = options.description; - } - if(options.templateVariables){ - params.body.template_variables = options.templateVariables; - } - if(options.width){ - params.body.width = options.width; - } - if(options.height){ - params.body.height = options.height; - } - if(options.readOnly){ - params.body.read_only = options.readOnly; + client.request("POST", "/screen", params, callback); } - client.request("POST", "/screen", params, callback); -} + /*section: screenboard + *comment: update an existing screenboard + *params: + * boardId: the id of the screenboard to update + * boardTitle: the name of the screenboard + * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info + * options: | + * optional, a object which can contain any of the following keys + * * description: description of the screenboard + * * templateVariables: | + * an array of objects with the following keys + * * name: the name of the variable + * * prefix: optional, the tag prefix for this variable + * * default: optional, the default value for this tag + * * width: the width of the screenboard in pixels + * * height: the height of the screenboard in pixels + * * readOnly: the read-only status of the screenboard + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const boardTitle = "my screenboard"; + * const widgets = [ + * { + * type: "image", + * height: 20, + * width: 32, + * y: 7, + * x: 32, + * url: "https://path/to/image.jpg" + * } + * ]; + * const options = { + * description: "it is super awesome" + * }; + * dogapi.screenboard.update( + * 1234, boardTitle, widgets, options, + * function(err, res){ + * console.dir(res); + * } + * ); + * ``` + */ + function update(boardId, boardTitle, widgets, options, callback) { + if (arguments.length < 5 && typeof arguments[3] === "function") { + callback = options; + options = {}; + } + if (typeof options !== "object") { + options = {}; + } -/*section: screenboard - *comment: update an existing screenboard - *params: - * boardId: the id of the screenboard to update - * boardTitle: the name of the screenboard - * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info - * options: | - * optional, a object which can contain any of the following keys - * * description: description of the screenboard - * * templateVariables: | - * an array of objects with the following keys - * * name: the name of the variable - * * prefix: optional, the tag prefix for this variable - * * default: optional, the default value for this tag - * * width: the width of the screenboard in pixels - * * height: the height of the screenboard in pixels - * * readOnly: the read-only status of the screenboard - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const boardTitle = "my screenboard"; - * const widgets = [ - * { - * type: "image", - * height: 20, - * width: 32, - * y: 7, - * x: 32, - * url: "https://path/to/image.jpg" - * } - * ]; - * const options = { - * description: "it is super awesome" - * }; - * dogapi.screenboard.update( - * 1234, boardTitle, widgets, options, - * function(err, res){ - * console.dir(res); - * } - * ); - * ``` - */ -function update(boardId, boardTitle, widgets, options, callback) { - if(arguments.length < 5 && typeof arguments[3] === "function"){ - callback = options; - options = {}; - } - if(typeof options !== "object"){ - options = {}; - } + const params = { + body: { + board_title: boardTitle, + widgets: widgets + } + }; - const params = { - body: { - board_title: boardTitle, - widgets: widgets - } - }; + if (options.description) { + params.body.description = options.description; + } + if (options.templateVariables) { + params.body.template_variables = options.templateVariables; + } + if (options.width) { + params.body.width = options.width; + } + if (options.height) { + params.body.height = options.height; + } + if (options.readOnly) { + params.body.read_only = options.readOnly; + } - if(options.description){ - params.body.description = options.description; - } - if(options.templateVariables){ - params.body.template_variables = options.templateVariables; - } - if(options.width){ - params.body.width = options.width; - } - if(options.height){ - params.body.height = options.height; - } - if(options.readOnly){ - params.body.read_only = options.readOnly; - } + client.request("PUT", util.format("/screen/%s", boardId), params, callback); + } - client.request("PUT", util.format("/screen/%s", boardId), params, callback); -} + /*section: screenboard + *comment: delete an existing screenboard + *params: + * boardId: the id of the screenboard to delete + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.screenboard.remove(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function remove(boardId, callback) { + client.request("DELETE", util.format("/screen/%s", boardId), callback); + } -/*section: screenboard - *comment: delete an existing screenboard - *params: - * boardId: the id of the screenboard to delete - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.screenboard.remove(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function remove(boardId, callback){ - client.request("DELETE", util.format("/screen/%s", boardId), callback); -} + /*section: screenboard + *comment: get the info of a single existing screenboard + *params: + * boardId: the id of the screenboard to fetch + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.screenboard.get(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function get(boardId, callback) { + client.request("GET", util.format("/screen/%s", boardId), callback); + } -/*section: screenboard - *comment: get the info of a single existing screenboard - *params: - * boardId: the id of the screenboard to fetch - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.screenboard.get(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function get(boardId, callback){ - client.request("GET", util.format("/screen/%s", boardId), callback); -} + /*section: screenboard + *comment: get all existing screenboards + *params: + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.screenboard.getAll(function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function getAll(callback) { + client.request("GET", "/screen", callback); + } -/*section: screenboard - *comment: get all existing screenboards - *params: - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.screenboard.getAll(function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function getAll(callback){ - client.request("GET", "/screen", callback); -} + /*section: screenboard + *comment: share an existing screenboard + *params: + * boardId: the id of the screenboard to share + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.screenboard.share(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function share(boardId, callback) { + client.request("POST", util.format("/screen/share/%s", boardId), callback); + } -/*section: screenboard - *comment: share an existing screenboard - *params: - * boardId: the id of the screenboard to share - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.screenboard.share(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function share(boardId, callback){ - client.request("POST", util.format("/screen/share/%s", boardId), callback); -} + return { + create: create, + remove: remove, + update: update, + get: get, + getAll: getAll, + share: share, + getUsage: function () { + return [ + " dogapi screenboard create <boardTitle> <widgets> [--description <description>] [--tmpvars <templateVariables>] [--width <width>] [--height <height>]", + " dogapi screenboard remove <boardId>", + " dogapi screenboard get <boardId>", + " dogapi screenboard getall", + " dogapi screenboard share <boardId>" + ]; + }, + getHelp: function () { + return [ + "Screenboard:", + " Subcommands:", + " create <boardTitle> <widgets> create a new screenboard, <widgets> is a json of the graph definition", + " update <boardId> <boardTitle> <widgets> update a screenboard", + " remove <boardId> remove an existing screenboard", + " get <boardId> get an existing screenboard", + " getall get all screenboards", + " share <boardId> get share info for an existing screenboard", + " Options:", + " --description <description> a description of the screenboard's content", + " --tmpvars <templateVariables> json representation of the template variable definition", + " --width <width> width of the screenboard in pixels", + " --height <height> height of the screenboard in pixels", + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "get") { + get(args._[4], callback); + } else if (subcommand === "getall") { + getAll(callback); + } else if (subcommand === "remove") { + remove(args._[4], callback); + } else if (subcommand === "share") { + share(args._[4], callback); + } else if (subcommand === "update") { + const boardId = args._[4]; + const boardTitle = args._[5]; + const widgets = json.parse(args._[6]); -module.exports = { - create: create, - remove: remove, - update: update, - get: get, - getAll: getAll, - share: share, - getUsage: function(){ - return [ - " dogapi screenboard create <boardTitle> <widgets> [--description <description>] [--tmpvars <templateVariables>] [--width <width>] [--height <height>]", - " dogapi screenboard remove <boardId>", - " dogapi screenboard get <boardId>", - " dogapi screenboard getall", - " dogapi screenboard share <boardId>" - ]; - }, - getHelp: function(){ - return [ - "Screenboard:", - " Subcommands:", - " create <boardTitle> <widgets> create a new screenboard, <widgets> is a json of the graph definition", - " update <boardId> <boardTitle> <widgets> update a screenboard", - " remove <boardId> remove an existing screenboard", - " get <boardId> get an existing screenboard", - " getall get all screenboards", - " share <boardId> get share info for an existing screenboard", - " Options:", - " --description <description> a description of the screenboard's content", - " --tmpvars <templateVariables> json representation of the template variable definition", - " --width <width> width of the screenboard in pixels", - " --height <height> height of the screenboard in pixels", - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "get"){ - get(args._[4], callback); - } else if(subcommand === "getall"){ - getAll(callback); - } else if(subcommand === "remove"){ - remove(args._[4], callback); - } else if(subcommand === "share"){ - share(args._[4], callback); - } else if (subcommand === "update"){ - const boardId = args._[4]; - const boardTitle = args._[5]; - const widgets = json.parse(args._[6]); + const options = {}; + if (args["description"]) { + options.description = args["description"]; + } + if (args["tmpvars"]) { + options.templateVariables = json.parse(args["tmpvars"]); + } + if (args["width"]) { + options.width = parseInt(args["width"]); + } + if (args["height"]) { + options.height = parseInt(args["height"]); + } - const options = {}; - if(args["description"]) { - options.description = args["description"]; - } - if(args["tmpvars"]){ - options.templateVariables = json.parse(args["tmpvars"]); - } - if(args["width"]){ - options.width = parseInt(args["width"]); - } - if(args["height"]){ - options.height = parseInt(args["height"]); - } + update(boardId, boardTitle, widgets, options, callback); + } else if (subcommand === "create") { + const boardTitle = args._[4]; + const widgets = json.parse(args._[5]); - update(boardId, boardTitle, widgets, options, callback); - } else if(subcommand === "create"){ - const boardTitle = args._[4]; - const widgets = json.parse(args._[5]); + const options = {}; + if (args["description"]) { + options.description = args["description"]; + } + if (args["tmpvars"]) { + options.templateVariables = json.parse(args["tmpvars"]); + } + if (args["width"]) { + options.width = parseInt(args["width"]); + } + if (args["height"]) { + options.height = parseInt(args["height"]); + } - const options = {}; - if(args["description"]) { - options.description = args["description"]; - } - if(args["tmpvars"]){ - options.templateVariables = json.parse(args["tmpvars"]); - } - if(args["width"]){ - options.width = parseInt(args["width"]); + create(boardTitle, widgets, options, callback); + } else { + callback("unknown subcommand or arguments try `dogapi screenboard --help` for help", false); } - if(args["height"]){ - options.height = parseInt(args["height"]); - } - - create(boardTitle, widgets, options, callback); - } else { - callback("unknown subcommand or arguments try `dogapi screenboard --help` for help", false); } - } + }; }; diff --git a/lib/api/search.js b/lib/api/search.js index b62ee36..0c57b03 100644 --- a/lib/api/search.js +++ b/lib/api/search.js @@ -1,53 +1,53 @@ -const client = require("../client"); +module.exports = function (client) { + /*section: search + *comment: | + * search for metrics and hosts from the past 24 hours + *params: + * query: the seach query to perform (e.g. "app1" or "hosts:app1" or "metrics:response") + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const query = "app"; + * dogapi.search.query(query, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function query(query, callback) { + const params = { + query: { + q: query + } + }; + client.request("GET", "/search", params, callback); + } -/*section: search - *comment: | - * search for metrics and hosts from the past 24 hours - *params: - * query: the seach query to perform (e.g. "app1" or "hosts:app1" or "metrics:response") - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const query = "app"; - * dogapi.search.query(query, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function query(query, callback){ - const params = { - query: { - q: query + return { + query: query, + getUsage: function () { + return [ + " dogapi search query <query>" + ]; + }, + getHelp: function () { + return [ + "Search:", + " Subcommands:", + " query <query> search for hosts and metrics from the last 24 hours" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "query" && args._.length > 4) { + query(args._[4], callback); + } else { + callback("unknown subcommand or arguments try `dogapi search --help` for help", false); + } } }; - client.request("GET", "/search", params, callback); -} - -module.exports = { - query: query, - getUsage: function(){ - return [ - " dogapi search query <query>" - ]; - }, - getHelp: function(){ - return [ - "Search:", - " Subcommands:", - " query <query> search for hosts and metrics from the last 24 hours" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "query" && args._.length > 4){ - query(args._[4], callback); - } else { - callback("unknown subcommand or arguments try `dogapi search --help` for help", false); - } - } }; diff --git a/lib/api/serviceCheck.js b/lib/api/serviceCheck.js index 1fb961d..b93d1f8 100644 --- a/lib/api/serviceCheck.js +++ b/lib/api/serviceCheck.js @@ -1,89 +1,90 @@ -const client = require("../client"); +module.exports = function (client) { -/*section: serviceCheck - *comment: | - * post an update to a service check - *params: - * check: the check name (e.g. "app.ok") - * hostName: the name of the host submitting the check - * status: one of `dogapi.OK`, `dogapi.WARNING`, `dogapi.CRITICAL` or `dogapi.UNKNOWN` - * parameters: | - * optional, an object containing any of the following - * * timestamp: POSIX timestamp for when the check happened - * * message: string message to accompany the check - * * tags: an array of "tag:value"'s associated with the check - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const check = "app.ok"; - * const hostName = "some.machine"; - * dogapi.serviceCheck.check( - * check, hostName, dogapi.WARNING, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function check(check, hostName, status, parameters, callback){ - if(arguments.length < 5 && typeof arguments[3] === "function"){ - callback = parameters; - parameters = {}; - } + /*section: serviceCheck + *comment: | + * post an update to a service check + *params: + * check: the check name (e.g. "app.ok") + * hostName: the name of the host submitting the check + * status: one of `dogapi.OK`, `dogapi.WARNING`, `dogapi.CRITICAL` or `dogapi.UNKNOWN` + * parameters: | + * optional, an object containing any of the following + * * timestamp: POSIX timestamp for when the check happened + * * message: string message to accompany the check + * * tags: an array of "tag:value"'s associated with the check + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const check = "app.ok"; + * const hostName = "some.machine"; + * dogapi.serviceCheck.check( + * check, hostName, dogapi.WARNING, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function check(check, hostName, status, parameters, callback) { + if (arguments.length < 5 && typeof arguments[3] === "function") { + callback = parameters; + parameters = {}; + } - if(typeof parameters !== "object"){ - parameters = {}; - } + if (typeof parameters !== "object") { + parameters = {}; + } - parameters.check = check; - parameters.host_name = hostName, - parameters.status = status; + parameters.check = check; + parameters.host_name = hostName, + parameters.status = status; - const params = { - body: parameters + const params = { + body: parameters + }; + client.request("POST", "/check_run", params, callback); }; - client.request("POST", "/check_run", params, callback); -}; -module.exports = { - check: check, - getUsage: function(){ - return [ - " dogapi servicecheck check <check> <host> <status> [--time <timestamp>] [--message <message>] [--tags <tags>]" - ]; - }, - getHelp: function(){ - return [ - "Service Check:", - " Subcommands:", - " check <check> <host> <status> add a new service check for <check> and <host> at level <status> (0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN)", - "", - " Options:", - " --time <timestamp> the POSIX timestamp to use for the check", - " --message <message> an optional message to accompany the check", - " --tags <tags> a comma separated list of \"tag:value\"'s for the check" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(args._.length > 6){ - const parameters = {}; - if(args["time"]){ - parameters.time = parseInt(args["time"]); + return { + check: check, + getUsage: function () { + return [ + " dogapi servicecheck check <check> <host> <status> [--time <timestamp>] [--message <message>] [--tags <tags>]" + ]; + }, + getHelp: function () { + return [ + "Service Check:", + " Subcommands:", + " check <check> <host> <status> add a new service check for <check> and <host> at level <status> (0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN)", + "", + " Options:", + " --time <timestamp> the POSIX timestamp to use for the check", + " --message <message> an optional message to accompany the check", + " --tags <tags> a comma separated list of \"tag:value\"'s for the check" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (args._.length > 6) { + const parameters = {}; + if (args["time"]) { + parameters.time = parseInt(args["time"]); + } + if (args["message"]) { + paramaters.message = args["message"]; + } + if (args["tags"]) { + parameters.tags = args["tags"].split(","); + } + check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); + } else { + callback("not enough arguments try `dogapi servicecheck --help` for help", false); } - if(args["message"]){ - paramaters.message = args["message"]; - } - if(args["tags"]){ - parameters.tags = args["tags"].split(","); - } - check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); - } else { - callback("not enough arguments try `dogapi servicecheck --help` for help", false); } - } + }; }; diff --git a/lib/api/tag.js b/lib/api/tag.js index 3f00eab..210b3a3 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -1,264 +1,265 @@ -const client = require("../client"); const util = require('util'); +module.exports = function (client) { -/*section: tag - *comment: | - * get all host tags - *params: - * source: | - * optional, only show tags for a particular source [default: null] - * callback: | - * function callback(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.tag.getAll(function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function getAll(source, callback){ - if(arguments.length < 2 && typeof arguments[0] === "function"){ - callback = source; - source = undefined; - } - - const params = { - query: { - source: source + /*section: tag + *comment: | + * get all host tags + *params: + * source: | + * optional, only show tags for a particular source [default: null] + * callback: | + * function callback(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.tag.getAll(function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function getAll(source, callback) { + if (arguments.length < 2 && typeof arguments[0] === "function") { + callback = source; + source = undefined; } - }; - client.request("GET", "/tags/hosts", params, callback); -} -/*section: tag - *comment: | - * get the host tags for a provided host name or host id - *params: - * hostname: | - * the hostname or host id - * options: - * | - * optional, an object of options for the query allowing the following - * * source: the source of the tags (e.g. chef, puppet, users, etc) [default: null] - * * by_source: whether or not to group the results by source [default: false] - * callback: | - * function callback(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.tag.get("host.name", function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function get(hostname, options, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = options; - options = {}; + const params = { + query: { + source: source + } + }; + client.request("GET", "/tags/hosts", params, callback); } - options = options || {}; - const params = { - query: { + /*section: tag + *comment: | + * get the host tags for a provided host name or host id + *params: + * hostname: | + * the hostname or host id + * options: + * | + * optional, an object of options for the query allowing the following + * * source: the source of the tags (e.g. chef, puppet, users, etc) [default: null] + * * by_source: whether or not to group the results by source [default: false] + * callback: | + * function callback(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.tag.get("host.name", function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function get(hostname, options, callback) { + if (arguments.length < 3 && typeof arguments[1] === "function") { + callback = options; + options = {}; } - }; - if(options.source){ - params.query.source = options.source; - } - if(options.by_source){ - params.query.by_source = options.by_source; - } - client.request("GET", "/tags/hosts/" + hostname, params, callback); -}; + options = options || {}; - -/*section: tag - *comment: | - * assign new host tags to the provided host name or host id - *params: - * hostname: | - * the hostname or host id - * tags: | - * list of `<tag>:<value>` tags to assign to the server - * source: | - * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] - * callback: | - * function callback(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.tag.create("host.name", ["role:webserver"], function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function create(hostname, tags, source, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = source; - source = undefined; - } - - const params = { - body: { - tags: tags, - source: source - }, + const params = { + query: { + } + }; + if (options.source) { + params.query.source = options.source; + } + if (options.by_source) { + params.query.by_source = options.by_source; + } + client.request("GET", "/tags/hosts/" + hostname, params, callback); }; - client.request("POST", "/tags/hosts/" + hostname, params, callback); -}; + /*section: tag + *comment: | + * assign new host tags to the provided host name or host id + *params: + * hostname: | + * the hostname or host id + * tags: | + * list of `<tag>:<value>` tags to assign to the server + * source: | + * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] + * callback: | + * function callback(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.tag.create("host.name", ["role:webserver"], function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function create(hostname, tags, source, callback) { + if (arguments.length < 4 && typeof arguments[2] === "function") { + callback = source; + source = undefined; + } -/*section: tag - *comment: | - * update the host tags for the provided host name or host id - *params: - * hostname: | - * the hostname or host id - * tags: | - * list of `<tag>:<value>` tags to assign to the server - * source: | - * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] - * callback: | - * function callback(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.tag.update("host.name", function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function update(hostname, tags, source, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = source; - source = undefined; - } + const params = { + body: { + tags: tags, + source: source + }, + }; - const params = { - body: { - tags: tags, - source: source - }, + client.request("POST", "/tags/hosts/" + hostname, params, callback); }; - client.request("PUT", "/tags/hosts/" + hostname, params, callback); -}; -/*section: tag - *comment: | - * delete the host tags for the provided host name or host id - *params: - * hostname: | - * the hostname or host id - * source: | - * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] - * callback: | - * function callback(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.tag.remove("host.name", function(err, results){ - * console.dir(results); - * }); - * ``` - */ -function remove(hostname, source, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = source; - source = undefined; - } - const params = { - query: { - source: source + /*section: tag + *comment: | + * update the host tags for the provided host name or host id + *params: + * hostname: | + * the hostname or host id + * tags: | + * list of `<tag>:<value>` tags to assign to the server + * source: | + * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] + * callback: | + * function callback(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.tag.update("host.name", function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function update(hostname, tags, source, callback) { + if (arguments.length < 4 && typeof arguments[2] === "function") { + callback = source; + source = undefined; } + + const params = { + body: { + tags: tags, + source: source + }, + }; + client.request("PUT", "/tags/hosts/" + hostname, params, callback); }; - client.request("DELETE", "/tags/hosts/" + hostname, params, callback); -}; -module.exports = { - _client: client, - getAll: getAll, - get: get, - create: create, - update: update, - remove: remove, - getUsage: function(){ - return [ - " dogapi tag getall [--source <source>]", - " dogapi tag get <host> [--source <source>] [--by-source]", - " dogapi tag remove <host> [--source <source>]", - " dogapi tag create <host> <tags> [--source <source>]", - " dogapi tag update <host> <tags> [--source <source>]" - ]; - }, - getHelp: function(){ - return [ - "Tag:", - " Subcommands:", - " getall get all tags", - " get <host> get all tags for a given host", - " remove <host> delete tags for a given host", - " create <host> <tags> add the comma separates \"tag:value\"'s from <tag> to <host>", - " update <host> <tags> update the comma separates \"tag:value\"'s from <tag> to <host>", - "", - " Options:", - " --source <source> the source of the tags (e.g. \"chef\", \"user\", \"jenkins\", etc)", - " --by-source whether the results should be grouped by source" - ]; - }, - handleCli: function(subcommand, args, callback){ - const source = args["source"]; - const host = args._[4]; + /*section: tag + *comment: | + * delete the host tags for the provided host name or host id + *params: + * hostname: | + * the hostname or host id + * source: | + * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] + * callback: | + * function callback(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.tag.remove("host.name", function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function remove(hostname, source, callback) { + if (arguments.length < 3 && typeof arguments[1] === "function") { + callback = source; + source = undefined; + } - if(subcommand === "getall"){ - getAll(source, callback); - } else if(subcommand === "get"){ - const options = {}; - if(source){ - options.source = source; + const params = { + query: { + source: source } - if(args["by-source"]){ - options.by_source = true; + }; + client.request("DELETE", "/tags/hosts/" + hostname, params, callback); + }; + + return { + _client: client, + getAll: getAll, + get: get, + create: create, + update: update, + remove: remove, + getUsage: function () { + return [ + " dogapi tag getall [--source <source>]", + " dogapi tag get <host> [--source <source>] [--by-source]", + " dogapi tag remove <host> [--source <source>]", + " dogapi tag create <host> <tags> [--source <source>]", + " dogapi tag update <host> <tags> [--source <source>]" + ]; + }, + getHelp: function () { + return [ + "Tag:", + " Subcommands:", + " getall get all tags", + " get <host> get all tags for a given host", + " remove <host> delete tags for a given host", + " create <host> <tags> add the comma separates \"tag:value\"'s from <tag> to <host>", + " update <host> <tags> update the comma separates \"tag:value\"'s from <tag> to <host>", + "", + " Options:", + " --source <source> the source of the tags (e.g. \"chef\", \"user\", \"jenkins\", etc)", + " --by-source whether the results should be grouped by source" + ]; + }, + handleCli: function (subcommand, args, callback) { + const source = args["source"]; + const host = args._[4]; + + if (subcommand === "getall") { + getAll(source, callback); + } else if (subcommand === "get") { + const options = {}; + if (source) { + options.source = source; + } + if (args["by-source"]) { + options.by_source = true; + } + get(host, options, callback); + } else if (subcommand === "create") { + const tags = args._[5].split(","); + create(host, tags, source, callback); + } else if (subcommand === "update") { + const tags = args._[5].split(","); + update(host, tags, source, callback); + } else if (subcommand === "delete") { + remove(host, source, callback); + } else { + callback("unknown subcommand or arguments try `dogapi tag --help` for help", false); } - get(host, options, callback); - } else if(subcommand === "create"){ - const tags = args._[5].split(","); - create(host, tags, source, callback); - } else if(subcommand === "update"){ - const tags = args._[5].split(","); - update(host, tags, source, callback); - } else if(subcommand === "delete"){ - remove(host, source, callback); - } else { - callback("unknown subcommand or arguments try `dogapi tag --help` for help", false); } - } -} + }; +}; diff --git a/lib/api/timeboard.js b/lib/api/timeboard.js index 9dcf4c4..90ffee4 100644 --- a/lib/api/timeboard.js +++ b/lib/api/timeboard.js @@ -1,275 +1,276 @@ -const client = require("../client"); const json = require("../json"); const util = require("util"); -/*section: timeboard - *comment: add a new timeboard - *params: - * title: the title of the timeboard - * description: the description of the timeboard - * graphs: | - * an array of objects with the following keys - * * title: the name of the graph - * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` - * templateVariables: | - * optional, an array of objects with the following keys - * * name: the name of the variable - * * prefix: optional, the tag prefix for this variable - * * default: optional, the default value for this tag - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const title = "Time Keeps on Slipping"; - * const description = "Into the Future"; - * const graphs = [ - * { - * definition: { - * events: [], - * requests: [ - * {q: "avg:system.mem.free{*}"} - * ], - * viz: "timeseries" - * }, - * title: "Average Memory Free" - * } - * ]; - * const templateVariables = [ - * { - * name: "host1", - * prefix: "host", - * "default": "host:my-host" - * } - * ]; - * dogapi.timeboard.create( - * title, description, graphs, templateVariables, - * function(err, res){ - * console.dir(res); - * } - * ); - * ``` - */ -function create(title, description, graphs, templateVariables, callback){ - if(arguments.length < 5 && typeof arguments[3] === "function"){ - callback = templateVariables; - templateVariables = []; - } - - const params = { - body: { - title: title, - description: description, - graphs: graphs +module.exports = function (client) { + /*section: timeboard + *comment: add a new timeboard + *params: + * title: the title of the timeboard + * description: the description of the timeboard + * graphs: | + * an array of objects with the following keys + * * title: the name of the graph + * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` + * templateVariables: | + * optional, an array of objects with the following keys + * * name: the name of the variable + * * prefix: optional, the tag prefix for this variable + * * default: optional, the default value for this tag + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const title = "Time Keeps on Slipping"; + * const description = "Into the Future"; + * const graphs = [ + * { + * definition: { + * events: [], + * requests: [ + * {q: "avg:system.mem.free{*}"} + * ], + * viz: "timeseries" + * }, + * title: "Average Memory Free" + * } + * ]; + * const templateVariables = [ + * { + * name: "host1", + * prefix: "host", + * "default": "host:my-host" + * } + * ]; + * dogapi.timeboard.create( + * title, description, graphs, templateVariables, + * function(err, res){ + * console.dir(res); + * } + * ); + * ``` + */ + function create(title, description, graphs, templateVariables, callback) { + if (arguments.length < 5 && typeof arguments[3] === "function") { + callback = templateVariables; + templateVariables = []; } - }; - if(Array.isArray(templateVariables) && templateVariables.length){ - params.body.template_variables = templateVariables; - } - client.request("POST", "/dash", params, callback); -} + const params = { + body: { + title: title, + description: description, + graphs: graphs + } + }; + if (Array.isArray(templateVariables) && templateVariables.length) { + params.body.template_variables = templateVariables; + } -/*section: timeboard - *comment: update an existing timeboard - *params: - * dashId: the id of the timeboard to update - * title: the title of the timeboard - * description: the description of the timeboard - * graphs: | - * an array of objects with the following keys - * * title: the name of the graph - * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` - * templateVariables: | - * optional, an array of objects with the following keys - * * name: the name of the variable - * * prefix: optional, the tag prefix for this variable - * * default: optional, the default value for this tag - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const title = "Time Keeps on Slipping"; - * const description = "Into the Future"; - * const graphs = [ - * { - * definition: { - * events: [], - * requests: [ - * {q: "avg:system.mem.free{*}"} - * ], - * viz: "timeseries" - * }, - * title: "Average Memory Free" - * } - * ]; - * const templateVariables = [ - * { - * name: "host1", - * prefix: "host", - * default: "host:my-host" - * } - * ]; - * dogapi.timeboard.update( - * 1234, title, description, graphs, templateVariables, - * function(err, res){ - * console.dir(res); - * } - * ); - * ``` - */ -function update(dashId, title, description, graphs, templateVariables, callback){ - if(arguments.length < 6 && typeof arguments[4] === "function"){ - callback = templateVariables; - templateVariables = []; + client.request("POST", "/dash", params, callback); } - const params = { - body: { - title: title, - description: description, - graphs: graphs + /*section: timeboard + *comment: update an existing timeboard + *params: + * dashId: the id of the timeboard to update + * title: the title of the timeboard + * description: the description of the timeboard + * graphs: | + * an array of objects with the following keys + * * title: the name of the graph + * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` + * templateVariables: | + * optional, an array of objects with the following keys + * * name: the name of the variable + * * prefix: optional, the tag prefix for this variable + * * default: optional, the default value for this tag + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const title = "Time Keeps on Slipping"; + * const description = "Into the Future"; + * const graphs = [ + * { + * definition: { + * events: [], + * requests: [ + * {q: "avg:system.mem.free{*}"} + * ], + * viz: "timeseries" + * }, + * title: "Average Memory Free" + * } + * ]; + * const templateVariables = [ + * { + * name: "host1", + * prefix: "host", + * default: "host:my-host" + * } + * ]; + * dogapi.timeboard.update( + * 1234, title, description, graphs, templateVariables, + * function(err, res){ + * console.dir(res); + * } + * ); + * ``` + */ + function update(dashId, title, description, graphs, templateVariables, callback) { + if (arguments.length < 6 && typeof arguments[4] === "function") { + callback = templateVariables; + templateVariables = []; } - }; - if(Array.isArray(templateVariables) && templateVariables.length){ - params.body.template_variables = templateVariables; + + const params = { + body: { + title: title, + description: description, + graphs: graphs + } + }; + if (Array.isArray(templateVariables) && templateVariables.length) { + params.body.template_variables = templateVariables; + } + + client.request("PUT", util.format("/dash/%s", dashId), params, callback); } - client.request("PUT", util.format("/dash/%s", dashId), params, callback); -} + /*section: timeboard + *comment: remove an existing timeboard + *params: + * dashId: the id of the timeboard to remove + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.timeboard.remove(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function remove(dashId, callback) { + client.request("DELETE", util.format("/dash/%s", dashId), {}, callback); + } -/*section: timeboard - *comment: remove an existing timeboard - *params: - * dashId: the id of the timeboard to remove - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.timeboard.remove(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function remove(dashId, callback){ - client.request("DELETE", util.format("/dash/%s", dashId), {}, callback); -} + /*section: timeboard + *comment: get all existing timeboards + *params: + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.timeboard.getAll(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function getAll(callback) { + client.request("GET", "/dash", {}, callback); + } -/*section: timeboard - *comment: get all existing timeboards - *params: - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.timeboard.getAll(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function getAll(callback){ - client.request("GET", "/dash", {}, callback); -} + /*section: timeboard + *comment: get an existing timeboard + *params: + * dashId: the id of the timeboard to get + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.timeboard.get(1234, function(err, res){ + * console.dir(res); + * }); + * ``` + */ + function get(dashId, callback) { + client.request("GET", util.format("/dash/%s", dashId), {}, callback); + } -/*section: timeboard - *comment: get an existing timeboard - *params: - * dashId: the id of the timeboard to get - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.timeboard.get(1234, function(err, res){ - * console.dir(res); - * }); - * ``` - */ -function get(dashId, callback){ - client.request("GET", util.format("/dash/%s", dashId), {}, callback); -} + return { + create: create, + update: update, + remove: remove, + getAll: getAll, + get: get, + getUsage: function () { + return [ + " dogapi timeboard get <dash-id>", + " dogapi timeboard getall", + " dogapi timeboard remove <dash-id>", + " dogapi timeboard create <title> <description> <graphs> [--tmpvars <templateVariables>]", + " dogapi timeboard update <dash-id> <title> <description> <graphs> [--tmpvars <templateVariables>]", + ]; + }, + getHelp: function () { + return [ + "Timeboard:", + " Subcommands:", + " get <dash-id> get an existing timeboard", + " getall get all existing timeboards", + " remove <dash-id> remove an existing timeboard", + " create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition", + " update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition", + " Options:", + " --tmpvars <templateVariables> a json representation of the template variables definition" + ]; + }, + handleCli: function (subcommand, args, callback) { + if (subcommand === "get") { + get(args._[4], callback); + } else if (subcommand === "getall") { + getAll(callback); + } else if (subcommand === "remove") { + remove(args._[4], callback); + } else if (subcommand === "create") { + const title = args._[4]; + const description = args._[5]; + const graphs = json.parse(args._[6]); + const templateVariables = []; + if (args["tmpvars"]) { + templateVariables = json.parse(args["tmpvars"]); + } -module.exports = { - create: create, - update: update, - remove: remove, - getAll: getAll, - get: get, - getUsage: function(){ - return [ - " dogapi timeboard get <dash-id>", - " dogapi timeboard getall", - " dogapi timeboard remove <dash-id>", - " dogapi timeboard create <title> <description> <graphs> [--tmpvars <templateVariables>]", - " dogapi timeboard update <dash-id> <title> <description> <graphs> [--tmpvars <templateVariables>]", - ]; - }, - getHelp: function(){ - return [ - "Timeboard:", - " Subcommands:", - " get <dash-id> get an existing timeboard", - " getall get all existing timeboards", - " remove <dash-id> remove an existing timeboard", - " create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition", - " update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition", - " Options:", - " --tmpvars <templateVariables> a json representation of the template variables definition" - ]; - }, - handleCli: function(subcommand, args, callback){ - if(subcommand === "get"){ - get(args._[4], callback); - } else if(subcommand === "getall"){ - getAll(callback); - } else if(subcommand === "remove"){ - remove(args._[4], callback); - } else if(subcommand === "create"){ - const title = args._[4]; - const description = args._[5]; - const graphs = json.parse(args._[6]); - const templateVariables = []; - if(args["tmpvars"]){ - templateVariables = json.parse(args["tmpvars"]); - } + create(title, description, graphs, templateVariables, callback); + } else if (subcommand === "update") { + const dashId = parseInt(args._[4]); + const title = args._[5]; + const description = args._[6]; + const graphs = json.parse(args._[7]); + const templateVariables = []; + if (args["tmpvars"]) { + templateVariables = json.parse(args["tmpvars"]); + } - create(title, description, graphs, templateVariables, callback); - } else if(subcommand === "update"){ - const dashId = parseInt(args._[4]); - const title = args._[5]; - const description = args._[6]; - const graphs = json.parse(args._[7]); - const templateVariables = []; - if(args["tmpvars"]){ - templateVariables = json.parse(args["tmpvars"]); + update(dashId, title, description, graphs, templateVariables, callback); + } else { + callback("unknown subcommand or arguments try `dogapi timeboard --help` for help", false); } - - update(dashId, title, description, graphs, templateVariables, callback); - } else { - callback("unknown subcommand or arguments try `dogapi timeboard --help` for help", false); } - } + }; }; diff --git a/lib/api/user.js b/lib/api/user.js index 1c45a33..6e426d8 100644 --- a/lib/api/user.js +++ b/lib/api/user.js @@ -1,48 +1,49 @@ -const client = require("../client"); +module.exports = function (client) { -/*section: user - *comment: invite users via e-mail - *params: - * emails: an array of email addresses to send invites to - * callback: function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * const emails = ["me@domain.com", "you@domain.com"]; - * dogapi.user.invite(emails, fuction(err, res){ - * console.dir(res): - * }); - * ``` - */ -function invite(emails, callback){ - const params = { - body: { - emails: emails - } + /*section: user + *comment: invite users via e-mail + *params: + * emails: an array of email addresses to send invites to + * callback: function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * const emails = ["me@domain.com", "you@domain.com"]; + * dogapi.user.invite(emails, fuction(err, res){ + * console.dir(res): + * }); + * ``` + */ + function invite(emails, callback) { + const params = { + body: { + emails: emails + } + }; + client.request("POST", "/invite_users", params, callback); }; - client.request("POST", "/invite_users", params, callback); -}; -module.exports = { - invite: invite, - getUsage: function(){ - return [ - " dogapi user invite <address>..." - ]; - }, - getHelp: function(){ - return [ - "User:", - " Subcommands:", - " invite <address>... invite the given list of e-mail addresses to your datadog org" - ]; - }, - handleCli: function(subcommand, args, callback){ - invite(args._.slice(4), callback) - } + return { + invite: invite, + getUsage: function () { + return [ + " dogapi user invite <address>..." + ]; + }, + getHelp: function () { + return [ + "User:", + " Subcommands:", + " invite <address>... invite the given list of e-mail addresses to your datadog org" + ]; + }, + handleCli: function (subcommand, args, callback) { + invite(args._.slice(4), callback) + } + }; }; diff --git a/lib/client.js b/lib/client.js index 6f2e28e..79aa338 100644 --- a/lib/client.js +++ b/lib/client.js @@ -12,13 +12,13 @@ const json = require("./json"); *example: | * See [client.request](#client-request) */ -var client = function(){ - this.api_key = null; - this.app_key = null; - this.proxy_agent = null; - this.http_options = null; - this.api_version = "v1"; - this.api_host = "app.datadoghq.com"; +const DatadogMetricClient = function(options){ + this.api_key = options.api_key || null; + this.app_key = options.app_key || null; + this.proxy_agent = options.proxy_agent || null; + this.http_options = options.http_options || null; + this.api_version = options.api_version || "v1"; + this.api_host = options.api_host || "app.datadoghq.com"; }; /*section: client @@ -46,7 +46,7 @@ var client = function(){ * }); * ``` */ -client.prototype.request = function(method, path, params, callback){ +DatadogMetricClient.prototype.request = function(method, path, params, callback){ if(arguments.length === 3 && typeof arguments[2] === "function"){ callback = arguments[2]; params = {body: ''}; // create params with empty body property @@ -129,4 +129,4 @@ client.prototype.request = function(method, path, params, callback){ req.end() }; -module.exports = new client(); +module.exports = DatadogMetricClient; diff --git a/lib/index.js b/lib/index.js index 9e4ef18..e0007bb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,6 @@ -require("./api")(module.exports); +const _ = require('lodash') +const api = require("./api").api; +const Client = require("./client"); /*section: dogapi *comment: configure the dogapi client with your app/api keys @@ -45,6 +47,13 @@ function initialize(options){ } }; +function DogApi(options) { + const client = new Client(options || {}); + _.forEach(api, (value, key) => { + this[key] = value(client) + }); +} + /*section: dogapi *comment: get the current POSIX timestamp *example: | @@ -58,8 +67,7 @@ function initialize(options){ function now(){ return parseInt(new Date().getTime() / 1000); }; - -module.exports.client = require("./client"), +module.exports = DogApi module.exports.initialize = initialize; module.exports.now = now; module.exports.OK = 0; diff --git a/test/api/embed.js b/test/api/embed.js index 3de5296..6cf9bff 100644 --- a/test/api/embed.js +++ b/test/api/embed.js @@ -1,12 +1,14 @@ -var assert = require("assert"); -var client = require("../../lib/client"); -var extend = require("extend"); -var embed = require("../../lib/api/embed"); -var sinon = require("sinon"); -var querystring = require("querystring"); +const assert = require("assert"); +const Client = require("../../lib/client"); +const extend = require("extend"); +const Embed = require("../../lib/api/embed"); +const sinon = require("sinon"); +const querystring = require("querystring"); describe("api/embed", function(){ - var stub_request; + const client = new Client({}); + const embed = Embed(client); + let stub_request; beforeEach(function(){ // Setup `client.request` as a stub stub_request = sinon.stub(client, "request"); @@ -18,7 +20,7 @@ describe("api/embed", function(){ }); describe("#create", function(){ it("should make a valid api call", function(){ - var graphJSON = { + const graphJSON = { viz: "timeseries", requests: [ { @@ -26,7 +28,7 @@ describe("api/embed", function(){ } ] }; - var options = { + const options = { timeframe: "1_hour", size: "large", legend: "yes", @@ -38,14 +40,14 @@ describe("api/embed", function(){ // Assert we properly called `client.request` assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; + const call_args = stub_request.getCall(0).args; // Method and endpoint are correct assert.equal(call_args[0], "POST"); assert.equal(call_args[1], "/graph/embed"); // Properly formatted body and content-type - var params = call_args[2]; - var expectedBody = { + const params = call_args[2]; + const expectedBody = { graph_json: JSON.stringify(graphJSON), timeframe: "1_hour", size: "large", @@ -57,7 +59,7 @@ describe("api/embed", function(){ }); it("should only require graph_json", function(){ - var graphJSON = { + const graphJSON = { viz: "timeseries", requests: [ { @@ -71,11 +73,11 @@ describe("api/embed", function(){ // Assert we properly called `client.request` assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; + const call_args = stub_request.getCall(0).args; // Properly formatted body - var params = call_args[2]; - var expectedBody = { + const params = call_args[2]; + const expectedBody = { graph_json: JSON.stringify(graphJSON) }; assert.deepEqual(querystring.parse(params.body), expectedBody); diff --git a/test/api/metric.js b/test/api/metric.js index dd00ed8..0bbc432 100644 --- a/test/api/metric.js +++ b/test/api/metric.js @@ -1,10 +1,12 @@ -var assert = require("assert"); -var client = require("../../lib/client"); -var extend = require("extend"); -var metric = require("../../lib/api/metric"); -var sinon = require("sinon"); +const assert = require("assert"); +const Client = require("../../lib/client"); +const extend = require("extend"); +const Metric = require("../../lib/api/metric"); +const sinon = require("sinon"); describe("api/metrics", function(){ + const client = new Client({}); + const metric = Metric(client); var stub_request; beforeEach(function(){ // Setup `client.request` as a stub From 9c26fa96713f9aebcffa45b774303f91af51c107 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe <adriean.khisbe@live.fr> Date: Fri, 1 Mar 2019 18:12:33 +0100 Subject: [PATCH 03/10] Add some tweaks methods to keep initial api working :hammer_and_pick: --- lib/api/index.js | 10 +--------- lib/index.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/api/index.js b/lib/api/index.js index 41a315b..cc81266 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -1,4 +1,4 @@ -const api = { +module.exports = { comment: require("./comment"), downtime: require("./downtime"), embed: require("./embed"), @@ -15,11 +15,3 @@ const api = { timeboard: require("./timeboard"), user: require("./user"), }; - -module.exports = function(obj){ - for(const key in api){ - obj[key] = api[key]; - } -}; - -module.exports.api = api; diff --git a/lib/index.js b/lib/index.js index e0007bb..8e1266b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,8 @@ -const _ = require('lodash') -const api = require("./api").api; +const _ = require('lodash'); +const api = require("./api"); const Client = require("./client"); +const initialClient = new Client({}) /*section: dogapi *comment: configure the dogapi client with your app/api keys *params: @@ -41,8 +42,8 @@ const Client = require("./client"); function initialize(options){ options = options || {}; for(var key in options){ - if(module.exports.client.hasOwnProperty(key)){ - module.exports.client[key] = options[key]; + if(initialClient.hasOwnProperty(key)){ + initialClient[key] = options[key]; } } }; @@ -50,10 +51,15 @@ function initialize(options){ function DogApi(options) { const client = new Client(options || {}); _.forEach(api, (value, key) => { - this[key] = value(client) + this[key] = value(client); }); } +DogApi.initialize = initialize; +_.forEach(api, (value, key) => { + DogApi[key] = value(initialClient); +}); + /*section: dogapi *comment: get the current POSIX timestamp *example: | @@ -67,8 +73,7 @@ function DogApi(options) { function now(){ return parseInt(new Date().getTime() / 1000); }; -module.exports = DogApi -module.exports.initialize = initialize; +module.exports = DogApi; module.exports.now = now; module.exports.OK = 0; module.exports.WARNING = 1; From 07613ae064c11d234737a6bfffb32fc8b61d8bc6 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe <adriean.khisbe@live.fr> Date: Fri, 1 Mar 2019 18:14:21 +0100 Subject: [PATCH 04/10] Add two examples file with the original and new api :bookmark_tabs: --- examples/new-interface.js | 10 ++++++++++ examples/original-interface.js | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 examples/new-interface.js create mode 100644 examples/original-interface.js diff --git a/examples/new-interface.js b/examples/new-interface.js new file mode 100644 index 0000000..7fd6cb6 --- /dev/null +++ b/examples/new-interface.js @@ -0,0 +1,10 @@ +var Dogapi = require("../lib"); + +var options = { + api_key: "YOUR_KEY_HERE", + app_key: "YOUR_KEY_HERE", +}; + +const dogapi = new Dogapi(options); + +dogapi.metric.send('test', 1) \ No newline at end of file diff --git a/examples/original-interface.js b/examples/original-interface.js new file mode 100644 index 0000000..c1e9e8c --- /dev/null +++ b/examples/original-interface.js @@ -0,0 +1,10 @@ +var dogapi = require("../lib"); + +var options = { + api_key: "YOUR_KEY_HERE", + app_key: "YOUR_KEY_HERE", +}; + +dogapi.initialize(options); + +dogapi.metric.send('test', 1) \ No newline at end of file From e50186817510f217f1acc3b966966ceab189fa62 Mon Sep 17 00:00:00 2001 From: Adriean Khisbe <adriean.khisbe@live.fr> Date: Tue, 5 Mar 2019 08:19:39 +0100 Subject: [PATCH 05/10] Set up linting configuration :gear: --- .eslintignore | 2 + .eslintrc | 39 + package-lock.json | 2396 +++++++++++++++++++++++++++++++++++++++++---- package.json | 3 + 4 files changed, 2244 insertions(+), 196 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..7517ec0 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules/ +test/coverage/ diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..0522bf4 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,39 @@ +{ + "env": { + "commonjs": true, + "es6": true, + "node": true + }, + "extends": [ + "plugin:@coorpacademy/coorpacademy/core", + "plugin:@coorpacademy/coorpacademy/mocha", + "plugin:@coorpacademy/coorpacademy/es20XX", + "plugin:@coorpacademy/coorpacademy/lodash-fp", + "plugin:@coorpacademy/coorpacademy/prettier" + ], + "parserOptions": { + "ecmaVersion": 2017, + "sourceType": "module" + }, + "plugins": [ + "@coorpacademy/coorpacademy" + ], + "rules": { + "promise/no-native": "off", + "strict": "off" + }, + "overrides": [ + { + "files": [ "scripts/migrate*.js", "lib/*.js" ], + "env": { + "mongo": true + } + }, + { + "files": ["**/test/**"], + "rules": { + "unicorn/filename-case": "off" + } + } + ] +} diff --git a/package-lock.json b/package-lock.json index ab42da1..e03ff91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,15 +4,274 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz", + "integrity": "sha512-cuAuTTIQ9RqcFRJ/Y8PvTh+paepNcaGxwQwjIDRWPXmzzyAeCO4KqS9ikMvq0MCbRk6GlYKwfzStrcP3/jSL8g==", + "dev": true, + "requires": { + "@babel/highlight": "7.0.0-beta.44" + } + }, + "@babel/generator": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.0.0-beta.44.tgz", + "integrity": "sha512-5xVb7hlhjGcdkKpMXgicAVgx8syK5VJz193k0i/0sLP6DzE6lRrU1K3B/rFefgdo9LPGMAOOOAWW4jycj07ShQ==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.44", + "jsesc": "2.5.2", + "lodash": "4.17.10", + "source-map": "0.5.7", + "trim-right": "1.0.1" + } + }, + "@babel/helper-function-name": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.44.tgz", + "integrity": "sha512-MHRG2qZMKMFaBavX0LWpfZ2e+hLloT++N7rfM3DYOMUOGCD8cVjqZpwiL8a0bOX3IYcQev1ruciT0gdFFRTxzg==", + "dev": true, + "requires": { + "@babel/helper-get-function-arity": "7.0.0-beta.44", + "@babel/template": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44" + } + }, + "@babel/helper-get-function-arity": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.44.tgz", + "integrity": "sha512-w0YjWVwrM2HwP6/H3sEgrSQdkCaxppqFeJtAnB23pRiJB5E/O9Yp7JAAeWBl+gGEgmBFinnTyOv2RN7rcSmMiw==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.44" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.44.tgz", + "integrity": "sha512-aQ7QowtkgKKzPGf0j6u77kBMdUFVBKNHw2p/3HX/POt5/oz8ec5cs0GwlgM8Hz7ui5EwJnzyfRmkNF1Nx1N7aA==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.44" + } + }, + "@babel/highlight": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz", + "integrity": "sha512-Il19yJvy7vMFm8AVAh6OZzaFoAd0hbkeMZiX3P5HGD+z7dyI7RzndHB0dg6Urh/VAFfHtpOIzDUSxmY6coyZWQ==", + "dev": true, + "requires": { + "chalk": "2.4.2", + "esutils": "2.0.2", + "js-tokens": "3.0.2" + } + }, + "@babel/template": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.44.tgz", + "integrity": "sha512-w750Sloq0UNifLx1rUqwfbnC6uSUk0mfwwgGRfdLiaUzfAOiH0tHJE6ILQIUi3KYkjiCDTskoIsnfqZvWLBDng==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44", + "babylon": "7.0.0-beta.44", + "lodash": "4.17.10" + } + }, + "@babel/traverse": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.44.tgz", + "integrity": "sha512-UHuDz8ukQkJCDASKHf+oDt3FVUzFd+QYfuBIsiNu/4+/ix6pP/C+uQZJ6K1oEfbCMv/IKWbgDEh7fcsnIE5AtA==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.44", + "@babel/generator": "7.0.0-beta.44", + "@babel/helper-function-name": "7.0.0-beta.44", + "@babel/helper-split-export-declaration": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44", + "babylon": "7.0.0-beta.44", + "debug": "3.1.0", + "globals": "11.11.0", + "invariant": "2.2.4", + "lodash": "4.17.10" + } + }, + "@babel/types": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.44.tgz", + "integrity": "sha512-5eTV4WRmqbaFM3v9gHAIljEQJU4Ssc6fxL61JN+Oe2ga/BwyjzjamwkCVVAQjHGuAX8i0BWo42dshL8eO5KfLQ==", + "dev": true, + "requires": { + "esutils": "2.0.2", + "lodash": "4.17.10", + "to-fast-properties": "2.0.0" + } + }, + "@coorpacademy/eslint-plugin-coorpacademy": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/@coorpacademy/eslint-plugin-coorpacademy/-/eslint-plugin-coorpacademy-8.1.1.tgz", + "integrity": "sha1-9PoNOWyVSdEaAYZXHhBvF0rLF0s=", + "dev": true, + "requires": { + "babel-eslint": "8.2.6", + "eslint-ast-utils": "1.1.0", + "eslint-config-prettier": "2.10.0", + "eslint-plugin-ava": "4.5.1", + "eslint-plugin-css-modules": "2.11.0", + "eslint-plugin-flowtype": "2.50.3", + "eslint-plugin-flowtype-errors": "3.6.0", + "eslint-plugin-fp": "2.3.0", + "eslint-plugin-import": "2.16.0", + "eslint-plugin-json": "1.4.0", + "eslint-plugin-lodash-fp": "2.1.3", + "eslint-plugin-mocha": "4.12.1", + "eslint-plugin-prettier": "2.7.0", + "eslint-plugin-promise": "3.8.0", + "eslint-plugin-react": "7.12.4", + "eslint-plugin-unicorn": "4.0.3", + "lodash": "4.17.10", + "prettier": "1.11.1", + "requireindex": "1.2.0" + } + }, + "acorn": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "dev": true + }, + "acorn-jsx": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", + "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", + "dev": true, + "requires": { + "acorn": "3.3.0" + }, + "dependencies": { + "acorn": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", + "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", + "dev": true + } + } + }, + "ajv": { + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", + "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", + "dev": true, + "requires": { + "fast-deep-equal": "2.0.1", + "fast-json-stable-stringify": "2.0.0", + "json-schema-traverse": "0.4.1", + "uri-js": "4.2.2" + } + }, + "ansi-escapes": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", + "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", + "dev": true + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "1.9.3" + } + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", "dev": true, "requires": { - "sprintf-js": "~1.0.2" + "sprintf-js": "1.0.3" } }, + "array-differ": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-differ/-/array-differ-1.0.0.tgz", + "integrity": "sha1-7/UuN1gknTO+QCuLuOVkuytdQDE=", + "dev": true + }, + "array-includes": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.0.3.tgz", + "integrity": "sha1-GEtI9i2S10UrsxsyMWXH+L0CJm0=", + "dev": true, + "requires": { + "define-properties": "1.1.3", + "es-abstract": "1.13.0" + } + }, + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "dev": true, + "requires": { + "array-uniq": "1.0.3" + } + }, + "array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", + "dev": true + }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, + "astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "dev": true + }, + "babel-eslint": { + "version": "8.2.6", + "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.6.tgz", + "integrity": "sha512-aCdHjhzcILdP8c9lej7hvXKvQieyRt20SF102SIGyY4cUIiw6UaAtK4j2o3dXX74jEmy0TJ0CEhv4fTIM3SzcA==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.44", + "@babel/traverse": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44", + "babylon": "7.0.0-beta.44", + "eslint-scope": "3.7.1", + "eslint-visitor-keys": "1.0.0" + } + }, + "babel-runtime": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dev": true, + "requires": { + "core-js": "2.6.5", + "regenerator-runtime": "0.11.1" + } + }, + "babylon": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.44.tgz", + "integrity": "sha512-5Hlm13BJVAioCHpImtFqNOF2H3ieTOHd0fmFGMxOJ9jgeFqeAwsv3u5P5cR7CSeFrkgHsT19DgFJkHV0/Mcd8g==", + "dev": true + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -31,7 +290,7 @@ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { - "balanced-match": "^1.0.0", + "balanced-match": "1.0.0", "concat-map": "0.0.1" } }, @@ -41,6 +300,74 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, + "buf-compare": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buf-compare/-/buf-compare-1.0.1.tgz", + "integrity": "sha1-/vKNqLgROgoNtEMLC2Rntpcws0o=", + "dev": true + }, + "callsites": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.0.0.tgz", + "integrity": "sha512-tWnkwu9YEq2uzlBDI4RcLn8jrFvF9AOi8PxDNU3hZZjJcjkcRAq3vCI+vZcg1SuxISDYe86k9VZFwAxDiJGoAw==", + "dev": true + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.4.0" + } + }, + "chardet": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", + "dev": true + }, + "clean-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz", + "integrity": "sha1-jffHquUf02h06PjQW5GAvBGj/tc=", + "dev": true, + "requires": { + "escape-string-regexp": "1.0.5" + } + }, + "cli-cursor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", + "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "dev": true, + "requires": { + "restore-cursor": "2.0.0" + } + }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", + "dev": true + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, "commander": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", @@ -53,6 +380,50 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "contains-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", + "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", + "dev": true + }, + "core-assert": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/core-assert/-/core-assert-0.2.1.tgz", + "integrity": "sha1-+F4s+b/tKPdzzIs/pcW2m9wC/j8=", + "dev": true, + "requires": { + "buf-compare": "1.0.1", + "is-error": "2.2.1" + } + }, + "core-js": { + "version": "2.6.5", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz", + "integrity": "sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==", + "dev": true + }, + "create-eslint-index": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/create-eslint-index/-/create-eslint-index-1.0.0.tgz", + "integrity": "sha1-2VQ3LYbVeS/NZ+nyt5GxqxYkEbs=", + "dev": true, + "requires": { + "lodash.get": "4.4.2" + } + }, + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "dev": true, + "requires": { + "nice-try": "1.0.5", + "path-key": "2.0.1", + "semver": "5.6.0", + "shebang-command": "1.2.0", + "which": "1.3.1" + } + }, "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", @@ -67,6 +438,30 @@ "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" }, + "deep-is": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true + }, + "deep-strict-equal": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/deep-strict-equal/-/deep-strict-equal-0.2.0.tgz", + "integrity": "sha1-SgeBR6irV/ag1PVUckPNIvROtOQ=", + "dev": true, + "requires": { + "core-assert": "0.2.1" + } + }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "dev": true, + "requires": { + "object-keys": "1.1.0" + } + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -79,8 +474,8 @@ "integrity": "sha1-+vMVSf8ME5RIbd8BLKqxeI1zcIU=", "dev": true, "requires": { - "docopt": "^0.4.1", - "esprima": "^1.2.3" + "docopt": "0.4.1", + "esprima": "1.2.5" }, "dependencies": { "docopt": { @@ -97,273 +492,1635 @@ } } }, + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "dev": true, + "requires": { + "esutils": "2.0.2", + "isarray": "1.0.0" + } + }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, + "enhance-visitors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/enhance-visitors/-/enhance-visitors-1.0.0.tgz", + "integrity": "sha1-qpRdBdpGVnKh69OP7i7T2oUY6Vo=", + "dev": true, + "requires": { + "lodash": "4.17.10" + } + }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "requires": { + "is-arrayish": "0.2.1" + } + }, + "es-abstract": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", + "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", + "dev": true, + "requires": { + "es-to-primitive": "1.2.0", + "function-bind": "1.1.1", + "has": "1.0.3", + "is-callable": "1.1.4", + "is-regex": "1.0.4", + "object-keys": "1.1.0" + } + }, + "es-to-primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", + "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "dev": true, + "requires": { + "is-callable": "1.1.4", + "is-date-object": "1.0.1", + "is-symbol": "1.0.2" + } + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, - "extend": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz", - "integrity": "sha1-WkdDU7nzNT3dgXbf03uRyDpG8dQ=" - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "glob": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", - "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", + "eslint": { + "version": "5.15.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.15.1.tgz", + "integrity": "sha512-NTcm6vQ+PTgN3UBsALw5BMhgO6i5EpIjQF/Xb5tIh3sk9QhrFafujUOczGz4J24JBlzWclSB9Vmx8d+9Z6bFCg==", "dev": true, "requires": { - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "2 || 3", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "@babel/code-frame": "7.0.0", + "ajv": "6.10.0", + "chalk": "2.4.2", + "cross-spawn": "6.0.5", + "debug": "4.1.1", + "doctrine": "3.0.0", + "eslint-scope": "4.0.2", + "eslint-utils": "1.3.1", + "eslint-visitor-keys": "1.0.0", + "espree": "5.0.1", + "esquery": "1.0.1", + "esutils": "2.0.2", + "file-entry-cache": "5.0.1", + "functional-red-black-tree": "1.0.1", + "glob": "7.1.3", + "globals": "11.11.0", + "ignore": "4.0.6", + "import-fresh": "3.0.0", + "imurmurhash": "0.1.4", + "inquirer": "6.2.2", + "js-yaml": "3.12.2", + "json-stable-stringify-without-jsonify": "1.0.1", + "levn": "0.3.0", + "lodash": "4.17.11", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "natural-compare": "1.4.0", + "optionator": "0.8.2", + "path-is-inside": "1.0.2", + "progress": "2.0.3", + "regexpp": "2.0.1", + "semver": "5.6.0", + "strip-ansi": "4.0.0", + "strip-json-comments": "2.0.1", + "table": "5.2.3", + "text-table": "0.2.0" }, "dependencies": { - "inflight": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.4.tgz", - "integrity": "sha1-bLtFIevVHODsCpNr/XZX736bFyo=", + "@babel/code-frame": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", + "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", "dev": true, "requires": { - "once": "^1.3.0", - "wrappy": "1" - }, - "dependencies": { - "wrappy": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz", - "integrity": "sha1-HmWWmWXMvC20VIxrhKbyxa7dRzk=", - "dev": true - } + "@babel/highlight": "7.0.0" } }, - "inherits": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", - "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=", + "@babel/highlight": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", + "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", + "dev": true, + "requires": { + "chalk": "2.4.2", + "esutils": "2.0.2", + "js-tokens": "4.0.0" + } + }, + "acorn": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", + "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", "dev": true }, - "once": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/once/-/once-1.3.3.tgz", - "integrity": "sha1-suJhVXzkwxTsgwTz+oJmPkKXyiA=", + "acorn-jsx": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", + "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "dev": true, "requires": { - "wrappy": "1" - }, - "dependencies": { - "wrappy": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz", - "integrity": "sha1-HmWWmWXMvC20VIxrhKbyxa7dRzk=", - "dev": true - } + "ms": "2.1.1" } }, - "path-is-absolute": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.0.tgz", - "integrity": "sha1-Jj2tpmqz8vsQv3+dJN2PPlcO+RI=", + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "2.0.2" + } + }, + "eslint-scope": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.2.tgz", + "integrity": "sha512-5q1+B/ogmHl8+paxtOKx38Z8LtWkVGuNt3+GQNErqwLl6ViNp/gdJGMCjZNxZ8j/VYjDNZ2Fo+eQc1TAVPIzbg==", + "dev": true, + "requires": { + "esrecurse": "4.2.1", + "estraverse": "4.2.0" + } + }, + "espree": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz", + "integrity": "sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A==", + "dev": true, + "requires": { + "acorn": "6.1.1", + "acorn-jsx": "5.0.1", + "eslint-visitor-keys": "1.0.0" + } + }, + "glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "dev": true - } - } - }, - "growl": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", - "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + }, + "js-yaml": { + "version": "3.12.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.2.tgz", + "integrity": "sha512-QHn/Lh/7HhZ/Twc7vJYQTkjuCa0kaCcDcjK5Zlk2rvnUpy7DxMJ23+Jc2dcyvltwQVg1nygAVlB2oRDFHoRS5Q==", + "dev": true, + "requires": { + "argparse": "1.0.10", + "esprima": "4.0.1" + } + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "dev": true + } + } + }, + "eslint-ast-utils": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-ast-utils/-/eslint-ast-utils-1.1.0.tgz", + "integrity": "sha512-otzzTim2/1+lVrlH19EfQQJEhVJSu0zOb9ygb3iapN6UlyaDtyRq4b5U1FuW0v1lRa9Fp/GJyHkSwm6NqABgCA==", + "dev": true, + "requires": { + "lodash.get": "4.4.2", + "lodash.zip": "4.2.0" + } + }, + "eslint-config-prettier": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-2.10.0.tgz", + "integrity": "sha512-Mhl90VLucfBuhmcWBgbUNtgBiK955iCDK1+aHAz7QfDQF6wuzWZ6JjihZ3ejJoGlJWIuko7xLqNm8BA5uenKhA==", + "dev": true, + "requires": { + "get-stdin": "5.0.1" + } + }, + "eslint-import-resolver-node": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz", + "integrity": "sha512-sfmTqJfPSizWu4aymbPr4Iidp5yKm8yDkHp+Ir3YiTHiiDfxh69mOUsmiqW6RZ9zRXFaF64GtYmN7e+8GHBv6Q==", + "dev": true, + "requires": { + "debug": "2.6.9", + "resolve": "1.10.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, + "eslint-module-utils": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.3.0.tgz", + "integrity": "sha512-lmDJgeOOjk8hObTysjqH7wyMi+nsHwwvfBykwfhjR1LNdd7C2uFJBvx4OpWYpXOw4df1yE1cDEVd1yLHitk34w==", + "dev": true, + "requires": { + "debug": "2.6.9", + "pkg-dir": "2.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, + "eslint-plugin-ava": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-ava/-/eslint-plugin-ava-4.5.1.tgz", + "integrity": "sha512-V0+QZkTYoEXAp8fojaoD85orqNgGfyHWpwQEUqVIRGCRsX9BFnKbG2eX875NgciF3Aouq7smOZcLYqQKgAyH7w==", + "dev": true, + "requires": { + "arrify": "1.0.1", + "deep-strict-equal": "0.2.0", + "enhance-visitors": "1.0.0", + "espree": "3.5.4", + "espurify": "1.8.1", + "import-modules": "1.1.0", + "multimatch": "2.1.0", + "pkg-up": "2.0.0" + } + }, + "eslint-plugin-css-modules": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-css-modules/-/eslint-plugin-css-modules-2.11.0.tgz", + "integrity": "sha512-CLvQvJOMlCywZzaI4HVu7QH/ltgNXvCg7giJGiE+sA9wh5zQ+AqTgftAzrERV22wHe1p688wrU/Zwxt1Ry922w==", + "dev": true, + "requires": { + "gonzales-pe": "4.2.3", + "lodash": "4.17.10" + } + }, + "eslint-plugin-flowtype": { + "version": "2.50.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.50.3.tgz", + "integrity": "sha512-X+AoKVOr7Re0ko/yEXyM5SSZ0tazc6ffdIOocp2fFUlWoDt7DV0Bz99mngOkAFLOAWjqRA5jPwqUCbrx13XoxQ==", + "dev": true, + "requires": { + "lodash": "4.17.10" + } + }, + "eslint-plugin-flowtype-errors": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype-errors/-/eslint-plugin-flowtype-errors-3.6.0.tgz", + "integrity": "sha1-V4KZQmHpJa7RMgYwFGY26I5K1VM=", + "dev": true, + "requires": { + "babel-runtime": "6.26.0", + "slash": "2.0.0" + } + }, + "eslint-plugin-fp": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-fp/-/eslint-plugin-fp-2.3.0.tgz", + "integrity": "sha1-N20qEIcQ6YGYC9w4deO5kg2gSJw=", + "dev": true, + "requires": { + "create-eslint-index": "1.0.0", + "eslint-ast-utils": "1.1.0", + "lodash": "4.17.10", + "req-all": "0.1.0" + } + }, + "eslint-plugin-import": { + "version": "2.16.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.16.0.tgz", + "integrity": "sha512-z6oqWlf1x5GkHIFgrSvtmudnqM6Q60KM4KvpWi5ubonMjycLjndvd5+8VAZIsTlHC03djdgJuyKG6XO577px6A==", + "dev": true, + "requires": { + "contains-path": "0.1.0", + "debug": "2.6.9", + "doctrine": "1.5.0", + "eslint-import-resolver-node": "0.3.2", + "eslint-module-utils": "2.3.0", + "has": "1.0.3", + "lodash": "4.17.11", + "minimatch": "3.0.4", + "read-pkg-up": "2.0.0", + "resolve": "1.10.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + } + } + }, + "eslint-plugin-json": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-json/-/eslint-plugin-json-1.4.0.tgz", + "integrity": "sha512-CECvgRAWtUzuepdlPWd+VA7fhyF9HT183pZnl8wQw5x699Mk/MbME/q8xtULBfooi3LUbj6fToieNmsvUcDxWA==", + "dev": true, + "requires": { + "vscode-json-languageservice": "3.2.1" + } + }, + "eslint-plugin-lodash-fp": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-lodash-fp/-/eslint-plugin-lodash-fp-2.1.3.tgz", + "integrity": "sha1-7B1ngqu4NEFTNLl6ILFFcwoNCng=", + "dev": true, + "requires": { + "create-eslint-index": "1.0.0", + "enhance-visitors": "1.0.0", + "eslint-ast-utils": "1.1.0", + "lodash": "4.17.10", + "req-all": "0.1.0" + } + }, + "eslint-plugin-mocha": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-4.12.1.tgz", + "integrity": "sha512-hxWtYHvLA0p/PKymRfDYh9Mxt5dYkg2Goy1vZDarTEEYfELP9ksga7kKG1NUKSQy27C8Qjc7YrSWTLUhOEOksA==", + "dev": true, + "requires": { + "ramda": "0.25.0" + } + }, + "eslint-plugin-prettier": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-2.7.0.tgz", + "integrity": "sha512-CStQYJgALoQBw3FsBzH0VOVDRnJ/ZimUlpLm226U8qgqYJfPOY/CPK6wyRInMxh73HSKg5wyRwdS4BVYYHwokA==", + "dev": true, + "requires": { + "fast-diff": "1.2.0", + "jest-docblock": "21.2.0" + } + }, + "eslint-plugin-promise": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-3.8.0.tgz", + "integrity": "sha512-JiFL9UFR15NKpHyGii1ZcvmtIqa3UTwiDAGb8atSffe43qJ3+1czVGN6UtkklpcJ2DVnqvTMzEKRaJdBkAL2aQ==", "dev": true }, - "has-flag": { + "eslint-plugin-react": { + "version": "7.12.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.12.4.tgz", + "integrity": "sha512-1puHJkXJY+oS1t467MjbqjvX53uQ05HXwjqDgdbGBqf5j9eeydI54G3KwiJmWciQ0HTBacIKw2jgwSBSH3yfgQ==", + "dev": true, + "requires": { + "array-includes": "3.0.3", + "doctrine": "2.1.0", + "has": "1.0.3", + "jsx-ast-utils": "2.0.1", + "object.fromentries": "2.0.0", + "prop-types": "15.7.2", + "resolve": "1.10.0" + }, + "dependencies": { + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "2.0.2" + } + } + } + }, + "eslint-plugin-unicorn": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-4.0.3.tgz", + "integrity": "sha512-F1JMyd42hx4qGhIaVdOSbDyhcxPgTy4BOzctTCkV+hqebPBUOAQn1f5AhMK2LTyiqCmKiTs8huAErbLBSWKoCQ==", + "dev": true, + "requires": { + "clean-regexp": "1.0.0", + "eslint-ast-utils": "1.1.0", + "import-modules": "1.1.0", + "lodash.camelcase": "4.3.0", + "lodash.kebabcase": "4.1.1", + "lodash.snakecase": "4.1.1", + "lodash.upperfirst": "4.3.1", + "safe-regex": "1.1.0" + } + }, + "eslint-scope": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz", + "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=", + "dev": true, + "requires": { + "esrecurse": "4.2.1", + "estraverse": "4.2.0" + } + }, + "eslint-utils": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", + "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", + "dev": true + }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "dev": true + }, + "espree": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", + "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "dev": true, + "requires": { + "acorn": "5.7.3", + "acorn-jsx": "3.0.1" + } + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, + "espurify": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/espurify/-/espurify-1.8.1.tgz", + "integrity": "sha512-ZDko6eY/o+D/gHCWyHTU85mKDgYcS4FJj7S+YD6WIInm7GQ6AnOjmcL4+buFV/JOztVLELi/7MmuGU5NHta0Mg==", + "dev": true, + "requires": { + "core-js": "2.6.5" + } + }, + "esquery": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", + "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "dev": true, + "requires": { + "estraverse": "4.2.0" + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "4.2.0" + } + }, + "estraverse": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", + "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", + "dev": true + }, + "esutils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true + }, + "extend": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz", + "integrity": "sha1-WkdDU7nzNT3dgXbf03uRyDpG8dQ=" + }, + "external-editor": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", + "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", + "dev": true, + "requires": { + "chardet": "0.7.0", + "iconv-lite": "0.4.24", + "tmp": "0.0.33" + } + }, + "fast-deep-equal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", "dev": true }, - "he": { + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, + "fast-json-stable-stringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", + "dev": true + }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true + }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "dev": true, + "requires": { + "escape-string-regexp": "1.0.5" + } + }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "2.0.1" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "2.0.0" + } + }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + } + }, + "flatted": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.0.tgz", + "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "function-bind": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, + "get-stdin": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz", + "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=", + "dev": true + }, + "glob": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", + "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", + "dev": true, + "requires": { + "inflight": "1.0.4", + "inherits": "2.0.1", + "minimatch": "3.0.4", + "once": "1.3.3", + "path-is-absolute": "1.0.0" + }, + "dependencies": { + "inflight": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.4.tgz", + "integrity": "sha1-bLtFIevVHODsCpNr/XZX736bFyo=", + "dev": true, + "requires": { + "once": "1.3.3", + "wrappy": "1.0.1" + }, + "dependencies": { + "wrappy": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz", + "integrity": "sha1-HmWWmWXMvC20VIxrhKbyxa7dRzk=", + "dev": true + } + } + }, + "inherits": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", + "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=", + "dev": true + }, + "once": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/once/-/once-1.3.3.tgz", + "integrity": "sha1-suJhVXzkwxTsgwTz+oJmPkKXyiA=", + "dev": true, + "requires": { + "wrappy": "1.0.1" + }, + "dependencies": { + "wrappy": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz", + "integrity": "sha1-HmWWmWXMvC20VIxrhKbyxa7dRzk=", + "dev": true + } + } + }, + "path-is-absolute": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.0.tgz", + "integrity": "sha1-Jj2tpmqz8vsQv3+dJN2PPlcO+RI=", + "dev": true + } + } + }, + "globals": { + "version": "11.11.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.11.0.tgz", + "integrity": "sha512-WHq43gS+6ufNOEqlrDBxVEbb8ntfXrfAUU2ZOpCxrBdGKW3gyv8mCxAfIBD0DroPKGrJ2eSsXsLtY9MPntsyTw==", + "dev": true + }, + "gonzales-pe": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/gonzales-pe/-/gonzales-pe-4.2.3.tgz", + "integrity": "sha512-Kjhohco0esHQnOiqqdJeNz/5fyPkOMD/d6XVjwTAoPGUFh0mCollPUTUTa2OZy4dYNAqlPIQdTiNzJTWdd9Htw==", + "dev": true, + "requires": { + "minimist": "1.1.3" + } + }, + "graceful-fs": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", + "dev": true + }, + "growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "dev": true + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "1.1.1" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "has-symbols": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", + "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", + "dev": true + }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, + "hosted-git-info": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", + "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", + "dev": true + }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "requires": { + "safer-buffer": "2.1.2" + } + }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, + "import-fresh": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", + "integrity": "sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ==", + "dev": true, + "requires": { + "parent-module": "1.0.0", + "resolve-from": "4.0.0" + } + }, + "import-modules": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/import-modules/-/import-modules-1.1.0.tgz", + "integrity": "sha1-dI23nFzEK7lwHvq0JPiU5yYA6dw=", + "dev": true + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "ini": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" + }, + "inquirer": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.2.tgz", + "integrity": "sha512-Z2rREiXA6cHRR9KBOarR3WuLlFzlIfAEIiB45ll5SSadMg7WqOh1MKEjjndfuH5ewXdixWCxqnVfGOQzPeiztA==", + "dev": true, + "requires": { + "ansi-escapes": "3.2.0", + "chalk": "2.4.2", + "cli-cursor": "2.1.0", + "cli-width": "2.2.0", + "external-editor": "3.0.3", + "figures": "2.0.0", + "lodash": "4.17.11", + "mute-stream": "0.0.7", + "run-async": "2.3.0", + "rxjs": "6.4.0", + "string-width": "2.1.1", + "strip-ansi": "5.0.0", + "through": "2.3.8" + }, + "dependencies": { + "ansi-regex": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.0.0.tgz", + "integrity": "sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==", + "dev": true + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "strip-ansi": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.0.0.tgz", + "integrity": "sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==", + "dev": true, + "requires": { + "ansi-regex": "4.0.0" + } + } + } + }, + "invariant": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", + "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", + "dev": true, + "requires": { + "loose-envify": "1.4.0" + } + }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true + }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + }, + "is-date-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", + "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", + "dev": true + }, + "is-error": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-error/-/is-error-2.2.1.tgz", + "integrity": "sha1-aEqW2EB2V3yY9M20DG0mpRI78Zw=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", + "dev": true + }, + "is-regex": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", + "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "dev": true, + "requires": { + "has": "1.0.3" + } + }, + "is-symbol": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", + "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "dev": true, + "requires": { + "has-symbols": "1.0.0" + } + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, + "jest-docblock": { + "version": "21.2.0", + "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-21.2.0.tgz", + "integrity": "sha512-5IZ7sY9dBAYSV+YjQ0Ovb540Ku7AO9Z5o2Cg789xj167iQuZ2cG+z0f3Uct6WeYLbU6aQiM2pCs7sZ+4dotydw==", + "dev": true + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + }, + "js-yaml": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.3.1.tgz", + "integrity": "sha1-yhrNNCPsJ10SFAp7q1HbAVugs8A=", + "dev": true, + "requires": { + "argparse": "1.0.10", + "esprima": "2.2.0" + }, + "dependencies": { + "esprima": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.2.0.tgz", + "integrity": "sha1-QpLB1o5Bc9gV+iKQ3Hr8ltgfzYM=", + "dev": true + } + } + }, + "jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "dev": true + }, + "json-bigint": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-0.1.4.tgz", + "integrity": "sha1-tdQLipAJ6S8Vf3wHnbCXABgw4B4=", + "requires": { + "bignumber.js": "1.1.1" + }, + "dependencies": { + "bignumber.js": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-1.1.1.tgz", + "integrity": "sha1-GkFdmsAUwTJWrx/u2dGj5XF6jPc=" + } + } + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, + "jsonc-parser": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.0.3.tgz", + "integrity": "sha512-WJi9y9ABL01C8CxTKxRRQkkSpY/x2bo4Gy0WuiZGrInxQqgxQpvkBCLNcDYcHOSdhx4ODgbFcgAvfL49C+PHgQ==", + "dev": true + }, + "jsx-ast-utils": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", + "integrity": "sha1-6AGxs5mF4g//yHtA43SAgOLcrH8=", + "dev": true, + "requires": { + "array-includes": "3.0.3" + } + }, + "levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "dev": true, + "requires": { + "prelude-ls": "1.1.2", + "type-check": "0.3.2" + } + }, + "load-json-file": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", + "dev": true, + "requires": { + "graceful-fs": "4.1.15", + "parse-json": "2.2.0", + "pify": "2.3.0", + "strip-bom": "3.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "2.0.0", + "path-exists": "3.0.0" + } + }, + "lodash": { + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + }, + "lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=", + "dev": true + }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "dev": true + }, + "lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY=", + "dev": true + }, + "lodash.snakecase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", + "integrity": "sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40=", + "dev": true + }, + "lodash.upperfirst": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz", + "integrity": "sha1-E2Xt9DFIBIHvDRxolXpe2Z1J984=", + "dev": true + }, + "lodash.zip": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz", + "integrity": "sha1-7GZi5IlkCO1KtsVCo5kLcswIACA=", + "dev": true + }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dev": true, + "requires": { + "js-tokens": "3.0.2" + } + }, + "marked": { + "version": "0.3.19", + "resolved": "https://registry.npmjs.org/marked/-/marked-0.3.19.tgz", + "integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==", + "dev": true + }, + "mimic-fn": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.1.3.tgz", + "integrity": "sha1-O+39kaktOQFvz6ocaB6Pqhoe/ag=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } + } + }, + "mocha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", + "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "dev": true, + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.15.1", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.5", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "5.4.0" + }, + "dependencies": { + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + } + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "multimatch": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/multimatch/-/multimatch-2.1.0.tgz", + "integrity": "sha1-nHkGoi+0wCkZ4vX3UWG0zb1LKis=", + "dev": true, + "requires": { + "array-differ": "1.0.0", + "array-union": "1.0.2", + "arrify": "1.0.1", + "minimatch": "3.0.4" + } + }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "dev": true + }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "dev": true + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "requires": { + "hosted-git-info": "2.7.1", + "resolve": "1.10.0", + "semver": "5.6.0", + "validate-npm-package-license": "3.0.4" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, + "object-keys": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.0.tgz", + "integrity": "sha512-6OO5X1+2tYkNyNEx6TsCxEqFfRWaqx6EtMiSbGrw8Ob8v9Ne+Hl8rBAgLBZn5wjEz3s/s6U1WXFUFOcxxAwUpg==", + "dev": true + }, + "object.fromentries": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/object.fromentries/-/object.fromentries-2.0.0.tgz", + "integrity": "sha512-9iLiI6H083uiqUuvzyY6qrlmc/Gz8hLQFOcb/Ri/0xXFkSNS3ctV+CbE6yM2+AnkYfOB3dGjdzC0wrMLIhQICA==", + "dev": true, + "requires": { + "define-properties": "1.1.3", + "es-abstract": "1.13.0", + "function-bind": "1.1.1", + "has": "1.0.3" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "dev": true, + "requires": { + "mimic-fn": "1.2.0" + } + }, + "optionator": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", + "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", + "dev": true, + "requires": { + "deep-is": "0.1.3", + "fast-levenshtein": "2.0.6", + "levn": "0.3.0", + "prelude-ls": "1.1.2", + "type-check": "0.3.2", + "wordwrap": "1.0.0" + } + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "1.3.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, + "parent-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.0.tgz", + "integrity": "sha512-8Mf5juOMmiE4FcmzYc4IaiS9L3+9paz2KOiXzkRviCP6aDmN49Hz6EMWz0lGNp9pX80GvvAuLADtyGfW/Em3TA==", + "dev": true, + "requires": { + "callsites": "3.0.0" + } + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "dev": true, + "requires": { + "error-ex": "1.3.2" + } + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-is-inside": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", + "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", + "dev": true + }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "path-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", + "dev": true, + "requires": { + "pify": "2.3.0" + } + }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, + "pkg-dir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz", + "integrity": "sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s=", + "dev": true, + "requires": { + "find-up": "2.1.0" + } + }, + "pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz", + "integrity": "sha1-yBmscoBZpGHKscOImivjxJoATX8=", + "dev": true, + "requires": { + "find-up": "2.1.0" + } + }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", + "dev": true + }, + "prettier": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.11.1.tgz", + "integrity": "sha512-T/KD65Ot0PB97xTrG8afQ46x3oiVhnfGjGESSI9NWYcG92+OUPZKkwHqGWXH2t9jK1crnQjubECW0FuOth+hxw==", "dev": true }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, + "prop-types": { + "version": "15.7.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", + "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", "dev": true, "requires": { - "once": "^1.3.0", - "wrappy": "1" + "loose-envify": "1.4.0", + "object-assign": "4.1.1", + "react-is": "16.8.3" } }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, - "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" + "ramda": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.25.0.tgz", + "integrity": "sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ==", + "dev": true }, - "js-yaml": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.3.1.tgz", - "integrity": "sha1-yhrNNCPsJ10SFAp7q1HbAVugs8A=", - "dev": true, + "rc": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", "requires": { - "argparse": "~1.0.2", - "esprima": "~2.2.0" + "deep-extend": "0.6.0", + "ini": "1.3.5", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" }, "dependencies": { - "esprima": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.2.0.tgz", - "integrity": "sha1-QpLB1o5Bc9gV+iKQ3Hr8ltgfzYM=", - "dev": true + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" } } }, - "json-bigint": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-0.1.4.tgz", - "integrity": "sha1-tdQLipAJ6S8Vf3wHnbCXABgw4B4=", + "react-is": { + "version": "16.8.3", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.3.tgz", + "integrity": "sha512-Y4rC1ZJmsxxkkPuMLwvKvlL1Zfpbcu+Bf4ZigkHup3v9EfdYhAlWAaVyA19olXq2o2mGn0w+dFKvk3pVVlYcIA==", + "dev": true + }, + "read-pkg": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", + "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=", + "dev": true, "requires": { - "bignumber.js": "~1.1.1" - }, - "dependencies": { - "bignumber.js": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-1.1.1.tgz", - "integrity": "sha1-GkFdmsAUwTJWrx/u2dGj5XF6jPc=" - } + "load-json-file": "2.0.0", + "normalize-package-data": "2.5.0", + "path-type": "2.0.0" } }, - "lodash": { - "version": "4.17.10", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + "read-pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", + "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=", + "dev": true, + "requires": { + "find-up": "2.1.0", + "read-pkg": "2.0.0" + } }, - "marked": { - "version": "0.3.19", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.3.19.tgz", - "integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==", + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", "dev": true }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "regexpp": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", + "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", + "dev": true + }, + "req-all": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/req-all/-/req-all-0.1.0.tgz", + "integrity": "sha1-EwBR4qzligLqy/ydRIV3pzapJzo=", + "dev": true + }, + "requireindex": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", + "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", + "dev": true + }, + "resolve": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", + "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", "dev": true, "requires": { - "brace-expansion": "^1.1.7" + "path-parse": "1.0.6" } }, - "minimist": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.1.3.tgz", - "integrity": "sha1-O+39kaktOQFvz6ocaB6Pqhoe/ag=" + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "restore-cursor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", + "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", "dev": true, "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } + "onetime": "2.0.1", + "signal-exit": "3.0.2" } }, - "mocha": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", - "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "ret": { + "version": "0.1.15", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", + "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", + "dev": true + }, + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", "dev": true, "requires": { - "browser-stdout": "1.3.1", - "commander": "2.15.1", - "debug": "3.1.0", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.5", - "he": "1.1.1", - "minimatch": "3.0.4", - "mkdirp": "0.5.1", - "supports-color": "5.4.0" + "glob": "7.1.3" }, "dependencies": { "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "dev": true, "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" } } } }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "dev": true, + "requires": { + "is-promise": "2.1.0" + } }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "rxjs": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.4.0.tgz", + "integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==", "dev": true, "requires": { - "wrappy": "1" + "tslib": "1.9.3" } }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "safe-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", + "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", + "dev": true, + "requires": { + "ret": "0.1.15" + } + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, - "rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "semver": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "dev": true + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, "requires": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" - } + "shebang-regex": "1.0.0" } }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true + }, "sinon": { "version": "1.15.4", "resolved": "https://registry.npmjs.org/sinon/-/sinon-1.15.4.tgz", @@ -373,7 +2130,7 @@ "formatio": "1.1.1", "lolex": "1.1.0", "samsam": "1.1.2", - "util": ">=0.10.3 <1" + "util": "0.10.3" }, "dependencies": { "formatio": { @@ -382,7 +2139,7 @@ "integrity": "sha1-XtPM1jZVEJc4NGXZlhmRAOhhYek=", "dev": true, "requires": { - "samsam": "~1.1" + "samsam": "1.1.2" } }, "lolex": { @@ -416,12 +2173,92 @@ } } }, + "slash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", + "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", + "dev": true + }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "3.2.1", + "astral-regex": "1.0.0", + "is-fullwidth-code-point": "2.0.0" + } + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + }, + "spdx-correct": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", + "integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==", + "dev": true, + "requires": { + "spdx-expression-parse": "3.0.0", + "spdx-license-ids": "3.0.3" + } + }, + "spdx-exceptions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", + "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", + "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, + "requires": { + "spdx-exceptions": "2.2.0", + "spdx-license-ids": "3.0.3" + } + }, + "spdx-license-ids": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz", + "integrity": "sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g==", + "dev": true + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "2.0.0", + "strip-ansi": "4.0.0" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "3.0.0" + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -433,14 +2270,181 @@ "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "3.0.0" + } + }, + "table": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/table/-/table-5.2.3.tgz", + "integrity": "sha512-N2RsDAMvDLvYwFcwbPyF3VmVSSkuF+G1e+8inhBLtHpvwXGw4QRPEZhihQNeEN0i1up6/f6ObCJXNdlRG3YVyQ==", + "dev": true, + "requires": { + "ajv": "6.10.0", + "lodash": "4.17.11", + "slice-ansi": "2.1.0", + "string-width": "3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.0.0.tgz", + "integrity": "sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==", + "dev": true + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "string-width": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.0.0.tgz", + "integrity": "sha512-rr8CUxBbvOZDUvc5lNIJ+OC1nPVpz+Siw9VBtUjB9b6jZehZLFt0JMCZzShFHIsI8cbhm0EsNIfWJMFV3cu3Ew==", + "dev": true, + "requires": { + "emoji-regex": "7.0.3", + "is-fullwidth-code-point": "2.0.0", + "strip-ansi": "5.0.0" + } + }, + "strip-ansi": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.0.0.tgz", + "integrity": "sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==", + "dev": true, + "requires": { + "ansi-regex": "4.0.0" + } + } + } + }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true + }, + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "requires": { + "os-tmpdir": "1.0.2" + } + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true + }, + "trim-right": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", + "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", + "dev": true + }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", + "dev": true + }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "dev": true, + "requires": { + "prelude-ls": "1.1.2" + } + }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, + "requires": { + "punycode": "2.1.1" + } + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "3.1.0", + "spdx-expression-parse": "3.0.0" + } + }, + "vscode-json-languageservice": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-3.2.1.tgz", + "integrity": "sha512-ee9MJ70/xR55ywvm0bZsDLhA800HCRE27AYgMNTU14RSg20Y+ngHdQnUt6OmiTXrQDI/7sne6QUOtHIN0hPQYA==", + "dev": true, + "requires": { + "jsonc-parser": "2.0.3", + "vscode-languageserver-types": "3.14.0", + "vscode-nls": "4.0.0", + "vscode-uri": "1.0.6" + } + }, + "vscode-languageserver-types": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.14.0.tgz", + "integrity": "sha512-lTmS6AlAlMHOvPQemVwo3CezxBp0sNB95KNPkqp3Nxd5VFEnuG1ByM0zlRWos0zjO3ZWtkvhal0COgiV1xIA4A==", + "dev": true + }, + "vscode-nls": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-4.0.0.tgz", + "integrity": "sha512-qCfdzcH+0LgQnBpZA53bA32kzp9rpq/f66Som577ObeuDlFIrtbEJ+A/+CCxjIh4G8dpJYNCKIsxpRAHIfsbNw==", + "dev": true + }, + "vscode-uri": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.6.tgz", + "integrity": "sha512-sLI2L0uGov3wKVb9EB+vIQBl9tVP90nqRvxSoJ35vI3NjxE8jfsE5DSOhWgSunHSZmKS4OCi2jrtfxK7uyp2ww==", + "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "requires": { + "isexe": "2.0.0" } }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", + "dev": true + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true + }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "0.5.1" + } } } } diff --git a/package.json b/package.json index 1ebf6d3..4c1e512 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "lib/index.js", "scripts": { "test": "./node_modules/.bin/mocha --recursive ./test", + "lint": "eslint lib test bin/dogapi examples", "docs": "node ./docs/create.js > index.html" }, "bin": { @@ -34,8 +35,10 @@ "rc": "^1.2.8" }, "devDependencies": { + "@coorpacademy/eslint-plugin-coorpacademy": "^8.1.1", "bignumber.js": "^2.0.7", "docast": "^0.1.1", + "eslint": "^5.15.1", "glob": "^6.0.0", "js-yaml": "^3.2.7", "marked": "^0.3.9", From 83303376d36d0b009744ad49e1ac49fa36d48d6f Mon Sep 17 00:00:00 2001 From: Adriean Khisbe <adriean.khisbe@live.fr> Date: Tue, 5 Mar 2019 08:22:03 +0100 Subject: [PATCH 06/10] Reformating with the new prettier configuration :wrench: --- bin/dogapi | 131 +++--- examples/new-interface.js | 10 +- examples/original-interface.js | 10 +- lib/api/comment.js | 179 +++++---- lib/api/downtime.js | 267 +++++++------ lib/api/embed.js | 177 ++++----- lib/api/event.js | 216 +++++----- lib/api/graph.js | 98 +++-- lib/api/host.js | 130 +++--- lib/api/index.js | 30 +- lib/api/infrastructure.js | 55 ++- lib/api/metric.js | 221 ++++++----- lib/api/monitor.js | 537 +++++++++++++------------ lib/api/screenboard.js | 331 ++++++++-------- lib/api/search.js | 62 ++- lib/api/serviceCheck.js | 107 +++-- lib/api/tag.js | 256 ++++++------ lib/api/timeboard.js | 220 +++++------ lib/api/user.js | 53 ++- lib/client.js | 175 ++++---- lib/constants.js | 16 +- lib/index.js | 40 +- lib/json.js | 7 +- test/api/embed.js | 152 +++---- test/api/graph.js | 16 +- test/api/metric.js | 701 ++++++++++++++++----------------- test/json.js | 42 +- 27 files changed, 2112 insertions(+), 2127 deletions(-) diff --git a/bin/dogapi b/bin/dogapi index 69f3a1a..e71588c 100755 --- a/bin/dogapi +++ b/bin/dogapi @@ -1,81 +1,90 @@ #!/usr/bin/env node -var dogapi = require("../"); -var json = require("../lib/json"); -var minimist = require("minimist"); -var rc = require("rc"); -var EOL = require("os").EOL; +const dogapi = require('..'); +const json = require('../lib/json'); +const minimist = require('minimist'); +const rc = require('rc'); +const EOL = require('os').EOL; -var config = rc("dogapi", { - api_key: null, - app_key: null +const config = rc('dogapi', { + api_key: null, + app_key: null }); dogapi.initialize(config); -var usage = [ - "Usage:", - " dogapi --help", - " dogapi <command> --help", - " dogapi --version", - " dogapi now", - " dogapi past <seconds-ago>", - " dogapi future <seconds-ahead>" +let usage = [ + 'Usage:', + ' dogapi --help', + ' dogapi <command> --help', + ' dogapi --version', + ' dogapi now', + ' dogapi past <seconds-ago>', + ' dogapi future <seconds-ahead>' ]; -var help = []; -for(var key in dogapi){ - if(!dogapi.hasOwnProperty(key)){ - continue; - } else if(!dogapi[key].hasOwnProperty("getUsage") || typeof dogapi[key].getUsage !== "function"){ - continue; - } else if(!dogapi[key].hasOwnProperty("handleCli") || typeof dogapi[key].handleCli !== "function"){ - continue; - } - usage = usage.concat(dogapi[key].getUsage()); +let help = []; +for (const key in dogapi) { + if (!dogapi.hasOwnProperty(key)) { + continue; + } else if ( + !dogapi[key].hasOwnProperty('getUsage') || + typeof dogapi[key].getUsage !== 'function' + ) { + continue; + } else if ( + !dogapi[key].hasOwnProperty('handleCli') || + typeof dogapi[key].handleCli !== 'function' + ) { + continue; + } + usage = usage.concat(dogapi[key].getUsage()); - if(dogapi[key].hasOwnProperty("getHelp") && typeof dogapi[key].getHelp === "function"){ - help = help.concat([""], dogapi[key].getHelp()); - } + if (dogapi[key].hasOwnProperty('getHelp') && typeof dogapi[key].getHelp === 'function') { + help = help.concat([''], dogapi[key].getHelp()); + } } usage = usage.concat(help); usage = usage.join(EOL); -var args = minimist(process.argv); +const args = minimist(process.argv); -var command = args._[2]; -var subcommand = args._[3]; +let command = args._[2]; +const subcommand = args._[3]; // this is the one unusual case -if(command === "servicecheck"){ - command = "serviceCheck"; +if (command === 'servicecheck') { + command = 'serviceCheck'; } -if(command === "now"){ - console.log(dogapi.now()); -} else if(command === "past" && args._.length > 3){ - console.log(dogapi.now() - parseInt(args._[args._.length - 1])); -} else if(command === "future" && args._.length > 3){ - console.log(dogapi.now() + parseInt(args._[args._.length - 1])); -} else if(dogapi.hasOwnProperty(command)){ - if(subcommand){ - dogapi[command].handleCli(subcommand, args, function(err, res){ - if(err){ - console.error(json.stringify(err, null, ' ')); - process.exit(1); - } else { - if(res === ""){ - res = "success"; - } - console.log(json.stringify(res, null, ' ')); - } - }); - } else { - var commandUsage = ["Usage:"].concat(dogapi[command].getUsage()); - if(dogapi[command].hasOwnProperty("getHelp") && typeof dogapi[command].getHelp === "function"){ - commandUsage = commandUsage.concat([EOL], dogapi[command].getHelp()); +if (command === 'now') { + console.log(dogapi.now()); +} else if (command === 'past' && args._.length > 3) { + console.log(dogapi.now() - parseInt(args._[args._.length - 1])); +} else if (command === 'future' && args._.length > 3) { + console.log(dogapi.now() + parseInt(args._[args._.length - 1])); +} else if (dogapi.hasOwnProperty(command)) { + if (subcommand) { + dogapi[command].handleCli(subcommand, args, function(err, res) { + if (err) { + console.error(json.stringify(err, null, ' ')); + process.exit(1); + } else { + if (res === '') { + res = 'success'; } - console.log(commandUsage.join(EOL).replace(/\$\{command\}/g, " dogapi")); + console.log(json.stringify(res, null, ' ')); + } + }); + } else { + let commandUsage = ['Usage:'].concat(dogapi[command].getUsage()); + if ( + dogapi[command].hasOwnProperty('getHelp') && + typeof dogapi[command].getHelp === 'function' + ) { + commandUsage = commandUsage.concat([EOL], dogapi[command].getHelp()); } -} else if(args.version){ - console.log(require("../package.json").version); + console.log(commandUsage.join(EOL).replace(/\$\{command\}/g, ' dogapi')); + } +} else if (args.version) { + console.log(require('../package.json').version); } else { - console.log(usage); + console.log(usage); } diff --git a/examples/new-interface.js b/examples/new-interface.js index 7fd6cb6..ea37b5e 100644 --- a/examples/new-interface.js +++ b/examples/new-interface.js @@ -1,10 +1,10 @@ -var Dogapi = require("../lib"); +const Dogapi = require('../lib'); -var options = { - api_key: "YOUR_KEY_HERE", - app_key: "YOUR_KEY_HERE", +const options = { + api_key: 'YOUR_KEY_HERE', + app_key: 'YOUR_KEY_HERE' }; const dogapi = new Dogapi(options); -dogapi.metric.send('test', 1) \ No newline at end of file +dogapi.metric.send('test', 1); diff --git a/examples/original-interface.js b/examples/original-interface.js index c1e9e8c..161f1a0 100644 --- a/examples/original-interface.js +++ b/examples/original-interface.js @@ -1,10 +1,10 @@ -var dogapi = require("../lib"); +const dogapi = require('../lib'); -var options = { - api_key: "YOUR_KEY_HERE", - app_key: "YOUR_KEY_HERE", +const options = { + api_key: 'YOUR_KEY_HERE', + app_key: 'YOUR_KEY_HERE' }; dogapi.initialize(options); -dogapi.metric.send('test', 1) \ No newline at end of file +dogapi.metric.send('test', 1); diff --git a/lib/api/comment.js b/lib/api/comment.js index df5b233..21e7879 100644 --- a/lib/api/comment.js +++ b/lib/api/comment.js @@ -1,7 +1,7 @@ -const util = require("util"); +const util = require('util'); -module.exports = function (client) { - /*section: comment +module.exports = function(client) { + /* section: comment *comment: create a new comment *params: * message: the message of the comment @@ -23,31 +23,31 @@ module.exports = function (client) { * }); * ``` */ - function create(message, properties, callback) { - if (arguments.length < 3 && typeof arguments[1] === "function") { - callback = properties; - properties = {}; - } - - const params = { - body: { - message: message - } - }; + function create(message, properties, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = properties; + properties = {}; + } - if (typeof properties === "object") { - if (properties.handle) { - params.body.handle = properties.handle; - } - if (properties.related_event_id) { - params.body.related_event_id = properties.related_event_id; - } - } + const params = { + body: { + message + } + }; - client.request("POST", "/comments", params, callback); + if (typeof properties === 'object') { + if (properties.handle) { + params.body.handle = properties.handle; + } + if (properties.related_event_id) { + params.body.related_event_id = properties.related_event_id; + } } - /*section: comment + client.request('POST', '/comments', params, callback); + } + + /* section: comment *comment: update an existing comment *params: * commentId: the id of the comment to update @@ -67,25 +67,25 @@ module.exports = function (client) { * }); * ``` */ - function update(commentId, message, handle, callback) { - if (arguments.length < 4 && typeof arguments[2] === "function") { - callback = handle; - handle = undefined; - } - - const params = { - body: { - message: message - } - }; - if (handle) { - params.body.handle = properties.handle; - } + function update(commentId, message, handle, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = handle; + handle = undefined; + } - client.request("PUT", util.format("/comments/%s", commentId), params, callback); + const params = { + body: { + message + } + }; + if (handle) { + params.body.handle = properties.handle; } - /*section: comment + client.request('PUT', util.format('/comments/%s', commentId), params, callback); + } + + /* section: comment *comment: remove a comment *params: * commentId: the id of the comment to remove @@ -103,56 +103,55 @@ module.exports = function (client) { * }); * ``` */ - function remove(commentId, callback) { - client.request("DELETE", util.format("/comments/%s", commentId), callback); - } + function remove(commentId, callback) { + client.request('DELETE', util.format('/comments/%s', commentId), callback); + } - - return { - create: create, - update: update, - remove: remove, - getUsage: function () { - return [ - " dogapi comment create <message> [--handle <handle>] [--event <event-id>]", - " dogapi comment update <comment-id> <message> [--handle <handle>]", - " dogapi comment remove <comment-id>" - ]; - }, - getHelp: function () { - return [ - "Comment:", - " Subcommands:", - " create <message> add a new comment", - " update <comment-id> <message> update an existing comment", - " remove <comment-id> delete a comment", - "", - " Options:", - " --handle <handle> the handle to associate with the comment (e.g. \"user@domain.com\")", - " --event <event-id> related event id to associate the comment with" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "create") { - const message = args._[4]; - const properties = {}; - if (args["handle"]) { - properties.handle = args["handle"]; - } - if (args["event"]) { - properties.related_event_id = parseInt(args["event"]); - } - create(message, properties, callback); - } else if (subcommand === "update") { - const commentId = args._[4]; - const message = args._[5]; - update(commentId, message, args["handle"], callback); - } else if (subcommand === "remove") { - const commentId = args._[4]; - remove(commentId, callback); - } else { - callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); - } + return { + create, + update, + remove, + getUsage() { + return [ + ' dogapi comment create <message> [--handle <handle>] [--event <event-id>]', + ' dogapi comment update <comment-id> <message> [--handle <handle>]', + ' dogapi comment remove <comment-id>' + ]; + }, + getHelp() { + return [ + 'Comment:', + ' Subcommands:', + ' create <message> add a new comment', + ' update <comment-id> <message> update an existing comment', + ' remove <comment-id> delete a comment', + '', + ' Options:', + ' --handle <handle> the handle to associate with the comment (e.g. "user@domain.com")', + ' --event <event-id> related event id to associate the comment with' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'create') { + const message = args._[4]; + const properties = {}; + if (args.handle) { + properties.handle = args.handle; } - }; + if (args.event) { + properties.related_event_id = parseInt(args.event); + } + create(message, properties, callback); + } else if (subcommand === 'update') { + const commentId = args._[4]; + const message = args._[5]; + update(commentId, message, args.handle, callback); + } else if (subcommand === 'remove') { + const commentId = args._[4]; + remove(commentId, callback); + } else { + callback('unknown subcommand or arguments try `dogapi comment --help` for help', false); + } + } + }; }; diff --git a/lib/api/downtime.js b/lib/api/downtime.js index 05eb600..805f1d4 100644 --- a/lib/api/downtime.js +++ b/lib/api/downtime.js @@ -1,7 +1,7 @@ -const util = require("util"); +const util = require('util'); -module.exports = function (client) { - /*section: downtime +module.exports = function(client) { + /* section: downtime *comment: schedule a new downtime *params: * scope: string scope that the downtime should apply to (e.g. "env:staging") @@ -24,32 +24,32 @@ module.exports = function (client) { * }); * ``` */ - function create(scope, properties, callback) { - if (arguments.length < 3 && typeof arguments[1] === "function") { - callback = properties; - properties = {}; - } + function create(scope, properties, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = properties; + properties = {}; + } - const params = { - body: { - scope: scope - } - }; - if (typeof properties === "object") { - if (properties.start) { - params.body.start = parseInt(properties.start); - } - if (properties.end) { - params.body.end = parseInt(properties.end); - } - if (properties.message) { - params.body.message = properties.message; - } - } - client.request("POST", "/downtime", params, callback); + const params = { + body: { + scope + } + }; + if (typeof properties === 'object') { + if (properties.start) { + params.body.start = parseInt(properties.start); + } + if (properties.end) { + params.body.end = parseInt(properties.end); + } + if (properties.message) { + params.body.message = properties.message; + } } + client.request('POST', '/downtime', params, callback); + } - /*section: downtime + /* section: downtime *comment: update an existing downtime *params: * downtimeId: the id the downtie to update @@ -76,32 +76,32 @@ module.exports = function (client) { * }); * ``` */ - function update(downtimeId, properties, callback) { - if (arguments.length < 3 && typeof arguments[1] === "function") { - callback = properties; - properties = {}; - } - const params = { - body: {} - }; - if (typeof properties === "object") { - if (properties.scope) { - params.body.scope = properties.scope; - } - if (properties.start) { - params.body.start = parseInt(properties.start); - } - if (properties.end) { - params.body.end = parseInt(properties.end); - } - if (properties.message) { - params.body.message = properties.message; - } - } - client.request("PUT", util.format("/downtime/%s", downtimeId), params, callback); + function update(downtimeId, properties, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = properties; + properties = {}; + } + const params = { + body: {} + }; + if (typeof properties === 'object') { + if (properties.scope) { + params.body.scope = properties.scope; + } + if (properties.start) { + params.body.start = parseInt(properties.start); + } + if (properties.end) { + params.body.end = parseInt(properties.end); + } + if (properties.message) { + params.body.message = properties.message; + } } + client.request('PUT', util.format('/downtime/%s', downtimeId), params, callback); + } - /*section: downtime + /* section: downtime *comment: delete a scheduled downtime *params: * downtimeId: the id of the downtime @@ -119,11 +119,11 @@ module.exports = function (client) { * }); * ``` */ - function remove(downtimeId, callback) { - client.request("DELETE", util.format("/downtime/%s", downtimeId), callback); - } + function remove(downtimeId, callback) { + client.request('DELETE', util.format('/downtime/%s', downtimeId), callback); + } - /*section: downtime + /* section: downtime *comment: get a scheduled downtimes details *params: * downtimeId: the id of the downtime @@ -141,11 +141,11 @@ module.exports = function (client) { * }); * ``` */ - function get(downtimeId, callback) { - client.request("GET", util.format("/downtime/%s", downtimeId), callback); - } + function get(downtimeId, callback) { + client.request('GET', util.format('/downtime/%s', downtimeId), callback); + } - /*section: downtime + /* section: downtime *comment: get all downtimes details *params: * callback: function(err, res) @@ -162,82 +162,81 @@ module.exports = function (client) { * }); * ``` */ - function getAll(callback) { - client.request("GET", "/downtime", callback); - } - + function getAll(callback) { + client.request('GET', '/downtime', callback); + } - return { - create: create, - update: update, - remove: remove, - get: get, - getAll: getAll, - getUsage: function () { - return [ - " dogapi downtime create <scope> [--start <start>] [--end <end>] [--message <message>]", - " dogapi downtime update <downtime-id> [--scope <scope>] [--start <start>] [--end <end>] [--message <message>]", - " dogapi downtime remove <downtime-id>", - " dogapi downtime get <downtime-id>", - " dogapi downtime getall", - ]; - }, - getHelp: function () { - return [ - "Downtime:", - " Subcommands:", - " create <scope> create a new downtime with the provided scope (e.g. \"env:staging\")", - " update <downtime-id> update an existing downtime with the provided id", - " remove <downtime-id> remove the downtime with the provided id", - " get <downtime-id> get the details of the downtime with the provided id", - " getall get the details of all downtimes", - "", - " Options:", - " --start <start> POSIX timestamp for when the downtime should start", - " --end <end> POSIX timestamp for when the downtime should end", - " --message <message> a string message to accompany the downtime", - " --scope <scope> the scope of the downtime (e.g. \"env:staging\")" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "get") { - get(args._[4], callback); - } else if (subcommand === "getall") { - getAll(callback); - } else if (subcommand === "remove") { - remove(args._[4], callback); - } else if (subcommand === "create") { - const scope = args._[4]; - const properties = {}; - if (args["start"]) { - properties.start = parseInt(args["start"]); - } - if (args["end"]) { - properties.end = parseInt(args["end"]); - } - if (args["message"]) { - properties.message = args["message"]; - } - create(scope, properties, callback); - } else if (subcommand === "update") { - const downtimeId = args._[4]; - const properties = {}; - if (args["scope"]) { - properties.scope = args["scope"]; - } - if (args["start"]) { - properties.start = parseInt(args["start"]); - } - if (args["end"]) { - properties.end = parseInt(args["end"]); - } - if (args["message"]) { - properties.message = args["message"]; - } - update(downtimeId, properties, callback); - } else { - callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false); - } + return { + create, + update, + remove, + get, + getAll, + getUsage() { + return [ + ' dogapi downtime create <scope> [--start <start>] [--end <end>] [--message <message>]', + ' dogapi downtime update <downtime-id> [--scope <scope>] [--start <start>] [--end <end>] [--message <message>]', + ' dogapi downtime remove <downtime-id>', + ' dogapi downtime get <downtime-id>', + ' dogapi downtime getall' + ]; + }, + getHelp() { + return [ + 'Downtime:', + ' Subcommands:', + ' create <scope> create a new downtime with the provided scope (e.g. "env:staging")', + ' update <downtime-id> update an existing downtime with the provided id', + ' remove <downtime-id> remove the downtime with the provided id', + ' get <downtime-id> get the details of the downtime with the provided id', + ' getall get the details of all downtimes', + '', + ' Options:', + ' --start <start> POSIX timestamp for when the downtime should start', + ' --end <end> POSIX timestamp for when the downtime should end', + ' --message <message> a string message to accompany the downtime', + ' --scope <scope> the scope of the downtime (e.g. "env:staging")' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'get') { + get(args._[4], callback); + } else if (subcommand === 'getall') { + getAll(callback); + } else if (subcommand === 'remove') { + remove(args._[4], callback); + } else if (subcommand === 'create') { + const scope = args._[4]; + const properties = {}; + if (args.start) { + properties.start = parseInt(args.start); } - }; + if (args.end) { + properties.end = parseInt(args.end); + } + if (args.message) { + properties.message = args.message; + } + create(scope, properties, callback); + } else if (subcommand === 'update') { + const downtimeId = args._[4]; + const properties = {}; + if (args.scope) { + properties.scope = args.scope; + } + if (args.start) { + properties.start = parseInt(args.start); + } + if (args.end) { + properties.end = parseInt(args.end); + } + if (args.message) { + properties.message = args.message; + } + update(downtimeId, properties, callback); + } else { + callback('unknown subcommand or arguments try `dogapi downtime --help` for help', false); + } + } + }; }; diff --git a/lib/api/embed.js b/lib/api/embed.js index 3921ed1..1252efd 100644 --- a/lib/api/embed.js +++ b/lib/api/embed.js @@ -1,10 +1,9 @@ -const extend = require("extend"); -const json = require("../json"); // TODO inline lib -const querystring = require("querystring"); +const querystring = require('querystring'); +const extend = require('extend'); +const json = require('../json'); // TODO inline lib -module.exports = function (client) { - - /*section: embed +module.exports = function(client) { + /* section: embed *comment: create an embed graph of a metric query *params: * graph_json: The request array to pass create in the embed @@ -45,28 +44,28 @@ module.exports = function (client) { * }); * ``` */ - function create(graphJSON, options, callback) { - if (callback === undefined && typeof options === "function") { - callback = options; - options = {}; - } - const body = { - graph_json: JSON.stringify(graphJSON) - }; - // Use `extend` to merge `options` into `body` - // DEV: `extend` will ignore any properties whose value is `undefined` - extend(body, options || {}); + function create(graphJSON, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = {}; + } + const body = { + graph_json: JSON.stringify(graphJSON) + }; + // Use `extend` to merge `options` into `body` + // DEV: `extend` will ignore any properties whose value is `undefined` + extend(body, options || {}); - // Create the request - const params = { - body: querystring.stringify(body), - contentType: "application/x-www-form-urlencoded" - }; + // Create the request + const params = { + body: querystring.stringify(body), + contentType: 'application/x-www-form-urlencoded' + }; - client.request("POST", "/graph/embed", params, callback); - } + client.request('POST', '/graph/embed', params, callback); + } - /*section: embed + /* section: embed *comment: delete an embed with a specific id *params: * embedId: the id of the embed to delete @@ -79,12 +78,11 @@ module.exports = function (client) { * }); * ``` */ - function revoke(embedId, callback) { - client.request("GET", "/graph/embed/" + embedId + "/revoke", callback); - } + function revoke(embedId, callback) { + client.request('GET', `/graph/embed/${embedId}/revoke`, callback); + } - - /*section: embed + /* section: embed *comment: get all embeds from datadog *params: * callback: function(err, res) @@ -95,11 +93,11 @@ module.exports = function (client) { * }); * ``` */ - function getAll(callback) { - client.request("GET", "/graph/embed", callback); - } + function getAll(callback) { + client.request('GET', '/graph/embed', callback); + } - /*section: embed + /* section: embed *comment: get a single embed *params: * embedId: the id of the embed to get @@ -112,61 +110,60 @@ module.exports = function (client) { * }); * ``` */ - function get(embedId, callback) { - client.request("GET", "/graph/embed/" + embedId, callback); - } - - return { - create: create, - revoke: revoke, - getAll: getAll, - get: get, - getUsage: function () { - return [ - " dogapi embed create <embed_json> [--timeframe <timeframe>] [--size <size>] [--legend <legend>] [--title <title>]", - " dogapi embed revoke <embed_id>", - " dogapi embed get <embed_id>", - " dogapi embed getall" - ]; - }, - getHelp: function () { - return [ - "Embed:", - " Subcommands:", - " create <embed_json> --timeframe <timeframe> --size <size> --legend <legend> --title <title> | create a new graph embed", - " revoke <embed_id> revoke/delete an embed", - " get <embed_id> gets a single embed object", - " getall gets all embed objects", - " Options:", - " --events <event-query> a query for event bands to add to the snapshot", - " --timeframe <timeframe> The timeframe for the embed (1_hour, 4_hours, 1_day, 2_days, and 1_week)", - " --size <size> The size of the embed to create (small, medium, large, xlarge)", - " --legend <legend> Whether or not to have a legend (yes, no)", - " --title <title> The title of the embed to create" + function get(embedId, callback) { + client.request('GET', `/graph/embed/${embedId}`, callback); + } - ]; - }, - handleCli: function (subcommand, args, callback) { - if (args._.length > 4 && subcommand === "create") { - const graph_json = json.parse(args._[4]); - const options = { - timeframe: args["timeframe"], - size: args["size"], - legend: args["legend"], - title: args["title"] - }; - create(graph_json, options, callback); - } else if (args._.length > 4 && subcommand === "revoke") { - const embedId = args._[4]; - revoke(embedId, callback); - } else if (args._.length > 4 && subcommand === "get") { - const embedId = args._[4]; - get(embedId, callback); - } else if (subcommand === "getall") { - getAll(callback); - } else { - callback("unknown subcommand or arguments try `dogapi embed --help` for help", false); - } - } - }; + return { + create, + revoke, + getAll, + get, + getUsage() { + return [ + ' dogapi embed create <embed_json> [--timeframe <timeframe>] [--size <size>] [--legend <legend>] [--title <title>]', + ' dogapi embed revoke <embed_id>', + ' dogapi embed get <embed_id>', + ' dogapi embed getall' + ]; + }, + getHelp() { + return [ + 'Embed:', + ' Subcommands:', + ' create <embed_json> --timeframe <timeframe> --size <size> --legend <legend> --title <title> | create a new graph embed', + ' revoke <embed_id> revoke/delete an embed', + ' get <embed_id> gets a single embed object', + ' getall gets all embed objects', + ' Options:', + ' --events <event-query> a query for event bands to add to the snapshot', + ' --timeframe <timeframe> The timeframe for the embed (1_hour, 4_hours, 1_day, 2_days, and 1_week)', + ' --size <size> The size of the embed to create (small, medium, large, xlarge)', + ' --legend <legend> Whether or not to have a legend (yes, no)', + ' --title <title> The title of the embed to create' + ]; + }, + handleCli(subcommand, args, callback) { + if (args._.length > 4 && subcommand === 'create') { + const graph_json = json.parse(args._[4]); + const options = { + timeframe: args.timeframe, + size: args.size, + legend: args.legend, + title: args.title + }; + create(graph_json, options, callback); + } else if (args._.length > 4 && subcommand === 'revoke') { + const embedId = args._[4]; + revoke(embedId, callback); + } else if (args._.length > 4 && subcommand === 'get') { + const embedId = args._[4]; + get(embedId, callback); + } else if (subcommand === 'getall') { + getAll(callback); + } else { + callback('unknown subcommand or arguments try `dogapi embed --help` for help', false); + } + } + }; }; diff --git a/lib/api/event.js b/lib/api/event.js index 3a31912..f92fb47 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -1,7 +1,7 @@ -const util = require("util"); +const util = require('util'); -module.exports = function (client) { - /*section: event +module.exports = function(client) { + /* section: event *comment: | * create a new event *params: @@ -42,25 +42,25 @@ module.exports = function (client) { * }); * ``` */ - function create(title, text, properties, callback) { - if (arguments.length < 4 && typeof arguments[2] === "function") { - callback = properties; - properties = {}; - } - if (typeof properties !== "object") { - properties = {}; - } + function create(title, text, properties, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = properties; + properties = {}; + } + if (typeof properties !== 'object') { + properties = {}; + } - properties.title = title; - properties.text = text; + properties.title = title; + properties.text = text; - const params = { - body: properties - }; - client.request("POST", "/events", params, callback); - } + const params = { + body: properties + }; + client.request('POST', '/events', params, callback); + } - /*section: event + /* section: event *comment: | * get event details from the provided event id *params: @@ -81,11 +81,11 @@ module.exports = function (client) { * }); * ``` */ - function get(eventId, callback) { - client.request("GET", util.format("/events/%s", eventId), callback); - } + function get(eventId, callback) { + client.request('GET', util.format('/events/%s', eventId), callback); + } - /*section: event + /* section: event *comment: | * query the event stream *params: @@ -117,94 +117,94 @@ module.exports = function (client) { * }); * ``` */ - function query(start, end, parameters, callback) { - if (arguments.length < 4 && typeof argument[2] === "function") { - callback = parameters; - parameters = {}; - } + function query(start, end, parameters, callback) { + if (arguments.length < 4 && typeof argument[2] === 'function') { + callback = parameters; + parameters = {}; + } - if (typeof parameters !== "object") { - parameters = {} - } - parameters.start = start; - parameters.end = end; + if (typeof parameters !== 'object') { + parameters = {}; + } + parameters.start = start; + parameters.end = end; - const params = { - query: parameters - }; + const params = { + query: parameters + }; - client.request("GET", "/events", params, callback); - } + client.request('GET', '/events', params, callback); + } - return { - create: create, - get: get, - query: query, - getUsage: function () { - return [ - " dogapi event get <event-id>", - " dogapi event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]", - " dogapi event create <title> <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]" - ]; - }, - getHelp: function () { - return [ - "Event:", - " Subcommands:", - " get <event-id> get the event with the provided <event-id>", - " query <from> <to> query the event stream between <from> and <to> POSIX timestamps", - " create <title> <text> create a new event with <title> and <text>", - " Options:", - " --priority <priority> the priority of the event \"normal\" or \"low\"", - " --sources <sources> a comma separated list of sources (e.g. \"users,jenkins,chef\")", - " --tags <tags> a comma separated list of \"tag:value\"'s", - " --time <time> a POSIX timestamp for when the event happened", - " --host <host> the host to associate the event to", - " --type <type> the event type \"error\", \"warning\", \"info\" or \"success\"", - " --agg-key <agg-key> an aggregation key to use to associate like events", - " --source <source> the source to associate with this event (e.g. \"users\", \"jenkins\", etc)" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "get" && args._.length > 4) { - get(parseInt(args._[4]), callback); - } else if (subcommand === "query" && args._.length > 5) { - const from = parseInt(args._[4]); - const to = parseInt(args._[5]); - const parameters = {}; - if (args["sources"]) { - parameters.sources = args["sources"]; - } - if (args["tags"]) { - parameters.tags = args["tags"]; - } - query(from, to, parameters, callback); - } else if (subcommand === "create" && args._.length > 5) { - const title = args._[4]; - const text = args._[5]; - const properties = {}; - if (args["priority"]) { - properties.priority = args["priority"]; - } - if (args["host"]) { - properties.host = args["host"]; - } - if (args["time"]) { - properties.date_happened = parseInt(args["time"]); - } - if (args["tags"]) { - properties.tags = args["tags"].split(","); - } - if (args["agg-key"]) { - properties.aggregation_key = args["agg-key"]; - } - if (args["source"]) { - properties.source_type_name = args["source"]; - } - create(title, text, properties, callback); - } else { - callback("unknown subcommand or arguments try `dogapi event --help` for help", false); - } + return { + create, + get, + query, + getUsage() { + return [ + ' dogapi event get <event-id>', + ' dogapi event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]', + ' dogapi event create <title> <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]' + ]; + }, + getHelp() { + return [ + 'Event:', + ' Subcommands:', + ' get <event-id> get the event with the provided <event-id>', + ' query <from> <to> query the event stream between <from> and <to> POSIX timestamps', + ' create <title> <text> create a new event with <title> and <text>', + ' Options:', + ' --priority <priority> the priority of the event "normal" or "low"', + ' --sources <sources> a comma separated list of sources (e.g. "users,jenkins,chef")', + ' --tags <tags> a comma separated list of "tag:value"\'s', + ' --time <time> a POSIX timestamp for when the event happened', + ' --host <host> the host to associate the event to', + ' --type <type> the event type "error", "warning", "info" or "success"', + ' --agg-key <agg-key> an aggregation key to use to associate like events', + ' --source <source> the source to associate with this event (e.g. "users", "jenkins", etc)' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'get' && args._.length > 4) { + get(parseInt(args._[4]), callback); + } else if (subcommand === 'query' && args._.length > 5) { + const from = parseInt(args._[4]); + const to = parseInt(args._[5]); + const parameters = {}; + if (args.sources) { + parameters.sources = args.sources; } - }; + if (args.tags) { + parameters.tags = args.tags; + } + query(from, to, parameters, callback); + } else if (subcommand === 'create' && args._.length > 5) { + const title = args._[4]; + const text = args._[5]; + const properties = {}; + if (args.priority) { + properties.priority = args.priority; + } + if (args.host) { + properties.host = args.host; + } + if (args.time) { + properties.date_happened = parseInt(args.time); + } + if (args.tags) { + properties.tags = args.tags.split(','); + } + if (args['agg-key']) { + properties.aggregation_key = args['agg-key']; + } + if (args.source) { + properties.source_type_name = args.source; + } + create(title, text, properties, callback); + } else { + callback('unknown subcommand or arguments try `dogapi event --help` for help', false); + } + } + }; }; diff --git a/lib/api/graph.js b/lib/api/graph.js index fd2906e..2390f47 100644 --- a/lib/api/graph.js +++ b/lib/api/graph.js @@ -1,9 +1,9 @@ -const Embed = require("./embed"); +const Embed = require('./embed'); -module.exports = function (client) { - const embed = Embed(client); +module.exports = function(client) { + const embed = Embed(client); - /*section: graph + /* section: graph *comment: take a snapshot of a metric query *params: * query: the metric query to use for the snapshot @@ -27,52 +27,50 @@ module.exports = function (client) { * }); * ``` */ - function snapshot(query, from, to, eventQuery, callback) { - if (arguments.length < 5 && typeof arguments[3] === "function") { - callback = eventQuery; - eventQuery = undefined; - } - const params = { - query: { - metric_query: query, - start: parseInt(from), - end: parseInt(to) - } - }; - if (eventQuery) { - params.query.event_query = eventQuery; - } - - client.request("GET", "/graph/snapshot", params, callback); + function snapshot(query, from, to, eventQuery, callback) { + if (arguments.length < 5 && typeof arguments[3] === 'function') { + callback = eventQuery; + eventQuery = undefined; } - - return { - snapshot: snapshot, - createEmbed: embed.create, - getUsage: function () { - return [ - " dogapi graph snapshot <query> <from> <to> [--events <event-query>]" - ]; - }, - getHelp: function () { - return [ - "Graph:", - " Subcommands:", - " snapshot <query> <from> <to> --events <event-query> | take a snapshot of a graph", - " Options:", - " --events <event-query> a query for event bands to add to the snapshot" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (args._.length > 5 && subcommand === "snapshot") { - const query = args._[4]; - const from = parseInt(args._[5]); - const to = parseInt(args._[6]); - const eventQuery = args["events"]; - snapshot(query, from, to, eventQuery, callback); - } else { - callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); - } - } + const params = { + query: { + metric_query: query, + start: parseInt(from), + end: parseInt(to) + } }; + if (eventQuery) { + params.query.event_query = eventQuery; + } + + client.request('GET', '/graph/snapshot', params, callback); + } + + return { + snapshot, + createEmbed: embed.create, + getUsage() { + return [' dogapi graph snapshot <query> <from> <to> [--events <event-query>]']; + }, + getHelp() { + return [ + 'Graph:', + ' Subcommands:', + ' snapshot <query> <from> <to> --events <event-query> | take a snapshot of a graph', + ' Options:', + ' --events <event-query> a query for event bands to add to the snapshot' + ]; + }, + handleCli(subcommand, args, callback) { + if (args._.length > 5 && subcommand === 'snapshot') { + const query = args._[4]; + const from = parseInt(args._[5]); + const to = parseInt(args._[6]); + const eventQuery = args.events; + snapshot(query, from, to, eventQuery, callback); + } else { + callback('unknown subcommand or arguments try `dogapi graph --help` for help', false); + } + } + }; }; diff --git a/lib/api/host.js b/lib/api/host.js index d6a597d..3b639e7 100644 --- a/lib/api/host.js +++ b/lib/api/host.js @@ -1,7 +1,7 @@ -const util = require("util"); +const util = require('util'); -module.exports = function (client) { - /*section: host +module.exports = function(client) { + /* section: host *comment: mute the given host, if it is not already muted *params: * hostname: the hostname of the host to mute @@ -23,27 +23,27 @@ module.exports = function (client) { * }); * ``` */ - function mute(hostname, options, callback) { - if (arguments.length < 3 && typeof arguments[1] === "function") { - callback = options; - options = {}; - } - const params = {}; - if (typeof options === "object") { - params.body = {}; // create body property - if (options.end) { - params.body.end = parseInt(options.end); - } - if (options.override) { - params.body.override = options.override; - } - } else { - params.body = ""; // create empty body - } - client.request("POST", util.format("/host/%s/mute", hostname), params, callback); + function mute(hostname, options, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = options; + options = {}; + } + const params = {}; + if (typeof options === 'object') { + params.body = {}; // create body property + if (options.end) { + params.body.end = parseInt(options.end); + } + if (options.override) { + params.body.override = options.override; + } + } else { + params.body = ''; // create empty body } + client.request('POST', util.format('/host/%s/mute', hostname), params, callback); + } - /*section: host + /* section: host *comment: unmute the given host, if it is not already unmuted *params: * hostname: the hostname of the host to unmute @@ -61,49 +61,49 @@ module.exports = function (client) { * }); * ``` */ - function unmute(hostname, callback) { - const params = { body: "" }; // create empty body - client.request("POST", util.format("/host/%s/unmute", hostname), params, callback); - } + function unmute(hostname, callback) { + const params = {body: ''}; // create empty body + client.request('POST', util.format('/host/%s/unmute', hostname), params, callback); + } - return { - mute: mute, - unmute: unmute, - getUsage: function () { - return [ - " dogapi host mute <host> [--end <end>] [--override]", - " dogapi host unmute <host>" - ]; - }, - getHelp: function () { - return [ - "Host:", - " Subcommands:", - " mute <host> mute the host with the provided hostname", - " unmute <host> unmute the host with the provided hostname", - "", - " Options:", - " --end <end> POSIX timestamp for when the mute should end", - " --override override an existing \"end\" for a mute on a host" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "mute") { - const hostname = args._[4]; - const options = {}; - if (args["end"]) { - options.end = parseInt(args["end"]); - } - if (args["override"]) { - options.override = args["override"]; - } - mute(hostname, options, callback); - } else if (subcommand === "unmute") { - const hostname = args._[4]; - unmute(hostname, callback); - } else { - callback("unknown subcommand or arguments try `dogapi host --help` for help", false); - } + return { + mute, + unmute, + getUsage() { + return [ + ' dogapi host mute <host> [--end <end>] [--override]', + ' dogapi host unmute <host>' + ]; + }, + getHelp() { + return [ + 'Host:', + ' Subcommands:', + ' mute <host> mute the host with the provided hostname', + ' unmute <host> unmute the host with the provided hostname', + '', + ' Options:', + ' --end <end> POSIX timestamp for when the mute should end', + ' --override override an existing "end" for a mute on a host' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'mute') { + const hostname = args._[4]; + const options = {}; + if (args.end) { + options.end = parseInt(args.end); + } + if (args.override) { + options.override = args.override; } - }; + mute(hostname, options, callback); + } else if (subcommand === 'unmute') { + const hostname = args._[4]; + unmute(hostname, callback); + } else { + callback('unknown subcommand or arguments try `dogapi host --help` for help', false); + } + } + }; }; diff --git a/lib/api/index.js b/lib/api/index.js index cc81266..5d9b0f1 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -1,17 +1,17 @@ module.exports = { - comment: require("./comment"), - downtime: require("./downtime"), - embed: require("./embed"), - event: require("./event"), - graph: require("./graph"), - host: require("./host"), - infrastructure: require("./infrastructure"), - metric: require("./metric"), - monitor: require("./monitor"), - screenboard: require("./screenboard"), - search: require("./search"), - serviceCheck: require("./serviceCheck"), - tag: require("./tag"), - timeboard: require("./timeboard"), - user: require("./user"), + comment: require('./comment'), + downtime: require('./downtime'), + embed: require('./embed'), + event: require('./event'), + graph: require('./graph'), + host: require('./host'), + infrastructure: require('./infrastructure'), + metric: require('./metric'), + monitor: require('./monitor'), + screenboard: require('./screenboard'), + search: require('./search'), + serviceCheck: require('./serviceCheck'), + tag: require('./tag'), + timeboard: require('./timeboard'), + user: require('./user') }; diff --git a/lib/api/infrastructure.js b/lib/api/infrastructure.js index 25caa6b..89ad706 100644 --- a/lib/api/infrastructure.js +++ b/lib/api/infrastructure.js @@ -1,6 +1,5 @@ -module.exports = function (client) { - - /*section: infrastructure +module.exports = function(client) { + /* section: infrastructure *comment: | * search for metrics or hosts *params: @@ -21,32 +20,30 @@ module.exports = function (client) { * }); * ``` */ - function search(query, callback) { - const params = { - query: { - q: query - } - }; + function search(query, callback) { + const params = { + query: { + q: query + } + }; - client.request("GET", "/search", params, callback); + client.request('GET', '/search', params, callback); + } + return { + search, + getUsage() { + return [' dogapi infrastructure search <query>']; + }, + getHelp() { + return [ + 'Infrastructure:', + ' Subcommands:', + ' search <query> query for hosts or metrics with <query> (see http://docs.datadoghq.com/api/#search)' + ]; + }, + handleCli(subcommand, args, callback) { + const query = args._[4]; + search(query, callback); } - return { - search: search, - getUsage: function () { - return [ - " dogapi infrastructure search <query>" - ] - }, - getHelp: function () { - return [ - "Infrastructure:", - " Subcommands:", - " search <query> query for hosts or metrics with <query> (see http://docs.datadoghq.com/api/#search)", - ]; - }, - handleCli: function (subcommand, args, callback) { - const query = args._[4]; - search(query, callback); - } - }; + }; }; diff --git a/lib/api/metric.js b/lib/api/metric.js index c8150f5..7c47c9f 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -1,6 +1,5 @@ -module.exports = function (client) { - - /*section: metric +module.exports = function(client) { + /* section: metric *comment: | * submit a new metric *params: @@ -38,27 +37,27 @@ module.exports = function (client) { * }); * ``` */ - function send(metric, points, extra, callback) { - if (arguments.length < 4 && typeof arguments[2] === "function") { - callback = extra; - extra = {}; - } - extra = extra || {}; - const series = [ - { - metric: metric, - points: points, - host: extra.host, - tags: extra.tags, - // DEV: For backwards compatibility, allow `metric_type` - type: extra.type || extra.metric_type - } - ]; - - send_all(series, callback); + function send(metric, points, extra, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = extra; + extra = {}; } + extra = extra || {}; + const series = [ + { + metric, + points, + host: extra.host, + tags: extra.tags, + // DEV: For backwards compatibility, allow `metric_type` + type: extra.type || extra.metric_type + } + ]; + + send_all(series, callback); + } - /*section: metric + /* section: metric *comment: | * send a list of metrics *params: @@ -100,48 +99,48 @@ module.exports = function (client) { * }); * ``` */ - function send_all(metrics, callback) { - const now = parseInt(new Date().getTime() / 1000); - for (let i = 0; i < metrics.length; ++i) { - // Try to normalize `points` - // DEV: We need `points` to be an array of arrays regardless of what they give us - // Always wrap points in an array, this way we will get: - // 500 => [500] - // [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]] - // [[<timestamp>, 500]] => [[<timestamp>, 500]] - let points = metrics[i].points; - if (!Array.isArray(metrics[i].points)) { - points = [points]; - } - points = points.map(function (point) { - // Make sure each point is an array, if not make array with current timestamp - // 500 => [<timestamp>, 500] - // [<timestamp>, 500] => unchanged - if (!Array.isArray(point)) { - const now = parseInt(new Date().getTime() / 1000); - point = [now, point]; - } - return point; - }); - - metrics[i].points = points; - - // DEV: Change `metric_type` to `type` for backwards compatibility - metrics[i].type = metrics[i].type || metrics[i].metric_type; - // Remove `metric_type` if it was set - // DEV: This will not cause an error if `metric_type` does not exist - delete metrics[i].metric_type; + function send_all(metrics, callback) { + const now = parseInt(new Date().getTime() / 1000); + for (let i = 0; i < metrics.length; ++i) { + // Try to normalize `points` + // DEV: We need `points` to be an array of arrays regardless of what they give us + // Always wrap points in an array, this way we will get: + // 500 => [500] + // [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]] + // [[<timestamp>, 500]] => [[<timestamp>, 500]] + let points = metrics[i].points; + if (!Array.isArray(metrics[i].points)) { + points = [points]; + } + points = points.map(function(point) { + // Make sure each point is an array, if not make array with current timestamp + // 500 => [<timestamp>, 500] + // [<timestamp>, 500] => unchanged + if (!Array.isArray(point)) { + const now = parseInt(new Date().getTime() / 1000); + point = [now, point]; } + return point; + }); + + metrics[i].points = points; - const params = { - body: { - series: metrics - } - }; - client.request("POST", "/series", params, callback); + // DEV: Change `metric_type` to `type` for backwards compatibility + metrics[i].type = metrics[i].type || metrics[i].metric_type; + // Remove `metric_type` if it was set + // DEV: This will not cause an error if `metric_type` does not exist + delete metrics[i].metric_type; } - /*section: metric + const params = { + body: { + series: metrics + } + }; + client.request('POST', '/series', params, callback); + } + + /* section: metric *comment: | * make a metric query *params: @@ -165,57 +164,57 @@ module.exports = function (client) { * }); * ``` */ - function query(from, to, query, callback) { - const params = { - query: { - from: from, - to: to, - query: query - } - }; - client.request("GET", "/query", params, callback); - } + function query(from, to, query, callback) { + const params = { + query: { + from, + to, + query + } + }; + client.request('GET', '/query', params, callback); + } - return { - send: send, - send_all: send_all, - query: query, - getUsage: function () { - return [ - " dogapi metric send <metric> <point> [--tags <tags>] [--host <host>] [--type <type>]", - " dogapi metric query <from> <to> <query>" - ] - }, - getHelp: function () { - return [ - "Metric:", - " Subcommands:", - " send <metric> <point> add a new datapoint for <metric> for right now", - " query <from> <to> <query> query for <query> between <from> and <to> POSIX timestamps", - "", - " Options:", - " --tags <tags> a comma separated list of \"tag:value\"'s", - " --host <host> the hostname that should be associated with this metric", - " --type <type> the type of metric \"gauge\" or \"count\"" - ] - }, - handleCli: function (subcommand, args, callback) { - if (args._.length > 5 && subcommand === "send") { - const extra = {}; - if (args.tags) { - extra.tags = args.tags.split(","); - } - extra.host = args.host; - extra.type = args.type; - send(args._[4], args._[5], extra, callback); - } else if (subcommand === "query" && args._.length > 6) { - const from = parseInt(args._[4]); - const to = parseInt(args._[5]); - const q = args._[6]; - query(from, to, q, callback); - } else { - callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); - } + return { + send, + send_all, + query, + getUsage() { + return [ + ' dogapi metric send <metric> <point> [--tags <tags>] [--host <host>] [--type <type>]', + ' dogapi metric query <from> <to> <query>' + ]; + }, + getHelp() { + return [ + 'Metric:', + ' Subcommands:', + ' send <metric> <point> add a new datapoint for <metric> for right now', + ' query <from> <to> <query> query for <query> between <from> and <to> POSIX timestamps', + '', + ' Options:', + ' --tags <tags> a comma separated list of "tag:value"\'s', + ' --host <host> the hostname that should be associated with this metric', + ' --type <type> the type of metric "gauge" or "count"' + ]; + }, + handleCli(subcommand, args, callback) { + if (args._.length > 5 && subcommand === 'send') { + const extra = {}; + if (args.tags) { + extra.tags = args.tags.split(','); } - }; + extra.host = args.host; + extra.type = args.type; + send(args._[4], args._[5], extra, callback); + } else if (subcommand === 'query' && args._.length > 6) { + const from = parseInt(args._[4]); + const to = parseInt(args._[5]); + const q = args._[6]; + query(from, to, q, callback); + } else { + callback('unknown subcommand or arguments try `dogapi metric --help` for help', false); + } + } + }; }; diff --git a/lib/api/monitor.js b/lib/api/monitor.js index 9f36def..7d31351 100644 --- a/lib/api/monitor.js +++ b/lib/api/monitor.js @@ -1,8 +1,7 @@ -const util = require("util"); +const util = require('util'); -module.exports = function(client){ - - /*section: monitor +module.exports = function(client) { + /* section: monitor *comment: create a new monitor *params: * type: one of "metric alert" or "service check" @@ -29,37 +28,37 @@ module.exports = function(client){ * }); * ``` */ - function create(type, query, properties, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = properties; - properties = {}; - } - - const params = { - body: { - type: type, - query: query - } - }; - - if(typeof properties === "object"){ - if(properties.name){ - params.body.name = properties.name; - } - if(properties.message){ - params.body.message = properties.message; - } - if(properties.tags){ - params.body.tags = properties.tags; - } - if(typeof properties.options === "object"){ - params.body.options = properties.options; - } - } - client.request("POST", "/monitor", params, callback); + function create(type, query, properties, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = properties; + properties = {}; + } + + const params = { + body: { + type, + query + } + }; + + if (typeof properties === 'object') { + if (properties.name) { + params.body.name = properties.name; + } + if (properties.message) { + params.body.message = properties.message; + } + if (properties.tags) { + params.body.tags = properties.tags; + } + if (typeof properties.options === 'object') { + params.body.options = properties.options; + } } - - /*section: monitor + client.request('POST', '/monitor', params, callback); + } + + /* section: monitor *comment: get an existing monitor's details *params: * monitorId: the id of the monitor @@ -78,23 +77,23 @@ module.exports = function(client){ * }); * ``` */ - function get(monitorId, groupStates, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = groupStates; - groupStates = undefined; - } - - const params = {}; - if(groupStates){ - params.query = { - group_states: groupStates.join(",") - }; - } - - client.request("GET", util.format("/monitor/%s", monitorId), params, callback); + function get(monitorId, groupStates, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = groupStates; + groupStates = undefined; } - - /*section: monitor + + const params = {}; + if (groupStates) { + params.query = { + group_states: groupStates.join(',') + }; + } + + client.request('GET', util.format('/monitor/%s', monitorId), params, callback); + } + + /* section: monitor *comment: get all monitors *params: * options: | @@ -116,28 +115,28 @@ module.exports = function(client){ * }); * ``` */ - function getAll(options, callback){ - if(arguments.length < 2 && typeof arguments[0] === "function"){ - callback = options; - options = {}; - } - const params = {}; - if(typeof options === "object"){ - params.query = {}; - if(options.group_states){ - params.query.group_states = options.group_states.join(","); - } - if(options.tags){ - params.query.tags = options.tags.join(","); - } - if(options.monitor_tags){ - params.query.monitor_tags = options.monitor_tags.join(","); - } - } - client.request("GET", "/monitor", params, callback); + function getAll(options, callback) { + if (arguments.length < 2 && typeof arguments[0] === 'function') { + callback = options; + options = {}; + } + const params = {}; + if (typeof options === 'object') { + params.query = {}; + if (options.group_states) { + params.query.group_states = options.group_states.join(','); + } + if (options.tags) { + params.query.tags = options.tags.join(','); + } + if (options.monitor_tags) { + params.query.monitor_tags = options.monitor_tags.join(','); + } } - - /*section: monitor + client.request('GET', '/monitor', params, callback); + } + + /* section: monitor *comment: update a monitor's details *params: * monitorId: the id of the monitor to edit @@ -163,36 +162,36 @@ module.exports = function(client){ * }); * ``` */ - function update(monitorId, query, properties, callback){ - if(arguments.length < 4 && typeof arguments[2] === "function"){ - callback = properties; - properties = {}; - } - - const params = { - body: { - query: query - } - }; - - if(typeof properties === "object"){ - if(properties.name){ - params.body.name = properties.name; - } - if(properties.message){ - params.body.message = properties.message; - } - if(properties.tags){ - params.body.tags = properties.tags; - } - if(typeof properties.options === "object"){ - params.body.options = properties.options; - } - } - client.request("PUT", util.format("/monitor/%s", monitorId), params, callback); + function update(monitorId, query, properties, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = properties; + properties = {}; } - - /*section: monitor + + const params = { + body: { + query + } + }; + + if (typeof properties === 'object') { + if (properties.name) { + params.body.name = properties.name; + } + if (properties.message) { + params.body.message = properties.message; + } + if (properties.tags) { + params.body.tags = properties.tags; + } + if (typeof properties.options === 'object') { + params.body.options = properties.options; + } + } + client.request('PUT', util.format('/monitor/%s', monitorId), params, callback); + } + + /* section: monitor *comment: delete an existing monitor *params: * monitorId: the id of the monitor to remove @@ -210,11 +209,11 @@ module.exports = function(client){ * }); * ``` */ - function remove(monitorId, callback){ - client.request("DELETE", util.format("/monitor/%s", monitorId), callback); - } - - /*section: monitor + function remove(monitorId, callback) { + client.request('DELETE', util.format('/monitor/%s', monitorId), callback); + } + + /* section: monitor *comment: mute an existing monitor *params: * monitorId: the id of the monitor to mute @@ -236,27 +235,27 @@ module.exports = function(client){ * }); * ``` */ - function mute(monitorId, options, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = options; - options = {}; - } - const params = {}; - if(typeof options === "object"){ - params.body = {}; - if(options.scope){ - params.body.scope = options.scope; - } - if(options.end){ - params.body.end = parseInt(options.end); - } - } else { - params.body = ""; // create empty body - } - client.request("POST", util.format("/monitor/%s/mute", monitorId), params, callback); + function mute(monitorId, options, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = options; + options = {}; + } + const params = {}; + if (typeof options === 'object') { + params.body = {}; + if (options.scope) { + params.body.scope = options.scope; + } + if (options.end) { + params.body.end = parseInt(options.end); + } + } else { + params.body = ''; // create empty body } - - /*section: monitor + client.request('POST', util.format('/monitor/%s/mute', monitorId), params, callback); + } + + /* section: monitor *comment: mute all monitors *params: * callback: function(err, res) @@ -273,11 +272,11 @@ module.exports = function(client){ * }); * ``` */ - function muteAll(callback){ - client.request("POST", "/monitor/mute_all", callback); - } - - /*section: monitor + function muteAll(callback) { + client.request('POST', '/monitor/mute_all', callback); + } + + /* section: monitor *comment: unmute an existing monitor *params: * monitorId: the id of the monitor to unmute @@ -296,23 +295,23 @@ module.exports = function(client){ * }); * ``` */ - function unmute(monitorId, scope, callback){ - if(arguments.length < 3 && typeof arguments[1] === "function"){ - callback = scope; - scope = undefined; - } - const params = {}; - if(scope){ - params.body = { - scope: scope - }; - } else { - params.body = ""; // create empty body - } - client.request("POST", util.format("/monitor/%s/unmute", monitorId), params, callback); + function unmute(monitorId, scope, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = scope; + scope = undefined; + } + const params = {}; + if (scope) { + params.body = { + scope + }; + } else { + params.body = ''; // create empty body } - - /*section: monitor + client.request('POST', util.format('/monitor/%s/unmute', monitorId), params, callback); + } + + /* section: monitor *comment: unmute all monitors *params: * callback: function(err, res) @@ -329,128 +328,128 @@ module.exports = function(client){ * }); * ``` */ - function unmuteAll(callback){ - client.request("POST", "/monitor/unmute_all", callback); - } - - return { - create: create, - get: get, - update: update, - remove: remove, - getAll: getAll, - mute: mute, - muteAll: muteAll, - unmute: unmute, - unmuteAll: unmuteAll, - getUsage: function(){ - return [ - " dogapi monitor create <type> <query> [--name <name>] [--message <message>]", - " dogapi monitor get <monitor-id> [--states <states>]", - " dogapi monitor getall [--states <states>] [--tags <tags>]", - " dogapi monitor mute <monitor-id> [--scope <scope>] [--end <end>]", - " dogapi monitor muteall", - " dogapi monitor remove <monitor-id>", - " dogapi monitor unmute <monitor-id> [--scope <scope>]", - " dogapi monitor unmuteall", - " dogapi monitor update <monitor-id> <query> [--name <name>] [--message <message>]" - ]; - }, - getHelp: function(){ - return [ - "Monitor:", - " Subcommands:", - " create <type> <query> create a new monitor", - " get <monitor-id> get a monitors details", - " getall get a list of all monitors", - " mute <monitor-id> mute the monitor with the id <monitor-id>", - " muteall mute all monitors", - " remove <monitor-id> delete the monitor with the id <monitor-id>", - " unmute <monitor-id> unmute the monitor with the id <monitor-id>", - " unmuteall unmute all monitors", - " update <monitor-id> <query> update an existing monitor", - "", - " Options:", - " --states <states> a comma separated list containing any of \"all\", \"alert\", \"warn\", or \"no data\"", - " --tags <tags> a comma separated list of \"tag:value\"'s", - " --scope <scope> the scope of the monitor to mute (e.g. \"role:db\")", - " --end <end> POSIX timestamp for when the mute should end", - " --name <name> the name for the monitor", - " --message <message> the message for the monitor" - ]; - }, - handleCli: function(subcommand, args, callback){ - const states = []; - if(args["states"]){ - states = args["states"].split(","); - } - - const tags = []; - if(args["tags"]){ - tags = args["tags"].split(","); - } - - const name = args["name"]; - const message = args["message"]; - - if(subcommand === "get"){ - const monitorId = args._[4]; - get(monitorId, states, callback); - } else if(subcommand === "getall"){ - const options = {}; - if(states.length){ - options.group_states = states; - } - if(tags.length){ - options.tags = tags; - } - getAll(options, callback); - } else if(subcommand === "mute"){ - const monitorId = args._[4]; - const options = {}; - if(args["scope"]){ - options.scope = args["scope"]; - } - if(args["end"]){ - options.end = args["end"]; - } - mute(monitorId, options, callback); - } else if(subcommand === "unmute"){ - const monitorId = args._[4]; - const scope = args["scope"]; - unmute(monitorId, scope, callback); - } else if(subcommand === "unmuteall"){ - unmuteAll(callback); - } else if(subcommand === "muteall"){ - muteAll(callback); - } else if(subcommand === "remove"){ - const monitorId = args._[4]; - remove(monitorId, callback); - } else if(subcommand === "create" && args._.length > 5){ - const type = args._[4]; - const query = args._[5]; - const properties = {}; - if(name){ - properties.name = name; - } - if(message){ - properties.message = message; - } - create(type, query, properties, callback); - } else if(subcommand === "update" && args._.length > 5){ - const monitorId = args._[4]; - const query = args._[5]; - const properties = {}; - if(name){ - properties.name = name; - } - if(message){ - properties.message = message; - } - update(monitorId, query, properties, callback); - } else { - callback("unknown subcommand or arguments try `dogapi monitor --help` for help", false); - } + function unmuteAll(callback) { + client.request('POST', '/monitor/unmute_all', callback); + } + + return { + create, + get, + update, + remove, + getAll, + mute, + muteAll, + unmute, + unmuteAll, + getUsage() { + return [ + ' dogapi monitor create <type> <query> [--name <name>] [--message <message>]', + ' dogapi monitor get <monitor-id> [--states <states>]', + ' dogapi monitor getall [--states <states>] [--tags <tags>]', + ' dogapi monitor mute <monitor-id> [--scope <scope>] [--end <end>]', + ' dogapi monitor muteall', + ' dogapi monitor remove <monitor-id>', + ' dogapi monitor unmute <monitor-id> [--scope <scope>]', + ' dogapi monitor unmuteall', + ' dogapi monitor update <monitor-id> <query> [--name <name>] [--message <message>]' + ]; + }, + getHelp() { + return [ + 'Monitor:', + ' Subcommands:', + ' create <type> <query> create a new monitor', + ' get <monitor-id> get a monitors details', + ' getall get a list of all monitors', + ' mute <monitor-id> mute the monitor with the id <monitor-id>', + ' muteall mute all monitors', + ' remove <monitor-id> delete the monitor with the id <monitor-id>', + ' unmute <monitor-id> unmute the monitor with the id <monitor-id>', + ' unmuteall unmute all monitors', + ' update <monitor-id> <query> update an existing monitor', + '', + ' Options:', + ' --states <states> a comma separated list containing any of "all", "alert", "warn", or "no data"', + ' --tags <tags> a comma separated list of "tag:value"\'s', + ' --scope <scope> the scope of the monitor to mute (e.g. "role:db")', + ' --end <end> POSIX timestamp for when the mute should end', + ' --name <name> the name for the monitor', + ' --message <message> the message for the monitor' + ]; + }, + handleCli(subcommand, args, callback) { + const states = []; + if (args.states) { + states = args.states.split(','); + } + + const tags = []; + if (args.tags) { + tags = args.tags.split(','); + } + + const name = args.name; + const message = args.message; + + if (subcommand === 'get') { + const monitorId = args._[4]; + get(monitorId, states, callback); + } else if (subcommand === 'getall') { + const options = {}; + if (states.length) { + options.group_states = states; } - }; + if (tags.length) { + options.tags = tags; + } + getAll(options, callback); + } else if (subcommand === 'mute') { + const monitorId = args._[4]; + const options = {}; + if (args.scope) { + options.scope = args.scope; + } + if (args.end) { + options.end = args.end; + } + mute(monitorId, options, callback); + } else if (subcommand === 'unmute') { + const monitorId = args._[4]; + const scope = args.scope; + unmute(monitorId, scope, callback); + } else if (subcommand === 'unmuteall') { + unmuteAll(callback); + } else if (subcommand === 'muteall') { + muteAll(callback); + } else if (subcommand === 'remove') { + const monitorId = args._[4]; + remove(monitorId, callback); + } else if (subcommand === 'create' && args._.length > 5) { + const type = args._[4]; + const query = args._[5]; + const properties = {}; + if (name) { + properties.name = name; + } + if (message) { + properties.message = message; + } + create(type, query, properties, callback); + } else if (subcommand === 'update' && args._.length > 5) { + const monitorId = args._[4]; + const query = args._[5]; + const properties = {}; + if (name) { + properties.name = name; + } + if (message) { + properties.message = message; + } + update(monitorId, query, properties, callback); + } else { + callback('unknown subcommand or arguments try `dogapi monitor --help` for help', false); + } + } + }; }; diff --git a/lib/api/screenboard.js b/lib/api/screenboard.js index b4253b7..57de1ed 100644 --- a/lib/api/screenboard.js +++ b/lib/api/screenboard.js @@ -1,8 +1,8 @@ -const json = require("../json"); -const util = require("util"); +const util = require('util'); +const json = require('../json'); -module.exports = function (client) { - /*section: screenboard +module.exports = function(client) { + /* section: screenboard *comment: create a new screenboard *params: * boardTitle: the name of the screenboard @@ -56,42 +56,42 @@ module.exports = function (client) { * ); * ``` */ - function create(boardTitle, widgets, options, callback) { - if (arguments.length < 4 && typeof arguments[2] === "function") { - callback = options; - options = {}; - } - if (typeof options !== "object") { - options = {}; - } - - const params = { - body: { - board_title: boardTitle, - widgets: widgets - } - }; + function create(boardTitle, widgets, options, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = options; + options = {}; + } + if (typeof options !== 'object') { + options = {}; + } - if (options.description) { - params.body.description = options.description; - } - if (options.templateVariables) { - params.body.template_variables = options.templateVariables; - } - if (options.width) { - params.body.width = options.width; - } - if (options.height) { - params.body.height = options.height; - } - if (options.readOnly) { - params.body.read_only = options.readOnly; - } + const params = { + body: { + board_title: boardTitle, + widgets + } + }; - client.request("POST", "/screen", params, callback); + if (options.description) { + params.body.description = options.description; + } + if (options.templateVariables) { + params.body.template_variables = options.templateVariables; + } + if (options.width) { + params.body.width = options.width; + } + if (options.height) { + params.body.height = options.height; + } + if (options.readOnly) { + params.body.read_only = options.readOnly; } - /*section: screenboard + client.request('POST', '/screen', params, callback); + } + + /* section: screenboard *comment: update an existing screenboard *params: * boardId: the id of the screenboard to update @@ -139,42 +139,42 @@ module.exports = function (client) { * ); * ``` */ - function update(boardId, boardTitle, widgets, options, callback) { - if (arguments.length < 5 && typeof arguments[3] === "function") { - callback = options; - options = {}; - } - if (typeof options !== "object") { - options = {}; - } - - const params = { - body: { - board_title: boardTitle, - widgets: widgets - } - }; + function update(boardId, boardTitle, widgets, options, callback) { + if (arguments.length < 5 && typeof arguments[3] === 'function') { + callback = options; + options = {}; + } + if (typeof options !== 'object') { + options = {}; + } - if (options.description) { - params.body.description = options.description; - } - if (options.templateVariables) { - params.body.template_variables = options.templateVariables; - } - if (options.width) { - params.body.width = options.width; - } - if (options.height) { - params.body.height = options.height; - } - if (options.readOnly) { - params.body.read_only = options.readOnly; - } + const params = { + body: { + board_title: boardTitle, + widgets + } + }; - client.request("PUT", util.format("/screen/%s", boardId), params, callback); + if (options.description) { + params.body.description = options.description; + } + if (options.templateVariables) { + params.body.template_variables = options.templateVariables; + } + if (options.width) { + params.body.width = options.width; + } + if (options.height) { + params.body.height = options.height; } + if (options.readOnly) { + params.body.read_only = options.readOnly; + } + + client.request('PUT', util.format('/screen/%s', boardId), params, callback); + } - /*section: screenboard + /* section: screenboard *comment: delete an existing screenboard *params: * boardId: the id of the screenboard to delete @@ -192,11 +192,11 @@ module.exports = function (client) { * }); * ``` */ - function remove(boardId, callback) { - client.request("DELETE", util.format("/screen/%s", boardId), callback); - } + function remove(boardId, callback) { + client.request('DELETE', util.format('/screen/%s', boardId), callback); + } - /*section: screenboard + /* section: screenboard *comment: get the info of a single existing screenboard *params: * boardId: the id of the screenboard to fetch @@ -214,11 +214,11 @@ module.exports = function (client) { * }); * ``` */ - function get(boardId, callback) { - client.request("GET", util.format("/screen/%s", boardId), callback); - } + function get(boardId, callback) { + client.request('GET', util.format('/screen/%s', boardId), callback); + } - /*section: screenboard + /* section: screenboard *comment: get all existing screenboards *params: * callback: function(err, res) @@ -235,11 +235,11 @@ module.exports = function (client) { * }); * ``` */ - function getAll(callback) { - client.request("GET", "/screen", callback); - } + function getAll(callback) { + client.request('GET', '/screen', callback); + } - /*section: screenboard + /* section: screenboard *comment: share an existing screenboard *params: * boardId: the id of the screenboard to share @@ -257,95 +257,94 @@ module.exports = function (client) { * }); * ``` */ - function share(boardId, callback) { - client.request("POST", util.format("/screen/share/%s", boardId), callback); - } + function share(boardId, callback) { + client.request('POST', util.format('/screen/share/%s', boardId), callback); + } + return { + create, + remove, + update, + get, + getAll, + share, + getUsage() { + return [ + ' dogapi screenboard create <boardTitle> <widgets> [--description <description>] [--tmpvars <templateVariables>] [--width <width>] [--height <height>]', + ' dogapi screenboard remove <boardId>', + ' dogapi screenboard get <boardId>', + ' dogapi screenboard getall', + ' dogapi screenboard share <boardId>' + ]; + }, + getHelp() { + return [ + 'Screenboard:', + ' Subcommands:', + ' create <boardTitle> <widgets> create a new screenboard, <widgets> is a json of the graph definition', + ' update <boardId> <boardTitle> <widgets> update a screenboard', + ' remove <boardId> remove an existing screenboard', + ' get <boardId> get an existing screenboard', + ' getall get all screenboards', + ' share <boardId> get share info for an existing screenboard', + ' Options:', + " --description <description> a description of the screenboard's content", + ' --tmpvars <templateVariables> json representation of the template variable definition', + ' --width <width> width of the screenboard in pixels', + ' --height <height> height of the screenboard in pixels' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'get') { + get(args._[4], callback); + } else if (subcommand === 'getall') { + getAll(callback); + } else if (subcommand === 'remove') { + remove(args._[4], callback); + } else if (subcommand === 'share') { + share(args._[4], callback); + } else if (subcommand === 'update') { + const boardId = args._[4]; + const boardTitle = args._[5]; + const widgets = json.parse(args._[6]); - return { - create: create, - remove: remove, - update: update, - get: get, - getAll: getAll, - share: share, - getUsage: function () { - return [ - " dogapi screenboard create <boardTitle> <widgets> [--description <description>] [--tmpvars <templateVariables>] [--width <width>] [--height <height>]", - " dogapi screenboard remove <boardId>", - " dogapi screenboard get <boardId>", - " dogapi screenboard getall", - " dogapi screenboard share <boardId>" - ]; - }, - getHelp: function () { - return [ - "Screenboard:", - " Subcommands:", - " create <boardTitle> <widgets> create a new screenboard, <widgets> is a json of the graph definition", - " update <boardId> <boardTitle> <widgets> update a screenboard", - " remove <boardId> remove an existing screenboard", - " get <boardId> get an existing screenboard", - " getall get all screenboards", - " share <boardId> get share info for an existing screenboard", - " Options:", - " --description <description> a description of the screenboard's content", - " --tmpvars <templateVariables> json representation of the template variable definition", - " --width <width> width of the screenboard in pixels", - " --height <height> height of the screenboard in pixels", - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "get") { - get(args._[4], callback); - } else if (subcommand === "getall") { - getAll(callback); - } else if (subcommand === "remove") { - remove(args._[4], callback); - } else if (subcommand === "share") { - share(args._[4], callback); - } else if (subcommand === "update") { - const boardId = args._[4]; - const boardTitle = args._[5]; - const widgets = json.parse(args._[6]); - - const options = {}; - if (args["description"]) { - options.description = args["description"]; - } - if (args["tmpvars"]) { - options.templateVariables = json.parse(args["tmpvars"]); - } - if (args["width"]) { - options.width = parseInt(args["width"]); - } - if (args["height"]) { - options.height = parseInt(args["height"]); - } - - update(boardId, boardTitle, widgets, options, callback); - } else if (subcommand === "create") { - const boardTitle = args._[4]; - const widgets = json.parse(args._[5]); + const options = {}; + if (args.description) { + options.description = args.description; + } + if (args.tmpvars) { + options.templateVariables = json.parse(args.tmpvars); + } + if (args.width) { + options.width = parseInt(args.width); + } + if (args.height) { + options.height = parseInt(args.height); + } - const options = {}; - if (args["description"]) { - options.description = args["description"]; - } - if (args["tmpvars"]) { - options.templateVariables = json.parse(args["tmpvars"]); - } - if (args["width"]) { - options.width = parseInt(args["width"]); - } - if (args["height"]) { - options.height = parseInt(args["height"]); - } + update(boardId, boardTitle, widgets, options, callback); + } else if (subcommand === 'create') { + const boardTitle = args._[4]; + const widgets = json.parse(args._[5]); - create(boardTitle, widgets, options, callback); - } else { - callback("unknown subcommand or arguments try `dogapi screenboard --help` for help", false); - } + const options = {}; + if (args.description) { + options.description = args.description; } - }; + if (args.tmpvars) { + options.templateVariables = json.parse(args.tmpvars); + } + if (args.width) { + options.width = parseInt(args.width); + } + if (args.height) { + options.height = parseInt(args.height); + } + + create(boardTitle, widgets, options, callback); + } else { + callback('unknown subcommand or arguments try `dogapi screenboard --help` for help', false); + } + } + }; }; diff --git a/lib/api/search.js b/lib/api/search.js index 0c57b03..0500fed 100644 --- a/lib/api/search.js +++ b/lib/api/search.js @@ -1,5 +1,5 @@ -module.exports = function (client) { - /*section: search +module.exports = function(client) { + /* section: search *comment: | * search for metrics and hosts from the past 24 hours *params: @@ -19,35 +19,33 @@ module.exports = function (client) { * }); * ``` */ - function query(query, callback) { - const params = { - query: { - q: query - } - }; - client.request("GET", "/search", params, callback); - } - - return { - query: query, - getUsage: function () { - return [ - " dogapi search query <query>" - ]; - }, - getHelp: function () { - return [ - "Search:", - " Subcommands:", - " query <query> search for hosts and metrics from the last 24 hours" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "query" && args._.length > 4) { - query(args._[4], callback); - } else { - callback("unknown subcommand or arguments try `dogapi search --help` for help", false); - } - } + function query(query, callback) { + const params = { + query: { + q: query + } }; + client.request('GET', '/search', params, callback); + } + + return { + query, + getUsage() { + return [' dogapi search query <query>']; + }, + getHelp() { + return [ + 'Search:', + ' Subcommands:', + ' query <query> search for hosts and metrics from the last 24 hours' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'query' && args._.length > 4) { + query(args._[4], callback); + } else { + callback('unknown subcommand or arguments try `dogapi search --help` for help', false); + } + } + }; }; diff --git a/lib/api/serviceCheck.js b/lib/api/serviceCheck.js index b93d1f8..0d39c8d 100644 --- a/lib/api/serviceCheck.js +++ b/lib/api/serviceCheck.js @@ -1,6 +1,5 @@ -module.exports = function (client) { - - /*section: serviceCheck +module.exports = function(client) { + /* section: serviceCheck *comment: | * post an update to a service check *params: @@ -29,62 +28,60 @@ module.exports = function (client) { * }); * ``` */ - function check(check, hostName, status, parameters, callback) { - if (arguments.length < 5 && typeof arguments[3] === "function") { - callback = parameters; - parameters = {}; - } + function check(check, hostName, status, parameters, callback) { + if (arguments.length < 5 && typeof arguments[3] === 'function') { + callback = parameters; + parameters = {}; + } - if (typeof parameters !== "object") { - parameters = {}; - } + if (typeof parameters !== 'object') { + parameters = {}; + } - parameters.check = check; - parameters.host_name = hostName, - parameters.status = status; + parameters.check = check; + (parameters.host_name = hostName), (parameters.status = status); - const params = { - body: parameters - }; - client.request("POST", "/check_run", params, callback); + const params = { + body: parameters }; + client.request('POST', '/check_run', params, callback); + } - - return { - check: check, - getUsage: function () { - return [ - " dogapi servicecheck check <check> <host> <status> [--time <timestamp>] [--message <message>] [--tags <tags>]" - ]; - }, - getHelp: function () { - return [ - "Service Check:", - " Subcommands:", - " check <check> <host> <status> add a new service check for <check> and <host> at level <status> (0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN)", - "", - " Options:", - " --time <timestamp> the POSIX timestamp to use for the check", - " --message <message> an optional message to accompany the check", - " --tags <tags> a comma separated list of \"tag:value\"'s for the check" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (args._.length > 6) { - const parameters = {}; - if (args["time"]) { - parameters.time = parseInt(args["time"]); - } - if (args["message"]) { - paramaters.message = args["message"]; - } - if (args["tags"]) { - parameters.tags = args["tags"].split(","); - } - check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); - } else { - callback("not enough arguments try `dogapi servicecheck --help` for help", false); - } + return { + check, + getUsage() { + return [ + ' dogapi servicecheck check <check> <host> <status> [--time <timestamp>] [--message <message>] [--tags <tags>]' + ]; + }, + getHelp() { + return [ + 'Service Check:', + ' Subcommands:', + ' check <check> <host> <status> add a new service check for <check> and <host> at level <status> (0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN)', + '', + ' Options:', + ' --time <timestamp> the POSIX timestamp to use for the check', + ' --message <message> an optional message to accompany the check', + ' --tags <tags> a comma separated list of "tag:value"\'s for the check' + ]; + }, + handleCli(subcommand, args, callback) { + if (args._.length > 6) { + const parameters = {}; + if (args.time) { + parameters.time = parseInt(args.time); } - }; + if (args.message) { + paramaters.message = args.message; + } + if (args.tags) { + parameters.tags = args.tags.split(','); + } + check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); + } else { + callback('not enough arguments try `dogapi servicecheck --help` for help', false); + } + } + }; }; diff --git a/lib/api/tag.js b/lib/api/tag.js index 210b3a3..1e967e0 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -1,8 +1,7 @@ const util = require('util'); -module.exports = function (client) { - - /*section: tag +module.exports = function(client) { + /* section: tag *comment: | * get all host tags *params: @@ -23,21 +22,21 @@ module.exports = function (client) { * }); * ``` */ - function getAll(source, callback) { - if (arguments.length < 2 && typeof arguments[0] === "function") { - callback = source; - source = undefined; - } - - const params = { - query: { - source: source - } - }; - client.request("GET", "/tags/hosts", params, callback); + function getAll(source, callback) { + if (arguments.length < 2 && typeof arguments[0] === 'function') { + callback = source; + source = undefined; } - /*section: tag + const params = { + query: { + source + } + }; + client.request('GET', '/tags/hosts', params, callback); + } + + /* section: tag *comment: | * get the host tags for a provided host name or host id *params: @@ -63,28 +62,26 @@ module.exports = function (client) { * }); * ``` */ - function get(hostname, options, callback) { - if (arguments.length < 3 && typeof arguments[1] === "function") { - callback = options; - options = {}; - } - options = options || {}; + function get(hostname, options, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = options; + options = {}; + } + options = options || {}; - const params = { - query: { - } - }; - if (options.source) { - params.query.source = options.source; - } - if (options.by_source) { - params.query.by_source = options.by_source; - } - client.request("GET", "/tags/hosts/" + hostname, params, callback); + const params = { + query: {} }; + if (options.source) { + params.query.source = options.source; + } + if (options.by_source) { + params.query.by_source = options.by_source; + } + client.request('GET', `/tags/hosts/${hostname}`, params, callback); + } - - /*section: tag + /* section: tag *comment: | * assign new host tags to the provided host name or host id *params: @@ -109,24 +106,23 @@ module.exports = function (client) { * }); * ``` */ - function create(hostname, tags, source, callback) { - if (arguments.length < 4 && typeof arguments[2] === "function") { - callback = source; - source = undefined; - } - - const params = { - body: { - tags: tags, - source: source - }, - }; + function create(hostname, tags, source, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = source; + source = undefined; + } - client.request("POST", "/tags/hosts/" + hostname, params, callback); + const params = { + body: { + tags, + source + } }; + client.request('POST', `/tags/hosts/${hostname}`, params, callback); + } - /*section: tag + /* section: tag *comment: | * update the host tags for the provided host name or host id *params: @@ -151,22 +147,22 @@ module.exports = function (client) { * }); * ``` */ - function update(hostname, tags, source, callback) { - if (arguments.length < 4 && typeof arguments[2] === "function") { - callback = source; - source = undefined; - } + function update(hostname, tags, source, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = source; + source = undefined; + } - const params = { - body: { - tags: tags, - source: source - }, - }; - client.request("PUT", "/tags/hosts/" + hostname, params, callback); + const params = { + body: { + tags, + source + } }; + client.request('PUT', `/tags/hosts/${hostname}`, params, callback); + } - /*section: tag + /* section: tag *comment: | * delete the host tags for the provided host name or host id *params: @@ -189,77 +185,77 @@ module.exports = function (client) { * }); * ``` */ - function remove(hostname, source, callback) { - if (arguments.length < 3 && typeof arguments[1] === "function") { - callback = source; - source = undefined; - } + function remove(hostname, source, callback) { + if (arguments.length < 3 && typeof arguments[1] === 'function') { + callback = source; + source = undefined; + } - const params = { - query: { - source: source - } - }; - client.request("DELETE", "/tags/hosts/" + hostname, params, callback); + const params = { + query: { + source + } }; + client.request('DELETE', `/tags/hosts/${hostname}`, params, callback); + } - return { - _client: client, - getAll: getAll, - get: get, - create: create, - update: update, - remove: remove, - getUsage: function () { - return [ - " dogapi tag getall [--source <source>]", - " dogapi tag get <host> [--source <source>] [--by-source]", - " dogapi tag remove <host> [--source <source>]", - " dogapi tag create <host> <tags> [--source <source>]", - " dogapi tag update <host> <tags> [--source <source>]" - ]; - }, - getHelp: function () { - return [ - "Tag:", - " Subcommands:", - " getall get all tags", - " get <host> get all tags for a given host", - " remove <host> delete tags for a given host", - " create <host> <tags> add the comma separates \"tag:value\"'s from <tag> to <host>", - " update <host> <tags> update the comma separates \"tag:value\"'s from <tag> to <host>", - "", - " Options:", - " --source <source> the source of the tags (e.g. \"chef\", \"user\", \"jenkins\", etc)", - " --by-source whether the results should be grouped by source" - ]; - }, - handleCli: function (subcommand, args, callback) { - const source = args["source"]; - const host = args._[4]; + return { + _client: client, + getAll, + get, + create, + update, + remove, + getUsage() { + return [ + ' dogapi tag getall [--source <source>]', + ' dogapi tag get <host> [--source <source>] [--by-source]', + ' dogapi tag remove <host> [--source <source>]', + ' dogapi tag create <host> <tags> [--source <source>]', + ' dogapi tag update <host> <tags> [--source <source>]' + ]; + }, + getHelp() { + return [ + 'Tag:', + ' Subcommands:', + ' getall get all tags', + ' get <host> get all tags for a given host', + ' remove <host> delete tags for a given host', + ' create <host> <tags> add the comma separates "tag:value"\'s from <tag> to <host>', + ' update <host> <tags> update the comma separates "tag:value"\'s from <tag> to <host>', + '', + ' Options:', + ' --source <source> the source of the tags (e.g. "chef", "user", "jenkins", etc)', + ' --by-source whether the results should be grouped by source' + ]; + }, + handleCli(subcommand, args, callback) { + const source = args.source; + const host = args._[4]; - if (subcommand === "getall") { - getAll(source, callback); - } else if (subcommand === "get") { - const options = {}; - if (source) { - options.source = source; - } - if (args["by-source"]) { - options.by_source = true; - } - get(host, options, callback); - } else if (subcommand === "create") { - const tags = args._[5].split(","); - create(host, tags, source, callback); - } else if (subcommand === "update") { - const tags = args._[5].split(","); - update(host, tags, source, callback); - } else if (subcommand === "delete") { - remove(host, source, callback); - } else { - callback("unknown subcommand or arguments try `dogapi tag --help` for help", false); - } + if (subcommand === 'getall') { + getAll(source, callback); + } else if (subcommand === 'get') { + const options = {}; + if (source) { + options.source = source; } - }; + if (args['by-source']) { + options.by_source = true; + } + get(host, options, callback); + } else if (subcommand === 'create') { + const tags = args._[5].split(','); + create(host, tags, source, callback); + } else if (subcommand === 'update') { + const tags = args._[5].split(','); + update(host, tags, source, callback); + } else if (subcommand === 'delete') { + remove(host, source, callback); + } else { + callback('unknown subcommand or arguments try `dogapi tag --help` for help', false); + } + } + }; }; diff --git a/lib/api/timeboard.js b/lib/api/timeboard.js index 90ffee4..160bc94 100644 --- a/lib/api/timeboard.js +++ b/lib/api/timeboard.js @@ -1,8 +1,8 @@ -const json = require("../json"); -const util = require("util"); +const util = require('util'); +const json = require('../json'); -module.exports = function (client) { - /*section: timeboard +module.exports = function(client) { + /* section: timeboard *comment: add a new timeboard *params: * title: the title of the timeboard @@ -54,27 +54,27 @@ module.exports = function (client) { * ); * ``` */ - function create(title, description, graphs, templateVariables, callback) { - if (arguments.length < 5 && typeof arguments[3] === "function") { - callback = templateVariables; - templateVariables = []; - } - - const params = { - body: { - title: title, - description: description, - graphs: graphs - } - }; - if (Array.isArray(templateVariables) && templateVariables.length) { - params.body.template_variables = templateVariables; - } + function create(title, description, graphs, templateVariables, callback) { + if (arguments.length < 5 && typeof arguments[3] === 'function') { + callback = templateVariables; + templateVariables = []; + } - client.request("POST", "/dash", params, callback); + const params = { + body: { + title, + description, + graphs + } + }; + if (Array.isArray(templateVariables) && templateVariables.length) { + params.body.template_variables = templateVariables; } - /*section: timeboard + client.request('POST', '/dash', params, callback); + } + + /* section: timeboard *comment: update an existing timeboard *params: * dashId: the id of the timeboard to update @@ -127,27 +127,27 @@ module.exports = function (client) { * ); * ``` */ - function update(dashId, title, description, graphs, templateVariables, callback) { - if (arguments.length < 6 && typeof arguments[4] === "function") { - callback = templateVariables; - templateVariables = []; - } - - const params = { - body: { - title: title, - description: description, - graphs: graphs - } - }; - if (Array.isArray(templateVariables) && templateVariables.length) { - params.body.template_variables = templateVariables; - } + function update(dashId, title, description, graphs, templateVariables, callback) { + if (arguments.length < 6 && typeof arguments[4] === 'function') { + callback = templateVariables; + templateVariables = []; + } - client.request("PUT", util.format("/dash/%s", dashId), params, callback); + const params = { + body: { + title, + description, + graphs + } + }; + if (Array.isArray(templateVariables) && templateVariables.length) { + params.body.template_variables = templateVariables; } - /*section: timeboard + client.request('PUT', util.format('/dash/%s', dashId), params, callback); + } + + /* section: timeboard *comment: remove an existing timeboard *params: * dashId: the id of the timeboard to remove @@ -165,11 +165,11 @@ module.exports = function (client) { * }); * ``` */ - function remove(dashId, callback) { - client.request("DELETE", util.format("/dash/%s", dashId), {}, callback); - } + function remove(dashId, callback) { + client.request('DELETE', util.format('/dash/%s', dashId), {}, callback); + } - /*section: timeboard + /* section: timeboard *comment: get all existing timeboards *params: * callback: function(err, res) @@ -186,11 +186,11 @@ module.exports = function (client) { * }); * ``` */ - function getAll(callback) { - client.request("GET", "/dash", {}, callback); - } + function getAll(callback) { + client.request('GET', '/dash', {}, callback); + } - /*section: timeboard + /* section: timeboard *comment: get an existing timeboard *params: * dashId: the id of the timeboard to get @@ -208,69 +208,69 @@ module.exports = function (client) { * }); * ``` */ - function get(dashId, callback) { - client.request("GET", util.format("/dash/%s", dashId), {}, callback); - } + function get(dashId, callback) { + client.request('GET', util.format('/dash/%s', dashId), {}, callback); + } - return { - create: create, - update: update, - remove: remove, - getAll: getAll, - get: get, - getUsage: function () { - return [ - " dogapi timeboard get <dash-id>", - " dogapi timeboard getall", - " dogapi timeboard remove <dash-id>", - " dogapi timeboard create <title> <description> <graphs> [--tmpvars <templateVariables>]", - " dogapi timeboard update <dash-id> <title> <description> <graphs> [--tmpvars <templateVariables>]", - ]; - }, - getHelp: function () { - return [ - "Timeboard:", - " Subcommands:", - " get <dash-id> get an existing timeboard", - " getall get all existing timeboards", - " remove <dash-id> remove an existing timeboard", - " create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition", - " update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition", - " Options:", - " --tmpvars <templateVariables> a json representation of the template variables definition" - ]; - }, - handleCli: function (subcommand, args, callback) { - if (subcommand === "get") { - get(args._[4], callback); - } else if (subcommand === "getall") { - getAll(callback); - } else if (subcommand === "remove") { - remove(args._[4], callback); - } else if (subcommand === "create") { - const title = args._[4]; - const description = args._[5]; - const graphs = json.parse(args._[6]); - const templateVariables = []; - if (args["tmpvars"]) { - templateVariables = json.parse(args["tmpvars"]); - } - - create(title, description, graphs, templateVariables, callback); - } else if (subcommand === "update") { - const dashId = parseInt(args._[4]); - const title = args._[5]; - const description = args._[6]; - const graphs = json.parse(args._[7]); - const templateVariables = []; - if (args["tmpvars"]) { - templateVariables = json.parse(args["tmpvars"]); - } + return { + create, + update, + remove, + getAll, + get, + getUsage() { + return [ + ' dogapi timeboard get <dash-id>', + ' dogapi timeboard getall', + ' dogapi timeboard remove <dash-id>', + ' dogapi timeboard create <title> <description> <graphs> [--tmpvars <templateVariables>]', + ' dogapi timeboard update <dash-id> <title> <description> <graphs> [--tmpvars <templateVariables>]' + ]; + }, + getHelp() { + return [ + 'Timeboard:', + ' Subcommands:', + ' get <dash-id> get an existing timeboard', + ' getall get all existing timeboards', + ' remove <dash-id> remove an existing timeboard', + ' create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition', + ' update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition', + ' Options:', + ' --tmpvars <templateVariables> a json representation of the template variables definition' + ]; + }, + handleCli(subcommand, args, callback) { + if (subcommand === 'get') { + get(args._[4], callback); + } else if (subcommand === 'getall') { + getAll(callback); + } else if (subcommand === 'remove') { + remove(args._[4], callback); + } else if (subcommand === 'create') { + const title = args._[4]; + const description = args._[5]; + const graphs = json.parse(args._[6]); + const templateVariables = []; + if (args.tmpvars) { + templateVariables = json.parse(args.tmpvars); + } - update(dashId, title, description, graphs, templateVariables, callback); - } else { - callback("unknown subcommand or arguments try `dogapi timeboard --help` for help", false); - } + create(title, description, graphs, templateVariables, callback); + } else if (subcommand === 'update') { + const dashId = parseInt(args._[4]); + const title = args._[5]; + const description = args._[6]; + const graphs = json.parse(args._[7]); + const templateVariables = []; + if (args.tmpvars) { + templateVariables = json.parse(args.tmpvars); } - }; + + update(dashId, title, description, graphs, templateVariables, callback); + } else { + callback('unknown subcommand or arguments try `dogapi timeboard --help` for help', false); + } + } + }; }; diff --git a/lib/api/user.js b/lib/api/user.js index 6e426d8..190ae5b 100644 --- a/lib/api/user.js +++ b/lib/api/user.js @@ -1,6 +1,5 @@ -module.exports = function (client) { - - /*section: user +module.exports = function(client) { + /* section: user *comment: invite users via e-mail *params: * emails: an array of email addresses to send invites to @@ -19,31 +18,29 @@ module.exports = function (client) { * }); * ``` */ - function invite(emails, callback) { - const params = { - body: { - emails: emails - } - }; - client.request("POST", "/invite_users", params, callback); + function invite(emails, callback) { + const params = { + body: { + emails + } }; + client.request('POST', '/invite_users', params, callback); + } - return { - invite: invite, - getUsage: function () { - return [ - " dogapi user invite <address>..." - ]; - }, - getHelp: function () { - return [ - "User:", - " Subcommands:", - " invite <address>... invite the given list of e-mail addresses to your datadog org" - ]; - }, - handleCli: function (subcommand, args, callback) { - invite(args._.slice(4), callback) - } - }; + return { + invite, + getUsage() { + return [' dogapi user invite <address>...']; + }, + getHelp() { + return [ + 'User:', + ' Subcommands:', + ' invite <address>... invite the given list of e-mail addresses to your datadog org' + ]; + }, + handleCli(subcommand, args, callback) { + invite(args._.slice(4), callback); + } + }; }; diff --git a/lib/client.js b/lib/client.js index 79aa338..fdc69e8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,27 +1,27 @@ -const https = require("https"); -const url = require("url"); -const util = require("util"); -const extend = require("extend"); +const https = require('https'); +const url = require('url'); +const util = require('util'); +const extend = require('extend'); const _ = require('lodash'); -const json = require("./json"); +const json = require('./json'); -/*section: client +/* section: client *comment: | * the constructor for _client_ object *params: *example: | * See [client.request](#client-request) */ -const DatadogMetricClient = function(options){ - this.api_key = options.api_key || null; - this.app_key = options.app_key || null; - this.proxy_agent = options.proxy_agent || null; - this.http_options = options.http_options || null; - this.api_version = options.api_version || "v1"; - this.api_host = options.api_host || "app.datadoghq.com"; +const DatadogMetricClient = function(options) { + this.api_key = options.api_key || null; + this.app_key = options.app_key || null; + this.proxy_agent = options.proxy_agent || null; + this.http_options = options.http_options || null; + this.api_version = options.api_version || 'v1'; + this.api_host = options.api_host || 'app.datadoghq.com'; }; -/*section: client +/* section: client *comment: | * used to make a raw request to the datadog api *params: @@ -46,87 +46,92 @@ const DatadogMetricClient = function(options){ * }); * ``` */ -DatadogMetricClient.prototype.request = function(method, path, params, callback){ - if(arguments.length === 3 && typeof arguments[2] === "function"){ - callback = arguments[2]; - params = {body: ''}; // create params with empty body property - } - - const body = (typeof params["body"] === "object") ? json.stringify(params["body"]) : params["body"]; - const query = { - "api_key": this.api_key, - "application_key": this.app_key, +DatadogMetricClient.prototype.request = function(method, path, params, callback) { + if (arguments.length === 3 && typeof arguments[2] === 'function') { + callback = arguments[2]; + params = {body: ''}; // create params with empty body property + } + + const body = typeof params.body === 'object' ? json.stringify(params.body) : params.body; + const query = { + api_key: this.api_key, + application_key: this.app_key + }; + + if (typeof params.query === 'object') { + extend(query, params.query); + } + + path = url.format({ + pathname: util.format('/api/%s%s', this.api_version, path), + query + }); + + const http_options = _.assign( + { + hostname: this.api_host, + port: 443, + method: method.toUpperCase(), + path + }, + this.http_options + ); + + if (this.proxy_agent) { + http_options.agent = this.proxy_agent; + } + + if (['POST', 'PUT'].indexOf(http_options.method) >= 0) { + http_options.headers = { + 'Content-Type': params.contentType ? params.contentType : 'application/json', + 'Content-Length': Buffer.byteLength(body) }; + } - if(typeof params["query"] === "object"){ - extend(query, params["query"]); - } - - path = url.format({ - "pathname": util.format("/api/%s%s", this.api_version, path), - "query": query, + const req = https.request(http_options, function(res) { + res.on('error', function(err) { + if (typeof callback === 'function') { + callback(err, null, res.statusCode); + } }); - const http_options = _.assign({ - hostname: this.api_host, - port: 443, - method: method.toUpperCase(), - path: path - }, this.http_options); - - if(this.proxy_agent){ - http_options["agent"] = this.proxy_agent; - } - - if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){ - http_options["headers"] = { - "Content-Type": params["contentType"] ? params["contentType"] : "application/json", - "Content-Length": Buffer.byteLength(body), - }; - } - - const req = https.request(http_options, function(res){ - res.on("error", function(err){ - if(typeof callback == "function"){ - callback(err, null, res.statusCode); - } - }); - - let data = ""; - res.on("data", function(chunk){ - data += chunk; - }); - - res.on("end", function(){ - let error = null; - try{ data = json.parse(data); }catch(e){} - if(data["errors"]){ - error = data["errors"]; - data = null; - } - - if(typeof callback === "function"){ - callback(error, data, res.statusCode); - } - }); + let data = ''; + res.on('data', function(chunk) { + data += chunk; }); - req.setTimeout(30000, function(){ - req.abort(); + res.on('end', function() { + let error = null; + try { + data = json.parse(data); + } catch (e) {} + if (data.errors) { + error = data.errors; + data = null; + } + + if (typeof callback === 'function') { + callback(error, data, res.statusCode); + } }); + }); - // This should only occur for errors such as a socket hang up prior to any - // data being received, or SSL-related issues. - req.on("error", function(err){ - if(typeof callback === "function"){ - callback(err, null, 0); - } - }); + req.setTimeout(30000, function() { + req.abort(); + }); - if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){ - req.write(body); + // This should only occur for errors such as a socket hang up prior to any + // data being received, or SSL-related issues. + req.on('error', function(err) { + if (typeof callback === 'function') { + callback(err, null, 0); } - req.end() + }); + + if (['POST', 'PUT'].indexOf(http_options.method) >= 0) { + req.write(body); + } + req.end(); }; module.exports = DatadogMetricClient; diff --git a/lib/constants.js b/lib/constants.js index 59c145a..701f3f7 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,13 +1,13 @@ module.exports.STATUSES = { - OK: 0, - WARNING: 1, - CRITICAL: 2, - UNKNOWN: 3, + OK: 0, + WARNING: 1, + CRITICAL: 2, + UNKNOWN: 3 }; module.exports.ALL_STATUSES = [ - module.exports.STATUSES.OK, - module.exports.STATUSES.WARNING, - module.exports.STATUSES.CRITICAL, - module.exports.STATUSES.UNKNOWN, + module.exports.STATUSES.OK, + module.exports.STATUSES.WARNING, + module.exports.STATUSES.CRITICAL, + module.exports.STATUSES.UNKNOWN ]; diff --git a/lib/index.js b/lib/index.js index 8e1266b..a2c5133 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,9 +1,9 @@ const _ = require('lodash'); -const api = require("./api"); -const Client = require("./client"); +const api = require('./api'); +const Client = require('./client'); -const initialClient = new Client({}) -/*section: dogapi +const initialClient = new Client({}); +/* section: dogapi *comment: configure the dogapi client with your app/api keys *params: * options: @@ -39,28 +39,28 @@ const initialClient = new Client({}) * dogapi.event.create(...); * ``` */ -function initialize(options){ - options = options || {}; - for(var key in options){ - if(initialClient.hasOwnProperty(key)){ - initialClient[key] = options[key]; - } +function initialize(options) { + options = options || {}; + for (const key in options) { + if (initialClient.hasOwnProperty(key)) { + initialClient[key] = options[key]; } -}; + } +} function DogApi(options) { - const client = new Client(options || {}); - _.forEach(api, (value, key) => { - this[key] = value(client); - }); + const client = new Client(options || {}); + _.forEach(api, (value, key) => { + this[key] = value(client); + }); } DogApi.initialize = initialize; _.forEach(api, (value, key) => { - DogApi[key] = value(initialClient); + DogApi[key] = value(initialClient); }); -/*section: dogapi +/* section: dogapi *comment: get the current POSIX timestamp *example: | * ```javascript @@ -70,9 +70,9 @@ _.forEach(api, (value, key) => { * parseInt(new Date().getTime() / 1000); * ``` */ -function now(){ - return parseInt(new Date().getTime() / 1000); -}; +function now() { + return parseInt(new Date().getTime() / 1000); +} module.exports = DogApi; module.exports.now = now; module.exports.OK = 0; diff --git a/lib/json.js b/lib/json.js index 1036179..fab1de2 100644 --- a/lib/json.js +++ b/lib/json.js @@ -1,7 +1,6 @@ -var JSONBig = require("json-bigint"); - +const JSONBig = require('json-bigint'); module.exports = { - stringify: JSONBig.stringify, - parse: JSONBig.parse + stringify: JSONBig.stringify, + parse: JSONBig.parse }; diff --git a/test/api/embed.js b/test/api/embed.js index 6cf9bff..a59fc18 100644 --- a/test/api/embed.js +++ b/test/api/embed.js @@ -1,86 +1,86 @@ -const assert = require("assert"); -const Client = require("../../lib/client"); -const extend = require("extend"); -const Embed = require("../../lib/api/embed"); -const sinon = require("sinon"); -const querystring = require("querystring"); +const assert = require('assert'); +const querystring = require('querystring'); +const extend = require('extend'); +const sinon = require('sinon'); +const Client = require('../../lib/client'); +const Embed = require('../../lib/api/embed'); -describe("api/embed", function(){ - const client = new Client({}); - const embed = Embed(client); - let stub_request; - beforeEach(function(){ - // Setup `client.request` as a stub - stub_request = sinon.stub(client, "request"); - }); - afterEach(function(){ - // Reset the original `client.request` - stub_request.restore(); - stub_request = null; - }); - describe("#create", function(){ - it("should make a valid api call", function(){ - const graphJSON = { - viz: "timeseries", - requests: [ - { - q: "system.cpu.idle{*}" - } - ] - }; - const options = { - timeframe: "1_hour", - size: "large", - legend: "yes", - title: "test graph embed" - }; +describe('api/embed', function() { + const client = new Client({}); + const embed = Embed(client); + let stub_request; + beforeEach(function() { + // Setup `client.request` as a stub + stub_request = sinon.stub(client, 'request'); + }); + afterEach(function() { + // Reset the original `client.request` + stub_request.restore(); + stub_request = null; + }); + describe('#create', function() { + it('should make a valid api call', function() { + const graphJSON = { + viz: 'timeseries', + requests: [ + { + q: 'system.cpu.idle{*}' + } + ] + }; + const options = { + timeframe: '1_hour', + size: 'large', + legend: 'yes', + title: 'test graph embed' + }; - // Make our api call - embed.create(graphJSON, options); + // Make our api call + embed.create(graphJSON, options); - // Assert we properly called `client.request` - assert(stub_request.calledOnce); - const call_args = stub_request.getCall(0).args; - // Method and endpoint are correct - assert.equal(call_args[0], "POST"); - assert.equal(call_args[1], "/graph/embed"); + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // Method and endpoint are correct + assert.equal(call_args[0], 'POST'); + assert.equal(call_args[1], '/graph/embed'); - // Properly formatted body and content-type - const params = call_args[2]; - const expectedBody = { - graph_json: JSON.stringify(graphJSON), - timeframe: "1_hour", - size: "large", - legend: "yes", - title: "test graph embed" - }; - assert.deepEqual(querystring.parse(params.body), expectedBody); - assert(params.contentType, "application/x-form-urlencoded"); - }); + // Properly formatted body and content-type + const params = call_args[2]; + const expectedBody = { + graph_json: JSON.stringify(graphJSON), + timeframe: '1_hour', + size: 'large', + legend: 'yes', + title: 'test graph embed' + }; + assert.deepEqual(querystring.parse(params.body), expectedBody); + assert(params.contentType, 'application/x-form-urlencoded'); + }); - it("should only require graph_json", function(){ - const graphJSON = { - viz: "timeseries", - requests: [ - { - q: "system.cpu.idle{*}" - } - ] - }; + it('should only require graph_json', function() { + const graphJSON = { + viz: 'timeseries', + requests: [ + { + q: 'system.cpu.idle{*}' + } + ] + }; - // Make our api call - embed.create(graphJSON); + // Make our api call + embed.create(graphJSON); - // Assert we properly called `client.request` - assert(stub_request.calledOnce); - const call_args = stub_request.getCall(0).args; + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; - // Properly formatted body - const params = call_args[2]; - const expectedBody = { - graph_json: JSON.stringify(graphJSON) - }; - assert.deepEqual(querystring.parse(params.body), expectedBody); - }); + // Properly formatted body + const params = call_args[2]; + const expectedBody = { + graph_json: JSON.stringify(graphJSON) + }; + assert.deepEqual(querystring.parse(params.body), expectedBody); }); + }); }); diff --git a/test/api/graph.js b/test/api/graph.js index 927cbbc..757ace5 100644 --- a/test/api/graph.js +++ b/test/api/graph.js @@ -1,10 +1,8 @@ -var assert = require("assert"); -var client = require("../../lib/client"); -var extend = require("extend"); -var graph = require("../../lib/api/graph"); -var sinon = require("sinon"); -var querystring = require("querystring"); +const assert = require('assert'); +const querystring = require('querystring'); +const extend = require('extend'); +const sinon = require('sinon'); +const client = require('../../lib/client'); +const graph = require('../../lib/api/graph'); -describe("api/graph", function(){ - -}); +describe('api/graph', function() {}); diff --git a/test/api/metric.js b/test/api/metric.js index 0bbc432..c7dc868 100644 --- a/test/api/metric.js +++ b/test/api/metric.js @@ -1,357 +1,356 @@ -const assert = require("assert"); -const Client = require("../../lib/client"); -const extend = require("extend"); -const Metric = require("../../lib/api/metric"); -const sinon = require("sinon"); - -describe("api/metrics", function(){ - const client = new Client({}); - const metric = Metric(client); - var stub_request; - beforeEach(function(){ - // Setup `client.request` as a stub - stub_request = sinon.stub(client, "request"); +const assert = require('assert'); +const extend = require('extend'); +const sinon = require('sinon'); +const Client = require('../../lib/client'); +const Metric = require('../../lib/api/metric'); + +describe('api/metrics', function() { + const client = new Client({}); + const metric = Metric(client); + let stub_request; + beforeEach(function() { + // Setup `client.request` as a stub + stub_request = sinon.stub(client, 'request'); + }); + afterEach(function() { + // Reset the original `client.request` + stub_request.restore(); + stub_request = null; + }); + describe('#send', function() { + it('should make a valid api call', function() { + // Make our api call + const now = parseInt(new Date().getTime() / 1000); + metric.send('metric.send', [[now, 500]]); + + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // Method and endpoint are correct + assert.equal(call_args[0], 'POST'); + assert.equal(call_args[1], '/series'); + + // Properly formatted body + // { body: series: [ {metric: "metric.send", host: undefined, tags: undefined, type: undefined} ] } + // DEV: host/tags/type are optional and should be undefined for this case + const data = call_args[2]; + assert(data.hasOwnProperty('body')); + assert(data.body.hasOwnProperty('series')); + + // Assert we have only 1 series + // series = [ {metric: "", ...}, ... ] + const series = data.body.series; + assert(Array.isArray(series)); + assert.equal(series.length, 1); + + // Assert the first series is properly formatted + // first_series = {metric: "", points: [], ...} + const first_series = series[0]; + assert.equal(first_series.metric, 'metric.send'); + assert(Array.isArray(first_series.points)); + assert.deepEqual(first_series.points, [[now, 500]]); + + // These keys are optional and should be set, but undefined + assert(first_series.hasOwnProperty('host')); + assert.equal(first_series.host, undefined); + assert(first_series.hasOwnProperty('tags')); + assert.equal(first_series.tags, undefined); + assert(first_series.hasOwnProperty('type')); + assert.equal(first_series.type, undefined); }); - afterEach(function(){ - // Reset the original `client.request` - stub_request.restore(); - stub_request = null; + + it('should properly normalize values to points', function() { + // Make our api call + metric.send('metrics.send.normalize', 500); + + // Assert we called `client.request` with the correct `points` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // { body: series: [ {points: [], }, ] } + const body = call_args[2].body; + assert.equal(body.series.length, 1); + + // points = [ [<timestamp>, 500] ] + const points = body.series[0].points; + assert(Array.isArray(points)); + assert.equal(points.length, 1); + + // point = [<timestamp>, 500] + const point = points[0]; + assert(Array.isArray(point)); + assert.equal(point.length, 2); + assert.equal(point[1], 500); + }); + + it('should properly normalize array of values to points', function() { + // Make our api call + metric.send('metrics.send.normalize', [500, 1000]); + + // Assert we called `client.request` with the correct `points` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // { body: series: [ {points: [], }, ] } + const body = call_args[2].body; + assert.equal(body.series.length, 1); + + // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] + const points = body.series[0].points; + assert(Array.isArray(points)); + assert.equal(points.length, 2); + + // point = [<timestamp>, 500] + let point = points[0]; + assert(Array.isArray(point)); + assert.equal(point.length, 2); + assert.equal(point[1], 500); + + // point = [<timestamp>, 1000] + point = points[1]; + assert(Array.isArray(point)); + assert.equal(point.length, 2); + assert.equal(point[1], 1000); + }); + + it('should not normalize correctly formatted points', function() { + // Make our api call + const now = parseInt(new Date().getTime() / 1000); + metric.send('metrics.send.normalize', [[now, 1000]]); + + // Assert we called `client.request` with the correct `points` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // { body: series: [ {points: [], }, ] } + const body = call_args[2].body; + assert.equal(body.series.length, 1); + + // points = [ [<timestamp>, 1000], ] + const points = body.series[0].points; + assert(Array.isArray(points)); + assert.equal(points.length, 1); + + // point = [<timestamp>, 500] + const point = points[0]; + assert(Array.isArray(point)); + assert.deepEqual(point, [now, 1000]); + }); + + it('should properly set metric type', function() { + // Make our api call + metric.send('metrics.send.counter', 5, {type: 'count'}); + + // Assert we called `client.request` with the correct `points` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // { body: series: [ {points: [], }, ] } + const body = call_args[2].body; + assert.equal(body.series.length, 1); + + // Assert we have only 1 series + // series = [ {metric: "", ...}, ... ] + const series = body.series; + assert(Array.isArray(series)); + assert.equal(series.length, 1); + + // Assert the first series is properly formatted + // first_series = {metric: "", type: "count", points: [], ...} + const first_series = series[0]; + assert.equal(first_series.metric, 'metrics.send.counter'); + assert(first_series.hasOwnProperty('type')); + assert.equal(first_series.type, 'count'); }); - describe("#send", function(){ - it("should make a valid api call", function(){ - // Make our api call - var now = parseInt(new Date().getTime() / 1000); - metric.send("metric.send", [[now, 500]]); - - // Assert we properly called `client.request` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // Method and endpoint are correct - assert.equal(call_args[0], "POST"); - assert.equal(call_args[1], "/series"); - - // Properly formatted body - // { body: series: [ {metric: "metric.send", host: undefined, tags: undefined, type: undefined} ] } - // DEV: host/tags/type are optional and should be undefined for this case - var data = call_args[2]; - assert(data.hasOwnProperty("body")); - assert(data.body.hasOwnProperty("series")); - - // Assert we have only 1 series - // series = [ {metric: "", ...}, ... ] - var series = data.body.series; - assert(Array.isArray(series)); - assert.equal(series.length, 1); - - // Assert the first series is properly formatted - // first_series = {metric: "", points: [], ...} - var first_series = series[0] - assert.equal(first_series.metric, "metric.send"); - assert(Array.isArray(first_series.points)); - assert.deepEqual(first_series.points, [[now, 500]]); - - // These keys are optional and should be set, but undefined - assert(first_series.hasOwnProperty("host")); - assert.equal(first_series.host, undefined); - assert(first_series.hasOwnProperty("tags")); - assert.equal(first_series.tags, undefined); - assert(first_series.hasOwnProperty("type")); - assert.equal(first_series.type, undefined); - }); - - it("should properly normalize values to points", function(){ - // Make our api call - metric.send("metrics.send.normalize", 500); - - // Assert we called `client.request` with the correct `points` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // { body: series: [ {points: [], }, ] } - var body = call_args[2].body; - assert.equal(body.series.length, 1); - - // points = [ [<timestamp>, 500] ] - var points = body.series[0].points; - assert(Array.isArray(points)); - assert.equal(points.length, 1); - - // point = [<timestamp>, 500] - var point = points[0]; - assert(Array.isArray(point)); - assert.equal(point.length, 2); - assert.equal(point[1], 500); - }); - - it("should properly normalize array of values to points", function(){ - // Make our api call - metric.send("metrics.send.normalize", [500, 1000]); - - // Assert we called `client.request` with the correct `points` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // { body: series: [ {points: [], }, ] } - var body = call_args[2].body; - assert.equal(body.series.length, 1); - - // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] - var points = body.series[0].points; - assert(Array.isArray(points)); - assert.equal(points.length, 2); - - // point = [<timestamp>, 500] - var point = points[0]; - assert(Array.isArray(point)); - assert.equal(point.length, 2); - assert.equal(point[1], 500); - - // point = [<timestamp>, 1000] - point = points[1]; - assert(Array.isArray(point)); - assert.equal(point.length, 2); - assert.equal(point[1], 1000); - }); - - it("should not normalize correctly formatted points", function(){ - // Make our api call - var now = parseInt(new Date().getTime() / 1000); - metric.send("metrics.send.normalize", [[now, 1000]]); - - // Assert we called `client.request` with the correct `points` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // { body: series: [ {points: [], }, ] } - var body = call_args[2].body; - assert.equal(body.series.length, 1); - - // points = [ [<timestamp>, 1000], ] - var points = body.series[0].points; - assert(Array.isArray(points)); - assert.equal(points.length, 1); - - // point = [<timestamp>, 500] - var point = points[0]; - assert(Array.isArray(point)); - assert.deepEqual(point, [now, 1000]); - }); - - it("should properly set metric type", function(){ - // Make our api call - metric.send("metrics.send.counter", 5, {type: "count"}); - - // Assert we called `client.request` with the correct `points` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // { body: series: [ {points: [], }, ] } - var body = call_args[2].body; - assert.equal(body.series.length, 1); - - // Assert we have only 1 series - // series = [ {metric: "", ...}, ... ] - var series = body.series; - assert(Array.isArray(series)); - assert.equal(series.length, 1); - - // Assert the first series is properly formatted - // first_series = {metric: "", type: "count", points: [], ...} - var first_series = series[0] - assert.equal(first_series.metric, "metrics.send.counter"); - assert(first_series.hasOwnProperty("type")); - assert.equal(first_series.type, "count"); - }); - - it("should properly set convert metric_type to type", function(){ - // Make our api call - metric.send("metrics.send.counter", 5, {metric_type: "count"}); - - // Assert we called `client.request` with the correct `points` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // { body: series: [ {points: [], }, ] } - var body = call_args[2].body; - assert.equal(body.series.length, 1); - - - // Assert we have only 1 series - // series = [ {metric: "", ...}, ... ] - var series = body.series; - assert(Array.isArray(series)); - assert.equal(series.length, 1); - - // Assert the first series is properly formatted - // first_series = {metric: "", type: "count", points: [], ...} - var first_series = series[0] - assert.equal(first_series.metric, "metrics.send.counter"); - assert(first_series.hasOwnProperty("type")); - assert.equal(first_series.type, "count"); - }); + + it('should properly set convert metric_type to type', function() { + // Make our api call + metric.send('metrics.send.counter', 5, {metric_type: 'count'}); + + // Assert we called `client.request` with the correct `points` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // { body: series: [ {points: [], }, ] } + const body = call_args[2].body; + assert.equal(body.series.length, 1); + + // Assert we have only 1 series + // series = [ {metric: "", ...}, ... ] + const series = body.series; + assert(Array.isArray(series)); + assert.equal(series.length, 1); + + // Assert the first series is properly formatted + // first_series = {metric: "", type: "count", points: [], ...} + const first_series = series[0]; + assert.equal(first_series.metric, 'metrics.send.counter'); + assert(first_series.hasOwnProperty('type')); + assert.equal(first_series.type, 'count'); + }); + }); + + describe('#send_all', function() { + it('should make a valid api call', function() { + // Make our api call + const now = parseInt(new Date().getTime() / 1000); + const metrics = [ + { + metric: 'metric.send_all', + points: [[now, 500]] + } + ]; + metric.send_all(metrics); + + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // Method and endpoint are correct + assert.equal(call_args[0], 'POST'); + assert.equal(call_args[1], '/series'); + + // Properly formatted body + // { body: series: [ {metric: "metric.send_all", host: undefined, tags: undefined, type: undefined} ] } + // DEV: host/tags/type are optional and should be undefined for this case + const data = call_args[2]; + assert(data.hasOwnProperty('body')); + assert(data.body.hasOwnProperty('series')); + + // Assert we have only 1 series + // series = [ {metric: "", ...}, ... ] + const series = data.body.series; + assert(Array.isArray(series)); + assert.equal(series.length, 1); + + // Assert the first series is properly formatted + // first_series = {metric: "", points: [], ...} + const first_series = series[0]; + assert.equal(first_series.metric, 'metric.send_all'); + assert(Array.isArray(first_series.points)); + assert.deepEqual(first_series.points, [[now, 500]]); + }); + + it('should properly normalize metric points', function() { + // Make our api call + const now = parseInt(new Date().getTime() / 1000); + const metrics = [ + { + metric: 'metric.send_all.normalize', + points: [[now, 500]] + }, + { + metric: 'metric.send_all.normalize', + points: [500, 1000] + }, + { + metric: 'metric.send_all.normalize', + points: 1000 + } + ]; + metric.send_all(metrics); + + // Assert we called `client.request` with the correct `points` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // { body: series: [ {points: [], }, ] } + const body = call_args[2].body; + assert.equal(body.series.length, 3); + + // points = [ [<timestamp>, 500] ] + let points = body.series[0].points; + assert(Array.isArray(points)); + assert.equal(points.length, 1); + assert.equal(points[0].length, 2); + assert.equal(points[0][1], 500); + + // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] + points = body.series[1].points; + assert(Array.isArray(points)); + assert.equal(points.length, 2); + assert.equal(points[0].length, 2); + assert.equal(points[0][1], 500); + assert.equal(points[1].length, 2); + assert.equal(points[1][1], 1000); + + // points = [ [<timestamp>, 1000] ] + points = body.series[2].points; + assert(Array.isArray(points)); + assert.equal(points.length, 1); + assert.equal(points[0].length, 2); + assert.equal(points[0][1], 1000); + }); + + it('should properly send metric type', function() { + // Make our api call + const metrics = [ + { + metric: 'metric.send.counter', + points: 5, + type: 'count' + } + ]; + metric.send_all(metrics); + + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // Method and endpoint are correct + assert.equal(call_args[0], 'POST'); + assert.equal(call_args[1], '/series'); + + // Properly formatted body + // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } + // DEV: host/tags are optional and should be undefined for this case + const data = call_args[2]; + assert(data.hasOwnProperty('body')); + assert(data.body.hasOwnProperty('series')); + + // Assert we have only 1 series + // series = [ {metric: "", ...}, ... ] + const series = data.body.series; + assert(Array.isArray(series)); + assert.equal(series.length, 1); + + // Assert the first series is properly formatted + // first_series = {metric: "", type: "count", points: [], ...} + const first_series = series[0]; + assert.equal(first_series.metric, 'metric.send.counter'); + assert(Array.isArray(first_series.points)); + assert.deepEqual(first_series.type, 'count'); }); - describe("#send_all", function(){ - it("should make a valid api call", function(){ - // Make our api call - var now = parseInt(new Date().getTime() / 1000); - var metrics = [ - { - metric: "metric.send_all", - points: [[now, 500]] - } - ]; - metric.send_all(metrics); - - // Assert we properly called `client.request` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // Method and endpoint are correct - assert.equal(call_args[0], "POST"); - assert.equal(call_args[1], "/series"); - - // Properly formatted body - // { body: series: [ {metric: "metric.send_all", host: undefined, tags: undefined, type: undefined} ] } - // DEV: host/tags/type are optional and should be undefined for this case - var data = call_args[2]; - assert(data.hasOwnProperty("body")); - assert(data.body.hasOwnProperty("series")); - - // Assert we have only 1 series - // series = [ {metric: "", ...}, ... ] - var series = data.body.series; - assert(Array.isArray(series)); - assert.equal(series.length, 1); - - // Assert the first series is properly formatted - // first_series = {metric: "", points: [], ...} - var first_series = series[0] - assert.equal(first_series.metric, "metric.send_all"); - assert(Array.isArray(first_series.points)); - assert.deepEqual(first_series.points, [[now, 500]]); - }); - - it("should properly normalize metric points", function(){ - // Make our api call - var now = parseInt(new Date().getTime() / 1000); - var metrics = [ - { - metric: "metric.send_all.normalize", - points: [[now, 500]] - }, - { - metric: "metric.send_all.normalize", - points: [500, 1000] - }, - { - metric: "metric.send_all.normalize", - points: 1000 - } - ]; - metric.send_all(metrics); - - // Assert we called `client.request` with the correct `points` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // { body: series: [ {points: [], }, ] } - var body = call_args[2].body; - assert.equal(body.series.length, 3); - - // points = [ [<timestamp>, 500] ] - var points = body.series[0].points; - assert(Array.isArray(points)); - assert.equal(points.length, 1); - assert.equal(points[0].length, 2); - assert.equal(points[0][1], 500); - - // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] - points = body.series[1].points; - assert(Array.isArray(points)); - assert.equal(points.length, 2); - assert.equal(points[0].length, 2); - assert.equal(points[0][1], 500); - assert.equal(points[1].length, 2); - assert.equal(points[1][1], 1000); - - // points = [ [<timestamp>, 1000] ] - points = body.series[2].points; - assert(Array.isArray(points)); - assert.equal(points.length, 1); - assert.equal(points[0].length, 2); - assert.equal(points[0][1], 1000); - }); - - it("should properly send metric type", function(){ - // Make our api call - var metrics = [ - { - metric: "metric.send.counter", - points: 5, - type: "count" - } - ]; - metric.send_all(metrics); - - // Assert we properly called `client.request` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // Method and endpoint are correct - assert.equal(call_args[0], "POST"); - assert.equal(call_args[1], "/series"); - - // Properly formatted body - // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } - // DEV: host/tags are optional and should be undefined for this case - var data = call_args[2]; - assert(data.hasOwnProperty("body")); - assert(data.body.hasOwnProperty("series")); - - // Assert we have only 1 series - // series = [ {metric: "", ...}, ... ] - var series = data.body.series; - assert(Array.isArray(series)); - assert.equal(series.length, 1); - - // Assert the first series is properly formatted - // first_series = {metric: "", type: "count", points: [], ...} - var first_series = series[0] - assert.equal(first_series.metric, "metric.send.counter"); - assert(Array.isArray(first_series.points)); - assert.deepEqual(first_series.type, "count"); - }); - - it("should properly send metric_type as type", function(){ - // Make our api call - var metrics = [ - { - metric: "metric.send.counter", - points: 5, - metric_type: "count" - } - ]; - metric.send_all(metrics); - - // Assert we properly called `client.request` - assert(stub_request.calledOnce); - var call_args = stub_request.getCall(0).args; - // Method and endpoint are correct - assert.equal(call_args[0], "POST"); - assert.equal(call_args[1], "/series"); - - // Properly formatted body - // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } - // DEV: host/tags are optional and should be undefined for this case - var data = call_args[2]; - assert(data.hasOwnProperty("body")); - assert(data.body.hasOwnProperty("series")); - - // Assert we have only 1 series - // series = [ {metric: "", ...}, ... ] - var series = data.body.series; - assert(Array.isArray(series)); - assert.equal(series.length, 1); - - // Assert the first series is properly formatted - // first_series = {metric: "", type: "count", points: [], ...} - var first_series = series[0] - assert.equal(first_series.metric, "metric.send.counter"); - assert(Array.isArray(first_series.points)); - assert.deepEqual(first_series.type, "count"); - }); + it('should properly send metric_type as type', function() { + // Make our api call + const metrics = [ + { + metric: 'metric.send.counter', + points: 5, + metric_type: 'count' + } + ]; + metric.send_all(metrics); + + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + const call_args = stub_request.getCall(0).args; + // Method and endpoint are correct + assert.equal(call_args[0], 'POST'); + assert.equal(call_args[1], '/series'); + + // Properly formatted body + // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } + // DEV: host/tags are optional and should be undefined for this case + const data = call_args[2]; + assert(data.hasOwnProperty('body')); + assert(data.body.hasOwnProperty('series')); + + // Assert we have only 1 series + // series = [ {metric: "", ...}, ... ] + const series = data.body.series; + assert(Array.isArray(series)); + assert.equal(series.length, 1); + + // Assert the first series is properly formatted + // first_series = {metric: "", type: "count", points: [], ...} + const first_series = series[0]; + assert.equal(first_series.metric, 'metric.send.counter'); + assert(Array.isArray(first_series.points)); + assert.deepEqual(first_series.type, 'count'); }); + }); }); diff --git a/test/json.js b/test/json.js index a1e2dff..73ba430 100644 --- a/test/json.js +++ b/test/json.js @@ -1,26 +1,26 @@ -var assert = require("assert"); -var BigNumber = require("bignumber.js"); -var json = require("../lib/json"); +const assert = require('assert'); +const BigNumber = require('bignumber.js'); +const json = require('../lib/json'); -describe("json", function(){ - describe("#parse()", function(){ - it("should properly parse big integers", function(){ - // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 - var data = "{\"id\": 2868860079149422351}"; - var parsed = json.parse(data); - // `parsed.id` is an instance of `BigNumber` - assert.equal(parsed.id.toString(), "2868860079149422351"); - }); +describe('json', function() { + describe('#parse()', function() { + it('should properly parse big integers', function() { + // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 + const data = '{"id": 2868860079149422351}'; + const parsed = json.parse(data); + // `parsed.id` is an instance of `BigNumber` + assert.equal(parsed.id.toString(), '2868860079149422351'); }); + }); - describe("#stringify()", function(){ - it("should properly parse big integers", function(){ - // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 - var data = {"id": new BigNumber('2868860079149422351')}; - var stringified = json.stringify(data); - // Yeah, it ends up being a string and not an int, but mostly we - // want to make sure it doesn't throw an error or provide the wrong number - assert.equal(stringified, "{\"id\":\"2868860079149422351\"}"); - }); + describe('#stringify()', function() { + it('should properly parse big integers', function() { + // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 + const data = {id: new BigNumber('2868860079149422351')}; + const stringified = json.stringify(data); + // Yeah, it ends up being a string and not an int, but mostly we + // want to make sure it doesn't throw an error or provide the wrong number + assert.equal(stringified, '{"id":"2868860079149422351"}'); }); + }); }); From 0dbab0c916e8ce11765039c00589439eead3ea97 Mon Sep 17 00:00:00 2001 From: Adriean Khisbe <adriean.khisbe@live.fr> Date: Tue, 5 Mar 2019 08:55:08 +0100 Subject: [PATCH 07/10] Make linting green again :white_check_mark: - disable some rules (put as warning) - refactor some stuff - fix some bugs introduced in 404e362 :bug: - fix some original bugs (paramater, argument) --- .eslintrc | 21 +-- lib/api/comment.js | 11 +- lib/api/downtime.js | 5 +- lib/api/embed.js | 5 +- lib/api/event.js | 7 +- lib/api/graph.js | 5 +- lib/api/host.js | 2 +- lib/api/index.js | 2 +- lib/api/metric.js | 128 +++++++++--------- lib/api/monitor.js | 20 ++- lib/api/screenboard.js | 5 +- lib/api/search.js | 9 +- lib/api/{serviceCheck.js => service-check.js} | 11 +- lib/api/tag.js | 4 +- lib/api/timeboard.js | 19 ++- lib/client.js | 17 +-- lib/index.js | 12 +- 17 files changed, 143 insertions(+), 140 deletions(-) rename lib/api/{serviceCheck.js => service-check.js} (89%) diff --git a/.eslintrc b/.eslintrc index 0522bf4..7c6905e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,20 +20,11 @@ ], "rules": { "promise/no-native": "off", - "strict": "off" + "strict": "off", + "fp/no-arguments": "warn", + "no-param-reassign": "warn", + "prefer-rest-params": "warn", + "fp/no-loops": "warn" }, - "overrides": [ - { - "files": [ "scripts/migrate*.js", "lib/*.js" ], - "env": { - "mongo": true - } - }, - { - "files": ["**/test/**"], - "rules": { - "unicorn/filename-case": "off" - } - } - ] + "overrides": [] } diff --git a/lib/api/comment.js b/lib/api/comment.js index 21e7879..d46ea55 100644 --- a/lib/api/comment.js +++ b/lib/api/comment.js @@ -75,12 +75,10 @@ module.exports = function(client) { const params = { body: { - message + message, + handle: handle || undefined } }; - if (handle) { - params.body.handle = properties.handle; - } client.request('PUT', util.format('/comments/%s', commentId), params, callback); } @@ -150,7 +148,10 @@ module.exports = function(client) { const commentId = args._[4]; remove(commentId, callback); } else { - callback('unknown subcommand or arguments try `dogapi comment --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi comment --help` for help', + false + ); } } }; diff --git a/lib/api/downtime.js b/lib/api/downtime.js index 805f1d4..8549a1f 100644 --- a/lib/api/downtime.js +++ b/lib/api/downtime.js @@ -235,7 +235,10 @@ module.exports = function(client) { } update(downtimeId, properties, callback); } else { - callback('unknown subcommand or arguments try `dogapi downtime --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi downtime --help` for help', + false + ); } } }; diff --git a/lib/api/embed.js b/lib/api/embed.js index 1252efd..696aa76 100644 --- a/lib/api/embed.js +++ b/lib/api/embed.js @@ -162,7 +162,10 @@ module.exports = function(client) { } else if (subcommand === 'getall') { getAll(callback); } else { - callback('unknown subcommand or arguments try `dogapi embed --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi embed --help` for help', + false + ); } } }; diff --git a/lib/api/event.js b/lib/api/event.js index f92fb47..164d4c4 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -118,7 +118,7 @@ module.exports = function(client) { * ``` */ function query(start, end, parameters, callback) { - if (arguments.length < 4 && typeof argument[2] === 'function') { + if (arguments.length < 4 && typeof arguments[2] === 'function') { callback = parameters; parameters = {}; } @@ -203,7 +203,10 @@ module.exports = function(client) { } create(title, text, properties, callback); } else { - callback('unknown subcommand or arguments try `dogapi event --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi event --help` for help', + false + ); } } }; diff --git a/lib/api/graph.js b/lib/api/graph.js index 2390f47..9e451fc 100644 --- a/lib/api/graph.js +++ b/lib/api/graph.js @@ -69,7 +69,10 @@ module.exports = function(client) { const eventQuery = args.events; snapshot(query, from, to, eventQuery, callback); } else { - callback('unknown subcommand or arguments try `dogapi graph --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi graph --help` for help', + false + ); } } }; diff --git a/lib/api/host.js b/lib/api/host.js index 3b639e7..b216300 100644 --- a/lib/api/host.js +++ b/lib/api/host.js @@ -102,7 +102,7 @@ module.exports = function(client) { const hostname = args._[4]; unmute(hostname, callback); } else { - callback('unknown subcommand or arguments try `dogapi host --help` for help', false); + return callback('unknown subcommand or arguments try `dogapi host --help` for help', false); } } }; diff --git a/lib/api/index.js b/lib/api/index.js index 5d9b0f1..2a5de0b 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -10,7 +10,7 @@ module.exports = { monitor: require('./monitor'), screenboard: require('./screenboard'), search: require('./search'), - serviceCheck: require('./serviceCheck'), + serviceCheck: require('./service-check'), tag: require('./tag'), timeboard: require('./timeboard'), user: require('./user') diff --git a/lib/api/metric.js b/lib/api/metric.js index 7c47c9f..dd7baac 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -1,62 +1,4 @@ module.exports = function(client) { - /* section: metric - *comment: | - * submit a new metric - *params: - * metric: the metric name - * points: | - * a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) - * or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) - * extra: | - * optional, object which can contain the following keys - * * host: the host source of the metric - * * tags: array of "tag:value"'s to use for the metric - * * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] - * callback: | - * function(err, res) - *example: | - * ```javascript - * const dogapi = require("dogapi"); - * const options = { - * api_key: "api_key", - * app_key: "app_key" - * }; - * dogapi.initialize(options); - * dogapi.metric.send("my.metric", 1000, function(err, results){ - * console.dir(results); - * }); - * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ - * console.dir(results); - * }); - * const now = parseInt(new Date().getTime() / 1000); - * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ - * console.dir(results); - * }); - * dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ - * console.dir(results); - * }); - * ``` - */ - function send(metric, points, extra, callback) { - if (arguments.length < 4 && typeof arguments[2] === 'function') { - callback = extra; - extra = {}; - } - extra = extra || {}; - const series = [ - { - metric, - points, - host: extra.host, - tags: extra.tags, - // DEV: For backwards compatibility, allow `metric_type` - type: extra.type || extra.metric_type - } - ]; - - send_all(series, callback); - } - /* section: metric *comment: | * send a list of metrics @@ -117,7 +59,6 @@ module.exports = function(client) { // 500 => [<timestamp>, 500] // [<timestamp>, 500] => unchanged if (!Array.isArray(point)) { - const now = parseInt(new Date().getTime() / 1000); point = [now, point]; } return point; @@ -140,13 +81,71 @@ module.exports = function(client) { client.request('POST', '/series', params, callback); } + /* section: metric + *comment: | + * submit a new metric + *params: + * metric: the metric name + * points: | + * a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) + * or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) + * extra: | + * optional, object which can contain the following keys + * * host: the host source of the metric + * * tags: array of "tag:value"'s to use for the metric + * * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] + * callback: | + * function(err, res) + *example: | + * ```javascript + * const dogapi = require("dogapi"); + * const options = { + * api_key: "api_key", + * app_key: "app_key" + * }; + * dogapi.initialize(options); + * dogapi.metric.send("my.metric", 1000, function(err, results){ + * console.dir(results); + * }); + * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ + * console.dir(results); + * }); + * const now = parseInt(new Date().getTime() / 1000); + * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ + * console.dir(results); + * }); + * dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ + * console.dir(results); + * }); + * ``` + */ + function send(metric, points, extra, callback) { + if (arguments.length < 4 && typeof arguments[2] === 'function') { + callback = extra; + extra = {}; + } + extra = extra || {}; + const series = [ + { + metric, + points, + host: extra.host, + tags: extra.tags, + // DEV: For backwards compatibility, allow `metric_type` + type: extra.type || extra.metric_type + } + ]; + + send_all(series, callback); + } + /* section: metric *comment: | * make a metric query *params: * from: POSIX timestamp for start of query * to: POSIX timestamp for end of query - * query: the string query to perform (e.g. "system.cpu.idle{*}by{host}") + * q: the string query to perform (e.g. "system.cpu.idle{*}by{host}") * callback: function(err, res) *example: | * ```javascript @@ -164,12 +163,12 @@ module.exports = function(client) { * }); * ``` */ - function query(from, to, query, callback) { + function query(from, to, q, callback) { const params = { query: { from, to, - query + query: q } }; client.request('GET', '/query', params, callback); @@ -213,7 +212,10 @@ module.exports = function(client) { const q = args._[6]; query(from, to, q, callback); } else { - callback('unknown subcommand or arguments try `dogapi metric --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi metric --help` for help', + false + ); } } }; diff --git a/lib/api/monitor.js b/lib/api/monitor.js index 7d31351..cb3b5bd 100644 --- a/lib/api/monitor.js +++ b/lib/api/monitor.js @@ -379,15 +379,8 @@ module.exports = function(client) { ]; }, handleCli(subcommand, args, callback) { - const states = []; - if (args.states) { - states = args.states.split(','); - } - - const tags = []; - if (args.tags) { - tags = args.tags.split(','); - } + const states = args.states ? args.states.split(',') : []; + const tags = args.tags ? args.tags.split(',') : []; const name = args.name; const message = args.message; @@ -397,10 +390,10 @@ module.exports = function(client) { get(monitorId, states, callback); } else if (subcommand === 'getall') { const options = {}; - if (states.length) { + if (states.length > 0) { options.group_states = states; } - if (tags.length) { + if (tags.length > 0) { options.tags = tags; } getAll(options, callback); @@ -448,7 +441,10 @@ module.exports = function(client) { } update(monitorId, query, properties, callback); } else { - callback('unknown subcommand or arguments try `dogapi monitor --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi monitor --help` for help', + false + ); } } }; diff --git a/lib/api/screenboard.js b/lib/api/screenboard.js index 57de1ed..8c2086e 100644 --- a/lib/api/screenboard.js +++ b/lib/api/screenboard.js @@ -343,7 +343,10 @@ module.exports = function(client) { create(boardTitle, widgets, options, callback); } else { - callback('unknown subcommand or arguments try `dogapi screenboard --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi screenboard --help` for help', + false + ); } } }; diff --git a/lib/api/search.js b/lib/api/search.js index 0500fed..a63a434 100644 --- a/lib/api/search.js +++ b/lib/api/search.js @@ -19,10 +19,10 @@ module.exports = function(client) { * }); * ``` */ - function query(query, callback) { + function query(q, callback) { const params = { query: { - q: query + q } }; client.request('GET', '/search', params, callback); @@ -44,7 +44,10 @@ module.exports = function(client) { if (subcommand === 'query' && args._.length > 4) { query(args._[4], callback); } else { - callback('unknown subcommand or arguments try `dogapi search --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi search --help` for help', + false + ); } } }; diff --git a/lib/api/serviceCheck.js b/lib/api/service-check.js similarity index 89% rename from lib/api/serviceCheck.js rename to lib/api/service-check.js index 0d39c8d..1bff849 100644 --- a/lib/api/serviceCheck.js +++ b/lib/api/service-check.js @@ -28,7 +28,7 @@ module.exports = function(client) { * }); * ``` */ - function check(check, hostName, status, parameters, callback) { + function check(checkName, hostName, status, parameters, callback) { if (arguments.length < 5 && typeof arguments[3] === 'function') { callback = parameters; parameters = {}; @@ -38,8 +38,9 @@ module.exports = function(client) { parameters = {}; } - parameters.check = check; - (parameters.host_name = hostName), (parameters.status = status); + parameters.check = checkName; + parameters.host_name = hostName; + parameters.status = status; const params = { body: parameters @@ -73,14 +74,14 @@ module.exports = function(client) { parameters.time = parseInt(args.time); } if (args.message) { - paramaters.message = args.message; + parameters.message = args.message; } if (args.tags) { parameters.tags = args.tags.split(','); } check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); } else { - callback('not enough arguments try `dogapi servicecheck --help` for help', false); + return callback('not enough arguments try `dogapi servicecheck --help` for help', false); } } }; diff --git a/lib/api/tag.js b/lib/api/tag.js index 1e967e0..1962234 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -1,5 +1,3 @@ -const util = require('util'); - module.exports = function(client) { /* section: tag *comment: | @@ -254,7 +252,7 @@ module.exports = function(client) { } else if (subcommand === 'delete') { remove(host, source, callback); } else { - callback('unknown subcommand or arguments try `dogapi tag --help` for help', false); + return callback('unknown subcommand or arguments try `dogapi tag --help` for help', false); } } }; diff --git a/lib/api/timeboard.js b/lib/api/timeboard.js index 160bc94..cfc787e 100644 --- a/lib/api/timeboard.js +++ b/lib/api/timeboard.js @@ -67,7 +67,7 @@ module.exports = function(client) { graphs } }; - if (Array.isArray(templateVariables) && templateVariables.length) { + if (Array.isArray(templateVariables) && templateVariables.length > 0) { params.body.template_variables = templateVariables; } @@ -140,7 +140,7 @@ module.exports = function(client) { graphs } }; - if (Array.isArray(templateVariables) && templateVariables.length) { + if (Array.isArray(templateVariables) && templateVariables.length > 0) { params.body.template_variables = templateVariables; } @@ -251,10 +251,7 @@ module.exports = function(client) { const title = args._[4]; const description = args._[5]; const graphs = json.parse(args._[6]); - const templateVariables = []; - if (args.tmpvars) { - templateVariables = json.parse(args.tmpvars); - } + const templateVariables = args.tmpvars ? json.parse(args.tmpvars) : []; create(title, description, graphs, templateVariables, callback); } else if (subcommand === 'update') { @@ -262,14 +259,14 @@ module.exports = function(client) { const title = args._[5]; const description = args._[6]; const graphs = json.parse(args._[7]); - const templateVariables = []; - if (args.tmpvars) { - templateVariables = json.parse(args.tmpvars); - } + const templateVariables = args.tmpvars ? json.parse(args.tmpvars) : []; update(dashId, title, description, graphs, templateVariables, callback); } else { - callback('unknown subcommand or arguments try `dogapi timeboard --help` for help', false); + return callback( + 'unknown subcommand or arguments try `dogapi timeboard --help` for help', + false + ); } } }; diff --git a/lib/client.js b/lib/client.js index fdc69e8..b77aa33 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2,7 +2,7 @@ const https = require('https'); const url = require('url'); const util = require('util'); const extend = require('extend'); -const _ = require('lodash'); +const _ = require('lodash/fp'); const json = require('./json'); /* section: client @@ -67,15 +67,12 @@ DatadogMetricClient.prototype.request = function(method, path, params, callback) query }); - const http_options = _.assign( - { - hostname: this.api_host, - port: 443, - method: method.toUpperCase(), - path - }, - this.http_options - ); + const http_options = _.assign(this.http_options, { + hostname: this.api_host, + port: 443, + method: method.toUpperCase(), + path + }); if (this.proxy_agent) { http_options.agent = this.proxy_agent; diff --git a/lib/index.js b/lib/index.js index a2c5133..33d1630 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,9 @@ -const _ = require('lodash'); +const _ = require('lodash/fp'); const api = require('./api'); const Client = require('./client'); +const forEach = _.forEach.convert({cap: false}); + const initialClient = new Client({}); /* section: dogapi *comment: configure the dogapi client with your app/api keys @@ -50,15 +52,15 @@ function initialize(options) { function DogApi(options) { const client = new Client(options || {}); - _.forEach(api, (value, key) => { + forEach((value, key) => { this[key] = value(client); - }); + }, api); } DogApi.initialize = initialize; -_.forEach(api, (value, key) => { +forEach((value, key) => { DogApi[key] = value(initialClient); -}); +}, api); /* section: dogapi *comment: get the current POSIX timestamp From b971434484e6abfe0d2f68361b01d65678c399f9 Mon Sep 17 00:00:00 2001 From: Adriean Khisbe <adriean.khisbe@live.fr> Date: Tue, 5 Mar 2019 09:10:18 +0100 Subject: [PATCH 08/10] Make linting green again for all files, not just lib :green_book: --- .eslintrc | 10 +++++++++- lib/client.js | 18 +++++++++++------- test/api/embed.js | 20 ++++++++++---------- test/api/graph.js | 8 -------- test/api/metric.js | 1 - 5 files changed, 30 insertions(+), 27 deletions(-) delete mode 100644 test/api/graph.js diff --git a/.eslintrc b/.eslintrc index 7c6905e..4ca1bdb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,5 +26,13 @@ "prefer-rest-params": "warn", "fp/no-loops": "warn" }, - "overrides": [] + "overrides": [ + { + "files": [ "bin/*" ], + "rules": { + "no-console": "off", + "no-continue": "warn" + } + } + ] } diff --git a/lib/client.js b/lib/client.js index b77aa33..42e4a33 100644 --- a/lib/client.js +++ b/lib/client.js @@ -88,27 +88,31 @@ DatadogMetricClient.prototype.request = function(method, path, params, callback) const req = https.request(http_options, function(res) { res.on('error', function(err) { if (typeof callback === 'function') { - callback(err, null, res.statusCode); + return callback(err, null, res.statusCode); } }); - let data = ''; + let _data = ''; res.on('data', function(chunk) { - data += chunk; + _data += chunk; }); res.on('end', function() { let error = null; + let data; + try { - data = json.parse(data); - } catch (e) {} + data = json.parse(_data); + } catch (e) { + data = {}; + } if (data.errors) { error = data.errors; data = null; } if (typeof callback === 'function') { - callback(error, data, res.statusCode); + return callback(error, data, res.statusCode); } }); }); @@ -121,7 +125,7 @@ DatadogMetricClient.prototype.request = function(method, path, params, callback) // data being received, or SSL-related issues. req.on('error', function(err) { if (typeof callback === 'function') { - callback(err, null, 0); + return callback(err, null, 0); } }); diff --git a/test/api/embed.js b/test/api/embed.js index a59fc18..081e3c6 100644 --- a/test/api/embed.js +++ b/test/api/embed.js @@ -1,6 +1,5 @@ const assert = require('assert'); const querystring = require('querystring'); -const extend = require('extend'); const sinon = require('sinon'); const Client = require('../../lib/client'); const Embed = require('../../lib/api/embed'); @@ -9,16 +8,17 @@ describe('api/embed', function() { const client = new Client({}); const embed = Embed(client); let stub_request; - beforeEach(function() { - // Setup `client.request` as a stub - stub_request = sinon.stub(client, 'request'); - }); - afterEach(function() { - // Reset the original `client.request` - stub_request.restore(); - stub_request = null; - }); + describe('#create', function() { + beforeEach(function() { + // Setup `client.request` as a stub + stub_request = sinon.stub(client, 'request'); + }); + afterEach(function() { + // Reset the original `client.request` + stub_request.restore(); + stub_request = null; + }); it('should make a valid api call', function() { const graphJSON = { viz: 'timeseries', diff --git a/test/api/graph.js b/test/api/graph.js deleted file mode 100644 index 757ace5..0000000 --- a/test/api/graph.js +++ /dev/null @@ -1,8 +0,0 @@ -const assert = require('assert'); -const querystring = require('querystring'); -const extend = require('extend'); -const sinon = require('sinon'); -const client = require('../../lib/client'); -const graph = require('../../lib/api/graph'); - -describe('api/graph', function() {}); diff --git a/test/api/metric.js b/test/api/metric.js index c7dc868..632ad5d 100644 --- a/test/api/metric.js +++ b/test/api/metric.js @@ -1,5 +1,4 @@ const assert = require('assert'); -const extend = require('extend'); const sinon = require('sinon'); const Client = require('../../lib/client'); const Metric = require('../../lib/api/metric'); From f1cbac8d73edf54659fa93d3fa19f19cbac27c13 Mon Sep 17 00:00:00 2001 From: Adriean Khisbe <adriean.khisbe@live.fr> Date: Tue, 5 Mar 2019 09:10:40 +0100 Subject: [PATCH 09/10] Configure travis to make lint run :traffic_light: --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 49cff8e..0299c94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,10 @@ node_js: - "9" - "10" - "node" + +install: + - npm install + +script: + - npm run lint + - npm test From 9785317bfa279d5f3c6ad0075c9e884f6d1b3cfa Mon Sep 17 00:00:00 2001 From: Adriean Khisbe <adriean.khisbe@live.fr> Date: Tue, 5 Mar 2019 09:16:33 +0100 Subject: [PATCH 10/10] Specify engine and drop support of node 4/5 :rotating_light: --- .travis.yml | 2 -- package.json | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0299c94..e01223c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: - - "4" - - "5" - "6" - "7" - "8" diff --git a/package.json b/package.json index 4c1e512..ce68540 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "2.8.3", "description": "Datadog API Node.JS Client", "main": "lib/index.js", + "engines": { + "node": ">= 6.10.0" + }, "scripts": { "test": "./node_modules/.bin/mocha --recursive ./test", "lint": "eslint lib test bin/dogapi examples",