UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

49 lines 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CredentialsJsonFile = void 0; const t = require("io-ts"); const path_1 = require("path"); const alwayscli_1 = require("@alwaysai/alwayscli"); const config_nodejs_1 = require("@alwaysai/config-nodejs"); const paths_1 = require("../paths"); const system_id_1 = require("./system-id"); const credentialsJsonCodec = t.record(t.string, t.any); function CredentialsJsonFile(filePath) { const systemId = (0, system_id_1.getSystemId)(); const path = filePath !== null && filePath !== void 0 ? filePath : (0, path_1.join)(paths_1.LOCAL_AAI_CFG_DIR, `alwaysai.credentials${systemId !== 'production' ? '.' + systemId : ''}.json`); const configFile = (0, config_nodejs_1.ConfigFile)({ path, codec: credentialsJsonCodec, ENOENT: { code: alwayscli_1.CLI_TERSE_ERROR, message: `File not found ${path}. Please ensure the ${paths_1.LOCAL_AAI_CFG_DIR} folder exists in the home directory and has read and write access for the current user` }, EACCES: { code: alwayscli_1.CLI_TERSE_ERROR, message: `Please ensure the permissions on ${path} and ${paths_1.LOCAL_AAI_CFG_DIR} include read and write access for the current user.` }, initialValue: {} }); configFile.initialize(); const authenticationStorage = { setItem(key, value) { configFile.update((config) => { config[key] = value; }); }, getItem(key) { return configFile.read()[key] || ''; }, removeItem(key) { configFile.update((config) => { delete config[key]; }); }, clear() { configFile.write({}); } }; return authenticationStorage; } exports.CredentialsJsonFile = CredentialsJsonFile; //# sourceMappingURL=credentials-json-file.js.map