onlineornot 0.0.8 → 0.0.10

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.8";
24054
+ var version = "0.0.10";
24055
24055
  var package_default = {
24056
24056
  name: "onlineornot",
24057
24057
  version,
@@ -24733,6 +24733,22 @@ var supports_color_default2 = supportsColor2;
24733
24733
  var import_node_util = require("node:util");
24734
24734
  var import_cli_table3 = __toESM(require_cli_table3());
24735
24735
  var import_esbuild = require("esbuild");
24736
+
24737
+ // src/environment-variables/factory.ts
24738
+ function getEnvironmentVariableFactory({
24739
+ variableName,
24740
+ defaultValue
24741
+ }) {
24742
+ return () => {
24743
+ if (process.env[variableName]) {
24744
+ return process.env[variableName];
24745
+ } else {
24746
+ return defaultValue?.();
24747
+ }
24748
+ };
24749
+ }
24750
+
24751
+ // src/logger.ts
24736
24752
  var LOGGER_LEVELS = {
24737
24753
  none: -1,
24738
24754
  error: 0,
@@ -24748,10 +24764,14 @@ var LOGGER_LEVEL_FORMAT_TYPE_MAP = {
24748
24764
  log: void 0,
24749
24765
  debug: void 0
24750
24766
  };
24767
+ var getLogLevelFromEnv = getEnvironmentVariableFactory({
24768
+ variableName: "ONLINEORNOT_LOG",
24769
+ defaultValue: () => "log"
24770
+ });
24751
24771
  var Logger = class {
24752
24772
  constructor() {
24753
24773
  }
24754
- loggerLevel = "log";
24774
+ loggerLevel = getLogLevelFromEnv() ?? "log";
24755
24775
  columns = process.stdout.columns;
24756
24776
  debug = (...args) => this.doLog("debug", args);
24757
24777
  info = (...args) => this.doLog("info", args);
@@ -24811,6 +24831,9 @@ async function printBanner() {
24811
24831
  );
24812
24832
  }
24813
24833
 
24834
+ // src/fetch/index.ts
24835
+ var import_node_url = require("node:url");
24836
+
24814
24837
  // src/parse.ts
24815
24838
  var JSON_ERROR_SUFFIX = " in JSON at position ";
24816
24839
  var ParseError = class extends Error {
@@ -24866,20 +24889,6 @@ var import_undici = __toESM(require_undici());
24866
24889
  // src/constants.ts
24867
24890
  var API_BASE_URL = "https://api.onlineornot.com/v1";
24868
24891
 
24869
- // src/environment-variables/factory.ts
24870
- function getEnvironmentVariableFactory({
24871
- variableName,
24872
- defaultValue
24873
- }) {
24874
- return () => {
24875
- if (process.env[variableName]) {
24876
- return process.env[variableName];
24877
- } else {
24878
- return defaultValue?.();
24879
- }
24880
- };
24881
- }
24882
-
24883
24892
  // src/environment-variables/misc-variables.ts
24884
24893
  var getOnlineOrNotAPITokenFromEnv = getEnvironmentVariableFactory({
24885
24894
  variableName: "ONLINEORNOT_API_TOKEN",
@@ -24989,6 +24998,31 @@ async function fetchResult(resource, init = {}, queryParams, abortSignal) {
24989
24998
  throwFetchError(resource, json);
24990
24999
  }
24991
25000
  }
25001
+ async function fetchPagedResult(resource, init = {}, queryParams) {
25002
+ const results = [];
25003
+ let getMoreResults = true;
25004
+ let page = 1;
25005
+ while (getMoreResults) {
25006
+ queryParams = new import_node_url.URLSearchParams(queryParams);
25007
+ queryParams.set("page", String(page));
25008
+ const json = await fetchInternal(
25009
+ resource,
25010
+ init,
25011
+ queryParams
25012
+ );
25013
+ if (json.success) {
25014
+ results.push(...json.result);
25015
+ if (hasMorePages(json.result_info)) {
25016
+ page = page + 1;
25017
+ } else {
25018
+ getMoreResults = false;
25019
+ }
25020
+ } else {
25021
+ throwFetchError(resource, json);
25022
+ }
25023
+ }
25024
+ return results;
25025
+ }
24992
25026
  function throwFetchError(resource, response) {
24993
25027
  const error = new ParseError({
24994
25028
  text: `A request to the OnlineOrNot API (${resource}) failed.`,
@@ -25002,6 +25036,12 @@ function throwFetchError(resource, response) {
25002
25036
  }
25003
25037
  throw error;
25004
25038
  }
25039
+ function hasMorePages(result_info) {
25040
+ const page = result_info?.page;
25041
+ const per_page = result_info?.per_page;
25042
+ const total = result_info?.total_count;
25043
+ return page !== void 0 && per_page !== void 0 && total !== void 0 && page * per_page < total;
25044
+ }
25005
25045
  function renderError(err, level = 0) {
25006
25046
  const chainedMessages = err.error_chain?.map(
25007
25047
  (chainedError) => `
@@ -25019,7 +25059,7 @@ function checksOptions(yargs) {
25019
25059
  });
25020
25060
  }
25021
25061
  async function checksHandler(args) {
25022
- const results = await fetchResult("/checks");
25062
+ const results = await fetchPagedResult("/checks");
25023
25063
  if (args.json) {
25024
25064
  logger.log(JSON.stringify(results, null, " "));
25025
25065
  } else {