@myvillage/cli 1.6.1 → 1.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myvillage/cli",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "MyVillageOS CLI for community developers",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,8 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import ora from 'ora';
3
3
  import { villageSpinner, brand } from '../utils/brand.js';
4
- import { isAuthenticated, loadCredentials } from '../utils/auth.js';
5
- import { getProfile, getProfilePosts } from '../utils/api.js';
4
+ import { isAuthenticated, loadCredentials, saveCredentials, getAccessToken } from '../utils/auth.js';
5
+ import { getProfile, getProfilePosts, getUserInfo } from '../utils/api.js';
6
6
  import { formatProfile, formatPostList, formatPagination } from '../utils/formatters.js';
7
7
 
8
8
  export async function profileCommand(handle, options) {
@@ -13,18 +13,47 @@ export async function profileCommand(handle, options) {
13
13
 
14
14
  // Resolve handle: default to the logged-in user's villagerId
15
15
  let target = handle;
16
- if (!target) {
16
+ const isSelf = !target;
17
+ if (isSelf) {
17
18
  const creds = loadCredentials();
18
19
  target = creds?.villager_id;
19
20
  if (!target) {
20
- console.log(chalk.red(' No villager ID found. Try logging out and back in, or provide a handle: myvillage profile <handle>'));
21
+ console.log(chalk.red(' \u2717 No villager ID found. Try logging out and back in, or provide a handle: myvillage profile <handle>'));
21
22
  return;
22
23
  }
23
24
  }
24
25
  const spinner = villageSpinner('Loading profile...').start();
25
26
 
26
27
  try {
27
- const result = await getProfile(target);
28
+ let result;
29
+ try {
30
+ result = await getProfile(target);
31
+ } catch (err) {
32
+ // If own profile lookup fails with 404, refresh userinfo and retry
33
+ if (isSelf && err.response?.status === 404) {
34
+ spinner.text = 'Refreshing user info...';
35
+ const accessToken = getAccessToken();
36
+ if (accessToken) {
37
+ const userInfo = await getUserInfo(accessToken);
38
+ const freshId = userInfo.villager?.villagerId;
39
+ if (freshId && freshId !== target) {
40
+ // Update stored credentials with the fresh villagerId
41
+ const creds = loadCredentials();
42
+ saveCredentials({ ...creds, villager_id: freshId });
43
+ target = freshId;
44
+ spinner.text = 'Loading profile...';
45
+ result = await getProfile(target);
46
+ } else {
47
+ throw err;
48
+ }
49
+ } else {
50
+ throw err;
51
+ }
52
+ } else {
53
+ throw err;
54
+ }
55
+ }
56
+
28
57
  spinner.stop();
29
58
 
30
59
  const profile = result.data || result;
@@ -54,5 +83,8 @@ export async function profileCommand(handle, options) {
54
83
  } catch (err) {
55
84
  const message = err.response?.data?.error || err.response?.data?.message || err.message;
56
85
  spinner.fail(`Failed to load profile: ${message}`);
86
+ if (isSelf && err.response?.status === 404) {
87
+ console.log(brand.teal(' Your stored villager ID may be out of sync. Try running \'myvillage logout\' then \'myvillage login\'.'));
88
+ }
57
89
  }
58
90
  }