@construct-space/cli 1.8.0 → 1.8.1

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 +113 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2876,26 +2876,92 @@ function listDesktopProfiles() {
2876
2876
  }
2877
2877
  return results;
2878
2878
  }
2879
- function credentialsPath() {
2880
- return join12(dataDir(), CREDENTIALS_FILE);
2879
+ function legacyCredentialsPath() {
2880
+ return join12(dataDir(), LEGACY_CREDENTIALS_FILE);
2881
2881
  }
2882
- function store(creds) {
2883
- const path = credentialsPath();
2882
+ function registryPath() {
2883
+ return join12(dataDir(), PROFILES_REGISTRY);
2884
+ }
2885
+ function readRegistry() {
2886
+ const path = registryPath();
2887
+ if (!existsSync10(path))
2888
+ return {};
2889
+ try {
2890
+ return JSON.parse(readFileSync7(path, "utf-8"));
2891
+ } catch {
2892
+ return {};
2893
+ }
2894
+ }
2895
+ function writeRegistry(reg) {
2896
+ const path = registryPath();
2884
2897
  mkdirSync4(dirname4(path), { recursive: true });
2885
- writeFileSync5(path, JSON.stringify(creds, null, 2) + `
2886
- `, { mode: 384 });
2898
+ writeFileSync5(path, JSON.stringify({ version: 1, ...reg }, null, 2));
2887
2899
  }
2888
- function load2() {
2889
- const path = credentialsPath();
2890
- if (existsSync10(path)) {
2891
- const data = JSON.parse(readFileSync7(path, "utf-8"));
2892
- if (data.token) {
2893
- if (!data.publisherKey && data.token.startsWith("csk_live_")) {
2894
- data.publisherKey = data.token;
2895
- }
2896
- return data;
2897
- }
2900
+ function store(creds) {
2901
+ const profileId = creds.profileId || creds.user?.id;
2902
+ if (!profileId) {
2903
+ throw new Error("cannot store credentials without a profile id (user.id or profileId)");
2904
+ }
2905
+ const profilePath = join12(profilesDir(), profileId, "auth.json");
2906
+ mkdirSync4(dirname4(profilePath), { recursive: true });
2907
+ let existing = {};
2908
+ if (existsSync10(profilePath)) {
2909
+ try {
2910
+ existing = JSON.parse(readFileSync7(profilePath, "utf-8"));
2911
+ } catch {}
2912
+ }
2913
+ existing.token = creds.token;
2914
+ existing.authenticated = true;
2915
+ existing.updated_at = new Date().toISOString();
2916
+ if (creds.user) {
2917
+ existing.user = { ...existing.user, ...creds.user };
2918
+ }
2919
+ if (creds.publisherKey) {
2920
+ existing.publisher = {
2921
+ ...existing.publisher,
2922
+ name: creds.publisherName || existing.publisher?.name || "",
2923
+ kind: creds.publisherKind || existing.publisher?.kind || "user",
2924
+ api_key: creds.publisherKey
2925
+ };
2926
+ }
2927
+ writeFileSync5(profilePath, JSON.stringify(existing, null, 2), { mode: 384 });
2928
+ const reg = readRegistry();
2929
+ reg.active_profile = profileId;
2930
+ reg.profiles = reg.profiles || [];
2931
+ const existingEntry = reg.profiles.find((p) => p.id === profileId);
2932
+ if (existingEntry) {
2933
+ if (creds.user?.name)
2934
+ existingEntry.name = creds.user.name;
2935
+ if (creds.user?.email)
2936
+ existingEntry.email = creds.user.email;
2937
+ } else if (creds.user) {
2938
+ reg.profiles.push({
2939
+ id: profileId,
2940
+ name: creds.user.name,
2941
+ email: creds.user.email
2942
+ });
2898
2943
  }
2944
+ writeRegistry(reg);
2945
+ }
2946
+ function migrateLegacyCredentials() {
2947
+ const legacy = legacyCredentialsPath();
2948
+ if (!existsSync10(legacy))
2949
+ return;
2950
+ try {
2951
+ const data = JSON.parse(readFileSync7(legacy, "utf-8"));
2952
+ if (!data.token)
2953
+ return;
2954
+ const pid = data.profileId || data.user?.id;
2955
+ if (!pid)
2956
+ return;
2957
+ const profilePath = join12(profilesDir(), pid, "auth.json");
2958
+ if (existsSync10(profilePath))
2959
+ return;
2960
+ store({ ...data, profileId: pid });
2961
+ } catch {}
2962
+ }
2963
+ function load2() {
2964
+ migrateLegacyCredentials();
2899
2965
  const fromProfile = loadFromActiveProfile();
2900
2966
  if (fromProfile)
2901
2967
  return fromProfile;
@@ -2945,11 +3011,24 @@ function isAuthenticated() {
2945
3011
  }
2946
3012
  }
2947
3013
  function clear() {
2948
- const path = credentialsPath();
2949
- if (existsSync10(path))
2950
- unlinkSync(path);
3014
+ const reg = readRegistry();
3015
+ const activeId = reg.active_profile;
3016
+ if (activeId) {
3017
+ const profilePath = join12(profilesDir(), activeId, "auth.json");
3018
+ if (existsSync10(profilePath)) {
3019
+ try {
3020
+ const data = JSON.parse(readFileSync7(profilePath, "utf-8"));
3021
+ data.authenticated = false;
3022
+ data.updated_at = new Date().toISOString();
3023
+ writeFileSync5(profilePath, JSON.stringify(data, null, 2), { mode: 384 });
3024
+ } catch {}
3025
+ }
3026
+ }
3027
+ const legacy = legacyCredentialsPath();
3028
+ if (existsSync10(legacy))
3029
+ unlinkSync(legacy);
2951
3030
  }
2952
- var CREDENTIALS_FILE = "credentials.json", DEFAULT_PORTAL = "https://my.construct.space/api/developer";
3031
+ var LEGACY_CREDENTIALS_FILE = "credentials.json", PROFILES_REGISTRY = "profiles.json", DEFAULT_PORTAL = "https://my.construct.space/api/developer";
2953
3032
  var init_auth = __esm(() => {
2954
3033
  init_appdir();
2955
3034
  });
@@ -10786,6 +10865,19 @@ async function loginFromProfile(profiles) {
10786
10865
  console.log(source_default.dim(` profile: ${picked.id}`));
10787
10866
  }
10788
10867
  async function loginWithToken(token) {
10868
+ if (token.startsWith("cst_live_")) {
10869
+ console.error(source_default.red("cst_live_* tokens are being retired."));
10870
+ console.error(source_default.dim(" Sign in via the Construct desktop app, or get a new"));
10871
+ console.error(source_default.dim(` identity token at ${source_default.cyan("https://my.construct.space/settings/tokens")}.`));
10872
+ process.exit(1);
10873
+ }
10874
+ if (token.startsWith("csk_live_")) {
10875
+ console.error(source_default.red("That's a publisher key, not an identity token."));
10876
+ console.error(source_default.dim(" Publisher keys (csk_live_*) authorize publish-as-publisher"));
10877
+ console.error(source_default.dim(" on top of identity. Pass an identity token (cat_*) here;"));
10878
+ console.error(source_default.dim(" the CLI loads your publisher key automatically once logged in."));
10879
+ process.exit(1);
10880
+ }
10789
10881
  let resp;
10790
10882
  try {
10791
10883
  resp = await fetch(ACCOUNTS_SCOPE_URL, {
@@ -11501,7 +11593,7 @@ function graphFork(newSpaceID) {
11501
11593
  // package.json
11502
11594
  var package_default = {
11503
11595
  name: "@construct-space/cli",
11504
- version: "1.8.0",
11596
+ version: "1.8.1",
11505
11597
  description: "Construct CLI \u2014 scaffold, build, develop, and publish spaces",
11506
11598
  type: "module",
11507
11599
  bin: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@construct-space/cli",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Construct CLI — scaffold, build, develop, and publish spaces",
5
5
  "type": "module",
6
6
  "bin": {