UNPKG

@voximplant/voxengine-ci

Version:

Manage Voximplant Platform `applications`, `rules` and `scenarios` from your own environment

49 lines (48 loc) 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VoxApplicationPlatformRepository = void 0; const Enums_1 = require("@voximplant/apiclient-nodejs/dist/Enums"); const api_error_response_type_1 = require("../types/api-error-response.type"); const log_message_generator_1 = require("../../utils/log-message-generator"); class VoxApplicationPlatformRepository { constructor(context) { this.context = context; this.lmg = log_message_generator_1.LogMessageGeneratorFactory.getInstance(); this.init = () => { console.info(this.lmg.generate('INFO__INIT_SUCCESS', this.constructor.name)); }; this.downloadApplications = async () => { const response = await this.context.client.Applications.getApplications({}); if ((0, api_error_response_type_1.isApiErrorResponse)(response)) { throw new Error(this.lmg.generate('ERR__VOXIMPLANT_API_ERROR', Enums_1.APIErrorCode[response.error.code])); } if (response.totalCount === 0) return []; const { result } = await this.context.client.Applications.getApplications({ withRules: true, count: response.totalCount, }); console.info(this.lmg.generate('INFO__APPLICATIONS_DOWNLOADED')); return result; }; this.getAccountName = async () => { const response = await this.context.client.Accounts.getAccountInfo({}); if ((0, api_error_response_type_1.isApiErrorResponse)(response)) { throw new Error(this.lmg.generate('ERR__VOXIMPLANT_API_ERROR', Enums_1.APIErrorCode[response.error.code])); } return response.result.accountName; }; this.addApplication = async (applicationName) => { const response = await this.context.client.Applications.addApplication({ applicationName, }); if ((0, api_error_response_type_1.isApiErrorResponse)(response)) { throw new Error(this.lmg.generate('ERR__VOXIMPLANT_API_ERROR', Enums_1.APIErrorCode[response.error.code])); } const { applicationId } = response; console.info(this.lmg.generate('INFO__APPLICATION_UPLOADED', applicationId.toString(), applicationName)); return applicationId; }; } } exports.VoxApplicationPlatformRepository = VoxApplicationPlatformRepository;