UNPKG

plazbot-cli

Version:
80 lines (79 loc) 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateCommand = void 0; const commander_1 = require("commander"); const plazbot_1 = require("plazbot"); const credentials_1 = require("../../utils/credentials"); const logger_1 = require("../../utils/logger"); exports.updateCommand = new commander_1.Command('update') .description('Actualiza un portal existente') .argument('<portalId>', 'ID del portal a actualizar') .option('-n, --name <name>', 'Nuevo nombre del portal') .option('-t, --title <title>', 'Nuevo título del portal') .option('-s, --subtitle <subtitle>', 'Nuevo subtítulo del portal') .option('-l, --logo <url>', 'Nueva URL del logo') .option('-d, --logo-dark <url>', 'Nueva URL del logo en modo oscuro') .option('-a, --access <type>', 'Tipo de acceso (direct o form)') .option('--disabled <value>', 'Estado de deshabilitación (true o false)') .option('--brand-off <value>', 'Estado de marca deshabilitada (true o false)') .option('--dev', 'Usar ambiente de desarrollo', false) .action(async (portalId, options) => { try { // Obtener credenciales guardadas const credentials = await (0, credentials_1.getStoredCredentials)(); const portal = new plazbot_1.Portal({ workspaceId: credentials.workspace, apiKey: credentials.apiKey, zone: credentials.zone, ...(options.dev && { customUrl: "http://localhost:5090" }) }); // Obtener detalles actuales del portal const currentPortal = await portal.getPortal(portalId); logger_1.logger.info('\n🌐 Actualizando portal...'); logger_1.logger.info('Portal actual:'); logger_1.logger.info(JSON.stringify(currentPortal.portal, null, 2)); // Construir objeto de actualización solo con los campos proporcionados const updateData = { id: portalId }; if (options.name) updateData.name = options.name; if (options.title) updateData.title = options.title; if (options.subtitle) updateData.subtitle = options.subtitle; if (options.logo) updateData.logo = options.logo; if (options.logoDark) updateData.logodark = options.logoDark; if (options.access) { if (options.access !== 'direct' && options.access !== 'form') { throw new Error('El tipo de acceso debe ser "direct" o "form"'); } updateData.access = options.access; } if (options.disabled) { if (options.disabled !== 'true' && options.disabled !== 'false') { throw new Error('El valor de disabled debe ser "true" o "false"'); } updateData.disabled = options.disabled === 'true'; } if (options.brandOff) { if (options.brandOff !== 'true' && options.brandOff !== 'false') { throw new Error('El valor de brand-off debe ser "true" o "false"'); } updateData.brandOff = options.brandOff === 'true'; } logger_1.logger.info('\nCambios a aplicar:'); logger_1.logger.info(JSON.stringify(updateData, null, 2)); const result = await portal.updatePortal(updateData); logger_1.logger.success('Portal actualizado exitosamente'); logger_1.logger.info(`Mensaje: ${result.message}`); if (options.dev) { logger_1.logger.warning('\nAmbiente: desarrollo'); } } catch (error) { const message = error instanceof Error ? error.message : 'Error desconocido al actualizar el portal'; logger_1.logger.error(message); process.exit(1); } });