@reporting-bi/cli 0.0.14 → 0.0.16
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.
- package/dist/index.js +112 -41
- 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 =
|
|
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
|
|
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
|
|
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:
|
|
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,
|
|
9611
|
+
async fetchWithAuth(url2, init2 = {}) {
|
|
9612
9612
|
const authInit = await this.getAuthInit();
|
|
9613
9613
|
return fetch(url2, {
|
|
9614
|
-
...
|
|
9614
|
+
...init2,
|
|
9615
9615
|
...authInit,
|
|
9616
9616
|
headers: {
|
|
9617
|
-
...
|
|
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
|
-
|
|
9806
|
-
|
|
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((
|
|
10131
|
+
return new Promise((resolve4) => {
|
|
10112
10132
|
let timeout;
|
|
10113
10133
|
const done = (result) => {
|
|
10114
10134
|
clearTimeout(timeout);
|
|
10115
10135
|
server.close();
|
|
10116
|
-
|
|
10136
|
+
resolve4(result);
|
|
10117
10137
|
};
|
|
10118
10138
|
const server = http.createServer((req, res) => {
|
|
10119
10139
|
const url2 = new URL(req.url || "", "http://localhost");
|
|
@@ -10174,14 +10194,21 @@ async function logout(domain2) {
|
|
|
10174
10194
|
// src/commands/status.ts
|
|
10175
10195
|
function status() {
|
|
10176
10196
|
const creds = loadCredentials();
|
|
10197
|
+
const local = findLocalConfig();
|
|
10177
10198
|
const domains = Object.keys(creds.connections);
|
|
10199
|
+
if (local) {
|
|
10200
|
+
console.log(`Local config (.rpbi/manifest.json):`);
|
|
10201
|
+
console.log(` domain: ${local.domain}`);
|
|
10202
|
+
console.log(` accounting: ${local.accounting ?? "not set"}`);
|
|
10203
|
+
console.log();
|
|
10204
|
+
}
|
|
10178
10205
|
if (domains.length === 0) {
|
|
10179
10206
|
console.log("Not logged in.");
|
|
10180
10207
|
return;
|
|
10181
10208
|
}
|
|
10182
10209
|
for (const domain2 of domains) {
|
|
10183
10210
|
const tokens = creds.connections[domain2];
|
|
10184
|
-
const isActive = creds.active === domain2;
|
|
10211
|
+
const isActive = local ? local.domain === domain2 : creds.active === domain2;
|
|
10185
10212
|
const now = Math.floor(Date.now() / 1e3);
|
|
10186
10213
|
const expiresIn = tokens.expires_at - now;
|
|
10187
10214
|
let expiry;
|
|
@@ -10273,11 +10300,11 @@ async function readContent(flags) {
|
|
|
10273
10300
|
return flags.content;
|
|
10274
10301
|
}
|
|
10275
10302
|
if (!process.stdin.isTTY) {
|
|
10276
|
-
return new Promise((
|
|
10303
|
+
return new Promise((resolve4) => {
|
|
10277
10304
|
let data = "";
|
|
10278
10305
|
process.stdin.setEncoding("utf-8");
|
|
10279
10306
|
process.stdin.on("data", (chunk) => data += chunk);
|
|
10280
|
-
process.stdin.on("end", () =>
|
|
10307
|
+
process.stdin.on("end", () => resolve4(data));
|
|
10281
10308
|
});
|
|
10282
10309
|
}
|
|
10283
10310
|
console.error("No content provided. Use --file, --content, or pipe to stdin.");
|
|
@@ -15345,7 +15372,7 @@ var NEVER = Object.freeze({
|
|
|
15345
15372
|
});
|
|
15346
15373
|
// @__NO_SIDE_EFFECTS__
|
|
15347
15374
|
function $constructor(name, initializer3, params) {
|
|
15348
|
-
function
|
|
15375
|
+
function init2(inst, def2) {
|
|
15349
15376
|
if (!inst._zod) {
|
|
15350
15377
|
Object.defineProperty(inst, "_zod", {
|
|
15351
15378
|
value: {
|
|
@@ -15377,14 +15404,14 @@ function $constructor(name, initializer3, params) {
|
|
|
15377
15404
|
function _(def2) {
|
|
15378
15405
|
var _a2;
|
|
15379
15406
|
const inst = params?.Parent ? new Definition() : this;
|
|
15380
|
-
|
|
15407
|
+
init2(inst, def2);
|
|
15381
15408
|
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
15382
15409
|
for (const fn of inst._zod.deferred) {
|
|
15383
15410
|
fn();
|
|
15384
15411
|
}
|
|
15385
15412
|
return inst;
|
|
15386
15413
|
}
|
|
15387
|
-
Object.defineProperty(_, "init", { value:
|
|
15414
|
+
Object.defineProperty(_, "init", { value: init2 });
|
|
15388
15415
|
Object.defineProperty(_, Symbol.hasInstance, {
|
|
15389
15416
|
value: (inst) => {
|
|
15390
15417
|
if (params?.Parent && inst instanceof params.Parent)
|
|
@@ -32360,7 +32387,7 @@ var Protocol = class {
|
|
|
32360
32387
|
return;
|
|
32361
32388
|
}
|
|
32362
32389
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
32363
|
-
await new Promise((
|
|
32390
|
+
await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
|
|
32364
32391
|
options?.signal?.throwIfAborted();
|
|
32365
32392
|
}
|
|
32366
32393
|
} catch (error48) {
|
|
@@ -32377,7 +32404,7 @@ var Protocol = class {
|
|
|
32377
32404
|
*/
|
|
32378
32405
|
request(request, resultSchema, options) {
|
|
32379
32406
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
32380
|
-
return new Promise((
|
|
32407
|
+
return new Promise((resolve4, reject) => {
|
|
32381
32408
|
const earlyReject = (error48) => {
|
|
32382
32409
|
reject(error48);
|
|
32383
32410
|
};
|
|
@@ -32455,7 +32482,7 @@ var Protocol = class {
|
|
|
32455
32482
|
if (!parseResult.success) {
|
|
32456
32483
|
reject(parseResult.error);
|
|
32457
32484
|
} else {
|
|
32458
|
-
|
|
32485
|
+
resolve4(parseResult.data);
|
|
32459
32486
|
}
|
|
32460
32487
|
} catch (error48) {
|
|
32461
32488
|
reject(error48);
|
|
@@ -32716,12 +32743,12 @@ var Protocol = class {
|
|
|
32716
32743
|
}
|
|
32717
32744
|
} catch {
|
|
32718
32745
|
}
|
|
32719
|
-
return new Promise((
|
|
32746
|
+
return new Promise((resolve4, reject) => {
|
|
32720
32747
|
if (signal.aborted) {
|
|
32721
32748
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
32722
32749
|
return;
|
|
32723
32750
|
}
|
|
32724
|
-
const timeoutId = setTimeout(
|
|
32751
|
+
const timeoutId = setTimeout(resolve4, interval);
|
|
32725
32752
|
signal.addEventListener("abort", () => {
|
|
32726
32753
|
clearTimeout(timeoutId);
|
|
32727
32754
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -33680,7 +33707,7 @@ var McpServer = class {
|
|
|
33680
33707
|
let task = createTaskResult.task;
|
|
33681
33708
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
33682
33709
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
33683
|
-
await new Promise((
|
|
33710
|
+
await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
|
|
33684
33711
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
33685
33712
|
if (!updatedTask) {
|
|
33686
33713
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -34323,12 +34350,12 @@ var StdioServerTransport = class {
|
|
|
34323
34350
|
this.onclose?.();
|
|
34324
34351
|
}
|
|
34325
34352
|
send(message) {
|
|
34326
|
-
return new Promise((
|
|
34353
|
+
return new Promise((resolve4) => {
|
|
34327
34354
|
const json3 = serializeMessage(message);
|
|
34328
34355
|
if (this._stdout.write(json3)) {
|
|
34329
|
-
|
|
34356
|
+
resolve4();
|
|
34330
34357
|
} else {
|
|
34331
|
-
this._stdout.once("drain",
|
|
34358
|
+
this._stdout.once("drain", resolve4);
|
|
34332
34359
|
}
|
|
34333
34360
|
});
|
|
34334
34361
|
}
|
|
@@ -34368,7 +34395,7 @@ function text(data) {
|
|
|
34368
34395
|
async function mcp() {
|
|
34369
34396
|
const server = new McpServer({
|
|
34370
34397
|
name: "reporting-bi",
|
|
34371
|
-
version: "0.0.
|
|
34398
|
+
version: "0.0.16"
|
|
34372
34399
|
});
|
|
34373
34400
|
server.tool(
|
|
34374
34401
|
"status",
|
|
@@ -34805,6 +34832,32 @@ async function mcp() {
|
|
|
34805
34832
|
await server.connect(transport);
|
|
34806
34833
|
}
|
|
34807
34834
|
|
|
34835
|
+
// src/commands/init.ts
|
|
34836
|
+
function init(args) {
|
|
34837
|
+
const { flags } = parseArgs(args);
|
|
34838
|
+
const creds = loadCredentials();
|
|
34839
|
+
const domain2 = flags.connection || creds.active;
|
|
34840
|
+
if (!domain2) {
|
|
34841
|
+
console.error("No connection specified. Use --connection <domain> or login first.");
|
|
34842
|
+
process.exit(1);
|
|
34843
|
+
}
|
|
34844
|
+
if (!creds.connections[domain2]) {
|
|
34845
|
+
console.error(`Not logged in to "${domain2}". Run "rpbi login ${domain2}" first.`);
|
|
34846
|
+
process.exit(1);
|
|
34847
|
+
}
|
|
34848
|
+
const existing = readManifest(process.cwd());
|
|
34849
|
+
const manifest = {
|
|
34850
|
+
domain: domain2,
|
|
34851
|
+
accounting: flags.accounting ? parseInt(flags.accounting) : existing?.accounting ?? creds.connections[domain2].accounting ?? 0,
|
|
34852
|
+
...existing?.pulledAt && { pulledAt: existing.pulledAt },
|
|
34853
|
+
...existing?.threads && { threads: existing.threads }
|
|
34854
|
+
};
|
|
34855
|
+
writeManifest(process.cwd(), manifest);
|
|
34856
|
+
console.log(`Initialized .rpbi/manifest.json`);
|
|
34857
|
+
console.log(` domain: ${manifest.domain}`);
|
|
34858
|
+
console.log(` accounting: ${manifest.accounting || "not set"}`);
|
|
34859
|
+
}
|
|
34860
|
+
|
|
34808
34861
|
// src/autoupdate.ts
|
|
34809
34862
|
var fs6 = __toESM(require("node:fs"));
|
|
34810
34863
|
var path4 = __toESM(require("node:path"));
|
|
@@ -34815,6 +34868,20 @@ var CONFIG_DIR2 = path4.join(os2.homedir(), ".config", "reporting-bi");
|
|
|
34815
34868
|
var UPDATE_CHECK_FILE = path4.join(CONFIG_DIR2, "update-check.json");
|
|
34816
34869
|
var CHECK_INTERVAL = 60 * 60 * 1e3;
|
|
34817
34870
|
var PACKAGE_NAME = "@reporting-bi/cli";
|
|
34871
|
+
var INSTALL_PREFIX = detectPrefix();
|
|
34872
|
+
function detectPrefix() {
|
|
34873
|
+
const binDir = path4.dirname(process.argv[1]);
|
|
34874
|
+
const libIndex = binDir.indexOf(path4.join("lib", "node_modules"));
|
|
34875
|
+
if (libIndex > 0) {
|
|
34876
|
+
const prefix = binDir.slice(0, libIndex - 1);
|
|
34877
|
+
if (prefix !== "/usr" && prefix !== "/usr/local") return prefix;
|
|
34878
|
+
}
|
|
34879
|
+
return null;
|
|
34880
|
+
}
|
|
34881
|
+
function npmInstallCmd(version2) {
|
|
34882
|
+
const prefix = INSTALL_PREFIX ? ` --prefix "${INSTALL_PREFIX}"` : "";
|
|
34883
|
+
return `npm install -g${prefix} ${PACKAGE_NAME}@${version2}`;
|
|
34884
|
+
}
|
|
34818
34885
|
function loadUpdateCheck() {
|
|
34819
34886
|
try {
|
|
34820
34887
|
return JSON.parse(fs6.readFileSync(UPDATE_CHECK_FILE, "utf-8"));
|
|
@@ -34827,26 +34894,26 @@ function saveUpdateCheck(data) {
|
|
|
34827
34894
|
fs6.writeFileSync(UPDATE_CHECK_FILE, JSON.stringify(data, null, 2));
|
|
34828
34895
|
}
|
|
34829
34896
|
function fetchLatestVersion() {
|
|
34830
|
-
return new Promise((
|
|
34897
|
+
return new Promise((resolve4) => {
|
|
34831
34898
|
const req = https.get(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { timeout: 5e3 }, (res) => {
|
|
34832
34899
|
if (res.statusCode !== 200) {
|
|
34833
34900
|
res.resume();
|
|
34834
|
-
return
|
|
34901
|
+
return resolve4(null);
|
|
34835
34902
|
}
|
|
34836
34903
|
let body = "";
|
|
34837
34904
|
res.on("data", (chunk) => body += chunk);
|
|
34838
34905
|
res.on("end", () => {
|
|
34839
34906
|
try {
|
|
34840
|
-
|
|
34907
|
+
resolve4(JSON.parse(body).version ?? null);
|
|
34841
34908
|
} catch {
|
|
34842
|
-
|
|
34909
|
+
resolve4(null);
|
|
34843
34910
|
}
|
|
34844
34911
|
});
|
|
34845
34912
|
});
|
|
34846
|
-
req.on("error", () =>
|
|
34913
|
+
req.on("error", () => resolve4(null));
|
|
34847
34914
|
req.on("timeout", () => {
|
|
34848
34915
|
req.destroy();
|
|
34849
|
-
|
|
34916
|
+
resolve4(null);
|
|
34850
34917
|
});
|
|
34851
34918
|
});
|
|
34852
34919
|
}
|
|
@@ -34870,9 +34937,9 @@ async function checkForUpdate() {
|
|
|
34870
34937
|
saveUpdateCheck({ lastCheck: now });
|
|
34871
34938
|
const latest = await fetchLatestVersion();
|
|
34872
34939
|
if (!latest) return;
|
|
34873
|
-
if (!isNewer(latest, "0.0.
|
|
34874
|
-
console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.0.
|
|
34875
|
-
(0, import_node_child_process2.execSync)(
|
|
34940
|
+
if (!isNewer(latest, "0.0.16")) return;
|
|
34941
|
+
console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.0.16"} \u2192 ${latest}...\x1B[0m`);
|
|
34942
|
+
(0, import_node_child_process2.execSync)(npmInstallCmd(latest), { stdio: "inherit" });
|
|
34876
34943
|
console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
|
|
34877
34944
|
} catch {
|
|
34878
34945
|
}
|
|
@@ -34883,12 +34950,12 @@ async function forceUpdate() {
|
|
|
34883
34950
|
console.error("Could not fetch latest version from npm.");
|
|
34884
34951
|
process.exit(1);
|
|
34885
34952
|
}
|
|
34886
|
-
if (!isNewer(latest, "0.0.
|
|
34887
|
-
console.log(`Already up to date (${"0.0.
|
|
34953
|
+
if (!isNewer(latest, "0.0.16")) {
|
|
34954
|
+
console.log(`Already up to date (${"0.0.16"}).`);
|
|
34888
34955
|
return;
|
|
34889
34956
|
}
|
|
34890
|
-
console.log(`Updating ${PACKAGE_NAME} ${"0.0.
|
|
34891
|
-
(0, import_node_child_process2.execSync)(
|
|
34957
|
+
console.log(`Updating ${PACKAGE_NAME} ${"0.0.16"} \u2192 ${latest}...`);
|
|
34958
|
+
(0, import_node_child_process2.execSync)(npmInstallCmd(latest), { stdio: "inherit" });
|
|
34892
34959
|
console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
|
|
34893
34960
|
saveUpdateCheck({ lastCheck: Date.now() });
|
|
34894
34961
|
}
|
|
@@ -34903,6 +34970,7 @@ Commands:
|
|
|
34903
34970
|
logout [domain] Logout and revoke tokens (default: active connection)
|
|
34904
34971
|
use <domain> [--accounting <id>] Switch active connection and/or set accounting
|
|
34905
34972
|
status Show all connections and active status
|
|
34973
|
+
init [--connection <domain>] [--accounting <id>] Initialize .rpbi/config.json in current directory
|
|
34906
34974
|
update Force update to latest version from npm
|
|
34907
34975
|
mcp Start MCP server (for AI agents, stdio transport)
|
|
34908
34976
|
|
|
@@ -35016,7 +35084,7 @@ Examples:
|
|
|
35016
35084
|
(async () => {
|
|
35017
35085
|
const [command, ...args] = process.argv.slice(2);
|
|
35018
35086
|
if (command === "--version" || command === "-v") {
|
|
35019
|
-
console.log("0.0.
|
|
35087
|
+
console.log("0.0.16");
|
|
35020
35088
|
return;
|
|
35021
35089
|
}
|
|
35022
35090
|
await checkForUpdate();
|
|
@@ -35075,6 +35143,9 @@ Examples:
|
|
|
35075
35143
|
case "update":
|
|
35076
35144
|
forceUpdate();
|
|
35077
35145
|
break;
|
|
35146
|
+
case "init":
|
|
35147
|
+
init(args);
|
|
35148
|
+
break;
|
|
35078
35149
|
default:
|
|
35079
35150
|
console.log(USAGE_default);
|
|
35080
35151
|
break;
|