Skip to content

Commit

Permalink
feat: use new inquirer
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Dec 30, 2023
1 parent 33fa74a commit 3cd0fbf
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 309 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ ALIASES
$ sf auth jwt grant
EXAMPLES
Log into an org with username [email protected] and on the default instance URL (https://login.salesforce.org). The
Log into an org with username [email protected] and on the default instance URL (https://login.salesforce.com). The
private key is stored in the file /Users/jdoe/JWT/server.key and the command uses the connected app with consumer
key (client id) 04580y4051234051.
Expand Down
12 changes: 1 addition & 11 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@
{
"command": "org:login:device",
"plugin": "@salesforce/plugin-auth",
"flags": [
"alias",
"client-id",
"disable-masking",
"instance-url",
"json",
"loglevel",
"set-default",
"set-default-dev-hub"
],
"flags": ["alias", "client-id", "instance-url", "json", "loglevel", "set-default", "set-default-dev-hub"],
"alias": ["force:auth:device:login", "auth:device:login"],
"flagChars": ["a", "d", "i", "r", "s"],
"flagAliases": [
Expand Down Expand Up @@ -101,7 +92,6 @@
"alias",
"browser",
"client-id",
"disable-masking",
"instance-url",
"json",
"loglevel",
Expand Down
2 changes: 1 addition & 1 deletion messages/jwt.grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ We recommend that you set an alias when you log into an org. Aliases make it eas

# examples

- Log into an org with username [email protected] and on the default instance URL (https://login.salesforce.org). The private key is stored in the file /Users/jdoe/JWT/server.key and the command uses the connected app with consumer key (client id) 04580y4051234051.
- Log into an org with username [email protected] and on the default instance URL (https://login.salesforce.com). The private key is stored in the file /Users/jdoe/JWT/server.key and the command uses the connected app with consumer key (client id) 04580y4051234051.

<%= config.bin %> <%= command.id %> --username [email protected] --jwt-key-file /Users/jdoe/JWT/server.key --client-id 04580y4051234051

Expand Down
4 changes: 0 additions & 4 deletions messages/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ Do you want to authorize this org for use with the Salesforce CLI?

Don't prompt for confirmation.

# flags.disable-masking.summary

Disable masking of user input; use with problematic terminals.

# clientSecretStdin

OAuth client secret of personal connected app? Press Enter if it's not required.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@inquirer/confirm": "^2.0.15",
"@inquirer/password": "^1.1.14",
"@oclif/core": "^3.15.0",
"@salesforce/core": "^6.4.2",
"@salesforce/kit": "^3.0.15",
Expand Down Expand Up @@ -219,7 +221,7 @@
"output": []
},
"link-check": {
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error",
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error",
"files": [
"./*.md",
"./!(CHANGELOG).md",
Expand Down
54 changes: 0 additions & 54 deletions src/authBaseCommand.ts

This file was deleted.

30 changes: 14 additions & 16 deletions src/commands/org/login/access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, Messages, matchesAccessToken, SfError, StateAggregator } from '@salesforce/core';
import { env } from '@salesforce/kit';
import { Interfaces } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import common from '../../../common.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'accesstoken.store');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

const ACCESS_TOKEN_FORMAT = '"<org id>!<accesstoken>"';

export default class LoginAccessToken extends AuthBaseCommand<AuthFields> {
export default class LoginAccessToken extends SfCommand<AuthFields> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly deprecateAliases = true;
public static aliases = ['force:auth:accesstoken:store', 'auth:accesstoken:store'];
public static readonly aliases = ['force:auth:accesstoken:store', 'auth:accesstoken:store'];

public static readonly flags = {
'instance-url': Flags.url({
Expand Down Expand Up @@ -72,7 +70,7 @@ export default class LoginAccessToken extends AuthBaseCommand<AuthFields> {
const { flags } = await this.parse(LoginAccessToken);
this.flags = flags;
const instanceUrl = flags['instance-url'].href;
const accessToken = await this.getAccessToken();
const accessToken = await getAccessToken();
const authInfo = await this.getUserInfo(accessToken, instanceUrl);
return this.storeAuthFromAccessToken(authInfo);
}
Expand Down Expand Up @@ -114,14 +112,14 @@ export default class LoginAccessToken extends AuthBaseCommand<AuthFields> {
}
return true;
}
}

private async getAccessToken(): Promise<string> {
const accessToken =
env.getString('SF_ACCESS_TOKEN') ?? env.getString('SFDX_ACCESS_TOKEN') ?? (await this.askForAccessToken());
const getAccessToken = async (): Promise<string> => {
const accessToken =
env.getString('SF_ACCESS_TOKEN') ?? env.getString('SFDX_ACCESS_TOKEN') ?? (await common.accessTokenPrompt());

if (!matchesAccessToken(accessToken)) {
throw new SfError(messages.getMessage('invalidAccessTokenFormat', [ACCESS_TOKEN_FORMAT]));
}
return accessToken;
if (!matchesAccessToken(accessToken)) {
throw new SfError(messages.getMessage('invalidAccessTokenFormat', [ACCESS_TOKEN_FORMAT]));
}
}
return accessToken;
};
23 changes: 7 additions & 16 deletions src/commands/org/login/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import { AuthFields, AuthInfo, DeviceOauthService, Messages, OAuth2Config } from '@salesforce/core';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand, loglevel } from '@salesforce/sf-plugins-core';
import { DeviceCodeResponse } from '@salesforce/core/lib/deviceOauthService.js';
import { ux } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import { Common } from '../../../common.js';
import common from '../../../common.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'device.login');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

export type DeviceLoginResult = (AuthFields & DeviceCodeResponse) | Record<string, never>;

export default class LoginDevice extends AuthBaseCommand<DeviceLoginResult> {
export default class LoginDevice extends SfCommand<DeviceLoginResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static aliases = ['force:auth:device:login', 'auth:device:login'];
public static readonly aliases = ['force:auth:device:login', 'auth:device:login'];

public static readonly flags = {
'client-id': Flags.string({
Expand Down Expand Up @@ -58,21 +55,15 @@ export default class LoginDevice extends AuthBaseCommand<DeviceLoginResult> {
deprecateAliases: true,
aliases: ['setalias'],
}),
'disable-masking': Flags.boolean({
summary: commonMessages.getMessage('flags.disable-masking.summary'),
hidden: true,
deprecateAliases: true,
aliases: ['disablemasking'],
}),
loglevel,
};

public async run(): Promise<DeviceLoginResult> {
const { flags } = await this.parse(LoginDevice);
if (await this.shouldExitCommand(false)) return {};
if (await common.shouldExitCommand(false)) return {};

const oauthConfig: OAuth2Config = {
loginUrl: await Common.resolveLoginUrl(flags['instance-url']?.href),
loginUrl: await common.resolveLoginUrl(flags['instance-url']?.href),
clientId: flags['client-id'],
};

Expand Down
18 changes: 8 additions & 10 deletions src/commands/org/login/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand, loglevel } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, AuthRemover, Logger, Messages, SfError } from '@salesforce/core';
import { Interfaces } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import { Common } from '../../../common.js';
import common from '../../../common.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'jwt.grant');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

export default class LoginJwt extends AuthBaseCommand<AuthFields> {
export default class LoginJwt extends SfCommand<AuthFields> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static aliases = ['force:auth:jwt:grant', 'auth:jwt:grant'];
public static readonly aliases = ['force:auth:jwt:grant', 'auth:jwt:grant'];

public static readonly flags = {
username: Flags.string({
// eslint-disable-next-line sf-plugin/dash-o
char: 'o',
summary: messages.getMessage('flags.username.summary'),
required: true,
Expand Down Expand Up @@ -88,7 +86,7 @@ export default class LoginJwt extends AuthBaseCommand<AuthFields> {
this.flags = flags;
let result: AuthFields = {};

if (await this.shouldExitCommand(flags['no-prompt'])) return {};
if (await common.shouldExitCommand(flags['no-prompt'])) return {};

try {
const authInfo = await this.initAuthInfo();
Expand Down Expand Up @@ -117,7 +115,7 @@ export default class LoginJwt extends AuthBaseCommand<AuthFields> {
privateKeyFile: this.flags['jwt-key-file'],
};

const loginUrl = await Common.resolveLoginUrl(this.flags['instance-url']?.href);
const loginUrl = await common.resolveLoginUrl(this.flags['instance-url']?.href);

const oauth2Options = loginUrl ? Object.assign(oauth2OptionsBase, { loginUrl }) : oauth2OptionsBase;

Expand Down
14 changes: 6 additions & 8 deletions src/commands/org/login/sfdx-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import fs from 'node:fs/promises';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand, loglevel } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import { parseJson } from '@salesforce/kit';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import common from '../../../common.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'sfdxurl.store');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

Expand All @@ -24,11 +22,11 @@ type AuthJson = AnyJson & {
result?: AnyJson & { sfdxAuthUrl: string };
sfdxAuthUrl: string;
};
export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {
export default class LoginSfdxUrl extends SfCommand<AuthFields> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description', [AUTH_URL_FORMAT]);
public static readonly examples = messages.getMessages('examples');
public static aliases = ['force:auth:sfdxurl:store', 'auth:sfdxurl:store'];
public static readonly aliases = ['force:auth:sfdxurl:store', 'auth:sfdxurl:store'];

public static readonly flags = {
'sfdx-url-file': Flags.file({
Expand Down Expand Up @@ -69,7 +67,7 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {

public async run(): Promise<AuthFields> {
const { flags } = await this.parse(LoginSfdxUrl);
if (await this.shouldExitCommand(flags['no-prompt'])) return {};
if (await common.shouldExitCommand(flags['no-prompt'])) return {};

const authFile = flags['sfdx-url-file'];

Expand Down
Loading

0 comments on commit 3cd0fbf

Please sign in to comment.