@a2hmarket/a2hmarket 0.6.4 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2hmarket/a2hmarket",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "index.ts",
@@ -308,8 +308,31 @@ async function runUpdate() {
308
308
  process.exit(0);
309
309
  }
310
310
 
311
- // 3. Update plugin
311
+ // 3. Backup credentials before uninstall
312
312
  logStep(3, "更新插件");
313
+ let savedCreds = null;
314
+ // Try openclaw.json plugin config first
315
+ try {
316
+ const cfg = JSON.parse(readFileSync(join(OPENCLAW_DIR, "openclaw.json"), "utf-8"));
317
+ const entry = cfg?.plugins?.entries?.a2hmarket;
318
+ if (entry?.agentId && entry?.agentKey) {
319
+ savedCreds = entry;
320
+ log(` ${CHECK} 凭证已备份 (openclaw.json)`);
321
+ }
322
+ } catch {}
323
+ // Fallback to credentials file
324
+ if (!savedCreds) {
325
+ try {
326
+ if (existsSync(CREDS_FILE)) {
327
+ savedCreds = JSON.parse(readFileSync(CREDS_FILE, "utf-8"));
328
+ log(` ${CHECK} 凭证已备份 (credentials.json)`);
329
+ }
330
+ } catch {}
331
+ }
332
+ if (!savedCreds) {
333
+ log(` ${WARN} 未找到凭证备份,更新后可能需要重新安装`);
334
+ }
335
+
313
336
  try {
314
337
  log(` 卸载旧版本...`);
315
338
  execSync('echo y | openclaw plugins uninstall a2hmarket 2>&1', { encoding: "utf-8", stdio: "pipe" });
@@ -321,6 +344,38 @@ async function runUpdate() {
321
344
  process.exit(1);
322
345
  }
323
346
 
347
+ // Restore credentials to both locations
348
+ if (savedCreds) {
349
+ // Restore credentials file
350
+ mkdirSync(DATA_DIR, { recursive: true });
351
+ const fileData = {
352
+ agent_id: savedCreds.agentId ?? savedCreds.agent_id,
353
+ agent_key: savedCreds.agentKey ?? savedCreds.agent_key,
354
+ api_url: savedCreds.apiUrl ?? savedCreds.api_url ?? "https://api.a2hmarket.ai",
355
+ mqtt_url: savedCreds.mqttUrl ?? savedCreds.mqtt_url ?? "mqtts://post-cn-e4k4o78q702.mqtt.aliyuncs.com:8883",
356
+ };
357
+ if (savedCreds.notify) fileData.notify = savedCreds.notify;
358
+ writeFileSync(CREDS_FILE, JSON.stringify(fileData, null, 2) + "\n");
359
+
360
+ // Restore openclaw.json plugin entry
361
+ try {
362
+ const configPath = join(OPENCLAW_DIR, "openclaw.json");
363
+ const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
364
+ if (!cfg.plugins) cfg.plugins = {};
365
+ if (!cfg.plugins.entries) cfg.plugins.entries = {};
366
+ cfg.plugins.entries.a2hmarket = {
367
+ enabled: true,
368
+ agentId: fileData.agent_id,
369
+ agentKey: fileData.agent_key,
370
+ apiUrl: fileData.api_url,
371
+ mqttUrl: fileData.mqtt_url,
372
+ ...(fileData.notify ? { notify: fileData.notify } : {}),
373
+ };
374
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n");
375
+ } catch {}
376
+ log(` ${CHECK} 凭证已恢复`);
377
+ }
378
+
324
379
  // 4. Re-link openclaw module
325
380
  log(` 配置模块依赖...`);
326
381
  try {