@construct-space/cli 1.4.1 → 1.4.2

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 +59 -9
  2. 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
- const org = resolveOrgId(explicit);
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();
@@ -11019,6 +11068,7 @@ program2.command("clean").description("Remove build artifacts").option("--all",
11019
11068
  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
11069
  program2.command("logout").description("Sign out").action(() => logout());
11021
11070
  program2.command("update").description("Update the CLI to the latest version").action(() => update());
11071
+ 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
11072
  var graph = program2.command("graph").description("Construct Graph \u2014 data models and GraphQL");
11023
11073
  graph.command("init").description("Initialize Graph in a space project").action(() => graphInit());
11024
11074
  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));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@construct-space/cli",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Construct CLI — scaffold, build, develop, and publish spaces",
5
5
  "type": "module",
6
6
  "bin": {