projex
Version:
A command line to manage the workflow
44 lines (43 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.login = void 0;
const _shared_1 = require("../../../../shared/index");
const util_1 = require("./util");
const _api_1 = require("../../../../api/index");
const login = async function (account, email, workspace, apiKey, apiToken, exitOnError = true) {
if (!account || !email || !workspace || !apiKey || !apiToken) {
_shared_1.log.error(_api_1.Colors.ERROR('please provide all the required parameters to log in.'));
if (exitOnError) {
process.exit(1);
}
else {
throw new Error('Missing required parameters');
}
}
const auth = await (0, util_1.serviceGetAuth)(account, apiKey, apiToken);
if (auth) {
const authToken = auth.data.token;
_shared_1.log.info('saving the authentication token in the VTEX config file...');
// Options for the config.json file
const options = {
account: account,
token: authToken,
workspace,
login: email,
env: 'prod',
};
// 1. Overwrite the config file from Vtex
await (0, util_1.saveVtexConfig)(options);
return true;
}
else {
_shared_1.log.error('error while obtaining authentication token');
if (exitOnError) {
process.exit(1);
}
else {
throw new Error('Failed to obtain authentication token');
}
}
};
exports.login = login;