Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@paybyrd/threedsecure-service

Package Overview
Dependencies
Maintainers
5
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paybyrd/threedsecure-service - npm Package Compare versions

Comparing version 3.2.4 to 3.2.5-rc.2

2

dist/index.module.js

@@ -1,2 +0,2 @@

function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},e.apply(this,arguments)}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}var r,n=/*#__PURE__*/function(){function e(){}var r=e.prototype;return r.flush=function(){return Promise.resolve()},r.log=function(e){var r,n=t({},e,{error:null==(r=e.error)?void 0:r.toString()});console.log(n)},e}();function o(e,t,r){if(!e.s){if(r instanceof i){if(!r.s)return void(r.o=o.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(o.bind(null,e,t),o.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(r||(r={}));var i=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{o(n,1,a(this.v))}catch(e){o(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?o(n,1,t?t(i):i):r?o(n,1,r(i)):o(n,2,i)}catch(e){o(n,2,e)}},n},e}();function a(e){return e instanceof i&&1&e.s}var s=/*#__PURE__*/function(){function e(t,r){void 0===r&&(r=new n),this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=r,this._options=t,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))}var t=e.prototype;return t.log=function(t){if(this._logger.log(t),this._options.restLoggerUrl){var r="["+this._options.service.name+"] "+t.message;t.elapsedTimeInMilliseconds&&(r=r+" in "+t.elapsedTimeInMilliseconds+"ms"),this._logs.unshift({customMessage:t.message,message:r,service:this._options.service,environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:t.method,correlationId:t.correlationId,content:t.content,exeption:e.getException(t.error),level:t.level,elapsedTimeInMilliseconds:t.elapsedTimeInMilliseconds})}},t.flush=function(){try{var t=function(){r._interval=setInterval(r.sendBatch.bind(r),1e3*(r._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))},r=this;clearInterval(r._interval);var n=function(e,t,r){for(var n;;){var s=e();if(a(s)&&(s=s.v),!s)return l;if(s.then){n=0;break}var l=r();if(l&&l.then){if(!a(l)){n=1;break}l=l.s}if(t){var c=t();if(c&&c.then&&!a(c)){n=2;break}}}var u=new i,h=o.bind(null,u,2);return(0===n?s.then(m):1===n?l.then(d):c.then(v)).then(void 0,h),u;function d(n){l=n;do{if(t&&(c=t())&&c.then&&!a(c))return void c.then(v).then(void 0,h);if(!(s=e())||a(s)&&!s.v)return void o(u,1,l);if(s.then)return void s.then(m).then(void 0,h);a(l=r())&&(l=l.v)}while(!l||!l.then);l.then(d).then(void 0,h)}function m(e){e?(l=r())&&l.then?l.then(d).then(void 0,h):d(l):o(u,1,l)}function v(){(s=e())?s.then?s.then(m).then(void 0,h):m(s):o(u,1,l)}}(function(){return!!r._logs.length},void 0,function(){return Promise.resolve(r.sendBatch()).then(function(){})});return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},t.sendBatch=function(){try{var e=this,t=e._logs.splice(0,10);if(!t.length)return Promise.resolve();var n=crypto.randomUUID(),o=function(o,i){try{var a=(s=1e3*(e._options.timeoutInSeconds||30),l=new AbortController,c=setTimeout(function(){return l.abort()},s),Promise.resolve(fetch(e._options.restLoggerUrl,{headers:{"content-type":"application/json"},method:"POST",keepalive:!0,body:JSON.stringify(t),signal:l.signal})).then(function(o){clearTimeout(c),o.ok||e._logger.log({message:"Error sending messages to API",content:t,method:"sendBatch",correlationId:n,level:r.Error})}))}catch(e){return i(e)}var s,l,c;return a&&a.then?a.then(void 0,i):a}(0,function(o){e._logger.log({error:o,message:"Error sending messages to API",content:t,method:"sendBatch",correlationId:n,level:r.Error})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},e.getException=function(e){return e?{stackTrace:e.stack,message:e.message,className:e.name}:null},e}();s.DEFAULT_BATCH_TIMEOUT=5;var l=/*#__PURE__*/function(){function e(){this.start=void 0,this.end=void 0,this.start=Date.now()}var t,r;return e.prototype.stop=function(){this.end=Date.now()},t=e,(r=[{key:"elapsed",get:function(){return(this.end||Date.now())-this.start}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o),n)}var o}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}(),c=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),u=/*#__PURE__*/function(){function e(){}return e.create=function(){var e=[48,32,24,16,15,8,4,1].find(function(e){return e<=screen.colorDepth});return{javaEnabled:navigator.javaEnabled(),javascriptEnabled:!0,language:navigator.language,userAgent:navigator.userAgent,screenWidth:window.screen.width,screenHeight:window.screen.height,timezoneOffset:(new Date).getTimezoneOffset(),colorDepth:e,acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}},e}(),h=/*#__PURE__*/function(){function e(e){var t=this;this._task=void 0,this._timeout=void 0,this._task=new Promise(function(r){t._timeout=setTimeout(r,e)})}var t=e.prototype;return t.wait=function(){return this._task},t.cancel=function(){clearTimeout(this._timeout),this._task=Promise.reject({message:"Timer cancelled"})},e.sleep=function(t){return new e(t)},e.cancel=function(e){clearTimeout(e)},e}(),d=/*#__PURE__*/function(){function e(){}return e.createIFrame=function(e){var t=document.createElement("iframe");return t.id=e.name,t.name=e.name,e.onReadyFn&&e.onReadyFn(t,e.isVisible),e.onCreatedFn&&(e.onCreatedFn(t),t.style.opacity=e.isVisible?"1":"0"),e.parent.appendChild(t),t},e.createForm=function(e){var t=document.createElement("form");return t.id=e.name,t.name=e.name,t.action=e.actionUrl,t.target=e.target,t.method=e.method,e.parent.appendChild(t),t},e.createInput=function(e){var t=document.createElement("input");return t.id=e.name,t.name=e.name,t.type=e.type,e.parent.appendChild(t),t},e}();function m(e,t,r){if(!e.s){if(r instanceof v){if(!r.s)return void(r.o=m.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(m.bind(null,e,t),m.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var v=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{m(n,1,i(this.v))}catch(e){m(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?m(n,1,t?t(o):o):r?m(n,1,r(o)):m(n,2,o)}catch(e){m(n,2,e)}},n},e}();function g(e){return e instanceof v&&1&e.s}var p,f=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}return e.prototype.execute=function(e){var t=this,n=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,a){try{var s,l=function(e){var n;if(s)return e;a(u),t._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(n=u)?void 0:n.error,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:r.Error})},c=1,u=null,d=function(e,t){var r;do{var n=e();if(n&&n.then){if(!g(n)){r=!0;break}n=n.v}var o=t();if(g(o)&&(o=o.v),!o)return n}while(!o.then);var i=new v,a=m.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;g(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!g(n))return void n.then(s).then(void 0,a);n=n.v}}m(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!g(n))return void n.then(s).then(void 0,a);n=n.v}if(g(r=t())&&(r=r.v),!r)return void m(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else m(i,1,n)}}(function(){function l(e){return s?e:(c++,Promise.resolve(h.sleep(1e3*t._options.attemptDelayInSeconds).wait()).then(function(){}))}var d=function(r,o){try{var i=Promise.resolve(n({attempt:c,maxAttempts:t._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(s=1);t.isTransientError||(a(t),s=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){u={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:c,maxAttempts:t._options.maxAttempts}},t._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:r.Warning})});return d&&d.then?d.then(l):l(d)},function(){return!s&&c<=t._options.maxAttempts});return Promise.resolve(d&&d.then?d.then(l):l(d))}catch(e){return Promise.reject(e)}})},e}(),I=/*#__PURE__*/function(){function t(e,t,r){void 0===r&&(r=new f(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var n=t.prototype;return n.send=function(t){try{var n=this,o=n;return Promise.resolve(n._retryPolicy.execute({executeFn:function(i){var a=i.attempt,s=i.maxAttempts;try{var c=function(e){clearTimeout(d);var t={isSuccess:v.ok,isTransientError:n.isTransientError(v),getData:function(){try{return Promise.resolve(v.clone().json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}};return t},u=1e3*(o._options.timeoutInSeconds||30),h=new AbortController,d=setTimeout(function(){return h.abort()},u),m=new URL(t.url);n._logger.log({message:"ExternalService - Request ("+m.host+")",content:{request:t,attempt:a,maxAttempts:s},method:"send",correlationId:t.correlationId,level:r.Information});var v,g=new l,p=function(o,i){try{var l=Promise.resolve(fetch(t.url,{headers:e({},t.headers,{"x-attempt":a.toString(),"x-max-attempt":s.toString(),accept:"application/json","content-type":"application/json",correlationId:t.correlationId}),keepalive:!0,body:JSON.stringify(t.body),method:t.method,signal:h.signal})).then(function(e){var o=n._logger,i=o.log,l="ExternalService - Response ("+m.host+")",c=(v=e).status;return Promise.resolve(v.clone().text()).then(function(e){i.call(o,{message:l,content:{request:t,attempt:a,maxAttempts:s,response:{statusCode:c,data:e}},method:"send",correlationId:t.correlationId,level:r.Information,elapsedTimeInMilliseconds:g.elapsed})})})}catch(e){return i(e)}return l&&l.then?l.then(void 0,i):l}(0,function(e){throw n._logger.log({message:"ExternalService - Error ("+m.host+")",content:{request:t,attempt:a,maxAttempts:s,error:e},method:"send",correlationId:t.correlationId,level:r.Error,elapsedTimeInMilliseconds:g.elapsed}),e});return Promise.resolve(p&&p.then?p.then(c):c())}catch(e){return Promise.reject(e)}},method:"["+t.method+"] "+t.url,correlationId:t.correlationId}))}catch(e){return Promise.reject(e)}},n.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},t}();!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(p||(p={}));var _=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}var t=e.prototype;return t.execute=function(t){var n=this;return t.authResponse.challengeUrl?new Promise(function(o,i){try{n._logger.log({message:"Challenge - Start",content:{authResponse:t.authResponse},method:"executeChallenge",correlationId:t.correlationId,level:r.Information}),n._options.container.innerHTML="";var a=d.createIFrame({parent:n._options.container,name:e.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!n._options.onIFrameCreatedFn,onCreatedFn:n._options.onIFrameCreatedFn,onReadyFn:n._options.onIFrameReadyFn});n._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var s=d.createForm({parent:n._options.container,name:e.FORM_NAME,actionUrl:t.authResponse.challengeUrl,target:e.IFRAME_NAME,method:"post"});n._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var u=d.createInput({parent:s,name:e.CREQ_INPUT_NAME,type:e.CREQ_INPUT_TYPE});n._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var h={threeDSServerTransID:t.authResponse.processId,acsTransID:t.authResponse.challengeId,messageVersion:t.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:n._options.challengeWindowSize||p.width250xheight400},m=c.convert(h);u.value=m,n._logger.log({message:"Challenge - Prepare cReq",content:{cReq:h,base64CReq:m},method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var v=new l;s.submit(),setTimeout(function e(){var o,i=a.contentDocument||(null==(o=a.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"Challenge - iFrame loaded in "+v.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeChallenge",correlationId:t.correlationId,level:r.Information})},100),n._logger.log({message:"Challenge - Submit form",content:{authResponse:t.authResponse,cReq:h,base64CReq:m},method:"executeChallenge",correlationId:t.correlationId,level:r.Information}),o()}catch(e){return n._logger.log({message:"Challenge - error",content:{authResponse:t.authResponse},error:e,method:"executeChallenge",correlationId:t.correlationId,level:r.Error}),i({message:e.toString()})}}):Promise.resolve()},t.reset=function(){try{var t,r,n;null==(t=document.getElementById(e.IFRAME_NAME))||t.remove(),null==(r=document.getElementById(e.FORM_NAME))||r.remove(),null==(n=document.getElementById(e.CREQ_INPUT_NAME))||n.remove()}catch(e){}},e}();_.IFRAME_NAME="challengeIframe",_.FORM_NAME="challengeForm",_.CREQ_INPUT_NAME="creq",_.CREQ_INPUT_TYPE="hidden";var y,A=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}var t=e.prototype;return t.execute=function(t){var n=this;return t.preAuthResponse.dsMethodUrl?new Promise(function(o,i){try{var a;n._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:t},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information}),n._options.container.innerHTML="";var s=d.createIFrame({parent:n._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!n._options.onIFrameCreatedFn});null==(a=n._options.onIFrameCreatedFn)||a.call(n._options,s),n._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var u=d.createForm({parent:n._options.container,name:e.FORM_NAME,actionUrl:t.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});n._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var h=d.createInput({parent:u,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});n._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var m={threeDSServerTransID:t.preAuthResponse.processId,threeDSMethodNotificationURL:t.preAuthResponse.notificationUrl},v=c.convert(m);h.value=v,n._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:m,threeDSMethodDataBase64:v},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var g=new l;u.submit(),setTimeout(function e(){var o,i=s.contentDocument||(null==(o=s.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information})},100),n._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:m,threeDSMethodDataBase64:v},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information}),o()}catch(e){return n._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:t},error:e,method:"directoryServerExecute",correlationId:t.correlationId,level:r.Error}),i({message:e.toString()})}}):Promise.resolve()},t.reset=function(){try{var t,r,n;null==(t=document.getElementById(e.IFRAME_NAME))||t.remove(),null==(r=document.getElementById(e.FORM_NAME))||r.remove(),null==(n=document.getElementById(e.FORM_INPUT_NAME))||n.remove()}catch(e){}},e}();A.IFRAME_NAME="threeDSMethodIframe",A.FORM_NAME="threeDSMethodForm",A.FORM_INPUT_NAME="threeDSMethodData",A.FROM_INPUT_TYPE="hidden",function(e){e.PreAuthStarted="preAuth:started",e.PreAuthCompleted="preAuth:completed",e.AuthStarted="auth:started",e.AuthCompleted="auth:completed",e.PostAuthStarted="postAuth:started",e.PostAuthCompleted="postAuth:completed",e.PostAuthFailed="postAuth:failed",e.ResetStarted="reset:started",e.ResetCompleted="reset:completed"}(y||(y={}));var S=/*#__PURE__*/function(){function e(t,r,n,o,i){void 0===r&&(r=new s(e.getLoggerOptions(t))),void 0===n&&(n=new I(e.getHttpClientOptions(t),r)),void 0===o&&(o=new A(t,r)),void 0===i&&(i=new _(t,r)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._observers=[],this._options=t,this._logger=r,this._client=n,this._directoryServer=o,this._challenge=i}var t=e.prototype;return t.subscribe=function(e){this._observers.push(e)},t.unsubscribe=function(e){var t=this._observers.indexOf(e);t>-1&&this._observers.splice(t,1)},t.execute=function(e,t){try{var n=this;return void 0===t&&(t=crypto.randomUUID()),e.correlationId||(e.correlationId=t,n._logger.log({message:"Obsolete request. CorrelationId is not set.",content:e,method:"execute",correlationId:e.correlationId,level:r.Information})),Promise.resolve(function(t,r){try{var o=Promise.resolve(n.preAuth(e)).then(function(t){return Promise.resolve(n._directoryServer.execute({preAuthResponse:t,correlationId:e.correlationId})).then(function(){return Promise.resolve(n.auth(e)).then(function(t){return Promise.resolve(n._challenge.execute({authResponse:t,correlationId:e.correlationId})).then(function(){return Promise.resolve(n.postAuth(e))})})})})}catch(e){return r(!0,e)}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):r(!1,o)}(0,function(e,t){return n.reset(),Promise.resolve(n._logger.flush()).then(function(){if(e)throw t;return t})}))}catch(e){return Promise.reject(e)}},t.preAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:r.Information}),t.notifyAll({name:y.PreAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:u.create()},correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:y.PreAuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.auth=function(e){try{var t=this;return t._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:r.Information}),t.notifyAll({name:y.AuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:y.AuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.postAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:r.Information}),t.notifyAll({name:y.PostAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/postAuth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData()).then(function(e){return t.notifyAll({name:y.PostAuthCompleted,data:e}),e})})}catch(e){return Promise.reject(e)}},t.reset=function(){this.notifyAll({name:y.ResetStarted}),this._challenge.reset(),this._directoryServer.reset(),this.notifyAll({name:y.ResetCompleted})},t.notifyAll=function(e){this._observers.forEach(function(t){return t.notify(e)})},e.getLoggerOptions=function(e){return{restLoggerUrl:e.logUrl,timeoutInSeconds:e.timeoutInSeconds||30,environment:e.environment||"Production",batchLogIntervalInSeconds:e.batchLogIntervalInSeconds||5,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.2.4"}}},e.getHttpClientOptions=function(e){return{timeoutInSeconds:e.timeoutInSeconds||30,attemptDelayInSeconds:e.attemptDelayInSeconds||2,maxAttempts:e.maxAttempts||50}},e}();export{p as ChallengeWindowSize,f as LinearRetryPolicy,S as ThreeDSecureService};
import{v4 as e}from"uuid";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},r.apply(this,arguments)}var n,o;(o=n||(n={}))[o.Trace=0]="Trace",o[o.Debug=1]="Debug",o[o.Information=2]="Information",o[o.Warning=3]="Warning",o[o.Error=4]="Error",o[o.Critical=5]="Critical",o[o.None=6]="None";var i=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.flush=function(){return Promise.resolve()},t.log=function(e){var t,o=r({},e,{error:null==(t=e.error)?void 0:t.toString()});switch(e.level){case n.Trace:return console.trace(o);case n.Debug:return console.debug(o);case n.Warning:return console.warn(o);case n.Error:case n.Critical:return console.error(o);default:return console.log(o)}},e}();function a(e,t,r){if(!e.s){if(r instanceof s){if(!r.s)return void(r.o=a.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(a.bind(null,e,t),a.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var s=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{a(n,1,i(this.v))}catch(e){a(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?a(n,1,t?t(o):o):r?a(n,1,r(o)):a(n,2,o)}catch(e){a(n,2,e)}},n},e}();function l(e){return e instanceof s&&1&e.s}function c(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var u=/*#__PURE__*/function(){function t(e,r){void 0===r&&(r=new i),this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=r,this._options=e,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||t.DEFAULT_BATCH_TIMEOUT))}var r=t.prototype;return r.log=function(e){if(this._logger.log(e),this._options.restLoggerUrl)return this._options.minimumLevel&&e.level<this._options.minimumLevel?this._logger.log({message:"Minimum level not achieved for sending",content:{log:e,minimumLevel:this._options.minimumLevel},method:"log",correlationId:e.correlationId,level:n.Warning}):void this._logs.unshift({executionDate:new Date,log:e});this._logger.log({message:"RestLoggerUrl is not defined",content:e,method:"log",correlationId:e.correlationId,level:n.Warning})},r.flush=function(r){try{var o=this;return void 0===r&&(r=e()),clearInterval(o._interval),Promise.resolve(function(e,t){try{var i=c(function(){var e=function(e,t,r){for(var n;;){var o=e();if(l(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!l(i)){n=1;break}i=i.s}if(t){var c=t();if(c&&c.then&&!l(c)){n=2;break}}}var u=new s,h=a.bind(null,u,2);return(0===n?o.then(m):1===n?i.then(d):c.then(g)).then(void 0,h),u;function d(n){i=n;do{if(t&&(c=t())&&c.then&&!l(c))return void c.then(g).then(void 0,h);if(!(o=e())||l(o)&&!o.v)return void a(u,1,i);if(o.then)return void o.then(m).then(void 0,h);l(i=r())&&(i=i.v)}while(!i||!i.then);i.then(d).then(void 0,h)}function m(e){e?(i=r())&&i.then?i.then(d).then(void 0,h):d(i):a(u,1,i)}function g(){(o=e())?o.then?o.then(m).then(void 0,h):m(o):a(u,1,i)}}(function(){return!!o._logs.length},void 0,function(){return Promise.resolve(o.sendBatch(r)).then(function(){})});if(e&&e.then)return e.then(function(){})},function(e){o._logger.log({error:e,message:"Error sending messages to API",method:"flush",correlationId:r,level:n.Error})})}catch(e){return t(!0,e)}return i&&i.then?i.then(t.bind(null,!1),t.bind(null,!0)):t(!1,i)}(0,function(e,r){if(o._interval=setInterval(o.sendBatch.bind(o),1e3*(o._options.batchLogIntervalInSeconds||t.DEFAULT_BATCH_TIMEOUT)),e)throw r;return r}))}catch(e){return Promise.reject(e)}},r.sendBatch=function(t){try{var r=this;void 0===t&&(t=e()),r._logger.log({message:"Start SendBatch",method:"sendBatch",correlationId:t,level:n.Debug});var o=r._logs.splice(0,10);if(!o.length)return Promise.resolve();var i=c(function(){var e=1e3*(r._options.timeoutInSeconds||30),i=new AbortController,a=setTimeout(function(){return i.abort()},e),s={headers:{"content-type":"application/json"},method:"POST",keepalive:!0,body:JSON.stringify(o.map(function(e){return r.getFullLog(e)})),signal:i.signal},l=new URL(r._options.restLoggerUrl);return r._logger.log({message:"ExternalService - Request ("+l.hostname+")",content:o,method:"sendBatch",correlationId:t,level:n.Debug}),Promise.resolve(fetch(r._options.restLoggerUrl,s)).then(function(e){clearTimeout(a),r._logger.log({message:"ExternalService - Response ("+l.hostname+")",method:"sendBatch",correlationId:t,level:n.Debug}),e.ok||r._logger.log({message:"Error sending messages to API",content:o,method:"sendBatch",correlationId:t,level:n.Error})})},function(e){r._logger.log({error:e,message:"Error sending messages to API",content:o,method:"sendBatch",correlationId:t,level:n.Error})});return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.getException=function(e){return e?{stackTrace:e.stack,message:e.message,className:e.name}:null},r.getFullLog=function(e){var r=e.log,n="["+this._options.service.name+"] "+r.message;return r.elapsedTimeInMilliseconds&&(n=n+" in "+r.elapsedTimeInMilliseconds+"ms"),{customMessage:r.message,message:n,service:this._options.service,environment:this._options.environment||"Development",executionDate:e.executionDate,entrypoint:"Execute",method:r.method,correlationId:r.correlationId,content:r.content,exeption:t.getException(r.error),level:r.level,elapsedTimeInMilliseconds:r.elapsedTimeInMilliseconds}},t}();u.DEFAULT_BATCH_TIMEOUT=5;var h=/*#__PURE__*/function(){function e(){this.start=void 0,this.end=void 0,this.start=Date.now()}var t,r;return e.prototype.stop=function(){this.end=Date.now()},t=e,(r=[{key:"elapsed",get:function(){return(this.end||Date.now())-this.start}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o),n)}var o}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}(),d=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),m=/*#__PURE__*/function(){function e(){}return e.create=function(){var e=[48,32,24,16,15,8,4,1].find(function(e){return e<=screen.colorDepth});return{javaEnabled:navigator.javaEnabled(),javascriptEnabled:!0,language:navigator.language,userAgent:navigator.userAgent,screenWidth:window.screen.width,screenHeight:window.screen.height,timezoneOffset:(new Date).getTimezoneOffset(),colorDepth:e,acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}},e}(),g=/*#__PURE__*/function(){function e(e){var t=this;this._task=void 0,this._timeout=void 0,this._task=new Promise(function(r){t._timeout=setTimeout(r,e)})}var t=e.prototype;return t.wait=function(){return this._task},t.cancel=function(){clearTimeout(this._timeout),this._task=Promise.reject({message:"Timer cancelled"})},e.sleep=function(t){return new e(t)},e.cancel=function(e){clearTimeout(e)},e}(),v=/*#__PURE__*/function(){function e(){}return e.createIFrame=function(e){var t=document.createElement("iframe");return t.id=e.name,t.name=e.name,e.onReadyFn&&e.onReadyFn(t,e.isVisible),e.onCreatedFn&&(e.onCreatedFn(t),t.style.opacity=e.isVisible?"1":"0"),e.parent.appendChild(t),t},e.createForm=function(e){var t=document.createElement("form");return t.id=e.name,t.name=e.name,t.action=e.actionUrl,t.target=e.target,t.method=e.method,e.parent.appendChild(t),t},e.createInput=function(e){var t=document.createElement("input");return t.id=e.name,t.name=e.name,t.type=e.type,e.parent.appendChild(t),t},e}();function p(e,t,r){if(!e.s){if(r instanceof f){if(!r.s)return void(r.o=p.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(p.bind(null,e,t),p.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var f=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{p(n,1,i(this.v))}catch(e){p(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?p(n,1,t?t(o):o):r?p(n,1,r(o)):p(n,2,o)}catch(e){p(n,2,e)}},n},e}();function I(e){return e instanceof f&&1&e.s}var _,y=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}return e.prototype.execute=function(e){var t=this,r=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,a){try{var s,l=function(e){var r;if(s)return e;a(u),t._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(r=u)?void 0:r.error,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:n.Error})},c=1,u=null,h=function(e,t){var r;do{var n=e();if(n&&n.then){if(!I(n)){r=!0;break}n=n.v}var o=t();if(I(o)&&(o=o.v),!o)return n}while(!o.then);var i=new f,a=p.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;I(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!I(n))return void n.then(s).then(void 0,a);n=n.v}}p(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!I(n))return void n.then(s).then(void 0,a);n=n.v}if(I(r=t())&&(r=r.v),!r)return void p(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else p(i,1,n)}}(function(){function l(e){return s?e:(c++,Promise.resolve(g.sleep(1e3*t._options.attemptDelayInSeconds).wait()).then(function(){}))}var h=function(n,o){try{var i=Promise.resolve(r({attempt:c,maxAttempts:t._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(s=1);t.isTransientError||(a(t),s=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){u={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:c,maxAttempts:t._options.maxAttempts}},t._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:n.Warning})});return h&&h.then?h.then(l):l(h)},function(){return!s&&c<=t._options.maxAttempts});return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}})},e}(),A=/*#__PURE__*/function(){function e(e,t,r){void 0===r&&(r=new y(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var r=e.prototype;return r.send=function(e){try{var r=this,o=r;return Promise.resolve(r._retryPolicy.execute({executeFn:function(i){var a=i.attempt,s=i.maxAttempts;try{var l=function(e){clearTimeout(d);var t={isSuccess:g.ok,isTransientError:r.isTransientError(g),getData:function(){try{return Promise.resolve(g.clone().json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}};return t},c=1e3*(o._options.timeoutInSeconds||30),u=new AbortController,d=setTimeout(function(){return u.abort()},c),m=new URL(e.url);r._logger.log({message:"ExternalService - Request ("+m.host+")",content:{request:e,attempt:a,maxAttempts:s},method:"send",correlationId:e.correlationId,level:n.Information});var g,v=new h,p=function(o,i){try{var l=Promise.resolve(fetch(e.url,{headers:t({},e.headers,{"x-attempt":a.toString(),"x-max-attempt":s.toString(),accept:"application/json","content-type":"application/json",correlationId:e.correlationId}),keepalive:!0,body:JSON.stringify(e.body),method:e.method,signal:u.signal})).then(function(t){var o=r._logger,i=o.log,l="ExternalService - Response ("+m.host+")",c=(g=t).status;return Promise.resolve(g.clone().text()).then(function(t){i.call(o,{message:l,content:{request:e,attempt:a,maxAttempts:s,response:{statusCode:c,data:t}},method:"send",correlationId:e.correlationId,level:n.Information,elapsedTimeInMilliseconds:v.elapsed})})})}catch(e){return i(e)}return l&&l.then?l.then(void 0,i):l}(0,function(t){throw r._logger.log({message:"ExternalService - Error ("+m.host+")",content:{request:e,attempt:a,maxAttempts:s,error:t},method:"send",correlationId:e.correlationId,level:n.Error,elapsedTimeInMilliseconds:v.elapsed}),t});return Promise.resolve(p&&p.then?p.then(l):l())}catch(e){return Promise.reject(e)}},method:"["+e.method+"] "+e.url,correlationId:e.correlationId}))}catch(e){return Promise.reject(e)}},r.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},e}();!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(_||(_={}));var S=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}var t=e.prototype;return t.execute=function(t){var r=this;return t.authResponse.challengeUrl?new Promise(function(o,i){try{r._logger.log({message:"Challenge - Start",content:{authResponse:t.authResponse},method:"executeChallenge",correlationId:t.correlationId,level:n.Information}),r._options.container.innerHTML="";var a=v.createIFrame({parent:r._options.container,name:e.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!r._options.onIFrameCreatedFn,onCreatedFn:r._options.onIFrameCreatedFn,onReadyFn:r._options.onIFrameReadyFn});r._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:t.correlationId,level:n.Information});var s=v.createForm({parent:r._options.container,name:e.FORM_NAME,actionUrl:t.authResponse.challengeUrl,target:e.IFRAME_NAME,method:"post"});r._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:t.correlationId,level:n.Information});var l=v.createInput({parent:s,name:e.CREQ_INPUT_NAME,type:e.CREQ_INPUT_TYPE});r._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:t.correlationId,level:n.Information});var c={threeDSServerTransID:t.authResponse.processId,acsTransID:t.authResponse.challengeId,messageVersion:t.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:r._options.challengeWindowSize||_.width250xheight400},u=d.convert(c);l.value=u,r._logger.log({message:"Challenge - Prepare cReq",content:{cReq:c,base64CReq:u},method:"executeChallenge",correlationId:t.correlationId,level:n.Information});var m=new h;s.submit(),setTimeout(function e(){var o,i=a.contentDocument||(null==(o=a.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):r._logger.log({message:"Challenge - iFrame loaded in "+m.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeChallenge",correlationId:t.correlationId,level:n.Information})},100),r._logger.log({message:"Challenge - Submit form",content:{authResponse:t.authResponse,cReq:c,base64CReq:u},method:"executeChallenge",correlationId:t.correlationId,level:n.Information}),o()}catch(e){return r._logger.log({message:"Challenge - error",content:{authResponse:t.authResponse},error:e,method:"executeChallenge",correlationId:t.correlationId,level:n.Error}),i({message:e.toString()})}}):Promise.resolve()},t.reset=function(){try{var t,r,n;null==(t=document.getElementById(e.IFRAME_NAME))||t.remove(),null==(r=document.getElementById(e.FORM_NAME))||r.remove(),null==(n=document.getElementById(e.CREQ_INPUT_NAME))||n.remove()}catch(e){}},e}();S.IFRAME_NAME="challengeIframe",S.FORM_NAME="challengeForm",S.CREQ_INPUT_NAME="creq",S.CREQ_INPUT_TYPE="hidden";var P,E=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}var t=e.prototype;return t.execute=function(t){var r=this;return t.preAuthResponse.dsMethodUrl?new Promise(function(o,i){try{var a;r._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:t},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information}),r._options.container.innerHTML="";var s=v.createIFrame({parent:r._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!r._options.onIFrameCreatedFn});null==(a=r._options.onIFrameCreatedFn)||a.call(r._options,s),r._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var l=v.createForm({parent:r._options.container,name:e.FORM_NAME,actionUrl:t.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});r._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var c=v.createInput({parent:l,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});r._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var u={threeDSServerTransID:t.preAuthResponse.processId,threeDSMethodNotificationURL:t.preAuthResponse.notificationUrl},m=d.convert(u);c.value=m,r._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:u,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var g=new h;l.submit(),setTimeout(function e(){var o,i=s.contentDocument||(null==(o=s.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):r._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information})},100),r._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:u,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information}),o()}catch(e){return r._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:t},error:e,method:"directoryServerExecute",correlationId:t.correlationId,level:n.Error}),i({message:e.toString()})}}):Promise.resolve()},t.reset=function(){try{var t,r,n;null==(t=document.getElementById(e.IFRAME_NAME))||t.remove(),null==(r=document.getElementById(e.FORM_NAME))||r.remove(),null==(n=document.getElementById(e.FORM_INPUT_NAME))||n.remove()}catch(e){}},e}();E.IFRAME_NAME="threeDSMethodIframe",E.FORM_NAME="threeDSMethodForm",E.FORM_INPUT_NAME="threeDSMethodData",E.FROM_INPUT_TYPE="hidden",function(e){e.PreAuthStarted="preAuth:started",e.PreAuthCompleted="preAuth:completed",e.AuthStarted="auth:started",e.AuthCompleted="auth:completed",e.PostAuthStarted="postAuth:started",e.PostAuthCompleted="postAuth:completed",e.PostAuthFailed="postAuth:failed",e.ResetStarted="reset:started",e.ResetCompleted="reset:completed"}(P||(P={}));var b=/*#__PURE__*/function(){function t(e,r,n,o,i){void 0===r&&(r=new u(t.getLoggerOptions(e))),void 0===n&&(n=new A(t.getHttpClientOptions(e),r)),void 0===o&&(o=new E(e,r)),void 0===i&&(i=new S(e,r)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._observers=[],this._options=e,this._logger=r,this._client=n,this._directoryServer=o,this._challenge=i}var r=t.prototype;return r.subscribe=function(e){this._observers.push(e)},r.unsubscribe=function(e){var t=this._observers.indexOf(e);t>-1&&this._observers.splice(t,1)},r.execute=function(t,r){try{var o=this;return void 0===r&&(r=e()),t.correlationId||(t.correlationId=r,o._logger.log({message:"Obsolete request. CorrelationId is not set.",content:t,method:"execute",correlationId:t.correlationId,level:n.Information})),Promise.resolve(function(e,r){try{var n=Promise.resolve(o.preAuth(t)).then(function(e){return Promise.resolve(o._directoryServer.execute({preAuthResponse:e,correlationId:t.correlationId})).then(function(){return Promise.resolve(o.auth(t)).then(function(e){return Promise.resolve(o._challenge.execute({authResponse:e,correlationId:t.correlationId})).then(function(){return Promise.resolve(o.postAuth(t))})})})})}catch(e){return r(!0,e)}return n&&n.then?n.then(r.bind(null,!1),r.bind(null,!0)):r(!1,n)}(0,function(e,t){return o.reset(),Promise.resolve(o._logger.flush()).then(function(){if(e)throw t;return t})}))}catch(e){return Promise.reject(e)}},r.preAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:n.Information}),t.notifyAll({name:P.PreAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:m.create()},correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:P.PreAuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.auth=function(e){try{var t=this;return t._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:n.Information}),t.notifyAll({name:P.AuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:P.AuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.postAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:n.Information}),t.notifyAll({name:P.PostAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/postAuth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData()).then(function(e){return t.notifyAll({name:P.PostAuthCompleted,data:e}),e})})}catch(e){return Promise.reject(e)}},r.reset=function(){this.notifyAll({name:P.ResetStarted}),this._challenge.reset(),this._directoryServer.reset(),this.notifyAll({name:P.ResetCompleted})},r.notifyAll=function(e){this._observers.forEach(function(t){return t.notify(e)})},t.getLoggerOptions=function(e){return{restLoggerUrl:e.logUrl,timeoutInSeconds:e.timeoutInSeconds||30,environment:e.environment||"Production",batchLogIntervalInSeconds:e.batchLogIntervalInSeconds||5,minimumLevel:n.Information,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.2.4"}}},t.getHttpClientOptions=function(e){return{timeoutInSeconds:e.timeoutInSeconds||30,attemptDelayInSeconds:e.attemptDelayInSeconds||2,maxAttempts:e.maxAttempts||50}},t}();export{_ as ChallengeWindowSize,y as LinearRetryPolicy,b as ThreeDSecureService};
//# sourceMappingURL=index.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).threedsecureService={})}(this,function(e){function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},r.apply(this,arguments)}var n,o=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.flush=function(){return Promise.resolve()},t.log=function(e){var t,n=r({},e,{error:null==(t=e.error)?void 0:t.toString()});console.log(n)},e}();function i(e,t,r){if(!e.s){if(r instanceof a){if(!r.s)return void(r.o=i.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(i.bind(null,e,t),i.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(n||(n={}));var a=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var a=1&o?t:r;if(a){try{i(n,1,a(this.v))}catch(e){i(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?i(n,1,t?t(o):o):r?i(n,1,r(o)):i(n,2,o)}catch(e){i(n,2,e)}},n},e}();function s(e){return e instanceof a&&1&e.s}var l=/*#__PURE__*/function(){function e(t,r){void 0===r&&(r=new o),this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=r,this._options=t,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))}var t=e.prototype;return t.log=function(t){if(this._logger.log(t),this._options.restLoggerUrl){var r="["+this._options.service.name+"] "+t.message;t.elapsedTimeInMilliseconds&&(r=r+" in "+t.elapsedTimeInMilliseconds+"ms"),this._logs.unshift({customMessage:t.message,message:r,service:this._options.service,environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:t.method,correlationId:t.correlationId,content:t.content,exeption:e.getException(t.error),level:t.level,elapsedTimeInMilliseconds:t.elapsedTimeInMilliseconds})}},t.flush=function(){try{var t=function(){r._interval=setInterval(r.sendBatch.bind(r),1e3*(r._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))},r=this;clearInterval(r._interval);var n=function(e,t,r){for(var n;;){var o=e();if(s(o)&&(o=o.v),!o)return l;if(o.then){n=0;break}var l=r();if(l&&l.then){if(!s(l)){n=1;break}l=l.s}if(t){var c=t();if(c&&c.then&&!s(c)){n=2;break}}}var u=new a,h=i.bind(null,u,2);return(0===n?o.then(m):1===n?l.then(d):c.then(v)).then(void 0,h),u;function d(n){l=n;do{if(t&&(c=t())&&c.then&&!s(c))return void c.then(v).then(void 0,h);if(!(o=e())||s(o)&&!o.v)return void i(u,1,l);if(o.then)return void o.then(m).then(void 0,h);s(l=r())&&(l=l.v)}while(!l||!l.then);l.then(d).then(void 0,h)}function m(e){e?(l=r())&&l.then?l.then(d).then(void 0,h):d(l):i(u,1,l)}function v(){(o=e())?o.then?o.then(m).then(void 0,h):m(o):i(u,1,l)}}(function(){return!!r._logs.length},void 0,function(){return Promise.resolve(r.sendBatch()).then(function(){})});return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},t.sendBatch=function(){try{var e=this,t=e._logs.splice(0,10);if(!t.length)return Promise.resolve();var r=crypto.randomUUID(),o=function(o,i){try{var a=(s=1e3*(e._options.timeoutInSeconds||30),l=new AbortController,c=setTimeout(function(){return l.abort()},s),Promise.resolve(fetch(e._options.restLoggerUrl,{headers:{"content-type":"application/json"},method:"POST",keepalive:!0,body:JSON.stringify(t),signal:l.signal})).then(function(o){clearTimeout(c),o.ok||e._logger.log({message:"Error sending messages to API",content:t,method:"sendBatch",correlationId:r,level:n.Error})}))}catch(e){return i(e)}var s,l,c;return a&&a.then?a.then(void 0,i):a}(0,function(o){e._logger.log({error:o,message:"Error sending messages to API",content:t,method:"sendBatch",correlationId:r,level:n.Error})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},e.getException=function(e){return e?{stackTrace:e.stack,message:e.message,className:e.name}:null},e}();l.DEFAULT_BATCH_TIMEOUT=5;var c=/*#__PURE__*/function(){function e(){this.start=void 0,this.end=void 0,this.start=Date.now()}var t,r;return e.prototype.stop=function(){this.end=Date.now()},t=e,(r=[{key:"elapsed",get:function(){return(this.end||Date.now())-this.start}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o),n)}var o}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}(),u=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),h=/*#__PURE__*/function(){function e(){}return e.create=function(){var e=[48,32,24,16,15,8,4,1].find(function(e){return e<=screen.colorDepth});return{javaEnabled:navigator.javaEnabled(),javascriptEnabled:!0,language:navigator.language,userAgent:navigator.userAgent,screenWidth:window.screen.width,screenHeight:window.screen.height,timezoneOffset:(new Date).getTimezoneOffset(),colorDepth:e,acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}},e}(),d=/*#__PURE__*/function(){function e(e){var t=this;this._task=void 0,this._timeout=void 0,this._task=new Promise(function(r){t._timeout=setTimeout(r,e)})}var t=e.prototype;return t.wait=function(){return this._task},t.cancel=function(){clearTimeout(this._timeout),this._task=Promise.reject({message:"Timer cancelled"})},e.sleep=function(t){return new e(t)},e.cancel=function(e){clearTimeout(e)},e}(),m=/*#__PURE__*/function(){function e(){}return e.createIFrame=function(e){var t=document.createElement("iframe");return t.id=e.name,t.name=e.name,e.onReadyFn&&e.onReadyFn(t,e.isVisible),e.onCreatedFn&&(e.onCreatedFn(t),t.style.opacity=e.isVisible?"1":"0"),e.parent.appendChild(t),t},e.createForm=function(e){var t=document.createElement("form");return t.id=e.name,t.name=e.name,t.action=e.actionUrl,t.target=e.target,t.method=e.method,e.parent.appendChild(t),t},e.createInput=function(e){var t=document.createElement("input");return t.id=e.name,t.name=e.name,t.type=e.type,e.parent.appendChild(t),t},e}();function v(e,t,r){if(!e.s){if(r instanceof g){if(!r.s)return void(r.o=v.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(v.bind(null,e,t),v.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var g=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{v(n,1,i(this.v))}catch(e){v(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?v(n,1,t?t(o):o):r?v(n,1,r(o)):v(n,2,o)}catch(e){v(n,2,e)}},n},e}();function p(e){return e instanceof g&&1&e.s}var f,I=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}return e.prototype.execute=function(e){var t=this,r=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,a){try{var s,l=function(e){var r;if(s)return e;a(u),t._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(r=u)?void 0:r.error,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:n.Error})},c=1,u=null,h=function(e,t){var r;do{var n=e();if(n&&n.then){if(!p(n)){r=!0;break}n=n.v}var o=t();if(p(o)&&(o=o.v),!o)return n}while(!o.then);var i=new g,a=v.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;p(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!p(n))return void n.then(s).then(void 0,a);n=n.v}}v(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!p(n))return void n.then(s).then(void 0,a);n=n.v}if(p(r=t())&&(r=r.v),!r)return void v(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else v(i,1,n)}}(function(){function l(e){return s?e:(c++,Promise.resolve(d.sleep(1e3*t._options.attemptDelayInSeconds).wait()).then(function(){}))}var h=function(n,o){try{var i=Promise.resolve(r({attempt:c,maxAttempts:t._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(s=1);t.isTransientError||(a(t),s=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){u={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:c,maxAttempts:t._options.maxAttempts}},t._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:n.Warning})});return h&&h.then?h.then(l):l(h)},function(){return!s&&c<=t._options.maxAttempts});return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}})},e}(),_=/*#__PURE__*/function(){function e(e,t,r){void 0===r&&(r=new I(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var r=e.prototype;return r.send=function(e){try{var r=this,o=r;return Promise.resolve(r._retryPolicy.execute({executeFn:function(i){var a=i.attempt,s=i.maxAttempts;try{var l=function(e){clearTimeout(d);var t={isSuccess:v.ok,isTransientError:r.isTransientError(v),getData:function(){try{return Promise.resolve(v.clone().json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}};return t},u=1e3*(o._options.timeoutInSeconds||30),h=new AbortController,d=setTimeout(function(){return h.abort()},u),m=new URL(e.url);r._logger.log({message:"ExternalService - Request ("+m.host+")",content:{request:e,attempt:a,maxAttempts:s},method:"send",correlationId:e.correlationId,level:n.Information});var v,g=new c,p=function(o,i){try{var l=Promise.resolve(fetch(e.url,{headers:t({},e.headers,{"x-attempt":a.toString(),"x-max-attempt":s.toString(),accept:"application/json","content-type":"application/json",correlationId:e.correlationId}),keepalive:!0,body:JSON.stringify(e.body),method:e.method,signal:h.signal})).then(function(t){var o=r._logger,i=o.log,l="ExternalService - Response ("+m.host+")",c=(v=t).status;return Promise.resolve(v.clone().text()).then(function(t){i.call(o,{message:l,content:{request:e,attempt:a,maxAttempts:s,response:{statusCode:c,data:t}},method:"send",correlationId:e.correlationId,level:n.Information,elapsedTimeInMilliseconds:g.elapsed})})})}catch(e){return i(e)}return l&&l.then?l.then(void 0,i):l}(0,function(t){throw r._logger.log({message:"ExternalService - Error ("+m.host+")",content:{request:e,attempt:a,maxAttempts:s,error:t},method:"send",correlationId:e.correlationId,level:n.Error,elapsedTimeInMilliseconds:g.elapsed}),t});return Promise.resolve(p&&p.then?p.then(l):l())}catch(e){return Promise.reject(e)}},method:"["+e.method+"] "+e.url,correlationId:e.correlationId}))}catch(e){return Promise.reject(e)}},r.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},e}();e.ChallengeWindowSize=void 0,(f=e.ChallengeWindowSize||(e.ChallengeWindowSize={})).width250xheight400="01",f.width390xheight400="02",f.width500xheight600="03",f.width600xheight400="04",f.fullscreen="05";var y=/*#__PURE__*/function(){function t(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}var r=t.prototype;return r.execute=function(r){var o=this;return r.authResponse.challengeUrl?new Promise(function(i,a){try{o._logger.log({message:"Challenge - Start",content:{authResponse:r.authResponse},method:"executeChallenge",correlationId:r.correlationId,level:n.Information}),o._options.container.innerHTML="";var s=m.createIFrame({parent:o._options.container,name:t.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!o._options.onIFrameCreatedFn,onCreatedFn:o._options.onIFrameCreatedFn,onReadyFn:o._options.onIFrameReadyFn});o._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:r.correlationId,level:n.Information});var l=m.createForm({parent:o._options.container,name:t.FORM_NAME,actionUrl:r.authResponse.challengeUrl,target:t.IFRAME_NAME,method:"post"});o._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:r.correlationId,level:n.Information});var h=m.createInput({parent:l,name:t.CREQ_INPUT_NAME,type:t.CREQ_INPUT_TYPE});o._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:r.correlationId,level:n.Information});var d={threeDSServerTransID:r.authResponse.processId,acsTransID:r.authResponse.challengeId,messageVersion:r.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:o._options.challengeWindowSize||e.ChallengeWindowSize.width250xheight400},v=u.convert(d);h.value=v,o._logger.log({message:"Challenge - Prepare cReq",content:{cReq:d,base64CReq:v},method:"executeChallenge",correlationId:r.correlationId,level:n.Information});var g=new c;l.submit(),setTimeout(function e(){var t,i=s.contentDocument||(null==(t=s.contentWindow)?void 0:t.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):o._logger.log({message:"Challenge - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeChallenge",correlationId:r.correlationId,level:n.Information})},100),o._logger.log({message:"Challenge - Submit form",content:{authResponse:r.authResponse,cReq:d,base64CReq:v},method:"executeChallenge",correlationId:r.correlationId,level:n.Information}),i()}catch(e){return o._logger.log({message:"Challenge - error",content:{authResponse:r.authResponse},error:e,method:"executeChallenge",correlationId:r.correlationId,level:n.Error}),a({message:e.toString()})}}):Promise.resolve()},r.reset=function(){try{var e,r,n;null==(e=document.getElementById(t.IFRAME_NAME))||e.remove(),null==(r=document.getElementById(t.FORM_NAME))||r.remove(),null==(n=document.getElementById(t.CREQ_INPUT_NAME))||n.remove()}catch(e){}},t}();y.IFRAME_NAME="challengeIframe",y.FORM_NAME="challengeForm",y.CREQ_INPUT_NAME="creq",y.CREQ_INPUT_TYPE="hidden";var A,S=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}var t=e.prototype;return t.execute=function(t){var r=this;return t.preAuthResponse.dsMethodUrl?new Promise(function(o,i){try{var a;r._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:t},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information}),r._options.container.innerHTML="";var s=m.createIFrame({parent:r._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!r._options.onIFrameCreatedFn});null==(a=r._options.onIFrameCreatedFn)||a.call(r._options,s),r._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var l=m.createForm({parent:r._options.container,name:e.FORM_NAME,actionUrl:t.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});r._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var h=m.createInput({parent:l,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});r._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var d={threeDSServerTransID:t.preAuthResponse.processId,threeDSMethodNotificationURL:t.preAuthResponse.notificationUrl},v=u.convert(d);h.value=v,r._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:d,threeDSMethodDataBase64:v},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information});var g=new c;l.submit(),setTimeout(function e(){var o,i=s.contentDocument||(null==(o=s.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):r._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information})},100),r._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:d,threeDSMethodDataBase64:v},method:"executeDirectoryServer",correlationId:t.correlationId,level:n.Information}),o()}catch(e){return r._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:t},error:e,method:"directoryServerExecute",correlationId:t.correlationId,level:n.Error}),i({message:e.toString()})}}):Promise.resolve()},t.reset=function(){try{var t,r,n;null==(t=document.getElementById(e.IFRAME_NAME))||t.remove(),null==(r=document.getElementById(e.FORM_NAME))||r.remove(),null==(n=document.getElementById(e.FORM_INPUT_NAME))||n.remove()}catch(e){}},e}();S.IFRAME_NAME="threeDSMethodIframe",S.FORM_NAME="threeDSMethodForm",S.FORM_INPUT_NAME="threeDSMethodData",S.FROM_INPUT_TYPE="hidden",function(e){e.PreAuthStarted="preAuth:started",e.PreAuthCompleted="preAuth:completed",e.AuthStarted="auth:started",e.AuthCompleted="auth:completed",e.PostAuthStarted="postAuth:started",e.PostAuthCompleted="postAuth:completed",e.PostAuthFailed="postAuth:failed",e.ResetStarted="reset:started",e.ResetCompleted="reset:completed"}(A||(A={}));var P=/*#__PURE__*/function(){function e(t,r,n,o,i){void 0===r&&(r=new l(e.getLoggerOptions(t))),void 0===n&&(n=new _(e.getHttpClientOptions(t),r)),void 0===o&&(o=new S(t,r)),void 0===i&&(i=new y(t,r)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._observers=[],this._options=t,this._logger=r,this._client=n,this._directoryServer=o,this._challenge=i}var t=e.prototype;return t.subscribe=function(e){this._observers.push(e)},t.unsubscribe=function(e){var t=this._observers.indexOf(e);t>-1&&this._observers.splice(t,1)},t.execute=function(e,t){try{var r=this;return void 0===t&&(t=crypto.randomUUID()),e.correlationId||(e.correlationId=t,r._logger.log({message:"Obsolete request. CorrelationId is not set.",content:e,method:"execute",correlationId:e.correlationId,level:n.Information})),Promise.resolve(function(t,n){try{var o=Promise.resolve(r.preAuth(e)).then(function(t){return Promise.resolve(r._directoryServer.execute({preAuthResponse:t,correlationId:e.correlationId})).then(function(){return Promise.resolve(r.auth(e)).then(function(t){return Promise.resolve(r._challenge.execute({authResponse:t,correlationId:e.correlationId})).then(function(){return Promise.resolve(r.postAuth(e))})})})})}catch(e){return n(!0,e)}return o&&o.then?o.then(n.bind(null,!1),n.bind(null,!0)):n(!1,o)}(0,function(e,t){return r.reset(),Promise.resolve(r._logger.flush()).then(function(){if(e)throw t;return t})}))}catch(e){return Promise.reject(e)}},t.preAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:n.Information}),t.notifyAll({name:A.PreAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:h.create()},correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:A.PreAuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.auth=function(e){try{var t=this;return t._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:n.Information}),t.notifyAll({name:A.AuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:A.AuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.postAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:n.Information}),t.notifyAll({name:A.PostAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/postAuth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData()).then(function(e){return t.notifyAll({name:A.PostAuthCompleted,data:e}),e})})}catch(e){return Promise.reject(e)}},t.reset=function(){this.notifyAll({name:A.ResetStarted}),this._challenge.reset(),this._directoryServer.reset(),this.notifyAll({name:A.ResetCompleted})},t.notifyAll=function(e){this._observers.forEach(function(t){return t.notify(e)})},e.getLoggerOptions=function(e){return{restLoggerUrl:e.logUrl,timeoutInSeconds:e.timeoutInSeconds||30,environment:e.environment||"Production",batchLogIntervalInSeconds:e.batchLogIntervalInSeconds||5,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.2.4"}}},e.getHttpClientOptions=function(e){return{timeoutInSeconds:e.timeoutInSeconds||30,attemptDelayInSeconds:e.attemptDelayInSeconds||2,maxAttempts:e.maxAttempts||50}},e}();e.LinearRetryPolicy=I,e.ThreeDSecureService=P});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("uuid")):"function"==typeof define&&define.amd?define(["exports","uuid"],t):t((e||self).threedsecureService={},e.uuid)}(this,function(e,t){function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},r.apply(this,arguments)}function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},n.apply(this,arguments)}var o,i;(i=o||(o={}))[i.Trace=0]="Trace",i[i.Debug=1]="Debug",i[i.Information=2]="Information",i[i.Warning=3]="Warning",i[i.Error=4]="Error",i[i.Critical=5]="Critical",i[i.None=6]="None";var a=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.flush=function(){return Promise.resolve()},t.log=function(e){var t,r=n({},e,{error:null==(t=e.error)?void 0:t.toString()});switch(e.level){case o.Trace:return console.trace(r);case o.Debug:return console.debug(r);case o.Warning:return console.warn(r);case o.Error:case o.Critical:return console.error(r);default:return console.log(r)}},e}();function s(e,t,r){if(!e.s){if(r instanceof l){if(!r.s)return void(r.o=s.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(s.bind(null,e,t),s.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var l=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{s(n,1,i(this.v))}catch(e){s(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?s(n,1,t?t(o):o):r?s(n,1,r(o)):s(n,2,o)}catch(e){s(n,2,e)}},n},e}();function c(e){return e instanceof l&&1&e.s}function u(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var h=/*#__PURE__*/function(){function e(t,r){void 0===r&&(r=new a),this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=r,this._options=t,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))}var r=e.prototype;return r.log=function(e){if(this._logger.log(e),this._options.restLoggerUrl)return this._options.minimumLevel&&e.level<this._options.minimumLevel?this._logger.log({message:"Minimum level not achieved for sending",content:{log:e,minimumLevel:this._options.minimumLevel},method:"log",correlationId:e.correlationId,level:o.Warning}):void this._logs.unshift({executionDate:new Date,log:e});this._logger.log({message:"RestLoggerUrl is not defined",content:e,method:"log",correlationId:e.correlationId,level:o.Warning})},r.flush=function(r){try{var n=this;return void 0===r&&(r=t.v4()),clearInterval(n._interval),Promise.resolve(function(e,t){try{var i=u(function(){var e=function(e,t,r){for(var n;;){var o=e();if(c(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!c(i)){n=1;break}i=i.s}if(t){var a=t();if(a&&a.then&&!c(a)){n=2;break}}}var u=new l,h=s.bind(null,u,2);return(0===n?o.then(m):1===n?i.then(d):a.then(g)).then(void 0,h),u;function d(n){i=n;do{if(t&&(a=t())&&a.then&&!c(a))return void a.then(g).then(void 0,h);if(!(o=e())||c(o)&&!o.v)return void s(u,1,i);if(o.then)return void o.then(m).then(void 0,h);c(i=r())&&(i=i.v)}while(!i||!i.then);i.then(d).then(void 0,h)}function m(e){e?(i=r())&&i.then?i.then(d).then(void 0,h):d(i):s(u,1,i)}function g(){(o=e())?o.then?o.then(m).then(void 0,h):m(o):s(u,1,i)}}(function(){return!!n._logs.length},void 0,function(){return Promise.resolve(n.sendBatch(r)).then(function(){})});if(e&&e.then)return e.then(function(){})},function(e){n._logger.log({error:e,message:"Error sending messages to API",method:"flush",correlationId:r,level:o.Error})})}catch(e){return t(!0,e)}return i&&i.then?i.then(t.bind(null,!1),t.bind(null,!0)):t(!1,i)}(0,function(t,r){if(n._interval=setInterval(n.sendBatch.bind(n),1e3*(n._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT)),t)throw r;return r}))}catch(e){return Promise.reject(e)}},r.sendBatch=function(e){try{var r=this;void 0===e&&(e=t.v4()),r._logger.log({message:"Start SendBatch",method:"sendBatch",correlationId:e,level:o.Debug});var n=r._logs.splice(0,10);if(!n.length)return Promise.resolve();var i=u(function(){var t=1e3*(r._options.timeoutInSeconds||30),i=new AbortController,a=setTimeout(function(){return i.abort()},t),s={headers:{"content-type":"application/json"},method:"POST",keepalive:!0,body:JSON.stringify(n.map(function(e){return r.getFullLog(e)})),signal:i.signal},l=new URL(r._options.restLoggerUrl);return r._logger.log({message:"ExternalService - Request ("+l.hostname+")",content:n,method:"sendBatch",correlationId:e,level:o.Debug}),Promise.resolve(fetch(r._options.restLoggerUrl,s)).then(function(t){clearTimeout(a),r._logger.log({message:"ExternalService - Response ("+l.hostname+")",method:"sendBatch",correlationId:e,level:o.Debug}),t.ok||r._logger.log({message:"Error sending messages to API",content:n,method:"sendBatch",correlationId:e,level:o.Error})})},function(t){r._logger.log({error:t,message:"Error sending messages to API",content:n,method:"sendBatch",correlationId:e,level:o.Error})});return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},e.getException=function(e){return e?{stackTrace:e.stack,message:e.message,className:e.name}:null},r.getFullLog=function(t){var r=t.log,n="["+this._options.service.name+"] "+r.message;return r.elapsedTimeInMilliseconds&&(n=n+" in "+r.elapsedTimeInMilliseconds+"ms"),{customMessage:r.message,message:n,service:this._options.service,environment:this._options.environment||"Development",executionDate:t.executionDate,entrypoint:"Execute",method:r.method,correlationId:r.correlationId,content:r.content,exeption:e.getException(r.error),level:r.level,elapsedTimeInMilliseconds:r.elapsedTimeInMilliseconds}},e}();h.DEFAULT_BATCH_TIMEOUT=5;var d=/*#__PURE__*/function(){function e(){this.start=void 0,this.end=void 0,this.start=Date.now()}var t,r;return e.prototype.stop=function(){this.end=Date.now()},t=e,(r=[{key:"elapsed",get:function(){return(this.end||Date.now())-this.start}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o),n)}var o}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}(),m=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),g=/*#__PURE__*/function(){function e(){}return e.create=function(){var e=[48,32,24,16,15,8,4,1].find(function(e){return e<=screen.colorDepth});return{javaEnabled:navigator.javaEnabled(),javascriptEnabled:!0,language:navigator.language,userAgent:navigator.userAgent,screenWidth:window.screen.width,screenHeight:window.screen.height,timezoneOffset:(new Date).getTimezoneOffset(),colorDepth:e,acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}},e}(),v=/*#__PURE__*/function(){function e(e){var t=this;this._task=void 0,this._timeout=void 0,this._task=new Promise(function(r){t._timeout=setTimeout(r,e)})}var t=e.prototype;return t.wait=function(){return this._task},t.cancel=function(){clearTimeout(this._timeout),this._task=Promise.reject({message:"Timer cancelled"})},e.sleep=function(t){return new e(t)},e.cancel=function(e){clearTimeout(e)},e}(),f=/*#__PURE__*/function(){function e(){}return e.createIFrame=function(e){var t=document.createElement("iframe");return t.id=e.name,t.name=e.name,e.onReadyFn&&e.onReadyFn(t,e.isVisible),e.onCreatedFn&&(e.onCreatedFn(t),t.style.opacity=e.isVisible?"1":"0"),e.parent.appendChild(t),t},e.createForm=function(e){var t=document.createElement("form");return t.id=e.name,t.name=e.name,t.action=e.actionUrl,t.target=e.target,t.method=e.method,e.parent.appendChild(t),t},e.createInput=function(e){var t=document.createElement("input");return t.id=e.name,t.name=e.name,t.type=e.type,e.parent.appendChild(t),t},e}();function p(e,t,r){if(!e.s){if(r instanceof I){if(!r.s)return void(r.o=p.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(p.bind(null,e,t),p.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var I=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{p(n,1,i(this.v))}catch(e){p(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?p(n,1,t?t(o):o):r?p(n,1,r(o)):p(n,2,o)}catch(e){p(n,2,e)}},n},e}();function _(e){return e instanceof I&&1&e.s}var y,A=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}return e.prototype.execute=function(e){var t=this,r=e.executeFn,n=e.method,i=e.correlationId;return new Promise(function(e,a){try{var s,l=function(e){var r;if(s)return e;a(u),t._logger.log({message:'Unhandled error calling "'+n+'"',error:null==(r=u)?void 0:r.error,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:n,correlationId:i,level:o.Error})},c=1,u=null,h=function(e,t){var r;do{var n=e();if(n&&n.then){if(!_(n)){r=!0;break}n=n.v}var o=t();if(_(o)&&(o=o.v),!o)return n}while(!o.then);var i=new I,a=p.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;_(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!_(n))return void n.then(s).then(void 0,a);n=n.v}}p(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!_(n))return void n.then(s).then(void 0,a);n=n.v}if(_(r=t())&&(r=r.v),!r)return void p(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else p(i,1,n)}}(function(){function l(e){return s?e:(c++,Promise.resolve(v.sleep(1e3*t._options.attemptDelayInSeconds).wait()).then(function(){}))}var h=function(n,o){try{var i=Promise.resolve(r({attempt:c,maxAttempts:t._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(s=1);t.isTransientError||(a(t),s=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){u={message:'Unhandled error calling "'+n+'"',error:e,additionalData:{attempt:c,maxAttempts:t._options.maxAttempts}},t._logger.log({message:'Unhandled error calling "'+n+'"',error:e,content:{attempt:c,maxAttempts:t._options.maxAttempts},method:n,correlationId:i,level:o.Warning})});return h&&h.then?h.then(l):l(h)},function(){return!s&&c<=t._options.maxAttempts});return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}})},e}(),S=/*#__PURE__*/function(){function e(e,t,r){void 0===r&&(r=new A(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var t=e.prototype;return t.send=function(e){try{var t=this,n=t;return Promise.resolve(t._retryPolicy.execute({executeFn:function(i){var a=i.attempt,s=i.maxAttempts;try{var l=function(e){clearTimeout(h);var r={isSuccess:g.ok,isTransientError:t.isTransientError(g),getData:function(){try{return Promise.resolve(g.clone().json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}};return r},c=1e3*(n._options.timeoutInSeconds||30),u=new AbortController,h=setTimeout(function(){return u.abort()},c),m=new URL(e.url);t._logger.log({message:"ExternalService - Request ("+m.host+")",content:{request:e,attempt:a,maxAttempts:s},method:"send",correlationId:e.correlationId,level:o.Information});var g,v=new d,f=function(n,i){try{var l=Promise.resolve(fetch(e.url,{headers:r({},e.headers,{"x-attempt":a.toString(),"x-max-attempt":s.toString(),accept:"application/json","content-type":"application/json",correlationId:e.correlationId}),keepalive:!0,body:JSON.stringify(e.body),method:e.method,signal:u.signal})).then(function(r){var n=t._logger,i=n.log,l="ExternalService - Response ("+m.host+")",c=(g=r).status;return Promise.resolve(g.clone().text()).then(function(t){i.call(n,{message:l,content:{request:e,attempt:a,maxAttempts:s,response:{statusCode:c,data:t}},method:"send",correlationId:e.correlationId,level:o.Information,elapsedTimeInMilliseconds:v.elapsed})})})}catch(e){return i(e)}return l&&l.then?l.then(void 0,i):l}(0,function(r){throw t._logger.log({message:"ExternalService - Error ("+m.host+")",content:{request:e,attempt:a,maxAttempts:s,error:r},method:"send",correlationId:e.correlationId,level:o.Error,elapsedTimeInMilliseconds:v.elapsed}),r});return Promise.resolve(f&&f.then?f.then(l):l())}catch(e){return Promise.reject(e)}},method:"["+e.method+"] "+e.url,correlationId:e.correlationId}))}catch(e){return Promise.reject(e)}},t.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},e}();e.ChallengeWindowSize=void 0,(y=e.ChallengeWindowSize||(e.ChallengeWindowSize={})).width250xheight400="01",y.width390xheight400="02",y.width500xheight600="03",y.width600xheight400="04",y.fullscreen="05";var P=/*#__PURE__*/function(){function t(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}var r=t.prototype;return r.execute=function(r){var n=this;return r.authResponse.challengeUrl?new Promise(function(i,a){try{n._logger.log({message:"Challenge - Start",content:{authResponse:r.authResponse},method:"executeChallenge",correlationId:r.correlationId,level:o.Information}),n._options.container.innerHTML="";var s=f.createIFrame({parent:n._options.container,name:t.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!n._options.onIFrameCreatedFn,onCreatedFn:n._options.onIFrameCreatedFn,onReadyFn:n._options.onIFrameReadyFn});n._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:r.correlationId,level:o.Information});var l=f.createForm({parent:n._options.container,name:t.FORM_NAME,actionUrl:r.authResponse.challengeUrl,target:t.IFRAME_NAME,method:"post"});n._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:r.correlationId,level:o.Information});var c=f.createInput({parent:l,name:t.CREQ_INPUT_NAME,type:t.CREQ_INPUT_TYPE});n._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:r.correlationId,level:o.Information});var u={threeDSServerTransID:r.authResponse.processId,acsTransID:r.authResponse.challengeId,messageVersion:r.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:n._options.challengeWindowSize||e.ChallengeWindowSize.width250xheight400},h=m.convert(u);c.value=h,n._logger.log({message:"Challenge - Prepare cReq",content:{cReq:u,base64CReq:h},method:"executeChallenge",correlationId:r.correlationId,level:o.Information});var g=new d;l.submit(),setTimeout(function e(){var t,i=s.contentDocument||(null==(t=s.contentWindow)?void 0:t.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"Challenge - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeChallenge",correlationId:r.correlationId,level:o.Information})},100),n._logger.log({message:"Challenge - Submit form",content:{authResponse:r.authResponse,cReq:u,base64CReq:h},method:"executeChallenge",correlationId:r.correlationId,level:o.Information}),i()}catch(e){return n._logger.log({message:"Challenge - error",content:{authResponse:r.authResponse},error:e,method:"executeChallenge",correlationId:r.correlationId,level:o.Error}),a({message:e.toString()})}}):Promise.resolve()},r.reset=function(){try{var e,r,n;null==(e=document.getElementById(t.IFRAME_NAME))||e.remove(),null==(r=document.getElementById(t.FORM_NAME))||r.remove(),null==(n=document.getElementById(t.CREQ_INPUT_NAME))||n.remove()}catch(e){}},t}();P.IFRAME_NAME="challengeIframe",P.FORM_NAME="challengeForm",P.CREQ_INPUT_NAME="creq",P.CREQ_INPUT_TYPE="hidden";var b,E=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}var t=e.prototype;return t.execute=function(t){var r=this;return t.preAuthResponse.dsMethodUrl?new Promise(function(n,i){try{var a;r._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:t},method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information}),r._options.container.innerHTML="";var s=f.createIFrame({parent:r._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!r._options.onIFrameCreatedFn});null==(a=r._options.onIFrameCreatedFn)||a.call(r._options,s),r._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information});var l=f.createForm({parent:r._options.container,name:e.FORM_NAME,actionUrl:t.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});r._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information});var c=f.createInput({parent:l,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});r._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information});var u={threeDSServerTransID:t.preAuthResponse.processId,threeDSMethodNotificationURL:t.preAuthResponse.notificationUrl},h=m.convert(u);c.value=h,r._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:u,threeDSMethodDataBase64:h},method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information});var g=new d;l.submit(),setTimeout(function e(){var n,i=s.contentDocument||(null==(n=s.contentWindow)?void 0:n.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):r._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information})},100),r._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:u,threeDSMethodDataBase64:h},method:"executeDirectoryServer",correlationId:t.correlationId,level:o.Information}),n()}catch(e){return r._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:t},error:e,method:"directoryServerExecute",correlationId:t.correlationId,level:o.Error}),i({message:e.toString()})}}):Promise.resolve()},t.reset=function(){try{var t,r,n;null==(t=document.getElementById(e.IFRAME_NAME))||t.remove(),null==(r=document.getElementById(e.FORM_NAME))||r.remove(),null==(n=document.getElementById(e.FORM_INPUT_NAME))||n.remove()}catch(e){}},e}();E.IFRAME_NAME="threeDSMethodIframe",E.FORM_NAME="threeDSMethodForm",E.FORM_INPUT_NAME="threeDSMethodData",E.FROM_INPUT_TYPE="hidden",function(e){e.PreAuthStarted="preAuth:started",e.PreAuthCompleted="preAuth:completed",e.AuthStarted="auth:started",e.AuthCompleted="auth:completed",e.PostAuthStarted="postAuth:started",e.PostAuthCompleted="postAuth:completed",e.PostAuthFailed="postAuth:failed",e.ResetStarted="reset:started",e.ResetCompleted="reset:completed"}(b||(b={}));var x=/*#__PURE__*/function(){function e(t,r,n,o,i){void 0===r&&(r=new h(e.getLoggerOptions(t))),void 0===n&&(n=new S(e.getHttpClientOptions(t),r)),void 0===o&&(o=new E(t,r)),void 0===i&&(i=new P(t,r)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._observers=[],this._options=t,this._logger=r,this._client=n,this._directoryServer=o,this._challenge=i}var r=e.prototype;return r.subscribe=function(e){this._observers.push(e)},r.unsubscribe=function(e){var t=this._observers.indexOf(e);t>-1&&this._observers.splice(t,1)},r.execute=function(e,r){try{var n=this;return void 0===r&&(r=t.v4()),e.correlationId||(e.correlationId=r,n._logger.log({message:"Obsolete request. CorrelationId is not set.",content:e,method:"execute",correlationId:e.correlationId,level:o.Information})),Promise.resolve(function(t,r){try{var o=Promise.resolve(n.preAuth(e)).then(function(t){return Promise.resolve(n._directoryServer.execute({preAuthResponse:t,correlationId:e.correlationId})).then(function(){return Promise.resolve(n.auth(e)).then(function(t){return Promise.resolve(n._challenge.execute({authResponse:t,correlationId:e.correlationId})).then(function(){return Promise.resolve(n.postAuth(e))})})})})}catch(e){return r(!0,e)}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):r(!1,o)}(0,function(e,t){return n.reset(),Promise.resolve(n._logger.flush()).then(function(){if(e)throw t;return t})}))}catch(e){return Promise.reject(e)}},r.preAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:o.Information}),t.notifyAll({name:b.PreAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:g.create()},correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:b.PreAuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.auth=function(e){try{var t=this;return t._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:o.Information}),t.notifyAll({name:b.AuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return t.notifyAll({name:b.AuthCompleted,data:e}),Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.postAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:o.Information}),t.notifyAll({name:b.PostAuthStarted,data:e}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/postAuth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData()).then(function(e){return t.notifyAll({name:b.PostAuthCompleted,data:e}),e})})}catch(e){return Promise.reject(e)}},r.reset=function(){this.notifyAll({name:b.ResetStarted}),this._challenge.reset(),this._directoryServer.reset(),this.notifyAll({name:b.ResetCompleted})},r.notifyAll=function(e){this._observers.forEach(function(t){return t.notify(e)})},e.getLoggerOptions=function(e){return{restLoggerUrl:e.logUrl,timeoutInSeconds:e.timeoutInSeconds||30,environment:e.environment||"Production",batchLogIntervalInSeconds:e.batchLogIntervalInSeconds||5,minimumLevel:o.Information,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.2.4"}}},e.getHttpClientOptions=function(e){return{timeoutInSeconds:e.timeoutInSeconds||30,attemptDelayInSeconds:e.attemptDelayInSeconds||2,maxAttempts:e.maxAttempts||50}},e}();e.LinearRetryPolicy=A,e.ThreeDSecureService=x});
//# sourceMappingURL=index.umd.js.map
{
"name": "@paybyrd/threedsecure-service",
"version": "3.2.4",
"version": "3.2.5-rc.2",
"description": "JS service implementation to control the 3DS flow over Paybyrd API",

@@ -47,8 +47,12 @@ "repository": {

"devDependencies": {
"@paybyrd/logger-js": "^1.2.2-rc.1",
"@types/uuid": "^9.0.8",
"buffer": "^6.0.3",
"live-server": "^1.2.2",
"microbundle": "^0.15.1",
"typescript": "^4.9.5",
"@paybyrd/logger-js": "^1.1.0",
"buffer": "^6.0.3"
"typescript": "^4.9.5"
},
"dependencies": {
"uuid": "^9.0.1"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc