From 3effb85fe3fbb79785984651cce85419e557022f Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 22 Oct 2020 08:44:10 -0600 Subject: [PATCH] fix: various bugs --- messages/list.json | 3 ++- messages/messages.json | 2 +- messages/sfdxurl.store.json | 2 +- package.json | 3 ++- src/commands/auth/device/login.ts | 2 +- src/commands/auth/jwt/grant.ts | 2 +- src/commands/auth/list.ts | 21 +++++++++++++-------- src/commands/auth/sfdxurl/store.ts | 2 +- src/commands/auth/web/login.ts | 2 +- src/prompts.ts | 14 +++++++++++--- 10 files changed, 34 insertions(+), 19 deletions(-) diff --git a/messages/list.json b/messages/list.json index 7d661f94..8c0792a9 100644 --- a/messages/list.json +++ b/messages/list.json @@ -1,3 +1,4 @@ { - "description": "list auth connection information" + "description": "list auth connection information", + "noResultsFound": "No results found" } diff --git a/messages/messages.json b/messages/messages.json index c7cfcbcb..5ac1ac88 100644 --- a/messages/messages.json +++ b/messages/messages.json @@ -25,7 +25,7 @@ "instanceUrl": "the login URL of the instance the org lives on", "authorizeCommandSuccess": "Successfully authorized %s with org ID %s", "authorizeCommandCloseBrowser": "You may now close the browser", - "warnAuth": "Logging in to a business or production org is not recommended on a demo or shared machine. Please run \"sfdx auth:logout --targetusername --noprompt\" when finished using this org, which is similar to logging out of the org in the browser.\n\nDo you want to authorize this org, %s, for use with the Salesforce CLI (y/n)?", + "warnAuth": "Logging in to a business or production org is not recommended on a demo or shared machine. Please run \"sfdx auth:logout --targetusername --noprompt\" when finished using this org, which is similar to logging out of the org in the browser.\n\nDo you want to authorize this org for use with the Salesforce CLI (y/n)?", "noPromptAuth": "do not prompt for auth confirmation in demo mode", "disableMasking": "disable masking of user input (for use with problematic terminals)", "clientSecretStdin": "OAuth client secret of personal connected app?" diff --git a/messages/sfdxurl.store.json b/messages/sfdxurl.store.json index 758aa1fa..24a2c790 100644 --- a/messages/sfdxurl.store.json +++ b/messages/sfdxurl.store.json @@ -1,5 +1,5 @@ { - "description": "authorize an org using an SFDX auth URL\nThe file must have the format \"%s\" or \"%s\".\nThe file must contain only the URL or be a JSON file that has a top-level property named sfdxAuthUrl.\nUse this command to get the SFDX auth URL for a Dev Hub org you have already authorized:\n\n $ sfdx force:org:display -u --verbose", + "description": "authorize an org using an SFDX auth URL\nAuthorize a Salesforce org using an SFDX auth URL stored within a file. The file must have the format \"%s\" or \"%s\".\nThe file must contain only the URL or be a JSON file that has a top-level property named sfdxAuthUrl.\nUse this command to get the SFDX auth URL for a Dev Hub org you have already authorized:\n\n $ sfdx force:org:display -u --verbose", "file": "path to a file containing the sfdx url", "examples": [ "sfdx auth:sfdxurl:store -f ", diff --git a/package.json b/package.json index d5867d72..52ed45bc 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,9 @@ "dependencies": { "@oclif/config": "^1.17.0", "@salesforce/command": "^3.0.3", - "@salesforce/core": "^2.13.0", + "@salesforce/core": "^2.14.0", "@salesforce/kit": "^1.3.3", + "chalk": "^4.1.0", "open": "^7.3.0", "tslib": "^1" }, diff --git a/src/commands/auth/device/login.ts b/src/commands/auth/device/login.ts index ec98ac77..d76e29ac 100644 --- a/src/commands/auth/device/login.ts +++ b/src/commands/auth/device/login.ts @@ -73,7 +73,7 @@ export default class Login extends SfdxCommand { if (approval) { const authInfo = await deviceOauthService.authorizeAndSave(approval); await Common.handleSideEffects(authInfo, this.flags); - const fields = authInfo.getFields(); + const fields = authInfo.getFields(true); const successMsg = messages.getMessage('success', [fields.username]); this.ux.log(successMsg); return fields; diff --git a/src/commands/auth/jwt/grant.ts b/src/commands/auth/jwt/grant.ts index f626b7a5..c7b868dd 100644 --- a/src/commands/auth/jwt/grant.ts +++ b/src/commands/auth/jwt/grant.ts @@ -66,7 +66,7 @@ export default class Grant extends SfdxCommand { try { const authInfo = await this.initAuthInfo(); await Common.handleSideEffects(authInfo, this.flags); - result = authInfo.getFields(); + result = authInfo.getFields(true); } catch (err) { throw SfdxError.create('@salesforce/plugin-auth', 'jwt.grant', 'JwtGrantError', [err.message]); } diff --git a/src/commands/auth/list.ts b/src/commands/auth/list.ts index 41edfea4..f6f76438 100644 --- a/src/commands/auth/list.ts +++ b/src/commands/auth/list.ts @@ -25,14 +25,19 @@ export default class List extends SfdxCommand { public static readonly description = messages.getMessage('description'); public static readonly flagsConfig: FlagsConfig = {}; public async run(): Promise { - const auths = await AuthInfo.listAllAuthorizations(); - const hasErrors = auths.filter((auth) => !!auth.error).length > 0; - const columns = ['alias', 'username', 'orgId', 'instanceUrl', 'oauthMethod']; - if (hasErrors) { - columns.push('error'); + try { + const auths = await AuthInfo.listAllAuthorizations(); + const hasErrors = auths.filter((auth) => !!auth.error).length > 0; + const columns = ['alias', 'username', 'orgId', 'instanceUrl', 'oauthMethod']; + if (hasErrors) { + columns.push('error'); + } + this.ux.styledHeader('authenticated orgs'); + this.ux.table(auths, columns); + return auths; + } catch (err) { + this.ux.log(messages.getMessage('noResultsFound')); + return []; } - this.ux.styledHeader('authenticated orgs'); - this.ux.table(auths, columns); - return auths; } } diff --git a/src/commands/auth/sfdxurl/store.ts b/src/commands/auth/sfdxurl/store.ts index bc653eae..e3662470 100644 --- a/src/commands/auth/sfdxurl/store.ts +++ b/src/commands/auth/sfdxurl/store.ts @@ -57,7 +57,7 @@ export default class Store extends SfdxCommand { await Common.handleSideEffects(authInfo, this.flags); - const result = authInfo.getFields(); + const result = authInfo.getFields(true); const successMsg = commonMessages.getMessage('authorizeCommandSuccess', [result.username, result.orgId]); this.ux.log(successMsg); return result; diff --git a/src/commands/auth/web/login.ts b/src/commands/auth/web/login.ts index 2ee58d07..c3aa80dc 100644 --- a/src/commands/auth/web/login.ts +++ b/src/commands/auth/web/login.ts @@ -73,7 +73,7 @@ export default class Login extends SfdxCommand { try { const authInfo = await this.executeLoginFlow(oauthConfig); await Common.handleSideEffects(authInfo, this.flags); - const fields = authInfo.getFields(); + const fields = authInfo.getFields(true); const successMsg = commonMessages.getMessage('authorizeCommandSuccess', [fields.username, fields.orgId]); this.ux.log(successMsg); return fields; diff --git a/src/prompts.ts b/src/prompts.ts index 77d8aae1..130c58ec 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -6,16 +6,22 @@ */ import { Messages, Global, Mode } from '@salesforce/core'; import { UX } from '@salesforce/command'; +import * as chalk from 'chalk'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-auth', 'messages'); +function dimMessage(message: string): string { + return chalk.dim(message); +} + export class Prompts { public static async shouldExitCommand(ux: UX, noPrompt?: boolean, message?: string): Promise { if (noPrompt || Global.getEnvironmentMode() !== Mode.DEMO) { return false; } else { - const answer = await ux.prompt(message || messages.getMessage('warnAuth')); + const msg = dimMessage(message || messages.getMessage('warnAuth')); + const answer = await ux.prompt(msg); return Prompts.answeredNo(answer); } } @@ -24,13 +30,15 @@ export class Prompts { if (noPrompt || Global.getEnvironmentMode() === Mode.DEMO) { return true; } else { - const answer = await ux.prompt(message || messages.getMessage('warnAuth')); + const msg = dimMessage(message || messages.getMessage('warnAuth')); + const answer = await ux.prompt(msg); return Prompts.answeredYes(answer); } } public static async askForClientSecret(ux: UX, disableMasking: false): Promise { - return ux.prompt(messages.getMessage('clientSecretStdin'), { + const msg = dimMessage(messages.getMessage('clientSecretStdin')); + return ux.prompt(msg, { type: disableMasking ? 'normal' : 'hide', }); }