UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

733 lines 35.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LotteryHandler = void 0; const base_handler_1 = require("./base.handler"); const lottery_service_1 = require("../services/lottery-service"); const errors_1 = require("../utils/errors"); const api_command_1 = require("../utils/api-command"); const VALID_LOTTERY_CONDITIONS = ['none', 'invite', 'duration', 'comment', 'question']; class LotteryHandler extends base_handler_1.BaseHandler { constructor(authConfig, serviceConfig) { super(); this.lotteryService = new lottery_service_1.LotteryServiceSdk(authConfig, serviceConfig); } async createLottery(options) { return this.executeWithErrorHandling(async () => { this.validateCreateOptions(options); const params = { channelId: options.channelId, activityName: options.name, lotteryCondition: options.type, amount: options.amount, prizeName: options.prizeName, }; if (options.receiveInfo) { params.receiveEnabled = 'Y'; params.receiveInfo = options.receiveInfo; } if (options.type !== 'none') { if (options.duration !== undefined) { params.duration = options.duration; } if (options.type === 'invite' && options.inviteNum !== undefined) { params.inviteNum = options.inviteNum; } if (options.type === 'comment' && options.comment !== undefined) { params.comment = options.comment; } } await (0, api_command_1.confirmWrite)(options.force, `Create lottery activity "${options.name}" on channel ${options.channelId}?`); const result = await this.lotteryService.createLotteryActivity(params); this.displayCreateResult(result, options); }, 'lottery.create'); } async listLottery(options) { return this.executeWithErrorHandling(async () => { this.validateListOptions(options); const params = { channelId: options.channelId, pageNumber: options.page ?? 1, pageSize: options.size ?? 10, }; const result = await this.lotteryService.listLotteryActivities(params); this.displayListResult(result, options); }, 'lottery.list'); } async getLottery(options) { return this.executeWithErrorHandling(async () => { this.validateGetOptions(options); const result = await this.lotteryService.getLotteryActivity({ channelId: options.channelId, id: options.id, }); this.displayGetResult(result, options); }, 'lottery.get'); } async updateLottery(options) { return this.executeWithErrorHandling(async () => { this.validateUpdateOptions(options); const params = { channelId: options.channelId, id: options.id, }; if (options.name !== undefined) params.activityName = options.name; if (options.amount !== undefined) params.amount = options.amount; if (options.prizeName !== undefined) params.prizeName = options.prizeName; await (0, api_command_1.confirmWrite)(options.force, `Update lottery activity ${options.id} on channel ${options.channelId}?`); const result = await this.lotteryService.updateLotteryActivity(params); this.displayUpdateResult(result, options); }, 'lottery.update'); } async deleteLottery(options) { return this.executeWithErrorHandling(async () => { this.validateDeleteOptions(options); await (0, api_command_1.confirmWrite)(options.force, `Delete lottery activity ${options.id} on channel ${options.channelId}?`); await this.lotteryService.deleteLotteryActivity({ channelId: options.channelId, id: options.id, }); console.log(`Lottery deleted successfully`); console.log(`Channel ID: ${options.channelId}`); console.log(`Activity ID: ${options.id}`); }, 'lottery.delete'); } async getWinners(options) { return this.executeWithErrorHandling(async () => { this.validateWinnersOptions(options); const params = { channelId: options.channelId, lotteryId: options.lotteryId, }; if (options.viewerId !== undefined) params.viewerId = options.viewerId; if (options.page !== undefined) params.page = options.page; if (options.limit !== undefined) params.limit = options.limit; const result = await this.lotteryService.getWinnerDetail(params); this.displayWinnersResult(result, options); }, 'lottery.winners'); } async getRecords(options) { return this.executeWithErrorHandling(async () => { this.validateRecordsOptions(options); const params = { channelId: options.channelId, }; if (options.startTime !== undefined) params.startTime = options.startTime; if (options.endTime !== undefined) params.endTime = options.endTime; if (options.sessionId !== undefined) params.sessionId = options.sessionId; if (options.page !== undefined) params.page = options.page; if (options.limit !== undefined) params.limit = options.limit; const result = await this.lotteryService.listLottery(params); this.displayRecordsResult(result, options); }, 'lottery.records'); } async getChannelRecords(options) { return this.executeWithErrorHandling(async () => { this.validateChannelRecordsOptions(options); const params = { channelIds: options.channelIds, startTime: options.startTime, endTime: options.endTime, }; if (options.sessionId !== undefined) params.sessionId = options.sessionId; if (options.page !== undefined) params.page = options.page; if (options.limit !== undefined) params.limit = options.limit; const result = await this.lotteryService.listChannelsLottery(params); this.displayGenericResult(result, options.output); }, 'lottery.channel-records'); } async getLegacyRecords(options) { return this.executeWithErrorHandling(async () => { this.validateLegacyRecordsOptions(options); const params = { channelId: options.channelId, startTime: options.startTime, endTime: options.endTime, }; if (options.sessionId !== undefined) params.sessionId = options.sessionId; if (options.page !== undefined) params.page = options.page; if (options.limit !== undefined) params.limit = options.limit; const result = await this.lotteryService.listLegacyLottery(params); this.displayRecordsResult(result, options); }, 'lottery.legacy-records'); } async downloadWinners(options) { return this.executeWithErrorHandling(async () => { this.validateDownloadWinnersOptions(options); const result = await this.lotteryService.downloadWinnerDetail({ channelId: options.channelId, lotteryId: options.lotteryId, }); this.displayGenericResult(result, options.output); }, 'lottery.download-winners'); } async addReceiveInfo(options) { return this.executeWithErrorHandling(async () => { this.validateReceiveInfoOptions(options); await (0, api_command_1.confirmWrite)(options.force, `Add receive info for lottery winner ${options.winnerCode}?`); const params = { channelId: options.channelId, lotteryId: options.lotteryId, winnerCode: options.winnerCode, viewerId: options.viewerId, }; const receiveInfo = this.parseReceiveInfo(options.receiveInfo); if (receiveInfo !== undefined) params.receiveInfo = receiveInfo; const result = await this.lotteryService.addReceiveInfoV4(params); this.displayGenericResult(result ?? { success: true }, options.output, 'Receive info saved successfully'); }, 'lottery.receive-info'); } async createWaitLottery(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery wait create', options, ['channelId', 'id', 'lotteryTime'], [], ['lotteryTime']); await (0, api_command_1.confirmWrite)(options.force, `Create wait lottery schedule for lottery ${options.id}?`); const result = await this.lotteryService.createConditionWaitLottery(this.toV4Params(options)); this.displayGenericResult(result ?? { success: true }, options.output, 'Wait lottery scheduled successfully'); }, 'lottery.wait.create'); } async listViewerGroups(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group list', options, ['channelId'], ['page', 'size']); const result = await this.lotteryService.listLotteryViewerGroups(this.toV4Params(options)); this.displayGenericResult(result, options.output); }, 'lottery.group.list'); } async createViewerGroup(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group create', options, ['channelId', 'title']); await (0, api_command_1.confirmWrite)(options.force, `Create lottery viewer group "${options.title}"?`); const result = await this.lotteryService.createLotteryViewerGroup(this.toV4Params(options)); this.displayGenericResult(result, options.output, 'Lottery viewer group created successfully'); }, 'lottery.group.create'); } async updateViewerGroup(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group update', options, ['channelId', 'id', 'title']); await (0, api_command_1.confirmWrite)(options.force, `Update lottery viewer group ${options.id}?`); const result = await this.lotteryService.updateLotteryViewerGroup(this.toV4Params(options)); this.displayGenericResult(result ?? { success: true }, options.output, 'Lottery viewer group updated successfully'); }, 'lottery.group.update'); } async deleteViewerGroup(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group delete', options, ['channelId', 'id']); await (0, api_command_1.confirmWrite)(options.force, `Delete lottery viewer group ${options.id}?`); const result = await this.lotteryService.deleteLotteryViewerGroup(this.toV4Params(options)); this.displayGenericResult(result ?? { success: true }, options.output, 'Lottery viewer group deleted successfully'); }, 'lottery.group.delete'); } async listGroupViewers(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group-viewer list', options, ['channelId', 'groupId'], ['page', 'size']); const result = await this.lotteryService.listLotteryGroupViewers(this.toV4Params(options)); this.displayGenericResult(result, options.output); }, 'lottery.group-viewer.list'); } async createGroupViewers(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group-viewer add', options, ['channelId', 'groupId']); this.validateArrayOption('viewerIds', options.viewerIds, options); await (0, api_command_1.confirmWrite)(options.force, `Add ${options.viewerIds.length} lottery group viewer(s)?`); const result = await this.lotteryService.createLotteryGroupViewers(this.toV4Params(options)); this.displayGenericResult(result, options.output, 'Lottery group viewers added successfully'); }, 'lottery.group-viewer.add'); } async createGroupViewerNames(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group-viewer add-names', options, ['channelId', 'groupId']); this.validateArrayOption('viewerNames', options.viewerNames, options); await (0, api_command_1.confirmWrite)(options.force, `Add ${options.viewerNames.length} lottery group viewer name(s)?`); const result = await this.lotteryService.createLotteryGroupViewerNames(this.toV4Params(options)); this.displayGenericResult(result, options.output, 'Lottery group viewer names added successfully'); }, 'lottery.group-viewer.add-names'); } async deleteGroupViewers(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery group-viewer delete', options, ['channelId', 'groupId']); this.validateArrayOption('ids', options.ids, options); await (0, api_command_1.confirmWrite)(options.force, `Delete ${options.ids.length} lottery group viewer record(s)?`); const result = await this.lotteryService.deleteLotteryGroupViewers(this.toV4Params(options)); this.displayGenericResult(result ?? { success: true }, options.output, 'Lottery group viewers deleted successfully'); }, 'lottery.group-viewer.delete'); } async listBlacklistViewers(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery blacklist list', options, ['channelId'], ['page', 'size']); const result = await this.lotteryService.listLotteryBlacklistViewers(this.toV4Params(options)); this.displayGenericResult(result, options.output); }, 'lottery.blacklist.list'); } async createBlacklistViewers(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery blacklist add', options, ['channelId']); this.validateArrayOption('viewerIds', options.viewerIds, options); await (0, api_command_1.confirmWrite)(options.force, `Add ${options.viewerIds.length} lottery blacklist viewer(s)?`); const result = await this.lotteryService.createLotteryBlacklistViewers(this.toV4Params(options)); this.displayGenericResult(result, options.output, 'Lottery blacklist viewers added successfully'); }, 'lottery.blacklist.add'); } async deleteBlacklistViewers(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery blacklist delete', options, ['channelId']); this.validateArrayOption('ids', options.ids, options); await (0, api_command_1.confirmWrite)(options.force, `Delete ${options.ids.length} lottery blacklist viewer record(s)?`); const result = await this.lotteryService.deleteLotteryBlacklistViewers(this.toV4Params(options)); this.displayGenericResult(result ?? { success: true }, options.output, 'Lottery blacklist viewers deleted successfully'); }, 'lottery.blacklist.delete'); } async listLuckyBagWinners(options) { return this.executeWithErrorHandling(async () => { this.validateGenericOptions('Lottery lucky-bag winners', options, ['activityId'], ['page', 'size']); const result = await this.lotteryService.listLuckyBagWinners(this.toV4Params(options)); this.displayGenericResult(result, options.output); }, 'lottery.lucky-bag.winners'); } validateCreateOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.name || options.name.trim() === '') { errors.push('name is required'); } if (!options.type || !VALID_LOTTERY_CONDITIONS.includes(options.type)) { errors.push('type must be one of: none, invite, duration, comment, question'); } if (typeof options.amount !== 'number' || !Number.isInteger(options.amount) || options.amount < 1) { errors.push('amount must be a positive integer'); } if (!options.prizeName || options.prizeName.trim() === '') { errors.push('prizeName is required'); } if (options.type === 'comment') { if (options.duration === undefined) { errors.push('duration is required for comment lottery'); } if (!options.comment || options.comment.trim() === '') { errors.push('comment is required for comment lottery'); } } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery create options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateListOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (options.page !== undefined) { if (typeof options.page !== 'number' || !Number.isInteger(options.page) || options.page < 1) { errors.push('page must be a positive integer'); } } if (options.size !== undefined) { if (typeof options.size !== 'number' || !Number.isInteger(options.size) || options.size < 1) { errors.push('size must be a positive integer'); } } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery list options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateGetOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.id || options.id.trim() === '') { errors.push('id is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery get options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateUpdateOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.id || options.id.trim() === '') { errors.push('id is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery update options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateDeleteOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.id || options.id.trim() === '') { errors.push('id is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery delete options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateWinnersOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.lotteryId || options.lotteryId.trim() === '') { errors.push('lotteryId is required'); } if (options.viewerId !== undefined && options.viewerId.trim() === '') { errors.push('viewerId must not be empty'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery winners options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateRecordsOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (typeof options.startTime !== 'number' || !Number.isInteger(options.startTime)) { errors.push('startTime is required'); } if (typeof options.endTime !== 'number' || !Number.isInteger(options.endTime)) { errors.push('endTime is required'); } if (typeof options.startTime === 'number' && typeof options.endTime === 'number' && options.startTime > options.endTime) { errors.push('startTime must be less than or equal to endTime'); } if (options.page !== undefined && (!Number.isInteger(options.page) || options.page < 1)) { errors.push('page must be a positive integer'); } if (options.limit !== undefined && (!Number.isInteger(options.limit) || options.limit < 1)) { errors.push('limit must be a positive integer'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery records options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateChannelRecordsOptions(options) { const errors = []; if (!Array.isArray(options.channelIds) || options.channelIds.length === 0) { errors.push('channelIds is required'); } this.validatePositiveNumber(errors, 'startTime', options.startTime); this.validatePositiveNumber(errors, 'endTime', options.endTime); this.validateOptionalPositiveInteger(errors, 'page', options.page); this.validateOptionalPositiveInteger(errors, 'limit', options.limit); if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery channel records options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateLegacyRecordsOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } this.validatePositiveNumber(errors, 'startTime', options.startTime); this.validatePositiveNumber(errors, 'endTime', options.endTime); this.validateOptionalPositiveInteger(errors, 'page', options.page); this.validateOptionalPositiveInteger(errors, 'limit', options.limit); if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery legacy records options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateDownloadWinnersOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.lotteryId || options.lotteryId.trim() === '') { errors.push('lotteryId is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery download winners options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateReceiveInfoOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.lotteryId || options.lotteryId.trim() === '') { errors.push('lotteryId is required'); } if (!options.winnerCode || options.winnerCode.trim() === '') { errors.push('winnerCode is required'); } if (!options.viewerId || options.viewerId.trim() === '') { errors.push('viewerId is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Lottery receive info options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validatePositiveNumber(errors, field, value) { if (!Number.isFinite(value) || value <= 0) { errors.push(`${field} must be a positive number`); } } validateOptionalPositiveInteger(errors, field, value) { if (value === undefined) return; if (!Number.isInteger(value) || value < 1) { errors.push(`${field} must be a positive integer`); } } validateGenericOptions(label, options, requiredFields, positiveIntegerFields = [], positiveNumberFields = []) { const errors = []; requiredFields.forEach((field) => { const value = options[field]; if (value === undefined || value === null || (typeof value === 'string' && value.trim() === '')) { errors.push(`${field} is required`); } }); positiveIntegerFields.forEach((field) => { const value = options[field]; if (value !== undefined && (!Number.isInteger(value) || value < 1)) { errors.push(`${field} must be a positive integer`); } }); positiveNumberFields.forEach((field) => { const value = options[field]; if (value !== undefined && (!Number.isFinite(value) || value <= 0)) { errors.push(`${field} must be a positive number`); } }); if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`${label} options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateArrayOption(field, value, options) { if (!Array.isArray(value) || value.length === 0) { throw new errors_1.PolyVValidationError(`${field} must be a non-empty array`, 'options', options, 'validation_failed'); } } toV4Params(options) { const params = (0, api_command_1.apiParams)(options); if (params.page !== undefined) { params.pageNumber = params.page; delete params.page; } if (params.size !== undefined) { params.pageSize = params.size; delete params.size; } return params; } displayCreateResult(result, options) { const data = result?.data ?? result; const activityId = data?.id || data?.activityId || data?.lotteryActivityId || 'N/A'; if (options.output === 'json') { this.displayData({ channelId: options.channelId, activityId, name: options.name, type: options.type, amount: options.amount, prizeName: options.prizeName, result }, 'json'); } else { console.log(`Lottery created successfully`); console.log(`Channel ID: ${options.channelId}`); console.log(`Activity ID: ${activityId}`); console.log(`Name: ${options.name}`); console.log(`Type: ${options.type}`); console.log(`Amount: ${options.amount}`); console.log(`Prize: ${options.prizeName}`); } } displayListResult(result, options) { const data = result?.data ?? result; const contents = data?.contents || []; const totalItems = data?.totalItems || contents.length; if (contents.length === 0) { this.displayInfo(`No lottery activities found for channel ${options.channelId}`); return; } if (options.output === 'json') { this.displayData({ channelId: options.channelId, totalItems, data: contents }, 'json'); } else { const tableData = contents.map((item) => ({ 'ID': item.id || '-', 'Name': this.truncate(item.activityName || '-', 30), 'Type': item.lotteryCondition || '-', 'Status': item.status || '-', 'Amount': item.amount || '-', 'Prize': this.truncate(item.prizeName || '-', 20), })); console.log(`Found ${totalItems} lottery activities`); this.displayAsTable(tableData); } } displayGetResult(result, options) { const data = result?.data ?? result; if (!data) { this.displayInfo(`No lottery activity found with ID ${options.id}`); return; } if (options.output === 'json') { this.displayData({ channelId: options.channelId, data }, 'json'); } else { console.log(`Lottery Activity Details`); console.log(`Channel ID: ${options.channelId}`); console.log(`ID: ${data.id || '-'}`); console.log(`Name: ${data.activityName || '-'}`); console.log(`Type: ${data.lotteryCondition || '-'}`); console.log(`Status: ${data.status || '-'}`); console.log(`Amount: ${data.amount || '-'}`); console.log(`Prize: ${data.prizeName || '-'}`); } } displayUpdateResult(result, options) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, id: options.id, result }, 'json'); } else { console.log(`Lottery updated successfully`); console.log(`Channel ID: ${options.channelId}`); console.log(`Activity ID: ${options.id}`); } } displayWinnersResult(result, options) { const data = result?.data?.contents || result?.data || []; if (!data || (Array.isArray(data) && data.length === 0)) { this.displayInfo(`No winners found for lottery ${options.lotteryId}`); return; } if (options.output === 'json') { this.displayData({ channelId: options.channelId, lotteryId: options.lotteryId, data }, 'json'); } else { const tableData = data.map((item) => ({ 'ID': this.truncate(item.viewerId || '-', 10), 'Nickname': this.truncate(item.nick || '-', 20), 'Winner Code': item.winnerCode || '-', 'Win Time': item.winTime ? new Date(item.winTime).toLocaleString() : '-', })); console.log(`Found ${data.length} winners`); this.displayAsTable(tableData); } } displayRecordsResult(result, options) { const data = result?.data?.contents || result?.data || []; if (!data || (Array.isArray(data) && data.length === 0)) { this.displayInfo(`No lottery records found for channel ${options.channelId}`); return; } if (options.output === 'json') { this.displayData({ channelId: options.channelId, data }, 'json'); } else { const tableData = data.map((item) => ({ 'Lottery ID': this.truncate(item.lotteryId || '-', 10), 'Session ID': this.truncate(item.sessionId || '-', 10), 'Prize': this.truncate(item.prize || '-', 20), 'Amount': item.amount || '-', 'Winners': item.winnerCount || '-', 'Created Time': item.createdTime ? new Date(item.createdTime).toLocaleString() : '-', })); console.log(`Found ${data.length} lottery records`); this.displayAsTable(tableData); } } displayGenericResult(result, format, successMessage) { if (successMessage && format !== 'json') { this.displaySuccess(successMessage); } this.displayData(result ?? { success: true }, format || 'table'); } parseReceiveInfo(value) { if (value === undefined || typeof value !== 'string') { return value; } const parsed = JSON.parse(value); if (!parsed || typeof parsed !== 'object') { throw new errors_1.PolyVValidationError('receiveInfo must be a JSON object or array', 'receiveInfo', value, 'validation_failed'); } return parsed; } truncate(str, maxLength) { if (!str) return '-'; return str.length > maxLength ? str.substring(0, maxLength) + '...' : str; } } exports.LotteryHandler = LotteryHandler; //# sourceMappingURL=lottery.handler.js.map