@reporting-bi/cli 0.0.13 → 0.0.15

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 +105 -35
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5752,7 +5752,7 @@ var require_compile = __commonJS({
5752
5752
  const schOrFunc = root.refs[ref];
5753
5753
  if (schOrFunc)
5754
5754
  return schOrFunc;
5755
- let _sch = resolve3.call(this, root, ref);
5755
+ let _sch = resolve4.call(this, root, ref);
5756
5756
  if (_sch === void 0) {
5757
5757
  const schema = (_a2 = root.localRefs) === null || _a2 === void 0 ? void 0 : _a2[ref];
5758
5758
  const { schemaId } = this.opts;
@@ -5779,7 +5779,7 @@ var require_compile = __commonJS({
5779
5779
  function sameSchemaEnv(s1, s2) {
5780
5780
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
5781
5781
  }
5782
- function resolve3(root, ref) {
5782
+ function resolve4(root, ref) {
5783
5783
  let sch;
5784
5784
  while (typeof (sch = this.refs[ref]) == "string")
5785
5785
  ref = sch;
@@ -6354,7 +6354,7 @@ var require_fast_uri = __commonJS({
6354
6354
  }
6355
6355
  return uri;
6356
6356
  }
6357
- function resolve3(baseURI, relativeURI, options) {
6357
+ function resolve4(baseURI, relativeURI, options) {
6358
6358
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
6359
6359
  const resolved = resolveComponent(parse3(baseURI, schemelessOptions), parse3(relativeURI, schemelessOptions), schemelessOptions, true);
6360
6360
  schemelessOptions.skipEscape = true;
@@ -6581,7 +6581,7 @@ var require_fast_uri = __commonJS({
6581
6581
  var fastUri = {
6582
6582
  SCHEMES,
6583
6583
  normalize,
6584
- resolve: resolve3,
6584
+ resolve: resolve4,
6585
6585
  resolveComponent,
6586
6586
  equal,
6587
6587
  serialize,
@@ -9608,13 +9608,13 @@ var ReportingAuthClient = class {
9608
9608
  }
9609
9609
  return { credentials: "include" };
9610
9610
  }
9611
- async fetchWithAuth(url2, init = {}) {
9611
+ async fetchWithAuth(url2, init2 = {}) {
9612
9612
  const authInit = await this.getAuthInit();
9613
9613
  return fetch(url2, {
9614
- ...init,
9614
+ ...init2,
9615
9615
  ...authInit,
9616
9616
  headers: {
9617
- ...init.headers,
9617
+ ...init2.headers,
9618
9618
  ...authInit.headers
9619
9619
  }
9620
9620
  });
@@ -9800,10 +9800,30 @@ function saveCredentials(data) {
9800
9800
  fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
9801
9801
  fs.writeFileSync(CREDENTIALS_FILE, JSON.stringify(data, null, 2), { mode: 384 });
9802
9802
  }
9803
+ function findLocalConfig(startDir) {
9804
+ let dir = path.resolve(startDir || process.cwd());
9805
+ while (true) {
9806
+ const manifestPath = path.join(dir, ".rpbi", "manifest.json");
9807
+ try {
9808
+ const data = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
9809
+ if (data.domain) return { domain: data.domain, accounting: data.accounting };
9810
+ } catch {
9811
+ }
9812
+ const parent = path.dirname(dir);
9813
+ if (parent === dir) return null;
9814
+ dir = parent;
9815
+ }
9816
+ }
9803
9817
  function getActiveConnection() {
9804
9818
  const creds = loadCredentials();
9805
- if (!creds.active || !creds.connections[creds.active]) return null;
9806
- return { domain: creds.active, tokens: creds.connections[creds.active] };
9819
+ const local = findLocalConfig();
9820
+ const domain2 = local?.domain ?? creds.active;
9821
+ if (!domain2 || !creds.connections[domain2]) return null;
9822
+ const tokens = { ...creds.connections[domain2] };
9823
+ if (local?.accounting) {
9824
+ tokens.accounting = local.accounting;
9825
+ }
9826
+ return { domain: domain2, tokens };
9807
9827
  }
9808
9828
  function storeTokens(domain2, tokens) {
9809
9829
  const creds = loadCredentials();
@@ -10108,12 +10128,12 @@ async function login(args) {
10108
10128
  }
10109
10129
  }
10110
10130
  function getAuthorizationCode(domain2) {
10111
- return new Promise((resolve3) => {
10131
+ return new Promise((resolve4) => {
10112
10132
  let timeout;
10113
10133
  const done = (result) => {
10114
10134
  clearTimeout(timeout);
10115
10135
  server.close();
10116
- resolve3(result);
10136
+ resolve4(result);
10117
10137
  };
10118
10138
  const server = http.createServer((req, res) => {
10119
10139
  const url2 = new URL(req.url || "", "http://localhost");
@@ -10273,11 +10293,11 @@ async function readContent(flags) {
10273
10293
  return flags.content;
10274
10294
  }
10275
10295
  if (!process.stdin.isTTY) {
10276
- return new Promise((resolve3) => {
10296
+ return new Promise((resolve4) => {
10277
10297
  let data = "";
10278
10298
  process.stdin.setEncoding("utf-8");
10279
10299
  process.stdin.on("data", (chunk) => data += chunk);
10280
- process.stdin.on("end", () => resolve3(data));
10300
+ process.stdin.on("end", () => resolve4(data));
10281
10301
  });
10282
10302
  }
10283
10303
  console.error("No content provided. Use --file, --content, or pipe to stdin.");
@@ -15345,7 +15365,7 @@ var NEVER = Object.freeze({
15345
15365
  });
15346
15366
  // @__NO_SIDE_EFFECTS__
15347
15367
  function $constructor(name, initializer3, params) {
15348
- function init(inst, def2) {
15368
+ function init2(inst, def2) {
15349
15369
  if (!inst._zod) {
15350
15370
  Object.defineProperty(inst, "_zod", {
15351
15371
  value: {
@@ -15377,14 +15397,14 @@ function $constructor(name, initializer3, params) {
15377
15397
  function _(def2) {
15378
15398
  var _a2;
15379
15399
  const inst = params?.Parent ? new Definition() : this;
15380
- init(inst, def2);
15400
+ init2(inst, def2);
15381
15401
  (_a2 = inst._zod).deferred ?? (_a2.deferred = []);
15382
15402
  for (const fn of inst._zod.deferred) {
15383
15403
  fn();
15384
15404
  }
15385
15405
  return inst;
15386
15406
  }
15387
- Object.defineProperty(_, "init", { value: init });
15407
+ Object.defineProperty(_, "init", { value: init2 });
15388
15408
  Object.defineProperty(_, Symbol.hasInstance, {
15389
15409
  value: (inst) => {
15390
15410
  if (params?.Parent && inst instanceof params.Parent)
@@ -32360,7 +32380,7 @@ var Protocol = class {
32360
32380
  return;
32361
32381
  }
32362
32382
  const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
32363
- await new Promise((resolve3) => setTimeout(resolve3, pollInterval));
32383
+ await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
32364
32384
  options?.signal?.throwIfAborted();
32365
32385
  }
32366
32386
  } catch (error48) {
@@ -32377,7 +32397,7 @@ var Protocol = class {
32377
32397
  */
32378
32398
  request(request, resultSchema, options) {
32379
32399
  const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
32380
- return new Promise((resolve3, reject) => {
32400
+ return new Promise((resolve4, reject) => {
32381
32401
  const earlyReject = (error48) => {
32382
32402
  reject(error48);
32383
32403
  };
@@ -32455,7 +32475,7 @@ var Protocol = class {
32455
32475
  if (!parseResult.success) {
32456
32476
  reject(parseResult.error);
32457
32477
  } else {
32458
- resolve3(parseResult.data);
32478
+ resolve4(parseResult.data);
32459
32479
  }
32460
32480
  } catch (error48) {
32461
32481
  reject(error48);
@@ -32716,12 +32736,12 @@ var Protocol = class {
32716
32736
  }
32717
32737
  } catch {
32718
32738
  }
32719
- return new Promise((resolve3, reject) => {
32739
+ return new Promise((resolve4, reject) => {
32720
32740
  if (signal.aborted) {
32721
32741
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
32722
32742
  return;
32723
32743
  }
32724
- const timeoutId = setTimeout(resolve3, interval);
32744
+ const timeoutId = setTimeout(resolve4, interval);
32725
32745
  signal.addEventListener("abort", () => {
32726
32746
  clearTimeout(timeoutId);
32727
32747
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
@@ -33680,7 +33700,7 @@ var McpServer = class {
33680
33700
  let task = createTaskResult.task;
33681
33701
  const pollInterval = task.pollInterval ?? 5e3;
33682
33702
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
33683
- await new Promise((resolve3) => setTimeout(resolve3, pollInterval));
33703
+ await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
33684
33704
  const updatedTask = await extra.taskStore.getTask(taskId);
33685
33705
  if (!updatedTask) {
33686
33706
  throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
@@ -34323,12 +34343,12 @@ var StdioServerTransport = class {
34323
34343
  this.onclose?.();
34324
34344
  }
34325
34345
  send(message) {
34326
- return new Promise((resolve3) => {
34346
+ return new Promise((resolve4) => {
34327
34347
  const json3 = serializeMessage(message);
34328
34348
  if (this._stdout.write(json3)) {
34329
- resolve3();
34349
+ resolve4();
34330
34350
  } else {
34331
- this._stdout.once("drain", resolve3);
34351
+ this._stdout.once("drain", resolve4);
34332
34352
  }
34333
34353
  });
34334
34354
  }
@@ -34368,7 +34388,7 @@ function text(data) {
34368
34388
  async function mcp() {
34369
34389
  const server = new McpServer({
34370
34390
  name: "reporting-bi",
34371
- version: "0.0.13"
34391
+ version: "0.0.15"
34372
34392
  });
34373
34393
  server.tool(
34374
34394
  "status",
@@ -34805,6 +34825,32 @@ async function mcp() {
34805
34825
  await server.connect(transport);
34806
34826
  }
34807
34827
 
34828
+ // src/commands/init.ts
34829
+ function init(args) {
34830
+ const { flags } = parseArgs(args);
34831
+ const creds = loadCredentials();
34832
+ const domain2 = flags.connection || creds.active;
34833
+ if (!domain2) {
34834
+ console.error("No connection specified. Use --connection <domain> or login first.");
34835
+ process.exit(1);
34836
+ }
34837
+ if (!creds.connections[domain2]) {
34838
+ console.error(`Not logged in to "${domain2}". Run "rpbi login ${domain2}" first.`);
34839
+ process.exit(1);
34840
+ }
34841
+ const existing = readManifest(process.cwd());
34842
+ const manifest = {
34843
+ domain: domain2,
34844
+ accounting: flags.accounting ? parseInt(flags.accounting) : existing?.accounting ?? creds.connections[domain2].accounting ?? 0,
34845
+ ...existing?.pulledAt && { pulledAt: existing.pulledAt },
34846
+ ...existing?.threads && { threads: existing.threads }
34847
+ };
34848
+ writeManifest(process.cwd(), manifest);
34849
+ console.log(`Initialized .rpbi/manifest.json`);
34850
+ console.log(` domain: ${manifest.domain}`);
34851
+ console.log(` accounting: ${manifest.accounting || "not set"}`);
34852
+ }
34853
+
34808
34854
  // src/autoupdate.ts
34809
34855
  var fs6 = __toESM(require("node:fs"));
34810
34856
  var path4 = __toESM(require("node:path"));
@@ -34827,26 +34873,26 @@ function saveUpdateCheck(data) {
34827
34873
  fs6.writeFileSync(UPDATE_CHECK_FILE, JSON.stringify(data, null, 2));
34828
34874
  }
34829
34875
  function fetchLatestVersion() {
34830
- return new Promise((resolve3) => {
34876
+ return new Promise((resolve4) => {
34831
34877
  const req = https.get(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { timeout: 5e3 }, (res) => {
34832
34878
  if (res.statusCode !== 200) {
34833
34879
  res.resume();
34834
- return resolve3(null);
34880
+ return resolve4(null);
34835
34881
  }
34836
34882
  let body = "";
34837
34883
  res.on("data", (chunk) => body += chunk);
34838
34884
  res.on("end", () => {
34839
34885
  try {
34840
- resolve3(JSON.parse(body).version ?? null);
34886
+ resolve4(JSON.parse(body).version ?? null);
34841
34887
  } catch {
34842
- resolve3(null);
34888
+ resolve4(null);
34843
34889
  }
34844
34890
  });
34845
34891
  });
34846
- req.on("error", () => resolve3(null));
34892
+ req.on("error", () => resolve4(null));
34847
34893
  req.on("timeout", () => {
34848
34894
  req.destroy();
34849
- resolve3(null);
34895
+ resolve4(null);
34850
34896
  });
34851
34897
  });
34852
34898
  }
@@ -34870,13 +34916,28 @@ async function checkForUpdate() {
34870
34916
  saveUpdateCheck({ lastCheck: now });
34871
34917
  const latest = await fetchLatestVersion();
34872
34918
  if (!latest) return;
34873
- if (!isNewer(latest, "0.0.13")) return;
34874
- console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.0.13"} \u2192 ${latest}...\x1B[0m`);
34919
+ if (!isNewer(latest, "0.0.15")) return;
34920
+ console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.0.15"} \u2192 ${latest}...\x1B[0m`);
34875
34921
  (0, import_node_child_process2.execSync)(`npm install -g ${PACKAGE_NAME}@${latest}`, { stdio: "inherit" });
34876
34922
  console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
34877
34923
  } catch {
34878
34924
  }
34879
34925
  }
34926
+ async function forceUpdate() {
34927
+ const latest = await fetchLatestVersion();
34928
+ if (!latest) {
34929
+ console.error("Could not fetch latest version from npm.");
34930
+ process.exit(1);
34931
+ }
34932
+ if (!isNewer(latest, "0.0.15")) {
34933
+ console.log(`Already up to date (${"0.0.15"}).`);
34934
+ return;
34935
+ }
34936
+ console.log(`Updating ${PACKAGE_NAME} ${"0.0.15"} \u2192 ${latest}...`);
34937
+ (0, import_node_child_process2.execSync)(`npm install -g ${PACKAGE_NAME}@${latest}`, { stdio: "inherit" });
34938
+ console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
34939
+ saveUpdateCheck({ lastCheck: Date.now() });
34940
+ }
34880
34941
 
34881
34942
  // USAGE.md
34882
34943
  var USAGE_default = `Reporting.bi CLI
@@ -34888,6 +34949,9 @@ Commands:
34888
34949
  logout [domain] Logout and revoke tokens (default: active connection)
34889
34950
  use <domain> [--accounting <id>] Switch active connection and/or set accounting
34890
34951
  status Show all connections and active status
34952
+ init [--connection <domain>] [--accounting <id>] Initialize .rpbi/config.json in current directory
34953
+ update Force update to latest version from npm
34954
+ mcp Start MCP server (for AI agents, stdio transport)
34891
34955
 
34892
34956
  Accounting:
34893
34957
  accounting list List available accountings
@@ -34999,7 +35063,7 @@ Examples:
34999
35063
  (async () => {
35000
35064
  const [command, ...args] = process.argv.slice(2);
35001
35065
  if (command === "--version" || command === "-v") {
35002
- console.log("0.0.13");
35066
+ console.log("0.0.15");
35003
35067
  return;
35004
35068
  }
35005
35069
  await checkForUpdate();
@@ -35055,6 +35119,12 @@ Examples:
35055
35119
  case "mcp":
35056
35120
  mcp();
35057
35121
  break;
35122
+ case "update":
35123
+ forceUpdate();
35124
+ break;
35125
+ case "init":
35126
+ init(args);
35127
+ break;
35058
35128
  default:
35059
35129
  console.log(USAGE_default);
35060
35130
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporting-bi/cli",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Reporting.bi CLI — command-line interface for the Reporting.bi platform",
6
6
  "main": "./dist/index.js",