@workbuddy/cli-edge 1.0.3 → 1.0.5
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 +48 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2141,6 +2141,9 @@ var {
|
|
|
2141
2141
|
Help
|
|
2142
2142
|
} = import__.default;
|
|
2143
2143
|
|
|
2144
|
+
// src/index.ts
|
|
2145
|
+
import * as readline from "readline";
|
|
2146
|
+
|
|
2144
2147
|
// src/secure-store.ts
|
|
2145
2148
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
2146
2149
|
import * as fs from "fs";
|
|
@@ -2539,7 +2542,12 @@ function buildHttpErrorMessage(status, contentType, buffer) {
|
|
|
2539
2542
|
if (contentType.includes("application/json")) {
|
|
2540
2543
|
try {
|
|
2541
2544
|
const parsed = JSON.parse(text);
|
|
2542
|
-
const
|
|
2545
|
+
const errorObj = parsed?.error;
|
|
2546
|
+
if (errorObj && typeof errorObj === "object") {
|
|
2547
|
+
const msg = errorObj.message ?? errorObj.code ?? JSON.stringify(errorObj);
|
|
2548
|
+
return "Request failed with status " + status + ": " + msg;
|
|
2549
|
+
}
|
|
2550
|
+
const detail = parsed?.message ?? (typeof errorObj === "string" ? errorObj : null) ?? parsed?.details;
|
|
2543
2551
|
return detail ? "Request failed with status " + status + ": " + detail : "Request failed with status " + status + ": " + text;
|
|
2544
2552
|
} catch {
|
|
2545
2553
|
return "Request failed with status " + status + ": " + text;
|
|
@@ -7967,6 +7975,34 @@ function isPlainObject2(value) {
|
|
|
7967
7975
|
|
|
7968
7976
|
// src/index.ts
|
|
7969
7977
|
var OUTPUT_FORMATS = new Set(["json", "table", "raw"]);
|
|
7978
|
+
function prompt(question, mask = false) {
|
|
7979
|
+
return new Promise((resolve) => {
|
|
7980
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
7981
|
+
if (mask) {
|
|
7982
|
+
const stdout = process.stdout;
|
|
7983
|
+
const onData = (char) => {
|
|
7984
|
+
const c = char.toString();
|
|
7985
|
+
if (c === `
|
|
7986
|
+
` || c === "\r" || c === "\x04")
|
|
7987
|
+
return;
|
|
7988
|
+
stdout.clearLine(0);
|
|
7989
|
+
stdout.cursorTo(0);
|
|
7990
|
+
stdout.write(question + "*".repeat(rl.line.length));
|
|
7991
|
+
};
|
|
7992
|
+
process.stdin.on("data", onData);
|
|
7993
|
+
rl.question(question, (answer) => {
|
|
7994
|
+
process.stdin.removeListener("data", onData);
|
|
7995
|
+
rl.close();
|
|
7996
|
+
resolve(answer.trim());
|
|
7997
|
+
});
|
|
7998
|
+
} else {
|
|
7999
|
+
rl.question(question, (answer) => {
|
|
8000
|
+
rl.close();
|
|
8001
|
+
resolve(answer.trim());
|
|
8002
|
+
});
|
|
8003
|
+
}
|
|
8004
|
+
});
|
|
8005
|
+
}
|
|
7970
8006
|
async function main() {
|
|
7971
8007
|
const program2 = new Command;
|
|
7972
8008
|
program2.name("workbuddy").description("WorkBuddy CLI").version(packageVersion);
|
|
@@ -7976,12 +8012,19 @@ async function main() {
|
|
|
7976
8012
|
}
|
|
7977
8013
|
function registerAuthCommands(program2) {
|
|
7978
8014
|
const auth = program2.command("auth").description("Manage WorkBuddy CLI credentials");
|
|
7979
|
-
auth.command("login").description("Store WorkBuddy API credentials locally").
|
|
8015
|
+
auth.command("login").description("Store WorkBuddy API credentials locally").option("--base-url <url>", "Tenant base URL (required)").option("--client-id <id>", "OAuth2 client ID (required)").option("--client-secret <secret>", "OAuth2 client secret (required, prompted if omitted)").option("--api-version <version>", "WorkBuddy API version header", "2026-01").option("--profile <name>", "Profile name", getActiveProfileName()).action(async (options) => {
|
|
8016
|
+
const baseUrl = options.baseUrl || await prompt("Tenant URL (e.g. https://yourcompany.workbuddy.com): ");
|
|
8017
|
+
const clientId = options.clientId || await prompt("Client ID: ");
|
|
8018
|
+
const clientSecret = options.clientSecret || await prompt("Client Secret: ", true);
|
|
8019
|
+
if (!baseUrl || !clientId || !clientSecret) {
|
|
8020
|
+
throw new Error("base-url, client-id, and client-secret are required");
|
|
8021
|
+
}
|
|
8022
|
+
console.log("");
|
|
7980
8023
|
const config = resolveConfig({
|
|
7981
8024
|
profile: options.profile,
|
|
7982
|
-
baseUrl
|
|
7983
|
-
clientId
|
|
7984
|
-
clientSecret
|
|
8025
|
+
baseUrl,
|
|
8026
|
+
clientId,
|
|
8027
|
+
clientSecret,
|
|
7985
8028
|
apiVersion: options.apiVersion,
|
|
7986
8029
|
accessToken: undefined
|
|
7987
8030
|
});
|