@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
108 lines (107 loc) • 3.78 kB
TypeScript
import { AsyncOptionalCreatable } from '@salesforce/kit';
import { JsonMap } from '@salesforce/ts-types';
import { AuthFields } from './authInfo';
/**
* Handles the removing of authorizations, which includes deleting the auth file
* in the global .sfdx folder, deleting any configs that are associated with the username/alias,
* and deleting any aliases associated with the username
*
* ```
* const remover = await AuthRemover.create();
* await remover.removeAuth('example@mycompany.com');
* ```
*
* ```
* const remover = await AuthRemover.create();
* await remover.removeAllAuths();
* ```
*
* ```
* const remover = await AuthRemover.create();
* const auth = await remover.findAuth(
* example@mycompany.com
* );
* await remover.removeAuth(auth.username);
* ```
*
* Pass a `projectPath` to resolve local config from a specific project instead of `process.cwd()`,
* and `skipCache` to re-read config from disk when the process-cached aggregator can't be trusted:
*
* ```
* const remover = await AuthRemover.create({ projectPath: '/path/to/project', skipCache: true });
* await remover.removeAuth('example@mycompany.com');
* ```
*/
export declare class AuthRemover extends AsyncOptionalCreatable<AuthRemoverOptions> {
private config;
private stateAggregator;
private logger;
private readonly projectPath?;
private readonly skipCache?;
constructor(options?: AuthRemoverOptions);
/**
* Removes the authentication and any configs or aliases associated with it
*
* @param usernameOrAlias the username or alias that you want to remove
*/
removeAuth(usernameOrAlias: string): Promise<void>;
/**
* Removes all authentication files and any configs or aliases associated with them
*/
removeAllAuths(): Promise<void>;
/**
* Finds authorization files for username/alias in the global .sfdx folder
* **Throws** *{@link SfError}{ name: 'TargetOrgNotSetError' }* if no target-org
* **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* if specified user is not found
*
* @param usernameOrAlias username or alias of the auth you want to find, defaults to the configured target-org
* @returns {Promise<SfOrg>}
*/
findAuth(usernameOrAlias?: string): Promise<AuthFields>;
/**
* Finds all org authorizations in the global info file (.sf/sf.json)
*
* @returns {Record<string, AuthFields>}
*/
findAllAuths(): Record<string, AuthFields & JsonMap>;
protected init(): Promise<void>;
/**
* Returns the username for a given alias if the alias exists.
*
* @param usernameOrAlias username or alias
* @returns {Promise<string>}
*/
private resolveUsername;
/**
* @returns {string}
*/
private getTargetOrg;
/**
* Returns aliases for provided username
*
* @param username username that's been aliased
* @returns {Promise<string[]>}
*/
private getAliases;
/**
* Unsets any configured values (both global and local) for provided username
*
* @param username username that you want to remove from config files
*/
private unsetConfigValues;
/**
* Unsets any aliases for provided username
*
* @param username username that you want to remove from aliases
*/
private unsetAliases;
}
export type AuthRemoverOptions = {
/** an absolute path to the project root, used to resolve local config; defaults to `process.cwd()` */
projectPath?: string;
/**
* re-read config from disk instead of trusting the process-cached ConfigAggregator. Set `true`
* when the config may have changed out of process or before this call. Defaults to `false`.
*/
skipCache?: boolean;
};