plazbot-cli
Version:
CLI para Plazbot SDK
34 lines (33 loc) • 1.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStoredCredentials = getStoredCredentials;
exports.saveCredentials = saveCredentials;
exports.removeCredentials = removeCredentials;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
const configDir = path_1.default.join(os_1.default.homedir(), '.plazbot');
const configPath = path_1.default.join(configDir, 'config.json');
async function getStoredCredentials() {
try {
const configRaw = await promises_1.default.readFile(configPath, 'utf-8');
const config = JSON.parse(configRaw);
if (!config.apiKey || !config.workspace || !config.zone) {
throw new Error('Credenciales incompletas');
}
return config;
}
catch (error) {
throw new Error("No se encontró una sesión activa. Ejecuta 'plazbot init' primero.");
}
}
async function saveCredentials(credentials) {
await promises_1.default.mkdir(configDir, { recursive: true });
await promises_1.default.writeFile(configPath, JSON.stringify(credentials, null, 2));
}
async function removeCredentials() {
await promises_1.default.rm(configPath, { force: true });
}