UNPKG

@salesforce/plugin-auth

Version:
53 lines 2.15 kB
/* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { loglevel, SfCommand } from '@salesforce/sf-plugins-core'; import { AuthInfo, Messages } from '@salesforce/core'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-auth', 'list'); export default class ListAuth extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static deprecateAliases = true; static aliases = ['force:auth:list', 'auth:list']; static flags = { loglevel, }; async run() { await this.parse(ListAuth); try { const auths = await AuthInfo.listAllAuthorizations(); if (auths.length === 0) { this.log(messages.getMessage('noResultsFound')); return []; } const mappedAuths = auths.map((auth) => { const { aliases, ...rest } = auth; // core3 moved to aliases as a string[], revert to alias as a string return { ...rest, alias: aliases ? aliases.join(',') : '' }; }); const hasErrors = auths.filter((auth) => !!auth.error).length > 0; this.table({ data: mappedAuths.map((auth) => ({ ALIAS: auth.alias, USERNAME: auth.username, 'ORG ID': auth.orgId, 'INSTANCE URL': auth.instanceUrl, 'AUTH METHOD': auth.oauthMethod, ...(hasErrors ? { error: { header: 'ERROR' } } : {}), })), title: 'authenticated orgs', }); return mappedAuths; } catch (err) { this.log(messages.getMessage('noResultsFound')); return []; } } } //# sourceMappingURL=auth.js.map