alwaysai
Version:
The alwaysAI command-line interface (CLI)
41 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const config_nodejs_1 = require("@alwaysai/config-nodejs");
const t = require("io-ts");
const codec = t.record(t.string, t.any);
exports.PLEASE_LOG_IN_MESSAGE = 'Authentication is required for this action. Please run "alwaysai user login"';
const ENOENT = {
message: exports.PLEASE_LOG_IN_MESSAGE,
code: 'TERSE',
};
const path = path_1.join(config_nodejs_1.ALWAYSAI_CONFIG_DIR, 'alwaysai.credentials.json');
const configFile = config_nodejs_1.ConfigFile({
path,
codec,
ENOENT,
initialValue: {},
});
configFile.update(() => {
// No-op: to write the file if it does not already exist
});
const storage = {
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.remove();
},
};
exports.credentialsStore = Object.assign({}, configFile, storage);
//# sourceMappingURL=credentials-store.js.map