UNPKG

@transferwise/approve-api-action-helpers

Version:

An http client that handles SCA protected requests gracefully

2 lines (1 loc) 37.1 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).twApproveApiActionHelpers={})}(this,(function(e){"use strict";function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){i(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,l(o.key),o)}}function i(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,n){return u=c()?Reflect.construct.bind():function(e,t,n){var o=[null];o.push.apply(o,t);var i=new(Function.bind.apply(e,o));return n&&a(i,n.prototype),i},u.apply(null,arguments)}function s(e){var t="function"==typeof Map?new Map:void 0;return s=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return u(e,arguments,r(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),a(o,e)},s(e)}function d(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var f="tw-approve-api-action-success",m="tw-approve-api-action-failed",p="tw-approve-api-action-closed",h={exports:{}};!function(e){!function(t){if("undefined"!=typeof window){var n,o=0,i=!1,r=!1,a=7,c="[iFrameSizer]",u=c.length,s=null,d=window.requestAnimationFrame,l=Object.freeze({max:1,scroll:1,bodyScroll:1,documentElementScroll:1}),f={},m=null,p=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,inPageLinks:!1,enablePublicMethods:!0,heightCalculationMethod:"bodyOffset",id:"iFrameResizer",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,mouseEvents:!0,resizeFrom:"parent",scrolling:!1,sizeHeight:!0,sizeWidth:!1,warningTimeout:5e3,tolerance:0,widthCalculationMethod:"scroll",onClose:function(){return!0},onClosed:function(){},onInit:function(){},onMessage:function(){T("onMessage function not defined")},onMouseEnter:function(){},onMouseLeave:function(){},onResized:function(){},onScroll:function(){return!0}}),h={};window.jQuery!==t&&((n=window.jQuery).fn?n.fn.iFrameResize||(n.fn.iFrameResize=function(e){return this.filter("iframe").each((function(t,n){L(n,e)})).end()}):E("","Unable to bind to jQuery, it is not fully loaded.")),"function"==typeof t&&t.amd?t([],D):e.exports=D(),window.iFrameResize=window.iFrameResize||D()}function g(){return window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver}function w(e,t,n){e.addEventListener(t,n,!1)}function v(e,t,n){e.removeEventListener(t,n,!1)}function y(e){return c+"["+function(e){var t="Host page: "+e;return window.top!==window.self&&(t=window.parentIFrame&&window.parentIFrame.getId?window.parentIFrame.getId()+": "+e:"Nested host page: "+e),t}(e)+"]"}function b(e){return f[e]?f[e].log:i}function O(e,t){M("log",e,t,b(e))}function E(e,t){M("info",e,t,b(e))}function T(e,t){M("warn",e,t,!0)}function M(e,t,n,o){!0===o&&"object"==typeof window.console&&console[e](y(t),n)}function x(e){function t(){i("Height"),i("Width"),F((function(){C(U),R(B),y("onResized",U)}),U,"init")}function n(e){return"border-box"!==e.boxSizing?0:(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}function o(e){return"border-box"!==e.boxSizing?0:(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}function i(e){var t=Number(f[B]["max"+e]),n=Number(f[B]["min"+e]),o=e.toLowerCase(),i=Number(U[o]);O(B,"Checking "+o+" is in range "+n+"-"+t),i<n&&(i=n,O(B,"Set "+o+" to min value")),i>t&&(i=t,O(B,"Set "+o+" to max value")),U[o]=""+i}function r(e){return H.slice(H.indexOf(":")+a+e)}function d(e,t){var n,o,i;n=function(){var n,o;j("Send Page Info","pageInfo:"+(n=document.body.getBoundingClientRect(),o=U.iframe.getBoundingClientRect(),JSON.stringify({iframeHeight:o.height,iframeWidth:o.width,clientHeight:Math.max(document.documentElement.clientHeight,window.innerHeight||0),clientWidth:Math.max(document.documentElement.clientWidth,window.innerWidth||0),offsetTop:parseInt(o.top-n.top,10),offsetLeft:parseInt(o.left-n.left,10),scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,documentHeight:document.documentElement.clientHeight,documentWidth:document.documentElement.clientWidth,windowHeight:window.innerHeight,windowWidth:window.innerWidth})),e,t)},o=32,h[i=t]||(h[i]=setTimeout((function(){h[i]=null,n()}),o))}function l(e){var t=e.getBoundingClientRect();return P(B),{x:Math.floor(Number(t.left)+Number(s.x)),y:Math.floor(Number(t.top)+Number(s.y))}}function m(e){var t=e?l(U.iframe):{x:0,y:0},n={x:Number(U.width)+t.x,y:Number(U.height)+t.y};O(B,"Reposition requested from iFrame (offset x:"+t.x+" y:"+t.y+")"),window.top===window.self?(s=n,p(),O(B,"--")):window.parentIFrame?window.parentIFrame["scrollTo"+(e?"Offset":"")](n.x,n.y):T(B,"Unable to scroll to requested position, window.parentIFrame not found")}function p(){!1===y("onScroll",s)?z():R(B)}function g(e){var t={};if(0===Number(U.width)&&0===Number(U.height)){var n=r(9).split(":");t={x:n[1],y:n[0]}}else t={x:U.width,y:U.height};y(e,{iframe:U.iframe,screenX:Number(t.x),screenY:Number(t.y),type:U.type})}function y(e,t){return I(B,e,t)}var b,M,x,k,L,W,H=e.data,U={},B=null;"[iFrameResizerChild]Ready"===H?function(){for(var e in f)j("iFrame requested init",A(e),f[e].iframe,e)}():c===(""+H).slice(0,u)&&H.slice(u).split(":")[0]in f?(x=H.slice(u).split(":"),k=x[1]?parseInt(x[1],10):0,L=f[x[0]]&&f[x[0]].iframe,W=getComputedStyle(L),U={iframe:L,id:x[0],height:k+n(W)+o(W),width:x[2],type:x[3]},B=U.id,f[B]&&(f[B].loaded=!0),(M=U.type in{true:1,false:1,undefined:1})&&O(B,"Ignoring init message from meta parent page"),!M&&function(e){var t=!0;return f[e]||(t=!1,T(U.type+" No settings for "+e+". Message was: "+H)),t}(B)&&(O(B,"Received: "+H),b=!0,null===U.iframe&&(T(B,"IFrame ("+U.id+") not found"),b=!1),b&&function(){var t,n=e.origin,o=f[B]&&f[B].checkOrigin;if(o&&""+n!="null"&&!(o.constructor===Array?function(){var e=0,t=!1;for(O(B,"Checking connection is from allowed list of origins: "+o);e<o.length;e++)if(o[e]===n){t=!0;break}return t}():(t=f[B]&&f[B].remoteHost,O(B,"Checking connection is from: "+t),n===t)))throw new Error("Unexpected message received from: "+n+" for "+U.iframe.id+". Message was: "+e.data+". This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.");return!0}()&&function(){switch(f[B]&&f[B].firstRun&&f[B]&&(f[B].firstRun=!1),U.type){case"close":S(U.iframe);break;case"message":a=r(6),O(B,"onMessage passed: {iframe: "+U.iframe.id+", message: "+a+"}"),y("onMessage",{iframe:U.iframe,message:JSON.parse(a)}),O(B,"--");break;case"mouseenter":g("onMouseEnter");break;case"mouseleave":g("onMouseLeave");break;case"autoResize":f[B].autoResize=JSON.parse(r(9));break;case"scrollTo":m(!1);break;case"scrollToOffset":m(!0);break;case"pageInfo":d(f[B]&&f[B].iframe,B),function(){function e(e,o){function i(){f[n]?d(f[n].iframe,n):t()}["scroll","resize"].forEach((function(t){O(n,e+t+" listener for sendPageInfo"),o(window,t,i)}))}function t(){e("Remove ",v)}var n=B;e("Add ",w),f[n]&&(f[n].stopPageInfo=t)}();break;case"pageInfoStop":f[B]&&f[B].stopPageInfo&&(f[B].stopPageInfo(),delete f[B].stopPageInfo);break;case"inPageLink":n=r(9).split("#")[1]||"",o=decodeURIComponent(n),(i=document.getElementById(o)||document.getElementsByName(o)[0])?(e=l(i),O(B,"Moving to in page link (#"+n+") at x: "+e.x+" y: "+e.y),s={x:e.x,y:e.y},p(),O(B,"--")):window.top===window.self?O(B,"In page link #"+n+" not found"):window.parentIFrame?window.parentIFrame.moveToAnchor(n):O(B,"In page link #"+n+" not found and window.parentIFrame not found");break;case"reset":N(U);break;case"init":t(),y("onInit",U.iframe);break;default:0===Number(U.width)&&0===Number(U.height)?T("Unsupported message received ("+U.type+"), this is likely due to the iframe containing a later version of iframe-resizer than the parent page"):t()}var e,n,o,i,a}())):E(B,"Ignored: "+H)}function I(e,t,n){var o=null,i=null;if(f[e]){if("function"!=typeof(o=f[e][t]))throw new TypeError(t+" on iFrame["+e+"] is not a function");i=o(n)}return i}function k(e){var t=e.id;delete f[t]}function S(e){var t=e.id;if(!1!==I(t,"onClose",t)){O(t,"Removing iFrame: "+t);try{e.parentNode&&e.parentNode.removeChild(e)}catch(e){T(e)}I(t,"onClosed",t),O(t,"--"),k(e)}else O(t,"Close iframe cancelled by onClose event")}function P(e){null===s&&O(e,"Get page position: "+(s={x:window.pageXOffset===t?document.documentElement.scrollLeft:window.pageXOffset,y:window.pageYOffset===t?document.documentElement.scrollTop:window.pageYOffset}).x+","+s.y)}function R(e){null!==s&&(window.scrollTo(s.x,s.y),O(e,"Set page position: "+s.x+","+s.y),z())}function z(){s=null}function N(e){O(e.id,"Size reset requested by "+("init"===e.type?"host page":"iFrame")),P(e.id),F((function(){C(e),j("reset","reset",e.iframe,e.id)}),e,"reset")}function C(e){function t(t){r||"0"!==e[t]||(r=!0,O(o,"Hidden iFrame detected, creating visibility listener"),function(){function e(){function e(e){function t(t){return"0px"===(f[e]&&f[e].iframe.style[t])}function n(e){return null!==e.offsetParent}f[e]&&n(f[e].iframe)&&(t("height")||t("width"))&&j("Visibility change","resize",f[e].iframe,e)}Object.keys(f).forEach((function(t){e(t)}))}function t(t){O("window","Mutation observed: "+t[0].target+" "+t[0].type),W(e,16)}function n(){var e=document.querySelector("body"),n={attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0};new o(t).observe(e,n)}var o=g();o&&n()}())}function n(n){!function(t){e.id?(e.iframe.style[t]=e[t]+"px",O(e.id,"IFrame ("+o+") "+t+" set to "+e[t]+"px")):O("undefined","messageData id not set")}(n),t(n)}var o=e.iframe.id;f[o]&&(f[o].sizeHeight&&n("height"),f[o].sizeWidth&&n("width"))}function F(e,t,n){n!==t.type&&d&&!window.jasmine?(O(t.id,"Requesting animation frame"),d(e)):e()}function j(e,t,n,o,i){var r,a=!1;o=o||n.id,f[o]&&(n&&"contentWindow"in n&&null!==n.contentWindow?(r=f[o]&&f[o].targetOrigin,O(o,"["+e+"] Sending msg to iframe["+o+"] ("+t+") targetOrigin: "+r),n.contentWindow.postMessage(c+t,r)):T(o,"["+e+"] IFrame("+o+") not found"),i&&f[o]&&f[o].warningTimeout&&(f[o].msgTimeout=setTimeout((function(){!f[o]||f[o].loaded||a||(a=!0,T(o,"IFrame has not responded within "+f[o].warningTimeout/1e3+" seconds. Check iFrameResizer.contentWindow.js has been loaded in iFrame. This message can be ignored if everything is working, or you can set the warningTimeout option to a higher value or zero to suppress this warning."))}),f[o].warningTimeout)))}function A(e){return e+":"+f[e].bodyMarginV1+":"+f[e].sizeWidth+":"+f[e].log+":"+f[e].interval+":"+f[e].enablePublicMethods+":"+f[e].autoResize+":"+f[e].bodyMargin+":"+f[e].heightCalculationMethod+":"+f[e].bodyBackground+":"+f[e].bodyPadding+":"+f[e].tolerance+":"+f[e].inPageLinks+":"+f[e].resizeFrom+":"+f[e].widthCalculationMethod+":"+f[e].mouseEvents}function L(e,n){function r(e){var t=e.split("Callback");if(2===t.length){var n="on"+t[0].charAt(0).toUpperCase()+t[0].slice(1);this[n]=this[e],delete this[e],T(u,"Deprecated: '"+e+"' has been renamed '"+n+"'. The old method will be removed in the next major version.")}}var a,c,u=function(t){if("string"!=typeof t)throw new TypeError("Invaild id for iFrame. Expected String");var r;return""===t&&(e.id=(r=n&&n.id||p.id+o++,null!==document.getElementById(r)&&(r+=o++),t=r),i=(n||{}).log,O(t,"Added missing iframe ID: "+t+" ("+e.src+")")),t}(e.id);u in f&&"iFrameResizer"in e?T(u,"Ignored iFrame, already setup."):(!function(t){var n;t=t||{},f[u]=Object.create(null),f[u].iframe=e,f[u].firstRun=!0,f[u].remoteHost=e.src&&e.src.split("/").slice(0,3).join("/"),function(e){if("object"!=typeof e)throw new TypeError("Options is not an object")}(t),Object.keys(t).forEach(r,t),function(e){for(var t in p)Object.prototype.hasOwnProperty.call(p,t)&&(f[u][t]=Object.prototype.hasOwnProperty.call(e,t)?e[t]:p[t])}(t),f[u]&&(f[u].targetOrigin=!0===f[u].checkOrigin?""===(n=f[u].remoteHost)||null!==n.match(/^(about:blank|javascript:|file:\/\/)/)?"*":n:"*")}(n),function(){switch(O(u,"IFrame scrolling "+(f[u]&&f[u].scrolling?"enabled":"disabled")+" for "+u),e.style.overflow=!1===(f[u]&&f[u].scrolling)?"hidden":"auto",f[u]&&f[u].scrolling){case"omit":break;case!0:e.scrolling="yes";break;case!1:e.scrolling="no";break;default:e.scrolling=f[u]?f[u].scrolling:"no"}}(),function(){function t(t){var n=f[u][t];1/0!==n&&0!==n&&(e.style[t]="number"==typeof n?n+"px":n,O(u,"Set "+t+" = "+e.style[t]))}function n(e){if(f[u]["min"+e]>f[u]["max"+e])throw new Error("Value for min"+e+" can not be greater than max"+e)}n("Height"),n("Width"),t("maxHeight"),t("minHeight"),t("maxWidth"),t("minWidth")}(),"number"!=typeof(f[u]&&f[u].bodyMargin)&&"0"!==(f[u]&&f[u].bodyMargin)||(f[u].bodyMarginV1=f[u].bodyMargin,f[u].bodyMargin=f[u].bodyMargin+"px"),a=A(u),(c=g())&&function(t){e.parentNode&&new t((function(t){t.forEach((function(t){Array.prototype.slice.call(t.removedNodes).forEach((function(t){t===e&&S(e)}))}))})).observe(e.parentNode,{childList:!0})}(c),w(e,"load",(function(){var n,o;j("iFrame.onload",a,e,t,!0),n=f[u]&&f[u].firstRun,o=f[u]&&f[u].heightCalculationMethod in l,!n&&o&&N({iframe:e,height:0,width:0,type:"init"})})),j("init",a,e,t,!0),f[u]&&(f[u].iframe.iFrameResizer={close:S.bind(null,f[u].iframe),removeListeners:k.bind(null,f[u].iframe),resize:j.bind(null,"Window resize","resize",f[u].iframe),moveToAnchor:function(e){j("Move to anchor","moveToAnchor:"+e,f[u].iframe,u)},sendMessage:function(e){j("Send Message","message:"+(e=JSON.stringify(e)),f[u].iframe,u)}}))}function W(e,t){null===m&&(m=setTimeout((function(){m=null,e()}),t))}function H(){"hidden"!==document.visibilityState&&(O("document","Trigger event: Visibility change"),W((function(){U("Tab Visible","resize")}),16))}function U(e,t){Object.keys(f).forEach((function(n){(function(e){return f[e]&&"parent"===f[e].resizeFrom&&f[e].autoResize&&!f[e].firstRun})(n)&&j(e,t,f[n].iframe,n)}))}function B(){w(window,"message",x),w(window,"resize",(function(){var e;O("window","Trigger event: "+(e="resize")),W((function(){U("Window "+e,"resize")}),16)})),w(document,"visibilitychange",H),w(document,"-webkit-visibilitychange",H)}function D(){function e(e,t){t&&(!function(){if(!t.tagName)throw new TypeError("Object is not a valid DOM element");if("IFRAME"!==t.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+t.tagName+">")}(),L(t,e),n.push(t))}var n;return function(){var e,t=["moz","webkit","o","ms"];for(e=0;e<t.length&&!d;e+=1)d=window[t[e]+"RequestAnimationFrame"];d?d=d.bind(window):O("setup","RequestAnimationFrame not supported")}(),B(),function(o,i){switch(n=[],function(e){e&&e.enablePublicMethods&&T("enablePublicMethods option has been removed, public methods are now always available in the iFrame")}(o),typeof i){case"undefined":case"string":Array.prototype.forEach.call(document.querySelectorAll(i||"iframe"),e.bind(t,o));break;case"object":e(o,i);break;default:throw new TypeError("Unexpected data type ("+typeof i+")")}return n}}}()}(h);var g=h.exports,w={exports:{}};!function(e){!function(t){if("undefined"!=typeof window){var n=!0,o=10,i="",r=0,a="",c=null,u="",s=!1,d={resize:1,click:1},l=128,f=!0,m=1,p="bodyOffset",h=p,g=!0,w="",v={},y=32,b=null,O=!1,E=!1,T="[iFrameSizer]",M=T.length,x="",I={max:1,min:1,bodyScroll:1,documentElementScroll:1},k="child",S=window.parent,P="*",R=0,z=!1,N=null,C=16,F=1,j="scroll",A=j,L=window,W=function(){ae("onMessage function not defined")},H=function(){},U=function(){},B={height:function(){return ae("Custom height calculation function not defined"),document.documentElement.offsetHeight},width:function(){return ae("Custom width calculation function not defined"),document.body.scrollWidth}},D={},q=!1;try{var V=Object.create({},{passive:{get:function(){q=!0}}});window.addEventListener("test",te,V),window.removeEventListener("test",te,V)}catch(e){}var X,J,Y,_,Q,K,G,Z={bodyOffset:function(){return document.body.offsetHeight+we("marginTop")+we("marginBottom")},offset:function(){return Z.bodyOffset()},bodyScroll:function(){return document.body.scrollHeight},custom:function(){return B.height()},documentElementOffset:function(){return document.documentElement.offsetHeight},documentElementScroll:function(){return document.documentElement.scrollHeight},max:function(){return Math.max.apply(null,ye(Z))},min:function(){return Math.min.apply(null,ye(Z))},grow:function(){return Z.max()},lowestElement:function(){return Math.max(Z.bodyOffset()||Z.documentElementOffset(),ve("bottom",Oe()))},taggedElement:function(){return be("bottom","data-iframe-height")}},$={bodyScroll:function(){return document.body.scrollWidth},bodyOffset:function(){return document.body.offsetWidth},custom:function(){return B.width()},documentElementScroll:function(){return document.documentElement.scrollWidth},documentElementOffset:function(){return document.documentElement.offsetWidth},scroll:function(){return Math.max($.bodyScroll(),$.documentElementScroll())},max:function(){return Math.max.apply(null,ye($))},min:function(){return Math.min.apply(null,ye($))},rightMostElement:function(){return ve("right",Oe())},taggedElement:function(){return be("right","data-iframe-width")}},ee=(X=Ee,Q=null,K=0,G=function(){K=Date.now(),Q=null,_=X.apply(J,Y),Q||(J=Y=null)},function(){var e=Date.now();K||(K=e);var t=C-(e-K);return J=this,Y=arguments,t<=0||t>C?(Q&&(clearTimeout(Q),Q=null),K=e,_=X.apply(J,Y),Q||(J=Y=null)):Q||(Q=setTimeout(G,t)),_});ne(window,"message",(function(n){var o={init:function(){w=n.data,S=n.source,ce(),f=!1,setTimeout((function(){g=!1}),l)},reset:function(){g?re("Page reset ignored by init"):(re("Page size reset by host page"),xe("resetPage"))},resize:function(){Te("resizeParent","Parent window requested size check")},moveToAnchor:function(){v.findTarget(r())},inPageLink:function(){this.moveToAnchor()},pageInfo:function(){var e=r();re("PageInfoFromParent called from parent: "+e),U(JSON.parse(e)),re(" --")},message:function(){var e=r();re("onMessage called from parent: "+e),W(JSON.parse(e)),re(" --")}};function i(){return n.data.split("]")[1].split(":")[0]}function r(){return n.data.slice(n.data.indexOf(":")+1)}function a(){return n.data.split(":")[2]in{true:1,false:1}}function c(){var r=i();r in o?o[r]():!e.exports&&"iFrameResize"in window||window.jQuery!==t&&"iFrameResize"in window.jQuery.prototype||a()||ae("Unexpected message ("+n.data+")")}T===(""+n.data).slice(0,M)&&(!1===f?c():a()?o.init():re('Ignored message of type "'+i()+'". Received before initialization.'))})),ne(window,"readystatechange",Se),Se()}function te(){}function ne(e,t,n,o){e.addEventListener(t,n,!!q&&(o||{}))}function oe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ie(e){return T+"["+x+"] "+e}function re(e){O&&"object"==typeof window.console&&console.log(ie(e))}function ae(e){"object"==typeof window.console&&console.warn(ie(e))}function ce(){var e;!function(){function e(e){return"true"===e}var o=w.slice(M).split(":");x=o[0],r=t===o[1]?r:Number(o[1]),s=t===o[2]?s:e(o[2]),O=t===o[3]?O:e(o[3]),y=t===o[4]?y:Number(o[4]),n=t===o[6]?n:e(o[6]),a=o[7],h=t===o[8]?h:o[8],i=o[9],u=o[10],R=t===o[11]?R:Number(o[11]),v.enable=t!==o[12]&&e(o[12]),k=t===o[13]?k:o[13],A=t===o[14]?A:o[14],E=t===o[15]?E:e(o[15])}(),re("Initialising iFrame ("+window.location.href+")"),function(){function e(){var e=window.iFrameResizer;re("Reading data from page: "+JSON.stringify(e)),Object.keys(e).forEach(ue,e),W="onMessage"in e?e.onMessage:W,H="onReady"in e?e.onReady:H,P="targetOrigin"in e?e.targetOrigin:P,h="heightCalculationMethod"in e?e.heightCalculationMethod:h,A="widthCalculationMethod"in e?e.widthCalculationMethod:A}function t(e,t){return"function"==typeof e&&(re("Setup custom "+t+"CalcMethod"),B[t]=e,e="custom"),e}"iFrameResizer"in window&&Object===window.iFrameResizer.constructor&&(e(),h=t(h,"height"),A=t(A,"width"));re("TargetOrigin for parent set to: "+P)}(),function(){t===a&&(a=r+"px");se("margin",function(e,t){-1!==t.indexOf("-")&&(ae("Negative CSS value ignored for "+e),t="");return t}("margin",a))}(),se("background",i),se("padding",u),(e=document.createElement("div")).style.clear="both",e.style.display="block",e.style.height="0",document.body.appendChild(e),me(),pe(),document.documentElement.style.height="",document.body.style.height="",re('HTML & body height set to "auto"'),re("Enable public methods"),L.parentIFrame={autoResize:function(e){return!0===e&&!1===n?(n=!0,he()):!1===e&&!0===n&&(n=!1,le("remove"),null!==c&&c.disconnect(),clearInterval(b)),ke(0,0,"autoResize",JSON.stringify(n)),n},close:function(){ke(0,0,"close")},getId:function(){return x},getPageInfo:function(e){"function"==typeof e?(U=e,ke(0,0,"pageInfo")):(U=function(){},ke(0,0,"pageInfoStop"))},moveToAnchor:function(e){v.findTarget(e)},reset:function(){Ie("parentIFrame.reset")},scrollTo:function(e,t){ke(t,e,"scrollTo")},scrollToOffset:function(e,t){ke(t,e,"scrollToOffset")},sendMessage:function(e,t){ke(0,0,"message",JSON.stringify(e),t)},setHeightCalculationMethod:function(e){h=e,me()},setWidthCalculationMethod:function(e){A=e,pe()},setTargetOrigin:function(e){re("Set targetOrigin: "+e),P=e},size:function(e,t){Te("size","parentIFrame.size("+(e||"")+(t?","+t:"")+")",e,t)}},function(){if(!0!==E)return;function e(e){ke(0,0,e.type,e.screenY+":"+e.screenX)}function t(t,n){re("Add event listener: "+n),ne(window.document,t,e)}t("mouseenter","Mouse Enter"),t("mouseleave","Mouse Leave")}(),he(),v=function(){function e(){return{x:window.pageXOffset===t?document.documentElement.scrollLeft:window.pageXOffset,y:window.pageYOffset===t?document.documentElement.scrollTop:window.pageYOffset}}function n(t){var n=t.getBoundingClientRect(),o=e();return{x:parseInt(n.left,10)+parseInt(o.x,10),y:parseInt(n.top,10)+parseInt(o.y,10)}}function o(e){function o(e){var t=n(e);re("Moving to in page link (#"+i+") at x: "+t.x+" y: "+t.y),ke(t.y,t.x,"scrollToOffset")}var i=e.split("#")[1]||e,r=decodeURIComponent(i),a=document.getElementById(r)||document.getElementsByName(r)[0];t===a?(re("In page link (#"+i+") not found in iFrame, so sending to parent"),ke(0,0,"inPageLink","#"+i)):o(a)}function i(){var e=window.location.hash,t=window.location.href;""!==e&&"#"!==e&&o(t)}function r(){function e(e){function t(e){e.preventDefault(),o(this.getAttribute("href"))}"#"!==e.getAttribute("href")&&ne(e,"click",t)}Array.prototype.forEach.call(document.querySelectorAll('a[href^="#"]'),e)}function a(){ne(window,"hashchange",i)}function c(){setTimeout(i,l)}function u(){Array.prototype.forEach&&document.querySelectorAll?(re("Setting up location.hash handlers"),r(),a(),c()):ae("In page linking not fully supported in this browser! (See README.md for IE8 workaround)")}v.enable?u():re("In page linking not enabled");return{findTarget:o}}(),Te("init","Init message from host page"),H()}function ue(e){var t=e.split("Callback");if(2===t.length){var n="on"+t[0].charAt(0).toUpperCase()+t[0].slice(1);this[n]=this[e],delete this[e],ae("Deprecated: '"+e+"' has been renamed '"+n+"'. The old method will be removed in the next major version.")}}function se(e,n){t!==n&&""!==n&&"null"!==n&&(document.body.style[e]=n,re("Body "+e+' set to "'+n+'"'))}function de(e){var t={add:function(t){function n(){Te(e.eventName,e.eventType)}D[t]=n,ne(window,t,n,{passive:!0})},remove:function(e){var t,n,o,i=D[e];delete D[e],t=window,n=e,o=i,t.removeEventListener(n,o,!1)}};e.eventNames&&Array.prototype.map?(e.eventName=e.eventNames[0],e.eventNames.map(t[e.method])):t[e.method](e.eventName),re(oe(e.method)+" event listener: "+e.eventType)}function le(e){de({method:e,eventType:"Animation Start",eventNames:["animationstart","webkitAnimationStart"]}),de({method:e,eventType:"Animation Iteration",eventNames:["animationiteration","webkitAnimationIteration"]}),de({method:e,eventType:"Animation End",eventNames:["animationend","webkitAnimationEnd"]}),de({method:e,eventType:"Input",eventName:"input"}),de({method:e,eventType:"Mouse Up",eventName:"mouseup"}),de({method:e,eventType:"Mouse Down",eventName:"mousedown"}),de({method:e,eventType:"Orientation Change",eventName:"orientationchange"}),de({method:e,eventType:"Print",eventNames:["afterprint","beforeprint"]}),de({method:e,eventType:"Ready State Change",eventName:"readystatechange"}),de({method:e,eventType:"Touch Start",eventName:"touchstart"}),de({method:e,eventType:"Touch End",eventName:"touchend"}),de({method:e,eventType:"Touch Cancel",eventName:"touchcancel"}),de({method:e,eventType:"Transition Start",eventNames:["transitionstart","webkitTransitionStart","MSTransitionStart","oTransitionStart","otransitionstart"]}),de({method:e,eventType:"Transition Iteration",eventNames:["transitioniteration","webkitTransitionIteration","MSTransitionIteration","oTransitionIteration","otransitioniteration"]}),de({method:e,eventType:"Transition End",eventNames:["transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend"]}),"child"===k&&de({method:e,eventType:"IFrame Resized",eventName:"resize"})}function fe(e,t,n,o){return t!==e&&(e in n||(ae(e+" is not a valid option for "+o+"CalculationMethod."),e=t),re(o+' calculation method set to "'+e+'"')),e}function me(){h=fe(h,p,Z,"height")}function pe(){A=fe(A,j,$,"width")}function he(){var e;!0===n?(le("add"),e=0>y,window.MutationObserver||window.WebKitMutationObserver?e?ge():c=function(){function e(e){function t(e){!1===e.complete&&(re("Attach listeners to "+e.src),e.addEventListener("load",i,!1),e.addEventListener("error",r,!1),u.push(e))}"attributes"===e.type&&"src"===e.attributeName?t(e.target):"childList"===e.type&&Array.prototype.forEach.call(e.target.querySelectorAll("img"),t)}function t(e){u.splice(u.indexOf(e),1)}function n(e){re("Remove listeners from "+e.src),e.removeEventListener("load",i,!1),e.removeEventListener("error",r,!1),t(e)}function o(e,t,o){n(e.target),Te(t,o+": "+e.target.src)}function i(e){o(e,"imageLoad","Image loaded")}function r(e){o(e,"imageLoadFailed","Image load failed")}function a(t){Te("mutationObserver","mutationObserver: "+t[0].target+" "+t[0].type),t.forEach(e)}function c(){var e=document.querySelector("body"),t={attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0};return d=new s(a),re("Create body MutationObserver"),d.observe(e,t),d}var u=[],s=window.MutationObserver||window.WebKitMutationObserver,d=c();return{disconnect:function(){"disconnect"in d&&(re("Disconnect body MutationObserver"),d.disconnect(),u.forEach(n))}}}():(re("MutationObserver not supported in this browser!"),ge())):re("Auto Resize disabled")}function ge(){0!==y&&(re("setInterval: "+y+"ms"),b=setInterval((function(){Te("interval","setInterval: "+y)}),Math.abs(y)))}function we(e,t){var n=0;return t=t||document.body,n=null===(n=document.defaultView.getComputedStyle(t,null))?0:n[e],parseInt(n,o)}function ve(e,t){for(var n=t.length,o=0,i=0,r=oe(e),a=Date.now(),c=0;c<n;c++)(o=t[c].getBoundingClientRect()[e]+we("margin"+r,t[c]))>i&&(i=o);return a=Date.now()-a,re("Parsed "+n+" HTML elements"),re("Element position calculated in "+a+"ms"),function(e){e>C/2&&re("Event throttle increased to "+(C=2*e)+"ms")}(a),i}function ye(e){return[e.bodyOffset(),e.bodyScroll(),e.documentElementOffset(),e.documentElementScroll()]}function be(e,t){var n=document.querySelectorAll("["+t+"]");return 0===n.length&&(ae("No tagged elements ("+t+") found on page"),document.querySelectorAll("body *")),ve(e,n)}function Oe(){return document.querySelectorAll("body *")}function Ee(e,n,o,i){var r,a;!function(){function e(e,t){return!(Math.abs(e-t)<=R)}return r=t===o?Z[h]():o,a=t===i?$[A]():i,e(m,r)||s&&e(F,a)}()&&"init"!==e?!(e in{init:1,interval:1,size:1})&&(h in I||s&&A in I)?Ie(n):e in{interval:1}||re("No change in size detected"):(Me(),ke(m=r,F=a,e))}function Te(e,t,n,o){z&&e in d?re("Trigger event cancelled: "+e):(e in{reset:1,resetPage:1,init:1}||re("Trigger event: "+t),"init"===e?Ee(e,t,n,o):ee(e,t,n,o))}function Me(){z||(z=!0,re("Trigger event lock on")),clearTimeout(N),N=setTimeout((function(){z=!1,re("Trigger event lock off"),re("--")}),l)}function xe(e){m=Z[h](),F=$[A](),ke(m,F,e)}function Ie(e){var t=h;h=p,re("Reset trigger event: "+e),Me(),xe("reset"),h=t}function ke(e,n,o,i,r){var a;t===r?r=P:re("Message targetOrigin: "+r),re("Sending message to host page ("+(a=x+":"+e+":"+n+":"+o+(t===i?"":":"+i))+")"),S.postMessage(T+a,r)}function Se(){"loading"!==document.readyState&&window.parent.postMessage("[iFrameResizerChild]Ready","*")}}()}(w);var v={iframeResize:g,iframeResizer:g,contentWindow:w.exports},y=function(e){var t=e.target,n=e.token,o=e.approvalPageUrl,i=e.flow,r=document.createElement("form"),a=document.createElement("input"),c=document.createElement("input"),u=document.createElement("input"),s=document.createElement("input");return r.style.display="none",t&&(r.target=t),r.method="POST",r.action=o,a.value=n,a.name="ott",r.appendChild(a),c.value="0.9.5",c.name="libVersion",r.appendChild(c),u.value=window.location.hostname,u.name="parentHostname",r.appendChild(u),s.value=i,s.name="flow",r.appendChild(s),r},b="\n .tw-approval-modal-overlay {\n position: fixed;\n bottom: 0;\n left: 0;\n right: 0;\n top: 0;\n height: 100%;\n width: 100%;\n background: rgba(55,81,126,0);\n transition: background-color .35s cubic-bezier(0,.94,.62,1);\n z-index: 1050;\n }\n .tw-approval-modal-overlay--open {\n background: rgba(55,81,126,0.8);\n }\n .tw-approval-modal-wrapper {\n height: 100%;\n width: 100vw;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 16px;\n }\n .tw-approval-modal {\n display: flex;\n max-height: 100%;\n width: 540px;\n background-color: #fff;\n border-radius: 3px;\n box-shadow: 0 5px 15px rgba(0,0,0,.2);\n overflow: auto;\n }\n .tw-approval-modal iframe {\n width: 100%;\n height: 520px;\n transition: height 0.1s ease-in-out;\n }\n";var O;var E={IFRAME:"iframe",TAB:"tab",POPUP:"popup"},T={PRODUCTION:"production",SANDBOX:"sandbox"},M=(i(O={},E.IFRAME,(function(e){var t,n,o=e.token,i=e.approvalPageUrl,r=e.resolve,a=e.reject;document.getElementById("tw-approve-api-action-styles")||(t=document.head,(n=document.createElement("style")).id="tw-approve-api-action-styles",n.appendChild(document.createTextNode(b)),t.appendChild(n));var c=document.createElement("div");c.id="tw-approval-modal-overlay",c.classList.add("tw-approval-modal-overlay");var u=document.createElement("div");u.classList.add("tw-approval-modal-wrapper"),c.appendChild(u);var s=document.createElement("div");s.classList.add("tw-approval-modal"),u.appendChild(s);var d=document.createElement("iframe");d.name="tw-approve-api-action",d.style.border="0",s.appendChild(d);var l=y({token:o,approvalPageUrl:i,flow:"iframe"});s.appendChild(l),document.body.appendChild(c),v.iframeResize({checkOrigin:!1,minHeight:400},d),c.classList.add("tw-approval-modal-overlay--open"),l.setAttribute("target","tw-approve-api-action"),l.submit();var h=function(e){switch(e.data){case f:return g(),void r();case m:return g(),void a();case p:g()}},g=function(){d.src="about:blank";var e=document.getElementById("tw-approval-modal-overlay");e.parentNode.removeChild(e),window.removeEventListener("message",h)};c.addEventListener("click",g,{once:!0}),window.addEventListener("message",h)})),i(O,E.TAB,(function(e){var t=e.token,n=e.approvalPageUrl,o=e.resolve,i=e.reject,r="tw-approve-api-action",a=y({target:r,token:t,approvalPageUrl:n,flow:"tab"});document.body.appendChild(a);var c=window.open(n,r);a.submit();var u=function(e){switch(e.data){case f:return s(),void o();case m:return s(),void i();case p:s()}},s=function(){c.close(),window.removeEventListener("message",u)};window.addEventListener("message",u)})),i(O,E.POPUP,(function(e){var t=e.token,n=e.approvalPageUrl,o=e.resolve,i=e.reject,r="tw-approve-api-action",a=y({target:r,token:t,approvalPageUrl:n,flow:"popup"});document.body.appendChild(a);var c=function(){var e=void 0!==window.screenLeft?window.screenLeft:window.screenX,t=void 0!==window.screenTop?window.screenTop:window.screenY,n=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,i=n/window.screen.availWidth;return{width:580/i,height:600/i,top:(o-600)/2/i+t,left:(n-580)/2/i+e}}(),u=c.width,s=c.height,d=c.top,l=c.left,h=window.open(n,r,"resizable,scrollbars,status,location,width=".concat(u,",height=").concat(s,",top=").concat(d,",left=").concat(l));a.submit(),h.focus&&h.focus();var g=function(e){switch(e.data){case f:return w(),void o();case m:return w(),void i();case p:w()}},w=function(){h.close(),window.removeEventListener("message",g)};window.addEventListener("message",g)})),O),x=function(e){return e===T.SANDBOX?"https://sandbox.transferwise.tech/approve-api-action/":"https://wise.com/approve-api-action/"};function I(e){var t=e.token,n=e.flow,o=void 0===n?E.IFRAME:n,i=e.mode,r=void 0===i?T.PRODUCTION:i,a=e.approvalPageUrl;return new Promise((function(e,n){var i={token:t,approvalPageUrl:a||x(r),resolve:e,reject:n};M[o](i)}))}var k=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}(f,e);var t,n,i,u,s,l=(t=f,n=c(),function(){var e,o=r(t);if(n){var i=r(this).constructor;e=Reflect.construct(o,arguments,i)}else e=o.apply(this,arguments);return d(this,e)});function f(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,f),(t=l.call(this,e.statusText)).name="HTTPError",t.response=e,t}return i=f,u&&o(i.prototype,u),s&&o(i,s),Object.defineProperty(i,"prototype",{writable:!1}),i}(s(Error));function S(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return fetch(e,n(n({},t),{},{headers:n(n({},{"Content-Type":"application/json"}),t.headers)})).then((function(e){if(!e.ok)throw new k(e);return e}))}function P(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){})()}function R(e){return e&&e.headers&&e.headers.get?e.headers.get("X-2FA-APPROVAL"):null}e.Flow=E,e.Mode=T,e.create=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return S(t,o).then((function(e){return{response:e,metadata:{scaRequired:!1}}})).catch((function(i){if(function(e){if(!e||!e.response)return!1;var t=R(e.response),n=e.response.status;return(403===n||400===n)&&t}(i)){var r=R(i.response);return P(e.onSCARequired),I({token:r,flow:e.flow,mode:e.mode,approvalPageUrl:e.approvalPageUrl}).then((function(){P(e.onSCACompleted);var i=n(n({},o.headers||{}),{},{"X-2FA-APPROVAL":r});return S(t,n(n({},o),{},{headers:i})).then((function(e){return{response:e,metadata:{scaRequired:!0}}}))}))}throw i})).then((function(e){return o&&o.withMetadata?e:e.response}))}},e.runFlow=I}));