@teaploy/megaprint
Version:
Megaprint npm integration
30 lines (29 loc) • 1.56 kB
JavaScript
;
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
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.post = void 0;
const node_fetch_1 = require("node-fetch");
const xml2js_1 = require("xml2js");
const actions_1 = require("./actions");
exports.post = (action, body, env, token = '') => __awaiter(void 0, void 0, void 0, function* () {
const url = actions_1.actionsUrl[env];
if (!url[action]) {
throw new Error('Invalid request action');
}
const options = {
method: 'POST',
body,
headers: Object.assign({ 'Content-Type': 'application/xml' }, (token !== '' && { Authorization: `Bearer ${token}` })),
};
const xmlResponse = yield node_fetch_1.default(url[action], options).then((response) => response.text());
return xml2js_1.parseStringPromise(xmlResponse);
});