@fluid-app/fluid-cli 0.1.754 → 0.1.756

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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { $ as walkCommands, A as pollAgentAccess, D as fetchUserCompanies, E as confirmMfa, F as validateToken, M as sendMfa, N as signup, O as getFluidApiBase, P as switchCompany, Q as visibleSubcommands, S as resolveCredentialSource, X as rootCommand, Y as filterCatalog, Z as visibleOptions, _ as getAuthToken, c as inputsModeActive, g as getActiveProfile, j as redeemIdentityLink, k as isInsecureRemoteBase, l as registerInputsHook, s as exitOnInputsError, u as createInputsReader, w as FLUID_API_ERROR, x as readFdToken } from "../hook-FXS3H4Pz.mjs";
3
- import { A as isClientProfile, C as readStoredConfig, D as getConfigDir, E as isStrictConfig, S as readConfig, T as writeConfig, _ as primeClientProfile, c as sessionFacts, j as isIdentityProfile, l as signInWithBrowser, n as describeIdentityError, o as primeIdentityProfile, p as clientAccessToken, r as identityToken, t as endUnusedSessions, u as signOutIdentity, w as updateConfig, y as resolveIdentityUrl } from "../profiles-X-HRUprR.mjs";
2
+ import { $ as walkCommands, A as pollAgentAccess, D as fetchUserCompanies, E as confirmMfa, F as validateToken, M as sendMfa, N as signup, O as getFluidApiBase, P as switchCompany, Q as visibleSubcommands, S as resolveCredentialSource, X as rootCommand, Y as filterCatalog, Z as visibleOptions, _ as getAuthToken, c as inputsModeActive, g as getActiveProfile, j as redeemIdentityLink, k as isInsecureRemoteBase, l as registerInputsHook, s as exitOnInputsError, u as createInputsReader, w as FLUID_API_ERROR, x as readFdToken } from "../hook-DsUGnlj-.mjs";
3
+ import { A as isClientProfile, C as readStoredConfig, D as getConfigDir, E as isStrictConfig, S as readConfig, T as writeConfig, _ as primeClientProfile, c as sessionFacts, j as isIdentityProfile, l as signInWithBrowser, n as describeIdentityError, o as primeIdentityProfile, p as clientAccessToken, r as identityToken, t as endUnusedSessions, u as signOutIdentity, w as updateConfig, y as resolveIdentityUrl } from "../profiles-5slwyRzI.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -447,6 +447,17 @@ function failed(code, message) {
447
447
  }
448
448
  };
449
449
  }
450
+ /**
451
+ * What pins an identity sign-in to the account and company a sign-in
452
+ * confirmed: the company, when known, and a fresh login so the browser's
453
+ * existing session is not reused.
454
+ */
455
+ function pinnedIdentity(companyUuid) {
456
+ return {
457
+ ...companyUuid ? { org: companyUuid } : {},
458
+ forceLogin: true
459
+ };
460
+ }
450
461
  /** Signs in through the identity service and stores the profile. */
451
462
  async function loginWithIdentity(context) {
452
463
  const apiBase = context.apiBase ?? getFluidApiBase();
@@ -463,11 +474,17 @@ async function loginWithIdentity(context) {
463
474
  signIn = await signInWithBrowser({
464
475
  identityUrl,
465
476
  log: context.log,
466
- loginHint: context.loginHint
477
+ loginHint: context.loginHint,
478
+ org: context.org,
479
+ prompt: context.forceLogin ? "login" : void 0
467
480
  });
468
481
  } catch (error) {
469
482
  return failed("IDENTITY_SIGN_IN_FAILED", describeIdentityError(error));
470
483
  }
484
+ if (context.org && signIn.facts.companyId && signIn.facts.companyId !== context.org) {
485
+ await signOutIdentity(signIn.auth).catch(() => void 0);
486
+ return failed("IDENTITY_COMPANY_MISMATCH", "The browser signed in to a different company than the sign-in link was for. Sign out of the browser's Fluid session and try again.");
487
+ }
471
488
  if (!signIn.facts.roles.some((role) => STAFF_ROLES.has(role))) {
472
489
  await signOutIdentity(signIn.auth).catch(() => void 0);
473
490
  return failed("SHOPPER_SESSION", "This account does not sign in as an admin or rep, so it cannot sign in to the CLI.");
@@ -526,7 +543,10 @@ async function loginWithIdentityLink(token, context) {
526
543
  }
527
544
  context.onLinkSettled?.();
528
545
  spinner.succeed("Sign-in link accepted");
529
- return loginWithIdentity(context);
546
+ return loginWithIdentity({
547
+ ...context,
548
+ ...pinnedIdentity(redemption.value.companyUuid)
549
+ });
530
550
  }
531
551
  //#endregion
532
552
  //#region src/commands/login.ts
@@ -754,7 +774,10 @@ async function loginWithEmail(opts, ui, deps) {
754
774
  return 1;
755
775
  }
756
776
  const linkToken = identityLinkToken(code);
757
- if (linkToken) return identityResult(await loginWithIdentityLink(linkToken, identityContext(opts, true, ui, deps)), ui, deps);
777
+ if (linkToken) return identityResult(await loginWithIdentityLink(linkToken, {
778
+ ...identityContext(opts, true, ui, deps),
779
+ loginHint: normaliseEmail(email)
780
+ }), ui, deps);
758
781
  if (!/^\d{6}$/.test(code)) {
759
782
  deps.log(chalk.red("Code must be exactly 6 digits."));
760
783
  if (attempt < MAX_CODE_ATTEMPTS) continue;
@@ -782,7 +805,11 @@ async function loginWithEmail(opts, ui, deps) {
782
805
  return ui.fail(confirmResult.error, confirmSpinner);
783
806
  }
784
807
  if (!confirmResult?.success) return 0;
785
- if (signInPathFor(confirmResult.value) === "identity") return identityResult(await loginWithIdentity(identityContext(opts, true, ui, deps)), ui, deps);
808
+ if (signInPathFor(confirmResult.value) === "identity") return identityResult(await loginWithIdentity({
809
+ ...identityContext(opts, true, ui, deps),
810
+ loginHint: normaliseEmail(email),
811
+ ...pinnedIdentity(confirmResult.value.companyUuid)
812
+ }), ui, deps);
786
813
  const { companies } = confirmResult.value;
787
814
  if (companies.length === 0) {
788
815
  deps.log(chalk.red("No companies found for this account."));
@@ -952,6 +979,7 @@ async function finishStep(opts, interactive, ui, deps) {
952
979
  if (opts.name && overwriteRule(opts.name, overwrite) === "refuse") return ui.fail(profileExists(opts.name, false));
953
980
  if (linkToken) return identityResult(await loginWithIdentityLink(linkToken, {
954
981
  ...identityContext(opts, interactive, ui, deps, record.baseUrl),
982
+ loginHint: normaliseEmail(email),
955
983
  onLinkSettled: () => deps.pending.remove(email)
956
984
  }), ui, deps);
957
985
  const spinner = ui.spinner("Verifying code...");
@@ -970,7 +998,11 @@ async function finishStep(opts, interactive, ui, deps) {
970
998
  }
971
999
  spinner.succeed("Verified");
972
1000
  deps.pending.remove(email);
973
- if (signInPathFor(confirmed.value) === "identity") return identityResult(await loginWithIdentity(identityContext(opts, interactive, ui, deps, record.baseUrl)), ui, deps);
1001
+ if (signInPathFor(confirmed.value) === "identity") return identityResult(await loginWithIdentity({
1002
+ ...identityContext(opts, interactive, ui, deps, record.baseUrl),
1003
+ loginHint: normaliseEmail(email),
1004
+ ...pinnedIdentity(confirmed.value.companyUuid)
1005
+ }), ui, deps);
974
1006
  const { companies } = confirmed.value;
975
1007
  const selected = findByShop(companies, shop);
976
1008
  if (!selected) {
@@ -1063,7 +1095,7 @@ const defaultSignupDeps = {
1063
1095
  isInteractive: () => Boolean(process.stdin.isTTY),
1064
1096
  agent: {
1065
1097
  poll: pollAgentAccess,
1066
- saveProfile: async (name, input, options) => (await import("../client-B7rLAOwk.mjs")).saveClientProfile(name, input, options),
1098
+ saveProfile: async (name, input, options) => (await import("../client-BABOfZRW.mjs")).saveClientProfile(name, input, options),
1067
1099
  strictConfig: isStrictConfig,
1068
1100
  stashRecovery: writeRecoveryFile,
1069
1101
  stderrIsTty: () => Boolean(process.stderr.isTTY),