UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

69 lines 4.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerWebAppCommands = registerWebAppCommands; const webapp_handler_1 = require("../handlers/webapp.handler"); const errors_1 = require("../utils/errors"); const api_command_1 = require("../utils/api-command"); function withWebAppHandler(program, run) { return (async () => { try { const { authConfig, serviceConfig } = await (0, api_command_1.loadApiCommandConfig)((0, api_command_1.commandParentOptions)(program)); await run(new webapp_handler_1.WebAppHandler(authConfig, serviceConfig)); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } })(); } function validateRoleType(value) { if (value !== 'root' && value !== 'child') { throw new Error('role-type must be root or child'); } return value; } function registerWebAppCommands(program) { const webappCmd = program.command('webapp').description('Manage WebApp roles and permissions'); webappCmd.command('permission-list') .description('List WebApp permissions') .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action((options) => withWebAppHandler(program, handler => handler.listPermissions(options))); const roleCmd = webappCmd.command('role').description('WebApp role APIs'); roleCmd.command('list') .description('List WebApp roles') .option('--page-number <page>', 'page number', api_command_1.parsePositiveInteger) .option('--page-size <size>', 'page size', api_command_1.parsePositiveInteger) .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action((options) => withWebAppHandler(program, handler => handler.listRoles(options))); roleCmd.command('get') .description('Get WebApp role detail') .requiredOption('--role-id <id>', 'role ID', api_command_1.parsePositiveInteger) .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action((options) => withWebAppHandler(program, handler => handler.getRole(options))); roleCmd.command('create') .description('Create WebApp role') .requiredOption('--name <name>', 'role name') .option('--desc <desc>', 'role description') .requiredOption('--role-type <type>', 'role type (root|child)', validateRoleType) .requiredOption('--permission-ids <ids>', 'permission IDs, comma-separated', api_command_1.parseNumberList) .option('-f, --force', 'skip confirmation prompt') .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action((options) => withWebAppHandler(program, handler => handler.createRole(options))); roleCmd.command('update') .description('Update WebApp role') .requiredOption('--role-id <id>', 'role ID', api_command_1.parsePositiveInteger) .requiredOption('--name <name>', 'role name') .option('--desc <desc>', 'role description') .requiredOption('--role-type <type>', 'role type (root|child)', validateRoleType) .option('--permission-ids <ids>', 'permission IDs, comma-separated', api_command_1.parseNumberList) .option('-f, --force', 'skip confirmation prompt') .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action((options) => withWebAppHandler(program, handler => handler.updateRole(options))); roleCmd.command('delete') .description('Delete WebApp role') .requiredOption('--role-id <id>', 'role ID', api_command_1.parsePositiveInteger) .option('-f, --force', 'skip confirmation prompt') .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action((options) => withWebAppHandler(program, handler => handler.deleteRole(options))); } //# sourceMappingURL=webapp.commands.js.map