@forge/cli-shared

9.10.0-next.1-experimental-1e956969.10.0-next.5
out/ui/text.js
~out/ui/text.jsModified
+28−5
Index: package/out/ui/text.js
===================================================================
--- package/out/ui/text.js
+++ package/out/ui/text.js
@@ -28,13 +28,17 @@
 const go = (link) => buildTerminalLink(`https://go.atlassian.com/${link}`);
 const gettingStartedDACLink = go('dac/platform/forge/getting-started/#log-in-with-an-atlassian-api-token');
 const command = (...args) => chalk_1.default.bold(args.join(' '));
 const forge = (...args) => command('forge', ...args);
+const autoSpaceSentences = (...sentences) => sentences
+    .filter((sentence) => sentence.length > 0)
+    .join(' ');
 function itemList(items, indent) {
     return items.map((item) => `${indent ?? ' '}- ${item}`).join(`\n${indent ?? ''}`);
 }
 const fatalError = (message) => chalk_1.default.bold(chalk_1.default.red(message));
 const approveRuleDescription = 'list of validation rules to approve';
+const keytarAccessErrorBase = (message) => `Keytar error detected: ${message}`;
 const capitalise = (word) => word.charAt(0).toUpperCase() + word.slice(1);
 exports.capitalise = capitalise;
 const getLintMessage = (line, column, message, level, colourFunction, reference) => `${chalk_1.default.dim(`${line}:${column}`.padEnd(7))} ${colourFunction(level.padEnd(8))} ${message}  ${chalk_1.default.dim(reference)}\n`;
 const checkLintTotalPlurals = (numErrors, numWarnings, numApprovals, numFixableErrors, numFixableWarnings) => ({
@@ -44,8 +48,18 @@
     pluralCheckedTotal: `${numErrors + numWarnings + numApprovals} ${numErrors + numWarnings + numApprovals === 1 ? 'issue' : 'issues'}`,
     pluralCheckedFixableErrors: `${numFixableErrors} ${numFixableErrors === 1 ? 'error' : 'errors'}`,
     pluralCheckedFixableWarnings: `${numFixableWarnings} ${numFixableWarnings === 1 ? 'warning' : 'warnings'}`
 });
+const platformKeytarRecommendations = () => {
+    switch (process.platform) {
+        case 'darwin':
+            return 'Ensure you enable access to the macOS keychain when prompted.';
+        case 'linux':
+            return `Ensure you have ${chalk_1.default.bold('libsecret')} installed.`;
+        default:
+            return '';
+    }
+};
 const globalTargetLocation = ({ unit, org }) => unit && org
     ? `in unit ${chalk_1.default.bold(unit)} in organization ${chalk_1.default.bold(org)}`
     : unit
         ? `in unit ${chalk_1.default.bold(unit)}`
@@ -53,11 +67,17 @@
 exports.Text = {
     buildTerminalLink,
     go,
     error: {
-        noTokenStored: `Not logged in. Run ${forge('login')}, or set the FORGE_EMAIL and FORGE_API_TOKEN environment variables before trying again. See ${gettingStartedDACLink} for more.`,
-        credentialsFilePermissions: `The CLI couldn't securely store your login credentials in the local credentials file. ` +
-            `Set the FORGE_EMAIL and FORGE_API_TOKEN environment variables instead. See ${gettingStartedDACLink} for more.`,
+        noKeytar: autoSpaceSentences(`The CLI couldn't securely store your login credentials in a local keychain.`, platformKeytarRecommendations(), `If a local keychain is not available, use environment variables before trying again. See ${gettingStartedDACLink} for more.`),
+        noTokenStored: `Not logged in. If a local keychain is available, run ${forge('login')}, otherwise set environment variables before trying again. See ${gettingStartedDACLink} for more.`,
+        keytarAccessError: {
+            other: (message) => keytarAccessErrorBase(message),
+            mac: (message) => keytarAccessErrorBase(message) +
+                `\nSomething went wrong while accessing Keychain Access. Try locking and unlocking the login keychain.`,
+            linux: (message) => keytarAccessErrorBase(message) + `\nSomething went wrong while accessing Secret Service API.`,
+            windows: (message) => keytarAccessErrorBase(message) + `\nSomething went wrong while accessing Credentials Vault.`
+        },
         outdatedCLIVersion: (installed, latest) => `Warning: Your version of Forge CLI is out of date. We recommend you update to the latest version to get the latest features and bug fixes.` +
             `\nRun ${command('npm', 'install', '-g', `${cli_details_1.FORGE_CLI_PACKAGE}@latest`)} to update from version ${chalk_1.default.bold(installed)} to ${chalk_1.default.bold(latest)}.` +
             `\n`,
         outdatedNodeVersion: (compatibleNodeVersion, currentNodeVersion) => fatalError(`Unsupported Node.js version. The CLI requires Node.js ${compatibleNodeVersion}, but you're using Node.js ${currentNodeVersion}.`),
@@ -68,9 +88,9 @@
         missingSiteUrlValue: 'Site parameter requires a site URL. Rerun the command with a valid site URL.',
         invalidSite: 'The site you entered is not an Atlassian site. Rerun the command with the URL to an Atlassian site to install the app.',
         invalidWorkspace: 'The workspace you entered is not a valid workspace. Rerun the command with the URL to a valid workspace to install the app.',
         invalidInstallationContext: 'Could not find an installation for the provided Atlassian app',
-        invalidTokenInCredentialFile: `Your API token is no longer valid. Run ${forge('login')} to reset your login credentials.`,
+        invalidTokenInKeytar: `Your API token is no longer valid. Run ${forge('login')} to reset your login credentials.`,
         invalidUpgradeTarget: 'You must specify either "all" or "code" as the upgrade target.',
         invalidTokenInEnv: (instructionsUrl, emailVar, tokenVar) => `The API token on your machine is no longer valid.` +
             `\n    1) Get a new API token: ${instructionsUrl}` +
             `\n    2) Set your email and the token to ${emailVar} and ${tokenVar} environment variables.`,
@@ -101,8 +121,11 @@
         invalidServicePort: (serviceKey) => `Invalid tunnel port value for service ${serviceKey}. The 'tunnel:port' must be an integer between 1024 and 49152. Update your manifest.yml and try again. See ${buildTerminalLink('https://developer.atlassian.com/platform/forge/containers-reference/ref-manifest/#tunnel')} for more information.`,
         environmentIsNotDefined: (envKey) => `Environment with name ${envKey} not defined. Create this environment with ${chalk_1.default.bold(`forge environments create -e ${envKey}`)} before proceeding.`
     },
     warning: {
+        plaintextCredentialsFound: (url) => `Your credentials were stored in plaintext by a previous version of the Forge CLI. For additional security, revoke your existing API token by visting this URL ${buildTerminalLink(url)}.`,
+        plaintextCredentialsMigrated: 'The credentials found in plaintext have been migrated to your local keychain.',
+        plaintextCredentialsNotMigrated: autoSpaceSentences(`The CLI couldn't securely store your login credentials in a local keychain.`, platformKeytarRecommendations(), `If a local keychain is not available, use environment variables instead. See ${gettingStartedDACLink} for more information.`),
         unsupportedNodeVersion: (_userNodeVersion, supportedNodeVersions) => log_color_1.LogColor.warn(`Warning: Forge CLI supports Node.js ${supportedNodeVersions}.` +
             `\nUnsupported Node.js versions are not guaranteed to work correctly.\n`),
         deprecation: {
             uikit: (modules) => {
@@ -217,9 +240,9 @@
             personalCredentials: (email, name, accountId) => `Logged in as ${name} (${email})\nAccount ID: ${accountId}`
         },
         error: {
             personalCredentialsEnv: (emailKey, apiTokenKey) => `We couldn't get your Atlassian account information. Check the ${emailKey} and ${apiTokenKey} environment variables.`,
-            personalCredentialsFile: `We couldn't get your Atlassian account information. You may need to run ${forge('login')} to log in again.`
+            personalCredentialsKeytar: `We couldn't get your Atlassian account information. You may need to run ${forge('login')} to log in again.`
         }
     },
     feedback: {
         cmd: 'feedback',