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.5-rc.2 to 3.2.5-rc.3

2

dist/index.module.js

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

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};
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.5"}}},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,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});
!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.5"}}},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.5-rc.2",
"version": "3.2.5-rc.3",
"description": "JS service implementation to control the 3DS flow over Paybyrd API",

@@ -5,0 +5,0 @@ "repository": {

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