UNPKG

@teaploy/megaprint

Version:
39 lines (38 loc) 1.88 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Configuration = void 0; const xml2js_1 = require("xml2js"); const utils_1 = require("../utils"); class Configuration { constructor(user, apiKey, env = utils_1.Environment.development, emitter) { this.apiToken = ''; this.user = user; this.apiKey = apiKey; this.environment = env; this.emitter = emitter; } init() { return __awaiter(this, void 0, void 0, function* () { const xmlBuilder = new xml2js_1.Builder(); const body = xmlBuilder.buildObject({ SolicitaTokenRequest: { usuario: this.user, apikey: this.apiKey }, }); const response = yield utils_1.Request.post(utils_1.Actions.generateToken, body, this.environment); if (response.SolicitaTokenResponse.tipo_respuesta[0] === '1') { console.error(response.SolicitaTokenResponse.listado_errores[0].error); throw new Error('Invalid authentication values'); } this.apiToken = response.SolicitaTokenResponse.token[0]; }); } } exports.Configuration = Configuration;