Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (args.sObjects || args.s) {
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,
const conn = new jsforce.Connection({
// you can change loginUrl to connect to sandbox or prerelease env.
loginUrl: instanceUrl
});
await conn.login(username, password);
const accessTokenOptions = {
accessToken: conn.accessToken,
instanceUrl: conn.instanceUrl,
loginUrl: instanceUrl,
orgId: getString(conn, 'userInfo.organizationId')
};
const auth = await AuthInfo.create({ username, accessTokenOptions });
await auth.save();
this.ux.log(`Authorized to ${username}`);
return { username, accessTokenOptions };
}
}
public static async isAScratchOrg(username: string): Promise {
try {
const authInfo = await AuthInfo.create({ username });
const authInfoFields = authInfo.getFields();
return Promise.resolve(
typeof authInfoFields.devHubUsername !== 'undefined'
);
} catch (e) {
throw e;
}
}
}