exponential-cli 1.28.0 → 1.29.0

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/index.js CHANGED
@@ -87,10 +87,11 @@ function handleError(error, json = false) {
87
87
  suggestion = "Run: exponential auth login --token <new-token> --api-url <url>";
88
88
  break;
89
89
  case "NOT_FOUND":
90
- message = "Resource not found";
90
+ message = message || "Resource not found";
91
91
  break;
92
92
  case "FORBIDDEN":
93
- message = "Access denied";
93
+ message = message || "Access denied";
94
+ suggestion = "Run `exponential auth whoami` to see which account this token is; that is the account to grant access to.";
94
95
  break;
95
96
  }
96
97
  const property = error.data?.property;
@@ -154,22 +155,54 @@ function createAuthCommand() {
154
155
  console.log(chalk2.green("Successfully logged out."));
155
156
  console.log(chalk2.gray(`Config cleared from: ${getConfigPath()}`));
156
157
  });
157
- auth.command("whoami").description("Show current authentication status").action(async () => {
158
+ auth.command("whoami").description("Show which account the stored token signs in as, and whether it is an agent").option("--json", "Output as JSON").action(async (options) => {
158
159
  if (!isAuthenticated()) {
159
- console.log(chalk2.yellow("Not authenticated."));
160
- console.log(chalk2.gray("Run: exponential auth login --token <jwt> --api-url <url>"));
160
+ if (options.json) {
161
+ console.log(JSON.stringify({ error: { code: "UNAUTHENTICATED", message: "Not authenticated" } }, null, 2));
162
+ } else {
163
+ console.log(chalk2.yellow("Not authenticated."));
164
+ console.log(chalk2.gray("Run: exponential auth login --token <jwt> --api-url <url>"));
165
+ }
161
166
  process.exit(1);
162
167
  }
163
168
  try {
164
169
  const config = getConfig();
165
170
  const client = getClient();
166
- const workspaces = await client.workspaces.list();
171
+ const [me, workspaces] = await Promise.all([
172
+ client.users.me(),
173
+ client.workspaces.list()
174
+ ]);
175
+ const workspaceCount = workspaces.length;
176
+ if (options.json) {
177
+ console.log(JSON.stringify({
178
+ id: me.id,
179
+ name: me.name,
180
+ email: me.email,
181
+ isAgent: me.isAgent,
182
+ agent: me.agent,
183
+ apiUrl: config.apiUrl,
184
+ workspaces: workspaceCount,
185
+ configPath: getConfigPath()
186
+ }, null, 2));
187
+ return;
188
+ }
167
189
  console.log(chalk2.green("Authenticated"));
190
+ console.log(`Account: ${chalk2.bold(me.name ?? "(unnamed)")} ${chalk2.gray(`(${me.id})`)}`);
191
+ if (me.email) {
192
+ console.log(chalk2.gray(`Email: ${me.email}`));
193
+ }
194
+ if (me.isAgent) {
195
+ const owner = me.agent?.owner.name ?? me.agent?.owner.id ?? "unknown";
196
+ console.log(`Type: ${chalk2.cyan("External agent")} ${chalk2.gray(`owned by ${owner}`)}`);
197
+ console.log(chalk2.gray("To give this agent a restricted project, add this account on the project's Members tab."));
198
+ } else {
199
+ console.log(`Type: ${chalk2.cyan("Person")}`);
200
+ }
168
201
  console.log(chalk2.gray(`API URL: ${config.apiUrl}`));
169
- console.log(chalk2.gray(`Workspaces: ${workspaces.length}`));
202
+ console.log(chalk2.gray(`Workspaces: ${workspaceCount}`));
170
203
  console.log(chalk2.gray(`Config: ${getConfigPath()}`));
171
204
  } catch (error) {
172
- handleError(error);
205
+ handleError(error, options.json);
173
206
  }
174
207
  });
175
208
  auth.command("show").description(