UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

60 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalHandler = void 0; const base_handler_1 = require("./base.handler"); const errors_1 = require("../utils/errors"); const confirmation_1 = require("../utils/confirmation"); const global_service_1 = require("../services/global-service"); class GlobalHandler extends base_handler_1.BaseHandler { constructor(authConfig, serviceConfig) { super(); this.globalService = new global_service_1.GlobalServiceSdk(authConfig, serviceConfig); } async getAuth(options) { return this.executeWithErrorHandling(async () => { const result = await this.globalService.getAuth(); this.displayData(result, (options.output || 'table')); }, 'global.getAuth'); } async updateAuth(options) { return this.executeWithErrorHandling(async () => { if (!Array.isArray(options.authSettings) || options.authSettings.length !== 2) { throw this.validationError('authSettings must be a JSON array with exactly 2 items', 'authSettings', options.authSettings); } await this.confirmWrite(options.force, 'Update global auth settings?'); await this.globalService.updateAuth({ authSettings: options.authSettings, }); this.displayData({ success: true }, (options.output || 'table')); }, 'global.updateAuth'); } async getPageSetting(options) { return this.executeWithErrorHandling(async () => { const result = await this.globalService.getPageSetting(); this.displayData(result, (options.output || 'table')); }, 'global.getPageSetting'); } async updatePageSetting(options) { return this.executeWithErrorHandling(async () => { if (!options.config || Object.keys(options.config).length === 0) { throw this.validationError('config must not be empty', 'config', options.config); } await this.confirmWrite(options.force, 'Update global page settings?'); await this.globalService.updatePageSetting(options.config); this.displayData({ success: true, ...options.config }, (options.output || 'table')); }, 'global.updatePageSetting'); } async confirmWrite(force, message) { if (force) return; const confirmed = await (0, confirmation_1.confirmDeletion)(message); if (!confirmed) { throw new Error('Operation cancelled.'); } } validationError(message, field, value) { return new errors_1.PolyVValidationError(message, field, value, 'validation_failed'); } } exports.GlobalHandler = GlobalHandler; //# sourceMappingURL=global.handler.js.map