Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
config.sObjects = (args.sObjects || args.s).split(',');
}
if (config.auth.accessToken === undefined) {
// if just username is set, load from sfdx
if (config.auth.username !== undefined && config.auth.password === undefined) {
let username = await Aliases.fetch(config.auth.username);
if (username) {
config.auth.username = username;
}
console.log(config.auth.username);
let connection: Connection = await Connection.create({
authInfo: await AuthInfo.create({ username: config.auth.username }
)
});
let org = await Org.create({ connection });
await org.refreshAuth();
connection = org.getConnection();
config.auth.accessToken = connection.accessToken;
config.auth.instanceUrl = connection.instanceUrl;
} else if (config.auth.username !== undefined && config.auth.password !== undefined) {
// otherwise lets try username/password flow
let pwConfig = new UsernamePasswordConfig(
config.auth.clientId,
config.auth.clientSecret,
config.auth.oAuthHost,
config.auth.username,
config.auth.password
);
return new Promise((resolve, reject) => {
try {
this.alias = alias;
Org.create({ aliasOrUsername: alias })
.then((resOrg: Org) => {
this.conn = resOrg.getConnection();
// LEARNING: How to generate the URL that sfdx force:org:open generates?
// this.conn.instanceUrl + "/secur/frontdoor.jsp\?sid\=" + this.conn.accessToken
Util.writeLog(`[${this.alias}] Alias for username: [${resOrg.getUsername()}]`, LogLevel.INFO);
this.order = new SchemaOrder(this);
this.discovery = new SchemaDiscovery(this);
resolve(this);
});
} catch (ex) {
this.resetValues(this.alias);
const msg = "Alias [" + this.alias + "] does not reference a valid org";
Util.throwError(msg);
reject(msg);
}
});
public async describeSObjectBatch(
projectPath: string,
types: string[],
nextToProcess: number
): Promise {
try {
const org = await Org.create({
aliasOrUsername: await ConfigUtil.getUsername(projectPath)
});
if (!this.accessToken || !this.instanceUrl) {
await this.getConnectionData(org);
}
let response: XHRResponse;
let options: XHROptions;
try {
options = this.buildXHROptions(types, nextToProcess);
response = await this.runRequest(options);
} catch (e) {
if (e.status !== 401) {
throw e;
}