onlineornot 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24051,7 +24051,7 @@ var Yargs = YargsFactory(esm_default);
24051
24051
  var yargs_default = Yargs;
24052
24052
 
24053
24053
  // package.json
24054
- var version = "0.0.7";
24054
+ var version = "0.0.9";
24055
24055
  var package_default = {
24056
24056
  name: "onlineornot",
24057
24057
  version,
@@ -24811,6 +24811,9 @@ async function printBanner() {
24811
24811
  );
24812
24812
  }
24813
24813
 
24814
+ // src/fetch/index.ts
24815
+ var import_node_url = require("node:url");
24816
+
24814
24817
  // src/parse.ts
24815
24818
  var JSON_ERROR_SUFFIX = " in JSON at position ";
24816
24819
  var ParseError = class extends Error {
@@ -24989,6 +24992,31 @@ async function fetchResult(resource, init = {}, queryParams, abortSignal) {
24989
24992
  throwFetchError(resource, json);
24990
24993
  }
24991
24994
  }
24995
+ async function fetchPagedResult(resource, init = {}, queryParams) {
24996
+ const results = [];
24997
+ let getMoreResults = true;
24998
+ let page = 1;
24999
+ while (getMoreResults) {
25000
+ queryParams = new import_node_url.URLSearchParams(queryParams);
25001
+ queryParams.set("page", String(page));
25002
+ const json = await fetchInternal(
25003
+ resource,
25004
+ init,
25005
+ queryParams
25006
+ );
25007
+ if (json.success) {
25008
+ results.push(...json.result);
25009
+ if (hasMorePages(json.result_info)) {
25010
+ page = page + 1;
25011
+ } else {
25012
+ getMoreResults = false;
25013
+ }
25014
+ } else {
25015
+ throwFetchError(resource, json);
25016
+ }
25017
+ }
25018
+ return results;
25019
+ }
24992
25020
  function throwFetchError(resource, response) {
24993
25021
  const error = new ParseError({
24994
25022
  text: `A request to the OnlineOrNot API (${resource}) failed.`,
@@ -25002,6 +25030,12 @@ function throwFetchError(resource, response) {
25002
25030
  }
25003
25031
  throw error;
25004
25032
  }
25033
+ function hasMorePages(result_info) {
25034
+ const page = result_info?.page;
25035
+ const per_page = result_info?.per_page;
25036
+ const total = result_info?.total_count;
25037
+ return page !== void 0 && per_page !== void 0 && total !== void 0 && page * per_page < total;
25038
+ }
25005
25039
  function renderError(err, level = 0) {
25006
25040
  const chainedMessages = err.error_chain?.map(
25007
25041
  (chainedError) => `
@@ -25019,7 +25053,7 @@ function checksOptions(yargs) {
25019
25053
  });
25020
25054
  }
25021
25055
  async function checksHandler(args) {
25022
- const results = await fetchResult("/checks");
25056
+ const results = await fetchPagedResult("/checks");
25023
25057
  if (args.json) {
25024
25058
  logger.log(JSON.stringify(results, null, " "));
25025
25059
  } else {
@@ -25036,6 +25070,36 @@ async function checksHandler(args) {
25036
25070
  }
25037
25071
  }
25038
25072
 
25073
+ // src/checks/individualCheck.ts
25074
+ function checkOptions(yargs) {
25075
+ return yargs.positional("id", {
25076
+ describe: "The ID of the check you wish to fetch",
25077
+ type: "string",
25078
+ demandOption: true
25079
+ }).option("json", {
25080
+ describe: "Return output as JSON",
25081
+ type: "boolean",
25082
+ default: false
25083
+ });
25084
+ }
25085
+ async function checkHandler(args) {
25086
+ const result = await fetchResult(`/checks/${args.id}`);
25087
+ if (args.json) {
25088
+ logger.log(JSON.stringify(result, null, " "));
25089
+ } else {
25090
+ await printBanner();
25091
+ logger.table([
25092
+ {
25093
+ "Check ID": result.id,
25094
+ Name: result.name,
25095
+ URL: result.url,
25096
+ Status: result.status,
25097
+ "Last queued": result.lastQueued
25098
+ }
25099
+ ]);
25100
+ }
25101
+ }
25102
+
25039
25103
  // src/whoami.ts
25040
25104
  async function whoami() {
25041
25105
  logger.log("Getting User settings...");
@@ -25107,6 +25171,12 @@ function createCLIParser(argv) {
25107
25171
  checksOptions,
25108
25172
  checksHandler
25109
25173
  );
25174
+ onlineornot.command(
25175
+ "check <id>",
25176
+ "\u{1F5D2}\uFE0F Review a specific uptime check",
25177
+ checkOptions,
25178
+ checkHandler
25179
+ );
25110
25180
  onlineornot.command(
25111
25181
  "whoami",
25112
25182
  "\u{1F575}\uFE0F Retrieve your user info and test your auth config",