UNPKG

projex

Version:
59 lines (58 loc) 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.saveVtexConfig = void 0; const Configstore = require('configstore'); const os_1 = require("os"); const path_1 = require("path"); const _shared_1 = require("../../../../../shared/index"); const VTEX_FOLDER = (0, path_1.join)((0, os_1.homedir)(), '.vtex'); const SESSION_FOLDER = (0, path_1.join)(VTEX_FOLDER, 'session'); const SESSION_STORE_PATH = (0, path_1.join)(SESSION_FOLDER, 'session.json'); const TOKEN_CACHE_STORE_PATH = (0, path_1.join)(SESSION_FOLDER, 'tokens.json'); const WORKSPACE_METADATA_STORE_PATH = (0, path_1.join)(SESSION_FOLDER, 'workspace.json'); /** * The `saveVtexConfig` function saves the Vtex configuration provided as input to the appropriate * configuration files. * @param {ConfigVtexJson} configuration - The `configuration` parameter is an object of type * `ConfigVtexJson` which contains the following properties: */ const saveVtexConfig = async (configuration) => { try { const conf = new Configstore('vtex'); await conf.clear(); conf.all = { account: configuration.account, token: configuration.token, workspace: configuration.workspace, login: configuration.login, _nextFeedbackDate: '2050-02-25T20:14:18.430Z', _numberOfReactLinks: null, _lastLinkReactDate: '2022-02-18T20:21:11.626Z', }; new Configstore('', {}, { configPath: TOKEN_CACHE_STORE_PATH }).clear(); new Configstore('', { [configuration.account]: configuration.token, }, { configPath: TOKEN_CACHE_STORE_PATH }); new Configstore('', {}, { configPath: WORKSPACE_METADATA_STORE_PATH, }).clear(); new Configstore('', { currentWorkspace: configuration.workspace, lastWorkspace: null, }, { configPath: WORKSPACE_METADATA_STORE_PATH, }); new Configstore('', {}, { configPath: SESSION_STORE_PATH }).clear(); new Configstore('', { account: configuration.account, login: configuration.login, token: configuration.token, }, { configPath: SESSION_STORE_PATH }); _shared_1.log.info('vtex credentials saved successfully.'); } catch (error) { _shared_1.log.error('an error occurred while saving VTEX credentials.', error); process.exit(1); } }; exports.saveVtexConfig = saveVtexConfig;