Skip to content
Snippets Groups Projects
viamapi-client.js 865 B
Newer Older
  • Learn to ignore specific revisions
  • 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
    
    	return connection.promise
    		.then((child) => child.initializeApiHost(apiUrl).then(() => child))
    
    
    window.setupViamAPI = setupViamAPI;