const Penpal = require('penpal').default; /** * Sets up interaction with Vereign Restful API * @param divId - target container to append iframe via Penpal * @param methods - list of methods to be used in iframe * @param iframeUrl - iframe URL to connect * @param apiUrl - API URL used to access API endpoints * @returns {*} */ function setupViamAPI(divId, methods, iframeUrl, apiUrl) { if (!apiUrl) { return Promise.reject('API Host not specified.'); } const connection = Penpal.connectToChild({ // URL of page to load into iframe. url: iframeUrl, // Container to which the iframe should be appended. appendTo: document.getElementById(divId), // Methods parent is exposing to child methods }); return connection.promise .then((child) => child.initializeApiHost(apiUrl).then(() => child)); } window.setupViamAPI = setupViamAPI;