@reporting-bi/cli 0.0.9 → 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.
Files changed (2) hide show
  1. package/dist/index.js +195 -120
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1055,13 +1055,13 @@ var require_implementation = __commonJS({
1055
1055
  if (typeof target !== "function" || toStr2.apply(target) !== funcType) {
1056
1056
  throw new TypeError(ERROR_MESSAGE + target);
1057
1057
  }
1058
- var args2 = slicy(arguments, 1);
1058
+ var args = slicy(arguments, 1);
1059
1059
  var bound;
1060
1060
  var binder = function() {
1061
1061
  if (this instanceof bound) {
1062
1062
  var result = target.apply(
1063
1063
  this,
1064
- concatty(args2, arguments)
1064
+ concatty(args, arguments)
1065
1065
  );
1066
1066
  if (Object(result) === result) {
1067
1067
  return result;
@@ -1070,10 +1070,10 @@ var require_implementation = __commonJS({
1070
1070
  }
1071
1071
  return target.apply(
1072
1072
  that,
1073
- concatty(args2, arguments)
1073
+ concatty(args, arguments)
1074
1074
  );
1075
1075
  };
1076
- var boundLength = max(0, target.length - args2.length);
1076
+ var boundLength = max(0, target.length - args.length);
1077
1077
  var boundArgs = [];
1078
1078
  for (var i = 0; i < boundLength; i++) {
1079
1079
  boundArgs[i] = "$" + i;
@@ -1144,11 +1144,11 @@ var require_call_bind_apply_helpers = __commonJS({
1144
1144
  var $TypeError = require_type();
1145
1145
  var $call = require_functionCall();
1146
1146
  var $actualApply = require_actualApply();
1147
- module2.exports = function callBindBasic(args2) {
1148
- if (args2.length < 1 || typeof args2[0] !== "function") {
1147
+ module2.exports = function callBindBasic(args) {
1148
+ if (args.length < 1 || typeof args[0] !== "function") {
1149
1149
  throw new $TypeError("a function is required");
1150
1150
  }
1151
- return $actualApply(bind, $call, args2);
1151
+ return $actualApply(bind, $call, args);
1152
1152
  };
1153
1153
  }
1154
1154
  });
@@ -2650,7 +2650,7 @@ var require_service = __commonJS({
2650
2650
  this.options.baseUrl = `https://${this.options.baseUrl}`;
2651
2651
  }
2652
2652
  }
2653
- createUrl(path2 = "", params) {
2653
+ createUrl(path3 = "", params) {
2654
2654
  if (this.options.xdebugSession) {
2655
2655
  params = params || {};
2656
2656
  params.XDEBUG_SESSION = this.options.xdebugSession === true ? "1" : this.options.xdebugSession.toString();
@@ -2660,8 +2660,8 @@ var require_service = __commonJS({
2660
2660
  }
2661
2661
  const queryString = params ? "?" + serializeRequestParams(params) : "";
2662
2662
  const a = params && params.accounting ? params.accounting.toString() : this.a ? this.a.toString() : null;
2663
- path2 = path2.replace(/^\//, "");
2664
- const parts = [this.options.baseUrl, a, this.options.name, path2];
2663
+ path3 = path3.replace(/^\//, "");
2664
+ const parts = [this.options.baseUrl, a, this.options.name, path3];
2665
2665
  return parts.filter((p) => p != null && p !== "").join("/") + queryString;
2666
2666
  }
2667
2667
  async createHeaders(headers) {
@@ -2702,28 +2702,28 @@ var require_service = __commonJS({
2702
2702
  return await response.text();
2703
2703
  }
2704
2704
  }
2705
- async getRaw(path2, params, options) {
2706
- return fetch(this.createUrl(path2, params), {
2705
+ async getRaw(path3, params, options) {
2706
+ return fetch(this.createUrl(path3, params), {
2707
2707
  headers: await this.createHeaders(options?.headers),
2708
2708
  credentials: this.credentials
2709
2709
  });
2710
2710
  }
2711
- async get(path2, params, options) {
2711
+ async get(path3, params, options) {
2712
2712
  if (options?.cache) {
2713
- const cachedData = this.cache.get({ path: path2, params });
2713
+ const cachedData = this.cache.get({ path: path3, params });
2714
2714
  if (cachedData)
2715
2715
  return cachedData;
2716
2716
  }
2717
- const response = await this.getRaw(path2, params, options);
2717
+ const response = await this.getRaw(path3, params, options);
2718
2718
  const responseData = await this.handleResponse(response, options?.parseResponse);
2719
2719
  if (options?.cache && responseData) {
2720
- this.cache.set({ path: path2, params }, responseData);
2720
+ this.cache.set({ path: path3, params }, responseData);
2721
2721
  }
2722
2722
  return responseData;
2723
2723
  }
2724
- async postRaw(path2, data, params, options) {
2724
+ async postRaw(path3, data, params, options) {
2725
2725
  const json = isObject(data) || Array.isArray(data);
2726
- return fetch(this.createUrl(path2, params), {
2726
+ return fetch(this.createUrl(path3, params), {
2727
2727
  method: "POST",
2728
2728
  body: json ? JSON.stringify(data) : data,
2729
2729
  headers: await this.createHeaders({
@@ -2733,24 +2733,24 @@ var require_service = __commonJS({
2733
2733
  credentials: this.credentials
2734
2734
  });
2735
2735
  }
2736
- async post(path2, data, params, options) {
2737
- const response = await this.postRaw(path2, data, params, options);
2736
+ async post(path3, data, params, options) {
2737
+ const response = await this.postRaw(path3, data, params, options);
2738
2738
  return this.handleResponse(response);
2739
2739
  }
2740
- async deleteRaw(path2, params, options) {
2741
- return fetch(this.createUrl(path2, params), {
2740
+ async deleteRaw(path3, params, options) {
2741
+ return fetch(this.createUrl(path3, params), {
2742
2742
  method: "DELETE",
2743
2743
  headers: await this.createHeaders(options?.headers),
2744
2744
  credentials: this.credentials
2745
2745
  });
2746
2746
  }
2747
- async delete(path2, params, options) {
2748
- const response = await this.deleteRaw(path2, params, options);
2747
+ async delete(path3, params, options) {
2748
+ const response = await this.deleteRaw(path3, params, options);
2749
2749
  return this.handleResponse(response);
2750
2750
  }
2751
- async putRaw(path2, data, params, options) {
2751
+ async putRaw(path3, data, params, options) {
2752
2752
  const json = isObject(data) || Array.isArray(data);
2753
- return fetch(this.createUrl(path2, params), {
2753
+ return fetch(this.createUrl(path3, params), {
2754
2754
  method: "PUT",
2755
2755
  body: json ? JSON.stringify(data) : data,
2756
2756
  headers: await this.createHeaders({
@@ -2760,8 +2760,8 @@ var require_service = __commonJS({
2760
2760
  credentials: this.credentials
2761
2761
  });
2762
2762
  }
2763
- async put(path2, data, params, options) {
2764
- const response = await this.putRaw(path2, data, params, options);
2763
+ async put(path3, data, params, options) {
2764
+ const response = await this.putRaw(path3, data, params, options);
2765
2765
  return this.handleResponse(response);
2766
2766
  }
2767
2767
  };
@@ -3136,21 +3136,21 @@ var FLAG_ALIASES = {
3136
3136
  s: "sort",
3137
3137
  f: "filter"
3138
3138
  };
3139
- function parseArgs(args2) {
3139
+ function parseArgs(args) {
3140
3140
  const positional = [];
3141
3141
  const flags = {};
3142
- for (let i = 0; i < args2.length; i++) {
3143
- if (args2[i].startsWith("--") && (i + 1 >= args2.length || args2[i + 1].startsWith("-"))) {
3144
- flags[args2[i].slice(2)] = "true";
3145
- } else if (args2[i].startsWith("--") && i + 1 < args2.length) {
3146
- flags[args2[i].slice(2)] = args2[i + 1];
3142
+ for (let i = 0; i < args.length; i++) {
3143
+ if (args[i].startsWith("--") && (i + 1 >= args.length || args[i + 1].startsWith("-"))) {
3144
+ flags[args[i].slice(2)] = "true";
3145
+ } else if (args[i].startsWith("--") && i + 1 < args.length) {
3146
+ flags[args[i].slice(2)] = args[i + 1];
3147
3147
  i++;
3148
- } else if (args2[i].startsWith("-") && !args2[i].startsWith("--") && i + 1 < args2.length) {
3149
- const key = FLAG_ALIASES[args2[i].slice(1)] || args2[i].slice(1);
3150
- flags[key] = args2[i + 1];
3148
+ } else if (args[i].startsWith("-") && !args[i].startsWith("--") && i + 1 < args.length) {
3149
+ const key = FLAG_ALIASES[args[i].slice(1)] || args[i].slice(1);
3150
+ flags[key] = args[i + 1];
3151
3151
  i++;
3152
3152
  } else {
3153
- positional.push(args2[i]);
3153
+ positional.push(args[i]);
3154
3154
  }
3155
3155
  }
3156
3156
  return { positional, flags };
@@ -3209,8 +3209,8 @@ async function fetchAccountingName(accountingId) {
3209
3209
  const match = accountings?.find((a) => a.accounting === accountingId);
3210
3210
  return match?.company ?? null;
3211
3211
  }
3212
- async function accounting(args2) {
3213
- const { positional, flags } = parseArgs(args2);
3212
+ async function accounting(args) {
3213
+ const { positional, flags } = parseArgs(args);
3214
3214
  const [subcommand] = positional;
3215
3215
  switch (subcommand) {
3216
3216
  case "list":
@@ -3294,8 +3294,8 @@ function openBrowser(url) {
3294
3294
  const cmd = platform === "darwin" ? "open" : platform === "win32" ? 'start ""' : "xdg-open";
3295
3295
  (0, import_node_child_process.exec)(`${cmd} ${JSON.stringify(url)}`);
3296
3296
  }
3297
- async function login(args2) {
3298
- const { positional, flags } = parseArgs(args2);
3297
+ async function login(args) {
3298
+ const { positional, flags } = parseArgs(args);
3299
3299
  const domain = positional[0] || "https://reporting.bi";
3300
3300
  const accounting2 = flags.accounting ? parseInt(flags.accounting) : void 0;
3301
3301
  console.log(`Logging in to ${domain}...`);
@@ -3426,8 +3426,8 @@ function status() {
3426
3426
  }
3427
3427
 
3428
3428
  // src/commands/use.ts
3429
- async function use(args2) {
3430
- const { positional, flags } = parseArgs(args2);
3429
+ async function use(args) {
3430
+ const { positional, flags } = parseArgs(args);
3431
3431
  const accounting2 = flags.accounting ? parseInt(flags.accounting) : void 0;
3432
3432
  let domain = positional[0];
3433
3433
  if (!domain && !accounting2) {
@@ -3525,8 +3525,8 @@ async function del(id, flags) {
3525
3525
  await service.delete(`page/${lang}/${id}`);
3526
3526
  console.log(`Page ${id} deleted.`);
3527
3527
  }
3528
- async function wiki(args2) {
3529
- const { positional, flags } = parseArgs(args2);
3528
+ async function wiki(args) {
3529
+ const { positional, flags } = parseArgs(args);
3530
3530
  const [subcommand, ...rest] = positional;
3531
3531
  switch (subcommand) {
3532
3532
  case "list":
@@ -3597,8 +3597,8 @@ async function search2(query, flags) {
3597
3597
  const results = await service.get("search", { ...getListParams(flags, DEFAULT_FIELDS), q: query });
3598
3598
  output(results || [], flags);
3599
3599
  }
3600
- async function etl(args2) {
3601
- const { positional, flags } = parseArgs(args2);
3600
+ async function etl(args) {
3601
+ const { positional, flags } = parseArgs(args);
3602
3602
  const [subcommand, ...rest] = positional;
3603
3603
  switch (subcommand) {
3604
3604
  case "list":
@@ -3656,8 +3656,8 @@ async function statusCmd(flags) {
3656
3656
  const statuses = await service.get("jobStatuses", getListParams(flags, DEFAULT_STATUS_FIELDS));
3657
3657
  output(statuses || [], flags);
3658
3658
  }
3659
- async function jobs(args2) {
3660
- const { positional, flags } = parseArgs(args2);
3659
+ async function jobs(args) {
3660
+ const { positional, flags } = parseArgs(args);
3661
3661
  const [subcommand, ...rest] = positional;
3662
3662
  switch (subcommand) {
3663
3663
  case "list":
@@ -3684,8 +3684,8 @@ async function jobs(args2) {
3684
3684
 
3685
3685
  // src/commands/analytics.ts
3686
3686
  var DEFAULT_CONTEXT_FIELDS = ["id_context", "name", "module", "user_name"];
3687
- async function context(args2) {
3688
- const { positional, flags } = parseArgs(args2);
3687
+ async function context(args) {
3688
+ const { positional, flags } = parseArgs(args);
3689
3689
  const [subcommand, ...rest] = positional;
3690
3690
  switch (subcommand) {
3691
3691
  case "list":
@@ -3710,8 +3710,8 @@ async function context(args2) {
3710
3710
  break;
3711
3711
  }
3712
3712
  }
3713
- async function report(args2) {
3714
- const { positional, flags } = parseArgs(args2);
3713
+ async function report(args) {
3714
+ const { positional, flags } = parseArgs(args);
3715
3715
  const id = positional[0];
3716
3716
  if (!id) {
3717
3717
  console.error("Usage: rpbi report <context_id> [--index N]");
@@ -3722,8 +3722,8 @@ async function report(args2) {
3722
3722
  const result = await service.get(`report/${id}/${index}`, void 0, { parseResponse: false });
3723
3723
  process.stdout.write(result || "");
3724
3724
  }
3725
- async function dimensions(args2) {
3726
- const { positional, flags } = parseArgs(args2);
3725
+ async function dimensions(args) {
3726
+ const { positional, flags } = parseArgs(args);
3727
3727
  const module2 = flags.module || flags.m;
3728
3728
  if (!module2) {
3729
3729
  console.error("Usage: rpbi dimensions --module <module>");
@@ -3733,8 +3733,8 @@ async function dimensions(args2) {
3733
3733
  const dims = await service.get(`visibleDimensions/${module2}`, getListParams(flags));
3734
3734
  output(dims || [], flags);
3735
3735
  }
3736
- async function years(args2) {
3737
- const { positional, flags } = parseArgs(args2);
3736
+ async function years(args) {
3737
+ const { positional, flags } = parseArgs(args);
3738
3738
  const service = await createService("analytics");
3739
3739
  const tree = await service.get("years");
3740
3740
  output(tree || [], flags);
@@ -3764,8 +3764,8 @@ async function roles(flags) {
3764
3764
  const result = await service.get("accessRoles", getListParams(flags, DEFAULT_ROLES_FIELDS));
3765
3765
  output(result || [], flags);
3766
3766
  }
3767
- async function users(args2) {
3768
- const { positional, flags } = parseArgs(args2);
3767
+ async function users(args) {
3768
+ const { positional, flags } = parseArgs(args);
3769
3769
  const [subcommand, ...rest] = positional;
3770
3770
  switch (subcommand) {
3771
3771
  case "list":
@@ -3823,8 +3823,8 @@ async function fiscalYears(flags) {
3823
3823
  const result = await service.get("fiscalYears", getListParams(flags));
3824
3824
  output(result || [], flags);
3825
3825
  }
3826
- async function def(args2) {
3827
- const { positional, flags } = parseArgs(args2);
3826
+ async function def(args) {
3827
+ const { positional, flags } = parseArgs(args);
3828
3828
  const [subcommand, ...rest] = positional;
3829
3829
  switch (subcommand) {
3830
3830
  case "statements":
@@ -3877,8 +3877,8 @@ async function exportCsv(id, flags) {
3877
3877
  const result = await service.get(`export/${id}/${type}`, void 0, { parseResponse: false });
3878
3878
  process.stdout.write(result || "");
3879
3879
  }
3880
- async function mdm(args2) {
3881
- const { positional, flags } = parseArgs(args2);
3880
+ async function mdm(args) {
3881
+ const { positional, flags } = parseArgs(args);
3882
3882
  const [subcommand, ...rest] = positional;
3883
3883
  switch (subcommand) {
3884
3884
  case "tables":
@@ -3947,8 +3947,8 @@ async function create(flags) {
3947
3947
  }
3948
3948
  output(result, flags);
3949
3949
  }
3950
- async function helpdesk(args2) {
3951
- const { positional, flags } = parseArgs(args2);
3950
+ async function helpdesk(args) {
3951
+ const { positional, flags } = parseArgs(args);
3952
3952
  const [subcommand, ...rest] = positional;
3953
3953
  switch (subcommand) {
3954
3954
  case "list":
@@ -3973,6 +3973,78 @@ async function helpdesk(args2) {
3973
3973
  }
3974
3974
  }
3975
3975
 
3976
+ // src/autoupdate.ts
3977
+ var fs4 = __toESM(require("node:fs"));
3978
+ var path2 = __toESM(require("node:path"));
3979
+ var os2 = __toESM(require("node:os"));
3980
+ var https = __toESM(require("node:https"));
3981
+ var import_node_child_process2 = require("node:child_process");
3982
+ var CONFIG_DIR2 = path2.join(os2.homedir(), ".config", "reporting-bi");
3983
+ var UPDATE_CHECK_FILE = path2.join(CONFIG_DIR2, "update-check.json");
3984
+ var CHECK_INTERVAL = 60 * 60 * 1e3;
3985
+ var PACKAGE_NAME = "@reporting-bi/cli";
3986
+ function loadUpdateCheck() {
3987
+ try {
3988
+ return JSON.parse(fs4.readFileSync(UPDATE_CHECK_FILE, "utf-8"));
3989
+ } catch {
3990
+ return { lastCheck: 0 };
3991
+ }
3992
+ }
3993
+ function saveUpdateCheck(data) {
3994
+ fs4.mkdirSync(CONFIG_DIR2, { recursive: true });
3995
+ fs4.writeFileSync(UPDATE_CHECK_FILE, JSON.stringify(data, null, 2));
3996
+ }
3997
+ function fetchLatestVersion() {
3998
+ return new Promise((resolve) => {
3999
+ const req = https.get(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { timeout: 5e3 }, (res) => {
4000
+ if (res.statusCode !== 200) {
4001
+ res.resume();
4002
+ return resolve(null);
4003
+ }
4004
+ let body = "";
4005
+ res.on("data", (chunk) => body += chunk);
4006
+ res.on("end", () => {
4007
+ try {
4008
+ resolve(JSON.parse(body).version ?? null);
4009
+ } catch {
4010
+ resolve(null);
4011
+ }
4012
+ });
4013
+ });
4014
+ req.on("error", () => resolve(null));
4015
+ req.on("timeout", () => {
4016
+ req.destroy();
4017
+ resolve(null);
4018
+ });
4019
+ });
4020
+ }
4021
+ function isNewer(remote, local) {
4022
+ const r = remote.split(".").map(Number);
4023
+ const l = local.split(".").map(Number);
4024
+ for (let i = 0; i < Math.max(r.length, l.length); i++) {
4025
+ const rv = r[i] ?? 0;
4026
+ const lv = l[i] ?? 0;
4027
+ if (rv > lv) return true;
4028
+ if (rv < lv) return false;
4029
+ }
4030
+ return false;
4031
+ }
4032
+ async function checkForUpdate() {
4033
+ try {
4034
+ const data = loadUpdateCheck();
4035
+ const now = Date.now();
4036
+ if (now - data.lastCheck < CHECK_INTERVAL) return;
4037
+ saveUpdateCheck({ lastCheck: now });
4038
+ const latest = await fetchLatestVersion();
4039
+ if (!latest) return;
4040
+ if (!isNewer(latest, "0.0.10")) return;
4041
+ console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.0.10"} \u2192 ${latest}...\x1B[0m`);
4042
+ (0, import_node_child_process2.execSync)(`npm install -g ${PACKAGE_NAME}@${latest}`, { stdio: "inherit" });
4043
+ console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
4044
+ } catch {
4045
+ }
4046
+ }
4047
+
3976
4048
  // USAGE.md
3977
4049
  var USAGE_default = `Reporting.bi CLI
3978
4050
 
@@ -4091,57 +4163,60 @@ Examples:
4091
4163
  `;
4092
4164
 
4093
4165
  // src/index.ts
4094
- var [command, ...args] = process.argv.slice(2);
4095
- switch (command) {
4096
- case "login":
4097
- login(args);
4098
- break;
4099
- case "logout":
4100
- logout(args[0]);
4101
- break;
4102
- case "use":
4103
- use(args);
4104
- break;
4105
- case "wiki":
4106
- wiki(args);
4107
- break;
4108
- case "accounting":
4109
- accounting(args);
4110
- break;
4111
- case "etl":
4112
- etl(args);
4113
- break;
4114
- case "jobs":
4115
- jobs(args);
4116
- break;
4117
- case "context":
4118
- context(args);
4119
- break;
4120
- case "report":
4121
- report(args);
4122
- break;
4123
- case "dimensions":
4124
- dimensions(args);
4125
- break;
4126
- case "years":
4127
- years(args);
4128
- break;
4129
- case "users":
4130
- users(args);
4131
- break;
4132
- case "def":
4133
- def(args);
4134
- break;
4135
- case "mdm":
4136
- mdm(args);
4137
- break;
4138
- case "helpdesk":
4139
- helpdesk(args);
4140
- break;
4141
- case "status":
4142
- status();
4143
- break;
4144
- default:
4145
- console.log(USAGE_default);
4146
- break;
4147
- }
4166
+ (async () => {
4167
+ await checkForUpdate();
4168
+ const [command, ...args] = process.argv.slice(2);
4169
+ switch (command) {
4170
+ case "login":
4171
+ login(args);
4172
+ break;
4173
+ case "logout":
4174
+ logout(args[0]);
4175
+ break;
4176
+ case "use":
4177
+ use(args);
4178
+ break;
4179
+ case "wiki":
4180
+ wiki(args);
4181
+ break;
4182
+ case "accounting":
4183
+ accounting(args);
4184
+ break;
4185
+ case "etl":
4186
+ etl(args);
4187
+ break;
4188
+ case "jobs":
4189
+ jobs(args);
4190
+ break;
4191
+ case "context":
4192
+ context(args);
4193
+ break;
4194
+ case "report":
4195
+ report(args);
4196
+ break;
4197
+ case "dimensions":
4198
+ dimensions(args);
4199
+ break;
4200
+ case "years":
4201
+ years(args);
4202
+ break;
4203
+ case "users":
4204
+ users(args);
4205
+ break;
4206
+ case "def":
4207
+ def(args);
4208
+ break;
4209
+ case "mdm":
4210
+ mdm(args);
4211
+ break;
4212
+ case "helpdesk":
4213
+ helpdesk(args);
4214
+ break;
4215
+ case "status":
4216
+ status();
4217
+ break;
4218
+ default:
4219
+ console.log(USAGE_default);
4220
+ break;
4221
+ }
4222
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporting-bi/cli",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Reporting.bi CLI — command-line interface for the Reporting.bi platform",
6
6
  "main": "./dist/index.js",