@construct-space/cli 1.4.1 → 1.4.3
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 +77 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2873,6 +2873,63 @@ var init_auth = __esm(() => {
|
|
|
2873
2873
|
init_appdir();
|
|
2874
2874
|
});
|
|
2875
2875
|
|
|
2876
|
+
// src/commands/whoami.ts
|
|
2877
|
+
var exports_whoami = {};
|
|
2878
|
+
__export(exports_whoami, {
|
|
2879
|
+
whoami: () => whoami
|
|
2880
|
+
});
|
|
2881
|
+
async function whoami() {
|
|
2882
|
+
let creds;
|
|
2883
|
+
try {
|
|
2884
|
+
creds = load2();
|
|
2885
|
+
} catch {
|
|
2886
|
+
console.error(source_default.red("Not signed in."));
|
|
2887
|
+
console.error(source_default.dim("Run 'construct login' first."));
|
|
2888
|
+
process.exit(1);
|
|
2889
|
+
}
|
|
2890
|
+
const res = await fetch(ACCOUNTS_SCOPE_URL2, {
|
|
2891
|
+
headers: { Authorization: `Bearer ${creds.token}`, Accept: "application/json" }
|
|
2892
|
+
});
|
|
2893
|
+
if (!res.ok) {
|
|
2894
|
+
console.error(source_default.red(`Scope lookup failed (${res.status}).`));
|
|
2895
|
+
console.error(source_default.dim("Token may be expired. Try: construct login"));
|
|
2896
|
+
process.exit(1);
|
|
2897
|
+
}
|
|
2898
|
+
const s = await res.json();
|
|
2899
|
+
if (!s.authenticated || !s.user) {
|
|
2900
|
+
console.error(source_default.red("Token rejected."));
|
|
2901
|
+
process.exit(1);
|
|
2902
|
+
}
|
|
2903
|
+
const name = [s.user.first_name, s.user.last_name].filter(Boolean).join(" ") || s.user.username || "";
|
|
2904
|
+
console.log(source_default.bold(s.user.email || name));
|
|
2905
|
+
if (name && name !== s.user.email)
|
|
2906
|
+
console.log(source_default.dim(" " + name));
|
|
2907
|
+
if (s.user.uuid)
|
|
2908
|
+
console.log(source_default.dim(" user " + s.user.uuid));
|
|
2909
|
+
if (s.scope === "org" && s.org) {
|
|
2910
|
+
console.log();
|
|
2911
|
+
console.log(source_default.cyan("Organization"));
|
|
2912
|
+
console.log(` ${s.org.name || s.org.slug || s.org.id}`);
|
|
2913
|
+
if (s.org.id)
|
|
2914
|
+
console.log(source_default.dim(" " + s.org.id));
|
|
2915
|
+
if (s.roles && s.roles.length)
|
|
2916
|
+
console.log(source_default.dim(" roles: " + s.roles.join(", ")));
|
|
2917
|
+
} else {
|
|
2918
|
+
console.log();
|
|
2919
|
+
console.log(source_default.cyan("Scope"));
|
|
2920
|
+
console.log(" Personal (no organization)");
|
|
2921
|
+
console.log(source_default.dim(" Switch to an org at https://my.construct.space"));
|
|
2922
|
+
}
|
|
2923
|
+
if (s.developer)
|
|
2924
|
+
console.log(source_default.dim(`
|
|
2925
|
+
developer capability: enabled`));
|
|
2926
|
+
}
|
|
2927
|
+
var ACCOUNTS_SCOPE_URL2 = "https://my.construct.space/api/accounts/me/scope";
|
|
2928
|
+
var init_whoami = __esm(() => {
|
|
2929
|
+
init_source();
|
|
2930
|
+
init_auth();
|
|
2931
|
+
});
|
|
2932
|
+
|
|
2876
2933
|
// src/lib/graphClient.ts
|
|
2877
2934
|
function graphBaseURL() {
|
|
2878
2935
|
return process.env.GRAPH_URL || "https://graph.construct.space";
|
|
@@ -2897,10 +2954,6 @@ async function graphRequest(opts) {
|
|
|
2897
2954
|
Authorization: `Bearer ${creds.token}`,
|
|
2898
2955
|
"Content-Type": "application/json"
|
|
2899
2956
|
};
|
|
2900
|
-
if (creds.user?.id)
|
|
2901
|
-
headers["X-Auth-User-ID"] = creds.user.id;
|
|
2902
|
-
if (opts.orgId)
|
|
2903
|
-
headers["X-Auth-Org-ID"] = opts.orgId;
|
|
2904
2957
|
const resp = await fetch(graphBaseURL() + opts.path, {
|
|
2905
2958
|
method: opts.method || "GET",
|
|
2906
2959
|
headers,
|
|
@@ -2922,11 +2975,7 @@ async function graphRequest(opts) {
|
|
|
2922
2975
|
return JSON.parse(text);
|
|
2923
2976
|
}
|
|
2924
2977
|
function requireOrgId(explicit) {
|
|
2925
|
-
|
|
2926
|
-
if (!org) {
|
|
2927
|
-
throw new Error("org context required. Pass --org <id> or set CONSTRUCT_ORG_ID. " + "Find your org id on the profile page or via accounts /api/me/scope.");
|
|
2928
|
-
}
|
|
2929
|
-
return org;
|
|
2978
|
+
return resolveOrgId(explicit);
|
|
2930
2979
|
}
|
|
2931
2980
|
var init_graphClient = __esm(() => {
|
|
2932
2981
|
init_auth();
|
|
@@ -10436,15 +10485,30 @@ function update() {
|
|
|
10436
10485
|
const rt = detect();
|
|
10437
10486
|
try {
|
|
10438
10487
|
if (rt.name === "bun") {
|
|
10439
|
-
|
|
10488
|
+
try {
|
|
10489
|
+
execSync5("bun pm cache rm", { stdio: "inherit" });
|
|
10490
|
+
} catch {}
|
|
10491
|
+
execSync5(`bun install -g ${PKG_NAME}@${latest}`, { stdio: "inherit" });
|
|
10440
10492
|
} else {
|
|
10441
|
-
execSync5(`npm install -g ${PKG_NAME}
|
|
10493
|
+
execSync5(`npm install -g --prefer-online ${PKG_NAME}@${latest}`, { stdio: "inherit" });
|
|
10442
10494
|
}
|
|
10443
|
-
console.log(source_default.green(`Updated to v${latest}`));
|
|
10444
10495
|
} catch (err) {
|
|
10445
10496
|
console.error(source_default.red(`Update failed: ${err.message}`));
|
|
10446
10497
|
process.exit(1);
|
|
10447
10498
|
}
|
|
10499
|
+
try {
|
|
10500
|
+
const installed = execSync5(`${rt.name === "bun" ? "bun" : "npm"} ${rt.name === "bun" ? "pm ls -g" : "ls -g --depth=0"} ${PKG_NAME}`, { encoding: "utf-8" });
|
|
10501
|
+
const match = installed.match(new RegExp(PKG_NAME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "@(\\d[^\\s]*)"));
|
|
10502
|
+
const resolved = match ? match[1] : "unknown";
|
|
10503
|
+
if (resolved && resolved !== latest) {
|
|
10504
|
+
console.warn(source_default.yellow(`Installed ${resolved} but expected ${latest}.`));
|
|
10505
|
+
console.warn(source_default.dim(" Try: bun pm cache rm && bun install -g " + PKG_NAME + "@" + latest));
|
|
10506
|
+
return;
|
|
10507
|
+
}
|
|
10508
|
+
console.log(source_default.green(`Updated to v${latest}`));
|
|
10509
|
+
} catch {
|
|
10510
|
+
console.log(source_default.green(`Updated to v${latest}`));
|
|
10511
|
+
}
|
|
10448
10512
|
}
|
|
10449
10513
|
|
|
10450
10514
|
// src/commands/graph/init.ts
|
|
@@ -11019,6 +11083,7 @@ program2.command("clean").description("Remove build artifacts").option("--all",
|
|
|
11019
11083
|
program2.command("login").description("Authenticate with Construct").option("--portal <url>", "Portal URL").option("--token <token>", "Authenticate with a token directly (skip desktop profile picker)").action(async (opts) => login(opts));
|
|
11020
11084
|
program2.command("logout").description("Sign out").action(() => logout());
|
|
11021
11085
|
program2.command("update").description("Update the CLI to the latest version").action(() => update());
|
|
11086
|
+
program2.command("whoami").alias("status").description("Show the signed-in user + current org scope").action(async () => (await Promise.resolve().then(() => (init_whoami(), exports_whoami))).whoami());
|
|
11022
11087
|
var graph = program2.command("graph").description("Construct Graph \u2014 data models and GraphQL");
|
|
11023
11088
|
graph.command("init").description("Initialize Graph in a space project").action(() => graphInit());
|
|
11024
11089
|
graph.command("generate <model> [fields...]").alias("g").description("Generate a data model").option("--access <rules>", "Access rules (e.g. read:member,create:member,update:owner,delete:admin)").action((model, fields, opts) => generate2(model, fields, opts));
|