@mdfriday/foundry 26.3.12 → 26.3.14

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/cli.js CHANGED
@@ -2571,26 +2571,44 @@ var init_user_factory = __esm({
2571
2571
  }
2572
2572
  /**
2573
2573
  * 保存用户到存储(合并保存 token, license, server config, sync config)
2574
+ *
2575
+ * ⚠️ 采用合并策略:先加载现有数据,再用新数据覆盖,避免丢失其他字段
2574
2576
  */
2575
2577
  async save(user) {
2576
2578
  try {
2579
+ const existingData = await this.storageProvider.loadUserData();
2577
2580
  const token = user.getToken();
2578
2581
  const license = user.getLicense();
2579
2582
  const syncConfig = user.getSyncConfig();
2580
2583
  const serverConfig = user.getServerConfig();
2581
2584
  const email = user.getEmail().getValue();
2582
- await this.storageProvider.saveUserData({
2583
- token,
2584
- license,
2585
- syncConfig,
2586
- serverConfig,
2585
+ const mergedData = {
2586
+ // 保留现有数据(如果有)
2587
+ ...existingData || {},
2588
+ // 用新数据覆盖(只覆盖存在的字段)
2589
+ ...token ? { token } : {},
2590
+ ...license ? { license } : {},
2591
+ ...syncConfig ? { syncConfig } : {},
2592
+ ...serverConfig ? { serverConfig } : {},
2587
2593
  email
2588
- });
2589
- log4.debug("User saved to storage", {
2594
+ // email 始终更新
2595
+ };
2596
+ if (!license && existingData?.license) {
2597
+ mergedData.license = existingData.license;
2598
+ log4.debug("Preserved existing license data during save");
2599
+ }
2600
+ if (!syncConfig && existingData?.syncConfig) {
2601
+ mergedData.syncConfig = existingData.syncConfig;
2602
+ log4.debug("Preserved existing syncConfig data during save");
2603
+ }
2604
+ await this.storageProvider.saveUserData(mergedData);
2605
+ log4.debug("User saved to storage (merged)", {
2590
2606
  email,
2591
- hasToken: !!token,
2592
- hasLicense: !!license,
2593
- hasSyncConfig: !!syncConfig
2607
+ hasToken: !!mergedData.token,
2608
+ hasLicense: !!mergedData.license,
2609
+ hasSyncConfig: !!mergedData.syncConfig,
2610
+ preservedLicense: !license && !!existingData?.license,
2611
+ preservedSyncConfig: !syncConfig && !!existingData?.syncConfig
2594
2612
  });
2595
2613
  } catch (error) {
2596
2614
  log4.error("Failed to save user to storage", error);
@@ -3980,9 +3998,10 @@ var init_workspace_factory = __esm({
3980
3998
  async saveUserData(data) {
3981
3999
  const userDataPath = import_path3.default.join(workspacePath, ".mdfriday", "user-data.json");
3982
4000
  await fsRepo.createDirectory(import_path3.default.dirname(userDataPath), true);
3983
- const jsonData = {
3984
- serverConfig: data.serverConfig.toJSON()
3985
- };
4001
+ const jsonData = {};
4002
+ if (data.serverConfig) {
4003
+ jsonData.serverConfig = data.serverConfig.toJSON();
4004
+ }
3986
4005
  if (data.token) {
3987
4006
  jsonData.token = data.token.toJSON();
3988
4007
  authentication.markAuthExists();
@@ -3990,6 +4009,9 @@ var init_workspace_factory = __esm({
3990
4009
  if (data.license) {
3991
4010
  jsonData.license = data.license.toJSON();
3992
4011
  }
4012
+ if (data.syncConfig) {
4013
+ jsonData.syncConfig = data.syncConfig.toJSON();
4014
+ }
3993
4015
  if (data.email) {
3994
4016
  jsonData.email = data.email;
3995
4017
  }
@@ -4000,7 +4022,7 @@ var init_workspace_factory = __esm({
4000
4022
  try {
4001
4023
  const content = await fsRepo.readFile(userDataPath, "utf-8");
4002
4024
  const data = JSON.parse(content);
4003
- const { Token: Token3, ServerConfig: ServerConfig2, License: License2 } = await Promise.resolve().then(() => (init_identity(), identity_exports));
4025
+ const { Token: Token3, ServerConfig: ServerConfig2, License: License2, SyncConfig: SyncConfig2 } = await Promise.resolve().then(() => (init_identity(), identity_exports));
4004
4026
  const result = {};
4005
4027
  if (data.serverConfig) {
4006
4028
  result.serverConfig = ServerConfig2.create(data.serverConfig.apiUrl, data.serverConfig.websiteUrl);
@@ -4014,9 +4036,14 @@ var init_workspace_factory = __esm({
4014
4036
  data.license.plan,
4015
4037
  data.license.expiresAt,
4016
4038
  data.license.features,
4017
- data.license.activatedAt
4039
+ data.license.activatedAt,
4040
+ data.license.activated,
4041
+ data.license.firstTime
4018
4042
  );
4019
4043
  }
4044
+ if (data.syncConfig) {
4045
+ result.syncConfig = SyncConfig2.fromJSON(data.syncConfig);
4046
+ }
4020
4047
  if (data.email) {
4021
4048
  result.email = data.email;
4022
4049
  }
@@ -55087,7 +55114,7 @@ For more information, visit: https://help.mdfriday.com
55087
55114
  * Show version
55088
55115
  */
55089
55116
  showVersion() {
55090
- const version = "26.3.12";
55117
+ const version = "26.3.14";
55091
55118
  return {
55092
55119
  success: true,
55093
55120
  message: `MDFriday CLI v${version}`