UNPKG

@voximplant/voxengine-ci

Version:

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

43 lines (42 loc) 2.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VoximplantContext = void 0; const apiclient_nodejs_1 = __importDefault(require("@voximplant/apiclient-nodejs")); const log_message_generator_1 = require("../../utils/log-message-generator"); class VoximplantContext { constructor(credentials) { this.credentials = credentials; this.lmg = log_message_generator_1.LogMessageGeneratorFactory.getInstance(); this.init = async () => /** * TODO: Check the 'await' keyword in the `await new Promise...` solution for the 'zero-cost async stack traces' api * V8 Official Documentation - https://v8.dev/docs/stack-trace-api * V8 Official LLD Google Doc - https://docs.google.com/document/d/13Sy_kBIJGP0XT34V1CV3nkWya4TwYx9L3Yv45LdGB6Q/edit * Outside information - https://cloudreports.net/v8-zero-cost-async-stack-traces/ */ await new Promise((resolve, reject) => { const uncaughtExceptionListener = (error) => { // @ts-expect-error 'error specific fields' if (error.code === 'ENOENT') { console.error(this.lmg.generate('ERR__INIT_FAILED', this.constructor.name)); } if (error.name === 'SyntaxError' && error.message.includes('JSON input')) { console.error(this.lmg.generate('ERR__INIT_FAILED_WRONG_CREDENTIALS_FILE_FORMAT', this.constructor.name)); } reject(error); }; process.on('uncaughtException', uncaughtExceptionListener); this.client = new apiclient_nodejs_1.default(this.credentials); this.client.onReady = () => { console.info(this.lmg.generate('INFO__INIT_SUCCESS', this.constructor.name)); process.off('uncaughtException', uncaughtExceptionListener); resolve(); }; }); } } exports.VoximplantContext = VoximplantContext;