UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

248 lines 11.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserSettingsHandler = void 0; const base_handler_1 = require("./base.handler"); const errors_1 = require("../utils/errors"); const api_command_1 = require("../utils/api-command"); const user_service_1 = require("../services/user.service"); class UserSettingsHandler extends base_handler_1.BaseHandler { constructor(authConfig, serviceConfig) { super(); this.service = new user_service_1.UserSettingsServiceSdk(authConfig, serviceConfig); } async listChildren(options) { this.show(await this.service.listChildAccounts(this.pagingParams(options)), options.output); } async listChildRoles(options) { this.show(await this.service.listChildAccountRoles(), options.output); } async createChild(options) { await (0, api_command_1.confirmWrite)(options.force, `Create child account ${options.childEmail}?`); this.show({ success: true, result: await this.service.createChildAccount((0, api_command_1.apiParams)({ childEmail: options.childEmail, childName: options.childName, password: options.password, roleId: options.roleId, organizationId: options.organizationId, telephone: options.telephone, description: options.description, })), }, options.output); } async updateChild(options) { const params = (0, api_command_1.apiParams)({ childEmail: options.childEmail, childName: options.childName, password: options.password, roleId: options.roleId, organizationId: options.organizationId, telephone: options.telephone, description: options.description, }); this.requireNonEmptyUpdate(params, 'child update'); await (0, api_command_1.confirmWrite)(options.force, `Update child account ${options.childEmail}?`); await this.service.updateChildAccount(params); this.show({ success: true, ...params }, options.output); } async deleteChild(options) { await (0, api_command_1.confirmWrite)(options.force, `Delete child account ${options.childEmail}?`); await this.service.deleteChildAccount({ childEmail: options.childEmail }); this.show({ success: true, childEmail: options.childEmail }, options.output); } async getChildBySale(options) { if (!options.saleId && !options.saleCode) { throw this.validationError('saleId or saleCode is required', 'sale', options); } this.show(await this.service.getChildBySale((0, api_command_1.apiParams)({ saleId: options.saleId, saleCode: options.saleCode, })), options.output); } async listOrganizations(options) { this.show(await this.service.listOrganizations(), options.output); } async createOrganization(options) { await (0, api_command_1.confirmWrite)(options.force, `Create organization ${options.name}?`); this.show({ success: true, result: await this.service.createOrganization((0, api_command_1.apiParams)({ name: options.name, parentId: options.parentId, description: options.description, })), }, options.output); } async deleteOrganization(options) { await (0, api_command_1.confirmWrite)(options.force, `Delete organization ${options.organizationId}?`); await this.service.deleteOrganization({ organizationId: options.organizationId }); this.show({ success: true, organizationId: options.organizationId }, options.output); } async getDonateTemplate(options) { this.show(await this.service.getDonateTemplate(), options.output); } async updateDonateTemplate(options) { const params = (0, api_command_1.apiParams)({ donateGiftEnabled: options.donateGiftEnabled, giftDonate: options.giftDonate, }); await (0, api_command_1.confirmWrite)(options.force, 'Update donate template?'); await this.service.updateDonateTemplate(params); this.show({ success: true, ...params }, options.output); } async getMarqueeTemplate(options) { this.show(await this.service.getMarqueeTemplate(), options.output); } async updateMarqueeTemplate(options) { const params = (0, api_command_1.apiParams)({ enable: options.enable, antiRecordType: options.antiRecordType, modelType: options.modelType, content: options.content, opacity: options.opacity, fontSize: options.fontSize, fontColor: options.fontColor, showMode: options.showMode, doubleEnabled: options.doubleEnabled, autoZoomEnabled: options.autoZoomEnabled, }); await (0, api_command_1.confirmWrite)(options.force, 'Update marquee template?'); await this.service.updateMarqueeTemplate(params); this.show({ success: true, ...params }, options.output); } async getRoleConfigTemplate(options) { this.show(await this.service.getRoleConfigTemplate(), options.output); } async updateRoleConfigTemplate(options) { this.requireNonEmptyUpdate(options.config, 'role config template'); await (0, api_command_1.confirmWrite)(options.force, 'Update role config template?'); await this.service.updateRoleConfigTemplate(options.config); this.show({ success: true, ...options.config }, options.output); } async getPlaybackSetting(options) { this.show(await this.service.getPlaybackSetting(), options.output); } async updatePlaybackSetting(options) { this.requireNonEmptyUpdate(options.config, 'playback setting'); await (0, api_command_1.confirmWrite)(options.force, 'Update playback setting?'); await this.service.updatePlaybackSetting(options.config); this.show({ success: true, ...options.config }, options.output); } async getAudioModerationSetting(options) { this.show(await this.service.getAudioModerationSetting(), options.output); } async updateAudioModerationSetting(options) { const params = (0, api_command_1.apiParams)({ moderationEnabled: options.moderationEnabled, moderationStrategy: options.moderationStrategy, badwordEnabled: options.badwordEnabled, illegalNotify: options.illegalNotify, }); await (0, api_command_1.confirmWrite)(options.force, 'Update audio moderation setting?'); await this.service.updateAudioModerationSetting(params); this.show({ success: true, ...params }, options.output); } async getVideoModerationSetting(options) { this.show(await this.service.getVideoModerationSetting(), options.output); } async updateVideoModerationSetting(options) { const params = (0, api_command_1.apiParams)({ moderationEnabled: options.moderationEnabled, moderationStrategy: options.moderationStrategy, imageFrequency: options.imageFrequency, illegalNotify: options.illegalNotify, }); await (0, api_command_1.confirmWrite)(options.force, 'Update video moderation setting?'); await this.service.updateVideoModerationSetting(params); this.show({ success: true, ...params }, options.output); } async getGlobalFooter(options) { this.show(await this.service.getGlobalFooter(), options.output); } async updateGlobalFooter(options) { const params = (0, api_command_1.apiParams)({ showFooterEnabled: options.showFooterEnabled, footerText: options.footerText, footTextLinkProtocol: options.footTextLinkProtocol, footTextLinkUrl: options.footTextLinkUrl, }); this.requireNonEmptyUpdate(params, 'global footer'); await (0, api_command_1.confirmWrite)(options.force, 'Update global footer?'); await this.service.updateGlobalFooter(params); this.show({ success: true, ...params }, options.output); } async getPvShowEnable(options) { this.show(await this.service.getPvShowEnable(), options.output); } async updatePvShowEnable(options) { await (0, api_command_1.confirmWrite)(options.force, 'Update PV show setting?'); await this.service.updatePvShowEnable({ enabled: options.enabled }); this.show({ success: true, enabled: options.enabled }, options.output); } async sendSms(options) { const phoneNumbers = (0, api_command_1.parseStringList)(options.phoneNumbers); if (phoneNumbers.length > 200) { throw this.validationError('phoneNumbers cannot exceed 200 items', 'phoneNumbers', options.phoneNumbers); } const templateParamNames = (0, api_command_1.parseStringList)(options.templateParamNames); const templateParamValues = (0, api_command_1.parseStringList)(options.templateParamValues); if (templateParamNames.length !== templateParamValues.length) { throw this.validationError('templateParamNames and templateParamValues must have the same length', 'templateParamValues', options.templateParamValues); } const params = { phoneNumbers, templateParamNames, templateParamValues }; await (0, api_command_1.confirmWrite)(options.force, `Send SMS to ${phoneNumbers.length} phone number(s)?`); await this.service.sendSms(params); this.show({ success: true, ...params }, options.output); } async getMicDuration(options) { this.show(await this.service.getMicDuration((0, api_command_1.apiParams)({ startTime: options.startTime, endTime: options.endTime, })), options.output); } async getMrConcurrencyDetail(options) { this.show(await this.service.getMrConcurrencyDetail(), options.output); } async getBillUseDetailList(options) { this.show(await this.service.getBillUseDetailList(this.pagingParams({ ...options, itemCategory: options.itemCategory, startDate: options.startDate, endDate: options.endDate, channelId: options.channelId, })), options.output); } async listWatchLogs(options) { this.show(await this.service.getWatchLogList(this.pagingParams(options)), options.output); } async getWatchLogDetail(options) { this.show(await this.service.getWatchLogDetail(this.pagingParams({ ...options, viewerId: options.viewerId, })), options.output); } pagingParams(options) { const { page, size, pageNumber, pageSize, output, force, ...rest } = options; void output; void force; return (0, api_command_1.compactParams)({ ...rest, pageNumber: page ?? pageNumber, pageSize: size ?? pageSize, }); } requireNonEmptyUpdate(params, label) { if (!params || Object.keys(params).length === 0) { throw this.validationError(`${label} update payload must not be empty`, 'config', params); } } validationError(message, field, value) { return new errors_1.PolyVValidationError(message, field, value, 'validation_failed'); } show(data, output = 'table') { this.displayData(data, output); } } exports.UserSettingsHandler = UserSettingsHandler; //# sourceMappingURL=user-settings.handler.js.map