@fluid-app/fluid-cli 0.1.668 → 0.1.670

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { A as identityToken, B as isIdentityProfile, C as readConfig, D as getConfigDir, E as isStrictConfig, F as signInWithBrowser, G as getFluidApiBase, I as signOutIdentity, J as signup, K as redeemIdentityLink, L as resolveIdentityUrl, M as primeIdentityProfile, P as sessionFacts, T as writeConfig, U as confirmMfa, V as FLUID_API_ERROR, W as fetchUserCompanies, X as validateToken, Y as switchCompany, _ as getAuthToken, c as inputsModeActive, dt as rootCommand, ft as visibleOptions, g as getActiveProfile, i as INPUTS_MODE_ENV, k as describeIdentityError, l as registerInputsHook, mt as walkCommands, pt as visibleSubcommands, q as sendMfa, s as exitOnInputsError, u as createInputsReader, ut as filterCatalog, w as updateConfig, x as resolveCredentialSource } from "../hook-C8GwU1TO.mjs";
2
+ import { $ as sendMfa, A as signInWithBrowser, B as getConfigDir, C as endUnusedSessions, D as primeIdentityProfile, F as resolveIdentityUrl, G as isClientProfile, I as readConfig, K as isIdentityProfile, L as updateConfig, M as clientAccessToken, P as primeClientProfile, Q as redeemIdentityLink, R as writeConfig, T as identityToken, X as fetchUserCompanies, Y as confirmMfa, Z as getFluidApiBase, _ as getAuthToken, _t as rootCommand, bt as walkCommands, c as inputsModeActive, et as signup, g as getActiveProfile, gt as filterCatalog, i as INPUTS_MODE_ENV, j as signOutIdentity, k as sessionFacts, l as registerInputsHook, nt as validateToken, q as FLUID_API_ERROR, s as exitOnInputsError, tt as switchCompany, u as createInputsReader, vt as visibleOptions, w as describeIdentityError, x as resolveCredentialSource, yt as visibleSubcommands, z as isStrictConfig } from "../hook-Cy4Rnvl2.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -9,8 +9,8 @@ import chalk from "chalk";
9
9
  import prompts from "prompts";
10
10
  import ora from "ora";
11
11
  import { createHash, randomBytes } from "node:crypto";
12
- import { spawn } from "node:child_process";
13
12
  import { dirname, isAbsolute, join, relative, sep } from "node:path";
13
+ import { spawn } from "node:child_process";
14
14
  //#region src/commands/commands.ts
15
15
  /**
16
16
  * fluid commands — list every installed command, or print the catalog as
@@ -245,42 +245,6 @@ const completeCommand = new Command("__complete").description("Print completions
245
245
  process.stdout.write(formatCandidates(completeWords(rootCommand(command), typed), opts.shell));
246
246
  });
247
247
  //#endregion
248
- //#region src/auth/identity/profiles.ts
249
- /**
250
- * Ending identity sessions when the profiles that use them go away.
251
- *
252
- * `fluid switch` gives each company its own profile, and in identity mode
253
- * those profiles share the session they were switched from. A session is
254
- * revoked only once no profile is left that uses it.
255
- */
256
- function sessionsIn(config) {
257
- const found = /* @__PURE__ */ new Map();
258
- for (const profile of Object.values(config.profiles)) {
259
- if (!isIdentityProfile(profile)) continue;
260
- const { auth } = profile;
261
- found.set(`${auth.identityUrl} ${auth.storageKey}`, auth);
262
- }
263
- return found;
264
- }
265
- /**
266
- * Revokes every identity session `before` used that `after` no longer does,
267
- * and deletes its refresh token from the credential store. Resolves with a
268
- * message for each session that could not be ended cleanly; never rejects.
269
- */
270
- async function endUnusedSessions(before, after) {
271
- const remaining = sessionsIn(after);
272
- const problems = [];
273
- for (const [key, auth] of sessionsIn(before)) {
274
- if (remaining.has(key)) continue;
275
- try {
276
- await signOutIdentity(auth);
277
- } catch (error) {
278
- problems.push(describeIdentityError(error));
279
- }
280
- }
281
- return problems;
282
- }
283
- //#endregion
284
248
  //#region src/auth/identity/sign-in-path.ts
285
249
  /**
286
250
  * The path a confirmed code puts the person on. A confirmation that kept any
@@ -1238,6 +1202,34 @@ const logoutCommand = new Command("logout").description("Remove stored authentic
1238
1202
  if (nextActive) console.log(chalk.dim(`Switched to profile ${nextActive}.`));
1239
1203
  });
1240
1204
  //#endregion
1205
+ //#region src/commands/profiles.ts
1206
+ /**
1207
+ * fluid profiles — list stored auth profiles. Never prints a secret: a
1208
+ * client profile shows its client id and company, and the secret stays in the
1209
+ * operating system credential store.
1210
+ */
1211
+ function modeOf(profile) {
1212
+ return profile.auth?.mode ?? "token";
1213
+ }
1214
+ const profilesCommand = new Command("profiles").description("List stored profiles").action(() => {
1215
+ const config = readConfig();
1216
+ const profiles = Object.values(config.profiles);
1217
+ if (profiles.length === 0) {
1218
+ console.log(chalk.yellow("No profiles stored. Run `fluid login` first."));
1219
+ return;
1220
+ }
1221
+ for (const profile of profiles) {
1222
+ const active = profile.name === config.activeProfile ? " (active)" : "";
1223
+ console.log(`${chalk.bold(profile.name)}${active}`);
1224
+ console.log(` Mode: ${modeOf(profile)}`);
1225
+ console.log(` Company: ${profile.companyName}`);
1226
+ if (profile.auth?.mode === "client") {
1227
+ console.log(` Client: ${profile.auth.clientId}`);
1228
+ console.log(` Org: ${profile.auth.org}`);
1229
+ }
1230
+ }
1231
+ });
1232
+ //#endregion
1241
1233
  //#region src/commands/whoami.ts
1242
1234
  /**
1243
1235
  * fluid whoami — show current auth profile and validate against API
@@ -1266,6 +1258,24 @@ async function whoamiIdentity(profile) {
1266
1258
  console.log(` Signed in: ${chalk.dim((/* @__PURE__ */ new Date(facts.authTime * 1e3)).toISOString())}`);
1267
1259
  console.log(` Stored: ${chalk.dim(profile.storedAt)}`);
1268
1260
  }
1261
+ async function whoamiClient(profile) {
1262
+ const spinner = ora("Requesting a token for this client...").start();
1263
+ try {
1264
+ await clientAccessToken(profile);
1265
+ } catch (error) {
1266
+ spinner.fail(chalk.red(describeIdentityError(error)));
1267
+ console.log(chalk.dim(`Profile: ${profile.name}`));
1268
+ process.exitCode = 1;
1269
+ return;
1270
+ }
1271
+ spinner.succeed(chalk.green("Authenticated (client credentials)"));
1272
+ console.log(` Profile: ${chalk.bold(profile.name)}`);
1273
+ console.log(` Company: ${chalk.bold(profile.companyName)}`);
1274
+ console.log(` Mode: client`);
1275
+ console.log(` Client ID: ${chalk.dim(profile.auth.clientId)}`);
1276
+ console.log(` Org: ${chalk.dim(profile.auth.org)}`);
1277
+ console.log(` Stored: ${chalk.dim(profile.storedAt)}`);
1278
+ }
1269
1279
  const whoamiCommand = new Command("whoami").description("Show the current authenticated profile").action(async () => {
1270
1280
  const profile = getActiveProfile();
1271
1281
  if (!profile) {
@@ -1277,6 +1287,10 @@ const whoamiCommand = new Command("whoami").description("Show the current authen
1277
1287
  await whoamiIdentity(profile);
1278
1288
  return;
1279
1289
  }
1290
+ if (isClientProfile(profile)) {
1291
+ await whoamiClient(profile);
1292
+ return;
1293
+ }
1280
1294
  const spinner = ora("Verifying token...").start();
1281
1295
  const result = await validateToken(profile.token ?? "", { baseUrl: process.env["FLUID_API_BASE"] || profile.baseUrl });
1282
1296
  if (!result.success) {
@@ -1423,6 +1437,10 @@ const switchCommand = new Command("switch").description("Switch between companie
1423
1437
  process.exitCode = 1;
1424
1438
  return;
1425
1439
  }
1440
+ if (isClientProfile(activeProfile)) {
1441
+ await localSwitch(profileArg);
1442
+ return;
1443
+ }
1426
1444
  const activeCompanyName = activeProfile.companyName;
1427
1445
  const activeBaseUrl = activeProfile.baseUrl ?? getFluidApiBase();
1428
1446
  const identity = isIdentityProfile(activeProfile) ? activeProfile : null;
@@ -1495,9 +1513,11 @@ const switchCommand = new Command("switch").description("Switch between companie
1495
1513
  async function primeCommandCredential(options) {
1496
1514
  if (typeof options.token === "string" && options.token) return;
1497
1515
  const source = resolveCredentialSource(typeof options.profile === "string" && options.profile ? options.profile : void 0);
1498
- if (source?.kind !== "profile" || !isIdentityProfile(source.profile)) return;
1516
+ if (source?.kind !== "profile") return;
1517
+ const { profile } = source;
1499
1518
  try {
1500
- await primeIdentityProfile(source.profile);
1519
+ if (isIdentityProfile(profile)) await primeIdentityProfile(profile);
1520
+ else if (isClientProfile(profile)) await primeClientProfile(profile);
1501
1521
  } catch (error) {
1502
1522
  process.stderr.write(`${chalk.yellow(describeIdentityError(error))}\n`);
1503
1523
  }
@@ -2050,6 +2070,7 @@ program.addCommand(signupCommand);
2050
2070
  program.addCommand(loginCommand);
2051
2071
  program.addCommand(logoutCommand);
2052
2072
  program.addCommand(whoamiCommand);
2073
+ program.addCommand(profilesCommand);
2053
2074
  program.addCommand(switchCommand);
2054
2075
  program.addCommand(commandsCommand);
2055
2076
  program.addCommand(completionCommand);
@@ -2059,6 +2080,7 @@ const selfAuthenticating = new Set([
2059
2080
  loginCommand,
2060
2081
  logoutCommand,
2061
2082
  whoamiCommand,
2083
+ profilesCommand,
2062
2084
  switchCommand,
2063
2085
  commandsCommand,
2064
2086
  completionCommand,