UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

164 lines • 7.01 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.confirmDeletion = confirmDeletion; exports.promptConfirmation = promptConfirmation; exports.isInteractiveEnvironment = isInteractiveEnvironment; exports.validateConfirmationEnvironment = validateConfirmationEnvironment; exports.confirmDangerousOperation = confirmDangerousOperation; const readline = __importStar(require("readline")); async function confirmDeletion(message, expectedInput = 'yes', timeoutMs = 30000) { if (!process.stdin.isTTY) { throw new Error('Interactive confirmation not available in non-TTY environment. Use --force flag to bypass confirmation.'); } return new Promise((resolve, reject) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const timeoutId = setTimeout(() => { rl.close(); reject(new Error(`Confirmation timed out after ${timeoutMs / 1000} seconds`)); }, timeoutMs); console.log(`\n🚨 ${message}`); console.log(`Type '${expectedInput}' to confirm, or anything else to cancel:`); rl.question('> ', (answer) => { clearTimeout(timeoutId); rl.close(); const normalizedAnswer = answer.trim().toLowerCase(); const normalizedExpected = expectedInput.toLowerCase(); const confirmed = normalizedAnswer === normalizedExpected || normalizedAnswer === 'y' || normalizedAnswer === 'yes'; if (confirmed) { console.log('āœ… Confirmed. Proceeding with operation...\n'); } else { console.log('āŒ Cancelled. Operation aborted.\n'); } resolve(confirmed); }); rl.on('SIGINT', () => { clearTimeout(timeoutId); rl.close(); console.log('\nāŒ Operation cancelled by user (Ctrl+C)\n'); resolve(false); }); }); } async function promptConfirmation(message, options = {}) { const { acceptedInputs = ['yes', 'y'], rejectedInputs = ['no', 'n'], timeout = 30000, caseSensitive = false } = options; if (!process.stdin.isTTY) { throw new Error('Interactive confirmation not available in non-TTY environment.'); } return new Promise((resolve, reject) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const timeoutId = setTimeout(() => { rl.close(); reject(new Error(`Confirmation timed out after ${timeout / 1000} seconds`)); }, timeout); console.log(`\n${message}`); console.log(`Accepted inputs: ${acceptedInputs.join(', ')}`); console.log(`Rejected inputs: ${rejectedInputs.join(', ')}`); rl.question('> ', (answer) => { clearTimeout(timeoutId); rl.close(); const processedAnswer = caseSensitive ? answer.trim() : answer.trim().toLowerCase(); const processedAccepted = caseSensitive ? acceptedInputs : acceptedInputs.map(input => input.toLowerCase()); const processedRejected = caseSensitive ? rejectedInputs : rejectedInputs.map(input => input.toLowerCase()); let confirmed; if (processedAccepted.includes(processedAnswer)) { confirmed = true; console.log('āœ… Confirmed. Proceeding with operation...\n'); } else if (processedRejected.includes(processedAnswer)) { confirmed = false; console.log('āŒ Cancelled. Operation aborted.\n'); } else { confirmed = false; console.log(`ā“ Invalid input: "${answer}". Operation cancelled.\n`); } resolve({ confirmed, input: answer.trim() }); }); rl.on('SIGINT', () => { clearTimeout(timeoutId); rl.close(); console.log('\nāŒ Operation cancelled by user (Ctrl+C)\n'); resolve({ confirmed: false, input: '' }); }); }); } function isInteractiveEnvironment() { return process.stdin.isTTY === true; } function validateConfirmationEnvironment(requireForce = true, forceFlag = false) { if (!isInteractiveEnvironment() && requireForce && !forceFlag) { throw new Error('Interactive confirmation not available in non-TTY environment. Use --force flag to bypass confirmation.'); } } async function confirmDangerousOperation(operationName, resourceId, additionalWarnings = []) { console.log('\n' + '='.repeat(60)); console.log('🚨 DANGEROUS OPERATION WARNING 🚨'); console.log('='.repeat(60)); console.log(`Operation: ${operationName.toUpperCase()}`); console.log(`Resource: ${resourceId}`); console.log('='.repeat(60)); if (additionalWarnings.length > 0) { console.log('\nWarnings:'); additionalWarnings.forEach((warning, index) => { console.log(`${index + 1}. ${warning}`); }); } console.log('\nThis action is IRREVERSIBLE and cannot be undone.'); console.log('All data associated with this resource will be permanently lost.'); const confirmed = await confirmDeletion(`Type 'yes' to confirm ${operationName} for ${resourceId}`, 'yes', 60000); console.log('='.repeat(60)); return confirmed; } //# sourceMappingURL=confirmation.js.map